calendar.lib.php 121 KB

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