myagenda.inc.php 41 KB

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