calendar.lib.php 122 KB

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