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