calendar.lib.php 126 KB

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