function get_content() { global $USER, $CFG, $SESSION, $COURSE; $cal_m = optional_param('cal_m', 0, PARAM_INT); $cal_y = optional_param('cal_y', 0, PARAM_INT); require_once $CFG->dirroot . '/calendar/lib.php'; if ($this->content !== NULL) { return $this->content; } // Reset the session variables calendar_session_vars($COURSE); $this->content = new stdClass(); $this->content->text = ''; $this->content->footer = ''; // [pj] To me it looks like this if would never be needed, but Penny added it // when committing the /my/ stuff. Reminder to discuss and learn what it's about. // It definitely needs SOME comment here! $courseshown = $COURSE->id; if ($courseshown == SITEID) { // Being displayed at site level. This will cause the filter to fall back to auto-detecting // the list of courses it will be grabbing events from. $filtercourse = NULL; $groupeventsfrom = NULL; $SESSION->cal_courses_shown = calendar_get_default_courses(true); calendar_set_referring_course(0); } else { // Forcibly filter events to include only those from the particular course we are in. $filtercourse = array($courseshown => $COURSE); $groupeventsfrom = array($courseshown => 1); } // We 'll need this later calendar_set_referring_course($courseshown); // MDL-9059, set to show this course when admins go into a course, then unset it. if ($COURSE->id != SITEID && !isset($SESSION->cal_courses_shown[$COURSE->id]) && has_capability('moodle/calendar:manageentries', get_context_instance(CONTEXT_SYSTEM))) { $courseset = true; $SESSION->cal_courses_shown[$COURSE->id] = $COURSE; } // Be VERY careful with the format for default courses arguments! // Correct formatting is [courseid] => 1 to be concise with moodlelib.php functions. calendar_set_filters($courses, $group, $user, $filtercourse, $groupeventsfrom, false); if ($courseshown == SITEID) { // For the front page $this->content->text .= calendar_overlib_html(); $this->content->text .= calendar_top_controls('frontpage', array('id' => $courseshown, 'm' => $cal_m, 'y' => $cal_y)); $this->content->text .= calendar_get_mini($courses, $group, $user, $cal_m, $cal_y); // No filters for now } else { // For any other course $this->content->text .= calendar_overlib_html(); $this->content->text .= calendar_top_controls('course', array('id' => $courseshown, 'm' => $cal_m, 'y' => $cal_y)); $this->content->text .= calendar_get_mini($courses, $group, $user, $cal_m, $cal_y); $this->content->text .= '<h3 class="eventskey">' . get_string('eventskey', 'calendar') . '</h3>'; $this->content->text .= '<div class="filters">' . calendar_filter_controls('course', '', $COURSE) . '</div>'; } // MDL-9059, unset this so that it doesn't stay in session if (!empty($courseset)) { unset($SESSION->cal_courses_shown[$COURSE->id]); } return $this->content; }
function get_content() { global $USER, $CFG, $SESSION, $COURSE; $cal_m = optional_param('cal_m', 0, PARAM_INT); $cal_y = optional_param('cal_y', 0, PARAM_INT); require_once $CFG->dirroot . '/calendar/lib.php'; if ($this->content !== NULL) { return $this->content; } // Reset the session variables calendar_session_vars($COURSE); $this->content = new stdClass(); $this->content->text = ''; if (empty($this->instance)) { // Overrides: use no course at all $courseshown = false; $filtercourse = array(); $this->content->footer = ''; } else { $courseshown = $COURSE->id; $this->content->footer = '<br /><a href="' . $CFG->wwwroot . '/calendar/view.php?view=upcoming&course=' . $courseshown . '">' . get_string('gotocalendar', 'calendar') . '</a>...'; $context = get_context_instance(CONTEXT_COURSE, $courseshown); if (has_capability('moodle/calendar:manageentries', $context) || has_capability('moodle/calendar:manageownentries', $context)) { $this->content->footer .= '<br /><a href="' . $CFG->wwwroot . '/calendar/event.php?action=new&course=' . $courseshown . '">' . get_string('newevent', 'calendar') . '</a>...'; } if ($courseshown == SITEID) { // Being displayed at site level. This will cause the filter to fall back to auto-detecting // the list of courses it will be grabbing events from. $filtercourse = NULL; $groupeventsfrom = NULL; $SESSION->cal_courses_shown = calendar_get_default_courses(true); calendar_set_referring_course(0); } else { // Forcibly filter events to include only those from the particular course we are in. $filtercourse = array($courseshown => $COURSE); $groupeventsfrom = array($courseshown => 1); } } // We 'll need this later calendar_set_referring_course($courseshown); // Be VERY careful with the format for default courses arguments! // Correct formatting is [courseid] => 1 to be concise with moodlelib.php functions. calendar_set_filters($courses, $group, $user, $filtercourse, $groupeventsfrom, false); $events = calendar_get_upcoming($courses, $group, $user, get_user_preferences('calendar_lookahead', CALENDAR_UPCOMING_DAYS), get_user_preferences('calendar_maxevents', CALENDAR_UPCOMING_MAXEVENTS)); if (!empty($this->instance)) { $this->content->text = calendar_get_sideblock_upcoming($events, 'view.php?view=day&course=' . $courseshown . '&'); } if (empty($this->content->text)) { $this->content->text = '<div class="post">' . get_string('noupcomingevents', 'calendar') . '</div>'; } return $this->content; }
function get_content() { global $USER, $CFG, $SESSION; $cal_m = optional_param('cal_m', 0, PARAM_INT); $cal_y = optional_param('cal_y', 0, PARAM_INT); require_once $CFG->dirroot . '/calendar/lib.php'; if ($this->content !== NULL) { return $this->content; } $this->content = new stdClass(); $this->content->text = ''; $filtercourse = array(); if (empty($this->instance)) { // Overrides: use no course at all $courseshown = false; $this->content->footer = ''; } else { $courseshown = $this->page->course->id; $this->content->footer = '<div class="gotocal"><a href="' . $CFG->wwwroot . '/calendar/view.php?view=upcoming&course=' . $courseshown . '">' . get_string('gotocalendar', 'calendar') . '</a>...</div>'; $context = context_course::instance($courseshown); if (has_any_capability(array('moodle/calendar:manageentries', 'moodle/calendar:manageownentries'), $context)) { $this->content->footer .= '<div class="newevent"><a href="' . $CFG->wwwroot . '/calendar/event.php?action=new&course=' . $courseshown . '">' . get_string('newevent', 'calendar') . '</a>...</div>'; } if ($courseshown == SITEID) { // Being displayed at site level. This will cause the filter to fall back to auto-detecting // the list of courses it will be grabbing events from. $filtercourse = calendar_get_default_courses(); } else { // Forcibly filter events to include only those from the particular course we are in. $filtercourse = array($courseshown => $this->page->course); } } list($courses, $group, $user) = calendar_set_filters($filtercourse); $defaultlookahead = CALENDAR_DEFAULT_UPCOMING_LOOKAHEAD; if (isset($CFG->calendar_lookahead)) { $defaultlookahead = intval($CFG->calendar_lookahead); } $lookahead = get_user_preferences('calendar_lookahead', $defaultlookahead); $defaultmaxevents = CALENDAR_DEFAULT_UPCOMING_MAXEVENTS; if (isset($CFG->calendar_maxevents)) { $defaultmaxevents = intval($CFG->calendar_maxevents); } $maxevents = get_user_preferences('calendar_maxevents', $defaultmaxevents); $events = calendar_get_upcoming($courses, $group, $user, $lookahead, $maxevents); if (!empty($this->instance)) { $this->content->text = calendar_get_block_upcoming($events, 'view.php?view=day&course=' . $courseshown . '&'); } if (empty($this->content->text)) { $this->content->text = '<div class="post">' . get_string('noupcomingevents', 'calendar') . '</div>'; } return $this->content; }
/** * Return the content of this block. * * @return stdClass the content */ public function get_content() { global $CFG; $calm = optional_param('cal_m', 0, PARAM_INT); $caly = optional_param('cal_y', 0, PARAM_INT); $time = optional_param('time', 0, PARAM_INT); require_once $CFG->dirroot . '/calendar/lib.php'; if ($this->content !== null) { return $this->content; } // If a day, month and year were passed then convert it to a timestamp. If these were passed then we can assume // the day, month and year are passed as Gregorian, as no where in core should we be passing these values rather // than the time. This is done for BC. if (!empty($calm) && !empty($caly)) { $time = make_timestamp($caly, $calm, 1); } else { if (empty($time)) { $time = time(); } } $this->content = new stdClass(); $this->content->text = ''; $this->content->footer = ''; // [pj] To me it looks like this if would never be needed, but Penny added it // when committing the /my/ stuff. Reminder to discuss and learn what it's about. // It definitely needs SOME comment here! $courseid = $this->page->course->id; $issite = $courseid == SITEID; if ($issite) { // Being displayed at site level. This will cause the filter to fall back to auto-detecting // the list of courses it will be grabbing events from. $filtercourse = calendar_get_default_courses(); } else { // Forcibly filter events to include only those from the particular course we are in. $filtercourse = array($courseid => $this->page->course); } list($courses, $group, $user) = calendar_set_filters($filtercourse); if ($issite) { // For the front page. $this->content->text .= calendar_get_mini($courses, $group, $user, false, false, 'frontpage', $courseid, $time); // No filters for now. } else { // For any other course. $this->content->text .= calendar_get_mini($courses, $group, $user, false, false, 'course', $courseid, $time); $this->content->text .= '<h3 class="eventskey">' . get_string('eventskey', 'calendar') . '</h3>'; $this->content->text .= '<div class="filters calendar_filters">' . calendar_filter_controls($this->page->url) . '</div>'; } return $this->content; }
function organizer_add_calendar() { global $PAGE, $DB; $courseid = optional_param('course', SITEID, PARAM_INT); if ($courseid != SITEID && !empty($courseid)) { $course = $DB->get_record('course', array('id' => $courseid)); $courses = array($course->id => $course); $issite = false; } else { $course = get_site(); $courses = calendar_get_default_courses(); $issite = true; } $now = usergetdate(time()); $calendar = new calendar_information($now['mday'], $now['mon'], $now['year']); $calendar->prepare_for_view($course, $courses); $renderer = $PAGE->get_renderer('core_calendar'); $calendar->add_sidecalendar_blocks($renderer, true, 'month'); $PAGE->requires->js_init_call('M.mod_organizer.fix_calendar_styles'); }
function get_content() { global $USER, $CFG, $SESSION; $cal_m = optional_param('cal_m', 0, PARAM_INT); $cal_y = optional_param('cal_y', 0, PARAM_INT); require_once $CFG->dirroot . '/calendar/lib.php'; if ($this->content !== NULL) { return $this->content; } $this->content = new stdClass(); $this->content->text = ''; $this->content->footer = ''; // [pj] To me it looks like this if would never be needed, but Penny added it // when committing the /my/ stuff. Reminder to discuss and learn what it's about. // It definitely needs SOME comment here! $courseid = $this->page->course->id; $issite = $courseid == SITEID; if ($issite) { // Being displayed at site level. This will cause the filter to fall back to auto-detecting // the list of courses it will be grabbing events from. $filtercourse = calendar_get_default_courses(); } else { // Forcibly filter events to include only those from the particular course we are in. $filtercourse = array($courseid => $this->page->course); } list($courses, $group, $user) = calendar_set_filters($filtercourse); if ($issite) { // For the front page $this->content->text .= calendar_top_controls('frontpage', array('id' => $courseid, 'm' => $cal_m, 'y' => $cal_y)); $this->content->text .= calendar_get_mini($courses, $group, $user, $cal_m, $cal_y); // No filters for now } else { // For any other course $this->content->text .= calendar_top_controls('course', array('id' => $courseid, 'm' => $cal_m, 'y' => $cal_y)); $this->content->text .= calendar_get_mini($courses, $group, $user, $cal_m, $cal_y); $this->content->text .= '<h3 class="eventskey">' . get_string('eventskey', 'calendar') . '</h3>'; $this->content->text .= '<div class="filters">' . calendar_filter_controls($this->page->url) . '</div>'; } return $this->content; }
$pollinterval = optional_param('pollinterval', 0, PARAM_INT); $action = optional_param('action', '', PARAM_ALPHA); $url = new moodle_url('/calendar/managesubscriptions.php'); if ($courseid != SITEID) { $url->param('course', $courseid); } navigation_node::override_active_url(new moodle_url('/calendar/view.php', array('view' => 'month'))); $PAGE->set_url($url); $PAGE->set_pagelayout('standard'); $PAGE->navbar->add(get_string('managesubscriptions', 'calendar')); if ($courseid != SITEID && !empty($courseid)) { $course = $DB->get_record('course', array('id' => $courseid)); $courses = array($course->id => $course); } else { $course = get_site(); $courses = calendar_get_default_courses(); } require_course_login($course); if (!calendar_user_can_add_event($course)) { print_error('errorcannotimport', 'calendar'); } $form = new calendar_addsubscription_form(null); $form->set_data(array('course' => $course->id)); $importresults = ''; $formdata = $form->get_data(); if (!empty($formdata)) { require_sesskey(); // Must have sesskey for all actions. $subscriptionid = calendar_add_subscription($formdata); if ($formdata->importfrom == CALENDAR_IMPORT_FROM_FILE) { // Blank the URL if it's a file import.
function calendar_session_vars($course = null) { global $SESSION, $USER; if (!empty($USER->id) && isset($USER->realuser) && !isset($SESSION->cal_loggedinas)) { // We just logged in as someone else, update the filtering unset($SESSION->cal_users_shown); unset($SESSION->cal_courses_shown); $SESSION->cal_loggedinas = true; if (intval(get_user_preferences('calendar_persistflt', 0))) { calendar_set_filters_status(get_user_preferences('calendar_savedflt', 0xff)); } } else { if (!empty($USER->id) && !isset($USER->realuser) && isset($SESSION->cal_loggedinas)) { // We just logged back to our real self, update again unset($SESSION->cal_users_shown); unset($SESSION->cal_courses_shown); unset($SESSION->cal_loggedinas); if (intval(get_user_preferences('calendar_persistflt', 0))) { calendar_set_filters_status(get_user_preferences('calendar_savedflt', 0xff)); } } } if (!isset($SESSION->cal_course_referer)) { $SESSION->cal_course_referer = 0; } if (!isset($SESSION->cal_show_global)) { $SESSION->cal_show_global = true; } if (!isset($SESSION->cal_show_groups)) { $SESSION->cal_show_groups = true; } if (!isset($SESSION->cal_show_course)) { $SESSION->cal_show_course = true; } if (!isset($SESSION->cal_show_user)) { $SESSION->cal_show_user = true; } if (isset($course)) { // speedup hack for calendar related blocks $SESSION->cal_courses_shown = array($course->id => $course); } else { $SESSION->cal_courses_shown = calendar_get_default_courses(true); } if (empty($SESSION->cal_users_shown)) { // The empty() instead of !isset() here makes a whole world of difference, // as it will automatically change to the user's id when the user first logs // in. With !isset(), it would never do that. $SESSION->cal_users_shown = !empty($USER->id) ? $USER->id : false; } else { if (is_numeric($SESSION->cal_users_shown) && !empty($USER->id) && $SESSION->cal_users_shown != $USER->id) { // Follow the white rabbit, for example if a teacher logs in as a student $SESSION->cal_users_shown = $USER->id; } } }
$courseid = ''; if (!empty($id)) { $courseid = '&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 { calendar_set_referring_course($id); $SESSION->cal_courses_shown = $id; } } } break; case 'showgroups': $SESSION->cal_show_groups = !$SESSION->cal_show_groups;
function startCalendar($course) { $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); // 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 = ''; $nav = calendar_get_link_tag(get_string('calendar', 'calendar'), CALENDAR_URL . 'view.php?view=upcoming&course=' . $course->id . '&', $now['mday'], $now['mon'], $now['year']); 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': $nav .= ' -> ' . userdate($time, get_string('strftimedate')); $pagetitle = get_string('dayview', 'calendar'); break; case 'month': $nav .= ' -> ' . 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($course->id)) { if ($course = get_record('course', 'id', $course->id)) { 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; } 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); } // 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 = get_field('course', 'shortname', 'id', $SESSION->cal_course_referer)) !== false) { // If we know about the referring course, show a return link and ALSO require login! require_login(); $nav = '<a href="' . $CFG->wwwroot . '/course/view.php?id=' . $SESSION->cal_course_referer . '">' . $shortname . '</a> -> ' . $nav; if (empty($course)) { $course = get_record('course', 'id', $SESSION->cal_course_referer); // Useful to have around } } $strcalendar = get_string('calendar', 'calendar'); $prefsbutton = calendar_preferences_button(); /// Print the page header if ($course->category) { $navigation = "<a href=\"../../course/view.php?id={$course->id}\">{$course->shortname}</a> ->"; } else { $navigation = ''; } echo calendar_overlib_html(); // Layout the whole page as three big columns. echo '<table id="calendar" style="height:100%;">'; echo '<tr>'; // START: Main column /// Print the main part of the pageecho $user; echo '<td class="maincalendar">'; echo '<div class="heightcontainer">'; }
function calendar_session_vars($course = null) { global $SESSION, $USER; if (!isset($SESSION->cal_course_referer)) { $SESSION->cal_course_referer = 0; } if (!isset($SESSION->cal_show_global)) { $SESSION->cal_show_global = true; } if (!isset($SESSION->cal_show_groups)) { $SESSION->cal_show_groups = true; } if (!isset($SESSION->cal_show_course)) { $SESSION->cal_show_course = true; } if (!isset($SESSION->cal_show_user)) { $SESSION->cal_show_user = true; } if ($course !== null) { // speedup hack for calendar related blocks if (isset($course->coursenode)) { // coursenode has been set up, which seems to break things further down the line. // Use a clone of $course with coursenode removed. $course = clone $course; unset($course->coursenode); } $SESSION->cal_courses_shown = array($course->id => $course); } else { $SESSION->cal_courses_shown = calendar_get_default_courses(true); } if (empty($SESSION->cal_users_shown)) { // The empty() instead of !isset() here makes a whole world of difference, // as it will automatically change to the user's id when the user first logs // in. With !isset(), it would never do that. $SESSION->cal_users_shown = isloggedin() ? $USER->id : false; } else { if (is_numeric($SESSION->cal_users_shown) && isloggedin() && $SESSION->cal_users_shown != $USER->id) { // Follow the white rabbit, for example if a teacher logs in as a student $SESSION->cal_users_shown = $USER->id; } } }
function calendar_session_vars($course = null) { global $SESSION, $USER; if (!isset($SESSION->cal_course_referer)) { $SESSION->cal_course_referer = 0; } if (!isset($SESSION->cal_show_global)) { $SESSION->cal_show_global = true; } if (!isset($SESSION->cal_show_groups)) { $SESSION->cal_show_groups = true; } if (!isset($SESSION->cal_show_course)) { $SESSION->cal_show_course = true; } if (!isset($SESSION->cal_show_user)) { $SESSION->cal_show_user = true; } if (isset($course)) { // speedup hack for calendar related blocks $SESSION->cal_courses_shown = array($course->id => $course); } else { $SESSION->cal_courses_shown = calendar_get_default_courses(true); } if (empty($SESSION->cal_users_shown)) { // The empty() instead of !isset() here makes a whole world of difference, // as it will automatically change to the user's id when the user first logs // in. With !isset(), it would never do that. $SESSION->cal_users_shown = !empty($USER->id) ? $USER->id : false; } else { if (is_numeric($SESSION->cal_users_shown) && !empty($USER->id) && $SESSION->cal_users_shown != $USER->id) { // Follow the white rabbit, for example if a teacher logs in as a student $SESSION->cal_users_shown = $USER->id; } } }
<?php global $USER, $CFG, $SESSION; $cal_m = optional_param('cal_m', 0, PARAM_INT); $cal_y = optional_param('cal_y', 0, PARAM_INT); require_once $CFG->dirroot . '/calendar/lib.php'; $filtercourse = array(); if (empty($this->instance)) { // Overrides: use no course at all $courseshown = false; } else { $courseshown = $this->page->course->id; } // Being displayed at site level. This will cause the filter to fall back to auto-detecting // the list of courses it will be grabbing events from. $filtercourse = calendar_get_default_courses(); list($courses, $group, $user) = calendar_set_filters($filtercourse); $defaultlookahead = CALENDAR_DEFAULT_UPCOMING_LOOKAHEAD; if (isset($CFG->calendar_lookahead)) { $defaultlookahead = intval($CFG->calendar_lookahead); } $lookahead = get_user_preferences('calendar_lookahead', $defaultlookahead); $defaultmaxevents = CALENDAR_DEFAULT_UPCOMING_MAXEVENTS; if (isset($CFG->calendar_maxevents)) { $defaultmaxevents = intval($CFG->calendar_maxevents); } $maxevents = 3; $events = calendar_get_upcoming($courses, $group, $user, $lookahead, $maxevents); $upcomingoutput = calendar_get_block_upcoming($events, 'view.php?view=day&course=' . $courseshown . '&'); echo $upcomingoutput; ?>