3 /////////////////////////////////////////////////////////////////////////////
5 // NOTICE OF COPYRIGHT //
7 // Moodle - Calendar extension //
9 // Copyright (C) 2003-2004 Greek School Network www.sch.gr //
12 // Avgoustos Tsinakos (tsinakos@teikav.edu.gr) //
13 // Jon Papaioannou (pj@moodle.org) //
15 // Programming and development: //
16 // Jon Papaioannou (pj@moodle.org) //
18 // For bugs, suggestions, etc contact: //
19 // Jon Papaioannou (pj@moodle.org) //
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. //
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. //
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: //
37 // http://www.gnu.org/copyleft/gpl.html //
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', 0, 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
);
55 $url = new moodle_url('/calendar/view.php');
56 if ($courseid !== 0) {
57 $url->param('course', $courseid);
59 if ($view !== 'upcoming') {
60 $url->param('view', $view);
63 $url->param('cal_d', $day);
66 $url->param('cal_m', $mon);
69 $url->param('cal_y', $yr);
73 //TODO: the courseid handling in /calendar/ is a bloody mess!!!
75 if ($courseid && $courseid != SITEID
) {
76 require_login($courseid);
77 } else if ($CFG->forcelogin
) {
78 $PAGE->set_context(get_context_instance(CONTEXT_SYSTEM
)); //TODO: wrong
81 $PAGE->set_context(get_context_instance(CONTEXT_SYSTEM
)); //TODO: wrong
84 $calendar = new calendar_information($day, $mon, $yr);
85 $calendar->courseid
= $courseid;
87 // Initialize the session variables
88 calendar_session_vars();
90 //add_to_log($course->id, "course", "view", "view.php?id=$course->id", "$course->id");
91 $now = usergetdate(time());
94 $strcalendar = get_string('calendar', 'calendar');
96 $link = calendar_get_link_href(new moodle_url(CALENDAR_URL
.'view.php', array('view'=>'upcoming', 'course'=>$courseid)),
97 $now['mday'], $now['mon'], $now['year']);
98 $PAGE->navbar
->add($strcalendar, $link);
100 if(!checkdate($mon, $day, $yr)) {
101 $day = intval($now['mday']);
102 $mon = intval($now['mon']);
103 $yr = intval($now['year']);
105 $time = make_timestamp($yr, $mon, $day);
109 $PAGE->navbar
->add(userdate($time, get_string('strftimedate')));
110 $pagetitle = get_string('dayview', 'calendar');
113 $PAGE->navbar
->add(userdate($time, get_string('strftimemonthyear')));
114 $pagetitle = get_string('detailedmonthview', 'calendar');
117 $pagetitle = get_string('upcomingevents', 'calendar');
120 // If a course has been supplied in the URL, change the filters to show that one
121 if (!empty($courseid)) {
122 if ($course = $DB->get_record('course', array('id'=>$courseid))) {
123 if ($course->id
== SITEID
) {
124 // If coming from the home page, show all courses
125 $SESSION->cal_courses_shown
= calendar_get_default_courses(true);
126 calendar_set_referring_course(0);
129 // Otherwise show just this one
130 $SESSION->cal_courses_shown
= $course->id
;
131 calendar_set_referring_course($SESSION->cal_courses_shown
);
137 if (!isloggedin() or isguestuser()) {
138 $defaultcourses = calendar_get_default_courses();
139 calendar_set_filters($calendar->courses
, $calendar->groups
, $calendar->users
, $defaultcourses, $defaultcourses);
141 calendar_set_filters($calendar->courses
, $calendar->groups
, $calendar->users
);
143 // Let's see if we are supposed to provide a referring course link
144 // but NOT for the "main page" course
145 if ($SESSION->cal_course_referer
!= SITEID
&&
146 ($shortname = $DB->get_field('course', 'shortname', array('id'=>$SESSION->cal_course_referer
))) !== false) {
147 require_login(); //TODO: very wrong!!
148 if (empty($course)) {
149 $course = $DB->get_record('course', array('id'=>$SESSION->cal_course_referer
)); // Useful to have around
153 $strcalendar = get_string('calendar', 'calendar');
154 $prefsbutton = calendar_preferences_button();
156 // Print title and header
157 $PAGE->set_title("$site->shortname: $strcalendar: $pagetitle");
158 $PAGE->set_heading($COURSE->fullname
);
159 $PAGE->set_button($prefsbutton);
160 $PAGE->set_pagelayout('standard');
162 $renderer = $PAGE->get_renderer('core_calendar');
163 $calendar->add_sidecalendar_blocks($renderer, true, $view);
165 echo $OUTPUT->header();
166 echo $renderer->start_layout();
167 echo html_writer
::start_tag('div', array('class'=>'heightcontainer'));
171 echo $renderer->show_day($calendar);
174 echo $renderer->show_month_detailed($calendar);
177 echo $renderer->show_upcoming_events($calendar, get_user_preferences('calendar_lookahead', CALENDAR_UPCOMING_DAYS
), get_user_preferences('calendar_maxevents', CALENDAR_UPCOMING_MAXEVENTS
));
181 //Link to calendar export page
182 echo $OUTPUT->container_start('bottom');
183 if (!empty($CFG->enablecalendarexport
)) {
184 echo $OUTPUT->single_button(new moodle_url('export.php', array('course'=>$courseid)), get_string('exportcalendar', 'calendar'));
186 $authtoken = sha1($USER->username
. $USER->password
. $CFG->calendar_exportsalt
);
187 $link = new moodle_url('/calendar/export_execute.php', array('preset_what'=>'all', 'prest_time'=>'recentupcoming', 'username'=>$USER->username
, 'authtoken'=>$authtoken));
188 $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')));
189 echo html_writer
::tag('a', $icon, array('href'=>$link));
192 echo $OUTPUT->container_end();
193 echo html_writer
::end_tag('div');
194 echo $renderer->complete_layout();
195 echo $OUTPUT->footer();