myagenda.inc.php 41 KB

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