MDL-14460, fix get_context_instance, merged from MOODLE_19_STABLE, see tracker.
[moodle.git] / calendar / view.php
CommitLineData
7423f116 1<?php // $Id$
2
3/////////////////////////////////////////////////////////////////////////////
4// //
5// NOTICE OF COPYRIGHT //
6// //
7// Moodle - Calendar extension //
8// //
9// Copyright (C) 2003-2004 Greek School Network www.sch.gr //
10// //
11// Designed by: //
bdcb26b7 12// Avgoustos Tsinakos (tsinakos@teikav.edu.gr) //
13// Jon Papaioannou (pj@moodle.org) //
7423f116 14// //
15// Programming and development: //
bdcb26b7 16// Jon Papaioannou (pj@moodle.org) //
7423f116 17// //
18// For bugs, suggestions, etc contact: //
bdcb26b7 19// Jon Papaioannou (pj@moodle.org) //
7423f116 20// //
21// The current module was developed at the University of Macedonia //
22// (www.uom.gr) under the funding of the Greek School Network (www.sch.gr) //
23// The aim of this project is to provide additional and improved //
24// functionality to the Asynchronous Distance Education service that the //
25// Greek School Network deploys. //
26// //
27// This program is free software; you can redistribute it and/or modify //
28// it under the terms of the GNU General Public License as published by //
29// the Free Software Foundation; either version 2 of the License, or //
30// (at your option) any later version. //
31// //
32// This program is distributed in the hope that it will be useful, //
33// but WITHOUT ANY WARRANTY; without even the implied warranty of //
34// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
35// GNU General Public License for more details: //
36// //
37// http://www.gnu.org/copyleft/gpl.html //
38// //
39/////////////////////////////////////////////////////////////////////////////
40
41// Display the calendar page.
42
43 require_once('../config.php');
08cebf19 44 require_once($CFG->dirroot.'/course/lib.php');
45 require_once($CFG->dirroot.'/calendar/lib.php');
707fbef4 46
7dc30088 47 $courseid = optional_param('course', 0, PARAM_INT);
48 $view = optional_param('view', 'upcoming', PARAM_ALPHA);
7f4d18fc 49 $day = optional_param('cal_d', 0, PARAM_INT);
50 $mon = optional_param('cal_m', 0, PARAM_INT);
51 $yr = optional_param('cal_y', 0, PARAM_INT);
7423f116 52
53 if(!$site = get_site()) {
54 redirect($CFG->wwwroot.'/'.$CFG->admin.'/index.php');
55 }
56
7dc30088 57 if ($courseid) {
58 require_login($courseid);
59 } else if ($CFG->forcelogin) {
2d4fb02f 60 require_login();
61 }
62
37d87d11 63 // Initialize the session variables
64 calendar_session_vars();
65
7423f116 66 //add_to_log($course->id, "course", "view", "view.php?id=$course->id", "$course->id");
7423f116 67 $now = usergetdate(time());
68 $pagetitle = '';
69
e295df44 70 $strcalendar = get_string('calendar', 'calendar');
71 $navlinks = array();
72 $navlinks[] = array('name' => $strcalendar,
73 'link' =>calendar_get_link_href(CALENDAR_URL.'view.php?view=upcoming&amp;course='.$courseid.'&amp;',
74 $now['mday'], $now['mon'], $now['year']),
75 'type' => 'misc');
76
7423f116 77
7423f116 78 if(!checkdate($mon, $day, $yr)) {
79 $day = intval($now['mday']);
80 $mon = intval($now['mon']);
81 $yr = intval($now['year']);
82 }
5147ad48 83 $time = make_timestamp($yr, $mon, $day);
7423f116 84
482dbe0c 85 switch($view) {
7423f116 86 case 'day':
e295df44 87 $navlinks[] = array('name' => userdate($time, get_string('strftimedate')), 'link' => null, 'type' => 'misc');
7423f116 88 $pagetitle = get_string('dayview', 'calendar');
89 break;
90 case 'month':
e295df44 91 $navlinks[] = array('name' => userdate($time, get_string('strftimemonthyear')), 'link' => null, 'type' => 'misc');
7423f116 92 $pagetitle = get_string('detailedmonthview', 'calendar');
7423f116 93 break;
94 case 'upcoming':
95 $pagetitle = get_string('upcomingevents', 'calendar');
96 break;
7423f116 97 }
98
227bc46b 99 // If a course has been supplied in the URL, change the filters to show that one
7dc30088 100 if (!empty($courseid)) {
101 if ($course = get_record('course', 'id', $courseid)) {
69963aa6 102 if ($course->id == SITEID) {
89adb174 103 // If coming from the home page, show all courses
104 $SESSION->cal_courses_shown = calendar_get_default_courses(true);
105 calendar_set_referring_course(0);
fd5594a0 106
107 } else {
89adb174 108 // Otherwise show just this one
d57fc786 109 $SESSION->cal_courses_shown = $course->id;
89adb174 110 calendar_set_referring_course($SESSION->cal_courses_shown);
111 }
227bc46b 112 }
7dc30088 113 } else {
114 $course = null;
227bc46b 115 }
116
1066e0dc 117 if (empty($USER->id) or isguest()) {
43c3ffbe 118 $defaultcourses = calendar_get_default_courses();
119 calendar_set_filters($courses, $groups, $users, $defaultcourses, $defaultcourses);
fd5594a0 120
121 } else {
34bf3ad4 122 calendar_set_filters($courses, $groups, $users);
43c3ffbe 123 }
124
7423f116 125 // Let's see if we are supposed to provide a referring course link
126 // but NOT for the "main page" course
69963aa6 127 if ($SESSION->cal_course_referer != SITEID &&
fd5594a0 128 ($shortname = get_field('course', 'shortname', 'id', $SESSION->cal_course_referer)) !== false) {
08cebf19 129 require_login();
d57fc786 130 if (empty($course)) {
131 $course = get_record('course', 'id', $SESSION->cal_course_referer); // Useful to have around
132 }
7423f116 133 }
134
1e1ff33b 135 $strcalendar = get_string('calendar', 'calendar');
1e1ff33b 136 $prefsbutton = calendar_preferences_button();
137
7423f116 138 // Print title and header
e295df44 139 $navigation = build_navigation($navlinks);
140 print_header("$site->shortname: $strcalendar: $pagetitle", $strcalendar, $navigation,
84854c09 141 '', '', true, $prefsbutton, user_login_string($site));
7423f116 142
143 echo calendar_overlib_html();
144
145 // Layout the whole page as three big columns.
3c49918a 146 echo '<table id="calendar" style="height:100%;">';
7d50b363 147 echo '<tr>';
7423f116 148
ff2ec3b5 149 // START: Main column
7423f116 150
7d50b363 151 echo '<td class="maincalendar">';
3c49918a 152 echo '<div class="heightcontainer">';
7423f116 153
482dbe0c 154 switch($view) {
7423f116 155 case 'day':
f21ed0f3 156 calendar_show_day($day, $mon, $yr, $courses, $groups, $users, $courseid);
7423f116 157 break;
158 case 'month':
f21ed0f3 159 calendar_show_month_detailed($mon, $yr, $courses, $groups, $users, $courseid);
7423f116 160 break;
161 case 'upcoming':
f21ed0f3 162 calendar_show_upcoming_events($courses, $groups, $users, get_user_preferences('calendar_lookahead', CALENDAR_UPCOMING_DAYS), get_user_preferences('calendar_maxevents', CALENDAR_UPCOMING_MAXEVENTS), $courseid);
7423f116 163 break;
164 }
3c49918a 165
ea185313 166 //Link to calendar export page
3c49918a 167 echo '<div class="bottom">';
9ba76792 168 print_single_button('export.php', array('course'=>$courseid), get_string('exportcalendar', 'calendar'));
3c49918a 169
ea185313 170 if (!empty($USER->id)) {
171 $authtoken = sha1($USER->username . $USER->password);
172 $usernameencoded = urlencode($USER->username);
3c49918a 173
174 echo "<a href=\"export_execute.php?preset_what=all&amp;preset_time=recentupcoming&amp;username=$usernameencoded&amp;authtoken=$authtoken\">"
175 .'<img src="'.$CFG->pixpath.'/i/ical.gif" height="14" width="36" '
176 .'alt="'.get_string('ical', 'calendar').'" '
177 .'title="'.get_string('quickdownloadcalendar', 'calendar').'" />'
178 .'</a>';
ea185313 179 }
7423f116 180
3c49918a 181 echo '</div>';
182 echo '</div>';
7423f116 183 echo '</td>';
184
ff2ec3b5 185 // END: Main column
7423f116 186
187 // START: Last column (3-month display)
7d50b363 188 echo '<td class="sidecalendar">';
ff2ec3b5 189 list($prevmon, $prevyr) = calendar_sub_month($mon, $yr);
190 list($nextmon, $nextyr) = calendar_add_month($mon, $yr);
f21ed0f3 191 $getvars = 'id='.$courseid.'&amp;cal_d='.$day.'&amp;cal_m='.$mon.'&amp;cal_y='.$yr; // For filtering
7d50b363 192
1a6ff43e 193 echo '<div class="sideblock">';
82208069 194 echo '<div class="header"><h2>'.get_string('eventskey', 'calendar').'</h2></div>';
7d50b363 195 echo '<div class="filters">';
1a6ff43e 196 echo calendar_filter_controls($view, $getvars, NULL, $courses);
197 echo '</div>';
7d50b363 198 echo '</div>';
199
1a6ff43e 200 echo '<div class="sideblock">';
82208069 201 echo '<div class="header"><h2>'.get_string('monthlyview', 'calendar').'</h2></div>';
1a6ff43e 202
203 echo '<div class="minicalendarblock minicalendartop">';
f21ed0f3 204 echo calendar_top_controls('display', array('id' => $courseid, 'm' => $prevmon, 'y' => $prevyr));
ff2ec3b5 205 echo calendar_get_mini($courses, $groups, $users, $prevmon, $prevyr);
3c47bfc7 206 echo '</div><div class="minicalendarblock">';
f21ed0f3 207 echo calendar_top_controls('display', array('id' => $courseid, 'm' => $mon, 'y' => $yr));
ff2ec3b5 208 echo calendar_get_mini($courses, $groups, $users, $mon, $yr);
3c47bfc7 209 echo '</div><div class="minicalendarblock">';
f21ed0f3 210 echo calendar_top_controls('display', array('id' => $courseid, 'm' => $nextmon, 'y' => $nextyr));
ff2ec3b5 211 echo calendar_get_mini($courses, $groups, $users, $nextmon, $nextyr);
deaa8842 212 echo '</div>';
1a6ff43e 213 echo '</div>';
7d50b363 214
ff2ec3b5 215 echo '</td>';
7423f116 216
217 echo '</tr></table>';
ff2ec3b5 218
7423f116 219 print_footer();
220
9958a08c 221
222
f21ed0f3 223function calendar_show_day($d, $m, $y, $courses, $groups, $users, $courseid) {
4a2c4132 224 global $CFG, $USER;
7423f116 225
9958a08c 226 if (!checkdate($m, $d, $y)) {
7423f116 227 $now = usergetdate(time());
228 list($d, $m, $y) = array(intval($now['mday']), intval($now['mon']), intval($now['year']));
229 }
230
34bf3ad4 231 $getvars = 'from=day&amp;cal_d='.$d.'&amp;cal_m='.$m.'&amp;cal_y='.$y; // For filtering
232
7423f116 233 $starttime = make_timestamp($y, $m, $d);
3c7e1b65 234 $endtime = make_timestamp($y, $m, $d + 1) - 1;
7423f116 235
9958a08c 236 $events = calendar_get_upcoming($courses, $groups, $users, 1, 100, $starttime);
7423f116 237
2ad2cbc3 238 $text = '';
86ac8b24 239 if (!isguest() && !empty($USER->id) && calendar_user_can_add_event()) {
2ad2cbc3 240 $text.= '<div class="buttons">';
241 $text.= '<form action="'.CALENDAR_URL.'event.php" method="get">';
2aab6488 242 $text.= '<div>';
7423f116 243 $text.= '<input type="hidden" name="action" value="new" />';
f21ed0f3 244 $text.= '<input type="hidden" name="course" value="'.$courseid.'" />';
11b0ffe8 245 $text.= '<input type="hidden" name="cal_d" value="'.$d.'" />';
7423f116 246 $text.= '<input type="hidden" name="cal_m" value="'.$m.'" />';
247 $text.= '<input type="hidden" name="cal_y" value="'.$y.'" />';
248 $text.= '<input type="submit" value="'.get_string('newevent', 'calendar').'" />';
2aab6488 249 $text.= '</div></form></div>';
7423f116 250 }
251
2ad2cbc3 252 $text .= get_string('dayview', 'calendar').': '.calendar_course_filter_selector($getvars);
253
df349d1d 254 echo '<div class="header">'.$text.'</div>';
7d50b363 255
f21ed0f3 256 echo '<div class="controls">'.calendar_top_controls('day', array('id' => $courseid, 'd' => $d, 'm' => $m, 'y' => $y)).'</div>';
7423f116 257
9958a08c 258 if (empty($events)) {
7423f116 259 // There is nothing to display today.
3477a900 260 echo '<h3>'.get_string('daywithnoevents', 'calendar').'</h3>';
9958a08c 261
262 } else {
263
2ad2cbc3 264 echo '<div class="eventlist">';
265
9958a08c 266 $underway = array();
7423f116 267
268 // First, print details about events that start today
9958a08c 269 foreach ($events as $event) {
7c50db30 270
54052a7a 271 $event->calendarcourseid = $courseid;
7c50db30 272
9958a08c 273 if ($event->timestart >= $starttime && $event->timestart <= $endtime) { // Print it now
9d567178 274
9d567178 275
8f896582 276/*
9d567178 277 $dayend = calendar_day_representation($event->timestart + $event->timeduration);
278 $timeend = calendar_time_representation($event->timestart + $event->timeduration);
279 $enddate = usergetdate($event->timestart + $event->timeduration);
280 // Set printable representation
281 echo calendar_get_link_tag($dayend, CALENDAR_URL.'view.php?view=day'.$morehref.'&amp;', $enddate['mday'], $enddate['mon'], $enddate['year']).' ('.$timeend.')';
282*/
8f896582 283 //unset($event->time);
b4892fa2 284
b4892fa2 285 $event->time = calendar_format_event_time($event, time(), '', false, $starttime);
227bc46b 286 calendar_print_event($event);
9958a08c 287
288 } else { // Save this for later
289 $underway[] = $event;
7423f116 290 }
291 }
292
293 // Then, show a list of all events that just span this day
9958a08c 294 if (!empty($underway)) {
3c134875 295 echo '<h3>'.get_string('spanningevents', 'calendar').':</h3>';
9958a08c 296 foreach ($underway as $event) {
b4892fa2 297 $event->time = calendar_format_event_time($event, time(), '', false, $starttime);
227bc46b 298 calendar_print_event($event);
7423f116 299 }
7423f116 300 }
2ad2cbc3 301
302 echo '</div>';
303
7423f116 304 }
7423f116 305}
306
f21ed0f3 307function calendar_show_month_detailed($m, $y, $courses, $groups, $users, $courseid) {
f2bffd9e 308 global $CFG, $SESSION, $USER, $CALENDARDAYS;
2b10fcf5 309 global $day, $mon, $yr;
7423f116 310
311 $getvars = 'from=month&amp;cal_d='.$day.'&amp;cal_m='.$mon.'&amp;cal_y='.$yr; // For filtering
312
313 $display = &New stdClass;
314 $display->minwday = get_user_preferences('calendar_startwday', CALENDAR_STARTING_WEEKDAY);
315 $display->maxwday = $display->minwday + 6;
316
317 if(!empty($m) && !empty($y)) {
318 $thisdate = usergetdate(time()); // Time and day at the user's location
319 if($m == $thisdate['mon'] && $y == $thisdate['year']) {
320 // Navigated to this month
321 $date = $thisdate;
322 $display->thismonth = true;
323 }
324 else {
325 // Navigated to other month, let's do a nice trick and save us a lot of work...
326 if(!checkdate($m, 1, $y)) {
327 $date = array('mday' => 1, 'mon' => $thisdate['mon'], 'year' => $thisdate['year']);
328 $display->thismonth = true;
329 }
330 else {
331 $date = array('mday' => 1, 'mon' => $m, 'year' => $y);
332 $display->thismonth = false;
333 }
334 }
335 }
336 else {
337 $date = usergetdate(time());
338 $display->thismonth = true;
339 }
340
341 // Fill in the variables we 're going to use, nice and tidy
342 list($d, $m, $y) = array($date['mday'], $date['mon'], $date['year']); // This is what we want to display
343 $display->maxdays = calendar_days_in_month($m, $y);
344
6cc1a805 345 $startwday = 0;
449c1d6c 346 if (get_user_timezone_offset() < 99) {
347 // We 'll keep these values as GMT here, and offset them when the time comes to query the db
348 $display->tstart = gmmktime(0, 0, 0, $m, 1, $y); // This is GMT
349 $display->tend = gmmktime(23, 59, 59, $m, $display->maxdays, $y); // GMT
6cc1a805 350 $startwday = gmdate('w', $display->tstart); // $display->tstart is already GMT, so don't use date(): messes with server's TZ
449c1d6c 351 } else {
352 // no timezone info specified
353 $display->tstart = mktime(0, 0, 0, $m, 1, $y);
354 $display->tend = mktime(23, 59, 59, $m, $display->maxdays, $y);
6cc1a805 355 $startwday = date('w', $display->tstart); // $display->tstart not necessarily GMT, so use date()
449c1d6c 356 }
7423f116 357
7423f116 358 // Align the starting weekday to fall in our display range
359 if($startwday < $display->minwday) {
360 $startwday += 7;
361 }
362
363 // Get events from database
8263f802 364 $events = calendar_get_events(usertime($display->tstart), usertime($display->tend), $users, $groups, $courses);
13534ef7
ML
365 if (!empty($events)) {
366 foreach($events as $eventid => $event) {
367 if (!empty($event->modulename)) {
368 $cm = get_coursemodule_from_instance($event->modulename, $event->instance);
369 if (!groups_course_module_visible($cm)) {
370 unset($events[$eventid]);
371 }
372 }
373 }
374 }
375
7423f116 376 // Extract information: events vs. time
7c50db30 377 calendar_events_by_day($events, $m, $y, $eventsbyday, $durationbyday, $typesbyday, $courses);
7423f116 378
2ad2cbc3 379 $text = '';
86ac8b24 380 if(!isguest() && !empty($USER->id) && calendar_user_can_add_event()) {
2ad2cbc3 381 $text.= '<div class="buttons"><form action="'.CALENDAR_URL.'event.php" method="get">';
2aab6488 382 $text.= '<div>';
7423f116 383 $text.= '<input type="hidden" name="action" value="new" />';
f21ed0f3 384 $text.= '<input type="hidden" name="course" value="'.$courseid.'" />';
7423f116 385 $text.= '<input type="hidden" name="cal_m" value="'.$m.'" />';
386 $text.= '<input type="hidden" name="cal_y" value="'.$y.'" />';
387 $text.= '<input type="submit" value="'.get_string('newevent', 'calendar').'" />';
2aab6488 388 $text.= '</div></form></div>';
7423f116 389 }
390
2ad2cbc3 391 $text .= get_string('detailedmonthview', 'calendar').': '.calendar_course_filter_selector($getvars);
392
df349d1d 393 echo '<div class="header">'.$text.'</div>';
43c3ffbe 394
7d50b363 395 echo '<div class="controls">';
f21ed0f3 396 echo calendar_top_controls('month', array('id' => $courseid, 'm' => $m, 'y' => $y));
7d50b363 397 echo '</div>';
7423f116 398
399 // Start calendar display
f136e4c5 400 echo '<table class="calendarmonth"><tr class="weekdays">'; // Begin table. First row: day names
7423f116 401
402 // Print out the names of the weekdays
7423f116 403 for($i = $display->minwday; $i <= $display->maxwday; ++$i) {
404 // This uses the % operator to get the correct weekday no matter what shift we have
405 // applied to the $display->minwday : $display->maxwday range from the default 0 : 6
54926e78 406 echo '<th scope="col">'.get_string($CALENDARDAYS[$i % 7], 'calendar').'</th>';
7423f116 407 }
408
f136e4c5 409 echo '</tr><tr>'; // End of day names; prepare for day numbers
7423f116 410
411 // For the table display. $week is the row; $dayweek is the column.
412 $week = 1;
413 $dayweek = $startwday;
414
415 // Paddding (the first week may have blank days in the beginning)
416 for($i = $display->minwday; $i < $startwday; ++$i) {
b4892fa2 417 echo '<td class="nottoday">&nbsp;</td>'."\n";
7423f116 418 }
419
420 // Now display all the calendar
421 for($day = 1; $day <= $display->maxdays; ++$day, ++$dayweek) {
422 if($dayweek > $display->maxwday) {
423 // We need to change week (table row)
424 echo "</tr>\n<tr>";
425 $dayweek = $display->minwday;
426 ++$week;
427 }
428
429 // Reset vars
7423f116 430 $cell = '';
f21ed0f3 431 $dayhref = calendar_get_link_href(CALENDAR_URL.'view.php?view=day&amp;course='.$courseid.'&amp;', $day, $m, $y);
f434283f 432
bb4a2e85 433 if(CALENDAR_WEEKEND & (1 << ($dayweek % 7))) {
7423f116 434 // Weekend. This is true no matter what the exact range is.
edbe6c1b 435 $class = 'weekend';
7423f116 436 }
437 else {
438 // Normal working day.
92668ad2 439 $class = '';
7423f116 440 }
441
442 // Special visual fx if an event is defined
443 if(isset($eventsbyday[$day])) {
7423f116 444 if(count($eventsbyday[$day]) == 1) {
445 $title = get_string('oneevent', 'calendar');
446 }
447 else {
448 $title = get_string('manyevents', 'calendar', count($eventsbyday[$day]));
449 }
edbe6c1b 450 $cell = '<div class="day"><a href="'.$dayhref.'" title="'.$title.'">'.$day.'</a></div>';
7423f116 451 }
452 else {
edbe6c1b 453 $cell = '<div class="day">'.$day.'</div>';
7423f116 454 }
455
456 // Special visual fx if an event spans many days
457 if(isset($typesbyday[$day]['durationglobal'])) {
edbe6c1b 458 $class .= ' duration_global';
7423f116 459 }
460 else if(isset($typesbyday[$day]['durationcourse'])) {
edbe6c1b 461 $class .= ' duration_course';
7423f116 462 }
463 else if(isset($typesbyday[$day]['durationgroup'])) {
edbe6c1b 464 $class .= ' duration_group';
7423f116 465 }
466 else if(isset($typesbyday[$day]['durationuser'])) {
edbe6c1b 467 $class .= ' duration_user';
7423f116 468 }
469
470 // Special visual fx for today
471 if($display->thismonth && $day == $d) {
edbe6c1b 472 $class .= ' today';
b4892fa2 473 } else {
474 $class .= ' nottoday';
7423f116 475 }
476
477 // Just display it
92668ad2 478 if(!empty($class)) {
479 $class = ' class="'.trim($class).'"';
480 }
481 echo '<td'.$class.'>'.$cell;
482
7423f116 483 if(isset($eventsbyday[$day])) {
760e522b 484 echo '<ul class="events-new">';
7423f116 485 foreach($eventsbyday[$day] as $eventindex) {
b4892fa2 486
487 // If event has a class set then add it to the event <li> tag
488 $eventclass = '';
489 if (!empty($events[$eventindex]->class)) {
490 $eventclass = ' class="'.$events[$eventindex]->class.'"';
491 }
492
493 echo '<li'.$eventclass.'><a href="'.$dayhref.'#event_'.$events[$eventindex]->id.'">'.format_string($events[$eventindex]->name, true).'</a></li>';
7423f116 494 }
edbe6c1b 495 echo '</ul>';
7423f116 496 }
497 if(isset($durationbyday[$day])) {
760e522b 498 echo '<ul class="events-underway">';
7423f116 499 foreach($durationbyday[$day] as $eventindex) {
fb73f3b3 500 echo '<li>['.format_string($events[$eventindex]->name,true).']</li>';
7423f116 501 }
760e522b 502 echo '</ul>';
7423f116 503 }
504 echo "</td>\n";
505 }
506
507 // Paddding (the last week may have blank days at the end)
508 for($i = $dayweek; $i <= $display->maxwday; ++$i) {
b4892fa2 509 echo '<td class="nottoday">&nbsp;</td>';
7423f116 510 }
f136e4c5 511 echo "</tr>\n"; // Last row ends
7423f116 512
7d50b363 513 echo "</table>\n"; // Tabular display of days ends
7423f116 514
e3bb6401 515 // OK, now for the filtering display
516 echo '<div class="filters"><table><tr>';
517
518 // Global events
519 if($SESSION->cal_show_global) {
520 echo '<td class="event_global" style="width: 8px;"></td><td><strong>'.get_string('globalevents', 'calendar').':</strong> ';
521 echo get_string('shown', 'calendar').' (<a href="'.CALENDAR_URL.'set.php?var=showglobal&amp;'.$getvars.'">'.get_string('clickhide', 'calendar').'</a>)</td>'."\n";
522 }
523 else {
524 echo '<td style="width: 8px;"></td><td><strong>'.get_string('globalevents', 'calendar').':</strong> ';
525 echo get_string('hidden', 'calendar').' (<a href="'.CALENDAR_URL.'set.php?var=showglobal&amp;'.$getvars.'">'.get_string('clickshow', 'calendar').'</a>)</td>'."\n";
526 }
527
528 // Course events
529 if(!empty($SESSION->cal_show_course)) {
530 echo '<td class="event_course" style="width: 8px;"></td><td><strong>'.get_string('courseevents', 'calendar').':</strong> ';
531 echo get_string('shown', 'calendar').' (<a href="'.CALENDAR_URL.'set.php?var=showcourses&amp;'.$getvars.'">'.get_string('clickhide', 'calendar').'</a>)</td>'."\n";
532 }
533 else {
534 echo '<td style="width: 8px;"></td><td><strong>'.get_string('courseevents', 'calendar').':</strong> ';
535 echo get_string('hidden', 'calendar').' (<a href="'.CALENDAR_URL.'set.php?var=showcourses&amp;'.$getvars.'">'.get_string('clickshow', 'calendar').'</a>)</td>'."\n";
536 }
537
538 echo "</tr>\n";
539
540 if(!empty($USER->id) && !isguest()) {
541 echo '<tr>';
542 // Group events
543 if($SESSION->cal_show_groups) {
544 echo '<td class="event_group" style="width: 8px;"></td><td><strong>'.get_string('groupevents', 'calendar').':</strong> ';
545 echo get_string('shown', 'calendar').' (<a href="'.CALENDAR_URL.'set.php?var=showgroups&amp;'.$getvars.'">'.get_string('clickhide', 'calendar').'</a>)</td>'."\n";
546 }
547 else {
548 echo '<td style="width: 8px;"></td><td><strong>'.get_string('groupevents', 'calendar').':</strong> ';
549 echo get_string('hidden', 'calendar').' (<a href="'.CALENDAR_URL.'set.php?var=showgroups&amp;'.$getvars.'">'.get_string('clickshow', 'calendar').'</a>)</td>'."\n";
550 }
551 // User events
552 if($SESSION->cal_show_user) {
553 echo '<td class="event_user" style="width: 8px;"></td><td><strong>'.get_string('userevents', 'calendar').':</strong> ';
554 echo get_string('shown', 'calendar').' (<a href="'.CALENDAR_URL.'set.php?var=showuser&amp;'.$getvars.'">'.get_string('clickhide', 'calendar').'</a>)</td>'."\n";
555 }
556 else {
557 echo '<td style="width: 8px;"></td><td><strong>'.get_string('userevents', 'calendar').':</strong> ';
558 echo get_string('hidden', 'calendar').' (<a href="'.CALENDAR_URL.'set.php?var=showuser&amp;'.$getvars.'">'.get_string('clickshow', 'calendar').'</a>)</td>'."\n";
559 }
560 echo "</tr>\n";
561 }
562
563 echo '</table></div>';
7423f116 564}
565
f21ed0f3 566function calendar_show_upcoming_events($courses, $groups, $users, $futuredays, $maxevents, $courseid) {
3395a558 567 global $USER;
552064d3 568
7423f116 569 $events = calendar_get_upcoming($courses, $groups, $users, $futuredays, $maxevents);
7423f116 570
edbe6c1b 571 $text = '';
552064d3 572
86ac8b24 573 if(!isguest() && !empty($USER->id) && calendar_user_can_add_event()) {
edbe6c1b 574 $text.= '<div class="buttons">';
575 $text.= '<form action="'.CALENDAR_URL.'event.php" method="get">';
2aab6488 576 $text.= '<div>';
f10f1b7b 577 $text.= '<input type="hidden" name="action" value="new" />';
f21ed0f3 578 $text.= '<input type="hidden" name="course" value="'.$courseid.'" />';
227bc46b 579 /*
f10f1b7b 580 $text.= '<input type="hidden" name="cal_m" value="'.$m.'" />';
581 $text.= '<input type="hidden" name="cal_y" value="'.$y.'" />';
227bc46b 582 */
f10f1b7b 583 $text.= '<input type="submit" value="'.get_string('newevent', 'calendar').'" />';
2aab6488 584 $text.= '</div></form></div>';
7423f116 585 }
586
edbe6c1b 587 $text .= get_string('upcomingevents', 'calendar').': '.calendar_course_filter_selector('from=upcoming');
588
df349d1d 589 echo '<div class="header">'.$text.'</div>';
7d50b363 590
9958a08c 591 if ($events) {
b4892fa2 592
edbe6c1b 593 echo '<div class="eventlist">';
9958a08c 594 foreach ($events as $event) {
b426fd83 595 $event->calendarcourseid = $courseid;
9958a08c 596 calendar_print_event($event);
597 }
edbe6c1b 598 echo '</div>';
9958a08c 599 } else {
9958a08c 600 print_heading(get_string('noupcomingevents', 'calendar'));
7423f116 601 }
7423f116 602}
603
34bf3ad4 604function calendar_course_filter_selector($getvars = '') {
605 global $USER, $SESSION;
606
1066e0dc 607 if (empty($USER->id) or isguest()) {
8792061c 608 return '';
609 }
610
ef35441d 611 if (has_capability('moodle/calendar:manageentries', get_context_instance(CONTEXT_SYSTEM)) && !empty($CFG->calendar_adminseesall)) {
e6d1d120 612 $courses = get_courses('all', 'c.shortname','c.id,c.shortname');
ed05bdfa 613 } else {
614 $courses = get_my_courses($USER->id, 'shortname');
615 }
34bf3ad4 616
6c40f0dc 617 unset($courses[SITEID]);
2d88c72a 618
69963aa6 619 $courseoptions[SITEID] = get_string('fulllistofcourses');
ed05bdfa 620 foreach ($courses as $course) {
bf0b04f3 621 $courseoptions[$course->id] = format_string($course->shortname);
34bf3ad4 622 }
ed05bdfa 623
624 if (is_numeric($SESSION->cal_courses_shown)) {
8792061c 625 $selected = $SESSION->cal_courses_shown;
ed05bdfa 626 } else {
8792061c 627 $selected = '';
628 }
ed05bdfa 629
647213f7 630 return popup_form(CALENDAR_URL.'set.php?var=setcourse&amp;'.$getvars.'&amp;id=',
ed05bdfa 631 $courseoptions, 'cal_course_flt', $selected, '', '', '', true);
34bf3ad4 632}
633
7423f116 634?>