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'); }
if ($yr !== 0) { $url->param('cal_y', $yr); } $PAGE->set_url($url); if ($courseid != SITEID && !empty($courseid)) { $course = $DB->get_record('course', array('id' => $courseid)); $courses = array($course->id => $course); $issite = false; navigation_node::override_active_url(new moodle_url('/course/view.php', array('id' => $course->id))); } else { $course = get_site(); $courses = calendar_get_default_courses(); $issite = true; } require_course_login($course); $calendar = new calendar_information($day, $mon, $yr); $calendar->prepare_for_view($course, $courses); $now = usergetdate(time()); $pagetitle = ''; $strcalendar = get_string('calendar', 'calendar'); 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;
/** * Displays the calendar for a single day * * @param calendar_information $calendar * @return string */ public function show_day(calendar_information $calendar, moodle_url $returnurl = null) { if ($returnurl === null) { $returnurl = $this->page->url; } $events = calendar_get_upcoming($calendar->courses, $calendar->groups, $calendar->users, 1, 100, $calendar->timestamp_today()); $output = html_writer::start_tag('div', array('class' => 'header')); $output .= $this->course_filter_selector($returnurl, get_string('dayviewfor', 'calendar')); if (calendar_user_can_add_event($calendar->course)) { $output .= $this->add_event_button($calendar->course->id, 0, 0, 0, $calendar->time); } $output .= html_writer::end_tag('div'); // Controls $output .= html_writer::tag('div', calendar_top_controls('day', array('id' => $calendar->courseid, 'time' => $calendar->time)), array('class' => 'controls')); if (empty($events)) { // There is nothing to display today. $output .= $this->output->heading(get_string('daywithnoevents', 'calendar'), 3); } else { $output .= html_writer::start_tag('div', array('class' => 'eventlist')); $underway = array(); // First, print details about events that start today foreach ($events as $event) { $event = new calendar_event($event); $event->calendarcourseid = $calendar->courseid; if ($event->timestart >= $calendar->timestamp_today() && $event->timestart <= $calendar->timestamp_tomorrow() - 1) { // Print it now $event->time = calendar_format_event_time($event, time(), null, false, $calendar->timestamp_today()); $output .= $this->event($event); } else { // Save this for later $underway[] = $event; } } // Then, show a list of all events that just span this day if (!empty($underway)) { $output .= $this->output->heading(get_string('spanningevents', 'calendar'), 3); foreach ($underway as $event) { $event->time = calendar_format_event_time($event, time(), null, false, $calendar->timestamp_today()); $output .= $this->event($event); } } $output .= html_writer::end_tag('div'); } return $output; }
$issite = false; } else { $course = get_site(); $courses = calendar_get_default_courses(); $issite = true; } require_course_login($course); $url = new moodle_url('/calendar/export.php', array('time' => $time)); if ($action !== '') { $url->param('action', $action); } if ($course !== NULL) { $url->param('course', $course->id); } $PAGE->set_url($url); $calendar = new calendar_information(0, 0, 0, $time); $calendar->prepare_for_view($course, $courses); $pagetitle = get_string('export', 'calendar'); // Print title and header if ($issite) { $PAGE->navbar->add($course->shortname, new moodle_url('/course/view.php', array('id' => $course->id))); } $link = new moodle_url(CALENDAR_URL . 'view.php', array('view' => 'upcoming', 'course' => $calendar->courseid)); $PAGE->navbar->add(get_string('calendar', 'calendar'), calendar_get_link_href($link, 0, 0, 0, $time)); $PAGE->navbar->add($pagetitle); $PAGE->set_title($course->shortname . ': ' . get_string('calendar', 'calendar') . ': ' . $pagetitle); $PAGE->set_heading($course->fullname); $PAGE->set_pagelayout('standard'); $renderer = $PAGE->get_renderer('core_calendar'); $calendar->add_sidecalendar_blocks($renderer); // Get the calendar type we are using.
if ($DB->record_exists('course', array('id' => $courseid))) { $courseexists = true; // Otherwise show just this one $SESSION->cal_courses_shown = $courseid; calendar_set_referring_course($SESSION->cal_courses_shown); } } } 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); $calendar = new calendar_information($cal_d, $cal_m, $cal_y); $calendar->courseid = $courseid; $strcalendar = get_string('calendar', 'calendar'); $link = clone $viewcalendarurl; $link->param('view', 'upcoming'); $formoptions = new stdClass(); if ($eventid !== 0) { $title = get_string('editevent', 'calendar'); $event = calendar_event::load($eventid); if (!calendar_edit_event_allowed($event)) { print_error('nopermissions'); } $event->action = $action; $event->course = $courseid; $event->timedurationuntil = $event->timestart + $event->timeduration; $event->count_repeats();
/** * Displays the calendar for a single day * * @param calendar_information $calendar * @return string */ public function show_day(calendar_information $calendar) { $calendar->checkdate(); $events = calendar_get_upcoming($calendar->courses, $calendar->groups, $calendar->users, 1, 100, $calendar->timestamp_today()); $output = html_writer::start_tag('div', array('class' => 'header')); if (!isguestuser() && isloggedin() && calendar_user_can_add_event()) { $output .= $this->add_event_button($calendar->courseid, $calendar->day, $calendar->month, $calendar->year); } //$output .= html_writer::tag('label', get_string('dayview', 'calendar'), array('for'=>'cal_course_flt_jump')); $output .= $this->course_filter_selector(array('from' => 'day', 'cal_d' => $calendar->day, 'cal_m' => $calendar->month, 'cal_y' => $calendar->year), get_string('dayview', 'calendar')); $output .= html_writer::end_tag('div'); // Controls $output .= html_writer::tag('div', calendar_top_controls('day', array('id' => $calendar->courseid, 'd' => $calendar->day, 'm' => $calendar->month, 'y' => $calendar->year)), array('class' => 'controls')); if (empty($events)) { // There is nothing to display today. $output .= $this->output->heading(get_string('daywithnoevents', 'calendar'), 3); } else { $output .= html_writer::start_tag('div', array('class' => 'eventlist')); $underway = array(); // First, print details about events that start today foreach ($events as $event) { $event = new calendar_event($event); $event->calendarcourseid = $calendar->courseid; if ($event->timestart >= $calendar->timestamp_today() && $event->timestart <= $calendar->timestamp_tomorrow() - 1) { // Print it now $event->time = calendar_format_event_time($event, time(), null, false, $calendar->timestamp_today()); $output .= $this->event($event); } else { // Save this for later $underway[] = $event; } } // Then, show a list of all events that just span this day if (!empty($underway)) { $output .= $this->output->heading(get_string('spanningevents', 'calendar'), 3); foreach ($underway as $event) { $event->time = calendar_format_event_time($event, time(), null, false, $calendar->timestamp_today()); $output .= $this->event($event); } } $output .= html_writer::end_tag('div'); } return $output; }
} $PAGE->set_url($url); //TODO: the courseid handling in /calendar/ is a bloody mess!!! if ($courseid && $courseid != SITEID) { require_login($courseid); } else { if ($CFG->forcelogin) { $PAGE->set_context(get_context_instance(CONTEXT_SYSTEM)); //TODO: wrong require_login(); } else { $PAGE->set_context(get_context_instance(CONTEXT_SYSTEM)); //TODO: wrong } } $calendar = new calendar_information($day, $mon, $yr); $calendar->courseid = $courseid; // 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 = ''; $strcalendar = get_string('calendar', 'calendar'); $link = calendar_get_link_href(new moodle_url(CALENDAR_URL . 'view.php', array('view' => 'upcoming', 'course' => $courseid)), $now['mday'], $now['mon'], $now['year']); $PAGE->navbar->add($strcalendar, $link); if (!checkdate($mon, $day, $yr)) { $day = intval($now['mday']); $mon = intval($now['mon']); $yr = intval($now['year']); } $time = make_timestamp($yr, $mon, $day);