-
Notifications
You must be signed in to change notification settings - Fork 13
/
signup.php
187 lines (150 loc) · 7.62 KB
/
signup.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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
<?php
require_once '../../config.php';
require_once 'lib.php';
require_once 'signup_form.php';
global $DB;
$s = required_param('s', PARAM_INT); // facetoface session ID
$backtoallsessions = optional_param('backtoallsessions', 0, PARAM_INT);
if (!$session = facetoface_get_session($s)) {
print_error('error:incorrectcoursemodulesession', 'facetoface');
}
if (!$facetoface = $DB->get_record('facetoface', array('id' => $session->facetoface))) {
print_error('error:incorrectfacetofaceid', 'facetoface');
}
if (!$course = $DB->get_record('course', array('id' => $facetoface->course))) {
print_error('error:coursemisconfigured', 'facetoface');
}
if (!$cm = get_coursemodule_from_instance("facetoface", $facetoface->id, $course->id)) {
print_error('error:incorrectcoursemoduleid', 'facetoface');
}
require_course_login($course, true, $cm);
$context = context_course::instance($course->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";
}
$pagetitle = format_string($facetoface->name);
$PAGE->set_cm($cm);
$PAGE->set_url('/mod/facetoface/signup.php', array('s' => $s, 'backtoallsessions' => $backtoallsessions));
$PAGE->set_title($pagetitle);
$PAGE->set_heading($course->fullname);
// Guests can't signup for a session, so offer them a choice of logging in or going back.
if (isguestuser()) {
$loginurl = $CFG->wwwroot.'/login/index.php';
if (!empty($CFG->loginhttps)) {
$loginurl = str_replace('http:','https:', $loginurl);
}
echo $OUTPUT->header();
$out = html_writer::tag('p', get_string('guestsno', 'facetoface')) .
html_writer::empty_tag('br') .
html_writer::tag('p', get_string('continuetologin', 'facetoface'));
echo $OUTPUT->confirm($out, $loginurl, get_referer(false));
echo $OUTPUT->footer();
exit();
}
$manageremail = false;
if (get_config(NULL, 'facetoface_addchangemanageremail')) {
$manageremail = facetoface_get_manageremail($USER->id);
}
$showdiscountcode = ($session->discountcost > 0);
$mform = new mod_facetoface_signup_form(null, compact('s', 'backtoallsessions', 'manageremail', 'showdiscountcode'));
if ($mform->is_cancelled()) {
redirect($returnurl);
}
if ($fromform = $mform->get_data()) { // Form submitted
if (empty($fromform->submitbutton)) {
print_error('error:unknownbuttonclicked', 'facetoface', $returnurl);
}
// User can not update Manager's email (depreciated functionality)
if (!empty($fromform->manageremail)) {
add_to_log($course->id, 'facetoface', 'update manageremail (FAILED)', "signup.php?s=$session->id", $facetoface->id, $cm->id);
}
// Get signup type
if (!$session->datetimeknown) {
$statuscode = MDL_F2F_STATUS_WAITLISTED;
} else if (facetoface_get_num_attendees($session->id) < $session->capacity) {
// Save available
$statuscode = MDL_F2F_STATUS_BOOKED;
} else {
$statuscode = MDL_F2F_STATUS_WAITLISTED;
}
if (!facetoface_session_has_capacity($session, $context) && (!$session->allowoverbook)) {
print_error('sessionisfull', 'facetoface', $returnurl);
} else if (facetoface_get_user_submissions($facetoface->id, $USER->id)) {
print_error('alreadysignedup', 'facetoface', $returnurl);
} else if (facetoface_manager_needed($facetoface) && !facetoface_get_manageremail($USER->id)) {
print_error('error:manageremailaddressmissing', 'facetoface', $returnurl);
} else if ($submissionid = facetoface_user_signup($session, $facetoface, $course, $fromform->discountcode, $fromform->notificationtype, $statuscode)) {
add_to_log($course->id, 'facetoface','signup',"signup.php?s=$session->id", $session->id, $cm->id);
$message = get_string('bookingcompleted', 'facetoface');
if ($session->datetimeknown && $facetoface->confirmationinstrmngr) {
$message .= html_writer::empty_tag('br') . html_writer::empty_tag('br') . get_string('confirmationsentmgr', 'facetoface');
} else {
$message .= html_writer::empty_tag('br') . html_writer::empty_tag('br') . get_string('confirmationsent', 'facetoface');
}
$timemessage = 4;
redirect($returnurl, $message, $timemessage);
} else {
add_to_log($course->id, 'facetoface','signup (FAILED)',"signup.php?s=$session->id", $session->id, $cm->id);
print_error('error:problemsigningup', 'facetoface', $returnurl);
}
redirect($returnurl);
} else if ($manageremail !== false) {
// Set values for the form
$toform = new stdClass();
$toform->manageremail = $manageremail;
$mform->set_data($toform);
}
echo $OUTPUT->header();
$heading = get_string('signupfor', 'facetoface', $facetoface->name);
$viewattendees = has_capability('mod/facetoface:viewattendees', $context);
$signedup = facetoface_check_signup($facetoface->id);
if ($signedup and $signedup != $session->id) {
print_error('error:signedupinothersession', 'facetoface', $returnurl);
}
echo $OUTPUT->box_start();
echo $OUTPUT->heading($heading);
$timenow = time();
if ($session->datetimeknown && facetoface_has_session_started($session, $timenow)) {
$inprogress_str = get_string('cannotsignupsessioninprogress', 'facetoface');
$over_str = get_string('cannotsignupsessionover', 'facetoface');
$errorstring = facetoface_is_session_in_progress($session, $timenow) ? $inprogress_str : $over_str;
echo html_writer::empty_tag('br') . $errorstring;
echo $OUTPUT->box_end();
echo $OUTPUT->footer($course);
exit;
}
if (!$signedup && !facetoface_session_has_capacity($session, $context) && (!$session->allowoverbook)) {
print_error('sessionisfull', 'facetoface', $returnurl);
echo $OUTPUT->box_end();
echo $OUTPUT->footer($course);
exit;
}
echo facetoface_print_session($session, $viewattendees);
if ($signedup) {
if (!($session->datetimeknown && facetoface_has_session_started($session, $timenow))) {
// Cancellation link
echo html_writer::link(new moodle_url('cancelsignup.php', array('s' => $session->id, 'backtoallsessions' => $backtoallsessions)), get_string('cancelbooking', 'facetoface'), array('title' => get_string('cancelbooking', 'facetoface')));
echo ' – ';
}
// See attendees link
if ($viewattendees) {
echo html_writer::link(new moodle_url('attendees.php', array('s' => $session->id, 'backtoallsessions' => $backtoallsessions)), get_string('seeattendees', 'facetoface'), array('title' => get_string('seeattendees', 'facetoface')));
}
echo html_writer::empty_tag('br') . html_writer::link($returnurl, get_string('goback', 'facetoface'), array('title' => get_string('goback', 'facetoface')));
}
// Don't allow signup to proceed if a manager is required
else if (facetoface_manager_needed($facetoface) && !facetoface_get_manageremail($USER->id)) {
// Check to see if the user has a managers email set
echo html_writer::tag('p', html_writer::tag('strong', get_string('error:manageremailaddressmissing', 'facetoface')));
echo html_writer::empty_tag('br') . html_writer::link($returnurl, get_string('goback', 'facetoface'), array('title' => get_string('goback', 'facetoface')));
} else if (!has_capability('mod/facetoface:signup', $context)) {
echo html_writer::tag('p', html_writer::tag('strong', get_string('error:nopermissiontosignup', 'facetoface')));
echo html_writer::empty_tag('br') . html_writer::link($returnurl, get_string('goback', 'facetoface'), array('title' => get_string('goback', 'facetoface')));
} else {
// Signup form
$mform->display();
}
echo $OUTPUT->box_end();
echo $OUTPUT->footer($course);