forked from catalyst/moodle-mod_facetoface
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cancelsignup.php
150 lines (123 loc) · 5.51 KB
/
cancelsignup.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Copyright (C) 2007-2011 Catalyst IT (http://www.catalyst.net.nz)
* Copyright (C) 2011-2013 Totara LMS (http://www.totaralms.com)
* Copyright (C) 2014 onwards Catalyst IT (http://www.catalyst-eu.net)
*
* @package mod
* @subpackage facetoface
* @copyright 2014 onwards Catalyst IT <http://www.catalyst-eu.net>
* @author Stacey Walker <[email protected]>
* @author Alastair Munro <[email protected]>
* @author Aaron Barnes <[email protected]>
* @author Francois Marier <[email protected]>
*/
require_once(dirname(dirname(dirname(__FILE__))) . '/config.php');
require_once('lib.php');
$s = required_param('s', PARAM_INT); // Facetoface session ID.
$confirm = optional_param('confirm', false, PARAM_BOOL);
$backtoallsessions = optional_param('backtoallsessions', 0, PARAM_INT);
if (!$session = facetoface_get_session($s)) {
throw new moodle_exception('error:incorrectcoursemodulesession', 'facetoface');
}
if (!$session->allowcancellations) {
throw new moodle_exception('error:cancellationsnotallowed', 'facetoface');
}
if (!$facetoface = $DB->get_record('facetoface', array('id' => $session->facetoface))) {
throw new moodle_exception('error:incorrectfacetofaceid', 'facetoface');
}
if (!$course = $DB->get_record('course', array('id' => $facetoface->course))) {
throw new moodle_exception('error:coursemisconfigured', 'facetoface');
}
if (!$cm = get_coursemodule_from_instance("facetoface", $facetoface->id, $course->id)) {
throw new moodle_exception('error:incorrectcoursemoduleid', 'facetoface');
}
require_course_login($course);
$context = context_course::instance($course->id);
$contextmodule = context_module::instance($cm->id);
require_capability('mod/facetoface:view', $context);
$returnurl = "$CFG->wwwroot/course/view.php?id=$course->id";
if ($backtoallsessions) {
$returnurl = "$CFG->wwwroot/mod/facetoface/view.php?f=$backtoallsessions";
}
$mform = new mod_facetoface_cancelsignup_form(null, compact('s', 'backtoallsessions'));
if ($mform->is_cancelled()) {
redirect($returnurl);
}
if ($fromform = $mform->get_data()) { // Form submitted.
if (empty($fromform->submitbutton)) {
throw new moodle_exception('error:unknownbuttonclicked', 'facetoface', $returnurl);
}
$timemessage = 4;
$errorstr = '';
if (facetoface_user_cancel($session, false, false, $errorstr, $fromform->cancelreason)) {
// Logging and events trigger.
$params = array(
'context' => $contextmodule,
'objectid' => $session->id
);
$event = \mod_facetoface\event\cancel_booking::create($params);
$event->add_record_snapshot('facetoface_sessions', $session);
$event->add_record_snapshot('facetoface', $facetoface);
$event->trigger();
$message = get_string('bookingcancelled', 'facetoface');
if ($session->datetimeknown) {
$error = facetoface_send_cancellation_notice($facetoface, $session, $USER->id);
if (empty($error)) {
if ($session->datetimeknown && $facetoface->cancellationinstrmngr) {
$message .= html_writer::empty_tag('br') . html_writer::empty_tag('br') . get_string('cancellationsentmgr', 'facetoface');
} else {
$message .= html_writer::empty_tag('br') . html_writer::empty_tag('br') . get_string('cancellationsent', 'facetoface');
}
} else {
throw new moodle_exception($error, 'facetoface');
}
}
redirect($returnurl, $message, $timemessage);
} else {
// Logging and events trigger.
$params = array(
'context' => $contextmodule,
'objectid' => $session->id
);
$event = \mod_facetoface\event\cancel_booking_failed::create($params);
$event->add_record_snapshot('facetoface_sessions', $session);
$event->add_record_snapshot('facetoface', $facetoface);
$event->trigger();
redirect($returnurl, $errorstr, $timemessage);
}
redirect($returnurl);
}
$pagetitle = format_string($facetoface->name);
$PAGE->set_cm($cm);
$PAGE->set_url('/mod/facetoface/cancelsignup.php', array('s' => $s, 'backtoallsessions' => $backtoallsessions, 'confirm' => $confirm));
$PAGE->set_title($pagetitle);
$PAGE->set_heading($course->fullname);
echo $OUTPUT->header();
$heading = get_string('cancelbookingfor', 'facetoface', format_string($facetoface->name));
$viewattendees = has_capability('mod/facetoface:viewattendees', $context);
$signedup = facetoface_check_signup($facetoface->id);
echo $OUTPUT->box_start();
echo $OUTPUT->heading($heading);
if ($signedup) {
facetoface_print_session($session, $viewattendees);
$mform->display();
} else {
throw new moodle_exception('notsignedup', 'facetoface', $returnurl);
}
echo $OUTPUT->box_end();
echo $OUTPUT->footer($course);