1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096 |
- <?php
- /* For licensing terms, see /license.txt */
- /**
- * Class Agenda
- *
- * @author: Julio Montoya <gugli100@gmail.com>
- */
- class Agenda
- {
- public $events = array();
- /** @var string Current type */
- public $type = 'personal';
- public $types = array('personal', 'admin', 'course');
- public $sessionId = 0;
- public $senderId;
- /** @var array */
- public $course;
- /** @var array */
- private $sessionInfo;
- /** @var string */
- public $comment;
- /** @var bool */
- private $isAllowedToEdit;
- public $eventStudentPublicationColor;
- /**
- * Constructor
- * @param string $type
- * @param int $senderId Optional The user sender ID
- * @param int $courseId Opitonal. The course ID
- * @param int $sessionId Optional The session ID
- */
- public function __construct(
- $type,
- $senderId = 0,
- $courseId = 0,
- $sessionId = 0
- ) {
- // Table definitions
- $this->tbl_global_agenda = Database::get_main_table(TABLE_MAIN_SYSTEM_CALENDAR);
- $this->tbl_personal_agenda = Database::get_main_table(TABLE_PERSONAL_AGENDA);
- $this->tbl_course_agenda = Database::get_course_table(TABLE_AGENDA);
- $this->table_repeat = Database::get_course_table(TABLE_AGENDA_REPEAT);
- $this->setType($type);
- $this->setSenderId($senderId ?: api_get_user_id());
- $isAllowToEdit = false;
- switch ($type) {
- case 'course':
- $sessionId = $sessionId ?: api_get_session_id();
- $sessionInfo = api_get_session_info($sessionId);
- $this->setSessionId($sessionId);
- $this->setSessionInfo($sessionInfo);
- // Setting the course object if we are in a course
- $courseInfo = api_get_course_info_by_id($courseId);
- if (!empty($courseInfo)) {
- $this->set_course($courseInfo);
- }
- // Check if teacher
- if (empty($sessionId)) {
- $isAllowToEdit = api_is_allowed_to_edit(false, true);
- } else {
- $isAllowToEdit = api_is_allowed_to_session_edit(
- false,
- true
- );
- }
- // Check
- if (api_get_course_setting('allow_user_edit_agenda') && api_is_allowed_in_course()) {
- $isAllowToEdit = true;
- }
- $groupId = api_get_group_id();
- if (!empty($groupId)) {
- $groupInfo = GroupManager::get_group_properties($groupId);
- $userHasAccess = GroupManager::user_has_access(
- api_get_user_id(),
- $groupInfo['iid'],
- GroupManager::GROUP_TOOL_CALENDAR
- );
- $isTutor = GroupManager::is_tutor_of_group(
- api_get_user_id(),
- $groupInfo
- );
- $isGroupAccess = $userHasAccess || $isTutor;
- if ($isGroupAccess) {
- $isAllowToEdit = true;
- } else {
- $isAllowToEdit = false;
- }
- }
- break;
- case 'admin':
- $isAllowToEdit = api_is_platform_admin();
- break;
- case 'personal':
- $isAllowToEdit = !api_is_anonymous();
- break;
- }
- $this->setIsAllowedToEdit($isAllowToEdit);
- $this->events = [];
- // Event colors
- $this->event_platform_color = 'red'; //red
- $this->event_course_color = '#458B00'; //green
- $this->event_group_color = '#A0522D'; //siena
- $this->event_session_color = '#00496D'; // kind of green
- $this->eventOtherSessionColor = '#999';
- $this->event_personal_color = 'steel blue'; //steel blue
- $this->eventStudentPublicationColor = '#FF8C00'; //DarkOrange
- }
- /**
- * @param int $senderId
- */
- public function setSenderId($senderId)
- {
- $this->senderId = intval($senderId);
- }
- /**
- * @return int
- */
- public function getSenderId()
- {
- return $this->senderId;
- }
- /**
- * @param string $type can be 'personal', 'admin' or 'course'
- */
- public function setType($type)
- {
- $typeList = $this->getTypes();
- if (in_array($type, $typeList)) {
- $this->type = $type;
- }
- }
- /**
- * @param int $id
- */
- public function setSessionId($id)
- {
- $this->sessionId = intval($id);
- }
- /**
- * @param array $sessionInfo
- */
- public function setSessionInfo($sessionInfo)
- {
- $this->sessionInfo = $sessionInfo;
- }
- /**
- * @return int $id
- */
- public function getSessionId()
- {
- return $this->sessionId;
- }
- /**
- * @param array $courseInfo
- */
- public function set_course($courseInfo)
- {
- $this->course = $courseInfo;
- }
- /**
- * @return array
- */
- public function getTypes()
- {
- return $this->types;
- }
- /**
- * Adds an event to the calendar
- * @param string $start datetime format: 2012-06-14 09:00:00
- * @param string $end datetime format: 2012-06-14 09:00:00
- * @param string $allDay (true, false)
- * @param string $title
- * @param string $content
- * @param array $usersToSend array('everyone') or a list of user/group ids
- * @param bool $addAsAnnouncement event as a *course* announcement
- * @param int $parentEventId
- * @param array $attachmentArray array of $_FILES['']
- * @param array $attachmentCommentList
- * @param string $eventComment
- * @param string $color
- *
- * @return int
- */
- public function addEvent(
- $start,
- $end,
- $allDay,
- $title,
- $content,
- $usersToSend = array(),
- $addAsAnnouncement = false,
- $parentEventId = null,
- $attachmentArray = array(),
- $attachmentCommentList = array(),
- $eventComment = null,
- $color = ''
- ) {
- $start = api_get_utc_datetime($start);
- $end = api_get_utc_datetime($end);
- $allDay = isset($allDay) && $allDay === 'true' ? 1 : 0;
- $id = null;
- switch ($this->type) {
- case 'personal':
- $attributes = array(
- 'user' => api_get_user_id(),
- 'title' => $title,
- 'text' => $content,
- 'date' => $start,
- 'enddate' => $end,
- 'all_day' => $allDay,
- 'color' => $color
- );
- $id = Database::insert(
- $this->tbl_personal_agenda,
- $attributes
- );
- break;
- case 'course':
- $attributes = array(
- 'title' => $title,
- 'content' => $content,
- 'start_date' => $start,
- 'end_date' => $end,
- 'all_day' => $allDay,
- 'session_id' => $this->getSessionId(),
- 'c_id' => $this->course['real_id'],
- 'comment' => $eventComment,
- 'color' => $color
- );
- if (!empty($parentEventId)) {
- $attributes['parent_event_id'] = $parentEventId;
- }
- $senderId = $this->getSenderId();
- $sessionId = $this->getSessionId();
- // Simple course event.
- $id = Database::insert($this->tbl_course_agenda, $attributes);
- if ($id) {
- $sql = "UPDATE ".$this->tbl_course_agenda." SET id = iid WHERE iid = $id";
- Database::query($sql);
- $groupId = api_get_group_id();
- $groupInfo = [];
- if ($groupId) {
- $groupInfo = GroupManager::get_group_properties(
- $groupId
- );
- }
- if (!empty($usersToSend)) {
- $sendTo = $this->parseSendToArray($usersToSend);
- if ($sendTo['everyone']) {
- api_item_property_update(
- $this->course,
- TOOL_CALENDAR_EVENT,
- $id,
- 'AgendaAdded',
- $senderId,
- $groupInfo,
- '',
- $start,
- $end,
- $sessionId
- );
- api_item_property_update(
- $this->course,
- TOOL_CALENDAR_EVENT,
- $id,
- 'visible',
- $senderId,
- $groupInfo,
- '',
- $start,
- $end,
- $sessionId
- );
- } else {
- // Storing the selected groups
- if (!empty($sendTo['groups'])) {
- foreach ($sendTo['groups'] as $group) {
- $groupInfoItem = [];
- if ($group) {
- $groupInfoItem = GroupManager::get_group_properties(
- $group
- );
- if ($groupInfoItem) {
- $groupIidItem = $groupInfoItem['iid'];
- }
- }
- api_item_property_update(
- $this->course,
- TOOL_CALENDAR_EVENT,
- $id,
- 'AgendaAdded',
- $senderId,
- $groupInfoItem,
- 0,
- $start,
- $end,
- $sessionId
- );
- api_item_property_update(
- $this->course,
- TOOL_CALENDAR_EVENT,
- $id,
- 'visible',
- $senderId,
- $groupInfoItem,
- 0,
- $start,
- $end,
- $sessionId
- );
- }
- }
- // storing the selected users
- if (!empty($sendTo['users'])) {
- foreach ($sendTo['users'] as $userId) {
- api_item_property_update(
- $this->course,
- TOOL_CALENDAR_EVENT,
- $id,
- 'AgendaAdded',
- $senderId,
- $groupInfo,
- $userId,
- $start,
- $end,
- $sessionId
- );
- api_item_property_update(
- $this->course,
- TOOL_CALENDAR_EVENT,
- $id,
- 'visible',
- $senderId,
- $groupInfo,
- $userId,
- $start,
- $end,
- $sessionId
- );
- }
- }
- }
- }
- // Add announcement.
- if ($addAsAnnouncement) {
- $this->storeAgendaEventAsAnnouncement(
- $id,
- $usersToSend
- );
- }
- // Add attachment.
- if (isset($attachmentArray) && !empty($attachmentArray)) {
- $counter = 0;
- foreach ($attachmentArray as $attachmentItem) {
- $this->addAttachment(
- $id,
- $attachmentItem,
- $attachmentCommentList[$counter],
- $this->course
- );
- $counter++;
- }
- }
- }
- break;
- case 'admin':
- if (api_is_platform_admin()) {
- $attributes = array(
- 'title' => $title,
- 'content' => $content,
- 'start_date' => $start,
- 'end_date' => $end,
- 'all_day' => $allDay,
- 'access_url_id' => api_get_current_access_url_id()
- );
- $id = Database::insert(
- $this->tbl_global_agenda,
- $attributes
- );
- }
- break;
- }
- return $id;
- }
- /**
- * @param int $eventId
- * @param int $courseId
- *
- * @return array
- */
- public function getRepeatedInfoByEvent($eventId, $courseId)
- {
- $repeatTable = Database::get_course_table(TABLE_AGENDA_REPEAT);
- $eventId = intval($eventId);
- $courseId = intval($courseId);
- $sql = "SELECT * FROM $repeatTable
- WHERE c_id = $courseId AND cal_id = $eventId";
- $res = Database::query($sql);
- $repeatInfo = array();
- if (Database::num_rows($res) > 0) {
- $repeatInfo = Database::fetch_array($res, 'ASSOC');
- }
- return $repeatInfo;
- }
- /**
- * @param int $eventId
- * @param string $type
- * @param string $end in local time
- * @param array $sentTo
- *
- * @return bool
- */
- public function addRepeatedItem($eventId, $type, $end, $sentTo = array())
- {
- $t_agenda = Database::get_course_table(TABLE_AGENDA);
- $t_agenda_r = Database::get_course_table(TABLE_AGENDA_REPEAT);
- if (empty($this->course)) {
- return false;
- }
- $course_id = $this->course['real_id'];
- $eventId = intval($eventId);
- $sql = "SELECT title, content, start_date, end_date, all_day
- FROM $t_agenda
- WHERE c_id = $course_id AND id = $eventId";
- $res = Database::query($sql);
- if (Database::num_rows($res) !== 1) {
- return false;
- }
- $row = Database::fetch_array($res);
- $origStartDate = api_strtotime($row['start_date'], 'UTC');
- $origEndDate = api_strtotime($row['end_date'], 'UTC');
- $diff = $origEndDate - $origStartDate;
- $title = $row['title'];
- $content = $row['content'];
- $allDay = $row['all_day'];
- $now = time();
- $type = Database::escape_string($type);
- $end = api_strtotime($end);
- if (1 <= $end && $end <= 500) {
- // We assume that, with this type of value, the user actually gives a count of repetitions
- //and that he wants us to calculate the end date with that (particularly in case of imports from ical)
- switch ($type) {
- case 'daily':
- $end = $origStartDate + (86400 * $end);
- break;
- case 'weekly':
- $end = $this->addWeek($origStartDate, $end);
- break;
- case 'monthlyByDate':
- $end = $this->addMonth($origStartDate, $end);
- break;
- case 'monthlyByDay':
- //TODO
- break;
- case 'monthlyByDayR':
- //TODO
- break;
- case 'yearly':
- $end = $this->addYear($origStartDate, $end);
- break;
- }
- }
- $typeList = array(
- 'daily',
- 'weekly',
- 'monthlyByDate',
- 'monthlyByDay',
- 'monthlyByDayR',
- 'yearly'
- );
- // The event has to repeat *in the future*. We don't allow repeated
- // events in the past
- if ($end > $now && in_array($type, $typeList)) {
- $sql = "INSERT INTO $t_agenda_r (c_id, cal_id, cal_type, cal_end)
- VALUES ($course_id, '$eventId', '$type', '$end')";
- Database::query($sql);
- switch ($type) {
- // @todo improve loop.
- case 'daily':
- for ($i = $origStartDate + 86400; $i <= $end; $i += 86400) {
- $start = date('Y-m-d H:i:s', $i);
- $repeatEnd = date('Y-m-d H:i:s', $i + $diff);
- $this->addEvent(
- $start,
- $repeatEnd,
- $allDay,
- $title,
- $content,
- $sentTo,
- false,
- $eventId
- );
- }
- break;
- case 'weekly':
- for ($i = $origStartDate + 604800; $i <= $end; $i += 604800) {
- $start = date('Y-m-d H:i:s', $i);
- $repeatEnd = date('Y-m-d H:i:s', $i + $diff);
- $this->addEvent(
- $start,
- $repeatEnd,
- $allDay,
- $title,
- $content,
- $sentTo,
- false,
- $eventId
- );
- }
- break;
- case 'monthlyByDate':
- $next_start = $this->addMonth($origStartDate);
- while ($next_start <= $end) {
- $start = date('Y-m-d H:i:s', $next_start);
- $repeatEnd = date('Y-m-d H:i:s', $next_start + $diff);
- $this->addEvent(
- $start,
- $repeatEnd,
- $allDay,
- $title,
- $content,
- $sentTo,
- false,
- $eventId
- );
- $next_start = $this->addMonth($next_start);
- }
- break;
- case 'monthlyByDay':
- //not yet implemented
- break;
- case 'monthlyByDayR':
- //not yet implemented
- break;
- case 'yearly':
- $next_start = $this->addYear($origStartDate);
- while ($next_start <= $end) {
- $start = date('Y-m-d H:i:s', $next_start);
- $repeatEnd = date('Y-m-d H:i:s', $next_start + $diff);
- $this->addEvent(
- $start,
- $repeatEnd,
- $allDay,
- $title,
- $content,
- $sentTo,
- false,
- $eventId
- );
- $next_start = $this->addYear($next_start);
- }
- break;
- }
- }
- return true;
- }
- /**
- * @param int $item_id
- * @param array $sentTo
- * @return int
- */
- public function storeAgendaEventAsAnnouncement($item_id, $sentTo = array())
- {
- $table_agenda = Database::get_course_table(TABLE_AGENDA);
- $course_id = api_get_course_int_id();
- // Check params
- if (empty($item_id) || $item_id != strval(intval($item_id))) {
- return -1;
- }
- // Get the agenda item.
- $item_id = intval($item_id);
- $sql = "SELECT * FROM $table_agenda
- WHERE c_id = $course_id AND id = ".$item_id;
- $res = Database::query($sql);
- if (Database::num_rows($res) > 0) {
- $row = Database::fetch_array($res, 'ASSOC');
- // Sending announcement
- if (!empty($sentTo)) {
- $id = AnnouncementManager::add_announcement(
- api_get_course_info(),
- api_get_session_id(),
- $row['title'],
- $row['content'],
- $sentTo,
- null,
- null,
- $row['end_date']
- );
- AnnouncementManager::sendEmail(
- api_get_course_info(),
- api_get_session_id(),
- $id
- );
- return $id;
- }
- }
- return -1;
- }
- /**
- * Edits an event
- *
- * @param int $id
- * @param string $start datetime format: 2012-06-14 09:00:00
- * @param string $end datetime format: 2012-06-14 09:00:00
- * @param int $allDay is all day 'true' or 'false'
- * @param string $title
- * @param string $content
- * @param array $usersToSend
- * @param array $attachmentArray
- * @param array $attachmentCommentList
- * @param string $comment
- * @param string $color
- * @param bool $addAnnouncement
- * @param bool $updateContent
- * @param int $authorId
- *
- * @return bool
- */
- public function editEvent(
- $id,
- $start,
- $end,
- $allDay,
- $title,
- $content,
- $usersToSend = array(),
- $attachmentArray = array(),
- $attachmentCommentList = array(),
- $comment = null,
- $color = '',
- $addAnnouncement = false,
- $updateContent = true,
- $authorId = 0
- ) {
- $start = api_get_utc_datetime($start);
- $end = api_get_utc_datetime($end);
- $allDay = isset($allDay) && $allDay == 'true' ? 1 : 0;
- $authorId = empty($authorId) ? api_get_user_id() : (int) $authorId;
- switch ($this->type) {
- case 'personal':
- $eventInfo = $this->get_event($id);
- if ($eventInfo['user'] != api_get_user_id()) {
- break;
- }
- $attributes = array(
- 'title' => $title,
- 'date' => $start,
- 'enddate' => $end,
- 'all_day' => $allDay,
- );
- if ($updateContent) {
- $attributes['text'] = $content;
- }
- if (!empty($color)) {
- $attributes['color'] = $color;
- }
- Database::update(
- $this->tbl_personal_agenda,
- $attributes,
- array('id = ?' => $id)
- );
- break;
- case 'course':
- $eventInfo = $this->get_event($id);
- if (empty($eventInfo)) {
- return false;
- }
- $groupId = api_get_group_id();
- $groupIid = 0;
- $groupInfo = [];
- if ($groupId) {
- $groupInfo = GroupManager::get_group_properties($groupId);
- if ($groupInfo) {
- $groupIid = $groupInfo['iid'];
- }
- }
- $course_id = $this->course['real_id'];
- if (empty($course_id)) {
- return false;
- }
- if ($this->getIsAllowedToEdit()) {
- $attributes = array(
- 'title' => $title,
- 'start_date' => $start,
- 'end_date' => $end,
- 'all_day' => $allDay,
- 'comment' => $comment
- );
- if ($updateContent) {
- $attributes['content'] = $content;
- }
- if (!empty($color)) {
- $attributes['color'] = $color;
- }
- Database::update(
- $this->tbl_course_agenda,
- $attributes,
- array(
- 'id = ? AND c_id = ? AND session_id = ? ' => array(
- $id,
- $course_id,
- $this->sessionId
- )
- )
- );
- if (!empty($usersToSend)) {
- $sendTo = $this->parseSendToArray($usersToSend);
- $usersToDelete = array_diff(
- $eventInfo['send_to']['users'],
- $sendTo['users']
- );
- $usersToAdd = array_diff(
- $sendTo['users'],
- $eventInfo['send_to']['users']
- );
- $groupsToDelete = array_diff(
- $eventInfo['send_to']['groups'],
- $sendTo['groups']
- );
- $groupToAdd = array_diff(
- $sendTo['groups'],
- $eventInfo['send_to']['groups']
- );
- if ($sendTo['everyone']) {
- // Delete all from group
- if (isset($eventInfo['send_to']['groups']) &&
- !empty($eventInfo['send_to']['groups'])
- ) {
- foreach ($eventInfo['send_to']['groups'] as $group) {
- $groupIidItem = 0;
- if ($group) {
- $groupInfoItem = GroupManager::get_group_properties(
- $group
- );
- if ($groupInfoItem) {
- $groupIidItem = $groupInfoItem['iid'];
- }
- }
- api_item_property_delete(
- $this->course,
- TOOL_CALENDAR_EVENT,
- $id,
- 0,
- $groupIidItem,
- $this->sessionId
- );
- }
- }
- // Storing the selected users.
- if (isset($eventInfo['send_to']['users']) &&
- !empty($eventInfo['send_to']['users'])
- ) {
- foreach ($eventInfo['send_to']['users'] as $userId) {
- api_item_property_delete(
- $this->course,
- TOOL_CALENDAR_EVENT,
- $id,
- $userId,
- $groupIid,
- $this->sessionId
- );
- }
- }
- // Add to everyone only.
- api_item_property_update(
- $this->course,
- TOOL_CALENDAR_EVENT,
- $id,
- 'visible',
- $authorId,
- $groupInfo,
- null,
- $start,
- $end,
- $this->sessionId
- );
- } else {
- // Delete "everyone".
- api_item_property_delete(
- $this->course,
- TOOL_CALENDAR_EVENT,
- $id,
- 0,
- 0,
- $this->sessionId
- );
- // Add groups
- if (!empty($groupToAdd)) {
- foreach ($groupToAdd as $group) {
- $groupInfoItem = [];
- if ($group) {
- $groupInfoItem = GroupManager::get_group_properties(
- $group
- );
- }
- api_item_property_update(
- $this->course,
- TOOL_CALENDAR_EVENT,
- $id,
- 'visible',
- $authorId,
- $groupInfoItem,
- 0,
- $start,
- $end,
- $this->sessionId
- );
- }
- }
- // Delete groups.
- if (!empty($groupsToDelete)) {
- foreach ($groupsToDelete as $group) {
- $groupIidItem = 0;
- $groupInfoItem = [];
- if ($group) {
- $groupInfoItem = GroupManager::get_group_properties(
- $group
- );
- if ($groupInfoItem) {
- $groupIidItem = $groupInfoItem['iid'];
- }
- }
- api_item_property_delete(
- $this->course,
- TOOL_CALENDAR_EVENT,
- $id,
- 0,
- $groupIidItem,
- $this->sessionId
- );
- }
- }
- // Add users.
- if (!empty($usersToAdd)) {
- foreach ($usersToAdd as $userId) {
- api_item_property_update(
- $this->course,
- TOOL_CALENDAR_EVENT,
- $id,
- 'visible',
- $authorId,
- $groupInfo,
- $userId,
- $start,
- $end,
- $this->sessionId
- );
- }
- }
- // Delete users.
- if (!empty($usersToDelete)) {
- foreach ($usersToDelete as $userId) {
- api_item_property_delete(
- $this->course,
- TOOL_CALENDAR_EVENT,
- $id,
- $userId,
- $groupInfo,
- $this->sessionId
- );
- }
- }
- }
- }
- // Add announcement.
- if (isset($addAnnouncement) && !empty($addAnnouncement)) {
- $this->storeAgendaEventAsAnnouncement(
- $id,
- $usersToSend
- );
- }
- // Add attachment.
- if (isset($attachmentArray) && !empty($attachmentArray)) {
- $counter = 0;
- foreach ($attachmentArray as $attachmentItem) {
- $this->updateAttachment(
- $attachmentItem['id'],
- $id,
- $attachmentItem,
- $attachmentCommentList[$counter],
- $this->course
- );
- $counter++;
- }
- }
- return true;
- } else {
- return false;
- }
- break;
- case 'admin':
- case 'platform':
- if (api_is_platform_admin()) {
- $attributes = array(
- 'title' => $title,
- 'start_date' => $start,
- 'end_date' => $end,
- 'all_day' => $allDay
- );
- if ($updateContent) {
- $attributes['content'] = $content;
- }
- Database::update(
- $this->tbl_global_agenda,
- $attributes,
- array('id = ?' => $id)
- );
- }
- break;
- }
- }
- /**
- * @param int $id
- * @param bool $deleteAllItemsFromSerie
- */
- public function deleteEvent($id, $deleteAllItemsFromSerie = false)
- {
- switch ($this->type) {
- case 'personal':
- $eventInfo = $this->get_event($id);
- if ($eventInfo['user'] == api_get_user_id()) {
- Database::delete(
- $this->tbl_personal_agenda,
- array('id = ?' => $id)
- );
- }
- break;
- case 'course':
- $course_id = api_get_course_int_id();
- if (!empty($course_id) && api_is_allowed_to_edit(null, true)) {
- // Delete
- $eventInfo = $this->get_event($id);
- if ($deleteAllItemsFromSerie) {
- /* This is one of the children.
- Getting siblings and delete 'Em all + the father! */
- if (isset($eventInfo['parent_event_id']) && !empty($eventInfo['parent_event_id'])) {
- // Removing items.
- $events = $this->getAllRepeatEvents(
- $eventInfo['parent_event_id']
- );
- if (!empty($events)) {
- foreach ($events as $event) {
- $this->deleteEvent($event['id']);
- }
- }
- // Removing parent.
- $this->deleteEvent($eventInfo['parent_event_id']);
- } else {
- // This is the father looking for the children.
- $events = $this->getAllRepeatEvents($id);
- if (!empty($events)) {
- foreach ($events as $event) {
- $this->deleteEvent($event['id']);
- }
- }
- }
- }
- // Removing from events.
- Database::delete(
- $this->tbl_course_agenda,
- array('id = ? AND c_id = ?' => array($id, $course_id))
- );
- api_item_property_update(
- $this->course,
- TOOL_CALENDAR_EVENT,
- $id,
- 'delete',
- api_get_user_id()
- );
- // Removing from series.
- Database::delete(
- $this->table_repeat,
- array(
- 'cal_id = ? AND c_id = ?' => array(
- $id,
- $course_id
- )
- )
- );
- if (isset($eventInfo['attachment']) && !empty($eventInfo['attachment'])) {
- foreach ($eventInfo['attachment'] as $attachment) {
- self::deleteAttachmentFile(
- $attachment['id'],
- $this->course
- );
- }
- }
- }
- break;
- case 'admin':
- if (api_is_platform_admin()) {
- Database::delete(
- $this->tbl_global_agenda,
- array('id = ?' => $id)
- );
- }
- break;
- }
- }
- /**
- * Get agenda events
- * @param int $start
- * @param int $end
- * @param int $course_id
- * @param int $groupId
- * @param int $user_id
- * @param string $format
- *
- * @return array|string
- */
- public function getEvents(
- $start,
- $end,
- $course_id = null,
- $groupId = null,
- $user_id = 0,
- $format = 'json'
- ) {
- switch ($this->type) {
- case 'admin':
- $this->getPlatformEvents($start, $end);
- break;
- case 'course':
- $courseInfo = api_get_course_info_by_id($course_id);
- // Session coach can see all events inside a session.
- if (api_is_coach()) {
- // Own course
- $this->getCourseEvents(
- $start,
- $end,
- $courseInfo,
- $groupId,
- $this->sessionId,
- $user_id
- );
- // Others
- $this->getSessionEvents(
- $start,
- $end,
- $this->sessionId,
- $user_id,
- $this->eventOtherSessionColor
- );
- } else {
- $this->getCourseEvents(
- $start,
- $end,
- $courseInfo,
- $groupId,
- $this->sessionId,
- $user_id
- );
- }
- break;
- case 'personal':
- default:
- $sessionFilterActive = false;
- if (!empty($this->sessionId)) {
- $sessionFilterActive = true;
- }
- if ($sessionFilterActive == false) {
- // Getting personal events
- $this->getPersonalEvents($start, $end);
- // Getting platform/admin events
- $this->getPlatformEvents($start, $end);
- }
- $ignoreVisibility = api_get_configuration_value('personal_agenda_show_all_session_events');
- // Getting course events
- $my_course_list = array();
- if (!api_is_anonymous()) {
- $session_list = SessionManager::get_sessions_by_user(
- api_get_user_id(),
- $ignoreVisibility
- );
- $my_course_list = CourseManager::get_courses_list_by_user_id(
- api_get_user_id(),
- false
- );
- }
- if (api_is_drh()) {
- if (api_drh_can_access_all_session_content()) {
- $session_list = array();
- $sessionList = SessionManager::get_sessions_followed_by_drh(
- api_get_user_id(),
- null,
- null,
- null,
- true,
- false
- );
- if (!empty($sessionList)) {
- foreach ($sessionList as $sessionItem) {
- $sessionId = $sessionItem['id'];
- $courses = SessionManager::get_course_list_by_session_id(
- $sessionId
- );
- $sessionInfo = array(
- 'session_id' => $sessionId,
- 'courses' => $courses
- );
- $session_list[] = $sessionInfo;
- }
- }
- }
- }
- if (!empty($session_list)) {
- foreach ($session_list as $session_item) {
- if ($sessionFilterActive) {
- if ($this->sessionId != $session_item['session_id']) {
- continue;
- }
- }
- $my_courses = $session_item['courses'];
- $my_session_id = $session_item['session_id'];
- if (!empty($my_courses)) {
- foreach ($my_courses as $course_item) {
- $courseInfo = api_get_course_info_by_id(
- $course_item['real_id']
- );
- $this->getCourseEvents(
- $start,
- $end,
- $courseInfo,
- 0,
- $my_session_id
- );
- }
- }
- }
- }
- if (!empty($my_course_list) && $sessionFilterActive == false) {
- foreach ($my_course_list as $courseInfoItem) {
- $courseInfo = api_get_course_info_by_id(
- $courseInfoItem['real_id']
- );
- if (isset($course_id) && !empty($course_id)) {
- if ($courseInfo['real_id'] == $course_id) {
- $this->getCourseEvents(
- $start,
- $end,
- $courseInfo
- );
- }
- } else {
- $this->getCourseEvents(
- $start,
- $end,
- $courseInfo
- );
- }
- }
- }
- break;
- }
- switch ($format) {
- case 'json':
- if (empty($this->events)) {
- return '';
- }
- return json_encode($this->events);
- break;
- case 'array':
- if (empty($this->events)) {
- return [];
- }
- return $this->events;
- break;
- }
- }
- /**
- * @param int $id
- * @param int $minute_delta
- * @return int
- */
- public function resizeEvent($id, $minute_delta)
- {
- $id = (int) $id;
- $delta = intval($minute_delta);
- $event = $this->get_event($id);
- if (!empty($event)) {
- switch ($this->type) {
- case 'personal':
- $sql = "UPDATE $this->tbl_personal_agenda SET
- enddate = DATE_ADD(enddate, INTERVAL $delta MINUTE)
- WHERE id = ".$id;
- Database::query($sql);
- break;
- case 'course':
- $sql = "UPDATE $this->tbl_course_agenda SET
- end_date = DATE_ADD(end_date, INTERVAL $delta MINUTE)
- WHERE
- c_id = ".$this->course['real_id']." AND
- id = ".$id;
- Database::query($sql);
- break;
- case 'admin':
- $sql = "UPDATE $this->tbl_global_agenda SET
- end_date = DATE_ADD(end_date, INTERVAL $delta MINUTE)
- WHERE id = ".$id;
- Database::query($sql);
- break;
- }
- }
- return 1;
- }
- /**
- * @param int $id
- * @param int $minute_delta minutes
- * @param int $allDay
- * @return int
- */
- public function move_event($id, $minute_delta, $allDay)
- {
- $id = (int) $id;
- $event = $this->get_event($id);
- if (empty($event)) {
- return false;
- }
- // we convert the hour delta into minutes and add the minute delta
- $delta = intval($minute_delta);
- $allDay = intval($allDay);
- if (!empty($event)) {
- switch ($this->type) {
- case 'personal':
- $sql = "UPDATE $this->tbl_personal_agenda SET
- all_day = $allDay, date = DATE_ADD(date, INTERVAL $delta MINUTE),
- enddate = DATE_ADD(enddate, INTERVAL $delta MINUTE)
- WHERE id=".$id;
- Database::query($sql);
- break;
- case 'course':
- $sql = "UPDATE $this->tbl_course_agenda SET
- all_day = $allDay,
- start_date = DATE_ADD(start_date, INTERVAL $delta MINUTE),
- end_date = DATE_ADD(end_date, INTERVAL $delta MINUTE)
- WHERE
- c_id = ".$this->course['real_id']." AND
- id=".$id;
- Database::query($sql);
- break;
- case 'admin':
- $sql = "UPDATE $this->tbl_global_agenda SET
- all_day = $allDay,
- start_date = DATE_ADD(start_date,INTERVAL $delta MINUTE),
- end_date = DATE_ADD(end_date, INTERVAL $delta MINUTE)
- WHERE id=".$id;
- Database::query($sql);
- break;
- }
- }
- return 1;
- }
- /**
- * Gets a single event
- *
- * @param int $id event id
- * @return array
- */
- public function get_event($id)
- {
- // make sure events of the personal agenda can only be seen by the user himself
- $id = intval($id);
- $event = null;
- switch ($this->type) {
- case 'personal':
- $sql = "SELECT * FROM ".$this->tbl_personal_agenda."
- WHERE id = $id AND user = ".api_get_user_id();
- $result = Database::query($sql);
- if (Database::num_rows($result)) {
- $event = Database::fetch_array($result, 'ASSOC');
- $event['description'] = $event['text'];
- $event['content'] = $event['text'];
- $event['start_date'] = $event['date'];
- $event['end_date'] = $event['enddate'];
- }
- break;
- case 'course':
- if (!empty($this->course['real_id'])) {
- $sql = "SELECT * FROM ".$this->tbl_course_agenda."
- WHERE c_id = ".$this->course['real_id']." AND id = ".$id;
- $result = Database::query($sql);
- if (Database::num_rows($result)) {
- $event = Database::fetch_array($result, 'ASSOC');
- $event['description'] = $event['content'];
- // Getting send to array
- $event['send_to'] = $this->getUsersAndGroupSubscribedToEvent(
- $id,
- $this->course['real_id'],
- $this->sessionId
- );
- // Getting repeat info
- $event['repeat_info'] = $this->getRepeatedInfoByEvent(
- $id,
- $this->course['real_id']
- );
- if (!empty($event['parent_event_id'])) {
- $event['parent_info'] = $this->get_event(
- $event['parent_event_id']
- );
- }
- $event['attachment'] = $this->getAttachmentList(
- $id,
- $this->course
- );
- }
- }
- break;
- case 'admin':
- case 'platform':
- $sql = "SELECT * FROM ".$this->tbl_global_agenda."
- WHERE id = $id";
- $result = Database::query($sql);
- if (Database::num_rows($result)) {
- $event = Database::fetch_array($result, 'ASSOC');
- $event['description'] = $event['content'];
- }
- break;
- }
- return $event;
- }
- /**
- * Gets personal events
- * @param int $start
- * @param int $end
- * @return array
- */
- public function getPersonalEvents($start, $end)
- {
- $start = intval($start);
- $end = intval($end);
- $startCondition = '';
- $endCondition = '';
- if ($start !== 0) {
- $start = api_get_utc_datetime($start);
- $startCondition = "AND date >= '".$start."'";
- }
- if ($start !== 0) {
- $end = api_get_utc_datetime($end);
- $endCondition = "AND (enddate <= '".$end."' OR enddate IS NULL)";
- }
- $user_id = api_get_user_id();
- $sql = "SELECT * FROM ".$this->tbl_personal_agenda."
- WHERE user = $user_id $startCondition $endCondition";
- $result = Database::query($sql);
- $my_events = array();
- if (Database::num_rows($result)) {
- while ($row = Database::fetch_array($result, 'ASSOC')) {
- $event = array();
- $event['id'] = 'personal_'.$row['id'];
- $event['title'] = $row['title'];
- $event['className'] = 'personal';
- $event['borderColor'] = $event['backgroundColor'] = $this->event_personal_color;
- $event['editable'] = true;
- $event['sent_to'] = get_lang('Me');
- $event['type'] = 'personal';
- if (!empty($row['date'])) {
- $event['start'] = $this->formatEventDate($row['date']);
- $event['start_date_localtime'] = api_get_local_time(
- $row['date']
- );
- }
- if (!empty($row['enddate'])) {
- $event['end'] = $this->formatEventDate($row['enddate']);
- $event['end_date_localtime'] = api_get_local_time(
- $row['enddate']
- );
- }
- $event['description'] = $row['text'];
- $event['allDay'] = isset($row['all_day']) && $row['all_day'] == 1 ? $row['all_day'] : 0;
- $event['parent_event_id'] = 0;
- $event['has_children'] = 0;
- $my_events[] = $event;
- $this->events[] = $event;
- }
- }
- return $my_events;
- }
- /**
- * Get user/group list per event.
- *
- * @param int $eventId
- * @param int $courseId
- * @param integer $sessionId
- * @paraù int $sessionId
- *
- * @return array
- */
- public function getUsersAndGroupSubscribedToEvent(
- $eventId,
- $courseId,
- $sessionId
- ) {
- $eventId = intval($eventId);
- $courseId = intval($courseId);
- $sessionId = intval($sessionId);
- $sessionCondition = "ip.session_id = $sessionId";
- if (empty($sessionId)) {
- $sessionCondition = " (ip.session_id = 0 OR ip.session_id IS NULL) ";
- }
- $tlb_course_agenda = Database::get_course_table(TABLE_AGENDA);
- $tbl_property = Database::get_course_table(TABLE_ITEM_PROPERTY);
- // Get sent_tos
- $sql = "SELECT DISTINCT to_user_id, to_group_id
- FROM $tbl_property ip
- INNER JOIN $tlb_course_agenda agenda
- ON (
- ip.ref = agenda.id AND
- ip.c_id = agenda.c_id AND
- ip.tool = '".TOOL_CALENDAR_EVENT."'
- )
- WHERE
- ref = $eventId AND
- ip.visibility = '1' AND
- ip.c_id = $courseId AND
- $sessionCondition
- ";
- $result = Database::query($sql);
- $users = array();
- $groups = array();
- $everyone = false;
- while ($row = Database::fetch_array($result, 'ASSOC')) {
- if (!empty($row['to_group_id'])) {
- $groups[] = $row['to_group_id'];
- }
- if (!empty($row['to_user_id'])) {
- $users[] = $row['to_user_id'];
- }
- if (empty($groups) && empty($users)) {
- if ($row['to_group_id'] == 0) {
- $everyone = true;
- }
- }
- }
- return array(
- 'everyone' => $everyone,
- 'users' => $users,
- 'groups' => $groups
- );
- }
- /**
- * @param int $start
- * @param int $end
- * @param int $sessionId
- * @param int $userId
- * @param string $color
- *
- * @return array
- */
- public function getSessionEvents(
- $start,
- $end,
- $sessionId = 0,
- $userId = 0,
- $color = ''
- ) {
- $courses = SessionManager::get_course_list_by_session_id($sessionId);
- if (!empty($courses)) {
- foreach ($courses as $course) {
- $this->getCourseEvents(
- $start,
- $end,
- $course,
- 0,
- $sessionId,
- 0,
- $color
- );
- }
- }
- }
- /**
- * @param int $start
- * @param int $end
- * @param array $courseInfo
- * @param int $groupId
- * @param int $session_id
- * @param int $user_id
- * @param string $color
- *
- * @return array
- */
- public function getCourseEvents(
- $start,
- $end,
- $courseInfo,
- $groupId = 0,
- $session_id = 0,
- $user_id = 0,
- $color = ''
- ) {
- $start = isset($start) && !empty($start) ? api_get_utc_datetime(intval($start)) : null;
- $end = isset($end) && !empty($end) ? api_get_utc_datetime(intval($end)) : null;
- if (empty($courseInfo)) {
- return array();
- }
- $course_id = $courseInfo['real_id'];
- if (empty($course_id)) {
- return array();
- }
- $session_id = intval($session_id);
- $user_id = intval($user_id);
- $groupList = GroupManager::get_group_list(null, $courseInfo['code']);
- $group_name_list = array();
- if (!empty($groupList)) {
- foreach ($groupList as $group) {
- $group_name_list[$group['id']] = $group['name'];
- }
- }
- $group_memberships = [];
- if (!empty($groupId)) {
- $group_memberships = array($groupId);
- } else {
- if (api_is_allowed_to_edit()) {
- // Getting all groups
- $groupList = GroupManager::get_group_list(null, $courseInfo['code']);
- if (!empty($groupList)) {
- $group_memberships = array_column($groupList, 'id');
- }
- } else {
- // get only related groups from user
- $group_memberships = GroupManager::get_group_ids(
- $course_id,
- $user_id
- );
- }
- }
- $tlb_course_agenda = Database::get_course_table(TABLE_AGENDA);
- $tbl_property = Database::get_course_table(TABLE_ITEM_PROPERTY);
- if (!empty($groupId)) {
- if (empty($user_id)) {
- $where_condition = "( ip.to_group_id IN (0, ".implode(", ", $group_memberships).") ) ";
- } else {
- $where_condition = "( ip.to_user_id = $user_id OR ip.to_user_id IS NULL OR (ip.to_group_id IN (0, ".implode(", ", $group_memberships).")) ) ";
- }
- if (empty($session_id)) {
- $sessionCondition = "
- (
- agenda.session_id = 0 AND (ip.session_id IS NULL OR ip.session_id = 0)
- ) ";
- } else {
- $sessionCondition = "
- (
- agenda.session_id = $session_id AND
- ip.session_id = $session_id
- ) ";
- }
- $sql = "SELECT DISTINCT
- agenda.*,
- ip.visibility,
- ip.to_group_id,
- ip.insert_user_id,
- ip.ref,
- to_user_id
- FROM $tlb_course_agenda agenda
- INNER JOIN $tbl_property ip
- ON (
- agenda.id = ip.ref AND
- agenda.c_id = ip.c_id AND
- ip.tool = '".TOOL_CALENDAR_EVENT."'
- )
- WHERE
- $where_condition AND
- ip.visibility = '1' AND
- agenda.c_id = $course_id AND
- $sessionCondition
- ";
- } else {
- $visibilityCondition = " ip.visibility='1' AND ";
- if (api_is_allowed_to_edit()) {
- if (empty($user_id)) {
- $where_condition = '';
- } else {
- $where_condition = " (ip.to_user_id = ".$user_id.") AND (ip.to_group_id IS NULL OR ip.to_group_id = 0) AND ";
- }
- $visibilityCondition = " (ip.visibility IN ('1', '0')) AND ";
- } else {
- // Show my items and also items sent to everyone
- $where_condition = " ( (ip.to_user_id = ".api_get_user_id()." OR (ip.to_user_id = 0 or ip.to_user_id is NULL)) AND (ip.to_group_id IS NULL OR ip.to_group_id = 0)) AND ";
- }
- if (empty($session_id)) {
- $sessionCondition = "
- (
- agenda.session_id = 0 AND
- (ip.session_id IS NULL OR ip.session_id = 0)
- ) ";
- } else {
- $sessionCondition = "
- (
- agenda.session_id = $session_id AND
- ip.session_id = $session_id
- ) ";
- }
- $sql = "SELECT DISTINCT
- agenda.*,
- ip.visibility,
- ip.to_group_id,
- ip.insert_user_id,
- ip.ref,
- to_user_id
- FROM $tlb_course_agenda agenda
- INNER JOIN $tbl_property ip
- ON (agenda.id = ip.ref AND agenda.c_id = ip.c_id AND ip.tool='".TOOL_CALENDAR_EVENT."' )
- WHERE
- $where_condition
- $visibilityCondition
- agenda.c_id = $course_id AND
- $sessionCondition
- ";
- }
- $dateCondition = null;
- if (!empty($start) && !empty($end)) {
- $dateCondition .= "AND (
- agenda.start_date BETWEEN '".$start."' AND '".$end."' OR
- agenda.end_date BETWEEN '".$start."' AND '".$end."' OR
- (
- agenda.start_date IS NOT NULL AND agenda.end_date IS NOT NULL AND
- YEAR(agenda.start_date) = YEAR(agenda.end_date) AND
- MONTH('$start') BETWEEN MONTH(agenda.start_date) AND MONTH(agenda.end_date)
- )
- )";
- }
- $sql .= $dateCondition;
- $result = Database::query($sql);
- $coachCanEdit = false;
- if (!empty($session_id)) {
- $coachCanEdit = api_is_coach($session_id, $course_id) || api_is_platform_admin();
- }
- if (Database::num_rows($result)) {
- $eventsAdded = array_column($this->events, 'unique_id');
- while ($row = Database::fetch_array($result, 'ASSOC')) {
- $event = array();
- $event['id'] = 'course_'.$row['id'];
- $event['unique_id'] = $row['iid'];
- // To avoid doubles
- if (in_array($event['unique_id'], $eventsAdded)) {
- continue;
- }
- $eventsAdded[] = $event['unique_id'];
- $eventId = $row['ref'];
- $items = $this->getUsersAndGroupSubscribedToEvent(
- $eventId,
- $course_id,
- $this->sessionId
- );
- $group_to_array = $items['groups'];
- $user_to_array = $items['users'];
- $attachmentList = $this->getAttachmentList(
- $row['id'],
- $courseInfo
- );
- $event['attachment'] = '';
- if (!empty($attachmentList)) {
- foreach ($attachmentList as $attachment) {
- $has_attachment = Display::return_icon(
- 'attachment.gif',
- get_lang('Attachment')
- );
- $user_filename = $attachment['filename'];
- $url = api_get_path(WEB_CODE_PATH).'calendar/download.php?file='.$attachment['path'].'&course_id='.$course_id.'&'.api_get_cidreq();
- $event['attachment'] .= $has_attachment.
- Display::url(
- $user_filename,
- $url
- ).'<br />';
- }
- }
- $event['title'] = $row['title'];
- $event['className'] = 'course';
- $event['allDay'] = 'false';
- $event['course_id'] = $course_id;
- $event['borderColor'] = $event['backgroundColor'] = $this->event_course_color;
- $sessionInfo = [];
- if (isset($row['session_id']) && !empty($row['session_id'])) {
- $sessionInfo = api_get_session_info($session_id);
- $event['borderColor'] = $event['backgroundColor'] = $this->event_session_color;
- }
- $event['session_name'] = isset($sessionInfo['name']) ? $sessionInfo['name'] : '';
- $event['course_name'] = isset($courseInfo['title']) ? $courseInfo['title'] : '';
- if (isset($row['to_group_id']) && !empty($row['to_group_id'])) {
- $event['borderColor'] = $event['backgroundColor'] = $this->event_group_color;
- }
- if (!empty($color)) {
- $event['borderColor'] = $event['backgroundColor'] = $color;
- }
- if (isset($row['color']) && !empty($row['color'])) {
- $event['borderColor'] = $event['backgroundColor'] = $row['color'];
- }
- $event['editable'] = false;
- if ($this->getIsAllowedToEdit() && $this->type == 'course') {
- $event['editable'] = true;
- if (!empty($session_id)) {
- if ($coachCanEdit == false) {
- $event['editable'] = false;
- }
- }
- }
- if (!empty($row['start_date'])) {
- $event['start'] = $this->formatEventDate(
- $row['start_date']
- );
- $event['start_date_localtime'] = api_get_local_time(
- $row['start_date']
- );
- }
- if (!empty($row['end_date'])) {
- $event['end'] = $this->formatEventDate($row['end_date']);
- $event['end_date_localtime'] = api_get_local_time(
- $row['end_date']
- );
- }
- $event['sent_to'] = '';
- $event['type'] = 'course';
- if ($row['session_id'] != 0) {
- $event['type'] = 'session';
- }
- // Event Sent to a group?
- if (isset($row['to_group_id']) && !empty($row['to_group_id'])) {
- $sent_to = array();
- if (!empty($group_to_array)) {
- foreach ($group_to_array as $group_item) {
- $sent_to[] = $group_name_list[$group_item];
- }
- }
- $sent_to = implode('@@', $sent_to);
- $sent_to = str_replace(
- '@@',
- '</div><div class="label_tag notice">',
- $sent_to
- );
- $event['sent_to'] = '<div class="label_tag notice">'.$sent_to.'</div>';
- $event['type'] = 'group';
- }
- // Event sent to a user?
- if (isset($row['to_user_id'])) {
- $sent_to = array();
- if (!empty($user_to_array)) {
- foreach ($user_to_array as $item) {
- $user_info = api_get_user_info($item);
- // Add username as tooltip for $event['sent_to'] - ref #4226
- $username = api_htmlentities(
- sprintf(
- get_lang('LoginX'),
- $user_info['username']
- ),
- ENT_QUOTES
- );
- $sent_to[] = "<span title='".$username."'>".$user_info['complete_name']."</span>";
- }
- }
- $sent_to = implode('@@', $sent_to);
- $sent_to = str_replace(
- '@@',
- '</div><div class="label_tag notice">',
- $sent_to
- );
- $event['sent_to'] = '<div class="label_tag notice">'.$sent_to.'</div>';
- }
- //Event sent to everyone!
- if (empty($event['sent_to'])) {
- $event['sent_to'] = '<div class="label_tag notice">'.get_lang(
- 'Everyone'
- ).'</div>';
- }
- $event['description'] = $row['content'];
- $event['visibility'] = $row['visibility'];
- $event['real_id'] = $row['id'];
- $event['allDay'] = isset($row['all_day']) && $row['all_day'] == 1 ? $row['all_day'] : 0;
- $event['parent_event_id'] = $row['parent_event_id'];
- $event['has_children'] = $this->hasChildren(
- $row['id'],
- $course_id
- ) ? 1 : 0;
- $event['comment'] = $row['comment'];
- $this->events[] = $event;
- }
- }
- return $this->events;
- }
- /**
- * @param int $start tms
- * @param int $end tms
- * @return array
- */
- public function getPlatformEvents($start, $end)
- {
- $start = isset($start) && !empty($start) ? api_get_utc_datetime(
- intval($start)
- ) : null;
- $end = isset($end) && !empty($end) ? api_get_utc_datetime(
- intval($end)
- ) : null;
- $dateCondition = '';
- if (!empty($start) && !empty($end)) {
- $dateCondition .= "AND (
- start_date BETWEEN '".$start."' AND '".$end."' OR
- end_date BETWEEN '".$start."' AND '".$end."' OR
- (
- start_date IS NOT NULL AND end_date IS NOT NULL AND
- YEAR(start_date) = YEAR(end_date) AND
- MONTH('$start') BETWEEN MONTH(start_date) AND MONTH(end_date)
- )
- )";
- }
- $access_url_id = api_get_current_access_url_id();
- $sql = "SELECT *
- FROM ".$this->tbl_global_agenda."
- WHERE access_url_id = $access_url_id
- $dateCondition";
- $result = Database::query($sql);
- $my_events = array();
- if (Database::num_rows($result)) {
- while ($row = Database::fetch_array($result, 'ASSOC')) {
- $event = array();
- $event['id'] = 'platform_'.$row['id'];
- $event['title'] = $row['title'];
- $event['className'] = 'platform';
- $event['allDay'] = 'false';
- $event['borderColor'] = $event['backgroundColor'] = $this->event_platform_color;
- $event['editable'] = false;
- $event['type'] = 'admin';
- if (api_is_platform_admin() && $this->type == 'admin') {
- $event['editable'] = true;
- }
- if (!empty($row['start_date'])) {
- $event['start'] = $this->formatEventDate(
- $row['start_date']
- );
- $event['start_date_localtime'] = api_get_local_time(
- $row['start_date']
- );
- }
- if (!empty($row['end_date'])) {
- $event['end'] = $this->formatEventDate($row['end_date']);
- $event['end_date_localtime'] = api_get_local_time(
- $row['end_date']
- );
- }
- $event['description'] = $row['content'];
- $event['allDay'] = isset($row['all_day']) && $row['all_day'] == 1 ? $row['all_day'] : 0;
- $event['parent_event_id'] = 0;
- $event['has_children'] = 0;
- $my_events[] = $event;
- $this->events[] = $event;
- }
- }
- return $my_events;
- }
- /**
- * Format needed for the Fullcalendar js lib
- *
- * @param string $utcTime
- * @return bool|string
- */
- private function formatEventDate($utcTime)
- {
- $utcTimeZone = new DateTimeZone('UTC');
- $platformTimeZone = new DateTimeZone(api_get_timezone());
- $eventDate = new DateTime($utcTime, $utcTimeZone);
- $eventDate->setTimezone($platformTimeZone);
- return $eventDate->format(DateTime::ISO8601);
- }
- /**
- * @param FormValidator $form
- * @param array $groupList
- * @param array $userList
- * @param array $sendTo array('users' => [1, 2], 'groups' => [3, 4])
- * @param array $attributes
- * @param bool $addOnlyItemsInSendTo
- * @param bool $required
- */
- public function setSendToSelect(
- $form,
- $groupList = [],
- $userList = [],
- $sendTo = [],
- $attributes = [],
- $addOnlyItemsInSendTo = false,
- $required = false
- ) {
- $params = array(
- 'id' => 'users_to_send_id',
- 'data-placeholder' => get_lang('Select'),
- 'multiple' => 'multiple',
- 'class' => 'multiple-select'
- );
- if (!empty($attributes)) {
- $params = array_merge($params, $attributes);
- if (empty($params['multiple'])) {
- unset($params['multiple']);
- }
- }
- $sendToGroups = isset($sendTo['groups']) ? $sendTo['groups'] : array();
- $sendToUsers = isset($sendTo['users']) ? $sendTo['users'] : array();
- /** @var HTML_QuickForm_select $select */
- $select = $form->addSelect(
- 'users_to_send',
- get_lang('To'),
- null,
- $params
- );
- if ($required) {
- $form->setRequired($select);
- }
- $selectedEveryoneOptions = array();
- if (isset($sendTo['everyone']) && $sendTo['everyone']) {
- $selectedEveryoneOptions = array('selected');
- $sendToUsers = array();
- }
- $select->addOption(
- get_lang('Everyone'),
- 'everyone',
- $selectedEveryoneOptions
- );
- $options = array();
- if (is_array($groupList)) {
- foreach ($groupList as $group) {
- $count_users = isset($group['count_users']) ? $group['count_users'] : $group['userNb'];
- $count_users = " – $count_users ".get_lang('Users');
- $option = array(
- 'text' => $group['name'].$count_users,
- 'value' => "GROUP:".$group['id']
- );
- $selected = in_array(
- $group['id'],
- $sendToGroups
- ) ? true : false;
- if ($selected) {
- $option['selected'] = 'selected';
- }
- if ($addOnlyItemsInSendTo) {
- if ($selected) {
- $options[] = $option;
- }
- } else {
- $options[] = $option;
- }
- }
- $select->addOptGroup($options, get_lang('Groups'));
- }
- // adding the individual users to the select form
- if (is_array($userList)) {
- $options = array();
- foreach ($userList as $user) {
- if ($user['status'] == ANONYMOUS) {
- continue;
- }
- $option = array(
- 'text' => api_get_person_name(
- $user['firstname'],
- $user['lastname']
- ).' ('.$user['username'].')',
- 'value' => "USER:".$user['user_id']
- );
- $selected = in_array(
- $user['user_id'],
- $sendToUsers
- ) ? true : false;
- if ($selected) {
- $option['selected'] = 'selected';
- }
- if ($addOnlyItemsInSendTo) {
- if ($selected) {
- $options[] = $option;
- }
- } else {
- $options[] = $option;
- }
- }
- $select->addOptGroup($options, get_lang('Users'));
- }
- }
- /**
- * Separates the users and groups array
- * users have a value USER:XXX (with XXX the user id
- * groups have a value GROUP:YYY (with YYY the group id)
- * use the 'everyone' key
- * @author Julio Montoya based in separate_users_groups in agenda.inc.php
- * @param array $to
- * @return array
- */
- public function parseSendToArray($to)
- {
- $groupList = array();
- $userList = array();
- $sendTo = null;
- $sendTo['everyone'] = false;
- if (is_array($to) && count($to) > 0) {
- foreach ($to as $item) {
- if ($item == 'everyone') {
- $sendTo['everyone'] = true;
- } else {
- list($type, $id) = explode(':', $item);
- switch ($type) {
- case 'GROUP':
- $groupList[] = $id;
- break;
- case 'USER':
- $userList[] = $id;
- break;
- }
- }
- }
- $sendTo['groups'] = $groupList;
- $sendTo['users'] = $userList;
- }
- return $sendTo;
- }
- /**
- * @param array $params
- * @return FormValidator
- */
- public function getForm($params = [])
- {
- $action = isset($params['action']) ? Security::remove_XSS($params['action']) : null;
- $id = isset($params['id']) ? intval($params['id']) : null;
- if ($this->type == 'course') {
- $url = api_get_self().'?'.api_get_cidreq().'&action='.$action.'&id='.$id.'&type='.$this->type;
- } else {
- $url = api_get_self().'?action='.$action.'&id='.$id.'&type='.$this->type;
- }
- $form = new FormValidator(
- 'add_event',
- 'post',
- $url,
- null,
- array('enctype' => 'multipart/form-data')
- );
- $idAttach = isset($params['id_attach']) ? intval(
- $params['id_attach']
- ) : null;
- $groupId = api_get_group_id();
- if ($id) {
- $form_title = get_lang('ModifyCalendarItem');
- } else {
- $form_title = get_lang('AddCalendarItem');
- }
- $form->addElement('header', $form_title);
- $form->addElement('hidden', 'id', $id);
- $form->addElement('hidden', 'action', $action);
- $form->addElement('hidden', 'id_attach', $idAttach);
- $isSubEventEdition = false;
- $isParentFromSerie = false;
- $showAttachmentForm = true;
- if ($this->type == 'course') {
- // Edition mode.
- if (!empty($id)) {
- $showAttachmentForm = false;
- if (isset($params['parent_event_id']) && !empty($params['parent_event_id'])) {
- $isSubEventEdition = true;
- }
- if (!empty($params['repeat_info'])) {
- $isParentFromSerie = true;
- }
- }
- }
- if ($isSubEventEdition) {
- $form->addElement(
- 'label',
- null,
- Display::return_message(
- get_lang('EditingThisEventWillRemoveItFromTheSerie'),
- 'warning'
- )
- );
- }
- $form->addElement('text', 'title', get_lang('ItemTitle'));
- if (isset($groupId) && !empty($groupId)) {
- $form->addElement(
- 'hidden',
- 'users_to_send[]',
- "GROUP:$groupId"
- );
- $form->addElement('hidden', 'to', 'true');
- } else {
- $sendTo = isset($params['send_to']) ? $params['send_to'] : ['everyone' => true];
- if ($this->type == 'course') {
- $this->showToForm($form, $sendTo, array(), false, true);
- }
- }
- $form->addDateRangePicker(
- 'date_range',
- get_lang('DateRange'),
- false,
- array('id' => 'date_range')
- );
- $form->addElement('checkbox', 'all_day', null, get_lang('AllDay'));
- if ($this->type == 'course') {
- $repeat = $form->addElement(
- 'checkbox',
- 'repeat',
- null,
- get_lang('RepeatEvent'),
- array('onclick' => 'return plus_repeated_event();')
- );
- $form->addElement(
- 'html',
- '<div id="options2" style="display:none">'
- );
- $form->addElement(
- 'select',
- 'repeat_type',
- get_lang('RepeatType'),
- self::getRepeatTypes()
- );
- $form->addElement(
- 'date_picker',
- 'repeat_end_day',
- get_lang('RepeatEnd'),
- array('id' => 'repeat_end_date_form')
- );
- if ($isSubEventEdition || $isParentFromSerie) {
- if ($isSubEventEdition) {
- $parentEvent = $params['parent_info'];
- $repeatInfo = $parentEvent['repeat_info'];
- } else {
- $repeatInfo = $params['repeat_info'];
- }
- $params['repeat'] = 1;
- $params['repeat_type'] = $repeatInfo['cal_type'];
- $params['repeat_end_day'] = substr(
- api_get_local_time($repeatInfo['cal_end']),
- 0,
- 10
- );
- $form->freeze(array('repeat_type', 'repeat_end_day'));
- $repeat->_attributes['disabled'] = 'disabled';
- }
- $form->addElement('html', '</div>');
- }
- if (!empty($id)) {
- if (empty($params['end_date'])) {
- $params['date_range'] = $params['end_date'];
- }
- $params['date_range'] =
- substr(api_get_local_time($params['start_date']), 0, 16).' / '.
- substr(api_get_local_time($params['end_date']), 0, 16);
- }
- if (!api_is_allowed_to_edit(null, true)) {
- $toolbar = 'AgendaStudent';
- } else {
- $toolbar = 'Agenda';
- }
- $form->addElement(
- 'html_editor',
- 'content',
- get_lang('Description'),
- null,
- array(
- 'ToolbarSet' => $toolbar,
- 'Width' => '100%',
- 'Height' => '200'
- )
- );
- if ($this->type == 'course') {
- $form->addElement('textarea', 'comment', get_lang('Comment'));
- $form->addLabel(
- get_lang('FilesAttachment'),
- '<span id="filepaths">
- <div id="filepath_1">
- <input type="file" name="attach_1"/><br />
- '.get_lang('Description').' <input type="text" name="legend[]" /><br /><br />
- </div>
- </span>'
- );
- $form->addLabel(
- '',
- '<span id="link-more-attach">
- <a href="javascript://" onclick="return add_image_form()">'.
- get_lang('AddOneMoreFile').'</a>
- </span> ('.sprintf(
- get_lang('MaximunFileSizeX'),
- format_file_size(
- api_get_setting('message_max_upload_filesize')
- )
- ).')'
- );
- if (isset($params['attachment']) && !empty($params['attachment'])) {
- $attachmentList = $params['attachment'];
- foreach ($attachmentList as $attachment) {
- $params['file_comment'] = $attachment['comment'];
- if (!empty($attachment['path'])) {
- $form->addElement(
- 'checkbox',
- 'delete_attachment['.$attachment['id'].']',
- null,
- get_lang(
- 'DeleteAttachment'
- ).': '.$attachment['filename']
- );
- }
- }
- }
- $form->addElement(
- 'textarea',
- 'file_comment',
- get_lang('FileComment')
- );
- }
- if (empty($id)) {
- $form->addElement(
- 'checkbox',
- 'add_announcement',
- null,
- get_lang('AddAnnouncement').' ('.get_lang('SendMail').')'
- );
- }
- if ($id) {
- $form->addButtonUpdate(get_lang('ModifyEvent'));
- } else {
- $form->addButtonSave(get_lang('AgendaAdd'));
- }
- $form->setDefaults($params);
- $form->addRule(
- 'date_range',
- get_lang('ThisFieldIsRequired'),
- 'required'
- );
- $form->addRule('title', get_lang('ThisFieldIsRequired'), 'required');
- return $form;
- }
- /**
- * @param FormValidator $form
- * @param array $sendTo array('everyone' => false, 'users' => [1, 2], 'groups' => [3, 4])
- * @param array $attributes
- * @param bool $addOnlyItemsInSendTo
- * @param bool $required
- * @return bool
- */
- public function showToForm(
- $form,
- $sendTo = array(),
- $attributes = array(),
- $addOnlyItemsInSendTo = false,
- $required = false
- ) {
- if ($this->type != 'course') {
- return false;
- }
- $order = 'lastname';
- if (api_is_western_name_order()) {
- $order = 'firstname';
- }
- $userList = CourseManager::get_user_list_from_course_code(
- api_get_course_id(),
- $this->sessionId,
- null,
- $order
- );
- $groupList = CourseManager::get_group_list_of_course(
- api_get_course_id(),
- $this->sessionId
- );
- $this->setSendToSelect(
- $form,
- $groupList,
- $userList,
- $sendTo,
- $attributes,
- $addOnlyItemsInSendTo,
- $required
- );
- return true;
- }
- /**
- * @param int $id
- * @param int $visibility 0= invisible, 1 visible
- * @param array $courseInfo
- * @param int $userId
- */
- public static function changeVisibility(
- $id,
- $visibility,
- $courseInfo,
- $userId = null
- ) {
- $id = intval($id);
- if (empty($userId)) {
- $userId = api_get_user_id();
- } else {
- $userId = intval($userId);
- }
- if ($visibility == 0) {
- api_item_property_update(
- $courseInfo,
- TOOL_CALENDAR_EVENT,
- $id,
- 'invisible',
- $userId
- );
- } else {
- api_item_property_update(
- $courseInfo,
- TOOL_CALENDAR_EVENT,
- $id,
- 'visible',
- $userId
- );
- }
- }
- /**
- * Get repeat types
- * @return array
- */
- public static function getRepeatTypes()
- {
- return array(
- 'daily' => get_lang('RepeatDaily'),
- 'weekly' => get_lang('RepeatWeekly'),
- 'monthlyByDate' => get_lang('RepeatMonthlyByDate'),
- //monthlyByDay"> get_lang('RepeatMonthlyByDay');
- //monthlyByDayR' => get_lang('RepeatMonthlyByDayR'),
- 'yearly' => get_lang('RepeatYearly')
- );
- }
- /**
- * Show a list with all the attachments according to the post's id
- * @param int $eventId
- * @param array $courseInfo
- * @return array with the post info
- */
- public function getAttachmentList($eventId, $courseInfo)
- {
- $tableAttachment = Database::get_course_table(TABLE_AGENDA_ATTACHMENT);
- $courseId = intval($courseInfo['real_id']);
- $eventId = intval($eventId);
- $sql = "SELECT id, path, filename, comment
- FROM $tableAttachment
- WHERE
- c_id = $courseId AND
- agenda_id = $eventId";
- $result = Database::query($sql);
- $list = array();
- if (Database::num_rows($result) != 0) {
- $list = Database::store_result($result, 'ASSOC');
- }
- return $list;
- }
- /**
- * Show a list with all the attachments according to the post's id
- * @param int $attachmentId
- * @param int $eventId
- * @param array $courseInfo
- * @return array with the post info
- */
- public function getAttachment($attachmentId, $eventId, $courseInfo)
- {
- $tableAttachment = Database::get_course_table(TABLE_AGENDA_ATTACHMENT);
- $courseId = intval($courseInfo['real_id']);
- $eventId = intval($eventId);
- $attachmentId = intval($attachmentId);
- $row = array();
- $sql = "SELECT id, path, filename, comment
- FROM $tableAttachment
- WHERE
- c_id = $courseId AND
- agenda_id = $eventId AND
- id = $attachmentId
- ";
- $result = Database::query($sql);
- if (Database::num_rows($result) != 0) {
- $row = Database::fetch_array($result, 'ASSOC');
- }
- return $row;
- }
- /**
- * Add an attachment file into agenda
- * @param int $eventId
- * @param array $fileUserUpload ($_FILES['user_upload'])
- * @param string $comment about file
- * @param array $courseInfo
- * @return string
- */
- public function addAttachment(
- $eventId,
- $fileUserUpload,
- $comment,
- $courseInfo
- ) {
- $agenda_table_attachment = Database::get_course_table(
- TABLE_AGENDA_ATTACHMENT
- );
- $eventId = intval($eventId);
- // Storing the attachments
- $upload_ok = false;
- if (!empty($fileUserUpload['name'])) {
- $upload_ok = process_uploaded_file($fileUserUpload);
- }
- if (!empty($upload_ok)) {
- $courseDir = $courseInfo['directory'].'/upload/calendar';
- $sys_course_path = api_get_path(SYS_COURSE_PATH);
- $uploadDir = $sys_course_path.$courseDir;
- // Try to add an extension to the file if it hasn't one
- $new_file_name = add_ext_on_mime(
- stripslashes($fileUserUpload['name']),
- $fileUserUpload['type']
- );
- // user's file name
- $file_name = $fileUserUpload['name'];
- if (!filter_extension($new_file_name)) {
- return Display::return_message(
- get_lang('UplUnableToSaveFileFilteredExtension'),
- 'error'
- );
- } else {
- $new_file_name = uniqid('');
- $new_path = $uploadDir.'/'.$new_file_name;
- $result = @move_uploaded_file(
- $fileUserUpload['tmp_name'],
- $new_path
- );
- $course_id = api_get_course_int_id();
- $size = intval($fileUserUpload['size']);
- // Storing the attachments if any
- if ($result) {
- $params = [
- 'c_id' => $course_id,
- 'filename' => $file_name,
- 'comment' => $comment,
- 'path' => $new_file_name,
- 'agenda_id' => $eventId,
- 'size' => $size
- ];
- $id = Database::insert($agenda_table_attachment, $params);
- if ($id) {
- $sql = "UPDATE $agenda_table_attachment
- SET id = iid WHERE iid = $id";
- Database::query($sql);
- api_item_property_update(
- $courseInfo,
- 'calendar_event_attachment',
- $id,
- 'AgendaAttachmentAdded',
- api_get_user_id()
- );
- }
- }
- }
- }
- }
- /**
- * @param int $attachmentId
- * @param int $eventId
- * @param array $fileUserUpload
- * @param string $comment
- * @param array $courseInfo
- */
- public function updateAttachment(
- $attachmentId,
- $eventId,
- $fileUserUpload,
- $comment,
- $courseInfo
- ) {
- $attachment = $this->getAttachment(
- $attachmentId,
- $eventId,
- $courseInfo
- );
- if (!empty($attachment)) {
- $this->deleteAttachmentFile($attachmentId, $courseInfo);
- }
- $this->addAttachment($eventId, $fileUserUpload, $comment, $courseInfo);
- }
- /**
- * This function delete a attachment file by id
- * @param int $attachmentId
- * @param array $courseInfo
- * @return string
- */
- public function deleteAttachmentFile($attachmentId, $courseInfo)
- {
- $agenda_table_attachment = Database::get_course_table(
- TABLE_AGENDA_ATTACHMENT
- );
- $attachmentId = intval($attachmentId);
- $courseId = $courseInfo['real_id'];
- if (empty($courseId) || empty($attachmentId)) {
- return false;
- }
- $sql = "DELETE FROM $agenda_table_attachment
- WHERE c_id = $courseId AND id = ".$attachmentId;
- $result = Database::query($sql);
- // update item_property
- api_item_property_update(
- $courseInfo,
- 'calendar_event_attachment',
- $attachmentId,
- 'AgendaAttachmentDeleted',
- api_get_user_id()
- );
- if (!empty($result)) {
- return Display::return_message(
- get_lang("AttachmentFileDeleteSuccess"),
- 'confirmation'
- );
- }
- }
- /**
- * Adds x weeks to a UNIX timestamp
- * @param int The timestamp
- * @param int The number of weeks to add
- * @param integer $timestamp
- * @return int The new timestamp
- */
- public function addWeek($timestamp, $num = 1)
- {
- return $timestamp + $num * 604800;
- }
- /**
- * Adds x months to a UNIX timestamp
- * @param int The timestamp
- * @param int The number of years to add
- * @param integer $timestamp
- * @return int The new timestamp
- */
- public function addMonth($timestamp, $num = 1)
- {
- list($y, $m, $d, $h, $n, $s) = split(
- '/',
- date('Y/m/d/h/i/s', $timestamp)
- );
- if ($m + $num > 12) {
- $y += floor($num / 12);
- $m += $num % 12;
- } else {
- $m += $num;
- }
- return mktime($h, $n, $s, $m, $d, $y);
- }
- /**
- * Adds x years to a UNIX timestamp
- * @param int The timestamp
- * @param int The number of years to add
- * @param integer $timestamp
- * @return int The new timestamp
- */
- public function addYear($timestamp, $num = 1)
- {
- list($y, $m, $d, $h, $n, $s) = split(
- '/',
- date('Y/m/d/h/i/s', $timestamp)
- );
- return mktime($h, $n, $s, $m, $d, $y + $num);
- }
- /**
- * @param int $eventId
- * @return array
- */
- public function getAllRepeatEvents($eventId)
- {
- $events = array();
- switch ($this->type) {
- case 'personal':
- break;
- case 'course':
- if (!empty($this->course['real_id'])) {
- $sql = "SELECT * FROM ".$this->tbl_course_agenda."
- WHERE
- c_id = ".$this->course['real_id']." AND
- parent_event_id = ".$eventId;
- $result = Database::query($sql);
- if (Database::num_rows($result)) {
- while ($row = Database::fetch_array($result, 'ASSOC')) {
- $events[] = $row;
- }
- }
- }
- break;
- }
- return $events;
- }
- /**
- * @param int $eventId
- * @param int $courseId
- *
- * @return bool
- */
- public function hasChildren($eventId, $courseId)
- {
- $eventId = intval($eventId);
- $courseId = intval($courseId);
- $sql = "SELECT count(DISTINCT(id)) as count
- FROM ".$this->tbl_course_agenda."
- WHERE
- c_id = $courseId AND
- parent_event_id = $eventId";
- $result = Database::query($sql);
- if (Database::num_rows($result)) {
- $row = Database::fetch_array($result, 'ASSOC');
- return $row['count'] > 0;
- }
- return false;
- }
- /**
- * @param int $filter
- * @param string $view
- * @return string
- */
- public function displayActions($view, $filter = 0)
- {
- $courseInfo = api_get_course_info();
- $groupInfo = GroupManager::get_group_properties(api_get_group_id());
- $groupIid = isset($groupInfo['iid']) ? $groupInfo['iid'] : 0;
- $courseCondition = '';
- if (!empty($courseInfo)) {
- $courseCondition = api_get_cidreq();
- }
- $actionsLeft = '';
- $actionsLeft .= "<a href='".api_get_path(WEB_CODE_PATH)."calendar/agenda_js.php?type={$this->type}&".$courseCondition."'>".
- Display::return_icon(
- 'calendar.png',
- get_lang('Calendar'),
- '',
- ICON_SIZE_MEDIUM
- )."</a>";
- $actionsLeft .= "<a href='".api_get_path(WEB_CODE_PATH)."calendar/agenda_list.php?type={$this->type}&".$courseCondition."'>".
- Display::return_icon(
- 'week.png',
- get_lang('AgendaList'),
- '',
- ICON_SIZE_MEDIUM
- )."</a>";
- $form = '';
- if (api_is_allowed_to_edit(false, true) ||
- (api_get_course_setting('allow_user_edit_agenda') && !api_is_anonymous()) &&
- api_is_allowed_to_session_edit(false, true) ||
- (GroupManager::user_has_access(
- api_get_user_id(),
- $groupIid,
- GroupManager::GROUP_TOOL_CALENDAR
- ) &&
- GroupManager::is_tutor_of_group(api_get_user_id(), $groupInfo))
- ) {
- $actionsLeft .= Display::url(
- Display::return_icon(
- 'new_event.png',
- get_lang('AgendaAdd'),
- '',
- ICON_SIZE_MEDIUM
- ),
- api_get_path(WEB_CODE_PATH)."calendar/agenda.php?".api_get_cidreq()."&action=add&type=".$this->type
- );
- $actionsLeft .= Display::url(
- Display::return_icon(
- 'import_calendar.png',
- get_lang('ICalFileImport'),
- '',
- ICON_SIZE_MEDIUM
- ),
- api_get_path(WEB_CODE_PATH)."calendar/agenda.php?".api_get_cidreq()."&action=importical&type=".$this->type
- );
- if ($this->type === 'course') {
- if (!isset($_GET['action'])) {
- $form = new FormValidator(
- 'form-search',
- 'post',
- '',
- '',
- array(),
- FormValidator::LAYOUT_INLINE
- );
- $attributes = array(
- 'multiple' => false,
- 'id' => 'select_form_id_search'
- );
- $selectedValues = $this->parseAgendaFilter($filter);
- $this->showToForm($form, $selectedValues, $attributes);
- $form = $form->returnForm();
- }
- }
- }
- if (api_is_platform_admin() ||
- api_is_teacher() ||
- api_is_student_boss() ||
- api_is_drh() ||
- api_is_session_admin() ||
- api_is_coach()
- ) {
- if ($this->type == 'personal') {
- $form = null;
- if (!isset($_GET['action'])) {
- $form = new FormValidator(
- 'form-search',
- 'get',
- api_get_self().'?type=personal&',
- '',
- array(),
- FormValidator::LAYOUT_INLINE
- );
- $sessions = SessionManager::get_sessions_by_user(
- api_get_user_id()
- );
- $form->addHidden('type', 'personal');
- $sessions = array_column(
- $sessions,
- 'session_name',
- 'session_id'
- );
- $sessions = ['0' => get_lang('SelectAnOption')] + $sessions;
- $form->addSelect(
- 'session_id',
- get_lang('Session'),
- $sessions,
- ['id' => 'session_id', 'onchange' => 'submit();']
- );
- $form->addButtonReset(get_lang('Reset'));
- $form = $form->returnForm();
- }
- }
- }
- $actionsRight = '';
- if ($view == 'calendar') {
- $actionsRight .= $form;
- }
- $toolbar = Display::toolbarAction(
- 'toolbar-agenda',
- array($actionsLeft, $actionsRight)
- );
- return $toolbar;
- }
- /**
- * @return FormValidator
- */
- public function getImportCalendarForm()
- {
- $form = new FormValidator(
- 'frm_import_ical',
- 'post',
- api_get_self().'?action=importical&type='.$this->type,
- array('enctype' => 'multipart/form-data')
- );
- $form->addElement('header', get_lang('ICalFileImport'));
- $form->addElement('file', 'ical_import', get_lang('ICalFileImport'));
- $form->addRule(
- 'ical_import',
- get_lang('ThisFieldIsRequired'),
- 'required'
- );
- $form->addButtonImport(get_lang('Import'), 'ical_submit');
- return $form;
- }
- /**
- * @param array $courseInfo
- * @param $file
- * @return false|string
- */
- public function importEventFile($courseInfo, $file)
- {
- $charset = api_get_system_encoding();
- $filepath = api_get_path(SYS_ARCHIVE_PATH).$file['name'];
- $messages = array();
- if (!@move_uploaded_file($file['tmp_name'], $filepath)) {
- error_log(
- 'Problem moving uploaded file: '.$file['error'].' in '.__FILE__.' line '.__LINE__
- );
- return false;
- }
- $data = file_get_contents($filepath);
- $trans = array(
- 'DAILY' => 'daily',
- 'WEEKLY' => 'weekly',
- 'MONTHLY' => 'monthlyByDate',
- 'YEARLY' => 'yearly'
- );
- $sentTo = array('everyone' => true);
- $calendar = Sabre\VObject\Reader::read($data);
- $currentTimeZone = api_get_timezone();
- if (!empty($calendar->VEVENT)) {
- foreach ($calendar->VEVENT as $event) {
- $start = $event->DTSTART->getDateTime();
- $end = $event->DTEND->getDateTime();
- //Sabre\VObject\DateTimeParser::parseDateTime(string $dt, \Sabre\VObject\DateTimeZone $tz)
- $startDateTime = api_get_local_time(
- $start->format('Y-m-d H:i:s'),
- $currentTimeZone,
- $start->format('e')
- );
- $endDateTime = api_get_local_time(
- $end->format('Y-m-d H:i'),
- $currentTimeZone,
- $end->format('e')
- );
- $title = api_convert_encoding(
- (string) $event->summary,
- $charset,
- 'UTF-8'
- );
- $description = api_convert_encoding(
- (string) $event->description,
- $charset,
- 'UTF-8'
- );
- $id = $this->addEvent(
- $startDateTime,
- $endDateTime,
- 'false',
- $title,
- $description,
- $sentTo
- );
- $messages[] = " $title - ".$startDateTime." - ".$endDateTime;
- //$attendee = (string)$event->attendee;
- /** @var Sabre\VObject\Property\ICalendar\Recur $repeat */
- $repeat = $event->RRULE;
- if ($id && !empty($repeat)) {
- $repeat = $repeat->getParts();
- $freq = $trans[$repeat['FREQ']];
- if (isset($repeat['UNTIL']) && !empty($repeat['UNTIL'])) {
- // Check if datetime or just date (strlen == 8)
- if (strlen($repeat['UNTIL']) == 8) {
- // Fix the datetime format to avoid exception in the next step
- $repeat['UNTIL'] .= 'T000000';
- }
- $until = Sabre\VObject\DateTimeParser::parseDateTime(
- $repeat['UNTIL'],
- new DateTimeZone($currentTimeZone)
- );
- $until = $until->format('Y-m-d H:i');
- //$res = agenda_add_repeat_item($courseInfo, $id, $freq, $until, $attendee);
- $this->addRepeatedItem(
- $id,
- $freq,
- $until,
- $sentTo
- );
- }
- if (!empty($repeat['COUNT'])) {
- /*$count = $repeat['COUNT'];
- $interval = $repeat['INTERVAL'];
- $endDate = null;
- switch($freq) {
- case 'daily':
- $start = api_strtotime($startDateTime);
- $date = new DateTime($startDateTime);
- $days = $count * $interval;
- var_dump($days);
- $date->add(new DateInterval("P".$days."D"));
- $endDate = $date->format('Y-m-d H:i');
- //$endDate = $count *
- for ($i = 0; $i < $count; $i++) {
- $days = 86400 * 7
- }
- }
- }*/
- //$res = agenda_add_repeat_item($courseInfo, $id, $freq, $count, $attendee);
- /*$this->addRepeatedItem(
- $id,
- $freq,
- $endDate,
- $sentTo
- );*/
- }
- }
- }
- }
- if (!empty($messages)) {
- $messages = implode('<br /> ', $messages);
- } else {
- $messages = get_lang('NoAgendaItems');
- }
- return $messages;
- }
- /**
- * Parse filter turns USER:12 to ['users' => [12])] or G:1 ['groups' => [1]]
- * @param integer $filter
- * @return array
- */
- public function parseAgendaFilter($filter)
- {
- $everyone = false;
- $groupId = null;
- $userId = null;
- if ($filter == 'everyone') {
- $everyone = true;
- } else {
- if (substr($filter, 0, 1) == 'G') {
- $groupId = str_replace('GROUP:', '', $filter);
- } else {
- $userId = str_replace('USER:', '', $filter);
- }
- }
- if (empty($userId) && empty($groupId)) {
- $everyone = true;
- }
- return array(
- 'everyone' => $everyone,
- 'users' => array($userId),
- 'groups' => array($groupId)
- );
- }
- /**
- * This function retrieves all the agenda items of all the courses the user is subscribed to
- */
- public static function get_myagendaitems(
- $user_id,
- $courses_dbs,
- $month,
- $year
- ) {
- $user_id = intval($user_id);
- $items = array();
- $my_list = array();
- // get agenda-items for every course
- foreach ($courses_dbs as $key => $array_course_info) {
- //databases of the courses
- $TABLEAGENDA = Database::get_course_table(TABLE_AGENDA);
- $TABLE_ITEMPROPERTY = Database::get_course_table(
- TABLE_ITEM_PROPERTY
- );
- $group_memberships = GroupManager::get_group_ids(
- $array_course_info['real_id'],
- $user_id
- );
- $course_user_status = CourseManager::getUserInCourseStatus(
- $user_id,
- $array_course_info['real_id']
- );
- // if the user is administrator of that course we show all the agenda items
- if ($course_user_status == '1') {
- //echo "course admin";
- $sqlquery = "SELECT DISTINCT agenda.*, ip.visibility, ip.to_group_id, ip.insert_user_id, ip.ref
- FROM ".$TABLEAGENDA." agenda,
- ".$TABLE_ITEMPROPERTY." ip
- WHERE agenda.id = ip.ref
- AND MONTH(agenda.start_date)='".$month."'
- AND YEAR(agenda.start_date)='".$year."'
- AND ip.tool='".TOOL_CALENDAR_EVENT."'
- AND ip.visibility='1'
- GROUP BY agenda.id
- ORDER BY start_date ";
- } else {
- // if the user is not an administrator of that course
- if (is_array($group_memberships) && count(
- $group_memberships
- ) > 0
- ) {
- $sqlquery = "SELECT agenda.*, ip.visibility, ip.to_group_id, ip.insert_user_id, ip.ref
- FROM ".$TABLEAGENDA." agenda,
- ".$TABLE_ITEMPROPERTY." ip
- WHERE agenda.id = ip.ref
- AND MONTH(agenda.start_date)='".$month."'
- AND YEAR(agenda.start_date)='".$year."'
- AND ip.tool='".TOOL_CALENDAR_EVENT."'
- AND ( ip.to_user_id='".$user_id."' OR (ip.to_group_id IS NULL OR ip.to_group_id IN (0, ".implode(
- ", ",
- $group_memberships
- ).")) )
- AND ip.visibility='1'
- ORDER BY start_date ";
- } else {
- $sqlquery = "SELECT agenda.*, ip.visibility, ip.to_group_id, ip.insert_user_id, ip.ref
- FROM ".$TABLEAGENDA." agenda,
- ".$TABLE_ITEMPROPERTY." ip
- WHERE agenda.id = ip.ref
- AND MONTH(agenda.start_date)='".$month."'
- AND YEAR(agenda.start_date)='".$year."'
- AND ip.tool='".TOOL_CALENDAR_EVENT."'
- AND ( ip.to_user_id='".$user_id."' OR ip.to_group_id='0' OR ip.to_group_id IS NULL)
- AND ip.visibility='1'
- ORDER BY start_date ";
- }
- }
- $result = Database::query($sqlquery);
- while ($item = Database::fetch_array($result, 'ASSOC')) {
- $agendaday = -1;
- if (!empty($item['start_date'])) {
- $item['start_date'] = api_get_local_time(
- $item['start_date']
- );
- $item['start_date_tms'] = api_strtotime(
- $item['start_date']
- );
- $agendaday = date("j", $item['start_date_tms']);
- }
- if (!empty($item['end_date'])) {
- $item['end_date'] = api_get_local_time($item['end_date']);
- }
- $url = api_get_path(
- WEB_CODE_PATH
- )."calendar/agenda.php?cidReq=".urlencode(
- $array_course_info["code"]
- )."&day=$agendaday&month=$month&year=$year#$agendaday";
- $item['url'] = $url;
- $item['course_name'] = $array_course_info['title'];
- $item['calendar_type'] = 'course';
- $item['course_id'] = $array_course_info['course_id'];
- $my_list[$agendaday][] = $item;
- }
- }
- // sorting by hour for every day
- $agendaitems = array();
- while (list ($agendaday, $tmpitems) = each($items)) {
- if (!isset($agendaitems[$agendaday])) {
- $agendaitems[$agendaday] = '';
- }
- sort($tmpitems);
- while (list ($key, $val) = each($tmpitems)) {
- $agendaitems[$agendaday] .= $val;
- }
- }
- return $my_list;
- }
- /**
- * This function retrieves one personal agenda item returns it.
- * @param array The array containing existing events. We add to this array.
- * @param int Day
- * @param int Month
- * @param int Year (4 digits)
- * @param int Week number
- * @param string Type of view (month_view, week_view, day_view)
- * @return array The results of the database query, or null if not found
- */
- public static function get_global_agenda_items(
- $agendaitems,
- $day = "",
- $month = "",
- $year = "",
- $week = "",
- $type
- ) {
- $tbl_global_agenda = Database::get_main_table(
- TABLE_MAIN_SYSTEM_CALENDAR
- );
- $month = intval($month);
- $year = intval($year);
- $week = intval($week);
- $day = intval($day);
- // 1. creating the SQL statement for getting the personal agenda items in MONTH view
- $current_access_url_id = api_get_current_access_url_id();
- if ($type == "month_view" or $type == "") {
- // We are in month view
- $sql = "SELECT * FROM ".$tbl_global_agenda." WHERE MONTH(start_date) = ".$month." AND YEAR(start_date) = ".$year." AND access_url_id = $current_access_url_id ORDER BY start_date ASC";
- }
- // 2. creating the SQL statement for getting the personal agenda items in WEEK view
- if ($type == "week_view") { // we are in week view
- $start_end_day_of_week = self::calculate_start_end_of_week(
- $week,
- $year
- );
- $start_day = $start_end_day_of_week['start']['day'];
- $start_month = $start_end_day_of_week['start']['month'];
- $start_year = $start_end_day_of_week['start']['year'];
- $end_day = $start_end_day_of_week['end']['day'];
- $end_month = $start_end_day_of_week['end']['month'];
- $end_year = $start_end_day_of_week['end']['year'];
- // in sql statements you have to use year-month-day for date calculations
- $start_filter = $start_year."-".$start_month."-".$start_day." 00:00:00";
- $start_filter = api_get_utc_datetime($start_filter);
- $end_filter = $end_year."-".$end_month."-".$end_day." 23:59:59";
- $end_filter = api_get_utc_datetime($end_filter);
- $sql = " SELECT * FROM ".$tbl_global_agenda." WHERE start_date>='".$start_filter."' AND start_date<='".$end_filter."' AND access_url_id = $current_access_url_id ";
- }
- // 3. creating the SQL statement for getting the personal agenda items in DAY view
- if ($type == "day_view") { // we are in day view
- // we could use mysql date() function but this is only available from 4.1 and higher
- $start_filter = $year."-".$month."-".$day." 00:00:00";
- $start_filter = api_get_utc_datetime($start_filter);
- $end_filter = $year."-".$month."-".$day." 23:59:59";
- $end_filter = api_get_utc_datetime($end_filter);
- $sql = " SELECT * FROM ".$tbl_global_agenda." WHERE start_date>='".$start_filter."' AND start_date<='".$end_filter."' AND access_url_id = $current_access_url_id";
- }
- $result = Database::query($sql);
- while ($item = Database::fetch_array($result)) {
- if (!empty($item['start_date'])) {
- $item['start_date'] = api_get_local_time($item['start_date']);
- $item['start_date_tms'] = api_strtotime($item['start_date']);
- }
- if (!empty($item['end_date'])) {
- $item['end_date'] = api_get_local_time($item['end_date']);
- }
- // we break the date field in the database into a date and a time part
- $agenda_db_date = explode(" ", $item['start_date']);
- $date = $agenda_db_date[0];
- $time = $agenda_db_date[1];
- // we divide the date part into a day, a month and a year
- $agendadate = explode("-", $date);
- $year = intval($agendadate[0]);
- $month = intval($agendadate[1]);
- $day = intval($agendadate[2]);
- // we divide the time part into hour, minutes, seconds
- $agendatime = explode(":", $time);
- $hour = $agendatime[0];
- $minute = $agendatime[1];
- $second = $agendatime[2];
- if ($type == 'month_view') {
- $item['calendar_type'] = 'global';
- $agendaitems[$day][] = $item;
- continue;
- }
- $start_time = api_format_date(
- $item['start_date'],
- TIME_NO_SEC_FORMAT
- );
- $end_time = '';
- if (!empty($item['end_date'])) {
- $end_time = ' - '.api_format_date(
- $item['end_date'],
- DATE_TIME_FORMAT_LONG
- );
- }
- // if the student has specified a course we a add a link to that course
- if ($item['course'] <> "") {
- $url = api_get_path(
- WEB_CODE_PATH
- )."admin/agenda.php?cidReq=".urlencode(
- $item['course']
- )."&day=$day&month=$month&year=$year#$day"; // RH //Patrick Cool: to highlight the relevant agenda item
- $course_link = "<a href=\"$url\" title=\"".$item['course']."\">".$item['course']."</a>";
- } else {
- $course_link = "";
- }
- // Creating the array that will be returned. If we have week or month view we have an array with the date as the key
- // if we have a day_view we use a half hour as index => key 33 = 16h30
- if ($type !== "day_view") {
- // This is the array construction for the WEEK or MONTH view
- //Display the Agenda global in the tab agenda (administrator)
- $agendaitems[$day] .= "<i>$start_time $end_time</i> - ";
- $agendaitems[$day] .= "<b>".get_lang('GlobalEvent')."</b>";
- $agendaitems[$day] .= "<div>".$item['title']."</div><br>";
- } else {
- // this is the array construction for the DAY view
- $halfhour = 2 * $agendatime['0'];
- if ($agendatime['1'] >= '30') {
- $halfhour = $halfhour + 1;
- }
- if (!is_array($agendaitems[$halfhour])) {
- $content = $agendaitems[$halfhour];
- }
- $agendaitems[$halfhour] = $content."<div><i>$hour:$minute</i> <b>".get_lang(
- 'GlobalEvent'
- ).": </b>".$item['title']."</div>";
- }
- }
- return $agendaitems;
- }
- /**
- * This function retrieves all the personal agenda items and add them to the agenda items found by the other functions.
- */
- public static function get_personal_agenda_items(
- $user_id,
- $agendaitems,
- $day = "",
- $month = "",
- $year = "",
- $week = "",
- $type
- ) {
- $tbl_personal_agenda = Database::get_main_table(TABLE_PERSONAL_AGENDA);
- $user_id = intval($user_id);
- // 1. creating the SQL statement for getting the personal agenda items in MONTH view
- if ($type == "month_view" or $type == "") {
- // we are in month view
- $sql = "SELECT * FROM ".$tbl_personal_agenda." WHERE user='".$user_id."' and MONTH(date)='".$month."' AND YEAR(date) = '".$year."' ORDER BY date ASC";
- }
- // 2. creating the SQL statement for getting the personal agenda items in WEEK view
- // we are in week view
- if ($type == "week_view") {
- $start_end_day_of_week = self::calculate_start_end_of_week(
- $week,
- $year
- );
- $start_day = $start_end_day_of_week['start']['day'];
- $start_month = $start_end_day_of_week['start']['month'];
- $start_year = $start_end_day_of_week['start']['year'];
- $end_day = $start_end_day_of_week['end']['day'];
- $end_month = $start_end_day_of_week['end']['month'];
- $end_year = $start_end_day_of_week['end']['year'];
- // in sql statements you have to use year-month-day for date calculations
- $start_filter = $start_year."-".$start_month."-".$start_day." 00:00:00";
- $start_filter = api_get_utc_datetime($start_filter);
- $end_filter = $end_year."-".$end_month."-".$end_day." 23:59:59";
- $end_filter = api_get_utc_datetime($end_filter);
- $sql = " SELECT * FROM ".$tbl_personal_agenda." WHERE user='".$user_id."' AND date>='".$start_filter."' AND date<='".$end_filter."'";
- }
- // 3. creating the SQL statement for getting the personal agenda items in DAY view
- if ($type == "day_view") {
- // we are in day view
- // we could use mysql date() function but this is only available from 4.1 and higher
- $start_filter = $year."-".$month."-".$day." 00:00:00";
- $start_filter = api_get_utc_datetime($start_filter);
- $end_filter = $year."-".$month."-".$day." 23:59:59";
- $end_filter = api_get_utc_datetime($end_filter);
- $sql = " SELECT * FROM ".$tbl_personal_agenda." WHERE user='".$user_id."' AND date>='".$start_filter."' AND date<='".$end_filter."'";
- }
- $result = Database::query($sql);
- while ($item = Database::fetch_array($result, 'ASSOC')) {
- $time_minute = api_convert_and_format_date(
- $item['date'],
- TIME_NO_SEC_FORMAT
- );
- $item['date'] = api_get_local_time($item['date']);
- $item['start_date_tms'] = api_strtotime($item['date']);
- $item['content'] = $item['text'];
- // we break the date field in the database into a date and a time part
- $agenda_db_date = explode(" ", $item['date']);
- $date = $agenda_db_date[0];
- $time = $agenda_db_date[1];
- // we divide the date part into a day, a month and a year
- $agendadate = explode("-", $item['date']);
- $year = intval($agendadate[0]);
- $month = intval($agendadate[1]);
- $day = intval($agendadate[2]);
- // we divide the time part into hour, minutes, seconds
- $agendatime = explode(":", $time);
- $hour = $agendatime[0];
- $minute = $agendatime[1];
- $second = $agendatime[2];
- if ($type == 'month_view') {
- $item['calendar_type'] = 'personal';
- $item['start_date'] = $item['date'];
- $agendaitems[$day][] = $item;
- continue;
- }
- // if the student has specified a course we a add a link to that course
- if ($item['course'] <> "") {
- $url = api_get_path(
- WEB_CODE_PATH
- )."calendar/agenda.php?cidReq=".urlencode(
- $item['course']
- )."&day=$day&month=$month&year=$year#$day"; // RH //Patrick Cool: to highlight the relevant agenda item
- $course_link = "<a href=\"$url\" title=\"".$item['course']."\">".$item['course']."</a>";
- } else {
- $course_link = "";
- }
- // Creating the array that will be returned. If we have week or month view we have an array with the date as the key
- // if we have a day_view we use a half hour as index => key 33 = 16h30
- if ($type !== "day_view") {
- // This is the array construction for the WEEK or MONTH view
- //Display events in agenda
- $agendaitems[$day] .= "<div><i>$time_minute</i> $course_link <a href=\"myagenda.php?action=view&view=personal&day=$day&month=$month&year=$year&id=".$item['id']."#".$item['id']."\" class=\"personal_agenda\">".$item['title']."</a></div><br />";
- } else {
- // this is the array construction for the DAY view
- $halfhour = 2 * $agendatime['0'];
- if ($agendatime['1'] >= '30') {
- $halfhour = $halfhour + 1;
- }
- //Display events by list
- $agendaitems[$halfhour] .= "<div><i>$time_minute</i> $course_link <a href=\"myagenda.php?action=view&view=personal&day=$day&month=$month&year=$year&id=".$item['id']."#".$item['id']."\" class=\"personal_agenda\">".$item['title']."</a></div>";
- }
- }
- return $agendaitems;
- }
- /**
- * Show the monthcalender of the given month
- * @param array Agendaitems
- * @param int Month number
- * @param int Year number
- * @param array Array of strings containing long week day names (deprecated, you can send an empty array instead)
- * @param string The month name
- * @return void Direct output
- */
- public static function display_mymonthcalendar(
- $user_id,
- $agendaitems,
- $month,
- $year,
- $weekdaynames = array(),
- $monthName,
- $show_content = true
- ) {
- global $DaysShort, $course_path;
- //Handle leap year
- $numberofdays = array(
- 0,
- 31,
- 28,
- 31,
- 30,
- 31,
- 30,
- 31,
- 31,
- 30,
- 31,
- 30,
- 31
- );
- if (($year % 400 == 0) or ($year % 4 == 0 and $year % 100 <> 0)) {
- $numberofdays[2] = 29;
- }
- //Get the first day of the month
- $dayone = getdate(mktime(0, 0, 0, $month, 1, $year));
- //Start the week on monday
- $startdayofweek = $dayone['wday'] <> 0 ? ($dayone['wday'] - 1) : 6;
- $g_cc = (isset($_GET['courseCode']) ? $_GET['courseCode'] : '');
- $next_month = ($month == 1 ? 12 : $month - 1);
- $prev_month = ($month == 12 ? 1 : $month + 1);
- $next_year = ($month == 1 ? $year - 1 : $year);
- $prev_year = ($month == 12 ? $year + 1 : $year);
- if ($show_content) {
- $back_url = Display::url(
- get_lang('Previous'),
- api_get_self()."?coursePath=".urlencode(
- $course_path
- )."&courseCode=".Security::remove_XSS(
- $g_cc
- )."&action=view&view=month&month=".$next_month."&year=".$next_year
- );
- $next_url = Display::url(
- get_lang('Next'),
- api_get_self()."?coursePath=".urlencode(
- $course_path
- )."&courseCode=".Security::remove_XSS(
- $g_cc
- )."&action=view&view=month&month=".$prev_month."&year=".$prev_year
- );
- } else {
- $back_url = Display::url(
- get_lang('Previous'),
- '',
- array(
- 'onclick' => "load_calendar('".$user_id."','".$next_month."', '".$next_year."'); ",
- 'class' => 'btn ui-button ui-widget ui-state-default'
- )
- );
- $next_url = Display::url(
- get_lang('Next'),
- '',
- array(
- 'onclick' => "load_calendar('".$user_id."','".$prev_month."', '".$prev_year."'); ",
- 'class' => 'pull-right btn ui-button ui-widget ui-state-default'
- )
- );
- }
- $html = '';
- $html .= '<div class="actions">';
- $html .= '<div class="row">';
- $html .= '<div class="col-md-4">'.$back_url.'</div>';
- $html .= '<div class="col-md-4"><p class="agenda-title text-center">'.$monthName." ".$year.'</p></div>';
- $html .= '<div class="col-md-4">'.$next_url.'</div>';
- $html .= '</div>';
- $html .= '</div>';
- $html .= '<table id="agenda_list2" class="table table-bordered">';
- $html .= '<tr>';
- for ($ii = 1; $ii < 8; $ii++) {
- $html .= '<td class="weekdays">'.$DaysShort[$ii % 7].'</td>';
- }
- $html .= '</tr>';
- $curday = -1;
- $today = getdate();
- while ($curday <= $numberofdays[$month]) {
- $html .= "<tr>";
- for ($ii = 0; $ii < 7; $ii++) {
- if (($curday == -1) && ($ii == $startdayofweek)) {
- $curday = 1;
- }
- if (($curday > 0) && ($curday <= $numberofdays[$month])) {
- $bgcolor = $class = 'class="days_week"';
- $dayheader = Display::div(
- $curday,
- array('class' => 'agenda_day')
- );
- if (($curday == $today['mday']) && ($year == $today['year']) && ($month == $today['mon'])) {
- $class = "class=\"days_today\" style=\"width:10%;\"";
- }
- $html .= "<td ".$class.">".$dayheader;
- if (!empty($agendaitems[$curday])) {
- $items = $agendaitems[$curday];
- $items = msort($items, 'start_date_tms');
- foreach ($items as $value) {
- $value['title'] = Security::remove_XSS(
- $value['title']
- );
- $start_time = api_format_date(
- $value['start_date'],
- TIME_NO_SEC_FORMAT
- );
- $end_time = '';
- if (!empty($value['end_date'])) {
- $end_time = '- <i>'.api_format_date(
- $value['end_date'],
- DATE_TIME_FORMAT_LONG
- ).'</i>';
- }
- $complete_time = '<i>'.api_format_date(
- $value['start_date'],
- DATE_TIME_FORMAT_LONG
- ).'</i> '.$end_time;
- $time = '<i>'.$start_time.'</i>';
- switch ($value['calendar_type']) {
- case 'personal':
- $bg_color = '#D0E7F4';
- $icon = Display::return_icon(
- 'user.png',
- get_lang('MyAgenda'),
- array(),
- ICON_SIZE_SMALL
- );
- break;
- case 'global':
- $bg_color = '#FFBC89';
- $icon = Display::return_icon(
- 'view_remove.png',
- get_lang('GlobalEvent'),
- array(),
- ICON_SIZE_SMALL
- );
- break;
- case 'course':
- $bg_color = '#CAFFAA';
- $icon_name = 'course.png';
- if (!empty($value['session_id'])) {
- $icon_name = 'session.png';
- }
- if ($show_content) {
- $icon = Display::url(
- Display::return_icon(
- $icon_name,
- $value['course_name'].' '.get_lang(
- 'Course'
- ),
- array(),
- ICON_SIZE_SMALL
- ),
- $value['url']
- );
- } else {
- $icon = Display::return_icon(
- $icon_name,
- $value['course_name'].' '.get_lang(
- 'Course'
- ),
- array(),
- ICON_SIZE_SMALL
- );
- }
- break;
- default:
- break;
- }
- $result = '<div class="rounded_div_agenda" style="background-color:'.$bg_color.';">';
- if ($show_content) {
- //Setting a personal event to green
- $icon = Display::div(
- $icon,
- array('style' => 'float:right')
- );
- $link = $value['calendar_type'].'_'.$value['id'].'_'.$value['course_id'].'_'.$value['session_id'];
- //Link to bubble
- $url = Display::url(
- cut($value['title'], 40),
- '#',
- array('id' => $link, 'class' => 'opener')
- );
- $result .= $time.' '.$icon.' '.Display::div(
- $url
- );
- //Hidden content
- $content = Display::div(
- $icon.Display::tag(
- 'h2',
- $value['course_name']
- ).'<hr />'.Display::tag(
- 'h3',
- $value['title']
- ).$complete_time.'<hr />'.Security::remove_XSS(
- $value['content']
- )
- );
- //Main div
- $result .= Display::div(
- $content,
- array(
- 'id' => 'main_'.$link,
- 'class' => 'dialog',
- 'style' => 'display:none'
- )
- );
- $result .= '</div>';
- $html .= $result;
- //echo Display::div($content, array('id'=>'main_'.$value['calendar_type'].'_'.$value['id'], 'class' => 'dialog'));
- } else {
- $html .= $result .= $icon.'</div>';
- }
- }
- }
- $html .= "</td>";
- $curday++;
- } else {
- $html .= "<td></td>";
- }
- }
- $html .= "</tr>";
- }
- $html .= "</table>";
- echo $html;
- }
- /**
- * Get personal agenda items between two dates (=all events from all registered courses)
- * @param int user ID of the user
- * @param string Optional start date in datetime format (if no start date is given, uses today)
- * @param string Optional end date in datetime format (if no date is given, uses one year from now)
- * @param integer $user_id
- * @return array Array of events ordered by start date, in
- * [0]('datestart','dateend','title'),[1]('datestart','dateend','title','link','coursetitle') format,
- * where datestart and dateend are in yyyyMMddhhmmss format.
- * @deprecated use agenda events
- */
- public static function get_personal_agenda_items_between_dates(
- $user_id,
- $date_start = '',
- $date_end = ''
- ) {
- $items = array();
- if ($user_id != strval(intval($user_id))) {
- return $items;
- }
- if (empty($date_start)) {
- $date_start = date('Y-m-d H:i:s');
- }
- if (empty($date_end)) {
- $date_end = date(
- 'Y-m-d H:i:s',
- mktime(0, 0, 0, date("m"), date("d"), date("Y") + 1)
- );
- }
- $expr = '/\d{4}-\d{2}-\d{2}\ \d{2}:\d{2}:\d{2}/';
- if (!preg_match($expr, $date_start)) {
- return $items;
- }
- if (!preg_match($expr, $date_end)) {
- return $items;
- }
- // get agenda-items for every course
- $courses = api_get_user_courses($user_id, false);
- foreach ($courses as $id => $course) {
- $c = api_get_course_info_by_id($course['real_id']);
- //databases of the courses
- $t_a = Database::get_course_table(TABLE_AGENDA, $course['db']);
- $t_ip = Database::get_course_table(
- TABLE_ITEM_PROPERTY,
- $course['db']
- );
- // get the groups to which the user belong
- $group_memberships = GroupManager:: get_group_ids(
- $course['db'],
- $user_id
- );
- // if the user is administrator of that course we show all the agenda items
- if ($course['status'] == '1') {
- //echo "course admin";
- $sqlquery = "SELECT ".
- " DISTINCT agenda.*, ip.visibility, ip.to_group_id, ip.insert_user_id, ip.ref ".
- " FROM ".$t_a." agenda, ".
- $t_ip." ip ".
- " WHERE agenda.id = ip.ref ".
- " AND agenda.start_date>='$date_start' ".
- " AND agenda.end_date<='$date_end' ".
- " AND ip.tool='".TOOL_CALENDAR_EVENT."' ".
- " AND ip.visibility='1' ".
- " GROUP BY agenda.id ".
- " ORDER BY start_date ";
- } else {
- // if the user is not an administrator of that course, then...
- if (is_array($group_memberships) && count(
- $group_memberships
- ) > 0
- ) {
- $sqlquery = "SELECT ".
- "DISTINCT agenda.*, ip.visibility, ip.to_group_id, ip.insert_user_id, ip.ref ".
- " FROM ".$t_a." agenda, ".
- $t_ip." ip ".
- " WHERE agenda.id = ip.ref ".
- " AND agenda.start_date>='$date_start' ".
- " AND agenda.end_date<='$date_end' ".
- " AND ip.tool='".TOOL_CALENDAR_EVENT."' ".
- " AND ( ip.to_user_id='".$user_id."' OR (ip.to_group_id IS NULL OR ip.to_group_id IN (0, ".implode(
- ", ",
- $group_memberships
- ).")) ) ".
- " AND ip.visibility='1' ".
- " ORDER BY start_date ";
- } else {
- $sqlquery = "SELECT ".
- "DISTINCT agenda.*, ip.visibility, ip.to_group_id, ip.insert_user_id, ip.ref ".
- " FROM ".$t_a." agenda, ".
- $t_ip." ip ".
- " WHERE agenda.id = ip.ref ".
- " AND agenda.start_date>='$date_start' ".
- " AND agenda.end_date<='$date_end' ".
- " AND ip.tool='".TOOL_CALENDAR_EVENT."' ".
- " AND ( ip.to_user_id='".$user_id."' OR ip.to_group_id='0' OR ip.to_group_id IS NULL) ".
- " AND ip.visibility='1' ".
- " ORDER BY start_date ";
- }
- }
- $result = Database::query($sqlquery);
- while ($item = Database::fetch_array($result)) {
- $agendaday = date("j", strtotime($item['start_date']));
- $month = date("n", strtotime($item['start_date']));
- $year = date("Y", strtotime($item['start_date']));
- $URL = api_get_path(
- WEB_PATH
- )."main/calendar/agenda.php?cidReq=".urlencode(
- $course["code"]
- )."&day=$agendaday&month=$month&year=$year#$agendaday";
- list($year, $month, $day, $hour, $min, $sec) = split(
- '[-: ]',
- $item['start_date']
- );
- $start_date = $year.$month.$day.$hour.$min;
- list($year, $month, $day, $hour, $min, $sec) = split(
- '[-: ]',
- $item['end_date']
- );
- $end_date = $year.$month.$day.$hour.$min;
- $items[] = array(
- 'datestart' => $start_date,
- 'dateend' => $end_date,
- 'title' => $item['title'],
- 'link' => $URL,
- 'coursetitle' => $c['name'],
- );
- }
- }
- return $items;
- }
- /**
- * This function retrieves one personal agenda item returns it.
- * @param int $id The agenda item ID
- * @return array The results of the database query, or null if not found
- */
- public static function get_personal_agenda_item($id)
- {
- $tbl_personal_agenda = Database::get_main_table(TABLE_PERSONAL_AGENDA);
- $id = intval($id);
- // make sure events of the personal agenda can only be seen by the user himself
- $user = api_get_user_id();
- $sql = " SELECT * FROM ".$tbl_personal_agenda." WHERE id=".$id." AND user = ".$user;
- $result = Database::query($sql);
- if (Database::num_rows($result) == 1) {
- $item = Database::fetch_array($result);
- } else {
- $item = null;
- }
- return $item;
- }
- /**
- * This function calculates the startdate of the week (monday)
- * and the enddate of the week (sunday)
- * and returns it as an array
- */
- public static function calculate_start_end_of_week($week_number, $year)
- {
- // determine the start and end date
- // step 1: we calculate a timestamp for a day in this week
- $random_day_in_week = mktime(
- 0,
- 0,
- 0,
- 1,
- 1,
- $year
- ) + ($week_number) * (7 * 24 * 60 * 60); // we calculate a random day in this week
- // step 2: we which day this is (0=sunday, 1=monday, ...)
- $number_day_in_week = date('w', $random_day_in_week);
- // step 3: we calculate the timestamp of the monday of the week we are in
- $start_timestamp = $random_day_in_week - (($number_day_in_week - 1) * 24 * 60 * 60);
- // step 4: we calculate the timestamp of the sunday of the week we are in
- $end_timestamp = $random_day_in_week + ((7 - $number_day_in_week + 1) * 24 * 60 * 60) - 3600;
- // step 5: calculating the start_day, end_day, start_month, end_month, start_year, end_year
- $start_day = date('j', $start_timestamp);
- $start_month = date('n', $start_timestamp);
- $start_year = date('Y', $start_timestamp);
- $end_day = date('j', $end_timestamp);
- $end_month = date('n', $end_timestamp);
- $end_year = date('Y', $end_timestamp);
- $start_end_array['start']['day'] = $start_day;
- $start_end_array['start']['month'] = $start_month;
- $start_end_array['start']['year'] = $start_year;
- $start_end_array['end']['day'] = $end_day;
- $start_end_array['end']['month'] = $end_month;
- $start_end_array['end']['year'] = $end_year;
- return $start_end_array;
- }
- /**
- * @return bool
- */
- public function getIsAllowedToEdit()
- {
- return $this->isAllowedToEdit;
- }
- /**
- * @param bool $isAllowedToEdit
- */
- public function setIsAllowedToEdit($isAllowedToEdit)
- {
- $this->isAllowedToEdit = $isAllowedToEdit;
- }
- /**
- * @param int $userId
- * @param array $event
- *
- * @return bool
- */
- public function sendEmail($userId, $event)
- {
- $userInfo = api_get_user_info($userId);
- if (!empty($this->sessionInfo)) {
- $courseTitle = $this->course['name'].' ('.$this->sessionInfo['title'].')';
- } else {
- $courseTitle = $this->course['name'];
- }
- api_mail_html(
- $userInfo['complete_name'],
- $userInfo['mail'],
- $subject,
- $emailBody
- );
- return true;
- }
- }
|