-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbookinghistory.php
113 lines (91 loc) · 4.29 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
<?php
// Displays booking history for the current user
require_once '../../config.php';
require_once('lib.php');
require_login();
$sid = required_param('session', PARAM_INT);
$userid = optional_param('userid', $USER->id, PARAM_INT);
// get all the required records
if (!$user = get_record('user','id',$userid)) {
print_error('error:invaliduserid', 'block_facetoface');
}
if (!$session = facetoface_get_session($sid)) {
print_error('error:invalidsessionid', 'block_facetoface');
}
if(!$facetoface = get_record('facetoface','id', $session->facetoface)) {
print_error('error:invalidfacetofaceid', 'block_facetoface');
}
if (!$course = get_record('course','id',$facetoface->course)) {
print_error('error:invalidcourseid', 'block_facetoface');
}
if ($userid != $USER->id) {
$contextuser = get_context_instance(CONTEXT_USER, $userid);
if (!has_capability('block/facetoface:viewbookings', $contextuser)) {
$contextcourse = get_context_instance(CONTEXT_COURSE, $course->id);
require_capability('mod/facetoface:viewattendees', $contextcourse);
}
}
$pagetitle = format_string(get_string('bookinghistory', 'block_facetoface'));
$navlinks[] = array('name' => $pagetitle, 'link' => '', 'type' => 'activityinstance');
$navigation = build_navigation($navlinks);
print_header_simple($pagetitle, '', $navigation);
print_box_start();
// Get signups from the DB
$bookings = 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 {$CFG->prefix}facetoface_sessions_dates d
JOIN {$CFG->prefix}facetoface_sessions s ON s.id = d.sessionid
JOIN {$CFG->prefix}facetoface f ON f.id = s.facetoface
JOIN {$CFG->prefix}facetoface_signups su ON su.sessionid = s.id
JOIN {$CFG->prefix}facetoface_signups_status ss ON ss.signupid = su.id
JOIN {$CFG->prefix}course c ON f.course = c.id
WHERE su.userid = $user->id AND su.sessionid = $session->id AND f.id = $session->facetoface
ORDER BY ss.timecreated ASC");
// Get session times
$sessiontimes = facetoface_get_session_dates($session->id);
if ($user->id != $USER->id) {
$fullname = '<a href="'.$CFG->wwwroot.'/user/view.php?id='.$user->id.'&course='.$course->id.'">'.fullname($user).'</a>';
$heading = get_string('bookinghistoryfor', 'block_facetoface', $fullname);
print_heading($heading, 'center');
} else {
echo "<br />";
}
print_heading(get_string('sessiondetails', 'block_facetoface'), 'center');
// print the session information
$cm = get_coursemodule_from_instance('facetoface', $facetoface->id, $course->id);
$contextmodule = get_context_instance(CONTEXT_MODULE, $cm->id);
$viewattendees = has_capability('mod/facetoface:viewattendees', $contextmodule);
facetoface_print_session($session, $viewattendees, false, false, true);
// print the booking history
if ($bookings and count($bookings) > 0) {
$table = new object();
$table->summary = get_string('sessionsdetailstablesummary', 'facetoface');
$table->width = '50%';
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 object();
$table->summary = get_string('sessionsdetailstablesummary', 'facetoface');
$table->width = '50%';
$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'));
}
}
print_heading(get_string('bookinghistory', 'block_facetoface'), 'center');
print_table($table);
print_box_end();
print_footer();