weekly release 2.3.9+
[moodle.git] / calendar / view.php
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 //  Display the calendar page.
43 require_once('../config.php');
44 require_once($CFG->dirroot.'/course/lib.php');
45 require_once($CFG->dirroot.'/calendar/lib.php');
47 $courseid = optional_param('course', SITEID, PARAM_INT);
48 $view = optional_param('view', 'upcoming', PARAM_ALPHA);
49 $day  = optional_param('cal_d', 0, PARAM_INT);
50 $mon  = optional_param('cal_m', 0, PARAM_INT);
51 $yr   = optional_param('cal_y', 0, PARAM_INT);
53 $url = new moodle_url('/calendar/view.php');
54 if ($courseid != SITEID) {
55     $url->param('course', $courseid);
56 }
57 if ($view !== 'upcoming') {
58     $url->param('view', $view);
59 }
60 if ($day !== 0) {
61     $url->param('cal_d', $day);
62 }
63 if ($mon !== 0) {
64     $url->param('cal_m', $mon);
65 }
66 if ($yr !== 0) {
67     $url->param('cal_y', $yr);
68 }
69 $PAGE->set_url($url);
71 if ($courseid != SITEID && !empty($courseid)) {
72     $course = $DB->get_record('course', array('id' => $courseid));
73     $courses = array($course->id => $course);
74     $issite = false;
75     navigation_node::override_active_url(new moodle_url('/course/view.php', array('id' => $course->id)));
76 } else {
77     $course = get_site();
78     $courses = calendar_get_default_courses();
79     $issite = true;
80 }
81 require_course_login($course);
83 $calendar = new calendar_information($day, $mon, $yr);
84 $calendar->prepare_for_view($course, $courses);
86 $now = usergetdate(time());
87 $pagetitle = '';
89 $strcalendar = get_string('calendar', 'calendar');
91 if (!checkdate($mon, $day, $yr)) {
92     $day = intval($now['mday']);
93     $mon = intval($now['mon']);
94     $yr = intval($now['year']);
95 }
96 $time = make_timestamp($yr, $mon, $day);
98 switch($view) {
99     case 'day':
100         $PAGE->navbar->add(userdate($time, get_string('strftimedate')));
101         $pagetitle = get_string('dayview', 'calendar');
102     break;
103     case 'month':
104         $PAGE->navbar->add(userdate($time, get_string('strftimemonthyear')));
105         $pagetitle = get_string('detailedmonthview', 'calendar');
106     break;
107     case 'upcoming':
108         $pagetitle = get_string('upcomingevents', 'calendar');
109     break;
112 // Print title and header
113 $PAGE->set_pagelayout('standard');
114 $PAGE->set_title("$course->shortname: $strcalendar: $pagetitle");
115 $PAGE->set_heading($COURSE->fullname);
116 $PAGE->set_button(calendar_preferences_button($course));
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'));
125 switch($view) {
126     case 'day':
127         echo $renderer->show_day($calendar);
128     break;
129     case 'month':
130         echo $renderer->show_month_detailed($calendar, $url);
131     break;
132     case 'upcoming':
133         $defaultlookahead = CALENDAR_DEFAULT_UPCOMING_LOOKAHEAD;
134         if (isset($CFG->calendar_lookahead)) {
135             $defaultlookahead = intval($CFG->calendar_lookahead);
136         }
137         $lookahead = get_user_preferences('calendar_lookahead', $defaultlookahead);
139         $defaultmaxevents = CALENDAR_DEFAULT_UPCOMING_MAXEVENTS;
140         if (isset($CFG->calendar_maxevents)) {
141             $defaultmaxevents = intval($CFG->calendar_maxevents);
142         }
143         $maxevents = get_user_preferences('calendar_maxevents', $defaultmaxevents);
144         echo $renderer->show_upcoming_events($calendar, $lookahead, $maxevents);
145     break;
148 //Link to calendar export page
149 echo $OUTPUT->container_start('bottom');
150 if (!empty($CFG->enablecalendarexport)) {
151     echo $OUTPUT->single_button(new moodle_url('export.php', array('course'=>$courseid)), get_string('exportcalendar', 'calendar'));
152     if (isloggedin()) {
153         $authtoken = sha1($USER->id . $USER->password . $CFG->calendar_exportsalt);
154         $link = new moodle_url('/calendar/export_execute.php', array('preset_what'=>'all', 'preset_time'=>'recentupcoming', 'userid' => $USER->id, 'authtoken'=>$authtoken));
155         $icon = html_writer::empty_tag('img', array('src'=>$OUTPUT->pix_url('i/ical'), 'height'=>'14', 'width'=>'36', 'alt'=>get_string('ical', 'calendar'), 'title'=>get_string('quickdownloadcalendar', 'calendar')));
156         echo html_writer::tag('a', $icon, array('href'=>$link));
157     }
160 echo $OUTPUT->container_end();
161 echo html_writer::end_tag('div');
162 echo $renderer->complete_layout();
163 echo $OUTPUT->footer();