myagenda.inc.php 41 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000
  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_user_personal_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_user_personal_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 = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE);
  493. $tbl_session_course_user= Database :: get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
  494. $tbl_session = Database :: get_main_table(TABLE_MAIN_SESSION);
  495. $sql_select_courses = "SELECT c.code k, c.visual_code vc, c.title i, c.tutor_name t,
  496. c.db_name db, c.directory dir, '5' as status
  497. FROM $TABLECOURS c, $tbl_session_course_user srcu
  498. WHERE srcu.id_user='".api_get_user_id()."'
  499. AND c.code=srcu.course_code
  500. UNION
  501. SELECT c.code k, c.visual_code vc, c.title i, c.tutor_name t,
  502. c.db_name db, c.directory dir, cru.status status
  503. FROM $TABLECOURS c, $TABLECOURSUSER cru
  504. WHERE cru.user_id='".api_get_user_id()."'
  505. AND c.code=cru.course_code";
  506. $result = Database::query($sql_select_courses);
  507. while ($row = Database::fetch_array($result)) {
  508. // we only need the database name of the course
  509. $courses[] = array ("db" => $row['db'], "code" => $row['k'], "visual_code" => $row['vc'], "title" => $row['i'], "directory" => $row['dir'], "status" => $row['status']);
  510. }
  511. return $courses;
  512. }
  513. /**
  514. * This function finds all the courses of the user and returns an array containing the
  515. * database name of the courses.
  516. */
  517. function get_courses_of_user() {
  518. $TABLECOURS = Database :: get_main_table(TABLE_MAIN_COURSE);
  519. $TABLECOURSUSER = Database :: get_main_table(TABLE_MAIN_COURSE_USER);
  520. $sql_select_courses = "SELECT course.code k, course.visual_code vc,
  521. course.title i, course.tutor_name t, course.db_name db, course.directory dir, course_rel_user.status status
  522. FROM $TABLECOURS course,
  523. $TABLECOURSUSER course_rel_user
  524. WHERE course.code = course_rel_user.course_code
  525. AND course_rel_user.user_id = '".api_get_user_id()."'";
  526. $result = Database::query($sql_select_courses);
  527. while ($row = Database::fetch_array($result))
  528. {
  529. // we only need the database name of the course
  530. $courses[] = array ("db" => $row['db'], "code" => $row['k'], "visual_code" => $row['vc'], "title" => $row['i'], "directory" => $row['dir'], "status" => $row['status']);
  531. }
  532. return $courses;
  533. }
  534. /**
  535. * This function retrieves all the personal agenda items and add them to the agenda items found by the other functions.
  536. */
  537. function get_personal_agenda_items($user_id, $agendaitems, $day = "", $month = "", $year = "", $week = "", $type) {
  538. $tbl_personal_agenda = Database :: get_user_personal_table(TABLE_PERSONAL_AGENDA);
  539. $user_id = intval($user_id);
  540. // 1. creating the SQL statement for getting the personal agenda items in MONTH view
  541. if ($type == "month_view" or $type == "") {
  542. // we are in month view
  543. $sql = "SELECT * FROM ".$tbl_personal_agenda." WHERE user='".$user_id."' and MONTH(date)='".$month."' AND YEAR(date) = '".$year."' ORDER BY date ASC";
  544. }
  545. // 2. creating the SQL statement for getting the personal agenda items in WEEK view
  546. // we are in week view
  547. if ($type == "week_view") {
  548. $start_end_day_of_week = calculate_start_end_of_week($week, $year);
  549. $start_day = $start_end_day_of_week['start']['day'];
  550. $start_month = $start_end_day_of_week['start']['month'];
  551. $start_year = $start_end_day_of_week['start']['year'];
  552. $end_day = $start_end_day_of_week['end']['day'];
  553. $end_month = $start_end_day_of_week['end']['month'];
  554. $end_year = $start_end_day_of_week['end']['year'];
  555. // in sql statements you have to use year-month-day for date calculations
  556. $start_filter = $start_year."-".$start_month."-".$start_day." 00:00:00";
  557. $start_filter = api_get_utc_datetime($start_filter);
  558. $end_filter = $end_year."-".$end_month."-".$end_day." 23:59:59";
  559. $end_filter = api_get_utc_datetime($end_filter);
  560. $sql = " SELECT * FROM ".$tbl_personal_agenda." WHERE user='".$user_id."' AND date>='".$start_filter."' AND date<='".$end_filter."'";
  561. }
  562. // 3. creating the SQL statement for getting the personal agenda items in DAY view
  563. if ($type == "day_view") {
  564. // we are in day view
  565. // we could use mysql date() function but this is only available from 4.1 and higher
  566. $start_filter = $year."-".$month."-".$day." 00:00:00";
  567. $start_filter = api_get_utc_datetime($start_filter);
  568. $end_filter = $year."-".$month."-".$day." 23:59:59";
  569. $end_filter = api_get_utc_datetime($end_filter);
  570. $sql = " SELECT * FROM ".$tbl_personal_agenda." WHERE user='".$user_id."' AND date>='".$start_filter."' AND date<='".$end_filter."'";
  571. }
  572. $result = Database::query($sql);
  573. while ($item = Database::fetch_array($result, 'ASSOC')) {
  574. $time_minute = api_convert_and_format_date($item['date'], TIME_NO_SEC_FORMAT);
  575. $item['date'] = api_get_local_time($item['date']);
  576. $item['start_date_tms'] = api_strtotime($item['date']);
  577. $item['content'] = $item['text'];
  578. // we break the date field in the database into a date and a time part
  579. $agenda_db_date = explode(" ", $item['date']);
  580. $date = $agenda_db_date[0];
  581. $time = $agenda_db_date[1];
  582. // we divide the date part into a day, a month and a year
  583. $agendadate = explode("-", $item['date']);
  584. $year = intval($agendadate[0]);
  585. $month = intval($agendadate[1]);
  586. $day = intval($agendadate[2]);
  587. // we divide the time part into hour, minutes, seconds
  588. $agendatime = explode(":", $time);
  589. $hour = $agendatime[0];
  590. $minute = $agendatime[1];
  591. $second = $agendatime[2];
  592. if ($type == 'month_view') {
  593. $item['calendar_type'] = 'personal';
  594. $item['start_date'] = $item['date'];
  595. $agendaitems[$day][] = $item;
  596. continue;
  597. }
  598. // if the student has specified a course we a add a link to that course
  599. if ($item['course'] <> "") {
  600. $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
  601. $course_link = "<a href=\"$url\" title=\"".$item['course']."\">".$item['course']."</a>";
  602. } else {
  603. $course_link = "";
  604. }
  605. // Creating the array that will be returned. If we have week or month view we have an array with the date as the key
  606. // if we have a day_view we use a half hour as index => key 33 = 16h30
  607. if ($type !== "day_view") {
  608. // This is the array construction for the WEEK or MONTH view
  609. //Display events in agenda
  610. $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 />";
  611. } else {
  612. // this is the array construction for the DAY view
  613. $halfhour = 2 * $agendatime['0'];
  614. if ($agendatime['1'] >= '30') {
  615. $halfhour = $halfhour +1;
  616. }
  617. //Display events by list
  618. $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>";
  619. }
  620. }
  621. return $agendaitems;
  622. }
  623. /**
  624. * This function retrieves one personal agenda item returns it.
  625. * @param int The agenda item ID
  626. * @return array The results of the database query, or null if not found
  627. */
  628. function get_personal_agenda_item($id) {
  629. $tbl_personal_agenda = Database :: get_user_personal_table(TABLE_PERSONAL_AGENDA);
  630. $id = Database::escape_string($id);
  631. // make sure events of the personal agenda can only be seen by the user himself
  632. $user = api_get_user_id();
  633. $sql = " SELECT * FROM ".$tbl_personal_agenda." WHERE id=".$id." AND user = ".$user;
  634. $result = Database::query($sql);
  635. if(Database::num_rows($result)==1) {
  636. $item = Database::fetch_array($result);
  637. } else {
  638. $item = null;
  639. }
  640. return $item;
  641. }
  642. /**
  643. * This function retrieves all the personal agenda items of the user and shows
  644. * these items in one list (ordered by date and grouped by month (the month_bar)
  645. */
  646. function show_personal_agenda() {
  647. global $MonthsLong, $charset;
  648. $tbl_personal_agenda = Database :: get_user_personal_table(TABLE_PERSONAL_AGENDA);
  649. // The SQL statement that retrieves all the personal agenda items of this user
  650. $sql = "SELECT * FROM ".$tbl_personal_agenda." WHERE user='".api_get_user_id()."' ORDER BY date DESC";
  651. $result = Database::query($sql);
  652. // variable initialisation
  653. $month_bar = "";
  654. // setting the default day, month and year
  655. if (!isset($_GET['day']) AND !isset($_GET['month']) AND !isset($_GET['year'])) {
  656. $today = getdate();
  657. $year = $today['year'];
  658. $month = $today['mon'];
  659. $day = $today['mday'];
  660. }
  661. $export_icon = 'export.png';
  662. $export_icon_low = 'export_low_fade.png';
  663. $export_icon_high = 'export_high_fade.png';
  664. // starting the table output
  665. echo '<table class="data_table">';
  666. $th = Display::tag('th', get_lang('Title'));
  667. $th .= Display::tag('th', get_lang('Content'));
  668. $th .= Display::tag('th', get_lang('StartTimeWindow'));
  669. $th .= Display::tag('th', get_lang('Modify'));
  670. echo Display::tag('tr', $th);
  671. if (Database::num_rows($result) > 0) {
  672. $counter = 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. /*
  682. if ($_GET["day"].$_GET["month"].$_GET["year"] <> $db_date) {
  683. $style = "data";
  684. $text_style = "text";
  685. } else {
  686. $style = "datanow";
  687. $text_style = "text";
  688. }*/
  689. $class = 'row_even';
  690. if ($counter % 2) {
  691. $class = 'row_odd';
  692. }
  693. echo '<tr class="'.$class.'">';
  694. echo '<td>';
  695. /* display: the title */
  696. echo $myrow['title'];
  697. echo "</td>";
  698. // display: the content
  699. $content = $myrow['text'];
  700. echo "<td>";
  701. echo $content;
  702. echo "</td>";
  703. //display: date and time
  704. echo '<td>';
  705. // adding an internal anchor
  706. /*echo "<a name=\"".$myrow["id"]."\"></a>";
  707. echo date("d", strtotime($myrow["date"]))." ".$MonthsLong[date("n", strtotime($myrow["date"])) - 1]." ".date("Y", strtotime($myrow["date"]))."&nbsp;";*/
  708. $myrow["date"] = api_get_local_time($myrow["date"]);
  709. echo api_format_date($myrow["date"], DATE_TIME_FORMAT_LONG);
  710. echo "</td>";
  711. //echo '<td></td>'; //remove when enabling ical
  712. //echo '<td class="'.$style.'">';
  713. //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>';
  714. //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>';
  715. //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>';
  716. //echo "</td>";
  717. //echo "</tr>";
  718. /* display: the edit / delete icons */
  719. echo "<td>";
  720. 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> ";
  721. 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>";
  722. echo "</td></tr>";
  723. $counter++;
  724. }
  725. } else {
  726. echo '<tr><td colspan="2">'.get_lang('NoAgendaItems').'</td></tr>';
  727. }
  728. echo "</table>";
  729. }
  730. /**
  731. * This function retrieves all the personal agenda items of the given user_id and shows
  732. * these items in one list (ordered by date and grouped by month (the month_bar)
  733. * @param int user id
  734. */
  735. function show_simple_personal_agenda($user_id) {
  736. global $MonthsLong, $charset;
  737. $tbl_personal_agenda = Database :: get_user_personal_table(TABLE_PERSONAL_AGENDA);
  738. // The SQL statement that retrieves all the personal agenda items of this user
  739. $sql = "SELECT * FROM ".$tbl_personal_agenda." WHERE user='".$user_id."' ORDER BY date DESC";
  740. $result = Database::query($sql);
  741. // variable initialisation
  742. $month_bar = "";
  743. // setting the default day, month and year
  744. if (!$_GET['day'] AND !$_GET['month'] AND !$_GET['year']) {
  745. $today = getdate();
  746. $year = $today['year'];
  747. $month = $today['mon'];
  748. $day = $today['mday'];
  749. }
  750. $export_icon = 'export.png';
  751. $export_icon_low = 'export_low_fade.png';
  752. $export_icon_high = 'export_high_fade.png';
  753. $content = '';
  754. // starting the table output
  755. if (Database::num_rows($result) > 0) {
  756. while ($myrow = Database::fetch_array($result)) {
  757. /*--------------------------------------------------
  758. display: the month bar
  759. --------------------------------------------------*/
  760. if ($month_bar != date("m", strtotime($myrow["date"])).date("Y", strtotime($myrow["date"]))) {
  761. $month_bar = date("m", strtotime($myrow["date"])).date("Y", strtotime($myrow["date"]));
  762. $content.= $MonthsLong[date("n", strtotime($myrow["date"])) - 1]." ".date("Y", strtotime($myrow["date"]));
  763. }
  764. // highlight: if a date in the small calendar is clicked we highlight the relevant items
  765. $db_date = (int) date("d", strtotime($myrow["date"])).date("n", strtotime($myrow["date"])).date("Y", strtotime($myrow["date"]));
  766. if ($_GET["day"].$_GET["month"].$_GET["year"] <> $db_date) {
  767. $style = "data";
  768. $text_style = "text";
  769. } else {
  770. $style = "datanow";
  771. $text_style = "text";
  772. }
  773. /*--------------------------------------------------
  774. display: date and time
  775. --------------------------------------------------*/
  776. // adding an internal anchor
  777. $content.= date("d", strtotime($myrow["date"]))." ".$MonthsLong[date("n", strtotime($myrow["date"])) - 1]." ".date("Y", strtotime($myrow["date"]))."&nbsp;";
  778. $content.= strftime(get_lang("timeNoSecFormat"), strtotime($myrow["date"]));
  779. $content.= '<br />';
  780. $content.= $myrow['title'];
  781. $content.= '<br />';
  782. return $content;
  783. }
  784. } else {
  785. return $content;
  786. }
  787. }
  788. /**
  789. * This function deletes a personal agenda item
  790. * There is an additional check to make sure that one cannot delete an item that
  791. * does not belong to him/her
  792. */
  793. function delete_personal_agenda($id) {
  794. $tbl_personal_agenda = Database :: get_user_personal_table(TABLE_PERSONAL_AGENDA);
  795. if ($id != strval(intval($id))) {
  796. return false; //potential SQL injection
  797. }
  798. if ($id <> '')
  799. {
  800. $sql = "SELECT * FROM ".$tbl_personal_agenda." WHERE user='".api_get_user_id()."' AND id='".$id."'";
  801. $result = Database::query($sql);
  802. $aantal = Database::num_rows($result);
  803. if ($aantal <> 0)
  804. {
  805. $sql = "DELETE FROM ".$tbl_personal_agenda." WHERE user='".api_get_user_id()."' AND id='".$id."'";
  806. $result = Database::query($sql);
  807. }
  808. }
  809. }
  810. /**
  811. * Get personal agenda items between two dates (=all events from all registered courses)
  812. * @param int user ID of the user
  813. * @param string Optional start date in datetime format (if no start date is given, uses today)
  814. * @param string Optional end date in datetime format (if no date is given, uses one year from now)
  815. * @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.
  816. * @TODO Implement really personal events (from user DB) and global events (from main DB)
  817. */
  818. function get_personal_agenda_items_between_dates($user_id, $date_start='', $date_end='') {
  819. $items = array ();
  820. if ($user_id != strval(intval($user_id))) { return $items; }
  821. if (empty($date_start)) { $date_start = date('Y-m-d H:i:s');}
  822. if (empty($date_end)) { $date_end = date('Y-m-d H:i:s',mktime(0, 0, 0, date("m"), date("d"), date("Y")+1));}
  823. $expr = '/\d{4}-\d{2}-\d{2}\ \d{2}:\d{2}:\d{2}/';
  824. if(!preg_match($expr,$date_start)) { return $items; }
  825. if(!preg_match($expr,$date_end)) { return $items; }
  826. // get agenda-items for every course
  827. $courses = api_get_user_courses($user_id,false);
  828. foreach ($courses as $id => $course)
  829. {
  830. $c = api_get_course_info($course['code']);
  831. //databases of the courses
  832. $t_a = Database :: get_course_table(TABLE_AGENDA, $course['db']);
  833. $t_ip = Database :: get_course_table(TABLE_ITEM_PROPERTY, $course['db']);
  834. // get the groups to which the user belong
  835. $group_memberships = GroupManager :: get_group_ids($course['db'], $user_id);
  836. // if the user is administrator of that course we show all the agenda items
  837. if ($course['status'] == '1') {
  838. //echo "course admin";
  839. $sqlquery = "SELECT ".
  840. " DISTINCT agenda.*, ip.visibility, ip.to_group_id, ip.insert_user_id, ip.ref ".
  841. " FROM ".$t_a." agenda, ".
  842. $t_ip." ip ".
  843. " WHERE agenda.id = ip.ref ".
  844. " AND agenda.start_date>='$date_start' ".
  845. " AND agenda.end_date<='$date_end' ".
  846. " AND ip.tool='".TOOL_CALENDAR_EVENT."' ".
  847. " AND ip.visibility='1' ".
  848. " GROUP BY agenda.id ".
  849. " ORDER BY start_date ";
  850. } else {
  851. // if the user is not an administrator of that course, then...
  852. if (is_array($group_memberships) && count($group_memberships)>0)
  853. {
  854. $sqlquery = "SELECT " .
  855. "DISTINCT agenda.*, ip.visibility, ip.to_group_id, ip.insert_user_id, ip.ref ".
  856. " FROM ".$t_a." agenda, ".
  857. $t_ip." ip ".
  858. " WHERE agenda.id = ip.ref ".
  859. " AND agenda.start_date>='$date_start' ".
  860. " AND agenda.end_date<='$date_end' ".
  861. " AND ip.tool='".TOOL_CALENDAR_EVENT."' ".
  862. " AND ( ip.to_user_id='".$user_id."' OR ip.to_group_id IN (0, ".implode(", ", $group_memberships).") ) ".
  863. " AND ip.visibility='1' ".
  864. " ORDER BY start_date ";
  865. } else {
  866. $sqlquery = "SELECT ".
  867. "DISTINCT agenda.*, ip.visibility, ip.to_group_id, ip.insert_user_id, ip.ref ".
  868. " FROM ".$t_a." agenda, ".
  869. $t_ip." ip ".
  870. " WHERE agenda.id = ip.ref ".
  871. " AND agenda.start_date>='$date_start' ".
  872. " AND agenda.end_date<='$date_end' ".
  873. " AND ip.tool='".TOOL_CALENDAR_EVENT."' ".
  874. " AND ( ip.to_user_id='".$user_id."' OR ip.to_group_id='0') ".
  875. " AND ip.visibility='1' ".
  876. " ORDER BY start_date ";
  877. }
  878. }
  879. $result = Database::query($sqlquery);
  880. while ($item = Database::fetch_array($result)) {
  881. $agendaday = date("j",strtotime($item['start_date']));
  882. $URL = api_get_path(WEB_PATH)."main/calendar/agenda.php?cidReq=".urlencode($course["code"])."&amp;day=$agendaday&amp;month=$month&amp;year=$year#$agendaday";
  883. list($year,$month,$day,$hour,$min,$sec) = split('[-: ]',$item['start_date']);
  884. $start_date = $year.$month.$day.$hour.$min;
  885. list($year,$month,$day,$hour,$min,$sec) = split('[-: ]',$item['end_date']);
  886. $end_date = $year.$month.$day.$hour.$min;
  887. $items[] = array(
  888. 'datestart'=>$start_date,
  889. 'dateend'=>$end_date,
  890. 'title'=>$item['title'],
  891. 'link'=>$URL,
  892. 'coursetitle'=>$c['name'],
  893. );
  894. }
  895. }
  896. return $items;
  897. }