MDL-70237 payment: Allow html tags in gateway description
[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);
797cedc7
SH
58$courseid = optional_param('courseid', SITEID, PARAM_INT);
59$courseid = optional_param('course', $courseid, PARAM_INT);
da304137
MN
60$day = optional_param('cal_d', 0, PARAM_INT);
61$month = optional_param('cal_m', 0, PARAM_INT);
62$year = optional_param('cal_y', 0, PARAM_INT);
63$time = optional_param('time', 0, PARAM_INT);
64
65// If a day, month and year were passed then convert it to a timestamp. If these were passed
66// then we can assume the day, month and year are passed as Gregorian, as no where in core
67// should we be passing these values rather than the time. This is done for BC.
68if (!empty($day) && !empty($month) && !empty($year)) {
69 if (checkdate($month, $day, $year)) {
70 $time = make_timestamp($year, $month, $day);
71 } else {
72 $time = time();
73 }
74} else if (empty($time)) {
75 $time = time();
76}
93c91ee4 77
797cedc7 78$url = new moodle_url('/calendar/event.php', array('action' => $action));
da304137 79
797cedc7
SH
80if ($eventid != 0) {
81 $url->param('id', $eventid);
82}
da304137 83
797cedc7
SH
84if ($courseid != SITEID) {
85 $url->param('course', $courseid);
86}
da304137 87
93c91ee4 88$PAGE->set_url($url);
566889aa 89$PAGE->set_pagelayout('admin');
93c91ee4 90
797cedc7 91if ($courseid != SITEID && !empty($courseid)) {
74df2951 92 $course = $DB->get_record('course', array('id' => $courseid), '*', MUST_EXIST);
797cedc7
SH
93 $courses = array($course->id => $course);
94 $issite = false;
95} else {
96 $course = get_site();
97 $courses = calendar_get_default_courses();
98 $issite = true;
99}
100require_login($course, false);
101
102if ($action === 'delete' && $eventid > 0) {
a6855934 103 $deleteurl = new moodle_url('/calendar/delete.php', array('id'=>$eventid));
76d9df3f
SH
104 if ($courseid > 0) {
105 $deleteurl->param('course', $courseid);
106 }
107 redirect($deleteurl);
108}
109
da304137 110$calendar = new calendar_information(0, 0, 0, $time);
d0e56d84 111$calendar->set_sources($course, $courses);
93c91ee4 112
76d9df3f 113$formoptions = new stdClass;
76d9df3f
SH
114if ($eventid !== 0) {
115 $title = get_string('editevent', 'calendar');
116 $event = calendar_event::load($eventid);
909d0858 117 if (!calendar_edit_event_allowed($event, true)) {
76d9df3f 118 print_error('nopermissions');
36dc3b71 119 }
76d9df3f
SH
120 $event->action = $action;
121 $event->course = $courseid;
122 $event->timedurationuntil = $event->timestart + $event->timeduration;
123 $event->count_repeats();
93c91ee4 124
76d9df3f
SH
125 if (!calendar_add_event_allowed($event)) {
126 print_error('nopermissions');
36dc3b71 127 }
c3feaf26
SB
128
129 // Check to see if this event is part of a subscription or import.
130 // If so display a warning on edit.
131 if (isset($event->subscriptionid) && ($event->subscriptionid != null)) {
132 \core\notification::add(get_string('eventsubscriptioneditwarning', 'calendar'), \core\output\notification::NOTIFY_INFO);
133 }
134
36dc3b71 135} else {
76d9df3f 136 $title = get_string('newevent', 'calendar');
797cedc7 137 calendar_get_allowed_types($formoptions->eventtypes, $course);
f4700b91 138 $event = new stdClass();
76d9df3f
SH
139 $event->action = $action;
140 $event->course = $courseid;
4370d73d 141 $event->courseid = $courseid;
76d9df3f
SH
142 $event->timeduration = 0;
143 if ($formoptions->eventtypes->courses) {
797cedc7 144 if (!$issite) {
76d9df3f 145 $event->eventtype = 'course';
93c91ee4 146 } else {
76d9df3f
SH
147 unset($formoptions->eventtypes->courses);
148 unset($formoptions->eventtypes->groups);
93c91ee4 149 }
36dc3b71 150 }
da304137 151 $event->timestart = $time;
f4700b91 152 $event = new calendar_event($event);
76d9df3f
SH
153 if (!calendar_add_event_allowed($event)) {
154 print_error('nopermissions');
36dc3b71
SH
155 }
156}
7423f116 157
76d9df3f
SH
158$properties = $event->properties(true);
159$formoptions->event = $event;
160$formoptions->hasduration = ($event->timeduration > 0);
161$mform = new event_form(null, $formoptions);
162$mform->set_data($properties);
163$data = $mform->get_data();
164if ($data) {
165 if ($data->duration == 1) {
166 $data->timeduration = $data->timedurationuntil- $data->timestart;
167 } else if ($data->duration == 2) {
168 $data->timeduration = $data->timedurationminutes * MINSECS;
169 } else {
170 $data->timeduration = 0;
bdbae764 171 }
7423f116 172
76d9df3f 173 $event->update($data);
797cedc7
SH
174
175 $params = array(
176 'view' => 'day',
da304137 177 'time' => $event->timestart,
797cedc7
SH
178 );
179 $eventurl = new moodle_url('/calendar/view.php', $params);
180 if (!empty($event->courseid) && $event->courseid != SITEID) {
76d9df3f 181 $eventurl->param('course', $event->courseid);
bdbae764 182 }
76d9df3f
SH
183 $eventurl->set_anchor('event_'.$event->id);
184 redirect($eventurl);
bdbae764 185}
7423f116 186
797cedc7
SH
187$viewcalendarurl = new moodle_url(CALENDAR_URL.'view.php', $PAGE->url->params());
188$viewcalendarurl->remove_params(array('id', 'action'));
189$viewcalendarurl->param('view', 'upcoming');
190$strcalendar = get_string('calendar', 'calendar');
191
192$PAGE->navbar->add($strcalendar, $viewcalendarurl);
76d9df3f 193$PAGE->navbar->add($title);
797cedc7
SH
194$PAGE->set_title($course->shortname.': '.$strcalendar.': '.$title);
195$PAGE->set_heading($course->fullname);
3c134875 196
36dc3b71
SH
197$renderer = $PAGE->get_renderer('core_calendar');
198$calendar->add_sidecalendar_blocks($renderer);
93c91ee4 199
36dc3b71 200echo $OUTPUT->header();
76d9df3f
SH
201echo $OUTPUT->heading($title);
202$mform->display();
93c91ee4 203echo $OUTPUT->footer();