myagenda.inc.php 45 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115
  1. <?php //$id: $
  2. /*
  3. ==============================================================================
  4. Dokeos - elearning and course management software
  5. Copyright (c) 2004 Dokeos S.A.
  6. Copyright (c) 2003 Ghent University (UGent)
  7. For a full list of contributors, see "credits.txt".
  8. The full license can be read in "license.txt".
  9. This program is free software; you can redistribute it and/or
  10. modify it under the terms of the GNU General Public License
  11. as published by the Free Software Foundation; either version 2
  12. of the License, or (at your option) any later version.
  13. See the GNU General Public License for more details.
  14. Contact: Dokeos, 181 rue Royale, B-1000 Brussels, Belgium, info@dokeos.com
  15. ==============================================================================
  16. @author: Patrick Cool <patrick.cool@UGent.be>, Ghent University
  17. @author: Toon Van Hoecke <toon.vanhoecke@ugent.be>, Ghent University
  18. @author: Eric Remy (initial version)
  19. @version: 2.2 alpha
  20. @description: this file generates a general agenda of all items of the
  21. courses the user is registered for
  22. ==============================================================================
  23. version info:
  24. -------------
  25. -> version 2.2 : Patrick Cool, patrick.cool@ugent.be, november 2004
  26. Personal Agenda added. The user can add personal agenda items. The items
  27. are stored in a dokeos_user database because it is not course or platform
  28. based. A personal agenda view was also added. This lists all the personal
  29. agenda items of that user.
  30. -> version 2.1 : Patrick Cool, patrick.cool@ugent.be, , oktober 2004
  31. This is the version that works with the Group based Agenda tool.
  32. -> version 2.0 (alpha): Patrick Cool, patrick.cool@ugent.be, , oktober 2004
  33. The 2.0 version introduces besides the month view also a week- and day view.
  34. In the 2.5 (final) version it will be possible for the student to add his/her
  35. own agenda items. The platform administrator can however decide if the students
  36. are allowed to do this or not.
  37. The alpha version only contains the three views. The personal agenda feature is
  38. not yet completely finished. There are however already some parts of the code
  39. for adding a personal agenda item present.
  40. this code was not released in an official dokeos but was only used in the offical
  41. server of the Ghent University where it underwent serious testing
  42. -> version 1.5: Toon Van Hoecke, toon.vanhoecke@ugent.be, december 2003
  43. -> version 1.0: Eric Remy, eremy@rmwc.edu, 6 Oct 2003
  44. The tool was initially called master-calendar as it collects all the calendar
  45. items of all the courses one is subscribed to. It was very soon integrated in
  46. Dokeos as this was a really basic and very usefull tool.
  47. */
  48. /**
  49. * This function retrieves all the agenda items of all the course of the user
  50. */
  51. function get_agendaitems($courses_dbs, $month, $year)
  52. {
  53. global $_user;
  54. global $_configuration;
  55. $items = array ();
  56. // get agenda-items for every course
  57. foreach ($courses_dbs as $key => $array_course_info)
  58. {
  59. //databases of the courses
  60. $TABLEAGENDA = Database :: get_course_table(TABLE_AGENDA, $array_course_info["db"]);
  61. $TABLE_ITEMPROPERTY = Database :: get_course_table(TABLE_ITEM_PROPERTY, $array_course_info["db"]);
  62. $group_memberships = GroupManager :: get_group_ids($array_course_info["db"], $_user['user_id']);
  63. // if the user is administrator of that course we show all the agenda items
  64. if ($array_course_info['status'] == '1')
  65. {
  66. //echo "course admin";
  67. $sqlquery = "SELECT
  68. DISTINCT agenda.*, item_property.*
  69. FROM ".$TABLEAGENDA." agenda,
  70. ".$TABLE_ITEMPROPERTY." item_property
  71. WHERE agenda.id = item_property.ref ".$show_all_current."
  72. AND MONTH(agenda.start_date)='".$month."'
  73. AND YEAR(agenda.start_date)='".$year."'
  74. AND item_property.tool='".TOOL_CALENDAR_EVENT."'
  75. AND item_property.visibility='1'
  76. GROUP BY agenda.id
  77. ORDER BY start_date ".$sort;
  78. }
  79. // if the user is not an administrator of that course
  80. else
  81. {
  82. //echo "GEEN course admin";
  83. if (is_array($group_memberships))
  84. {
  85. $sqlquery = "SELECT
  86. agenda.*, item_property.*
  87. FROM ".$TABLEAGENDA." agenda,
  88. ".$TABLE_ITEMPROPERTY." item_property
  89. WHERE `agenda`.`id` = `item_property`.`ref` ".$show_all_current."
  90. AND MONTH(`agenda`.`start_date`)='".$month."'
  91. AND YEAR(`agenda`.`start_date`)='".$year."'
  92. AND `item_property`.`tool`='".TOOL_CALENDAR_EVENT."'
  93. AND ( `item_property`.`to_user_id`='".$_user['user_id']."' OR `item_property`.`to_group_id` IN (0, ".implode(", ", $group_memberships).") )
  94. AND `item_property`.`visibility`='1'
  95. ORDER BY start_date ".$sort;
  96. }
  97. else
  98. {
  99. $sqlquery = "SELECT
  100. agenda.*, item_property.*
  101. FROM ".$TABLEAGENDA." agenda,
  102. ".$TABLE_ITEMPROPERTY." item_property
  103. WHERE `agenda`.`id` = `item_property`.`ref` ".$show_all_current."
  104. AND MONTH(`agenda`.`start_date`)='".$month."'
  105. AND YEAR(`agenda`.`start_date`)='".$year."'
  106. AND `item_property`.`tool`='".TOOL_CALENDAR_EVENT."'
  107. AND ( `item_property`.`to_user_id`='".$_user['user_id']."' OR `item_property`.`to_group_id`='0')
  108. AND `item_property`.`visibility`='1'
  109. ORDER BY start_date ".$sort;
  110. }
  111. }
  112. $result = api_sql_query($sqlquery, __FILE__, __LINE__);
  113. while ($item = mysql_fetch_array($result))
  114. {
  115. $agendaday = date("j",strtotime($item['start_date']));
  116. $time= date("H:i",strtotime($item['start_date']));
  117. $URL = api_get_path(WEB_PATH)."main/calendar/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
  118. $items[$agendaday][$item['start_time']] .= "<i>".$time."</i> <a href=\"$URL\" title=\"".$array_course_info["name"]."\">".$array_course_info["visual_code"]."</a> ".$item['title']."<br />";
  119. }
  120. }
  121. // sorting by hour for every day
  122. $agendaitems = array ();
  123. while (list ($agendaday, $tmpitems) = each($items))
  124. {
  125. sort($tmpitems);
  126. while (list ($key, $val) = each($tmpitems))
  127. {
  128. $agendaitems[$agendaday] .= $val;
  129. }
  130. }
  131. //print_r($agendaitems);
  132. return $agendaitems;
  133. }
  134. /**
  135. * Show the monthcalender of the given month
  136. */
  137. function display_monthcalendar($agendaitems, $month, $year, $weekdaynames, $monthName)
  138. {
  139. global $DaysShort,$course_path;
  140. //Handle leap year
  141. $numberofdays = array (0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
  142. if (($year % 400 == 0) or ($year % 4 == 0 and $year % 100 <> 0))
  143. $numberofdays[2] = 29;
  144. //Get the first day of the month
  145. $dayone = getdate(mktime(0, 0, 0, $month, 1, $year));
  146. //Start the week on monday
  147. $startdayofweek = $dayone['wday'] <> 0 ? ($dayone['wday'] - 1) : 6;
  148. $backwardsURL = api_get_self()."?coursePath=".urlencode($course_path)."&amp;courseCode=".Security::remove_XSS($_GET['courseCode'])."&amp;action=view&amp;view=month&amp;month=". ($month == 1 ? 12 : $month -1)."&amp;year=". ($month == 1 ? $year -1 : $year);
  149. $forewardsURL = api_get_self()."?coursePath=".urlencode($course_path)."&amp;courseCode=".Security::remove_XSS($_GET['courseCode'])."&amp;action=view&amp;view=month&amp;month=". ($month == 12 ? 1 : $month +1)."&amp;year=". ($month == 12 ? $year +1 : $year);
  150. echo "<table id=\"agenda_list\">\n", "<tr class=\"title\">\n", "<td width=\"10%\"><a href=\"", $backwardsURL, "\">&#171;</a></td>\n", "<td width=\"80%\" colspan=\"5\">", $monthName, " ", $year, "</td>\n", "<td width=\"10%\"><a href=\"", $forewardsURL, "\">&#187;</a></td>\n", "</tr>\n";
  151. echo "<tr>\n";
  152. for ($ii = 1; $ii < 8; $ii ++)
  153. {
  154. echo "<td class=\"weekdays\">", $DaysShort[$ii % 7], "</td>\n";
  155. }
  156. echo "</tr>\n";
  157. $curday = -1;
  158. $today = getdate();
  159. while ($curday <= $numberofdays[$month])
  160. {
  161. echo "<tr>\n";
  162. for ($ii = 0; $ii < 7; $ii ++)
  163. {
  164. if (($curday == -1) && ($ii == $startdayofweek))
  165. {
  166. $curday = 1;
  167. }
  168. if (($curday > 0) && ($curday <= $numberofdays[$month]))
  169. {
  170. $bgcolor = $ii < 5 ? $class = "class=\"days_week\"" : $class = "class=\"days_weekend\"";
  171. $dayheader = "<b>$curday</b>";
  172. if (($curday == $today[mday]) && ($year == $today[year]) && ($month == $today[mon]))
  173. {
  174. $dayheader = "$curday - ".get_lang("Today")."<br />";
  175. $class = "class=\"days_today\"";
  176. }
  177. echo "<td ".$class.">", "".$dayheader;
  178. if (!empty($agendaitems[$curday]))
  179. {
  180. echo "<span class=\"agendaitem\">".$agendaitems[$curday]."</span>";
  181. }
  182. echo "</td>\n";
  183. $curday ++;
  184. }
  185. else
  186. {
  187. echo "<td>&nbsp;</td>\n";
  188. }
  189. }
  190. echo "</tr>\n";
  191. }
  192. echo "</table>\n";
  193. }
  194. /**
  195. * Show the mini calender of the given month
  196. */
  197. function display_minimonthcalendar($agendaitems, $month, $year, $monthName)
  198. {
  199. global $DaysShort,$course_path;
  200. //Handle leap year
  201. $numberofdays = array (0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
  202. if (($year % 400 == 0) or ($year % 4 == 0 and $year % 100 <> 0))
  203. $numberofdays[2] = 29;
  204. //Get the first day of the month
  205. $dayone = getdate(mktime(0, 0, 0, $month, 1, $year));
  206. //Start the week on monday
  207. $startdayofweek = $dayone['wday'] <> 0 ? ($dayone['wday'] - 1) : 6;
  208. $backwardsURL = api_get_self()."?coursePath=".urlencode($course_path)."&amp;courseCode=".Security::remove_XSS($_GET['courseCode'])."&amp;month=". ($month == 1 ? 12 : $month -1)."&amp;year=". ($month == 1 ? $year -1 : $year);
  209. $forewardsURL = api_get_self()."?coursePath=".urlencode($course_path)."&amp;courseCode=".Security::remove_XSS($_GET['courseCode'])."&amp;month=". ($month == 12 ? 1 : $month +1)."&amp;year=". ($month == 12 ? $year +1 : $year);
  210. echo "<table id=\"smallcalendar\">\n", "<tr class=\"title\">\n", "<td width=\"10%\"><a href=\"", $backwardsURL, "\">&#171;</a></td>\n", "<td width=\"80%\" colspan=\"5\">", $monthName, " ", $year, "</td>\n", "<td width=\"10%\"><a href=\"", $forewardsURL, "\">&#187;</a></td>\n", "</tr>\n";
  211. echo "<tr>\n";
  212. for ($ii = 1; $ii < 8; $ii ++)
  213. {
  214. echo "<td class=\"weekdays\">", $DaysShort[$ii % 7], "</td>\n";
  215. }
  216. echo "</tr>\n";
  217. $curday = -1;
  218. $today = getdate();
  219. while ($curday <= $numberofdays[$month])
  220. {
  221. echo "<tr>\n";
  222. for ($ii = 0; $ii < 7; $ii ++)
  223. {
  224. if (($curday == -1) && ($ii == $startdayofweek))
  225. {
  226. $curday = 1;
  227. }
  228. if (($curday > 0) && ($curday <= $numberofdays[$month]))
  229. {
  230. $bgcolor = $ii < 5 ? $class = "class=\"days_week\"" : $class = "class=\"days_weekend\"";
  231. $dayheader = "$curday";
  232. if (($curday == $today[mday]) && ($year == $today[year]) && ($month == $today[mon]))
  233. {
  234. $dayheader = "$curday";
  235. $class = "class=\"days_today\"";
  236. }
  237. echo "\t<td ".$class.">";
  238. if ($agendaitems[$curday] <> "")
  239. {
  240. echo "<a href=\"".api_get_self()."?action=view&amp;view=day&amp;day=".$curday."&amp;month=".$month."&amp;year=".$year."\">".$dayheader."</a>";
  241. }
  242. else
  243. {
  244. echo $dayheader;
  245. }
  246. // "a".$dayheader." <span class=\"agendaitem\">".$agendaitems[$curday]."</span>\n";
  247. echo "</td>\n";
  248. $curday ++;
  249. }
  250. else
  251. {
  252. echo "<td>&nbsp;</td>\n";
  253. }
  254. }
  255. echo "</tr>\n";
  256. }
  257. echo "</table>\n";
  258. }
  259. /**
  260. * Display the weekly view of the calendar
  261. */
  262. function display_weekcalendar($agendaitems, $month, $year, $weekdaynames, $monthName)
  263. {
  264. global $DaysShort,$course_path;
  265. global $MonthsLong;
  266. // timestamp of today
  267. $today = time();
  268. $day_of_the_week = date("w", $today);
  269. $thisday_of_the_week = date("w", $today);
  270. // the week number of the year
  271. $week_number = date("W", $today);
  272. $thisweek_number = $week_number;
  273. // if we moved to the next / previous week we have to recalculate the $today variable
  274. if ($_GET['week'])
  275. {
  276. $today = mktime(0, 0, 0, 1, 1, $year);
  277. $today = $today + (((int)$_GET['week']-1) * (7 * 24 * 60 * 60));
  278. $week_number = date("W", $today);
  279. }
  280. // calculating the start date of the week
  281. // the date of the monday of this week is the timestamp of today minus
  282. // number of days that have already passed this week * 24 hours * 60 minutes * 60 seconds
  283. $current_day = date("j", $today); // Day of the month without leading zeros (1 to 31) of today
  284. $day_of_the_week = date("w", $today); // Numeric representation of the day of the week 0 (for Sunday) through 6 (for Saturday) of today
  285. $timestamp_first_date_of_week = $today - (($day_of_the_week -1) * 24 * 60 * 60); // timestamp of the monday of this week
  286. $timestamp_last_date_of_week = $today + ((7 - $day_of_the_week) * 24 * 60 * 60); // timestamp of the sunday of this week
  287. $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);
  288. $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);
  289. echo "<table id=\"agenda_list\">\n";
  290. // The title row containing the the week information (week of the year (startdate of week - enddate of week)
  291. echo "<tr class=\"title\">\n";
  292. echo "<td width=\"10%\"><a href=\"", $backwardsURL, "\">&#171;</a></td>\n";
  293. echo "<td colspan=\"5\">".get_lang("Week")." ".$week_number;
  294. 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).')';
  295. echo "</td>";
  296. echo "<td width=\"10%\"><a href=\"", $forewardsURL, "\">&#187;</a></td>\n", "</tr>\n";
  297. // The second row containing the short names of the days of the week
  298. echo "<tr>\n";
  299. // this is the Day of the month without leading zeros (1 to 31) of the monday of this week
  300. $tmp_timestamp = $timestamp_first_date_of_week;
  301. for ($ii = 1; $ii < 8; $ii ++)
  302. {
  303. $is_today = ($ii == $thisday_of_the_week AND (!isset($_GET['week']) OR $_GET['week']==$thisweek_number));
  304. echo "\t<td class=\"weekdays\">";
  305. if ($is_today)
  306. {
  307. echo "<font color=#CC3300>";
  308. }
  309. echo $DaysShort[$ii % 7]." ".date("j", $tmp_timestamp)." ".$MonthsLong[date("n", $tmp_timestamp) - 1];
  310. if ($is_today)
  311. {
  312. echo "</font>";
  313. }
  314. echo "</td>\n";
  315. // we 24 hours * 60 minutes * 60 seconds to the $tmp_timestamp
  316. $array_tmp_timestamp[] = $tmp_timestamp;
  317. $tmp_timestamp = $tmp_timestamp + (24 * 60 * 60);
  318. }
  319. echo "</tr>\n";
  320. // the table cells containing all the entries for that day
  321. echo "<tr>\n";
  322. $counter = 0;
  323. foreach ($array_tmp_timestamp as $key => $value)
  324. {
  325. if ($counter < 5)
  326. {
  327. $class = "class=\"days_week\"";
  328. }
  329. else
  330. {
  331. $class = "class=\"days_weekend\"";
  332. }
  333. if ($counter == $thisday_of_the_week -1 AND (!isset($_GET['week']) OR $_GET['week']==$thisweek_number))
  334. {
  335. $class = "class=\"days_today\"";
  336. }
  337. echo "\t<td ".$class.">";
  338. echo "<span class=\"agendaitem\">".$agendaitems[date("j", $value)]."&nbsp;</span> ";
  339. echo "</td>\n";
  340. $counter ++;
  341. }
  342. echo "</tr>\n";
  343. echo "</table>\n";
  344. }
  345. /**
  346. * Show the mini calender of the given month
  347. */
  348. function display_daycalendar($agendaitems, $day, $month, $year, $weekdaynames, $monthName)
  349. {
  350. global $DaysShort, $DaysLong, $course_path;
  351. global $MonthsLong;
  352. global $query;
  353. // timestamp of today
  354. $today = mktime();
  355. $nextday = $today + (24 * 60 * 60);
  356. $previousday = $today - (24 * 60 * 60);
  357. // the week number of the year
  358. $week_number = date("W", $today);
  359. // if we moved to the next / previous day we have to recalculate the $today variable
  360. if ($_GET['day'])
  361. {
  362. $today = mktime(0, 0, 0, $month, $day, $year);
  363. $nextday = $today + (24 * 60 * 60);
  364. $previousday = $today - (24 * 60 * 60);
  365. $week_number = date("W", $today);
  366. }
  367. // calculating the start date of the week
  368. // the date of the monday of this week is the timestamp of today minus
  369. // number of days that have already passed this week * 24 hours * 60 minutes * 60 seconds
  370. $current_day = date("j", $today); // Day of the month without leading zeros (1 to 31) of today
  371. $day_of_the_week = date("w", $today); // Numeric representation of the day of the week 0 (for Sunday) through 6 (for Saturday) of today
  372. //$timestamp_first_date_of_week=$today-(($day_of_the_week-1)*24*60*60); // timestamp of the monday of this week
  373. //$timestamp_last_date_of_week=$today+((7-$day_of_the_week)*24*60*60); // timestamp of the sunday of this week
  374. // we are loading all the calendar items of all the courses for today
  375. echo "<table id=\"agenda_list\">\n";
  376. // the forward and backwards url
  377. $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);
  378. $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);
  379. // The title row containing the day
  380. echo "<tr class=\"title\">\n", "<td width=\"10%\"><a href=\"", $backwardsURL, "\">&#171;</a></td>\n", "<td>";
  381. echo $DaysLong[$day_of_the_week]." ".date("j", $today)." ".$MonthsLong[date("n", $today) - 1]." ".date("Y", $today);
  382. echo "</td>";
  383. echo "<td width=\"10%\"><a href=\"", $forewardsURL, "\">&#187;</a></td>\n";
  384. echo "</tr>\n";
  385. // the rows for each half an hour
  386. for ($i = 10; $i < 48; $i ++)
  387. {
  388. echo "<tr>\n";
  389. echo "\t";
  390. if ($i % 2 == 0)
  391. {
  392. $class = "class=\"alternativeBgLight\"";
  393. echo ("<td $class valign=\"top\" width=\"75\">". (($i) / 2)." ".get_lang("HourShort")." 00</td>\n");
  394. }
  395. else
  396. {
  397. $class = "";
  398. echo ("<td valign=\"top\" width=\"75\">". ((($i) / 2) - (1 / 2))." ".get_lang("HourShort")." 30</td>\n");
  399. }
  400. echo "\t<td $class valign=\"top\" colspan=\"2\">\n";
  401. if (is_array($agendaitems[$i]))
  402. {
  403. foreach ($agendaitems[$i] as $key => $value)
  404. {
  405. echo $value;
  406. }
  407. }
  408. else
  409. {
  410. echo $agendaitems[$i];
  411. }
  412. echo "\t</td>\n";
  413. echo "</tr>\n";
  414. }
  415. echo "</table>\n";
  416. }
  417. /**
  418. * Show the monthcalender of the given month
  419. */
  420. function get_day_agendaitems($courses_dbs, $month, $year, $day)
  421. {
  422. global $_user;
  423. global $_configuration;
  424. $items = array ();
  425. // get agenda-items for every course
  426. //$query=api_sql_query($sql_select_courses);
  427. foreach ($courses_dbs as $key => $array_course_info)
  428. {
  429. //databases of the courses
  430. $TABLEAGENDA = Database :: get_course_table(TABLE_AGENDA, $array_course_info["db"]);
  431. $TABLE_ITEMPROPERTY = Database :: get_course_table(TABLE_ITEM_PROPERTY, $array_course_info["db"]);
  432. // getting all the groups of the user for the current course
  433. $group_memberships = GroupManager :: get_group_ids($array_course_info["db"], $_user['user_id']);
  434. // if the user is administrator of that course we show all the agenda items
  435. if ($array_course_info['status'] == '1')
  436. {
  437. //echo "course admin";
  438. $sqlquery = "SELECT
  439. DISTINCT agenda.*, item_property.*
  440. FROM ".$TABLEAGENDA." agenda,
  441. ".$TABLE_ITEMPROPERTY." item_property
  442. WHERE `agenda`.`id` = `item_property`.`ref` ".$show_all_current."
  443. AND DAYOFMONTH(start_date)='".$day."' AND MONTH(start_date)='".$month."' AND YEAR(start_date)='".$year."'
  444. AND `item_property`.`tool`='".TOOL_CALENDAR_EVENT."'
  445. AND `item_property`.`visibility`='1'
  446. GROUP BY agenda.id
  447. ORDER BY start_date ".$sort;
  448. }
  449. // if the user is not an administrator of that course
  450. else
  451. {
  452. //echo "GEEN course admin";
  453. if (is_array($group_memberships))
  454. {
  455. $sqlquery = "SELECT
  456. agenda.*, item_property.*
  457. FROM ".$TABLEAGENDA." agenda,
  458. ".$TABLE_ITEMPROPERTY." item_property
  459. WHERE `agenda`.`id` = `item_property`.`ref` ".$show_all_current."
  460. AND DAYOFMONTH(start_date)='".$day."' AND MONTH(start_date)='".$month."' AND YEAR(start_date)='".$year."'
  461. AND `item_property`.`tool`='".TOOL_CALENDAR_EVENT."'
  462. AND ( `item_property`.`to_user_id`='".$_user['user_id']."' OR `item_property`.`to_group_id` IN (0, ".implode(", ", $group_memberships).") )
  463. AND `item_property`.`visibility`='1'
  464. ORDER BY start_date ".$sort;
  465. }
  466. else
  467. {
  468. $sqlquery = "SELECT
  469. agenda.*, item_property.*
  470. FROM ".$TABLEAGENDA." agenda,
  471. ".$TABLE_ITEMPROPERTY." item_property
  472. WHERE `agenda`.`id` = `item_property`.`ref` ".$show_all_current."
  473. AND DAYOFMONTH(start_date)='".$day."' AND MONTH(start_date)='".$month."' AND YEAR(start_date)='".$year."'
  474. AND `item_property`.`tool`='".TOOL_CALENDAR_EVENT."'
  475. AND ( `item_property`.`to_user_id`='".$_user['user_id']."' OR `item_property`.`to_group_id`='0')
  476. AND `item_property`.`visibility`='1'
  477. ORDER BY start_date ".$sort;
  478. }
  479. }
  480. //$sqlquery = "SELECT * FROM $agendadb WHERE DAYOFMONTH(day)='$day' AND month(day)='$month' AND year(day)='$year'";
  481. //echo "abc";
  482. //echo $sqlquery;
  483. $result = api_sql_query($sqlquery, __FILE__, __LINE__);
  484. //echo mysql_num_rows($result);
  485. while ($item = mysql_fetch_array($result))
  486. {
  487. // in the display_daycalendar function we use $i (ranging from 0 to 47) for each halfhour
  488. // we want to know for each agenda item for this day to wich halfhour it must be assigned
  489. list ($datepart, $timepart) = split(" ", $item['start_date']);
  490. list ($year, $month, $day) = explode("-", $datepart);
  491. list ($hours, $minutes, $seconds) = explode(":", $timepart);
  492. $halfhour = 2 * $hours;
  493. if ($minutes >= '30')
  494. {
  495. $halfhour = $halfhour +1;
  496. }
  497. //$URL = $_configuration['root_web'].$mycours["dir"]."/";
  498. $URL = $_configuration['root_web']."main/calendar/agenda.php?cidReq=".urlencode($array_course_info["code"])."&amp;day=$day&amp;month=$month&amp;year=$year#$day"; // RH //Patrick Cool: to highlight the relevant agenda item
  499. $items[$halfhour][] .= "<i>".$hours.":".$minutes."</i> <a href=\"$URL\" title=\"".$array_course_info['name']."\">".$array_course_info['visual_code']."</a> ".$item['title']."<br />";
  500. }
  501. }
  502. // sorting by hour for every day
  503. /*$agendaitems = array();
  504. while (list($agendaday, $tmpitems) = each($items))
  505. {
  506. sort($tmpitems);
  507. while (list($key,$val) = each($tmpitems))
  508. {
  509. $agendaitems[$agendaday].=$val;
  510. }
  511. }*/
  512. $agendaitems = $items;
  513. //print_r($agendaitems);
  514. return $agendaitems;
  515. }
  516. /**
  517. * Return agenda items of the week
  518. */
  519. function get_week_agendaitems($courses_dbs, $month, $year, $week = '')
  520. {
  521. global $TABLEAGENDA, $TABLE_ITEMPROPERTY;
  522. global $_user;
  523. global $_configuration;
  524. $items = array ();
  525. // The default value of the week
  526. if ($week == '')
  527. {
  528. $week_number = date("W", time());
  529. }
  530. else
  531. {
  532. $week_number = $week;
  533. }
  534. $start_end = calculate_start_end_of_week($week_number, $year);
  535. $start_filter = $start_end['start']['year']."-".$start_end['start']['month']."-".$start_end['start']['day'];
  536. $end_filter = $start_end['end']['year']."-".$start_end['end']['month']."-".$start_end['end']['day'];
  537. // get agenda-items for every course
  538. foreach ($courses_dbs as $key => $array_course_info)
  539. {
  540. //databases of the courses
  541. $TABLEAGENDA = Database :: get_course_table(TABLE_AGENDA, $array_course_info["db"]);
  542. $TABLE_ITEMPROPERTY = Database :: get_course_table(TABLE_ITEM_PROPERTY, $array_course_info["db"]);
  543. // getting all the groups of the user for the current course
  544. $group_memberships = GroupManager :: get_group_ids($array_course_info["db"], $_user['user_id']);
  545. // if the user is administrator of that course we show all the agenda items
  546. if ($array_course_info['status'] == '1')
  547. {
  548. //echo "course admin";
  549. $sqlquery = "SELECT
  550. DISTINCT a.*, i.*
  551. FROM ".$TABLEAGENDA." a,
  552. ".$TABLE_ITEMPROPERTY." i
  553. WHERE a.id = i.ref
  554. AND a.start_date>='".$start_filter."' AND a.start_date<='".$end_filter."'
  555. AND i.tool='".TOOL_CALENDAR_EVENT."'
  556. AND i.visibility='1'
  557. GROUP BY a.id
  558. ORDER BY a.start_date";
  559. }
  560. // if the user is not an administrator of that course
  561. else
  562. {
  563. //echo "GEEN course admin";
  564. if (is_array($group_memberships))
  565. {
  566. $sqlquery = "SELECT
  567. a.*, i.*
  568. FROM ".$TABLEAGENDA." a,
  569. ".$TABLE_ITEMPROPERTY." i
  570. WHERE a.id = i.`ref`
  571. AND a.start_date>='".$start_filter."' AND a.start_date<='".$end_filter."'
  572. AND i.tool='".TOOL_CALENDAR_EVENT."'
  573. AND ( i.to_user_id='".$_user['user_id']."' OR i.to_group_id IN (0, ".implode(", ", $group_memberships).") )
  574. AND i.visibility='1'
  575. ORDER BY a.start_date";
  576. }
  577. else
  578. {
  579. $sqlquery = "SELECT
  580. a.*, i.*
  581. FROM ".$TABLEAGENDA." a,
  582. ".$TABLE_ITEMPROPERTY." i
  583. WHERE a.id = i.ref
  584. AND a.start_date>='".$start_filter."' AND a.start_date<='".$end_filter."'
  585. AND i.tool='".TOOL_CALENDAR_EVENT."'
  586. AND ( i.to_user_id='".$_user['user_id']."' OR i.to_group_id='0')
  587. AND i.visibility='1'
  588. ORDER BY a.start_date";
  589. }
  590. }
  591. //echo "<pre>".$sqlquery."</pre>";
  592. // $sqlquery = "SELECT * FROM $agendadb WHERE (DAYOFMONTH(day)>='$start_day' AND DAYOFMONTH(day)<='$end_day')
  593. // AND (MONTH(day)>='$start_month' AND MONTH(day)<='$end_month')
  594. // AND (YEAR(day)>='$start_year' AND YEAR(day)<='$end_year')";
  595. $result = api_sql_query($sqlquery, __FILE__, __LINE__);
  596. while ($item = mysql_fetch_array($result))
  597. {
  598. $agendaday = date("j",strtotime($item['start_date']));
  599. $time= date("H:i",strtotime($item['start_date']));
  600. $URL = $_configuration['root_web']."main/calendar/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
  601. $items[$agendaday][$item['start_time']] .= "<i>$time</i> <a href=\"$URL\" title=\"".$array_course_info["name"]."\">".$array_course_info["visual_code"]."</a> ".$item['title']."<br />";
  602. }
  603. }
  604. // sorting by hour for every day
  605. $agendaitems = array ();
  606. while (list ($agendaday, $tmpitems) = each($items))
  607. {
  608. sort($tmpitems);
  609. while (list ($key, $val) = each($tmpitems))
  610. {
  611. $agendaitems[$agendaday] .= $val;
  612. }
  613. }
  614. //print_r($agendaitems);
  615. return $agendaitems;
  616. }
  617. /**
  618. * This function shows all the forms that are needed form adding /editing a new personal agenda item
  619. * when there is no $id passed in the function we are adding a new agenda item, if there is a $id
  620. * we are editing
  621. * attention: we have to check that the student is editing an item that belongs to him/her
  622. */
  623. function show_new_item_form($id = "")
  624. {
  625. global $year, $MonthsLong;
  626. global $tbl_personal_agenda;
  627. global $_user;
  628. // we construct the default time and date data (used if we are not editing a personal agenda item)
  629. $today = getdate();
  630. $day = $today['mday'];
  631. $month = $today['mon'];
  632. $year = $today['year'];
  633. $hours = $today['hours'];
  634. $minutes = $today['minutes'];
  635. // if an $id is passed to this function this means we are editing an item
  636. // we are loading the information here (we do this after everything else
  637. // to overwrite the default information)
  638. if ($id <> "")
  639. {
  640. $sql = "SELECT * FROM ".$tbl_personal_agenda." WHERE user='".$_user['user_id']."' AND id='".$id."'";
  641. $result = api_sql_query($sql, __FILE__, __LINE__);
  642. $aantal = mysql_num_rows($result);
  643. if ($aantal <> 0)
  644. {
  645. $row = mysql_fetch_array($result);
  646. $year = substr($row['date'], 0, 4);
  647. $month = substr($row['date'], 5, 2);
  648. $day = substr($row['date'], 8, 2);
  649. $hours = substr($row['date'], 11, 2);
  650. $minutes = substr($row['date'], 14, 2);
  651. $title = $row['title'];
  652. $text = $row['text'];
  653. }
  654. else
  655. {
  656. return false;
  657. }
  658. }
  659. echo "<form method=\"post\" action=\"myagenda.php?action=add_personal_agenda_item&amp;id=$id\" name=\"newedit_form\">\n";
  660. echo "<table width=\"100%\" id=\"newedit_form\">\n";
  661. echo "\t<tr class=\"title\">\n\t\t<td colspan=\"3\"><h4>";
  662. echo ($_GET['action'] == 'edit_personal_agenda_item') ? get_lang("ModifyPersonalCalendarItem") : get_lang("AddPersonalCalendarItem");
  663. echo "</h4></td>\n\t</tr>\n";
  664. echo "\t<tr class=\"subtitle\">\n\t\t<td>\n";
  665. echo "<!-- date: 1 -> 31 -->\n";
  666. echo "\t\t".get_lang("Date").": \n";
  667. // ********** The form containing the days (0->31) ********** \\
  668. echo "<select name=\"frm_day\">\n";
  669. // small loop for filling all the dates
  670. // 2do: the available dates should be those of the selected month => february is from 1 to 28 (or 29) and not to 31
  671. for ($i = 1; $i <= 31; $i ++)
  672. {
  673. // values have to have double digits
  674. if ($i <= 9)
  675. {
  676. $value = "0".$i;
  677. }
  678. else
  679. {
  680. $value = $i;
  681. }
  682. // the current day is indicated with [] around the date
  683. if ($value == $day)
  684. {
  685. echo "\t\t\t\t <option value=\"".$value."\" selected>".$i."</option>\n";
  686. }
  687. else
  688. {
  689. echo "\t\t\t\t <option value=\"".$value."\">".$i."</option>\n";
  690. }
  691. }
  692. echo "</select>\n\n";
  693. // ********** The form containing the months (jan->dec) ********** \\
  694. echo "<!-- month: january -> december -->\n";
  695. echo "<select name=\"frm_month\">\n";
  696. for ($i = 1; $i <= 12; $i ++)
  697. {
  698. // values have to have double digits
  699. if ($i <= 9)
  700. {
  701. $value = "0".$i;
  702. }
  703. else
  704. {
  705. $value = $i;
  706. }
  707. // the current month is indicated with [] around the month name
  708. if ($value == $month)
  709. {
  710. echo "\t<option value=\"".$value."\" selected>".$MonthsLong[$i -1]."</option>\n";
  711. }
  712. else
  713. {
  714. echo "\t<option value=\"".$value."\">".$MonthsLong[$i -1]."</option>\n";
  715. }
  716. }
  717. echo "</select>\n\n";
  718. // ********** The form containing the years ********** \\
  719. echo "<!-- year -->\n";
  720. echo "<select name=\"frm_year\">";
  721. echo "<option value=\"". ($year -1)."\">". ($year -1)."</option>\n";
  722. echo "<option value=\"".$year."\" selected>".$year."</option>\n";
  723. for ($i = 1; $i <= 5; $i ++)
  724. {
  725. $value = $year + $i;
  726. echo "\t<option value=\"".$value."\">".$value."</option>\n";
  727. }
  728. echo "</select>";
  729. echo "<a title=\"Kalender\" href=\"javascript:openCalendar('newedit_form', 'frm_')\"><img src=\"../img/calendar_select.gif\" border=\"0\" valign=\"absmiddle\"/></a>";
  730. echo "</td><td width=\"50%\">";
  731. // ********** The form containing the hours (00->23) ********** \\
  732. echo "<!-- time: hour -->\n";
  733. echo get_lang("Time").": \n";
  734. echo "<select name=\"frm_hour\">\n";
  735. for ($i = 1; $i <= 24; $i ++)
  736. {
  737. // values have to have double digits
  738. if ($i <= 9)
  739. {
  740. $value = "0".$i;
  741. }
  742. else
  743. {
  744. $value = $i;
  745. }
  746. // the current hour is indicated with [] around the hour
  747. if ($hours == $value)
  748. {
  749. echo "\t\t\t\t<option value=\"".$value."\" selected> ".$value." </option>\n";
  750. }
  751. else
  752. {
  753. echo "\t\t\t\t<option value=\"".$value."\"> ".$value." </option>\n";
  754. }
  755. }
  756. echo "</select>";
  757. // ********** The form containing the minutes ********** \\
  758. echo "<select name=\"frm_minute\">";
  759. echo "<option value=\"".$minutes."\">".$minutes."</option>";
  760. echo "<option value=\"00\">00</option>";
  761. echo "<option value=\"05\">05</option>";
  762. echo "<option value=\"10\">10</option>";
  763. echo "<option value=\"15\">15</option>";
  764. echo "<option value=\"20\">20</option>";
  765. echo "<option value=\"25\">25</option>";
  766. echo "<option value=\"30\">30</option>";
  767. echo "<option value=\"35\">35</option>";
  768. echo "<option value=\"40\">40</option>";
  769. echo "<option value=\"45\">45</option>";
  770. echo "<option value=\"50\">50</option>";
  771. echo "<option value=\"55\">55</option>";
  772. echo "</select>";
  773. echo "</td></tr>";
  774. // ********** The title field ********** \\
  775. echo "<tr class=\"subtitle\"><td colspan=\"2\">";
  776. echo get_lang('Title').': <input type="text" name="frm_title" size="50" value="'.$title.'" />';
  777. echo "</td></tr>";
  778. // ********** The text field ********** \\
  779. echo "<tr><td colspan=\"2\">";
  780. //api_disp_html_area('frm_content', $text, '300px');
  781. echo'<textarea name="frm_content" style="width: 450px; height: 100px;">'.$text.'</textarea>';
  782. echo "</td></tr>";
  783. // ********** The Submit button********** \\
  784. echo "<tr><td colspan=\"2\">";
  785. echo '<input type="submit" name="Submit" value="'.get_lang('Ok').'" />';
  786. echo "</td></tr>";
  787. echo "</table>\n</form>\n";
  788. }
  789. /**
  790. * This function shows all the forms that are needed form adding a new personal agenda item
  791. */
  792. function store_personal_item($day, $month, $year, $hour, $minute, $title, $content, $id = "")
  793. {
  794. global $tbl_personal_agenda;
  795. global $_user;
  796. //constructing the date
  797. $date = $year."-".$month."-".$day." ".$hour.":".$minute.":00";
  798. if ($id <> "")
  799. { // we are updating
  800. $sql = "UPDATE ".$tbl_personal_agenda." SET user='".$_user['user_id']."', title='".$title."', text='".$content."', date='".$date."' WHERE id='".$id."'";
  801. }
  802. else
  803. { // we are adding a new item
  804. $sql = "INSERT INTO $tbl_personal_agenda (user, title, text, date) VALUES ('".$_user['user_id']."','$title', '$content', '$date')";
  805. }
  806. $result = api_sql_query($sql, __FILE__, __LINE__);
  807. }
  808. /**
  809. * This function finds all the courses of the user and returns an array containing the
  810. * database name of the courses.
  811. */
  812. function get_courses_of_user()
  813. {
  814. global $TABLECOURS;
  815. global $TABLECOURSUSER;
  816. global $_user;
  817. $sql_select_courses = "SELECT course.code k, course.visual_code vc,
  818. course.title i, course.tutor_name t, course.db_name db, course.directory dir, course_rel_user.status status
  819. FROM $TABLECOURS course,
  820. $TABLECOURSUSER course_rel_user
  821. WHERE course.code = course_rel_user.course_code
  822. AND course_rel_user.user_id = '".$_user['user_id']."'";
  823. $result = api_sql_query($sql_select_courses);
  824. while ($row = mysql_fetch_array($result))
  825. {
  826. // we only need the database name of the course
  827. $courses[] = array ("db" => $row['db'], "code" => $row['k'], "visual_code" => $row['vc'], "title" => $row['i'], "directory" => $row['dir'], "status" => $row['status']);
  828. }
  829. return $courses;
  830. }
  831. /**
  832. * This function retrieves all the personal agenda items and add them to the agenda items found by the other functions.
  833. */
  834. function get_personal_agenda_items($agendaitems, $day = "", $month = "", $year = "", $week = "", $type)
  835. {
  836. global $tbl_personal_agenda;
  837. global $_user;
  838. global $_configuration;
  839. // 1. creating the SQL statement for getting the personal agenda items in MONTH view
  840. if ($type == "month_view" or $type == "") // we are in month view
  841. {
  842. $sql = "SELECT * FROM ".$tbl_personal_agenda." WHERE user='".$_user['user_id']."' and MONTH(date)='".$month."' AND YEAR(date) = '".$year."' ORDER BY date ASC";
  843. }
  844. // 2. creating the SQL statement for getting the personal agenda items in WEEK view
  845. if ($type == "week_view") // we are in week view
  846. {
  847. $start_end_day_of_week = calculate_start_end_of_week($week, $year);
  848. $start_day = $start_end_day_of_week['start']['day'];
  849. $start_month = $start_end_day_of_week['start']['month'];
  850. $start_year = $start_end_day_of_week['start']['year'];
  851. $end_day = $start_end_day_of_week['end']['day'];
  852. $end_month = $start_end_day_of_week['end']['month'];
  853. $end_year = $start_end_day_of_week['end']['year'];
  854. // in sql statements you have to use year-month-day for date calculations
  855. $start_filter = $start_year."-".$start_month."-".$start_day." 00:00:00";
  856. $end_filter = $end_year."-".$end_month."-".$end_day." 23:59:59";
  857. $sql = " SELECT * FROM ".$tbl_personal_agenda." WHERE user='".$_user['user_id']."'
  858. AND date>='".$start_filter."' AND date<='".$end_filter."'";
  859. }
  860. // 3. creating the SQL statement for getting the personal agenda items in DAY view
  861. if ($type == "day_view") // we are in day view
  862. {
  863. // we could use mysql date() function but this is only available from 4.1 and higher
  864. $start_filter = $year."-".$month."-".$day." 00:00:00";
  865. $end_filter = $year."-".$month."-".$day." 23:59:59";
  866. $sql = " SELECT * FROM ".$tbl_personal_agenda." WHERE user='".$_user['user_id']."' AND date>='".$start_filter."' AND date<='".$end_filter."'";
  867. }
  868. //echo "day:".$day."/";
  869. //echo "month:".$month."/";
  870. //echo "year:".$year."/";
  871. //echo "week:".$week."/";
  872. //echo $type."<p>";
  873. //echo "<pre>".$sql."</pre>";
  874. $result = api_sql_query($sql, __FILE__, __LINE__);
  875. while ($item = mysql_fetch_array($result))
  876. {
  877. // we break the date field in the database into a date and a time part
  878. $agenda_db_date = explode(" ", $item[date]);
  879. $date = $agenda_db_date[0];
  880. $time = $agenda_db_date[1];
  881. // we divide the date part into a day, a month and a year
  882. $agendadate = explode("-", $date);
  883. $year = intval($agendadate[0]);
  884. $month = intval($agendadate[1]);
  885. $day = intval($agendadate[2]);
  886. // we divide the time part into hour, minutes, seconds
  887. $agendatime = explode(":", $time);
  888. $hour = $agendatime[0];
  889. $minute = $agendatime[1];
  890. $second = $agendatime[2];
  891. // if the student has specified a course we a add a link to that course
  892. if ($item['course'] <> "")
  893. {
  894. $url = $_configuration['root_web']."main/calendar/agenda.php?cidReq=".urlencode($item['course'])."&amp;day=$day&amp;month=$month&amp;year=$year#$day"; // RH //Patrick Cool: to highlight the relevant agenda item
  895. $course_link = "<a href=\"$url\" title=\"".$item['course']."\">".$item['course']."</a>";
  896. }
  897. else
  898. {
  899. $course_link = "";
  900. }
  901. // Creating the array that will be returned. If we have week or month view we have an array with the date as the key
  902. // if we have a day_view we use a half hour as index => key 33 = 16h30
  903. if ($type !== "day_view") // This is the array construction for the WEEK or MONTH view
  904. {
  905. $agendaitems[$day] .= "<div><i>$hour:$minute</i> $course_link <a href=\"myagenda.php?action=view&amp;view=personal&amp;day=$day&amp;month=$month&amp;year=$year&amp;id=".$item['id']."#".$item['id']."\" class=\"personal_agenda\">".$item['title']."</a></div>";
  906. }
  907. else // this is the array construction for the DAY view
  908. {
  909. $halfhour = 2 * $agendatime['0'];
  910. if ($agendatime['1'] >= '30')
  911. {
  912. $halfhour = $halfhour +1;
  913. }
  914. $agendaitems[$halfhour] .= "<div><i>$hour:$minute</i> $course_link <a href=\"myagenda.php?action=view&amp;view=personal&amp;day=$day&amp;month=$month&amp;year=$year&amp;id=".$item['id']."#".$item['id']."\" class=\"personal_agenda\">".$item['title']."</a></div>";
  915. }
  916. }
  917. //print_r($agendaitems);
  918. return $agendaitems;
  919. }
  920. /**
  921. * This function retrieves all the personal agenda items and add them to the agenda items found by the other functions.
  922. * @param int The agenda item ID
  923. * @return array The results of the database query, or null if not found
  924. */
  925. function get_personal_agenda_item($id)
  926. {
  927. $tbl_personal_agenda = Database :: get_user_personal_table(TABLE_PERSONAL_AGENDA);
  928. $id = Database::escape_string($id);
  929. $sql = " SELECT * FROM ".$tbl_personal_agenda." WHERE id=".$id;
  930. $result = api_sql_query($sql, __FILE__, __LINE__);
  931. if(Database::num_rows($result)==1)
  932. {
  933. $item = Database::fetch_array($result);
  934. }
  935. else
  936. {
  937. $item = null;
  938. }
  939. return $item;
  940. }
  941. /**
  942. * This function retrieves all the personal agenda items of the user and shows
  943. * these items in one list (ordered by date and grouped by month (the month_bar)
  944. */
  945. function show_personal_agenda()
  946. {
  947. global $tbl_personal_agenda;
  948. global $MonthsLong, $charset;
  949. global $_user;
  950. // The SQL statement that retrieves all the personal agenda items of this user
  951. $sql = "SELECT * FROM ".$tbl_personal_agenda." WHERE user='".$_user['user_id']."' ORDER BY date DESC";
  952. $result = api_sql_query($sql, __FILE__, __LINE__);
  953. // variable initialisation
  954. $month_bar = "";
  955. // starting the table output
  956. echo "<table id=\"agenda_list\">\n";
  957. // setting the default day, month and year
  958. if (!$_GET['day'] AND !$_GET['month'] AND !$_GET['year'])
  959. {
  960. $today = getdate();
  961. $year = $today['year'];
  962. $month = $today['mon'];
  963. $day = $today['mday'];
  964. }
  965. $export_icon = api_get_path('WEB_IMG_PATH').'export.png';
  966. if (Database::num_rows($result) > 0)
  967. {
  968. while ($myrow = Database::fetch_array($result))
  969. {
  970. /*--------------------------------------------------
  971. display: the month bar
  972. --------------------------------------------------*/
  973. if ($month_bar != date("m", strtotime($myrow["date"])).date("Y", strtotime($myrow["date"])))
  974. {
  975. $month_bar = date("m", strtotime($myrow["date"])).date("Y", strtotime($myrow["date"]));
  976. echo "<tr><td class=\"title\" colspan=\"2\" class=\"month\" valign=\"top\">".$MonthsLong[date("n", strtotime($myrow["date"])) - 1]." ".date("Y", strtotime($myrow["date"]))."</td></tr>\n";
  977. }
  978. // highlight: if a date in the small calendar is clicked we highlight the relevant items
  979. $db_date = (int) date("d", strtotime($myrow["date"])).date("n", strtotime($myrow["date"])).date("Y", strtotime($myrow["date"]));
  980. if ($_GET["day"].$_GET["month"].$_GET["year"] <> $db_date)
  981. {
  982. $style = "data";
  983. $text_style = "text";
  984. }
  985. else
  986. {
  987. $style = "datanow";
  988. $text_style = "text";
  989. }
  990. /*--------------------------------------------------
  991. display: date and time
  992. --------------------------------------------------*/
  993. echo "\t<tr>\n\t\t";
  994. echo '<td class="'.$style.'">';
  995. // adding an internal anchor
  996. echo "<a name=\"".$myrow["id"]."\"></a>";
  997. echo date("d", strtotime($myrow["date"]))." ".$MonthsLong[date("n", strtotime($myrow["date"])) - 1]." ".date("Y", strtotime($myrow["date"]))."&nbsp;";
  998. echo ucfirst(strftime(get_lang("timeNoSecFormat"), strtotime($myrow["date"])));
  999. echo "</td>";
  1000. echo '<td class="'.$style.'">';
  1001. echo '<a class="ical_export" href="ical_export.php?type=personal&id='.$myrow['id'].'&class=confidential" title="'.get_lang('ExportiCal').'"><img src="'.$export_icon.'" alt="'.get_lang('ExportiCalConfidential').'"/></a>';
  1002. echo '<a class="ical_export" href="ical_export.php?type=personal&id='.$myrow['id'].'&class=private" title="'.get_lang('ExportiCalPerso').'"><img src="'.$export_icon.'" alt="'.get_lang('ExportiCalPrivate').'"/></a>';
  1003. echo '<a class="ical_export" href="ical_export.php?type=personal&id='.$myrow['id'].'&class=public" title="'.get_lang('ExportiCalPro').'"><img src="'.$export_icon.'" alt="'.get_lang('ExportiCalPublic').'"/></a>';
  1004. echo "\n\t\t</td>\n\t";
  1005. echo "</tr>";
  1006. /*--------------------------------------------------
  1007. display: the title
  1008. --------------------------------------------------*/
  1009. echo "<tr>";
  1010. echo '<td class="'.$style.'" colspan="2">';
  1011. echo $myrow['title'];
  1012. echo "\n\t\t</td>\n\t";
  1013. echo "</tr>\n";
  1014. /*--------------------------------------------------
  1015. display: the content
  1016. --------------------------------------------------*/
  1017. $content = $myrow['text'];
  1018. $content = make_clickable($content);
  1019. $content = text_filter($content);
  1020. echo "\t<tr>\n\t\t<td class=\"".$text_style."\" colspan='2'>";
  1021. echo $content;
  1022. echo "</td></tr>";
  1023. /*--------------------------------------------------
  1024. display: the edit / delete icons
  1025. --------------------------------------------------*/
  1026. echo "\t<tr>\n\t\t<td class=\"".$text_style."\" colspan='2'>";
  1027. echo "<a href=\"myagenda.php?action=edit_personal_agenda_item&amp;id=".$myrow['id']."\"><img src=\"../img/edit.gif\" border=\"0\" alt=\"".get_lang('Edit')."\" /></a>";
  1028. echo "<a href=\"".api_get_self()."?action=delete&amp;id=".$myrow['id']."\" onclick=\"javascript:if(!confirm('".addslashes(htmlentities(get_lang('ConfirmYourChoice'),ENT_QUOTES,$charset))."')) return false;\"><img src=\"../img/delete.gif\" border=\"0\" alt=\"".get_lang('Delete')."\" /></a>";
  1029. echo "</td></tr>";
  1030. }
  1031. }
  1032. else
  1033. {
  1034. echo '<tr><td colspan="2">'.get_lang('NoAgendaItems').'</td></tr>';
  1035. }
  1036. echo "</table>\n";
  1037. }
  1038. /**
  1039. * This function deletes a personal agenda item
  1040. * There is an additional check to make sure that one cannot delete an item that
  1041. * does not belong to him/her
  1042. */
  1043. function delete_personal_agenda($id)
  1044. {
  1045. global $tbl_personal_agenda;
  1046. global $_user;
  1047. if ($id <> '')
  1048. {
  1049. $sql = "SELECT * FROM ".$tbl_personal_agenda." WHERE user='".$_user['user_id']."' AND id='".$id."'";
  1050. $result = api_sql_query($sql, __FILE__, __LINE__);
  1051. $aantal = mysql_num_rows($result);
  1052. if ($aantal <> 0)
  1053. {
  1054. $sql = "DELETE FROM ".$tbl_personal_agenda." WHERE user='".$_user['user_id']."' AND id='".$id."'";
  1055. $result = api_sql_query($sql, __FILE__, __LINE__);
  1056. }
  1057. }
  1058. }
  1059. /**
  1060. * This function calculates the startdate of the week (monday)
  1061. * and the enddate of the week (sunday)
  1062. * and returns it as an array
  1063. */
  1064. function calculate_start_end_of_week($week_number, $year)
  1065. {
  1066. // determine the start and end date
  1067. // step 1: we calculate a timestamp for a day in this week
  1068. $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
  1069. // step 2: we which day this is (0=sunday, 1=monday, ...)
  1070. $number_day_in_week = date('w', $random_day_in_week);
  1071. // step 3: we calculate the timestamp of the monday of the week we are in
  1072. $start_timestamp = $random_day_in_week - (($number_day_in_week -1) * 24 * 60 * 60);
  1073. // step 4: we calculate the timestamp of the sunday of the week we are in
  1074. $end_timestamp = $random_day_in_week + ((7 - $number_day_in_week +1) * 24 * 60 * 60) - 3600;
  1075. // step 5: calculating the start_day, end_day, start_month, end_month, start_year, end_year
  1076. $start_day = date('j', $start_timestamp);
  1077. $start_month = date('n', $start_timestamp);
  1078. $start_year = date('Y', $start_timestamp);
  1079. $end_day = date('j', $end_timestamp);
  1080. $end_month = date('n', $end_timestamp);
  1081. $end_year = date('Y', $end_timestamp);
  1082. $start_end_array['start']['day'] = $start_day;
  1083. $start_end_array['start']['month'] = $start_month;
  1084. $start_end_array['start']['year'] = $start_year;
  1085. $start_end_array['end']['day'] = $end_day;
  1086. $start_end_array['end']['month'] = $end_month;
  1087. $start_end_array['end']['year'] = $end_year;
  1088. return $start_end_array;
  1089. }
  1090. ?>