calendar.lib.php 121 KB

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