myagenda.inc.php 43 KB

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