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 $getvars = 'id='.$courseid.'&cal_d='.$day.'&cal_m='.$month.'&cal_y='.$year;
141 return html_writer
::tag('div', calendar_filter_controls($view, $getvars, NULL, $courses), array('class'=>'calendar_filters filters'));
145 * Produces the content for the three months block (pretend block)
147 * This includes the previous month, the current month, and the next month
149 * @param calendar_information $calendar
152 public function fake_block_threemonths(calendar_information
$calendar) {
154 list($prevmon, $prevyr) = calendar_sub_month($calendar->month
, $calendar->year
);
155 list($nextmon, $nextyr) = calendar_add_month($calendar->month
, $calendar->year
);
157 $content = html_writer
::start_tag('div', array('class'=>'minicalendarblock'));
158 $content .= calendar_top_controls('display', array('id' => $calendar->courseid
, 'm' => $prevmon, 'y' => $prevyr));
159 $content .= calendar_get_mini($calendar->courses
, $calendar->groups
, $calendar->users
, $prevmon, $prevyr);
160 $content .= html_writer
::end_tag('div');
161 $content .= html_writer
::start_tag('div', array('class'=>'minicalendarblock'));
162 $content .= calendar_top_controls('display', array('id' => $calendar->courseid
, 'm' => $calendar->month
, 'y' => $calendar->year
));
163 $content .= calendar_get_mini($calendar->courses
, $calendar->groups
, $calendar->users
, $calendar->month
, $calendar->year
);
164 $content .= html_writer
::end_tag('div');
165 $content .= html_writer
::start_tag('div', array('class'=>'minicalendarblock'));
166 $content .= calendar_top_controls('display', array('id' => $calendar->courseid
, 'm' => $nextmon, 'y' => $nextyr));
167 $content .= calendar_get_mini($calendar->courses
, $calendar->groups
, $calendar->users
, $nextmon, $nextyr);
168 $content .= html_writer
::end_tag('div');
173 * Adds a pretent calendar block
175 * @param block_contents $bc
176 * @param mixed $pos BLOCK_POS_RIGHT | BLOCK_POS_LEFT
178 public function add_pretend_calendar_block(block_contents
$bc, $pos=BLOCK_POS_RIGHT
) {
179 $this->page
->blocks
->add_pretend_block($bc, $pos);
183 * Creates a button to add a new event
185 * @param int $courseid
191 protected function add_event_button($courseid, $day=null, $month=null, $year=null) {
192 $output = html_writer
::start_tag('div', array('class'=>'buttons'));
193 $output .= html_writer
::start_tag('form', array('action'=>CALENDAR_URL
.'event.php', 'method'=>'get'));
194 $output .= html_writer
::start_tag('div');
195 $output .= html_writer
::empty_tag('input', array('type'=>'hidden', 'name'=>'action', 'value'=>'new'));
196 $output .= html_writer
::empty_tag('input', array('type'=>'hidden', 'name'=>'course', 'value'=>$courseid));
198 $output .= html_writer
::empty_tag('input', array('type'=>'hidden', 'name'=>'cal_d', 'value'=>$day));
200 if ($month !== null) {
201 $output .= html_writer
::empty_tag('input', array('type'=>'hidden', 'name'=>'cal_m', 'value'=>$month));
203 if ($year !== null) {
204 $output .= html_writer
::empty_tag('input', array('type'=>'hidden', 'name'=>'cal_y', 'value'=>$year));
206 $output .= html_writer
::empty_tag('input', array('type'=>'submit', 'value'=>get_string('newevent', 'calendar')));
207 $output .= html_writer
::end_tag('div');
208 $output .= html_writer
::end_tag('form');
209 $output .= html_writer
::end_tag('div');
214 * Displays the calendar for a single day
216 * @param calendar_information $calendar
219 public function show_day(calendar_information
$calendar) {
220 $calendar->checkdate();
221 $events = calendar_get_upcoming($calendar->courses
, $calendar->groups
, $calendar->users
, 1, 100, $calendar->timestamp_today());
223 $output = html_writer
::start_tag('div', array('class'=>'header'));
224 if (!isguestuser() && isloggedin() && calendar_user_can_add_event()) {
225 $output .= $this->add_event_button($calendar->courseid
, $calendar->day
, $calendar->month
, $calendar->year
);
227 //$output .= html_writer::tag('label', get_string('dayview', 'calendar'), array('for'=>'cal_course_flt_jump'));
228 $output .= $this->course_filter_selector(array('from'=>'day', 'cal_d'=>$calendar->day
, 'cal_m'=>$calendar->month
, 'cal_y'=>$calendar->year
), get_string('dayview', 'calendar'));
229 $output .= html_writer
::end_tag('div');
231 $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'));
233 if (empty($events)) {
234 // There is nothing to display today.
235 $output .= $this->output
->heading(get_string('daywithnoevents', 'calendar'), 3);
237 $output .= html_writer
::start_tag('div', array('class'=>'eventlist'));
239 // First, print details about events that start today
240 foreach ($events as $event) {
241 $event = new calendar_event($event);
242 $event->calendarcourseid
= $calendar->courseid
;
243 if ($event->timestart
>= $calendar->timestamp_today() && $event->timestart
<= $calendar->timestamp_tomorrow()-1) { // Print it now
244 $event->time
= calendar_format_event_time($event, time(), '', false, $calendar->timestamp_today());
245 $output .= $this->event($event);
246 } else { // Save this for later
247 $underway[] = $event;
251 // Then, show a list of all events that just span this day
252 if (!empty($underway)) {
253 $output .= $this->output
->heading(get_string('spanningevents', 'calendar'), 3);
254 foreach ($underway as $event) {
255 $event->time
= calendar_format_event_time($event, time(), '', false, $calendar->timestamp_today());
256 $output .= $this->event($event);
260 $output .= html_writer
::end_tag('div');
269 * @param calendar_event $event
270 * @param bool $showactions
273 public function event(calendar_event
$event, $showactions=true) {
274 $event = calendar_add_event_metadata($event);
276 $output = html_writer
::tag('a', '', array('name'=>'event_'.$event->id
));
278 $table = new html_table();
279 $table->attributes
= array('class'=>'event', 'cellspacing'=>'0');
280 $table->data
= array(
281 0 => new html_table_row(),
282 1 => new html_table_row(),
285 if (!empty($event->icon
)) {
286 $table->data
[0]->cells
[0] = new html_table_cell($event->icon
);
288 $table->data
[0]->cells
[0] = new html_table_cell($this->output
->spacer(array('height'=>16, 'width'=>16, 'br'=>true)));
290 $table->data
[0]->cells
[0]->attributes
['class'] .= ' picture';
292 $table->data
[0]->cells
[1] = new html_table_cell();
293 $table->data
[0]->cells
[1]->attributes
['class'] .= ' topic';
294 if (!empty($event->referer
)) {
295 $table->data
[0]->cells
[1]->text
.= html_writer
::tag('div', $event->referer
, array('class'=>'referer'));
297 $table->data
[0]->cells
[1]->text
.= html_writer
::tag('div', $event->name
, array('class'=>'name'));
299 if (!empty($event->courselink
)) {
300 $table->data
[0]->cells
[1]->text
.= html_writer
::tag('div', $event->courselink
, array('class'=>'course'));
302 if (!empty($event->time
)) {
303 $table->data
[0]->cells
[1]->text
.= html_writer
::tag('span', $event->time
, array('class'=>'date'));
305 $table->data
[0]->cells
[1]->text
.= html_writer
::tag('span', calendar_time_representation($event->timestart
), array('class'=>'date'));
308 $table->data
[1]->cells
[0] = new html_table_cell(' ');
309 $table->data
[1]->cells
[0]->attributes
['class'] .= 'side';
311 $table->data
[1]->cells
[1] = new html_table_cell($event->description
);
312 $table->data
[1]->cells
[1]->attributes
['class'] .= ' description';
313 if (isset($event->cssclass
)) {
314 $table->data
[1]->cells
[1]->attributes
['class'] .= ' '.$event->cssclass
;
317 if (calendar_edit_event_allowed($event) && $showactions) {
318 if (empty($event->cmid
)) {
319 $editlink = new moodle_url(CALENDAR_URL
.'event.php', array('action'=>'edit', 'id'=>$event->id
));
320 $deletelink = new moodle_url(CALENDAR_URL
.'delete.php', array('id'=>$event->id
));
321 if (!empty($event->calendarcourseid
)) {
322 $editlink->param('course', $event->calendarcourseid
);
323 $deletelink->param('course', $event->calendarcourseid
);
326 $editlink = new moodle_url('/course/mod.php', array('update'=>$event->cmid
, 'return'=>true, 'sesskey'=>sesskey()));
330 $commands = html_writer
::start_tag('div', array('class'=>'commands'));
331 $commands .= html_writer
::start_tag('a', array('href'=>$editlink));
332 $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')));
333 $commands .= html_writer
::end_tag('a');
334 if ($deletelink != null) {
335 $commands .= html_writer
::start_tag('a', array('href'=>$deletelink));
336 $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')));
337 $commands .= html_writer
::end_tag('a');
339 $commands .= html_writer
::end_tag('div');
340 $table->data
[1]->cells
[1]->text
.= $commands;
342 return html_writer
::table($table);
346 * Displays a month in detail
348 * @global array $CALENDARDAYS
349 * @param calendar_information $calendar
352 public function show_month_detailed(calendar_information
$calendar) {
353 global $CALENDARDAYS;
355 $date = usergetdate(time());
356 list($d, $m, $y) = array($date['mday'], $date['mon'], $date['year']); // This is what we want to display
358 $display = new stdClass
;
359 $display->minwday
= get_user_preferences('calendar_startwday', calendar_get_starting_weekday());
360 $display->maxwday
= $display->minwday +
6;
361 $display->thismonth
= true;
362 $display->maxdays
= calendar_days_in_month($m, $y);
365 if (get_user_timezone_offset() < 99) {
366 // We 'll keep these values as GMT here, and offset them when the time comes to query the db
367 $display->tstart
= gmmktime(0, 0, 0, $m, 1, $y); // This is GMT
368 $display->tend
= gmmktime(23, 59, 59, $m, $display->maxdays
, $y); // GMT
369 $startwday = gmdate('w', $display->tstart
); // $display->tstart is already GMT, so don't use date(): messes with server's TZ
371 // no timezone info specified
372 $display->tstart
= mktime(0, 0, 0, $m, 1, $y);
373 $display->tend
= mktime(23, 59, 59, $m, $display->maxdays
, $y);
374 $startwday = date('w', $display->tstart
); // $display->tstart not necessarily GMT, so use date()
377 // Align the starting weekday to fall in our display range
378 if ($startwday < $display->minwday
) {
382 // Get events from database
383 $events = calendar_get_events(usertime($display->tstart
), usertime($display->tend
), $calendar->users
, $calendar->groups
, $calendar->courses
);
384 if (!empty($events)) {
385 foreach($events as $eventid => $event) {
386 $event = new calendar_event($event);
387 if (!empty($event->modulename
)) {
388 $cm = get_coursemodule_from_instance($event->modulename
, $event->instance
);
389 if (!groups_course_module_visible($cm)) {
390 unset($events[$eventid]);
396 // Extract information: events vs. time
397 calendar_events_by_day($events, $m, $y, $eventsbyday, $durationbyday, $typesbyday, $calendar->courses
);
399 $output = html_writer
::start_tag('div', array('class'=>'header'));
400 if(!isguestuser() && isloggedin() && calendar_user_can_add_event()) {
401 $output .= $this->add_event_button($calendar->courseid
, null, $calendar->month
, $calendar->year
);
403 $output .= get_string('detailedmonthview', 'calendar').': '.$this->course_filter_selector(array('from'=>'month', 'cal_d'=>$calendar->day
, 'cal_m'=>$calendar->month
, 'cal_y'=>$calendar->year
));
404 $output .= html_writer
::end_tag('div', array('class'=>'header'));
406 $output .= html_writer
::tag('div', calendar_top_controls('day', array('id' => $calendar->courseid
, 'm' => $calendar->month
, 'y' => $calendar->year
)), array('class'=>'controls'));
408 $table = new html_table();
409 $table->attributes
= array('class'=>'calendarmonth calendartable');
410 $table->data
= array();
412 $header = new html_table_row();
413 $header->attributes
= array('class'=>'weekdays');
414 $header->cells
= array();
415 for($i = $display->minwday
; $i <= $display->maxwday
; ++
$i) {
416 // This uses the % operator to get the correct weekday no matter what shift we have
417 // applied to the $display->minwday : $display->maxwday range from the default 0 : 6
418 $cell = new html_table_cell(get_string($CALENDARDAYS[$i %
7], 'calendar'));
419 $cell->header
= true;
420 $header->cells
[] = $cell;
423 // For the table display. $week is the row; $dayweek is the column.
425 $dayweek = $startwday;
427 $row = new html_table_row(array());
428 // Paddding (the first week may have blank days in the beginning)
429 for($i = $display->minwday
; $i < $startwday; ++
$i) {
430 $cell = new html_table_cell(' ');
431 $cell->attributes
= array('class'=>'nottoday');
432 $row->cells
[] = $cell;
435 // Now display all the calendar
436 for ($calendar->day
= 1; $calendar->day
<= $display->maxdays
; ++
$calendar->day
, ++
$dayweek) {
437 if($dayweek > $display->maxwday
) {
438 // We need to change week (table row)
439 $table->data
[] = $row;
440 $row = new html_table_row(array());
441 $dayweek = $display->minwday
;
446 $cell = new html_table_cell();
447 $dayhref = calendar_get_link_href(CALENDAR_URL
.'view.php?view=day&course='.$calendar->courseid
.'&', $calendar->day
, $m, $y);
449 $cellclasses = array();
451 if(CALENDAR_WEEKEND
& (1 << ($dayweek %
7))) {
452 // Weekend. This is true no matter what the exact range is.
453 $cellclasses[] = 'weekend';
456 // Special visual fx if an event is defined
457 if (isset($eventsbyday[$calendar->day
])) {
458 if(count($eventsbyday[$calendar->day
]) == 1) {
459 $title = get_string('oneevent', 'calendar');
461 $title = get_string('manyevents', 'calendar', count($eventsbyday[$calendar->day
]));
463 $cell->text
= html_writer
::tag('div', html_writer
::link($dayhref, $calendar->day
, array('title'=>$title)), array('class'=>'day'));
465 $cell->text
= html_writer
::tag('div', $calendar->day
, array('class'=>'day'));
468 // Special visual fx if an event spans many days
469 $durationclass = false;
470 if (isset($typesbyday[$calendar->day
]['durationglobal'])) {
471 $durationclass = 'duration_global';
472 } else if (isset($typesbyday[$calendar->day
]['durationcourse'])) {
473 $durationclass = 'duration_course';
474 } else if (isset($typesbyday[$calendar->day
]['durationgroup'])) {
475 $durationclass = 'duration_group';
476 } else if (isset($typesbyday[$calendar->day
]['durationuser'])) {
477 $durationclass = 'duration_user';
479 if ($durationclass) {
480 $cellclasses[] = 'duration';
481 $cellclasses[] = $durationclass;
484 // Special visual fx for today
485 if($display->thismonth
&& $calendar->day
== $d) {
486 $cellclasses[] = 'today';
488 $cellclasses[] = 'nottoday';
490 $cell->attributes
= array('class'=>join(' ',$cellclasses));
492 if (isset($eventsbyday[$calendar->day
])) {
493 $cell->text
.= html_writer
::start_tag('ul', array('class'=>'events-new'));
494 foreach($eventsbyday[$calendar->day
] as $eventindex) {
495 // If event has a class set then add it to the event <li> tag
496 $attributes = array();
497 if (!empty($events[$eventindex]->class)) {
498 $attributes['class'] = $events[$eventindex]->class;
500 $link = html_writer
::link($dayhref.'#event_'.$events[$eventindex]->id
, format_string($events[$eventindex]->name
, true));
501 $cell->text
.= html_writer
::tag('li', $link, $attributes);
503 $cell->text
.= html_writer
::end_tag('ul');
505 if (isset($durationbyday[$calendar->day
])) {
506 $cell->text
.= html_writer
::start_tag('ul', array('class'=>'events-underway'));
507 foreach($durationbyday[$calendar->day
] as $eventindex) {
508 $cell->text
.= html_writer
::tag('li', '['.format_string($events[$eventindex]->name
,true).']', array('class'=>'events-underway'));
510 $cell->text
.= html_writer
::end_tag('ul');
512 $row->cells
[] = $cell;
515 // Paddding (the last week may have blank days at the end)
516 for($i = $dayweek; $i <= $display->maxwday
; ++
$i) {
517 $cell = new html_table_cell(' ');
518 $cell->attributes
= array('class'=>'nottoday');
519 $row->cells
[] = $cell;
521 $table->data
[] = $row;
522 $output .= html_writer
::table($table);
524 // OK, now for the filtering display
525 $output .= $this->filter_selection_table($calendar);
530 * Displays a filter selection table
532 * @param calendar_information $calendar
535 protected function filter_selection_table(calendar_information
$calendar) {
538 $output = html_writer
::start_tag('div', array('class'=>'filters'));
539 $output .= html_writer
::start_tag('table');
540 $output .= html_writer
::start_tag('tr');
543 $link = new moodle_url(CALENDAR_URL
.'set.php', array('var'=>'showglobal', 'from'=>'month', 'cal_d'=>$calendar->day
, 'cal_m'=>$calendar->month
, 'cal_y'=>$calendar->year
));
544 if($SESSION->cal_show_global
) {
545 $output .= html_writer
::tag('td', '', array('class'=>'calendar_event_global', 'style'=>'width:8px;'));
546 $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')).')');
548 $output .= html_writer
::tag('td', '', array('style'=>'width:8px;'));
549 $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')).')');
553 $link = new moodle_url(CALENDAR_URL
.'set.php', array('var'=>'showcourses', 'from'=>'month', 'cal_d'=>$calendar->day
, 'cal_m'=>$calendar->month
, 'cal_y'=>$calendar->year
));
554 if(!empty($SESSION->cal_show_course
)) {
555 $output .= html_writer
::tag('td', '', array('class'=>'calendar_event_course', 'style'=>'width:8px;'));
556 $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')).')');
558 $output .= html_writer
::tag('td', '', array('style'=>'width:8px;'));
559 $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')).')');
561 $output .= html_writer
::end_tag('tr');
563 if(isloggedin() && !isguestuser()) {
564 $output .= html_writer
::start_tag('tr');
566 $link = new moodle_url(CALENDAR_URL
.'set.php', array('var'=>'showgroups', 'from'=>'month', 'cal_d'=>$calendar->day
, 'cal_m'=>$calendar->month
, 'cal_y'=>$calendar->year
));
567 if($SESSION->cal_show_groups
) {
568 $output .= html_writer
::tag('td', '', array('class'=>'calendar_event_group', 'style'=>'width:8px;'));
569 $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')).')');
571 $output .= html_writer
::tag('td', '', array('style'=>'width:8px;'));
572 $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')).')');
575 $link = new moodle_url(CALENDAR_URL
.'set.php', array('var'=>'showuser', 'from'=>'month', 'cal_d'=>$calendar->day
, 'cal_m'=>$calendar->month
, 'cal_y'=>$calendar->year
));
576 if($SESSION->cal_show_user
) {
577 $output .= html_writer
::tag('td', '', array('class'=>'calendar_event_user', 'style'=>'width:8px;'));
578 $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')).')');
580 $output .= html_writer
::tag('td', '', array('style'=>'width:8px;'));
581 $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')).')');
583 $output .= html_writer
::end_tag('tr');
585 $output .= html_writer
::end_tag('table');
586 $output .= html_writer
::end_tag('div');
591 * Displays upcoming events
593 * @param calendar_information $calendar
594 * @param int $futuredays
595 * @param int $maxevents
598 public function show_upcoming_events(calendar_information
$calendar, $futuredays, $maxevents) {
599 $events = calendar_get_upcoming($calendar->courses
, $calendar->groups
, $calendar->users
, $futuredays, $maxevents);
601 $output = html_writer
::start_tag('div', array('class'=>'header'));
602 if (!isguestuser() && isloggedin() && calendar_user_can_add_event()) {
603 $output .= $this->add_event_button($calendar->courseid
);
605 $output .= html_writer
::tag('label', get_string('upcomingevents', 'calendar'), array('for'=>'cal_course_flt_jump'));
606 $output .= $this->course_filter_selector(array('from'=>'upcoming'));
607 $output .= html_writer
::end_tag('div');
610 $output .= html_writer
::start_tag('div', array('class'=>'eventlist'));
611 foreach ($events as $event) {
612 // Convert to calendar_event object so that we transform description
614 $event = new calendar_event($event);
615 $event->calendarcourseid
= $calendar->courseid
;
616 $output .= $this->event($event);
618 $output .= html_writer
::end_tag('div');
620 $output .= $this->output
->heading(get_string('noupcomingevents', 'calendar'));
627 * Displays a course filter selector
629 * @param array $getvars
632 protected function course_filter_selector(array $getvars = array(), $label=null) {
633 global $USER, $SESSION;
635 if (!isloggedin() or isguestuser()) {
639 if (has_capability('moodle/calendar:manageentries', get_context_instance(CONTEXT_SYSTEM
)) && !empty($CFG->calendar_adminseesall
)) {
640 $courses = get_courses('all', 'c.shortname','c.id,c.shortname');
642 $courses = enrol_get_my_courses();
645 unset($courses[SITEID
]);
647 $courseoptions = array();
648 $courseoptions[SITEID
] = get_string('fulllistofcourses');
649 foreach ($courses as $course) {
650 $courseoptions[$course->id
] = format_string($course->shortname
);
653 if (is_numeric($SESSION->cal_courses_shown
)) {
654 $selected = $SESSION->cal_courses_shown
;
658 $getvars['var'] = 'setcourse';
659 $select = new single_select(new moodle_url(CALENDAR_URL
.'set.php', $getvars), 'id', $courseoptions, $selected, null);
660 $select->class = 'cal_courses_flt';
661 if ($label !== null) {
662 $select->label
= $label;
664 return $this->output
->render($select);