calendar.lib.php 136 KB

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