calendar.lib.php 136 KB

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