myagenda.inc.php 41 KB

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