add page heading
[moodle.git] / calendar / event.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
93c91ee4 41/**
76d9df3f 42 * This file is part of the Calendar section Moodle
93c91ee4 43 *
44 * @copyright 2003-2004 Jon Papaioannou (pj@moodle.org)
45 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v2 or later
46 * @package calendar
47 */
48
49require_once('../config.php');
76d9df3f 50require_once($CFG->dirroot.'/calendar/event_form.php');
93c91ee4 51require_once($CFG->dirroot.'/calendar/lib.php');
52require_once($CFG->dirroot.'/course/lib.php');
93c91ee4 53
54require_login();
55
76d9df3f 56$action = optional_param('action', 'new', PARAM_ALPHA);
93c91ee4 57$eventid = optional_param('id', 0, PARAM_INT);
76d9df3f 58$courseid = optional_param('courseid', 0, PARAM_INT);
93c91ee4 59$cal_y = optional_param('cal_y', 0, PARAM_INT);
60$cal_m = optional_param('cal_m', 0, PARAM_INT);
61$cal_d = optional_param('cal_d', 0, PARAM_INT);
62
76d9df3f
SH
63if ($courseid === 0) {
64 $courseid = optional_param('course', 0, PARAM_INT);
65}
66
a6855934 67$url = new moodle_url('/calendar/event.php', array('action'=>$action));
93c91ee4 68if ($eventid !== 0) $url->param('id', $eventid);
76d9df3f 69if ($courseid !== 0) $url->param('course', $courseid);
93c91ee4 70if ($cal_y !== 0) $url->param('cal_y', $cal_y);
71if ($cal_m !== 0) $url->param('cal_m', $cal_m);
72if ($cal_d !== 0) $url->param('cal_d', $cal_d);
73$PAGE->set_url($url);
74
76d9df3f 75if ($action === 'delete' && $eventid>0) {
a6855934 76 $deleteurl = new moodle_url('/calendar/delete.php', array('id'=>$eventid));
76d9df3f
SH
77 if ($courseid > 0) {
78 $deleteurl->param('course', $courseid);
79 }
80 redirect($deleteurl);
81}
82
83$viewcalendarurl = new moodle_url(CALENDAR_URL.'view.php');
84$viewcalendarurl->params($PAGE->url->params());
85$viewcalendarurl->remove_params(array('id','action'));
86
87$now = usergetdate(time());
88
89if (isguestuser()) {
93c91ee4 90 // Guests cannot do anything with events
76d9df3f 91 redirect(new moodle_url(CALENDAR_URL.'view.php', array('view'=>'upcoming', 'course'=>$courseid)));
93c91ee4 92}
f21ed0f3 93
93c91ee4 94$focus = '';
bf8756a6 95
2a250a0b 96$site = get_site();
7423f116 97
93c91ee4 98calendar_session_vars();
37d87d11 99
93c91ee4 100// If a course has been supplied in the URL, change the filters to show that one
76d9df3f
SH
101$courseexists = false;
102if ($courseid > 0) {
103 if ($courseid == SITEID) {
93c91ee4 104 // If coming from the site page, show all courses
105 $SESSION->cal_courses_shown = calendar_get_default_courses(true);
106 calendar_set_referring_course(0);
76d9df3f
SH
107 } else if ($DB->record_exists('course', array('id'=>$courseid))) {
108 $courseexists = true;
93c91ee4 109 // Otherwise show just this one
76d9df3f 110 $SESSION->cal_courses_shown = $courseid;
93c91ee4 111 calendar_set_referring_course($SESSION->cal_courses_shown);
112 }
113}
89adb174 114
93c91ee4 115if (!empty($SESSION->cal_course_referer)) {
116 // TODO: This is part of the Great $course Hack in Moodle. Replace it at some point.
117 $course = $DB->get_record('course', array('id'=>$SESSION->cal_course_referer));
118} else {
119 $course = $site;
120}
e6fbb4d1 121
76d9df3f 122require_login($course, false);
e295df44 123
76d9df3f
SH
124$strcalendar = get_string('calendar', 'calendar');
125$link = clone($viewcalendarurl);
126$link->param('view', 'upcoming');
93c91ee4 127
76d9df3f 128$formoptions = new stdClass;
93c91ee4 129
76d9df3f
SH
130if ($eventid !== 0) {
131 $title = get_string('editevent', 'calendar');
132 $event = calendar_event::load($eventid);
133 if (!calendar_edit_event_allowed($event)) {
134 print_error('nopermissions');
7423f116 135 }
76d9df3f
SH
136 $event->action = $action;
137 $event->course = $courseid;
138 $event->timedurationuntil = $event->timestart + $event->timeduration;
139 $event->count_repeats();
93c91ee4 140
76d9df3f
SH
141 if (!calendar_add_event_allowed($event)) {
142 print_error('nopermissions');
93c91ee4 143 }
62d11d77 144 } else {
76d9df3f
SH
145 $title = get_string('newevent', 'calendar');
146 calendar_get_allowed_types($formoptions->eventtypes, $USER->id);
147 $event = new calendar_event();
148 $event->action = $action;
149 $event->course = $courseid;
150 $event->timeduration = 0;
151 if ($formoptions->eventtypes->courses) {
152 if ($courseexists) {
153 $event->courseid = $courseid;
154 $event->eventtype = 'course';
93c91ee4 155 } else {
76d9df3f
SH
156 unset($formoptions->eventtypes->courses);
157 unset($formoptions->eventtypes->groups);
93c91ee4 158 }
93c91ee4 159 }
160
93c91ee4 161 if($cal_y && $cal_m && $cal_d && checkdate($cal_m, $cal_d, $cal_y)) {
76d9df3f
SH
162 $event->timestart = make_timestamp($cal_y, $cal_m, $cal_d, 0, 0, 0);
163 } else if($cal_y && $cal_m && checkdate($cal_m, 1, $cal_y)) {
93c91ee4 164 if($cal_y == $now['year'] && $cal_m == $now['mon']) {
76d9df3f
SH
165 $event->timestart = make_timestamp($cal_y, $cal_m, $now['mday'], 0, 0, 0);
166 } else {
167 $event->timestart = make_timestamp($cal_y, $cal_m, 1, 0, 0, 0);
7423f116 168 }
93c91ee4 169 }
76d9df3f
SH
170
171 if (!calendar_add_event_allowed($event)) {
172 print_error('nopermissions');
93c91ee4 173 }
93c91ee4 174 }
7423f116 175
76d9df3f
SH
176$properties = $event->properties(true);
177$formoptions->event = $event;
178$formoptions->hasduration = ($event->timeduration > 0);
179$mform = new event_form(null, $formoptions);
180$mform->set_data($properties);
181$data = $mform->get_data();
182if ($data) {
183 if ($data->duration == 1) {
184 $data->timeduration = $data->timedurationuntil- $data->timestart;
185 } else if ($data->duration == 2) {
186 $data->timeduration = $data->timedurationminutes * MINSECS;
187 } else {
188 $data->timeduration = 0;
bdbae764 189 }
7423f116 190
76d9df3f
SH
191 $event->update($data);
192 $eventurl = new moodle_url(CALENDAR_URL.'view.php', array('view'=>'day'));
193 if (!empty($event->courseid)) {
194 $eventurl->param('course', $event->courseid);
bdbae764 195 }
76d9df3f
SH
196 $eventurl->param('cal_d', date('j', $event->timestart));
197 $eventurl->param('cal_m', date('n', $event->timestart));
198 $eventurl->param('cal_y', date('Y', $event->timestart));
199 $eventurl->set_anchor('event_'.$event->id);
200 redirect($eventurl);
bdbae764 201}
7423f116 202
76d9df3f
SH
203$PAGE->navbar->add($strcalendar, $link);
204$PAGE->navbar->add($title);
205$PAGE->set_title($site->shortname.': '.$strcalendar.': '.$title);
bd08a24a 206$PAGE->set_heading($COURSE->fullname);
3c134875 207
76d9df3f 208echo $OUTPUT->header();
93c91ee4 209
93c91ee4 210
90723839 211echo '<table class="calendarlayout">';
76d9df3f
SH
212echo '<tr><td class="maincalendar">';
213echo $OUTPUT->heading($title);
214$mform->display();
93c91ee4 215echo '</td>';
216
76d9df3f 217// when adding an event you can not be a guest, so it's reasonalbe to ignore defaultcourses MDL-10353
93c91ee4 218calendar_set_filters($courses, $groups, $users);
76d9df3f
SH
219list($prevmon, $prevyr) = calendar_sub_month((int)$now['mon'], (int)$now['year']);
220list($nextmon, $nextyr) = calendar_add_month((int)$now['mon'], (int)$now['year']);
93c91ee4 221
222echo '<td class="sidecalendar">';
93c91ee4 223
6605ff8c
SH
224$block = $OUTPUT->box_start('block');
225$block .= $OUTPUT->box($OUTPUT->heading(get_string('eventskey', 'calendar')), 'header');
226$block .= $OUTPUT->box(calendar_filter_controls('event', 'action='.$action.'&amp;id='.$event->id), 'filters content');
227$block .= $OUTPUT->box_end();
228$block .= $OUTPUT->box_start('block');
229$block .= $OUTPUT->box($OUTPUT->heading(get_string('monthlyview', 'calendar')), 'header');
230$block .= $OUTPUT->box_start('content');
231$block .= $OUTPUT->box_start('minicalendarblock minicalendartop');
232$block .= calendar_top_controls('display', array('id' => $courseid, 'm' => $prevmon, 'y' => $prevyr));
233$block .= calendar_get_mini($courses, $groups, $users, $prevmon, $prevyr);
234$block .= $OUTPUT->box_end();
235$block .= $OUTPUT->box_start('minicalendarblock');
236$block .= calendar_top_controls('display', array('id' => $courseid, 'm' => (int)$now['mon'], 'y' => (int)$now['year']));
237$block .= calendar_get_mini($courses, $groups, $users, (int)$now['mon'], (int)$now['year']);
238$block .= $OUTPUT->box_end();
239$block .= $OUTPUT->box_start('minicalendarblock');
240$block .= calendar_top_controls('display', array('id' => $courseid, 'm' => $nextmon, 'y' => $nextyr));
241$block .= calendar_get_mini($courses, $groups, $users, $nextmon, $nextyr);
242$block .= $OUTPUT->box_end();
243$block .= $OUTPUT->box_end();
244$block .= $OUTPUT->box_end();
245echo $block;
76d9df3f
SH
246
247echo '</td></tr>';
248echo '</table>';
93c91ee4 249
250echo $OUTPUT->footer();