myagenda.inc.php 40 KB

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