PageRenderTime 63ms CodeModel.GetById 24ms RepoModel.GetById 1ms app.codeStats 0ms

/calendar/lib.php

https://bitbucket.org/ceu/moodle_demo
PHP | 1610 lines | 1152 code | 202 blank | 256 comment | 454 complexity | b90d327afc6812811e13bc4e61495569 MD5 | raw file
Possible License(s): BSD-3-Clause, LGPL-2.0, LGPL-2.1

Large files files are truncated, but you can click here to view the full file

  1. <?php // $Id: lib.php,v 1.206.2.16 2012/05/11 14:18:36 moodlerobot Exp $
  2. /////////////////////////////////////////////////////////////////////////////
  3. // //
  4. // NOTICE OF COPYRIGHT //
  5. // //
  6. // Moodle - Calendar extension //
  7. // //
  8. // Copyright (C) 2003-2004 Greek School Network www.sch.gr //
  9. // //
  10. // Designed by: //
  11. // Avgoustos Tsinakos (tsinakos@teikav.edu.gr) //
  12. // Jon Papaioannou (pj@moodle.org) //
  13. // //
  14. // Programming and development: //
  15. // Jon Papaioannou (pj@moodle.org) //
  16. // //
  17. // For bugs, suggestions, etc contact: //
  18. // Jon Papaioannou (pj@moodle.org) //
  19. // //
  20. // The current module was developed at the University of Macedonia //
  21. // (www.uom.gr) under the funding of the Greek School Network (www.sch.gr) //
  22. // The aim of this project is to provide additional and improved //
  23. // functionality to the Asynchronous Distance Education service that the //
  24. // Greek School Network deploys. //
  25. // //
  26. // This program is free software; you can redistribute it and/or modify //
  27. // it under the terms of the GNU General Public License as published by //
  28. // the Free Software Foundation; either version 2 of the License, or //
  29. // (at your option) any later version. //
  30. // //
  31. // This program is distributed in the hope that it will be useful, //
  32. // but WITHOUT ANY WARRANTY; without even the implied warranty of //
  33. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
  34. // GNU General Public License for more details: //
  35. // //
  36. // http://www.gnu.org/copyleft/gpl.html //
  37. // //
  38. /////////////////////////////////////////////////////////////////////////////
  39. // These are read by the administration component to provide default values
  40. define('CALENDAR_DEFAULT_UPCOMING_LOOKAHEAD', 21);
  41. define('CALENDAR_DEFAULT_UPCOMING_MAXEVENTS', 10);
  42. define('CALENDAR_DEFAULT_STARTING_WEEKDAY', 1);
  43. // This is a packed bitfield: day X is "weekend" if $field & (1 << X) is true
  44. // Default value = 65 = 64 + 1 = 2^6 + 2^0 = Saturday & Sunday
  45. define('CALENDAR_DEFAULT_WEEKEND', 65);
  46. // Fetch the correct values from admin settings/lang pack
  47. // If no such settings found, use the above defaults
  48. $firstday = isset($CFG->calendar_startwday) ? $CFG->calendar_startwday : get_string('firstdayofweek');
  49. if(!is_numeric($firstday)) {
  50. define ('CALENDAR_STARTING_WEEKDAY', CALENDAR_DEFAULT_STARTING_WEEKDAY);
  51. }
  52. else {
  53. define ('CALENDAR_STARTING_WEEKDAY', intval($firstday) % 7);
  54. }
  55. define ('CALENDAR_UPCOMING_DAYS', isset($CFG->calendar_lookahead) ? intval($CFG->calendar_lookahead) : CALENDAR_DEFAULT_UPCOMING_LOOKAHEAD);
  56. define ('CALENDAR_UPCOMING_MAXEVENTS', isset($CFG->calendar_maxevents) ? intval($CFG->calendar_maxevents) : CALENDAR_DEFAULT_UPCOMING_MAXEVENTS);
  57. define ('CALENDAR_WEEKEND', isset($CFG->calendar_weekend) ? intval($CFG->calendar_weekend) : CALENDAR_DEFAULT_WEEKEND);
  58. define ('CALENDAR_URL', $CFG->wwwroot.'/calendar/');
  59. define ('CALENDAR_TF_24', '%H:%M');
  60. define ('CALENDAR_TF_12', '%I:%M %p');
  61. $CALENDARDAYS = array('sunday','monday','tuesday','wednesday','thursday','friday','saturday');
  62. function calendar_get_mini($courses, $groups, $users, $cal_month = false, $cal_year = false) {
  63. global $CFG, $USER;
  64. $display = new stdClass;
  65. $display->minwday = get_user_preferences('calendar_startwday', CALENDAR_STARTING_WEEKDAY);
  66. $display->maxwday = $display->minwday + 6;
  67. $content = '';
  68. if(!empty($cal_month) && !empty($cal_year)) {
  69. $thisdate = usergetdate(time()); // Date and time the user sees at his location
  70. if($cal_month == $thisdate['mon'] && $cal_year == $thisdate['year']) {
  71. // Navigated to this month
  72. $date = $thisdate;
  73. $display->thismonth = true;
  74. }
  75. else {
  76. // Navigated to other month, let's do a nice trick and save us a lot of work...
  77. if(!checkdate($cal_month, 1, $cal_year)) {
  78. $date = array('mday' => 1, 'mon' => $thisdate['mon'], 'year' => $thisdate['year']);
  79. $display->thismonth = true;
  80. }
  81. else {
  82. $date = array('mday' => 1, 'mon' => $cal_month, 'year' => $cal_year);
  83. $display->thismonth = false;
  84. }
  85. }
  86. }
  87. else {
  88. $date = usergetdate(time()); // Date and time the user sees at his location
  89. $display->thismonth = true;
  90. }
  91. // Fill in the variables we 're going to use, nice and tidy
  92. list($d, $m, $y) = array($date['mday'], $date['mon'], $date['year']); // This is what we want to display
  93. $display->maxdays = calendar_days_in_month($m, $y);
  94. if (get_user_timezone_offset() < 99) {
  95. // We 'll keep these values as GMT here, and offset them when the time comes to query the db
  96. $display->tstart = gmmktime(0, 0, 0, $m, 1, $y); // This is GMT
  97. $display->tend = gmmktime(23, 59, 59, $m, $display->maxdays, $y); // GMT
  98. } else {
  99. // no timezone info specified
  100. $display->tstart = mktime(0, 0, 0, $m, 1, $y);
  101. $display->tend = mktime(23, 59, 59, $m, $display->maxdays, $y);
  102. }
  103. $startwday = dayofweek(1, $m, $y);
  104. // Align the starting weekday to fall in our display range
  105. // This is simple, not foolproof.
  106. if($startwday < $display->minwday) {
  107. $startwday += 7;
  108. }
  109. // TODO: THIS IS TEMPORARY CODE!
  110. // [pj] I was just reading through this and realized that I when writing this code I was probably
  111. // asking for trouble, as all these time manipulations seem to be unnecessary and a simple
  112. // make_timestamp would accomplish the same thing. So here goes a test:
  113. //$test_start = make_timestamp($y, $m, 1);
  114. //$test_end = make_timestamp($y, $m, $display->maxdays, 23, 59, 59);
  115. //if($test_start != usertime($display->tstart) - dst_offset_on($display->tstart)) {
  116. //notify('Failed assertion in calendar/lib.php line 126; display->tstart = '.$display->tstart.', dst_offset = '.dst_offset_on($display->tstart).', usertime = '.usertime($display->tstart).', make_t = '.$test_start);
  117. //}
  118. //if($test_end != usertime($display->tend) - dst_offset_on($display->tend)) {
  119. //notify('Failed assertion in calendar/lib.php line 130; display->tend = '.$display->tend.', dst_offset = '.dst_offset_on($display->tend).', usertime = '.usertime($display->tend).', make_t = '.$test_end);
  120. //}
  121. // Get the events matching our criteria. Don't forget to offset the timestamps for the user's TZ!
  122. $events = calendar_get_events(
  123. usertime($display->tstart) - dst_offset_on($display->tstart),
  124. usertime($display->tend) - dst_offset_on($display->tend),
  125. $users, $groups, $courses);
  126. // Set event course class for course events
  127. if (!empty($events)) {
  128. foreach ($events as $eventid => $event) {
  129. if (!empty($event->modulename)) {
  130. $cm = get_coursemodule_from_instance($event->modulename, $event->instance);
  131. if (!groups_course_module_visible($cm)) {
  132. unset($events[$eventid]);
  133. }
  134. }
  135. }
  136. }
  137. // This is either a genius idea or an idiot idea: in order to not complicate things, we use this rule: if, after
  138. // possibly removing SITEID from $courses, there is only one course left, then clicking on a day in the month
  139. // will also set the $SESSION->cal_courses_shown variable to that one course. Otherwise, we 'd need to add extra
  140. // arguments to this function.
  141. $morehref = '';
  142. if(!empty($courses)) {
  143. $courses = array_diff($courses, array(SITEID));
  144. if(count($courses) == 1) {
  145. $morehref = '&amp;course='.reset($courses);
  146. }
  147. }
  148. // We want to have easy access by day, since the display is on a per-day basis.
  149. // Arguments passed by reference.
  150. //calendar_events_by_day($events, $display->tstart, $eventsbyday, $durationbyday, $typesbyday);
  151. calendar_events_by_day($events, $m, $y, $eventsbyday, $durationbyday, $typesbyday, $courses);
  152. //Accessibility: added summary and <abbr> elements.
  153. ///global $CALENDARDAYS; appears to be broken.
  154. $days_title = array('sunday','monday','tuesday','wednesday','thursday','friday','saturday');
  155. $summary = get_string('calendarheading', 'calendar', userdate(make_timestamp($y, $m), get_string('strftimemonthyear')));
  156. $summary = get_string('tabledata', 'access', $summary);
  157. $content .= '<table class="minicalendar" summary="'.$summary.'">'; // Begin table
  158. $content .= '<tr class="weekdays">'; // Header row: day names
  159. // Print out the names of the weekdays
  160. $days = array('sun', 'mon', 'tue', 'wed', 'thu', 'fri', 'sat');
  161. for($i = $display->minwday; $i <= $display->maxwday; ++$i) {
  162. // This uses the % operator to get the correct weekday no matter what shift we have
  163. // applied to the $display->minwday : $display->maxwday range from the default 0 : 6
  164. $content .= '<th scope="col"><abbr title="'. get_string($days_title[$i % 7], 'calendar') .'">'.
  165. get_string($days[$i % 7], 'calendar') ."</abbr></th>\n";
  166. }
  167. $content .= '</tr><tr>'; // End of day names; prepare for day numbers
  168. // For the table display. $week is the row; $dayweek is the column.
  169. $dayweek = $startwday;
  170. // Paddding (the first week may have blank days in the beginning)
  171. for($i = $display->minwday; $i < $startwday; ++$i) {
  172. $content .= '<td class="dayblank">&nbsp;</td>'."\n";
  173. }
  174. // Now display all the calendar
  175. for($day = 1; $day <= $display->maxdays; ++$day, ++$dayweek) {
  176. if($dayweek > $display->maxwday) {
  177. // We need to change week (table row)
  178. $content .= '</tr><tr>';
  179. $dayweek = $display->minwday;
  180. }
  181. // Reset vars
  182. $cell = '';
  183. if(CALENDAR_WEEKEND & (1 << ($dayweek % 7))) {
  184. // Weekend. This is true no matter what the exact range is.
  185. $class = 'weekend day';
  186. }
  187. else {
  188. // Normal working day.
  189. $class = 'day';
  190. }
  191. // Special visual fx if an event is defined
  192. if(isset($eventsbyday[$day])) {
  193. $dayhref = calendar_get_link_href(CALENDAR_URL.'view.php?view=day'.$morehref.'&amp;', $day, $m, $y);
  194. // OverLib popup
  195. $popupcontent = '';
  196. foreach($eventsbyday[$day] as $eventid) {
  197. if (!isset($events[$eventid])) {
  198. continue;
  199. }
  200. $event = $events[$eventid];
  201. if(!empty($event->modulename)) {
  202. $popupicon = $CFG->modpixpath.'/'.$event->modulename.'/icon.gif';
  203. $popupalt = $event->modulename;
  204. } else if ($event->courseid == SITEID) { // Site event
  205. $popupicon = $CFG->pixpath.'/c/site.gif';
  206. $popupalt = '';
  207. } else if ($event->courseid != 0 && $event->courseid != SITEID && $event->groupid == 0) { // Course event
  208. $popupicon = $CFG->pixpath.'/c/course.gif';
  209. $popupalt = '';
  210. } else if ($event->groupid) { // Group event
  211. $popupicon = $CFG->pixpath.'/c/group.gif';
  212. $popupalt = '';
  213. } else if ($event->userid) { // User event
  214. $popupicon = $CFG->pixpath.'/c/user.gif';
  215. $popupalt = '';
  216. }
  217. $popupcontent .= '<div><img class="icon" src="'.$popupicon.'" alt="'.$popupalt.'" /><a href="'.$dayhref.'#event_'.$event->id.'">'.format_string($event->name, true).'</a></div>';
  218. }
  219. //Accessibility: functionality moved to calendar_get_popup.
  220. if($display->thismonth && $day == $d) {
  221. $popup = calendar_get_popup(true, $events[$eventid]->timestart, $popupcontent);
  222. } else {
  223. $popup = calendar_get_popup(false, $events[$eventid]->timestart, $popupcontent);
  224. }
  225. // Class and cell content
  226. if(isset($typesbyday[$day]['startglobal'])) {
  227. $class .= ' event_global';
  228. }
  229. else if(isset($typesbyday[$day]['startcourse'])) {
  230. $class .= ' event_course';
  231. }
  232. else if(isset($typesbyday[$day]['startgroup'])) {
  233. $class .= ' event_group';
  234. }
  235. else if(isset($typesbyday[$day]['startuser'])) {
  236. $class .= ' event_user';
  237. }
  238. $cell = '<a href="'.$dayhref.'" '.$popup.'>'.$day.'</a>';
  239. }
  240. else {
  241. $cell = $day;
  242. }
  243. if(isset($typesbyday[$day]['durationglobal'])) {
  244. $class .= ' duration_global';
  245. }
  246. else if(isset($typesbyday[$day]['durationcourse'])) {
  247. $class .= ' duration_course';
  248. }
  249. else if(isset($typesbyday[$day]['durationgroup'])) {
  250. $class .= ' duration_group';
  251. }
  252. else if(isset($typesbyday[$day]['durationuser'])) {
  253. $class .= ' duration_user';
  254. }
  255. // If event has a class set then add it to the table day <td> tag
  256. // Note: only one colour for minicalendar
  257. if(isset($eventsbyday[$day])) {
  258. foreach($eventsbyday[$day] as $eventid) {
  259. if (!isset($events[$eventid])) {
  260. continue;
  261. }
  262. $event = $events[$eventid];
  263. if (!empty($event->class)) {
  264. $class .= ' '.$event->class;
  265. }
  266. break;
  267. }
  268. }
  269. // Special visual fx for today
  270. //Accessibility: hidden text for today, and popup.
  271. if($display->thismonth && $day == $d) {
  272. $class .= ' today';
  273. $today = get_string('today', 'calendar').' '.userdate(time(), get_string('strftimedayshort'));
  274. if(! isset($eventsbyday[$day])) {
  275. $class .= ' eventnone';
  276. $popup = calendar_get_popup(true, false);
  277. $cell = '<a href="#" '.$popup.'>'.$day.'</a>';
  278. }
  279. $cell = get_accesshide($today.' ').$cell;
  280. }
  281. // Just display it
  282. if(!empty($class)) {
  283. $class = ' class="'.$class.'"';
  284. }
  285. $content .= '<td'.$class.'>'.$cell."</td>\n";
  286. }
  287. // Paddding (the last week may have blank days at the end)
  288. for($i = $dayweek; $i <= $display->maxwday; ++$i) {
  289. $content .= '<td class="dayblank">&nbsp;</td>';
  290. }
  291. $content .= '</tr>'; // Last row ends
  292. $content .= '</table>'; // Tabular display of days ends
  293. return $content;
  294. }
  295. /**
  296. * calendar_get_popup, called at multiple points in from calendar_get_mini.
  297. * Copied and modified from calendar_get_mini.
  298. * @uses OverLib popup.
  299. * @param $is_today bool, false except when called on the current day.
  300. * @param $event_timestart mixed, $events[$eventid]->timestart, OR false if there are no events.
  301. * @param $popupcontent string.
  302. * @return $popup string, contains onmousover and onmouseout events.
  303. */
  304. function calendar_get_popup($is_today, $event_timestart, $popupcontent='') {
  305. $popupcaption = '';
  306. if($is_today) {
  307. $popupcaption = get_string('today', 'calendar').' ';
  308. }
  309. if (false === $event_timestart) {
  310. $popupcaption .= userdate(time(), get_string('strftimedayshort'));
  311. $popupcontent = get_string('eventnone', 'calendar');
  312. } else {
  313. $popupcaption .= get_string('eventsfor', 'calendar', userdate($event_timestart, get_string('strftimedayshort')));
  314. }
  315. $popupcontent = str_replace("'", "\'", htmlspecialchars($popupcontent));
  316. $popupcaption = str_replace("'", "\'", htmlspecialchars($popupcaption));
  317. $popup = 'onmouseover="return overlib(\''.$popupcontent.'\', CAPTION, \''.$popupcaption.'\');" onmouseout="return nd();"';
  318. return $popup;
  319. }
  320. function calendar_get_upcoming($courses, $groups, $users, $daysinfuture, $maxevents, $fromtime=0) {
  321. global $CFG, $COURSE;
  322. $display = new stdClass;
  323. $display->range = $daysinfuture; // How many days in the future we 'll look
  324. $display->maxevents = $maxevents;
  325. $output = array();
  326. // Prepare "course caching", since it may save us a lot of queries
  327. $coursecache = array();
  328. $processed = 0;
  329. $now = time(); // We 'll need this later
  330. $usermidnighttoday = usergetmidnight($now);
  331. if ($fromtime) {
  332. $display->tstart = $fromtime;
  333. } else {
  334. $display->tstart = $usermidnighttoday;
  335. }
  336. // This works correctly with respect to the user's DST, but it is accurate
  337. // only because $fromtime is always the exact midnight of some day!
  338. $display->tend = usergetmidnight($display->tstart + DAYSECS * $display->range + 3 * HOURSECS) - 1;
  339. // Get the events matching our criteria
  340. $events = calendar_get_events($display->tstart, $display->tend, $users, $groups, $courses);
  341. // This is either a genius idea or an idiot idea: in order to not complicate things, we use this rule: if, after
  342. // possibly removing SITEID from $courses, there is only one course left, then clicking on a day in the month
  343. // will also set the $SESSION->cal_courses_shown variable to that one course. Otherwise, we 'd need to add extra
  344. // arguments to this function.
  345. $morehref = '';
  346. if(!empty($courses)) {
  347. $courses = array_diff($courses, array(SITEID));
  348. if(count($courses) == 1) {
  349. $morehref = '&amp;course='.reset($courses);
  350. }
  351. }
  352. if ($events !== false) {
  353. $modinfo =& get_fast_modinfo($COURSE);
  354. foreach($events as $event) {
  355. if (!empty($event->modulename)) {
  356. if ($event->courseid == $COURSE->id) {
  357. if (isset($modinfo->instances[$event->modulename][$event->instance])) {
  358. $cm = $modinfo->instances[$event->modulename][$event->instance];
  359. if (!$cm->uservisible) {
  360. continue;
  361. }
  362. }
  363. } else {
  364. if (!$cm = get_coursemodule_from_instance($event->modulename, $event->instance)) {
  365. continue;
  366. }
  367. if (!coursemodule_visible_for_user($cm)) {
  368. continue;
  369. }
  370. }
  371. if ($event->modulename == 'assignment'){
  372. // TODO: rewrite this hack somehow
  373. if (!calendar_edit_event_allowed($event)){ // cannot manage entries, eg. student
  374. if(!$assignment = get_record('assignment','id',$event->instance)){
  375. // error("assignment ID was incorrect");
  376. continue;
  377. }
  378. // assign assignment to assignment object to use hidden_is_hidden method
  379. require_once($CFG->dirroot.'/mod/assignment/lib.php');
  380. if (!file_exists($CFG->dirroot.'/mod/assignment/type/'.$assignment->assignmenttype.'/assignment.class.php')) {
  381. continue;
  382. }
  383. require_once ($CFG->dirroot.'/mod/assignment/type/'.$assignment->assignmenttype.'/assignment.class.php');
  384. $assignmentclass = 'assignment_'.$assignment->assignmenttype;
  385. $assignmentinstance = new $assignmentclass($cm->id, $assignment, $cm);
  386. if ($assignmentinstance->description_is_hidden()){//force not to show description before availability
  387. $event->description = get_string('notavailableyet', 'assignment');
  388. }
  389. }
  390. }
  391. }
  392. if ($processed >= $display->maxevents) {
  393. break;
  394. }
  395. $event->time = calendar_format_event_time($event, $now, $morehref);
  396. $output[] = $event;
  397. ++$processed;
  398. }
  399. }
  400. return $output;
  401. }
  402. function calendar_add_event_metadata($event) {
  403. global $CFG;
  404. //Support multilang in event->name
  405. $event->name = format_string($event->name,true);
  406. if(!empty($event->modulename)) { // Activity event
  407. // The module name is set. I will assume that it has to be displayed, and
  408. // also that it is an automatically-generated event. And of course that the
  409. // fields for get_coursemodule_from_instance are set correctly.
  410. $module = calendar_get_module_cached($coursecache, $event->modulename, $event->instance);
  411. if ($module === false) {
  412. return;
  413. }
  414. $modulename = get_string('modulename', $event->modulename);
  415. $eventtype = get_string($event->eventtype, $event->modulename);
  416. $icon = $CFG->modpixpath.'/'.$event->modulename.'/icon.gif';
  417. $event->icon = '<img height="16" width="16" src="'.$icon.'" alt="'.$eventtype.'" title="'.$modulename.'" style="vertical-align: middle;" />';
  418. $event->referer = '<a href="'.$CFG->wwwroot.'/mod/'.$event->modulename.'/view.php?id='.$module->id.'">'.$event->name.'</a>';
  419. $event->courselink = '<a href="'.$CFG->wwwroot.'/course/view.php?id='.$module->course.'">'.$coursecache[$module->course]->fullname.'</a>';
  420. $event->cmid = $module->id;
  421. } else if($event->courseid == SITEID) { // Site event
  422. $event->icon = '<img height="16" width="16" src="'.$CFG->pixpath.'/c/site.gif" alt="'.get_string('globalevent', 'calendar').'" style="vertical-align: middle;" />';
  423. $event->cssclass = 'event_global';
  424. } else if($event->courseid != 0 && $event->courseid != SITEID && $event->groupid == 0) { // Course event
  425. calendar_get_course_cached($coursecache, $event->courseid);
  426. $event->icon = '<img height="16" width="16" src="'.$CFG->pixpath.'/c/course.gif" alt="'.get_string('courseevent', 'calendar').'" style="vertical-align: middle;" />';
  427. $event->courselink = '<a href="'.$CFG->wwwroot.'/course/view.php?id='.$event->courseid.'">'.$coursecache[$event->courseid]->fullname.'</a>';
  428. $event->cssclass = 'event_course';
  429. } else if ($event->groupid) { // Group event
  430. $event->icon = '<img height="16" width="16" src="'.$CFG->pixpath.'/c/group.gif" alt="'.get_string('groupevent', 'calendar').'" style="vertical-align: middle;" />';
  431. $event->cssclass = 'event_group';
  432. } else if($event->userid) { // User event
  433. $event->icon = '<img height="16" width="16" src="'.$CFG->pixpath.'/c/user.gif" alt="'.get_string('userevent', 'calendar').'" style="vertical-align: middle;" />';
  434. $event->cssclass = 'event_user';
  435. }
  436. return $event;
  437. }
  438. function calendar_print_event($event) {
  439. global $CFG, $USER;
  440. static $strftimetime;
  441. $event = calendar_add_event_metadata($event);
  442. echo '<a name="event_'.$event->id.'"></a><table class="event" cellspacing="0">';
  443. echo '<tr><td class="picture">';
  444. if (!empty($event->icon)) {
  445. echo $event->icon;
  446. } else {
  447. print_spacer(16,16);
  448. }
  449. echo '</td>';
  450. echo '<td class="topic">';
  451. if (!empty($event->referer)) {
  452. echo '<div class="referer">'.$event->referer.'</div>';
  453. } else {
  454. echo '<div class="name">'.$event->name."</div>";
  455. }
  456. if (!empty($event->courselink)) {
  457. echo '<div class="course">'.$event->courselink.' </div>';
  458. }
  459. if (!empty($event->time)) {
  460. echo '<span class="date">'.$event->time.'</span>';
  461. } else {
  462. echo '<span class="date">'.calendar_time_representation($event->timestart).'</span>';
  463. }
  464. echo '</td></tr>';
  465. echo '<tr><td class="side">&nbsp;</td>';
  466. if (isset($event->cssclass)) {
  467. echo '<td class="description '.$event->cssclass.'">';
  468. } else {
  469. echo '<td class="description">';
  470. }
  471. echo format_text($event->description, FORMAT_HTML);
  472. if (calendar_edit_event_allowed($event)) {
  473. echo '<div class="commands">';
  474. $calendarcourseid = '';
  475. if (!empty($event->calendarcourseid)) {
  476. $calendarcourseid = '&amp;course='.$event->calendarcourseid;
  477. }
  478. if (empty($event->cmid)) {
  479. $editlink = CALENDAR_URL.'event.php?action=edit&amp;id='.$event->id.$calendarcourseid;
  480. $deletelink = CALENDAR_URL.'event.php?action=delete&amp;id='.$event->id.$calendarcourseid;
  481. } else {
  482. $editlink = $CFG->wwwroot.'/course/mod.php?update='.$event->cmid.'&amp;return=true&amp;sesskey='.$USER->sesskey;
  483. $deletelink = ''; // deleting activities directly from calendar is dangerous/confusing - see MDL-11843
  484. }
  485. echo ' <a href="'.$editlink.'"><img
  486. src="'.$CFG->pixpath.'/t/edit.gif" alt="'.get_string('tt_editevent', 'calendar').'"
  487. title="'.get_string('tt_editevent', 'calendar').'" /></a>';
  488. if ($deletelink) {
  489. echo ' <a href="'.$deletelink.'"><img
  490. src="'.$CFG->pixpath.'/t/delete.gif" alt="'.get_string('tt_deleteevent', 'calendar').'"
  491. title="'.get_string('tt_deleteevent', 'calendar').'" /></a>';
  492. }
  493. echo '</div>';
  494. }
  495. echo '</td></tr></table>';
  496. }
  497. /**
  498. * Get calendar events
  499. * @param int $tstart Start time of time range for events
  500. * @param int $tend End time of time range for events
  501. * @param array/int/boolean $users array of users, user id or boolean for all/no user events
  502. * @param array/int/boolean $groups array of groups, group id or boolean for all/no group events
  503. * @param array/int/boolean $courses array of courses, course id or boolean for all/no course events
  504. * @param boolean $withduration whether only events starting within time range selected
  505. * or events in progress/already started selected as well
  506. * @param boolean $ignorehidden whether to select only visible events or all events
  507. * @return array of selected events or an empty array if there aren't any (or there was an error)
  508. */
  509. function calendar_get_events($tstart, $tend, $users, $groups, $courses, $withduration=true, $ignorehidden=true) {
  510. $whereclause = '';
  511. // Quick test
  512. if(is_bool($users) && is_bool($groups) && is_bool($courses)) {
  513. return array();
  514. }
  515. if(is_array($users) && !empty($users)) {
  516. // Events from a number of users
  517. if(!empty($whereclause)) $whereclause .= ' OR';
  518. $whereclause .= ' (userid IN ('.implode(',', $users).') AND courseid = 0 AND groupid = 0)';
  519. }
  520. else if(is_numeric($users)) {
  521. // Events from one user
  522. if(!empty($whereclause)) $whereclause .= ' OR';
  523. $whereclause .= ' (userid = '.$users.' AND courseid = 0 AND groupid = 0)';
  524. }
  525. else if($users === true) {
  526. // Events from ALL users
  527. if(!empty($whereclause)) $whereclause .= ' OR';
  528. $whereclause .= ' (userid != 0 AND courseid = 0 AND groupid = 0)';
  529. }
  530. else if($users === false) {
  531. // No user at all, do nothing
  532. }
  533. if(is_array($groups) && !empty($groups)) {
  534. // Events from a number of groups
  535. if(!empty($whereclause)) $whereclause .= ' OR';
  536. $whereclause .= ' groupid IN ('.implode(',', $groups).')';
  537. }
  538. else if(is_numeric($groups)) {
  539. // Events from one group
  540. if(!empty($whereclause)) $whereclause .= ' OR ';
  541. $whereclause .= ' groupid = '.$groups;
  542. }
  543. else if($groups === true) {
  544. // Events from ALL groups
  545. if(!empty($whereclause)) $whereclause .= ' OR ';
  546. $whereclause .= ' groupid != 0';
  547. }
  548. // boolean false (no groups at all): we don't need to do anything
  549. if(is_array($courses)) {
  550. // A number of courses (maybe none at all!)
  551. if(!empty($courses)) {
  552. if(!empty($whereclause)) {
  553. $whereclause .= ' OR';
  554. }
  555. $whereclause .= ' (groupid = 0 AND courseid IN ('.implode(',', $courses).'))';
  556. }
  557. else {
  558. // This means NO courses, not that we don't care!
  559. // No need to do anything
  560. }
  561. }
  562. else if(is_numeric($courses)) {
  563. // One course
  564. if(!empty($whereclause)) $whereclause .= ' OR';
  565. $whereclause .= ' (groupid = 0 AND courseid = '.$courses.')';
  566. }
  567. else if($courses === true) {
  568. // Events from ALL courses
  569. if(!empty($whereclause)) $whereclause .= ' OR';
  570. $whereclause .= ' (groupid = 0 AND courseid != 0)';
  571. }
  572. // Security check: if, by now, we have NOTHING in $whereclause, then it means
  573. // that NO event-selecting clauses were defined. Thus, we won't be returning ANY
  574. // events no matter what. Allowing the code to proceed might return a completely
  575. // valid query with only time constraints, thus selecting ALL events in that time frame!
  576. if(empty($whereclause)) {
  577. return array();
  578. }
  579. if($withduration) {
  580. $timeclause = '(timestart >= '.$tstart.' OR timestart + timeduration > '.$tstart.') AND timestart <= '.$tend;
  581. }
  582. else {
  583. $timeclause = 'timestart >= '.$tstart.' AND timestart <= '.$tend;
  584. }
  585. if(!empty($whereclause)) {
  586. // We have additional constraints
  587. $whereclause = $timeclause.' AND ('.$whereclause.')';
  588. }
  589. else {
  590. // Just basic time filtering
  591. $whereclause = $timeclause;
  592. }
  593. if ($ignorehidden) {
  594. $whereclause .= ' AND visible = 1';
  595. }
  596. $events = get_records_select('event', $whereclause, 'timestart');
  597. if ($events === false) {
  598. $events = array();
  599. }
  600. return $events;
  601. }
  602. function calendar_top_controls($type, $data) {
  603. global $CFG, $CALENDARDAYS, $THEME;
  604. $content = '';
  605. if(!isset($data['d'])) {
  606. $data['d'] = 1;
  607. }
  608. // Ensure course id passed if relevant
  609. // Required due to changes in view/lib.php mainly (calendar_session_vars())
  610. $courseid = '';
  611. if (!empty($data['id'])) {
  612. $courseid = '&amp;course='.$data['id'];
  613. }
  614. if(!checkdate($data['m'], $data['d'], $data['y'])) {
  615. $time = time();
  616. }
  617. else {
  618. $time = make_timestamp($data['y'], $data['m'], $data['d']);
  619. }
  620. $date = usergetdate($time);
  621. $data['m'] = $date['mon'];
  622. $data['y'] = $date['year'];
  623. //Accessibility: calendar block controls, replaced <table> with <div>.
  624. //$nexttext = link_arrow_right(get_string('monthnext', 'access'), $url='', $accesshide=true);
  625. //$prevtext = link_arrow_left(get_string('monthprev', 'access'), $url='', $accesshide=true);
  626. switch($type) {
  627. case 'frontpage':
  628. list($prevmonth, $prevyear) = calendar_sub_month($data['m'], $data['y']);
  629. list($nextmonth, $nextyear) = calendar_add_month($data['m'], $data['y']);
  630. $nextlink = calendar_get_link_next(get_string('monthnext', 'access'), 'index.php?', 0, $nextmonth, $nextyear, $accesshide=true);
  631. $prevlink = calendar_get_link_previous(get_string('monthprev', 'access'), 'index.php?', 0, $prevmonth, $prevyear, true);
  632. $content .= "\n".'<div class="calendar-controls">'. $prevlink;
  633. $content .= '<span class="hide"> | </span><span class="current"><a href="'.calendar_get_link_href(CALENDAR_URL.'view.php?view=month'.$courseid.'&amp;', 1, $data['m'], $data['y']).'">'.userdate($time, get_string('strftimemonthyear')).'</a></span>';
  634. $content .= '<span class="hide"> | </span>'. $nextlink ."\n";
  635. $content .= "<span class=\"clearer\"><!-- --></span></div>\n";
  636. break;
  637. case 'course':
  638. list($prevmonth, $prevyear) = calendar_sub_month($data['m'], $data['y']);
  639. list($nextmonth, $nextyear) = calendar_add_month($data['m'], $data['y']);
  640. $nextlink = calendar_get_link_next(get_string('monthnext', 'access'), 'view.php?id='.$data['id'].'&amp;', 0, $nextmonth, $nextyear, $accesshide=true);
  641. $prevlink = calendar_get_link_previous(get_string('monthprev', 'access'), 'view.php?id='.$data['id'].'&amp;', 0, $prevmonth, $prevyear, true);
  642. $content .= "\n".'<div class="calendar-controls">'. $prevlink;
  643. $content .= '<span class="hide"> | </span><span class="current"><a href="'.calendar_get_link_href(CALENDAR_URL.'view.php?view=month'.$courseid.'&amp;', 1, $data['m'], $data['y']).'">'.userdate($time, get_string('strftimemonthyear')).'</a></span>';
  644. $content .= '<span class="hide"> | </span>'. $nextlink ."\n";
  645. $content .= "<span class=\"clearer\"><!-- --></span></div>\n";
  646. break;
  647. case 'upcoming':
  648. $content .= '<div style="text-align: center;"><a href="'.CALENDAR_URL.'view.php?view=upcoming"'.$courseid.'>'.userdate($time, get_string('strftimemonthyear'))."</a></div>\n";
  649. break;
  650. case 'display':
  651. $content .= '<div style="text-align: center;"><a href="'.calendar_get_link_href(CALENDAR_URL.'view.php?view=month'.$courseid.'&amp;', 1, $data['m'], $data['y']).'">'.userdate($time, get_string('strftimemonthyear'))."</a></div>\n";
  652. break;
  653. case 'month':
  654. list($prevmonth, $prevyear) = calendar_sub_month($data['m'], $data['y']);
  655. list($nextmonth, $nextyear) = calendar_add_month($data['m'], $data['y']);
  656. $prevdate = make_timestamp($prevyear, $prevmonth, 1);
  657. $nextdate = make_timestamp($nextyear, $nextmonth, 1);
  658. $content .= "\n".'<div class="calendar-controls">';
  659. $content .= calendar_get_link_previous(userdate($prevdate, get_string('strftimemonthyear')), 'view.php?view=month'.$courseid.'&amp;', 1, $prevmonth, $prevyear);
  660. $content .= '<span class="hide"> | </span><span class="current">'.userdate($time, get_string('strftimemonthyear'))."</span>\n";
  661. $content .= '<span class="hide"> | </span>'.calendar_get_link_next(userdate($nextdate, get_string('strftimemonthyear')), 'view.php?view=month'.$courseid.'&amp;', 1, $nextmonth, $nextyear);
  662. $content .= "<span class=\"clearer\"><!-- --></span></div>\n";
  663. break;
  664. case 'day':
  665. $data['d'] = $date['mday']; // Just for convenience
  666. $prevdate = usergetdate(make_timestamp($data['y'], $data['m'], $data['d'] - 1));
  667. $nextdate = usergetdate(make_timestamp($data['y'], $data['m'], $data['d'] + 1));
  668. $prevname = calendar_wday_name($CALENDARDAYS[$prevdate['wday']]);
  669. $nextname = calendar_wday_name($CALENDARDAYS[$nextdate['wday']]);
  670. $content .= "\n".'<div class="calendar-controls">';
  671. $content .= calendar_get_link_previous($prevname, 'view.php?view=day'.$courseid.'&amp;', $prevdate['mday'], $prevdate['mon'], $prevdate['year']);
  672. // Get the format string
  673. $text = get_string('strftimedaydate');
  674. /*
  675. // Regexp hackery to make a link out of the month/year part
  676. $text = ereg_replace('(%B.+%Y|%Y.+%B|%Y.+%m[^ ]+)', '<a href="'.calendar_get_link_href('view.php?view=month&amp;', 1, $data['m'], $data['y']).'">\\1</a>', $text);
  677. $text = ereg_replace('(F.+Y|Y.+F|Y.+m[^ ]+)', '<a href="'.calendar_get_link_href('view.php?view=month&amp;', 1, $data['m'], $data['y']).'">\\1</a>', $text);
  678. */
  679. // Replace with actual values and lose any day leading zero
  680. $text = userdate($time, $text);
  681. // Print the actual thing
  682. $content .= '<span class="hide"> | </span><span class="current">'.$text.'</span>';
  683. $content .= '<span class="hide"> | </span>'. calendar_get_link_next($nextname, 'view.php?view=day'.$courseid.'&amp;', $nextdate['mday'], $nextdate['mon'], $nextdate['year']);
  684. $content .= "<span class=\"clearer\"><!-- --></span></div>\n";
  685. break;
  686. }
  687. return $content;
  688. }
  689. function calendar_filter_controls($type, $vars = NULL, $course = NULL, $courses = NULL) {
  690. global $CFG, $SESSION, $USER;
  691. $groupevents = true;
  692. $getvars = '';
  693. $id = optional_param( 'id',0,PARAM_INT );
  694. switch($type) {
  695. case 'event':
  696. case 'upcoming':
  697. case 'day':
  698. case 'month':
  699. $getvars = '&amp;from='.$type;
  700. break;
  701. case 'course':
  702. if ($id > 0) {
  703. $getvars = '&amp;from=course&amp;id='.$id;
  704. } else {
  705. $getvars = '&amp;from=course';
  706. }
  707. if (isset($course->groupmode) and $course->groupmode == NOGROUPS and $course->groupmodeforce) {
  708. $groupevents = false;
  709. }
  710. break;
  711. }
  712. if (!empty($vars)) {
  713. $getvars .= '&amp;'.$vars;
  714. }
  715. $content = '<table>';
  716. $content .= '<tr>';
  717. if($SESSION->cal_show_global) {
  718. $content .= '<td class="eventskey event_global" style="width: 11px;"><img src="'.$CFG->pixpath.'/t/hide.gif" class="iconsmall" alt="'.get_string('hide').'" title="'.get_string('tt_hideglobal', 'calendar').'" style="cursor:pointer" onclick="location.href='."'".CALENDAR_URL.'set.php?var=showglobal'.$getvars."'".'" /></td>';
  719. $content .= '<td><a href="'.CALENDAR_URL.'set.php?var=showglobal'.$getvars.'" title="'.get_string('tt_hideglobal', 'calendar').'">'.get_string('global', 'calendar').'</a></td>'."\n";
  720. } else {
  721. $content .= '<td style="width: 11px;"><img src="'.$CFG->pixpath.'/t/show.gif" class="iconsmall" alt="'.get_string('show').'" title="'.get_string('tt_showglobal', 'calendar').'" style="cursor:pointer" onclick="location.href='."'".CALENDAR_URL.'set.php?var=showglobal'.$getvars."'".'" /></td>';
  722. $content .= '<td><a href="'.CALENDAR_URL.'set.php?var=showglobal'.$getvars.'" title="'.get_string('tt_showglobal', 'calendar').'">'.get_string('global', 'calendar').'</a></td>'."\n";
  723. }
  724. if($SESSION->cal_show_course) {
  725. $content .= '<td class="eventskey event_course" style="width: 11px;"><img src="'.$CFG->pixpath.'/t/hide.gif" class="iconsmall" alt="'.get_string('hide').'" title="'.get_string('tt_hidecourse', 'calendar').'" style="cursor:pointer" onclick="location.href='."'".CALENDAR_URL.'set.php?var=showcourses'.$getvars."'".'" /></td>';
  726. $content .= '<td><a href="'.CALENDAR_URL.'set.php?var=showcourses'.$getvars.'" title="'.get_string('tt_hidecourse', 'calendar').'">'.get_string('course', 'calendar').'</a></td>'."\n";
  727. } else {
  728. $content .= '<td style="width: 11px;"><img src="'.$CFG->pixpath.'/t/show.gif" class="iconsmall" alt="'.get_string('hide').'" title="'.get_string('tt_showcourse', 'calendar').'" style="cursor:pointer" onclick="location.href='."'".CALENDAR_URL.'set.php?var=showcourses'.$getvars."'".'" /></td>';
  729. $content .= '<td><a href="'.CALENDAR_URL.'set.php?var=showcourses'.$getvars.'" title="'.get_string('tt_showcourse', 'calendar').'">'.get_string('course', 'calendar').'</a></td>'."\n";
  730. }
  731. if(!empty($USER->id) && !isguest()) {
  732. $content .= "</tr>\n<tr>";
  733. if($groupevents) {
  734. // This course MIGHT have group events defined, so show the filter
  735. if($SESSION->cal_show_groups) {
  736. $content .= '<td class="eventskey event_group" style="width: 11px;"><img src="'.$CFG->pixpath.'/t/hide.gif" class="iconsmall" alt="'.get_string('hide').'" title="'.get_string('tt_hidegroups', 'calendar').'" style="cursor:pointer" onclick="location.href='."'".CALENDAR_URL.'set.php?var=showgroups'.$getvars."'".'" /></td>';
  737. $content .= '<td><a href="'.CALENDAR_URL.'set.php?var=showgroups'.$getvars.'" title="'.get_string('tt_hidegroups', 'calendar').'">'.get_string('group', 'calendar').'</a></td>'."\n";
  738. } else {
  739. $content .= '<td style="width: 11px;"><img src="'.$CFG->pixpath.'/t/show.gif" class="iconsmall" alt="'.get_string('show').'" title="'.get_string('tt_showgroups', 'calendar').'" style="cursor:pointer" onclick="location.href='."'".CALENDAR_URL.'set.php?var=showgroups'.$getvars."'".'" /></td>';
  740. $content .= '<td><a href="'.CALENDAR_URL.'set.php?var=showgroups'.$getvars.'" title="'.get_string('tt_showgroups', 'calendar').'">'.get_string('group', 'calendar').'</a></td>'."\n";
  741. }
  742. } else {
  743. // This course CANNOT have group events, so lose the filter
  744. $content .= '<td style="width: 11px;"></td><td>&nbsp;</td>'."\n";
  745. }
  746. if($SESSION->cal_show_user) {
  747. $content .= '<td class="eventskey event_user" style="width: 11px;"><img src="'.$CFG->pixpath.'/t/hide.gif" class="iconsmall" alt="'.get_string('hide').'" title="'.get_string('tt_hideuser', 'calendar').'" style="cursor:pointer" onclick="location.href='."'".CALENDAR_URL.'set.php?var=showuser'.$getvars."'".'" /></td>';
  748. $content .= '<td><a href="'.CALENDAR_URL.'set.php?var=showuser'.$getvars.'" title="'.get_string('tt_hideuser', 'calendar').'">'.get_string('user', 'calendar').'</a></td>'."\n";
  749. } else {
  750. $content .= '<td style="width: 11px;"><img src="'.$CFG->pixpath.'/t/show.gif" class="iconsmall" alt="'.get_string('show').'" title="'.get_string('tt_showuser', 'calendar').'" style="cursor:pointer" onclick="location.href='."'".CALENDAR_URL.'set.php?var=showuser'.$getvars."'".'" /></td>';
  751. $content .= '<td><a href="'.CALENDAR_URL.'set.php?var=showuser'.$getvars.'" title="'.get_string('tt_showuser', 'calendar').'">'.get_string('user', 'calendar').'</a></td>'."\n";
  752. }
  753. }
  754. $content .= "</tr>\n</table>\n";
  755. return $content;
  756. }
  757. function calendar_day_representation($tstamp, $now = false, $usecommonwords = true) {
  758. static $shortformat;
  759. if(empty($shortformat)) {
  760. $shortformat = get_string('strftimedayshort');
  761. }
  762. if($now === false) {
  763. $now = time();
  764. }
  765. // To have it in one place, if a change is needed
  766. $formal = userdate($tstamp, $shortformat);
  767. $datestamp = usergetdate($tstamp);
  768. $datenow = usergetdate($now);
  769. if($usecommonwords == false) {
  770. // We don't want words, just a date
  771. return $formal;
  772. }
  773. else if($datestamp['year'] == $datenow['year'] && $datestamp['yday'] == $datenow['yday']) {
  774. // Today
  775. return get_string('today', 'calendar');
  776. }
  777. else if(
  778. ($datestamp['year'] == $datenow['year'] && $datestamp['yday'] == $datenow['yday'] - 1 ) ||
  779. ($datestamp['year'] == $datenow['year'] - 1 && $datestamp['mday'] == 31 && $datestamp['mon'] == 12 && $datenow['yday'] == 1)
  780. ) {
  781. // Yesterday
  782. return get_string('yesterday', 'calendar');
  783. }
  784. else if(
  785. ($datestamp['year'] == $datenow['year'] && $datestamp['yday'] == $datenow['yday'] + 1 ) ||
  786. ($datestamp['year'] == $datenow['year'] + 1 && $datenow['mday'] == 31 && $datenow['mon'] == 12 && $datestamp['yday'] == 1)
  787. ) {
  788. // Tomorrow
  789. return get_string('tomorrow', 'calendar');
  790. }
  791. else {
  792. return $formal;
  793. }
  794. }
  795. function calendar_time_representation($time) {
  796. static $langtimeformat = NULL;
  797. if($langtimeformat === NULL) {
  798. $langtimeformat = get_string('strftimetime');
  799. }
  800. $timeformat = get_user_preferences('calendar_timeformat');
  801. if(empty($timeformat)){
  802. $timeformat = get_config(NULL,'calendar_site_timeformat');
  803. }
  804. // The ? is needed because the preference might be present, but empty
  805. return userdate($time, empty($timeformat) ? $langtimeformat : $timeformat);
  806. }
  807. /**
  808. * TODO document
  809. */
  810. function calendar_get_link_href($linkbase, $d, $m, $y) {
  811. if(empty($linkbase)) return '';
  812. $paramstr = '';
  813. if(!empty($d)) $paramstr .= '&amp;cal_d='.$d;
  814. if(!empty($m)) $paramstr .= '&amp;cal_m='.$m;
  815. if(!empty($y)) $paramstr .= '&amp;cal_y='.$y;
  816. if(!empty($paramstr)) $paramstr = substr($paramstr, 5);
  817. return $linkbase.$paramstr;
  818. }
  819. /**
  820. * TODO document
  821. */
  822. function calendar_get_link_tag($text, $linkbase, $d, $m, $y) {
  823. $href = calendar_get_link_href($linkbase, $d, $m, $y);
  824. if(empty($href)) return $text;
  825. return '<a href="'.$href.'">'.$text.'</a>';
  826. }
  827. /**
  828. * Build and return a previous month HTML link, with an arrow.
  829. * @param string $text The text label.
  830. * @param string $linkbase The URL stub.
  831. * @param int $d $m $y Day of month, month and year numbers.
  832. * @param bool $accesshide Default visible, or hide from all except screenreaders.
  833. * @return string HTML string.
  834. */
  835. function calendar_get_link_previous($text, $linkbase, $d, $m, $y, $accesshide=false) {
  836. $href = calendar_get_link_href($linkbase, $d, $m, $y);
  837. if(empty($href)) return $text;
  838. return link_arrow_left($text, $href, $accesshide, 'previous');
  839. }
  840. /**
  841. * Build and return a next month HTML link, with an arrow.
  842. * @param string $text The text label.
  843. * @param string $linkbase The URL stub.
  844. * @param int $d $m $y Day of month, month and year numbers.
  845. * @param bool $accesshide Default visible, or hide from all except screenreaders.
  846. * @return string HTML string.
  847. */
  848. function calendar_get_link_next($text, $linkbase, $d, $m, $y, $accesshide=false) {
  849. $href = calendar_get_link_href($linkbase, $d, $m, $y);
  850. if(empty($href)) return $text;
  851. return link_arrow_right($text, $href, $accesshide, 'next');
  852. }
  853. function calendar_wday_name($englishname) {
  854. return get_string(strtolower($englishname), 'calendar');
  855. }
  856. function calendar_days_in_month($month, $year) {
  857. return intval(date('t', mktime(0, 0, 0, $month, 1, $year)));
  858. }
  859. function calendar_get_sideblock_upcoming($events, $linkhref = NULL) {
  860. $content = '';
  861. $lines = count($events);
  862. if (!$lines) {
  863. return $content;
  864. }
  865. for ($i = 0; $i < $lines; ++$i) {
  866. if (!isset($events[$i]->time)) { // Just for robustness
  867. continue;
  868. }
  869. $events[$i] = calendar_add_event_metadata($events[$i]);
  870. $content .= '<div class="event"><span class="icon c0">'.$events[$i]->icon.'</span> ';
  871. if (!empty($events[$i]->referer)) {
  872. // That's an activity event, so let's provide the hyperlink
  873. $content .= $events[$i]->referer;
  874. } else {
  875. if(!empty($linkhref)) {
  876. $ed = usergetdate($events[$i]->timestart);
  877. $href = calendar_get_link_href(CALENDAR_URL.$linkhref, $ed['mday'], $ed['mon'], $ed['year']);
  878. $content .= '<a href="'.$href.'#event_'.$events[$i]->id.'">'.$events[$i]->name.'</a>';
  879. }
  880. else {
  881. $content .= $events[$i]->name;
  882. }
  883. }
  884. $events[$i]->time = str_replace('&raquo;', '<br />&raquo;', $events[$i]->time);
  885. $content .= '<div class="date">'.$events[$i]->time.'</div></div>';
  886. if ($i < $lines - 1) $content .= '<hr />';
  887. }
  888. return $content;
  889. }
  890. function calendar_add_month($month, $year) {
  891. if($month == 12) {
  892. return array(1, $year + 1);
  893. }
  894. else {
  895. return array($month + 1, $year);
  896. }
  897. }
  898. function calendar_sub_month($month, $year) {
  899. if($month == 1) {
  900. return array(12, $year - 1);
  901. }
  902. else {
  903. return array($month - 1, $year);
  904. }
  905. }
  906. function calendar_events_by_day($events, $month, $year, &$eventsbyday, &$durationbyday, &$typesbyday, &$courses) {
  907. $eventsbyday = array();
  908. $typesbyday = array();
  909. $durationbyday = array();
  910. if($events === false) {
  911. return;
  912. }
  913. foreach($events as $event) {
  914. $startdate = usergetdate($event->timestart);
  915. // Set end date = start date if no duration
  916. if ($event->timedura

Large files files are truncated, but you can click here to view the full file