/** * 添加考场在考人员统计 * @return mixed */ public function set_exam_place_member($exam_id = 0, $place_id = 0, $uid = 0) { $exam_id = intval($exam_id); $place_id = intval($place_id); $uid = intval($uid); if ($uid <= 0) { return false; } /** * source: redis * key: exam:place:student:testting-exam_id:place_id * type: sets * value : uid */ $redis = $this->redis_model; $key = $this->pre . "exam:place:student:testting-{$exam_id}:{$place_id}"; $val = $uid; if ($redis->sismember($key, $uid)) { //添加日志 demo_exam_log(EXAM_LOG_RELOGIN_IN_TESTTING, null, $uid); // throw new Exception('抱歉,该考生已经在考试中.'); } else { $redis->sadd($key, $uid); } return true; }
/** * 考生日志记录 */ public function push() { $action = $this->input->post('act'); $data = $this->input->post('data'); if ($action && ($log_type = Log_type_desc::get_log_alia($action))) { $log_content = array('time' => date('Y-m-d H:i:s')); $data = (array) json_decode($data); if (is_array($data) && count($data)) { switch ($log_type) { case EXAM_LOG_WINDOW_BLUR: if (isset($data['count'])) { $log_content = '离开考试界面 ' . $data['count'] . ' 次'; } break; case EXAM_LOG_WINDOW_BLUR_LONG_TIME: if (isset($data['time'])) { $min = ceil($data['time'] / 60); if ($min >= 2) { $log_content = '离开考试界面 2 分钟以上'; } else { $log_content = '离开考试界面 ' . $min . ' 分钟'; } } break; } } demo_exam_log($log_type, $log_content); die; } }
/** * 检查考试状态 * 1、是否已结束 * 2、是否学生已交卷 */ function check_exam_status($subject_id) { $segment_controller = $this->uri->rsegment(1); $segment_action = $this->uri->rsegment(2); //如果考生已经交卷,转到成功,提交成功等待页 $report_mark = $this->session->userdata('report_mark'); if ($report_mark != '' && ($segment_controller != 'test' && $segment_action != 'report')) { redirect('demo/test/report?act=doing'); } $current_exam = $this->get_session_current_exam(); if (!isset($current_exam['exam_pid'])) { redirect('demo/index/login?subject_id=' . $subject_id); } //检查该考生是否已经交卷 $this->load->model('demo/exam_test_paper_model'); $uid = $this->session->userdata('demo_exam_uid'); $student_test_status = $this->exam_test_paper_model->get_student_test_status($current_exam['place_id'], $uid); if ($student_test_status !== false && $student_test_status != 0 && ($segment_controller != 'index' && $segment_action != 'login')) { //清除考生会话信息 $this->load->model('demo/student_model'); $this->student_model->destory_exam_student_session(); //作弊行为 if ($student_test_status < 0) { message('很遗憾,您在本场考试中有作弊行为,无法继续考试.', 'demo/index/login'); } else { if ($this->session->userdata('report_mark')) { message('抱歉,您已经交卷了.', 'demo/test/report?act=get'); } else { message('抱歉,您已经交卷了.', 'demo/index/login?subject_id=' . $subject_id); } } } else { //判断该考生是否有离开考试界面嫌疑 $this->load->model('demo/student_log_stat_model', 'log_stat_model'); if ($this->log_stat_model->has_beyond_active_time($current_exam['exam_id'], $current_exam['place_id'], $uid)) { //添加考生日志,如果系统已经添加了该日志记录,则跳过 $log_type = EXAM_LOG_LEAVE_TEST_PAGE; $exam_pid = $current_exam['exam_id']; $place_id = $current_exam['place_id']; $last_active_time = $this->log_stat_model->get_student_last_active_time($current_exam['exam_id'], $current_exam['place_id'], $uid); $result = $this->db->query("select count(*) as count from {pre}exam_logs where exam_id={$exam_pid} and place_id={$place_id} and uid={$uid} and type={$log_type} and ctime>='{$last_active_time}'")->row(); if (!$result->count) { demo_exam_log($log_type); } } } }
/** * 学生登录检查 */ public function check_login() { //获取当前 $current_exam = $this->exam_model->get_session_current_exam(true); $exam_ticket = trim($this->input->post('exam_ticket')); $password = $this->input->post('password'); if (!strlen($exam_ticket)) { output_json(CODE_ERROR, '请输入正确的准考证号.'); } if (!is_email($exam_ticket) && !is_idcard($exam_ticket) && !is_numeric($exam_ticket)) { output_json(CODE_ERROR, '请输入合法的登陆帐号.'); } if (!strlen($password)) { output_json(CODE_ERROR, '密码不能为空.'); } //检查帐号密码是否正确 $this->load->model('demo/student_model'); $student = $this->student_model->is_valid_student($exam_ticket, $password); if (!$student) { output_json(CODE_ERROR, '登陆帐号或密码不正确,请检查.'); } $place_id = $current_exam['place_id']; $user_id = $student['uid']; //设置考生考卷信息 $place_id = $current_exam['place_id']; $uid = $student['uid']; $this->load->model('demo/exam_test_paper_model'); $test_paper_model = $this->exam_test_paper_model; //设定考生考卷 /** * 需要事先判断 本场考试 是否已经分配考生试卷 */ $test_papers = $test_paper_model->get_stduent_test_paper($place_id, $uid, 'etp_flag,etp_id', null); if (!count($test_papers)) { $insert_ids = $test_paper_model->set_student_test_paper($place_id, $uid); //设置考试记录 if ($insert_ids === false) { output_json(CODE_ERROR, '抱歉,该学科未分配样卷.', array(), 'demo/index/login'); } if (count($insert_ids)) { $this->session->set_userdata(array('etp_id' => implode(',', $insert_ids))); } } else { $etp_flag = $test_papers[0]['etp_flag']; if ($etp_flag < 0) { output_json(CODE_ERROR, '很遗憾,您在本场考试中有作弊行为,无法继续考试.', array(), 'demo/index/login'); } elseif ($etp_flag > 0) { //用于生成测评报告标识 $all_userdata = $this->session->all_userdata(); $report_mark = $all_userdata['exam_pid'] . '_' . $all_userdata['subject_id'] . '_' . $uid . '_' . $all_userdata['exam_id']; $this->session->set_userdata('report_mark', $report_mark); output_json(CODE_SUCCESS, '抱歉,您已经交卷了, 将为您跳转到您的测评报告.', array(), 'setTimeout(function () {window.location.href="' . site_url('demo/test/report/?act=get') . '";}, 3000);'); //message('抱歉,您已经交卷了, 将为您跳转到您的测评报告.', 'demo/test/report?act=get'); } } //添加考场在考人员统计 //检查考生是否已经登录过 $this->load->model('demo/student_log_stat_model'); try { $this->student_log_stat_model->set_exam_place_member($current_exam['exam_id'], $current_exam['place_id'], $user_id); } catch (Exception $e) { output_json(CODE_ERROR, $e->getMessage()); } //==================登录成功操作======================== //考生登录成功,将考生信息保存在session $student['demo_exam_uid'] = $student['uid']; //补齐当前考生的 学校 & 年级信息 $this->load->model('demo/school_model'); $school = $this->school_model->get_school_by_id($student['school_id']); $student['school_name'] = count($school) ? $school['school_name'] : '--'; //获取年级信息 $grade_id = $student['grade_id']; $grades = C('grades'); $student['grade_name'] = isset($grades[$grade_id]) ? $grades[$grade_id] : '--'; //设置考生的会话 $this->student_model->set_exam_student_session($student); //判断该考生是否有离开考试界面嫌疑 $this->load->model('demo/student_log_stat_model', 'log_stat_model'); if ($this->log_stat_model->has_beyond_active_time($current_exam['exam_id'], $current_exam['place_id'], $uid)) { //机考日志 demo_exam_log(EXAM_LOG_RELOGIN_AFTER_LEAVE_TEST_PAGE); $this->log_stat_model->set_exam_place_student_active_status($current_exam['exam_id'], $current_exam['place_id'], $uid); } else { //机考日志 demo_exam_log(EXAM_LOG_LOGIN, array('ip' => $this->input->ip_address())); } output_json(CODE_SUCCESS); }