|
|
@ -492,24 +492,25 @@ class mod_attendance_structure { |
|
|
|
public function take_from_form_data($formdata) { |
|
|
|
global $DB, $USER; |
|
|
|
// TODO: WARNING - $formdata is unclean - comes from direct $_POST - ideally needs a rewrite but we do some cleaning below. |
|
|
|
// This whole function could do with a nice clean up. |
|
|
|
$statuses = implode(',', array_keys( (array)$this->get_statuses() )); |
|
|
|
$now = time(); |
|
|
|
$sesslog = array(); |
|
|
|
$formdata = (array)$formdata; |
|
|
|
foreach ($formdata as $key => $value) { |
|
|
|
if (substr($key, 0, 4) == 'user') { |
|
|
|
$sid = substr($key, 4); |
|
|
|
if (!(is_numeric($sid) && is_numeric($value))) { // Sanity check on $sid and $value. |
|
|
|
// Look at Remarks field because the user options may not be passed if empty. |
|
|
|
if (substr($key, 0, 7) == 'remarks') { |
|
|
|
$sid = substr($key, 7); |
|
|
|
if (!(is_numeric($sid))) { // Sanity check on $sid. |
|
|
|
print_error('nonnumericid', 'attendance'); |
|
|
|
} |
|
|
|
$sesslog[$sid] = new stdClass(); |
|
|
|
$sesslog[$sid]->studentid = $sid; // We check is_numeric on this above. |
|
|
|
$sesslog[$sid]->statusid = $value; // We check is_numeric on this above. |
|
|
|
$sesslog[$sid]->statusset = $statuses; |
|
|
|
$sesslog[$sid]->remarks = ''; |
|
|
|
if (array_key_exists('remarks'.$sid, $formdata)) { |
|
|
|
$sesslog[$sid]->remarks = clean_param($formdata['remarks' . $sid], PARAM_TEXT); |
|
|
|
if (array_key_exists('user'.$sid, $formdata) && is_numeric($formdata['user' . $sid])) { |
|
|
|
$sesslog[$sid]->statusid = $formdata['user' . $sid]; |
|
|
|
} |
|
|
|
$sesslog[$sid]->statusset = $statuses; |
|
|
|
$sesslog[$sid]->remarks = $value; |
|
|
|
$sesslog[$sid]->sessionid = $this->pageparams->sessionid; |
|
|
|
$sesslog[$sid]->timetaken = $now; |
|
|
|
$sesslog[$sid]->takenby = $USER->id; |
|
|
@ -518,7 +519,8 @@ class mod_attendance_structure { |
|
|
|
|
|
|
|
$dbsesslog = $this->get_session_log($this->pageparams->sessionid); |
|
|
|
foreach ($sesslog as $log) { |
|
|
|
if ($log->statusid) { |
|
|
|
// Don't save a record if no statusid or remark. |
|
|
|
if (!empty($log->statusid) || !empty($log->remarks)) { |
|
|
|
if (array_key_exists($log->studentid, $dbsesslog)) { |
|
|
|
$log->id = $dbsesslog[$log->studentid]->id; |
|
|
|
$DB->update_record('attendance_log', $log); |
|
|
|