Commit | Line | Data |
---|---|---|
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 | ||
41 | // Display the calendar page. | |
42 | ||
93c91ee4 | 43 | require_once('../config.php'); |
44 | require_once($CFG->dirroot.'/course/lib.php'); | |
45 | require_once($CFG->dirroot.'/calendar/lib.php'); | |
707fbef4 | 46 | |
797cedc7 | 47 | $courseid = optional_param('course', SITEID, PARAM_INT); |
93c91ee4 | 48 | $view = optional_param('view', 'upcoming', PARAM_ALPHA); |
da304137 MN |
49 | $day = optional_param('cal_d', 0, PARAM_INT); |
50 | $mon = optional_param('cal_m', 0, PARAM_INT); | |
51 | $year = optional_param('cal_y', 0, PARAM_INT); | |
52 | $time = optional_param('time', 0, PARAM_INT); | |
7423f116 | 53 | |
a6855934 | 54 | $url = new moodle_url('/calendar/view.php'); |
da304137 | 55 | |
da304137 MN |
56 | // If a day, month and year were passed then convert it to a timestamp. If these were passed |
57 | // then we can assume the day, month and year are passed as Gregorian, as no where in core | |
58 | // should we be passing these values rather than the time. This is done for BC. | |
59 | if (!empty($day) && !empty($mon) && !empty($year)) { | |
60 | if (checkdate($mon, $day, $year)) { | |
61 | $time = make_timestamp($year, $mon, $day); | |
da304137 | 62 | } |
7bdc3ba6 NP |
63 | } |
64 | ||
65 | if (empty($time)) { | |
66 | $time = time(); | |
67 | } | |
68 | ||
69 | if ($courseid != SITEID) { | |
70 | $url->param('course', $courseid); | |
71 | } | |
72 | ||
73 | if ($view !== 'upcoming') { | |
74 | $time = usergetmidnight($time); | |
75 | $url->param('view', $view); | |
93c91ee4 | 76 | } |
da304137 MN |
77 | |
78 | $url->param('time', $time); | |
79 | ||
93c91ee4 | 80 | $PAGE->set_url($url); |
c9c9fb90 | 81 | |
797cedc7 SH |
82 | if ($courseid != SITEID && !empty($courseid)) { |
83 | $course = $DB->get_record('course', array('id' => $courseid)); | |
84 | $courses = array($course->id => $course); | |
85 | $issite = false; | |
86 | navigation_node::override_active_url(new moodle_url('/course/view.php', array('id' => $course->id))); | |
ca74470c | 87 | } else { |
797cedc7 SH |
88 | $course = get_site(); |
89 | $courses = calendar_get_default_courses(); | |
90 | $issite = true; | |
93c91ee4 | 91 | } |
da304137 | 92 | |
797cedc7 | 93 | require_course_login($course); |
2d4fb02f | 94 | |
da304137 | 95 | $calendar = new calendar_information(0, 0, 0, $time); |
797cedc7 | 96 | $calendar->prepare_for_view($course, $courses); |
37d87d11 | 97 | |
93c91ee4 | 98 | $pagetitle = ''; |
7423f116 | 99 | |
93c91ee4 | 100 | $strcalendar = get_string('calendar', 'calendar'); |
7423f116 | 101 | |
93c91ee4 | 102 | switch($view) { |
103 | case 'day': | |
104 | $PAGE->navbar->add(userdate($time, get_string('strftimedate'))); | |
3fe4a2fa | 105 | $pagetitle = get_string('dayviewtitle', 'calendar', userdate($time, get_string('strftimedaydate'))); |
93c91ee4 | 106 | break; |
107 | case 'month': | |
108 | $PAGE->navbar->add(userdate($time, get_string('strftimemonthyear'))); | |
3fe4a2fa | 109 | $pagetitle = get_string('detailedmonthviewtitle', 'calendar', userdate($time, get_string('strftimemonthyear'))); |
93c91ee4 | 110 | break; |
111 | case 'upcoming': | |
112 | $pagetitle = get_string('upcomingevents', 'calendar'); | |
113 | break; | |
114 | } | |
1e1ff33b | 115 | |
93c91ee4 | 116 | // Print title and header |
36dc3b71 | 117 | $PAGE->set_pagelayout('standard'); |
797cedc7 SH |
118 | $PAGE->set_title("$course->shortname: $strcalendar: $pagetitle"); |
119 | $PAGE->set_heading($COURSE->fullname); | |
120 | $PAGE->set_button(calendar_preferences_button($course)); | |
f22f1333 | 121 | |
36dc3b71 SH |
122 | $renderer = $PAGE->get_renderer('core_calendar'); |
123 | $calendar->add_sidecalendar_blocks($renderer, true, $view); | |
7423f116 | 124 | |
36dc3b71 SH |
125 | echo $OUTPUT->header(); |
126 | echo $renderer->start_layout(); | |
127 | echo html_writer::start_tag('div', array('class'=>'heightcontainer')); | |
136f8f09 | 128 | echo $OUTPUT->heading(get_string('calendar', 'calendar')); |
7423f116 | 129 | |
93c91ee4 | 130 | switch($view) { |
131 | case 'day': | |
36dc3b71 | 132 | echo $renderer->show_day($calendar); |
93c91ee4 | 133 | break; |
134 | case 'month': | |
05f9d136 | 135 | echo $renderer->show_month_detailed($calendar, $url); |
93c91ee4 | 136 | break; |
137 | case 'upcoming': | |
797cedc7 SH |
138 | $defaultlookahead = CALENDAR_DEFAULT_UPCOMING_LOOKAHEAD; |
139 | if (isset($CFG->calendar_lookahead)) { | |
140 | $defaultlookahead = intval($CFG->calendar_lookahead); | |
141 | } | |
142 | $lookahead = get_user_preferences('calendar_lookahead', $defaultlookahead); | |
143 | ||
144 | $defaultmaxevents = CALENDAR_DEFAULT_UPCOMING_MAXEVENTS; | |
145 | if (isset($CFG->calendar_maxevents)) { | |
146 | $defaultmaxevents = intval($CFG->calendar_maxevents); | |
147 | } | |
148 | $maxevents = get_user_preferences('calendar_maxevents', $defaultmaxevents); | |
149 | echo $renderer->show_upcoming_events($calendar, $lookahead, $maxevents); | |
93c91ee4 | 150 | break; |
151 | } | |
3c49918a | 152 | |
e30390a0 | 153 | //Link to calendar export page. |
93c91ee4 | 154 | echo $OUTPUT->container_start('bottom'); |
155 | if (!empty($CFG->enablecalendarexport)) { | |
5c2ed7e2 | 156 | echo $OUTPUT->single_button(new moodle_url('export.php', array('course'=>$courseid)), get_string('exportcalendar', 'calendar')); |
e30390a0 SH |
157 | if (calendar_user_can_add_event($course)) { |
158 | echo $OUTPUT->single_button(new moodle_url('/calendar/managesubscriptions.php', array('course'=>$courseid)), get_string('managesubscriptions', 'calendar')); | |
159 | } | |
4f0c2d00 | 160 | if (isloggedin()) { |
4a222f02 BB |
161 | $authtoken = sha1($USER->id . $DB->get_field('user', 'password', array('id' => $USER->id)) . $CFG->calendar_exportsalt); |
162 | $link = new moodle_url( | |
163 | '/calendar/export_execute.php', | |
164 | array('preset_what'=>'all', 'preset_time' => 'recentupcoming', 'userid' => $USER->id, 'authtoken'=>$authtoken) | |
165 | ); | |
166 | echo html_writer::tag('a', 'iCal', | |
167 | array('href' => $link, 'title' => get_string('quickdownloadcalendar', 'calendar'), 'class' => 'ical-link')); | |
ea185313 | 168 | } |
93c91ee4 | 169 | } |
797cedc7 | 170 | |
93c91ee4 | 171 | echo $OUTPUT->container_end(); |
36dc3b71 SH |
172 | echo html_writer::end_tag('div'); |
173 | echo $renderer->complete_layout(); | |
136f8f09 | 174 | echo $OUTPUT->footer(); |