forked from Wunderbyte-GmbH/moodle-mod_booking
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathview.php
213 lines (179 loc) · 8.89 KB
/
view.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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
<?php // $Id: view.php,v 1.102.2.11 2011/02/04 17:12:18 dasistwas Exp $
require_once("../../config.php");
require_once("lib.php");
require_once($CFG->libdir . '/completionlib.php');
$id = required_param('id', PARAM_INT); // Course Module ID
$action = optional_param('action', '', PARAM_ALPHA);
$optionid = optional_param('optionid', '', PARAM_INT);
$confirm = optional_param('confirm', '',PARAM_INT);
$answer = optional_param('answer', '',PARAM_ALPHANUM);
$url = new moodle_url('/mod/booking/view.php', array('id'=>$id));
$PAGE->set_url($url);
if (! $cm = get_coursemodule_from_id('booking', $id)) {
print_error('invalidcoursemodule');
}
if (! $course = $DB->get_record("course", array("id" => $cm->course))) {
print_error('coursemisconf');
}
require_course_login($course, false, $cm);
if (!$booking = booking_get_booking($cm)) {
print_error("Course module is incorrect");
}
$strbooking = get_string('modulename', 'booking');
$strbookings = get_string('modulenameplural', 'booking');
if (!$context = get_context_instance(CONTEXT_MODULE, $cm->id)) {
print_error('badcontext');
}
// check if booking options have already been set or if they are still empty
$records = $DB->get_records('booking_options', array('bookingid' => $booking->id));
if (empty($records)) { // Brand new database!
if (has_capability('mod/booking:updatebooking', $context)) {
redirect($CFG->wwwroot.'/mod/booking/editoptions.php?id='.$cm->id.'&optionid=add'); // Redirect to field entry
} else {
print_error("There are no booking options available yet");
}
}
// check if data has been submitted to be processed
if ($action == 'delbooking' and confirm_sesskey() && $confirm == 1 and has_capability('mod/booking:choose', $context) and ($booking->allowupdate or has_capability('mod/booking:deleteresponses', $context))) {
if ($answer = $DB->get_record('booking_answers', array('bookingid' => $booking->id, 'userid' => $USER->id, 'optionid' => $optionid))) {
$newbookeduser = booking_check_statuschange($optionid, $booking, $USER->id, $cm->id);
if(booking_delete_singlebooking($answer,$booking,$optionid,$newbookeduser,$cm->id)){
echo $OUTPUT->header();
$contents = get_string('bookingdeleted','booking');
$contents .= $OUTPUT->single_button($url, get_string('continue'),'get');
echo $OUTPUT->box($contents, 'box generalbox', 'notice');
echo $OUTPUT->footer();
die;
}
}
} elseif ($action == 'delbooking' and confirm_sesskey() and has_capability('mod/booking:choose', $context) and ($booking->allowupdate or has_capability('mod/booking:deleteresponses', $context))){ //print confirm delete form
echo $OUTPUT->header();
$options = array('id' => $cm->id, 'action' => 'delbooking', 'confirm' => 1, 'optionid' => $optionid, 'sesskey' => $USER->sesskey);
$deletemessage = $booking->option[$optionid]->text."<br />".$booking->option[$optionid]->coursestarttimetext." - ".$booking->option[$optionid]->courseendtimetext;
echo $OUTPUT->confirm(get_string('deletebooking','booking',$deletemessage), new moodle_url('view.php',$options),$url);
echo $OUTPUT->footer();
die;
}
// before processing data user has to agree to booking policy and confirm booking
if ($form = data_submitted() && has_capability('mod/booking:choose', $context) && confirm_sesskey() && $confirm != 1 && $answer) {
booking_confirm_booking($answer, $booking, $USER, $cm,$url);
die;
}
$PAGE->set_title(format_string($booking->name));
$PAGE->set_heading($course->fullname);
echo $OUTPUT->header();
// check if custom user profile fields are required and redirect to complete them if necessary
if (has_capability('moodle/user:editownprofile', $context, NULL, false) and booking_check_user_profile_fields($USER->id) and !has_capability('moodle/site:doanything', $context)){ # doanything does not exist in Moodle 2 ...
$contents = get_string('mustfilloutuserinfobeforebooking','booking');
$contents .= $OUTPUT->single_button(new moodle_url("edituserprofile.php", array('cmid' => $cm->id, 'courseid' => $course->id)), get_string('continue'),'get');
echo $OUTPUT->box($contents, 'box generalbox', 'notice');
echo $OUTPUT->footer();
die;
}
/// Submit any new data if there is any
if ($form = data_submitted() && has_capability('mod/booking:choose', $context)) {
$timenow = time();
if (!empty($answer)) {
if(booking_user_submit_response($answer, $booking, $USER, $course->id, $cm)){
$contents = get_string('bookingsaved','booking');
if ($booking->sendmail){
$contents .= "<br />".get_string('mailconfirmationsent', 'booking').".";
}
$contents .= $OUTPUT->single_button(new moodle_url("view.php", array('id' => $cm->id)),get_string('continue'),'get');
echo $OUTPUT->box($contents,'box generalbox', 'notice');
echo $OUTPUT->footer();
die;
} elseif (is_int($answer)) {
$contents = get_string('bookingmeanwhilefull','booking')." ".$booking->option[$answer]->text;
$contents .= $OUTPUT->single_button(new moodle_url("view.php", array('id' => $cm->id)),'get');
echo $OUTPUT->box($contents,'box generalbox', 'notice');
echo $OUTPUT->footer();
die;
}
} else {
$contents = get_string('nobookingselected','booking');
$contents .= $OUTPUT->single_button(new moodle_url("view.php", array('id' => $cm->id)),'get');
echo $OUTPUT->box($contents,'box generalbox', 'notice');
echo $OUTPUT->footer();
die;
}
}
// we have to refresh $booking as it is modified by submitted data;
$booking = booking_get_booking($cm);
/// Display the booking and possibly results
add_to_log($course->id, "booking", "view", "view.php?id=$cm->id", $booking->id, $cm->id);
$bookinglist = booking_get_spreadsheet_data($booking, $cm);
echo '<div class="clearer"></div>';
if ($booking->intro) {
echo $OUTPUT->box(format_module_intro('booking', $booking, $cm->id,true), 'generalbox', 'intro');
}
//download spreadsheet of all users
if (has_capability('mod/booking:downloadresponses',$context)) {
/// Download spreadsheet for all booking options
echo $html = html_writer::tag('div', get_string('downloadallresponses', 'booking').': ', array('style' => 'font-weight: bold; text-align: left;'));
$optionstochoose = array( 'all' => get_string('allbookingoptions', 'booking'));
foreach ($booking->option as $option){
$optionstochoose[$option->id] = $option->text;
}
$options = array();
$options["id"] = "$cm->id";
$options["optionid"] = 0;
$options["download"] = "ods";
$options['action'] = "all";
$button = $OUTPUT->single_button(new moodle_url("report.php", $options), get_string("downloadods"));
echo '<div style="text-align: right; display:table;">';
echo html_writer::tag('span', $button, array('style' => 'text-align: right; display:table-cell;'));
$options["download"] = "xls";
$button = $OUTPUT->single_button(new moodle_url("report.php", $options), get_string("downloadexcel"));
echo html_writer::tag('span', $button, array('style' => 'text-align: right; display:table-cell;'));
echo '</div>';
}
$current = false; // Initialise for later
//if user has already made a selection, show their selected answer.
/// Print the form
$bookingopen = true;
$timenow = time();
// This fonction already exist in Moodle 2.x
/*if ($booking->timeclose !=0) {
if ($booking->timeopen > $timenow && !has_capability('mod/booking:updatebooking', $context)) {
echo $OUTPUT->box(get_string("notopenyet", "booking", userdate($booking->timeopen)), "center");
echo $OUTPUT->footer();
exit;
} else if ($timenow > $booking->timeclose && !has_capability('mod/booking:updatebooking', $context)) {
echo $OUTPUT->box(get_string("expired", "booking", userdate($booking->timeclose)), "center");
$bookingopen = false;
}
}*/
// Manage guest
if (isset($USER->username) && ($USER->username == 'guest')) {
echo $OUTPUT->box(get_string("havetologin", "booking"));
echo $OUTPUT->footer();
exit;
}
if ( !$current and $bookingopen and has_capability('mod/booking:choose', $context) ) {
echo $OUTPUT->box(booking_show_maxperuser($booking, $USER, $bookinglist), 'box mdl-align');
if ($action=='mybooking'){
$message = "<a href=\"view.php?id=$cm->id\">".get_string('showallbookings','booking')."</a>";
echo $OUTPUT->box($message,'box mdl-align');
booking_show_form($booking, $USER, $cm, $bookinglist,1);
} else {
$message = "<a href=\"view.php?id=$cm->id&action=mybooking\">".get_string('showmybookings','booking')."</a>";
echo $OUTPUT->box($message,'box mdl-align');
booking_show_form($booking, $USER, $cm, $bookinglist,0);
}
$bookingformshown = true;
} else {
$bookingformshown = false;
}
if (!$bookingformshown) {
if ($bookingopen) # Il ne faut pas afficher ce message que si les réservations sont ouvertes !
echo $OUTPUT->box(get_string("norighttobook", "booking"));
}
if (has_capability('mod/booking:updatebooking', $context)) {
$addoptionurl = new moodle_url('editoptions.php', array('id'=>$cm->id, 'optionid'=> 'add'));
echo '<div style="width: 100%; text-align: center;">';
echo $OUTPUT->single_button($addoptionurl,get_string('addnewbookingoption','booking'),'get');
echo '</div>';
}
echo $OUTPUT->footer();
?>