Merge branch 'MDL-52318-master' of https://github.com/snake/moodle
[moodle.git] / calendar / view.php
blobdf616e1f2b8eed2c20d2857adecc47b7535aa626
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 $categoryid = optional_param('category', null, PARAM_INT);
53 $courseid = optional_param('course', SITEID, PARAM_INT);
54 $view = optional_param('view', 'upcoming', PARAM_ALPHA);
55 $time = optional_param('time', 0, PARAM_INT);
57 $url = new moodle_url('/calendar/view.php');
59 if (empty($time)) {
60 $time = time();
63 if ($courseid != SITEID) {
64 $url->param('course', $courseid);
67 if ($categoryid) {
68 $url->param('categoryid', $categoryid);
71 if ($view !== 'upcoming') {
72 $time = usergetmidnight($time);
73 $url->param('view', $view);
76 $url->param('time', $time);
78 $PAGE->set_url($url);
80 $course = get_course($courseid);
82 if ($courseid != SITEID && !empty($courseid)) {
83 navigation_node::override_active_url(new moodle_url('/course/view.php', array('id' => $course->id)));
84 } else if (!empty($categoryid)) {
85 $PAGE->set_category_by_id($categoryid);
86 navigation_node::override_active_url(new moodle_url('/course/index.php', array('categoryid' => $categoryid)));
87 } else {
88 $PAGE->set_context(context_system::instance());
91 require_login($course, false);
93 $calendar = calendar_information::create($time, $courseid, $categoryid);
95 $pagetitle = '';
97 $strcalendar = get_string('calendar', 'calendar');
99 switch($view) {
100 case 'day':
101 $PAGE->navbar->add(userdate($time, get_string('strftimedate')));
102 $pagetitle = get_string('dayviewtitle', 'calendar', userdate($time, get_string('strftimedaydate')));
103 break;
104 case 'month':
105 $PAGE->navbar->add(userdate($time, get_string('strftimemonthyear')));
106 $pagetitle = get_string('detailedmonthviewtitle', 'calendar', userdate($time, get_string('strftimemonthyear')));
107 break;
108 case 'upcoming':
109 $pagetitle = get_string('upcomingevents', 'calendar');
110 break;
113 // Print title and header
114 $PAGE->set_pagelayout('standard');
115 $PAGE->set_title("$course->shortname: $strcalendar: $pagetitle");
116 $PAGE->set_heading($COURSE->fullname);
118 $renderer = $PAGE->get_renderer('core_calendar');
119 $calendar->add_sidecalendar_blocks($renderer, true, $view);
121 echo $OUTPUT->header();
122 echo $renderer->start_layout();
123 echo html_writer::start_tag('div', array('class'=>'heightcontainer'));
124 echo $OUTPUT->heading(get_string('calendar', 'calendar'));
127 list($data, $template) = calendar_get_view($calendar, $view);
128 echo $renderer->render_from_template($template, $data);
130 echo html_writer::end_tag('div');
132 list($data, $template) = calendar_get_footer_options($calendar);
133 echo $renderer->render_from_template($template, $data);
135 echo $renderer->complete_layout();
136 echo $OUTPUT->footer();