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. global $MonthsLong;
  1034. $htmlHeadXtra[] = to_javascript();
  1035. // the default values for the forms
  1036. if ($_GET['originalresource'] !== 'no') {
  1037. $day = date('d');
  1038. $month = date('m');
  1039. $year = date('Y');
  1040. $hours = 9;
  1041. $minutes= '00';
  1042. $end_day = date('d');
  1043. $end_month = date('m');
  1044. $end_year = date('Y');
  1045. $end_hours = 17;
  1046. $end_minutes= '00';
  1047. $repeat = false;
  1048. } else {
  1049. // we are coming from the resource linker so there might already have been some information in the form.
  1050. // When we clicked on the button to add resources we stored every form information into a session and now we
  1051. // are doing the opposite thing: getting the information out of the session and putting it into variables to
  1052. // display it in the forms.
  1053. $form_elements=$_SESSION['formelements'];
  1054. $day=$form_elements['day'];
  1055. $month=$form_elements['month'];
  1056. $year=$form_elements['year'];
  1057. $hours=$form_elements['hour'];
  1058. $minutes=$form_elements['minutes'];
  1059. $end_day=$form_elements['end_day'];
  1060. $end_month=$form_elements['end_month'];
  1061. $end_year=$form_elements['end_year'];
  1062. $end_hours=$form_elements['end_hours'];
  1063. $end_minutes=$form_elements['end_minutes'];
  1064. $title=$form_elements['title'];
  1065. $content=$form_elements['content'];
  1066. $id=$form_elements['id'];
  1067. $to=$form_elements['to'];
  1068. $repeat = $form_elements['repeat'];
  1069. }
  1070. // switching the send to all/send to groups/send to users
  1071. if ($_POST['To']) {
  1072. $day = $_POST['fday'];
  1073. $month = $_POST['fmonth'];
  1074. $year = $_POST['fyear'];
  1075. $hours = $_POST['fhour'];
  1076. $minutes = $_POST['fminute'];
  1077. $end_day = $_POST['end_fday'];
  1078. $end_month = $_POST['end_fmonth'];
  1079. $end_year = $_POST['end_fyear'];
  1080. $end_hours = $_POST['end_fhour'];
  1081. $end_minutes = $_POST['end_fminute'];
  1082. $title = $_POST['title'];
  1083. $content = $_POST['content'];
  1084. // the invisible fields
  1085. $action = $_POST['action'];
  1086. $id = $_POST['id'];
  1087. $repeat = !empty($_POST['repeat'])?true:false;
  1088. }
  1089. // if the id is set then we are editing an agenda item
  1090. if (is_int($id)) {
  1091. //echo "before get_agenda_item".$_SESSION['allow_individual_calendar'];
  1092. $item_2_edit=get_agenda_item($id);
  1093. $title = $item_2_edit['title'];
  1094. $content= $item_2_edit['content'];
  1095. // start date
  1096. $item_2_edit['start_date'] = api_get_local_time($item_2_edit['start_date']);
  1097. // start date
  1098. list($datepart, $timepart) = split(" ", $item_2_edit['start_date']);
  1099. list($year, $month, $day) = explode("-", $datepart);
  1100. list($hours, $minutes, $seconds) = explode(":", $timepart);
  1101. // end date
  1102. $item_2_edit['end_date'] = api_get_local_time($item_2_edit['end_date']);
  1103. list($datepart, $timepart) = split(" ", $item_2_edit['end_date']);
  1104. list($end_year, $end_month, $end_day) = explode("-", $datepart);
  1105. list($end_hours, $end_minutes, $end_seconds) = explode(":", $timepart);
  1106. // attachments
  1107. //edit_added_resources("Agenda", $id);
  1108. $to=$item_2_edit['to'];
  1109. //echo "<br />after get_agenda_item".$_SESSION['allow_individual_calendar'];
  1110. }
  1111. $content=stripslashes($content);
  1112. $title=stripslashes($title);
  1113. // we start a completely new item, we do not come from the resource linker
  1114. if ($_GET['originalresource']!=="no" and $_GET['action']=="add")
  1115. {
  1116. $_SESSION["formelements"]=null;
  1117. //unset_session_resources();//--------------------------------------------------------------------------------------
  1118. }
  1119. ?>
  1120. <!-- START OF THE FORM -->
  1121. <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">
  1122. <input type="hidden" name="id" value="<?php if (isset($id)) echo $id; ?>" />
  1123. <input type="hidden" name="action" value="<?php if (isset($_GET['action'])) echo Security::remove_XSS($_GET['action']); ?>" />
  1124. <input type="hidden" name="sort" value="asc" />
  1125. <input type="hidden" name="submit_event" value="ok" />
  1126. <?php
  1127. echo '<div class="row"><div class="form_header">';
  1128. echo (isset($id) AND $id<>'')?get_lang('ModifyCalendarItem'):get_lang("AddCalendarItem");
  1129. echo '</div></div>';
  1130. ?>
  1131. <table border="0" cellpadding="5" cellspacing="0" width="80%" id="newedit_form">
  1132. <!-- START date and time -->
  1133. <tr>
  1134. <div>
  1135. <table border="0" width="100%">
  1136. <tr><td colspan="4">
  1137. <div id="err_date" style="display:none;color:red"></div>
  1138. <div id="err_start_date" style="display:none;color:red"></div>
  1139. </td></tr>
  1140. <td width="10%">
  1141. <!-- date: 1 -> 31 -->
  1142. <nobr><?php echo get_lang('StartDate').": "; ?></nobr>
  1143. </td>
  1144. <td width="35%">
  1145. <select name="fday" onchange="javascript:document.new_calendar_item.end_fday.value=this.value;">
  1146. <?php
  1147. // small loop for filling all the dates
  1148. // 2do: the available dates should be those of the selected month => february is from 1 to 28 (or 29) and not to 31
  1149. foreach (range(1, 31) as $i)
  1150. {
  1151. // values have to have double digits
  1152. $value = ($i <= 9 ? '0'.$i : $i );
  1153. // the current day is indicated with [] around the date
  1154. if ($value==$day)
  1155. {
  1156. echo " <option value=\"".$value."\" selected> ".$i." </option>";
  1157. }
  1158. else
  1159. {
  1160. echo "<option value=\"$value\">$i</option>";
  1161. }
  1162. }
  1163. ?>
  1164. </select>
  1165. <!-- month: january -> december -->
  1166. <select name="fmonth" onchange="javascript:document.new_calendar_item.end_fmonth.value=this.value;">
  1167. <?php
  1168. for ($i=1; $i<=12; $i++)
  1169. {
  1170. // values have to have double digits
  1171. if ($i<=9)
  1172. {
  1173. $value="0".$i;
  1174. }
  1175. else
  1176. {
  1177. $value=$i;
  1178. }
  1179. if ($value==$month)
  1180. {
  1181. echo " <option value=\"".$value."\" selected>".$MonthsLong[$i-1]."</option>\n";
  1182. }
  1183. else
  1184. {
  1185. echo " <option value=\"".$value."\">".$MonthsLong[$i-1]."</option>\n";
  1186. }
  1187. } ?>
  1188. </select>
  1189. <select name="fyear" onchange="javascript:document.new_calendar_item.end_fyear.value=this.value;">
  1190. <option value="<?php echo ($year-1); ?>"><?php echo ($year-1); ?></option>
  1191. <option value="<?php echo $year; ?>" selected="selected"><?php echo $year; ?></option>
  1192. <?php
  1193. echo "\n";
  1194. for ($i=1; $i<=5; $i++)
  1195. {
  1196. $value=$year+$i;
  1197. echo "<option value=\"$value\">$value</option>\n";
  1198. } ?>
  1199. </select>
  1200. <a href="javascript:openCalendar('new_calendar_item','f')"><?php Display::display_icon('calendar_select.gif', get_lang('Select'), array ('style' => 'vertical-align: middle;')); ?></a>
  1201. </td>
  1202. <td width="10%">
  1203. <nobr><?php echo get_lang('StartTime').": \n"; ?></nobr>
  1204. </td>
  1205. <td>
  1206. <select name="fhour" onchange="javascript:document.new_calendar_item.end_fhour.value=this.value;">
  1207. <!-- <option value="--">--</option> -->
  1208. <?php
  1209. echo "\n";
  1210. foreach (range(0, 23) as $i)
  1211. {
  1212. // values have to have double digits
  1213. $value = ($i <= 9 ? '0'.$i : $i );
  1214. // the current hour is indicated with [] around the hour
  1215. if ($hours==$value)
  1216. {
  1217. echo "<option value=\"".$value."\" selected> ".$value." </option>\n";
  1218. }
  1219. else
  1220. {
  1221. echo "<option value=\"$value\">$value</option>\n";
  1222. }
  1223. } ?>
  1224. </select>
  1225. <select name="fminute" onchange="javascript:document.new_calendar_item.end_fminute.value=this.value;">
  1226. <!-- <option value="<?php echo $minutes ?>"><?php echo $minutes; ?></option> -->
  1227. <!-- <option value="--">--</option> -->
  1228. <?php
  1229. foreach (range(0, 59) as $i)
  1230. {
  1231. // values have to have double digits
  1232. $value = ($i <= 9 ? '0'.$i : $i );
  1233. if ($minutes == $value) {
  1234. echo "<option value=\"".$value."\" selected> ".$value." </option>";
  1235. } else {
  1236. echo "<option value=\"$value\">$value</option>";
  1237. }
  1238. } ?>
  1239. </select>
  1240. </td>
  1241. </div>
  1242. </tr>
  1243. <!-- END date and time -->
  1244. <tr>
  1245. <div>
  1246. <tr><td colspan="4"><div id="err_end_date" style="display:none;color:red"></div></td></tr>
  1247. <td >
  1248. <!-- date: 1 -> 31 -->
  1249. <nobr><?php echo get_lang('EndDate').": "; ?></nobr>
  1250. </td>
  1251. <td >
  1252. <select name="end_fday">
  1253. <?php
  1254. // small loop for filling all the dates
  1255. // 2do: the available dates should be those of the selected month => february is from 1 to 28 (or 29) and not to 31
  1256. echo "\n";
  1257. foreach (range(1, 31) as $i)
  1258. {
  1259. // values have to have double digits
  1260. $value = ($i <= 9 ? '0'.$i : $i );
  1261. // the current day is indicated with [] around the date
  1262. if ($value==$end_day)
  1263. { echo " <option value=\"".$value."\" selected> ".$i." </option>\n";}
  1264. else
  1265. { echo " <option value=\"".$value."\">".$i."</option>\n"; }
  1266. }?>
  1267. </select>
  1268. <!-- month: january -> december -->
  1269. <select name="end_fmonth">
  1270. <?php
  1271. echo "\n";
  1272. foreach (range(1, 12) as $i)
  1273. {
  1274. // values have to have double digits
  1275. $value = ($i <= 9 ? '0'.$i : $i );
  1276. if ($value==$end_month)
  1277. { echo " <option value=\"".$value."\" selected>".$MonthsLong[$i-1]."</option>\n"; }
  1278. else
  1279. { echo " <option value=\"".$value."\">".$MonthsLong[$i-1]."</option>\n"; }
  1280. }?>
  1281. </select>
  1282. <select name="end_fyear">
  1283. <option value="<?php echo ($end_year-1) ?>"><?php echo ($end_year-1) ?></option>
  1284. <option value="<?php echo $end_year ?>" selected> <?php echo $end_year ?> </option>
  1285. <?php
  1286. echo "\n";
  1287. for ($i=1; $i<=5; $i++)
  1288. {
  1289. $value=$end_year+$i;
  1290. echo "<option value=\"$value\">$value</option>\n";
  1291. } ?>
  1292. </select>
  1293. <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>
  1294. </td>
  1295. <td >
  1296. <nobr><?php echo get_lang('EndTime').": \n"; ?></nobr>
  1297. </td>
  1298. <td >
  1299. <select name="end_fhour">
  1300. <!-- <option value="--">--</option> -->
  1301. <?php
  1302. echo "\n";
  1303. foreach (range(0, 23) as $i)
  1304. {
  1305. // values have to have double digits
  1306. $value = ($i <= 9 ? '0'.$i : $i );
  1307. // the current hour is indicated with [] around the hour
  1308. if ($end_hours==$value)
  1309. { echo "<option value=\"".$value."\" selected> ".$value." </option>\n"; }
  1310. else
  1311. { echo "<option value=\"".$value."\"> ".$value." </option>\n"; }
  1312. } ?>
  1313. </select>
  1314. <select name="end_fminute">
  1315. <!-- <option value="<?php echo $end_minutes; ?>"><?php echo $end_minutes; ?></option> -->
  1316. <!-- <option value="--">--</option> -->
  1317. <?php
  1318. foreach (range(0, 59) as $i)
  1319. {
  1320. // values have to have double digits
  1321. $value = ($i <= 9 ? '0'.$i : $i );
  1322. if ($minutes == $value) {
  1323. echo "<option value=\"".$value."\" selected> ".$value." </option>";
  1324. } else {
  1325. echo "<option value=\"$value\">$value</option>";
  1326. }
  1327. } ?>
  1328. </select>
  1329. <br>
  1330. </td>
  1331. </div>
  1332. </tr>
  1333. <tr><td colspan="4">
  1334. <hr noshade="noshade" color="#cccccc" />
  1335. <div id="err_title" style="display:none;color:red"></div>
  1336. </td></tr>
  1337. <tr class="subtitle">
  1338. <td colspan="4" valign="top"><?php echo get_lang('ItemTitle'); ?> :
  1339. <!--<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>-->
  1340. <input type="text" size="60" name="title" value="<?php if (isset($title)) echo $title; ?>" />
  1341. </td>
  1342. </tr>
  1343. <tr>
  1344. <td colspan="4">
  1345. <?php
  1346. require_once api_get_path(LIBRARY_PATH) . "/fckeditor/fckeditor.php";
  1347. $oFCKeditor = new FCKeditor('content') ;
  1348. $oFCKeditor->ToolbarSet = 'GlobalAgenda';
  1349. $oFCKeditor->Width = '100%';
  1350. $oFCKeditor->Height = '175';
  1351. $oFCKeditor->Value = $content;
  1352. $return = $oFCKeditor->CreateHtml();
  1353. echo $return;
  1354. ?>
  1355. </td>
  1356. </tr>
  1357. <!--<?php /* ADDED BY UGENT, Patrick Cool, march 2004 */ ?>
  1358. <tr>
  1359. <td colspan="4">
  1360. <?php
  1361. //onclick="selectAll(this.form.elements[6],true)"
  1362. // show_addresource_button('onclick="selectAll(this.form.elements[6],true)"');
  1363. ?>
  1364. </td>
  1365. </tr>-->
  1366. <?php
  1367. //if ($_SESSION['addedresource'])
  1368. echo "<tr>\n";
  1369. echo "<td colspan=\"4\">\n";
  1370. //echo display_resources(0);//--------------------------------------------------------
  1371. $test=$_SESSION['addedresource'];
  1372. echo "</td>\n</tr>\n";
  1373. /* END ADDED BY UGENT, Patrick Cool, march 2004 */
  1374. if(empty($id)) //only show repeat fields when adding the first time
  1375. {
  1376. ?>
  1377. <tr>
  1378. <td colspan="4" />
  1379. </tr>
  1380. <?php
  1381. }//only show repeat fields if adding, not if editing
  1382. ?>
  1383. <tr>
  1384. <td colspan="4">
  1385. <?php
  1386. if ($_GET['action']=='edit'){
  1387. $class='save';
  1388. $text=get_lang('ModifyEvent');
  1389. }else{
  1390. $class='add';
  1391. $text=get_lang('AddEvent');
  1392. }
  1393. ?>
  1394. <button type="button" class="add" value="<?php echo get_lang('Ok'); ?>" onclick="validate_date()" ><?php echo $text; ?></button>
  1395. </td>
  1396. </tr>
  1397. </table>
  1398. </form>
  1399. <?php
  1400. }
  1401. function get_agendaitems($month, $year)
  1402. {
  1403. global $_user;
  1404. global $_configuration;
  1405. $month=Database::escape_string($month);
  1406. $year=Database::escape_string($year);
  1407. $items = array ();
  1408. //databases of the courses
  1409. $TABLEAGENDA = Database :: get_main_table(TABLE_MAIN_SYSTEM_CALENDAR);
  1410. //$TABLE_ITEMPROPERTY = Database :: get_course_table(TABLE_ITEM_PROPERTY);
  1411. //$group_memberships = GroupManager :: get_group_ids(Database::get_current_course_database(), $_user['user_id']);
  1412. // if the user is administrator of that course we show all the agenda items
  1413. //if (api_is_allowed_to_edit())
  1414. //{
  1415. //echo "course admin";
  1416. $sqlquery = "SELECT
  1417. DISTINCT *
  1418. FROM ".$TABLEAGENDA."
  1419. WHERE
  1420. MONTH(start_date)='".$month."'
  1421. AND YEAR(start_date)='".$year."'
  1422. GROUP BY id
  1423. ORDER BY start_date ";
  1424. //}
  1425. // if the user is not an administrator of that course
  1426. /* else
  1427. {
  1428. //echo "GEEN course admin";
  1429. if (is_array($group_memberships) && count($group_memberships)>0)
  1430. {
  1431. $sqlquery = "SELECT
  1432. agenda.*
  1433. FROM ".$TABLEAGENDA."
  1434. WHERE
  1435. MONTH(agenda.start_date)='".$month."'
  1436. AND YEAR(agenda.start_date)='".$year."'
  1437. ORDER BY start_date ";
  1438. }
  1439. else
  1440. {
  1441. $sqlquery = "SELECT
  1442. agenda.*, item_property.*
  1443. FROM ".$TABLEAGENDA."
  1444. WHERE
  1445. MONTH(agenda.start_date)='".$month."'
  1446. AND YEAR(agenda.start_date)='".$year."'
  1447. ORDER BY start_date ";
  1448. }
  1449. }*/
  1450. //$mycourse = api_get_course_info();
  1451. $portal_url = $_configuration['root_web'];
  1452. if ($_configuration['multiple_access_urls']) {
  1453. $access_url_id = api_get_current_access_url_id();
  1454. if ($access_url_id != -1 ){
  1455. $url = api_get_access_url($access_url_id);
  1456. $portal_url = $url['url'];
  1457. }
  1458. }
  1459. $result = Database::query($sqlquery);
  1460. while ($item = Database::fetch_array($result))
  1461. {
  1462. $agendaday_string = api_convert_and_format_date($item['start_date'], "%d", date_default_timezone_get());
  1463. $agendaday = intval($agendaday_string);
  1464. $time = api_convert_and_format_date($item['start_date'], TIME_NO_SEC_FORMAT, date_default_timezone_get());
  1465. $URL = $portal_url.'main/admin/agenda.php?day='.$agendaday."&amp;month=".$month."&amp;year=".$year; // RH //Patrick Cool: to highlight the relevant agenda item
  1466. $items[$agendaday][$item['start_time']] .= '<i>'.$time.'</i> <a href="'.$URL.'" title="'.$item['title'].'<br />';
  1467. }
  1468. // sorting by hour for every day
  1469. $agendaitems = array ();
  1470. while (list ($agendaday, $tmpitems) = each($items))
  1471. {
  1472. sort($tmpitems);
  1473. while (list ($key, $val) = each($tmpitems))
  1474. {
  1475. $agendaitems[$agendaday] .= $val;
  1476. }
  1477. }
  1478. return $agendaitems;
  1479. }
  1480. function display_upcoming_events() {
  1481. echo '<br /><b>'.get_lang('UpcomingEvent').'</b><br />';
  1482. $number_of_items_to_show = (int)api_get_setting('number_of_upcoming_events');
  1483. //databases of the courses
  1484. $TABLEAGENDA = Database :: get_main_table(TABLE_MAIN_SYSTEM_CALENDAR);
  1485. //$TABLE_ITEMPROPERTY = Database :: get_course_table(TABLE_ITEM_PROPERTY);
  1486. //$mycourse = api_get_course_info();
  1487. //$myuser = api_get_user_info();
  1488. //$group_memberships = GroupManager :: get_group_ids($mycourse['dbName'], $myuser['user_id']);
  1489. // if the user is administrator of that course we show all the agenda items
  1490. /*if (api_is_allowed_to_edit())
  1491. {*/
  1492. //echo "course admin";
  1493. $sqlquery = "SELECT DISTINCT * FROM ".$TABLEAGENDA;
  1494. global $_configuration;
  1495. $current_access_url_id = 1;
  1496. if ($_configuration['multiple_access_urls']) {
  1497. $current_access_url_id = api_get_current_access_url_id();
  1498. }
  1499. $sqlquery .= "WHERE access_url_id = $current_access_url_id ";
  1500. $sqlquery .= " ORDER BY start_date ";
  1501. //}
  1502. // if the user is not an administrator of that course
  1503. $result = Database::query($sqlquery);
  1504. $counter = 0;
  1505. while ($item = Database::fetch_array($result,'ASSOC')) {
  1506. if ($counter < $number_of_items_to_show) {
  1507. echo api_get_local_time($item['start_date']),' - ',$item['title'],'<br />';
  1508. $counter++;
  1509. }
  1510. }
  1511. }
  1512. /**
  1513. * This function calculates the startdate of the week (monday)
  1514. * and the enddate of the week (sunday)
  1515. * and returns it as an array
  1516. */
  1517. function calculate_start_end_of_week($week_number, $year)
  1518. {
  1519. // determine the start and end date
  1520. // step 1: we calculate a timestamp for a day in this week
  1521. $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
  1522. // step 2: we which day this is (0=sunday, 1=monday, ...)
  1523. $number_day_in_week = date('w', $random_day_in_week);
  1524. // step 3: we calculate the timestamp of the monday of the week we are in
  1525. $start_timestamp = $random_day_in_week - (($number_day_in_week -1) * 24 * 60 * 60);
  1526. // step 4: we calculate the timestamp of the sunday of the week we are in
  1527. $end_timestamp = $random_day_in_week + ((7 - $number_day_in_week +1) * 24 * 60 * 60) - 3600;
  1528. // step 5: calculating the start_day, end_day, start_month, end_month, start_year, end_year
  1529. $start_day = date('j', $start_timestamp);
  1530. $start_month = date('n', $start_timestamp);
  1531. $start_year = date('Y', $start_timestamp);
  1532. $end_day = date('j', $end_timestamp);
  1533. $end_month = date('n', $end_timestamp);
  1534. $end_year = date('Y', $end_timestamp);
  1535. $start_end_array['start']['day'] = $start_day;
  1536. $start_end_array['start']['month'] = $start_month;
  1537. $start_end_array['start']['year'] = $start_year;
  1538. $start_end_array['end']['day'] = $end_day;
  1539. $start_end_array['end']['month'] = $end_month;
  1540. $start_end_array['end']['year'] = $end_year;
  1541. return $start_end_array;
  1542. }
  1543. /**
  1544. * Show the mini calendar of the given month
  1545. */
  1546. function display_daycalendar($agendaitems, $day, $month, $year, $weekdaynames, $monthName)
  1547. {
  1548. global $DaysShort, $DaysLong, $course_path;
  1549. global $MonthsLong;
  1550. global $query;
  1551. // timestamp of today
  1552. $today = mktime();
  1553. $nextday = $today + (24 * 60 * 60);
  1554. $previousday = $today - (24 * 60 * 60);
  1555. // the week number of the year
  1556. $week_number = date("W", $today);
  1557. // if we moved to the next / previous day we have to recalculate the $today variable
  1558. if ($_GET['day'])
  1559. {
  1560. $today = mktime(0, 0, 0, $month, $day, $year);
  1561. $nextday = $today + (24 * 60 * 60);
  1562. $previousday = $today - (24 * 60 * 60);
  1563. $week_number = date("W", $today);
  1564. }
  1565. // calculating the start date of the week
  1566. // the date of the monday of this week is the timestamp of today minus
  1567. // number of days that have already passed this week * 24 hours * 60 minutes * 60 seconds
  1568. $current_day = date("j", $today); // Day of the month without leading zeros (1 to 31) of today
  1569. $day_of_the_week = date("w", $today); // Numeric representation of the day of the week 0 (for Sunday) through 6 (for Saturday) of today
  1570. //$timestamp_first_date_of_week=$today-(($day_of_the_week-1)*24*60*60); // timestamp of the monday of this week
  1571. //$timestamp_last_date_of_week=$today+((7-$day_of_the_week)*24*60*60); // timestamp of the sunday of this week
  1572. // we are loading all the calendar items of all the courses for today
  1573. echo "<table class=\"data_table\">\n";
  1574. // the forward and backwards url
  1575. $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);
  1576. $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);
  1577. // The title row containing the day
  1578. echo "<tr>\n", "<th width=\"10%\"><a href=\"", $backwardsURL, "\">".Display::return_icon('action_prev.png',get_lang('Previous'))."</a></th>\n", "<th>";
  1579. echo $DaysLong[$day_of_the_week]." ".date("j", $today)." ".$MonthsLong[date("n", $today) - 1]." ".date("Y", $today);
  1580. echo "</th>";
  1581. echo "<th width=\"10%\"><a href=\"", $forewardsURL, "\">".Display::return_icon('action_next.png',get_lang('Next'))."</a></th>\n";
  1582. echo "</tr>\n";
  1583. // the rows for each half an hour
  1584. for ($i = 10; $i < 48; $i ++)
  1585. {
  1586. if ($i % 2 == 0)
  1587. {
  1588. $class = "class=\"row_even\"";
  1589. }
  1590. else
  1591. {
  1592. $class = "class=\"row_odd\"";
  1593. }
  1594. echo "<tr $class>\n";
  1595. echo "";
  1596. if ($i % 2 == 0)
  1597. {
  1598. echo ("<td valign=\"top\" width=\"75\">". (($i) / 2)." ".get_lang("HourShort")." 00</td>\n");
  1599. }
  1600. else
  1601. {
  1602. echo ("<td valign=\"top\" width=\"75\">". ((($i) / 2) - (1 / 2))." ".get_lang("HourShort")." 30</td>\n");
  1603. }
  1604. echo "<td $class valign=\"top\" colspan=\"2\">\n";
  1605. if (is_array($agendaitems[$i]))
  1606. {
  1607. foreach ($agendaitems[$i] as $key => $value)
  1608. {
  1609. echo $value;
  1610. }
  1611. }
  1612. else
  1613. {
  1614. echo $agendaitems[$i];
  1615. }
  1616. echo "</td>\n";
  1617. echo "</tr>\n";
  1618. }
  1619. echo "</table>\n";
  1620. }
  1621. /**
  1622. * Display the weekly view of the calendar
  1623. */
  1624. function display_weekcalendar($agendaitems, $month, $year, $weekdaynames, $monthName)
  1625. {
  1626. global $DaysShort,$course_path;
  1627. global $MonthsLong;
  1628. // timestamp of today
  1629. $today = time();
  1630. $day_of_the_week = date("w", $today);
  1631. $thisday_of_the_week = date("w", $today);
  1632. // the week number of the year
  1633. $week_number = date("W", $today);
  1634. $thisweek_number = $week_number;
  1635. // if we moved to the next / previous week we have to recalculate the $today variable
  1636. if ($_GET['week'])
  1637. {
  1638. $today = mktime(0, 0, 0, 1, 1, $year);
  1639. $today = $today + (((int)$_GET['week']-1) * (7 * 24 * 60 * 60));
  1640. $week_number = date("W", $today);
  1641. }
  1642. // calculating the start date of the week
  1643. // the date of the monday of this week is the timestamp of today minus
  1644. // number of days that have already passed this week * 24 hours * 60 minutes * 60 seconds
  1645. $current_day = date("j", $today); // Day of the month without leading zeros (1 to 31) of today
  1646. $day_of_the_week = date("w", $today); // Numeric representation of the day of the week 0 (for Sunday) through 6 (for Saturday) of today
  1647. $timestamp_first_date_of_week = $today - (($day_of_the_week -1) * 24 * 60 * 60); // timestamp of the monday of this week
  1648. $timestamp_last_date_of_week = $today + ((7 - $day_of_the_week) * 24 * 60 * 60); // timestamp of the sunday of this week
  1649. $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);
  1650. $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);
  1651. echo "<table id=\"agenda_list\">\n";
  1652. // The title row containing the the week information (week of the year (startdate of week - enddate of week)
  1653. echo "<tr class=\"title\">\n";
  1654. echo "<td width=\"10%\"><a href=\"", $backwardsURL, "\">".Display::return_icon('action_prev.png',get_lang('Previous'))."</a></td>\n";
  1655. echo "<td colspan=\"5\">".get_lang("Week")." ".$week_number;
  1656. 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).')';
  1657. echo "</td>";
  1658. echo "<td width=\"10%\"><a href=\"", $forewardsURL, "\">".Display::return_icon('action_next.png',get_lang('Next'))."</a></td>", "</tr>";
  1659. // The second row containing the short names of the days of the week
  1660. echo "<tr>\n";
  1661. // this is the Day of the month without leading zeros (1 to 31) of the monday of this week
  1662. $tmp_timestamp = $timestamp_first_date_of_week;
  1663. for ($ii = 1; $ii < 8; $ii ++)
  1664. {
  1665. $is_today = ($ii == $thisday_of_the_week AND (!isset($_GET['week']) OR $_GET['week']==$thisweek_number));
  1666. echo "<td class=\"weekdays\">";
  1667. if ($is_today)
  1668. {
  1669. echo "<font color=#CC3300>";
  1670. }
  1671. echo $DaysShort[$ii % 7]." ".date("j", $tmp_timestamp)." ".$MonthsLong[date("n", $tmp_timestamp) - 1];
  1672. if ($is_today)
  1673. {
  1674. echo "</font>";
  1675. }
  1676. echo "</td>\n";
  1677. // we 24 hours * 60 minutes * 60 seconds to the $tmp_timestamp
  1678. $array_tmp_timestamp[] = $tmp_timestamp;
  1679. $tmp_timestamp = $tmp_timestamp + (24 * 60 * 60);
  1680. }
  1681. echo "</tr>\n";
  1682. // the table cells containing all the entries for that day
  1683. echo "<tr>\n";
  1684. $counter = 0;
  1685. foreach ($array_tmp_timestamp as $key => $value)
  1686. {
  1687. if ($counter < 5)
  1688. {
  1689. $class = "class=\"days_week\"";
  1690. }
  1691. else
  1692. {
  1693. $class = "class=\"days_weekend\"";
  1694. }
  1695. if ($counter == $thisday_of_the_week -1 AND (!isset($_GET['week']) OR $_GET['week']==$thisweek_number))
  1696. {
  1697. $class = "class=\"days_today\"";
  1698. }
  1699. echo "<td ".$class.">";
  1700. echo "<span class=\"agendaitem\">".$agendaitems[date('j', $value)]."&nbsp;</span> ";
  1701. echo "</td>\n";
  1702. $counter ++;
  1703. }
  1704. echo "</tr>\n";
  1705. echo "</table>\n";
  1706. }
  1707. /**
  1708. * Show the monthcalender of the given month
  1709. */
  1710. function get_day_agendaitems($courses_dbs, $month, $year, $day)
  1711. {
  1712. global $_user;
  1713. global $_configuration;
  1714. global $setting_agenda_link;
  1715. $items = array ();
  1716. // get agenda-items for every course
  1717. //$query=Database::query($sql_select_courses);
  1718. foreach ($courses_dbs as $key => $array_course_info)
  1719. {
  1720. //databases of the courses
  1721. $TABLEAGENDA = Database :: get_main_table(TABLE_MAIN_SYSTEM_CALENDAR);
  1722. //$TABLE_ITEMPROPERTY = Database :: get_course_table(TABLE_ITEM_PROPERTY, $array_course_info['db']);
  1723. // getting all the groups of the user for the current course
  1724. //$group_memberships = GroupManager :: get_group_ids($array_course_info['db'], $_user['user_id']);
  1725. // if the user is administrator of that course we show all the agenda items
  1726. if ($array_course_info['status'] == '1')
  1727. {
  1728. //echo "course admin";
  1729. $sqlquery = "SELECT DISTINCT *
  1730. FROM ".$TABLEAGENDA."
  1731. WHERE
  1732. DAYOFMONTH(start_date)='".$day."' AND MONTH(start_date)='".$month."' AND YEAR(start_date)='".$year."'
  1733. GROUP BY agenda.id
  1734. ORDER BY start_date ";
  1735. }
  1736. // if the user is not an administrator of that course
  1737. /*else
  1738. {
  1739. //echo "GEEN course admin";
  1740. if (is_array($group_memberships) && count($group_memberships)>0)
  1741. {
  1742. $sqlquery = "SELECT
  1743. agenda.*
  1744. FROM ".$TABLEAGENDA."
  1745. WHERE
  1746. DAYOFMONTH(start_date)='".$day."' AND MONTH(start_date)='".$month."' AND YEAR(start_date)='".$year."'
  1747. ORDER BY start_date ";
  1748. }
  1749. else
  1750. {
  1751. $sqlquery = "SELECT
  1752. agenda.*
  1753. FROM ".$TABLEAGENDA."
  1754. WHERE
  1755. DAYOFMONTH(start_date)='".$day."' AND MONTH(start_date)='".$month."' AND YEAR(start_date)='".$year."'
  1756. ORDER BY start_date ";
  1757. }
  1758. }*/
  1759. //$sqlquery = "SELECT * FROM $agendadb WHERE DAYOFMONTH(day)='$day' AND month(day)='$month' AND year(day)='$year'";
  1760. //echo "abc";
  1761. //echo $sqlquery;
  1762. $result = Database::query($sqlquery);
  1763. $portal_url = $_configuration['root_web'];
  1764. if ($_configuration['multiple_access_urls']) {
  1765. $access_url_id = api_get_current_access_url_id();
  1766. if ($access_url_id != -1 ){
  1767. $url = api_get_access_url($access_url_id);
  1768. $portal_url = $url['url'];
  1769. }
  1770. }
  1771. //echo Database::num_rows($result);
  1772. while ($item = Database::fetch_array($result))
  1773. {
  1774. // in the display_daycalendar function we use $i (ranging from 0 to 47) for each halfhour
  1775. // we want to know for each agenda item for this day to wich halfhour it must be assigned
  1776. $item['start_date'] = api_get_local_time($item['start_date'], null, date_default_timezone_get());
  1777. list ($datepart, $timepart) = split(" ", $item['start_date']);
  1778. list ($year, $month, $day) = explode("-", $datepart);
  1779. list ($hours, $minutes, $seconds) = explode(":", $timepart);
  1780. $halfhour = 2 * $hours;
  1781. if ($minutes >= '30')
  1782. {
  1783. $halfhour = $halfhour +1;
  1784. }
  1785. if ($setting_agenda_link == 'coursecode')
  1786. {
  1787. $title=$array_course_info['title'];
  1788. $agenda_link = api_substr($title, 0, 14);
  1789. }
  1790. else
  1791. {
  1792. $agenda_link = Display::return_icon('course_home.gif');
  1793. }
  1794. //$URL = $_configuration['root_web'].$mycours["dir"]."/";
  1795. $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
  1796. $items[$halfhour][] .= "<i>".$hours.":".$minutes."</i> <a href=\"$URL\" title=\"".$array_course_info['name']."\">".$agenda_link."</a> ".$item['title']."<br />";
  1797. }
  1798. }
  1799. // sorting by hour for every day
  1800. $agendaitems = array();
  1801. while (list($agendaday, $tmpitems) = each($items))
  1802. {
  1803. sort($tmpitems);
  1804. while (list($key,$val) = each($tmpitems))
  1805. {
  1806. $agendaitems[$agendaday].=$val;
  1807. }
  1808. }
  1809. $agendaitems = $items;
  1810. //print_r($agendaitems);
  1811. return $agendaitems;
  1812. }
  1813. /**
  1814. * Return agenda items of the week
  1815. */
  1816. function get_week_agendaitems($courses_dbs, $month, $year, $week = '')
  1817. {
  1818. global $_user;
  1819. global $_configuration;
  1820. global $setting_agenda_link;
  1821. $TABLEAGENDA = Database :: get_main_table(TABLE_MAIN_SYSTEM_CALENDAR);
  1822. $items = array ();
  1823. // The default value of the week
  1824. if ($week == '')
  1825. {
  1826. $week_number = date("W", time());
  1827. }
  1828. else
  1829. {
  1830. $week_number = $week;
  1831. }
  1832. $start_end = calculate_start_end_of_week($week_number, $year);
  1833. $start_filter = $start_end['start']['year']."-".$start_end['start']['month']."-".$start_end['start']['day'];
  1834. $end_filter = $start_end['end']['year']."-".$start_end['end']['month']."-".$start_end['end']['day'];
  1835. // get agenda-items for every course
  1836. foreach ($courses_dbs as $key => $array_course_info)
  1837. {
  1838. //databases of the courses
  1839. $TABLEAGENDA = Database :: get_main_table(TABLE_MAIN_SYSTEM_CALENDAR);
  1840. //$TABLE_ITEMPROPERTY = Database :: get_course_table(TABLE_ITEM_PROPERTY, $array_course_info["db"]);
  1841. // getting all the groups of the user for the current course
  1842. // $group_memberships = GroupManager :: get_group_ids($array_course_info["db"], $_user['user_id']);
  1843. // if the user is administrator of that course we show all the agenda items
  1844. //if ($array_course_info['status'] == '1')
  1845. //{
  1846. //echo "course admin";
  1847. $sqlquery = "SELECT DISTINCT * FROM ".$TABLEAGENDA." ORDER BY start_date";
  1848. //}
  1849. // if the user is not an administrator of that course
  1850. //else
  1851. //{
  1852. //echo "GEEN course admin";
  1853. /* if (is_array($group_memberships) && count($group_memberships)>0)
  1854. {
  1855. $sqlquery = "SELECT * FROM ".$TABLEAGENDA." ORDER BY a.start_date";
  1856. }
  1857. else*/
  1858. //{
  1859. // $sqlquery = "SELECT * FROM ".$TABLEAGENDA." ORDER BY a.start_date";
  1860. //}
  1861. //}
  1862. //echo "<pre>".$sqlquery."</pre>";
  1863. // $sqlquery = "SELECT * FROM $agendadb WHERE (DAYOFMONTH(day)>='$start_day' AND DAYOFMONTH(day)<='$end_day')
  1864. // AND (MONTH(day)>='$start_month' AND MONTH(day)<='$end_month')
  1865. // AND (YEAR(day)>='$start_year' AND YEAR(day)<='$end_year')";
  1866. $result = Database::query($sqlquery);
  1867. $portal_url = $_configuration['root_web'];
  1868. if ($_configuration['multiple_access_urls']) {
  1869. $access_url_id = api_get_current_access_url_id();
  1870. if ($access_url_id != -1 ){
  1871. $url = api_get_access_url($access_url_id);
  1872. $portal_url = $url['url'];
  1873. }
  1874. }
  1875. while ($item = Database::fetch_array($result))
  1876. {
  1877. $agendaday_string = api_convert_and_format_date($item['start_date'], "%d", date_default_timezone_get());
  1878. $agendaday = intval($agendaday_string);
  1879. $time = api_convert_and_format_date($item['start_date'], TIME_NO_SEC_FORMAT, date_default_timezone_get());
  1880. if ($setting_agenda_link == 'coursecode')
  1881. {
  1882. $title=$array_course_info['title'];
  1883. $agenda_link = api_substr($title, 0, 14);
  1884. }
  1885. else
  1886. {
  1887. $agenda_link = Display::return_icon('course_home.gif');
  1888. }
  1889. $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
  1890. $items[$agendaday][$item['start_time']] .= "<i>$time</i> <a href=\"$URL\" title=\"".$array_course_info["name"]."\">".$agenda_link."</a> ".$item['title']."<br />";
  1891. }
  1892. }
  1893. // sorting by hour for every day
  1894. $agendaitems = array ();
  1895. while (list ($agendaday, $tmpitems) = each($items))
  1896. {
  1897. sort($tmpitems);
  1898. while (list ($key, $val) = each($tmpitems))
  1899. {
  1900. $agendaitems[$agendaday] .= $val;
  1901. }
  1902. }
  1903. //print_r($agendaitems);
  1904. return $agendaitems;
  1905. }
  1906. /**
  1907. * Get repeated events of a course between two dates (timespan of a day).
  1908. * Returns an array containing the events
  1909. * @param string Course info array (as returned by api_get_course_info())
  1910. * @param int UNIX timestamp of span start. Defaults 0, later transformed into today's start
  1911. * @param int UNIX timestamp. Defaults to 0, later transformed into today's end
  1912. * @param array A set of parameters to alter the SQL query
  1913. * @return array [int] => [course_id,parent_event_id,start_date,end_date,title,description]
  1914. */
  1915. function get_repeated_events_day_view($course_info,$start=0,$end=0,$params)
  1916. {
  1917. $events = array();
  1918. //initialise all values
  1919. $y=0;
  1920. $m=0;
  1921. $d=0;
  1922. //block $end if higher than 2038 -- PHP doesn't go past that
  1923. if($end>2145934800){$end = 2145934800;}
  1924. if($start == 0 or $end == 0)
  1925. {
  1926. $y=date('Y');
  1927. $m=date('m');
  1928. $d=date('j');
  1929. }
  1930. if($start==0)
  1931. {
  1932. $start = mktime(0,0,0,$m,$d,$y);
  1933. }
  1934. $db_start = date('Y-m-d H:i:s',$start);
  1935. if($end==0)
  1936. {
  1937. $end = mktime(23,59,59,$m,$d,$y);
  1938. }
  1939. //$db_end = date('Y-m-d H:i:s',$end);
  1940. $t_cal = Database::get_main_table(TABLE_MAIN_SYSTEM_CALENDAR,$course_info['dbName']);
  1941. $t_cal_repeat = Database::get_course_table(TABLE_AGENDA_REPEAT,$course_info['dbName']);
  1942. $t_ip = Database::get_course_table(TABLE_ITEM_PROPERTY,$course_info['dbName']);
  1943. $sql = "SELECT c.id, c.title, c.content, " .
  1944. " UNIX_TIMESTAMP(c.start_date) as orig_start, UNIX_TIMESTAMP(c.end_date) as orig_end, " .
  1945. " cr.cal_type, cr.cal_end " .
  1946. " FROM $t_cal c, $t_cal_repeat cr, $t_ip as item_property " .
  1947. " WHERE cr.cal_end >= $start " .
  1948. " AND cr.cal_id = c.id " .
  1949. " AND item_property.ref = c.id ".
  1950. " AND item_property.tool = '".TOOL_CALENDAR_EVENT."' ".
  1951. " AND c.start_date <= '$db_start' "
  1952. .(!empty($params['conditions'])?$params['conditions']:'')
  1953. .(!empty($params['groupby'])?' GROUP BY '.$params['groupby']:'')
  1954. .(!empty($params['orderby'])?' ORDER BY '.$params['orderby']:'');
  1955. $res = Database::query($sql);
  1956. if(Database::num_rows($res)>0)
  1957. {
  1958. while($row = Database::fetch_array($res))
  1959. {
  1960. $orig_start = $row['orig_start'];
  1961. $orig_end = $row['orig_start'];
  1962. $repeat_type = $row['cal_type'];
  1963. switch($repeat_type)
  1964. {
  1965. case 'daily':
  1966. //we are in the daily view, so if this element is repeated daily and
  1967. //the repetition is still active today (which is a condition of the SQL query)
  1968. //then the event happens today. Just build today's timestamp for start and end
  1969. $time_orig_h = date('H',$orig_start);
  1970. $time_orig_m = date('i',$orig_start);
  1971. $time_orig_s = date('s',$orig_start);
  1972. $int_time = (($time_orig_h*60)+$time_orig_m)*60+$time_orig_s; //time in seconds since 00:00:00
  1973. $span = $orig_end - $orig_start; //total seconds between start and stop of original event
  1974. $current_start =$start + $int_time; //unixtimestamp start of today's event
  1975. $current_stop = $start+$int_time+$span; //unixtimestamp stop of today's event
  1976. $events[] = array($course_info['id'],$row['id'],$current_start,$current_stop,$row['title'],$row['content']);
  1977. break;
  1978. case 'weekly':
  1979. $time_orig = date('Y/n/W/j/N/G/i/s',$orig_start);
  1980. list($y_orig,$m_orig,$w_orig,$d_orig,$dw_orig,$h_orig,$n_orig,$s_orig) = split('/',$time_orig);
  1981. $time_now = date('Y/n/W/j/N/G/i/s',$end);
  1982. list($y_now,$m_now,$w_now,$d_now,$dw_now,$h_now,$n_now,$s_now) = split('/',$time_now);
  1983. if((($y_now>$y_orig) OR (($y_now == $y_orig) && ($w_now>$w_orig))) && ($dw_orig == $dw_now))
  1984. { //if the event is after the original (at least one week) and the day of the week is the same
  1985. $time_orig_end = date('Y/n/W/j/N/G/i/s',$orig_end);
  1986. 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);
  1987. $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']);
  1988. }
  1989. break;
  1990. case 'monthlyByDate':
  1991. $time_orig = date('Y/n/j/G/i/s',$orig_start);
  1992. list($y_orig,$m_orig,$d_orig,$h_orig,$n_orig,$s_orig) = split('/',$time_orig);
  1993. $time_now = date('Y/n/j/G/i/s',$end);
  1994. list($y_now,$m_now,$d_now,$h_now,$n_now,$s_now) = split('/',$time_now);
  1995. if((($y_now>$y_orig) OR (($y_now == $y_orig) && ($m_now>$m_orig))) && ($d_orig == $d_now))
  1996. {
  1997. $time_orig_end = date('Y/n/j/G/i/s',$orig_end);
  1998. list($y_orig_e,$m_orig_e,$d_orig_e,$h_orig_e,$n_orig_e,$s_orig_e) = split('/',$time_orig_end);
  1999. $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']);
  2000. }
  2001. break;
  2002. case 'monthlyByDayR':
  2003. //not implemented yet
  2004. break;
  2005. case 'monthlyByDay':
  2006. //not implemented yet
  2007. break;
  2008. case 'yearly':
  2009. $time_orig = date('Y/n/j/z/G/i/s',$orig_start);
  2010. list($y_orig,$m_orig,$d_orig,$dy_orig,$h_orig,$n_orig,$s_orig) = split('/',$time_orig);
  2011. $time_now = date('Y/n/j/z/G/i/s',$end);
  2012. list($y_now,$m_now,$d_now,$dy_now,$h_now,$n_now,$s_now) = split('/',$time_now);
  2013. if(($y_now>$y_orig) && ($dy_orig == $dy_now))
  2014. {
  2015. $time_orig_end = date('Y/n/j/G/i/s',$orig_end);
  2016. 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);
  2017. $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']);
  2018. }
  2019. break;
  2020. default:
  2021. break;
  2022. }
  2023. }
  2024. }
  2025. return $events;
  2026. }
  2027. /**
  2028. * Get repeated events of a course between two dates (timespan of a week).
  2029. * Returns an array containing the events
  2030. * @param string Course info array (as returned by api_get_course_info())
  2031. * @param int UNIX timestamp of span start. Defaults 0, later transformed into today's start
  2032. * @param int UNIX timestamp. Defaults to 0, later transformed into today's end
  2033. * @param array A set of parameters to alter the SQL query
  2034. * @return array [int] => [course_id,parent_event_id,start_date,end_date,title,description]
  2035. */
  2036. function get_repeated_events_week_view($course_info,$start=0,$end=0,$params)
  2037. {
  2038. $events = array();
  2039. //block $end if higher than 2038 -- PHP doesn't go past that
  2040. if($end>2145934800){$end = 2145934800;}
  2041. //initialise all values
  2042. $y=0;
  2043. $m=0;
  2044. $d=0;
  2045. if($start == 0 or $end == 0)
  2046. {
  2047. $time = time();
  2048. $dw = date('w',$time);
  2049. $week_start = $time - (($dw-1)*86400);
  2050. $y = date('Y',$week_start);
  2051. $m = date('m',$week_start);
  2052. $d = date('j',$week_start);
  2053. $w = date('W',$week_start);
  2054. }
  2055. if($start==0)
  2056. {
  2057. $start = mktime(0,0,0,$m,$d,$y);
  2058. }
  2059. $db_start = date('Y-m-d H:i:s',$start);
  2060. if($end==0)
  2061. {
  2062. $end = $start+(86400*7)-1; //start of week, more 7 days, minus 1 second to get back to the previoyus day
  2063. }
  2064. //$db_end = date('Y-m-d H:i:s',$end);
  2065. $t_cal = Database::get_main_table(TABLE_MAIN_SYSTEM_CALENDAR);
  2066. //$t_cal_repeat = Database::get_course_table(TABLE_AGENDA_REPEAT,$course_info['dbName']);
  2067. //$t_ip = Database::get_course_table(TABLE_ITEM_PROPERTY,$course_info['dbName']);
  2068. $sql = "SELECT c.id, c.title, c.content, " .
  2069. " UNIX_TIMESTAMP(c.start_date) as orig_start, UNIX_TIMESTAMP(c.end_date) as orig_end " .
  2070. " FROM ". $t_cal ."
  2071. AS c WHERE c.start_date <= '$db_start' "
  2072. .(!empty($params['conditions'])?$params['conditions']:'')
  2073. .(!empty($params['groupby'])?' GROUP BY '.$params['groupby']:'')
  2074. .(!empty($params['orderby'])?' ORDER BY '.$params['orderby']:'');
  2075. $res = Database::query($sql);
  2076. if(Database::num_rows($res)>0)
  2077. {
  2078. while($row = Database::fetch_array($res))
  2079. {
  2080. $orig_start = $row['orig_start'];
  2081. $orig_end = $row['orig_end'];
  2082. $repeat_type = $row['cal_type'];
  2083. switch($repeat_type)
  2084. {
  2085. case 'daily':
  2086. $time_orig_h = date('H',$orig_start);
  2087. $time_orig_m = date('i',$orig_start);
  2088. $time_orig_s = date('s',$orig_start);
  2089. $int_time = (($time_orig_h*60)+$time_orig_m)*60+$time_orig_s; //time in seconds since 00:00:00
  2090. $span = $orig_end - $orig_start; //total seconds between start and stop of original event
  2091. for($i=0;$i<7;$i++)
  2092. {
  2093. $current_start = $start + ($i*86400) + $int_time; //unixtimestamp start of today's event
  2094. $current_stop = $start + ($i*86400) + $int_time + $span; //unixtimestamp stop of today's event
  2095. $events[] = array($course_info['id'],$row['id'],$current_start,$current_stop,$row['title'],$row['content']);
  2096. }
  2097. break;
  2098. case 'weekly':
  2099. $time_orig = date('Y/n/W/j/N/G/i/s',$orig_start);
  2100. list($y_orig,$m_orig,$w_orig,$d_orig,$dw_orig,$h_orig,$n_orig,$s_orig) = split('/',$time_orig);
  2101. $time_now = date('Y/n/W/j/N/G/i/s',$end);
  2102. list($y_now,$m_now,$w_now,$d_now,$dw_now,$h_now,$n_now,$s_now) = split('/',$time_now);
  2103. if((($y_now>$y_orig) OR (($y_now == $y_orig) && ($w_now>$w_orig))))
  2104. { //if the event is after the original (at least one week) and the day of the week is the same
  2105. $time_orig_end = date('Y/n/W/j/N/G/i/s',$orig_end);
  2106. 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);
  2107. $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']);
  2108. }
  2109. break;
  2110. case 'monthlyByDate':
  2111. $time_orig = date('Y/n/W/j/G/i/s',$orig_start);
  2112. list($y_orig,$m_orig,$w_orig,$d_orig,$h_orig,$n_orig,$s_orig) = split('/',$time_orig);
  2113. $time_now = date('Y/n/W/j/G/i/s',$end);
  2114. list($y_now,$m_now,$w_now,$d_now,$h_now,$n_now,$s_now) = split('/',$time_now);
  2115. $event_repetition_time = mktime($h_orig,$n_orig,$s_orig,$m_now,$d_orig,$y_now);
  2116. if((($y_now>$y_orig) OR (($y_now == $y_orig) && ($m_now>$m_orig))) && ($start<$event_repetition_time && $event_repetition_time<$end))
  2117. { //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
  2118. $time_orig_end = date('Y/n/j/G/i/s',$orig_end);
  2119. list($y_orig_e,$m_orig_e,$d_orig_e,$h_orig_e,$n_orig_e,$s_orig_e) = split('/',$time_orig_end);
  2120. $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']);
  2121. }
  2122. break;
  2123. case 'monthlyByDayR':
  2124. //not implemented yet
  2125. break;
  2126. case 'monthlyByDay':
  2127. //not implemented yet
  2128. break;
  2129. case 'yearly':
  2130. $time_orig = date('Y/n/j/z/G/i/s',$orig_start);
  2131. list($y_orig,$m_orig,$d_orig,$dy_orig,$h_orig,$n_orig,$s_orig) = split('/',$time_orig);
  2132. $time_now = date('Y/n/j/z/G/i/s',$end);
  2133. list($y_now,$m_now,$d_now,$dy_now,$h_now,$n_now,$s_now) = split('/',$time_now);
  2134. $event_repetition_time = mktime($h_orig,$n_orig,$s_orig,$m_orig,$d_orig,$y_now);
  2135. if((($y_now>$y_orig) && ($start<$event_repetition_time && $event_repetition_time<$end)))
  2136. {
  2137. $time_orig_end = date('Y/n/j/G/i/s',$orig_end);
  2138. 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);
  2139. $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']);
  2140. }
  2141. break;
  2142. default:
  2143. break;
  2144. }
  2145. }
  2146. }
  2147. return $events;
  2148. }
  2149. /**
  2150. * Get repeated events of a course between two dates (timespan of a month).
  2151. * Returns an array containing the events
  2152. * @param string Course info array (as returned by api_get_course_info())
  2153. * @param int UNIX timestamp of span start. Defaults 0, later transformed into today's start
  2154. * @param int UNIX timestamp. Defaults to 0, later transformed into today's end
  2155. * @param array A set of parameters to alter the SQL query
  2156. * @return array [int] => [course_id,parent_event_id,start_date,end_date,title,description]
  2157. */
  2158. function get_repeated_events_month_view($course_info,$start=0,$end=0,$params)
  2159. {
  2160. $events = array();
  2161. //block $end if higher than 2038 -- PHP doesn't go past that
  2162. if($end>2145934800){$end = 2145934800;}
  2163. //initialise all values
  2164. $y=0;
  2165. $m=0;
  2166. $d=0;
  2167. if($start == 0 or $end == 0)
  2168. {
  2169. $time = time();
  2170. $y = date('Y');
  2171. $m = date('m');
  2172. }
  2173. if($start==0)
  2174. {
  2175. $start = mktime(0,0,0,$m,1,$y);
  2176. }
  2177. $db_start = date('Y-m-d H:i:s',$start);
  2178. if($end==0)
  2179. {
  2180. if($m==12)
  2181. {
  2182. $end = mktime(0,0,0,1,1,$y+1)-1; //start of next month, minus 1 second to get back to the previoyus day
  2183. }
  2184. else
  2185. {
  2186. $end = mktime(0,0,0,$m+1,1,$y)-1;
  2187. }
  2188. }
  2189. //$db_end = date('Y-m-d H:i:s',$end);
  2190. $t_cal = Database::get_main_table(TABLE_MAIN_SYSTEM_CALENDAR);
  2191. $t_cal_repeat = Database::get_course_table(TABLE_AGENDA_REPEAT,$course_info['dbName']);
  2192. $t_ip = Database::get_course_table(TABLE_ITEM_PROPERTY,$course_info['dbName']);
  2193. $sql = "SELECT c.id, c.title, c.content, " .
  2194. " UNIX_TIMESTAMP(c.start_date) as orig_start, UNIX_TIMESTAMP(c.end_date) as orig_end, " .
  2195. " cr.cal_type, cr.cal_end " .
  2196. " FROM $t_cal c, $t_cal_repeat cr, $t_ip as item_property " .
  2197. " WHERE cr.cal_end >= $start " .
  2198. " AND cr.cal_id = c.id " .
  2199. " AND item_property.ref = c.id ".
  2200. " AND item_property.tool = '".TOOL_CALENDAR_EVENT."' ".
  2201. " AND c.start_date <= '$db_start' "
  2202. .(!empty($params['conditions'])?$params['conditions']:'')
  2203. .(!empty($params['groupby'])?' GROUP BY '.$params['groupby']:'')
  2204. .(!empty($params['orderby'])?' ORDER BY '.$params['orderby']:'');
  2205. $res = Database::query($sql);
  2206. if(Database::num_rows($res)>0)
  2207. {
  2208. while($row = Database::fetch_array($res))
  2209. {
  2210. $orig_start = $row['orig_start'];
  2211. $orig_end = $row['orig_end'];
  2212. $repeat_type = $row['cal_type'];
  2213. switch($repeat_type)
  2214. {
  2215. case 'daily':
  2216. $time_orig_h = date('H',$orig_start);
  2217. $time_orig_m = date('i',$orig_start);
  2218. $time_orig_s = date('s',$orig_start);
  2219. $month_last_day = date('d',$end);
  2220. $int_time = (($time_orig_h*60)+$time_orig_m)*60+$time_orig_s; //time in seconds since 00:00:00
  2221. $span = $orig_end - $orig_start; //total seconds between start and stop of original event
  2222. for($i=0;$i<$month_last_day;$i++)
  2223. {
  2224. $current_start = $start + ($i*86400) + $int_time; //unixtimestamp start of today's event
  2225. $current_stop = $start + ($i*86400) + $int_time + $span; //unixtimestamp stop of today's event
  2226. $events[] = array($course_info['id'],$row['id'],$current_start,$current_stop,$row['title'],$row['content']);
  2227. }
  2228. break;
  2229. case 'weekly':
  2230. //A weekly repeated event is very difficult to catch in a month view,
  2231. //because weeks start before or at the same time as the first day of the month
  2232. //The same can be said for the end of the month.
  2233. // The idea is thus to get all possible events by enlarging the scope of
  2234. // the month to get complete weeks covering the complete month, and then take out
  2235. // the events that start before the 1st ($start) or after the last day of the month ($end)
  2236. $time_orig = date('Y/n/W/j/N/G/i/s',$orig_start);
  2237. list($y_orig,$m_orig,$w_orig,$d_orig,$dw_orig,$h_orig,$n_orig,$s_orig) = split('/',$time_orig);
  2238. $time_orig_end = date('Y/n/W/j/N/G/i/s',$orig_end);
  2239. 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);
  2240. $time_now = date('Y/n/W/j/N/G/i/s',$end);
  2241. list($y_now,$m_now,$w_now,$d_now,$dw_now,$h_now,$n_now,$s_now) = split('/',$time_now);
  2242. $month_first_week = date('W',$start);
  2243. $month_last_week = date('W',$end);
  2244. if(($y_now>$y_orig) OR (($y_now == $y_orig) && ($w_now>$w_orig)))
  2245. { //if the event is after the original (at least one week) and the day of the week is the same
  2246. for($i=$month_first_week;$i<=$month_last_week;$i++)
  2247. {
  2248. //the "day of the week" of repetition is the same as the $dw_orig,
  2249. //so to get the "day of the month" from the "day of the week", we have
  2250. //to get the first "day of the week" for this week and add the number
  2251. //of days (in seconds) to reach the $dw_orig
  2252. //example: the first week spans between the 28th of April (Monday) to the
  2253. // 4th of May (Sunday). The event occurs on the 2nd day of each week.
  2254. // This means the event occurs on 29/4, 6/5, 13/5, 20/5 and 27/5.
  2255. // We want to get all of these, and then reject 29/4 because it is out
  2256. // of the month itself.
  2257. //First, to get the start time of the first day of the month view (even if
  2258. // the day is from the past month), we get the month start date (1/5) and
  2259. // see which day of the week it is, and subtract the number of days necessary
  2260. // to get back to the first day of the week.
  2261. $month_first_day_weekday = date('N',$start);
  2262. $first_week_start = $start - (($month_first_day_weekday-1)*86400);
  2263. //Second, we add the week day of the original event, so that we have an
  2264. // absolute time that represents the first repetition of the event in
  2265. // our 4- or 5-weeks timespan
  2266. $first_event_repeat_start = $first_week_start + (($dw_orig-1)*86400) + ($h_orig*3600) + ($n_orig*60) + $s_orig;
  2267. //Third, we start looping through the repetitions and see if they are between
  2268. // $start and $end
  2269. for($i = $first_event_repeat_start; $i<=$end; $i+=604800)
  2270. {
  2271. if($start<$i && $i<$end)
  2272. {
  2273. list($y_repeat,$m_repeat,$d_repeat,$h_repeat,$n_repeat,$s_repeat) = split('/',date('Y/m/j/H/i/s',$i));
  2274. $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']);
  2275. }
  2276. }
  2277. }
  2278. }
  2279. break;
  2280. case 'monthlyByDate':
  2281. $time_orig = date('Y/n/W/j/G/i/s',$orig_start);
  2282. list($y_orig,$m_orig,$w_orig,$d_orig,$h_orig,$n_orig,$s_orig) = split('/',$time_orig);
  2283. $time_now = date('Y/n/W/j/G/i/s',$end);
  2284. list($y_now,$m_now,$w_now,$d_now,$h_now,$n_now,$s_now) = split('/',$time_now);
  2285. $event_repetition_time = mktime($h_orig,$n_orig,$s_orig,$m_now,$d_orig,$y_now);
  2286. if(($y_now>$y_orig) OR (($y_now == $y_orig) && ($m_now>$m_orig)))
  2287. { //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
  2288. $time_orig_end = date('Y/n/j/G/i/s',$orig_end);
  2289. list($y_orig_e,$m_orig_e,$d_orig_e,$h_orig_e,$n_orig_e,$s_orig_e) = split('/',$time_orig_end);
  2290. $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']);
  2291. }
  2292. break;
  2293. case 'monthlyByDayR':
  2294. //not implemented yet
  2295. break;
  2296. case 'monthlyByDay':
  2297. //not implemented yet
  2298. break;
  2299. case 'yearly':
  2300. $time_orig = date('Y/n/j/z/G/i/s',$orig_start);
  2301. list($y_orig,$m_orig,$d_orig,$dy_orig,$h_orig,$n_orig,$s_orig) = split('/',$time_orig);
  2302. $time_now = date('Y/n/j/z/G/i/s',$end);
  2303. list($y_now,$m_now,$d_now,$dy_now,$h_now,$n_now,$s_now) = split('/',$time_now);
  2304. $event_repetition_time = mktime($h_orig,$n_orig,$s_orig,$m_orig,$d_orig,$y_now);
  2305. if((($y_now>$y_orig) && ($start<$event_repetition_time && $event_repetition_time<$end)))
  2306. {
  2307. $time_orig_end = date('Y/n/j/G/i/s',$orig_end);
  2308. 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);
  2309. $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']);
  2310. }
  2311. break;
  2312. default:
  2313. break;
  2314. }
  2315. }
  2316. }
  2317. return $events;
  2318. }
  2319. /**
  2320. * Get repeated events of a course between two dates (1 year timespan). Used for the list display.
  2321. * 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)
  2322. * Returns an array containing the events
  2323. * @param string Course info array (as returned by api_get_course_info())
  2324. * @param int UNIX timestamp of span start. Defaults 0, later transformed into today's start
  2325. * @param int UNIX timestamp. Defaults to 0, later transformed into today's end
  2326. * @param array A set of parameters to alter the SQL query
  2327. * @return array [int] => [course_id,parent_event_id,start_date,end_date,title,description]
  2328. */
  2329. function get_repeated_events_list_view($course_info,$start=0,$end=0,$params)
  2330. {
  2331. $events = array();
  2332. //block $end if higher than 2038 -- PHP doesn't go past that
  2333. if($end>2145934800){$end = 2145934800;}
  2334. //initialise all values
  2335. $y=0;
  2336. $m=0;
  2337. $d=0;
  2338. if(empty($start) or empty($end))
  2339. {
  2340. $time = time();
  2341. $y = date('Y');
  2342. $m = date('m');
  2343. }
  2344. if(empty($start))
  2345. {
  2346. $start = mktime(0, 0, 0, $m, 1, $y);
  2347. }
  2348. $db_start = date('Y-m-d H:i:s', $start);
  2349. if(empty($end))
  2350. {
  2351. $end = mktime(0, 0, 0, 1, 1, 2037);
  2352. }
  2353. //$db_end = date('Y-m-d H:i:s',$end);
  2354. $t_cal = Database::get_main_table(TABLE_MAIN_SYSTEM_CALENDAR,$course_info['dbName']);
  2355. $t_cal_repeat = Database::get_course_table(TABLE_AGENDA_REPEAT,$course_info['dbName']);
  2356. $t_ip = Database::get_course_table(TABLE_ITEM_PROPERTY,$course_info['dbName']);
  2357. $sql = "SELECT c.id, c.title, c.content, " .
  2358. " UNIX_TIMESTAMP(c.start_date) as orig_start, UNIX_TIMESTAMP(c.end_date) as orig_end, " .
  2359. " cr.cal_type, cr.cal_end " .
  2360. " FROM $t_cal c, $t_cal_repeat cr, $t_ip as item_property " .
  2361. " WHERE cr.cal_end >= $start " .
  2362. " AND cr.cal_id = c.id " .
  2363. " AND item_property.ref = c.id ".
  2364. " AND item_property.tool = '".TOOL_CALENDAR_EVENT."' ".
  2365. " AND c.start_date <= '$db_start' "
  2366. .(!empty($params['conditions'])?$params['conditions']:'')
  2367. .(!empty($params['groupby'])?' GROUP BY '.$params['groupby']:'')
  2368. .(!empty($params['orderby'])?' ORDER BY '.$params['orderby']:'');
  2369. $res = Database::query($sql);
  2370. if(Database::num_rows($res)>0)
  2371. {
  2372. while($row = Database::fetch_array($res))
  2373. {
  2374. $orig_start = $row['orig_start'];
  2375. $orig_end = $row['orig_end'];
  2376. $repeat_type = $row['cal_type'];
  2377. $repeat_end = $row['cal_end'];
  2378. switch($repeat_type)
  2379. {
  2380. case 'daily':
  2381. $time_orig_h = date('H',$orig_start);
  2382. $time_orig_m = date('i',$orig_start);
  2383. $time_orig_s = date('s',$orig_start);
  2384. $span = $orig_end - $orig_start; //total seconds between start and stop of original event
  2385. for($i=$orig_start+86400;($i<$end && $i<=$repeat_end);$i+=86400)
  2386. {
  2387. $current_start = $i; //unixtimestamp start of today's event
  2388. $current_stop = $i + $span; //unixtimestamp stop of today's event
  2389. $events[] = array($course_info['id'],$row['id'],$current_start,$current_stop,$row['title'],$row['content']);
  2390. }
  2391. break;
  2392. case 'weekly':
  2393. //A weekly repeated event is very difficult to catch in a month view,
  2394. // because weeks start before or at the same time as the first day of the month
  2395. //The same can be said for the end of the month.
  2396. // The idea is thus to get all possible events by enlarging the scope of
  2397. // the month to get complete weeks covering the complete month, and then take out
  2398. // the events that start before the 1st ($start) or after the last day of the month ($end)
  2399. $time_orig = date('Y/n/W/j/N/G/i/s',$orig_start);
  2400. list($y_orig,$m_orig,$w_orig,$d_orig,$dw_orig,$h_orig,$n_orig,$s_orig) = split('/',$time_orig);
  2401. $time_orig_end = date('Y/n/W/j/N/G/i/s',$orig_end);
  2402. 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);
  2403. $time_now = date('Y/n/W/j/N/G/i/s',$end);
  2404. list($y_now,$m_now,$w_now,$d_now,$dw_now,$h_now,$n_now,$s_now) = split('/',$time_now);
  2405. if($w_now==52)
  2406. {
  2407. ++$y_now;
  2408. $w_now=1;
  2409. }
  2410. else
  2411. {
  2412. ++$w_now;
  2413. }
  2414. $month_first_week = date('W',$start);
  2415. $total_weeks = ((date('Y',$end)-$y_orig)-1)*52;
  2416. $month_last_week = $month_first_week + $total_weeks;
  2417. if(($y_now>$y_orig) OR (($y_now == $y_orig) && ($w_now>$w_orig)))
  2418. { //if the event is after the original (at least one week) and the day of the week is the same
  2419. //for($i=$month_first_week;($i<=$month_last_week && $i<1000);$i++)
  2420. //{
  2421. /*
  2422. The "day of the week" of repetition is the same as the $dw_orig,
  2423. so to get the "day of the month" from the "day of the week", we have
  2424. to get the first "day of the week" for this week and add the number
  2425. of days (in seconds) to reach the $dw_orig
  2426. example: the first week spans between the 28th of April (Monday) to the
  2427. 4th of May (Sunday). The event occurs on the 2nd day of each week.
  2428. This means the event occurs on 29/4, 6/5, 13/5, 20/5 and 27/5.
  2429. We want to get all of these, and then reject 29/4 because it is out
  2430. of the month itself.
  2431. First, to get the start time of the first day of the month view (even if
  2432. the day is from the past month), we get the month start date (1/5) and
  2433. see which day of the week it is, and subtract the number of days necessary
  2434. to get back to the first day of the week.
  2435. */
  2436. $month_first_day_weekday = date('N',$start);
  2437. $first_week_start = $start - (($month_first_day_weekday-1)*86400);
  2438. //Second, we add the week day of the original event, so that we have an
  2439. // absolute time that represents the first repetition of the event in
  2440. // our 4- or 5-weeks timespan
  2441. $first_event_repeat_start = $first_week_start + (($dw_orig-1)*86400) + ($h_orig*3600) + ($n_orig*60) + $s_orig;
  2442. //Third, we start looping through the repetitions and see if they are between
  2443. // $start and $end
  2444. for($i = $first_event_repeat_start; ($i<=$end && $i<=$repeat_end); $i+=604800)
  2445. {
  2446. if($start<$i && $i<=$end && $i<=$repeat_end)
  2447. {
  2448. list($y_repeat,$m_repeat,$d_repeat,$h_repeat,$n_repeat,$s_repeat) = split('/',date('Y/m/j/H/i/s',$i));
  2449. $new_start_time = mktime($h_orig,$n_orig,$s_orig,$m_now,$d_orig,$y_now);
  2450. $new_stop_time = mktime($h_orig_e,$n_orig_e,$s_orig_e,$m_now,$d_orig_e,$y_now);
  2451. $events[] = array($course_info['id'], $row['id'], $new_start_time, $new_stop_time, $row['title'], $row['content']);
  2452. }
  2453. $time_now = date('Y/n/W/j/N/G/i/s',$i+604800);
  2454. list($y_now,$m_now,$w_now,$d_now,$dw_now,$h_now,$n_now,$s_now) = split('/',$time_now);
  2455. }
  2456. //}
  2457. }
  2458. break;
  2459. case 'monthlyByDate':
  2460. $time_orig = date('Y/n/W/j/G/i/s',$orig_start);
  2461. list($y_orig,$m_orig,$w_orig,$d_orig,$h_orig,$n_orig,$s_orig) = split('/',$time_orig);
  2462. $time_now = date('Y/n/W/j/G/i/s',$start);
  2463. list($y_now,$m_now,$w_now,$d_now,$h_now,$n_now,$s_now) = split('/',$time_now);
  2464. //make sure we are one month ahead (to avoid being the same month as the original event)
  2465. if($m_now==12)
  2466. {
  2467. ++$y_now;
  2468. $m_now = 1;
  2469. }
  2470. else
  2471. {
  2472. ++$m_now;
  2473. }
  2474. $time_orig_end = date('Y/n/j/G/i/s',$orig_end);
  2475. list($y_orig_e,$m_orig_e,$d_orig_e,$h_orig_e,$n_orig_e,$s_orig_e) = split('/',$time_orig_end);
  2476. $event_repetition_time = mktime($h_orig,$n_orig,$s_orig,$m_now,$d_orig,$y_now);
  2477. $diff = $orig_end - $orig_start;
  2478. while((($y_now>$y_orig) OR (($y_now == $y_orig) && ($m_now>$m_orig))) && ($event_repetition_time < $end) && ($event_repetition_time < $repeat_end))
  2479. { //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
  2480. $new_start_time = mktime($h_orig,$n_orig,$s_orig,$m_now,$d_orig,$y_now);
  2481. $new_stop_time = mktime($h_orig_e,$n_orig_e,$s_orig_e,$m_now,$d_orig_e,$y_now);
  2482. $events[] = array($course_info['id'],$row['id'],$new_start_time,$new_stop_time,$row['title'],$row['content']);
  2483. if($m_now==12)
  2484. {
  2485. ++$y_now;
  2486. $m_now = 1;
  2487. }
  2488. else
  2489. {
  2490. ++$m_now;
  2491. }
  2492. $event_repetition_time = mktime($h_orig,$n_orig,$s_orig,$m_now,$d_orig,$y_now);
  2493. }
  2494. break;
  2495. case 'monthlyByDayR':
  2496. //not implemented yet
  2497. break;
  2498. case 'monthlyByDay':
  2499. //not implemented yet
  2500. break;
  2501. case 'yearly':
  2502. $time_orig = date('Y/n/j/z/G/i/s',$orig_start);
  2503. list($y_orig,$m_orig,$d_orig,$dy_orig,$h_orig,$n_orig,$s_orig) = split('/',$time_orig);
  2504. $time_now = date('Y/n/j/z/G/i/s',$end);
  2505. list($y_now,$m_now,$d_now,$dy_now,$h_now,$n_now,$s_now) = split('/',$time_now);
  2506. $event_repetition_time = mktime($h_orig,$n_orig,$s_orig,$m_orig,$d_orig,$y_now);
  2507. while((($y_now>$y_orig) && ($start<$event_repetition_time && $event_repetition_time<$end && $event_repetition_time<$repeat_end)))
  2508. {
  2509. $time_orig_end = date('Y/n/j/G/i/s',$orig_end);
  2510. 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);
  2511. $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']);
  2512. ++$y_now;
  2513. $event_repetition_time = mktime($h_orig,$n_orig,$s_orig,$m_orig,$d_orig,$y_now);
  2514. }
  2515. break;
  2516. default:
  2517. break;
  2518. }
  2519. }
  2520. }
  2521. return $events;
  2522. }
  2523. /**
  2524. * Tells if an agenda item is repeated
  2525. * @param string Course database
  2526. * @param int The agenda item
  2527. * @return boolean True if repeated, false otherwise
  2528. */
  2529. function is_repeated_event($id,$course=null)
  2530. {
  2531. if(empty($course))
  2532. {
  2533. $course_info = api_get_course_info();
  2534. $course = $course_info['dbName'];
  2535. }
  2536. $id = (int) $id;
  2537. //$t_agenda_repeat = Database::get_course_table(TABLE_AGENDA_REPEAT,$course);
  2538. $sql = "SELECT * FROM $t_agenda_repeat WHERE cal_id = $id";
  2539. $res = Database::query($sql);
  2540. if(Database::num_rows($res)>0)
  2541. {
  2542. return true;
  2543. }
  2544. return false;
  2545. }
  2546. /**
  2547. * Adds x weeks to a UNIX timestamp
  2548. * @param int The timestamp
  2549. * @param int The number of weeks to add
  2550. * @return int The new timestamp
  2551. */
  2552. function add_week($timestamp,$num=1)
  2553. {
  2554. return $timestamp + $num*604800;
  2555. }
  2556. /**
  2557. * Adds x months to a UNIX timestamp
  2558. * @param int The timestamp
  2559. * @param int The number of years to add
  2560. * @return int The new timestamp
  2561. */
  2562. function add_month($timestamp,$num=1)
  2563. {
  2564. list($y, $m, $d, $h, $n, $s) = split('/',date('Y/m/d/h/i/s',$timestamp));
  2565. if($m+$num>12)
  2566. {
  2567. $y += floor($num/12);
  2568. $m += $num%12;
  2569. }
  2570. else
  2571. {
  2572. $m += $num;
  2573. }
  2574. return mktime($h, $n, $s, $m, $d, $y);
  2575. }
  2576. /**
  2577. * Adds x years to a UNIX timestamp
  2578. * @param int The timestamp
  2579. * @param int The number of years to add
  2580. * @return int The new timestamp
  2581. */
  2582. function add_year($timestamp,$num=1)
  2583. {
  2584. list($y, $m, $d, $h, $n, $s) = split('/',date('Y/m/d/h/i/s',$timestamp));
  2585. return mktime($h, $n, $s, $m, $d, $y+$num);
  2586. }
  2587. /**
  2588. * Adds an agenda item in the database. Similar to store_new_agenda_item() except it takes parameters
  2589. * @param array Course info
  2590. * @param string Event title
  2591. * @param string Event content/description
  2592. * @param string Start date
  2593. * @param string End date
  2594. * @param array List of groups to which this event is added
  2595. * @param int Parent id (optional)
  2596. * @return int The new item's DB ID
  2597. */
  2598. function agenda_add_item($title, $content, $db_start_date, $db_end_date) {
  2599. $user_id = api_get_user_id();
  2600. $t_agenda = Database::get_main_table(TABLE_MAIN_SYSTEM_CALENDAR);
  2601. // some filtering of the input data
  2602. $title = Database::escape_string($title); // no html allowed in the title
  2603. $content = Database::escape_string($content);
  2604. $db_start_date = api_get_utc_datetime($db_start_date);
  2605. $start_date = Database::escape_string($db_start_date);
  2606. $db_end_date = api_get_utc_datetime($db_end_date);
  2607. $end_date = Database::escape_string($db_end_date);
  2608. // check if exists in calendar_event table
  2609. $sql = "SELECT * FROM $t_agenda WHERE title='$title' AND content = '$content' AND start_date = '$start_date' AND end_date = '$end_date' ";
  2610. $result = Database::query($sql);
  2611. $count = Database::num_rows($result);
  2612. if ($count > 0) {
  2613. return false;
  2614. }
  2615. $sql = "INSERT INTO $t_agenda (title,content, start_date, end_date, access_url_id)
  2616. VALUES ('".$title."','".$content."', '".$start_date."','".$end_date."', '".api_get_current_access_url_id()."')";
  2617. $result = Database::query($sql);
  2618. $last_id = Database::insert_id();
  2619. return $last_id;
  2620. }
  2621. /**
  2622. * Adds a repetitive item to the database
  2623. * @param array Course info
  2624. * @param int The original event's id
  2625. * @param string Type of repetition
  2626. * @param int Timestamp of end of repetition (repeating until that date)
  2627. * @param array Original event's destination
  2628. * @return boolean False if error, True otherwise
  2629. */
  2630. function get_calendar_items($month, $year) {
  2631. global $_user, $_course;
  2632. global $is_allowed_to_edit;
  2633. $month=Database::escape_string($month);
  2634. $year=Database::escape_string($year);
  2635. // database variables
  2636. $TABLEAGENDA = Database::get_main_table(TABLE_MAIN_SYSTEM_CALENDAR);
  2637. //$TABLE_ITEM_PROPERTY=Database::get_course_table(TABLE_ITEM_PROPERTY);
  2638. $month_first_day = mktime(0,0,0,$month,1,$year);
  2639. $month_last_day = mktime(0,0,0,$month+1,1,$year)-1;
  2640. if ($month==12) {
  2641. $month_last_day = mktime(0,0,0,1,1,$year+1)-1;
  2642. }
  2643. $repeats = array();
  2644. $data=array();
  2645. if (api_is_allowed_to_edit()) {
  2646. $sql="SELECT DISTINCT *
  2647. FROM ".$TABLEAGENDA." agenda
  2648. WHERE MONTH(start_date)='".$month."' AND YEAR(start_date)='".$year."'";
  2649. global $_configuration;
  2650. $current_access_url_id = 1;
  2651. if ($_configuration['multiple_access_urls']) {
  2652. $current_access_url_id = api_get_current_access_url_id();
  2653. }
  2654. $sql .= " AND access_url_id = '$current_access_url_id' ";
  2655. $sql .= "GROUP BY id ORDER BY start_date ";
  2656. $result=Database::query($sql);
  2657. while ($row=Database::fetch_array($result)) {
  2658. $datum_item=(int)substr($row["start_date"],8,2);
  2659. $data[$datum_item][intval($datum_item)][] = $row;
  2660. }
  2661. }
  2662. return $data;
  2663. }
  2664. /**
  2665. * This function is not been used or deprecated
  2666. */
  2667. function agenda_add_repeat_item($course_info,$orig_id,$type,$end,$orig_dest)
  2668. {/*
  2669. $t_agenda = Database::get_main_table(TABLE_MAIN_SYSTEM_CALENDAR,$course_info['dbName']);
  2670. // $t_agenda_r = Database::get_course_table(TABLE_AGENDA_REPEAT,$course_info['dbName']);
  2671. //$sql = "SELECT title, content, UNIX_TIMESTAMP(start_date) as sd, UNIX_TIMESTAMP(end_date) as ed FROM $t_agenda WHERE id = $orig_id";
  2672. $sql = "SELECT title, content, start_date as sd, end_date as ed FROM $t_agenda WHERE id = $orig_id";
  2673. $res = Database::query($sql);
  2674. if(Database::num_rows($res)!==1){return false;}
  2675. $row = Database::fetch_array($res);
  2676. //$orig_start = $row['sd'];
  2677. $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));
  2678. //$orig_end = $row['ed'];
  2679. $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));
  2680. $diff = $orig_end - $orig_start;
  2681. $orig_title = $row['title'];
  2682. $orig_content = $row['content'];
  2683. $now = time();
  2684. $type = Database::escape_string($type);
  2685. $end = (int) $end;
  2686. if(1<=$end && $end<=500)
  2687. {
  2688. //we assume that, with this type of value, the user actually gives a count of repetitions
  2689. //and that he wants us to calculate the end date with that (particularly in case of imports from ical)
  2690. switch($type)
  2691. {
  2692. case 'daily':
  2693. $end = $orig_start + (86400*$end);
  2694. break;
  2695. case 'weekly':
  2696. $end = add_week($orig_start,$end);
  2697. break;
  2698. case 'monthlyByDate':
  2699. $end = add_month($orig_start,$end);
  2700. break;
  2701. case 'monthlyByDay':
  2702. //TODO
  2703. break;
  2704. case 'monthlyByDayR':
  2705. //TODO
  2706. break;
  2707. case 'yearly':
  2708. $end = add_year($orig_start,$end);
  2709. break;
  2710. }
  2711. }
  2712. if($end > $now
  2713. && in_array($type,array('daily','weekly','monthlyByDate','monthlyByDay','monthlyByDayR','yearly')))
  2714. {
  2715. $sql = "INSERT INTO $t_agenda_r (cal_id, cal_type, cal_end)" .
  2716. " VALUES ($orig_id,'$type',$end)";
  2717. $res = Database::query($sql);
  2718. switch($type)
  2719. {
  2720. case 'daily':
  2721. for($i = $orig_start + 86400; ($i <= $end); $i += 86400)
  2722. {
  2723. $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);
  2724. }
  2725. break;
  2726. case 'weekly':
  2727. for($i = $orig_start + 604800; ($i <= $end); $i += 604800)
  2728. {
  2729. $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);
  2730. }
  2731. break;
  2732. case 'monthlyByDate':
  2733. $next_start = add_month($orig_start);
  2734. while($next_start <= $end)
  2735. {
  2736. $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);
  2737. $next_start = add_month($next_start);
  2738. }
  2739. break;
  2740. case 'monthlyByDay':
  2741. //not yet implemented
  2742. break;
  2743. case 'monthlyByDayR':
  2744. //not yet implemented
  2745. break;
  2746. case 'yearly':
  2747. $next_start = add_year($orig_start);
  2748. while($next_start <= $end)
  2749. {
  2750. $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);
  2751. $next_start = add_year($next_start);
  2752. }
  2753. break;
  2754. }
  2755. }
  2756. return true;*/
  2757. }
  2758. /**
  2759. * Import an iCal file into the database
  2760. * @param array Course info
  2761. * @return boolean True on success, false otherwise
  2762. */
  2763. function agenda_import_ical($course_info,$file) {
  2764. require_once api_get_path(LIBRARY_PATH).'fileUpload.lib.php';
  2765. $charset = api_get_system_encoding();
  2766. $filepath = api_get_path(SYS_ARCHIVE_PATH).$file['name'];
  2767. if(!@move_uploaded_file($file['tmp_name'],$filepath))
  2768. {
  2769. error_log('Problem moving uploaded file: '.$file['error'].' in '.__FILE__.' line '.__LINE__);
  2770. return false;
  2771. }
  2772. require_once api_get_path(LIBRARY_PATH).'icalcreator/iCalcreator.class.php';
  2773. $ical = new vcalendar();
  2774. $ical->setConfig('directory', dirname($filepath) );
  2775. $ical->setConfig('filename', basename($filepath) );
  2776. $ical->parse();
  2777. //we need to recover: summary, description, dtstart, dtend, organizer, attendee, location (=course name),
  2778. // rrule
  2779. $ve = $ical->getComponent(VEVENT);
  2780. //print_r($ve);
  2781. $ttitle = $ve->getProperty('summary');
  2782. //print_r($ttitle);
  2783. $title = api_convert_encoding($ttitle,$charset,'UTF-8');
  2784. $tdesc = $ve->getProperty('description');
  2785. $desc = api_convert_encoding($tdesc,$charset,'UTF-8');
  2786. $ts = $ve->getProperty('dtstart');
  2787. $start_date = $ts['year'].'-'.$ts['month'].'-'.$ts['day'].' '.$ts['hour'].':'.$ts['min'].':'.$ts['sec'];
  2788. $ts = $ve->getProperty('dtend');
  2789. $end_date = $ts['year'].'-'.$ts['month'].'-'.$ts['day'].' '.$ts['hour'].':'.$ts['min'].':'.$ts['sec'];
  2790. //echo $start_date.' - '.$end_date;
  2791. $organizer = $ve->getProperty('organizer');
  2792. $attendee = $ve->getProperty('attendee');
  2793. $course_name = $ve->getProperty('location');
  2794. //insert the event in our database
  2795. $id = agenda_add_item($course_info,$title,$desc,$start_date,$end_date,$_POST['selectedform']);
  2796. $repeat = $ve->getProperty('rrule');
  2797. if(is_array($repeat) && !empty($repeat['FREQ']))
  2798. {
  2799. $trans = array('DAILY'=>'daily','WEEKLY'=>'weekly','MONTHLY'=>'monthlyByDate','YEARLY'=>'yearly');
  2800. $freq = $trans[$repeat['FREQ']];
  2801. $interval = $repeat['INTERVAL'];
  2802. if(isset($repeat['UNTIL']) && is_array($repeat['UNTIL']))
  2803. {
  2804. $until = mktime(23,59,59,$repeat['UNTIL']['month'],$repeat['UNTIL']['day'],$repeat['UNTIL']['year']);
  2805. $res = agenda_add_repeat_item($course_info,$id,$freq,$until,$_POST['selectedform']);
  2806. }
  2807. //TODO: deal with count
  2808. if(!empty($repeat['COUNT']))
  2809. {
  2810. $count = $repeat['COUNT'];
  2811. $res = agenda_add_repeat_item($course_info,$id,$freq,$count,$_POST['selectedform']);
  2812. }
  2813. }
  2814. return true;
  2815. }
  2816. ?>