calendar MDL-19793 Upgrade deprecated calls and added set_url calls
authorsamhemelryk <samhemelryk>
Tue, 29 Sep 2009 02:51:00 +0000 (02:51 +0000)
committersamhemelryk <samhemelryk>
Tue, 29 Sep 2009 02:51:00 +0000 (02:51 +0000)
calendar/event.php
calendar/export.php
calendar/index.php
calendar/lib.php
calendar/preferences.php
calendar/set.php
calendar/view.php

index c9089ef..3a975da 100644 (file)
@@ -1,4 +1,4 @@
-<?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&amp;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&amp;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&amp;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&amp;id='.$form->id, $form->name);
+                        $timestartoffset = 'timestart - '.($event->timestart - $form->timestart);
                     }
 
-                    // OK, now redirect to day view
-                    redirect(CALENDAR_URL.'view.php?view=day&amp;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&amp;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&amp;id='.$form->id, $form->name);
                 }
+
+                // OK, now redirect to day view
+                redirect(CALENDAR_URL.'view.php?view=day&amp;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&amp;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&amp;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&amp;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&amp;id='.$eventid, $form->name);
                     }
-                    // OK, now redirect to day view
-                    redirect(CALENDAR_URL.'view.php?view=day&amp;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&amp;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&amp;course='.$urlcourse.'&amp;',
-                                   $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&amp;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&amp;course='.$urlcourse.'&amp;',
+                               $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&amp;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.'&amp;type='.$eventtype.'&amp;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.'&amp;type='.$eventtype.'&amp;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) {
@@ -651,4 +659,5 @@ function calendar_add_event_allowed($event) {
             return false;
     }
 }
-?>
+
+?>
\ No newline at end of file
index f759edf..50a8bb3 100644 (file)
@@ -1,4 +1,50 @@
-<?php // $Id$
+<?php
+
+/////////////////////////////////////////////////////////////////////////////
+//                                                                         //
+// NOTICE OF COPYRIGHT                                                     //
+//                                                                         //
+// Moodle - Calendar extension                                             //
+//                                                                         //
+// Copyright (C) 2003-2004  Greek School Network            www.sch.gr     //
+//                                                                         //
+// Designed by:                                                            //
+//     Avgoustos Tsinakos (tsinakos@teikav.edu.gr)                         //
+//     Jon Papaioannou (pj@moodle.org)                                     //
+//                                                                         //
+// Programming and development:                                            //
+//     Jon Papaioannou (pj@moodle.org)                                     //
+//                                                                         //
+// For bugs, suggestions, etc contact:                                     //
+//     Jon Papaioannou (pj@moodle.org)                                     //
+//                                                                         //
+// The current module was developed at the University of Macedonia         //
+// (www.uom.gr) under the funding of the Greek School Network (www.sch.gr) //
+// The aim of this project is to provide additional and improved           //
+// functionality to the Asynchronous Distance Education service that the   //
+// Greek School Network deploys.                                           //
+//                                                                         //
+// This program is free software; you can redistribute it and/or modify    //
+// it under the terms of the GNU General Public License as published by    //
+// the Free Software Foundation; either version 2 of the License, or       //
+// (at your option) any later version.                                     //
+//                                                                         //
+// This program is distributed in the hope that it will be useful,         //
+// but WITHOUT ANY WARRANTY; without even the implied warranty of          //
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the           //
+// GNU General Public License for more details:                            //
+//                                                                         //
+//          http://www.gnu.org/copyleft/gpl.html                           //
+//                                                                         //
+/////////////////////////////////////////////////////////////////////////////
+
+/**
+ * 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.'/course/lib.php');
@@ -15,6 +61,24 @@ if ($courseid = optional_param('course', 0, PARAM_INT)) {
     $course = NULL;
 }
 
+$url = new moodle_url($CFG->wwwroot.'/calendar/export.php');
+if ($action !== '') {
+    $url->param('action', $action);
+}
+if ($cal_d !== 0) {
+    $url->param('cal_d', $cal_d);
+}
+if ($cal_m !== 0) {
+    $url->param('cal_m', $cal_m);
+}
+if ($cal_y !== 0) {
+    $url->param('cal_y', $cal_y);
+}
+if ($course !== 0) {
+    $url->param('course', $course);
+}
+$PAGE->set_url($url);
+
 require_login();
 
 if (empty($CFG->enablecalendarexport)) {
@@ -43,14 +107,16 @@ if(!checkdate($mon, $day, $yr)) {
 }
 $time = make_timestamp($yr, $mon, $day);
 
-if (empty($USER->id) or isguest()) {
+$isguest = has_capability('moodle/legacy:guest', get_context_instance(CONTEXT_SYSTEM), 0, false);
+
+if (empty($USER->id) or $isguest) {
     $defaultcourses = calendar_get_default_courses();
     calendar_set_filters($courses, $groups, $users, $defaultcourses, $defaultcourses);
 } else {
     calendar_set_filters($courses, $groups, $users);
 }
 
-if (empty($USER->id) or isguest()) {
+if (empty($USER->id) or $isguest) {
     $defaultcourses = calendar_get_default_courses();
     calendar_set_filters($courses, $groups, $users, $defaultcourses, $defaultcourses);
 
index 53490cb..271f9f1 100644 (file)
@@ -1,7 +1,5 @@
-<?php // %Id%
+<?php
 
-    require('../config.php');
-
-    redirect($CFG->wwwroot.'/calendar/view.php');
-
-?>
+require('../config.php');
+$PAGE->set_url(new moodle_url($CFG->wwwroot.'/calendar/view.php'));
+redirect($CFG->wwwroot.'/calendar/view.php');
\ No newline at end of file
index 3b95bac..310c23b 100644 (file)
@@ -1,4 +1,4 @@
-<?php // $Id$
+<?php
 
 /////////////////////////////////////////////////////////////////////////////
 //                                                                         //
@@ -845,7 +845,7 @@ function calendar_filter_controls($type, $vars = NULL, $course = NULL, $courses
     }
 
 
-    if(!empty($USER->id) && !isguest()) {
+    if(!empty($USER->id) && !has_capability('moodle/legacy:guest', get_context_instance(CONTEXT_SYSTEM), 0, false)) {
         $content .= "</tr>\n<tr>";
 
         if($groupevents) {
@@ -1426,7 +1426,7 @@ function calendar_preferences_button() {
     global $CFG, $USER;
 
     // Guests have no preferences
-    if (empty($USER->id) || isguest()) {
+    if (empty($USER->id) || has_capability('moodle/legacy:guest', get_context_instance(CONTEXT_SYSTEM), 0, false)) {
         return '';
     }
 
index 39fb7aa..b27e599 100644 (file)
@@ -1,87 +1,88 @@
-<?PHP  // $Id$
-       // preferences.php - user prefs for calendar
+<?php
 
-    require_once('../config.php');
-    require_once($CFG->dirroot.'/calendar/lib.php');
+// preferences.php - user prefs for calendar
 
-    if (isset($SESSION->cal_course_referer)) {
-        if (! $course = $DB->get_record('course', array('id'=>$SESSION->cal_course_referer))) {
-            $course = get_site();
-        }
-    }
+require_once('../config.php');
+require_once($CFG->dirroot.'/calendar/lib.php');
 
-    if ($course->id != SITEID) {
-        require_login($course->id);
+if (isset($SESSION->cal_course_referer)) {
+    if (! $course = $DB->get_record('course', array('id'=>$SESSION->cal_course_referer))) {
+        $course = get_site();
     }
-    // Initialize the session variables
-    calendar_session_vars();
+}
+
+$PAGE->set_url(new moodle_url($CFG->wwwroot.'/calendar/preferences.php'));
+
+if ($course->id != SITEID) {
+    require_login($course->id);
+}
+// Initialize the session variables
+calendar_session_vars();
 
 /// If data submitted, then process and store.
 
-    if ($form = data_submitted()) {
-        foreach ($form as $preference => $value) {
-            switch ($preference) {
-                case 'timeformat':
-                    if ($value != CALENDAR_TF_12 and $value != CALENDAR_TF_24) {
-                        $value = '';
-                    }
-                    set_user_preference('calendar_timeformat', $value);
-                break;
-                case 'startwday':
-                    $value = intval($value);
-                    if ($value < 0 or $value > 6) {
-                        $value = abs($value % 7);
-                    }
-                    set_user_preference('calendar_startwday', $value);
-                break;
-                case 'maxevents':
-                    if (intval($value) >= 1) {
-                        set_user_preference('calendar_maxevents', $value);
-                    }
-                break;
-                case 'lookahead':
-                    if (intval($value) >= 1) {
-                        set_user_preference('calendar_lookahead', $value);
-                    }
-                break;
-                case 'persistflt':
-                    set_user_preference('calendar_persistflt', intval($value));
-                break;
-            }
+if ($form = data_submitted()) {
+    foreach ($form as $preference => $value) {
+        switch ($preference) {
+            case 'timeformat':
+                if ($value != CALENDAR_TF_12 and $value != CALENDAR_TF_24) {
+                    $value = '';
+                }
+                set_user_preference('calendar_timeformat', $value);
+            break;
+            case 'startwday':
+                $value = intval($value);
+                if ($value < 0 or $value > 6) {
+                    $value = abs($value % 7);
+                }
+                set_user_preference('calendar_startwday', $value);
+            break;
+            case 'maxevents':
+                if (intval($value) >= 1) {
+                    set_user_preference('calendar_maxevents', $value);
+                }
+            break;
+            case 'lookahead':
+                if (intval($value) >= 1) {
+                    set_user_preference('calendar_lookahead', $value);
+                }
+            break;
+            case 'persistflt':
+                set_user_preference('calendar_persistflt', intval($value));
+            break;
         }
-        redirect('view.php?course='.$course->id, get_string('changessaved'), 1);
-        exit;
     }
+    redirect('view.php?course='.$course->id, get_string('changessaved'), 1);
+    exit;
+}
 
-    $site = get_site();
-
-    $strcalendar = get_string('calendar', 'calendar');
-    $strpreferences = get_string('preferences', 'calendar');
+$site = get_site();
 
-    if ($course->id != SITEID) {
-       $PAGE->navbar-add($course->shortname, new moodle_url($CFG->wwwroot.'/course/view.php', array('id'=>$course->id)));
-    }
-    $PAGE->navbar->add($strpreferences, new moodle_url($CFG->wwwroot.'/calendar/view.php'));
+$strcalendar = get_string('calendar', 'calendar');
+$strpreferences = get_string('preferences', 'calendar');
 
-    $PAGE->set_title("$site->shortname: $strcalendar: $strpreferences");
-    $PAGE->set_heading($strcalendar);
-    $PAGE->set_headingmenu(user_login_string($site));
+if ($course->id != SITEID) {
+   $PAGE->navbar-add($course->shortname, new moodle_url($CFG->wwwroot.'/course/view.php', array('id'=>$course->id)));
+}
+$PAGE->navbar->add($strpreferences, new moodle_url($CFG->wwwroot.'/calendar/view.php'));
 
-    echo $OUTPUT->header();
+$PAGE->set_title("$site->shortname: $strcalendar: $strpreferences");
+$PAGE->set_heading($strcalendar);
+$PAGE->set_headingmenu(user_login_string($site));
 
-    echo $OUTPUT->heading($strpreferences);
+echo $OUTPUT->header();
 
-    echo $OUTPUT->box_start('generalbox boxaligncenter');
+echo $OUTPUT->heading($strpreferences);
 
-    $prefs->timeformat = get_user_preferences('calendar_timeformat', '');
-    $prefs->startwday  = get_user_preferences('calendar_startwday', CALENDAR_STARTING_WEEKDAY);
-    $prefs->maxevents  = get_user_preferences('calendar_maxevents', CALENDAR_UPCOMING_MAXEVENTS);
-    $prefs->lookahead  = get_user_preferences('calendar_lookahead', CALENDAR_UPCOMING_DAYS);
-    $prefs->persistflt = get_user_preferences('calendar_persistflt', 0);
+echo $OUTPUT->box_start('generalbox boxaligncenter');
 
-    include('./preferences.html');
-    echo $OUTPUT->box_end();
+$prefs->timeformat = get_user_preferences('calendar_timeformat', '');
+$prefs->startwday  = get_user_preferences('calendar_startwday', CALENDAR_STARTING_WEEKDAY);
+$prefs->maxevents  = get_user_preferences('calendar_maxevents', CALENDAR_UPCOMING_MAXEVENTS);
+$prefs->lookahead  = get_user_preferences('calendar_lookahead', CALENDAR_UPCOMING_DAYS);
+$prefs->persistflt = get_user_preferences('calendar_persistflt', 0);
 
-    echo $OUTPUT->footer();
+include('./preferences.html');
+echo $OUTPUT->box_end();
 
-?>
+echo $OUTPUT->footer();
\ No newline at end of file
index 106c940..7853cc1 100644 (file)
@@ -1,4 +1,4 @@
-<?php // $Id$
+<?php
 
 /////////////////////////////////////////////////////////////////////////////
 //                                                                         //
 //                                                                         //
 /////////////////////////////////////////////////////////////////////////////
 
-    require_once('../config.php');
-    require_once($CFG->dirroot.'/calendar/lib.php');
+require_once('../config.php');
+require_once($CFG->dirroot.'/calendar/lib.php');
 
-    $from = required_param('from', PARAM_ALPHA);
-    $var = required_param('var', PARAM_ALPHA);
-    $id = optional_param('id', 0, PARAM_INT);
-    $cal_d = optional_param('cal_d', 0, PARAM_INT);
-    $cal_m = optional_param('cal_m', 0, PARAM_INT);
-    $cal_y = optional_param('cal_y', 0, PARAM_INT);
-    $action = optional_param('action', '', PARAM_ALPHA);
-    $type = optional_param('type', '', PARAM_ALPHA);
+$from = required_param('from', PARAM_ALPHA);
+$var = required_param('var', PARAM_ALPHA);
+$id = optional_param('id', 0, PARAM_INT);
+$cal_d = optional_param('cal_d', 0, PARAM_INT);
+$cal_m = optional_param('cal_m', 0, PARAM_INT);
+$cal_y = optional_param('cal_y', 0, PARAM_INT);
+$action = optional_param('action', '', PARAM_ALPHA);
+$type = optional_param('type', '', PARAM_ALPHA);
 
-    // Initialize the session variables
-    calendar_session_vars();
+$url = new moodle_url($CFG->wwwroot.'/calendar/set.php', array('from'=>$from,'var'=>$var));
+if ($id !== 0) {
+    $url->param('id', $id);
+}
+if ($cal_d !== 0) {
+    $url->param('cal_d', $cal_d);
+}
+if ($cal_m !== 0) {
+    $url->param('cal_m', $cal_m);
+}
+if ($cal_y !== 0) {
+    $url->param('cal_y', $cal_y);
+}
+if ($action !== 0) {
+    $url->param('action', $action);
+}
+if ($type !== 0) {
+    $url->param('type', $type);
+}
+$PAGE->set_url($url);
 
-    // Ensure course id passed if relevant
-    // Required due to changes in view/lib.php mainly (calendar_session_vars())
-    $courseid = '';
-    if (!empty($id)) {
-        $courseid = '&amp;course='.$id;
-    }
+// Initialize the session variables
+calendar_session_vars();
 
-    switch($var) {
-        case 'setuser':
-            // Not implemented yet (or possibly at all)
-        break;
-        case 'setcourse':
-            $id = intval($id);
-            if($id == 0) {
+// Ensure course id passed if relevant
+// Required due to changes in view/lib.php mainly (calendar_session_vars())
+$courseid = '';
+if (!empty($id)) {
+    $courseid = '&amp;course='.$id;
+}
+
+switch($var) {
+    case 'setuser':
+        // Not implemented yet (or possibly at all)
+    break;
+    case 'setcourse':
+        $id = intval($id);
+        if($id == 0) {
+            $SESSION->cal_courses_shown = array();
+            calendar_set_referring_course(0);
+        }
+        else if($id == 1) {
+            $SESSION->cal_courses_shown = calendar_get_default_courses(true);
+            calendar_set_referring_course(0);
+        }
+        else {
+            if($DB->get_record('course', array('id'=>$id)) === false) {
+                // There is no such course
                 $SESSION->cal_courses_shown = array();
                 calendar_set_referring_course(0);
             }
-            else if($id == 1) {
-                $SESSION->cal_courses_shown = calendar_get_default_courses(true);
-                calendar_set_referring_course(0);
-            }
             else {
-                if($DB->get_record('course', array('id'=>$id)) === false) {
-                    // There is no such course
-                    $SESSION->cal_courses_shown = array();
-                    calendar_set_referring_course(0);
-                }
-                else {
-                    calendar_set_referring_course($id);
-                    $SESSION->cal_courses_shown = $id;
-                }
+                calendar_set_referring_course($id);
+                $SESSION->cal_courses_shown = $id;
             }
-        break;
-        case 'showgroups':
-            $SESSION->cal_show_groups = !$SESSION->cal_show_groups;
-            set_user_preference('calendar_savedflt', calendar_get_filters_status());
-        break;
-        case 'showcourses':
-            $SESSION->cal_show_course = !$SESSION->cal_show_course;
-            set_user_preference('calendar_savedflt', calendar_get_filters_status());
-        break;
-        case 'showglobal':
-            $SESSION->cal_show_global = !$SESSION->cal_show_global;
-            set_user_preference('calendar_savedflt', calendar_get_filters_status());
-        break;
-        case 'showuser':
-            $SESSION->cal_show_user = !$SESSION->cal_show_user;
-            set_user_preference('calendar_savedflt', calendar_get_filters_status());
-        break;
-    }
+        }
+    break;
+    case 'showgroups':
+        $SESSION->cal_show_groups = !$SESSION->cal_show_groups;
+        set_user_preference('calendar_savedflt', calendar_get_filters_status());
+    break;
+    case 'showcourses':
+        $SESSION->cal_show_course = !$SESSION->cal_show_course;
+        set_user_preference('calendar_savedflt', calendar_get_filters_status());
+    break;
+    case 'showglobal':
+        $SESSION->cal_show_global = !$SESSION->cal_show_global;
+        set_user_preference('calendar_savedflt', calendar_get_filters_status());
+    break;
+    case 'showuser':
+        $SESSION->cal_show_user = !$SESSION->cal_show_user;
+        set_user_preference('calendar_savedflt', calendar_get_filters_status());
+    break;
+}
 
-    switch($from) {
-        case 'event':
-            redirect(CALENDAR_URL.'event.php?action='.$action.'&amp;type='.$type.'&amp;id='.intval($id));
-        break;
-        case 'month':
-            redirect(CALENDAR_URL.'view.php?view=month'.$courseid.'&cal_d='.$cal_d.'&cal_m='.$cal_m.'&cal_y='.$cal_y);
-        break;
-        case 'upcoming':
-            redirect(CALENDAR_URL.'view.php?view=upcoming'.$courseid);
-        break;
-        case 'day':
-            redirect(CALENDAR_URL.'view.php?view=day'.$courseid.'&cal_d='.$cal_d.'&cal_m='.$cal_m.'&cal_y='.$cal_y);
-        break;
-        case 'course':
-            redirect($CFG->wwwroot.'/course/view.php?id='.intval($id));
-        break;
-        default:
+switch($from) {
+    case 'event':
+        redirect(CALENDAR_URL.'event.php?action='.$action.'&amp;type='.$type.'&amp;id='.intval($id));
+    break;
+    case 'month':
+        redirect(CALENDAR_URL.'view.php?view=month'.$courseid.'&cal_d='.$cal_d.'&cal_m='.$cal_m.'&cal_y='.$cal_y);
+    break;
+    case 'upcoming':
+        redirect(CALENDAR_URL.'view.php?view=upcoming'.$courseid);
+    break;
+    case 'day':
+        redirect(CALENDAR_URL.'view.php?view=day'.$courseid.'&cal_d='.$cal_d.'&cal_m='.$cal_m.'&cal_y='.$cal_y);
+    break;
+    case 'course':
+        redirect($CFG->wwwroot.'/course/view.php?id='.intval($id));
+    break;
+    default:
 
-    }
-?>
+}
\ No newline at end of file
index 255e849..051025f 100644 (file)
@@ -1,4 +1,4 @@
-<?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&amp;course='.$courseid.'&amp;',
-                                   $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&amp;course='.$courseid.'&amp;',
+                               $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&amp;preset_time=recentupcoming&amp;username=$usernameencoded&amp;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&amp;preset_time=recentupcoming&amp;username=$usernameencoded&amp;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.'&amp;cal_d='.$day.'&amp;cal_m='.$mon.'&amp;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.'&amp;cal_d='.$day.'&amp;cal_m='.$mon.'&amp;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();
 
 
 
@@ -255,7 +263,7 @@ function calendar_show_day($d, $m, $y, $courses, $groups, $users, $courseid) {
     $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>';
@@ -396,7 +404,7 @@ function calendar_show_month_detailed($m, $y, $courses, $groups, $users, $course
     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" />';
@@ -556,7 +564,7 @@ function calendar_show_month_detailed($m, $y, $courses, $groups, $users, $course
                 
             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) {         
@@ -589,7 +597,7 @@ function calendar_show_upcoming_events($courses, $groups, $users, $futuredays, $
 
     $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>';
@@ -623,7 +631,7 @@ function calendar_show_upcoming_events($courses, $groups, $users, $futuredays, $
 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 '';
     }