myagenda.inc.php 42 KB

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