calendar.lib.php 120 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034
  1. <?php // $id: $
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * @package chamilo.admin
  5. * @author Carlos Vargas
  6. * This file is the calendar/agenda.inc.php
  7. *
  8. * @todo This file should not exist since it redeclares many of the functions in calendar/agenda.inc.php thanks cvargas!!! : jmontoya
  9. */
  10. /*
  11. Constants and variables
  12. */
  13. // the variables for the days and the months
  14. // Defining the shorts for the days
  15. $DaysShort = api_get_week_days_short();
  16. // Defining the days of the week to allow translation of the days
  17. $DaysLong = api_get_week_days_long();
  18. // Defining the months of the year to allow translation of the months
  19. $MonthsLong = api_get_months_long();
  20. /*
  21. FUNCTIONS
  22. */
  23. /**
  24. * Retrieves all the agenda items from the table
  25. * @author: Patrick Cool <patrick.cool@UGent.be>, Ghent University
  26. * @author Yannick Warnier <yannick.warnier@dokeos.com> - cleanup
  27. * @param integer $month: the integer value of the month we are viewing
  28. * @param integer $year: the 4-digit year indication e.g. 2005
  29. * @return array
  30. */
  31. /**
  32. * show the mini calender of the given month
  33. * @author: Patrick Cool <patrick.cool@UGent.be>, Ghent University
  34. * @param array an array containing all the agenda items for the given month
  35. * @param integer $month: the integer value of the month we are viewing
  36. * @param integer $year: the 4-digit year indication e.g. 2005
  37. * @param string $monthName: the language variable for the mont name
  38. * @return html code
  39. * @todo refactor this so that $monthName is no longer needed as a parameter
  40. */
  41. function display_minimonthcalendar($agendaitems, $month, $year, $monthName) {
  42. global $DaysShort;
  43. //Handle leap year
  44. $numberofdays = array (0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
  45. if (($year % 400 == 0) or ($year % 4 == 0 and $year % 100 <> 0))
  46. $numberofdays[2] = 29;
  47. //Get the first day of the month
  48. $dayone = getdate(mktime(0, 0, 0, $month, 1, $year));
  49. //Start the week on monday
  50. $startdayofweek = $dayone['wday'] <> 0 ? ($dayone['wday'] - 1) : 6;
  51. $backwardsURL = api_get_self()."?".api_get_cidreq()."&amp;coursePath=".(empty($_GET['coursePath'])?'':$_GET['coursePath'])."&amp;courseCode=".(empty($_GET['courseCode'])?'':$_GET['courseCode'])."&amp;month=". ($month == 1 ? 12 : $month -1)."&amp;year=". ($month == 1 ? $year -1 : $year);
  52. $forewardsURL = api_get_self()."?".api_get_cidreq()."&amp;coursePath=".(empty($_GET['coursePath'])?'':$_GET['coursePath'])."&amp;courseCode=".(empty($_GET['courseCode'])?'':$_GET['courseCode'])."&amp;month=". ($month == 12 ? 1 : $month +1)."&amp;year=". ($month == 12 ? $year +1 : $year);
  53. echo "<table class=\"data_table\">",
  54. "<tr>",
  55. "<th width=\"10%\"><a href=\"", $backwardsURL, "\"> ".Display::return_icon('action_prev.png',get_lang('Previous'))." </a></th>",
  56. "<th width=\"80%\" colspan=\"5\">", $monthName, " ", $year, "</th>",
  57. "<th width=\"10%\"><a href=\"", $forewardsURL, "\"> ".Display::return_icon('action_next.png',get_lang('Next'))."</a></th>", "</tr>";
  58. echo "<tr>";
  59. for ($ii = 1; $ii < 8; $ii ++)
  60. {
  61. echo "<td class=\"weekdays\">", $DaysShort[$ii % 7], "</td>";
  62. }
  63. echo "</tr>";
  64. $curday = -1;
  65. $today = getdate();
  66. while ($curday <= $numberofdays[$month])
  67. {
  68. echo "<tr>";
  69. for ($ii = 0; $ii < 7; $ii ++)
  70. {
  71. if (($curday == -1) && ($ii == $startdayofweek))
  72. {
  73. $curday = 1;
  74. }
  75. if (($curday > 0) && ($curday <= $numberofdays[$month]))
  76. {
  77. $bgcolor = $ii < 5 ? $class="class=\"days_week\"" : $class="class=\"days_weekend\"";
  78. $dayheader = "$curday";
  79. if (($curday == $today['mday']) && ($year == $today['year']) && ($month == $today['mon']))
  80. {
  81. $dayheader = "$curday";
  82. $class = "class=\"days_today\"";
  83. }
  84. echo "<td ".$class.">";
  85. if (!empty($agendaitems[$curday]))
  86. {
  87. echo "<a href=\"".api_get_self()."?".api_get_cidreq()."&amp;action=view&amp;view=day&amp;day=".$curday."&amp;month=".$month."&amp;year=".$year."\">".$dayheader."</a>";
  88. }
  89. else
  90. {
  91. echo $dayheader;
  92. }
  93. // "a".$dayheader." <span class=\"agendaitem\">".$agendaitems[$curday]."</span>";
  94. echo "</td>";
  95. $curday ++;
  96. }
  97. else
  98. {
  99. echo "<td>&nbsp;</td>";
  100. }
  101. }
  102. echo "</tr>";
  103. }
  104. echo "</table>";
  105. }
  106. /**
  107. * show the calender of the given month
  108. * @author: Patrick Cool <patrick.cool@UGent.be>, Ghent University
  109. * @param integer $month: the integer value of the month we are viewing
  110. * @param integer $year: the 4-digit year indication e.g. 2005
  111. * @return html code
  112. */
  113. /**
  114. * returns all the javascript that is required for easily selecting the target people/groups this goes into the $htmlHeadXtra[] array
  115. * @author: Patrick Cool <patrick.cool@UGent.be>, Ghent University
  116. * @return javascript code
  117. */
  118. function to_javascript() {
  119. $Send2All=get_lang("Send2All");
  120. return "<script type=\"text/javascript\" language=\"JavaScript\">
  121. <!-- Begin javascript menu swapper
  122. function move(fbox, tbox)
  123. {
  124. var arrFbox = new Array();
  125. var arrTbox = new Array();
  126. var arrLookup = new Array();
  127. var i;
  128. for (i = 0; i < tbox.options.length; i++)
  129. {
  130. arrLookup[tbox.options[i].text] = tbox.options[i].value;
  131. arrTbox[i] = tbox.options[i].text;
  132. }
  133. var fLength = 0;
  134. var tLength = arrTbox.length;
  135. for(i = 0; i < fbox.options.length; i++)
  136. {
  137. arrLookup[fbox.options[i].text] = fbox.options[i].value;
  138. if (fbox.options[i].selected && fbox.options[i].value != \"\")
  139. {
  140. arrTbox[tLength] = fbox.options[i].text;
  141. tLength++;
  142. }
  143. else
  144. {
  145. arrFbox[fLength] = fbox.options[i].text;
  146. fLength++;
  147. }
  148. }
  149. arrFbox.sort();
  150. arrTbox.sort();
  151. fbox.length = 0;
  152. tbox.length = 0;
  153. var c;
  154. for(c = 0; c < arrFbox.length; c++)
  155. {
  156. var no = new Option();
  157. no.value = arrLookup[arrFbox[c]];
  158. no.text = arrFbox[c];
  159. fbox[c] = no;
  160. }
  161. for(c = 0; c < arrTbox.length; c++)
  162. {
  163. var no = new Option();
  164. no.value = arrLookup[arrTbox[c]];
  165. no.text = arrTbox[c];
  166. tbox[c] = no;
  167. }
  168. }
  169. function checkDate(month, day, year)
  170. {
  171. var monthLength =
  172. new Array(31,28,31,30,31,30,31,31,30,31,30,31);
  173. if (!day || !month || !year)
  174. return false;
  175. // check for bisestile year
  176. if (year/4 == parseInt(year/4))
  177. monthLength[1] = 29;
  178. if (month < 1 || month > 12)
  179. return false;
  180. if (day > monthLength[month-1])
  181. return false;
  182. return true;
  183. }
  184. function mktime()
  185. {
  186. var no, ma = 0, mb = 0, i = 0, d = new Date(), argv = arguments, argc = argv.length;
  187. d.setHours(0,0,0); d.setDate(1); d.setMonth(1); d.setYear(1972);
  188. var dateManip = {
  189. 0: function(tt){ return d.setHours(tt); },
  190. 1: function(tt){ return d.setMinutes(tt); },
  191. 2: function(tt){ set = d.setSeconds(tt); mb = d.getDate() - 1; return set; },
  192. 3: function(tt){ set = d.setMonth(parseInt(tt)-1); ma = d.getFullYear() - 1972; return set; },
  193. 4: function(tt){ return d.setDate(tt+mb); },
  194. 5: function(tt){ return d.setYear(tt+ma); }
  195. };
  196. for( i = 0; i < argc; i++ ){
  197. no = parseInt(argv[i]*1);
  198. if (isNaN(no)) {
  199. return false;
  200. } else {
  201. // arg is number, lets manipulate date object
  202. if(!dateManip[i](no)){
  203. // failed
  204. return false;
  205. }
  206. }
  207. }
  208. return Math.floor(d.getTime()/1000);
  209. }
  210. function validate()
  211. {
  212. var f = document.new_calendar_item;
  213. f.submit();
  214. return true;
  215. }
  216. function validate_date()
  217. {
  218. var start_day = document.new_calendar_item.fday.value;
  219. var start_month = document.new_calendar_item.fmonth.value;
  220. var start_year = document.new_calendar_item.fyear.value;
  221. var start_hour = document.new_calendar_item.fhour.value;
  222. var start_minute = document.new_calendar_item.fminute.value;
  223. var start_date = mktime(start_hour,start_minute,0,start_month,start_day,start_year)
  224. var ends_day = document.new_calendar_item.end_fday.value;
  225. var ends_month = document.new_calendar_item.end_fmonth.value;
  226. var ends_year = document.new_calendar_item.end_fyear.value;
  227. var ends_hour = document.new_calendar_item.end_fhour.value;
  228. var ends_minute = document.new_calendar_item.end_fminute.value;
  229. var ends_date = mktime(ends_hour,ends_minute,0,ends_month,ends_day,ends_year)
  230. msg_err1 = document.getElementById(\"err_date\");
  231. msg_err2 = document.getElementById(\"err_start_date\");
  232. msg_err3 = document.getElementById(\"err_end_date\");
  233. msg_err4 = document.getElementById(\"err_title\");
  234. if (start_date > ends_date) {
  235. msg_err1.style.display =\"block\";
  236. msg_err1.innerHTML=\"".get_lang('EndDateCannotBeBeforeTheStartDate')."\";
  237. msg_err2.innerHTML=\"\";msg_err3.innerHTML=\"\";
  238. } else if (!checkDate(start_month,start_day,start_year)) {
  239. msg_err2.style.display =\"block\";
  240. msg_err2.innerHTML=\"".get_lang('InvalidDate')."\";
  241. msg_err1.innerHTML=\"\";msg_err3.innerHTML=\"\";
  242. } else if (!checkDate(ends_month,ends_day,ends_year)) {
  243. msg_err3.style.display =\"block\";
  244. msg_err3.innerHTML=\"".get_lang('InvalidDate')."\";
  245. msg_err1.innerHTML=\"\";msg_err2.innerHTML=\"\";
  246. } else if (document.new_calendar_item.title.value == '') {
  247. msg_err4.style.display =\"block\";
  248. msg_err4.innerHTML=\"".get_lang('FieldRequired')."\";
  249. msg_err1.innerHTML=\"\";msg_err2.innerHTML=\"\";msg_err3.innerHTML=\"\";
  250. } else {
  251. document.new_calendar_item.submit();
  252. }
  253. }
  254. // End -->
  255. </script>";
  256. }
  257. /**
  258. * returns the javascript for setting a filter. This is a jump menu
  259. * @author: Patrick Cool <patrick.cool@UGent.be>, Ghent University
  260. * @return javascript code
  261. */
  262. function user_group_filter_javascript() {
  263. return "<script language=\"JavaScript\" type=\"text/JavaScript\">
  264. <!--
  265. function MM_jumpMenu(targ,selObj,restore){
  266. eval(targ+\".location='\"+selObj.options[selObj.selectedIndex].value+\"'\");
  267. if (restore) selObj.selectedIndex=0;
  268. }
  269. //-->
  270. </script>
  271. ";
  272. }
  273. function display_monthcalendar($month, $year) {
  274. global $MonthsLong;
  275. global $DaysShort;
  276. global $origin;
  277. // grabbing all the calendar items for this year and storing it in a array
  278. $data=get_calendar_items($month,$year);
  279. //Handle leap year
  280. $numberofdays = array(0,31,28,31,30,31,30,31,31,30,31,30,31);
  281. if (($year%400 == 0) or ($year%4==0 and $year%100<>0)) $numberofdays[2] = 29;
  282. //Get the first day of the month
  283. $dayone = getdate(mktime(0,0,0,$month,1,$year));
  284. //Start the week on monday
  285. $startdayofweek = $dayone['wday']<>0 ? ($dayone['wday']-1) : 6;
  286. $backwardsURL = api_get_self()."?".api_get_cidreq()."&amp;origin=$origin&amp;month=".($month==1 ? 12 : $month-1)."&amp;year=".($month==1 ? $year-1 : $year);
  287. $forewardsURL = api_get_self()."?".api_get_cidreq()."&amp;origin=$origin&amp;month=".($month==12 ? 1 : $month+1)."&amp;year=".($month==12 ? $year+1 : $year);
  288. $maand_array_maandnummer=$month-1;
  289. echo "<table class=\"data_table\">",
  290. "<tr>",
  291. "<th width=\"10%\"><a href=\"",$backwardsURL,"\"> ".Display::return_icon('action_prev.png',get_lang('Previous'))."</a></th>",
  292. "<th width=\"80%\" colspan=\"5\">",$MonthsLong[$maand_array_maandnummer]," ",$year,"</th>",
  293. "<th width=\"10%\"><a href=\"",$forewardsURL,"\"> ".Display::return_icon('action_next.png',get_lang('Next'))."</a></th>",
  294. "</tr>";
  295. echo "<tr>";
  296. for ($ii=1;$ii<8; $ii++) {
  297. echo "<td class=\"weekdays\" width=\"14%\">",$DaysShort[$ii%7],"</td>";
  298. }
  299. echo "</tr>";
  300. $curday = -1;
  301. $today = getdate();
  302. while ($curday <=$numberofdays[$month]) {
  303. echo "<tr>";
  304. for ($ii=0; $ii<7; $ii++) {
  305. if (($curday == -1)&&($ii==$startdayofweek)) {
  306. $curday = 1;
  307. }
  308. if (($curday>0)&&($curday<=$numberofdays[$month])) {
  309. $bgcolor = $ii<5 ? "class=\"row_odd\"" : "class=\"row_even\"";
  310. $dayheader = "$curday";
  311. if (key_exists($curday,$data)) {
  312. $dayheader="<a href='".api_get_self()."?".api_get_cidreq()."&amp;view=list&amp;origin=$origin&amp;month=$month&amp;year=$year&amp;day=$curday#$curday'>".$curday."</a>";
  313. foreach ($data[$curday] as $key=>$agenda_item) {
  314. foreach ($agenda_item as $key=>$value) {
  315. $start_time = api_convert_and_format_date($value['start_date'], TIME_NO_SEC_FORMAT);
  316. $end_time = api_convert_and_format_date($value['end_date'], TIME_NO_SEC_FORMAT);
  317. $dayheader .= '<br /><b>'.$start_time.' - '.$end_time.'</b>';
  318. $dayheader .= ' - ';
  319. $dayheader .= $value['title'];
  320. }
  321. }
  322. }
  323. if (($curday==$today['mday'])&&($year ==$today['year'])&&($month == $today['mon'])) {
  324. echo "<td id=\"today\" ",$bgcolor,"\">".$dayheader." ";
  325. } else {
  326. echo "<td id=\"days\" ",$bgcolor,"\">".$dayheader." ";
  327. }
  328. echo "</td>";
  329. $curday++;
  330. } else {
  331. echo "<td>&nbsp;</td>";
  332. }
  333. }
  334. echo "</tr>";
  335. }
  336. echo "</table>";
  337. }
  338. /**
  339. * this function shows the form with the user that were not selected
  340. * @author: Patrick Cool <patrick.cool@UGent.be>, Ghent University
  341. * @return html code
  342. */
  343. /**
  344. * This function stores the Agenda Item in the table calendar_event and updates the item_property table also
  345. * @author: Patrick Cool <patrick.cool@UGent.be>, Ghent University
  346. * @return integer the id of the last added agenda item
  347. */
  348. function store_new_agenda_item() {
  349. $TABLEAGENDA = Database::get_main_table(TABLE_MAIN_SYSTEM_CALENDAR);
  350. //$t_agenda_repeat = Database::get_course_Table(TABLE_AGENDA_REPEAT);
  351. // some filtering of the input data
  352. $title=strip_tags(trim($_POST['title'])); // no html allowed in the title
  353. $content=trim($_POST['content']);
  354. $start_date=(int)$_POST['fyear']."-".(int)$_POST['fmonth']."-".(int)$_POST['fday']." ".(int)$_POST['fhour'].":".(int)$_POST['fminute'].":00";
  355. $end_date=(int)$_POST['end_fyear']."-".(int)$_POST['end_fmonth']."-".(int)$_POST['end_fday']." ".(int)$_POST['end_fhour'].":".(int)$_POST['end_fminute'].":00";
  356. // store in the table calendar_event
  357. $sql = "INSERT INTO ".$TABLEAGENDA." (title,content, start_date, end_date)
  358. VALUES ('".$title."','".$content."', '".$start_date."','".$end_date."')";
  359. $result = Database::query($sql) or die (Database::error());
  360. $last_id=Database::insert_id();
  361. // store in last_tooledit (first the groups, then the users
  362. $to=$_POST['selectedform'];
  363. /* if ((!is_null($to))or (!empty($_SESSION['toolgroup']))) // !is_null($to): when no user is selected we send it to everyone
  364. {
  365. $send_to=separate_users_groups($to);
  366. // storing the selected groups
  367. if (is_array($send_to['groups']))
  368. {
  369. foreach ($send_to['groups'] as $group)
  370. {
  371. api_item_property_update($_course, TOOL_CALENDAR_EVENT, $last_id,"AgendaAdded", $_user['user_id'], $group,'',$start_date, $end_date);
  372. }
  373. }
  374. // storing the selected users
  375. if (is_array($send_to['users']))
  376. {
  377. foreach ($send_to['users'] as $user)
  378. {
  379. api_item_property_update($_course, TOOL_CALENDAR_EVENT, $last_id,"AgendaAdded", $_user['user_id'],'',$user, $start_date,$end_date);
  380. }
  381. }
  382. }
  383. else // the message is sent to everyone, so we set the group to 0
  384. {
  385. api_item_property_update($_course, TOOL_CALENDAR_EVENT, $last_id,"AgendaAdded", $_user['user_id'], '','',$start_date,$end_date);
  386. }*/
  387. // storing the resources
  388. //store_resources($_SESSION['source_type'],$last_id);
  389. //if repetitive, insert element into agenda_repeat table
  390. /* if(!empty($_POST['repeat']) && !empty($_POST['repeat_type']))
  391. {
  392. if(!empty($_POST['repeat_end_year']) && !empty($_POST['repeat_end_month']) && !empty($_POST['repeat_end_day']))
  393. {
  394. $end_y = intval($_POST['repeat_end_year']);
  395. $end_m = intval($_POST['repeat_end_month']);
  396. $end_d = intval($_POST['repeat_end_day']);
  397. $end = mktime((int)$_POST['fhour'],(int)$_POST['fminute'],0,$end_m,$end_d,$end_y);
  398. $now = time();
  399. $type = Database::escape_string($_POST['repeat_type']);
  400. if($end > $now
  401. && in_array($type,array('daily','weekly','monthlyByDate','monthlyByDay','monthlyByDayR','yearly')))
  402. {
  403. $sql = "INSERT INTO $t_agenda_repeat (cal_id, cal_type, cal_end)" .
  404. " VALUES ($last_id,'$type',$end)";
  405. $res = Database::query($sql);
  406. }
  407. }
  408. }
  409. return $last_id;*/
  410. return $last_id;
  411. }
  412. /**
  413. * The links that allows the student AND course administrator to show all agenda items and sort up/down
  414. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  415. */
  416. function display_courseadmin_links() {
  417. echo "<a href='".api_get_self()."?".api_get_cidreq()."&action=add&amp;origin=".Security::remove_XSS($_GET['origin'])."'>".Display::return_icon('new_platform_event.png', get_lang('AgendaAdd'),'','32')."</a>";
  418. }
  419. function display_student_links() {
  420. if ($_SESSION['view'] <> 'month') {
  421. echo '<a href="'.api_get_self().'?action=view&amp;view=month">'.
  422. Display::return_icon('month_empty.png',get_lang('MonthView'),'','32').'</a>';
  423. if ($_SESSION['sort'] == 'DESC') {
  424. echo '<a href="'.api_get_self().'?sort=asc&amp;origin='.Security::remove_XSS($_GET['origin']).'">'.Display::return_icon('calendar_normal.png',get_lang('AgendaSortChronologicallyUp'),'','32').'</a>';
  425. } else {
  426. //echo '<a href="'.api_get_self().'?sort=desc&amp;origin='.Security::remove_XSS($_GET['origin']).'"> '.Display::return_icon('calendar_inverse.png',get_lang('AgendaSortChronologicallyDown'),'','32').'</a>';
  427. }
  428. } else {
  429. echo '<a href="'.api_get_self().'?action=view&amp;view=list">'.Display::return_icon('week.png', get_lang('ListView'),'','32').'</a>';
  430. }
  431. }
  432. /**
  433. * get all the information of the agenda_item from the database
  434. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  435. * @param integer the id of the agenda item we are getting all the information of
  436. * @return an associative array that contains all the information of the agenda item. The keys are the database fields
  437. */
  438. function get_agenda_item($id) {
  439. $TABLEAGENDA = Database::get_main_table(TABLE_MAIN_SYSTEM_CALENDAR);
  440. //$t_agenda_repeat = Database::get_course_table(TABLE_AGENDA_REPEAT);
  441. $item = array();
  442. if(empty($id)) {
  443. $id=intval($_GET['id']);
  444. } else {
  445. $id = intval($id);
  446. }
  447. if(empty($id)){return $item;}
  448. $sql = "SELECT * FROM ".$TABLEAGENDA." WHERE id='".$id."'";
  449. $result = Database::query($sql);
  450. $entry_to_edit = Database::fetch_array($result);
  451. $item['title'] = $entry_to_edit["title"];
  452. $item['content'] = $entry_to_edit["content"];
  453. $item['start_date'] = $entry_to_edit["start_date"];
  454. $item['end_date'] = $entry_to_edit["end_date"];
  455. $item['to'] == "everyone";
  456. // if the item has been sent to everybody then we show the compact to form
  457. if ($item['to']=="everyone") {
  458. $_SESSION['allow_individual_calendar']="hide";
  459. } else {
  460. $_SESSION['allow_individual_calendar']="show";
  461. }
  462. return $item;
  463. }
  464. /**
  465. * This is the function that updates an agenda item. It does 3 things
  466. * 1. storethe start_date, end_date, title and message in the calendar_event table
  467. * 2. store the groups/users who this message is meant for in the item_property table
  468. * 3. modify the attachments (if needed)
  469. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  470. */
  471. function store_edited_agenda_item() {
  472. // STEP 1: editing the calendar_event table
  473. // 1.a. some filtering of the input data
  474. $id=(int)$_POST['id'];
  475. $title=strip_tags(trim($_POST['title'])); // no html allowed in the title
  476. $content=trim($_POST['content']);
  477. $start_date=(int)$_POST['fyear']."-".(int)$_POST['fmonth']."-".(int)$_POST['fday']." ".(int)$_POST['fhour'].":".(int)$_POST['fminute'].":00";
  478. $end_date=(int)$_POST['end_fyear']."-".(int)$_POST['end_fmonth']."-".(int)$_POST['end_fday']." ".(int)$_POST['end_fhour'].":".(int)$_POST['end_fminute'].":00";
  479. $to=$_POST['selectedform'];
  480. // 1.b. the actual saving in calendar_event table
  481. $edit_result=save_edit_agenda_item($id,$title,$content,$start_date,$end_date);
  482. echo '<br />';
  483. Display::display_normal_message(get_lang("EditSuccess"));
  484. }
  485. /**
  486. * This function stores the Agenda Item in the table calendar_event and updates the item_property table also (after an edit)
  487. * @author: Patrick Cool <patrick.cool@UGent.be>, Ghent University
  488. */
  489. function save_edit_agenda_item($id, $title, $content, $start_date, $end_date) {
  490. $TABLEAGENDA = Database::get_main_table(TABLE_MAIN_SYSTEM_CALENDAR);
  491. $id=Database::escape_string($id);
  492. $title=Database::escape_string($title);
  493. $content=Database::escape_string($content);
  494. $start_date = api_get_utc_datetime($start_date);
  495. $start_date = Database::escape_string($start_date);
  496. $end_date = api_get_utc_datetime($end_date);
  497. $end_date = Database::escape_string($end_date);
  498. // store the modifications in the table calendar_event
  499. $sql = "UPDATE ".$TABLEAGENDA."
  500. SET title='".$title."',
  501. content='".$content."',
  502. start_date='".$start_date."',
  503. end_date='".$end_date."'
  504. WHERE id='".$id."'";
  505. $result = Database::query($sql) or die (Database::error());
  506. return true;
  507. }
  508. /**
  509. * This is the function that deletes an agenda item.
  510. * The agenda item is no longer fycically deleted but the visibility in the item_property table is set to 2
  511. * which means that it is invisible for the student AND course admin. Only the platform administrator can see it.
  512. * This will in a later stage allow the platform administrator to recover resources that were mistakenly deleted
  513. * by the course administrator
  514. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  515. * @param integer the id of the agenda item wa are deleting
  516. * @return bool true if it's success or false otherwise
  517. */
  518. function delete_agenda_item($id)
  519. {
  520. global $_course;
  521. $t_agenda = Database::get_main_table(TABLE_MAIN_SYSTEM_CALENDAR);
  522. $id = intval($id);
  523. $sql = "SELECT * FROM $t_agenda WHERE id = '$id'";
  524. $res = Database::query($sql);
  525. if(Database::num_rows($res) > 0)
  526. {
  527. $sql = "DELETE FROM ".$t_agenda." WHERE id='$id'";
  528. $result = Database::query($sql) or die (Database::error());
  529. api_item_property_update($_course,TOOL_CALENDAR_EVENT,$id,'delete',api_get_user_id());
  530. return true;
  531. }
  532. return false;
  533. }
  534. /**
  535. * Makes an agenda item visible or invisible for a student
  536. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  537. * @param integer id the id of the agenda item we are changing the visibility of
  538. */
  539. function showhide_agenda_item($id) {
  540. global $nameTools;
  541. /*==================================================
  542. SHOW / HIDE A CALENDAR ITEM
  543. ==================================================*/
  544. // and $_GET['isStudentView']<>"false" is added to prevent that the visibility is changed after you do the following:
  545. // change visibility -> studentview -> course manager view
  546. if ((api_is_allowed_to_edit() && !api_is_anonymous()) and $_GET['isStudentView']<>"false")
  547. {
  548. if (isset($_GET['id'])&&$_GET['id']&&isset($_GET['action'])&&$_GET['action']=="showhide")
  549. {
  550. $id=(int)addslashes($_GET['id']);
  551. change_visibility($nameTools,$id);
  552. Display::display_normal_message(get_lang("VisibilityChanged"));
  553. }
  554. }
  555. }
  556. /**
  557. * Displays all the agenda items
  558. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  559. * @author Yannick Warnier <yannick.warnier@dokeos.com> - cleanup
  560. */
  561. function display_agenda_items() {
  562. global $select_month, $select_year;
  563. global $DaysShort, $DaysLong, $MonthsLong;
  564. global $is_courseAdmin;
  565. global $dateFormatLong, $timeNoSecFormat,$charset, $_user, $_course;
  566. $TABLEAGENDA = Database::get_main_table(TABLE_MAIN_SYSTEM_CALENDAR);
  567. // getting the group memberships
  568. //$group_memberships=GroupManager::get_group_ids($_course['dbName'],$_user['user_id']);
  569. // getting the name of the groups
  570. //$group_names=get_course_groups();
  571. /*--------------------------------------------------
  572. CONSTRUCT THE SQL STATEMENT
  573. --------------------------------------------------*/
  574. $start = 0;
  575. $stop = 0;
  576. // this is to make a difference between showing everything (all months) or only the current month)
  577. // $show_all_current is a part of the sql statement
  578. if ($_SESSION['show_all_admin']!=="showall")
  579. {
  580. $show_all_current=" AND MONTH(start_date)=$select_month AND year(start_date)=$select_year";
  581. $start = mktime(0,0,0,$select_month,1,$select_year);
  582. $stop = 0;
  583. if(empty($select_year)){$select_year = date('Y');}
  584. if(empty($select_month)){$select_month = date('m');}
  585. if($select_month==12)
  586. {
  587. $stop = mktime(0,0,0,1,1,$select_year+1)-1;
  588. }
  589. else
  590. {
  591. $stop = mktime(0,0,0,$select_month+1,1,$select_year)-1;
  592. }
  593. }
  594. else
  595. {
  596. $show_all_current="";
  597. $start = time();
  598. $stop = mktime(0,0,0,1,1,2038);//by default, set year to maximum for mktime()
  599. }
  600. // 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
  601. $repeats = array(); //placeholder for repeated events
  602. if (api_is_allowed_to_edit() && !api_is_anonymous()) {
  603. $sql="SELECT * FROM ".$TABLEAGENDA;
  604. global $_configuration;
  605. $current_access_url_id = 1;
  606. if ($_configuration['multiple_access_urls']) {
  607. $current_access_url_id = api_get_current_access_url_id();
  608. }
  609. $sql .= " WHERE access_url_id = $current_access_url_id";
  610. $sql .= ' ORDER BY start_date '.$_SESSION['sort'];
  611. //echo "<pre>".$sql."</pre>";
  612. $result=Database::query($sql) or die(Database::error());
  613. $number_items=Database::num_rows($result);
  614. } else {
  615. $number_items = 0;
  616. }
  617. /*--------------------------------------------------
  618. DISPLAY: NO ITEMS
  619. --------------------------------------------------*/
  620. if ($number_items==0)
  621. {
  622. echo "<table class=\"data_table\" ><tr><td>".get_lang("NoAgendaItems")."</td></tr></table>";
  623. }
  624. /*--------------------------------------------------
  625. DISPLAY: THE ITEMS
  626. --------------------------------------------------*/
  627. $month_bar="";
  628. $event_list="";
  629. $counter=0;
  630. $export_icon = 'export.png';
  631. $export_icon_low = 'export_low_fade.png';
  632. $export_icon_high = 'export_high_fade.png';
  633. while($myrow=Database::fetch_array($result)) {
  634. $is_repeated = !empty($myrow['parent_event_id']);
  635. echo '<table class="data_table">';
  636. $myrow["start_date"] = api_get_local_time($myrow["start_date"]);
  637. if ($month_bar != api_format_date($myrow["start_date"], "%m%Y")) {
  638. $month_bar = api_format_date($myrow["start_date"], "%m%Y");
  639. echo "<tr><td class=\"agenda_month_divider\" colspan=\"3\" valign=\"top\">".
  640. api_format_date($myrow["start_date"], "%B %Y").
  641. "</td></tr>";
  642. }
  643. /*--------------------------------------------------
  644. display: the icon, title, destinees of the item
  645. -------------------------------------------------*/
  646. echo '<tr>';
  647. // highlight: if a date in the small calendar is clicked we highlight the relevant items
  648. $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");
  649. if ($_GET["day"].$_GET["month"].$_GET["year"] <>$db_date) {
  650. if ($myrow['visibility']=='0') {
  651. $style="data_hidden";
  652. $stylenotbold="datanotbold_hidden";
  653. $text_style="text_hidden";
  654. } else {
  655. $style="data";
  656. $stylenotbold="datanotbold";
  657. $text_style="text";
  658. }
  659. } else {
  660. $style="datanow";
  661. $stylenotbold="datanotboldnow";
  662. $text_style="textnow";
  663. }
  664. echo "<th>";
  665. // adding an internal anchor
  666. echo "<a name=\"".(int)date("d",strtotime($myrow["start_date"]))."\"></a>";
  667. // the icons. If the message is sent to one or more specific users/groups
  668. // we add the groups icon
  669. // 2do: if it is sent to groups we display the group icon, if it is sent to a user we show the user icon
  670. Display::display_icon('platform_event.png', get_lang('GlobalEvent'),'','22');
  671. /*if ($myrow['to_group_id']!=='0') {
  672. echo Display::return_icon('group.gif', get_lang('AllUsersOfThePlatform'));
  673. }*/
  674. echo " ".$myrow['title']."";
  675. echo "</th>";
  676. // the message has been sent to
  677. echo "<th>".get_lang("SentTo").": ".get_lang('AllUsersOfThePlatform');
  678. //$sent_to=sent_to(TOOL_CALENDAR_EVENT, $myrow["ref"]);
  679. //$sent_to_form=sent_to_form($sent_to);
  680. // echo $sent_to_form;
  681. echo "</th>";
  682. if (!$is_repeated && (api_is_allowed_to_edit(false,true) OR (api_get_course_setting('allow_user_edit_agenda') && !api_is_anonymous()))) {
  683. if( ! (api_is_course_coach() && !api_is_element_in_the_session(TOOL_AGENDA, $myrow['id'] ) ) )
  684. { // a coach can only delete an element belonging to his session
  685. echo '<th>'.get_lang('Actions');
  686. echo '</th></tr>';
  687. }
  688. }
  689. // display: the title
  690. echo "<tr class='row_odd'>";
  691. echo "<td>".get_lang("StartTimeWindow").": ";
  692. echo api_format_date($myrow["start_date"], DATE_TIME_FORMAT_LONG);
  693. echo "</td>";
  694. echo "<td>";
  695. if ($myrow["end_date"]<>"0000-00-00 00:00:00") {
  696. $myrow["end_date"] = api_get_local_time($myrow["end_date"]);
  697. echo get_lang("EndTimeWindow").": ";
  698. echo api_format_date($myrow["end_date"], DATE_TIME_FORMAT_LONG);
  699. }
  700. echo "</td>";
  701. if (!$is_repeated && (api_is_allowed_to_edit(false,true) OR (api_get_course_setting('allow_user_edit_agenda') && !api_is_anonymous()))) {
  702. if( ! (api_is_course_coach() && !api_is_element_in_the_session(TOOL_AGENDA, $myrow['id'] ) ) )
  703. { // a coach can only delete an element belonging to his session
  704. $mylink = api_get_self().'?'.api_get_cidreq().'&amp;origin='.Security::remove_XSS($_GET['origin']).'&amp;id='.$myrow['id'];
  705. echo '<td align="center">';
  706. // edit
  707. echo '<a href="'.$mylink.'&amp;action=edit&amp;title="'.get_lang("ModifyCalendarItem").'">';
  708. echo Display::return_icon('edit.gif', get_lang('ModifyCalendarItem'))."</a>";
  709. echo "<a href=\"".$mylink."&amp;action=delete\" onclick=\"javascript:if(!confirm('".addslashes(api_htmlentities(get_lang("ConfirmYourChoice"),ENT_QUOTES,$charset))."')) return false;\" title=\"".get_lang("Delete")."\"> ";
  710. echo Display::return_icon('delete.gif', get_lang('Delete'))."</a>";
  711. }
  712. if (!$is_repeated && (api_is_allowed_to_edit(false,true) OR (api_get_course_setting('allow_user_edit_agenda') && !api_is_anonymous()))) {
  713. if( ! (api_is_course_coach() && !api_is_element_in_the_session(TOOL_AGENDA, $myrow['id'] ) ) ) {
  714. // a coach can only delete an element belonging to his session
  715. $td_colspan= '<td colspan="3">';
  716. } else {
  717. $td_colspan= '<td colspan="2">';
  718. }
  719. } else {
  720. $td_colspan= '<td colspan="2">';
  721. }
  722. $mylink = 'calendar_ical_export.php?'.api_get_cidreq().'&amp;type=course&amp;id='.$myrow['id'];
  723. echo '<a class="ical_export" href="'.$mylink.'&amp;class=confidential" title="'.get_lang('ExportiCalConfidential').'">'.Display::return_icon($export_icon_high, get_lang('ExportiCalConfidential')).'</a> ';
  724. echo '<a class="ical_export" href="'.$mylink.'&amp;class=private" title="'.get_lang('ExportiCalPrivate').'">'.Display::return_icon($export_icon_low, get_lang('ExportiCalPrivate')).'</a> ';
  725. echo '<a class="ical_export" href="'.$mylink.'&amp;class=public" title="'.get_lang('ExportiCalPublic').'">'.Display::return_icon($export_icon, get_lang('ExportiCalPublic')).'</a> ';
  726. echo '<a href="#" onclick="javascript:win_print=window.open(\'calendar_view_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('print.gif', get_lang('Print')).'</a>&nbsp;';
  727. echo '</td>';
  728. echo '</tr>';
  729. }
  730. /*--------------------------------------------------
  731. display: the content
  732. --------------------------------------------------*/
  733. $content = $myrow['content'];
  734. $content = make_clickable($content);
  735. $content = text_filter($content);
  736. echo "<tr class='row_even'>";
  737. echo "<td colspan='3'>";
  738. echo $content;
  739. // show attachment list
  740. if (!empty($attachment_list)) {
  741. $realname=$attachment_list['path'];
  742. $user_filename=$attachment_list['filename'];
  743. $full_file_name = 'download.php?file='.$realname;
  744. echo Display::return_icon('attachment.gif',get_lang('Attachment'));
  745. echo '<a href="'.$full_file_name.'';
  746. echo ' "> '.$user_filename.' </a>';
  747. echo '<span class="forum_attach_comment" >'.$attachment_list['comment'].'</span>';
  748. if (api_is_allowed_to_edit()) {
  749. echo '&nbsp;&nbsp;<a href="'.api_get_self().'?'.api_get_cidreq().'&amp;origin='.Security::remove_XSS($_GET['origin']).'&amp;action=delete_attach&amp;id_attach='.$attachment_list['id'].'" onclick="javascript:if(!confirm(\''.addslashes(api_htmlentities(get_lang("ConfirmYourChoice"),ENT_QUOTES,$charset)).'\')) return false;">'.Display::return_icon('delete.gif',get_lang('Delete')).'</a><br />';
  750. }
  751. }
  752. echo '</td></tr>';
  753. /*--------------------------------------------------
  754. display: the added resources
  755. --------------------------------------------------
  756. if (check_added_resources("Agenda", $myrow["id"]))
  757. {
  758. echo '<tr>';
  759. echo '<td colspan="3">';
  760. echo "<i>".get_lang("AddedResources")."</i><br/>";
  761. if ($myrow['visibility']==0)
  762. {
  763. $addedresource_style="invisible";
  764. }
  765. display_added_resources("Agenda", $myrow["id"], $addedresource_style);
  766. echo "</td></tr>";
  767. }*/
  768. $event_list.=$myrow['id'].',';
  769. $counter++;
  770. /*--------------------------------------------------
  771. display: jump-to-top icon
  772. --------------------------------------------------*/
  773. echo '<tr>';
  774. echo '<td colspan="3">';
  775. if($is_repeated){echo get_lang('RepeatedEvent'),'<a href="',api_get_self(),'?',api_get_cidreq,'&amp;agenda_id=',$myrow['parent_event_id'],'" alt="',get_lang('RepeatedEventViewOriginalEvent'),'">',get_lang('RepeatedEventViewOriginalEvent'),'</a>';}
  776. echo "<a href=\"#top\">".Display::return_icon('top.gif', get_lang('Top'))."</a></td></tr>";
  777. echo "</table><br /><br />";
  778. } // end while ($myrow=Database::fetch_array($result))
  779. if(!empty($event_list))
  780. {
  781. $event_list=substr($event_list,0,-1);
  782. }
  783. else
  784. {
  785. $event_list='0';
  786. }
  787. echo "<form name=\"event_list_form\"><input type=\"hidden\" name=\"event_list\" value=\"$event_list\" /></form>";
  788. // closing the layout table
  789. echo "</td>",
  790. "</tr>",
  791. "</table>";
  792. }
  793. /**
  794. * Displays only 1 agenda item. This is used when an agenda item is added to the learning path.
  795. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  796. */
  797. function display_one_agenda_item($agenda_id)
  798. {
  799. global $select_month, $select_year;
  800. global $DaysShort, $DaysLong, $MonthsLong;
  801. global $is_courseAdmin;
  802. global $dateFormatLong, $timeNoSecFormat, $charset;
  803. global $_user;
  804. $TABLEAGENDA = Database::get_main_table(TABLE_MAIN_SYSTEM_CALENDAR);
  805. $TABLE_ITEM_PROPERTY = Database::get_course_table(TABLE_ITEM_PROPERTY);
  806. $agenda_id=Database::escape_string($agenda_id);
  807. //echo "displaying agenda items";
  808. // getting the name of the groups
  809. //$group_names=get_course_groups();
  810. /*--------------------------------------------------
  811. CONSTRUCT THE SQL STATEMENT
  812. --------------------------------------------------*/
  813. $sql="SELECT * FROM ".$TABLEAGENDA;
  814. $result=Database::query($sql) or die(Database::error());
  815. $number_items=Database::num_rows($result);
  816. $myrow=Database::fetch_array($result); // there should be only one item so no need for a while loop
  817. $sql_rep = "SELECT * FROM $TABLEAGENDA WHERE id = $agenda_id";
  818. $res_rep = Database::query($sql_rep);
  819. $repeat = false;
  820. $repeat_id = 0;
  821. if(Database::num_rows($res_rep)>0)
  822. {
  823. $repeat=true;
  824. $row_rep = Database::fetch_array($res_rep);
  825. //$repeat_id = $row_rep['parent_event_id'];
  826. }
  827. /*--------------------------------------------------
  828. DISPLAY: NO ITEMS
  829. --------------------------------------------------*/
  830. if ($number_items==0)
  831. {
  832. echo "<table id=\"data_table\" ><tr><td>".get_lang("NoAgendaItems")."</td></tr></table>";
  833. }
  834. /*--------------------------------------------------
  835. DISPLAY: THE ITEMS
  836. --------------------------------------------------*/
  837. echo "<table id=\"data_table\">";
  838. /*--------------------------------------------------
  839. DISPLAY : the icon, title, destinees of the item
  840. --------------------------------------------------*/
  841. echo "<tr>";
  842. // highlight: if a date in the small calendar is clicked we highlight the relevant items
  843. $myrow["start_date"] = api_get_local_time($myrow["start_date"], null, date_default_timezone_get());
  844. $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");
  845. if ($_GET["day"].$_GET["month"].$_GET["year"] <>$db_date)
  846. {
  847. if ($myrow['visibility']=='0')
  848. {
  849. $style="data_hidden";
  850. $stylenotbold="datanotbold_hidden";
  851. $text_style="text_hidden";
  852. }
  853. else
  854. {
  855. $style="data";
  856. $stylenotbold="datanotbold";
  857. $text_style="text";
  858. }
  859. }
  860. else
  861. {
  862. $style="datanow";
  863. $stylenotbold="datanotboldnow";
  864. $text_style="textnow";
  865. }
  866. echo "<td class=\"".$style."\">";
  867. // adding an internal anchor
  868. echo "<a name=\"".(int)date("d",strtotime($myrow["start_date"]))."\"></a>";
  869. // the icons. If the message is sent to one or more specific users/groups
  870. // we add the groups icon
  871. // 2do: if it is sent to groups we display the group icon, if it is sent to a user we show the user icon
  872. echo Display::return_icon('agenda.gif');
  873. if ($myrow['to_group_id']!=='0')
  874. {
  875. echo Display::return_icon('group.gif');
  876. }
  877. echo " ".$myrow['title']."";
  878. echo "</td>";
  879. // the message has been sent to
  880. echo "<td class=\"".$stylenotbold."\">".get_lang("SentTo").": ".get_lang('AllUsersOfThePlatform');
  881. //$sent_to = sent_to(TOOL_CALENDAR_EVENT, $myrow["ref"]);
  882. //sent_to_form=sent_to_form($sent_to);
  883. //echo $sent_to_form;
  884. echo "</td></tr>";
  885. /*--------------------------------------------------
  886. DISPLAY: the title
  887. --------------------------------------------------*/
  888. echo "<tr class=\"".$stylenotbold."\">";
  889. echo "<td>".get_lang("StartTime").": ";
  890. echo api_format_date($myrow["start_date"]);
  891. echo "</td>";
  892. echo "<td>".get_lang("EndTime").": ";
  893. echo api_convert_and_format_date($myrow["end_date"], null, date_default_timezone_get());
  894. echo "</td>";
  895. echo "</tr>";
  896. /*--------------------------------------------------
  897. DISPLAY: the content
  898. --------------------------------------------------*/
  899. $export_icon = '../img/export.png';
  900. $export_icon_low = '../img/export_low_fade.png';
  901. $export_icon_high = '../img/export_high_fade.png';
  902. $content = $myrow['content'];
  903. $content = make_clickable($content);
  904. $content = text_filter($content);
  905. //echo "<tr><td class=\"".$text_style."\" colspan='2'>";
  906. //echo $content;
  907. //echo "</td></tr>";
  908. echo "<tr class='row_even'>";
  909. echo '<td colspan="2">';
  910. echo $content;
  911. echo '</td></tr>';
  912. /*--------------------------------------------------
  913. DISPLAY: the added resources
  914. --------------------------------------------------*/
  915. /*
  916. if (check_added_resources("Agenda", $myrow["id"]))
  917. {
  918. echo "<tr><td colspan='2'>";
  919. echo "<i>".get_lang("AddedResources")."</i><br/>";
  920. if ($myrow['visibility']==0)
  921. {
  922. $addedresource_style="invisible";
  923. }
  924. display_added_resources("Agenda", $myrow["id"], $addedresource_style);
  925. echo "</td></tr>";
  926. }
  927. */
  928. /*--------------------------------------------------
  929. DISPLAY: edit delete button (course admin only)
  930. --------------------------------------------------*/
  931. echo '<tr><td colspan="2">';
  932. if (!$repeat && api_is_allowed_to_edit(false,true)) {
  933. // edit
  934. $mylink = api_get_self()."?".api_get_cidreq()."&amp;origin=".Security::remove_XSS($_GET['origin'])."&amp;id=".$myrow['id'];
  935. echo "<a href=\"".$mylink."&amp;action=edit\">",
  936. Display::return_icon('edit.gif', get_lang('ModifyCalendarItem')), "</a>",
  937. "<a href=\"".$mylink."&amp;action=delete\" onclick=\"javascript:if(!confirm('".addslashes(api_htmlentities(get_lang("ConfirmYourChoice"),ENT_QUOTES,$charset))."')) return false;\">",
  938. Display::return_icon('delete.gif', get_lang('Delete')),"</a>";
  939. if ($myrow['visibility']==1) {
  940. $image_visibility="visible";
  941. } else {
  942. $image_visibility="invisible";
  943. }
  944. echo '<a href="'.$mylink.'&amp;action=showhide">',Display::return_icon($image_visibility, get_lang('Visible')),'</a><br /><br />';
  945. }
  946. $mylink = 'calendar_ical_export.php?'.api_get_cidreq().'&amp;type=course&amp;id='.$myrow['id'];
  947. echo '<a class="ical_export" href="'.$mylink.'&amp;class=confidential" title="'.get_lang('ExportiCalConfidential').'">'.Display::return_icon($export_icon_high, get_lang('ExportiCalConfidential')).'</a> ';
  948. echo '<a class="ical_export" href="'.$mylink.'&amp;class=private" title="'.get_lang('ExportiCalPrivate').'">'.Display::return_icon($export_icon_low, get_lang('ExportiCalPrivate')).'</a> ';
  949. echo '<a class="ical_export" href="'.$mylink.'&amp;class=public" title="'.get_lang('ExportiCalPublic').'">'.Display::return_icon($export_icon, get_lang('ExportiCalPublic')).'</a> ';
  950. echo '<a href="#" onclick="javascript:win_print=window.open(\'calendar_view_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('print.gif', get_lang('Print')).'</a>&nbsp;';
  951. echo "</td>";
  952. if($repeat) {
  953. echo '<tr>';
  954. echo '<td colspan="2">',get_lang('RepeatedEvent'),'<a href="',api_get_self(),'?',api_get_cidreq(),'&amp;agenda_id=',$repeat_id,'" alt="',get_lang('RepeatedEventViewOriginalEvent'),'">',get_lang('RepeatedEventViewOriginalEvent'),'</a></td>';
  955. echo '</tr>';
  956. }
  957. echo "</table>";
  958. // closing the layout table
  959. echo "</td>",
  960. "</tr>",
  961. "</table>";
  962. }
  963. /**
  964. * (This function is probably deprecated for this module)
  965. * Show the form for adding a new agenda item. This is the same function that is used whenever we are editing an
  966. * agenda item. When the id parameter is empty (default behaviour), then we show an empty form, else we are editing and
  967. * we have to retrieve the information that is in the database and use this information in the forms.
  968. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  969. * @param integer id, the id of the agenda item we are editing. By default this is empty which means that we are adding an
  970. * agenda item.
  971. */
  972. function show_group_filter_form()
  973. {
  974. /** @todo this select missing to implement */
  975. //$group_list=get_course_groups();
  976. echo "<select name=\"select\" onchange=\"MM_jumpMenu('parent',this,0)\">";
  977. echo "<option value=\"agenda.php?group=none\">show all groups</option>";
  978. /*foreach($group_list as $this_group)
  979. {
  980. // echo "<option value=\"agenda.php?isStudentView=true&amp;group=".$this_group['id']."\">".$this_group['name']."</option>";
  981. echo "<option value=\"agenda.php?group=".$this_group['id']."\" ";
  982. echo ($this_group['id']==$_SESSION['group'])? " selected":"" ;
  983. echo ">".$this_group['name']."</option>";
  984. }
  985. */
  986. echo "</select>";
  987. }
  988. function show_user_filter_form()
  989. {
  990. /** @todo this select missing to implement */
  991. //$user_list=get_course_users();
  992. echo "<select name=\"select\" onchange=\"MM_jumpMenu('parent',this,0)\">";
  993. echo "<option value=\"agenda.php?user=none\">show all users</option>";
  994. /*foreach($user_list as $this_user)
  995. {
  996. // echo "<option value=\"agenda.php?isStudentView=true&amp;user=".$this_user['uid']."\">".$this_user['lastName']." ".$this_user['firstName']."</option>";
  997. echo "<option value=\"agenda.php?user=".$this_user['uid']."\" ";
  998. echo ($this_user['uid']==$_SESSION['user'])? " selected":"" ;
  999. echo ">".$this_user['lastName']." ".$this_user['firstName']."</option>";
  1000. }*/
  1001. echo "</select>";
  1002. }
  1003. function show_user_group_filter_form()
  1004. {
  1005. /** @todo this select missing to implement */
  1006. echo "<select name=\"select\" onchange=\"MM_jumpMenu('parent',this,0)\">";
  1007. echo "<option value=\"agenda.php?user=none\">".get_lang("ShowAll")."</option>";
  1008. // Groups
  1009. echo "<optgroup label=\"".get_lang("Groups")."\">";
  1010. //$group_list=get_course_groups();
  1011. /* foreach($group_list as $this_group)
  1012. {
  1013. // echo "<option value=\"agenda.php?isStudentView=true&amp;group=".$this_group['id']."\">".$this_group['name']."</option>";
  1014. echo "<option value=\"agenda.php?group=".$this_group['id']."\" ";
  1015. echo ($this_group['id']==$_SESSION['group'])? " selected":"" ;
  1016. echo ">".$this_group['name']."</option>";
  1017. }*/
  1018. echo "</optgroup>";
  1019. // Users
  1020. echo "<optgroup label=\"".get_lang("Users")."\">";
  1021. //$user_list=get_course_users();
  1022. /* foreach($user_list as $this_user)
  1023. {
  1024. // echo "<option value=\"agenda.php?isStudentView=true&amp;user=".$this_user['uid']."\">".$this_user['lastName']." ".$this_user['firstName']."</option>";
  1025. echo "<option value=\"agenda.php?user=".$this_user['uid']."\" ";
  1026. echo ($this_user['uid']==$_SESSION['user'])? " selected":"" ;
  1027. echo ">".$this_user['lastName']." ".$this_user['firstName']."</option>";
  1028. }*/
  1029. echo "</optgroup>";
  1030. echo "</select>";
  1031. }
  1032. function show_add_form($id = '')
  1033. {
  1034. global $MonthsLong;
  1035. $htmlHeadXtra[] = to_javascript();
  1036. // the default values for the forms
  1037. if ($_GET['originalresource'] !== 'no') {
  1038. $day = date('d');
  1039. $month = date('m');
  1040. $year = date('Y');
  1041. $hours = 9;
  1042. $minutes= '00';
  1043. $end_day = date('d');
  1044. $end_month = date('m');
  1045. $end_year = date('Y');
  1046. $end_hours = 17;
  1047. $end_minutes= '00';
  1048. $repeat = false;
  1049. } else {
  1050. // we are coming from the resource linker so there might already have been some information in the form.
  1051. // When we clicked on the button to add resources we stored every form information into a session and now we
  1052. // are doing the opposite thing: getting the information out of the session and putting it into variables to
  1053. // display it in the forms.
  1054. $form_elements=$_SESSION['formelements'];
  1055. $day=$form_elements['day'];
  1056. $month=$form_elements['month'];
  1057. $year=$form_elements['year'];
  1058. $hours=$form_elements['hour'];
  1059. $minutes=$form_elements['minutes'];
  1060. $end_day=$form_elements['end_day'];
  1061. $end_month=$form_elements['end_month'];
  1062. $end_year=$form_elements['end_year'];
  1063. $end_hours=$form_elements['end_hours'];
  1064. $end_minutes=$form_elements['end_minutes'];
  1065. $title=$form_elements['title'];
  1066. $content=$form_elements['content'];
  1067. $id=$form_elements['id'];
  1068. $to=$form_elements['to'];
  1069. $repeat = $form_elements['repeat'];
  1070. }
  1071. // switching the send to all/send to groups/send to users
  1072. if ($_POST['To']) {
  1073. $day = $_POST['fday'];
  1074. $month = $_POST['fmonth'];
  1075. $year = $_POST['fyear'];
  1076. $hours = $_POST['fhour'];
  1077. $minutes = $_POST['fminute'];
  1078. $end_day = $_POST['end_fday'];
  1079. $end_month = $_POST['end_fmonth'];
  1080. $end_year = $_POST['end_fyear'];
  1081. $end_hours = $_POST['end_fhour'];
  1082. $end_minutes = $_POST['end_fminute'];
  1083. $title = $_POST['title'];
  1084. $content = $_POST['content'];
  1085. // the invisible fields
  1086. $action = $_POST['action'];
  1087. $id = $_POST['id'];
  1088. $repeat = !empty($_POST['repeat'])?true:false;
  1089. }
  1090. // if the id is set then we are editing an agenda item
  1091. if (is_int($id)) {
  1092. //echo "before get_agenda_item".$_SESSION['allow_individual_calendar'];
  1093. $item_2_edit=get_agenda_item($id);
  1094. $title = $item_2_edit['title'];
  1095. $content= $item_2_edit['content'];
  1096. // start date
  1097. $item_2_edit['start_date'] = api_get_local_time($item_2_edit['start_date']);
  1098. // start date
  1099. list($datepart, $timepart) = split(" ", $item_2_edit['start_date']);
  1100. list($year, $month, $day) = explode("-", $datepart);
  1101. list($hours, $minutes, $seconds) = explode(":", $timepart);
  1102. // end date
  1103. $item_2_edit['end_date'] = api_get_local_time($item_2_edit['end_date']);
  1104. list($datepart, $timepart) = split(" ", $item_2_edit['end_date']);
  1105. list($end_year, $end_month, $end_day) = explode("-", $datepart);
  1106. list($end_hours, $end_minutes, $end_seconds) = explode(":", $timepart);
  1107. // attachments
  1108. //edit_added_resources("Agenda", $id);
  1109. $to=$item_2_edit['to'];
  1110. //echo "<br />after get_agenda_item".$_SESSION['allow_individual_calendar'];
  1111. }
  1112. $content=stripslashes($content);
  1113. $title=stripslashes($title);
  1114. // we start a completely new item, we do not come from the resource linker
  1115. if ($_GET['originalresource']!=="no" and $_GET['action']=="add")
  1116. {
  1117. $_SESSION["formelements"]=null;
  1118. //unset_session_resources();//--------------------------------------------------------------------------------------
  1119. }
  1120. ?>
  1121. <!-- START OF THE FORM -->
  1122. <form enctype="multipart/form-data" action="<?php echo api_get_self().'?origin='.Security::remove_XSS($_GET['origin']).'&amp;action='.Security::remove_XSS($_GET['action']); ?>" method="post" name="new_calendar_item">
  1123. <input type="hidden" name="id" value="<?php if (isset($id)) echo $id; ?>" />
  1124. <input type="hidden" name="action" value="<?php if (isset($_GET['action'])) echo Security::remove_XSS($_GET['action']); ?>" />
  1125. <input type="hidden" name="sort" value="asc" />
  1126. <input type="hidden" name="submit_event" value="ok" />
  1127. <?php
  1128. echo '<div class="row"><div class="form_header">';
  1129. echo (isset($id) AND $id<>'')?get_lang('ModifyCalendarItem'):get_lang("AddCalendarItem");
  1130. echo '</div></div>';
  1131. ?>
  1132. <table border="0" cellpadding="5" cellspacing="0" width="80%" id="newedit_form">
  1133. <!-- START date and time -->
  1134. <tr>
  1135. <div>
  1136. <table border="0" width="100%">
  1137. <tr><td colspan="4">
  1138. <div id="err_date" style="display:none;color:red"></div>
  1139. <div id="err_start_date" style="display:none;color:red"></div>
  1140. </td></tr>
  1141. <td width="10%">
  1142. <!-- date: 1 -> 31 -->
  1143. <nobr><?php echo get_lang('StartDate').": "; ?></nobr>
  1144. </td>
  1145. <td width="35%">
  1146. <select name="fday" onchange="javascript:document.new_calendar_item.end_fday.value=this.value;">
  1147. <?php
  1148. // small loop for filling all the dates
  1149. // 2do: the available dates should be those of the selected month => february is from 1 to 28 (or 29) and not to 31
  1150. foreach (range(1, 31) as $i)
  1151. {
  1152. // values have to have double digits
  1153. $value = ($i <= 9 ? '0'.$i : $i );
  1154. // the current day is indicated with [] around the date
  1155. if ($value==$day)
  1156. {
  1157. echo " <option value=\"".$value."\" selected> ".$i." </option>";
  1158. }
  1159. else
  1160. {
  1161. echo "<option value=\"$value\">$i</option>";
  1162. }
  1163. }
  1164. ?>
  1165. </select>
  1166. <!-- month: january -> december -->
  1167. <select name="fmonth" onchange="javascript:document.new_calendar_item.end_fmonth.value=this.value;">
  1168. <?php
  1169. for ($i=1; $i<=12; $i++)
  1170. {
  1171. // values have to have double digits
  1172. if ($i<=9)
  1173. {
  1174. $value="0".$i;
  1175. }
  1176. else
  1177. {
  1178. $value=$i;
  1179. }
  1180. if ($value==$month)
  1181. {
  1182. echo " <option value=\"".$value."\" selected>".$MonthsLong[$i-1]."</option>\n";
  1183. }
  1184. else
  1185. {
  1186. echo " <option value=\"".$value."\">".$MonthsLong[$i-1]."</option>\n";
  1187. }
  1188. } ?>
  1189. </select>
  1190. <select name="fyear" onchange="javascript:document.new_calendar_item.end_fyear.value=this.value;">
  1191. <option value="<?php echo ($year-1); ?>"><?php echo ($year-1); ?></option>
  1192. <option value="<?php echo $year; ?>" selected="selected"><?php echo $year; ?></option>
  1193. <?php
  1194. echo "\n";
  1195. for ($i=1; $i<=5; $i++)
  1196. {
  1197. $value=$year+$i;
  1198. echo "<option value=\"$value\">$value</option>\n";
  1199. } ?>
  1200. </select>
  1201. <a href="javascript:openCalendar('new_calendar_item','f')"><?php Display::display_icon('calendar_select.gif', get_lang('Select'), array ('style' => 'vertical-align: middle;')); ?></a>
  1202. </td>
  1203. <td width="10%">
  1204. <nobr><?php echo get_lang('StartTime').": \n"; ?></nobr>
  1205. </td>
  1206. <td>
  1207. <select name="fhour" onchange="javascript:document.new_calendar_item.end_fhour.value=this.value;">
  1208. <!-- <option value="--">--</option> -->
  1209. <?php
  1210. echo "\n";
  1211. foreach (range(0, 23) as $i)
  1212. {
  1213. // values have to have double digits
  1214. $value = ($i <= 9 ? '0'.$i : $i );
  1215. // the current hour is indicated with [] around the hour
  1216. if ($hours==$value)
  1217. {
  1218. echo "<option value=\"".$value."\" selected> ".$value." </option>\n";
  1219. }
  1220. else
  1221. {
  1222. echo "<option value=\"$value\">$value</option>\n";
  1223. }
  1224. } ?>
  1225. </select>
  1226. <select name="fminute" onchange="javascript:document.new_calendar_item.end_fminute.value=this.value;">
  1227. <!-- <option value="<?php echo $minutes ?>"><?php echo $minutes; ?></option> -->
  1228. <!-- <option value="--">--</option> -->
  1229. <?php
  1230. foreach (range(0, 59) as $i)
  1231. {
  1232. // values have to have double digits
  1233. $value = ($i <= 9 ? '0'.$i : $i );
  1234. echo "<option value=\"$value\">$value</option>\n";
  1235. } ?>
  1236. </select>
  1237. </td>
  1238. </div>
  1239. </tr>
  1240. <!-- END date and time -->
  1241. <tr>
  1242. <div>
  1243. <tr><td colspan="4"><div id="err_end_date" style="display:none;color:red"></div></td></tr>
  1244. <td >
  1245. <!-- date: 1 -> 31 -->
  1246. <nobr><?php echo get_lang('EndDate').": "; ?></nobr>
  1247. </td>
  1248. <td >
  1249. <select name="end_fday">
  1250. <?php
  1251. // small loop for filling all the dates
  1252. // 2do: the available dates should be those of the selected month => february is from 1 to 28 (or 29) and not to 31
  1253. echo "\n";
  1254. foreach (range(1, 31) as $i)
  1255. {
  1256. // values have to have double digits
  1257. $value = ($i <= 9 ? '0'.$i : $i );
  1258. // the current day is indicated with [] around the date
  1259. if ($value==$end_day)
  1260. { echo " <option value=\"".$value."\" selected> ".$i." </option>\n";}
  1261. else
  1262. { echo " <option value=\"".$value."\">".$i."</option>\n"; }
  1263. }?>
  1264. </select>
  1265. <!-- month: january -> december -->
  1266. <select name="end_fmonth">
  1267. <?php
  1268. echo "\n";
  1269. foreach (range(1, 12) as $i)
  1270. {
  1271. // values have to have double digits
  1272. $value = ($i <= 9 ? '0'.$i : $i );
  1273. if ($value==$end_month)
  1274. { echo " <option value=\"".$value."\" selected>".$MonthsLong[$i-1]."</option>\n"; }
  1275. else
  1276. { echo " <option value=\"".$value."\">".$MonthsLong[$i-1]."</option>\n"; }
  1277. }?>
  1278. </select>
  1279. <select name="end_fyear">
  1280. <option value="<?php echo ($end_year-1) ?>"><?php echo ($end_year-1) ?></option>
  1281. <option value="<?php echo $end_year ?>" selected> <?php echo $end_year ?> </option>
  1282. <?php
  1283. echo "\n";
  1284. for ($i=1; $i<=5; $i++)
  1285. {
  1286. $value=$end_year+$i;
  1287. echo "<option value=\"$value\">$value</option>\n";
  1288. } ?>
  1289. </select>
  1290. <a href="javascript:openCalendar('new_calendar_item', 'end_f')"><?php Display::display_icon('calendar_select.gif',get_lang('Select'), array ('style' => 'vertical-align: middle;')); ?></a>
  1291. </td>
  1292. <td >
  1293. <nobr><?php echo get_lang('EndTime').": \n"; ?></nobr>
  1294. </td>
  1295. <td >
  1296. <select name="end_fhour">
  1297. <!-- <option value="--">--</option> -->
  1298. <?php
  1299. echo "\n";
  1300. foreach (range(0, 23) as $i)
  1301. {
  1302. // values have to have double digits
  1303. $value = ($i <= 9 ? '0'.$i : $i );
  1304. // the current hour is indicated with [] around the hour
  1305. if ($end_hours==$value)
  1306. { echo "<option value=\"".$value."\" selected> ".$value." </option>\n"; }
  1307. else
  1308. { echo "<option value=\"".$value."\"> ".$value." </option>\n"; }
  1309. } ?>
  1310. </select>
  1311. <select name="end_fminute">
  1312. <!-- <option value="<?php echo $end_minutes; ?>"><?php echo $end_minutes; ?></option> -->
  1313. <!-- <option value="--">--</option> -->
  1314. <?php
  1315. foreach (range(0, 59) as $i)
  1316. {
  1317. // values have to have double digits
  1318. $value = ($i <= 9 ? '0'.$i : $i );
  1319. echo "<option value=\"$value\">$value</option>\n";
  1320. } ?>
  1321. </select>
  1322. <br>
  1323. </td>
  1324. </div>
  1325. </tr>
  1326. <tr><td colspan="4">
  1327. <hr noshade="noshade" color="#cccccc" />
  1328. <div id="err_title" style="display:none;color:red"></div>
  1329. </td></tr>
  1330. <tr class="subtitle">
  1331. <td colspan="4" valign="top"><?php echo get_lang('ItemTitle'); ?> :
  1332. <!--<div style='margin-left: 80px'><textarea name="title" cols="50" rows="2" wrap="virtual" style="vertical-align:top; width:75%; height:50px;"><?php if (isset($title)) echo $title; ?></textarea></div>-->
  1333. <input type="text" size="60" name="title" value="<?php if (isset($title)) echo $title; ?>" />
  1334. </td>
  1335. </tr>
  1336. <tr>
  1337. <td colspan="4">
  1338. <?php
  1339. require_once api_get_path(LIBRARY_PATH) . "/fckeditor/fckeditor.php";
  1340. $oFCKeditor = new FCKeditor('content') ;
  1341. $oFCKeditor->ToolbarSet = 'GlobalAgenda';
  1342. $oFCKeditor->Width = '100%';
  1343. $oFCKeditor->Height = '175';
  1344. $oFCKeditor->Value = $content;
  1345. $return = $oFCKeditor->CreateHtml();
  1346. echo $return;
  1347. ?>
  1348. </td>
  1349. </tr>
  1350. <!--<?php /* ADDED BY UGENT, Patrick Cool, march 2004 */ ?>
  1351. <tr>
  1352. <td colspan="4">
  1353. <?php
  1354. //onclick="selectAll(this.form.elements[6],true)"
  1355. // show_addresource_button('onclick="selectAll(this.form.elements[6],true)"');
  1356. ?>
  1357. </td>
  1358. </tr>-->
  1359. <?php
  1360. //if ($_SESSION['addedresource'])
  1361. echo "<tr>\n";
  1362. echo "<td colspan=\"4\">\n";
  1363. //echo display_resources(0);//--------------------------------------------------------
  1364. $test=$_SESSION['addedresource'];
  1365. echo "</td>\n</tr>\n";
  1366. /* END ADDED BY UGENT, Patrick Cool, march 2004 */
  1367. if(empty($id)) //only show repeat fields when adding the first time
  1368. {
  1369. ?>
  1370. <tr>
  1371. <td colspan="4" />
  1372. </tr>
  1373. <?php
  1374. }//only show repeat fields if adding, not if editing
  1375. ?>
  1376. <tr>
  1377. <td colspan="4">
  1378. <?php
  1379. if ($_GET['action']=='edit'){
  1380. $class='save';
  1381. $text=get_lang('ModifyEvent');
  1382. }else{
  1383. $class='add';
  1384. $text=get_lang('AddEvent');
  1385. }
  1386. ?>
  1387. <button type="button" class="add" value="<?php echo get_lang('Ok'); ?>" onclick="validate_date()" ><?php echo $text; ?></button>
  1388. </td>
  1389. </tr>
  1390. </table>
  1391. </form>
  1392. <?php
  1393. }
  1394. function get_agendaitems($month, $year)
  1395. {
  1396. global $_user;
  1397. global $_configuration;
  1398. $month=Database::escape_string($month);
  1399. $year=Database::escape_string($year);
  1400. $items = array ();
  1401. //databases of the courses
  1402. $TABLEAGENDA = Database :: get_main_table(TABLE_MAIN_SYSTEM_CALENDAR);
  1403. //$TABLE_ITEMPROPERTY = Database :: get_course_table(TABLE_ITEM_PROPERTY);
  1404. //$group_memberships = GroupManager :: get_group_ids(Database::get_current_course_database(), $_user['user_id']);
  1405. // if the user is administrator of that course we show all the agenda items
  1406. //if (api_is_allowed_to_edit())
  1407. //{
  1408. //echo "course admin";
  1409. $sqlquery = "SELECT
  1410. DISTINCT *
  1411. FROM ".$TABLEAGENDA."
  1412. WHERE
  1413. MONTH(start_date)='".$month."'
  1414. AND YEAR(start_date)='".$year."'
  1415. GROUP BY id
  1416. ORDER BY start_date ";
  1417. //}
  1418. // if the user is not an administrator of that course
  1419. /* else
  1420. {
  1421. //echo "GEEN course admin";
  1422. if (is_array($group_memberships) && count($group_memberships)>0)
  1423. {
  1424. $sqlquery = "SELECT
  1425. agenda.*
  1426. FROM ".$TABLEAGENDA."
  1427. WHERE
  1428. MONTH(agenda.start_date)='".$month."'
  1429. AND YEAR(agenda.start_date)='".$year."'
  1430. ORDER BY start_date ";
  1431. }
  1432. else
  1433. {
  1434. $sqlquery = "SELECT
  1435. agenda.*, item_property.*
  1436. FROM ".$TABLEAGENDA."
  1437. WHERE
  1438. MONTH(agenda.start_date)='".$month."'
  1439. AND YEAR(agenda.start_date)='".$year."'
  1440. ORDER BY start_date ";
  1441. }
  1442. }*/
  1443. //$mycourse = api_get_course_info();
  1444. $portal_url = $_configuration['root_web'];
  1445. if ($_configuration['multiple_access_urls']) {
  1446. $access_url_id = api_get_current_access_url_id();
  1447. if ($access_url_id != -1 ){
  1448. $url = api_get_access_url($access_url_id);
  1449. $portal_url = $url['url'];
  1450. }
  1451. }
  1452. $result = Database::query($sqlquery);
  1453. while ($item = Database::fetch_array($result))
  1454. {
  1455. $agendaday_string = api_convert_and_format_date($item['start_date'], "%d", date_default_timezone_get());
  1456. $agendaday = intval($agendaday_string);
  1457. $time = api_convert_and_format_date($item['start_date'], TIME_NO_SEC_FORMAT, date_default_timezone_get());
  1458. $URL = $portal_url.'main/admin/agenda.php?day='.$agendaday."&amp;month=".$month."&amp;year=".$year; // RH //Patrick Cool: to highlight the relevant agenda item
  1459. $items[$agendaday][$item['start_time']] .= '<i>'.$time.'</i> <a href="'.$URL.'" title="'.$item['title'].'<br />';
  1460. }
  1461. // sorting by hour for every day
  1462. $agendaitems = array ();
  1463. while (list ($agendaday, $tmpitems) = each($items))
  1464. {
  1465. sort($tmpitems);
  1466. while (list ($key, $val) = each($tmpitems))
  1467. {
  1468. $agendaitems[$agendaday] .= $val;
  1469. }
  1470. }
  1471. return $agendaitems;
  1472. }
  1473. function display_upcoming_events() {
  1474. echo '<br /><b>'.get_lang('UpcomingEvent').'</b><br />';
  1475. $number_of_items_to_show = (int)api_get_setting('number_of_upcoming_events');
  1476. //databases of the courses
  1477. $TABLEAGENDA = Database :: get_main_table(TABLE_MAIN_SYSTEM_CALENDAR);
  1478. //$TABLE_ITEMPROPERTY = Database :: get_course_table(TABLE_ITEM_PROPERTY);
  1479. //$mycourse = api_get_course_info();
  1480. //$myuser = api_get_user_info();
  1481. //$group_memberships = GroupManager :: get_group_ids($mycourse['dbName'], $myuser['user_id']);
  1482. // if the user is administrator of that course we show all the agenda items
  1483. /*if (api_is_allowed_to_edit())
  1484. {*/
  1485. //echo "course admin";
  1486. $sqlquery = "SELECT DISTINCT * FROM ".$TABLEAGENDA;
  1487. global $_configuration;
  1488. $current_access_url_id = 1;
  1489. if ($_configuration['multiple_access_urls']) {
  1490. $current_access_url_id = api_get_current_access_url_id();
  1491. }
  1492. $sqlquery .= "WHERE access_url_id = $current_access_url_id ";
  1493. $sqlquery .= " ORDER BY start_date ";
  1494. //}
  1495. // if the user is not an administrator of that course
  1496. $result = Database::query($sqlquery);
  1497. $counter = 0;
  1498. while ($item = Database::fetch_array($result,'ASSOC')) {
  1499. if ($counter < $number_of_items_to_show) {
  1500. echo api_get_local_time($item['start_date']),' - ',$item['title'],'<br />';
  1501. $counter++;
  1502. }
  1503. }
  1504. }
  1505. /**
  1506. * This function calculates the startdate of the week (monday)
  1507. * and the enddate of the week (sunday)
  1508. * and returns it as an array
  1509. */
  1510. function calculate_start_end_of_week($week_number, $year)
  1511. {
  1512. // determine the start and end date
  1513. // step 1: we calculate a timestamp for a day in this week
  1514. $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
  1515. // step 2: we which day this is (0=sunday, 1=monday, ...)
  1516. $number_day_in_week = date('w', $random_day_in_week);
  1517. // step 3: we calculate the timestamp of the monday of the week we are in
  1518. $start_timestamp = $random_day_in_week - (($number_day_in_week -1) * 24 * 60 * 60);
  1519. // step 4: we calculate the timestamp of the sunday of the week we are in
  1520. $end_timestamp = $random_day_in_week + ((7 - $number_day_in_week +1) * 24 * 60 * 60) - 3600;
  1521. // step 5: calculating the start_day, end_day, start_month, end_month, start_year, end_year
  1522. $start_day = date('j', $start_timestamp);
  1523. $start_month = date('n', $start_timestamp);
  1524. $start_year = date('Y', $start_timestamp);
  1525. $end_day = date('j', $end_timestamp);
  1526. $end_month = date('n', $end_timestamp);
  1527. $end_year = date('Y', $end_timestamp);
  1528. $start_end_array['start']['day'] = $start_day;
  1529. $start_end_array['start']['month'] = $start_month;
  1530. $start_end_array['start']['year'] = $start_year;
  1531. $start_end_array['end']['day'] = $end_day;
  1532. $start_end_array['end']['month'] = $end_month;
  1533. $start_end_array['end']['year'] = $end_year;
  1534. return $start_end_array;
  1535. }
  1536. /**
  1537. * Show the mini calendar of the given month
  1538. */
  1539. function display_daycalendar($agendaitems, $day, $month, $year, $weekdaynames, $monthName)
  1540. {
  1541. global $DaysShort, $DaysLong, $course_path;
  1542. global $MonthsLong;
  1543. global $query;
  1544. // timestamp of today
  1545. $today = mktime();
  1546. $nextday = $today + (24 * 60 * 60);
  1547. $previousday = $today - (24 * 60 * 60);
  1548. // the week number of the year
  1549. $week_number = date("W", $today);
  1550. // if we moved to the next / previous day we have to recalculate the $today variable
  1551. if ($_GET['day'])
  1552. {
  1553. $today = mktime(0, 0, 0, $month, $day, $year);
  1554. $nextday = $today + (24 * 60 * 60);
  1555. $previousday = $today - (24 * 60 * 60);
  1556. $week_number = date("W", $today);
  1557. }
  1558. // calculating the start date of the week
  1559. // the date of the monday of this week is the timestamp of today minus
  1560. // number of days that have already passed this week * 24 hours * 60 minutes * 60 seconds
  1561. $current_day = date("j", $today); // Day of the month without leading zeros (1 to 31) of today
  1562. $day_of_the_week = date("w", $today); // Numeric representation of the day of the week 0 (for Sunday) through 6 (for Saturday) of today
  1563. //$timestamp_first_date_of_week=$today-(($day_of_the_week-1)*24*60*60); // timestamp of the monday of this week
  1564. //$timestamp_last_date_of_week=$today+((7-$day_of_the_week)*24*60*60); // timestamp of the sunday of this week
  1565. // we are loading all the calendar items of all the courses for today
  1566. echo "<table class=\"data_table\">\n";
  1567. // the forward and backwards url
  1568. $backwardsURL = api_get_self()."?coursePath=".urlencode($course_path)."&amp;courseCode=".Security::remove_XSS($_GET['courseCode'])."&amp;action=view&amp;view=day&amp;day=".date("j", $previousday)."&amp;month=".date("n", $previousday)."&amp;year=".date("Y", $previousday);
  1569. $forewardsURL = api_get_self()."?coursePath=".urlencode($course_path)."&amp;courseCode=".Security::remove_XSS($_GET['courseCode'])."&amp;action=view&amp;view=day&amp;day=".date("j", $nextday)."&amp;month=".date("n", $nextday)."&amp;year=".date("Y", $nextday);
  1570. // The title row containing the day
  1571. echo "<tr>\n", "<th width=\"10%\"><a href=\"", $backwardsURL, "\">".Display::return_icon('action_prev.png',get_lang('Previous'))."</a></th>\n", "<th>";
  1572. echo $DaysLong[$day_of_the_week]." ".date("j", $today)." ".$MonthsLong[date("n", $today) - 1]." ".date("Y", $today);
  1573. echo "</th>";
  1574. echo "<th width=\"10%\"><a href=\"", $forewardsURL, "\">".Display::return_icon('action_next.png',get_lang('Next'))."</a></th>\n";
  1575. echo "</tr>\n";
  1576. // the rows for each half an hour
  1577. for ($i = 10; $i < 48; $i ++)
  1578. {
  1579. if ($i % 2 == 0)
  1580. {
  1581. $class = "class=\"row_even\"";
  1582. }
  1583. else
  1584. {
  1585. $class = "class=\"row_odd\"";
  1586. }
  1587. echo "<tr $class>\n";
  1588. echo "";
  1589. if ($i % 2 == 0)
  1590. {
  1591. echo ("<td valign=\"top\" width=\"75\">". (($i) / 2)." ".get_lang("HourShort")." 00</td>\n");
  1592. }
  1593. else
  1594. {
  1595. echo ("<td valign=\"top\" width=\"75\">". ((($i) / 2) - (1 / 2))." ".get_lang("HourShort")." 30</td>\n");
  1596. }
  1597. echo "<td $class valign=\"top\" colspan=\"2\">\n";
  1598. if (is_array($agendaitems[$i]))
  1599. {
  1600. foreach ($agendaitems[$i] as $key => $value)
  1601. {
  1602. echo $value;
  1603. }
  1604. }
  1605. else
  1606. {
  1607. echo $agendaitems[$i];
  1608. }
  1609. echo "</td>\n";
  1610. echo "</tr>\n";
  1611. }
  1612. echo "</table>\n";
  1613. }
  1614. /**
  1615. * Display the weekly view of the calendar
  1616. */
  1617. function display_weekcalendar($agendaitems, $month, $year, $weekdaynames, $monthName)
  1618. {
  1619. global $DaysShort,$course_path;
  1620. global $MonthsLong;
  1621. // timestamp of today
  1622. $today = time();
  1623. $day_of_the_week = date("w", $today);
  1624. $thisday_of_the_week = date("w", $today);
  1625. // the week number of the year
  1626. $week_number = date("W", $today);
  1627. $thisweek_number = $week_number;
  1628. // if we moved to the next / previous week we have to recalculate the $today variable
  1629. if ($_GET['week'])
  1630. {
  1631. $today = mktime(0, 0, 0, 1, 1, $year);
  1632. $today = $today + (((int)$_GET['week']-1) * (7 * 24 * 60 * 60));
  1633. $week_number = date("W", $today);
  1634. }
  1635. // calculating the start date of the week
  1636. // the date of the monday of this week is the timestamp of today minus
  1637. // number of days that have already passed this week * 24 hours * 60 minutes * 60 seconds
  1638. $current_day = date("j", $today); // Day of the month without leading zeros (1 to 31) of today
  1639. $day_of_the_week = date("w", $today); // Numeric representation of the day of the week 0 (for Sunday) through 6 (for Saturday) of today
  1640. $timestamp_first_date_of_week = $today - (($day_of_the_week -1) * 24 * 60 * 60); // timestamp of the monday of this week
  1641. $timestamp_last_date_of_week = $today + ((7 - $day_of_the_week) * 24 * 60 * 60); // timestamp of the sunday of this week
  1642. $backwardsURL = api_get_self()."?coursePath=".urlencode($course_path)."&amp;courseCode=".Security::remove_XSS($_GET['courseCode'])."&amp;action=view&amp;view=week&amp;week=". ($week_number -1);
  1643. $forewardsURL = api_get_self()."?coursePath=".urlencode($course_path)."&amp;courseCode=".Security::remove_XSS($_GET['courseCode'])."&amp;action=view&amp;view=week&amp;week=". ($week_number +1);
  1644. echo "<table id=\"agenda_list\">\n";
  1645. // The title row containing the the week information (week of the year (startdate of week - enddate of week)
  1646. echo "<tr class=\"title\">\n";
  1647. echo "<td width=\"10%\"><a href=\"", $backwardsURL, "\">".Display::return_icon('action_prev.png',get_lang('Previous'))."</a></td>\n";
  1648. echo "<td colspan=\"5\">".get_lang("Week")." ".$week_number;
  1649. 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).')';
  1650. echo "</td>";
  1651. echo "<td width=\"10%\"><a href=\"", $forewardsURL, "\">".Display::return_icon('action_next.png',get_lang('Next'))."</a></td>", "</tr>";
  1652. // The second row containing the short names of the days of the week
  1653. echo "<tr>\n";
  1654. // this is the Day of the month without leading zeros (1 to 31) of the monday of this week
  1655. $tmp_timestamp = $timestamp_first_date_of_week;
  1656. for ($ii = 1; $ii < 8; $ii ++)
  1657. {
  1658. $is_today = ($ii == $thisday_of_the_week AND (!isset($_GET['week']) OR $_GET['week']==$thisweek_number));
  1659. echo "<td class=\"weekdays\">";
  1660. if ($is_today)
  1661. {
  1662. echo "<font color=#CC3300>";
  1663. }
  1664. echo $DaysShort[$ii % 7]." ".date("j", $tmp_timestamp)." ".$MonthsLong[date("n", $tmp_timestamp) - 1];
  1665. if ($is_today)
  1666. {
  1667. echo "</font>";
  1668. }
  1669. echo "</td>\n";
  1670. // we 24 hours * 60 minutes * 60 seconds to the $tmp_timestamp
  1671. $array_tmp_timestamp[] = $tmp_timestamp;
  1672. $tmp_timestamp = $tmp_timestamp + (24 * 60 * 60);
  1673. }
  1674. echo "</tr>\n";
  1675. // the table cells containing all the entries for that day
  1676. echo "<tr>\n";
  1677. $counter = 0;
  1678. foreach ($array_tmp_timestamp as $key => $value)
  1679. {
  1680. if ($counter < 5)
  1681. {
  1682. $class = "class=\"days_week\"";
  1683. }
  1684. else
  1685. {
  1686. $class = "class=\"days_weekend\"";
  1687. }
  1688. if ($counter == $thisday_of_the_week -1 AND (!isset($_GET['week']) OR $_GET['week']==$thisweek_number))
  1689. {
  1690. $class = "class=\"days_today\"";
  1691. }
  1692. echo "<td ".$class.">";
  1693. echo "<span class=\"agendaitem\">".$agendaitems[date('j', $value)]."&nbsp;</span> ";
  1694. echo "</td>\n";
  1695. $counter ++;
  1696. }
  1697. echo "</tr>\n";
  1698. echo "</table>\n";
  1699. }
  1700. /**
  1701. * Show the monthcalender of the given month
  1702. */
  1703. function get_day_agendaitems($courses_dbs, $month, $year, $day)
  1704. {
  1705. global $_user;
  1706. global $_configuration;
  1707. global $setting_agenda_link;
  1708. $items = array ();
  1709. // get agenda-items for every course
  1710. //$query=Database::query($sql_select_courses);
  1711. foreach ($courses_dbs as $key => $array_course_info)
  1712. {
  1713. //databases of the courses
  1714. $TABLEAGENDA = Database :: get_main_table(TABLE_MAIN_SYSTEM_CALENDAR);
  1715. //$TABLE_ITEMPROPERTY = Database :: get_course_table(TABLE_ITEM_PROPERTY, $array_course_info['db']);
  1716. // getting all the groups of the user for the current course
  1717. //$group_memberships = GroupManager :: get_group_ids($array_course_info['db'], $_user['user_id']);
  1718. // if the user is administrator of that course we show all the agenda items
  1719. if ($array_course_info['status'] == '1')
  1720. {
  1721. //echo "course admin";
  1722. $sqlquery = "SELECT DISTINCT *
  1723. FROM ".$TABLEAGENDA."
  1724. WHERE
  1725. DAYOFMONTH(start_date)='".$day."' AND MONTH(start_date)='".$month."' AND YEAR(start_date)='".$year."'
  1726. GROUP BY agenda.id
  1727. ORDER BY start_date ";
  1728. }
  1729. // if the user is not an administrator of that course
  1730. /*else
  1731. {
  1732. //echo "GEEN course admin";
  1733. if (is_array($group_memberships) && count($group_memberships)>0)
  1734. {
  1735. $sqlquery = "SELECT
  1736. agenda.*
  1737. FROM ".$TABLEAGENDA."
  1738. WHERE
  1739. DAYOFMONTH(start_date)='".$day."' AND MONTH(start_date)='".$month."' AND YEAR(start_date)='".$year."'
  1740. ORDER BY start_date ";
  1741. }
  1742. else
  1743. {
  1744. $sqlquery = "SELECT
  1745. agenda.*
  1746. FROM ".$TABLEAGENDA."
  1747. WHERE
  1748. DAYOFMONTH(start_date)='".$day."' AND MONTH(start_date)='".$month."' AND YEAR(start_date)='".$year."'
  1749. ORDER BY start_date ";
  1750. }
  1751. }*/
  1752. //$sqlquery = "SELECT * FROM $agendadb WHERE DAYOFMONTH(day)='$day' AND month(day)='$month' AND year(day)='$year'";
  1753. //echo "abc";
  1754. //echo $sqlquery;
  1755. $result = Database::query($sqlquery);
  1756. $portal_url = $_configuration['root_web'];
  1757. if ($_configuration['multiple_access_urls']) {
  1758. $access_url_id = api_get_current_access_url_id();
  1759. if ($access_url_id != -1 ){
  1760. $url = api_get_access_url($access_url_id);
  1761. $portal_url = $url['url'];
  1762. }
  1763. }
  1764. //echo Database::num_rows($result);
  1765. while ($item = Database::fetch_array($result))
  1766. {
  1767. // in the display_daycalendar function we use $i (ranging from 0 to 47) for each halfhour
  1768. // we want to know for each agenda item for this day to wich halfhour it must be assigned
  1769. $item['start_date'] = api_get_local_time($item['start_date'], null, date_default_timezone_get());
  1770. list ($datepart, $timepart) = split(" ", $item['start_date']);
  1771. list ($year, $month, $day) = explode("-", $datepart);
  1772. list ($hours, $minutes, $seconds) = explode(":", $timepart);
  1773. $halfhour = 2 * $hours;
  1774. if ($minutes >= '30')
  1775. {
  1776. $halfhour = $halfhour +1;
  1777. }
  1778. if ($setting_agenda_link == 'coursecode')
  1779. {
  1780. $title=$array_course_info['title'];
  1781. $agenda_link = api_substr($title, 0, 14);
  1782. }
  1783. else
  1784. {
  1785. $agenda_link = Display::return_icon('course_home.gif');
  1786. }
  1787. //$URL = $_configuration['root_web'].$mycours["dir"]."/";
  1788. $URL = $portal_url.'main/admin/agenda.php?cidReq='."&amp;day=$day&amp;month=$month&amp;year=$year#$day"; // RH //Patrick Cool: to highlight the relevant agenda item
  1789. $items[$halfhour][] .= "<i>".$hours.":".$minutes."</i> <a href=\"$URL\" title=\"".$array_course_info['name']."\">".$agenda_link."</a> ".$item['title']."<br />";
  1790. }
  1791. }
  1792. // sorting by hour for every day
  1793. $agendaitems = array();
  1794. while (list($agendaday, $tmpitems) = each($items))
  1795. {
  1796. sort($tmpitems);
  1797. while (list($key,$val) = each($tmpitems))
  1798. {
  1799. $agendaitems[$agendaday].=$val;
  1800. }
  1801. }
  1802. $agendaitems = $items;
  1803. //print_r($agendaitems);
  1804. return $agendaitems;
  1805. }
  1806. /**
  1807. * Return agenda items of the week
  1808. */
  1809. function get_week_agendaitems($courses_dbs, $month, $year, $week = '')
  1810. {
  1811. global $_user;
  1812. global $_configuration;
  1813. global $setting_agenda_link;
  1814. $TABLEAGENDA = Database :: get_main_table(TABLE_MAIN_SYSTEM_CALENDAR);
  1815. $items = array ();
  1816. // The default value of the week
  1817. if ($week == '')
  1818. {
  1819. $week_number = date("W", time());
  1820. }
  1821. else
  1822. {
  1823. $week_number = $week;
  1824. }
  1825. $start_end = calculate_start_end_of_week($week_number, $year);
  1826. $start_filter = $start_end['start']['year']."-".$start_end['start']['month']."-".$start_end['start']['day'];
  1827. $end_filter = $start_end['end']['year']."-".$start_end['end']['month']."-".$start_end['end']['day'];
  1828. // get agenda-items for every course
  1829. foreach ($courses_dbs as $key => $array_course_info)
  1830. {
  1831. //databases of the courses
  1832. $TABLEAGENDA = Database :: get_main_table(TABLE_MAIN_SYSTEM_CALENDAR);
  1833. //$TABLE_ITEMPROPERTY = Database :: get_course_table(TABLE_ITEM_PROPERTY, $array_course_info["db"]);
  1834. // getting all the groups of the user for the current course
  1835. // $group_memberships = GroupManager :: get_group_ids($array_course_info["db"], $_user['user_id']);
  1836. // if the user is administrator of that course we show all the agenda items
  1837. //if ($array_course_info['status'] == '1')
  1838. //{
  1839. //echo "course admin";
  1840. $sqlquery = "SELECT DISTINCT * FROM ".$TABLEAGENDA." ORDER BY start_date";
  1841. //}
  1842. // if the user is not an administrator of that course
  1843. //else
  1844. //{
  1845. //echo "GEEN course admin";
  1846. /* if (is_array($group_memberships) && count($group_memberships)>0)
  1847. {
  1848. $sqlquery = "SELECT * FROM ".$TABLEAGENDA." ORDER BY a.start_date";
  1849. }
  1850. else*/
  1851. //{
  1852. // $sqlquery = "SELECT * FROM ".$TABLEAGENDA." ORDER BY a.start_date";
  1853. //}
  1854. //}
  1855. //echo "<pre>".$sqlquery."</pre>";
  1856. // $sqlquery = "SELECT * FROM $agendadb WHERE (DAYOFMONTH(day)>='$start_day' AND DAYOFMONTH(day)<='$end_day')
  1857. // AND (MONTH(day)>='$start_month' AND MONTH(day)<='$end_month')
  1858. // AND (YEAR(day)>='$start_year' AND YEAR(day)<='$end_year')";
  1859. $result = Database::query($sqlquery);
  1860. $portal_url = $_configuration['root_web'];
  1861. if ($_configuration['multiple_access_urls']) {
  1862. $access_url_id = api_get_current_access_url_id();
  1863. if ($access_url_id != -1 ){
  1864. $url = api_get_access_url($access_url_id);
  1865. $portal_url = $url['url'];
  1866. }
  1867. }
  1868. while ($item = Database::fetch_array($result))
  1869. {
  1870. $agendaday_string = api_convert_and_format_date($item['start_date'], "%d", date_default_timezone_get());
  1871. $agendaday = intval($agendaday_string);
  1872. $time = api_convert_and_format_date($item['start_date'], TIME_NO_SEC_FORMAT, date_default_timezone_get());
  1873. if ($setting_agenda_link == 'coursecode')
  1874. {
  1875. $title=$array_course_info['title'];
  1876. $agenda_link = api_substr($title, 0, 14);
  1877. }
  1878. else
  1879. {
  1880. $agenda_link = Display::return_icon('course_home.gif');
  1881. }
  1882. $URL = $portal_url."main/admin/agenda.php?cidReq=".urlencode($array_course_info["code"])."&amp;day=$agendaday&amp;month=$month&amp;year=$year#$agendaday"; // RH //Patrick Cool: to highlight the relevant agenda item
  1883. $items[$agendaday][$item['start_time']] .= "<i>$time</i> <a href=\"$URL\" title=\"".$array_course_info["name"]."\">".$agenda_link."</a> ".$item['title']."<br />";
  1884. }
  1885. }
  1886. // sorting by hour for every day
  1887. $agendaitems = array ();
  1888. while (list ($agendaday, $tmpitems) = each($items))
  1889. {
  1890. sort($tmpitems);
  1891. while (list ($key, $val) = each($tmpitems))
  1892. {
  1893. $agendaitems[$agendaday] .= $val;
  1894. }
  1895. }
  1896. //print_r($agendaitems);
  1897. return $agendaitems;
  1898. }
  1899. /**
  1900. * Get repeated events of a course between two dates (timespan of a day).
  1901. * Returns an array containing the events
  1902. * @param string Course info array (as returned by api_get_course_info())
  1903. * @param int UNIX timestamp of span start. Defaults 0, later transformed into today's start
  1904. * @param int UNIX timestamp. Defaults to 0, later transformed into today's end
  1905. * @param array A set of parameters to alter the SQL query
  1906. * @return array [int] => [course_id,parent_event_id,start_date,end_date,title,description]
  1907. */
  1908. function get_repeated_events_day_view($course_info,$start=0,$end=0,$params)
  1909. {
  1910. $events = array();
  1911. //initialise all values
  1912. $y=0;
  1913. $m=0;
  1914. $d=0;
  1915. //block $end if higher than 2038 -- PHP doesn't go past that
  1916. if($end>2145934800){$end = 2145934800;}
  1917. if($start == 0 or $end == 0)
  1918. {
  1919. $y=date('Y');
  1920. $m=date('m');
  1921. $d=date('j');
  1922. }
  1923. if($start==0)
  1924. {
  1925. $start = mktime(0,0,0,$m,$d,$y);
  1926. }
  1927. $db_start = date('Y-m-d H:i:s',$start);
  1928. if($end==0)
  1929. {
  1930. $end = mktime(23,59,59,$m,$d,$y);
  1931. }
  1932. //$db_end = date('Y-m-d H:i:s',$end);
  1933. $t_cal = Database::get_main_table(TABLE_MAIN_SYSTEM_CALENDAR,$course_info['dbName']);
  1934. $t_cal_repeat = Database::get_course_table(TABLE_AGENDA_REPEAT,$course_info['dbName']);
  1935. $t_ip = Database::get_course_table(TABLE_ITEM_PROPERTY,$course_info['dbName']);
  1936. $sql = "SELECT c.id, c.title, c.content, " .
  1937. " UNIX_TIMESTAMP(c.start_date) as orig_start, UNIX_TIMESTAMP(c.end_date) as orig_end, " .
  1938. " cr.cal_type, cr.cal_end " .
  1939. " FROM $t_cal c, $t_cal_repeat cr, $t_ip as item_property " .
  1940. " WHERE cr.cal_end >= $start " .
  1941. " AND cr.cal_id = c.id " .
  1942. " AND item_property.ref = c.id ".
  1943. " AND item_property.tool = '".TOOL_CALENDAR_EVENT."' ".
  1944. " AND c.start_date <= '$db_start' "
  1945. .(!empty($params['conditions'])?$params['conditions']:'')
  1946. .(!empty($params['groupby'])?' GROUP BY '.$params['groupby']:'')
  1947. .(!empty($params['orderby'])?' ORDER BY '.$params['orderby']:'');
  1948. $res = Database::query($sql);
  1949. if(Database::num_rows($res)>0)
  1950. {
  1951. while($row = Database::fetch_array($res))
  1952. {
  1953. $orig_start = $row['orig_start'];
  1954. $orig_end = $row['orig_start'];
  1955. $repeat_type = $row['cal_type'];
  1956. switch($repeat_type)
  1957. {
  1958. case 'daily':
  1959. //we are in the daily view, so if this element is repeated daily and
  1960. //the repetition is still active today (which is a condition of the SQL query)
  1961. //then the event happens today. Just build today's timestamp for start and end
  1962. $time_orig_h = date('H',$orig_start);
  1963. $time_orig_m = date('i',$orig_start);
  1964. $time_orig_s = date('s',$orig_start);
  1965. $int_time = (($time_orig_h*60)+$time_orig_m)*60+$time_orig_s; //time in seconds since 00:00:00
  1966. $span = $orig_end - $orig_start; //total seconds between start and stop of original event
  1967. $current_start =$start + $int_time; //unixtimestamp start of today's event
  1968. $current_stop = $start+$int_time+$span; //unixtimestamp stop of today's event
  1969. $events[] = array($course_info['id'],$row['id'],$current_start,$current_stop,$row['title'],$row['content']);
  1970. break;
  1971. case 'weekly':
  1972. $time_orig = date('Y/n/W/j/N/G/i/s',$orig_start);
  1973. list($y_orig,$m_orig,$w_orig,$d_orig,$dw_orig,$h_orig,$n_orig,$s_orig) = split('/',$time_orig);
  1974. $time_now = date('Y/n/W/j/N/G/i/s',$end);
  1975. list($y_now,$m_now,$w_now,$d_now,$dw_now,$h_now,$n_now,$s_now) = split('/',$time_now);
  1976. if((($y_now>$y_orig) OR (($y_now == $y_orig) && ($w_now>$w_orig))) && ($dw_orig == $dw_now))
  1977. { //if the event is after the original (at least one week) and the day of the week is the same
  1978. $time_orig_end = date('Y/n/W/j/N/G/i/s',$orig_end);
  1979. 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);
  1980. $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']);
  1981. }
  1982. break;
  1983. case 'monthlyByDate':
  1984. $time_orig = date('Y/n/j/G/i/s',$orig_start);
  1985. list($y_orig,$m_orig,$d_orig,$h_orig,$n_orig,$s_orig) = split('/',$time_orig);
  1986. $time_now = date('Y/n/j/G/i/s',$end);
  1987. list($y_now,$m_now,$d_now,$h_now,$n_now,$s_now) = split('/',$time_now);
  1988. if((($y_now>$y_orig) OR (($y_now == $y_orig) && ($m_now>$m_orig))) && ($d_orig == $d_now))
  1989. {
  1990. $time_orig_end = date('Y/n/j/G/i/s',$orig_end);
  1991. list($y_orig_e,$m_orig_e,$d_orig_e,$h_orig_e,$n_orig_e,$s_orig_e) = split('/',$time_orig_end);
  1992. $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']);
  1993. }
  1994. break;
  1995. case 'monthlyByDayR':
  1996. //not implemented yet
  1997. break;
  1998. case 'monthlyByDay':
  1999. //not implemented yet
  2000. break;
  2001. case 'yearly':
  2002. $time_orig = date('Y/n/j/z/G/i/s',$orig_start);
  2003. list($y_orig,$m_orig,$d_orig,$dy_orig,$h_orig,$n_orig,$s_orig) = split('/',$time_orig);
  2004. $time_now = date('Y/n/j/z/G/i/s',$end);
  2005. list($y_now,$m_now,$d_now,$dy_now,$h_now,$n_now,$s_now) = split('/',$time_now);
  2006. if(($y_now>$y_orig) && ($dy_orig == $dy_now))
  2007. {
  2008. $time_orig_end = date('Y/n/j/G/i/s',$orig_end);
  2009. 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);
  2010. $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']);
  2011. }
  2012. break;
  2013. default:
  2014. break;
  2015. }
  2016. }
  2017. }
  2018. return $events;
  2019. }
  2020. /**
  2021. * Get repeated events of a course between two dates (timespan of a week).
  2022. * Returns an array containing the events
  2023. * @param string Course info array (as returned by api_get_course_info())
  2024. * @param int UNIX timestamp of span start. Defaults 0, later transformed into today's start
  2025. * @param int UNIX timestamp. Defaults to 0, later transformed into today's end
  2026. * @param array A set of parameters to alter the SQL query
  2027. * @return array [int] => [course_id,parent_event_id,start_date,end_date,title,description]
  2028. */
  2029. function get_repeated_events_week_view($course_info,$start=0,$end=0,$params)
  2030. {
  2031. $events = array();
  2032. //block $end if higher than 2038 -- PHP doesn't go past that
  2033. if($end>2145934800){$end = 2145934800;}
  2034. //initialise all values
  2035. $y=0;
  2036. $m=0;
  2037. $d=0;
  2038. if($start == 0 or $end == 0)
  2039. {
  2040. $time = time();
  2041. $dw = date('w',$time);
  2042. $week_start = $time - (($dw-1)*86400);
  2043. $y = date('Y',$week_start);
  2044. $m = date('m',$week_start);
  2045. $d = date('j',$week_start);
  2046. $w = date('W',$week_start);
  2047. }
  2048. if($start==0)
  2049. {
  2050. $start = mktime(0,0,0,$m,$d,$y);
  2051. }
  2052. $db_start = date('Y-m-d H:i:s',$start);
  2053. if($end==0)
  2054. {
  2055. $end = $start+(86400*7)-1; //start of week, more 7 days, minus 1 second to get back to the previoyus day
  2056. }
  2057. //$db_end = date('Y-m-d H:i:s',$end);
  2058. $t_cal = Database::get_main_table(TABLE_MAIN_SYSTEM_CALENDAR);
  2059. //$t_cal_repeat = Database::get_course_table(TABLE_AGENDA_REPEAT,$course_info['dbName']);
  2060. //$t_ip = Database::get_course_table(TABLE_ITEM_PROPERTY,$course_info['dbName']);
  2061. $sql = "SELECT c.id, c.title, c.content, " .
  2062. " UNIX_TIMESTAMP(c.start_date) as orig_start, UNIX_TIMESTAMP(c.end_date) as orig_end " .
  2063. " FROM ". $t_cal ."
  2064. AS c WHERE c.start_date <= '$db_start' "
  2065. .(!empty($params['conditions'])?$params['conditions']:'')
  2066. .(!empty($params['groupby'])?' GROUP BY '.$params['groupby']:'')
  2067. .(!empty($params['orderby'])?' ORDER BY '.$params['orderby']:'');
  2068. $res = Database::query($sql);
  2069. if(Database::num_rows($res)>0)
  2070. {
  2071. while($row = Database::fetch_array($res))
  2072. {
  2073. $orig_start = $row['orig_start'];
  2074. $orig_end = $row['orig_end'];
  2075. $repeat_type = $row['cal_type'];
  2076. switch($repeat_type)
  2077. {
  2078. case 'daily':
  2079. $time_orig_h = date('H',$orig_start);
  2080. $time_orig_m = date('i',$orig_start);
  2081. $time_orig_s = date('s',$orig_start);
  2082. $int_time = (($time_orig_h*60)+$time_orig_m)*60+$time_orig_s; //time in seconds since 00:00:00
  2083. $span = $orig_end - $orig_start; //total seconds between start and stop of original event
  2084. for($i=0;$i<7;$i++)
  2085. {
  2086. $current_start = $start + ($i*86400) + $int_time; //unixtimestamp start of today's event
  2087. $current_stop = $start + ($i*86400) + $int_time + $span; //unixtimestamp stop of today's event
  2088. $events[] = array($course_info['id'],$row['id'],$current_start,$current_stop,$row['title'],$row['content']);
  2089. }
  2090. break;
  2091. case 'weekly':
  2092. $time_orig = date('Y/n/W/j/N/G/i/s',$orig_start);
  2093. list($y_orig,$m_orig,$w_orig,$d_orig,$dw_orig,$h_orig,$n_orig,$s_orig) = split('/',$time_orig);
  2094. $time_now = date('Y/n/W/j/N/G/i/s',$end);
  2095. list($y_now,$m_now,$w_now,$d_now,$dw_now,$h_now,$n_now,$s_now) = split('/',$time_now);
  2096. if((($y_now>$y_orig) OR (($y_now == $y_orig) && ($w_now>$w_orig))))
  2097. { //if the event is after the original (at least one week) and the day of the week is the same
  2098. $time_orig_end = date('Y/n/W/j/N/G/i/s',$orig_end);
  2099. 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);
  2100. $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']);
  2101. }
  2102. break;
  2103. case 'monthlyByDate':
  2104. $time_orig = date('Y/n/W/j/G/i/s',$orig_start);
  2105. list($y_orig,$m_orig,$w_orig,$d_orig,$h_orig,$n_orig,$s_orig) = split('/',$time_orig);
  2106. $time_now = date('Y/n/W/j/G/i/s',$end);
  2107. list($y_now,$m_now,$w_now,$d_now,$h_now,$n_now,$s_now) = split('/',$time_now);
  2108. $event_repetition_time = mktime($h_orig,$n_orig,$s_orig,$m_now,$d_orig,$y_now);
  2109. if((($y_now>$y_orig) OR (($y_now == $y_orig) && ($m_now>$m_orig))) && ($start<$event_repetition_time && $event_repetition_time<$end))
  2110. { //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
  2111. $time_orig_end = date('Y/n/j/G/i/s',$orig_end);
  2112. list($y_orig_e,$m_orig_e,$d_orig_e,$h_orig_e,$n_orig_e,$s_orig_e) = split('/',$time_orig_end);
  2113. $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']);
  2114. }
  2115. break;
  2116. case 'monthlyByDayR':
  2117. //not implemented yet
  2118. break;
  2119. case 'monthlyByDay':
  2120. //not implemented yet
  2121. break;
  2122. case 'yearly':
  2123. $time_orig = date('Y/n/j/z/G/i/s',$orig_start);
  2124. list($y_orig,$m_orig,$d_orig,$dy_orig,$h_orig,$n_orig,$s_orig) = split('/',$time_orig);
  2125. $time_now = date('Y/n/j/z/G/i/s',$end);
  2126. list($y_now,$m_now,$d_now,$dy_now,$h_now,$n_now,$s_now) = split('/',$time_now);
  2127. $event_repetition_time = mktime($h_orig,$n_orig,$s_orig,$m_orig,$d_orig,$y_now);
  2128. if((($y_now>$y_orig) && ($start<$event_repetition_time && $event_repetition_time<$end)))
  2129. {
  2130. $time_orig_end = date('Y/n/j/G/i/s',$orig_end);
  2131. 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);
  2132. $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']);
  2133. }
  2134. break;
  2135. default:
  2136. break;
  2137. }
  2138. }
  2139. }
  2140. return $events;
  2141. }
  2142. /**
  2143. * Get repeated events of a course between two dates (timespan of a month).
  2144. * Returns an array containing the events
  2145. * @param string Course info array (as returned by api_get_course_info())
  2146. * @param int UNIX timestamp of span start. Defaults 0, later transformed into today's start
  2147. * @param int UNIX timestamp. Defaults to 0, later transformed into today's end
  2148. * @param array A set of parameters to alter the SQL query
  2149. * @return array [int] => [course_id,parent_event_id,start_date,end_date,title,description]
  2150. */
  2151. function get_repeated_events_month_view($course_info,$start=0,$end=0,$params)
  2152. {
  2153. $events = array();
  2154. //block $end if higher than 2038 -- PHP doesn't go past that
  2155. if($end>2145934800){$end = 2145934800;}
  2156. //initialise all values
  2157. $y=0;
  2158. $m=0;
  2159. $d=0;
  2160. if($start == 0 or $end == 0)
  2161. {
  2162. $time = time();
  2163. $y = date('Y');
  2164. $m = date('m');
  2165. }
  2166. if($start==0)
  2167. {
  2168. $start = mktime(0,0,0,$m,1,$y);
  2169. }
  2170. $db_start = date('Y-m-d H:i:s',$start);
  2171. if($end==0)
  2172. {
  2173. if($m==12)
  2174. {
  2175. $end = mktime(0,0,0,1,1,$y+1)-1; //start of next month, minus 1 second to get back to the previoyus day
  2176. }
  2177. else
  2178. {
  2179. $end = mktime(0,0,0,$m+1,1,$y)-1;
  2180. }
  2181. }
  2182. //$db_end = date('Y-m-d H:i:s',$end);
  2183. $t_cal = Database::get_main_table(TABLE_MAIN_SYSTEM_CALENDAR);
  2184. $t_cal_repeat = Database::get_course_table(TABLE_AGENDA_REPEAT,$course_info['dbName']);
  2185. $t_ip = Database::get_course_table(TABLE_ITEM_PROPERTY,$course_info['dbName']);
  2186. $sql = "SELECT c.id, c.title, c.content, " .
  2187. " UNIX_TIMESTAMP(c.start_date) as orig_start, UNIX_TIMESTAMP(c.end_date) as orig_end, " .
  2188. " cr.cal_type, cr.cal_end " .
  2189. " FROM $t_cal c, $t_cal_repeat cr, $t_ip as item_property " .
  2190. " WHERE cr.cal_end >= $start " .
  2191. " AND cr.cal_id = c.id " .
  2192. " AND item_property.ref = c.id ".
  2193. " AND item_property.tool = '".TOOL_CALENDAR_EVENT."' ".
  2194. " AND c.start_date <= '$db_start' "
  2195. .(!empty($params['conditions'])?$params['conditions']:'')
  2196. .(!empty($params['groupby'])?' GROUP BY '.$params['groupby']:'')
  2197. .(!empty($params['orderby'])?' ORDER BY '.$params['orderby']:'');
  2198. $res = Database::query($sql);
  2199. if(Database::num_rows($res)>0)
  2200. {
  2201. while($row = Database::fetch_array($res))
  2202. {
  2203. $orig_start = $row['orig_start'];
  2204. $orig_end = $row['orig_end'];
  2205. $repeat_type = $row['cal_type'];
  2206. switch($repeat_type)
  2207. {
  2208. case 'daily':
  2209. $time_orig_h = date('H',$orig_start);
  2210. $time_orig_m = date('i',$orig_start);
  2211. $time_orig_s = date('s',$orig_start);
  2212. $month_last_day = date('d',$end);
  2213. $int_time = (($time_orig_h*60)+$time_orig_m)*60+$time_orig_s; //time in seconds since 00:00:00
  2214. $span = $orig_end - $orig_start; //total seconds between start and stop of original event
  2215. for($i=0;$i<$month_last_day;$i++)
  2216. {
  2217. $current_start = $start + ($i*86400) + $int_time; //unixtimestamp start of today's event
  2218. $current_stop = $start + ($i*86400) + $int_time + $span; //unixtimestamp stop of today's event
  2219. $events[] = array($course_info['id'],$row['id'],$current_start,$current_stop,$row['title'],$row['content']);
  2220. }
  2221. break;
  2222. case 'weekly':
  2223. //A weekly repeated event is very difficult to catch in a month view,
  2224. //because weeks start before or at the same time as the first day of the month
  2225. //The same can be said for the end of the month.
  2226. // The idea is thus to get all possible events by enlarging the scope of
  2227. // the month to get complete weeks covering the complete month, and then take out
  2228. // the events that start before the 1st ($start) or after the last day of the month ($end)
  2229. $time_orig = date('Y/n/W/j/N/G/i/s',$orig_start);
  2230. list($y_orig,$m_orig,$w_orig,$d_orig,$dw_orig,$h_orig,$n_orig,$s_orig) = split('/',$time_orig);
  2231. $time_orig_end = date('Y/n/W/j/N/G/i/s',$orig_end);
  2232. 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);
  2233. $time_now = date('Y/n/W/j/N/G/i/s',$end);
  2234. list($y_now,$m_now,$w_now,$d_now,$dw_now,$h_now,$n_now,$s_now) = split('/',$time_now);
  2235. $month_first_week = date('W',$start);
  2236. $month_last_week = date('W',$end);
  2237. if(($y_now>$y_orig) OR (($y_now == $y_orig) && ($w_now>$w_orig)))
  2238. { //if the event is after the original (at least one week) and the day of the week is the same
  2239. for($i=$month_first_week;$i<=$month_last_week;$i++)
  2240. {
  2241. //the "day of the week" of repetition is the same as the $dw_orig,
  2242. //so to get the "day of the month" from the "day of the week", we have
  2243. //to get the first "day of the week" for this week and add the number
  2244. //of days (in seconds) to reach the $dw_orig
  2245. //example: the first week spans between the 28th of April (Monday) to the
  2246. // 4th of May (Sunday). The event occurs on the 2nd day of each week.
  2247. // This means the event occurs on 29/4, 6/5, 13/5, 20/5 and 27/5.
  2248. // We want to get all of these, and then reject 29/4 because it is out
  2249. // of the month itself.
  2250. //First, to get the start time of the first day of the month view (even if
  2251. // the day is from the past month), we get the month start date (1/5) and
  2252. // see which day of the week it is, and subtract the number of days necessary
  2253. // to get back to the first day of the week.
  2254. $month_first_day_weekday = date('N',$start);
  2255. $first_week_start = $start - (($month_first_day_weekday-1)*86400);
  2256. //Second, we add the week day of the original event, so that we have an
  2257. // absolute time that represents the first repetition of the event in
  2258. // our 4- or 5-weeks timespan
  2259. $first_event_repeat_start = $first_week_start + (($dw_orig-1)*86400) + ($h_orig*3600) + ($n_orig*60) + $s_orig;
  2260. //Third, we start looping through the repetitions and see if they are between
  2261. // $start and $end
  2262. for($i = $first_event_repeat_start; $i<=$end; $i+=604800)
  2263. {
  2264. if($start<$i && $i<$end)
  2265. {
  2266. list($y_repeat,$m_repeat,$d_repeat,$h_repeat,$n_repeat,$s_repeat) = split('/',date('Y/m/j/H/i/s',$i));
  2267. $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']);
  2268. }
  2269. }
  2270. }
  2271. }
  2272. break;
  2273. case 'monthlyByDate':
  2274. $time_orig = date('Y/n/W/j/G/i/s',$orig_start);
  2275. list($y_orig,$m_orig,$w_orig,$d_orig,$h_orig,$n_orig,$s_orig) = split('/',$time_orig);
  2276. $time_now = date('Y/n/W/j/G/i/s',$end);
  2277. list($y_now,$m_now,$w_now,$d_now,$h_now,$n_now,$s_now) = split('/',$time_now);
  2278. $event_repetition_time = mktime($h_orig,$n_orig,$s_orig,$m_now,$d_orig,$y_now);
  2279. if(($y_now>$y_orig) OR (($y_now == $y_orig) && ($m_now>$m_orig)))
  2280. { //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
  2281. $time_orig_end = date('Y/n/j/G/i/s',$orig_end);
  2282. list($y_orig_e,$m_orig_e,$d_orig_e,$h_orig_e,$n_orig_e,$s_orig_e) = split('/',$time_orig_end);
  2283. $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']);
  2284. }
  2285. break;
  2286. case 'monthlyByDayR':
  2287. //not implemented yet
  2288. break;
  2289. case 'monthlyByDay':
  2290. //not implemented yet
  2291. break;
  2292. case 'yearly':
  2293. $time_orig = date('Y/n/j/z/G/i/s',$orig_start);
  2294. list($y_orig,$m_orig,$d_orig,$dy_orig,$h_orig,$n_orig,$s_orig) = split('/',$time_orig);
  2295. $time_now = date('Y/n/j/z/G/i/s',$end);
  2296. list($y_now,$m_now,$d_now,$dy_now,$h_now,$n_now,$s_now) = split('/',$time_now);
  2297. $event_repetition_time = mktime($h_orig,$n_orig,$s_orig,$m_orig,$d_orig,$y_now);
  2298. if((($y_now>$y_orig) && ($start<$event_repetition_time && $event_repetition_time<$end)))
  2299. {
  2300. $time_orig_end = date('Y/n/j/G/i/s',$orig_end);
  2301. 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);
  2302. $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']);
  2303. }
  2304. break;
  2305. default:
  2306. break;
  2307. }
  2308. }
  2309. }
  2310. return $events;
  2311. }
  2312. /**
  2313. * Get repeated events of a course between two dates (1 year timespan). Used for the list display.
  2314. * 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)
  2315. * Returns an array containing the events
  2316. * @param string Course info array (as returned by api_get_course_info())
  2317. * @param int UNIX timestamp of span start. Defaults 0, later transformed into today's start
  2318. * @param int UNIX timestamp. Defaults to 0, later transformed into today's end
  2319. * @param array A set of parameters to alter the SQL query
  2320. * @return array [int] => [course_id,parent_event_id,start_date,end_date,title,description]
  2321. */
  2322. function get_repeated_events_list_view($course_info,$start=0,$end=0,$params)
  2323. {
  2324. $events = array();
  2325. //block $end if higher than 2038 -- PHP doesn't go past that
  2326. if($end>2145934800){$end = 2145934800;}
  2327. //initialise all values
  2328. $y=0;
  2329. $m=0;
  2330. $d=0;
  2331. if(empty($start) or empty($end))
  2332. {
  2333. $time = time();
  2334. $y = date('Y');
  2335. $m = date('m');
  2336. }
  2337. if(empty($start))
  2338. {
  2339. $start = mktime(0, 0, 0, $m, 1, $y);
  2340. }
  2341. $db_start = date('Y-m-d H:i:s', $start);
  2342. if(empty($end))
  2343. {
  2344. $end = mktime(0, 0, 0, 1, 1, 2037);
  2345. }
  2346. //$db_end = date('Y-m-d H:i:s',$end);
  2347. $t_cal = Database::get_main_table(TABLE_MAIN_SYSTEM_CALENDAR,$course_info['dbName']);
  2348. $t_cal_repeat = Database::get_course_table(TABLE_AGENDA_REPEAT,$course_info['dbName']);
  2349. $t_ip = Database::get_course_table(TABLE_ITEM_PROPERTY,$course_info['dbName']);
  2350. $sql = "SELECT c.id, c.title, c.content, " .
  2351. " UNIX_TIMESTAMP(c.start_date) as orig_start, UNIX_TIMESTAMP(c.end_date) as orig_end, " .
  2352. " cr.cal_type, cr.cal_end " .
  2353. " FROM $t_cal c, $t_cal_repeat cr, $t_ip as item_property " .
  2354. " WHERE cr.cal_end >= $start " .
  2355. " AND cr.cal_id = c.id " .
  2356. " AND item_property.ref = c.id ".
  2357. " AND item_property.tool = '".TOOL_CALENDAR_EVENT."' ".
  2358. " AND c.start_date <= '$db_start' "
  2359. .(!empty($params['conditions'])?$params['conditions']:'')
  2360. .(!empty($params['groupby'])?' GROUP BY '.$params['groupby']:'')
  2361. .(!empty($params['orderby'])?' ORDER BY '.$params['orderby']:'');
  2362. $res = Database::query($sql);
  2363. if(Database::num_rows($res)>0)
  2364. {
  2365. while($row = Database::fetch_array($res))
  2366. {
  2367. $orig_start = $row['orig_start'];
  2368. $orig_end = $row['orig_end'];
  2369. $repeat_type = $row['cal_type'];
  2370. $repeat_end = $row['cal_end'];
  2371. switch($repeat_type)
  2372. {
  2373. case 'daily':
  2374. $time_orig_h = date('H',$orig_start);
  2375. $time_orig_m = date('i',$orig_start);
  2376. $time_orig_s = date('s',$orig_start);
  2377. $span = $orig_end - $orig_start; //total seconds between start and stop of original event
  2378. for($i=$orig_start+86400;($i<$end && $i<=$repeat_end);$i+=86400)
  2379. {
  2380. $current_start = $i; //unixtimestamp start of today's event
  2381. $current_stop = $i + $span; //unixtimestamp stop of today's event
  2382. $events[] = array($course_info['id'],$row['id'],$current_start,$current_stop,$row['title'],$row['content']);
  2383. }
  2384. break;
  2385. case 'weekly':
  2386. //A weekly repeated event is very difficult to catch in a month view,
  2387. // because weeks start before or at the same time as the first day of the month
  2388. //The same can be said for the end of the month.
  2389. // The idea is thus to get all possible events by enlarging the scope of
  2390. // the month to get complete weeks covering the complete month, and then take out
  2391. // the events that start before the 1st ($start) or after the last day of the month ($end)
  2392. $time_orig = date('Y/n/W/j/N/G/i/s',$orig_start);
  2393. list($y_orig,$m_orig,$w_orig,$d_orig,$dw_orig,$h_orig,$n_orig,$s_orig) = split('/',$time_orig);
  2394. $time_orig_end = date('Y/n/W/j/N/G/i/s',$orig_end);
  2395. 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);
  2396. $time_now = date('Y/n/W/j/N/G/i/s',$end);
  2397. list($y_now,$m_now,$w_now,$d_now,$dw_now,$h_now,$n_now,$s_now) = split('/',$time_now);
  2398. if($w_now==52)
  2399. {
  2400. ++$y_now;
  2401. $w_now=1;
  2402. }
  2403. else
  2404. {
  2405. ++$w_now;
  2406. }
  2407. $month_first_week = date('W',$start);
  2408. $total_weeks = ((date('Y',$end)-$y_orig)-1)*52;
  2409. $month_last_week = $month_first_week + $total_weeks;
  2410. if(($y_now>$y_orig) OR (($y_now == $y_orig) && ($w_now>$w_orig)))
  2411. { //if the event is after the original (at least one week) and the day of the week is the same
  2412. //for($i=$month_first_week;($i<=$month_last_week && $i<1000);$i++)
  2413. //{
  2414. /*
  2415. The "day of the week" of repetition is the same as the $dw_orig,
  2416. so to get the "day of the month" from the "day of the week", we have
  2417. to get the first "day of the week" for this week and add the number
  2418. of days (in seconds) to reach the $dw_orig
  2419. example: the first week spans between the 28th of April (Monday) to the
  2420. 4th of May (Sunday). The event occurs on the 2nd day of each week.
  2421. This means the event occurs on 29/4, 6/5, 13/5, 20/5 and 27/5.
  2422. We want to get all of these, and then reject 29/4 because it is out
  2423. of the month itself.
  2424. First, to get the start time of the first day of the month view (even if
  2425. the day is from the past month), we get the month start date (1/5) and
  2426. see which day of the week it is, and subtract the number of days necessary
  2427. to get back to the first day of the week.
  2428. */
  2429. $month_first_day_weekday = date('N',$start);
  2430. $first_week_start = $start - (($month_first_day_weekday-1)*86400);
  2431. //Second, we add the week day of the original event, so that we have an
  2432. // absolute time that represents the first repetition of the event in
  2433. // our 4- or 5-weeks timespan
  2434. $first_event_repeat_start = $first_week_start + (($dw_orig-1)*86400) + ($h_orig*3600) + ($n_orig*60) + $s_orig;
  2435. //Third, we start looping through the repetitions and see if they are between
  2436. // $start and $end
  2437. for($i = $first_event_repeat_start; ($i<=$end && $i<=$repeat_end); $i+=604800)
  2438. {
  2439. if($start<$i && $i<=$end && $i<=$repeat_end)
  2440. {
  2441. list($y_repeat,$m_repeat,$d_repeat,$h_repeat,$n_repeat,$s_repeat) = split('/',date('Y/m/j/H/i/s',$i));
  2442. $new_start_time = mktime($h_orig,$n_orig,$s_orig,$m_now,$d_orig,$y_now);
  2443. $new_stop_time = mktime($h_orig_e,$n_orig_e,$s_orig_e,$m_now,$d_orig_e,$y_now);
  2444. $events[] = array($course_info['id'], $row['id'], $new_start_time, $new_stop_time, $row['title'], $row['content']);
  2445. }
  2446. $time_now = date('Y/n/W/j/N/G/i/s',$i+604800);
  2447. list($y_now,$m_now,$w_now,$d_now,$dw_now,$h_now,$n_now,$s_now) = split('/',$time_now);
  2448. }
  2449. //}
  2450. }
  2451. break;
  2452. case 'monthlyByDate':
  2453. $time_orig = date('Y/n/W/j/G/i/s',$orig_start);
  2454. list($y_orig,$m_orig,$w_orig,$d_orig,$h_orig,$n_orig,$s_orig) = split('/',$time_orig);
  2455. $time_now = date('Y/n/W/j/G/i/s',$start);
  2456. list($y_now,$m_now,$w_now,$d_now,$h_now,$n_now,$s_now) = split('/',$time_now);
  2457. //make sure we are one month ahead (to avoid being the same month as the original event)
  2458. if($m_now==12)
  2459. {
  2460. ++$y_now;
  2461. $m_now = 1;
  2462. }
  2463. else
  2464. {
  2465. ++$m_now;
  2466. }
  2467. $time_orig_end = date('Y/n/j/G/i/s',$orig_end);
  2468. list($y_orig_e,$m_orig_e,$d_orig_e,$h_orig_e,$n_orig_e,$s_orig_e) = split('/',$time_orig_end);
  2469. $event_repetition_time = mktime($h_orig,$n_orig,$s_orig,$m_now,$d_orig,$y_now);
  2470. $diff = $orig_end - $orig_start;
  2471. while((($y_now>$y_orig) OR (($y_now == $y_orig) && ($m_now>$m_orig))) && ($event_repetition_time < $end) && ($event_repetition_time < $repeat_end))
  2472. { //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
  2473. $new_start_time = mktime($h_orig,$n_orig,$s_orig,$m_now,$d_orig,$y_now);
  2474. $new_stop_time = mktime($h_orig_e,$n_orig_e,$s_orig_e,$m_now,$d_orig_e,$y_now);
  2475. $events[] = array($course_info['id'],$row['id'],$new_start_time,$new_stop_time,$row['title'],$row['content']);
  2476. if($m_now==12)
  2477. {
  2478. ++$y_now;
  2479. $m_now = 1;
  2480. }
  2481. else
  2482. {
  2483. ++$m_now;
  2484. }
  2485. $event_repetition_time = mktime($h_orig,$n_orig,$s_orig,$m_now,$d_orig,$y_now);
  2486. }
  2487. break;
  2488. case 'monthlyByDayR':
  2489. //not implemented yet
  2490. break;
  2491. case 'monthlyByDay':
  2492. //not implemented yet
  2493. break;
  2494. case 'yearly':
  2495. $time_orig = date('Y/n/j/z/G/i/s',$orig_start);
  2496. list($y_orig,$m_orig,$d_orig,$dy_orig,$h_orig,$n_orig,$s_orig) = split('/',$time_orig);
  2497. $time_now = date('Y/n/j/z/G/i/s',$end);
  2498. list($y_now,$m_now,$d_now,$dy_now,$h_now,$n_now,$s_now) = split('/',$time_now);
  2499. $event_repetition_time = mktime($h_orig,$n_orig,$s_orig,$m_orig,$d_orig,$y_now);
  2500. while((($y_now>$y_orig) && ($start<$event_repetition_time && $event_repetition_time<$end && $event_repetition_time<$repeat_end)))
  2501. {
  2502. $time_orig_end = date('Y/n/j/G/i/s',$orig_end);
  2503. 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);
  2504. $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']);
  2505. ++$y_now;
  2506. $event_repetition_time = mktime($h_orig,$n_orig,$s_orig,$m_orig,$d_orig,$y_now);
  2507. }
  2508. break;
  2509. default:
  2510. break;
  2511. }
  2512. }
  2513. }
  2514. return $events;
  2515. }
  2516. /**
  2517. * Tells if an agenda item is repeated
  2518. * @param string Course database
  2519. * @param int The agenda item
  2520. * @return boolean True if repeated, false otherwise
  2521. */
  2522. function is_repeated_event($id,$course=null)
  2523. {
  2524. if(empty($course))
  2525. {
  2526. $course_info = api_get_course_info();
  2527. $course = $course_info['dbName'];
  2528. }
  2529. $id = (int) $id;
  2530. //$t_agenda_repeat = Database::get_course_table(TABLE_AGENDA_REPEAT,$course);
  2531. $sql = "SELECT * FROM $t_agenda_repeat WHERE cal_id = $id";
  2532. $res = Database::query($sql);
  2533. if(Database::num_rows($res)>0)
  2534. {
  2535. return true;
  2536. }
  2537. return false;
  2538. }
  2539. /**
  2540. * Adds x weeks to a UNIX timestamp
  2541. * @param int The timestamp
  2542. * @param int The number of weeks to add
  2543. * @return int The new timestamp
  2544. */
  2545. function add_week($timestamp,$num=1)
  2546. {
  2547. return $timestamp + $num*604800;
  2548. }
  2549. /**
  2550. * Adds x months to a UNIX timestamp
  2551. * @param int The timestamp
  2552. * @param int The number of years to add
  2553. * @return int The new timestamp
  2554. */
  2555. function add_month($timestamp,$num=1)
  2556. {
  2557. list($y, $m, $d, $h, $n, $s) = split('/',date('Y/m/d/h/i/s',$timestamp));
  2558. if($m+$num>12)
  2559. {
  2560. $y += floor($num/12);
  2561. $m += $num%12;
  2562. }
  2563. else
  2564. {
  2565. $m += $num;
  2566. }
  2567. return mktime($h, $n, $s, $m, $d, $y);
  2568. }
  2569. /**
  2570. * Adds x years to a UNIX timestamp
  2571. * @param int The timestamp
  2572. * @param int The number of years to add
  2573. * @return int The new timestamp
  2574. */
  2575. function add_year($timestamp,$num=1)
  2576. {
  2577. list($y, $m, $d, $h, $n, $s) = split('/',date('Y/m/d/h/i/s',$timestamp));
  2578. return mktime($h, $n, $s, $m, $d, $y+$num);
  2579. }
  2580. /**
  2581. * Adds an agenda item in the database. Similar to store_new_agenda_item() except it takes parameters
  2582. * @param array Course info
  2583. * @param string Event title
  2584. * @param string Event content/description
  2585. * @param string Start date
  2586. * @param string End date
  2587. * @param array List of groups to which this event is added
  2588. * @param int Parent id (optional)
  2589. * @return int The new item's DB ID
  2590. */
  2591. function agenda_add_item($title, $content, $db_start_date, $db_end_date) {
  2592. $user_id = api_get_user_id();
  2593. $t_agenda = Database::get_main_table(TABLE_MAIN_SYSTEM_CALENDAR);
  2594. // some filtering of the input data
  2595. $title = Database::escape_string($title); // no html allowed in the title
  2596. $content = Database::escape_string($content);
  2597. $db_start_date = api_get_utc_datetime($db_start_date);
  2598. $start_date = Database::escape_string($db_start_date);
  2599. $db_end_date = api_get_utc_datetime($db_end_date);
  2600. $end_date = Database::escape_string($db_end_date);
  2601. // check if exists in calendar_event table
  2602. $sql = "SELECT * FROM $t_agenda WHERE title='$title' AND content = '$content' AND start_date = '$start_date' AND end_date = '$end_date' ";
  2603. $result = Database::query($sql);
  2604. $count = Database::num_rows($result);
  2605. if ($count > 0) {
  2606. return false;
  2607. }
  2608. $sql = "INSERT INTO $t_agenda (title,content, start_date, end_date, access_url_id)
  2609. VALUES ('".$title."','".$content."', '".$start_date."','".$end_date."', '".api_get_current_access_url_id()."')";
  2610. $result = Database::query($sql);
  2611. $last_id = Database::insert_id();
  2612. return $last_id;
  2613. }
  2614. /**
  2615. * Adds a repetitive item to the database
  2616. * @param array Course info
  2617. * @param int The original event's id
  2618. * @param string Type of repetition
  2619. * @param int Timestamp of end of repetition (repeating until that date)
  2620. * @param array Original event's destination
  2621. * @return boolean False if error, True otherwise
  2622. */
  2623. function get_calendar_items($month, $year) {
  2624. global $_user, $_course;
  2625. global $is_allowed_to_edit;
  2626. $month=Database::escape_string($month);
  2627. $year=Database::escape_string($year);
  2628. // database variables
  2629. $TABLEAGENDA = Database::get_main_table(TABLE_MAIN_SYSTEM_CALENDAR);
  2630. //$TABLE_ITEM_PROPERTY=Database::get_course_table(TABLE_ITEM_PROPERTY);
  2631. $month_first_day = mktime(0,0,0,$month,1,$year);
  2632. $month_last_day = mktime(0,0,0,$month+1,1,$year)-1;
  2633. if ($month==12) {
  2634. $month_last_day = mktime(0,0,0,1,1,$year+1)-1;
  2635. }
  2636. $repeats = array();
  2637. $data=array();
  2638. if (api_is_allowed_to_edit()) {
  2639. $sql="SELECT DISTINCT *
  2640. FROM ".$TABLEAGENDA." agenda
  2641. WHERE MONTH(start_date)='".$month."' AND YEAR(start_date)='".$year."'";
  2642. global $_configuration;
  2643. $current_access_url_id = 1;
  2644. if ($_configuration['multiple_access_urls']) {
  2645. $current_access_url_id = api_get_current_access_url_id();
  2646. }
  2647. $sql .= " AND access_url_id = '$current_access_url_id' ";
  2648. $sql .= "GROUP BY id ORDER BY start_date ";
  2649. $result=Database::query($sql);
  2650. while ($row=Database::fetch_array($result)) {
  2651. $datum_item=(int)substr($row["start_date"],8,2);
  2652. $data[$datum_item][intval($datum_item)][] = $row;
  2653. }
  2654. }
  2655. return $data;
  2656. }
  2657. /**
  2658. * This function is not been used or deprecated
  2659. */
  2660. function agenda_add_repeat_item($course_info,$orig_id,$type,$end,$orig_dest)
  2661. {/*
  2662. $t_agenda = Database::get_main_table(TABLE_MAIN_SYSTEM_CALENDAR,$course_info['dbName']);
  2663. // $t_agenda_r = Database::get_course_table(TABLE_AGENDA_REPEAT,$course_info['dbName']);
  2664. //$sql = "SELECT title, content, UNIX_TIMESTAMP(start_date) as sd, UNIX_TIMESTAMP(end_date) as ed FROM $t_agenda WHERE id = $orig_id";
  2665. $sql = "SELECT title, content, start_date as sd, end_date as ed FROM $t_agenda WHERE id = $orig_id";
  2666. $res = Database::query($sql);
  2667. if(Database::num_rows($res)!==1){return false;}
  2668. $row = Database::fetch_array($res);
  2669. //$orig_start = $row['sd'];
  2670. $orig_start = mktime(substr($row['sd'],11,2),substr($row['sd'],14,2),substr($row['sd'],17,2),substr($row['sd'],5,2),substr($row['sd'],8,2),substr($row['sd'],0,4));
  2671. //$orig_end = $row['ed'];
  2672. $orig_end = mktime(substr($row['ed'],11,2),substr($row['ed'],14,2),substr($row['ed'],17,2),substr($row['ed'],5,2),substr($row['ed'],8,2),substr($row['ed'],0,4));
  2673. $diff = $orig_end - $orig_start;
  2674. $orig_title = $row['title'];
  2675. $orig_content = $row['content'];
  2676. $now = time();
  2677. $type = Database::escape_string($type);
  2678. $end = (int) $end;
  2679. if(1<=$end && $end<=500)
  2680. {
  2681. //we assume that, with this type of value, the user actually gives a count of repetitions
  2682. //and that he wants us to calculate the end date with that (particularly in case of imports from ical)
  2683. switch($type)
  2684. {
  2685. case 'daily':
  2686. $end = $orig_start + (86400*$end);
  2687. break;
  2688. case 'weekly':
  2689. $end = add_week($orig_start,$end);
  2690. break;
  2691. case 'monthlyByDate':
  2692. $end = add_month($orig_start,$end);
  2693. break;
  2694. case 'monthlyByDay':
  2695. //TODO
  2696. break;
  2697. case 'monthlyByDayR':
  2698. //TODO
  2699. break;
  2700. case 'yearly':
  2701. $end = add_year($orig_start,$end);
  2702. break;
  2703. }
  2704. }
  2705. if($end > $now
  2706. && in_array($type,array('daily','weekly','monthlyByDate','monthlyByDay','monthlyByDayR','yearly')))
  2707. {
  2708. $sql = "INSERT INTO $t_agenda_r (cal_id, cal_type, cal_end)" .
  2709. " VALUES ($orig_id,'$type',$end)";
  2710. $res = Database::query($sql);
  2711. switch($type)
  2712. {
  2713. case 'daily':
  2714. for($i = $orig_start + 86400; ($i <= $end); $i += 86400)
  2715. {
  2716. $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);
  2717. }
  2718. break;
  2719. case 'weekly':
  2720. for($i = $orig_start + 604800; ($i <= $end); $i += 604800)
  2721. {
  2722. $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);
  2723. }
  2724. break;
  2725. case 'monthlyByDate':
  2726. $next_start = add_month($orig_start);
  2727. while($next_start <= $end)
  2728. {
  2729. $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);
  2730. $next_start = add_month($next_start);
  2731. }
  2732. break;
  2733. case 'monthlyByDay':
  2734. //not yet implemented
  2735. break;
  2736. case 'monthlyByDayR':
  2737. //not yet implemented
  2738. break;
  2739. case 'yearly':
  2740. $next_start = add_year($orig_start);
  2741. while($next_start <= $end)
  2742. {
  2743. $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);
  2744. $next_start = add_year($next_start);
  2745. }
  2746. break;
  2747. }
  2748. }
  2749. return true;*/
  2750. }
  2751. /**
  2752. * Import an iCal file into the database
  2753. * @param array Course info
  2754. * @return boolean True on success, false otherwise
  2755. */
  2756. function agenda_import_ical($course_info,$file) {
  2757. require_once api_get_path(LIBRARY_PATH).'fileUpload.lib.php';
  2758. $charset = api_get_system_encoding();
  2759. $filepath = api_get_path(SYS_ARCHIVE_PATH).$file['name'];
  2760. if(!@move_uploaded_file($file['tmp_name'],$filepath))
  2761. {
  2762. error_log('Problem moving uploaded file: '.$file['error'].' in '.__FILE__.' line '.__LINE__);
  2763. return false;
  2764. }
  2765. require_once api_get_path(LIBRARY_PATH).'icalcreator/iCalcreator.class.php';
  2766. $ical = new vcalendar();
  2767. $ical->setConfig('directory', dirname($filepath) );
  2768. $ical->setConfig('filename', basename($filepath) );
  2769. $ical->parse();
  2770. //we need to recover: summary, description, dtstart, dtend, organizer, attendee, location (=course name),
  2771. // rrule
  2772. $ve = $ical->getComponent(VEVENT);
  2773. //print_r($ve);
  2774. $ttitle = $ve->getProperty('summary');
  2775. //print_r($ttitle);
  2776. $title = api_convert_encoding($ttitle,$charset,'UTF-8');
  2777. $tdesc = $ve->getProperty('description');
  2778. $desc = api_convert_encoding($tdesc,$charset,'UTF-8');
  2779. $ts = $ve->getProperty('dtstart');
  2780. $start_date = $ts['year'].'-'.$ts['month'].'-'.$ts['day'].' '.$ts['hour'].':'.$ts['min'].':'.$ts['sec'];
  2781. $ts = $ve->getProperty('dtend');
  2782. $end_date = $ts['year'].'-'.$ts['month'].'-'.$ts['day'].' '.$ts['hour'].':'.$ts['min'].':'.$ts['sec'];
  2783. //echo $start_date.' - '.$end_date;
  2784. $organizer = $ve->getProperty('organizer');
  2785. $attendee = $ve->getProperty('attendee');
  2786. $course_name = $ve->getProperty('location');
  2787. //insert the event in our database
  2788. $id = agenda_add_item($course_info,$title,$desc,$start_date,$end_date,$_POST['selectedform']);
  2789. $repeat = $ve->getProperty('rrule');
  2790. if(is_array($repeat) && !empty($repeat['FREQ']))
  2791. {
  2792. $trans = array('DAILY'=>'daily','WEEKLY'=>'weekly','MONTHLY'=>'monthlyByDate','YEARLY'=>'yearly');
  2793. $freq = $trans[$repeat['FREQ']];
  2794. $interval = $repeat['INTERVAL'];
  2795. if(isset($repeat['UNTIL']) && is_array($repeat['UNTIL']))
  2796. {
  2797. $until = mktime(23,59,59,$repeat['UNTIL']['month'],$repeat['UNTIL']['day'],$repeat['UNTIL']['year']);
  2798. $res = agenda_add_repeat_item($course_info,$id,$freq,$until,$_POST['selectedform']);
  2799. }
  2800. //TODO: deal with count
  2801. if(!empty($repeat['COUNT']))
  2802. {
  2803. $count = $repeat['COUNT'];
  2804. $res = agenda_add_repeat_item($course_info,$id,$freq,$count,$_POST['selectedform']);
  2805. }
  2806. }
  2807. return true;
  2808. }
  2809. ?>