add page heading
[moodle.git] / calendar / view.php
CommitLineData
93c91ee4 1<?php
7423f116 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
93c91ee4 43require_once('../config.php');
44require_once($CFG->dirroot.'/course/lib.php');
45require_once($CFG->dirroot.'/calendar/lib.php');
707fbef4 46
93c91ee4 47$courseid = optional_param('course', 0, PARAM_INT);
48$view = optional_param('view', 'upcoming', PARAM_ALPHA);
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
2a250a0b 53$site = get_site();
7423f116 54
a6855934 55$url = new moodle_url('/calendar/view.php');
93c91ee4 56if ($courseid !== 0) {
57 $url->param('course', $courseid);
58}
59if ($view !== 'upcoming') {
60 $url->param('view', $view);
61}
62if ($day !== 0) {
63 $url->param('cal_d', $day);
64}
65if ($mon !== 0) {
66 $url->param('cal_m', $mon);
67}
68if ($yr !== 0) {
69 $url->param('cal_y', $yr);
70}
71$PAGE->set_url($url);
c9c9fb90 72
9b610c98 73if ($courseid && $courseid != SITEID) {
93c91ee4 74 require_login($courseid);
75} else if ($CFG->forcelogin) {
76 require_login();
77}
2d4fb02f 78
93c91ee4 79// Initialize the session variables
80calendar_session_vars();
37d87d11 81
93c91ee4 82//add_to_log($course->id, "course", "view", "view.php?id=$course->id", "$course->id");
83$now = usergetdate(time());
84$pagetitle = '';
7423f116 85
93c91ee4 86$strcalendar = get_string('calendar', 'calendar');
7423f116 87
93c91ee4 88$link = calendar_get_link_href(CALENDAR_URL.'view.php?view=upcoming&amp;course='.$courseid.'&amp;',
89 $now['mday'], $now['mon'], $now['year']);
90$PAGE->navbar->add($strcalendar, new moodle_url($link));
91
92if(!checkdate($mon, $day, $yr)) {
93 $day = intval($now['mday']);
94 $mon = intval($now['mon']);
95 $yr = intval($now['year']);
96}
97$time = make_timestamp($yr, $mon, $day);
98
99switch($view) {
100 case 'day':
101 $PAGE->navbar->add(userdate($time, get_string('strftimedate')));
102 $pagetitle = get_string('dayview', 'calendar');
103 break;
104 case 'month':
105 $PAGE->navbar->add(userdate($time, get_string('strftimemonthyear')));
106 $pagetitle = get_string('detailedmonthview', 'calendar');
107 break;
108 case 'upcoming':
109 $pagetitle = get_string('upcomingevents', 'calendar');
110 break;
111}
112
113// If a course has been supplied in the URL, change the filters to show that one
114if (!empty($courseid)) {
115 if ($course = $DB->get_record('course', array('id'=>$courseid))) {
116 if ($course->id == SITEID) {
117 // If coming from the home page, show all courses
118 $SESSION->cal_courses_shown = calendar_get_default_courses(true);
119 calendar_set_referring_course(0);
120
121 } else {
122 // Otherwise show just this one
123 $SESSION->cal_courses_shown = $course->id;
124 calendar_set_referring_course($SESSION->cal_courses_shown);
227bc46b 125 }
126 }
93c91ee4 127} else {
128 $course = null;
129}
227bc46b 130
4f0c2d00 131if (!isloggedin() or isguestuser()) {
93c91ee4 132 $defaultcourses = calendar_get_default_courses();
133 calendar_set_filters($courses, $groups, $users, $defaultcourses, $defaultcourses);
fd5594a0 134
93c91ee4 135} else {
136 calendar_set_filters($courses, $groups, $users);
137}
43c3ffbe 138
93c91ee4 139// Let's see if we are supposed to provide a referring course link
140// but NOT for the "main page" course
141if ($SESSION->cal_course_referer != SITEID &&
142 ($shortname = $DB->get_field('course', 'shortname', array('id'=>$SESSION->cal_course_referer))) !== false) {
143 require_login();
144 if (empty($course)) {
145 $course = $DB->get_record('course', array('id'=>$SESSION->cal_course_referer)); // Useful to have around
7423f116 146 }
93c91ee4 147}
7423f116 148
93c91ee4 149$strcalendar = get_string('calendar', 'calendar');
150$prefsbutton = calendar_preferences_button();
1e1ff33b 151
93c91ee4 152// Print title and header
153$PAGE->set_title("$site->shortname: $strcalendar: $pagetitle");
bd08a24a 154$PAGE->set_heading($COURSE->fullname);
93c91ee4 155$PAGE->set_button($prefsbutton);
f22f1333 156
93c91ee4 157echo $OUTPUT->header();
7423f116 158
93c91ee4 159// Layout the whole page as three big columns.
90723839 160echo '<table class="calendarlayout">';
93c91ee4 161echo '<tr>';
7423f116 162
93c91ee4 163// START: Main column
7423f116 164
93c91ee4 165echo '<td class="maincalendar">';
166echo '<div class="heightcontainer">';
7423f116 167
93c91ee4 168switch($view) {
169 case 'day':
170 calendar_show_day($day, $mon, $yr, $courses, $groups, $users, $courseid);
171 break;
172 case 'month':
173 calendar_show_month_detailed($mon, $yr, $courses, $groups, $users, $courseid);
174 break;
175 case 'upcoming':
176 calendar_show_upcoming_events($courses, $groups, $users, get_user_preferences('calendar_lookahead', CALENDAR_UPCOMING_DAYS), get_user_preferences('calendar_maxevents', CALENDAR_UPCOMING_MAXEVENTS), $courseid);
177 break;
178}
3c49918a 179
93c91ee4 180//Link to calendar export page
181echo $OUTPUT->container_start('bottom');
182if (!empty($CFG->enablecalendarexport)) {
5c2ed7e2 183 echo $OUTPUT->single_button(new moodle_url('export.php', array('course'=>$courseid)), get_string('exportcalendar', 'calendar'));
dbf9d4cb 184
4f0c2d00 185 if (isloggedin()) {
93c91ee4 186 $authtoken = sha1($USER->username . $USER->password . $CFG->calendar_exportsalt);
187 $usernameencoded = urlencode($USER->username);
dbf9d4cb 188
93c91ee4 189 echo "<a href=\"export_execute.php?preset_what=all&amp;preset_time=recentupcoming&amp;username=$usernameencoded&amp;authtoken=$authtoken\">"
b5d0cafc 190 .'<img src="'.$OUTPUT->pix_url('i/ical') . '" height="14" width="36" '
93c91ee4 191 .'alt="'.get_string('ical', 'calendar').'" '
192 .'title="'.get_string('quickdownloadcalendar', 'calendar').'" />'
193 .'</a>';
ea185313 194 }
93c91ee4 195}
7423f116 196
93c91ee4 197echo $OUTPUT->container_end();
198echo '</div>';
199echo '</td>';
7423f116 200
93c91ee4 201// END: Main column
7423f116 202
93c91ee4 203// START: Last column (3-month display)
204echo '<td class="sidecalendar">';
205list($prevmon, $prevyr) = calendar_sub_month($mon, $yr);
206list($nextmon, $nextyr) = calendar_add_month($mon, $yr);
207$getvars = 'id='.$courseid.'&amp;cal_d='.$day.'&amp;cal_m='.$mon.'&amp;cal_y='.$yr; // For filtering
7d50b363 208
93c91ee4 209$content='<div class="filters">';
210$content.=calendar_filter_controls($view, $getvars, NULL, $courses);
211$content.='</div>';
212
213$bc = new block_contents();
214$bc->content = $content;
215$bc->footer = '';
216$bc->title = strip_tags(get_string('eventskey', 'calendar'));
217echo $OUTPUT->block($bc, BLOCK_POS_LEFT);
218
219$content='<div class="minicalendarblock minicalendartop">';
220$content.=calendar_top_controls('display', array('id' => $courseid, 'm' => $prevmon, 'y' => $prevyr));
221$content.=calendar_get_mini($courses, $groups, $users, $prevmon, $prevyr);
222$content.='</div><div class="minicalendarblock">';
223$content.=calendar_top_controls('display', array('id' => $courseid, 'm' => $mon, 'y' => $yr));
224$content.=calendar_get_mini($courses, $groups, $users, $mon, $yr);
225$content.='</div><div class="minicalendarblock">';
226$content.=calendar_top_controls('display', array('id' => $courseid, 'm' => $nextmon, 'y' => $nextyr));
227$content.=calendar_get_mini($courses, $groups, $users, $nextmon, $nextyr);
228$content.='</div>';
229
230$bc = new block_contents();
231$bc->content = $content;
232$bc->footer = '';
233$bc->title = strip_tags(get_string('monthlyview', 'calendar'));
234echo $OUTPUT->block($bc, BLOCK_POS_LEFT);
7d50b363 235
93c91ee4 236echo '</td>';
7423f116 237
93c91ee4 238echo '</tr></table>';
ff2ec3b5 239
93c91ee4 240echo $OUTPUT->footer();
7423f116 241
9958a08c 242
243
f21ed0f3 244function calendar_show_day($d, $m, $y, $courses, $groups, $users, $courseid) {
4a2c4132 245 global $CFG, $USER;
7423f116 246
9958a08c 247 if (!checkdate($m, $d, $y)) {
7423f116 248 $now = usergetdate(time());
249 list($d, $m, $y) = array(intval($now['mday']), intval($now['mon']), intval($now['year']));
250 }
251
34bf3ad4 252 $getvars = 'from=day&amp;cal_d='.$d.'&amp;cal_m='.$m.'&amp;cal_y='.$y; // For filtering
253
7423f116 254 $starttime = make_timestamp($y, $m, $d);
3c7e1b65 255 $endtime = make_timestamp($y, $m, $d + 1) - 1;
7423f116 256
9958a08c 257 $events = calendar_get_upcoming($courses, $groups, $users, 1, 100, $starttime);
7423f116 258
2ad2cbc3 259 $text = '';
4f0c2d00 260 if (!isguestuser() && isloggedin() && calendar_user_can_add_event()) {
2ad2cbc3 261 $text.= '<div class="buttons">';
262 $text.= '<form action="'.CALENDAR_URL.'event.php" method="get">';
2aab6488 263 $text.= '<div>';
7423f116 264 $text.= '<input type="hidden" name="action" value="new" />';
f21ed0f3 265 $text.= '<input type="hidden" name="course" value="'.$courseid.'" />';
11b0ffe8 266 $text.= '<input type="hidden" name="cal_d" value="'.$d.'" />';
7423f116 267 $text.= '<input type="hidden" name="cal_m" value="'.$m.'" />';
268 $text.= '<input type="hidden" name="cal_y" value="'.$y.'" />';
269 $text.= '<input type="submit" value="'.get_string('newevent', 'calendar').'" />';
2aab6488 270 $text.= '</div></form></div>';
7423f116 271 }
272
e6c4b5f2
EL
273 $text .= '<label for="cal_course_flt_jump">'.
274 get_string('dayview', 'calendar').
275 ':</label>'.
276 calendar_course_filter_selector($getvars);
2ad2cbc3 277
df349d1d 278 echo '<div class="header">'.$text.'</div>';
7d50b363 279
f21ed0f3 280 echo '<div class="controls">'.calendar_top_controls('day', array('id' => $courseid, 'd' => $d, 'm' => $m, 'y' => $y)).'</div>';
7423f116 281
9958a08c 282 if (empty($events)) {
7423f116 283 // There is nothing to display today.
3477a900 284 echo '<h3>'.get_string('daywithnoevents', 'calendar').'</h3>';
9958a08c 285
286 } else {
287
2ad2cbc3 288 echo '<div class="eventlist">';
289
9958a08c 290 $underway = array();
7423f116 291
292 // First, print details about events that start today
9958a08c 293 foreach ($events as $event) {
7c50db30 294
76d9df3f 295 $event = new calendar_event($event);
54052a7a 296 $event->calendarcourseid = $courseid;
7c50db30 297
9958a08c 298 if ($event->timestart >= $starttime && $event->timestart <= $endtime) { // Print it now
9d567178 299
9d567178 300
8f896582 301/*
9d567178 302 $dayend = calendar_day_representation($event->timestart + $event->timeduration);
303 $timeend = calendar_time_representation($event->timestart + $event->timeduration);
304 $enddate = usergetdate($event->timestart + $event->timeduration);
305 // Set printable representation
306 echo calendar_get_link_tag($dayend, CALENDAR_URL.'view.php?view=day'.$morehref.'&amp;', $enddate['mday'], $enddate['mon'], $enddate['year']).' ('.$timeend.')';
307*/
8f896582 308 //unset($event->time);
b4892fa2 309
b4892fa2 310 $event->time = calendar_format_event_time($event, time(), '', false, $starttime);
227bc46b 311 calendar_print_event($event);
9958a08c 312
313 } else { // Save this for later
314 $underway[] = $event;
7423f116 315 }
316 }
317
318 // Then, show a list of all events that just span this day
9958a08c 319 if (!empty($underway)) {
3c134875 320 echo '<h3>'.get_string('spanningevents', 'calendar').':</h3>';
9958a08c 321 foreach ($underway as $event) {
b4892fa2 322 $event->time = calendar_format_event_time($event, time(), '', false, $starttime);
227bc46b 323 calendar_print_event($event);
7423f116 324 }
7423f116 325 }
2ad2cbc3 326
327 echo '</div>';
328
7423f116 329 }
7423f116 330}
331
f21ed0f3 332function calendar_show_month_detailed($m, $y, $courses, $groups, $users, $courseid) {
f2bffd9e 333 global $CFG, $SESSION, $USER, $CALENDARDAYS;
2b10fcf5 334 global $day, $mon, $yr;
7423f116 335
336 $getvars = 'from=month&amp;cal_d='.$day.'&amp;cal_m='.$mon.'&amp;cal_y='.$yr; // For filtering
337
62d11d77 338 $display = new stdClass;
76d9df3f 339 $display->minwday = get_user_preferences('calendar_startwday', calendar_get_starting_weekday());
7423f116 340 $display->maxwday = $display->minwday + 6;
341
342 if(!empty($m) && !empty($y)) {
343 $thisdate = usergetdate(time()); // Time and day at the user's location
344 if($m == $thisdate['mon'] && $y == $thisdate['year']) {
345 // Navigated to this month
346 $date = $thisdate;
347 $display->thismonth = true;
348 }
349 else {
350 // Navigated to other month, let's do a nice trick and save us a lot of work...
351 if(!checkdate($m, 1, $y)) {
352 $date = array('mday' => 1, 'mon' => $thisdate['mon'], 'year' => $thisdate['year']);
353 $display->thismonth = true;
354 }
355 else {
356 $date = array('mday' => 1, 'mon' => $m, 'year' => $y);
357 $display->thismonth = false;
358 }
359 }
360 }
361 else {
362 $date = usergetdate(time());
363 $display->thismonth = true;
364 }
365
366 // Fill in the variables we 're going to use, nice and tidy
367 list($d, $m, $y) = array($date['mday'], $date['mon'], $date['year']); // This is what we want to display
368 $display->maxdays = calendar_days_in_month($m, $y);
369
6cc1a805 370 $startwday = 0;
449c1d6c 371 if (get_user_timezone_offset() < 99) {
372 // We 'll keep these values as GMT here, and offset them when the time comes to query the db
373 $display->tstart = gmmktime(0, 0, 0, $m, 1, $y); // This is GMT
374 $display->tend = gmmktime(23, 59, 59, $m, $display->maxdays, $y); // GMT
6cc1a805 375 $startwday = gmdate('w', $display->tstart); // $display->tstart is already GMT, so don't use date(): messes with server's TZ
449c1d6c 376 } else {
377 // no timezone info specified
378 $display->tstart = mktime(0, 0, 0, $m, 1, $y);
379 $display->tend = mktime(23, 59, 59, $m, $display->maxdays, $y);
6cc1a805 380 $startwday = date('w', $display->tstart); // $display->tstart not necessarily GMT, so use date()
449c1d6c 381 }
7423f116 382
7423f116 383 // Align the starting weekday to fall in our display range
384 if($startwday < $display->minwday) {
385 $startwday += 7;
386 }
387
388 // Get events from database
8263f802 389 $events = calendar_get_events(usertime($display->tstart), usertime($display->tend), $users, $groups, $courses);
13534ef7
ML
390 if (!empty($events)) {
391 foreach($events as $eventid => $event) {
76d9df3f 392 $event = new calendar_event($event);
13534ef7
ML
393 if (!empty($event->modulename)) {
394 $cm = get_coursemodule_from_instance($event->modulename, $event->instance);
395 if (!groups_course_module_visible($cm)) {
396 unset($events[$eventid]);
397 }
398 }
399 }
400 }
aa6c1ced 401
7423f116 402 // Extract information: events vs. time
7c50db30 403 calendar_events_by_day($events, $m, $y, $eventsbyday, $durationbyday, $typesbyday, $courses);
7423f116 404
2ad2cbc3 405 $text = '';
4f0c2d00 406 if(!isguestuser() && isloggedin() && calendar_user_can_add_event()) {
2ad2cbc3 407 $text.= '<div class="buttons"><form action="'.CALENDAR_URL.'event.php" method="get">';
2aab6488 408 $text.= '<div>';
7423f116 409 $text.= '<input type="hidden" name="action" value="new" />';
f21ed0f3 410 $text.= '<input type="hidden" name="course" value="'.$courseid.'" />';
7423f116 411 $text.= '<input type="hidden" name="cal_m" value="'.$m.'" />';
412 $text.= '<input type="hidden" name="cal_y" value="'.$y.'" />';
413 $text.= '<input type="submit" value="'.get_string('newevent', 'calendar').'" />';
2aab6488 414 $text.= '</div></form></div>';
7423f116 415 }
416
2ad2cbc3 417 $text .= get_string('detailedmonthview', 'calendar').': '.calendar_course_filter_selector($getvars);
418
df349d1d 419 echo '<div class="header">'.$text.'</div>';
43c3ffbe 420
7d50b363 421 echo '<div class="controls">';
f21ed0f3 422 echo calendar_top_controls('month', array('id' => $courseid, 'm' => $m, 'y' => $y));
7d50b363 423 echo '</div>';
7423f116 424
425 // Start calendar display
90723839 426 echo '<table class="calendarmonth calendartable"><tr class="weekdays">'; // Begin table. First row: day names
7423f116 427
428 // Print out the names of the weekdays
7423f116 429 for($i = $display->minwday; $i <= $display->maxwday; ++$i) {
430 // This uses the % operator to get the correct weekday no matter what shift we have
431 // applied to the $display->minwday : $display->maxwday range from the default 0 : 6
54926e78 432 echo '<th scope="col">'.get_string($CALENDARDAYS[$i % 7], 'calendar').'</th>';
7423f116 433 }
434
f136e4c5 435 echo '</tr><tr>'; // End of day names; prepare for day numbers
7423f116 436
437 // For the table display. $week is the row; $dayweek is the column.
438 $week = 1;
439 $dayweek = $startwday;
440
441 // Paddding (the first week may have blank days in the beginning)
442 for($i = $display->minwday; $i < $startwday; ++$i) {
b4892fa2 443 echo '<td class="nottoday">&nbsp;</td>'."\n";
7423f116 444 }
445
446 // Now display all the calendar
447 for($day = 1; $day <= $display->maxdays; ++$day, ++$dayweek) {
448 if($dayweek > $display->maxwday) {
449 // We need to change week (table row)
450 echo "</tr>\n<tr>";
451 $dayweek = $display->minwday;
452 ++$week;
453 }
454
455 // Reset vars
7423f116 456 $cell = '';
f21ed0f3 457 $dayhref = calendar_get_link_href(CALENDAR_URL.'view.php?view=day&amp;course='.$courseid.'&amp;', $day, $m, $y);
f434283f 458
bb4a2e85 459 if(CALENDAR_WEEKEND & (1 << ($dayweek % 7))) {
7423f116 460 // Weekend. This is true no matter what the exact range is.
edbe6c1b 461 $class = 'weekend';
7423f116 462 }
463 else {
464 // Normal working day.
92668ad2 465 $class = '';
7423f116 466 }
467
468 // Special visual fx if an event is defined
469 if(isset($eventsbyday[$day])) {
7423f116 470 if(count($eventsbyday[$day]) == 1) {
471 $title = get_string('oneevent', 'calendar');
472 }
473 else {
474 $title = get_string('manyevents', 'calendar', count($eventsbyday[$day]));
475 }
edbe6c1b 476 $cell = '<div class="day"><a href="'.$dayhref.'" title="'.$title.'">'.$day.'</a></div>';
7423f116 477 }
478 else {
edbe6c1b 479 $cell = '<div class="day">'.$day.'</div>';
7423f116 480 }
481
482 // Special visual fx if an event spans many days
90723839
SH
483 $durationclass = false;
484 if (isset($typesbyday[$day]['durationglobal'])) {
485 $durationclass = ' duration_global';
486 } else if(isset($typesbyday[$day]['durationcourse'])) {
487 $durationclass = ' duration_course';
488 } else if(isset($typesbyday[$day]['durationgroup'])) {
489 $durationclass = ' duration_group';
490 } else if(isset($typesbyday[$day]['durationuser'])) {
491 $durationclass = ' duration_user';
7423f116 492 }
90723839
SH
493 if ($durationclass) {
494 $class .= ' duration '.$durationclass;
7423f116 495 }
496
497 // Special visual fx for today
498 if($display->thismonth && $day == $d) {
edbe6c1b 499 $class .= ' today';
b4892fa2 500 } else {
501 $class .= ' nottoday';
7423f116 502 }
503
504 // Just display it
92668ad2 505 if(!empty($class)) {
506 $class = ' class="'.trim($class).'"';
507 }
508 echo '<td'.$class.'>'.$cell;
509
7423f116 510 if(isset($eventsbyday[$day])) {
760e522b 511 echo '<ul class="events-new">';
7423f116 512 foreach($eventsbyday[$day] as $eventindex) {
b4892fa2 513
514 // If event has a class set then add it to the event <li> tag
515 $eventclass = '';
516 if (!empty($events[$eventindex]->class)) {
517 $eventclass = ' class="'.$events[$eventindex]->class.'"';
518 }
519
520 echo '<li'.$eventclass.'><a href="'.$dayhref.'#event_'.$events[$eventindex]->id.'">'.format_string($events[$eventindex]->name, true).'</a></li>';
7423f116 521 }
edbe6c1b 522 echo '</ul>';
7423f116 523 }
524 if(isset($durationbyday[$day])) {
760e522b 525 echo '<ul class="events-underway">';
7423f116 526 foreach($durationbyday[$day] as $eventindex) {
fb73f3b3 527 echo '<li>['.format_string($events[$eventindex]->name,true).']</li>';
7423f116 528 }
760e522b 529 echo '</ul>';
7423f116 530 }
531 echo "</td>\n";
532 }
533
534 // Paddding (the last week may have blank days at the end)
535 for($i = $dayweek; $i <= $display->maxwday; ++$i) {
b4892fa2 536 echo '<td class="nottoday">&nbsp;</td>';
7423f116 537 }
f136e4c5 538 echo "</tr>\n"; // Last row ends
7423f116 539
7d50b363 540 echo "</table>\n"; // Tabular display of days ends
7423f116 541
4454447d 542 // OK, now for the filtering display
e6c4b5f2
EL
543 echo '<div class="filters"><table><tr>';
544
545 // Global events
546 if($SESSION->cal_show_global) {
90723839 547 echo '<td class="calendar_event_global" style="width: 8px;"></td><td><strong>'.get_string('globalevents', 'calendar').':</strong> ';
e6c4b5f2
EL
548 echo get_string('shown', 'calendar').' (<a href="'.CALENDAR_URL.'set.php?var=showglobal&amp;'.$getvars.'">'.get_string('clickhide', 'calendar').'</a>)</td>'."\n";
549 } else {
550 echo '<td style="width: 8px;"></td><td><strong>'.get_string('globalevents', 'calendar').':</strong> ';
551 echo get_string('hidden', 'calendar').' (<a href="'.CALENDAR_URL.'set.php?var=showglobal&amp;'.$getvars.'">'.get_string('clickshow', 'calendar').'</a>)</td>'."\n";
552 }
553
554 // Course events
555 if(!empty($SESSION->cal_show_course)) {
90723839 556 echo '<td class="calendar_event_course" style="width: 8px;"></td><td><strong>'.get_string('courseevents', 'calendar').':</strong> ';
e6c4b5f2
EL
557 echo get_string('shown', 'calendar').' (<a href="'.CALENDAR_URL.'set.php?var=showcourses&amp;'.$getvars.'">'.get_string('clickhide', 'calendar').'</a>)</td>'."\n";
558 } else {
559 echo '<td style="width: 8px;"></td><td><strong>'.get_string('courseevents', 'calendar').':</strong> ';
560 echo get_string('hidden', 'calendar').' (<a href="'.CALENDAR_URL.'set.php?var=showcourses&amp;'.$getvars.'">'.get_string('clickshow', 'calendar').'</a>)</td>'."\n";
561 }
562
563 echo "</tr>\n";
564
4f0c2d00 565 if(isloggedin() && !isguestuser()) {
e6c4b5f2
EL
566 echo '<tr>';
567 // Group events
568 if($SESSION->cal_show_groups) {
90723839 569 echo '<td class="calendar_event_group" style="width: 8px;"></td><td><strong>'.get_string('groupevents', 'calendar').':</strong> ';
e6c4b5f2
EL
570 echo get_string('shown', 'calendar').' (<a href="'.CALENDAR_URL.'set.php?var=showgroups&amp;'.$getvars.'">'.get_string('clickhide', 'calendar').'</a>)</td>'."\n";
571 } else {
572 echo '<td style="width: 8px;"></td><td><strong>'.get_string('groupevents', 'calendar').':</strong> ';
573 echo get_string('hidden', 'calendar').' (<a href="'.CALENDAR_URL.'set.php?var=showgroups&amp;'.$getvars.'">'.get_string('clickshow', 'calendar').'</a>)</td>'."\n";
574 }
575 // User events
576 if($SESSION->cal_show_user) {
90723839 577 echo '<td class="calendar_event_user" style="width: 8px;"></td><td><strong>'.get_string('userevents', 'calendar').':</strong> ';
e6c4b5f2
EL
578 echo get_string('shown', 'calendar').' (<a href="'.CALENDAR_URL.'set.php?var=showuser&amp;'.$getvars.'">'.get_string('clickhide', 'calendar').'</a>)</td>'."\n";
579 } else {
580 echo '<td style="width: 8px;"></td><td><strong>'.get_string('userevents', 'calendar').':</strong> ';
581 echo get_string('hidden', 'calendar').' (<a href="'.CALENDAR_URL.'set.php?var=showuser&amp;'.$getvars.'">'.get_string('clickshow', 'calendar').'</a>)</td>'."\n";
582 }
583 echo "</tr>\n";
584 }
585
586 echo '</table></div>';
7423f116 587}
588
f21ed0f3 589function calendar_show_upcoming_events($courses, $groups, $users, $futuredays, $maxevents, $courseid) {
bca9ba8c 590 global $USER, $OUTPUT;
552064d3 591
7423f116 592 $events = calendar_get_upcoming($courses, $groups, $users, $futuredays, $maxevents);
7423f116 593
edbe6c1b 594 $text = '';
552064d3 595
4f0c2d00 596 if(!isguestuser() && isloggedin() && calendar_user_can_add_event()) {
edbe6c1b 597 $text.= '<div class="buttons">';
598 $text.= '<form action="'.CALENDAR_URL.'event.php" method="get">';
2aab6488 599 $text.= '<div>';
f10f1b7b 600 $text.= '<input type="hidden" name="action" value="new" />';
f21ed0f3 601 $text.= '<input type="hidden" name="course" value="'.$courseid.'" />';
f10f1b7b 602 $text.= '<input type="submit" value="'.get_string('newevent', 'calendar').'" />';
2aab6488 603 $text.= '</div></form></div>';
7423f116 604 }
605
e6c4b5f2
EL
606 $text .= '<label for="cal_course_flt_jump">'.
607 get_string('upcomingevents', 'calendar').
608 ': </label>'.
609 calendar_course_filter_selector('from=upcoming');
edbe6c1b 610
df349d1d 611 echo '<div class="header">'.$text.'</div>';
7d50b363 612
9958a08c 613 if ($events) {
b4892fa2 614
edbe6c1b 615 echo '<div class="eventlist">';
9958a08c 616 foreach ($events as $event) {
76d9df3f
SH
617 // Convert to calendar_event object so that we transform description
618 // accordingly
619 $event = new calendar_event($event);
b426fd83 620 $event->calendarcourseid = $courseid;
9958a08c 621 calendar_print_event($event);
622 }
edbe6c1b 623 echo '</div>';
9958a08c 624 } else {
bca9ba8c 625 echo $OUTPUT->heading(get_string('noupcomingevents', 'calendar'));
7423f116 626 }
7423f116 627}
628
34bf3ad4 629function calendar_course_filter_selector($getvars = '') {
5da8e2ee 630 global $USER, $SESSION, $OUTPUT;
34bf3ad4 631
4f0c2d00 632 if (!isloggedin() or isguestuser()) {
8792061c 633 return '';
634 }
635
ef35441d 636 if (has_capability('moodle/calendar:manageentries', get_context_instance(CONTEXT_SYSTEM)) && !empty($CFG->calendar_adminseesall)) {
e6d1d120 637 $courses = get_courses('all', 'c.shortname','c.id,c.shortname');
ed05bdfa 638 } else {
639 $courses = get_my_courses($USER->id, 'shortname');
640 }
34bf3ad4 641
6c40f0dc 642 unset($courses[SITEID]);
2d88c72a 643
6fe3775a 644 $courseoptions = array();
69963aa6 645 $courseoptions[SITEID] = get_string('fulllistofcourses');
ed05bdfa 646 foreach ($courses as $course) {
bf0b04f3 647 $courseoptions[$course->id] = format_string($course->shortname);
34bf3ad4 648 }
ed05bdfa 649
650 if (is_numeric($SESSION->cal_courses_shown)) {
8792061c 651 $selected = $SESSION->cal_courses_shown;
ed05bdfa 652 } else {
8792061c 653 $selected = '';
654 }
6fe3775a
PS
655 $select = new single_select(new moodle_url(CALENDAR_URL.'set.php?var=setcourse&'.$getvars), 'id', $courseoptions, $selected, null);
656 $select->class = 'cal_courses_flt';
657 echo $OUTPUT->render($select);
34bf3ad4 658}