calendar.lib.php 120 KB

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