myagenda.inc.php 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988
  1. <?php //$Id: agenda.php 16490 2008-10-10 14:29:52Z elixir_inter $
  2. /* For licensing terms, see /dokeos_license.txt
  3. ==============================================================================
  4. @author: Patrick Cool <patrick.cool@UGent.be>, Ghent University
  5. @author: Toon Van Hoecke <toon.vanhoecke@ugent.be>, Ghent University
  6. @author: Eric Remy (initial version)
  7. @version: 2.2 alpha
  8. @description: this file generates a general agenda of all items of the
  9. courses the user is registered for
  10. ==============================================================================
  11. version info:
  12. -------------
  13. -> version 2.2 : Patrick Cool, patrick.cool@ugent.be, november 2004
  14. Personal Agenda added. The user can add personal agenda items. The items
  15. are stored in a chamilo_user database because it is not course or platform
  16. based. A personal agenda view was also added. This lists all the personal
  17. agenda items of that user.
  18. -> version 2.1 : Patrick Cool, patrick.cool@ugent.be, , oktober 2004
  19. This is the version that works with the Group based Agenda tool.
  20. -> version 2.0 (alpha): Patrick Cool, patrick.cool@ugent.be, , oktober 2004
  21. The 2.0 version introduces besides the month view also a week- and day view.
  22. In the 2.5 (final) version it will be possible for the student to add his/her
  23. own agenda items. The platform administrator can however decide if the students
  24. are allowed to do this or not.
  25. The alpha version only contains the three views. The personal agenda feature is
  26. not yet completely finished. There are however already some parts of the code
  27. for adding a personal agenda item present.
  28. this code was not released in an official dokeos but was only used in the offical
  29. server of the Ghent University where it underwent serious testing
  30. -> version 1.5: Toon Van Hoecke, toon.vanhoecke@ugent.be, december 2003
  31. -> version 1.0: Eric Remy, eremy@rmwc.edu, 6 Oct 2003
  32. The tool was initially called master-calendar as it collects all the calendar
  33. items of all the courses one is subscribed to. It was very soon integrated in
  34. Dokeos as this was a really basic and very usefull tool.
  35. */
  36. /**
  37. * Settings (you may alter this at will
  38. */
  39. $setting_agenda_link = 'coursecode'; // valid values are coursecode and icon
  40. /**
  41. * This function retrieves all the agenda items of all the courses the user is subscribed to
  42. */
  43. function get_myagendaitems($courses_dbs, $month, $year)
  44. {
  45. global $_user;
  46. global $_configuration;
  47. global $setting_agenda_link;
  48. $items = array ();
  49. // get agenda-items for every course
  50. foreach ($courses_dbs as $key => $array_course_info)
  51. {
  52. //databases of the courses
  53. $TABLEAGENDA = Database :: get_course_table(TABLE_AGENDA, $array_course_info["db"]);
  54. $TABLE_ITEMPROPERTY = Database :: get_course_table(TABLE_ITEM_PROPERTY, $array_course_info["db"]);
  55. $group_memberships = GroupManager :: get_group_ids($array_course_info["db"], $_user['user_id']);
  56. // if the user is administrator of that course we show all the agenda items
  57. if ($array_course_info['status'] == '1')
  58. {
  59. //echo "course admin";
  60. $sqlquery = "SELECT
  61. DISTINCT agenda.*, ip.visibility, ip.to_group_id, ip.insert_user_id, ip.ref
  62. FROM ".$TABLEAGENDA." agenda,
  63. ".$TABLE_ITEMPROPERTY." ip
  64. WHERE agenda.id = ip.ref
  65. AND MONTH(agenda.start_date)='".$month."'
  66. AND YEAR(agenda.start_date)='".$year."'
  67. AND ip.tool='".TOOL_CALENDAR_EVENT."'
  68. AND ip.visibility='1'
  69. GROUP BY agenda.id
  70. ORDER BY start_date ";
  71. }
  72. // if the user is not an administrator of that course
  73. else
  74. {
  75. //echo "GEEN course admin";
  76. if (is_array($group_memberships) && count($group_memberships)>0)
  77. {
  78. $sqlquery = "SELECT
  79. agenda.*, ip.visibility, ip.to_group_id, ip.insert_user_id, ip.ref
  80. FROM ".$TABLEAGENDA." agenda,
  81. ".$TABLE_ITEMPROPERTY." ip
  82. WHERE agenda.id = ip.ref
  83. AND MONTH(agenda.start_date)='".$month."'
  84. AND YEAR(agenda.start_date)='".$year."'
  85. AND ip.tool='".TOOL_CALENDAR_EVENT."'
  86. AND ( ip.to_user_id='".$_user['user_id']."' OR ip.to_group_id IN (0, ".implode(", ", $group_memberships).") )
  87. AND ip.visibility='1'
  88. ORDER BY start_date ";
  89. }
  90. else
  91. {
  92. $sqlquery = "SELECT
  93. agenda.*, ip.visibility, ip.to_group_id, ip.insert_user_id, ip.ref
  94. FROM ".$TABLEAGENDA." agenda,
  95. ".$TABLE_ITEMPROPERTY." ip
  96. WHERE agenda.id = ip.ref
  97. AND MONTH(agenda.start_date)='".$month."'
  98. AND YEAR(agenda.start_date)='".$year."'
  99. AND ip.tool='".TOOL_CALENDAR_EVENT."'
  100. AND ( ip.to_user_id='".$_user['user_id']."' OR ip.to_group_id='0')
  101. AND ip.visibility='1'
  102. ORDER BY start_date ";
  103. }
  104. }
  105. $result = Database::query($sqlquery);
  106. while ($item = Database::fetch_array($result)) {
  107. $agendaday = date("j",strtotime($item['start_date']));
  108. if(!isset($items[$agendaday])){$items[$agendaday]=array();}
  109. $time = api_convert_and_format_date($item['start_date'], TIME_NO_SEC_FORMAT, date_default_timezone_get());
  110. $end_time = api_convert_and_format_date($item['end_date'], TIME_NO_SEC_FORMAT, date_default_timezone_get());
  111. $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
  112. if ($setting_agenda_link == 'coursecode') {
  113. $title=$array_course_info['title'];
  114. $agenda_link = api_substr($title, 0, 14);
  115. }
  116. else {
  117. $agenda_link = Display::return_icon('course_home.gif');
  118. }
  119. if(!isset($items[$agendaday][$item['start_date']])) {
  120. $items[$agendaday][$item['start_date']] = '';
  121. }
  122. $items[$agendaday][$item['start_date']] .= "".get_lang('StartTimeWindow')."&nbsp;<i>".$time."</i>"."&nbsp;-&nbsp;".get_lang("EndTimeWindow")."&nbsp;<i>".$end_time."</i>&nbsp;";
  123. $items[$agendaday][$item['start_date']] .= '<br />'."<a href=\"$URL\" title=\"".Security::remove_XSS($array_course_info['title'])."\">".$agenda_link."</a> ".Security::remove_XSS($item['title'])."<br /> ";
  124. $items[$agendaday][$item['start_date']] .= '<br/>';
  125. }
  126. }
  127. // sorting by hour for every day
  128. $agendaitems = array ();
  129. while (list ($agendaday, $tmpitems) = each($items)) {
  130. if(!isset($agendaitems[$agendaday])) {
  131. $agendaitems[$agendaday] = '';
  132. }
  133. sort($tmpitems);
  134. while (list ($key, $val) = each($tmpitems)) {
  135. $agendaitems[$agendaday] .= $val;
  136. }
  137. }
  138. //print_r($agendaitems);
  139. return $agendaitems;
  140. }
  141. /**
  142. * Show the monthcalender of the given month
  143. * @param array Agendaitems
  144. * @param int Month number
  145. * @param int Year number
  146. * @param array Array of strings containing long week day names (deprecated, you can send an empty array instead)
  147. * @param string The month name
  148. * @return void Direct output
  149. */
  150. function display_mymonthcalendar($agendaitems, $month, $year, $weekdaynames=array(), $monthName)
  151. {
  152. global $DaysShort,$course_path;
  153. //Handle leap year
  154. $numberofdays = array (0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
  155. if (($year % 400 == 0) or ($year % 4 == 0 and $year % 100 <> 0))
  156. $numberofdays[2] = 29;
  157. //Get the first day of the month
  158. $dayone = getdate(mktime(0, 0, 0, $month, 1, $year));
  159. //Start the week on monday
  160. $startdayofweek = $dayone['wday'] <> 0 ? ($dayone['wday'] - 1) : 6;
  161. $g_cc = (isset($_GET['courseCode'])?$_GET['courseCode']:'');
  162. $backwardsURL = api_get_self()."?coursePath=".urlencode($course_path)."&amp;courseCode=".Security::remove_XSS($g_cc)."&amp;action=view&amp;view=month&amp;month=". ($month == 1 ? 12 : $month -1)."&amp;year=". ($month == 1 ? $year -1 : $year);
  163. $forewardsURL = api_get_self()."?coursePath=".urlencode($course_path)."&amp;courseCode=".Security::remove_XSS($g_cc)."&amp;action=view&amp;view=month&amp;month=". ($month == 12 ? 1 : $month +1)."&amp;year=". ($month == 12 ? $year +1 : $year);
  164. echo "<table class=\"data_table\">\n", "<tr>\n", "<th width=\"10%\"><a href=\"", $backwardsURL, "\">&#171;</a></th>\n", "<th width=\"80%\" colspan=\"5\">", $monthName, " ", $year, "</th>\n", "<th width=\"10%\"><a href=\"", $forewardsURL, "\">&#187;</a></th>\n", "</tr>\n";
  165. echo "<tr>\n";
  166. for ($ii = 1; $ii < 8; $ii ++)
  167. {
  168. echo "<td class=\"weekdays\">", $DaysShort[$ii % 7], "</td>\n";
  169. }
  170. echo "</tr>\n";
  171. $curday = -1;
  172. $today = getdate();
  173. while ($curday <= $numberofdays[$month]) {
  174. echo "<tr>\n";
  175. for ($ii = 0; $ii < 7; $ii ++) {
  176. if (($curday == -1) && ($ii == $startdayofweek)) {
  177. $curday = 1;
  178. }
  179. if (($curday > 0) && ($curday <= $numberofdays[$month])) {
  180. $bgcolor = $ii < 5 ? $class = "class=\"days_week\" style=\"width:10%;\"" : $class = "class=\"days_weekend\" style=\"width:10%;\"";
  181. $dayheader = "<b>$curday</b><br />";
  182. if (($curday == $today['mday']) && ($year == $today['year']) && ($month == $today['mon'])) {
  183. $dayheader = "<b>$curday - ".get_lang("Today")."</b><br />";
  184. $class = "class=\"days_today\" style=\"width:10%;\"";
  185. }
  186. echo "<td ".$class.">", "".$dayheader;
  187. if (!empty($agendaitems[$curday])) {
  188. echo "<span class=\"agendaitem\">".$agendaitems[$curday]."</span>";
  189. }
  190. echo "</td>\n";
  191. $curday ++;
  192. } else {
  193. echo "<td>&nbsp;</td>\n";
  194. }
  195. }
  196. echo "</tr>\n";
  197. }
  198. echo "</table>\n";
  199. }
  200. /**
  201. * Show the mini calender of the given month
  202. */
  203. function display_myminimonthcalendar($agendaitems, $month, $year, $monthName)
  204. {
  205. global $DaysShort,$course_path;
  206. //Handle leap year
  207. $numberofdays = array (0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
  208. if (($year % 400 == 0) or ($year % 4 == 0 and $year % 100 <> 0))
  209. $numberofdays[2] = 29;
  210. //Get the first day of the month
  211. $dayone = getdate(mktime(0, 0, 0, $month, 1, $year));
  212. //Start the week on monday
  213. $startdayofweek = $dayone['wday'] <> 0 ? ($dayone['wday'] - 1) : 6;
  214. $g_cc = (isset($_GET['courseCode'])?$_GET['courseCode']:'');
  215. $backwardsURL = api_get_self()."?coursePath=".urlencode($course_path)."&amp;courseCode=".Security::remove_XSS($g_cc)."&amp;month=". ($month == 1 ? 12 : $month -1)."&amp;year=". ($month == 1 ? $year -1 : $year);
  216. $forewardsURL = api_get_self()."?coursePath=".urlencode($course_path)."&amp;courseCode=".Security::remove_XSS($g_cc)."&amp;month=". ($month == 12 ? 1 : $month +1)."&amp;year=". ($month == 12 ? $year +1 : $year);
  217. echo "<table class=\"data_table\">\n", "<tr>\n", "<th width=\"10%\"><a href=\"", $backwardsURL, "\">&#171;</a></th>\n", "<th width=\"80%\" colspan=\"5\">", $monthName, " ", $year, "</th>\n", "<th width=\"10%\"><a href=\"", $forewardsURL, "\">&#187;</a></th>\n", "</tr>\n";
  218. echo "<tr>\n";
  219. for ($ii = 1; $ii < 8; $ii ++)
  220. {
  221. echo "<td class=\"weekdays\">", $DaysShort[$ii % 7], "</td>\n";
  222. }
  223. echo "</tr>\n";
  224. $curday = -1;
  225. $today = getdate();
  226. while ($curday <= $numberofdays[$month])
  227. {
  228. echo "<tr>\n";
  229. for ($ii = 0; $ii < 7; $ii ++)
  230. {
  231. if (($curday == -1) && ($ii == $startdayofweek))
  232. {
  233. $curday = 1;
  234. }
  235. if (($curday > 0) && ($curday <= $numberofdays[$month]))
  236. {
  237. $bgcolor = $ii < 5 ? $class = "class=\"days_week\"" : $class = "class=\"days_weekend\"";
  238. $dayheader = "$curday";
  239. if (($curday == $today['mday']) && ($year == $today['year']) && ($month == $today['mon']))
  240. {
  241. $dayheader = "$curday";
  242. $class = "class=\"days_today\"";
  243. }
  244. echo "\t<td ".$class.">";
  245. if (!empty($agendaitems[$curday]))
  246. {
  247. echo "<a href=\"".api_get_self()."?action=view&amp;view=day&amp;day=".$curday."&amp;month=".$month."&amp;year=".$year."\">".$dayheader."</a>";
  248. }
  249. else
  250. {
  251. echo $dayheader;
  252. }
  253. // "a".$dayheader." <span class=\"agendaitem\">".$agendaitems[$curday]."</span>\n";
  254. echo "</td>\n";
  255. $curday ++;
  256. }
  257. else
  258. {
  259. echo "<td>&nbsp;</td>\n";
  260. }
  261. }
  262. echo "</tr>\n";
  263. }
  264. echo "</table>\n";
  265. }
  266. /**
  267. * This function shows all the forms that are needed form adding /editing a new personal agenda item
  268. * when there is no $id passed in the function we are adding a new agenda item, if there is a $id
  269. * we are editing
  270. * attention: we have to check that the student is editing an item that belongs to him/her
  271. */
  272. function show_new_personal_item_form($id = "")
  273. {
  274. global $year, $MonthsLong;
  275. global $tbl_personal_agenda;
  276. global $_user;
  277. // we construct the default time and date data (used if we are not editing a personal agenda item)
  278. $today = getdate();
  279. $day = $today['mday'];
  280. $month = $today['mon'];
  281. $year = $today['year'];
  282. $hours = $today['hours'];
  283. $minutes = $today['minutes'];
  284. $content=stripslashes($content);
  285. $title=stripslashes($title);
  286. // if an $id is passed to this function this means we are editing an item
  287. // we are loading the information here (we do this after everything else
  288. // to overwrite the default information)
  289. if (strlen($id) > 0 && $id != strval(intval($id))) {
  290. return false; //potential SQL injection
  291. }
  292. if ($id <> "")
  293. {
  294. $sql = "SELECT * FROM ".$tbl_personal_agenda." WHERE user='".$_user['user_id']."' AND id='".$id."'";
  295. $result = Database::query($sql);
  296. $aantal = Database::num_rows($result);
  297. if ($aantal <> 0)
  298. {
  299. $row = Database::fetch_array($result);
  300. $year = substr($row['date'], 0, 4);
  301. $month = substr($row['date'], 5, 2);
  302. $day = substr($row['date'], 8, 2);
  303. $hours = substr($row['date'], 11, 2);
  304. $minutes = substr($row['date'], 14, 2);
  305. $title = $row['title'];
  306. $text = $row['text'];
  307. }
  308. else
  309. {
  310. return false;
  311. }
  312. }
  313. echo '<form method="post" action="myagenda.php?action=add_personal_agenda_item&amp;id=$id" name="newedit_form">';
  314. echo '<div id="newedit_form">';
  315. echo '<div class="title">';
  316. echo ($_GET['action'] == 'edit_personal_agenda_item') ? get_lang("ModifyPersonalCalendarItem") : get_lang("AddPersonalCalendarItem");
  317. echo '</div>';
  318. echo '<div>';
  319. echo '<!-- date: 1 -> 31 -->';
  320. echo '<br/>';
  321. echo ''.get_lang("Date").': ';
  322. // ********** The form containing the days (0->31) ********** \\
  323. echo '<select name="frm_day">';
  324. // small loop for filling all the dates
  325. // 2do: the available dates should be those of the selected month => february is from 1 to 28 (or 29) and not to 31
  326. for ($i = 1; $i <= 31; $i ++)
  327. {
  328. // values have to have double digits
  329. if ($i <= 9)
  330. {
  331. $value = "0".$i;
  332. }
  333. else
  334. {
  335. $value = $i;
  336. }
  337. // the current day is indicated with [] around the date
  338. if ($value == $day)
  339. {
  340. echo '<option value='.$value.' selected>'.$i.'</option>';
  341. }
  342. else
  343. {
  344. echo '<option value='.$value.'>'.$i.'</option>';
  345. }
  346. }
  347. echo '</select>';
  348. // ********** The form containing the months (jan->dec) ********** \\
  349. echo '<!-- month: january -> december -->';
  350. echo '<select name="frm_month">';
  351. for ($i = 1; $i <= 12; $i ++)
  352. {
  353. // values have to have double digits
  354. if ($i <= 9)
  355. {
  356. $value = "0".$i;
  357. }
  358. else
  359. {
  360. $value = $i;
  361. }
  362. // the current month is indicated with [] around the month name
  363. if ($value == $month)
  364. {
  365. echo '<option value='.$value.' selected>'.$MonthsLong[$i -1].'</option>';
  366. }
  367. else
  368. {
  369. echo '<option value='.$value.'>'.$MonthsLong[$i -1].'</option>';
  370. }
  371. }
  372. echo '</select>';
  373. // ********** The form containing the years ********** \\
  374. echo '<!-- year -->';
  375. echo '<select name="frm_year">';
  376. echo '<option value='. ($year -1).'>'. ($year -1).'</option>';
  377. echo '<option value='.$year.' selected>'.$year.'</option>';
  378. for ($i = 1; $i <= 5; $i ++)
  379. {
  380. $value = $year + $i;
  381. echo '<option value='.$value.'>'.$value.'</option>';
  382. }
  383. echo '</select>&nbsp;&nbsp;';
  384. echo "<a title=\"Kalender\" href=\"javascript:openCalendar('newedit_form', 'frm_')\">".Display::return_icon('calendar_select.gif', get_lang('Select'), array ('style' => 'vertical-align: middle;'))."</a>";
  385. echo '&nbsp;&nbsp;';
  386. // ********** The form containing the hours (00->23) ********** \\
  387. echo '<!-- time: hour -->';
  388. echo get_lang("Time").': ';
  389. echo '<select name="frm_hour">';
  390. for ($i = 1; $i <= 24; $i ++)
  391. {
  392. // values have to have double digits
  393. if ($i <= 9)
  394. {
  395. $value = "0".$i;
  396. }
  397. else
  398. {
  399. $value = $i;
  400. }
  401. // the current hour is indicated with [] around the hour
  402. if ($hours == $value)
  403. {
  404. echo '<option value='.$value.' selected>'.$value.'</option>';
  405. }
  406. else
  407. {
  408. echo '<option value='.$value.'> '.$value.' </option>';
  409. }
  410. }
  411. echo '</select>';
  412. // ********** The form containing the minutes ********** \\
  413. echo "<select name=\"frm_minute\">";
  414. echo "<option value=\"".$minutes."\">".$minutes."</option>";
  415. echo "<option value=\"00\">00</option>";
  416. echo "<option value=\"05\">05</option>";
  417. echo "<option value=\"10\">10</option>";
  418. echo "<option value=\"15\">15</option>";
  419. echo "<option value=\"20\">20</option>";
  420. echo "<option value=\"25\">25</option>";
  421. echo "<option value=\"30\">30</option>";
  422. echo "<option value=\"35\">35</option>";
  423. echo "<option value=\"40\">40</option>";
  424. echo "<option value=\"45\">45</option>";
  425. echo "<option value=\"50\">50</option>";
  426. echo "<option value=\"55\">55</option>";
  427. echo '</select>';
  428. echo '</div><br/>';
  429. // ********** The title field ********** \\
  430. echo '<div>';
  431. echo ''.get_lang('Title').' : <input type="text" name="frm_title" size="50" value="'.$title.'" />';
  432. echo '</div>';
  433. // ********** The text field ********** \\
  434. echo '<div class="formw">';
  435. require_once(api_get_path(LIBRARY_PATH) . "/fckeditor/fckeditor.php");
  436. $oFCKeditor = new FCKeditor('frm_content') ;
  437. $oFCKeditor->Width = '80%';
  438. $oFCKeditor->Height = '200';
  439. if(!api_is_allowed_to_edit(null,true)) {
  440. $oFCKeditor->ToolbarSet = 'AgendaStudent';
  441. } else {
  442. $oFCKeditor->ToolbarSet = 'Agenda';
  443. }
  444. $oFCKeditor->Value = $content;
  445. $return = $oFCKeditor->CreateHtml();
  446. echo $return;
  447. echo '</div>';
  448. // ********** The Submit button********** \\
  449. echo '<div>';
  450. echo '<button type="submit" class="add" name="Submit" value="'.get_lang('AddEvent').'" >'.get_lang('AddEvent').'</button>';
  451. echo '</div>';
  452. echo '</div>';
  453. echo '</form>';
  454. }
  455. /**
  456. * This function shows all the forms that are needed form adding a new personal agenda item
  457. */
  458. function store_personal_item($day, $month, $year, $hour, $minute, $title, $content, $id = "")
  459. {
  460. global $tbl_personal_agenda;
  461. global $_user;
  462. //constructing the date
  463. $date = $year."-".$month."-".$day." ".$hour.":".$minute.":00";
  464. $date = Database::escape_string($date);
  465. $title = Database::escape_string($title);
  466. $content = Database::escape_string($content);
  467. if ($id != strval(intval($id))) {
  468. return false; //potential SQL injection
  469. }
  470. if ($id <> "")
  471. { // we are updating
  472. $sql = "UPDATE ".$tbl_personal_agenda." SET user='".$_user['user_id']."', title='".$title."', text='".$content."', date='".$date."' WHERE id='".$id."'";
  473. }
  474. else
  475. { // we are adding a new item
  476. $sql = "INSERT INTO $tbl_personal_agenda (user, title, text, date) VALUES ('".$_user['user_id']."','$title', '$content', '$date')";
  477. }
  478. $result = Database::query($sql);
  479. }
  480. /**
  481. * This function finds all the courses (also those of sessions) of the user and returns an array containing the
  482. * database name of the courses.
  483. * Xritten by Noel Dieschburg <noel.dieschburg@dokeos.com>
  484. */
  485. function get_all_courses_of_user()
  486. {
  487. global $TABLECOURS;
  488. global $TABLECOURSUSER;
  489. global $_user;
  490. $tbl_session_course = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE);
  491. $tbl_session_course_user= Database :: get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
  492. $tbl_session = Database :: get_main_table(TABLE_MAIN_SESSION);
  493. $sql_select_courses = "SELECT c.code k, c.visual_code vc, c.title i, c.tutor_name t,
  494. c.db_name db, c.directory dir, '5' as status
  495. FROM $TABLECOURS c, $tbl_session_course_user srcu
  496. WHERE srcu.id_user='".$_user['user_id']."'
  497. AND c.code=srcu.course_code
  498. UNION
  499. SELECT c.code k, c.visual_code vc, c.title i, c.tutor_name t,
  500. c.db_name db, c.directory dir, cru.status status
  501. FROM $TABLECOURS c, $TABLECOURSUSER cru
  502. WHERE cru.user_id='".$_user['user_id']."'
  503. AND c.code=cru.course_code";
  504. $result = Database::query($sql_select_courses);
  505. while ($row = Database::fetch_array($result))
  506. {
  507. // we only need the database name of the course
  508. $courses[] = array ("db" => $row['db'], "code" => $row['k'], "visual_code" => $row['vc'], "title" => $row['i'], "directory" => $row['dir'], "status" => $row['status']);
  509. }
  510. return $courses;
  511. }
  512. /**
  513. * This function finds all the courses of the user and returns an array containing the
  514. * database name of the courses.
  515. */
  516. function get_courses_of_user()
  517. {
  518. global $TABLECOURS;
  519. global $TABLECOURSUSER;
  520. global $_user;
  521. $sql_select_courses = "SELECT course.code k, course.visual_code vc,
  522. course.title i, course.tutor_name t, course.db_name db, course.directory dir, course_rel_user.status status
  523. FROM $TABLECOURS course,
  524. $TABLECOURSUSER course_rel_user
  525. WHERE course.code = course_rel_user.course_code
  526. AND course_rel_user.user_id = '".$_user['user_id']."'";
  527. $result = Database::query($sql_select_courses);
  528. while ($row = Database::fetch_array($result))
  529. {
  530. // we only need the database name of the course
  531. $courses[] = array ("db" => $row['db'], "code" => $row['k'], "visual_code" => $row['vc'], "title" => $row['i'], "directory" => $row['dir'], "status" => $row['status']);
  532. }
  533. return $courses;
  534. }
  535. /**
  536. * This function retrieves all the personal agenda items and add them to the agenda items found by the other functions.
  537. */
  538. function get_personal_agenda_items($agendaitems, $day = "", $month = "", $year = "", $week = "", $type)
  539. {
  540. global $tbl_personal_agenda;
  541. global $_user;
  542. global $_configuration;
  543. // 1. creating the SQL statement for getting the personal agenda items in MONTH view
  544. if ($type == "month_view" or $type == "") // we are in month view
  545. {
  546. $sql = "SELECT * FROM ".$tbl_personal_agenda." WHERE user='".$_user['user_id']."' and MONTH(date)='".$month."' AND YEAR(date) = '".$year."' ORDER BY date ASC";
  547. }
  548. // 2. creating the SQL statement for getting the personal agenda items in WEEK view
  549. if ($type == "week_view") // we are in week view
  550. {
  551. $start_end_day_of_week = calculate_start_end_of_week($week, $year);
  552. $start_day = $start_end_day_of_week['start']['day'];
  553. $start_month = $start_end_day_of_week['start']['month'];
  554. $start_year = $start_end_day_of_week['start']['year'];
  555. $end_day = $start_end_day_of_week['end']['day'];
  556. $end_month = $start_end_day_of_week['end']['month'];
  557. $end_year = $start_end_day_of_week['end']['year'];
  558. // in sql statements you have to use year-month-day for date calculations
  559. $start_filter = $start_year."-".$start_month."-".$start_day." 00:00:00";
  560. $end_filter = $end_year."-".$end_month."-".$end_day." 23:59:59";
  561. $sql = " SELECT * FROM ".$tbl_personal_agenda." WHERE user='".$_user['user_id']."'
  562. AND date>='".$start_filter."' AND date<='".$end_filter."'";
  563. }
  564. // 3. creating the SQL statement for getting the personal agenda items in DAY view
  565. if ($type == "day_view") // we are in day view
  566. {
  567. // we could use mysql date() function but this is only available from 4.1 and higher
  568. $start_filter = $year."-".$month."-".$day." 00:00:00";
  569. $end_filter = $year."-".$month."-".$day." 23:59:59";
  570. $sql = " SELECT * FROM ".$tbl_personal_agenda." WHERE user='".$_user['user_id']."' AND date>='".$start_filter."' AND date<='".$end_filter."'";
  571. }
  572. //echo "day:".$day."/";
  573. //echo "month:".$month."/";
  574. //echo "year:".$year."/";
  575. //echo "week:".$week."/";
  576. //echo $type."<p>";
  577. //echo "<pre>".$sql."</pre>";
  578. global $_configuration;
  579. $root_url = $_configuration['root_web'];
  580. if ($_configuration['multiple_access_urls']==true) {
  581. $access_url_id = api_get_current_access_url_id();
  582. if ($access_url_id != -1 ){
  583. $url = api_get_access_url($access_url_id);
  584. $root_url = $url['url'];
  585. }
  586. }
  587. $result = Database::query($sql);
  588. while ($item = Database::fetch_array($result))
  589. {
  590. // we break the date field in the database into a date and a time part
  591. $agenda_db_date = explode(" ", $item[date]);
  592. $date = $agenda_db_date[0];
  593. $time = $agenda_db_date[1];
  594. // we divide the date part into a day, a month and a year
  595. $agendadate = explode("-", $date);
  596. $year = intval($agendadate[0]);
  597. $month = intval($agendadate[1]);
  598. $day = intval($agendadate[2]);
  599. // we divide the time part into hour, minutes, seconds
  600. $agendatime = explode(":", $time);
  601. $hour = $agendatime[0];
  602. $minute = $agendatime[1];
  603. $second = $agendatime[2];
  604. // if the student has specified a course we a add a link to that course
  605. if ($item['course'] <> "")
  606. {
  607. $url = $root_url."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
  608. $course_link = "<a href=\"$url\" title=\"".$item['course']."\">".$item['course']."</a>";
  609. }
  610. else
  611. {
  612. $course_link = "";
  613. }
  614. // Creating the array that will be returned. If we have week or month view we have an array with the date as the key
  615. // if we have a day_view we use a half hour as index => key 33 = 16h30
  616. if ($type !== "day_view") // This is the array construction for the WEEK or MONTH view
  617. {
  618. //Display events in agenda
  619. $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><br />";
  620. }
  621. else // this is the array construction for the DAY view
  622. {
  623. $halfhour = 2 * $agendatime['0'];
  624. if ($agendatime['1'] >= '30')
  625. {
  626. $halfhour = $halfhour +1;
  627. }
  628. //Display events by list
  629. $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>";
  630. }
  631. }
  632. //print_r($agendaitems);
  633. return $agendaitems;
  634. }
  635. /**
  636. * This function retrieves one personal agenda item returns it.
  637. * @param int The agenda item ID
  638. * @return array The results of the database query, or null if not found
  639. */
  640. function get_personal_agenda_item($id)
  641. {
  642. $tbl_personal_agenda = Database :: get_user_personal_table(TABLE_PERSONAL_AGENDA);
  643. $id = Database::escape_string($id);
  644. // make sure events of the personal agenda can only be seen by the user himself
  645. $user = api_get_user_id();
  646. $sql = " SELECT * FROM ".$tbl_personal_agenda." WHERE id=".$id." AND user = ".$user;
  647. $result = Database::query($sql);
  648. if(Database::num_rows($result)==1)
  649. {
  650. $item = Database::fetch_array($result);
  651. }
  652. else
  653. {
  654. $item = null;
  655. }
  656. return $item;
  657. }
  658. /**
  659. * This function retrieves all the personal agenda items of the user and shows
  660. * these items in one list (ordered by date and grouped by month (the month_bar)
  661. */
  662. function show_personal_agenda()
  663. {
  664. global $tbl_personal_agenda;
  665. global $MonthsLong, $charset;
  666. global $_user;
  667. // The SQL statement that retrieves all the personal agenda items of this user
  668. $sql = "SELECT * FROM ".$tbl_personal_agenda." WHERE user='".$_user['user_id']."' ORDER BY date DESC";
  669. $result = Database::query($sql);
  670. // variable initialisation
  671. $month_bar = "";
  672. // setting the default day, month and year
  673. if (!$_GET['day'] AND !$_GET['month'] AND !$_GET['year'])
  674. {
  675. $today = getdate();
  676. $year = $today['year'];
  677. $month = $today['mon'];
  678. $day = $today['mday'];
  679. }
  680. $export_icon = 'export.png';
  681. $export_icon_low = 'export_low_fade.png';
  682. $export_icon_high = 'export_high_fade.png';
  683. // starting the table output
  684. echo "<table class=\"data_table\">\n";
  685. if (Database::num_rows($result) > 0)
  686. {
  687. while ($myrow = Database::fetch_array($result))
  688. {
  689. /*--------------------------------------------------
  690. display: the month bar
  691. --------------------------------------------------*/
  692. if ($month_bar != date("m", strtotime($myrow["date"])).date("Y", strtotime($myrow["date"])))
  693. {
  694. $month_bar = date("m", strtotime($myrow["date"])).date("Y", strtotime($myrow["date"]));
  695. echo "<tr><th class=\"title\" colspan=\"2\" class=\"month\" valign=\"top\">".$MonthsLong[date("n", strtotime($myrow["date"])) - 1]." ".date("Y", strtotime($myrow["date"]))."</th></tr>\n";
  696. }
  697. // highlight: if a date in the small calendar is clicked we highlight the relevant items
  698. $db_date = (int) date("d", strtotime($myrow["date"])).date("n", strtotime($myrow["date"])).date("Y", strtotime($myrow["date"]));
  699. if ($_GET["day"].$_GET["month"].$_GET["year"] <> $db_date)
  700. {
  701. $style = "data";
  702. $text_style = "text";
  703. }
  704. else
  705. {
  706. $style = "datanow";
  707. $text_style = "text";
  708. }
  709. /*--------------------------------------------------
  710. display: date and time
  711. --------------------------------------------------*/
  712. echo "\t<tr>\n\t\t";
  713. echo '<td class="'.$style.'">';
  714. // adding an internal anchor
  715. echo "<a name=\"".$myrow["id"]."\"></a>";
  716. echo date("d", strtotime($myrow["date"]))." ".$MonthsLong[date("n", strtotime($myrow["date"])) - 1]." ".date("Y", strtotime($myrow["date"]))."&nbsp;";
  717. echo api_ucfirst(strftime(get_lang("timeNoSecFormat"), strtotime($myrow["date"])));
  718. echo "</td>";
  719. echo '<td></td>'; //remove when enabling ical
  720. //echo '<td class="'.$style.'">';
  721. //echo '<a class="ical_export" href="ical_export.php?type=personal&id='.$myrow['id'].'&class=confidential" title="'.get_lang('ExportiCalConfidential').'">'.Display::return_icon($export_icon_high, get_lang('ExportiCalConfidential')).'</a>';
  722. //echo '<a class="ical_export" href="ical_export.php?type=personal&id='.$myrow['id'].'&class=private" title="'.get_lang('ExportiCalPrivate').'">'.Display::return_icon($export_icon_low, get_lang('ExportiCalPrivate')).'</a>';
  723. //echo '<a class="ical_export" href="ical_export.php?type=personal&id='.$myrow['id'].'&class=public" title="'.get_lang('ExportiCalPublic').'">'.Display::return_icon($export_icon, get_lang('ExportiCalPublic')).'</a>';
  724. //echo "\n\t\t</td>\n\t";
  725. echo "</tr>";
  726. /*--------------------------------------------------
  727. display: the title
  728. --------------------------------------------------*/
  729. echo "<tr>";
  730. echo '<td class="'.$style.'" colspan="2">';
  731. echo $myrow['title'];
  732. echo "\n\t\t</td>\n\t";
  733. echo "</tr>\n";
  734. /*--------------------------------------------------
  735. display: the content
  736. --------------------------------------------------*/
  737. $content = $myrow['text'];
  738. $content = make_clickable($content);
  739. $content = text_filter($content);
  740. echo "\t<tr>\n\t\t<td class=\"".$text_style."\" colspan='2'>";
  741. echo $content;
  742. echo "</td></tr>";
  743. /*--------------------------------------------------
  744. display: the edit / delete icons
  745. --------------------------------------------------*/
  746. echo "\t<tr>\n\t\t<td class=\"".$text_style."\" colspan='2'>";
  747. echo "<a href=\"myagenda.php?action=edit_personal_agenda_item&amp;id=".$myrow['id']."\">".Display::return_icon('edit.gif', get_lang('Edit'))."</a>";
  748. echo "<a href=\"".api_get_self()."?action=delete&amp;id=".$myrow['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>";
  749. echo "</td></tr>";
  750. }
  751. }
  752. else
  753. {
  754. echo '<tr><td colspan="2">'.get_lang('NoAgendaItems').'</td></tr>';
  755. }
  756. echo "</table>\n";
  757. }
  758. /**
  759. * This function retrieves all the personal agenda items of the given user_id and shows
  760. * these items in one list (ordered by date and grouped by month (the month_bar)
  761. * @param int user id
  762. */
  763. function show_simple_personal_agenda($user_id)
  764. {
  765. $tbl_personal_agenda = Database :: get_user_personal_table(TABLE_PERSONAL_AGENDA);
  766. global $MonthsLong, $charset;
  767. // The SQL statement that retrieves all the personal agenda items of this user
  768. $sql = "SELECT * FROM ".$tbl_personal_agenda." WHERE user='".$user_id."' ORDER BY date DESC";
  769. $result = Database::query($sql);
  770. // variable initialisation
  771. $month_bar = "";
  772. // setting the default day, month and year
  773. if (!$_GET['day'] AND !$_GET['month'] AND !$_GET['year']) {
  774. $today = getdate();
  775. $year = $today['year'];
  776. $month = $today['mon'];
  777. $day = $today['mday'];
  778. }
  779. $export_icon = 'export.png';
  780. $export_icon_low = 'export_low_fade.png';
  781. $export_icon_high = 'export_high_fade.png';
  782. $content = '';
  783. // starting the table output
  784. if (Database::num_rows($result) > 0) {
  785. while ($myrow = Database::fetch_array($result)) {
  786. /*--------------------------------------------------
  787. display: the month bar
  788. --------------------------------------------------*/
  789. if ($month_bar != date("m", strtotime($myrow["date"])).date("Y", strtotime($myrow["date"]))) {
  790. $month_bar = date("m", strtotime($myrow["date"])).date("Y", strtotime($myrow["date"]));
  791. $content.= $MonthsLong[date("n", strtotime($myrow["date"])) - 1]." ".date("Y", strtotime($myrow["date"]));
  792. }
  793. // highlight: if a date in the small calendar is clicked we highlight the relevant items
  794. $db_date = (int) date("d", strtotime($myrow["date"])).date("n", strtotime($myrow["date"])).date("Y", strtotime($myrow["date"]));
  795. if ($_GET["day"].$_GET["month"].$_GET["year"] <> $db_date) {
  796. $style = "data";
  797. $text_style = "text";
  798. } else {
  799. $style = "datanow";
  800. $text_style = "text";
  801. }
  802. /*--------------------------------------------------
  803. display: date and time
  804. --------------------------------------------------*/
  805. // adding an internal anchor
  806. $content.= date("d", strtotime($myrow["date"]))." ".$MonthsLong[date("n", strtotime($myrow["date"])) - 1]." ".date("Y", strtotime($myrow["date"]))."&nbsp;";
  807. $content.= api_ucfirst(strftime(get_lang("timeNoSecFormat"), strtotime($myrow["date"])));
  808. /*--------------------------------------------------
  809. display: the title
  810. --------------------------------------------------*/
  811. $content.= '<br />';
  812. $content.= $myrow['title'];
  813. $content.= '<br />';
  814. /*--------------------------------------------------
  815. display: the content
  816. --------------------------------------------------*/
  817. /*
  818. $content = $myrow['title'];
  819. $content = make_clickable($content);
  820. $content = text_filter($content);*/
  821. return $content;
  822. }
  823. } else {
  824. return $content;
  825. }
  826. }
  827. /**
  828. * This function deletes a personal agenda item
  829. * There is an additional check to make sure that one cannot delete an item that
  830. * does not belong to him/her
  831. */
  832. function delete_personal_agenda($id)
  833. {
  834. global $tbl_personal_agenda;
  835. global $_user;
  836. if ($id != strval(intval($id))) {
  837. return false; //potential SQL injection
  838. }
  839. if ($id <> '')
  840. {
  841. $sql = "SELECT * FROM ".$tbl_personal_agenda." WHERE user='".$_user['user_id']."' AND id='".$id."'";
  842. $result = Database::query($sql);
  843. $aantal = Database::num_rows($result);
  844. if ($aantal <> 0)
  845. {
  846. $sql = "DELETE FROM ".$tbl_personal_agenda." WHERE user='".$_user['user_id']."' AND id='".$id."'";
  847. $result = Database::query($sql);
  848. }
  849. }
  850. }
  851. /**
  852. * Get personal agenda items between two dates (=all events from all registered courses)
  853. * @param int user ID of the user
  854. * @param string Optional start date in datetime format (if no start date is given, uses today)
  855. * @param string Optional end date in datetime format (if no date is given, uses one year from now)
  856. * @return array Array of events ordered by start date, in [0]('datestart','dateend','title'),[1]('datestart','dateend','title','link','coursetitle') format, where datestart and dateend are in yyyyMMddhhmmss format.
  857. * @TODO Implement really personal events (from user DB) and global events (from main DB)
  858. */
  859. function get_personal_agenda_items_between_dates($user_id, $date_start='', $date_end='') {
  860. $items = array ();
  861. if ($user_id != strval(intval($user_id))) { return $items; }
  862. if (empty($date_start)) { $date_start = date('Y-m-d H:i:s');}
  863. if (empty($date_end)) { $date_end = date('Y-m-d H:i:s',mktime(0, 0, 0, date("m"), date("d"), date("Y")+1));}
  864. $expr = '/\d{4}-\d{2}-\d{2}\ \d{2}:\d{2}:\d{2}/';
  865. if(!preg_match($expr,$date_start)) { return $items; }
  866. if(!preg_match($expr,$date_end)) { return $items; }
  867. // get agenda-items for every course
  868. $courses = api_get_user_courses($user_id,false);
  869. require_once(api_get_path(LIBRARY_PATH).'groupmanager.lib.php');
  870. foreach ($courses as $id => $course)
  871. {
  872. $c = api_get_course_info($course['code']);
  873. //databases of the courses
  874. $t_a = Database :: get_course_table(TABLE_AGENDA, $course['db']);
  875. $t_ip = Database :: get_course_table(TABLE_ITEM_PROPERTY, $course['db']);
  876. // get the groups to which the user belong
  877. $group_memberships = GroupManager :: get_group_ids($course['db'], $user_id);
  878. // if the user is administrator of that course we show all the agenda items
  879. if ($course['status'] == '1') {
  880. //echo "course admin";
  881. $sqlquery = "SELECT ".
  882. " DISTINCT agenda.*, ip.visibility, ip.to_group_id, ip.insert_user_id, ip.ref ".
  883. " FROM ".$t_a." agenda, ".
  884. $t_ip." ip ".
  885. " WHERE agenda.id = ip.ref ".
  886. " AND agenda.start_date>='$date_start' ".
  887. " AND agenda.end_date<='$date_end' ".
  888. " AND ip.tool='".TOOL_CALENDAR_EVENT."' ".
  889. " AND ip.visibility='1' ".
  890. " GROUP BY agenda.id ".
  891. " ORDER BY start_date ";
  892. } else {
  893. // if the user is not an administrator of that course, then...
  894. if (is_array($group_memberships) && count($group_memberships)>0)
  895. {
  896. $sqlquery = "SELECT " .
  897. " agenda.*, ip.visibility, ip.to_group_id, ip.insert_user_id, ip.ref ".
  898. " FROM ".$t_a." agenda, ".
  899. $t_ip." ip ".
  900. " WHERE agenda.id = ip.ref ".
  901. " AND agenda.start_date>='$date_start' ".
  902. " AND agenda.end_date<='$date_end' ".
  903. " AND ip.tool='".TOOL_CALENDAR_EVENT."' ".
  904. " AND ( ip.to_user_id='".$user_id."' OR ip.to_group_id IN (0, ".implode(", ", $group_memberships).") ) ".
  905. " AND ip.visibility='1' ".
  906. " ORDER BY start_date ";
  907. } else {
  908. $sqlquery = "SELECT ".
  909. " agenda.*, ip.visibility, ip.to_group_id, ip.insert_user_id, ip.ref ".
  910. " FROM ".$t_a." agenda, ".
  911. $t_ip." ip ".
  912. " WHERE agenda.id = ip.ref ".
  913. " AND agenda.start_date>='$date_start' ".
  914. " AND agenda.end_date<='$date_end' ".
  915. " AND ip.tool='".TOOL_CALENDAR_EVENT."' ".
  916. " AND ( ip.to_user_id='".$user_id."' OR ip.to_group_id='0') ".
  917. " AND ip.visibility='1' ".
  918. " ORDER BY start_date ";
  919. }
  920. }
  921. $result = Database::query($sqlquery);
  922. while ($item = Database::fetch_array($result)) {
  923. $agendaday = date("j",strtotime($item['start_date']));
  924. $URL = api_get_path(WEB_PATH)."main/calendar/agenda.php?cidReq=".urlencode($course["code"])."&amp;day=$agendaday&amp;month=$month&amp;year=$year#$agendaday";
  925. list($year,$month,$day,$hour,$min,$sec) = split('[-: ]',$item['start_date']);
  926. $start_date = $year.$month.$day.$hour.$min;
  927. list($year,$month,$day,$hour,$min,$sec) = split('[-: ]',$item['end_date']);
  928. $end_date = $year.$month.$day.$hour.$min;
  929. $items[] = array(
  930. 'datestart'=>$start_date,
  931. 'dateend'=>$end_date,
  932. 'title'=>$item['title'],
  933. 'link'=>$URL,
  934. 'coursetitle'=>$c['name'],
  935. );
  936. }
  937. }
  938. return $items;
  939. }
  940. ?>