myagenda.inc.php 41 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004
  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 = intval($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. // adding an internal anchor
  778. $content.= date("d", strtotime($myrow["date"]))." ".$MonthsLong[date("n", strtotime($myrow["date"])) - 1]." ".date("Y", strtotime($myrow["date"]))."&nbsp;";
  779. $content.= strftime(get_lang("timeNoSecFormat"), strtotime($myrow["date"]));
  780. $content.= '<br />';
  781. $content.= $myrow['title'];
  782. $content.= '<br />';
  783. return $content;
  784. }
  785. } else {
  786. return $content;
  787. }
  788. }
  789. /**
  790. * This function deletes a personal agenda item
  791. * There is an additional check to make sure that one cannot delete an item that
  792. * does not belong to him/her
  793. */
  794. function delete_personal_agenda($id) {
  795. $tbl_personal_agenda = Database :: get_user_personal_table(TABLE_PERSONAL_AGENDA);
  796. if ($id != strval(intval($id))) {
  797. return false; //potential SQL injection
  798. }
  799. if ($id <> '')
  800. {
  801. $sql = "SELECT * FROM ".$tbl_personal_agenda." WHERE user='".api_get_user_id()."' AND id='".$id."'";
  802. $result = Database::query($sql);
  803. $aantal = Database::num_rows($result);
  804. if ($aantal <> 0)
  805. {
  806. $sql = "DELETE FROM ".$tbl_personal_agenda." WHERE user='".api_get_user_id()."' AND id='".$id."'";
  807. $result = Database::query($sql);
  808. }
  809. }
  810. }
  811. /**
  812. * Get personal agenda items between two dates (=all events from all registered courses)
  813. * @param int user ID of the user
  814. * @param string Optional start date in datetime format (if no start date is given, uses today)
  815. * @param string Optional end date in datetime format (if no date is given, uses one year from now)
  816. * @return array Array of events ordered by start date, in [0]('datestart','dateend','title'),[1]('datestart','dateend','title','link','coursetitle') format, where datestart and dateend are in yyyyMMddhhmmss format.
  817. * @TODO Implement really personal events (from user DB) and global events (from main DB)
  818. */
  819. function get_personal_agenda_items_between_dates($user_id, $date_start='', $date_end='') {
  820. $items = array ();
  821. if ($user_id != strval(intval($user_id))) { return $items; }
  822. if (empty($date_start)) { $date_start = date('Y-m-d H:i:s');}
  823. if (empty($date_end)) { $date_end = date('Y-m-d H:i:s',mktime(0, 0, 0, date("m"), date("d"), date("Y")+1));}
  824. $expr = '/\d{4}-\d{2}-\d{2}\ \d{2}:\d{2}:\d{2}/';
  825. if(!preg_match($expr,$date_start)) { return $items; }
  826. if(!preg_match($expr,$date_end)) { return $items; }
  827. // get agenda-items for every course
  828. $courses = api_get_user_courses($user_id,false);
  829. require_once(api_get_path(LIBRARY_PATH).'groupmanager.lib.php');
  830. foreach ($courses as $id => $course) {
  831. $c = api_get_course_info($course['code']);
  832. //databases of the courses
  833. $t_a = Database :: get_course_table(TABLE_AGENDA, $course['db']);
  834. $t_ip = Database :: get_course_table(TABLE_ITEM_PROPERTY, $course['db']);
  835. // get the groups to which the user belong
  836. $group_memberships = GroupManager :: get_group_ids($course['db'], $user_id);
  837. // if the user is administrator of that course we show all the agenda items
  838. if ($course['status'] == '1') {
  839. //echo "course admin";
  840. $sqlquery = "SELECT ".
  841. " DISTINCT agenda.*, ip.visibility, ip.to_group_id, ip.insert_user_id, ip.ref ".
  842. " FROM ".$t_a." agenda, ".
  843. $t_ip." ip ".
  844. " WHERE agenda.id = ip.ref ".
  845. " AND agenda.start_date>='$date_start' ".
  846. " AND agenda.end_date<='$date_end' ".
  847. " AND ip.tool='".TOOL_CALENDAR_EVENT."' ".
  848. " AND ip.visibility='1' ".
  849. " GROUP BY agenda.id ".
  850. " ORDER BY start_date ";
  851. } else {
  852. // if the user is not an administrator of that course, then...
  853. if (is_array($group_memberships) && count($group_memberships)>0)
  854. {
  855. $sqlquery = "SELECT " .
  856. "DISTINCT agenda.*, ip.visibility, ip.to_group_id, ip.insert_user_id, ip.ref ".
  857. " FROM ".$t_a." agenda, ".
  858. $t_ip." ip ".
  859. " WHERE agenda.id = ip.ref ".
  860. " AND agenda.start_date>='$date_start' ".
  861. " AND agenda.end_date<='$date_end' ".
  862. " AND ip.tool='".TOOL_CALENDAR_EVENT."' ".
  863. " AND ( ip.to_user_id='".$user_id."' OR ip.to_group_id IN (0, ".implode(", ", $group_memberships).") ) ".
  864. " AND ip.visibility='1' ".
  865. " ORDER BY start_date ";
  866. } else {
  867. $sqlquery = "SELECT ".
  868. "DISTINCT agenda.*, ip.visibility, ip.to_group_id, ip.insert_user_id, ip.ref ".
  869. " FROM ".$t_a." agenda, ".
  870. $t_ip." ip ".
  871. " WHERE agenda.id = ip.ref ".
  872. " AND agenda.start_date>='$date_start' ".
  873. " AND agenda.end_date<='$date_end' ".
  874. " AND ip.tool='".TOOL_CALENDAR_EVENT."' ".
  875. " AND ( ip.to_user_id='".$user_id."' OR ip.to_group_id='0') ".
  876. " AND ip.visibility='1' ".
  877. " ORDER BY start_date ";
  878. }
  879. }
  880. $result = Database::query($sqlquery);
  881. while ($item = Database::fetch_array($result)) {
  882. $agendaday = date("j",strtotime($item['start_date']));
  883. $month = date("n",strtotime($item['start_date']));
  884. $year = date("Y",strtotime($item['start_date']));
  885. $URL = api_get_path(WEB_PATH)."main/calendar/agenda.php?cidReq=".urlencode($course["code"])."&amp;day=$agendaday&amp;month=$month&amp;year=$year#$agendaday";
  886. list($year,$month,$day,$hour,$min,$sec) = split('[-: ]',$item['start_date']);
  887. $start_date = $year.$month.$day.$hour.$min;
  888. list($year,$month,$day,$hour,$min,$sec) = split('[-: ]',$item['end_date']);
  889. $end_date = $year.$month.$day.$hour.$min;
  890. $items[] = array(
  891. 'datestart'=>$start_date,
  892. 'dateend'=>$end_date,
  893. 'title'=>$item['title'],
  894. 'link'=>$URL,
  895. 'coursetitle'=>$c['name'],
  896. );
  897. }
  898. }
  899. return $items;
  900. }