-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbookinghistory.php
144 lines (120 loc) · 5.57 KB
/
bookinghistory.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
<?php
/*
* This file is part of Totara LMS
*
* Copyright (C) 2009 Catalyst IT LTD
* Copyright (C) 2010 - 2012 Totara Learning Solutions LTD
*
* This program 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 2 of the License, or
* (at your option) any later version.
*
* This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
*
* @author Alastair Munro <[email protected]>
* @author Francois Marier <[email protected]>
* @package blocks
* @subpackage facetoface
*/
// Displays booking history for the current user
require_once(dirname(dirname(dirname(__FILE__))) . '/config.php');
require_once('lib.php');
$PAGE->set_context(get_system_context());
require_login();
$sid = required_param('session', PARAM_INT);
$userid = optional_param('userid', $USER->id, PARAM_INT);
// get all the required records
if (!$user = $DB->get_record('user', array('id' => $userid))) {
print_error('error:invaliduserid', 'block_facetoface');
}
if (!$session = facetoface_get_session($sid)) {
print_error('error:invalidsessionid', 'block_facetoface');
}
if (!$facetoface = $DB->get_record('facetoface', array('id' => $session->facetoface))) {
print_error('error:invalidfacetofaceid', 'block_facetoface');
}
if (!$course = $DB->get_record('course', array('id' => $facetoface->course))) {
print_error('error:invalidcourseid', 'block_facetoface');
}
if ($userid != $USER->id) {
$contextuser = context_user::instance($userid);
if (!has_capability('block/facetoface:viewbookings', $contextuser)) {
$contextcourse = context_course::instance($course->id);
require_capability('mod/facetoface:viewattendees', $contextcourse);
}
}
$pagetitle = format_string(get_string('bookinghistory', 'block_facetoface'));
$PAGE->navbar->add(get_string('bookings', 'block_facetoface'), new moodle_url('/blocks/facetoface/mysignups.php', array('userid' => $userid)));
$PAGE->navbar->add($pagetitle);
$PAGE->set_title($pagetitle);
$PAGE->set_heading($SITE->fullname);
$PAGE->set_url('/blocks/facetoface/mysessions.php');
$PAGE->set_pagelayout('standard');
echo $OUTPUT->header();
echo $OUTPUT->box_start();
// Get signups from the DB
$bookings = $DB->get_records_sql("SELECT ss.timecreated, ss.statuscode, ss.grade, ss.note,
c.id as courseid, c.fullname AS coursename,
f.name, f.id as facetofaceid, s.id as sessionid,
d.id, d.timestart, d.timefinish
FROM {facetoface_sessions_dates} d
JOIN {facetoface_sessions} s ON s.id = d.sessionid
JOIN {facetoface} f ON f.id = s.facetoface
JOIN {facetoface_signups} su ON su.sessionid = s.id
JOIN {facetoface_signups_status} ss ON ss.signupid = su.id
JOIN {course} c ON f.course = c.id
WHERE su.userid = ? AND su.sessionid = ? AND f.id = ?
ORDER BY ss.timecreated ASC", array($user->id, $session->id, $session->facetoface));
// Get session times
$sessiontimes = facetoface_get_session_dates($session->id);
if ($user->id != $USER->id) {
$fullname = html_writer::link(new moodle_url('/user/view.php', array('id' => $user->id, 'course' => $course->id)), fullname($user));
$heading = get_string('bookinghistoryfor', 'block_facetoface', $fullname);
echo $OUTPUT->heading($heading);
} else {
echo html_writer::empty_tag('br');
}
echo $OUTPUT->heading(get_string('sessiondetails', 'block_facetoface'));
// print the session information
$cm = get_coursemodule_from_instance('facetoface', $facetoface->id, $course->id);
$contextmodule = context_module::instance($cm->id);
$viewattendees = has_capability('mod/facetoface:viewattendees', $contextmodule);
echo facetoface_print_session($session, $viewattendees, false, false, true);
// print the booking history
if ($bookings and count($bookings) > 0) {
$table = new html_table();
$table->summary = get_string('sessionsdetailstablesummary', 'facetoface');
$table->attributes['class'] = 'generaltable bookinghistory';
foreach ($bookings as $booking) {
$row = array(
get_string('status_'.facetoface_get_status($booking->statuscode), 'facetoface'),
userdate($booking->timecreated, get_string('strftimedatetime'))
);
if (strlen(trim($booking->note))) {
$row[] = $booking->note;
}
$table->data[] = $row;
}
} else {
// no booking history available
$table = new html_table();
$table->summary = get_string('sessionsdetailstablesummary', 'facetoface');
$table->attributes['class'] = 'generaltable bookinghistory';
$table->align = array('center');
if ($user->id != $USER->id) {
$table->data[] = array(get_string('nobookinghistoryfor','block_facetoface',fullname($user)));
} else {
$table->data[] = array(get_string('nobookinghistory','block_facetoface'));
}
}
echo $OUTPUT->heading(get_string('bookinghistory', 'block_facetoface'));
echo html_writer::table($table);
echo $OUTPUT->box_end();
echo $OUTPUT->footer();