/
class_division.php
290 lines (239 loc) · 8.5 KB
/
class_division.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
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
<?php
require_once('../../config.php');
require_once($CFG->libdir.'/blocklib.php');
require_once(dirname(__FILE__).'/locallib.php');
//
define('PAGE_ROW_SIZE', $CFG->page_row_size);
$courseid = required_param('course', PARAM_INTEGER); // Course id
$classid = optional_param('class', 0, PARAM_INTEGER);
$sort = optional_param('sort', 'firstname', PARAM_ALPHA);
$order = optional_param('order', 'ASC', PARAM_ALPHA);
$newclassid = 0;
$newclassids = optional_param_array('newclass', array(), PARAM_INTEGER);
if (($formdata = data_submitted()) and !confirm_sesskey()) {
print_error('invalidsesskey');
}
//
$wwwBlock = $CFG->wwwroot.'/blocks/autoattend';
$wwwMyURL = $wwwBlock.'/class_division.php';
$wwwParams = jbxl_get_url_params_array($_SERVER["REQUEST_URI"]);
if (!$sort) {
if (array_key_exists('sort', $wwwParams)) {
$sort = $wwwParams['sort'];
}
else {
if ($CFG->output_idnumber) $sort = 'idnumber';
else $sort = 'lastname';
}
}
$urlparams['course'] = $courseid;
if ($classid) $urlparams['class'] = $classid;
if ($sort) $urlparams['sort'] = $sort;
if ($order) $urlparams['order'] = $order;
$PAGE->set_url('/blocks/autoattend/class_division.php', $urlparams);
$course = $DB->get_record('course', array('id'=>$courseid));
if (!$course) {
print_error('courseidwrong', 'block_autoattend');
}
require_login($course->id);
$context = jbxl_get_course_context($course->id);
$isassist = false;
$isteacher = jbxl_is_teacher($USER->id, $context);
if (!$isteacher) {
$isassist = jbxl_is_assistant($USER->id, $context);
if (!$isassist) {
print_error('notaccessstudent', 'block_autoattend');
}
}
$user = $DB->get_record('user', array('id'=>$USER->id));
if (!$user) {
print_error('nosuchuser', 'block_autoattend');
}
//////////////////////////////////////////////////////////////////////////////////////////
//
function class_division_make_header(&$table, $url_options, $start, $end, $name_pattern, $order)
{
global $CFG, $wwwMyURL;
$firstname = '<a href="'.$wwwMyURL.$url_options.'&sort=firstname&order='.$order.'">'.get_string('firstname').'</a>';
$lastname = '<a href="'.$wwwMyURL.$url_options.'&sort=lastname&order='.$order.'">' .get_string('lastname').'</a>';
$fullnamehead = jbxl_get_fullnamehead($name_pattern, $firstname, $lastname, '/');
//
unset($table->head);
unset($table->align);
unset($table->size);
unset($table->wrap);
$table->head [] = '#';
$table->align[] = 'center';
$table->size [] = '20px';
$table->head [] = '';
$table->align[] = '';
$table->size [] = '20px';
$table->head [] = $fullnamehead;
$table->align[] = 'left';
$table->size [] = '140px';
$table->wrap [2]= 'nowrap';
$cellnum = 4;
if ($CFG->output_idnumber) {
$table->head [] = '<a href="'.$wwwMyURL.$url_options.'&sort=idnumber&order='.$order.'">ID</a>';
$table->align[] = 'center';
$table->size [] = '60px';
$table->wrap [] = 'nowrap';
$cellnum++;
}
$table->head [] = get_string('classname', 'block_autoattend');
$table->align[] = 'center';
$table->size [] = '80px';
$table->wrap [] = 'nowrap';
$table->head [] = "<a href=\"javascript:select_all_check_in('TD','cell c".$cellnum." lastcol',null,$start,$end);\">".get_string('changeclass','block_autoattend')."</a>";
$table->align[] = 'center';
$table->size [] = '80px';
$table->wrap [] = 'nowrap';
return;
}
function class_division_show_table($students, $courseid, $classid, $name_pattern, $order, $classes, $newclassid)
{
global $CFG, $wwwBlock, $OUTPUT;
$url_options = '?course='.$courseid.'&class='.$classid;
//
if (empty($order) or $order=='ASC') {
$order = 'DESC';
}
else $order = 'ASC';
//
$table = new html_table();
$i = 0;
$n = 0;
foreach($students as $student) {
$classinfo = autoattend_get_user_class($student->id, $courseid);
if ($classinfo->classid==$classid or $classid==0 or ($classid==NON_CLASSID and $classinfo->classid==0)
or ($classid==VALID_CLASSID and $classinfo->classid>=0)) {
$i++;
$table->data[$student->id][] = $i;
$username = jbxl_get_user_name($student->id, $name_pattern);
$pic_options = array('size'=>20, 'link'=>true, 'alttext'=>true, 'courseid'=>$courseid, 'popup'=>true);
$table->data[$student->id][] = $OUTPUT->user_picture($student, $pic_options);
$table->data[$student->id][] = '<a href="'.$wwwBlock.'/index.php?course='.$courseid.'&student='.$student->id.'" target="_blank">'.$username.'</a>';
if ($CFG->output_idnumber) {
if (empty($student->idnumber)) $idnum = ' - ';
else $idnum = $student->idnumber;
$table->data[$student->id][] = $idnum;
}
$table->data[$student->id][] = $classinfo->name;
$table->data[$student->id][] = '<input type="checkbox" name="changeclass'.$student->id.'" value="1" />';
//
if ($i%PAGE_ROW_SIZE==0) {
echo '<div align="center">';
class_division_make_header($table, $url_options, $i-PAGE_ROW_SIZE, $i, $name_pattern, $order);
echo html_writer::table($table);
class_division_submit_button($classes, $newclassid, $n);
$n++;
echo '</div><br />';
//echo '</div>';
unset($table->data);
}
}
}
if ($i%PAGE_ROW_SIZE!=0 or $i==0) {
echo '<div align="center">';
class_division_make_header($table, $url_options, $i-$i%PAGE_ROW_SIZE, $i, $name_pattern, $order);
echo html_writer::table($table);
class_division_submit_button($classes, $newclassid, $n);
echo '</div>';
}
return;
}
function class_division_submit_button($classes, $newclassid, $n)
{
echo '<select name="newclass['.$n.']">';
{
if ($newclassid==0) $selected = 'selected="selected"';
else $selected = '';
echo '<option value="0" '.$selected.'>'.get_string('nonclass','block_autoattend').'</option >';
foreach ($classes as $class) {
if ($newclassid==$class->id) $selected = 'selected="selected"';
else $selected = '';
echo '<option value="'.$class->id.'" '.$selected.'>'.$class->name.'</option>';
}
echo '<option value="-1" >'.get_string('exclusion','block_autoattend').'</option>';
}
echo '</select> ';
echo '<input type="submit" name="change_class['.$n.']" value="'.get_string('changeclass','block_autoattend').'" />';
}
//////////////////////////////////////////////////////////////////////////////////////////
// Print Header
$title = $course->shortname.': '.get_string('autoattend','block_autoattend');
if ($course->category) {
//$title.= ' '.get_string('class_division','block_autoattend');
$title.= ' '.get_string('students_list','block_autoattend');
}
$PAGE->set_title($title);
$PAGE->set_heading($course->fullname);
$PAGE->set_cacheable(true);
$PAGE->set_button(' ');
//$PAGE->set_headingmenu();
echo $OUTPUT->header();
echo "<script type=\"text/javascript\">
<!--
function select_all_check_in(elTagName, elClass, elId, start, end) {
var inputs = document.getElementsByTagName('INPUT');
inputs = filterByParent(inputs, function(el) {return findParentNode(el, elTagName, elClass, elId);});
for(var i=start; i<end; i++) {
if(inputs[i].type=='checkbox') {
inputs[i].checked = !inputs[i].checked;
}
}
}
//-->
</script>";
//
$currenttab = 'class_division';
include('tabs.php');
//
//$sort = ($sort=='firstname' ? 'firstname' : 'lastname');
if ($sort!='firstname' and $sort!='idnumber') $sort = 'lastname';
$sort .= ' '.$order;
$students = jbxl_get_course_students($context, $sort);
// Display Attendance Table
if ($students) {
//
if (isset($formdata->change_class) and is_array($formdata->change_class)) {
//
foreach ($formdata->change_class as $key=>$value) {
$newclassid = $newclassids[$key];
//
$cnt = 0;
foreach($_POST as $key=>$value) {
if (substr($key, 0, 11)=='changeclass') {
$studentid = substr($key, 11, strlen($key)-11);
if (is_numeric($studentid)) {
$class = autoattend_get_user_class($studentid, $course->id);
if ($class->classid!=$newclassid) {
$class->classid = $newclassid;
if ($class->id!=0) {
$DB->update_record('autoattend_classifies', $class);
}
else {
$class->id = $DB->insert_record('autoattend_classifies', $class);
}
$cnt++;
}
}
}
}
break; // only use first element
}
if ($cnt>0) {
autoattend_update_grades($course->id);
}
}
//
$name_pattern = autoattend_get_namepattern($course->id);
$classes = autoattend_get_session_classes($course->id);
$url_options = '?course='.$courseid.'&sort='.$sort;
include('html/class_division.html');
}
//
else {
echo $OUTPUT->heading(get_string('nothingtodisplay'));
}
echo $OUTPUT->footer($course);