3 // This file is part of Moodle - http://moodle.org/
5 // Moodle is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation, either version 3 of the License, or
8 // (at your option) any later version.
10 // Moodle is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
19 * This file contains the renderers for the calendar within Moodle
21 * @copyright 2010 Sam Hemelryk
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
27 * The primary renderer for the calendar.
29 class core_calendar_renderer extends plugin_renderer_base {
32 * Creates a basic export form
34 * @param bool $allowthisweek
35 * @param bool $allownextweek
36 * @param bool $allownextmonth
37 * @param string $username
38 * @param string $authtoken
41 public function basic_export_form($allowthisweek, $allownextweek, $allownextmonth, $username, $authtoken) {
43 $output = html_writer::tag('div', get_string('export', 'calendar'), array('class'=>'header'));
44 $output .= html_writer::start_tag('fieldset');
45 $output .= html_writer::tag('legend', get_string('commontasks', 'calendar'));
46 $output .= html_writer::start_tag('form', array('action'=>new moodle_url('/calendar/export_execute.php'), 'method'=>'get'));
48 $output .= html_writer::tag('div', get_string('iwanttoexport', 'calendar'));
50 $output .= html_writer::start_tag('div', array('class'=>'indent'));
51 $output .= html_writer::empty_tag('input', array('type'=>'radio', 'name'=>'preset_what', 'id'=>'pw_all', 'value'=>'all', 'checked'=>'checked'));
52 $output .= html_writer::tag('label', get_string('eventsall', 'calendar'), array('for'=>'pw_all'));
53 $output .= html_writer::empty_tag('br');
54 $output .= html_writer::empty_tag('input', array('type'=>'radio', 'name'=>'preset_what', 'id'=>'pw_course', 'value'=>'courses'));
55 $output .= html_writer::tag('label', get_string('eventsrelatedtocourses', 'calendar'), array('for'=>'pw_course'));
56 $output .= html_writer::empty_tag('br');
57 $output .= html_writer::end_tag('div');
59 $output .= html_writer::tag('div', get_string('for', 'calendar').':');
61 $output .= html_writer::start_tag('div', array('class'=>'indent'));
63 $output .= html_writer::empty_tag('input', array('type'=>'radio', 'name'=>'preset_time', 'id'=>'pt_wknow', 'value'=>'weeknow', 'checked'=>'checked'));
64 $output .= html_writer::tag('label', get_string('weekthis', 'calendar'), array('for'=>'pt_wknow'));
65 $output .= html_writer::empty_tag('br');
68 $output .= html_writer::empty_tag('input', array('type'=>'radio', 'name'=>'preset_time', 'id'=>'pt_wknext', 'value'=>'weeknext'));
69 $output .= html_writer::tag('label', get_string('weeknext', 'calendar'), array('for'=>'pt_wknext'));
70 $output .= html_writer::empty_tag('br');
72 $output .= html_writer::empty_tag('input', array('type'=>'radio', 'name'=>'preset_time', 'id'=>'pt_monnow', 'value'=>'monthnow'));
73 $output .= html_writer::tag('label', get_string('monththis', 'calendar'), array('for'=>'pt_monnow'));
74 $output .= html_writer::empty_tag('br');
75 if ($allownextmonth) {
76 $output .= html_writer::empty_tag('input', array('type'=>'radio', 'name'=>'preset_time', 'id'=>'pt_monnext', 'value'=>'monthnext'));
77 $output .= html_writer::tag('label', get_string('monthnext', 'calendar'), array('for'=>'pt_monnext'));
78 $output .= html_writer::empty_tag('br');
80 $output .= html_writer::empty_tag('input', array('type'=>'radio', 'name'=>'preset_time', 'id'=>'pt_recupc', 'value'=>'recentupcoming'));
81 $output .= html_writer::tag('label', get_string('recentupcoming', 'calendar'), array('for'=>'pt_recupc'));
82 $output .= html_writer::empty_tag('br');
83 $output .= html_writer::end_tag('div');
85 $output .= html_writer::start_tag('div', array('class'=>'rightalign'));
86 $output .= html_writer::empty_tag('input', array('type'=>'hidden', 'name'=>'cal_d', 'value'=>''));
87 $output .= html_writer::empty_tag('input', array('type'=>'hidden', 'name'=>'cal_m', 'value'=>''));
88 $output .= html_writer::empty_tag('input', array('type'=>'hidden', 'name'=>'cal_y', 'value'=>''));
89 $output .= html_writer::empty_tag('input', array('type'=>'hidden', 'name'=>'username', 'value'=>$username));
90 $output .= html_writer::empty_tag('input', array('type'=>'hidden', 'name'=>'authtoken', 'value'=>$authtoken));
92 $output .= html_writer::empty_tag('input', array('type'=>'button', 'id'=>'generateurl', 'value'=>get_string('generateurlbutton', 'calendar')));
93 $output .= html_writer::empty_tag('input', array('type'=>'submit', 'value'=>get_string('exportbutton', 'calendar')));
95 $output .= html_writer::end_tag('div');
97 $output .= html_writer::end_tag('form');
98 $output .= html_writer::end_tag('fieldset');
100 $output .= html_writer::start_tag('div', array('id'=>'urlbox', 'style'=>'display:none;'));
101 $output .= html_writer::tag('p', get_string('urlforical', 'calendar'));
102 $output .= html_writer::tag('div', '', array('id'=>'url', 'style'=>'overflow:scroll;width:650px;'));
103 $output .= html_writer::end_tag('div');
105 $this->page->requires->yui_module('moodle-calendar-eventmanager', 'M.core_calendar.init_basic_export', array($allowthisweek, $allownextweek, $allownextmonth, $username, $authtoken));
111 * Starts the standard layout for the page
115 public function start_layout() {
116 return html_writer::start_tag('div', array('class'=>'maincalendar'));
120 * Creates the remainder of the layout
124 public function complete_layout() {
125 return html_writer::end_tag('div');
129 * Produces the content for the filters block (pretend block)
131 * @param int $courseid
136 * @param int $courses
139 public function fake_block_filters($courseid, $day, $month, $year, $view, $courses) {
140 return html_writer::tag('div', calendar_filter_controls($this->page->url), array('class'=>'calendar_filters filters'));
144 * Produces the content for the three months block (pretend block)
146 * This includes the previous month, the current month, and the next month
148 * @param calendar_information $calendar
151 public function fake_block_threemonths(calendar_information $calendar) {
153 list($prevmon, $prevyr) = calendar_sub_month($calendar->month, $calendar->year);
154 list($nextmon, $nextyr) = calendar_add_month($calendar->month, $calendar->year);
156 $content = html_writer::start_tag('div', array('class'=>'minicalendarblock'));
157 $content .= calendar_top_controls('display', array('id' => $calendar->courseid, 'm' => $prevmon, 'y' => $prevyr));
158 $content .= calendar_get_mini($calendar->courses, $calendar->groups, $calendar->users, $prevmon, $prevyr);
159 $content .= html_writer::end_tag('div');
160 $content .= html_writer::start_tag('div', array('class'=>'minicalendarblock'));
161 $content .= calendar_top_controls('display', array('id' => $calendar->courseid, 'm' => $calendar->month, 'y' => $calendar->year));
162 $content .= calendar_get_mini($calendar->courses, $calendar->groups, $calendar->users, $calendar->month, $calendar->year);
163 $content .= html_writer::end_tag('div');
164 $content .= html_writer::start_tag('div', array('class'=>'minicalendarblock'));
165 $content .= calendar_top_controls('display', array('id' => $calendar->courseid, 'm' => $nextmon, 'y' => $nextyr));
166 $content .= calendar_get_mini($calendar->courses, $calendar->groups, $calendar->users, $nextmon, $nextyr);
167 $content .= html_writer::end_tag('div');
172 * Adds a pretent calendar block
174 * @param block_contents $bc
175 * @param mixed $pos BLOCK_POS_RIGHT | BLOCK_POS_LEFT
177 public function add_pretend_calendar_block(block_contents $bc, $pos=BLOCK_POS_RIGHT) {
178 $this->page->blocks->add_fake_block($bc, $pos);
182 * Creates a button to add a new event
184 * @param int $courseid
190 protected function add_event_button($courseid, $day=null, $month=null, $year=null) {
191 $output = html_writer::start_tag('div', array('class'=>'buttons'));
192 $output .= html_writer::start_tag('form', array('action'=>CALENDAR_URL.'event.php', 'method'=>'get'));
193 $output .= html_writer::start_tag('div');
194 $output .= html_writer::empty_tag('input', array('type'=>'hidden', 'name'=>'action', 'value'=>'new'));
195 $output .= html_writer::empty_tag('input', array('type'=>'hidden', 'name'=>'course', 'value'=>$courseid));
197 $output .= html_writer::empty_tag('input', array('type'=>'hidden', 'name'=>'cal_d', 'value'=>$day));
199 if ($month !== null) {
200 $output .= html_writer::empty_tag('input', array('type'=>'hidden', 'name'=>'cal_m', 'value'=>$month));
202 if ($year !== null) {
203 $output .= html_writer::empty_tag('input', array('type'=>'hidden', 'name'=>'cal_y', 'value'=>$year));
205 $output .= html_writer::empty_tag('input', array('type'=>'submit', 'value'=>get_string('newevent', 'calendar')));
206 $output .= html_writer::end_tag('div');
207 $output .= html_writer::end_tag('form');
208 $output .= html_writer::end_tag('div');
213 * Displays the calendar for a single day
215 * @param calendar_information $calendar
218 public function show_day(calendar_information $calendar, moodle_url $returnurl = null) {
220 if ($returnurl === null) {
221 $returnurl = $this->page->url;
224 $calendar->checkdate();
225 $events = calendar_get_upcoming($calendar->courses, $calendar->groups, $calendar->users, 1, 100, $calendar->timestamp_today());
227 $output = html_writer::start_tag('div', array('class'=>'header'));
228 if (calendar_user_can_add_event($calendar->course)) {
229 $output .= $this->add_event_button($calendar->course->id, $calendar->day, $calendar->month, $calendar->year);
231 //$output .= html_writer::tag('label', get_string('dayview', 'calendar'), array('for'=>'cal_course_flt_jump'));
232 $output .= $this->course_filter_selector($returnurl, get_string('dayview', 'calendar'));
233 $output .= html_writer::end_tag('div');
235 $output .= html_writer::tag('div', calendar_top_controls('day', array('id' => $calendar->courseid, 'd' => $calendar->day, 'm' => $calendar->month, 'y' => $calendar->year)), array('class'=>'controls'));
237 if (empty($events)) {
238 // There is nothing to display today.
239 $output .= $this->output->heading(get_string('daywithnoevents', 'calendar'), 3);
241 $output .= html_writer::start_tag('div', array('class'=>'eventlist'));
243 // First, print details about events that start today
244 foreach ($events as $event) {
245 $event = new calendar_event($event);
246 $event->calendarcourseid = $calendar->courseid;
247 if ($event->timestart >= $calendar->timestamp_today() && $event->timestart <= $calendar->timestamp_tomorrow()-1) { // Print it now
248 $event->time = calendar_format_event_time($event, time(), null, false, $calendar->timestamp_today());
249 $output .= $this->event($event);
250 } else { // Save this for later
251 $underway[] = $event;
255 // Then, show a list of all events that just span this day
256 if (!empty($underway)) {
257 $output .= $this->output->heading(get_string('spanningevents', 'calendar'), 3);
258 foreach ($underway as $event) {
259 $event->time = calendar_format_event_time($event, time(), null, false, $calendar->timestamp_today());
260 $output .= $this->event($event);
264 $output .= html_writer::end_tag('div');
273 * @param calendar_event $event
274 * @param bool $showactions
277 public function event(calendar_event $event, $showactions=true) {
278 $event = calendar_add_event_metadata($event);
280 $anchor = html_writer::tag('a', '', array('name'=>'event_'.$event->id));
282 $table = new html_table();
283 $table->attributes = array('class'=>'event', 'cellspacing'=>'0');
284 $table->data = array(
285 0 => new html_table_row(),
286 1 => new html_table_row(),
289 if (!empty($event->icon)) {
290 $table->data[0]->cells[0] = new html_table_cell($anchor.$event->icon);
292 $table->data[0]->cells[0] = new html_table_cell($anchor.$this->output->spacer(array('height'=>16, 'width'=>16, 'br'=>true)));
294 $table->data[0]->cells[0]->attributes['class'] .= ' picture';
296 $table->data[0]->cells[1] = new html_table_cell();
297 $table->data[0]->cells[1]->attributes['class'] .= ' topic';
298 if (!empty($event->referer)) {
299 $table->data[0]->cells[1]->text .= html_writer::tag('div', $event->referer, array('class'=>'referer'));
301 $table->data[0]->cells[1]->text .= html_writer::tag('div', $event->name, array('class'=>'name'));
303 if (!empty($event->courselink)) {
304 $table->data[0]->cells[1]->text .= html_writer::tag('div', $event->courselink, array('class'=>'course'));
306 if (!empty($event->time)) {
307 $table->data[0]->cells[1]->text .= html_writer::tag('span', $event->time, array('class'=>'date'));
309 $table->data[0]->cells[1]->text .= html_writer::tag('span', calendar_time_representation($event->timestart), array('class'=>'date'));
312 $table->data[1]->cells[0] = new html_table_cell(' ');
313 $table->data[1]->cells[0]->attributes['class'] .= 'side';
315 $table->data[1]->cells[1] = new html_table_cell($event->description);
316 $table->data[1]->cells[1]->attributes['class'] .= ' description';
317 if (isset($event->cssclass)) {
318 $table->data[1]->cells[1]->attributes['class'] .= ' '.$event->cssclass;
321 if (calendar_edit_event_allowed($event) && $showactions) {
322 if (empty($event->cmid)) {
323 $editlink = new moodle_url(CALENDAR_URL.'event.php', array('action'=>'edit', 'id'=>$event->id));
324 $deletelink = new moodle_url(CALENDAR_URL.'delete.php', array('id'=>$event->id));
325 if (!empty($event->calendarcourseid)) {
326 $editlink->param('course', $event->calendarcourseid);
327 $deletelink->param('course', $event->calendarcourseid);
330 $editlink = new moodle_url('/course/mod.php', array('update'=>$event->cmid, 'return'=>true, 'sesskey'=>sesskey()));
334 $commands = html_writer::start_tag('div', array('class'=>'commands'));
335 $commands .= html_writer::start_tag('a', array('href'=>$editlink));
336 $commands .= html_writer::empty_tag('img', array('src'=>$this->output->pix_url('t/edit'), 'alt'=>get_string('tt_editevent', 'calendar'), 'title'=>get_string('tt_editevent', 'calendar')));
337 $commands .= html_writer::end_tag('a');
338 if ($deletelink != null) {
339 $commands .= html_writer::start_tag('a', array('href'=>$deletelink));
340 $commands .= html_writer::empty_tag('img', array('src'=>$this->output->pix_url('t/delete'), 'alt'=>get_string('tt_deleteevent', 'calendar'), 'title'=>get_string('tt_deleteevent', 'calendar')));
341 $commands .= html_writer::end_tag('a');
343 $commands .= html_writer::end_tag('div');
344 $table->data[1]->cells[1]->text .= $commands;
346 return html_writer::table($table);
350 * Displays a month in detail
352 * @param calendar_information $calendar
355 public function show_month_detailed(calendar_information $calendar, moodle_url $returnurl = null) {
358 if (empty($returnurl)) {
359 $returnurl = $this->page->url;
362 $date = usergetdate(time());
364 $display = new stdClass;
365 $display->minwday = get_user_preferences('calendar_startwday', calendar_get_starting_weekday());
366 $display->maxwday = $display->minwday + 6;
367 $display->thismonth = ($date['mon'] == $calendar->month);
368 $display->maxdays = calendar_days_in_month($calendar->month, $calendar->year);
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, $calendar->month, 1, $calendar->year); // This is GMT
374 $display->tend = gmmktime(23, 59, 59, $calendar->month, $display->maxdays, $calendar->year); // GMT
375 $startwday = gmdate('w', $display->tstart); // $display->tstart is already GMT, so don't use date(): messes with server's TZ
377 // no timezone info specified
378 $display->tstart = mktime(0, 0, 0, $calendar->month, 1, $calendar->year);
379 $display->tend = mktime(23, 59, 59, $calendar->month, $display->maxdays, $calendar->year);
380 $startwday = date('w', $display->tstart); // $display->tstart not necessarily GMT, so use date()
383 // Align the starting weekday to fall in our display range
384 if ($startwday < $display->minwday) {
388 // Get events from database
389 $events = calendar_get_events(usertime($display->tstart), usertime($display->tend), $calendar->users, $calendar->groups, $calendar->courses);
390 if (!empty($events)) {
391 foreach($events as $eventid => $event) {
392 $event = new calendar_event($event);
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]);
402 // Extract information: events vs. time
403 calendar_events_by_day($events, $calendar->month, $calendar->year, $eventsbyday, $durationbyday, $typesbyday, $calendar->courses);
405 $output = html_writer::start_tag('div', array('class'=>'header'));
406 if (calendar_user_can_add_event($calendar->course)) {
407 $output .= $this->add_event_button($calendar->course->id, null, $calendar->month, $calendar->year);
409 $output .= get_string('detailedmonthview', 'calendar').': '.$this->course_filter_selector($returnurl);
410 $output .= html_writer::end_tag('div', array('class'=>'header'));
412 $output .= html_writer::tag('div', calendar_top_controls('month', array('id' => $calendar->courseid, 'm' => $calendar->month, 'y' => $calendar->year)), array('class'=>'controls'));
414 $days = calendar_get_days();
416 $table = new html_table();
417 $table->attributes = array('class'=>'calendarmonth calendartable');
418 $table->data = array();
420 $header = new html_table_row();
421 $header->attributes = array('class'=>'weekdays');
422 $header->cells = array();
423 for($i = $display->minwday; $i <= $display->maxwday; ++$i) {
424 // This uses the % operator to get the correct weekday no matter what shift we have
425 // applied to the $display->minwday : $display->maxwday range from the default 0 : 6
426 $cell = new html_table_cell(get_string($days[$i % 7], 'calendar'));
427 $cell->header = true;
428 $header->cells[] = $cell;
431 // For the table display. $week is the row; $dayweek is the column.
433 $dayweek = $startwday;
435 $row = new html_table_row(array());
436 // Paddding (the first week may have blank days in the beginning)
437 for($i = $display->minwday; $i < $startwday; ++$i) {
438 $cell = new html_table_cell(' ');
439 $cell->attributes = array('class'=>'nottoday');
440 $row->cells[] = $cell;
443 // Now display all the calendar
444 $weekend = CALENDAR_DEFAULT_WEEKEND;
445 if (isset($CFG->calendar_weekend)) {
446 $weekend = intval($CFG->calendar_weekend);
449 for ($calendar->day = 1; $calendar->day <= $display->maxdays; ++$calendar->day, ++$dayweek) {
450 if($dayweek > $display->maxwday) {
451 // We need to change week (table row)
452 $table->data[] = $row;
453 $row = new html_table_row(array());
454 $dayweek = $display->minwday;
459 $cell = new html_table_cell();
460 $dayhref = calendar_get_link_href(new moodle_url(CALENDAR_URL.'view.php', array('view'=>'day', 'course'=>$calendar->courseid)), $calendar->day, $calendar->month, $calendar->year);
462 $cellclasses = array();
464 if ($weekend & (1 << ($dayweek % 7))) {
465 // Weekend. This is true no matter what the exact range is.
466 $cellclasses[] = 'weekend';
469 // Special visual fx if an event is defined
470 if (isset($eventsbyday[$calendar->day])) {
471 if(count($eventsbyday[$calendar->day]) == 1) {
472 $title = get_string('oneevent', 'calendar');
474 $title = get_string('manyevents', 'calendar', count($eventsbyday[$calendar->day]));
476 $cell->text = html_writer::tag('div', html_writer::link($dayhref, $calendar->day, array('title'=>$title)), array('class'=>'day'));
478 $cell->text = html_writer::tag('div', $calendar->day, array('class'=>'day'));
481 // Special visual fx if an event spans many days
482 $durationclass = false;
483 if (isset($typesbyday[$calendar->day]['durationglobal'])) {
484 $durationclass = 'duration_global';
485 } else if (isset($typesbyday[$calendar->day]['durationcourse'])) {
486 $durationclass = 'duration_course';
487 } else if (isset($typesbyday[$calendar->day]['durationgroup'])) {
488 $durationclass = 'duration_group';
489 } else if (isset($typesbyday[$calendar->day]['durationuser'])) {
490 $durationclass = 'duration_user';
492 if ($durationclass) {
493 $cellclasses[] = 'duration';
494 $cellclasses[] = $durationclass;
497 // Special visual fx for today
498 if($display->thismonth && $calendar->day == $calendar->day) {
499 $cellclasses[] = 'today';
501 $cellclasses[] = 'nottoday';
503 $cell->attributes = array('class'=>join(' ',$cellclasses));
505 if (isset($eventsbyday[$calendar->day])) {
506 $cell->text .= html_writer::start_tag('ul', array('class'=>'events-new'));
507 foreach($eventsbyday[$calendar->day] as $eventindex) {
508 // If event has a class set then add it to the event <li> tag
509 $attributes = array();
510 if (!empty($events[$eventindex]->class)) {
511 $attributes['class'] = $events[$eventindex]->class;
513 $dayhref->set_anchor('event_'.$events[$eventindex]->id);
514 $link = html_writer::link($dayhref, format_string($events[$eventindex]->name, true));
515 $cell->text .= html_writer::tag('li', $link, $attributes);
517 $cell->text .= html_writer::end_tag('ul');
519 if (isset($durationbyday[$calendar->day])) {
520 $cell->text .= html_writer::start_tag('ul', array('class'=>'events-underway'));
521 foreach($durationbyday[$calendar->day] as $eventindex) {
522 $cell->text .= html_writer::tag('li', '['.format_string($events[$eventindex]->name,true).']', array('class'=>'events-underway'));
524 $cell->text .= html_writer::end_tag('ul');
526 $row->cells[] = $cell;
529 // Paddding (the last week may have blank days at the end)
530 for($i = $dayweek; $i <= $display->maxwday; ++$i) {
531 $cell = new html_table_cell(' ');
532 $cell->attributes = array('class'=>'nottoday');
533 $row->cells[] = $cell;
535 $table->data[] = $row;
536 $output .= html_writer::table($table);
538 // OK, now for the filtering display
539 $output .= $this->filter_selection_table($calendar);
544 * Displays a filter selection table
546 * @param calendar_information $calendar
549 protected function filter_selection_table(calendar_information $calendar, moodle_url $returnurl = null) {
552 if ($returnurl === null) {
553 $returnurl = $this->page->url;
556 $output = html_writer::start_tag('div', array('class'=>'filters'));
557 $output .= html_writer::start_tag('table');
558 $output .= html_writer::start_tag('tr');
561 $link = new moodle_url(CALENDAR_URL.'set.php', array('var' => 'showglobal', 'return' => $returnurl));
562 if (calendar_show_event_type(CALENDAR_EVENT_GLOBAL)) {
563 $output .= html_writer::tag('td', '', array('class'=>'calendar_event_global', 'style'=>'width:8px;'));
564 $output .= html_writer::tag('td', html_writer::tag('strong', get_string('globalevents', 'calendar')).' '.get_string('shown', 'calendar').' ('.html_writer::link($link, get_string('clickhide', 'calendar')).')');
566 $output .= html_writer::tag('td', '', array('style'=>'width:8px;'));
567 $output .= html_writer::tag('td', html_writer::tag('strong', get_string('globalevents', 'calendar')).' '.get_string('hidden', 'calendar').' ('.html_writer::link($link, get_string('clickshow', 'calendar')).')');
571 $link = new moodle_url(CALENDAR_URL.'set.php', array('var'=>'showcourses', 'return' => $returnurl));
572 if (calendar_show_event_type(CALENDAR_EVENT_COURSE)) {
573 $output .= html_writer::tag('td', '', array('class'=>'calendar_event_course', 'style'=>'width:8px;'));
574 $output .= html_writer::tag('td', html_writer::tag('strong', get_string('courseevents', 'calendar')).' '.get_string('shown', 'calendar').' ('.html_writer::link($link, get_string('clickhide', 'calendar')).')');
576 $output .= html_writer::tag('td', '', array('style'=>'width:8px;'));
577 $output .= html_writer::tag('td', html_writer::tag('strong', get_string('courseevents', 'calendar')).' '.get_string('hidden', 'calendar').' ('.html_writer::link($link, get_string('clickshow', 'calendar')).')');
579 $output .= html_writer::end_tag('tr');
581 if(isloggedin() && !isguestuser()) {
582 $output .= html_writer::start_tag('tr');
584 $link = new moodle_url(CALENDAR_URL.'set.php', array('var'=>'showgroups', 'return' => $returnurl));
585 if (calendar_show_event_type(CALENDAR_EVENT_GROUP)) {
586 $output .= html_writer::tag('td', '', array('class'=>'calendar_event_group', 'style'=>'width:8px;'));
587 $output .= html_writer::tag('td', html_writer::tag('strong', get_string('groupevents', 'calendar')).' '.get_string('shown', 'calendar').' ('.html_writer::link($link, get_string('clickhide', 'calendar')).')');
589 $output .= html_writer::tag('td', '', array('style'=>'width:8px;'));
590 $output .= html_writer::tag('td', html_writer::tag('strong', get_string('groupevents', 'calendar')).' '.get_string('hidden', 'calendar').' ('.html_writer::link($link, get_string('clickshow', 'calendar')).')');
593 $link = new moodle_url(CALENDAR_URL.'set.php', array('var'=>'showuser', 'return' => $returnurl));
594 if (calendar_show_event_type(CALENDAR_EVENT_USER)) {
595 $output .= html_writer::tag('td', '', array('class'=>'calendar_event_user', 'style'=>'width:8px;'));
596 $output .= html_writer::tag('td', html_writer::tag('strong', get_string('userevents', 'calendar')).' '.get_string('shown', 'calendar').' ('.html_writer::link($link, get_string('clickhide', 'calendar')).')');
598 $output .= html_writer::tag('td', '', array('style'=>'width:8px;'));
599 $output .= html_writer::tag('td', html_writer::tag('strong', get_string('userevents', 'calendar')).' '.get_string('hidden', 'calendar').' ('.html_writer::link($link, get_string('clickshow', 'calendar')).')');
601 $output .= html_writer::end_tag('tr');
603 $output .= html_writer::end_tag('table');
604 $output .= html_writer::end_tag('div');
609 * Displays upcoming events
611 * @param calendar_information $calendar
612 * @param int $futuredays
613 * @param int $maxevents
616 public function show_upcoming_events(calendar_information $calendar, $futuredays, $maxevents, moodle_url $returnurl = null) {
618 if ($returnurl === null) {
619 $returnurl = $this->page->url;
622 $events = calendar_get_upcoming($calendar->courses, $calendar->groups, $calendar->users, $futuredays, $maxevents);
624 $output = html_writer::start_tag('div', array('class'=>'header'));
625 if (calendar_user_can_add_event($calendar->course)) {
626 $output .= $this->add_event_button($calendar->course->id);
628 $output .= html_writer::tag('label', get_string('upcomingevents', 'calendar'), array('for'=>'cal_course_flt_jump'));
629 $output .= $this->course_filter_selector($returnurl);
630 $output .= html_writer::end_tag('div');
633 $output .= html_writer::start_tag('div', array('class'=>'eventlist'));
634 foreach ($events as $event) {
635 // Convert to calendar_event object so that we transform description
637 $event = new calendar_event($event);
638 $event->calendarcourseid = $calendar->courseid;
639 $output .= $this->event($event);
641 $output .= html_writer::end_tag('div');
643 $output .= $this->output->heading(get_string('noupcomingevents', 'calendar'));
650 * Displays a course filter selector
652 * @param array $getvars
655 protected function course_filter_selector(moodle_url $returnurl, $label=null) {
656 global $USER, $SESSION, $CFG;
658 if (!isloggedin() or isguestuser()) {
662 if (has_capability('moodle/calendar:manageentries', get_context_instance(CONTEXT_SYSTEM)) && !empty($CFG->calendar_adminseesall)) {
663 $courses = get_courses('all', 'c.shortname','c.id,c.shortname');
665 $courses = enrol_get_my_courses();
668 unset($courses[SITEID]);
670 $courseoptions = array();
671 $courseoptions[SITEID] = get_string('fulllistofcourses');
672 foreach ($courses as $course) {
673 $courseoptions[$course->id] = format_string($course->shortname);
676 if ($this->page->course->id !== SITEID) {
677 $selected = $this->page->course->id;
681 $select = new single_select(new moodle_url(CALENDAR_URL.'set.php', array('return' => $returnurl, 'var' => 'setcourse')), 'id', $courseoptions, $selected, null);
682 $select->class = 'cal_courses_flt';
683 if ($label !== null) {
684 $select->label = $label;
686 return $this->output->render($select);