calendar.lib.php 122 KB

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