forked from danmarsden/moodle_mod_attforblock_old
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreport.php
198 lines (169 loc) · 8.64 KB
/
report.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
<?PHP // $Id: report.php,v 1.1.2.4 2009/02/28 16:49:17 dlnsk Exp $
// generates sessions
require_once('../../config.php');
require_once($CFG->libdir.'/blocklib.php');
require_once('locallib.php');
define('USER_SMALL_CLASS', 20); // Below this is considered small
define('USER_LARGE_CLASS', 200); // Above this is considered large
define('DEFAULT_PAGE_SIZE', 20);
$id = required_param('id', PARAM_INT);
$group = optional_param('group', -1, PARAM_INT); // Group to show
$view = optional_param('view', NULL, PARAM_ALPHA); // which page to show
$current = optional_param('current', 0, PARAM_INT);
$sort = optional_param('sort', 'lastname', PARAM_ALPHA);
if ($id) {
if (! $cm = get_record('course_modules', 'id', $id)) {
error('Course Module ID was incorrect');
}
if (! $course = get_record('course', 'id', $cm->course)) {
error('Course is misconfigured');
}
if (! $attforblock = get_record('attforblock', 'id', $cm->instance)) {
error("Course module is incorrect");
}
}
require_login($course->id);
if (! $user = get_record('user', 'id', $USER->id) ) {
error("No such user in this course");
}
if (!$context = get_context_instance(CONTEXT_MODULE, $cm->id)) {
print_error('badcontext');
}
if ($view)
set_current_view($course->id, $_GET['view']);
else
$view = get_current_view($course->id);
require_capability('mod/attforblock:viewreports', $context);
//add info to log
add_to_log($course->id, 'attendance', 'report displayed', 'mod/attforblock/report.php?id='.$id, $user->lastname.' '.$user->firstname);
/// Print headers
$navlinks[] = array('name' => $attforblock->name, 'link' => "view.php?id=$id", 'type' => 'activity');
$navlinks[] = array('name' => get_string('report', 'attforblock'), 'link' => null, 'type' => 'activityinstance');
$navigation = build_navigation($navlinks);
print_header("$course->shortname: ".$attforblock->name.' - ' .get_string('report','attforblock'), $course->fullname,
$navigation, "", "", true, " ", navmenu($course));
show_tabs($cm, $context, 'report');
$sort = $sort == 'firstname' ? 'firstname' : 'lastname';
if(!count_records('attendance_sessions', 'courseid', $course->id)) { // no session exists for this course
redirect("sessions.php?id=$cm->id&action=add");
} else {
if ($current == 0)
$current = get_current_date($course->id);
else
set_current_date ($course->id, $current);
$ret = print_filter_controls("report.php", $id, 0, $sort, GROUP_SELECTOR);
$startdate = $ret['startdate'];
$enddate = $ret['enddate'];
$currentgroup = $ret['currentgroup'];
if ($startdate && $enddate) {
$where = "courseid={$course->id} AND sessdate >= $course->startdate AND sessdate >= $startdate AND sessdate < $enddate";
} else {
$where = "courseid={$course->id} AND sessdate >= $course->startdate";
}
if ($currentgroup) {
$where .= " AND (groupid=0 OR groupid=".$currentgroup.")";
$students = get_users_by_capability($context, 'moodle/legacy:student', '', "u.$sort ASC", '', '', $currentgroup, '', false);
} else {
$students = get_users_by_capability($context, 'moodle/legacy:student', '', "u.$sort ASC", '', '', '', '', false);
}
$statuses = get_statuses($course->id);
$allstatuses = get_statuses($course->id, false);
if ($students and
($course_sess = get_records_select('attendance_sessions', $where, 'sessdate ASC'))) {
$firstname = "<a href=\"report.php?id=$id&sort=firstname\">".get_string('firstname').'</a>';
$lastname = "<a href=\"report.php?id=$id&sort=lastname\">".get_string('lastname').'</a>';
if ($CFG->fullnamedisplay == 'lastname firstname') { // for better view (dlnsk)
$fullnamehead = "$lastname / $firstname";
} else {
$fullnamehead = "$firstname / $lastname";
}
$table->head[] = '';
$table->align[] = '';
$table->size[] = '1px';
$table->head[] = $fullnamehead;
$table->align[] = 'left';
$table->size[] = '';
$table->class = 'generaltable attwidth';
$allowtake = has_capability('mod/attforblock:takeattendances', $context);
$allowchange = has_capability('mod/attforblock:changeattendances', $context);
$groups = groups_get_all_groups($course->id);
foreach($course_sess as $sessdata) {
if (count_records('attendance_log', 'sessionid', $sessdata->id)) {
if ($allowchange) {
$sessdate = "<a href=\"attendances.php?id=$id&sessionid={$sessdata->id}&grouptype={$sessdata->groupid}\">".
userdate($sessdata->sessdate, get_string('strftimedm', 'attforblock').'<br />('.get_string('strftimehm', 'attforblock').')').
'</a>';
} else {
$sessdate = userdate($sessdata->sessdate, get_string('strftimedm', 'attforblock').'<br />('.get_string('strftimehm', 'attforblock').')');
}
$sesstype = $sessdata->groupid ? $groups[$sessdata->groupid]->name : get_string('commonsession', 'attforblock');
$table->head[] = $sessdate.'<br />'.$sesstype;
} else {
if ($allowtake) {
$sessdate = "<a href=\"attendances.php?id=$id&sessionid={$sessdata->id}&grouptype={$sessdata->groupid}\">".
userdate($sessdata->sessdate, get_string('strftimedm', 'attforblock').'<br />('.get_string('strftimehm', 'attforblock').')').
'</a>';
} else {
$sessdate = userdate($sessdata->sessdate, get_string('strftimedm', 'attforblock').'<br />('.get_string('strftimehm', 'attforblock').')');
}
$sesstype = $sessdata->groupid ? $groups[$sessdata->groupid]->name : get_string('commonsession', 'attforblock');
$table->head[] = $sessdate.'<br />'.$sesstype;
}
$table->align[] = 'center';
$table->size[] = '1px';
}
for ($i=0; $i<5; $i++) {
$table->align[] = 'center';
$table->size[] = '1px';
}
foreach($statuses as $st) {
$table->head[] = $st->acronym;
}
if ($attforblock->grade) {
$table->head[] = get_string('grade');//.' / '.$maxgrade;
$table->align[] = 'right';
$table->size[] = '1px';
$table->head[] = '%';
}
foreach($students as $student) {
$table->data[$student->id][] = print_user_picture($student->id, $course->id, $student->picture, 20, true, true);
$table->data[$student->id][] = "<a href=\"view.php?id=$id&student={$student->id}\">".fullname($student).'</a>';
$studgroups = groups_get_all_groups($COURSE->id, $student->id);
foreach($course_sess as $sessdata) {
if ($att = get_record('attendance_log', 'sessionid', $sessdata->id, 'studentid', $student->id)) {
if (isset($statuses[$att->statusid])) {
$table->data[$student->id][] = $statuses[$att->statusid]->acronym;
} else {
$table->data[$student->id][] = '<font color="red"><b>'.$allstatuses[$att->statusid]->acronym.'</b></font>';
}
} else {
if ($sessdata->groupid && !array_key_exists($sessdata->groupid, $studgroups))
$table->data[$student->id][] = '';
else
if($sessdata->lasttaken > 0) {
$table->data[$student->id][] = '–';
} else {
$table->data[$student->id][] = '?';
}
}
}
foreach($statuses as $st) {
$table->data[$student->id][] = get_attendance($student->id, $course, $st->id);
}
if ($attforblock->grade) {
$table->data[$student->id][] = get_grade($student->id, $course).' / '.get_maxgrade($student->id, $course);
$table->data[$student->id][] = get_percent($student->id, $course).'%';
}
}
print_table($table);
} else {
print_heading(get_string('nothingtodisplay'), 'center');
}
echo get_string('status','attforblock').':<br />';
foreach($statuses as $st) {
echo $st->acronym.' - '.$st->description.'<br />';
}
}
print_footer($course);
exit;
?>