-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreport.php
256 lines (227 loc) · 12.4 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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
<?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');
require_once('../../enrol/locallib.php'); // to get a list of enrolled students
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', 'weeks', PARAM_ALPHA); // which page to show
$current = optional_param('current', 0, PARAM_INT);
$sort = optional_param('sort', 'lastname', PARAM_ALPHA);
$url = new moodle_url('/mod/attforblock/report.php');
if ($id) {
if (! $cm = $DB->get_record('course_modules', array('id' => $id))) {
print_error('Course Module ID was incorrect');
}
if (! $course = $DB->get_record('course', array('id' => $cm->course))) {
print_error('Course is misconfigured');
}
if (! $attforblock = $DB->get_record('attforblock', array('id' => $cm->instance))) {
print_error("Course module is incorrect");
}
}
$url->param($id);
$url->param($view);
$url->param($group);
$url->param($current);
$url->param($sort);
$PAGE->set_url($url);
require_login($course->id);
if (! $user = $DB->get_record('user', array('id' => $USER->id)) ) {
print_error("No such user in this course");
}
if (!$context = get_context_instance(CONTEXT_MODULE, $cm->id)) {
print_error('badcontext');
}
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);
$navlinks[] = array('name' => $attforblock->name, 'link' => "view.php?id=$id", 'type' => 'activity');
$navlinks[] = array('name' => get_string('report', 'attforblock'), 'link' => null, 'type' => 'activityinstance');
$sort = $sort == 'firstname' ? 'firstname' : 'lastname';
if(!$DB->count_records('attendance_sessions', array('courseid' => $course->id))) { // no session exists for this course
redirect("sessions.php?id=$cm->id&action=add");
} else { // display attendance report
print_header("$course->shortname: ".$attforblock->name.' - ' .get_string('report','attforblock'), $course->fullname,
$navlinks, "", "", true, " ", navmenu($course));
show_tabs($cm, $context, 'report');
/// find out current groups mode
$groupmode = groups_get_activity_groupmode($cm);
$currentgroup = groups_get_activity_group($cm, true);
if ($groupmode == VISIBLEGROUPS ||
($groupmode && has_capability('moodle/site:accessallgroups', $context))) {
groups_print_activity_menu($cm, $CFG->wwwroot."/mod/attforblock/report.php?id=$id&sort=$sort");
}
echo '<div align="right">';
echo $OUTPUT->help_icon('report', 'attforblock', get_string('help'));
echo '</div>';
$manager = new course_enrolment_manager($course);
if ($currentgroup) {
/*
$sql = "SELECT u.*
FROM {role_assignments} ra, {user} u, {course} c, {context} cxt
WHERE ra.userid = u.id
AND ra.contextid = cxt.id
AND cxt.contextlevel = 50
AND cxt.instanceid = c.id
AND c.id = ?
AND roleid =5
AND u.id IN (SELECT userid FROM {groups_members} gm WHERE gm.groupid = ?)
ORDER BY u.$sort ASC";
$params = array($cm->course, $currentgroup);
$students = $DB->get_records_sql($sql, $params);
*/
$students = $manager->get_users('lastname'); // FIXME add $currentgroup somehow
} else {
$students = $manager->get_users('lastname');
}
// display date interval selector
$rec = $DB->get_record_sql("SELECT MIN(sessdate) AS min, MAX(sessdate) AS max
FROM {attendance_sessions}
WHERE courseid=? AND sessdate >= ?", array($course->id, $course->startdate));
$firstdate = $rec->min;
$lastdate = $rec->max;
$now = time();
$current = $current == 0 ? $now : $current;
list(,,,$wday, $syear, $smonth, $sday) = array_values(usergetdate($firstdate));
$wday = $wday == 0 ? 7 : $wday; //////////////////////////////////////////////////// Нужна проверка настройки календаря
$startdate = make_timestamp($syear, $smonth, $sday-$wday+1); //GMT timestamp but for local midnight of monday
$options['all'] = get_string('alltaken','attforblock');
$options['weeks'] = get_string('weeks','attforblock');
$options['months'] = get_string('months','attforblock');
echo '<center>';
echo $OUTPUT->help_icon('display', 'attforblock', get_string('display','attforblock'));
echo ': ';
if (isset($_GET['view'])) {
set_current_view($course->id, $_GET['view']);
}
$view = get_current_view($course->id);
$popupurl = 'report.php?id='.$id.'&sort='.$sort;
echo $OUTPUT->single_select(new moodle_url($popupurl), 'view', $options, null, null, 'viewmenu');
$out = '';
$list = array();
if ($view === 'weeks') {
$format = get_string('str_ftimedm', 'attforblock');
for ($i = 0, $monday = $startdate; $monday <= $lastdate; $i++, $monday += ONE_WEEK) {
if ($DB->count_records_select('attendance_sessions', "courseid=? AND sessdate >= ? AND sessdate < ?", array($course->id, $monday, ($monday + ONE_WEEK)))) {
$list[] = $monday;
}
}
} elseif ($view === 'months') {
$startdate = make_timestamp($syear, $smonth, 1);
$format = '%B';
for ($i = 0, $month = $startdate; $month <= $lastdate; $i++, $month = make_timestamp($syear, $smonth+$i, 1)) {
if ($DB->count_records_select('attendance_sessions', "courseid=? AND sessdate >= ? AND sessdate < ?", array($course->id, $month, make_timestamp($syear, $smonth+$i+1, 1)))) {
$list[] = $month;
}
}
}
$found = false;
for ($i = count($list)-1; $i >= 0; $i--) {
if ($list[$i] <= $current && !$found) {
$found = true;
$current = $list[$i];
$out = '<b>'.userdate($list[$i], $format).'</b> / '.$out;
} else {
$out = "\n<a href=\"report.php?id=$id&current={$list[$i]}&sort=$sort\">".userdate($list[$i], $format)."</a> / ".$out;
}
}
echo substr($out, 0, -2)."</center>\n";
$statuses = get_statuses($course->id);
$allstatuses = get_statuses($course->id, false);
if ($view === 'weeks') {
$where = "courseid=? AND sessdate >= ? AND sessdate >= ? AND sessdate < ?";
$params = array($course->id, $course->startdate, $current, ($current + ONE_WEEK));
} elseif ($view === 'months') {
$sdate = array_values(usergetdate($current));
$where = "courseid=? AND sessdate >= ? AND sessdate >= ? AND sessdate < ?";
$params = array($course->id, $course->startdate, $current, make_timestamp($sdate[6], $sdate[5]+1, 1));
} else {
$where = "courseid=? AND sessdate >= ? AND sessdate <= ?";
$params = array($course->id, $course->startdate, time());
}
if ($students && ($course_sess = $DB->get_records_select('attendance_sessions', $where, $params, '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 = new html_table();
$table->head[] = '';
$table->align[] = '';
$table->size[] = '1px';
$table->head[] = $fullnamehead;
$table->align[] = 'left';
$table->size[] = '';
$allowtake = has_capability('mod/attforblock:takeattendances', $context);
$allowchange = has_capability('mod/attforblock:changeattendances', $context);
foreach($course_sess as $sessdata) {
if ($DB->count_records('attendance_log', array('sessionid' => $sessdata->id))) {
if ($allowchange) {
$table->head[] = "<a href=\"attendances.php?id=$id&sessionid={$sessdata->id}\">".
userdate($sessdata->sessdate, get_string('str_ftimedm', 'attforblock').'<br />('.get_string('str_ftimehm', 'attforblock').')').
'</a>';
} else {
$table->head[] = userdate($sessdata->sessdate, get_string('str_ftimedm', 'attforblock').'<br />('.get_string('str_ftimehm', 'attforblock').')');
}
} else {
if ($allowtake) {
$table->head[] = "<a href=\"attendances.php?id=$id&sessionid={$sessdata->id}\">".
userdate($sessdata->sessdate, get_string('str_ftimedm', 'attforblock').'<br />('.get_string('str_ftimehm', 'attforblock').')').
'</a>';
} else {
$table->head[] = userdate($sessdata->sessdate, get_string('str_ftimedm', 'attforblock').'<br />('.get_string('str_ftimehm', 'attforblock').')');
}
}
$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;
}
$table->head[] = get_string('grade');//.' / '.$maxgrade;
$table->align[] = 'right';
$table->size[] = '1px';
$table->head[] = '%';
foreach($students as $student) {
$table->data[$student->id][] = $OUTPUT->user_picture($student, array($course->id));
$table->data[$student->id][] = "<a href=\"view.php?id=$id&student={$student->id}\">".fullname($student).'</a>';
foreach($course_sess as $sessdata) {
if ($att = $DB->get_record('attendance_log', array('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 {
$table->data[$student->id][] = '-';
}
}
foreach($statuses as $st) {
$table->data[$student->id][] = get_attendance($student->id, $course, $st->id);
}
$table->data[$student->id][] = get_grade($student->id, $course).' / '.get_maxgrade($student->id, $course);
$table->data[$student->id][] = get_percent($student->id, $course).'%';
}
echo '<br />';
echo html_writer::table($table);
} else {
echo $OUTPUT->heading(get_string('nothingtodisplay'));
}
echo get_string('status','attforblock').':<br />';
foreach($statuses as $st) {
echo $st->acronym.' - '.$st->description.'<br />';
}
}
echo $OUTPUT->footer($course);
?>