Automatic installer lang files (20101011)
[moodle.git] / calendar / event.php
blobf2fa2937a03114dc6eb69d8fb9faebd1c0b41b21
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 /**
42 * This file is part of the Calendar section Moodle
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
49 require_once('../config.php');
50 require_once($CFG->dirroot.'/calendar/event_form.php');
51 require_once($CFG->dirroot.'/calendar/lib.php');
52 require_once($CFG->dirroot.'/course/lib.php');
54 require_login();
56 $action = optional_param('action', 'new', PARAM_ALPHA);
57 $eventid = optional_param('id', 0, PARAM_INT);
58 $courseid = optional_param('courseid', 0, PARAM_INT);
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);
63 if ($courseid === 0) {
64 $courseid = optional_param('course', 0, PARAM_INT);
67 $url = new moodle_url('/calendar/event.php', array('action'=>$action));
68 if ($eventid !== 0) $url->param('id', $eventid);
69 if ($courseid !== 0) $url->param('course', $courseid);
70 if ($cal_y !== 0) $url->param('cal_y', $cal_y);
71 if ($cal_m !== 0) $url->param('cal_m', $cal_m);
72 if ($cal_d !== 0) $url->param('cal_d', $cal_d);
73 $PAGE->set_url($url);
74 $PAGE->set_context(get_context_instance(CONTEXT_SYSTEM));
75 $PAGE->set_pagelayout('standard');
77 if ($action === 'delete' && $eventid>0) {
78 $deleteurl = new moodle_url('/calendar/delete.php', array('id'=>$eventid));
79 if ($courseid > 0) {
80 $deleteurl->param('course', $courseid);
82 redirect($deleteurl);
85 $viewcalendarurl = new moodle_url(CALENDAR_URL.'view.php');
86 $viewcalendarurl->params($PAGE->url->params());
87 $viewcalendarurl->remove_params(array('id','action'));
89 $now = usergetdate(time());
91 if (isguestuser()) {
92 // Guests cannot do anything with events
93 redirect(new moodle_url(CALENDAR_URL.'view.php', array('view'=>'upcoming', 'course'=>$courseid)));
96 $focus = '';
98 $site = get_site();
100 calendar_session_vars();
102 // If a course has been supplied in the URL, change the filters to show that one
103 $courseexists = false;
104 if ($courseid > 0) {
105 if ($courseid == SITEID) {
106 // If coming from the site page, show all courses
107 $SESSION->cal_courses_shown = calendar_get_default_courses(true);
108 calendar_set_referring_course(0);
109 } else if ($DB->record_exists('course', array('id'=>$courseid))) {
110 $courseexists = true;
111 // Otherwise show just this one
112 $SESSION->cal_courses_shown = $courseid;
113 calendar_set_referring_course($SESSION->cal_courses_shown);
117 if (!empty($SESSION->cal_course_referer)) {
118 // TODO: This is part of the Great $course Hack in Moodle. Replace it at some point.
119 $course = $DB->get_record('course', array('id'=>$SESSION->cal_course_referer));
120 } else {
121 $course = $site;
124 require_login($course, false);
126 $calendar = new calendar_information($cal_d, $cal_m, $cal_y);
127 $calendar->courseid = $courseid;
129 $strcalendar = get_string('calendar', 'calendar');
130 $link = clone($viewcalendarurl);
131 $link->param('view', 'upcoming');
133 $formoptions = new stdClass;
135 if ($eventid !== 0) {
136 $title = get_string('editevent', 'calendar');
137 $event = calendar_event::load($eventid);
138 if (!calendar_edit_event_allowed($event)) {
139 print_error('nopermissions');
141 $event->action = $action;
142 $event->course = $courseid;
143 $event->timedurationuntil = $event->timestart + $event->timeduration;
144 $event->count_repeats();
146 if (!calendar_add_event_allowed($event)) {
147 print_error('nopermissions');
149 } else {
150 $title = get_string('newevent', 'calendar');
151 calendar_get_allowed_types($formoptions->eventtypes, $USER->id);
152 $event = new calendar_event();
153 $event->action = $action;
154 $event->course = $courseid;
155 $event->timeduration = 0;
156 if ($formoptions->eventtypes->courses) {
157 if ($courseexists) {
158 $event->courseid = $courseid;
159 $event->eventtype = 'course';
160 } else {
161 unset($formoptions->eventtypes->courses);
162 unset($formoptions->eventtypes->groups);
165 if($cal_y && $cal_m && $cal_d && checkdate($cal_m, $cal_d, $cal_y)) {
166 $event->timestart = make_timestamp($cal_y, $cal_m, $cal_d, 0, 0, 0);
167 } else if($cal_y && $cal_m && checkdate($cal_m, 1, $cal_y)) {
168 if($cal_y == $now['year'] && $cal_m == $now['mon']) {
169 $event->timestart = make_timestamp($cal_y, $cal_m, $now['mday'], 0, 0, 0);
170 } else {
171 $event->timestart = make_timestamp($cal_y, $cal_m, 1, 0, 0, 0);
174 if (!calendar_add_event_allowed($event)) {
175 print_error('nopermissions');
179 $properties = $event->properties(true);
180 $formoptions->event = $event;
181 $formoptions->hasduration = ($event->timeduration > 0);
182 $mform = new event_form(null, $formoptions);
183 $mform->set_data($properties);
184 $data = $mform->get_data();
185 if ($data) {
186 if ($data->duration == 1) {
187 $data->timeduration = $data->timedurationuntil- $data->timestart;
188 } else if ($data->duration == 2) {
189 $data->timeduration = $data->timedurationminutes * MINSECS;
190 } else {
191 $data->timeduration = 0;
194 $event->update($data);
195 $eventurl = new moodle_url(CALENDAR_URL.'view.php', array('view'=>'day'));
196 if (!empty($event->courseid)) {
197 $eventurl->param('course', $event->courseid);
199 $eventurl->param('cal_d', date('j', $event->timestart));
200 $eventurl->param('cal_m', date('n', $event->timestart));
201 $eventurl->param('cal_y', date('Y', $event->timestart));
202 $eventurl->set_anchor('event_'.$event->id);
203 redirect($eventurl);
206 $PAGE->navbar->add($strcalendar, $link);
207 $PAGE->navbar->add($title);
208 $PAGE->set_title($site->shortname.': '.$strcalendar.': '.$title);
209 $PAGE->set_heading($COURSE->fullname);
211 calendar_set_filters($calendar->courses, $calendar->groups, $calendar->users);
212 $renderer = $PAGE->get_renderer('core_calendar');
213 $calendar->add_sidecalendar_blocks($renderer);
215 echo $OUTPUT->header();
216 echo $renderer->start_layout();
217 echo $OUTPUT->heading($title);
218 $mform->display();
219 echo $renderer->complete_layout();
220 echo $OUTPUT->footer();