-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsignup.php
187 lines (154 loc) · 7.59 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';
$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 = get_record('facetoface', 'id', $session->facetoface)) {
print_error('error:incorrectfacetofaceid', 'facetoface');
}
if (!$course = get_record('course', '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);
$context = get_context_instance(CONTEXT_COURSE, $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);
$navlinks[] = array('name' => get_string('modulenameplural', 'facetoface'), 'link' => "index.php?id=$course->id", 'type' => 'title');
$navlinks[] = array('name' => $pagetitle, 'link' => '', 'type' => 'activityinstance');
$navigation = build_navigation($navlinks);
// 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);
}
print_header_simple($pagetitle, '', $navigation, '', '', true,
update_module_button($cm->id, $course->id, get_string('modulename', 'facetoface')));
notice_yesno('<p>' . get_string('guestsno', 'facetoface') . "</p>\n\n</p>" .
get_string('liketologin') . '</p>', $loginurl, get_referer(false));
print_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;
} elseif (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);
}
elseif (facetoface_get_user_submissions($facetoface->id, $USER->id)) {
print_error('alreadysignedup', 'facetoface', $returnurl);
}
elseif (facetoface_manager_needed($facetoface) && !facetoface_get_manageremail($USER->id)){
print_error('error:manageremailaddressmissing', 'facetoface', $returnurl);
}
elseif ($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 .= '<br /><br />'.get_string('confirmationsentmgr', 'facetoface');
}
else {
$message .= '<br /><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);
}
elseif ($manageremail !== false) {
// Set values for the form
$toform = new object();
$toform->manageremail = $manageremail;
$mform->set_data($toform);
}
print_header_simple($pagetitle, '', $navigation, '', '', true,
update_module_button($cm->id, $course->id, get_string('modulename', 'facetoface')));
$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);
}
print_box_start();
print_heading($heading, 'center');
$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 '<br />' . $errorstring;
print_box_end();
print_footer($course);
exit;
}
if (!$signedup && !facetoface_session_has_capacity($session, $context) && (!$session->allowoverbook)) {
print_error('sessionisfull', 'facetoface', $returnurl);
print_box_end();
print_footer($course);
exit;
}
facetoface_print_session($session, $viewattendees);
if ($signedup) {
if (!($session->datetimeknown && facetoface_has_session_started($session, $timenow))) {
// Cancellation link
echo '<a href="'.$CFG->wwwroot.'/mod/facetoface/cancelsignup.php?s='.$session->id.'&backtoallsessions='.$backtoallsessions.'" title="'.get_string('cancelbooking','facetoface').'">'.get_string('cancelbooking', 'facetoface').'">'.get_string('cancelbooking', 'facetoface').'</a>';
echo ' – ';
}
// See attendees link
if ($viewattendees) {
echo '<a href="'.$CFG->wwwroot.'/mod/facetoface/attendees.php?s='.$session->id.'&backtoallsessions='.$backtoallsessions.'" title="'.get_string('seeattendees', 'facetoface').'">'.get_string('seeattendees', 'facetoface').'</a>';
}
echo '<br/><a href="'.$returnurl.'" title="'.get_string('goback', 'facetoface').'">'.get_string('goback', 'facetoface').'</a>';
}
// Don't allow signup to proceed if a manager is required
elseif (facetoface_manager_needed($facetoface) && !facetoface_get_manageremail($USER->id)){
// Check to see if the user has a managers email set
echo '<p><strong>'.get_string('error:manageremailaddressmissing', 'facetoface').'</strong></p>';
echo '<br/><a href="'.$returnurl.'" title="'.get_string('goback', 'facetoface').'">'.get_string('goback', 'facetoface').'</a>';
} elseif (!has_capability('mod/facetoface:signup', $context)) {
echo '<p><strong>'.get_string('error:nopermissiontosignup', 'facetoface').'</strong></p>';
echo '<br/><a href="'.$returnurl.'" title="'.get_string('goback', 'facetoface').'">'.get_string('goback', 'facetoface').'</a>';
} else {
// Signup form
$mform->display();
}
print_box_end();
print_footer($course);