agenda.inc.php 217 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * @author: Julio Montoya <gugli100@gmail.com> BeezNest 2011 - Lots of fixes - UI improvements, security fixes,
  5. * @author: Patrick Cool, patrick.cool@UGent.be
  6. * @todo this code should be clean as well as the myagenda.inc.php - jmontoya
  7. * @package chamilo.calendar
  8. */
  9. /**
  10. * Code
  11. */
  12. // the variables for the days and the months
  13. // Defining the shorts for the days
  14. $DaysShort = api_get_week_days_short();
  15. // Defining the days of the week to allow translation of the days
  16. $DaysLong = api_get_week_days_long();
  17. // Defining the months of the year to allow translation of the months
  18. $MonthsLong = api_get_months_long();
  19. $htmlHeadXtra[] = to_javascript();
  20. $htmlHeadXtra[] = '<script>
  21. function setFocus(){
  22. $("#agenda_title").focus();
  23. }
  24. $(function() {
  25. setFocus();
  26. $("#select_form_id_search").change(function() {
  27. var temp ="&user_id="+$("#select_form_id_search").val();
  28. var position =String(window.location).indexOf("&user");
  29. var url_length = String(window.location).length;
  30. var url = String(window.location).substring(0,position)+temp;
  31. if (position > 0) {
  32. window.location.replace(url);
  33. } else {
  34. url = String(window.location)+temp;
  35. window.location.replace(url);
  36. }
  37. });
  38. });
  39. </script>';
  40. /**
  41. * Retrieves all the agenda items from the table
  42. * @author: Patrick Cool <patrick.cool@UGent.be>, Ghent University
  43. * @author Yannick Warnier <yannick.warnier@dokeos.com> - cleanup
  44. * @author Julio Montoya - Refactoring
  45. * @param integer $month: the integer value of the month we are viewing
  46. * @param integer $year: the 4-digit year indication e.g. 2005
  47. * @return array
  48. */
  49. function get_calendar_items($select_month, $select_year, $select_day = false)
  50. {
  51. $course_info = api_get_course_info();
  52. $select_month = intval($select_month);
  53. $select_year = intval($select_year);
  54. if ($select_day)
  55. $select_day = intval($select_day);
  56. if (!empty($select_month) && !empty($select_year)) {
  57. $show_all_current = " AND MONTH(start_date) = $select_month AND year(start_date) = $select_year";
  58. if ($select_day) {
  59. $show_all_current .= ' AND DAY(start_date) = '.$select_day;
  60. }
  61. $show_all_current_personal = " AND MONTH(date) = $select_month AND year(date) = $select_year";
  62. if ($select_day) {
  63. $show_all_current_personal .= ' AND DAY(date) = '.$select_day;
  64. }
  65. } else {
  66. $show_all_current = '';
  67. $show_all_current_personal = '';
  68. }
  69. // database variables
  70. $TABLEAGENDA = Database::get_course_table(TABLE_AGENDA);
  71. $TABLE_ITEM_PROPERTY = Database::get_course_table(TABLE_ITEM_PROPERTY);
  72. $group_memberships = GroupManager::get_group_ids($course_info['real_id'], api_get_user_id());
  73. $repeats = array();
  74. /* CONSTRUCT THE SQL STATEMENT */
  75. // by default we use the id of the current user. The course administrator can see the agenda of other users by using the user / group filter
  76. $user_id = api_get_user_id();
  77. if (isset($_SESSION['user'])) {
  78. $user_id = intval($_SESSION['user']);
  79. }
  80. $group_id = api_get_group_id();
  81. $session_condition = api_get_session_condition(api_get_session_id());
  82. if (api_is_allowed_to_edit(false, true) OR (api_get_course_setting('allow_user_edit_agenda') && !api_is_anonymous())) {
  83. // A.1. you are a course admin with a USER filter
  84. // => see only the messages of this specific user + the messages of the group (s)he is member of.
  85. if (!empty($_SESSION['user'])) {
  86. $group_memberships = GroupManager::get_group_ids($course_info['real_id'], $_SESSION['user']);
  87. $show_user = true;
  88. $new_group_memberships = array();
  89. foreach ($group_memberships as $id) {
  90. // did i have access to the same
  91. $has_access = GroupManager::user_has_access(api_get_user_id(), $id, GroupManager::GROUP_TOOL_CALENDAR);
  92. $result = GroupManager::get_group_properties($id);
  93. if ($has_access && $result['calendar_state'] != '0') {
  94. $new_group_memberships[] = $id;
  95. }
  96. }
  97. $group_memberships = $new_group_memberships;
  98. if (is_array($group_memberships) && count($group_memberships) > 0) {
  99. $sql = "SELECT
  100. agenda.*, ip.visibility, ip.to_group_id, ip.insert_user_id, ip.ref
  101. FROM ".$TABLEAGENDA." agenda, ".$TABLE_ITEM_PROPERTY." ip
  102. WHERE agenda.id = ip.ref ".$show_all_current."
  103. AND ip.tool='".TOOL_CALENDAR_EVENT."'
  104. AND ( ip.to_user_id = $user_id OR ip.to_group_id IN (0, ".implode(", ", $group_memberships).") )
  105. AND ip.visibility='1'
  106. $session_condition";
  107. } else {
  108. //AND ( ip.to_user_id=$user_id OR ip.to_group_id='0')
  109. $sql = "SELECT agenda.*, ip.visibility, ip.to_group_id, ip.insert_user_id, ip.ref
  110. FROM ".$TABLEAGENDA." agenda, ".$TABLE_ITEM_PROPERTY." ip
  111. WHERE agenda.id = ip.ref ".$show_all_current."
  112. AND ip.tool='".TOOL_CALENDAR_EVENT."'
  113. AND ( ip.to_user_id = $user_id )
  114. AND ip.visibility='1'
  115. $session_condition";
  116. }
  117. }
  118. // A.2. you are a course admin with a GROUP filter
  119. // => see only the messages of this specific group
  120. elseif (!empty($_SESSION['group'])) {
  121. if (!empty($group_id)) {
  122. $result = GroupManager::get_group_properties($group_id);
  123. $has_access = GroupManager::user_has_access(api_get_user_id(), $group_id, GroupManager::GROUP_TOOL_CALENDAR);
  124. //echo '<pre>';print_R($result);
  125. // lastedit
  126. if (!$has_access || $result['calendar_state'] == '0') {
  127. $group_id = 0;
  128. }
  129. }
  130. $sql = "SELECT agenda.*, ip.visibility, ip.to_group_id, ip.insert_user_id, ip.ref
  131. FROM ".$TABLEAGENDA." agenda, ".$TABLE_ITEM_PROPERTY." ip
  132. WHERE agenda.id = ip.ref ".$show_all_current."
  133. AND ip.tool='".TOOL_CALENDAR_EVENT."'
  134. AND ( ip.to_group_id=$group_id)
  135. AND ip.lastedit_type<>'CalendareventDeleted'
  136. $session_condition
  137. GROUP BY ip.ref";
  138. //removed - > AND toolitemproperties.visibility='1'
  139. }
  140. // A.3 you are a course admin without any group or user filter
  141. else {
  142. // A.3.a you are a course admin without user or group filter but WITH studentview
  143. // => see all the messages of all the users and groups without editing possibilities
  144. if (isset($_GET['isStudentView']) && $_GET['isStudentView'] == 'true') {
  145. $sql = "SELECT
  146. agenda.*, ip.visibility, ip.to_group_id, ip.insert_user_id, ip.ref
  147. FROM ".$TABLEAGENDA." agenda, ".$TABLE_ITEM_PROPERTY." ip
  148. WHERE agenda.id = ip.ref ".$show_all_current."
  149. AND ip.tool='".TOOL_CALENDAR_EVENT."'
  150. AND ip.visibility='1'
  151. $session_condition
  152. GROUP BY ip.ref
  153. ORDER $sort_item $sort";
  154. }
  155. // A.3.b you are a course admin or a student
  156. else {
  157. // A.3.b.1 you are a course admin without user or group filter and WITHOUT studentview (= the normal course admin view)
  158. // => see all the messages of all the users and groups with editing possibilities
  159. if (api_is_course_admin()) {
  160. $sql = "SELECT
  161. agenda.*, ip.visibility, ip.to_group_id, ip.insert_user_id, ip.ref
  162. FROM ".$TABLEAGENDA." agenda, ".$TABLE_ITEM_PROPERTY." ip
  163. WHERE agenda.id = ip.ref ".$show_all_current."
  164. AND ip.tool='".TOOL_CALENDAR_EVENT."'
  165. AND ( ip.visibility='0' OR ip.visibility='1')
  166. $session_condition
  167. GROUP BY ip.ref";
  168. } else {
  169. // A.3.b.2 you are a student with no group filter possibly showall
  170. //when showing all the events we do not show the group events
  171. //todo showing ALL events including the groups events that are available
  172. $sql = "SELECT
  173. agenda.*, ip.visibility, ip.to_group_id, ip.insert_user_id, ip.ref
  174. FROM ".$TABLEAGENDA." agenda, ".$TABLE_ITEM_PROPERTY." ip
  175. WHERE agenda.id = ip.ref ".$show_all_current."
  176. AND ip.tool='".TOOL_CALENDAR_EVENT."'
  177. AND ( ip.visibility='0' OR ip.visibility='1')
  178. $session_condition
  179. GROUP BY ip.ref";
  180. /*
  181. if (is_array($group_memberships) && count($group_memberships)>0)
  182. {
  183. echo $sql="SELECT
  184. agenda.*, toolitemproperties.*
  185. FROM ".$TABLEAGENDA." agenda, ".$TABLE_ITEM_PROPERTY." toolitemproperties
  186. WHERE agenda.id = toolitemproperties.ref ".$show_all_current."
  187. AND toolitemproperties.tool='".TOOL_CALENDAR_EVENT."'
  188. AND toolitemproperties.visibility='1' AND toolitemproperties.to_group_id IN (0, ".implode(", ", $group_memberships).")
  189. $session_condition
  190. GROUP BY toolitemproperties.ref
  191. ORDER BY start_date ".$sort;
  192. }
  193. else
  194. {
  195. $sql="SELECT
  196. agenda.*, toolitemproperties.*
  197. FROM ".$TABLEAGENDA." agenda, ".$TABLE_ITEM_PROPERTY." toolitemproperties
  198. WHERE agenda.id = toolitemproperties.ref ".$show_all_current."
  199. AND toolitemproperties.tool='".TOOL_CALENDAR_EVENT."'
  200. AND toolitemproperties.visibility='1' AND toolitemproperties.to_group_id='0'
  201. $session_condition
  202. GROUP BY toolitemproperties.ref
  203. ORDER BY start_date ".$sort;
  204. }
  205. */
  206. }
  207. }
  208. }
  209. } //if (is_allowed_to_edit() OR( api_get_course_setting('allow_user_edit_agenda') && !api_is_anonymous()))
  210. // B. you are a student
  211. else {
  212. if (is_array($group_memberships) && count($group_memberships) > 0) {
  213. $sql = "SELECT
  214. agenda.*, ip.visibility, ip.to_group_id, ip.insert_user_id, ip.ref
  215. FROM ".$TABLEAGENDA." agenda, ".$TABLE_ITEM_PROPERTY." ip
  216. WHERE agenda.id = ip.ref ".$show_all_current."
  217. AND ip.tool='".TOOL_CALENDAR_EVENT."'
  218. AND ( ip.to_user_id=$user_id OR ip.to_group_id IN (0, ".implode(", ", $group_memberships).") )
  219. AND ip.visibility='1'
  220. $session_condition";
  221. } else {
  222. if (api_get_user_id()) {
  223. $sql = "SELECT
  224. agenda.*, ip.visibility, ip.to_group_id, ip.insert_user_id, ip.ref
  225. FROM ".$TABLEAGENDA." agenda, ".$TABLE_ITEM_PROPERTY." ip
  226. WHERE agenda.id = ip.ref ".$show_all_current."
  227. AND ip.tool='".TOOL_CALENDAR_EVENT."'
  228. AND ( ip.to_user_id=$user_id OR ip.to_group_id='0')
  229. AND ip.visibility='1'
  230. $session_condition";
  231. } else {
  232. $sql = "SELECT
  233. agenda.*, ip.visibility, ip.to_group_id, ip.insert_user_id, ip.ref
  234. FROM ".$TABLEAGENDA." agenda, ".$TABLE_ITEM_PROPERTY." ip
  235. WHERE agenda.id = ip.ref ".$show_all_current."
  236. AND ip.tool='".TOOL_CALENDAR_EVENT."'
  237. AND ip.to_group_id='0'
  238. AND ip.visibility='1'
  239. $session_condition";
  240. }
  241. }
  242. } // you are a student
  243. $my_events = array();
  244. $avoid_doubles = array();
  245. $result = Database::query($sql);
  246. //Course venets
  247. while ($row = Database::fetch_array($result, 'ASSOC')) {
  248. $row['calendar_type'] = 'course';
  249. if (!in_array($row['id'], $avoid_doubles)) {
  250. if (!empty($row['start_date']) && $row['start_date'] != '0000-00-00 00:00:00') {
  251. $row['start_date'] = api_get_local_time($row['start_date']);
  252. $row['start_date_tms'] = api_strtotime($row['start_date']);
  253. }
  254. if (!empty($row['end_date']) && $row['end_date'] != '0000-00-00 00:00:00') {
  255. $row['end_date'] = api_get_local_time($row['end_date']);
  256. $row['end_date_tms'] = api_strtotime($row['end_date']);
  257. }
  258. $my_events[] = $row;
  259. $avoid_doubles[] = $row['id'];
  260. }
  261. }
  262. //Check my personal calendar items
  263. if (api_get_setting('allow_personal_agenda') == 'true' && empty($_SESSION['user']) && empty($_SESSION['group'])) {
  264. $tbl_personal_agenda = Database :: get_user_personal_table(TABLE_PERSONAL_AGENDA);
  265. // 1. creating the SQL statement for getting the personal agenda items in MONTH view
  266. $sql = "SELECT id, title, text as content , date as start_date, enddate as end_date, parent_event_id FROM ".$tbl_personal_agenda."
  267. WHERE user='".api_get_user_id()."' ".$show_all_current_personal;
  268. $result = Database::query($sql);
  269. while ($row = Database::fetch_array($result, 'ASSOC')) {
  270. $row['calendar_type'] = 'personal';
  271. if (!empty($row['start_date']) && $row['start_date'] != '0000-00-00 00:00:00') {
  272. $row['start_date'] = api_get_local_time($row['start_date']);
  273. $row['start_date_tms'] = api_strtotime($row['start_date']);
  274. }
  275. if (!empty($row['end_date']) && $row['end_date'] != '0000-00-00 00:00:00') {
  276. $row['end_date'] = api_get_local_time($row['end_date']);
  277. $row['end_date_tms'] = api_strtotime($row['end_date']);
  278. }
  279. $my_events[] = $row;
  280. }
  281. }
  282. //Check global agenda events
  283. if (empty($_SESSION['user']) && empty($_SESSION['group'])) {
  284. $table_agenda_system = Database :: get_main_table(TABLE_MAIN_SYSTEM_CALENDAR);
  285. $current_access_url_id = api_get_current_access_url_id();
  286. $sql = "SELECT DISTINCT id, title, content , start_date, end_date FROM ".$table_agenda_system."
  287. WHERE 1=1 ".$show_all_current." AND access_url_id = $current_access_url_id";
  288. $result = Database::query($sql);
  289. while ($row = Database::fetch_array($result, 'ASSOC')) {
  290. if (!empty($row['start_date']) && $row['start_date'] != '0000-00-00 00:00:00') {
  291. $row['start_date'] = api_get_local_time($row['start_date']);
  292. $row['start_date_tms'] = api_strtotime($row['start_date']);
  293. }
  294. if (!empty($row['end_date']) && $row['end_date'] != '0000-00-00 00:00:00') {
  295. $row['end_date'] = api_get_local_time($row['end_date']);
  296. $row['end_date_tms'] = api_strtotime($row['end_date']);
  297. }
  298. $row['calendar_type'] = 'global';
  299. $my_events[] = $row;
  300. }
  301. }
  302. return $my_events;
  303. }
  304. /**
  305. * show the mini calender of the given month
  306. * @author: Patrick Cool <patrick.cool@UGent.be>, Ghent University
  307. * @param array an array containing all the agenda items for the given month
  308. * @param integer $month: the integer value of the month we are viewing
  309. * @param integer $year: the 4-digit year indication e.g. 2005
  310. * @param string $monthName: the language variable for the mont name
  311. * @return html code
  312. * @todo refactor this so that $monthName is no longer needed as a parameter
  313. */
  314. function display_minimonthcalendar($agenda_items, $month, $year)
  315. {
  316. global $DaysShort, $MonthsLong;
  317. if (empty($month)) {
  318. $month = intval(date('m'));
  319. }
  320. if (empty($year)) {
  321. $month = date('Y');
  322. }
  323. $month_name = $MonthsLong[$month - 1];
  324. //Handle leap year
  325. $numberofdays = array(0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
  326. if (($year % 400 == 0) or ($year % 4 == 0 and $year % 100 <> 0))
  327. $numberofdays[2] = 29;
  328. //Get the first day of the month
  329. $dayone = getdate(mktime(0, 0, 0, $month, 1, $year));
  330. //Start the week on monday
  331. $startdayofweek = $dayone['wday'] <> 0 ? ($dayone['wday'] - 1) : 6;
  332. $backwardsURL = api_get_self()."?".api_get_cidreq()."&coursePath=".(empty($_GET['coursePath']) ? '' : Security::remove_XSS($_GET['coursePath']))."&courseCode=".(empty($_GET['courseCode']) ? '' : Security::remove_XSS($_GET['courseCode']))."&month=".($month == 1 ? 12 : $month - 1)."&year=".($month == 1 ? $year - 1 : $year);
  333. $forewardsURL = api_get_self()."?".api_get_cidreq()."&coursePath=".(empty($_GET['coursePath']) ? '' : Security::remove_XSS($_GET['coursePath']))."&courseCode=".(empty($_GET['courseCode']) ? '' : Security::remove_XSS($_GET['courseCode']))."&month=".($month == 12 ? 1 : $month + 1)."&year=".($month == 12 ? $year + 1 : $year);
  334. $month_link = Display::url($month_name." ".$year, api_get_self()."?".api_get_cidreq()."&month=".($month)."&year=".$year);
  335. $new_items = array();
  336. foreach ($agenda_items as $item) {
  337. $day = intval(substr($item["start_date"], 8, 2));
  338. $my_month = intval(substr($item["start_date"], 5, 2));
  339. if ($my_month == $month) {
  340. $new_items[$day][] = 1;
  341. }
  342. }
  343. $agenda_items = $new_items;
  344. echo "<table class=\"data_table\">",
  345. "<tr>",
  346. "<th width=\"10%\"><a href=\"", $backwardsURL, "\">".Display::return_icon('action_prev.png', get_lang('Previous'))." </a></th>",
  347. "<th width=\"80%\" colspan=\"5\">".$month_link."</th>",
  348. "<th width=\"10%\"><a href=\"", $forewardsURL, "\"> ".Display::return_icon('action_next.png', get_lang('Next'))." </a></th></tr>";
  349. echo "<tr>";
  350. for ($ii = 1; $ii < 8; $ii++) {
  351. echo "<td class=\"weekdays\">", $DaysShort[$ii % 7], "</td>";
  352. }
  353. echo "</tr>";
  354. $curday = -1;
  355. $today = getdate();
  356. while ($curday <= $numberofdays[$month]) {
  357. echo "<tr>";
  358. for ($ii = 0; $ii < 7; $ii++) {
  359. if (($curday == -1) && ($ii == $startdayofweek)) {
  360. $curday = 1;
  361. }
  362. if (($curday > 0) && ($curday <= $numberofdays[$month])) {
  363. $bgcolor = $ii < 5 ? $class = "class=\"days_week\"" : $class = "class=\"days_weekend\"";
  364. $dayheader = "$curday";
  365. if (($curday == $today['mday']) && ($year == $today['year']) && ($month == $today['mon'])) {
  366. $dayheader = "$curday";
  367. $class = "class=\"days_today\"";
  368. }
  369. echo "<td ".$class.">";
  370. if (!empty($agenda_items[$curday])) {
  371. echo "<a href=\"".api_get_self()."?".api_get_cidreq()."&amp;sort=asc&amp;toolgroup=".api_get_group_id()."&amp;action=view&amp;view=day&amp;day=".$curday."&amp;month=".$month."&amp;year=".$year."#".$curday."\">".$dayheader."</a>";
  372. } else {
  373. echo $dayheader;
  374. }
  375. // "a".$dayheader." <span class=\"agendaitem\">".$agenda_items[$curday]."</span>";
  376. echo "</td>";
  377. $curday++;
  378. } else {
  379. echo "<td></td>";
  380. }
  381. }
  382. echo "</tr>";
  383. }
  384. echo "</table>";
  385. }
  386. /**
  387. * show the calender of the given month
  388. * @author: Patrick Cool <patrick.cool@UGent.be>, Ghent University
  389. * @author Julio Montoya - adding some nice styles
  390. * @param integer $month: the integer value of the month we are viewing
  391. * @param integer $year: the 4-digit year indication e.g. 2005
  392. * @return html code
  393. */
  394. function display_monthcalendar($month, $year, $agenda_items)
  395. {
  396. global $MonthsLong;
  397. global $DaysShort;
  398. global $origin;
  399. //Handle leap year
  400. $numberofdays = array(0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
  401. if (($year % 400 == 0) or ($year % 4 == 0 and $year % 100 <> 0))
  402. $numberofdays[2] = 29;
  403. //Get the first day of the month
  404. $dayone = getdate(mktime(0, 0, 0, $month, 1, $year));
  405. //Start the week on monday
  406. $startdayofweek = $dayone['wday'] <> 0 ? ($dayone['wday'] - 1) : 6;
  407. $backwardsURL = api_get_self()."?".api_get_cidreq()."&view=".Security::remove_XSS($_GET['view'])."&origin=$origin&amp;month=".($month == 1 ? 12 : $month - 1)."&amp;year=".($month == 1 ? $year - 1 : $year);
  408. $forewardsURL = api_get_self()."?".api_get_cidreq()."&view=".Security::remove_XSS($_GET['view'])."&origin=$origin&amp;month=".($month == 12 ? 1 : $month + 1)."&amp;year=".($month == 12 ? $year + 1 : $year);
  409. $new_month = $month - 1;
  410. echo '<table id="agenda_list">';
  411. echo '<tr>';
  412. echo '<th width="10%"><a href="'.$backwardsURL.'">'.Display::return_icon('action_prev.png', get_lang('Previous'), array(), 32).'</a></th>';
  413. echo '<th width="80%" colspan="5"><br /><h3>'.$MonthsLong[$new_month].' '.$year.'</h3></th>';
  414. echo '<th width="10%"><a href="'.$forewardsURL.'"> '.Display::return_icon('action_next.png', get_lang('Next'), array(), 32).'</a></th>';
  415. echo '</tr>';
  416. echo '<tr>';
  417. for ($ii = 1; $ii < 8; $ii++) {
  418. echo '<td class="weekdays" width="14%">'.$DaysShort[$ii % 7].'</td>';
  419. }
  420. echo '</tr>';
  421. $curday = -1;
  422. $today = getdate();
  423. $new_items = array();
  424. foreach ($agenda_items as $item) {
  425. $day = intval(substr($item["start_date"], 8, 2));
  426. $my_month = intval(substr($item["start_date"], 5, 2));
  427. if ($my_month == $month) {
  428. $new_items[$day][] = $item;
  429. }
  430. }
  431. $agenda_items = $new_items;
  432. while ($curday <= $numberofdays[$month]) {
  433. echo '<tr>';
  434. //week
  435. for ($ii = 0; $ii < 7; $ii++) {
  436. if (($curday == -1) && ($ii == $startdayofweek)) {
  437. $curday = 1;
  438. }
  439. if (($curday > 0) && ($curday <= $numberofdays[$month])) {
  440. $bgcolor = $ii < 5 ? 'class="row_odd"' : 'class="row_even"';
  441. $dayheader = Display::div($curday, array('class' => 'agenda_day'));
  442. if (key_exists($curday, $agenda_items)) {
  443. $dayheader = Display::div($curday, array('class' => 'agenda_day'));
  444. $events_in_day = msort($agenda_items[$curday], 'start_date_tms');
  445. foreach ($events_in_day as $value) {
  446. $some_content = false;
  447. $month_start_date = (int) substr($value['start_date'], 5, 2);
  448. if ($month == $month_start_date) {
  449. $some_content = true;
  450. $start_time = api_format_date($value['start_date'], TIME_NO_SEC_FORMAT);
  451. $end_time = '';
  452. if (!empty($value['end_date']) && $value['end_date'] != '0000-00-00 00:00:00') {
  453. $end_time = '-&nbsp;<i>'.api_format_date($value['end_date'], DATE_TIME_FORMAT_LONG).'</i>';
  454. }
  455. $complete_time = '<i>'.api_format_date($value['start_date'], DATE_TIME_FORMAT_LONG).'</i>&nbsp;'.$end_time;
  456. $time = '<i>'.$start_time.'</i>';
  457. switch ($value['calendar_type']) {
  458. case 'personal':
  459. $bg_color = '#D0E7F4';
  460. $icon = Display::return_icon('user.png', get_lang('MyAgenda'), array(), 22);
  461. break;
  462. case 'global':
  463. $bg_color = '#FFBC89';
  464. $icon = Display::return_icon('view_remove.png', get_lang('GlobalEvent'), array(), 22);
  465. break;
  466. case 'course':
  467. $bg_color = '#CAFFAA';
  468. $value['course_name'] = isset($value['course_name']) ? $value['course_name'] : null;
  469. $value['url'] = isset($value['url']) ? $value['url'] : null;
  470. $icon = Display::url(Display::return_icon('course.png', $value['course_name'].' '.get_lang('Course'), array(), 22), $value['url']);
  471. break;
  472. default:
  473. break;
  474. }
  475. $icon = Display::div($icon, array('style' => 'float:right'));
  476. //Setting a personal event to green
  477. $dayheader.= '<div class="rounded_div_agenda" style="background-color:'.$bg_color.';">';
  478. //Link to bubble
  479. $url = Display::url(cut($value['title'], 40), '#', array('id' => $value['calendar_type'].'_'.$value['id'], 'class' => 'opener'));
  480. $dayheader .= $time.' '.$icon.' '.Display::div($url);
  481. //Hidden content
  482. $content = Display::div($icon.Display::tag('h1', $value['title']).$complete_time.'<hr />'.$value['content']);
  483. //Main div
  484. $dayheader .= Display::div($content, array('id' => 'main_'.$value['calendar_type'].'_'.$value['id'], 'class' => 'dialog', 'style' => 'display:none'));
  485. $dayheader .= '</div>';
  486. }
  487. //Do not show links with no content
  488. if (!$some_content) {
  489. $dayheader = Display::div($curday, array('class' => 'agenda_day'));
  490. }
  491. }
  492. }
  493. if (($curday == $today['mday']) && ($year == $today['year']) && ($month == $today['mon'])) {
  494. echo '<td class="days_today"'.$bgcolor.' style="height:122px;width:10%">'.$dayheader;
  495. } else {
  496. $class = 'days_week';
  497. echo '<td class="'.$class.'" '.$bgcolor.' style="height:122px;width:10%">'.$dayheader;
  498. }
  499. echo '</td>';
  500. $curday++;
  501. } else {
  502. echo '<td>&nbsp;</td>';
  503. }
  504. }
  505. echo '</tr>';
  506. } // end while
  507. echo '</table>';
  508. }
  509. /**
  510. * returns all the javascript that is required for easily selecting the target people/groups this goes into the $htmlHeadXtra[] array
  511. * @author: Patrick Cool <patrick.cool@UGent.be>, Ghent University
  512. * @return javascript code
  513. */
  514. function to_javascript()
  515. {
  516. return "<script type=\"text/javascript\" language=\"javascript\">
  517. $(function() {
  518. //js used when generating images on the fly see function Tracking::show_course_detail()
  519. $(\".dialog\").dialog(\"destroy\");
  520. $(\".dialog\").dialog({
  521. autoOpen: false,
  522. show: \"blind\",
  523. resizable: false,
  524. height:300,
  525. width:550,
  526. modal: true
  527. });
  528. $(\".opener\").click(function() {
  529. var my_id = $(this).attr('id');
  530. var big_image = '#main_' + my_id;
  531. $( big_image ).dialog(\"open\");
  532. return false;
  533. });
  534. });
  535. <!-- Begin javascript menu swapper
  536. function move(fbox, tbox)
  537. {
  538. // @todo : change associative arrays arrLookup and arrLookupTitle that use firstname/lastnam as key
  539. // so, pb with homonyms
  540. var arrFbox = new Array();
  541. var arrTbox = new Array();
  542. var arrLookup = new Array();
  543. var arrLookupTitle = new Array();
  544. var i;
  545. for (i = 0; i < tbox.options.length; i++)
  546. {
  547. arrLookup[tbox.options[i].text] = tbox.options[i].value;
  548. arrLookupTitle[tbox.options[i].text] = tbox.options[i].title;
  549. arrTbox[i] = tbox.options[i].text;
  550. }
  551. var fLength = 0;
  552. var tLength = arrTbox.length;
  553. for(i = 0; i < fbox.options.length; i++)
  554. {
  555. arrLookup[fbox.options[i].text] = fbox.options[i].value;
  556. arrLookupTitle[fbox.options[i].text] = fbox.options[i].title;
  557. if (fbox.options[i].selected && fbox.options[i].value != \"\")
  558. {
  559. arrTbox[tLength] = fbox.options[i].text;
  560. tLength++;
  561. }
  562. else
  563. {
  564. arrFbox[fLength] = fbox.options[i].text;
  565. fLength++;
  566. }
  567. }
  568. //arrFbox.sort();
  569. //arrTbox.sort()
  570. var arrFboxGroup = new Array();
  571. var arrFboxUser = new Array();
  572. var prefix_x;
  573. for (x = 0; x < arrFbox.length; x++) {
  574. prefix_x = arrFbox[x].substring(0,2);
  575. if (prefix_x == 'G:') {
  576. arrFboxGroup.push(arrFbox[x]);
  577. } else {
  578. arrFboxUser.push(arrFbox[x]);
  579. }
  580. }
  581. arrFboxGroup.sort();
  582. arrFboxUser.sort();
  583. arrFbox = arrFboxGroup.concat(arrFboxUser);
  584. var arrTboxGroup = new Array();
  585. var arrTboxUser = new Array();
  586. var prefix_y;
  587. for (y = 0; y < arrTbox.length; y++) {
  588. prefix_y = arrTbox[y].substring(0,2);
  589. if (prefix_y == 'G:') {
  590. arrTboxGroup.push(arrTbox[y]);
  591. } else {
  592. arrTboxUser.push(arrTbox[y]);
  593. }
  594. }
  595. arrTboxGroup.sort();
  596. arrTboxUser.sort();
  597. arrTbox = arrTboxGroup.concat(arrTboxUser);
  598. fbox.length = 0;
  599. tbox.length = 0;
  600. var c;
  601. for(c = 0; c < arrFbox.length; c++)
  602. {
  603. var no = new Option();
  604. no.value = arrLookup[arrFbox[c]];
  605. no.text = arrFbox[c];
  606. no.title = arrLookupTitle[arrFbox[c]];
  607. fbox[c] = no;
  608. }
  609. for(c = 0; c < arrTbox.length; c++)
  610. {
  611. var no = new Option();
  612. no.value = arrLookup[arrTbox[c]];
  613. no.text = arrTbox[c];
  614. no.title = arrLookupTitle[arrTbox[c]];
  615. tbox[c] = no;
  616. }
  617. }
  618. function checkDate(month, day, year)
  619. {
  620. var monthLength =
  621. new Array(31,28,31,30,31,30,31,31,30,31,30,31);
  622. if (!day || !month || !year)
  623. return false;
  624. // check for bisestile year
  625. if (year/4 == parseInt(year/4))
  626. monthLength[1] = 29;
  627. if (month < 1 || month > 12)
  628. return false;
  629. if (day > monthLength[month-1])
  630. return false;
  631. return true;
  632. }
  633. function mktime() {
  634. var no, ma = 0, mb = 0, i = 0, d = new Date(), argv = arguments, argc = argv.length;
  635. d.setHours(0,0,0); d.setDate(1); d.setMonth(1); d.setYear(1972);
  636. var dateManip = {
  637. 0: function(tt){ return d.setHours(tt); },
  638. 1: function(tt){ return d.setMinutes(tt); },
  639. 2: function(tt){ set = d.setSeconds(tt); mb = d.getDate() - 1; return set; },
  640. 3: function(tt){ set = d.setMonth(parseInt(tt)-1); ma = d.getFullYear() - 1972; return set; },
  641. 4: function(tt){ return d.setDate(tt+mb); },
  642. 5: function(tt){ return d.setYear(tt+ma); }
  643. };
  644. for( i = 0; i < argc; i++ ){
  645. no = parseInt(argv[i]*1);
  646. if (isNaN(no)) {
  647. return false;
  648. } else {
  649. // arg is number, lets manipulate date object
  650. if(!dateManip[i](no)){
  651. // failed
  652. return false;
  653. }
  654. }
  655. }
  656. return Math.floor(d.getTime()/1000);
  657. }
  658. function validate() {
  659. var f = document.new_calendar_item;
  660. f.submit();
  661. return true;
  662. }
  663. function selectAll(cbList,bSelect,showwarning) {
  664. var start_day = document.new_calendar_item.fday.value;
  665. var start_month = document.new_calendar_item.fmonth.value;
  666. var start_year = document.new_calendar_item.fyear.value;
  667. var start_hour = document.new_calendar_item.fhour.value;
  668. var start_minute = document.new_calendar_item.fminute.value;
  669. var start_date = mktime(start_hour,start_minute,0,start_month,start_day,start_year)
  670. var ends_day = document.new_calendar_item.end_fday.value;
  671. var ends_month = document.new_calendar_item.end_fmonth.value;
  672. var ends_year = document.new_calendar_item.end_fyear.value;
  673. var ends_hour = document.new_calendar_item.end_fhour.value;
  674. var ends_minute = document.new_calendar_item.end_fminute.value;
  675. var ends_date = mktime(ends_hour,ends_minute,0,ends_month,ends_day,ends_year)
  676. msg_err1 = document.getElementById(\"err_date\");
  677. msg_err2 = document.getElementById(\"err_start_date\");
  678. msg_err3 = document.getElementById(\"err_end_date\");
  679. msg_err4 = document.getElementById(\"err_title\");
  680. var error = false;
  681. if (start_date > ends_date) {
  682. if ($('#empty_end_date').is(':checked')) {
  683. msg_err1.innerHTML=\"\";
  684. msg_err2.innerHTML=\"\";
  685. msg_err3.innerHTML=\"\";
  686. } else {
  687. error = true;
  688. msg_err1.style.display =\"block\";
  689. msg_err1.innerHTML=\"".get_lang('EndDateCannotBeBeforeTheStartDate')."\";
  690. msg_err2.innerHTML=\"\";
  691. msg_err3.innerHTML=\"\";
  692. }
  693. }
  694. if (!checkDate(start_month,start_day,start_year)) {
  695. msg_err2.style.display =\"block\";
  696. msg_err2.innerHTML=\"".get_lang('InvalidDate')."\";
  697. msg_err1.innerHTML=\"\";
  698. msg_err3.innerHTML=\"\";
  699. error = true;
  700. }
  701. if (!checkDate(ends_month,ends_day,ends_year)) {
  702. msg_err3.style.display =\"block\";
  703. msg_err3.innerHTML=\"".get_lang('InvalidDate')."\";
  704. msg_err1.innerHTML=\"\";msg_err2.innerHTML=\"\";
  705. error = true;
  706. }
  707. if (document.new_calendar_item.title.value == '') {
  708. msg_err4.style.display =\"block\";
  709. msg_err4.innerHTML=\"".get_lang('FieldRequired')."\";
  710. msg_err1.innerHTML=\"\";msg_err2.innerHTML=\"\";msg_err3.innerHTML=\"\";
  711. error = true;
  712. }
  713. if (error == false) {
  714. if (cbList) {
  715. if (cbList.length < 1) {
  716. if (!confirm(\"".get_lang('Send2All')."\")) {
  717. return false;
  718. }
  719. }
  720. for (var i=0; i<cbList.length; i++)
  721. cbList[i].selected = cbList[i].checked = bSelect;
  722. }
  723. document.new_calendar_item.submit();
  724. }
  725. }
  726. function reverseAll(cbList)
  727. {
  728. for (var i=0; i<cbList.length; i++)
  729. {
  730. cbList[i].checked = !(cbList[i].checked)
  731. cbList[i].selected = !(cbList[i].selected)
  732. }
  733. }
  734. function plus_attachment() {
  735. if (document.getElementById('options').style.display == 'none') {
  736. document.getElementById('options').style.display = 'block';
  737. document.getElementById('plus').innerHTML='&nbsp;<img style=\"vertical-align:middle;\" src=\"../img/div_hide.gif\" alt=\"\" />&nbsp;".get_lang('AddAnAttachment')."';
  738. } else {
  739. document.getElementById('options').style.display = 'none';
  740. document.getElementById('plus').innerHTML='&nbsp;<img style=\"vertical-align:middle;\" src=\"../img/div_show.gif\" alt=\"\" />&nbsp;".get_lang('AddAnAttachment')."';
  741. }
  742. }
  743. function plus_repeated_event() {
  744. if (document.getElementById('options2').style.display == 'none') {
  745. document.getElementById('options2').style.display = 'block';
  746. document.getElementById('plus2').innerHTML='&nbsp;<img style=\"vertical-align:middle;\" src=\"../img/div_hide.gif\" alt=\"\" />&nbsp;".get_lang('RepeatEvent')."';
  747. } else {
  748. document.getElementById('options2').style.display = 'none';
  749. document.getElementById('plus2').innerHTML='&nbsp;<img style=\"vertical-align:middle;\" src=\"../img/div_show.gif\" alt=\"\" />&nbsp;".get_lang('RepeatEvent')."';
  750. }
  751. }
  752. /*
  753. function plus_ical() {
  754. if (document.getElementById('icalform').style.display == 'none') {
  755. document.getElementById('icalform').style.display = 'block';
  756. document.getElementById('plusical').innerHTML='';
  757. }
  758. }
  759. */
  760. // End -->
  761. </script>";
  762. }
  763. /**
  764. * returns the javascript for setting a filter. This is a jump menu
  765. * @author: Patrick Cool <patrick.cool@UGent.be>, Ghent University
  766. * @return javascript code
  767. */
  768. function user_group_filter_javascript()
  769. {
  770. return "<script language=\"JavaScript\" type=\"text/JavaScript\">
  771. <!--
  772. function MM_jumpMenu(targ,selObj,restore){
  773. eval(targ+\".location='\"+selObj.options[selObj.selectedIndex].value+\"'\");
  774. if (restore) selObj.selectedIndex=0;
  775. }
  776. //-->
  777. </script>
  778. ";
  779. }
  780. /**
  781. * this function gets all the users of the current course
  782. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  783. * @return array: associative array where the key is the id of the user and the value is an array containing
  784. the first name, the last name, the user id
  785. */
  786. function get_course_users()
  787. {
  788. global $_cid;
  789. $tbl_user = Database::get_main_table(TABLE_MAIN_USER);
  790. $tbl_courseUser = Database::get_main_table(TABLE_MAIN_COURSE_USER);
  791. $tbl_session_course_user = Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
  792. // not 100% if this is necessary, this however prevents a notice
  793. if (!isset($courseadmin_filter)) {
  794. $courseadmin_filter = '';
  795. }
  796. //
  797. $order_clause = api_sort_by_first_name() ? ' ORDER BY u.firstname, u.lastname' : ' ORDER BY u.lastname, u.firstname';
  798. $sql = "SELECT u.user_id uid, u.lastname lastName, u.firstname firstName, u.username
  799. FROM $tbl_user as u, $tbl_courseUser as cu
  800. WHERE cu.course_code = '".api_get_course_id()."'
  801. AND cu.user_id = u.user_id $courseadmin_filter".$order_clause;
  802. $result = Database::query($sql);
  803. while ($user = Database::fetch_array($result)) {
  804. $users[$user[0]] = $user;
  805. }
  806. $session_id = api_get_session_id();
  807. if (!empty($session_id)) {
  808. $users = array();
  809. $sql = "SELECT u.user_id uid, u.lastname lastName, u.firstName firstName, u.username
  810. FROM $tbl_session_course_user AS session_course_user
  811. INNER JOIN $tbl_user u ON u.user_id = session_course_user.id_user
  812. WHERE id_session = ".$session_id."
  813. AND course_code = '".api_get_course_id()."'";
  814. $result = Database::query($sql);
  815. while ($user = Database::fetch_array($result)) {
  816. $users[$user[0]] = $user;
  817. }
  818. }
  819. return $users;
  820. }
  821. /**
  822. * this function gets all the groups of the course
  823. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  824. * @return array
  825. */
  826. function get_course_groups()
  827. {
  828. $group_list = array();
  829. $group_list = CourseManager::get_group_list_of_course(api_get_course_id(), api_get_session_id());
  830. return $group_list;
  831. }
  832. /**
  833. * this function shows the form for sending a message to a specific group or user.
  834. * @author: Patrick Cool <patrick.cool@UGent.be>, Ghent University
  835. *
  836. * @return html code
  837. */
  838. function show_to_form($to_already_selected)
  839. {
  840. $order = 'lastname';
  841. if (api_is_western_name_order()) {
  842. $order = 'firstname';
  843. }
  844. $user_list = CourseManager::get_user_list_from_course_code(api_get_course_id(), api_get_session_id(), null, $order);
  845. $group_list = CourseManager::get_group_list_of_course(api_get_course_id(), api_get_session_id());
  846. construct_not_selected_select_form($group_list, $user_list, $to_already_selected);
  847. }
  848. /**
  849. * this function shows the form with the user that were not selected
  850. * @author: Patrick Cool <patrick.cool@UGent.be>, Ghent University
  851. * @return html code
  852. */
  853. function construct_not_selected_select_form($group_list = null, $user_list = null, $to_already_selected = array())
  854. {
  855. echo '<select data-placeholder="'.get_lang('Select').'" style="width:150px;" class="chzn-select" id="selected_form_id_search" name="selected_form[]" multiple="multiple">';
  856. // Adding the groups to the select form
  857. if (isset($to_already_selected) && $to_already_selected === 'everyone') {
  858. echo '<option selected="selected" value="everyone">'.get_lang('Everyone').'</option>';
  859. //} else {
  860. } else {
  861. echo '<option value="everyone">'.get_lang('Everyone').'</option>';
  862. }
  863. if (is_array($group_list)) {
  864. echo '<optgroup label="'.get_lang('Groups').'">';
  865. foreach ($group_list as $this_group) {
  866. //api_display_normal_message("group " . $thisGroup[id] . $thisGroup[name]);
  867. if (!is_array($to_already_selected) || !in_array("GROUP:".$this_group['id'], $to_already_selected)) {
  868. // $to_already_selected is the array containing the groups (and users) that are already selected
  869. echo "<option value=\"GROUP:".$this_group['id']."\">",
  870. "G: ", $this_group['name'], " &ndash; ".$this_group['userNb']." ".get_lang('Users').
  871. "</option>";
  872. }
  873. }
  874. // a divider
  875. }
  876. echo "</optgroup>";
  877. // adding the individual users to the select form
  878. if (!empty($user_list)) {
  879. echo '<optgroup label="'.get_lang('Users').'">';
  880. foreach ($user_list as $this_user) {
  881. // $to_already_selected is the array containing the users (and groups) that are already selected
  882. if (!is_array($to_already_selected) || !in_array("USER:".$this_user['user_id'], $to_already_selected)) {
  883. $username = api_htmlentities(sprintf(get_lang('LoginX'), $this_user['username']), ENT_QUOTES);
  884. $user_info = api_get_person_name($this_user['firstname'], $this_user['lastname']).' ('.$this_user['username'].')';
  885. echo "<option title='$username' value='USER:".$this_user['user_id']."'>$user_info</option>";
  886. }
  887. }
  888. echo "</optgroup>";
  889. }
  890. echo "</select>";
  891. }
  892. function show_to($filter = 0, $id = null)
  893. {
  894. $order = 'lastname';
  895. if (api_is_western_name_order()) {
  896. $order = 'firstname';
  897. }
  898. $user_list = CourseManager::get_user_list_from_course_code(api_get_course_id(), api_get_session_id(), null, $order);
  899. $group_list = CourseManager::get_group_list_of_course(api_get_course_id(), api_get_session_id());
  900. return construct_to_select_form($group_list, $user_list, $filter, $id);
  901. }
  902. function construct_to_select_form($group_list = null, $user_list = null, $filter = 0, $id = null) {
  903. $result = '<form class="form-search" style="margin-top:3px;">';
  904. $result .= '<select data-placeholder= "'.get_lang('FilterAll').'" name="sel_to" class="chzn-select" id="select_form_id_search">';
  905. // adding the groups to the select form
  906. $result .= '<option value=""></option>';
  907. $result .= '<option value="0">'.get_lang('FilterAll').'</option>';
  908. if (is_array($group_list)) {
  909. $result .= '<optgroup label="'.get_lang('FilterByGroup').'">';
  910. $this_group_name = count($group_list);
  911. foreach ($group_list as $this_group) {
  912. $group_filter = 'G:'.$this_group['id'];
  913. $selected = $group_filter == $filter ? "selected" : null;
  914. $result .= "<option value=G:".$this_group['id']." ".$selected.">".$this_group['name']."</option>";
  915. }
  916. $result .= "</optgroup>";
  917. }
  918. // adding the individual users to the select form
  919. if (!empty($user_list)) {
  920. $result .= '<optgroup label="'.get_lang('FilterByUser').'">';
  921. foreach ($user_list as $this_user) {
  922. $username = api_htmlentities(sprintf(get_lang('LoginX'), $this_user['username']), ENT_QUOTES);
  923. $user_info = api_get_person_name($this_user['firstname'], $this_user['lastname']).' ('.$this_user['username'].')';
  924. $selected = $this_user['user_id'] == $filter ? "selected" : null;
  925. $result .= "<option title='$username' value=".$this_user['user_id']." ".$selected.">$user_info</option>";
  926. }
  927. $result .= "</optgroup>";
  928. }
  929. $result .= "</select>";
  930. $result .= "</form>";
  931. return $result;
  932. }
  933. /**
  934. * This function shows the form with the user that were selected
  935. * @author: Patrick Cool <patrick.cool@UGent.be>, Ghent University
  936. * @return html code
  937. */
  938. function construct_selected_select_form($group_list = null, $user_list = null, $to_already_selected)
  939. {
  940. // we separate the $to_already_selected array (containing groups AND users into
  941. // two separate arrays
  942. if (is_array($to_already_selected)) {
  943. $groupuser = separate_users_groups($to_already_selected);
  944. }
  945. $groups_to_already_selected = $groupuser['groups'];
  946. $users_to_already_selected = $groupuser['users'];
  947. // we load all the groups and all the users into a reference array that we use to search the name of the group / user
  948. $ref_array_groups = get_course_groups();
  949. $ref_array_users = get_course_users();
  950. // we construct the form of the already selected groups / users
  951. echo "<select id=\"selected_form2\" name=\"selectedform2[]\" size=\"5\" multiple=\"multiple\" style=\"width:200px\">";
  952. if (is_array($to_already_selected)) {
  953. $select_options_group = array();
  954. $select_options_user = array();
  955. $select_options_groupuser = array();
  956. foreach ($to_already_selected as $groupuser) {
  957. list($type, $id) = explode(":", $groupuser);
  958. if ($type == "GROUP") {
  959. $select_options_group[] = "<option value=\"".$groupuser."\">G: ".$ref_array_groups[$id]['name']."</option>";
  960. //echo "<option value=\"".$groupuser."\">G: ".$ref_array_groups[$id]['name']."</option>";
  961. } else {
  962. $username = api_htmlentities(sprintf(get_lang('LoginX'), $ref_array_users[$id]['username']), ENT_QUOTES);
  963. $user_info = api_get_person_name($ref_array_users[$id]['firstName'], $ref_array_users[$id]['lastName']);
  964. $select_options_user[] = "<option title='$username' value='".$groupuser."'>$user_info</option>";
  965. //echo "<option value=\"".$groupuser."\">".api_get_person_name($ref_array_users[$id]['firstName'], $ref_array_users[$id]['lastName'])."</option>";
  966. }
  967. }
  968. $select_options_group[] = "<option value=\"\">--------------------------------------------</option>";
  969. $select_options_groupuser = array_merge($select_options_group, $select_options_user);
  970. foreach ($select_options_groupuser as $select_options) {
  971. echo $select_options;
  972. }
  973. } else {
  974. if ($to_already_selected == 'everyone') {
  975. // adding the groups to the select form
  976. if (is_array($group_list)) {
  977. foreach ($group_list as $this_group) {
  978. //api_display_normal_message("group " . $thisGroup[id] . $thisGroup[name]);
  979. if (!is_array($to_already_selected) || !in_array("GROUP:".$this_group['id'], $to_already_selected)) { // $to_already_selected is the array containing the groups (and users) that are already selected
  980. echo "<option value=\"GROUP:".$this_group['id']."\">",
  981. "G: ", $this_group['name'], " &ndash; ".$this_group['userNb']." ".get_lang('Users').
  982. "</option>";
  983. }
  984. }
  985. }
  986. echo "<option value=\"\">--------------------------------------------</option>";
  987. // adding the individual users to the select form
  988. foreach ($user_list as $this_user) {
  989. if (!is_array($to_already_selected) || !in_array("USER:".$this_user['uid'], $to_already_selected)) { // $to_already_selected is the array containing the users (and groups) that are already selected
  990. echo "<option value=\"USER:", $this_user['uid'], "\">",
  991. "", api_get_person_name($this_user['firstName'], $this_user['lastName']),
  992. "</option>";
  993. }
  994. }
  995. }
  996. }
  997. echo "</select>";
  998. }
  999. /**
  1000. * This function stores the Agenda Item in the table calendar_event and updates the item_property table also
  1001. * @author: Patrick Cool <patrick.cool@UGent.be>, Ghent University
  1002. * @return integer the id of the last added agenda item
  1003. */
  1004. function store_new_agenda_item()
  1005. {
  1006. global $_course;
  1007. $TABLEAGENDA = Database::get_course_table(TABLE_AGENDA);
  1008. $t_agenda_repeat = Database::get_course_Table(TABLE_AGENDA_REPEAT);
  1009. $course_id = api_get_course_int_id();
  1010. // some filtering of the input data
  1011. $title = trim($_POST['title']); // no html allowed in the title
  1012. $content = trim($_POST['content']);
  1013. $start_date = (int) $_POST['fyear']."-".(int) $_POST['fmonth']."-".(int) $_POST['fday']." ".(int) $_POST['fhour'].":".(int) $_POST['fminute'].":00";
  1014. $end_date = (int) $_POST['end_fyear']."-".(int) $_POST['end_fmonth']."-".(int) $_POST['end_fday']." ".(int) $_POST['end_fhour'].":".(int) $_POST['end_fminute'].":00";
  1015. $title = Database::escape_string($title);
  1016. $content = Database::escape_string($content);
  1017. $start_date = Database::escape_string($start_date);
  1018. $end_date = Database::escape_string($end_date);
  1019. if ($_POST['empty_end_date'] == 'on') {
  1020. $end_date = "0000-00-00 00:00:00";
  1021. }
  1022. // store in the table calendar_event
  1023. $sql = "INSERT INTO ".$TABLEAGENDA." (c_id, title,content, start_date, end_date)
  1024. VALUES ($course_id, '".$title."','".$content."', '".$start_date."','".$end_date."')";
  1025. $result = Database::query($sql);
  1026. $last_id = Database::insert_id();
  1027. // store in last_tooledit (first the groups, then the users
  1028. $to = $_POST['selectedform'];
  1029. if ((!is_null($to)) || (!empty($_SESSION['toolgroup']))) { // !is_null($to): when no user is selected we send it to everyone
  1030. //$send_to=separate_users_groups($to);
  1031. $send_to = separate_users_groups(explode('|', $to));
  1032. // storing the selected groups
  1033. if (is_array($send_to['groups'])) {
  1034. foreach ($send_to['groups'] as $group) {
  1035. api_item_property_update($_course, TOOL_CALENDAR_EVENT, $last_id, "AgendaAdded", api_get_user_id(), $group, '', $start_date, $end_date);
  1036. }
  1037. }
  1038. // storing the selected users
  1039. if (is_array($send_to['users'])) {
  1040. foreach ($send_to['users'] as $user) {
  1041. api_item_property_update($_course, TOOL_CALENDAR_EVENT, $last_id, "AgendaAdded", api_get_user_id(), '', $user, $start_date, $end_date);
  1042. }
  1043. }
  1044. } else { // the message is sent to everyone, so we set the group to 0
  1045. api_item_property_update($_course, TOOL_CALENDAR_EVENT, $last_id, "AgendaAdded", api_get_user_id(), '', '', $start_date, $end_date);
  1046. }
  1047. // storing the resources
  1048. store_resources($_SESSION['source_type'], $last_id);
  1049. $course_id = api_get_course_int_id();
  1050. //if repetitive, insert element into agenda_repeat table
  1051. if (!empty($_POST['repeat']) && !empty($_POST['repeat_type'])) {
  1052. if (!empty($_POST['repeat_end_year']) && !empty($_POST['repeat_end_month']) && !empty($_POST['repeat_end_day'])) {
  1053. $end_y = intval($_POST['repeat_end_year']);
  1054. $end_m = intval($_POST['repeat_end_month']);
  1055. $end_d = intval($_POST['repeat_end_day']);
  1056. $end = mktime((int) $_POST['fhour'], (int) $_POST['fminute'], 0, $end_m, $end_d, $end_y);
  1057. $now = time();
  1058. $type = Database::escape_string($_POST['repeat_type']);
  1059. if ($end > $now && in_array($type, array('daily', 'weekly', 'monthlyByDate', 'monthlyByDay', 'monthlyByDayR', 'yearly'))) {
  1060. $sql = "INSERT INTO $t_agenda_repeat (c_id, cal_id, cal_type, cal_end)".
  1061. " VALUES ($course_id, $last_id,'$type',$end)";
  1062. $res = Database::query($sql);
  1063. }
  1064. }
  1065. }
  1066. return $last_id;
  1067. }
  1068. /**
  1069. * Stores the given agenda item as an announcement (unlinked copy)
  1070. * @param integer Agenda item's ID
  1071. * @return integer New announcement item's ID
  1072. */
  1073. function store_agenda_item_as_announcement($item_id)
  1074. {
  1075. $table_agenda = Database::get_course_table(TABLE_AGENDA);
  1076. $table_ann = Database::get_course_table(TABLE_ANNOUNCEMENT);
  1077. //check params
  1078. if (empty($item_id) or $item_id != strval(intval($item_id))) {
  1079. return -1;
  1080. }
  1081. //get the agenda item
  1082. $item_id = Database::escape_string($item_id);
  1083. $sql = "SELECT * FROM $table_agenda WHERE id = ".$item_id;
  1084. $res = Database::query($sql);
  1085. $course_id = api_get_course_int_id();
  1086. if (Database::num_rows($res) > 0) {
  1087. $row = Database::fetch_array($res);
  1088. //we have the agenda event, copy it
  1089. //get the maximum value for display order in announcement table
  1090. $sql_max = "SELECT MAX(display_order) FROM $table_ann WHERE c_id = $course_id ";
  1091. $res_max = Database::query($sql_max);
  1092. $row_max = Database::fetch_array($res_max);
  1093. $max = intval($row_max[0]) + 1;
  1094. //build the announcement text
  1095. $content = $row['content'];
  1096. //insert announcement
  1097. $session_id = api_get_session_id();
  1098. $sql_ins = "INSERT INTO $table_ann (c_id, title,content,end_date,display_order,session_id) ".
  1099. "VALUES ($course_id, '".Database::escape_string($row['title'])."','".Database::escape_string($content)."','".Database::escape_string($row['end_date'])."','$max','$session_id')";
  1100. $res_ins = Database::query($sql_ins);
  1101. if ($res > 0) {
  1102. $ann_id = Database::insert_id();
  1103. //Now also get the list of item_properties rows for this agenda_item (calendar_event)
  1104. //and copy them into announcement item_properties
  1105. $table_props = Database::get_course_table(TABLE_ITEM_PROPERTY);
  1106. $sql_props = "SELECT * FROM $table_props WHERE tool = 'calendar_event' AND ref='$item_id'";
  1107. $res_props = Database::query($sql_props);
  1108. if (Database::num_rows($res_props) > 0) {
  1109. while ($row_props = Database::fetch_array($res_props)) {
  1110. //insert into announcement item_property
  1111. $time = api_get_utc_datetime();
  1112. $sql_ins_props = "INSERT INTO $table_props ".
  1113. "(c_id, tool, insert_user_id, insert_date, ".
  1114. "lastedit_date, ref, lastedit_type,".
  1115. "lastedit_user_id, to_group_id, to_user_id, ".
  1116. "visibility, start_visible, end_visible)".
  1117. " VALUES ".
  1118. "($course_id, 'announcement','".$row_props['insert_user_id']."','".$time."',".
  1119. "'$time','$ann_id','AnnouncementAdded',".
  1120. "'".$row_props['last_edit_user_id']."','".$row_props['to_group_id']."','".$row_props['to_user_id']."',".
  1121. "'".$row_props['visibility']."','".$row_props['start_visible']."','".$row_props['end_visible']."')";
  1122. $res_ins_props = Database::query($sql_ins_props);
  1123. if ($res_ins_props <= 0) {
  1124. return -1;
  1125. } else {
  1126. //copy was a success
  1127. return $ann_id;
  1128. }
  1129. }
  1130. }
  1131. } else {
  1132. return -1;
  1133. }
  1134. }
  1135. return -1;
  1136. }
  1137. /**
  1138. * This function separates the users from the groups
  1139. * users have a value USER:XXX (with XXX the dokeos id
  1140. * groups have a value GROUP:YYY (with YYY the group id)
  1141. * @author: Patrick Cool <patrick.cool@UGent.be>, Ghent University
  1142. * @return array
  1143. */
  1144. function separate_users_groups($to)
  1145. {
  1146. $grouplist = array();
  1147. $userlist = array();
  1148. $send_to = null;
  1149. $send_to['everyone'] = false;
  1150. if (is_array($to) && count($to) > 0) {
  1151. foreach ($to as $to_item) {
  1152. list($type, $id) = explode(':', $to_item);
  1153. switch ($type) {
  1154. case 'everyone':
  1155. $send_to['everyone'] = true;
  1156. case 'GROUP':
  1157. $grouplist[] = $id;
  1158. break;
  1159. case 'USER':
  1160. $userlist[] = $id;
  1161. break;
  1162. }
  1163. }
  1164. $send_to['groups'] = $grouplist;
  1165. $send_to['users'] = $userlist;
  1166. }
  1167. return $send_to;
  1168. }
  1169. /**
  1170. * returns all the users and all the groups a specific Agenda item has been sent to
  1171. * @author: Patrick Cool <patrick.cool@UGent.be>, Ghent University
  1172. * @return array
  1173. */
  1174. function sent_to($tool, $id)
  1175. {
  1176. $TABLE_ITEM_PROPERTY = Database::get_course_table(TABLE_ITEM_PROPERTY);
  1177. $tool = Database::escape_string($tool);
  1178. $id = Database::escape_string($id);
  1179. $sql = "SELECT * FROM $TABLE_ITEM_PROPERTY WHERE tool='".$tool."' AND ref='".$id."'";
  1180. $result = Database::query($sql);
  1181. while ($row = Database::fetch_array($result)) {
  1182. // if to_group_id is null then it is sent to a specific user
  1183. // if to_group_id = 0 then it is sent to everybody
  1184. if (!is_null($row['to_group_id'])) {
  1185. $sent_to_group[] = $row['to_group_id'];
  1186. //echo $row['to_group_id'];
  1187. }
  1188. // if to_user_id <> 0 then it is sent to a specific user
  1189. if ($row['to_user_id'] <> 0) {
  1190. $sent_to_user[] = $row['to_user_id'];
  1191. }
  1192. }
  1193. if (isset($sent_to_group)) {
  1194. $sent_to['groups'] = $sent_to_group;
  1195. }
  1196. if (isset($sent_to_user)) {
  1197. $sent_to['users'] = $sent_to_user;
  1198. }
  1199. return $sent_to;
  1200. }
  1201. /**
  1202. * constructs the form to display all the groups and users the message has been sent to
  1203. * @author: Patrick Cool <patrick.cool@UGent.be>, Ghent University
  1204. * @param array $sent_to_array: a 2 dimensional array containing the groups and the users
  1205. * the first level is a distinction between groups and users: $sent_to_array['groups'] and $sent_to_array['users']
  1206. * $sent_to_array['groups'] (resp. $sent_to_array['users']) is also an array containing all the id's of the
  1207. * groups (resp. users) who have received this message.
  1208. * @return html
  1209. */
  1210. function sent_to_form($sent_to_array)
  1211. {
  1212. // we find all the names of the groups
  1213. $group_names = get_course_groups();
  1214. // we count the number of users and the number of groups
  1215. if (isset($sent_to_array['users'])) {
  1216. $number_users = count($sent_to_array['users']);
  1217. } else {
  1218. $number_users = 0;
  1219. }
  1220. if (isset($sent_to_array['groups'])) {
  1221. $number_groups = count($sent_to_array['groups']);
  1222. } else {
  1223. $number_groups = 0;
  1224. }
  1225. $total_numbers = $number_users + $number_groups;
  1226. $output = array();
  1227. // starting the form if there is more than one user/group
  1228. if ($total_numbers > 1) {
  1229. //$output.="<option>".get_lang("SentTo")."</option>";
  1230. // outputting the name of the groups
  1231. if (is_array($sent_to_array['groups'])) {
  1232. foreach ($sent_to_array['groups'] as $group_id) {
  1233. if (isset($group_names[$group_id]['name'])) {
  1234. $output[] = $group_names[$group_id]['name'];
  1235. }
  1236. }
  1237. }
  1238. if (isset($sent_to_array['users'])) {
  1239. if (is_array($sent_to_array['users'])) {
  1240. foreach ($sent_to_array['users'] as $user_id) {
  1241. // @todo add username as tooltip - is this fucntion still used ?
  1242. // $user_info= api_get_user_info($user_id);
  1243. // $username = api_htmlentities(sprintf(get_lang('LoginX'), $user_info['username']), ENT_QUOTES);
  1244. $output[] = api_get_person_name($user_info['firstName'], $user_info['lastName']);
  1245. }
  1246. }
  1247. }
  1248. } else {
  1249. // there is only one user/group
  1250. if (is_array($sent_to_array['users'])) {
  1251. // @todo add username as tooltip - is this fucntion still used ?
  1252. // $user_info = api_get_user_info($sent_to_array['users'][0]);
  1253. // $username = api_htmlentities(sprintf(get_lang('LoginX'), $user_info['username']), ENT_QUOTES);
  1254. $output[] = api_get_person_name($user_info['firstName'], $user_info['lastName']);
  1255. }
  1256. if (is_array($sent_to_array['groups']) and $sent_to_array['groups'][0] !== 0) {
  1257. $group_id = $sent_to_array['groups'][0];
  1258. $output[] = $group_names[$group_id]['name'];
  1259. }
  1260. if (is_array($sent_to_array['groups']) and $sent_to_array['groups'][0] == 0) {
  1261. $output[] = get_lang("Everybody");
  1262. }
  1263. }
  1264. if (!empty($output)) {
  1265. $output = array_filter($output);
  1266. if (count($output) > 0) {
  1267. $output = implode(', ', $output);
  1268. }
  1269. return $output;
  1270. }
  1271. }
  1272. /**
  1273. * This function displays a dropdown list that allows the course administrator do view the calendar items of one specific group
  1274. * @author: Patrick Cool <patrick.cool@UGent.be>, Ghent University
  1275. */
  1276. function show_group_filter_form()
  1277. {
  1278. $group_list = get_course_groups();
  1279. echo "<select name=\"select\" onchange=\"javascript: MM_jumpMenu('parent',this,0)\">";
  1280. echo "<option value=\"agenda.php?group=none\">".get_lang('ShowAll')."</option>";
  1281. foreach ($group_list as $this_group) {
  1282. echo "<option value=\"agenda.php?action=view&group=".$this_group['id']."\" ";
  1283. echo ($this_group['id'] == $_SESSION['group']) ? " selected" : "";
  1284. echo ">".$this_group['name']."</option>";
  1285. }
  1286. echo "</select>";
  1287. }
  1288. /**
  1289. * This function displays a dropdown list that allows the course administrator do view the calendar items of one specific group
  1290. * @author: Patrick Cool <patrick.cool@UGent.be>, Ghent University
  1291. */
  1292. function show_user_filter_form()
  1293. {
  1294. $user_list = get_course_users();
  1295. echo "<select name=\"select\" onchange=\"javascript: MM_jumpMenu('parent',this,0)\">";
  1296. echo "<option value=\"agenda.php?user=none\">".get_lang('ShowAll')."</option>";
  1297. foreach ($user_list as $this_user) {
  1298. // echo "<option value=\"agenda.php?isStudentView=true&amp;user=".$this_user['uid']."\">".api_get_person_name($this_user['firstName'], $this_user['lastName'])."</option>";
  1299. echo "<option value=\"agenda.php?action=view&user=".$this_user['uid']."\" ";
  1300. echo ($this_user['uid'] == $_SESSION['user']) ? " selected" : "";
  1301. echo ">".api_get_person_name($this_user['firstName'], $this_user['lastName'])."</option>";
  1302. }
  1303. echo "</select>";
  1304. }
  1305. /**
  1306. * This function displays a dropdown list that allows the course administrator do view the calendar items of one specific group
  1307. * @author: Patrick Cool <patrick.cool@UGent.be>, Ghent University
  1308. */
  1309. function show_user_group_filter_form()
  1310. {
  1311. echo "<select name=\"select\" onchange=\"javascript: MM_jumpMenu('parent',this,0)\">";
  1312. echo "<option value=\"agenda.php?user=none&action=view\">".get_lang("ShowAll")."</option>";
  1313. // Groups
  1314. $group_list = get_course_groups();
  1315. $group_available_to_access = array();
  1316. $option = '';
  1317. if (!empty($group_list)) {
  1318. $option = "<optgroup label=\"".get_lang("Groups")."\">";
  1319. foreach ($group_list as $this_group) {
  1320. // echo "<option value=\"agenda.php?isStudentView=true&amp;group=".$this_group['id']."\">".$this_group['name']."</option>";
  1321. $has_access = GroupManager::user_has_access(api_get_user_id(), $this_group['id'], GroupManager::GROUP_TOOL_CALENDAR);
  1322. $result = GroupManager::get_group_properties($this_group['id']);
  1323. if ($result['calendar_state'] != '0') {
  1324. $group_available_to_access[] = $this_group['id'];
  1325. }
  1326. // lastedit
  1327. if ($has_access || $result['calendar_state'] == '1') {
  1328. $option.= "<option value=\"agenda.php?action=view&group=".$this_group['id']."\" ";
  1329. $option.= ($this_group['id'] == $_SESSION['group']) ? " selected" : "";
  1330. $option.= ">".$this_group['name']."</option>";
  1331. }
  1332. }
  1333. $option.= "</optgroup>";
  1334. }
  1335. echo $option;
  1336. // Users
  1337. $user_list = get_course_users();
  1338. if (!empty($user_list)) {
  1339. echo "<optgroup label=\"".get_lang("Users")."\">";
  1340. foreach ($user_list as $this_user) {
  1341. echo "<option value=\"agenda.php?action=view&user=".$this_user['uid']."\" ";
  1342. echo (isset($_SESSION['user']) && $this_user['uid'] == $_SESSION['user']) ? " selected" : "";
  1343. echo ">".api_get_person_name($this_user['firstName'], $this_user['lastName'])."</option>";
  1344. }
  1345. echo "</optgroup>";
  1346. }
  1347. echo "</select>";
  1348. }
  1349. /**
  1350. * This tools loads all the users and all the groups who have received a specific item (in this case an agenda item)
  1351. * @author: Patrick Cool <patrick.cool@UGent.be>, Ghent University
  1352. */
  1353. function load_edit_users($tool, $id)
  1354. {
  1355. $tool = Database::escape_string($tool);
  1356. $id = Database::escape_string($id);
  1357. $TABLE_ITEM_PROPERTY = Database::get_course_table(TABLE_ITEM_PROPERTY);
  1358. $course_id = api_get_course_int_id();
  1359. $sql = "SELECT * FROM $TABLE_ITEM_PROPERTY WHERE c_id = $course_id AND tool='$tool' AND ref='$id'";
  1360. $result = Database::query($sql) or die(Database::error());
  1361. while ($row = Database::fetch_array($result)) {
  1362. $to_group = $row['to_group_id'];
  1363. switch ($to_group) {
  1364. // it was send to one specific user
  1365. case null:
  1366. $to[] = "USER:".$row['to_user_id'];
  1367. break;
  1368. // it was sent to everyone
  1369. case 0:
  1370. return "everyone";
  1371. exit;
  1372. break;
  1373. default:
  1374. $to[] = "GROUP:".$row['to_group_id'];
  1375. }
  1376. }
  1377. return $to;
  1378. }
  1379. /**
  1380. * This functions swithes the visibility a course resource using the visible field in 'last_tooledit' values: 0 = invisible
  1381. * @author: Patrick Cool <patrick.cool@UGent.be>, Ghent University
  1382. */
  1383. function change_visibility($tool, $id, $visibility)
  1384. {
  1385. global $_course;
  1386. $TABLE_ITEM_PROPERTY = Database::get_course_table(TABLE_ITEM_PROPERTY);
  1387. $tool = Database::escape_string($tool);
  1388. $id = Database::escape_string($id);
  1389. if ($visibility == 0) {
  1390. $sql_visibility = "UPDATE $TABLE_ITEM_PROPERTY SET visibility='0' WHERE tool='$tool' AND ref='$id'";
  1391. api_item_property_update($_course, TOOL_CALENDAR_EVENT, $id, "invisible", api_get_user_id());
  1392. } else {
  1393. $sql_visibility = "UPDATE $TABLE_ITEM_PROPERTY SET visibility='1' WHERE tool='$tool' AND ref='$id'";
  1394. api_item_property_update($_course, TOOL_CALENDAR_EVENT, $id, "visible", api_get_user_id());
  1395. }
  1396. }
  1397. /**
  1398. * The links that allows the course administrator to add a new agenda item, to filter on groups or users
  1399. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  1400. */
  1401. function display_courseadmin_links($filter = 0)
  1402. {
  1403. if (!api_get_course_int_id()) {
  1404. $type = isset($_REQUEST['type']) ? Security::remove_XSS($_REQUEST['type']) : 'personal';
  1405. if ($type == 'platform') {
  1406. $type = 'admin';
  1407. }
  1408. return "<a href='agenda_js.php?type=$type'>".Display::return_icon('calendar.png', get_lang('Agenda'), '', ICON_SIZE_MEDIUM)."</a>";
  1409. }
  1410. $form = null;
  1411. if (!isset($_GET['action'])) {
  1412. $form = show_to($filter, 'select_form_id_search');
  1413. $actions = "<a href='agenda_js.php?type=course&".api_get_cidreq()."'>".Display::return_icon('calendar_na.png', get_lang('Agenda'), '', ICON_SIZE_MEDIUM)."</a>";
  1414. } else {
  1415. $actions = "<a href='agenda_js.php?type=course&".api_get_cidreq()."'>".Display::return_icon('calendar.png', get_lang('Agenda'), '', ICON_SIZE_MEDIUM)."</a>";
  1416. }
  1417. $actions .= "<a href='agenda_list.php?type=course&".api_get_cidreq()."'>".Display::return_icon('week.png', get_lang('Agenda'), '', ICON_SIZE_MEDIUM)."</a>";
  1418. $actions .= "<a href='agenda.php?".api_get_cidreq()."&amp;sort=asc&amp;toolgroup=".api_get_group_id()."&action=add'>".Display::return_icon('new_event.png', get_lang('AgendaAdd'), '', ICON_SIZE_MEDIUM)."</a>";
  1419. $actions .= "<a href='agenda.php?".api_get_cidreq()."&action=importical'>".Display::return_icon('import_calendar.png', get_lang('ICalFileImport'), '', ICON_SIZE_MEDIUM)."</a>";
  1420. $actions .= $form;
  1421. return $actions;
  1422. }
  1423. /**
  1424. * The links that allows the student AND course administrator to show all agenda items and sort up/down
  1425. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  1426. * @author Julio Montoya removing options, changing to a simple agenda tool
  1427. */
  1428. function display_student_links()
  1429. {
  1430. global $show;
  1431. $month = isset($_GET['month']) ? intval($_GET['month']) : null;
  1432. $year = isset($_GET['year']) ? intval($_GET['year']) : null;
  1433. $day_url = '&month='.$month.'&year='.$year;
  1434. if ($_SESSION['view'] <> 'month') {
  1435. echo "<a href=\"".api_get_self()."?action=view".$day_url."&toolgroup=".api_get_group_id()."&amp;view=month\">".Display::return_icon('month_empty.png', get_lang('MonthView'), '', ICON_SIZE_MEDIUM)."</a> ";
  1436. } else {
  1437. echo "<a href=\"".api_get_self()."?action=view".$day_url."&toolgroup=".api_get_group_id()."&amp;view=list\">".Display::return_icon('week.png', get_lang('ListView'), '', ICON_SIZE_MEDIUM)."</a> ";
  1438. }
  1439. $day_url = '&month='.date('m').'&year='.date('Y').'&view='.Security::remove_XSS($_GET['view']);
  1440. $today_url = api_get_self()."?action=view".$day_url."&toolgroup=".api_get_group_id();
  1441. echo Display::url(get_lang('Today'), $today_url, array('class' => 'btn'));
  1442. }
  1443. /**
  1444. * get all the information of the agenda_item from the database
  1445. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  1446. * @param integer the id of the agenda item we are getting all the information of
  1447. * @return array an associative array that contains all the information of the agenda item. The keys are the database fields
  1448. */
  1449. function get_agenda_item($id)
  1450. {
  1451. global $TABLEAGENDA;
  1452. $t_agenda_repeat = Database::get_course_table(TABLE_AGENDA_REPEAT);
  1453. $id = Database::escape_string($id);
  1454. $item = array();
  1455. if (empty($id)) {
  1456. $id = intval(Database::escape_string(($_GET['id'])));
  1457. } else {
  1458. $id = (int) $id;
  1459. }
  1460. $course_id = api_get_course_int_id();
  1461. if (empty($id)) {
  1462. return $item;
  1463. }
  1464. $sql = "SELECT * FROM ".$TABLEAGENDA." WHERE id='".$id."' AND c_id = $course_id ";
  1465. $result = Database::query($sql);
  1466. $entry_to_edit = Database::fetch_array($result);
  1467. $item['title'] = $entry_to_edit["title"];
  1468. $item['content'] = $entry_to_edit["content"];
  1469. $item['start_date'] = $entry_to_edit["start_date"];
  1470. $item['end_date'] = $entry_to_edit["end_date"];
  1471. $item['to'] = load_edit_users(TOOL_CALENDAR_EVENT, $id);
  1472. // if the item has been sent to everybody then we show the compact to form
  1473. if ($item['to'] == "everyone") {
  1474. $_SESSION['allow_individual_calendar'] = "hide";
  1475. } else {
  1476. $_SESSION['allow_individual_calendar'] = "show";
  1477. }
  1478. $item['repeat'] = false;
  1479. $sql = "SELECT * FROM $t_agenda_repeat WHERE c_id = $course_id AND cal_id = $id";
  1480. $res = Database::query($sql);
  1481. if (Database::num_rows($res) > 0) {
  1482. //this event is repetitive
  1483. $row = Database::fetch_array($res);
  1484. $item['repeat'] = true;
  1485. $item['repeat_type'] = $row['cal_type'];
  1486. $item['repeat_end'] = $row['cal_end'];
  1487. $item['repeat_frequency'] = $row['cal_frequency']; //unused in 1.8.5 RC1 - will be used later to say if once every 2 or 3 weeks, for example
  1488. $item['repeat_days'] = $row['cal_days']; //unused in 1.8.5 RC1 - will be used later
  1489. }
  1490. //TODO - add management of repeat exceptions
  1491. return $item;
  1492. }
  1493. /**
  1494. * This is the function that updates an agenda item. It does 3 things
  1495. * 1. storethe start_date, end_date, title and message in the calendar_event table
  1496. * 2. store the groups/users who this message is meant for in the item_property table
  1497. * 3. modify the attachments (if needed)
  1498. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  1499. * @author Julio Montoya Adding UTC support
  1500. */
  1501. function store_edited_agenda_item($event_id, $id_attach, $file_comment)
  1502. {
  1503. // STEP 1: editing the calendar_event table
  1504. // 1.a. some filtering of the input data
  1505. $id = $event_id;
  1506. $title = strip_tags(trim($_POST['title'])); // no html allowed in the title
  1507. $content = trim($_POST['content']);
  1508. $start_date = (int) $_POST['fyear']."-".(int) $_POST['fmonth']."-".(int) $_POST['fday']." ".(int) $_POST['fhour'].":".(int) $_POST['fminute'].":00";
  1509. $end_date = (int) $_POST['end_fyear']."-".(int) $_POST['end_fmonth']."-".(int) $_POST['end_fday']." ".(int) $_POST['end_fhour'].":".(int) $_POST['end_fminute'].":00";
  1510. $to = $_POST['selectedform'];
  1511. if ($_POST['empty_end_date'] == 'on') {
  1512. $end_date = "0000-00-00 00:00:00";
  1513. }
  1514. $course_info = api_get_course_info();
  1515. $agendaObj = new Agenda();
  1516. if (empty($course_info)) {
  1517. $agendaObj->type = 'personal';
  1518. } else {
  1519. $agendaObj->set_course($course_info);
  1520. $agendaObj->type = 'course';
  1521. if (api_is_course_coach() && !api_is_element_in_the_session(TOOL_AGENDA, $event_id)) {
  1522. return false;
  1523. }
  1524. if (!api_is_allowed_to_edit(null, true)) {
  1525. return false;
  1526. }
  1527. }
  1528. $all_day = isset($_REQUEST['all_day']) && !empty($_REQUEST['all_day']) ? 1 : 0;
  1529. $agendaObj->edit_event($id, $start_date, $end_date, $all_day, null, $title, $content);
  1530. if (empty($id_attach)) {
  1531. add_agenda_attachment_file($file_comment, $id);
  1532. } else {
  1533. edit_agenda_attachment_file($file_comment, $id, $id_attach);
  1534. }
  1535. // step 2: editing the item_property table (=delete all and add the new destination users/groups)
  1536. /*if ($edit_result = true) {
  1537. // 2.a. delete everything for the users
  1538. $sql_delete = "DELETE FROM ".$TABLE_ITEM_PROPERTY." WHERE c_id = $course_id AND ref='$id' AND tool='".TOOL_CALENDAR_EVENT."'";
  1539. $result = Database::query($sql_delete) or die(Database::error());
  1540. // 2.b. storing the new users/groups
  1541. if (!is_null($to)) { // !is_null($to): when no user is selected we send it to everyone
  1542. $send_to = separate_users_groups($to);
  1543. // storing the selected groups
  1544. if (is_array($send_to['groups'])) {
  1545. foreach ($send_to['groups'] as $group) {
  1546. api_item_property_update($_course, TOOL_CALENDAR_EVENT, $id, "AgendaModified", api_get_user_id(), $group, '', $start_date, $end_date);
  1547. }
  1548. }
  1549. // storing the selected users
  1550. if (is_array($send_to['users'])) {
  1551. foreach ($send_to['users'] as $user) {
  1552. api_item_property_update($_course, TOOL_CALENDAR_EVENT, $id, "AgendaModified", api_get_user_id(), '', $user, $start_date, $end_date);
  1553. }
  1554. }
  1555. } else {
  1556. // the message is sent to everyone, so we set the group to 0
  1557. api_item_property_update($_course, TOOL_CALENDAR_EVENT, $id, "AgendaModified", api_get_user_id(), '', '', $start_date, $end_date);
  1558. }
  1559. }*/
  1560. // step 3: update the attachments (=delete all and add those in the session
  1561. update_added_resources("Agenda", $id);
  1562. // return the message;
  1563. Display::display_confirmation_message(get_lang("EditSuccess"));
  1564. }
  1565. /**
  1566. * This function stores the Agenda Item in the table calendar_event and updates the item_property table also (after an edit)
  1567. * @author: Patrick Cool <patrick.cool@UGent.be>, Ghent University
  1568. */
  1569. function save_edit_agenda_item($id, $title, $content, $start_date, $end_date)
  1570. {
  1571. $TABLEAGENDA = Database::get_course_table(TABLE_AGENDA);
  1572. $id = Database::escape_string($id);
  1573. $title = Database::escape_string($title);
  1574. $content = Database::escape_string($content);
  1575. $start_date = Database::escape_string($start_date);
  1576. $end_date = Database::escape_string($end_date);
  1577. // store the modifications in the table calendar_event
  1578. $sql = "UPDATE ".$TABLEAGENDA."
  1579. SET title ='".$title."',
  1580. content ='".$content."',
  1581. start_date ='".$start_date."',
  1582. end_date ='".$end_date."'
  1583. WHERE id='".$id."'";
  1584. $result = Database::query($sql);
  1585. return true;
  1586. }
  1587. /**
  1588. * This is the function that deletes an agenda item.
  1589. * The agenda item is no longer physically deleted but the visibility in the item_property table is set to 2
  1590. * which means that it is invisible for the student AND course admin. Only the platform administrator can see it.
  1591. * This will in a later stage allow the platform administrator to recover resources that were mistakenly deleted
  1592. * by the course administrator
  1593. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  1594. * @param integer the id of the agenda item wa are deleting
  1595. */
  1596. function delete_agenda_item($id)
  1597. {
  1598. global $_course;
  1599. $id = Database::escape_string($id);
  1600. if (api_is_allowed_to_edit(false, true) OR (api_get_course_setting('allow_user_edit_agenda') && !api_is_anonymous())) {
  1601. if (!empty($_GET['id']) && isset($_GET['action']) && $_GET['action'] == "delete") {
  1602. $t_agenda = Database::get_course_table(TABLE_AGENDA);
  1603. $t_agenda_r = Database::get_course_table(TABLE_AGENDA_REPEAT);
  1604. $id = intval($_GET['id']);
  1605. $sql = "SELECT * FROM $t_agenda_r WHERE cal_id = $id";
  1606. $res = Database::query($sql);
  1607. if (Database::num_rows($res) > 0) {
  1608. $sql_children = "SELECT * FROM $t_agenda WHERE parent_event_id = $id";
  1609. $res_children = Database::query($sql_children);
  1610. if (Database::num_rows($res_children) > 0) {
  1611. while ($row_child = Database::fetch_array($res_children)) {
  1612. api_item_property_update($_course, TOOL_CALENDAR_EVENT, $row_child['id'], 'delete', api_get_user_id());
  1613. }
  1614. }
  1615. $sql_del = "DELETE FROM $t_agenda_r WHERE cal_id = $id";
  1616. $res_del = Database::query($sql_del);
  1617. }
  1618. //$sql = "DELETE FROM ".$TABLEAGENDA." WHERE id='$id'";
  1619. //$sql= "UPDATE ".$TABLE_ITEM_PROPERTY." SET visibility='2' WHERE tool='Agenda' and ref='$id'";
  1620. //$result = Database::query($sql) or die (Database::error());
  1621. api_item_property_update($_course, TOOL_CALENDAR_EVENT, $id, 'delete', api_get_user_id());
  1622. // delete the resources that were added to this agenda item
  1623. // 2DO: as we no longer fysically delete the agenda item (to make it possible to 'restore'
  1624. // deleted items, we should not delete the added resources either.
  1625. // delete_added_resource("Agenda", $id); // -> this is no longer needed as the message is not really deleted but only visibility=2 (only platform admin can see it)
  1626. //resetting the $id;
  1627. $id = null;
  1628. // displaying the result message in the yellow box
  1629. Display::display_confirmation_message(get_lang("AgendaDeleteSuccess"));
  1630. } // if (isset($id)&&$id&&isset($action)&&$action=="delete")
  1631. } // if ($is_allowed_to_edit)
  1632. }
  1633. /**
  1634. * Makes an agenda item visible or invisible for a student
  1635. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  1636. * @param integer id the id of the agenda item we are changing the visibility of
  1637. */
  1638. function showhide_agenda_item($id)
  1639. {
  1640. global $nameTools;
  1641. /*
  1642. SHOW / HIDE A CALENDAR ITEM
  1643. */
  1644. // and $_GET['isStudentView']<>"false" is added to prevent that the visibility is changed after you do the following:
  1645. // change visibility -> studentview -> course manager view
  1646. if ((api_is_allowed_to_edit(false, true) OR (api_get_course_setting('allow_user_edit_agenda') && !api_is_anonymous())) and $_GET['isStudentView'] <> "false") {
  1647. if (isset($_GET['id']) && isset($_GET['action']) && $_GET['action'] == "showhide") {
  1648. $id = (int) addslashes($_GET['id']);
  1649. if (isset($_GET['next_action']) && $_GET['next_action'] == strval(intval($_GET['next_action']))) {
  1650. $visibility = $_GET['next_action'];
  1651. change_visibility($nameTools, $id, $visibility);
  1652. Display::display_confirmation_message(get_lang("VisibilityChanged"));
  1653. }
  1654. }
  1655. }
  1656. }
  1657. /**
  1658. * Displays all the agenda items
  1659. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  1660. * @author Yannick Warnier <yannick.warnier@beeznest.com> - cleanup
  1661. * @author Julio Montoya <gugli100@gmail.com> - Refactoring
  1662. */
  1663. function display_agenda_items($agenda_items, $day = false)
  1664. {
  1665. global $charset;
  1666. if (isset($day) && $day) {
  1667. $new_items = array();
  1668. foreach ($agenda_items as $item) {
  1669. if (substr($item['start_date'], 8, 2) == $day) {
  1670. $new_items[] = $item;
  1671. }
  1672. }
  1673. $agenda_items = $new_items;
  1674. }
  1675. if (isset($_GET['sort']) && $_GET['sort'] == 'asc') {
  1676. $sort_inverse = 'desc';
  1677. $sort = 'asc';
  1678. } else {
  1679. $sort_inverse = 'asc';
  1680. $sort = 'desc';
  1681. }
  1682. if (isset($_GET['col']) && $_GET['col'] == 'end') {
  1683. $sort_item = 'end_date_tms';
  1684. $col = 'end';
  1685. } else {
  1686. $sort_item = 'start_date_tms';
  1687. $col = 'start';
  1688. }
  1689. $agenda_items = msort($agenda_items, $sort_item, $sort);
  1690. //DISPLAY: NO ITEMS
  1691. if (empty($agenda_items)) {
  1692. echo Display::display_warning_message(get_lang('NoAgendaItems'));
  1693. } else {
  1694. echo '<table class="data_table">';
  1695. $th = Display::tag('th', get_lang('Title'));
  1696. $month = isset($_GET['month']) ? intval($_GET['month']) : null;
  1697. $year = isset($_GET['year']) ? intval($_GET['year']) : null;
  1698. $day = isset($_GET['day']) ? intval($_GET['day']) : null;
  1699. $url = api_get_self().'?'.api_get_cidreq().'&month='.$month.'&year='.$year.'&day='.$day;
  1700. $th .= Display::tag('th', Display::url(get_lang('StartTimeWindow'), $url.'&sort='.$sort_inverse.'&col=start'));
  1701. $th .= Display::tag('th', Display::url(get_lang('EndTimeWindow'), $url.'&sort='.$sort_inverse.'&col=end'));
  1702. if ((api_is_allowed_to_edit(false, true) OR (api_get_course_setting('allow_user_edit_agenda') && !api_is_anonymous()))) {
  1703. $th .= Display::tag('th', get_lang('Modify'));
  1704. }
  1705. echo Display::tag('tr', $th);
  1706. $counter = 0;
  1707. foreach ($agenda_items as $myrow) {
  1708. $is_repeated = !empty($myrow['parent_event_id']);
  1709. $class = 'row_even';
  1710. if ($counter % 2) {
  1711. $class = 'row_odd';
  1712. }
  1713. /* display: the icon, title, destinees of the item */
  1714. echo '<tr class="'.$class.'">';
  1715. //Title
  1716. echo "<td>";
  1717. $attach_icon = '';
  1718. // attachment list
  1719. $attachment_list = get_attachment($myrow['id']);
  1720. if (!empty($attachment_list)) {
  1721. $attach_icon = ' '.Display::return_icon('attachment.gif', get_lang('Attachment'));
  1722. }
  1723. $title_class = '';
  1724. if (isset($myrow['visibility']) && $myrow['visibility'] == 0) {
  1725. $title_class = 'invisible';
  1726. }
  1727. switch ($myrow['calendar_type']) {
  1728. case 'global':
  1729. $icon_type = Display::return_icon('view_remove.png', get_lang('GlobalEvent'), array(), 22);
  1730. echo $icon_type.' '.$myrow['title'].$attach_icon;
  1731. break;
  1732. case 'personal':
  1733. $icon_type = Display::return_icon('user.png', get_lang(' '), array(), 22);
  1734. echo $icon_type.' '.$myrow['title'].$attach_icon;
  1735. break;
  1736. case 'course':
  1737. $icon_type = Display::return_icon('course.png', get_lang('Course'), array(), 22);
  1738. $agenda_url = api_get_path(WEB_CODE_PATH).'calendar/agenda.php?agenda_id='.$myrow['id'].'&action=view';
  1739. echo Display::url($icon_type.' '.$myrow['title'].$attach_icon, $agenda_url, array('class' => $title_class));
  1740. break;
  1741. }
  1742. echo '</td>';
  1743. //Start date
  1744. echo '<td>';
  1745. if (!empty($myrow['start_date']) && $myrow['start_date'] != '0000-00-00 00:00:00') {
  1746. echo api_format_date($myrow['start_date']);
  1747. }
  1748. echo '</td>';
  1749. //End date
  1750. echo '<td>';
  1751. if (!empty($myrow['end_date']) && $myrow['end_date'] != '0000-00-00 00:00:00') {
  1752. echo api_format_date($myrow['end_date']);
  1753. }
  1754. echo '</td>';
  1755. /* Display: edit delete button (course admin only) */
  1756. if (!$is_repeated && (api_is_allowed_to_edit(false, true) OR (api_get_course_setting('allow_user_edit_agenda') && !api_is_anonymous())) && $myrow['calendar_type'] == 'course') {
  1757. echo '<td align="center">';
  1758. if (!(api_is_course_coach() && !api_is_element_in_the_session(TOOL_AGENDA, $myrow['id']))) {
  1759. // a coach can only delete an element belonging to his session
  1760. $mylink = api_get_self().'?'.api_get_cidreq().'&origin='.Security::remove_XSS($_GET['origin']).'&id='.$myrow['id'].'&sort='.$sort.'&col='.$col.'&';
  1761. // edit
  1762. echo '<a href="'.$mylink.api_get_cidreq()."&toolgroup=".Security::remove_XSS($_GET['toolgroup']).'&action=edit&id_attach='.$attachment_list['id'].'" title="'.get_lang("ModifyCalendarItem").'">';
  1763. echo Display::return_icon('edit.png', get_lang('ModifyCalendarItem'), '', ICON_SIZE_SMALL)."</a>";
  1764. echo '<a href="'.$mylink.api_get_cidreq()."&toolgroup=".Security::remove_XSS($_GET['toolgroup']).'&action=announce" title="'.get_lang("AddAnnouncement").'">';
  1765. echo Display::return_icon('new_announce.png', get_lang('AddAnnouncement'), array(), ICON_SIZE_SMALL)."</a> ";
  1766. if ($myrow['visibility'] == 1) {
  1767. $image_visibility = "visible";
  1768. $text_visibility = get_lang("Hide");
  1769. $next_action = 0;
  1770. } else {
  1771. $image_visibility = "invisible";
  1772. $text_visibility = get_lang("Show");
  1773. $next_action = 1;
  1774. }
  1775. echo '<a href="'.$mylink.api_get_cidreq().'&toolgroup='.Security::remove_XSS($_GET['toolgroup']).'&action=showhide&next_action='.$next_action.'" title="'.$text_visibility.'">'.Display::return_icon($image_visibility.'.png', $text_visibility, '', ICON_SIZE_SMALL).'</a> ';
  1776. echo "<a href=\"".$mylink.api_get_cidreq()."&toolgroup=".Security::remove_XSS($_GET['toolgroup'])."&action=delete\" onclick=\"javascript:if(!confirm('".addslashes(api_htmlentities(get_lang("ConfirmYourChoice"), ENT_QUOTES, $charset))."')) return false;\" title=\"".get_lang("Delete")."\"> ";
  1777. echo Display::return_icon('delete.png', get_lang('Delete'), '', ICON_SIZE_SMALL)."&nbsp;</a>";
  1778. }
  1779. $mylink = 'ical_export.php?'.api_get_cidreq().'&type=course&id='.$myrow['id'];
  1780. //echo '<a class="ical_export" href="'.$mylink.'&class=confidential" title="'.get_lang('ExportiCalConfidential').'">'.Display::return_icon($export_icon_high, get_lang('ExportiCalConfidential')).'</a> ';
  1781. //echo '<a class="ical_export" href="'.$mylink.'&class=private" title="'.get_lang('ExportiCalPrivate').'">'.Display::return_icon($export_icon_low, get_lang('ExportiCalPrivate')).'</a> ';
  1782. //echo '<a class="ical_export" href="'.$mylink.'&class=public" title="'.get_lang('ExportiCalPublic').'">'.Display::return_icon($export_icon, get_lang('ExportiCalPublic')).'</a> ';
  1783. echo '<a href="#" onclick="javascript:win_print=window.open(\'print.php?id='.$myrow['id'].'\',\'popup\',\'left=100,top=100,width=700,height=500,scrollbars=1,resizable=0\'); win_print.focus(); return false;">'.Display::return_icon('printer.png', get_lang('Print'), '', ICON_SIZE_SMALL).'</a>&nbsp;';
  1784. echo '</td>';
  1785. } else {
  1786. if ($is_repeated && (api_is_allowed_to_edit(false, true) || api_get_course_setting('allow_user_edit_agenda') && !api_is_anonymous() )) {
  1787. echo '<td align="center">';
  1788. echo get_lang('RepeatedEvent'), ' <a href="', api_get_self(), '?', api_get_cidreq(), '&agenda_id=', $myrow['parent_event_id'], '" alt="', get_lang('RepeatedEventViewOriginalEvent'), '">', get_lang('RepeatedEventViewOriginalEvent'), '</a>';
  1789. echo '</td>';
  1790. }
  1791. if ((api_is_allowed_to_edit(false, true) || (api_get_course_setting('allow_user_edit_agenda') && !api_is_anonymous()) ) && ($myrow['calendar_type'] == 'personal' OR $myrow['calendar_type'] == 'global')) {
  1792. echo '<td align="center">';
  1793. echo '</td>';
  1794. }
  1795. }
  1796. $counter++;
  1797. echo "</tr>";
  1798. } // end while ($myrow=Database::fetch_array($result))
  1799. echo "</table><br /><br />";
  1800. }
  1801. if (!empty($event_list)) {
  1802. $event_list = api_substr($event_list, 0, -1);
  1803. } else {
  1804. $event_list = '0';
  1805. }
  1806. echo "<form name=\"event_list_form\"><input type=\"hidden\" name=\"event_list\" value=\"$event_list\" /></form>";
  1807. // closing the layout table
  1808. echo "</td>",
  1809. "</tr>",
  1810. "</table>";
  1811. }
  1812. /**
  1813. * Show a list with all the attachments according to the post's id
  1814. * @param the post's id
  1815. * @return array with the post info
  1816. * @author Christian Fasanando
  1817. * @version November 2008, dokeos 1.8.6
  1818. */
  1819. function get_attachment($agenda_id, $course_id = null)
  1820. {
  1821. $agenda_table_attachment = Database::get_course_table(TABLE_AGENDA_ATTACHMENT);
  1822. if (empty($course_id)) {
  1823. $course_id = api_get_course_int_id();
  1824. } else {
  1825. $course_id = intval($course_id);
  1826. }
  1827. $agenda_id = Database::escape_string($agenda_id);
  1828. $row = array();
  1829. $sql = 'SELECT id,path, filename,comment FROM '.$agenda_table_attachment.' WHERE c_id = '.$course_id.' AND agenda_id = '.(int) $agenda_id.'';
  1830. $result = Database::query($sql);
  1831. if (Database::num_rows($result) != 0) {
  1832. $row = Database::fetch_array($result);
  1833. }
  1834. return $row;
  1835. }
  1836. /**
  1837. * Displays only 1 agenda item. This is used when an agenda item is added to the learning path.
  1838. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  1839. */
  1840. function display_one_agenda_item($agenda_id)
  1841. {
  1842. global $TABLEAGENDA;
  1843. global $TABLE_ITEM_PROPERTY;
  1844. global $select_month, $select_year;
  1845. global $DaysShort, $DaysLong, $MonthsLong;
  1846. global $is_courseAdmin;
  1847. global $dateFormatLong, $timeNoSecFormat, $charset;
  1848. // getting the name of the groups
  1849. $group_names = get_course_groups();
  1850. $agenda_id = intval($agenda_id);
  1851. if (!(api_is_allowed_to_edit(false, true) || (api_get_course_setting('allow_user_edit_agenda') && !api_is_anonymous()))) {
  1852. $visibility_condition = " AND ip.visibility='1' ";
  1853. }
  1854. $sql = "SELECT agenda.*, ip.visibility, ip.to_group_id, ip.insert_user_id, ip.ref
  1855. FROM ".$TABLEAGENDA." agenda, ".$TABLE_ITEM_PROPERTY." ip
  1856. WHERE agenda.id = ip.ref
  1857. AND ip.tool='".TOOL_CALENDAR_EVENT."'
  1858. $visibility_condition
  1859. AND agenda.id='$agenda_id'";
  1860. $result = Database::query($sql);
  1861. $number_items = Database::num_rows($result);
  1862. $myrow = Database::fetch_array($result, 'ASSOC'); // there should be only one item so no need for a while loop
  1863. $sql_rep = "SELECT * FROM $TABLEAGENDA WHERE id = $agenda_id AND parent_event_id IS NOT NULL AND parent_event_id !=0";
  1864. $res_rep = Database::query($sql_rep);
  1865. $repeat = false;
  1866. $repeat_id = 0;
  1867. if (Database::num_rows($res_rep) > 0) {
  1868. $repeat = true;
  1869. $row_rep = Database::fetch_array($res_rep);
  1870. $repeat_id = $row_rep['parent_event_id'];
  1871. }
  1872. // DISPLAY: NO ITEMS
  1873. if ($number_items == 0) {
  1874. Display::display_warning_message(get_lang("NoAgendaItems"));
  1875. return false;
  1876. }
  1877. // DISPLAY: THE ITEMS
  1878. echo "<table id=\"data_table\" class=\"data_table\">";
  1879. // DISPLAY : the icon, title, destinees of the item
  1880. $myrow["start_date"] = api_get_local_time($myrow["start_date"]);
  1881. // highlight: if a date in the small calendar is clicked we highlight the relevant items
  1882. $db_date = (int) api_format_date($myrow["start_date"], "%d").intval(api_format_date($myrow["start_date"], "%m")).api_format_date($myrow["start_date"], "%Y");
  1883. if ($_GET["day"].$_GET["month"].$_GET["year"] <> $db_date) {
  1884. if ($myrow['visibility'] == '0') {
  1885. $style = "data_hidden";
  1886. $stylenotbold = "datanotbold_hidden";
  1887. $text_style = "text_hidden";
  1888. } else {
  1889. $style = "data";
  1890. $stylenotbold = "datanotbold";
  1891. $text_style = "text";
  1892. }
  1893. } else {
  1894. $style = "datanow";
  1895. $stylenotbold = "datanotboldnow";
  1896. $text_style = "textnow";
  1897. }
  1898. echo Display::tag('h2', $myrow['title']);
  1899. echo "<tr>";
  1900. if (api_is_allowed_to_edit(false, true)) {
  1901. if (!(api_is_course_coach() && !api_is_element_in_the_session(TOOL_AGENDA, $myrow['id']))) {
  1902. // a coach can only delete an element belonging to his session
  1903. // DISPLAY: edit delete button (course admin only)
  1904. $export_icon = '../img/export.png';
  1905. $export_icon_low = '../img/export_low_fade.png';
  1906. $export_icon_high = '../img/export_high_fade.png';
  1907. echo '<th style="text-align:right">';
  1908. if (!$repeat && api_is_allowed_to_edit(false, true)) {
  1909. // edit
  1910. $mylink = api_get_self()."?".api_get_cidreq()."&origin=".Security::remove_XSS($_GET['origin'])."&id=".$myrow['id'];
  1911. if (!empty($_GET['agenda_id'])) {
  1912. // rather ugly hack because the id parameter is already set above but below we set it again
  1913. $mylink .= '&agenda_id='.Security::remove_XSS($_GET['agenda_id']).'&id='.Security::remove_XSS($_GET['agenda_id']);
  1914. }
  1915. if ($myrow['visibility'] == 1) {
  1916. $image_visibility = "visible";
  1917. $next_action = 0;
  1918. } else {
  1919. $image_visibility = "invisible";
  1920. $next_action = 1;
  1921. }
  1922. echo '<a href="'.$mylink.'&action=showhide&next_action='.$next_action.'">'.Display::return_icon($image_visibility.'.png', get_lang('Visible'), '', ICON_SIZE_SMALL).'</a>';
  1923. echo "<a href=\"".$mylink."&action=edit\">",
  1924. Display::return_icon('edit.png', get_lang('ModifyCalendarItem'), '', ICON_SIZE_SMALL), "</a>",
  1925. "<a href=\"".$mylink."&action=delete\" onclick=\"javascript:if(!confirm('".addslashes(api_htmlentities(get_lang("ConfirmYourChoice"), ENT_QUOTES, $charset))."')) return false;\">",
  1926. Display::return_icon('delete.png', get_lang('Delete'), '', ICON_SIZE_SMALL), "</a>";
  1927. }
  1928. $mylink = 'ical_export.php?'.api_get_cidreq().'&type=course&id='.$myrow['id'];
  1929. //echo '<a class="ical_export" href="'.$mylink.'&class=confidential" title="'.get_lang('ExportiCalConfidential').'">'.Display::return_icon($export_icon_high, get_lang('ExportiCalConfidential')).'</a> ';
  1930. //echo '<a class="ical_export" href="'.$mylink.'&class=private" title="'.get_lang('ExportiCalPrivate').'">'.Display::return_icon($export_icon_low, get_lang('ExportiCalPrivate')).'</a> ';
  1931. //echo '<a class="ical_export" href="'.$mylink.'&class=public" title="'.get_lang('ExportiCalPublic').'">'.Display::return_icon($export_icon, get_lang('ExportiCalPublic')).'</a> ';
  1932. echo '<a href="javascript: void(0);" onclick="javascript:win_print=window.open(\'print.php?id='.$myrow['id'].'\',\'popup\',\'left=100,top=100,width=700,height=500,scrollbars=1,resizable=0\'); win_print.focus(); return false;">'.Display::return_icon('printer.png', get_lang('Print'), '', ICON_SIZE_SMALL).'</a>&nbsp;';
  1933. echo "</th>";
  1934. }
  1935. }
  1936. // title
  1937. echo "<tr class='row_odd'>";
  1938. echo '<td colspan="2">'.get_lang("StartTime").": ";
  1939. echo api_format_date($myrow['start_date']);
  1940. echo "</td>";
  1941. echo "</td>";
  1942. echo "<tr class='row_odd'>";
  1943. echo '<td colspan="2">'.get_lang("EndTime").": ";
  1944. echo api_convert_and_format_date($myrow['end_date']);
  1945. echo "</td>";
  1946. // Content
  1947. $content = $myrow['content'];
  1948. $content = make_clickable($content);
  1949. echo '<tr class="row_even">';
  1950. echo '<td '.(api_is_allowed_to_edit() ? 'colspan="3"' : 'colspan="2"').'>';
  1951. echo $content;
  1952. echo '</td></tr>';
  1953. //Attachments
  1954. $attachment_list = get_attachment($agenda_id);
  1955. if (!empty($attachment_list)) {
  1956. echo '<tr class="row_even"><td colspan="2">';
  1957. $realname = $attachment_list['path'];
  1958. $user_filename = $attachment_list['filename'];
  1959. $full_file_name = 'download.php?file='.$realname;
  1960. echo Display::return_icon('attachment.gif', get_lang('Attachment'));
  1961. echo '<a href="'.$full_file_name.'"> '.$user_filename.'</a>';
  1962. if (api_is_allowed_to_edit()) {
  1963. echo '&nbsp;&nbsp;<a href="'.api_get_self().'?'.api_get_cidreq().'&origin='.Security::remove_XSS($_GET['origin']).'&action=delete_attach&id_attach='.$attachment_list['id'].'" onclick="javascript:if(!confirm(\''.addslashes(api_htmlentities(get_lang("ConfirmYourChoice"), ENT_QUOTES, $charset)).'\')) return false;">'.Display::return_icon('delete.png', get_lang('Delete'), '', ICON_SIZE_SMALL).'</a><br />';
  1964. }
  1965. echo '<br /><span class="forum_attach_comment" >'.$attachment_list['comment'].'</span>';
  1966. echo '</td></tr>';
  1967. }
  1968. // the message has been sent to
  1969. echo '<tr>';
  1970. echo "<td class='announcements_datum'>".get_lang("SentTo").": ";
  1971. $sent_to = sent_to(TOOL_CALENDAR_EVENT, $myrow["ref"]);
  1972. $sent_to_form = sent_to_form($sent_to);
  1973. echo $sent_to_form;
  1974. echo "</td></tr>";
  1975. if ($repeat) {
  1976. echo '<tr>';
  1977. echo '<td colspan="2">';
  1978. echo get_lang('RepeatedEvent').' <a href="', api_get_self(), '?', api_get_cidreq(), '&agenda_id=', $repeat_id, '" alt="', get_lang('RepeatedEventViewOriginalEvent'), '">', get_lang('RepeatedEventViewOriginalEvent'), '</a>';
  1979. echo '</td>';
  1980. echo '</tr>';
  1981. }
  1982. /* Added resources */
  1983. if (check_added_resources("Agenda", $myrow["id"])) {
  1984. echo "<tr><td colspan='3'>";
  1985. echo "<i>".get_lang("AddedResources")."</i><br/>";
  1986. if ($myrow['visibility'] == 0) {
  1987. $addedresource_style = "invisible";
  1988. }
  1989. display_added_resources("Agenda", $myrow["id"], $addedresource_style);
  1990. echo "</td></tr>";
  1991. }
  1992. // closing the layout table
  1993. echo "</td>",
  1994. "</tr>",
  1995. "</table>";
  1996. }
  1997. /**
  1998. * Show the form for adding a new agenda item. This is the same function that is used whenever we are editing an
  1999. * agenda item. When the id parameter is empty (default behaviour), then we show an empty form, else we are editing and
  2000. * we have to retrieve the information that is in the database and use this information in the forms.
  2001. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  2002. * @param integer id, the id of the agenda item we are editing. By default this is empty which means that we are adding an
  2003. * agenda item.
  2004. */
  2005. function show_add_form($id = '', $type = null)
  2006. {
  2007. global $MonthsLong;
  2008. $htmlHeadXtra[] = to_javascript();
  2009. // the default values for the forms
  2010. if ($_GET['originalresource'] !== 'no') {
  2011. $day = date('d');
  2012. $month = date('m');
  2013. $year = date('Y');
  2014. $hours = 9;
  2015. $minutes = '00';
  2016. $end_day = date('d');
  2017. $end_month = date('m');
  2018. $end_year = date('Y');
  2019. $end_hours = 17;
  2020. $end_minutes = '00';
  2021. $repeat = false;
  2022. } else {
  2023. // we are coming from the resource linker so there might already have been some information in the form.
  2024. // When we clicked on the button to add resources we stored every form information into a session and now we
  2025. // are doing the opposite thing: getting the information out of the session and putting it into variables to
  2026. // display it in the forms.
  2027. $form_elements = $_SESSION['formelements'];
  2028. $day = $form_elements['day'];
  2029. $month = $form_elements['month'];
  2030. $year = $form_elements['year'];
  2031. $hours = $form_elements['hour'];
  2032. $minutes = $form_elements['minutes'];
  2033. $end_day = $form_elements['end_day'];
  2034. $end_month = $form_elements['end_month'];
  2035. $end_year = $form_elements['end_year'];
  2036. $end_hours = $form_elements['end_hours'];
  2037. $end_minutes = $form_elements['end_minutes'];
  2038. $title = $form_elements['title'];
  2039. $content = $form_elements['content'];
  2040. $id = $form_elements['id'];
  2041. $to = $form_elements['to'];
  2042. $repeat = $form_elements['repeat'];
  2043. }
  2044. // switching the send to all/send to groups/send to users
  2045. if (isset($_POST['To']) && $_POST['To']) {
  2046. $day = $_POST['fday'];
  2047. $month = $_POST['fmonth'];
  2048. $year = $_POST['fyear'];
  2049. $hours = $_POST['fhour'];
  2050. $minutes = $_POST['fminute'];
  2051. $end_day = $_POST['end_fday'];
  2052. $end_month = $_POST['end_fmonth'];
  2053. $end_year = $_POST['end_fyear'];
  2054. $end_hours = $_POST['end_fhour'];
  2055. $end_minutes = $_POST['end_fminute'];
  2056. $title = $_POST['title'];
  2057. $content = $_POST['content'];
  2058. // the invisible fields
  2059. $action = $_POST['action'];
  2060. $id = $_POST['id'];
  2061. $repeat = !empty($_POST['repeat']) ? true : false;
  2062. }
  2063. $default_no_empty_end_date = 0;
  2064. $course_info = null;
  2065. // if the id is set then we are editing an agenda item
  2066. if (!empty($id)) {
  2067. $course_info = api_get_course_info();
  2068. $agendaObj = new Agenda();
  2069. if (!empty($course_info)) {
  2070. $agendaObj->set_course($course_info);
  2071. $agendaObj->type = 'course';
  2072. } else {
  2073. if (api_is_platform_admin() && $type == 'platform') {
  2074. $agendaObj->type = 'admin';
  2075. } else {
  2076. $agendaObj->type = 'personal';
  2077. }
  2078. }
  2079. $agendaItem = $agendaObj->get_event($id);
  2080. $title = $agendaItem['title'];
  2081. $content = $agendaItem['description'];
  2082. // start date
  2083. if ($agendaItem['start_date'] != '0000-00-00 00:00:00') {
  2084. $agendaItem['start_date'] = api_get_local_time($agendaItem['start_date']);
  2085. list($datepart, $timepart) = explode(" ", $agendaItem['start_date']);
  2086. list($year, $month, $day) = explode("-", $datepart);
  2087. list($hours, $minutes, $seconds) = explode(":", $timepart);
  2088. }
  2089. // end date
  2090. if (!empty($agendaItem['end_date']) && $agendaItem['end_date'] != '0000-00-00 00:00:00') {
  2091. $agendaItem['end_date'] = api_get_local_time($agendaItem['end_date']);
  2092. list($datepart, $timepart) = explode(" ", $agendaItem['end_date']);
  2093. list($end_year, $end_month, $end_day) = explode("-", $datepart);
  2094. list($end_hours, $end_minutes, $end_seconds) = explode(":", $timepart);
  2095. } else {
  2096. if ($agendaItem['all_day']) {
  2097. $end_year = $year;
  2098. $end_month = $month;
  2099. $end_day = $day;
  2100. $end_hours = $hours;
  2101. $end_minutes = $minutes;
  2102. $end_seconds = $seconds;
  2103. }
  2104. }
  2105. // attachments
  2106. //edit_added_resources("Agenda", $id);
  2107. //$to = $item_2_edit['to'];
  2108. } else {
  2109. $to = load_edit_users(TOOL_CALENDAR_EVENT, $id);
  2110. }
  2111. $content = stripslashes($content);
  2112. $title = stripslashes($title);
  2113. // we start a completely new item, we do not come from the resource linker
  2114. if (isset($_GET['originalresource']) && $_GET['originalresource'] !== "no" and $_GET['action'] == "add") {
  2115. $_SESSION["formelements"] = null;
  2116. unset_session_resources();
  2117. }
  2118. $origin = isset($_GET['origin']) ? Security::remove_XSS($_GET['origin']) : null;
  2119. $course_url = empty($course_info) ? null : api_get_cidreq();
  2120. ?>
  2121. <!-- START OF THE FORM -->
  2122. <form class="form-horizontal" enctype="multipart/form-data" action="<?php echo api_get_self().'?type='.Security::remove_XSS($type).'&origin='.$origin.'&'.$course_url."&sort=asc&toolgroup=".api_get_group_id().'&action='.Security::remove_XSS($_GET['action']); ?>" method="post" name="new_calendar_item">
  2123. <input type="hidden" name="id" value="<?php if (isset($id)) echo $id; ?>" />
  2124. <input type="hidden" name="action" value="<?php if (isset($_GET['action'])) echo $_GET['action']; ?>" />
  2125. <input type="hidden" name="id_attach" value="<?php echo isset($_REQUEST['id_attach']) ? intval($_REQUEST['id_attach']) : null; ?>" />
  2126. <input type="hidden" name="sort" value="asc" />
  2127. <input type="hidden" name="submit_event" value="ok" />
  2128. <?php
  2129. // The form title
  2130. if (isset($id) AND $id <> '') {
  2131. $form_title = get_lang('ModifyCalendarItem');
  2132. } else {
  2133. $form_title = get_lang('AddCalendarItem');
  2134. }
  2135. echo '<legend>'.$form_title.'</legend>';
  2136. // the title of the agenda item
  2137. echo '<div class="control-group">
  2138. <label class="control-label">
  2139. <span class="form_required">*</span>'.get_lang('ItemTitle').'
  2140. </label>
  2141. <div class="controls">
  2142. <div id="err_title" style="display:none;color:red"></div>
  2143. <input type="text" id="agenda_title" class="span5" name="title" value="';
  2144. if (isset($title))
  2145. echo $title;
  2146. echo '" />
  2147. </div>
  2148. </div>';
  2149. // selecting the users / groups
  2150. $group_id = api_get_group_id();
  2151. if (empty($id)) {
  2152. if (isset($group_id) && !empty($group_id)) {
  2153. echo '<input type="hidden" name="selected_form[0]" value="GROUP:'.$group_id.'"/>';
  2154. echo '<input type="hidden" name="To" value="true"/>';
  2155. } else {
  2156. echo '<div class="control-group">
  2157. <label class="control-label">
  2158. '.Display::return_icon('group.png', get_lang('To'), array('align' => 'absmiddle'), ICON_SIZE_SMALL).' '.get_lang('To').'</a>
  2159. </label>
  2160. <div class="controls">';
  2161. show_to_form($to);
  2162. echo '</div>
  2163. </div>';
  2164. }
  2165. }
  2166. // start date and time
  2167. echo '<div class="control-group">';
  2168. echo '<label class="control-label">'.get_lang('StartDate').'</label>
  2169. <div class="controls">
  2170. <div id="err_date" style="display:none;color:red"></div>
  2171. <div id="err_start_date" style="display:none;color:red"></div>';
  2172. ?>
  2173. <select name="fday" onchange="javascript:document.new_calendar_item.end_fday.value=this.value;">
  2174. <?php
  2175. // small loop for filling all the dates
  2176. // 2do: the available dates should be those of the selected month => february is from 1 to 28 (or 29) and not to 31
  2177. foreach (range(1, 31) as $i) {
  2178. // values have to have double digits
  2179. $value = ($i <= 9 ? '0'.$i : $i );
  2180. // the current day is indicated with [] around the date
  2181. if ($value == $day) {
  2182. echo "<option value=\"".$value."\" selected> ".$i." </option>";
  2183. } else {
  2184. echo "<option value=\"$value\">$i</option>";
  2185. }
  2186. }
  2187. ?>
  2188. </select>
  2189. <select name="fmonth" onchange="javascript:document.new_calendar_item.end_fmonth.value=this.value;">
  2190. <?php
  2191. for ($i = 1; $i <= 12; $i++) {
  2192. // values have to have double digits
  2193. if ($i <= 9) {
  2194. $value = "0".$i;
  2195. } else {
  2196. $value = $i;
  2197. }
  2198. if ($value == $month) {
  2199. echo "<option value=\"".$value."\" selected>".$MonthsLong[$i - 1]."</option>";
  2200. } else {
  2201. echo "<option value=\"".$value."\">".$MonthsLong[$i - 1]."</option>";
  2202. }
  2203. }
  2204. ?>
  2205. </select>
  2206. <select name="fyear" onchange="javascript:document.new_calendar_item.end_fyear.value=this.value;">
  2207. <option value="<?php echo ($year - 1); ?>"><?php echo ($year - 1); ?></option>
  2208. <option value="<?php echo $year; ?>" selected="selected"><?php echo $year; ?></option>
  2209. <?php
  2210. for ($i = 1; $i <= 5; $i++) {
  2211. $value = $year + $i;
  2212. echo "<option value=\"$value\">$value</option>";
  2213. }
  2214. ?>
  2215. </select>
  2216. <a href="javascript:openCalendar('new_calendar_item', 'f')">
  2217. <?php Display::display_icon('calendar_select.gif', get_lang('Select'), array('style' => 'vertical-align: middle;')); ?>
  2218. </a>
  2219. &nbsp;<?php echo get_lang('StartTime').": "; ?>&nbsp;
  2220. <select name="fhour" onchange="javascript:document.new_calendar_item.end_fhour.value=this.value;">
  2221. <!-- <option value="--">--</option> -->
  2222. <?php
  2223. foreach (range(0, 23) as $i) {
  2224. // values have to have double digits
  2225. $value = ($i <= 9 ? '0'.$i : $i );
  2226. // the current hour is indicated with [] around the hour
  2227. if ($hours == $value) {
  2228. echo "<option value=\"".$value."\" selected> ".$value." </option>";
  2229. } else {
  2230. echo "<option value=\"$value\">$value</option>";
  2231. }
  2232. }
  2233. ?>
  2234. </select>
  2235. <select name="fminute" onchange="javascript:document.new_calendar_item.end_fminute.value=this.value;">
  2236. <!-- <option value="<?php echo $minutes ?>"><?php echo $minutes; ?></option> -->
  2237. <?php
  2238. foreach (range(0, 59) as $i) {
  2239. // values have to have double digits
  2240. $value = ($i <= 9 ? '0'.$i : $i );
  2241. if ($minutes == $value) {
  2242. echo "<option value=\"".$value."\" selected> ".$value." </option>";
  2243. } else {
  2244. echo "<option value=\"$value\">$value</option>";
  2245. }
  2246. }
  2247. ?>
  2248. </select>
  2249. <?php
  2250. echo ' </div>
  2251. </div>';
  2252. echo '<script>
  2253. $(function() {
  2254. $("#empty_end_date").click(function(){
  2255. if ($("#empty_end_date").is(":checked")) {
  2256. $("#end_date_span").hide();
  2257. } else {
  2258. $("#end_date_span").show();
  2259. }
  2260. });';
  2261. if (isset($item_2_edit['end_date']) && $item_2_edit['end_date'] == '0000-00-00 00:00:00') {
  2262. echo '$("#end_date_span").hide();';
  2263. } echo '
  2264. });
  2265. </script>';
  2266. // end date and time
  2267. echo '<span id="end_date_span">';
  2268. echo '<div class="control-group">
  2269. <label class="control-label">
  2270. '.get_lang('EndDate').'
  2271. </label>
  2272. <div class="controls">
  2273. <div id="err_end_date" style="display:none;color:red"></div>';
  2274. ?>
  2275. <select id="end_fday" name="end_fday">
  2276. <?php
  2277. // small loop for filling all the dates
  2278. // 2do: the available dates should be those of the selected month => february is from 1 to 28 (or 29) and not to 31
  2279. foreach (range(1, 31) as $i) {
  2280. // values have to have double digits
  2281. $value = ($i <= 9 ? '0'.$i : $i );
  2282. // the current day is indicated with [] around the date
  2283. if ($value == $end_day) {
  2284. echo "<option value=\"".$value."\" selected> ".$i." </option>";
  2285. } else {
  2286. echo "<option value=\"".$value."\">".$i."</option>";
  2287. }
  2288. }
  2289. ?>
  2290. </select>
  2291. <!-- month: january -> december -->
  2292. <select id="end_fmonth" name="end_fmonth">
  2293. <?php
  2294. foreach (range(1, 12) as $i) {
  2295. // values have to have double digits
  2296. $value = ($i <= 9 ? '0'.$i : $i );
  2297. if ($value == $end_month) {
  2298. echo "<option value=\"".$value."\" selected>".$MonthsLong[$i - 1]."</option>";
  2299. } else {
  2300. echo "<option value=\"".$value."\">".$MonthsLong[$i - 1]."</option>";
  2301. }
  2302. }
  2303. ?>
  2304. </select>
  2305. <select id="end_fyear" name="end_fyear">
  2306. <option value="<?php echo ($end_year - 2) ?>"><?php echo ($end_year - 2) ?></option>
  2307. <option value="<?php echo ($end_year - 1) ?>"><?php echo ($end_year - 1) ?></option>
  2308. <option value="<?php echo $end_year ?>" selected> <?php echo $end_year ?> </option>
  2309. <?php
  2310. for ($i = 1; $i <= 5; $i++) {
  2311. $value = $end_year + $i;
  2312. echo "<option value=\"$value\">$value</option>";
  2313. }
  2314. ?>
  2315. </select>
  2316. <a href="javascript:openCalendar('new_calendar_item', 'end_f')">
  2317. <?php echo Display::span(Display::return_icon('calendar_select.gif', get_lang('Select'), array('style' => 'vertical-align: middle;')), array('id' => 'end_date_calendar_icon')); ?>
  2318. </a>
  2319. &nbsp;<?php echo get_lang('EndTime').": "; ?>&nbsp;
  2320. <select id="end_fhour" name="end_fhour">
  2321. <!-- <option value="--">--</option> -->
  2322. <?php
  2323. foreach (range(0, 23) as $i) {
  2324. // values have to have double digits
  2325. $value = ($i <= 9 ? '0'.$i : $i );
  2326. // the current hour is indicated with [] around the hour
  2327. if ($end_hours == $value) {
  2328. echo "<option value=\"".$value."\" selected> ".$value." </option>";
  2329. } else {
  2330. echo "<option value=\"".$value."\"> ".$value." </option>";
  2331. }
  2332. }
  2333. ?>
  2334. </select>
  2335. <select id="end_fminute" name="end_fminute">
  2336. <!-- <option value="<?php echo $end_minutes; ?>"><?php echo $end_minutes; ?></option> -->
  2337. <!-- <option value="--">--</option> -->
  2338. <?php
  2339. foreach (range(0, 59) as $i) {
  2340. // values have to have double digits
  2341. //$value = ($i <= 9 ? '0'.$i : $i );
  2342. $value = ($i <= 9 ? '0'.$i : $i );
  2343. if ($end_minutes == $value) {
  2344. echo "<option value=\"".$value."\" selected> ".$value." </option>";
  2345. } else {
  2346. echo "<option value=\"$value\">$value</option>";
  2347. }
  2348. }
  2349. ?>
  2350. </select>
  2351. <?php
  2352. echo ' </div>
  2353. </div> </span>';
  2354. // Repeating the calendar item
  2355. if (empty($id)) {
  2356. //only show repeat fields when adding, not for editing an calendar item
  2357. echo '<div class="control-group">
  2358. <label class="control-label"></label>
  2359. <div class="controls">
  2360. <a href="javascript://" onclick="return plus_repeated_event();"><span id="plus2">
  2361. <img style="vertical-align:middle;" src="../img/div_show.gif" alt="" />&nbsp;'.get_lang('RepeatEvent').'</span>
  2362. </a>';
  2363. ?>
  2364. <table id="options2" style="display: none;">
  2365. <tr>
  2366. <td>
  2367. <label for="repeat_id">
  2368. <input id="repeat_id" type="checkbox" name="repeat" <?php echo ($repeat ? 'checked="checked"' : ''); ?>/>
  2369. <?php echo get_lang('RepeatEvent'); ?>
  2370. </label></td>
  2371. <td>
  2372. </td>
  2373. </tr>
  2374. <tr>
  2375. <td><label><?php echo get_lang('RepeatType'); ?></label></td>
  2376. <td>
  2377. <select name="repeat_type">
  2378. <option value="daily"><?php echo get_lang('RepeatDaily'); ?></option>
  2379. <option value="weekly"><?php echo get_lang('RepeatWeekly'); ?></option>
  2380. <option value="monthlyByDate"><?php echo get_lang('RepeatMonthlyByDate'); ?></option>
  2381. <!--option value="monthlyByDay"><?php echo get_lang('RepeatMonthlyByDay'); ?></option>
  2382. <option value="monthlyByDayR"><?php echo get_lang('RepeatMonthlyByDayR'); ?></option-->
  2383. <option value="yearly"><?php echo get_lang('RepeatYearly'); ?></option>
  2384. </select>
  2385. </td>
  2386. </tr>
  2387. <tr>
  2388. <td><label><?php echo get_lang('RepeatEnd'); ?></label></td>
  2389. <td>
  2390. <select name="repeat_end_day">
  2391. <?php
  2392. // small loop for filling all the dates
  2393. // 2do: the available dates should be those of the selected month => february is from 1 to 28 (or 29) and not to 31
  2394. foreach (range(1, 31) as $i) {
  2395. // values have to have double digits
  2396. $value = ($i <= 9 ? '0'.$i : $i );
  2397. // the current day is indicated with [] around the date
  2398. if ($value == $end_day) {
  2399. echo "<option value=\"".$value."\" selected> ".$i." </option>";
  2400. } else {
  2401. echo "<option value=\"".$value."\">".$i."</option>";
  2402. }
  2403. }
  2404. ?>
  2405. </select>
  2406. <!-- month: january -> december -->
  2407. <select name="repeat_end_month">
  2408. <?php
  2409. foreach (range(1, 12) as $i) {
  2410. // values have to have double digits
  2411. $value = ($i <= 9 ? '0'.$i : $i );
  2412. if ($value == $end_month + 1) {
  2413. echo '<option value="', $value, '" selected="selected">', $MonthsLong[$i - 1], "</option>";
  2414. } else {
  2415. echo '<option value="', $value, '">', $MonthsLong[$i - 1], "</option>";
  2416. }
  2417. }
  2418. ?>
  2419. </select>
  2420. <select name="repeat_end_year">
  2421. <option value="<?php echo ($end_year - 1) ?>"><?php echo ($end_year - 1) ?></option>
  2422. <option value="<?php echo $end_year ?>" selected> <?php echo $end_year ?> </option>
  2423. <?php
  2424. for ($i = 1; $i <= 5; $i++) {
  2425. $value = $end_year + $i;
  2426. echo "<option value=\"$value\">$value</option>";
  2427. }
  2428. ?>
  2429. </select>
  2430. <a href="javascript:openCalendar('new_calendar_item', 'repeat_end_')">
  2431. <?php Display::display_icon('calendar_select.gif', get_lang('Select'), array('style' => 'vertical-align: middle;')); ?>
  2432. </a>
  2433. </td>
  2434. </tr>
  2435. </table>
  2436. <?php
  2437. echo ' </div>
  2438. </div>';
  2439. }
  2440. if (isset($agendaItem['all_day'])) {
  2441. $checked = null;
  2442. if ($agendaItem['all_day']) {
  2443. $checked = 'checked';
  2444. }
  2445. echo ' <div class="control-group">
  2446. <label class="control-label"></label>
  2447. <div class="controls">
  2448. <input type="checkbox" '.$checked.' name="all_day"/> '.get_lang('AllDay').'
  2449. </div>
  2450. </div>';
  2451. }
  2452. //only show repeat fields if adding, not if editing
  2453. // the main area of the agenda item: the wysiwyg editor
  2454. echo ' <div class="control-group">
  2455. <label class="control-label">
  2456. <span class="form_required">*</span>'.get_lang('Description').'
  2457. </label>
  2458. <div class="controls">';
  2459. require_once api_get_path(LIBRARY_PATH)."/fckeditor/fckeditor.php";
  2460. $oFCKeditor = new FCKeditor('content');
  2461. $oFCKeditor->Width = '100%';
  2462. $oFCKeditor->Height = '200';
  2463. if (!api_is_allowed_to_edit(null, true)) {
  2464. $oFCKeditor->ToolbarSet = 'AgendaStudent';
  2465. } else {
  2466. $oFCKeditor->ToolbarSet = 'Agenda';
  2467. }
  2468. $oFCKeditor->Value = $content;
  2469. $return = $oFCKeditor->CreateHtml();
  2470. echo $return;
  2471. echo '</div>
  2472. <div class = "controls">
  2473. <label>
  2474. <input id="add_announcement" type="checkbox" name="add_announcement" checked="checked"/>
  2475. '.get_lang('AddAnnouncement').'&nbsp('.get_lang('SendMail').')
  2476. </label>
  2477. </div>
  2478. </div>';
  2479. if ($agendaObj->type == 'course') {
  2480. // File attachment
  2481. echo ' <div class="control-group">
  2482. <label class="control-label">
  2483. '.get_lang('AddAnAttachment').'&nbsp;</label>
  2484. <div class="controls">
  2485. <input type="file" name="user_upload"/>
  2486. </div>
  2487. <label class="control-label">'.
  2488. get_lang('Comment').'
  2489. </label>
  2490. <div class="controls">
  2491. <textarea name="file_comment" type="textarea"></textarea>
  2492. </div>
  2493. </div>';
  2494. }
  2495. // the submit button for storing the calendar item
  2496. echo ' <div class="control-group">
  2497. <label class="control-label">
  2498. </label>
  2499. <div class="controls">';
  2500. if (isset($_GET['id'])) {
  2501. $class = 'save';
  2502. $text = get_lang('ModifyEvent');
  2503. } else {
  2504. $class = 'add';
  2505. $text = get_lang('AgendaAdd');
  2506. }
  2507. echo '<button class="'.$class.'" type="button" name="name" onclick="selectAll(document.getElementById(\'selected_form\'),true)">'.$text.'</button>';
  2508. echo ' </div>
  2509. </div>';
  2510. ?>
  2511. </form>
  2512. <?php
  2513. }
  2514. function get_agendaitems($month, $year)
  2515. {
  2516. $items = array();
  2517. $month = Database::escape_string($month);
  2518. $year = Database::escape_string($year);
  2519. //databases of the courses
  2520. $TABLEAGENDA = Database :: get_course_table(TABLE_AGENDA);
  2521. $TABLE_ITEMPROPERTY = Database :: get_course_table(TABLE_ITEM_PROPERTY);
  2522. $course_info = api_get_course_info();
  2523. $group_memberships = GroupManager :: get_group_ids($course_info['real_id'], api_get_user_id());
  2524. // if the user is administrator of that course we show all the agenda items
  2525. if (api_is_allowed_to_edit(false, true)) {
  2526. //echo "course admin";
  2527. $sqlquery = "SELECT
  2528. DISTINCT agenda.*, item_property.*
  2529. FROM ".$TABLEAGENDA." agenda,
  2530. ".$TABLE_ITEMPROPERTY." item_property
  2531. WHERE agenda.id = item_property.ref
  2532. AND MONTH(agenda.start_date)='".$month."'
  2533. AND YEAR(agenda.start_date)='".$year."'
  2534. AND item_property.tool='".TOOL_CALENDAR_EVENT."'
  2535. AND item_property.visibility='1'
  2536. GROUP BY agenda.id
  2537. ORDER BY start_date ";
  2538. }
  2539. // if the user is not an administrator of that course
  2540. else {
  2541. //echo "GEEN course admin";
  2542. if (is_array($group_memberships) && count($group_memberships) > 0) {
  2543. $sqlquery = "SELECT
  2544. agenda.*, item_property.*
  2545. FROM ".$TABLEAGENDA." agenda,
  2546. ".$TABLE_ITEMPROPERTY." item_property
  2547. WHERE agenda.id = item_property.ref
  2548. AND MONTH(agenda.start_date)='".$month."'
  2549. AND YEAR(agenda.start_date)='".$year."'
  2550. AND item_property.tool='".TOOL_CALENDAR_EVENT."'
  2551. AND ( item_property.to_user_id='".api_get_user_id()."' OR item_property.to_group_id IN (0, ".implode(", ", $group_memberships).") )
  2552. AND item_property.visibility='1'
  2553. ORDER BY start_date ";
  2554. } else {
  2555. $sqlquery = "SELECT
  2556. agenda.*, item_property.*
  2557. FROM ".$TABLEAGENDA." agenda,
  2558. ".$TABLE_ITEMPROPERTY." item_property
  2559. WHERE agenda.id = item_property.ref
  2560. AND MONTH(agenda.start_date)='".$month."'
  2561. AND YEAR(agenda.start_date)='".$year."'
  2562. AND item_property.tool='".TOOL_CALENDAR_EVENT."'
  2563. AND ( item_property.to_user_id='".api_get_user_id()."' OR item_property.to_group_id='0')
  2564. AND item_property.visibility='1'
  2565. ORDER BY start_date ";
  2566. }
  2567. }
  2568. $mycourse = api_get_course_info();
  2569. $result = Database::query($sqlquery);
  2570. while ($item = Database::fetch_array($result)) {
  2571. $agendaday_string = api_convert_and_format_date($item['start_date'], "%d", date_default_timezone_get());
  2572. $agendaday = intval($agendaday_string);
  2573. $time = api_convert_and_format_date($item['start_date'], TIME_NO_SEC_FORMAT);
  2574. $URL = api_get_path(WEB_CODE_PATH).'calendar/agenda.php?cidReq='.$mycourse['id']."&day=$agendaday&month=$month&year=$year#$agendaday"; // RH //Patrick Cool: to highlight the relevant agenda item
  2575. $items[$agendaday][$item['start_time']] .= '<i>'.$time.'</i> <a href="'.$URL.'" title="'.$mycourse['name'].'">'.$mycourse['official_code'].'</a> '.$item['title'].'<br />';
  2576. }
  2577. // sorting by hour for every day
  2578. $agendaitems = array();
  2579. while (list ($agendaday, $tmpitems) = each($items)) {
  2580. sort($tmpitems);
  2581. while (list ($key, $val) = each($tmpitems)) {
  2582. $agendaitems[$agendaday] .= $val;
  2583. }
  2584. }
  2585. return $agendaitems;
  2586. }
  2587. function display_upcoming_events()
  2588. {
  2589. $number_of_items_to_show = (int) api_get_setting('number_of_upcoming_events');
  2590. //databases of the courses
  2591. $TABLEAGENDA = Database :: get_course_table(TABLE_AGENDA);
  2592. $TABLE_ITEMPROPERTY = Database :: get_course_table(TABLE_ITEM_PROPERTY);
  2593. $mycourse = api_get_course_info();
  2594. $myuser = api_get_user_info();
  2595. $session_id = api_get_session_id();
  2596. $course_id = $mycourse['real_id'];
  2597. $group_memberships = GroupManager :: get_group_ids($mycourse['real_id'], $myuser['user_id']);
  2598. // if the user is administrator of that course we show all the agenda items
  2599. if (api_is_allowed_to_edit(false, true)) {
  2600. //echo "course admin";
  2601. $sqlquery = "SELECT
  2602. DISTINCT agenda.*, item_property.*
  2603. FROM ".$TABLEAGENDA." agenda,
  2604. ".$TABLE_ITEMPROPERTY." item_property
  2605. WHERE
  2606. agenda.c_id = $course_id AND
  2607. item_property.c_id = $course_id AND
  2608. agenda.id = item_property.ref
  2609. AND item_property.tool='".TOOL_CALENDAR_EVENT."'
  2610. AND item_property.visibility='1'
  2611. AND agenda.start_date > NOW()
  2612. AND session_id = '".$session_id."'
  2613. GROUP BY agenda.id
  2614. ORDER BY start_date ";
  2615. }
  2616. // if the user is not an administrator of that course
  2617. else {
  2618. //echo "GEEN course admin";
  2619. if (is_array($group_memberships) and count($group_memberships) > 0) {
  2620. $sqlquery = "SELECT
  2621. agenda.*, item_property.*
  2622. FROM ".$TABLEAGENDA." agenda,
  2623. ".$TABLE_ITEMPROPERTY." item_property
  2624. WHERE
  2625. agenda.c_id = $course_id AND
  2626. item_property.c_id = $course_id AND
  2627. agenda.id = item_property.ref
  2628. AND item_property.tool='".TOOL_CALENDAR_EVENT."'
  2629. AND ( item_property.to_user_id='".$myuser['user_id']."' OR item_property.to_group_id IN (0, ".implode(", ", $group_memberships).") )
  2630. AND item_property.visibility='1'
  2631. AND agenda.start_date > NOW()
  2632. AND session_id = '".$session_id."'
  2633. ORDER BY start_date ";
  2634. } else {
  2635. $sqlquery = "SELECT
  2636. agenda.*, item_property.*
  2637. FROM ".$TABLEAGENDA." agenda,
  2638. ".$TABLE_ITEMPROPERTY." item_property
  2639. WHERE
  2640. agenda.c_id = $course_id AND
  2641. item_property.c_id = $course_id AND
  2642. agenda.id = item_property.ref
  2643. AND item_property.tool='".TOOL_CALENDAR_EVENT."'
  2644. AND ( item_property.to_user_id='".$myuser['user_id']."' OR item_property.to_group_id='0')
  2645. AND item_property.visibility='1'
  2646. AND agenda.start_date > NOW()
  2647. AND session_id = '".$session_id."'
  2648. ORDER BY start_date ";
  2649. }
  2650. }
  2651. $result = Database::query($sqlquery);
  2652. $counter = 0;
  2653. if (Database::num_rows($result) > 0) {
  2654. echo '<h4>'.get_lang('UpcomingEvent').'</h4><br />';
  2655. while ($item = Database::fetch_array($result, 'ASSOC')) {
  2656. if ($counter < $number_of_items_to_show) {
  2657. echo api_get_local_time($item['start_date']), ' - ', $item['title'], '<br />';
  2658. $counter++;
  2659. }
  2660. }
  2661. }
  2662. }
  2663. /**
  2664. * This function calculates the startdate of the week (monday)
  2665. * and the enddate of the week (sunday)
  2666. * and returns it as an array
  2667. * @todo check if this function is correct
  2668. */
  2669. function calculate_start_end_of_week($week_number, $year)
  2670. {
  2671. // determine the start and end date
  2672. // step 1: we calculate a timestamp for a day in this week
  2673. //@todo Why ($week_number - 1) ?
  2674. //$random_day_in_week = mktime(0, 0, 0, 1, 1, $year) + ($week_number-1) * (7 * 24 * 60 * 60); // we calculate a random day in this week
  2675. $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
  2676. // step 2: we which day this is (0=sunday, 1=monday, ...)
  2677. $number_day_in_week = date('w', $random_day_in_week);
  2678. // step 3: we calculate the timestamp of the monday of the week we are in
  2679. $start_timestamp = $random_day_in_week - (($number_day_in_week - 1) * 24 * 60 * 60);
  2680. // step 4: we calculate the timestamp of the sunday of the week we are in
  2681. $end_timestamp = $random_day_in_week + ((7 - $number_day_in_week + 1) * 24 * 60 * 60) - 3600;
  2682. // step 5: calculating the start_day, end_day, start_month, end_month, start_year, end_year
  2683. $start_day = date('j', $start_timestamp);
  2684. $start_month = date('n', $start_timestamp);
  2685. $start_year = date('Y', $start_timestamp);
  2686. $end_day = date('j', $end_timestamp);
  2687. $end_month = date('n', $end_timestamp);
  2688. $end_year = date('Y', $end_timestamp);
  2689. $start_end_array['start']['day'] = $start_day;
  2690. $start_end_array['start']['month'] = $start_month;
  2691. $start_end_array['start']['year'] = $start_year;
  2692. $start_end_array['end']['day'] = $end_day;
  2693. $start_end_array['end']['month'] = $end_month;
  2694. $start_end_array['end']['year'] = $end_year;
  2695. return $start_end_array;
  2696. }
  2697. /**
  2698. * Show the mini calendar of the given month
  2699. */
  2700. function display_daycalendar($agendaitems, $day, $month, $year, $weekdaynames, $monthName)
  2701. {
  2702. global $DaysShort, $DaysLong, $course_path;
  2703. global $MonthsLong;
  2704. global $query;
  2705. // timestamp of today
  2706. $today = mktime();
  2707. $nextday = $today + (24 * 60 * 60);
  2708. $previousday = $today - (24 * 60 * 60);
  2709. // the week number of the year
  2710. $week_number = date("W", $today);
  2711. // if we moved to the next / previous day we have to recalculate the $today variable
  2712. if (isset($_GET['day'])) {
  2713. $today = mktime(0, 0, 0, $month, $day, $year);
  2714. $nextday = $today + (24 * 60 * 60);
  2715. $previousday = $today - (24 * 60 * 60);
  2716. $week_number = date("W", $today);
  2717. }
  2718. // calculating the start date of the week
  2719. // the date of the monday of this week is the timestamp of today minus
  2720. // number of days that have already passed this week * 24 hours * 60 minutes * 60 seconds
  2721. $current_day = date("j", $today); // Day of the month without leading zeros (1 to 31) of today
  2722. $day_of_the_week = date("w", $today); // Numeric representation of the day of the week 0 (for Sunday) through 6 (for Saturday) of today
  2723. // we are loading all the calendar items of all the courses for today
  2724. echo "<table class=\"data_table\">";
  2725. // the forward and backwards url
  2726. $course_code = isset($_GET['courseCode']) ? Security::remove_XSS($_GET['courseCode']) : null;
  2727. $backwardsURL = api_get_self()."?coursePath=".urlencode($course_path)."&courseCode=".$course_code."&action=view&view=day&day=".date("j", $previousday)."&month=".date("n", $previousday)."&year=".date("Y", $previousday);
  2728. $forewardsURL = api_get_self()."?coursePath=".urlencode($course_path)."&courseCode=".$course_code."&action=view&view=day&day=".date("j", $nextday)."&month=".date("n", $nextday)."&year=".date("Y", $nextday);
  2729. // The title row containing the day
  2730. echo "<tr>", "<th width=\"10%\"><a href=\"", $backwardsURL, "\">".Display::return_icon('action_prev.png', get_lang('Previous'))."</a></th>", "<th>";
  2731. echo $DaysLong[$day_of_the_week]." ".date("j", $today)." ".$MonthsLong[date("n", $today) - 1]." ".date("Y", $today);
  2732. echo "</th>";
  2733. echo "<th width=\"10%\"><a href=\"", $forewardsURL, "\">".Display::return_icon('action_next.png', get_lang('Next'))."</a></th>";
  2734. echo "</tr>";
  2735. // From 0 to 5h
  2736. $class = "class=\"row_even\"";
  2737. echo "<tr $class>";
  2738. echo ("<td valign=\"top\" width=\"75\">0:00 ".get_lang("HourShort")." - 4:30 ".get_lang("HourShort")."</td>");
  2739. echo "<td $class valign=\"top\" colspan=\"2\">";
  2740. for ($i = 0; $i < 10; $i++) {
  2741. if (isset($agendaitems[$i])) {
  2742. if (is_array($agendaitems[$i])) {
  2743. foreach ($agendaitems[$i] as $key => $value) {
  2744. echo $value;
  2745. }
  2746. } else {
  2747. echo $agendaitems[$i];
  2748. }
  2749. }
  2750. }
  2751. echo "</td>";
  2752. echo "</tr>";
  2753. // the rows for each half an hour
  2754. for ($i = 10; $i < 48; $i++) {
  2755. if ($i % 2 == 0) {
  2756. $class = "class=\"row_even\"";
  2757. } else {
  2758. $class = "class=\"row_odd\"";
  2759. }
  2760. echo "<tr $class>";
  2761. echo "";
  2762. if ($i % 2 == 0) {
  2763. echo ("<td valign=\"top\" width=\"75\">".(($i) / 2)." ".get_lang("HourShort")." 00</td>");
  2764. } else {
  2765. echo ("<td valign=\"top\" width=\"75\">".((($i) / 2) - (1 / 2))." ".get_lang("HourShort")." 30</td>");
  2766. }
  2767. echo "<td $class valign=\"top\" colspan=\"2\">";
  2768. if (isset($agendaitems[$i])) {
  2769. if (is_array($agendaitems[$i])) {
  2770. foreach ($agendaitems[$i] as $key => $value) {
  2771. echo $value;
  2772. }
  2773. } else {
  2774. echo $agendaitems[$i];
  2775. }
  2776. }
  2777. echo "</td>";
  2778. echo "</tr>";
  2779. }
  2780. echo "</table>";
  2781. }
  2782. /**
  2783. * Display the weekly view of the calendar
  2784. */
  2785. function display_weekcalendar($agendaitems, $month, $year, $weekdaynames, $monthName)
  2786. {
  2787. global $DaysShort, $course_path;
  2788. global $MonthsLong;
  2789. // timestamp of today
  2790. $today = time();
  2791. $day_of_the_week = date("w", $today);
  2792. $thisday_of_the_week = date("w", $today);
  2793. // the week number of the year
  2794. $week_number = date("W", $today);
  2795. $thisweek_number = $week_number;
  2796. // if we moved to the next / previous week we have to recalculate the $today variable
  2797. if (!isset($_GET['week'])) {
  2798. $week_number = date("W", $today);
  2799. } else {
  2800. $week_number = intval($_GET['week']);
  2801. }
  2802. // calculating the start date of the week
  2803. // the date of the monday of this week is the timestamp of today minus
  2804. // number of days that have already passed this week * 24 hours * 60 minutes * 60 seconds
  2805. $current_day = date("j", $today); // Day of the month without leading zeros (1 to 31) of today
  2806. $day_of_the_week = date("w", $today); // Numeric representation of the day of the week 0 (for Sunday) through 6 (for Saturday) of today
  2807. //Using the same script to calculate the start/end of a week
  2808. $start_end = calculate_start_end_of_week($week_number, $year);
  2809. $timestamp_first_date_of_week = mktime(0, 0, 0, $start_end['start']['month'], $start_end['start']['day'], $start_end['start']['year']);
  2810. $timestamp_last_date_of_week = mktime(0, 0, 0, $start_end['end']['month'], $start_end['end']['day'], $start_end['end']['year']);
  2811. $backwardsURL = api_get_self()."?coursePath=".urlencode($course_path)."&courseCode=".api_get_course_id()."&action=view&view=week&week=".($week_number - 1);
  2812. $forewardsURL = api_get_self()."?coursePath=".urlencode($course_path)."&courseCode=".api_get_course_id()."&action=view&view=week&week=".($week_number + 1);
  2813. echo '<table class="data_table">';
  2814. // The title row containing the the week information (week of the year (startdate of week - enddate of week)
  2815. echo '<tr>';
  2816. echo "<th width=\"10%\"><a href=\"", $backwardsURL, "\">".Display::return_icon('action_prev.png', get_lang('Previous'))."</a></th>";
  2817. echo "<th colspan=\"5\">".get_lang("Week")." ".$week_number;
  2818. echo " (".$DaysShort['1']." ".date("j", $timestamp_first_date_of_week)." ".$MonthsLong[date("n", $timestamp_first_date_of_week) - 1]." ".date("Y", $timestamp_first_date_of_week)." - ".$DaysShort['0']." ".date("j", $timestamp_last_date_of_week)." ".$MonthsLong[date("n", $timestamp_last_date_of_week) - 1]." ".date("Y", $timestamp_last_date_of_week).')';
  2819. echo "</th>";
  2820. echo "<th width=\"10%\"><a href=\"", $forewardsURL, "\">".Display::return_icon('action_next.png', get_lang('Next'))."</a></th>", "</tr>";
  2821. // The second row containing the short names of the days of the week
  2822. echo "<tr>";
  2823. //Printing the week days
  2824. // this is the Day of the month without leading zeros (1 to 31) of the monday of this week
  2825. $tmp_timestamp = $timestamp_first_date_of_week;
  2826. for ($ii = 1; $ii < 8; $ii++) {
  2827. $is_today = ($ii == $thisday_of_the_week AND (!isset($_GET['week']) OR $_GET['week'] == $thisweek_number));
  2828. echo "<td class=\"weekdays\">";
  2829. if ($is_today) {
  2830. echo "<font color=#CC3300>";
  2831. }
  2832. echo $DaysShort[$ii % 7]." ".date("j", $tmp_timestamp)." ".$MonthsLong[date("n", $tmp_timestamp) - 1];
  2833. if ($is_today) {
  2834. echo "</font>";
  2835. }
  2836. echo "</td>";
  2837. // we 24 hours * 60 minutes * 60 seconds to the $tmp_timestamp
  2838. $array_tmp_timestamp[] = $tmp_timestamp;
  2839. $tmp_timestamp = $tmp_timestamp + (24 * 60 * 60);
  2840. }
  2841. echo "</tr>";
  2842. // The table cells containing all the entries for that day
  2843. echo "<tr>";
  2844. $counter = 0;
  2845. foreach ($array_tmp_timestamp as $key => $value) {
  2846. if ($counter < 5) {
  2847. $class = "class=\"days_week\"";
  2848. } else {
  2849. $class = "class=\"days_weekend\"";
  2850. }
  2851. if ($counter == $thisday_of_the_week - 1 AND (!isset($_GET['week']) OR $_GET['week'] == $thisweek_number)) {
  2852. $class = "class=\"days_today\"";
  2853. }
  2854. echo "<td ".$class.">";
  2855. $data = isset($agendaitems[date('j', $value)]) ? $agendaitems[date('j', $value)] : null;
  2856. echo "<span class=\"agendaitem\">".$data."&nbsp;</span> ";
  2857. echo "</td>";
  2858. $counter++;
  2859. }
  2860. echo "</tr>";
  2861. echo "</table>";
  2862. }
  2863. /**
  2864. * Show the monthcalender of the given month
  2865. */
  2866. function get_day_agendaitems($courses_dbs, $month, $year, $day)
  2867. {
  2868. global $setting_agenda_link;
  2869. $items = array();
  2870. // get agenda-items for every course
  2871. //$query=Database::query($sql_select_courses);
  2872. foreach ($courses_dbs as $key => $array_course_info) {
  2873. //echo $array_course_info['db'];
  2874. //databases of the courses
  2875. $TABLEAGENDA = Database :: get_course_table(TABLE_AGENDA);
  2876. $TABLE_ITEMPROPERTY = Database :: get_course_table(TABLE_ITEM_PROPERTY);
  2877. // getting all the groups of the user for the current course
  2878. $group_memberships = GroupManager :: get_group_ids($array_course_info['real_id'], api_get_user_id());
  2879. $course_user_status = CourseManager::get_user_in_course_status(api_get_user_id(), $array_course_info['code']);
  2880. $start_filter = $year."-".$month."-".$day." 00:00:00";
  2881. $start_filter = api_get_utc_datetime($start_filter);
  2882. $end_filter = $year."-".$month."-".$day." 23:59:59";
  2883. $end_filter = api_get_utc_datetime($end_filter);
  2884. // if the user is administrator of that course we show all the agenda items
  2885. if ($course_user_status == '1') {
  2886. //echo "course admin";
  2887. $sqlquery = "SELECT
  2888. DISTINCT agenda.*, item_property.*
  2889. FROM ".$TABLEAGENDA." agenda,
  2890. ".$TABLE_ITEMPROPERTY." item_property
  2891. WHERE agenda.id = item_property.ref
  2892. AND start_date>='".$start_filter."' AND start_date<='".$end_filter."'
  2893. AND item_property.tool='".TOOL_CALENDAR_EVENT."'
  2894. AND item_property.visibility='1'
  2895. GROUP BY agenda.id
  2896. ORDER BY start_date ";
  2897. }
  2898. // if the user is not an administrator of that course
  2899. else {
  2900. //echo "course admin";
  2901. if (is_array($group_memberships) && count($group_memberships) > 0) {
  2902. $sqlquery = "SELECT
  2903. agenda.*, item_property.*
  2904. FROM ".$TABLEAGENDA." agenda,
  2905. ".$TABLE_ITEMPROPERTY." item_property
  2906. WHERE agenda.id = item_property.ref
  2907. AND start_date>='".$start_filter."' AND start_date<='".$end_filter."'
  2908. AND item_property.tool='".TOOL_CALENDAR_EVENT."'
  2909. AND ( item_property.to_user_id='".api_get_user_id()."' OR item_property.to_group_id IN (0, ".implode(", ", $group_memberships).") )
  2910. AND item_property.visibility='1'
  2911. ORDER BY start_date ";
  2912. } else {
  2913. $sqlquery = "SELECT
  2914. agenda.*, item_property.*
  2915. FROM ".$TABLEAGENDA." agenda,
  2916. ".$TABLE_ITEMPROPERTY." item_property
  2917. WHERE agenda.id = item_property.ref
  2918. AND start_date>='".$start_filter."' AND start_date<='".$end_filter."'
  2919. AND item_property.tool='".TOOL_CALENDAR_EVENT."'
  2920. AND ( item_property.to_user_id='".api_get_user_id()."' OR item_property.to_group_id='0')
  2921. AND item_property.visibility='1'
  2922. ORDER BY start_date ";
  2923. }
  2924. }
  2925. $result = Database::query($sqlquery);
  2926. while ($item = Database::fetch_array($result)) {
  2927. // in the display_daycalendar function we use $i (ranging from 0 to 47) for each halfhour
  2928. // we want to know for each agenda item for this day to wich halfhour it must be assigned
  2929. $item['start_date'] = api_get_local_time($item['start_date']);
  2930. $time_minute = api_format_date($item['start_date'], TIME_NO_SEC_FORMAT);
  2931. list ($datepart, $timepart) = explode(" ", $item['start_date']);
  2932. list ($year, $month, $day) = explode("-", $datepart);
  2933. list ($hours, $minutes, $seconds) = explode(":", $timepart);
  2934. $halfhour = 2 * $hours;
  2935. if ($minutes >= '30') {
  2936. $halfhour = $halfhour + 1;
  2937. }
  2938. if ($setting_agenda_link == 'coursecode') {
  2939. $title = $array_course_info['title'];
  2940. $agenda_link = cut($title, 14, true);
  2941. } else {
  2942. $agenda_link = Display::return_icon('course_home.png', '&nbsp;', '', ICON_SIZE_SMALL);
  2943. }
  2944. $URL = api_get_path(WEB_CODE_PATH).'calendar/agenda.php?cidReq='.urlencode($array_course_info["code"])."&day=$day&month=$month&year=$year#$day"; // RH //Patrick Cool: to highlight the relevant agenda item
  2945. $items[$halfhour][] .= "<i>$time_minute</i> <a href=\"$URL\" title=\"".$array_course_info['title']."\">".$agenda_link."</a> ".$item['title']."<br />";
  2946. }
  2947. }
  2948. // sorting by hour for every day
  2949. $agendaitems = array();
  2950. while (list($agendaday, $tmpitems) = each($items)) {
  2951. sort($tmpitems);
  2952. while (list($key, $val) = each($tmpitems)) {
  2953. $agendaitems[$agendaday].=$val;
  2954. }
  2955. }
  2956. return $agendaitems;
  2957. }
  2958. /**
  2959. * Return agenda items of the week
  2960. */
  2961. function get_week_agendaitems($courses_dbs, $month, $year, $week = '')
  2962. {
  2963. global $setting_agenda_link;
  2964. $TABLEAGENDA = Database :: get_course_table(TABLE_AGENDA);
  2965. $TABLE_ITEMPROPERTY = Database :: get_course_table(TABLE_ITEM_PROPERTY);
  2966. $items = array();
  2967. // The default value of the week
  2968. if ($week == '') {
  2969. $week_number = date("W", time());
  2970. } else {
  2971. $week_number = $week;
  2972. }
  2973. $start_end = calculate_start_end_of_week($week_number, $year);
  2974. $start_filter = $start_end['start']['year']."-".$start_end['start']['month']."-".$start_end['start']['day']." 00:00:00";
  2975. $start_filter = api_get_utc_datetime($start_filter);
  2976. $end_filter = $start_end['end']['year']."-".$start_end['end']['month']."-".$start_end['end']['day']." 23:59:59";
  2977. $end_filter = api_get_utc_datetime($end_filter);
  2978. // get agenda-items for every course
  2979. foreach ($courses_dbs as $key => $array_course_info) {
  2980. //databases of the courses
  2981. $TABLEAGENDA = Database :: get_course_table(TABLE_AGENDA);
  2982. $TABLE_ITEMPROPERTY = Database :: get_course_table(TABLE_ITEM_PROPERTY);
  2983. // getting all the groups of the user for the current course
  2984. $group_memberships = GroupManager :: get_group_ids($array_course_info["real_id"], api_get_user_id());
  2985. $user_course_status = CourseManager::get_user_in_course_status(api_get_user_id(), $array_course_info["code"]);
  2986. // if the user is administrator of that course we show all the agenda items
  2987. if ($user_course_status == '1') {
  2988. //echo "course admin";
  2989. $sqlquery = "SELECT
  2990. DISTINCT a.*, i.*
  2991. FROM ".$TABLEAGENDA." a,
  2992. ".$TABLE_ITEMPROPERTY." i
  2993. WHERE a.id = i.ref
  2994. AND a.start_date>='".$start_filter."' AND a.start_date<='".$end_filter."'
  2995. AND i.tool='".TOOL_CALENDAR_EVENT."'
  2996. AND i.visibility='1'
  2997. GROUP BY a.id
  2998. ORDER BY a.start_date";
  2999. }
  3000. // if the user is not an administrator of that course
  3001. else {
  3002. //echo "GEEN course admin";
  3003. if (is_array($group_memberships) && count($group_memberships) > 0) {
  3004. $sqlquery = "SELECT
  3005. a.*, i.*
  3006. FROM ".$TABLEAGENDA." a,
  3007. ".$TABLE_ITEMPROPERTY." i
  3008. WHERE a.id = i.ref
  3009. AND a.start_date>='".$start_filter."' AND a.start_date<='".$end_filter."'
  3010. AND i.tool='".TOOL_CALENDAR_EVENT."'
  3011. AND ( i.to_user_id='".api_get_user_id()."' OR i.to_group_id IN (0, ".implode(", ", $group_memberships).") )
  3012. AND i.visibility='1'
  3013. ORDER BY a.start_date";
  3014. } else {
  3015. $sqlquery = "SELECT
  3016. a.*, i.*
  3017. FROM ".$TABLEAGENDA." a,
  3018. ".$TABLE_ITEMPROPERTY." i
  3019. WHERE a.id = i.ref
  3020. AND a.start_date>='".$start_filter."' AND a.start_date<='".$end_filter."'
  3021. AND i.tool='".TOOL_CALENDAR_EVENT."'
  3022. AND ( i.to_user_id='".api_get_user_id()."' OR i.to_group_id='0')
  3023. AND i.visibility='1'
  3024. ORDER BY a.start_date";
  3025. }
  3026. }
  3027. //echo "<pre>".$sqlquery."</pre>";
  3028. // $sqlquery = "SELECT * FROM $agendadb WHERE (DAYOFMONTH(day)>='$start_day' AND DAYOFMONTH(day)<='$end_day')
  3029. // AND (MONTH(day)>='$start_month' AND MONTH(day)<='$end_month')
  3030. // AND (YEAR(day)>='$start_year' AND YEAR(day)<='$end_year')";
  3031. //var_dump($sqlquery);
  3032. $result = Database::query($sqlquery);
  3033. while ($item = Database::fetch_array($result)) {
  3034. $agendaday_string = api_convert_and_format_date($item['start_date'], "%d", date_default_timezone_get());
  3035. $agendaday = intval($agendaday_string);
  3036. $start_time = api_convert_and_format_date($item['start_date'], TIME_NO_SEC_FORMAT);
  3037. $end_time = api_convert_and_format_date($item['end_date'], DATE_TIME_FORMAT_LONG);
  3038. if ($setting_agenda_link == 'coursecode') {
  3039. $title = $array_course_info['title'];
  3040. $agenda_link = cut($title, 14, true);
  3041. } else {
  3042. $agenda_link = Display::return_icon('course_home.png', '&nbsp;', '', ICON_SIZE_SMALL);
  3043. }
  3044. $URL = api_get_path(WEB_CODE_PATH)."calendar/agenda.php?cidReq=".urlencode($array_course_info["code"])."&day=$agendaday&month=$month&year=$year#$agendaday"; // RH //Patrick Cool: to highlight the relevant agenda item
  3045. //Display the events in agenda
  3046. $content = "<i>$start_time - $end_time</i> <a href=\"$URL\" title=\"".$array_course_info["title"]."\"> <br />".$agenda_link."</a>";
  3047. $content .= "<div>".$item['title']."</div><br>";
  3048. $items[$agendaday][$item['start_date']] .= $content;
  3049. }
  3050. }
  3051. $agendaitems = array();
  3052. // sorting by hour for every day
  3053. while (list ($agendaday, $tmpitems) = each($items)) {
  3054. sort($tmpitems);
  3055. while (list ($key, $val) = each($tmpitems)) {
  3056. $agendaitems[$agendaday] .= $val;
  3057. }
  3058. }
  3059. return $agendaitems;
  3060. }
  3061. /**
  3062. * Get repeated events of a course between two dates (timespan of a day).
  3063. * Returns an array containing the events
  3064. * @param string Course info array (as returned by api_get_course_info())
  3065. * @param int UNIX timestamp of span start. Defaults 0, later transformed into today's start
  3066. * @param int UNIX timestamp. Defaults to 0, later transformed into today's end
  3067. * @param array A set of parameters to alter the SQL query
  3068. * @return array [int] => [course_id,parent_event_id,start_date,end_date,title,description]
  3069. */
  3070. function get_repeated_events_day_view($course_info, $start = 0, $end = 0, $params)
  3071. {
  3072. $events = array();
  3073. //initialise all values
  3074. $y = 0;
  3075. $m = 0;
  3076. $d = 0;
  3077. //block $end if higher than 2038 -- PHP doesn't go past that
  3078. if ($end > 2145934800) {
  3079. $end = 2145934800;
  3080. }
  3081. if ($start == 0 or $end == 0) {
  3082. $y = date('Y');
  3083. $m = date('m');
  3084. $d = date('j');
  3085. }
  3086. if ($start == 0) {
  3087. $start = mktime(0, 0, 0, $m, $d, $y);
  3088. }
  3089. $db_start = date('Y-m-d H:i:s', $start);
  3090. if ($end == 0) {
  3091. $end = mktime(23, 59, 59, $m, $d, $y);
  3092. }
  3093. //$db_end = date('Y-m-d H:i:s',$end);
  3094. $t_cal = Database::get_course_table(TABLE_AGENDA, $course_info['dbName']);
  3095. $t_cal_repeat = Database::get_course_table(TABLE_AGENDA_REPEAT, $course_info['dbName']);
  3096. $t_ip = Database::get_course_table(TABLE_ITEM_PROPERTY, $course_info['dbName']);
  3097. $sql = "SELECT c.id, c.title, c.content, ".
  3098. " UNIX_TIMESTAMP(c.start_date) as orig_start, UNIX_TIMESTAMP(c.end_date) as orig_end, ".
  3099. " cr.cal_type, cr.cal_end ".
  3100. " FROM $t_cal c, $t_cal_repeat cr, $t_ip as item_property ".
  3101. " WHERE cr.cal_end >= $start ".
  3102. " AND cr.cal_id = c.id ".
  3103. " AND item_property.ref = c.id ".
  3104. " AND item_property.tool = '".TOOL_CALENDAR_EVENT."' ".
  3105. " AND c.start_date <= '$db_start' "
  3106. .(!empty($params['conditions']) ? $params['conditions'] : '')
  3107. .(!empty($params['groupby']) ? ' GROUP BY '.$params['groupby'] : '')
  3108. .(!empty($params['orderby']) ? ' ORDER BY '.$params['orderby'] : '');
  3109. $res = Database::query($sql);
  3110. if (Database::num_rows($res) > 0) {
  3111. while ($row = Database::fetch_array($res)) {
  3112. $orig_start = $row['orig_start'];
  3113. $orig_end = $row['orig_end'];
  3114. $repeat_type = $row['cal_type'];
  3115. switch ($repeat_type) {
  3116. case 'daily':
  3117. //we are in the daily view, so if this element is repeated daily and
  3118. //the repetition is still active today (which is a condition of the SQL query)
  3119. //then the event happens today. Just build today's timestamp for start and end
  3120. $time_orig_h = date('H', $orig_start);
  3121. $time_orig_m = date('i', $orig_start);
  3122. $time_orig_s = date('s', $orig_start);
  3123. $int_time = (($time_orig_h * 60) + $time_orig_m) * 60 + $time_orig_s; //time in seconds since 00:00:00
  3124. $span = $orig_end - $orig_start; //total seconds between start and stop of original event
  3125. $current_start = $start + $int_time; //unixtimestamp start of today's event
  3126. $current_stop = $start + $int_time + $span; //unixtimestamp stop of today's event
  3127. $events[] = array($course_info['id'], $row['id'], $current_start, $current_stop, $row['title'], $row['content']);
  3128. break;
  3129. case 'weekly':
  3130. $time_orig = date('Y/n/W/j/N/G/i/s', $orig_start);
  3131. list($y_orig, $m_orig, $w_orig, $d_orig, $dw_orig, $h_orig, $n_orig, $s_orig) = split('/', $time_orig);
  3132. $time_now = date('Y/n/W/j/N/G/i/s', $end);
  3133. list($y_now, $m_now, $w_now, $d_now, $dw_now, $h_now, $n_now, $s_now) = split('/', $time_now);
  3134. if ((($y_now > $y_orig) OR (($y_now == $y_orig) && ($w_now > $w_orig))) && ($dw_orig == $dw_now)) { //if the event is after the original (at least one week) and the day of the week is the same
  3135. $time_orig_end = date('Y/n/W/j/N/G/i/s', $orig_end);
  3136. list($y_orig_e, $m_orig_e, $w_orig_e, $d_orig_e, $dw_orig_e, $h_orig_e, $n_orig_e, $s_orig_e) = split('/', $time_orig_end);
  3137. $events[] = array($course_info['id'], $row['id'], mktime($h_orig, $n_orig, $s_orig, $m_now, $d_orig, $y_now), mktime($h_orig_e, $n_orig_e, $s_orig_e, $m_now, $d_orig_e, $y_now), $row['title'], $row['content']);
  3138. }
  3139. break;
  3140. case 'monthlyByDate':
  3141. $time_orig = date('Y/n/j/G/i/s', $orig_start);
  3142. list($y_orig, $m_orig, $d_orig, $h_orig, $n_orig, $s_orig) = split('/', $time_orig);
  3143. $time_now = date('Y/n/j/G/i/s', $end);
  3144. list($y_now, $m_now, $d_now, $h_now, $n_now, $s_now) = split('/', $time_now);
  3145. if ((($y_now > $y_orig) OR (($y_now == $y_orig) && ($m_now > $m_orig))) && ($d_orig == $d_now)) {
  3146. $time_orig_end = date('Y/n/j/G/i/s', $orig_end);
  3147. list($y_orig_e, $m_orig_e, $d_orig_e, $h_orig_e, $n_orig_e, $s_orig_e) = split('/', $time_orig_end);
  3148. $events[] = array($course_info['id'], $row['id'], mktime($h_orig, $n_orig, $s_orig, $m_now, $d_orig, $y_now), mktime($h_orig_e, $n_orig_e, $s_orig_e, $m_now, $d_orig_e, $y_now), $row['title'], $row['content']);
  3149. }
  3150. break;
  3151. case 'monthlyByDayR':
  3152. //not implemented yet
  3153. break;
  3154. case 'monthlyByDay':
  3155. //not implemented yet
  3156. break;
  3157. case 'yearly':
  3158. $time_orig = date('Y/n/j/z/G/i/s', $orig_start);
  3159. list($y_orig, $m_orig, $d_orig, $dy_orig, $h_orig, $n_orig, $s_orig) = split('/', $time_orig);
  3160. $time_now = date('Y/n/j/z/G/i/s', $end);
  3161. list($y_now, $m_now, $d_now, $dy_now, $h_now, $n_now, $s_now) = split('/', $time_now);
  3162. if (($y_now > $y_orig) && ($dy_orig == $dy_now)) {
  3163. $time_orig_end = date('Y/n/j/G/i/s', $orig_end);
  3164. list($y_orig_e, $m_orig_e, $d_orig_e, $dy_orig_e, $h_orig_e, $n_orig_e, $s_orig_e) = split('/', $time_orig_end);
  3165. $events[] = array($course_info['id'], $row['id'], mktime($h_orig, $n_orig, $s_orig, $m_now, $d_orig, $y_now), mktime($h_orig_e, $n_orig_e, $s_orig_e, $m_now, $d_orig_e, $y_now), $row['title'], $row['content']);
  3166. }
  3167. break;
  3168. default:
  3169. break;
  3170. }
  3171. }
  3172. }
  3173. return $events;
  3174. }
  3175. /**
  3176. * (This function is not been use in the code)
  3177. * Get repeated events of a course between two dates (timespan of a week).
  3178. * Returns an array containing the events
  3179. * @param string Course info array (as returned by api_get_course_info())
  3180. * @param int UNIX timestamp of span start. Defaults 0, later transformed into today's start
  3181. * @param int UNIX timestamp. Defaults to 0, later transformed into today's end
  3182. * @param array A set of parameters to alter the SQL query
  3183. * @return array [int] => [course_id,parent_event_id,start_date,end_date,title,description]
  3184. */
  3185. function get_repeated_events_week_view($course_info, $start = 0, $end = 0, $params)
  3186. {
  3187. $events = array();
  3188. //block $end if higher than 2038 -- PHP doesn't go past that
  3189. if ($end > 2145934800) {
  3190. $end = 2145934800;
  3191. }
  3192. //initialise all values
  3193. $y = 0;
  3194. $m = 0;
  3195. $d = 0;
  3196. if ($start == 0 or $end == 0) {
  3197. $time = time();
  3198. $dw = date('w', $time);
  3199. $week_start = $time - (($dw - 1) * 86400);
  3200. $y = date('Y', $week_start);
  3201. $m = date('m', $week_start);
  3202. $d = date('j', $week_start);
  3203. $w = date('W', $week_start);
  3204. }
  3205. if ($start == 0) {
  3206. $start = mktime(0, 0, 0, $m, $d, $y);
  3207. }
  3208. $db_start = date('Y-m-d H:i:s', $start);
  3209. if ($end == 0) {
  3210. $end = $start + (86400 * 7) - 1; //start of week, more 7 days, minus 1 second to get back to the previoyus day
  3211. }
  3212. //$db_end = date('Y-m-d H:i:s',$end);
  3213. $t_cal = Database::get_course_table(TABLE_AGENDA, $course_info['dbName']);
  3214. $t_cal_repeat = Database::get_course_table(TABLE_AGENDA_REPEAT, $course_info['dbName']);
  3215. $t_ip = Database::get_course_table(TABLE_ITEM_PROPERTY, $course_info['dbName']);
  3216. $sql = "SELECT c.id, c.title, c.content, ".
  3217. " UNIX_TIMESTAMP(c.start_date) as orig_start, UNIX_TIMESTAMP(c.end_date) as orig_end, ".
  3218. " cr.cal_type, cr.cal_end ".
  3219. " FROM $t_cal c, $t_cal_repeat cr, $t_ip as item_property ".
  3220. " WHERE cr.cal_end >= $start ".
  3221. " AND cr.cal_id = c.id ".
  3222. " AND item_property.ref = c.id ".
  3223. " AND item_property.tool = '".TOOL_CALENDAR_EVENT."' ".
  3224. " AND c.start_date <= '$db_start' "
  3225. .(!empty($params['conditions']) ? $params['conditions'] : '')
  3226. .(!empty($params['groupby']) ? ' GROUP BY '.$params['groupby'] : '')
  3227. .(!empty($params['orderby']) ? ' ORDER BY '.$params['orderby'] : '');
  3228. $res = Database::query($sql);
  3229. if (Database::num_rows($res) > 0) {
  3230. while ($row = Database::fetch_array($res)) {
  3231. $orig_start = $row['orig_start'];
  3232. $orig_end = $row['orig_end'];
  3233. $repeat_type = $row['cal_type'];
  3234. switch ($repeat_type) {
  3235. case 'daily':
  3236. $time_orig_h = date('H', $orig_start);
  3237. $time_orig_m = date('i', $orig_start);
  3238. $time_orig_s = date('s', $orig_start);
  3239. $int_time = (($time_orig_h * 60) + $time_orig_m) * 60 + $time_orig_s; //time in seconds since 00:00:00
  3240. $span = $orig_end - $orig_start; //total seconds between start and stop of original event
  3241. for ($i = 0; $i < 7; $i++) {
  3242. $current_start = $start + ($i * 86400) + $int_time; //unixtimestamp start of today's event
  3243. $current_stop = $start + ($i * 86400) + $int_time + $span; //unixtimestamp stop of today's event
  3244. $events[] = array($course_info['id'], $row['id'], $current_start, $current_stop, $row['title'], $row['content']);
  3245. }
  3246. break;
  3247. case 'weekly':
  3248. $time_orig = date('Y/n/W/j/N/G/i/s', $orig_start);
  3249. list($y_orig, $m_orig, $w_orig, $d_orig, $dw_orig, $h_orig, $n_orig, $s_orig) = split('/', $time_orig);
  3250. $time_now = date('Y/n/W/j/N/G/i/s', $end);
  3251. list($y_now, $m_now, $w_now, $d_now, $dw_now, $h_now, $n_now, $s_now) = split('/', $time_now);
  3252. if ((($y_now > $y_orig) OR (($y_now == $y_orig) && ($w_now > $w_orig)))) { //if the event is after the original (at least one week) and the day of the week is the same
  3253. $time_orig_end = date('Y/n/W/j/N/G/i/s', $orig_end);
  3254. list($y_orig_e, $m_orig_e, $w_orig_e, $d_orig_e, $dw_orig_e, $h_orig_e, $n_orig_e, $s_orig_e) = split('/', $time_orig_end);
  3255. $events[] = array($course_info['id'], $row['id'], mktime($h_orig, $n_orig, $s_orig, $m_now, $d_orig, $y_now), mktime($h_orig_e, $n_orig_e, $s_orig_e, $m_now, $d_orig_e, $y_now), $row['title'], $row['content']);
  3256. }
  3257. break;
  3258. case 'monthlyByDate':
  3259. $time_orig = date('Y/n/W/j/G/i/s', $orig_start);
  3260. list($y_orig, $m_orig, $w_orig, $d_orig, $h_orig, $n_orig, $s_orig) = split('/', $time_orig);
  3261. $time_now = date('Y/n/W/j/G/i/s', $end);
  3262. list($y_now, $m_now, $w_now, $d_now, $h_now, $n_now, $s_now) = split('/', $time_now);
  3263. $event_repetition_time = mktime($h_orig, $n_orig, $s_orig, $m_now, $d_orig, $y_now);
  3264. if ((($y_now > $y_orig) OR (($y_now == $y_orig) && ($m_now > $m_orig))) && ($start < $event_repetition_time && $event_repetition_time < $end)) { //if the event is after the original (at least one month) and the original event's day is between the first day of the week and the last day of the week
  3265. $time_orig_end = date('Y/n/j/G/i/s', $orig_end);
  3266. list($y_orig_e, $m_orig_e, $d_orig_e, $h_orig_e, $n_orig_e, $s_orig_e) = split('/', $time_orig_end);
  3267. $events[] = array($course_info['id'], $row['id'], mktime($h_orig, $n_orig, $s_orig, $m_now, $d_orig, $y_now), mktime($h_orig_e, $n_orig_e, $s_orig_e, $m_now, $d_orig_e, $y_now), $row['title'], $row['content']);
  3268. }
  3269. break;
  3270. case 'monthlyByDayR':
  3271. //not implemented yet
  3272. break;
  3273. case 'monthlyByDay':
  3274. //not implemented yet
  3275. break;
  3276. case 'yearly':
  3277. $time_orig = date('Y/n/j/z/G/i/s', $orig_start);
  3278. list($y_orig, $m_orig, $d_orig, $dy_orig, $h_orig, $n_orig, $s_orig) = split('/', $time_orig);
  3279. $time_now = date('Y/n/j/z/G/i/s', $end);
  3280. list($y_now, $m_now, $d_now, $dy_now, $h_now, $n_now, $s_now) = split('/', $time_now);
  3281. $event_repetition_time = mktime($h_orig, $n_orig, $s_orig, $m_orig, $d_orig, $y_now);
  3282. if ((($y_now > $y_orig) && ($start < $event_repetition_time && $event_repetition_time < $end))) {
  3283. $time_orig_end = date('Y/n/j/G/i/s', $orig_end);
  3284. list($y_orig_e, $m_orig_e, $d_orig_e, $dy_orig_e, $h_orig_e, $n_orig_e, $s_orig_e) = split('/', $time_orig_end);
  3285. $events[] = array($course_info['id'], $row['id'], mktime($h_orig, $n_orig, $s_orig, $m_now, $d_orig, $y_now), mktime($h_orig_e, $n_orig_e, $s_orig_e, $m_now, $d_orig_e, $y_now), $row['title'], $row['content']);
  3286. }
  3287. break;
  3288. default:
  3289. break;
  3290. }
  3291. }
  3292. }
  3293. return $events;
  3294. }
  3295. /**
  3296. * Get repeated events of a course between two dates (timespan of a month).
  3297. * Returns an array containing the events
  3298. * @param string Course info array (as returned by api_get_course_info())
  3299. * @param int UNIX timestamp of span start. Defaults 0, later transformed into today's start
  3300. * @param int UNIX timestamp. Defaults to 0, later transformed into today's end
  3301. * @param array A set of parameters to alter the SQL query
  3302. * @return array [int] => [course_id,parent_event_id,start_date,end_date,title,description]
  3303. */
  3304. function get_repeated_events_month_view($course_info, $start = 0, $end = 0, $params)
  3305. {
  3306. $events = array();
  3307. //block $end if higher than 2038 -- PHP doesn't go past that
  3308. if ($end > 2145934800) {
  3309. $end = 2145934800;
  3310. }
  3311. //initialise all values
  3312. $y = 0;
  3313. $m = 0;
  3314. $d = 0;
  3315. if ($start == 0 or $end == 0) {
  3316. $time = time();
  3317. $y = date('Y');
  3318. $m = date('m');
  3319. }
  3320. if ($start == 0) {
  3321. $start = mktime(0, 0, 0, $m, 1, $y);
  3322. }
  3323. $db_start = date('Y-m-d H:i:s', $start);
  3324. if ($end == 0) {
  3325. if ($m == 12) {
  3326. $end = mktime(0, 0, 0, 1, 1, $y + 1) - 1; //start of next month, minus 1 second to get back to the previoyus day
  3327. } else {
  3328. $end = mktime(0, 0, 0, $m + 1, 1, $y) - 1;
  3329. }
  3330. }
  3331. //$db_end = date('Y-m-d H:i:s',$end);
  3332. $t_cal = Database::get_course_table(TABLE_AGENDA, $course_info['dbName']);
  3333. $t_cal_repeat = Database::get_course_table(TABLE_AGENDA_REPEAT, $course_info['dbName']);
  3334. $t_ip = Database::get_course_table(TABLE_ITEM_PROPERTY, $course_info['dbName']);
  3335. $sql = "SELECT c.id, c.title, c.content, ".
  3336. " UNIX_TIMESTAMP(c.start_date) as orig_start, UNIX_TIMESTAMP(c.end_date) as orig_end, ".
  3337. " cr.cal_type, cr.cal_end ".
  3338. " FROM $t_cal c, $t_cal_repeat cr, $t_ip as item_property ".
  3339. " WHERE cr.cal_end >= $start ".
  3340. " AND cr.cal_id = c.id ".
  3341. " AND item_property.ref = c.id ".
  3342. " AND item_property.tool = '".TOOL_CALENDAR_EVENT."' ".
  3343. " AND c.start_date <= '$db_start' "
  3344. .(!empty($params['conditions']) ? $params['conditions'] : '')
  3345. .(!empty($params['groupby']) ? ' GROUP BY '.$params['groupby'] : '')
  3346. .(!empty($params['orderby']) ? ' ORDER BY '.$params['orderby'] : '');
  3347. $res = Database::query($sql);
  3348. if (Database::num_rows($res) > 0) {
  3349. while ($row = Database::fetch_array($res)) {
  3350. $orig_start = $row['orig_start'];
  3351. $orig_end = $row['orig_end'];
  3352. $repeat_type = $row['cal_type'];
  3353. switch ($repeat_type) {
  3354. case 'daily':
  3355. $time_orig_h = date('H', $orig_start);
  3356. $time_orig_m = date('i', $orig_start);
  3357. $time_orig_s = date('s', $orig_start);
  3358. $month_last_day = date('d', $end);
  3359. $int_time = (($time_orig_h * 60) + $time_orig_m) * 60 + $time_orig_s; //time in seconds since 00:00:00
  3360. $span = $orig_end - $orig_start; //total seconds between start and stop of original event
  3361. for ($i = 0; $i < $month_last_day; $i++) {
  3362. $current_start = $start + ($i * 86400) + $int_time; //unixtimestamp start of today's event
  3363. $current_stop = $start + ($i * 86400) + $int_time + $span; //unixtimestamp stop of today's event
  3364. $events[] = array($course_info['id'], $row['id'], $current_start, $current_stop, $row['title'], $row['content']);
  3365. }
  3366. break;
  3367. case 'weekly':
  3368. //A weekly repeated event is very difficult to catch in a month view,
  3369. //because weeks start before or at the same time as the first day of the month
  3370. //The same can be said for the end of the month.
  3371. // The idea is thus to get all possible events by enlarging the scope of
  3372. // the month to get complete weeks covering the complete month, and then take out
  3373. // the events that start before the 1st ($start) or after the last day of the month ($end)
  3374. $time_orig = date('Y/n/W/j/N/G/i/s', $orig_start);
  3375. list($y_orig, $m_orig, $w_orig, $d_orig, $dw_orig, $h_orig, $n_orig, $s_orig) = split('/', $time_orig);
  3376. $time_orig_end = date('Y/n/W/j/N/G/i/s', $orig_end);
  3377. list($y_orig_e, $m_orig_e, $w_orig_e, $d_orig_e, $dw_orig_e, $h_orig_e, $n_orig_e, $s_orig_e) = split('/', $time_orig_end);
  3378. $time_now = date('Y/n/W/j/N/G/i/s', $end);
  3379. list($y_now, $m_now, $w_now, $d_now, $dw_now, $h_now, $n_now, $s_now) = split('/', $time_now);
  3380. $month_first_week = date('W', $start);
  3381. $month_last_week = date('W', $end);
  3382. if (($y_now > $y_orig) OR (($y_now == $y_orig) && ($w_now > $w_orig))) { //if the event is after the original (at least one week) and the day of the week is the same
  3383. for ($i = $month_first_week; $i <= $month_last_week; $i++) {
  3384. //the "day of the week" of repetition is the same as the $dw_orig,
  3385. //so to get the "day of the month" from the "day of the week", we have
  3386. //to get the first "day of the week" for this week and add the number
  3387. //of days (in seconds) to reach the $dw_orig
  3388. //example: the first week spans between the 28th of April (Monday) to the
  3389. // 4th of May (Sunday). The event occurs on the 2nd day of each week.
  3390. // This means the event occurs on 29/4, 6/5, 13/5, 20/5 and 27/5.
  3391. // We want to get all of these, and then reject 29/4 because it is out
  3392. // of the month itself.
  3393. //First, to get the start time of the first day of the month view (even if
  3394. // the day is from the past month), we get the month start date (1/5) and
  3395. // see which day of the week it is, and subtract the number of days necessary
  3396. // to get back to the first day of the week.
  3397. $month_first_day_weekday = date('N', $start);
  3398. $first_week_start = $start - (($month_first_day_weekday - 1) * 86400);
  3399. //Second, we add the week day of the original event, so that we have an
  3400. // absolute time that represents the first repetition of the event in
  3401. // our 4- or 5-weeks timespan
  3402. $first_event_repeat_start = $first_week_start + (($dw_orig - 1) * 86400) + ($h_orig * 3600) + ($n_orig * 60) + $s_orig;
  3403. //Third, we start looping through the repetitions and see if they are between
  3404. // $start and $end
  3405. for ($i = $first_event_repeat_start; $i <= $end; $i+=604800) {
  3406. if ($start < $i && $i < $end) {
  3407. list($y_repeat, $m_repeat, $d_repeat, $h_repeat, $n_repeat, $s_repeat) = split('/', date('Y/m/j/H/i/s', $i));
  3408. $events[] = array($course_info['id'], $row['id'], mktime($h_orig, $n_orig, $s_orig, $m_now, $d_orig, $y_now), mktime($h_orig_e, $n_orig_e, $s_orig_e, $m_now, $d_orig_e, $y_now), $row['title'], $row['content']);
  3409. }
  3410. }
  3411. }
  3412. }
  3413. break;
  3414. case 'monthlyByDate':
  3415. $time_orig = date('Y/n/W/j/G/i/s', $orig_start);
  3416. list($y_orig, $m_orig, $w_orig, $d_orig, $h_orig, $n_orig, $s_orig) = split('/', $time_orig);
  3417. $time_now = date('Y/n/W/j/G/i/s', $end);
  3418. list($y_now, $m_now, $w_now, $d_now, $h_now, $n_now, $s_now) = split('/', $time_now);
  3419. $event_repetition_time = mktime($h_orig, $n_orig, $s_orig, $m_now, $d_orig, $y_now);
  3420. if (($y_now > $y_orig) OR (($y_now == $y_orig) && ($m_now > $m_orig))) { //if the event is after the original (at least one month) and the original event's day is between the first day of the week and the last day of the week
  3421. $time_orig_end = date('Y/n/j/G/i/s', $orig_end);
  3422. list($y_orig_e, $m_orig_e, $d_orig_e, $h_orig_e, $n_orig_e, $s_orig_e) = split('/', $time_orig_end);
  3423. $events[] = array($course_info['id'], $row['id'], mktime($h_orig, $n_orig, $s_orig, $m_now, $d_orig, $y_now), mktime($h_orig_e, $n_orig_e, $s_orig_e, $m_now, $d_orig_e, $y_now), $row['title'], $row['content']);
  3424. }
  3425. break;
  3426. case 'monthlyByDayR':
  3427. //not implemented yet
  3428. break;
  3429. case 'monthlyByDay':
  3430. //not implemented yet
  3431. break;
  3432. case 'yearly':
  3433. $time_orig = date('Y/n/j/z/G/i/s', $orig_start);
  3434. list($y_orig, $m_orig, $d_orig, $dy_orig, $h_orig, $n_orig, $s_orig) = split('/', $time_orig);
  3435. $time_now = date('Y/n/j/z/G/i/s', $end);
  3436. list($y_now, $m_now, $d_now, $dy_now, $h_now, $n_now, $s_now) = split('/', $time_now);
  3437. $event_repetition_time = mktime($h_orig, $n_orig, $s_orig, $m_orig, $d_orig, $y_now);
  3438. if ((($y_now > $y_orig) && ($start < $event_repetition_time && $event_repetition_time < $end))) {
  3439. $time_orig_end = date('Y/n/j/G/i/s', $orig_end);
  3440. list($y_orig_e, $m_orig_e, $d_orig_e, $dy_orig_e, $h_orig_e, $n_orig_e, $s_orig_e) = split('/', $time_orig_end);
  3441. $events[] = array($course_info['id'], $row['id'], mktime($h_orig, $n_orig, $s_orig, $m_now, $d_orig, $y_now), mktime($h_orig_e, $n_orig_e, $s_orig_e, $m_now, $d_orig_e, $y_now), $row['title'], $row['content']);
  3442. }
  3443. break;
  3444. default:
  3445. break;
  3446. }
  3447. }
  3448. }
  3449. return $events;
  3450. }
  3451. /**
  3452. * Get repeated events of a course between two dates (1 year timespan). Used for the list display.
  3453. * This is virtually unlimited but by default it shortens to 100 years from now (even a birthday shouldn't be useful more than this time - except for turtles)
  3454. * Returns an array containing the events
  3455. * @param string Course info array (as returned by api_get_course_info())
  3456. * @param int UNIX timestamp of span start. Defaults 0, later transformed into today's start
  3457. * @param int UNIX timestamp. Defaults to 0, later transformed into today's end
  3458. * @param array A set of parameters to alter the SQL query
  3459. * @return array [int] => [course_id,parent_event_id,start_date,end_date,title,description]
  3460. */
  3461. function get_repeated_events_list_view($course_info, $start = 0, $end = 0, $params)
  3462. {
  3463. $events = array();
  3464. //block $end if higher than 2038 -- PHP doesn't go past that
  3465. if ($end > 2145934800) {
  3466. $end = 2145934800;
  3467. }
  3468. //initialise all values
  3469. $y = 0;
  3470. $m = 0;
  3471. $d = 0;
  3472. if (empty($start) or empty($end)) {
  3473. $time = time();
  3474. $y = date('Y');
  3475. $m = date('m');
  3476. }
  3477. if (empty($start)) {
  3478. $start = mktime(0, 0, 0, $m, 1, $y);
  3479. }
  3480. $db_start = date('Y-m-d H:i:s', $start);
  3481. if (empty($end)) {
  3482. $end = mktime(0, 0, 0, 1, 1, 2037);
  3483. }
  3484. //$db_end = date('Y-m-d H:i:s',$end);
  3485. $t_cal = Database::get_course_table(TABLE_AGENDA, $course_info['dbName']);
  3486. $t_cal_repeat = Database::get_course_table(TABLE_AGENDA_REPEAT, $course_info['dbName']);
  3487. $t_ip = Database::get_course_table(TABLE_ITEM_PROPERTY, $course_info['dbName']);
  3488. $sql = "SELECT c.id, c.title, c.content, ".
  3489. " UNIX_TIMESTAMP(c.start_date) as orig_start, UNIX_TIMESTAMP(c.end_date) as orig_end, ".
  3490. " cr.cal_type, cr.cal_end ".
  3491. " FROM $t_cal c, $t_cal_repeat cr, $t_ip as item_property ".
  3492. " WHERE cr.cal_end >= $start ".
  3493. " AND cr.cal_id = c.id ".
  3494. " AND item_property.ref = c.id ".
  3495. " AND item_property.tool = '".TOOL_CALENDAR_EVENT."' ".
  3496. " AND c.start_date <= '$db_start' "
  3497. .(!empty($params['conditions']) ? $params['conditions'] : '')
  3498. .(!empty($params['groupby']) ? ' GROUP BY '.$params['groupby'] : '')
  3499. .(!empty($params['orderby']) ? ' ORDER BY '.$params['orderby'] : '');
  3500. $res = Database::query($sql);
  3501. if (Database::num_rows($res) > 0) {
  3502. while ($row = Database::fetch_array($res)) {
  3503. $orig_start = $row['orig_start'];
  3504. $orig_end = $row['orig_end'];
  3505. $repeat_type = $row['cal_type'];
  3506. $repeat_end = $row['cal_end'];
  3507. switch ($repeat_type) {
  3508. case 'daily':
  3509. $time_orig_h = date('H', $orig_start);
  3510. $time_orig_m = date('i', $orig_start);
  3511. $time_orig_s = date('s', $orig_start);
  3512. $span = $orig_end - $orig_start; //total seconds between start and stop of original event
  3513. for ($i = $orig_start + 86400; ($i < $end && $i <= $repeat_end); $i+=86400) {
  3514. $current_start = $i; //unixtimestamp start of today's event
  3515. $current_stop = $i + $span; //unixtimestamp stop of today's event
  3516. $events[] = array($course_info['id'], $row['id'], $current_start, $current_stop, $row['title'], $row['content']);
  3517. }
  3518. break;
  3519. case 'weekly':
  3520. //A weekly repeated event is very difficult to catch in a month view,
  3521. // because weeks start before or at the same time as the first day of the month
  3522. //The same can be said for the end of the month.
  3523. // The idea is thus to get all possible events by enlarging the scope of
  3524. // the month to get complete weeks covering the complete month, and then take out
  3525. // the events that start before the 1st ($start) or after the last day of the month ($end)
  3526. $time_orig = date('Y/n/W/j/N/G/i/s', $orig_start);
  3527. list($y_orig, $m_orig, $w_orig, $d_orig, $dw_orig, $h_orig, $n_orig, $s_orig) = split('/', $time_orig);
  3528. $time_orig_end = date('Y/n/W/j/N/G/i/s', $orig_end);
  3529. list($y_orig_e, $m_orig_e, $w_orig_e, $d_orig_e, $dw_orig_e, $h_orig_e, $n_orig_e, $s_orig_e) = split('/', $time_orig_end);
  3530. $time_now = date('Y/n/W/j/N/G/i/s', $end);
  3531. list($y_now, $m_now, $w_now, $d_now, $dw_now, $h_now, $n_now, $s_now) = split('/', $time_now);
  3532. if ($w_now == 52) {
  3533. ++$y_now;
  3534. $w_now = 1;
  3535. } else {
  3536. ++$w_now;
  3537. }
  3538. $month_first_week = date('W', $start);
  3539. $total_weeks = ((date('Y', $end) - $y_orig) - 1) * 52;
  3540. $month_last_week = $month_first_week + $total_weeks;
  3541. if (($y_now > $y_orig) OR (($y_now == $y_orig) && ($w_now > $w_orig))) { //if the event is after the original (at least one week) and the day of the week is the same
  3542. //for($i=$month_first_week;($i<=$month_last_week && $i<1000);$i++)
  3543. //{
  3544. /*
  3545. The "day of the week" of repetition is the same as the $dw_orig,
  3546. so to get the "day of the month" from the "day of the week", we have
  3547. to get the first "day of the week" for this week and add the number
  3548. of days (in seconds) to reach the $dw_orig
  3549. example: the first week spans between the 28th of April (Monday) to the
  3550. 4th of May (Sunday). The event occurs on the 2nd day of each week.
  3551. This means the event occurs on 29/4, 6/5, 13/5, 20/5 and 27/5.
  3552. We want to get all of these, and then reject 29/4 because it is out
  3553. of the month itself.
  3554. First, to get the start time of the first day of the month view (even if
  3555. the day is from the past month), we get the month start date (1/5) and
  3556. see which day of the week it is, and subtract the number of days necessary
  3557. to get back to the first day of the week.
  3558. */
  3559. $month_first_day_weekday = date('N', $start);
  3560. $first_week_start = $start - (($month_first_day_weekday - 1) * 86400);
  3561. //Second, we add the week day of the original event, so that we have an
  3562. // absolute time that represents the first repetition of the event in
  3563. // our 4- or 5-weeks timespan
  3564. $first_event_repeat_start = $first_week_start + (($dw_orig - 1) * 86400) + ($h_orig * 3600) + ($n_orig * 60) + $s_orig;
  3565. //Third, we start looping through the repetitions and see if they are between
  3566. // $start and $end
  3567. for ($i = $first_event_repeat_start; ($i <= $end && $i <= $repeat_end); $i+=604800) {
  3568. if ($start < $i && $i <= $end && $i <= $repeat_end) {
  3569. list($y_repeat, $m_repeat, $d_repeat, $h_repeat, $n_repeat, $s_repeat) = split('/', date('Y/m/j/H/i/s', $i));
  3570. $new_start_time = mktime($h_orig, $n_orig, $s_orig, $m_now, $d_orig, $y_now);
  3571. $new_stop_time = mktime($h_orig_e, $n_orig_e, $s_orig_e, $m_now, $d_orig_e, $y_now);
  3572. $events[] = array($course_info['id'], $row['id'], $new_start_time, $new_stop_time, $row['title'], $row['content']);
  3573. }
  3574. $time_now = date('Y/n/W/j/N/G/i/s', $i + 604800);
  3575. list($y_now, $m_now, $w_now, $d_now, $dw_now, $h_now, $n_now, $s_now) = split('/', $time_now);
  3576. }
  3577. //}
  3578. }
  3579. break;
  3580. case 'monthlyByDate':
  3581. $time_orig = date('Y/n/W/j/G/i/s', $orig_start);
  3582. list($y_orig, $m_orig, $w_orig, $d_orig, $h_orig, $n_orig, $s_orig) = split('/', $time_orig);
  3583. $time_now = date('Y/n/W/j/G/i/s', $start);
  3584. list($y_now, $m_now, $w_now, $d_now, $h_now, $n_now, $s_now) = split('/', $time_now);
  3585. //make sure we are one month ahead (to avoid being the same month as the original event)
  3586. if ($m_now == 12) {
  3587. ++$y_now;
  3588. $m_now = 1;
  3589. } else {
  3590. ++$m_now;
  3591. }
  3592. $time_orig_end = date('Y/n/j/G/i/s', $orig_end);
  3593. list($y_orig_e, $m_orig_e, $d_orig_e, $h_orig_e, $n_orig_e, $s_orig_e) = split('/', $time_orig_end);
  3594. $event_repetition_time = mktime($h_orig, $n_orig, $s_orig, $m_now, $d_orig, $y_now);
  3595. $diff = $orig_end - $orig_start;
  3596. while ((($y_now > $y_orig) OR (($y_now == $y_orig) && ($m_now > $m_orig))) && ($event_repetition_time < $end) && ($event_repetition_time < $repeat_end)) { //if the event is after the original (at least one month) and the original event's day is between the first day of the week and the last day of the week
  3597. $new_start_time = mktime($h_orig, $n_orig, $s_orig, $m_now, $d_orig, $y_now);
  3598. $new_stop_time = mktime($h_orig_e, $n_orig_e, $s_orig_e, $m_now, $d_orig_e, $y_now);
  3599. $events[] = array($course_info['id'], $row['id'], $new_start_time, $new_stop_time, $row['title'], $row['content']);
  3600. if ($m_now == 12) {
  3601. ++$y_now;
  3602. $m_now = 1;
  3603. } else {
  3604. ++$m_now;
  3605. }
  3606. $event_repetition_time = mktime($h_orig, $n_orig, $s_orig, $m_now, $d_orig, $y_now);
  3607. }
  3608. break;
  3609. case 'monthlyByDayR':
  3610. //not implemented yet
  3611. break;
  3612. case 'monthlyByDay':
  3613. //not implemented yet
  3614. break;
  3615. case 'yearly':
  3616. $time_orig = date('Y/n/j/z/G/i/s', $orig_start);
  3617. list($y_orig, $m_orig, $d_orig, $dy_orig, $h_orig, $n_orig, $s_orig) = split('/', $time_orig);
  3618. $time_now = date('Y/n/j/z/G/i/s', $end);
  3619. list($y_now, $m_now, $d_now, $dy_now, $h_now, $n_now, $s_now) = split('/', $time_now);
  3620. $event_repetition_time = mktime($h_orig, $n_orig, $s_orig, $m_orig, $d_orig, $y_now);
  3621. while ((($y_now > $y_orig) && ($start < $event_repetition_time && $event_repetition_time < $end && $event_repetition_time < $repeat_end))) {
  3622. $time_orig_end = date('Y/n/j/G/i/s', $orig_end);
  3623. list($y_orig_e, $m_orig_e, $d_orig_e, $dy_orig_e, $h_orig_e, $n_orig_e, $s_orig_e) = split('/', $time_orig_end);
  3624. $events[] = array($course_info['id'], $row['id'], mktime($h_orig, $n_orig, $s_orig, $m_now, $d_orig, $y_now), mktime($h_orig_e, $n_orig_e, $s_orig_e, $m_now, $d_orig_e, $y_now), $row['title'], $row['content']);
  3625. ++$y_now;
  3626. $event_repetition_time = mktime($h_orig, $n_orig, $s_orig, $m_orig, $d_orig, $y_now);
  3627. }
  3628. break;
  3629. default:
  3630. break;
  3631. }
  3632. }
  3633. }
  3634. return $events;
  3635. }
  3636. /**
  3637. * Tells if an agenda item is repeated
  3638. * @param string Course database
  3639. * @param int The agenda item
  3640. * @return boolean True if repeated, false otherwise
  3641. */
  3642. function is_repeated_event($id, $course = null)
  3643. {
  3644. if (empty($course)) {
  3645. $course_info = api_get_course_info();
  3646. $course = $course_info['dbName'];
  3647. }
  3648. $id = (int) $id;
  3649. $t_agenda_repeat = Database::get_course_table(TABLE_AGENDA_REPEAT, $course);
  3650. $sql = "SELECT * FROM $t_agenda_repeat WHERE cal_id = $id";
  3651. $res = Database::query($sql);
  3652. if (Database::num_rows($res) > 0) {
  3653. return true;
  3654. }
  3655. return false;
  3656. }
  3657. /**
  3658. * Adds x weeks to a UNIX timestamp
  3659. * @param int The timestamp
  3660. * @param int The number of weeks to add
  3661. * @return int The new timestamp
  3662. */
  3663. function add_week($timestamp, $num = 1)
  3664. {
  3665. return $timestamp + $num * 604800;
  3666. }
  3667. /**
  3668. * Adds x months to a UNIX timestamp
  3669. * @param int The timestamp
  3670. * @param int The number of years to add
  3671. * @return int The new timestamp
  3672. */
  3673. function add_month($timestamp, $num = 1)
  3674. {
  3675. list($y, $m, $d, $h, $n, $s) = split('/', date('Y/m/d/h/i/s', $timestamp));
  3676. if ($m + $num > 12) {
  3677. $y += floor($num / 12);
  3678. $m += $num % 12;
  3679. } else {
  3680. $m += $num;
  3681. }
  3682. return mktime($h, $n, $s, $m, $d, $y);
  3683. }
  3684. /**
  3685. * Adds x years to a UNIX timestamp
  3686. * @param int The timestamp
  3687. * @param int The number of years to add
  3688. * @return int The new timestamp
  3689. */
  3690. function add_year($timestamp, $num = 1)
  3691. {
  3692. list($y, $m, $d, $h, $n, $s) = split('/', date('Y/m/d/h/i/s', $timestamp));
  3693. return mktime($h, $n, $s, $m, $d, $y + $num);
  3694. }
  3695. /**
  3696. * Adds an agenda item in the database. Similar to store_new_agenda_item() except it takes parameters
  3697. * @param array Course info
  3698. * @param string Event title
  3699. * @param string Event content/description
  3700. * @param string Start date
  3701. * @param string End date
  3702. * @param array List of groups to which this event is added
  3703. * @param int Parent id (optional)
  3704. * @return int The new item's DB ID
  3705. */
  3706. function agenda_add_item($course_info, $title, $content, $db_start_date, $db_end_date, $to = array(), $parent_id = null, $file_comment = '')
  3707. {
  3708. $user_id = api_get_user_id();
  3709. // database table definitions
  3710. $t_agenda = Database::get_course_table(TABLE_AGENDA);
  3711. $item_property = Database::get_course_table(TABLE_ITEM_PROPERTY);
  3712. // some filtering of the input data
  3713. $title = Database::escape_string($title);
  3714. $content = Database::escape_string($content);
  3715. $db_start_date = api_get_utc_datetime($db_start_date);
  3716. $start_date = Database::escape_string($db_start_date);
  3717. if (!empty($db_end_date)) {
  3718. $db_end_date = api_get_utc_datetime($db_end_date);
  3719. }
  3720. $end_date = Database::escape_string($db_end_date);
  3721. $id_session = api_get_session_id();
  3722. $course_id = api_get_course_int_id();
  3723. $group_id = api_get_group_id();
  3724. // check if exists in calendar_event table and if it is not deleted!
  3725. $sql = "SELECT * FROM $t_agenda agenda, $item_property item_property
  3726. WHERE
  3727. agenda.c_id = $course_id AND
  3728. item_property.c_id = $course_id AND
  3729. agenda.title = '$title'
  3730. AND agenda.content = '$content'
  3731. AND agenda.start_date = '$start_date'
  3732. AND agenda.end_date = '$end_date' ".(!empty($parent_id) ? "
  3733. AND agenda.parent_event_id = '$parent_id'" : "")."
  3734. AND agenda.session_id = '$id_session'
  3735. AND item_property.tool = '".TOOL_CALENDAR_EVENT."'
  3736. AND item_property.ref = agenda.id
  3737. AND item_property.visibility <> 2";
  3738. $result = Database::query($sql);
  3739. $count = Database::num_rows($result);
  3740. if ($count > 0) {
  3741. return false;
  3742. }
  3743. $course_id = api_get_course_int_id();
  3744. $sql = "INSERT INTO ".$t_agenda." (c_id, title,content, start_date, end_date".(!empty($parent_id) ? ',parent_event_id' : '').", session_id)
  3745. VALUES($course_id, '".$title."','".$content."', '".$start_date."','".$end_date."'".(!empty($parent_id) ? ','.((int) $parent_id) : '').", '".$id_session."')";
  3746. $result = Database::query($sql);
  3747. $last_id = Database::insert_id();
  3748. // add a attachment file in agenda
  3749. add_agenda_attachment_file($file_comment, $last_id);
  3750. // store in last_tooledit (first the groups, then the users
  3751. if (!empty($to)) {
  3752. $send_to = separate_users_groups($to);
  3753. // storing the selected groups
  3754. if (is_array($send_to['groups'])) {
  3755. foreach ($send_to['groups'] as $group) {
  3756. api_item_property_update($course_info, TOOL_CALENDAR_EVENT, $last_id, "AgendaAdded", $user_id, $group, 0, $start_date, $end_date);
  3757. $done = true;
  3758. }
  3759. }
  3760. // storing the selected users
  3761. if (is_array($send_to['users'])) {
  3762. foreach ($send_to['users'] as $user) {
  3763. api_item_property_update($course_info, TOOL_CALENDAR_EVENT, $last_id, "AgendaAdded", $user_id, 0, $user, $start_date, $end_date);
  3764. $done = true;
  3765. }
  3766. }
  3767. if (isset($send_to['everyone']) && $send_to['everyone']) {
  3768. api_item_property_update($course_info, TOOL_CALENDAR_EVENT, $last_id, "AgendaAdded", $user_id, 0, 0, $start_date, $end_date);
  3769. }
  3770. }
  3771. // storing the resources
  3772. if (!empty($_SESSION['source_type']) && !empty($last_id)) {
  3773. store_resources($_SESSION['source_type'], $last_id);
  3774. }
  3775. return $last_id;
  3776. }
  3777. /**
  3778. * This function delete a attachment file by id
  3779. * @param integer attachment file Id
  3780. *
  3781. */
  3782. function delete_attachment_file($id_attach)
  3783. {
  3784. global $_course;
  3785. $agenda_table_attachment = Database::get_course_table(TABLE_AGENDA_ATTACHMENT);
  3786. $id_attach = intval($id_attach);
  3787. $sql = "DELETE FROM $agenda_table_attachment WHERE id = ".$id_attach;
  3788. $result = Database::query($sql);
  3789. $last_id_file = Database::insert_id();
  3790. // update item_property
  3791. api_item_property_update($_course, 'calendar_event_attachment', $id_attach, 'AgendaAttachmentDeleted', api_get_user_id());
  3792. if (!empty($result)) {
  3793. Display::display_confirmation_message(get_lang("AttachmentFileDeleteSuccess"));
  3794. }
  3795. }
  3796. /**
  3797. * This function add a attachment file into agenda
  3798. * @param string a comment about file
  3799. * @param int last id from calendar table
  3800. *
  3801. */
  3802. function add_agenda_attachment_file($file_comment, $last_id)
  3803. {
  3804. global $_course;
  3805. $agenda_table_attachment = Database::get_course_table(TABLE_AGENDA_ATTACHMENT);
  3806. $last_id = intval($last_id);
  3807. // Storing the attachments
  3808. if (!empty($_FILES['user_upload']['name'])) {
  3809. $upload_ok = process_uploaded_file($_FILES['user_upload']);
  3810. }
  3811. if (!empty($upload_ok)) {
  3812. $courseDir = $_course['path'].'/upload/calendar';
  3813. $sys_course_path = api_get_path(SYS_COURSE_PATH);
  3814. $updir = $sys_course_path.$courseDir;
  3815. // Try to add an extension to the file if it hasn't one
  3816. $new_file_name = add_ext_on_mime(stripslashes($_FILES['user_upload']['name']), $_FILES['user_upload']['type']);
  3817. // user's file name
  3818. $file_name = $_FILES['user_upload']['name'];
  3819. if (!filter_extension($new_file_name)) {
  3820. Display :: display_error_message(get_lang('UplUnableToSaveFileFilteredExtension'));
  3821. } else {
  3822. $new_file_name = uniqid('');
  3823. $new_path = $updir.'/'.$new_file_name;
  3824. $result = @move_uploaded_file($_FILES['user_upload']['tmp_name'], $new_path);
  3825. $safe_file_comment = Database::escape_string($file_comment);
  3826. $safe_file_name = Database::escape_string($file_name);
  3827. $safe_new_file_name = Database::escape_string($new_file_name);
  3828. $course_id = api_get_course_int_id();
  3829. // Storing the attachments if any
  3830. if ($result) {
  3831. $sql = 'INSERT INTO '.$agenda_table_attachment.'(c_id, filename,comment, path,agenda_id,size) '.
  3832. "VALUES ($course_id, '".$safe_file_name."', '".$safe_file_comment."', '".$safe_new_file_name."' , '".$last_id."', '".intval($_FILES['user_upload']['size'])."' )";
  3833. Database::query($sql);
  3834. //$message.=' / '.get_lang('FileUploadSucces').'<br />';
  3835. $last_id_file = Database::insert_id();
  3836. api_item_property_update($_course, 'calendar_event_attachment', $last_id_file, 'AgendaAttachmentAdded', api_get_user_id());
  3837. }
  3838. }
  3839. }
  3840. }
  3841. /**
  3842. * This function edit a attachment file into agenda
  3843. * @param string a comment about file
  3844. * @param int Agenda Id
  3845. * @param int attachment file Id
  3846. */
  3847. function edit_agenda_attachment_file($file_comment, $agenda_id, $id_attach)
  3848. {
  3849. global $_course;
  3850. $agenda_table_attachment = Database::get_course_table(TABLE_AGENDA_ATTACHMENT);
  3851. // Storing the attachments
  3852. if (!empty($_FILES['user_upload']['name'])) {
  3853. $upload_ok = process_uploaded_file($_FILES['user_upload']);
  3854. }
  3855. if (!empty($upload_ok)) {
  3856. $courseDir = $_course['path'].'/upload/calendar';
  3857. $sys_course_path = api_get_path(SYS_COURSE_PATH);
  3858. $updir = $sys_course_path.$courseDir;
  3859. // Try to add an extension to the file if it hasn't one
  3860. $new_file_name = add_ext_on_mime(stripslashes($_FILES['user_upload']['name']), $_FILES['user_upload']['type']);
  3861. // user's file name
  3862. $file_name = $_FILES['user_upload']['name'];
  3863. if (!filter_extension($new_file_name)) {
  3864. Display :: display_error_message(get_lang('UplUnableToSaveFileFilteredExtension'));
  3865. } else {
  3866. $new_file_name = uniqid('');
  3867. $new_path = $updir.'/'.$new_file_name;
  3868. $result = @move_uploaded_file($_FILES['user_upload']['tmp_name'], $new_path);
  3869. $safe_file_comment = Database::escape_string($file_comment);
  3870. $safe_file_name = Database::escape_string($file_name);
  3871. $safe_new_file_name = Database::escape_string($new_file_name);
  3872. $safe_agenda_id = (int) $agenda_id;
  3873. $safe_id_attach = (int) $id_attach;
  3874. // Storing the attachments if any
  3875. if ($result) {
  3876. $sql = "UPDATE $agenda_table_attachment SET filename = '$safe_file_name', comment = '$safe_file_comment', path = '$safe_new_file_name', agenda_id = '$safe_agenda_id', size ='".intval($_FILES['user_upload']['size'])."'
  3877. WHERE id = '$safe_id_attach'";
  3878. Database::query($sql);
  3879. api_item_property_update($_course, 'calendar_event_attachment', $safe_id_attach, 'AgendaAttachmentUpdated', api_get_user_id());
  3880. }
  3881. }
  3882. }
  3883. }
  3884. /**
  3885. * Adds a repetitive item to the database
  3886. * @param array Course info
  3887. * @param int The original event's id
  3888. * @param string Type of repetition
  3889. * @param int Timestamp of end of repetition (repeating until that date)
  3890. * @param array Original event's destination (users list)
  3891. * @param string a comment about a attachment file into agenda
  3892. * @return boolean False if error, True otherwise
  3893. */
  3894. function agenda_add_repeat_item($course_info, $orig_id, $type, $end, $orig_dest, $file_comment = '')
  3895. {
  3896. $t_agenda = Database::get_course_table(TABLE_AGENDA);
  3897. $t_agenda_r = Database::get_course_table(TABLE_AGENDA_REPEAT);
  3898. $course_id = $course_info['real_id'];
  3899. $sql = 'SELECT title, content, start_date as sd, end_date as ed FROM '.$t_agenda.' WHERE c_id = '.$course_id.' AND id ="'.intval($orig_id).'" ';
  3900. $res = Database::query($sql);
  3901. if (Database::num_rows($res) !== 1) {
  3902. return false;
  3903. }
  3904. $row = Database::fetch_array($res);
  3905. $orig_start = api_strtotime(api_get_local_time($row['sd']));
  3906. $orig_end = api_strtotime(api_get_local_time($row['ed']));
  3907. $diff = $orig_end - $orig_start;
  3908. $orig_title = $row['title'];
  3909. $orig_content = $row['content'];
  3910. $now = time();
  3911. $type = Database::escape_string($type);
  3912. $end = intval($end);
  3913. if (1 <= $end && $end <= 500) {
  3914. //we assume that, with this type of value, the user actually gives a count of repetitions
  3915. //and that he wants us to calculate the end date with that (particularly in case of imports from ical)
  3916. switch ($type) {
  3917. case 'daily':
  3918. $end = $orig_start + (86400 * $end);
  3919. break;
  3920. case 'weekly':
  3921. $end = add_week($orig_start, $end);
  3922. break;
  3923. case 'monthlyByDate':
  3924. $end = add_month($orig_start, $end);
  3925. break;
  3926. case 'monthlyByDay':
  3927. //TODO
  3928. break;
  3929. case 'monthlyByDayR':
  3930. //TODO
  3931. break;
  3932. case 'yearly':
  3933. $end = add_year($orig_start, $end);
  3934. break;
  3935. }
  3936. }
  3937. if ($end > $now
  3938. && in_array($type, array('daily', 'weekly', 'monthlyByDate', 'monthlyByDay', 'monthlyByDayR', 'yearly'))) {
  3939. $sql = "INSERT INTO $t_agenda_r (c_id, cal_id, cal_type, cal_end) VALUES ($course_id, '$orig_id','$type',$end)";
  3940. $res = Database::query($sql);
  3941. switch ($type) {
  3942. case 'daily':
  3943. for ($i = $orig_start + 86400; ($i <= $end); $i += 86400) {
  3944. $res = agenda_add_item($course_info, $orig_title, $orig_content, date('Y-m-d H:i:s', $i), date('Y-m-d H:i:s', $i + $diff), $orig_dest, $orig_id, $file_comment);
  3945. }
  3946. break;
  3947. case 'weekly':
  3948. for ($i = $orig_start + 604800; ($i <= $end); $i += 604800) {
  3949. $res = agenda_add_item($course_info, $orig_title, $orig_content, date('Y-m-d H:i:s', $i), date('Y-m-d H:i:s', $i + $diff), $orig_dest, $orig_id, $file_comment);
  3950. }
  3951. break;
  3952. case 'monthlyByDate':
  3953. $next_start = add_month($orig_start);
  3954. while ($next_start <= $end) {
  3955. $res = agenda_add_item($course_info, $orig_title, $orig_content, date('Y-m-d H:i:s', $next_start), date('Y-m-d H:i:s', $next_start + $diff), $orig_dest, $orig_id, $file_comment);
  3956. $next_start = add_month($next_start);
  3957. }
  3958. break;
  3959. case 'monthlyByDay':
  3960. //not yet implemented
  3961. break;
  3962. case 'monthlyByDayR':
  3963. //not yet implemented
  3964. break;
  3965. case 'yearly':
  3966. $next_start = add_year($orig_start);
  3967. while ($next_start <= $end) {
  3968. $res = agenda_add_item($course_info, $orig_title, $orig_content, date('Y-m-d H:i:s', $next_start), date('Y-m-d H:i:s', $next_start + $diff), $orig_dest, $orig_id, $file_comment);
  3969. $next_start = add_year($next_start);
  3970. }
  3971. break;
  3972. }
  3973. }
  3974. return true;
  3975. }
  3976. /**
  3977. * Import an iCal file into the database
  3978. * @param array Course info
  3979. * @return boolean True on success, false otherwise
  3980. */
  3981. function agenda_import_ical($course_info, $file)
  3982. {
  3983. require_once api_get_path(LIBRARY_PATH).'fileUpload.lib.php';
  3984. $charset = api_get_system_encoding();
  3985. $filepath = api_get_path(SYS_ARCHIVE_PATH).$file['name'];
  3986. if (!@move_uploaded_file($file['tmp_name'], $filepath)) {
  3987. error_log('Problem moving uploaded file: '.$file['error'].' in '.__FILE__.' line '.__LINE__);
  3988. return false;
  3989. }
  3990. require_once api_get_path(LIBRARY_PATH).'icalcreator/iCalcreator.class.php';
  3991. $ical = new vcalendar();
  3992. $ical->setConfig('directory', dirname($filepath));
  3993. $ical->setConfig('filename', basename($filepath));
  3994. $return = $ical->parse();
  3995. //we need to recover: summary, description, dtstart, dtend, organizer, attendee, location (=course name),
  3996. /*
  3997. $ve = $ical->getComponent(VEVENT);
  3998. $ttitle = $ve->getProperty('summary');
  3999. $title = api_convert_encoding($ttitle,$charset,'UTF-8');
  4000. $tdesc = $ve->getProperty('description');
  4001. $desc = api_convert_encoding($tdesc,$charset,'UTF-8');
  4002. $start_date = $ve->getProperty('dtstart');
  4003. $start_date_string = $start_date['year'].'-'.$start_date['month'].'-'.$start_date['day'].' '.$start_date['hour'].':'.$start_date['min'].':'.$start_date['sec'];
  4004. $ts = $ve->getProperty('dtend');
  4005. if ($ts) {
  4006. $end_date_string = $ts['year'].'-'.$ts['month'].'-'.$ts['day'].' '.$ts['hour'].':'.$ts['min'].':'.$ts['sec'];
  4007. } else {
  4008. //Check duration if dtend does not exist
  4009. $duration = $ve->getProperty('duration');
  4010. if ($duration) {
  4011. $duration = $ve->getProperty('duration');
  4012. $duration_string = $duration['year'].'-'.$duration['month'].'-'.$duration['day'].' '.$duration['hour'].':'.$duration['min'].':'.$duration['sec'];
  4013. $start_date_tms = mktime(intval($start_date['hour']), intval($start_date['min']), intval($start_date['sec']), intval($start_date['month']), intval($start_date['day']), intval($start_date['year']));
  4014. //$start_date_tms = mktime(($start_date['hour']), ($start_date['min']), ($start_date['sec']), ($start_date['month']), ($start_date['day']), ($start_date['year']));
  4015. //echo date('d-m-Y - h:i:s', $start_date_tms);
  4016. $end_date_string = mktime(intval($start_date['hour']) +$duration['hour'], intval($start_date['min']) + $duration['min'], intval($start_date['sec']) + $duration['sec'], intval($start_date['month']) + $duration['month'], intval($start_date['day'])+$duration['day'], intval($start_date['year']) + $duration['year']);
  4017. $end_date_string = date('Y-m-d H:i:s', $end_date_string);
  4018. //echo date('d-m-Y - h:i:s', $end_date_string);
  4019. }
  4020. }
  4021. //echo $start_date.' - '.$end_date;
  4022. $organizer = $ve->getProperty('organizer');
  4023. $attendee = $ve->getProperty('attendee');
  4024. $course_name = $ve->getProperty('location');
  4025. //insert the event in our database
  4026. //var_dump($title,$desc,$start_date,$end_date);
  4027. $id = agenda_add_item($course_info,$title,$desc,$start_date_string,$end_date_string,$_POST['selectedform']);
  4028. $repeat = $ve->getProperty('rrule');
  4029. if(is_array($repeat) && !empty($repeat['FREQ'])) {
  4030. $trans = array('DAILY'=>'daily','WEEKLY'=>'weekly','MONTHLY'=>'monthlyByDate','YEARLY'=>'yearly');
  4031. $freq = $trans[$repeat['FREQ']];
  4032. $interval = $repeat['INTERVAL'];
  4033. if(isset($repeat['UNTIL']) && is_array($repeat['UNTIL'])) {
  4034. $until = mktime(23,59,59,$repeat['UNTIL']['month'],$repeat['UNTIL']['day'],$repeat['UNTIL']['year']);
  4035. $res = agenda_add_repeat_item($course_info,$id,$freq,$until,$_POST['selectedform']);
  4036. } */
  4037. $eventcount = 0;
  4038. $message = array();
  4039. $agenda_obj = new Agenda();
  4040. while (true) {
  4041. //we need to recover: summary, description, dtstart, dtend, organizer, attendee, location (=course name)
  4042. $ve = $ical->getComponent('VEVENT', $eventcount);
  4043. if (!$ve) {
  4044. break;
  4045. }
  4046. $ttitle = $ve->getProperty('summary');
  4047. $title = api_convert_encoding($ttitle, $charset, 'UTF-8');
  4048. $tdesc = $ve->getProperty('description');
  4049. $desc = api_convert_encoding($tdesc, $charset, 'UTF-8');
  4050. $start_date = $ve->getProperty('dtstart', false, true);
  4051. if (isset($start_date['params']['VALUE'])) {
  4052. $start_date_value = $start_date['value'];
  4053. if ($start_date['params']['VALUE'] == 'DATE') {
  4054. $start_date_string = $start_date_value['year'].'-'.$start_date_value['month'].'-'.$start_date_value['day'].'';
  4055. } else {
  4056. $start_date_string = $start_date_value['year'].'-'.$start_date_value['month'].'-'.$start_date_value['day'].' '.$start_date_value['hour'].':'.$start_date_value['min'].':'.$start_date_value['sec'];
  4057. }
  4058. } else {
  4059. continue;
  4060. }
  4061. $ts = $ve->getProperty('dtend');
  4062. if ($ts) {
  4063. $end_date = $ve->getProperty('dtend', false, true);
  4064. if (isset($end_date['params']['VALUE'])) {
  4065. $end_date_value = $end_date['value'];
  4066. if ($end_date['params']['VALUE'] == 'DATE') {
  4067. $end_date_string = $end_date_value['year'].'-'.$end_date_value['month'].'-'.$end_date_value['day'].'';
  4068. } else {
  4069. $end_date_string = $end_date_value['year'].'-'.$end_date_value['month'].'-'.$end_date_value['day'].' '.$end_date_value['hour'].':'.$end_date_value['min'].':'.$end_date_value['sec'];
  4070. }
  4071. } else {
  4072. //Default behaviour
  4073. $end_date_string = $ts['year'].'-'.$ts['month'].'-'.$ts['day'].' '.$ts['hour'].':'.$ts['min'].':'.$ts['sec'];
  4074. }
  4075. } else {
  4076. //Check duration if dtend does not exist
  4077. $duration = $ve->getProperty('duration');
  4078. if ($duration) {
  4079. $duration = $ve->getProperty('duration');
  4080. $duration_string = $duration['year'].'-'.$duration['month'].'-'.$duration['day'].' '.$duration['hour'].':'.$duration['min'].':'.$duration['sec'];
  4081. $start_date_tms = mktime(intval($start_date['hour']), intval($start_date['min']), intval($start_date['sec']), intval($start_date['month']), intval($start_date['day']), intval($start_date['year']));
  4082. //$start_date_tms = mktime(($start_date['hour']), ($start_date['min']), ($start_date['sec']), ($start_date['month']), ($start_date['day']), ($start_date['year']));
  4083. //echo date('d-m-Y - h:i:s', $start_date_tms);
  4084. $end_date_string = mktime(intval($start_date['hour']) + $duration['hour'], intval($start_date['min']) + $duration['min'], intval($start_date['sec']) + $duration['sec'], intval($start_date['month']) + $duration['month'], intval($start_date['day']) + $duration['day'], intval($start_date['year']) + $duration['year']);
  4085. $end_date_string = api_get_utc_datetime($end_date_string);
  4086. //echo date('d-m-Y - h:i:s', $end_date_string);
  4087. }
  4088. }
  4089. //echo $start_date.' - '.$end_date;
  4090. $organizer = $ve->getProperty('organizer');
  4091. $attendee = $ve->getProperty('attendee');
  4092. $course_name = $ve->getProperty('location');
  4093. //insert the event in our database
  4094. $agenda_obj->type = 'course';
  4095. $all_day = 'false';
  4096. if ($start_date_string == $end_date_string) {
  4097. $all_day = 'true';
  4098. }
  4099. $date = new DateTime($start_date_string);
  4100. $date->add(new DateInterval('P1D'));
  4101. if ($start_date_string == $date->format('Y-m-d h:i:s')) {
  4102. $all_day = 'true';
  4103. }
  4104. //var_dump($start_date_string, $end_date_string, $all_day);
  4105. $id = $agenda_obj->add_event($start_date_string, $end_date_string, $all_day, null, $title, $desc, array('everyone'));
  4106. $message[] = " $title - ".$start_date_string." - ".$end_date_string;
  4107. $repeat = $ve->getProperty('rrule');
  4108. if (is_array($repeat) && !empty($repeat['FREQ'])) {
  4109. $trans = array(
  4110. 'DAILY' => 'daily',
  4111. 'WEEKLY' => 'weekly',
  4112. 'MONTHLY' => 'monthlyByDate',
  4113. 'YEARLY' => 'yearly'
  4114. );
  4115. $freq = $trans[$repeat['FREQ']];
  4116. $interval = $repeat['INTERVAL'];
  4117. if (isset($repeat['UNTIL']) && is_array($repeat['UNTIL'])) {
  4118. $until = mktime(23, 59, 59, $repeat['UNTIL']['month'], $repeat['UNTIL']['day'], $repeat['UNTIL']['year']);
  4119. $res = agenda_add_repeat_item($course_info, $id, $freq, $until, $attendee);
  4120. }
  4121. //TODO: deal with count
  4122. if (!empty($repeat['COUNT'])) {
  4123. $count = $repeat['COUNT'];
  4124. $res = agenda_add_repeat_item($course_info, $id, $freq, $count, $attendee);
  4125. }
  4126. }
  4127. $eventcount++;
  4128. }
  4129. if (!empty($message)) {
  4130. $message = implode('<br /> ', $message);
  4131. }
  4132. return $message;
  4133. }
  4134. /**
  4135. * This function retrieves one personal agenda item returns it.
  4136. * @param array The array containing existing events. We add to this array.
  4137. * @param int Day
  4138. * @param int Month
  4139. * @param int Year (4 digits)
  4140. * @param int Week number
  4141. * @param string Type of view (month_view, week_view, day_view)
  4142. * @return array The results of the database query, or null if not found
  4143. */
  4144. function get_global_agenda_items($agendaitems, $day = "", $month = "", $year = "", $week = "", $type)
  4145. {
  4146. $tbl_global_agenda = Database::get_main_table(TABLE_MAIN_SYSTEM_CALENDAR);
  4147. $month = Database::escape_string($month);
  4148. $year = Database::escape_string($year);
  4149. $week = Database::escape_string($week);
  4150. $day = Database::escape_string($day);
  4151. // 1. creating the SQL statement for getting the personal agenda items in MONTH view
  4152. $current_access_url_id = api_get_current_access_url_id();
  4153. if ($type == "month_view" or $type == "") {
  4154. // We are in month view
  4155. $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";
  4156. }
  4157. // 2. creating the SQL statement for getting the personal agenda items in WEEK view
  4158. if ($type == "week_view") { // we are in week view
  4159. $start_end_day_of_week = calculate_start_end_of_week($week, $year);
  4160. $start_day = $start_end_day_of_week['start']['day'];
  4161. $start_month = $start_end_day_of_week['start']['month'];
  4162. $start_year = $start_end_day_of_week['start']['year'];
  4163. $end_day = $start_end_day_of_week['end']['day'];
  4164. $end_month = $start_end_day_of_week['end']['month'];
  4165. $end_year = $start_end_day_of_week['end']['year'];
  4166. // in sql statements you have to use year-month-day for date calculations
  4167. $start_filter = $start_year."-".$start_month."-".$start_day." 00:00:00";
  4168. $start_filter = api_get_utc_datetime($start_filter);
  4169. $end_filter = $end_year."-".$end_month."-".$end_day." 23:59:59";
  4170. $end_filter = api_get_utc_datetime($end_filter);
  4171. $sql = " SELECT * FROM ".$tbl_global_agenda." WHERE start_date>='".$start_filter."' AND start_date<='".$end_filter."' AND access_url_id = $current_access_url_id ";
  4172. }
  4173. // 3. creating the SQL statement for getting the personal agenda items in DAY view
  4174. if ($type == "day_view") { // we are in day view
  4175. // we could use mysql date() function but this is only available from 4.1 and higher
  4176. $start_filter = $year."-".$month."-".$day." 00:00:00";
  4177. $start_filter = api_get_utc_datetime($start_filter);
  4178. $end_filter = $year."-".$month."-".$day." 23:59:59";
  4179. $end_filter = api_get_utc_datetime($end_filter);
  4180. $sql = " SELECT * FROM ".$tbl_global_agenda." WHERE start_date>='".$start_filter."' AND start_date<='".$end_filter."' AND access_url_id = $current_access_url_id";
  4181. }
  4182. $result = Database::query($sql);
  4183. while ($item = Database::fetch_array($result)) {
  4184. if ($item['start_date'] != '0000-00-00 00:00:00') {
  4185. $item['start_date'] = api_get_local_time($item['start_date']);
  4186. $item['start_date_tms'] = api_strtotime($item['start_date']);
  4187. }
  4188. if ($item['end_date'] != '0000-00-00 00:00:00') {
  4189. $item['end_date'] = api_get_local_time($item['end_date']);
  4190. }
  4191. // we break the date field in the database into a date and a time part
  4192. $agenda_db_date = explode(" ", $item['start_date']);
  4193. $date = $agenda_db_date[0];
  4194. $time = $agenda_db_date[1];
  4195. // we divide the date part into a day, a month and a year
  4196. $agendadate = explode("-", $date);
  4197. $year = intval($agendadate[0]);
  4198. $month = intval($agendadate[1]);
  4199. $day = intval($agendadate[2]);
  4200. // we divide the time part into hour, minutes, seconds
  4201. $agendatime = explode(":", $time);
  4202. $hour = $agendatime[0];
  4203. $minute = $agendatime[1];
  4204. $second = $agendatime[2];
  4205. if ($type == 'month_view') {
  4206. $item['calendar_type'] = 'global';
  4207. $agendaitems[$day][] = $item;
  4208. continue;
  4209. }
  4210. $start_time = api_format_date($item['start_date'], TIME_NO_SEC_FORMAT);
  4211. $end_time = '';
  4212. if ($item['end_date'] != '0000-00-00 00:00:00') {
  4213. $end_time = ' - '.api_format_date($item['end_date'], DATE_TIME_FORMAT_LONG);
  4214. }
  4215. // if the student has specified a course we a add a link to that course
  4216. if ($item['course'] <> "") {
  4217. $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
  4218. $course_link = "<a href=\"$url\" title=\"".$item['course']."\">".$item['course']."</a>";
  4219. } else {
  4220. $course_link = "";
  4221. }
  4222. // Creating the array that will be returned. If we have week or month view we have an array with the date as the key
  4223. // if we have a day_view we use a half hour as index => key 33 = 16h30
  4224. if ($type !== "day_view") {
  4225. // This is the array construction for the WEEK or MONTH view
  4226. //Display the Agenda global in the tab agenda (administrator)
  4227. $agendaitems[$day] .= "<i>$start_time $end_time</i>&nbsp;-&nbsp;";
  4228. $agendaitems[$day] .= "<b>".get_lang('GlobalEvent')."</b>";
  4229. $agendaitems[$day] .= "<div>".$item['title']."</div><br>";
  4230. } else {
  4231. // this is the array construction for the DAY view
  4232. $halfhour = 2 * $agendatime['0'];
  4233. if ($agendatime['1'] >= '30') {
  4234. $halfhour = $halfhour + 1;
  4235. }
  4236. if (!is_array($agendaitems[$halfhour]))
  4237. $content = $agendaitems[$halfhour];
  4238. $agendaitems[$halfhour] = $content."<div><i>$hour:$minute</i> <b>".get_lang('GlobalEvent').": </b>".$item['title']."</div>";
  4239. }
  4240. }
  4241. return $agendaitems;
  4242. }
  4243. function display_ical_import_form()
  4244. {
  4245. $form = new FormValidator('frm_import_ical', 'post', api_get_self().'?action='.Security::remove_XSS($_GET['action']), array('enctype' => 'multipart/form-data'));
  4246. $form->addElement('header', get_lang('ICalFileImport'));
  4247. $form->addElement('file', 'ical_import', get_lang('ICalFileImport'));
  4248. $form->addRule('ical_import', get_lang('ThisFieldIsRequired'), 'required');
  4249. $form->addElement('button', 'ical_submit', get_lang('Import'));
  4250. $form->display();
  4251. }