id; // return if (!empty($submit) && $submit==get_string('return', 'block_autoattend')) { if ($fromform=='updateUser') redirect('index.php?course='.$courseid.'&student='.$userid); redirect('index.php?course='.$courseid); } if (empty($attsid) && $fromform=='updateAttendance') { redirect('index.php?course='.$courseid, get_string('missinfo', 'block_autoattend'), 3); } if (empty($userid) && $fromform=='updateUser') { redirect('index.php?course='.$courseid, get_string('missinfo', 'block_autoattend'), 3); } // if (! $course = get_record('course', 'id', $courseid)) { error(get_string('courseidwrong','block_autoattend')); } require_login($course->id); if (!isteacher($course->id)) { error(get_string('notaccessstudent','block_autoattend')); } if (empty($userid)) $userid = $USER->id; if (! $user = get_record('user', 'id', $userid) ) { error(get_string('nosuchuser','block_autoattend')); } $attids = array(); // stores ids $status = array(); // stores status $prvstatus = array(); // stores previus status $remarks = array(); // stores remarks if any foreach($_POST as $key => $value) { if (substr($key,0,8) == 'statusid') { $aid = substr($key, 8, strlen($key)-8); $attsids[] = $aid; // radioボタンを選択していない場合は備考は無効 $status[$aid] = $value; } if (substr($key,0,9) == 'prvstatus') { $aid = substr($key, 9, strlen($key)-9); $prvstatus[$aid] = $value; } if (substr($key,0,7) == 'remarks') { $aid = substr($key, 7, strlen($key)-7); $remarks[$aid] = $value; } } // 学生データの書き込み foreach($attsids as $att) { if ($fromform=='updateUser') { //$userid = $userid; $attsid = $att; } else { $userid = $att; //$attsid = $attsid } $calledtime = time(); $std = get_record('autoattend_students', 'attsid', $attsid, 'studentid', $userid); $result = ""; $called = ""; if ($std) { if ($status[$att]!=$prvstatus[$att]) { $called = 'M'; $rec->status = $status[$att]; $rec->called = $called; $rec->calledby = $teacher; $rec->calledtime = $calledtime; } $rec->id = $std->id; $rec->attsid = $attsid; $rec->studentid = $userid; $rec->remarks = $remarks[$att]; $result = update_record('autoattend_students', $rec); unset($rec); } else { // new student record if ($status[$att]!=$prvstatus[$att]) $called = 'M'; else $called = 'D'; $rec->attsid = $attsid; $rec->studentid = $userid; $rec->status = $status[$att]; $rec->called = $called; $rec->calledby = $teacher; $rec->calledtime = $calledtime; $rec->remarks = $remarks[$att]; $result = insert_record('autoattend_students', $rec); unset($rec); } if ($result and $called=='M') { $loginfo = MANUAL_SUBMIT_LOG."=$attsid,$userid,{$prvstatus[$att]},{$status[$att]}"; add_to_log($course->id, 'autoattend', 'submit manualattend', 'index.php?course='.$course->id, $loginfo); } } // 出席表の書き込み global $TIME_OFFSET; $sess = get_record('autoattend_sessions', 'id', $attsid); if ($sess->timetaken==0) $rec->timetaken = time(); else $rec->timemodified = time(); $prvstate = $sess->state; if ($prvstate!='C') { // 一度完了したものは変更しない $etime = $sess->sessdate + $sess->endtime - $TIME_OFFSET; $ntime = time(); if ($etime<=$ntime) $state = 'C'; else $state = 'O'; } else { $state = 'C'; } $rec->state = $state; $rec->id = $attsid; $rec->takenby = $teacher; $result = update_record('autoattend_sessions', $rec); if ($result) { $dsptm = 1; $mssg = get_string('attendsuccess', 'block_autoattend'); $loginfo = "=$attsid,$prvstate,$state"; add_to_log($course->id, 'autoattend', 'submit sessions', 'index.php?course='.$course->id, $loginfo); } else { $dsptm = 5; $mssg = get_string('attenderror', 'block_autoattend'); } redirect($fromform.'.php?course='.$course->id.'&attsid='.$attsid.'&userid='.$userid, $mssg, $dsptm); ?>