MDL-59392 calendar: Move template to parent Node
[moodle.git] / calendar / view.php
CommitLineData
93c91ee4 1<?php
7423f116 2
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: //
bdcb26b7 12// Avgoustos Tsinakos (tsinakos@teikav.edu.gr) //
13// Jon Papaioannou (pj@moodle.org) //
7423f116 14// //
15// Programming and development: //
bdcb26b7 16// Jon Papaioannou (pj@moodle.org) //
7423f116 17// //
18// For bugs, suggestions, etc contact: //
bdcb26b7 19// Jon Papaioannou (pj@moodle.org) //
7423f116 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/////////////////////////////////////////////////////////////////////////////
40
9629790b
SB
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
46 */
7423f116 47
93c91ee4 48require_once('../config.php');
49require_once($CFG->dirroot.'/course/lib.php');
50require_once($CFG->dirroot.'/calendar/lib.php');
707fbef4 51
797cedc7 52$courseid = optional_param('course', SITEID, PARAM_INT);
93c91ee4 53$view = optional_param('view', 'upcoming', PARAM_ALPHA);
da304137
MN
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);
7423f116 58
a6855934 59$url = new moodle_url('/calendar/view.php');
da304137 60
da304137
MN
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.
64if (!empty($day) && !empty($mon) && !empty($year)) {
65 if (checkdate($mon, $day, $year)) {
66 $time = make_timestamp($year, $mon, $day);
da304137 67 }
7bdc3ba6
NP
68}
69
70if (empty($time)) {
71 $time = time();
72}
73
74if ($courseid != SITEID) {
75 $url->param('course', $courseid);
76}
77
78if ($view !== 'upcoming') {
79 $time = usergetmidnight($time);
80 $url->param('view', $view);
93c91ee4 81}
da304137
MN
82
83$url->param('time', $time);
84
93c91ee4 85$PAGE->set_url($url);
c9c9fb90 86
797cedc7 87if ($courseid != SITEID && !empty($courseid)) {
fb1a615d
JP
88 // Course ID must be valid and existing.
89 $course = $DB->get_record('course', array('id' => $courseid), '*', MUST_EXIST);
797cedc7
SH
90 $courses = array($course->id => $course);
91 $issite = false;
92 navigation_node::override_active_url(new moodle_url('/course/view.php', array('id' => $course->id)));
ca74470c 93} else {
797cedc7
SH
94 $course = get_site();
95 $courses = calendar_get_default_courses();
96 $issite = true;
93c91ee4 97}
da304137 98
fb1a615d 99require_login($course, false);
2d4fb02f 100
da304137 101$calendar = new calendar_information(0, 0, 0, $time);
797cedc7 102$calendar->prepare_for_view($course, $courses);
37d87d11 103
93c91ee4 104$pagetitle = '';
7423f116 105
93c91ee4 106$strcalendar = get_string('calendar', 'calendar');
7423f116 107
93c91ee4 108switch($view) {
109 case 'day':
110 $PAGE->navbar->add(userdate($time, get_string('strftimedate')));
3fe4a2fa 111 $pagetitle = get_string('dayviewtitle', 'calendar', userdate($time, get_string('strftimedaydate')));
93c91ee4 112 break;
113 case 'month':
114 $PAGE->navbar->add(userdate($time, get_string('strftimemonthyear')));
3fe4a2fa 115 $pagetitle = get_string('detailedmonthviewtitle', 'calendar', userdate($time, get_string('strftimemonthyear')));
93c91ee4 116 break;
117 case 'upcoming':
118 $pagetitle = get_string('upcomingevents', 'calendar');
119 break;
120}
1e1ff33b 121
93c91ee4 122// Print title and header
36dc3b71 123$PAGE->set_pagelayout('standard');
797cedc7
SH
124$PAGE->set_title("$course->shortname: $strcalendar: $pagetitle");
125$PAGE->set_heading($COURSE->fullname);
f22f1333 126
36dc3b71
SH
127$renderer = $PAGE->get_renderer('core_calendar');
128$calendar->add_sidecalendar_blocks($renderer, true, $view);
7423f116 129
36dc3b71
SH
130echo $OUTPUT->header();
131echo $renderer->start_layout();
132echo html_writer::start_tag('div', array('class'=>'heightcontainer'));
136f8f09 133echo $OUTPUT->heading(get_string('calendar', 'calendar'));
7423f116 134
64ff737a
AN
135if ($view == 'day' || $view == 'upcoming') {
136 switch($view) {
137 case 'day':
138 echo $renderer->show_day($calendar);
139 break;
140 case 'upcoming':
141 $defaultlookahead = CALENDAR_DEFAULT_UPCOMING_LOOKAHEAD;
142 if (isset($CFG->calendar_lookahead)) {
143 $defaultlookahead = intval($CFG->calendar_lookahead);
144 }
145 $lookahead = get_user_preferences('calendar_lookahead', $defaultlookahead);
146
147 $defaultmaxevents = CALENDAR_DEFAULT_UPCOMING_MAXEVENTS;
148 if (isset($CFG->calendar_maxevents)) {
149 $defaultmaxevents = intval($CFG->calendar_maxevents);
150 }
151 $maxevents = get_user_preferences('calendar_maxevents', $defaultmaxevents);
152 echo $renderer->show_upcoming_events($calendar, $lookahead, $maxevents);
153 break;
154 }
64ff737a
AN
155} else if ($view == 'month') {
156 list($data, $template) = calendar_get_view($calendar, $view);
157 echo $renderer->render_from_template($template, $data);
158}
36dc3b71 159echo html_writer::end_tag('div');
644b2e98
SL
160
161list($data, $template) = calendar_get_footer_options($calendar);
162echo $renderer->render_from_template($template, $data);
163
136f8f09 164echo $OUTPUT->footer();