calendar.lib.php 118 KB

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