calendar.lib.php 122 KB

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