calendar.lib.php 125 KB

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