-<?php // $Id$
+<?php
/////////////////////////////////////////////////////////////////////////////
// //
// //
/////////////////////////////////////////////////////////////////////////////
- require_once('../config.php');
- require_once($CFG->dirroot.'/calendar/lib.php');
- require_once($CFG->dirroot.'/course/lib.php');
- require_once($CFG->dirroot.'/mod/forum/lib.php');
-
- require_login();
-
- $action = required_param('action', PARAM_ALPHA);
- $eventid = optional_param('id', 0, PARAM_INT);
- $eventtype = optional_param('type', 'select', PARAM_ALPHA);
- $urlcourse = optional_param('course', 0, PARAM_INT);
- $cal_y = optional_param('cal_y', 0, PARAM_INT);
- $cal_m = optional_param('cal_m', 0, PARAM_INT);
- $cal_d = optional_param('cal_d', 0, PARAM_INT);
-
- $url = new moodle_url($CFG->wwwroot.'/calendar/event.php', array('action'=>$action));
- if ($eventid !== 0) $url->param('id', $eventid);
- if ($eventtype !== 'select') $url->param('type', $eventtype);
- if ($urlcourse !== 0) $url->param('course', $urlcourse);
- if ($cal_y !== 0) $url->param('cal_y', $cal_y);
- if ($cal_m !== 0) $url->param('cal_m', $cal_m);
- if ($cal_d !== 0) $url->param('cal_d', $cal_d);
- $PAGE->set_url($url);
-
- if(isguest()) {
- // Guests cannot do anything with events
- redirect(CALENDAR_URL.'view.php?view=upcoming&course='.$urlcourse);
- }
+/**
+ * This file is part of the User section Moodle
+ *
+ * @copyright 2003-2004 Jon Papaioannou (pj@moodle.org)
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v2 or later
+ * @package calendar
+ */
+
+require_once('../config.php');
+require_once($CFG->dirroot.'/calendar/lib.php');
+require_once($CFG->dirroot.'/course/lib.php');
+require_once($CFG->dirroot.'/mod/forum/lib.php');
+
+require_login();
+
+$action = required_param('action', PARAM_ALPHA);
+$eventid = optional_param('id', 0, PARAM_INT);
+$eventtype = optional_param('type', 'select', PARAM_ALPHA);
+$urlcourse = optional_param('course', 0, PARAM_INT);
+$cal_y = optional_param('cal_y', 0, PARAM_INT);
+$cal_m = optional_param('cal_m', 0, PARAM_INT);
+$cal_d = optional_param('cal_d', 0, PARAM_INT);
+
+$url = new moodle_url($CFG->wwwroot.'/calendar/event.php', array('action'=>$action));
+if ($eventid !== 0) $url->param('id', $eventid);
+if ($eventtype !== 'select') $url->param('type', $eventtype);
+if ($urlcourse !== 0) $url->param('course', $urlcourse);
+if ($cal_y !== 0) $url->param('cal_y', $cal_y);
+if ($cal_m !== 0) $url->param('cal_m', $cal_m);
+if ($cal_d !== 0) $url->param('cal_d', $cal_d);
+$PAGE->set_url($url);
+
+if (has_capability('moodle/legacy:guest', get_context_instance(CONTEXT_SYSTEM), 0, false)) {
+ // Guests cannot do anything with events
+ redirect(CALENDAR_URL.'view.php?view=upcoming&course='.$urlcourse);
+}
- $focus = '';
+$focus = '';
- if(!$site = get_site()) {
- redirect($CFG->wwwroot.'/'.$CFG->admin.'/index.php');
- }
+if(!$site = get_site()) {
+ redirect($CFG->wwwroot.'/'.$CFG->admin.'/index.php');
+}
- $strcalendar = get_string('calendar', 'calendar');
+$strcalendar = get_string('calendar', 'calendar');
- // Initialize the session variables
- calendar_session_vars();
+// Initialize the session variables
+calendar_session_vars();
- $now = usergetdate(time());
+$now = usergetdate(time());
- $day = intval($now['mday']);
- $mon = intval($now['mon']);
- $yr = intval($now['year']);
+$day = intval($now['mday']);
+$mon = intval($now['mon']);
+$yr = intval($now['year']);
- if ($usehtmleditor = can_use_html_editor()) {
- $defaultformat = FORMAT_HTML;
- } else {
- $defaultformat = FORMAT_MOODLE;
- }
+if ($usehtmleditor = can_use_html_editor()) {
+ $defaultformat = FORMAT_HTML;
+} else {
+ $defaultformat = FORMAT_MOODLE;
+}
- // If a course has been supplied in the URL, change the filters to show that one
- if($urlcourse > 0 && $DB->record_exists('course', array('id'=>$urlcourse))) {
- require_login($urlcourse, false);
+// If a course has been supplied in the URL, change the filters to show that one
+if($urlcourse > 0 && $DB->record_exists('course', array('id'=>$urlcourse))) {
+ require_login($urlcourse, false);
- if($urlcourse == SITEID) {
- // If coming from the site page, show all courses
- $SESSION->cal_courses_shown = calendar_get_default_courses(true);
- calendar_set_referring_course(0);
- }
- else {
- // Otherwise show just this one
- $SESSION->cal_courses_shown = $urlcourse;
- calendar_set_referring_course($SESSION->cal_courses_shown);
- }
+ if($urlcourse == SITEID) {
+ // If coming from the site page, show all courses
+ $SESSION->cal_courses_shown = calendar_get_default_courses(true);
+ calendar_set_referring_course(0);
}
+ else {
+ // Otherwise show just this one
+ $SESSION->cal_courses_shown = $urlcourse;
+ calendar_set_referring_course($SESSION->cal_courses_shown);
+ }
+}
- switch($action) {
- case 'delete':
- $title = get_string('deleteevent', 'calendar');
- $event = $DB->get_record('event', array('id'=>$eventid));
- if($event === false) {
- print_error('invalidevent');
- }
- if(!calendar_edit_event_allowed($event)) {
- print_error('nopermissions');
- }
- break;
+switch($action) {
+ case 'delete':
+ $title = get_string('deleteevent', 'calendar');
+ $event = $DB->get_record('event', array('id'=>$eventid));
+ if($event === false) {
+ print_error('invalidevent');
+ }
+ if(!calendar_edit_event_allowed($event)) {
+ print_error('nopermissions');
+ }
+ break;
- case 'edit':
- $title = get_string('editevent', 'calendar');
- $event = $DB->get_record('event', array('id'=>$eventid));
- $repeats = optional_param('repeats', 0, PARAM_INT);
+ case 'edit':
+ $title = get_string('editevent', 'calendar');
+ $event = $DB->get_record('event', array('id'=>$eventid));
+ $repeats = optional_param('repeats', 0, PARAM_INT);
- if ($event === false) {
- print_error('invalidevent');
- }
- if (!calendar_edit_event_allowed($event)) {
- print_error('nopermissions');
- }
+ if ($event === false) {
+ print_error('invalidevent');
+ }
+ if (!calendar_edit_event_allowed($event)) {
+ print_error('nopermissions');
+ }
- if($form = data_submitted()) {
+ if($form = data_submitted()) {
- $form->name = clean_param(strip_tags($form->name,'<lang><span>'), PARAM_CLEAN);
+ $form->name = clean_param(strip_tags($form->name,'<lang><span>'), PARAM_CLEAN);
- // To avoid double slashes
- $form->name = $form->name;
- $form->description = $form->description;
+ // To avoid double slashes
+ $form->name = $form->name;
+ $form->description = $form->description;
- $form->timestart = make_timestamp($form->startyr, $form->startmon, $form->startday, $form->starthr, $form->startmin);
- if($form->duration == 1) {
- $form->timeduration = make_timestamp($form->endyr, $form->endmon, $form->endday, $form->endhr, $form->endmin) - $form->timestart;
- if($form->timeduration < 0) {
- $form->timeduration = 0;
- }
- }
- else if($form->duration == 2) {
- $form->timeduration = $form->minutes * MINSECS;
- }
- else {
+ $form->timestart = make_timestamp($form->startyr, $form->startmon, $form->startday, $form->starthr, $form->startmin);
+ if($form->duration == 1) {
+ $form->timeduration = make_timestamp($form->endyr, $form->endmon, $form->endday, $form->endhr, $form->endmin) - $form->timestart;
+ if($form->timeduration < 0) {
$form->timeduration = 0;
}
+ }
+ else if($form->duration == 2) {
+ $form->timeduration = $form->minutes * MINSECS;
+ }
+ else {
+ $form->timeduration = 0;
+ }
- validate_form($form, $err);
-
- if (count($err) == 0) {
-
- if($event->repeatid && $repeats) {
- // Update all
- if($form->timestart >= $event->timestart) {
- $timestartoffset = 'timestart + '.($form->timestart - $event->timestart);
- }
- else {
- $timestartoffset = 'timestart - '.($event->timestart - $form->timestart);
- }
-
- $sql = "UPDATE {event}
- SET name = ?,
- description = ?,
- timestart = ?,
- timeduration = ?,
- timemodified = ?
- WHERE repeatid = ?";
- $params = array($form->name, $form->description, $timestartoffset, $form->timeduration, time(), $event->repeatid);
+ validate_form($form, $err);
- $DB->execute($sql, $params);
+ if (count($err) == 0) {
- /// Log the event update.
- add_to_log($form->courseid, 'calendar', 'edit all', 'event.php?action=edit&id='.$form->id, $form->name);
+ if($event->repeatid && $repeats) {
+ // Update all
+ if($form->timestart >= $event->timestart) {
+ $timestartoffset = 'timestart + '.($form->timestart - $event->timestart);
}
-
else {
- // Update this
- $form->timemodified = time();
- $DB->update_record('event', $form);
-
- /// Log the event update.
- add_to_log($form->courseid, 'calendar', 'edit', 'event.php?action=edit&id='.$form->id, $form->name);
+ $timestartoffset = 'timestart - '.($event->timestart - $form->timestart);
}
- // OK, now redirect to day view
- redirect(CALENDAR_URL.'view.php?view=day&course='.$urlcourse.'&cal_d='.$form->startday.'&cal_m='.$form->startmon.'&cal_y='.$form->startyr);
+ $sql = "UPDATE {event}
+ SET name = ?,
+ description = ?,
+ timestart = ?,
+ timeduration = ?,
+ timemodified = ?
+ WHERE repeatid = ?";
+ $params = array($form->name, $form->description, $timestartoffset, $form->timeduration, time(), $event->repeatid);
+
+ $DB->execute($sql, $params);
+
+ /// Log the event update.
+ add_to_log($form->courseid, 'calendar', 'edit all', 'event.php?action=edit&id='.$form->id, $form->name);
}
+
else {
- foreach ($err as $key => $value) {
- $focus = 'form.'.$key;
- }
+ // Update this
+ $form->timemodified = time();
+ $DB->update_record('event', $form);
+
+ /// Log the event update.
+ add_to_log($form->courseid, 'calendar', 'edit', 'event.php?action=edit&id='.$form->id, $form->name);
}
+
+ // OK, now redirect to day view
+ redirect(CALENDAR_URL.'view.php?view=day&course='.$urlcourse.'&cal_d='.$form->startday.'&cal_m='.$form->startmon.'&cal_y='.$form->startyr);
}
- break;
+ else {
+ foreach ($err as $key => $value) {
+ $focus = 'form.'.$key;
+ }
+ }
+ }
+ break;
- case 'new':
- $title = get_string('newevent', 'calendar');
- $form = data_submitted();
- if(!empty($form) && !empty($form->name)) {
+ case 'new':
+ $title = get_string('newevent', 'calendar');
+ $form = data_submitted();
+ if(!empty($form) && !empty($form->name)) {
- $form->name = clean_text(strip_tags($form->name, '<lang><span>'));
+ $form->name = clean_text(strip_tags($form->name, '<lang><span>'));
- $form->timestart = make_timestamp($form->startyr, $form->startmon, $form->startday, $form->starthr, $form->startmin);
- if($form->duration == 1) {
- $form->timeduration = make_timestamp($form->endyr, $form->endmon, $form->endday, $form->endhr, $form->endmin) - $form->timestart;
- if($form->timeduration < 0) {
- $form->timeduration = 0;
- }
- }
- else if ($form->duration == 2) {
- $form->timeduration = $form->minutes * MINSECS;
- }
- else {
+ $form->timestart = make_timestamp($form->startyr, $form->startmon, $form->startday, $form->starthr, $form->startmin);
+ if($form->duration == 1) {
+ $form->timeduration = make_timestamp($form->endyr, $form->endmon, $form->endday, $form->endhr, $form->endmin) - $form->timestart;
+ if($form->timeduration < 0) {
$form->timeduration = 0;
}
- if(!calendar_add_event_allowed($form)) {
- print_error('nopermissions');
- }
- validate_form($form, $err);
- if (count($err) == 0) {
- $form->timemodified = time();
+ }
+ else if ($form->duration == 2) {
+ $form->timeduration = $form->minutes * MINSECS;
+ }
+ else {
+ $form->timeduration = 0;
+ }
+ if(!calendar_add_event_allowed($form)) {
+ print_error('nopermissions');
+ }
+ validate_form($form, $err);
+ if (count($err) == 0) {
+ $form->timemodified = time();
- /// Get the event id for the log record.
- $eventid = $DB->insert_record('event', $form);
-
- /// Use the event id as the repeatid to link repeat entries together
- if ($form->repeat) {
- $form->repeatid = $form->id = $eventid;
- $DB->update_record('event', $form); // update the row, to set its repeatid
- }
+ /// Get the event id for the log record.
+ $eventid = $DB->insert_record('event', $form);
- /// Log the event entry.
- add_to_log($form->courseid, 'calendar', 'add', 'event.php?action=edit&id='.$eventid, $form->name);
+ /// Use the event id as the repeatid to link repeat entries together
+ if ($form->repeat) {
+ $form->repeatid = $form->id = $eventid;
+ $DB->update_record('event', $form); // update the row, to set its repeatid
+ }
- if ($form->repeat) {
- for($i = 1; $i < $form->repeats; $i++) {
- // What's the DST offset for the previous repeat?
- $dst_offset_prev = dst_offset_on($form->timestart);
+ /// Log the event entry.
+ add_to_log($form->courseid, 'calendar', 'add', 'event.php?action=edit&id='.$eventid, $form->name);
- $form->timestart += WEEKSECS;
+ if ($form->repeat) {
+ for($i = 1; $i < $form->repeats; $i++) {
+ // What's the DST offset for the previous repeat?
+ $dst_offset_prev = dst_offset_on($form->timestart);
- // If the offset has changed in the meantime, update this repeat accordingly
- $form->timestart += $dst_offset_prev - dst_offset_on($form->timestart);
+ $form->timestart += WEEKSECS;
- /// Get the event id for the log record.
- $eventid = $DB->insert_record('event', $form);
+ // If the offset has changed in the meantime, update this repeat accordingly
+ $form->timestart += $dst_offset_prev - dst_offset_on($form->timestart);
- /// Log the event entry.
- add_to_log($form->courseid, 'calendar', 'add', 'event.php?action=edit&id='.$eventid, $form->name);
- }
+ /// Get the event id for the log record.
+ $eventid = $DB->insert_record('event', $form);
+
+ /// Log the event entry.
+ add_to_log($form->courseid, 'calendar', 'add', 'event.php?action=edit&id='.$eventid, $form->name);
}
- // OK, now redirect to day view
- redirect(CALENDAR_URL.'view.php?view=day&course='.$urlcourse.'&cal_d='.$form->startday.'&cal_m='.$form->startmon.'&cal_y='.$form->startyr);
}
- else {
- foreach ($err as $key => $value) {
- $focus = 'form.'.$key;
- }
+ // OK, now redirect to day view
+ redirect(CALENDAR_URL.'view.php?view=day&course='.$urlcourse.'&cal_d='.$form->startday.'&cal_m='.$form->startmon.'&cal_y='.$form->startyr);
+ }
+ else {
+ foreach ($err as $key => $value) {
+ $focus = 'form.'.$key;
}
}
- break;
- default: // no action
- $title='';
- break;
- }
+ }
+ break;
+ default: // no action
+ $title='';
+ break;
+}
- if (!empty($SESSION->cal_course_referer)) {
- // TODO: This is part of the Great $course Hack in Moodle. Replace it at some point.
- $course = $DB->get_record('course', array('id'=>$SESSION->cal_course_referer));
- } else {
- $course = $site;
- }
- require_login($course, false);
-
- $link = calendar_get_link_href(CALENDAR_URL.'view.php?view=upcoming&course='.$urlcourse.'&',
- $now['mday'], $now['mon'], $now['year']);
-
- $PAGE->requires->yui_lib('animation');
- $PAGE->requires->js('calendar/calendar.js');
-
- $PAGE->navbar->add($strcalendar, new moodle_url($link));
- $PAGE->navbar->add($title);
- $PAGE->set_title($site->shortname.': '.$strcalendar.': '.$title);
- $PAGE->set_heading($strcalendar);
- $PAGE->set_headingmenu(user_login_string($site));
- $PAGE->set_focuscontrol('eventform.name');
-
- echo $OUTPUT->header();
-
- echo '<table id="calendar">';
- echo '<tr><td class="maincalendar">';
-
- switch ($action) {
- case 'delete':
- $confirm = optional_param('confirm', 0, PARAM_INT);
- $repeats = optional_param('repeats', 0, PARAM_INT);
- if ($confirm) {
- // Kill it and redirect to day view
- if(($event = $DB->get_record('event', array('id'=>$eventid))) !== false) {
-
- if ($event->repeatid && $repeats) {
- $DB->delete_records('event', array('repeatid'=>$event->repeatid));
- add_to_log($event->courseid, 'calendar', 'delete all', '', $event->name);
- } else {
- $DB->delete_records('event', array('id'=>$eventid));
- add_to_log($event->courseid, 'calendar', 'delete', '', $event->name);
- }
- }
+if (!empty($SESSION->cal_course_referer)) {
+ // TODO: This is part of the Great $course Hack in Moodle. Replace it at some point.
+ $course = $DB->get_record('course', array('id'=>$SESSION->cal_course_referer));
+} else {
+ $course = $site;
+}
+require_login($course, false);
- echo '</td></tr></table>';
- redirect(CALENDAR_URL.'view.php?view=day&course='.$urlcourse.'&cal_d='.$_REQUEST['d'].'&cal_m='.$_REQUEST['m'].'&cal_y='.$_REQUEST['y']);
+$link = calendar_get_link_href(CALENDAR_URL.'view.php?view=upcoming&course='.$urlcourse.'&',
+ $now['mday'], $now['mon'], $now['year']);
- }
- else {
- $eventtime = usergetdate($event->timestart);
- $m = $eventtime['mon'];
- $d = $eventtime['mday'];
- $y = $eventtime['year'];
+$PAGE->requires->yui_lib('animation');
+$PAGE->requires->js('calendar/calendar.js');
- if ($event->repeatid) {
- $repeatcount = $DB->count_records('event', array('repeatid'=>$event->repeatid));
- } else {
- $repeatcount = 0;
- }
+$PAGE->navbar->add($strcalendar, new moodle_url($link));
+$PAGE->navbar->add($title);
+$PAGE->set_title($site->shortname.': '.$strcalendar.': '.$title);
+$PAGE->set_heading($strcalendar);
+$PAGE->set_headingmenu(user_login_string($site));
+$PAGE->set_focuscontrol('eventform.name');
- // Display confirmation form
- echo '<div class="header">'.get_string('deleteevent', 'calendar').': '.$event->name.'</div>';
- echo '<h2>'.get_string('confirmeventdelete', 'calendar').'</h2>';
- if($repeatcount > 1) {
- echo '<p>'.get_string('youcandeleteallrepeats', 'calendar', $repeatcount).'</p>';
- }
- echo '<div class="eventlist">';
- $event->time = calendar_format_event_time($event, time(), '', false);
- calendar_print_event($event);
- echo '</div>';
- include('event_delete.html');
- }
- break;
-
- case 'edit':
- if(empty($form)) {
- $form->name = $event->name;
- $form->courseid = $event->courseid; // Not to update, but for date validation
- $form->description = $event->description;
- $form->timestart = $event->timestart;
- $form->timeduration = $event->timeduration;
- $form->id = $event->id;
- $form->format = $defaultformat;
- if($event->timeduration > HOURSECS) {
- // More than one hour, so default to normal duration mode
- $form->duration = 1;
- $form->minutes = '';
- }
- else if($event->timeduration) {
- // Up to one hour, "minutes" mode probably is better here
- $form->duration = 2;
- $form->minutes = $event->timeduration / MINSECS;
- }
- else {
- // No duration
- $form->duration = 0;
- $form->minutes = '';
+echo $OUTPUT->header();
+
+echo '<table id="calendar">';
+echo '<tr><td class="maincalendar">';
+
+switch ($action) {
+ case 'delete':
+ $confirm = optional_param('confirm', 0, PARAM_INT);
+ $repeats = optional_param('repeats', 0, PARAM_INT);
+ if ($confirm) {
+ // Kill it and redirect to day view
+ if(($event = $DB->get_record('event', array('id'=>$eventid))) !== false) {
+
+ if ($event->repeatid && $repeats) {
+ $DB->delete_records('event', array('repeatid'=>$event->repeatid));
+ add_to_log($event->courseid, 'calendar', 'delete all', '', $event->name);
+ } else {
+ $DB->delete_records('event', array('id'=>$eventid));
+ add_to_log($event->courseid, 'calendar', 'delete', '', $event->name);
}
}
- if (!empty($form->courseid)) {
- // TODO: This is part of the Great $course Hack in Moodle. Replace it at some point.
- $course = $DB->get_record('course', array('id'=>$form->courseid));
- } else {
- $course = $site;
- }
+ echo '</td></tr></table>';
+ redirect(CALENDAR_URL.'view.php?view=day&course='.$urlcourse.'&cal_d='.$_REQUEST['d'].'&cal_m='.$_REQUEST['m'].'&cal_y='.$_REQUEST['y']);
+
+ }
+ else {
+ $eventtime = usergetdate($event->timestart);
+ $m = $eventtime['mon'];
+ $d = $eventtime['mday'];
+ $y = $eventtime['year'];
if ($event->repeatid) {
$repeatcount = $DB->count_records('event', array('repeatid'=>$event->repeatid));
- $repeatcount = $fetch->repeatcount;
} else {
$repeatcount = 0;
}
- echo '<div class="header">'.get_string('editevent', 'calendar').'</div>';
- include('event_edit.html');
- break;
-
- case 'new':
- if($cal_y && $cal_m && $cal_d && checkdate($cal_m, $cal_d, $cal_y)) {
- $form->timestart = make_timestamp($cal_y, $cal_m, $cal_d, 0, 0, 0);
+ // Display confirmation form
+ echo '<div class="header">'.get_string('deleteevent', 'calendar').': '.$event->name.'</div>';
+ echo '<h2>'.get_string('confirmeventdelete', 'calendar').'</h2>';
+ if($repeatcount > 1) {
+ echo '<p>'.get_string('youcandeleteallrepeats', 'calendar', $repeatcount).'</p>';
}
- else if($cal_y && $cal_m && checkdate($cal_m, 1, $cal_y)) {
- if($cal_y == $now['year'] && $cal_m == $now['mon']) {
- $form->timestart = make_timestamp($cal_y, $cal_m, $now['mday'], 0, 0, 0);
- }
- else {
- $form->timestart = make_timestamp($cal_y, $cal_m, 1, 0, 0, 0);
- }
+ echo '<div class="eventlist">';
+ $event->time = calendar_format_event_time($event, time(), '', false);
+ calendar_print_event($event);
+ echo '</div>';
+ include('event_delete.html');
+ }
+ break;
+
+ case 'edit':
+ if(empty($form)) {
+ $form->name = $event->name;
+ $form->courseid = $event->courseid; // Not to update, but for date validation
+ $form->description = $event->description;
+ $form->timestart = $event->timestart;
+ $form->timeduration = $event->timeduration;
+ $form->id = $event->id;
+ $form->format = $defaultformat;
+ if($event->timeduration > HOURSECS) {
+ // More than one hour, so default to normal duration mode
+ $form->duration = 1;
+ $form->minutes = '';
}
- if(!isset($form->timestart) or $form->timestart < 0) {
- $form->timestart = time();
+ else if($event->timeduration) {
+ // Up to one hour, "minutes" mode probably is better here
+ $form->duration = 2;
+ $form->minutes = $event->timeduration / MINSECS;
}
+ else {
+ // No duration
+ $form->duration = 0;
+ $form->minutes = '';
+ }
+ }
+
+ if (!empty($form->courseid)) {
+ // TODO: This is part of the Great $course Hack in Moodle. Replace it at some point.
+ $course = $DB->get_record('course', array('id'=>$form->courseid));
+ } else {
+ $course = $site;
+ }
- calendar_get_allowed_types($allowed);
- if(!$allowed->groups && !$allowed->courses && !$allowed->site) {
- // Take the shortcut
- $eventtype = 'user';
+ if ($event->repeatid) {
+ $repeatcount = $DB->count_records('event', array('repeatid'=>$event->repeatid));
+ $repeatcount = $fetch->repeatcount;
+ } else {
+ $repeatcount = 0;
+ }
+
+ echo '<div class="header">'.get_string('editevent', 'calendar').'</div>';
+ include('event_edit.html');
+ break;
+
+ case 'new':
+ if($cal_y && $cal_m && $cal_d && checkdate($cal_m, $cal_d, $cal_y)) {
+ $form->timestart = make_timestamp($cal_y, $cal_m, $cal_d, 0, 0, 0);
+ }
+ else if($cal_y && $cal_m && checkdate($cal_m, 1, $cal_y)) {
+ if($cal_y == $now['year'] && $cal_m == $now['mon']) {
+ $form->timestart = make_timestamp($cal_y, $cal_m, $now['mday'], 0, 0, 0);
}
+ else {
+ $form->timestart = make_timestamp($cal_y, $cal_m, 1, 0, 0, 0);
+ }
+ }
+ if(!isset($form->timestart) or $form->timestart < 0) {
+ $form->timestart = time();
+ }
- $header = '';
+ calendar_get_allowed_types($allowed);
+ if(!$allowed->groups && !$allowed->courses && !$allowed->site) {
+ // Take the shortcut
+ $eventtype = 'user';
+ }
- switch($eventtype) {
- case 'user':
+ $header = '';
+
+ switch($eventtype) {
+ case 'user':
+ $form->name = '';
+ $form->description = '';
+ $form->courseid = 0;
+ $form->groupid = 0;
+ $form->userid = $USER->id;
+ $form->modulename = '';
+ $form->eventtype = '';
+ $form->instance = 0;
+ $form->timeduration = 0;
+ $form->duration = 0;
+ $form->repeat = 0;
+ $form->repeats = '';
+ $form->minutes = '';
+ $form->type = 'user';
+ $header = get_string('typeuser', 'calendar');
+ break;
+ case 'group':
+ $groupid = optional_param('groupid', 0, PARAM_INT);
+ if (! ($group = groups_get_group($groupid))) { //TODO:check.
+ calendar_get_allowed_types($allowed);
+ $eventtype = 'select';
+ }
+ else {
$form->name = '';
$form->description = '';
- $form->courseid = 0;
- $form->groupid = 0;
+ $form->courseid = $group->courseid;
+ $form->groupid = $group->id;
$form->userid = $USER->id;
$form->modulename = '';
$form->eventtype = '';
$form->repeat = 0;
$form->repeats = '';
$form->minutes = '';
- $form->type = 'user';
- $header = get_string('typeuser', 'calendar');
- break;
- case 'group':
- $groupid = optional_param('groupid', 0, PARAM_INT);
- if (! ($group = groups_get_group($groupid))) { //TODO:check.
- calendar_get_allowed_types($allowed);
- $eventtype = 'select';
- }
- else {
- $form->name = '';
- $form->description = '';
- $form->courseid = $group->courseid;
- $form->groupid = $group->id;
- $form->userid = $USER->id;
- $form->modulename = '';
- $form->eventtype = '';
- $form->instance = 0;
- $form->timeduration = 0;
- $form->duration = 0;
- $form->repeat = 0;
- $form->repeats = '';
- $form->minutes = '';
- $form->type = 'group';
- $header = get_string('typegroup', 'calendar');
- }
- break;
- case 'course':
- $courseid = optional_param('courseid', 0, PARAM_INT);
- if (!$DB->record_exists('course', array('id'=>$courseid))) {
- calendar_get_allowed_types($allowed);
- $eventtype = 'select';
- }
- else {
- $form->name = '';
- $form->description = '';
- $form->courseid = $courseid;
- $form->groupid = 0;
- $form->userid = $USER->id;
- $form->modulename = '';
- $form->eventtype = '';
- $form->instance = 0;
- $form->timeduration = 0;
- $form->duration = 0;
- $form->repeat = 0;
- $form->repeats = '';
- $form->minutes = '';
- $form->type = 'course';
- $header = get_string('typecourse', 'calendar');
- }
- break;
- case 'site':
+ $form->type = 'group';
+ $header = get_string('typegroup', 'calendar');
+ }
+ break;
+ case 'course':
+ $courseid = optional_param('courseid', 0, PARAM_INT);
+ if (!$DB->record_exists('course', array('id'=>$courseid))) {
+ calendar_get_allowed_types($allowed);
+ $eventtype = 'select';
+ }
+ else {
$form->name = '';
$form->description = '';
- $form->courseid = SITEID;
+ $form->courseid = $courseid;
$form->groupid = 0;
$form->userid = $USER->id;
$form->modulename = '';
$form->repeat = 0;
$form->repeats = '';
$form->minutes = '';
- $form->type = 'site';
- $header = get_string('typesite', 'calendar');
- break;
- case 'select':
- break;
- default:
- print_error('unsupportedevent');
- }
-
- $form->format = $defaultformat;
- if(!empty($header)) {
- $header = ' ('.$header.')';
- }
+ $form->type = 'course';
+ $header = get_string('typecourse', 'calendar');
+ }
+ break;
+ case 'site':
+ $form->name = '';
+ $form->description = '';
+ $form->courseid = SITEID;
+ $form->groupid = 0;
+ $form->userid = $USER->id;
+ $form->modulename = '';
+ $form->eventtype = '';
+ $form->instance = 0;
+ $form->timeduration = 0;
+ $form->duration = 0;
+ $form->repeat = 0;
+ $form->repeats = '';
+ $form->minutes = '';
+ $form->type = 'site';
+ $header = get_string('typesite', 'calendar');
+ break;
+ case 'select':
+ break;
+ default:
+ print_error('unsupportedevent');
+ }
- echo '<div class="header">'.get_string('newevent', 'calendar').$header.'</div>';
+ $form->format = $defaultformat;
+ if(!empty($header)) {
+ $header = ' ('.$header.')';
+ }
- if($eventtype == 'select') {
- $courseid = optional_param('courseid', $SESSION->cal_course_referer, PARAM_INT);
- if ($courseid == 0) { // workaround by Dan for bug #6130
- $courseid = SITEID;
- }
- if (!$course = $DB->get_record('course', array('id'=>$courseid))) {
- print_error('invalidcourse');
- }
-
- $groupid = groups_get_course_group($course);
+ echo '<div class="header">'.get_string('newevent', 'calendar').$header.'</div>';
- echo '<h2>'.get_string('eventkind', 'calendar').':</h2>';
- echo '<div id="selecteventtype">';
- include('event_select.html');
- echo '</div>';
+ if($eventtype == 'select') {
+ $courseid = optional_param('courseid', $SESSION->cal_course_referer, PARAM_INT);
+ if ($courseid == 0) { // workaround by Dan for bug #6130
+ $courseid = SITEID;
}
- else {
- include('event_new.html');
+ if (!$course = $DB->get_record('course', array('id'=>$courseid))) {
+ print_error('invalidcourse');
}
- break;
- }
- echo '</td>';
-
- // START: Last column (3-month display)
-
- $defaultcourses = calendar_get_default_courses();
- //calendar_set_filters($courses, $groups, $users, $defaultcourses, $defaultcourses);
-
- // when adding an event you can not be a guest, so I think it's reasonalbe to ignore defaultcourses
- // MDL-10353
- calendar_set_filters($courses, $groups, $users);
- list($prevmon, $prevyr) = calendar_sub_month($mon, $yr);
- list($nextmon, $nextyr) = calendar_add_month($mon, $yr);
-
- echo '<td class="sidecalendar">';
- echo '<div class="sideblock">';
- echo '<div class="header">'.get_string('eventskey', 'calendar').'</div>';
- echo '<div class="filters">';
- echo calendar_filter_controls('event', 'action='.$action.'&type='.$eventtype.'&id='.$eventid);
- echo '</div>';
- echo '</div>';
-
- echo '<div class="sideblock">';
- echo '<div class="header">'.get_string('monthlyview', 'calendar').'</div>';
- echo '<div class="minicalendarblock minicalendartop">';
- echo calendar_top_controls('display', array('id' => $urlcourse, 'm' => $prevmon, 'y' => $prevyr));
- echo calendar_get_mini($courses, $groups, $users, $prevmon, $prevyr);
- echo '</div><div class="minicalendarblock">';
- echo calendar_top_controls('display', array('id' => $urlcourse, 'm' => $mon, 'y' => $yr));
- echo calendar_get_mini($courses, $groups, $users, $mon, $yr);
- echo '</div><div class="minicalendarblock">';
- echo calendar_top_controls('display', array('id' => $urlcourse, 'm' => $nextmon, 'y' => $nextyr));
- echo calendar_get_mini($courses, $groups, $users, $nextmon, $nextyr);
- echo '</div>';
- echo '</div>';
-
- echo '</td>';
- echo '</tr></table>';
-
- echo $OUTPUT->footer();
+ $groupid = groups_get_course_group($course);
+
+ echo '<h2>'.get_string('eventkind', 'calendar').':</h2>';
+ echo '<div id="selecteventtype">';
+ include('event_select.html');
+ echo '</div>';
+ }
+ else {
+ include('event_new.html');
+ }
+
+ break;
+}
+echo '</td>';
+
+// START: Last column (3-month display)
+
+$defaultcourses = calendar_get_default_courses();
+//calendar_set_filters($courses, $groups, $users, $defaultcourses, $defaultcourses);
+
+// when adding an event you can not be a guest, so I think it's reasonalbe to ignore defaultcourses
+// MDL-10353
+calendar_set_filters($courses, $groups, $users);
+list($prevmon, $prevyr) = calendar_sub_month($mon, $yr);
+list($nextmon, $nextyr) = calendar_add_month($mon, $yr);
+
+echo '<td class="sidecalendar">';
+echo '<div class="sideblock">';
+echo '<div class="header">'.get_string('eventskey', 'calendar').'</div>';
+echo '<div class="filters">';
+echo calendar_filter_controls('event', 'action='.$action.'&type='.$eventtype.'&id='.$eventid);
+echo '</div>';
+echo '</div>';
+
+echo '<div class="sideblock">';
+echo '<div class="header">'.get_string('monthlyview', 'calendar').'</div>';
+echo '<div class="minicalendarblock minicalendartop">';
+echo calendar_top_controls('display', array('id' => $urlcourse, 'm' => $prevmon, 'y' => $prevyr));
+echo calendar_get_mini($courses, $groups, $users, $prevmon, $prevyr);
+echo '</div><div class="minicalendarblock">';
+echo calendar_top_controls('display', array('id' => $urlcourse, 'm' => $mon, 'y' => $yr));
+echo calendar_get_mini($courses, $groups, $users, $mon, $yr);
+echo '</div><div class="minicalendarblock">';
+echo calendar_top_controls('display', array('id' => $urlcourse, 'm' => $nextmon, 'y' => $nextyr));
+echo calendar_get_mini($courses, $groups, $users, $nextmon, $nextyr);
+echo '</div>';
+echo '</div>';
+
+echo '</td>';
+echo '</tr></table>';
+
+echo $OUTPUT->footer();
function validate_form(&$form, &$err) {
return false;
}
}
-?>
+
+?>
\ No newline at end of file
-<?php // $Id$
+<?php
/////////////////////////////////////////////////////////////////////////////
// //
// Display the calendar page.
- require_once('../config.php');
- require_once($CFG->dirroot.'/course/lib.php');
- require_once($CFG->dirroot.'/calendar/lib.php');
+require_once('../config.php');
+require_once($CFG->dirroot.'/course/lib.php');
+require_once($CFG->dirroot.'/calendar/lib.php');
- $courseid = optional_param('course', 0, PARAM_INT);
- $view = optional_param('view', 'upcoming', PARAM_ALPHA);
- $day = optional_param('cal_d', 0, PARAM_INT);
- $mon = optional_param('cal_m', 0, PARAM_INT);
- $yr = optional_param('cal_y', 0, PARAM_INT);
+$courseid = optional_param('course', 0, PARAM_INT);
+$view = optional_param('view', 'upcoming', PARAM_ALPHA);
+$day = optional_param('cal_d', 0, PARAM_INT);
+$mon = optional_param('cal_m', 0, PARAM_INT);
+$yr = optional_param('cal_y', 0, PARAM_INT);
- if(!$site = get_site()) {
- redirect($CFG->wwwroot.'/'.$CFG->admin.'/index.php');
- }
+if(!$site = get_site()) {
+ redirect($CFG->wwwroot.'/'.$CFG->admin.'/index.php');
+}
- $url = new moodle_url($CFG->wwwroot.'/calendar/view.php');
- if ($courseid !== 0) {
- $url->param('course', $courseid);
- }
- if ($view !== 'upcoming') {
- $url->param('view', $view);
- }
- if ($day !== 0) {
- $url->param('cal_d', $day);
- }
- if ($mon !== 0) {
- $url->param('cal_m', $mon);
- }
- if ($yr !== 0) {
- $url->param('cal_y', $yr);
- }
- $PAGE->set_url($url);
+$url = new moodle_url($CFG->wwwroot.'/calendar/view.php');
+if ($courseid !== 0) {
+ $url->param('course', $courseid);
+}
+if ($view !== 'upcoming') {
+ $url->param('view', $view);
+}
+if ($day !== 0) {
+ $url->param('cal_d', $day);
+}
+if ($mon !== 0) {
+ $url->param('cal_m', $mon);
+}
+if ($yr !== 0) {
+ $url->param('cal_y', $yr);
+}
+$PAGE->set_url($url);
- if ($courseid) {
- require_login($courseid);
- } else if ($CFG->forcelogin) {
- require_login();
- }
+if ($courseid) {
+ require_login($courseid);
+} else if ($CFG->forcelogin) {
+ require_login();
+}
- // Initialize the session variables
- calendar_session_vars();
+// Initialize the session variables
+calendar_session_vars();
- //add_to_log($course->id, "course", "view", "view.php?id=$course->id", "$course->id");
- $now = usergetdate(time());
- $pagetitle = '';
+//add_to_log($course->id, "course", "view", "view.php?id=$course->id", "$course->id");
+$now = usergetdate(time());
+$pagetitle = '';
- $strcalendar = get_string('calendar', 'calendar');
-
- $link = calendar_get_link_href(CALENDAR_URL.'view.php?view=upcoming&course='.$courseid.'&',
- $now['mday'], $now['mon'], $now['year']);
- $PAGE->navbar->add($strcalendar, new moodle_url($link));
-
- if(!checkdate($mon, $day, $yr)) {
- $day = intval($now['mday']);
- $mon = intval($now['mon']);
- $yr = intval($now['year']);
- }
- $time = make_timestamp($yr, $mon, $day);
-
- switch($view) {
- case 'day':
- $PAGE->navbar->add(userdate($time, get_string('strftimedate')));
- $pagetitle = get_string('dayview', 'calendar');
- break;
- case 'month':
- $PAGE->navbar->add(userdate($time, get_string('strftimemonthyear')));
- $pagetitle = get_string('detailedmonthview', 'calendar');
- break;
- case 'upcoming':
- $pagetitle = get_string('upcomingevents', 'calendar');
- break;
- }
+$strcalendar = get_string('calendar', 'calendar');
- // If a course has been supplied in the URL, change the filters to show that one
- if (!empty($courseid)) {
- if ($course = $DB->get_record('course', array('id'=>$courseid))) {
- if ($course->id == SITEID) {
- // If coming from the home page, show all courses
- $SESSION->cal_courses_shown = calendar_get_default_courses(true);
- calendar_set_referring_course(0);
-
- } else {
- // Otherwise show just this one
- $SESSION->cal_courses_shown = $course->id;
- calendar_set_referring_course($SESSION->cal_courses_shown);
- }
+$link = calendar_get_link_href(CALENDAR_URL.'view.php?view=upcoming&course='.$courseid.'&',
+ $now['mday'], $now['mon'], $now['year']);
+$PAGE->navbar->add($strcalendar, new moodle_url($link));
+
+if(!checkdate($mon, $day, $yr)) {
+ $day = intval($now['mday']);
+ $mon = intval($now['mon']);
+ $yr = intval($now['year']);
+}
+$time = make_timestamp($yr, $mon, $day);
+
+switch($view) {
+ case 'day':
+ $PAGE->navbar->add(userdate($time, get_string('strftimedate')));
+ $pagetitle = get_string('dayview', 'calendar');
+ break;
+ case 'month':
+ $PAGE->navbar->add(userdate($time, get_string('strftimemonthyear')));
+ $pagetitle = get_string('detailedmonthview', 'calendar');
+ break;
+ case 'upcoming':
+ $pagetitle = get_string('upcomingevents', 'calendar');
+ break;
+}
+
+// If a course has been supplied in the URL, change the filters to show that one
+if (!empty($courseid)) {
+ if ($course = $DB->get_record('course', array('id'=>$courseid))) {
+ if ($course->id == SITEID) {
+ // If coming from the home page, show all courses
+ $SESSION->cal_courses_shown = calendar_get_default_courses(true);
+ calendar_set_referring_course(0);
+
+ } else {
+ // Otherwise show just this one
+ $SESSION->cal_courses_shown = $course->id;
+ calendar_set_referring_course($SESSION->cal_courses_shown);
}
- } else {
- $course = null;
}
+} else {
+ $course = null;
+}
- if (empty($USER->id) or isguest()) {
- $defaultcourses = calendar_get_default_courses();
- calendar_set_filters($courses, $groups, $users, $defaultcourses, $defaultcourses);
+if (empty($USER->id) or has_capability('moodle/legacy:guest', get_context_instance(CONTEXT_SYSTEM), 0, false)) {
+ $defaultcourses = calendar_get_default_courses();
+ calendar_set_filters($courses, $groups, $users, $defaultcourses, $defaultcourses);
- } else {
- calendar_set_filters($courses, $groups, $users);
- }
+} else {
+ calendar_set_filters($courses, $groups, $users);
+}
- // Let's see if we are supposed to provide a referring course link
- // but NOT for the "main page" course
- if ($SESSION->cal_course_referer != SITEID &&
- ($shortname = $DB->get_field('course', 'shortname', array('id'=>$SESSION->cal_course_referer))) !== false) {
- require_login();
- if (empty($course)) {
- $course = $DB->get_record('course', array('id'=>$SESSION->cal_course_referer)); // Useful to have around
- }
+// Let's see if we are supposed to provide a referring course link
+// but NOT for the "main page" course
+if ($SESSION->cal_course_referer != SITEID &&
+ ($shortname = $DB->get_field('course', 'shortname', array('id'=>$SESSION->cal_course_referer))) !== false) {
+ require_login();
+ if (empty($course)) {
+ $course = $DB->get_record('course', array('id'=>$SESSION->cal_course_referer)); // Useful to have around
}
+}
- $strcalendar = get_string('calendar', 'calendar');
- $prefsbutton = calendar_preferences_button();
+$strcalendar = get_string('calendar', 'calendar');
+$prefsbutton = calendar_preferences_button();
- // Print title and header
- $PAGE->set_title("$site->shortname: $strcalendar: $pagetitle");
- $PAGE->set_heading($strcalendar);
- $PAGE->set_headingmenu(user_login_string($site));
- $PAGE->set_button($prefsbutton);
+// Print title and header
+$PAGE->set_title("$site->shortname: $strcalendar: $pagetitle");
+$PAGE->set_heading($strcalendar);
+$PAGE->set_headingmenu(user_login_string($site));
+$PAGE->set_button($prefsbutton);
- $PAGE->requires->yui_lib('animation');
- $PAGE->requires->js('calendar/calendar.js');
+$PAGE->requires->yui_lib('animation');
+$PAGE->requires->js('calendar/calendar.js');
- echo $OUTPUT->header();
+echo $OUTPUT->header();
- // Layout the whole page as three big columns.
- echo '<table id="calendar" style="height:100%;">';
- echo '<tr>';
+// Layout the whole page as three big columns.
+echo '<table id="calendar" style="height:100%;">';
+echo '<tr>';
- // START: Main column
+// START: Main column
- echo '<td class="maincalendar">';
- echo '<div class="heightcontainer">';
+echo '<td class="maincalendar">';
+echo '<div class="heightcontainer">';
- switch($view) {
- case 'day':
- calendar_show_day($day, $mon, $yr, $courses, $groups, $users, $courseid);
- break;
- case 'month':
- calendar_show_month_detailed($mon, $yr, $courses, $groups, $users, $courseid);
- break;
- case 'upcoming':
- calendar_show_upcoming_events($courses, $groups, $users, get_user_preferences('calendar_lookahead', CALENDAR_UPCOMING_DAYS), get_user_preferences('calendar_maxevents', CALENDAR_UPCOMING_MAXEVENTS), $courseid);
- break;
- }
+switch($view) {
+ case 'day':
+ calendar_show_day($day, $mon, $yr, $courses, $groups, $users, $courseid);
+ break;
+ case 'month':
+ calendar_show_month_detailed($mon, $yr, $courses, $groups, $users, $courseid);
+ break;
+ case 'upcoming':
+ calendar_show_upcoming_events($courses, $groups, $users, get_user_preferences('calendar_lookahead', CALENDAR_UPCOMING_DAYS), get_user_preferences('calendar_maxevents', CALENDAR_UPCOMING_MAXEVENTS), $courseid);
+ break;
+}
- //Link to calendar export page
- echo $OUTPUT->container_start('bottom');
- if (!empty($CFG->enablecalendarexport)) {
- echo $OUTPUT->button(html_form::make_button('export.php', array('course'=>$courseid), get_string('exportcalendar', 'calendar')));
+//Link to calendar export page
+echo $OUTPUT->container_start('bottom');
+if (!empty($CFG->enablecalendarexport)) {
+ echo $OUTPUT->button(html_form::make_button('export.php', array('course'=>$courseid), get_string('exportcalendar', 'calendar')));
- if (!empty($USER->id)) {
- $authtoken = sha1($USER->username . $USER->password . $CFG->calendar_exportsalt);
- $usernameencoded = urlencode($USER->username);
+ if (!empty($USER->id)) {
+ $authtoken = sha1($USER->username . $USER->password . $CFG->calendar_exportsalt);
+ $usernameencoded = urlencode($USER->username);
- echo "<a href=\"export_execute.php?preset_what=all&preset_time=recentupcoming&username=$usernameencoded&authtoken=$authtoken\">"
- .'<img src="'.$OUTPUT->old_icon_url('i/ical') . '" height="14" width="36" '
- .'alt="'.get_string('ical', 'calendar').'" '
- .'title="'.get_string('quickdownloadcalendar', 'calendar').'" />'
- .'</a>';
- }
+ echo "<a href=\"export_execute.php?preset_what=all&preset_time=recentupcoming&username=$usernameencoded&authtoken=$authtoken\">"
+ .'<img src="'.$OUTPUT->old_icon_url('i/ical') . '" height="14" width="36" '
+ .'alt="'.get_string('ical', 'calendar').'" '
+ .'title="'.get_string('quickdownloadcalendar', 'calendar').'" />'
+ .'</a>';
}
+}
- echo $OUTPUT->container_end();
- echo '</div>';
- echo '</td>';
+echo $OUTPUT->container_end();
+echo '</div>';
+echo '</td>';
- // END: Main column
+// END: Main column
- // START: Last column (3-month display)
- echo '<td class="sidecalendar">';
- list($prevmon, $prevyr) = calendar_sub_month($mon, $yr);
- list($nextmon, $nextyr) = calendar_add_month($mon, $yr);
- $getvars = 'id='.$courseid.'&cal_d='.$day.'&cal_m='.$mon.'&cal_y='.$yr; // For filtering
+// START: Last column (3-month display)
+echo '<td class="sidecalendar">';
+list($prevmon, $prevyr) = calendar_sub_month($mon, $yr);
+list($nextmon, $nextyr) = calendar_add_month($mon, $yr);
+$getvars = 'id='.$courseid.'&cal_d='.$day.'&cal_m='.$mon.'&cal_y='.$yr; // For filtering
- $content='<div class="filters">';
- $content.=calendar_filter_controls($view, $getvars, NULL, $courses);
- $content.='</div>';
-
- print_side_block(get_string('eventskey', 'calendar'),$content);
-
- $content='<div class="minicalendarblock minicalendartop">';
- $content.=calendar_top_controls('display', array('id' => $courseid, 'm' => $prevmon, 'y' => $prevyr));
- $content.=calendar_get_mini($courses, $groups, $users, $prevmon, $prevyr);
- $content.='</div><div class="minicalendarblock">';
- $content.=calendar_top_controls('display', array('id' => $courseid, 'm' => $mon, 'y' => $yr));
- $content.=calendar_get_mini($courses, $groups, $users, $mon, $yr);
- $content.='</div><div class="minicalendarblock">';
- $content.=calendar_top_controls('display', array('id' => $courseid, 'm' => $nextmon, 'y' => $nextyr));
- $content.=calendar_get_mini($courses, $groups, $users, $nextmon, $nextyr);
- $content.='</div>';
-
- print_side_block(get_string('monthlyview', 'calendar'),$content);
+$content='<div class="filters">';
+$content.=calendar_filter_controls($view, $getvars, NULL, $courses);
+$content.='</div>';
+
+$bc = new block_contents();
+$bc->content = $content;
+$bc->footer = '';
+$bc->title = strip_tags(get_string('eventskey', 'calendar'));
+echo $OUTPUT->block($bc, BLOCK_POS_LEFT);
+
+$content='<div class="minicalendarblock minicalendartop">';
+$content.=calendar_top_controls('display', array('id' => $courseid, 'm' => $prevmon, 'y' => $prevyr));
+$content.=calendar_get_mini($courses, $groups, $users, $prevmon, $prevyr);
+$content.='</div><div class="minicalendarblock">';
+$content.=calendar_top_controls('display', array('id' => $courseid, 'm' => $mon, 'y' => $yr));
+$content.=calendar_get_mini($courses, $groups, $users, $mon, $yr);
+$content.='</div><div class="minicalendarblock">';
+$content.=calendar_top_controls('display', array('id' => $courseid, 'm' => $nextmon, 'y' => $nextyr));
+$content.=calendar_get_mini($courses, $groups, $users, $nextmon, $nextyr);
+$content.='</div>';
+
+$bc = new block_contents();
+$bc->content = $content;
+$bc->footer = '';
+$bc->title = strip_tags(get_string('monthlyview', 'calendar'));
+echo $OUTPUT->block($bc, BLOCK_POS_LEFT);
- echo '</td>';
+echo '</td>';
- echo '</tr></table>';
+echo '</tr></table>';
- echo $OUTPUT->footer();
+echo $OUTPUT->footer();
$events = calendar_get_upcoming($courses, $groups, $users, 1, 100, $starttime);
$text = '';
- if (!isguest() && !empty($USER->id) && calendar_user_can_add_event()) {
+ if (!has_capability('moodle/legacy:guest', get_context_instance(CONTEXT_SYSTEM), 0, false) && !empty($USER->id) && calendar_user_can_add_event()) {
$text.= '<div class="buttons">';
$text.= '<form action="'.CALENDAR_URL.'event.php" method="get">';
$text.= '<div>';
calendar_events_by_day($events, $m, $y, $eventsbyday, $durationbyday, $typesbyday, $courses);
$text = '';
- if(!isguest() && !empty($USER->id) && calendar_user_can_add_event()) {
+ if(!has_capability('moodle/legacy:guest', get_context_instance(CONTEXT_SYSTEM), 0, false) && !empty($USER->id) && calendar_user_can_add_event()) {
$text.= '<div class="buttons"><form action="'.CALENDAR_URL.'event.php" method="get">';
$text.= '<div>';
$text.= '<input type="hidden" name="action" value="new" />';
echo "</tr>\n";
- if(!empty($USER->id) && !isguest()) {
+ if(!empty($USER->id) && !has_capability('moodle/legacy:guest', get_context_instance(CONTEXT_SYSTEM), 0, false)) {
echo '<tr>';
// Group events
if($SESSION->cal_show_groups) {
$text = '';
- if(!isguest() && !empty($USER->id) && calendar_user_can_add_event()) {
+ if(!has_capability('moodle/legacy:guest', get_context_instance(CONTEXT_SYSTEM), 0, false) && !empty($USER->id) && calendar_user_can_add_event()) {
$text.= '<div class="buttons">';
$text.= '<form action="'.CALENDAR_URL.'event.php" method="get">';
$text.= '<div>';
function calendar_course_filter_selector($getvars = '') {
global $USER, $SESSION, $OUTPUT;
- if (empty($USER->id) or isguest()) {
+ if (empty($USER->id) or has_capability('moodle/legacy:guest', get_context_instance(CONTEXT_SYSTEM), 0, false)) {
return '';
}