MDL-57765 behat: Allow exact selectors to be used
[moodle.git] / calendar / view.php
bloba55aee6e1950197b633b1b62d5c1b763b0efe390
1 <?php
3 /////////////////////////////////////////////////////////////////////////////
4 // //
5 // NOTICE OF COPYRIGHT //
6 // //
7 // Moodle - Calendar extension //
8 // //
9 // Copyright (C) 2003-2004 Greek School Network www.sch.gr //
10 // //
11 // Designed by: //
12 // Avgoustos Tsinakos (tsinakos@teikav.edu.gr) //
13 // Jon Papaioannou (pj@moodle.org) //
14 // //
15 // Programming and development: //
16 // Jon Papaioannou (pj@moodle.org) //
17 // //
18 // For bugs, suggestions, etc contact: //
19 // Jon Papaioannou (pj@moodle.org) //
20 // //
21 // The current module was developed at the University of Macedonia //
22 // (www.uom.gr) under the funding of the Greek School Network (www.sch.gr) //
23 // The aim of this project is to provide additional and improved //
24 // functionality to the Asynchronous Distance Education service that the //
25 // Greek School Network deploys. //
26 // //
27 // This program is free software; you can redistribute it and/or modify //
28 // it under the terms of the GNU General Public License as published by //
29 // the Free Software Foundation; either version 2 of the License, or //
30 // (at your option) any later version. //
31 // //
32 // This program is distributed in the hope that it will be useful, //
33 // but WITHOUT ANY WARRANTY; without even the implied warranty of //
34 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
35 // GNU General Public License for more details: //
36 // //
37 // http://www.gnu.org/copyleft/gpl.html //
38 // //
39 /////////////////////////////////////////////////////////////////////////////
41 /**
42 * Display the calendar page.
43 * @copyright 2003 Jon Papaioannou
44 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
45 * @package core_calendar
48 require_once('../config.php');
49 require_once($CFG->dirroot.'/course/lib.php');
50 require_once($CFG->dirroot.'/calendar/lib.php');
52 $courseid = optional_param('course', SITEID, PARAM_INT);
53 $view = optional_param('view', 'upcoming', PARAM_ALPHA);
54 $day = optional_param('cal_d', 0, PARAM_INT);
55 $mon = optional_param('cal_m', 0, PARAM_INT);
56 $year = optional_param('cal_y', 0, PARAM_INT);
57 $time = optional_param('time', 0, PARAM_INT);
59 $url = new moodle_url('/calendar/view.php');
61 // If a day, month and year were passed then convert it to a timestamp. If these were passed
62 // then we can assume the day, month and year are passed as Gregorian, as no where in core
63 // should we be passing these values rather than the time. This is done for BC.
64 if (!empty($day) && !empty($mon) && !empty($year)) {
65 if (checkdate($mon, $day, $year)) {
66 $time = make_timestamp($year, $mon, $day);
70 if (empty($time)) {
71 $time = time();
74 if ($courseid != SITEID) {
75 $url->param('course', $courseid);
78 if ($view !== 'upcoming') {
79 $time = usergetmidnight($time);
80 $url->param('view', $view);
83 $url->param('time', $time);
85 $PAGE->set_url($url);
87 if ($courseid != SITEID && !empty($courseid)) {
88 $course = $DB->get_record('course', array('id' => $courseid));
89 $courses = array($course->id => $course);
90 $issite = false;
91 navigation_node::override_active_url(new moodle_url('/course/view.php', array('id' => $course->id)));
92 } else {
93 $course = get_site();
94 $courses = calendar_get_default_courses();
95 $issite = true;
98 require_course_login($course);
100 $calendar = new calendar_information(0, 0, 0, $time);
101 $calendar->prepare_for_view($course, $courses);
103 $pagetitle = '';
105 $strcalendar = get_string('calendar', 'calendar');
107 switch($view) {
108 case 'day':
109 $PAGE->navbar->add(userdate($time, get_string('strftimedate')));
110 $pagetitle = get_string('dayviewtitle', 'calendar', userdate($time, get_string('strftimedaydate')));
111 break;
112 case 'month':
113 $PAGE->navbar->add(userdate($time, get_string('strftimemonthyear')));
114 $pagetitle = get_string('detailedmonthviewtitle', 'calendar', userdate($time, get_string('strftimemonthyear')));
115 break;
116 case 'upcoming':
117 $pagetitle = get_string('upcomingevents', 'calendar');
118 break;
121 // Print title and header
122 $PAGE->set_pagelayout('standard');
123 $PAGE->set_title("$course->shortname: $strcalendar: $pagetitle");
124 $PAGE->set_heading($COURSE->fullname);
126 $renderer = $PAGE->get_renderer('core_calendar');
127 $calendar->add_sidecalendar_blocks($renderer, true, $view);
129 echo $OUTPUT->header();
130 echo $renderer->start_layout();
131 echo html_writer::start_tag('div', array('class'=>'heightcontainer'));
132 echo $OUTPUT->heading(get_string('calendar', 'calendar'));
134 switch($view) {
135 case 'day':
136 echo $renderer->show_day($calendar);
137 break;
138 case 'month':
139 echo $renderer->show_month_detailed($calendar, $url);
140 break;
141 case 'upcoming':
142 $defaultlookahead = CALENDAR_DEFAULT_UPCOMING_LOOKAHEAD;
143 if (isset($CFG->calendar_lookahead)) {
144 $defaultlookahead = intval($CFG->calendar_lookahead);
146 $lookahead = get_user_preferences('calendar_lookahead', $defaultlookahead);
148 $defaultmaxevents = CALENDAR_DEFAULT_UPCOMING_MAXEVENTS;
149 if (isset($CFG->calendar_maxevents)) {
150 $defaultmaxevents = intval($CFG->calendar_maxevents);
152 $maxevents = get_user_preferences('calendar_maxevents', $defaultmaxevents);
153 echo $renderer->show_upcoming_events($calendar, $lookahead, $maxevents);
154 break;
157 //Link to calendar export page.
158 echo $OUTPUT->container_start('bottom');
159 if (!empty($CFG->enablecalendarexport)) {
160 echo $OUTPUT->single_button(new moodle_url('export.php', array('course'=>$courseid)), get_string('exportcalendar', 'calendar'));
161 if (calendar_user_can_add_event($course)) {
162 echo $OUTPUT->single_button(new moodle_url('/calendar/managesubscriptions.php', array('course'=>$courseid)), get_string('managesubscriptions', 'calendar'));
164 if (isloggedin()) {
165 $authtoken = sha1($USER->id . $DB->get_field('user', 'password', array('id' => $USER->id)) . $CFG->calendar_exportsalt);
166 $link = new moodle_url(
167 '/calendar/export_execute.php',
168 array('preset_what'=>'all', 'preset_time' => 'recentupcoming', 'userid' => $USER->id, 'authtoken'=>$authtoken)
170 echo html_writer::tag('a', 'iCal',
171 array('href' => $link, 'title' => get_string('quickdownloadcalendar', 'calendar'), 'class' => 'ical-link m-l-1'));
175 echo $OUTPUT->container_end();
176 echo html_writer::end_tag('div');
177 echo $renderer->complete_layout();
178 echo $OUTPUT->footer();