calendar.lib.php 120 KB

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