Esempio n. 1
0
 /**
  * 考生日志记录
  */
 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;
             }
         }
         //$sql="select sleep(10)";
         //$this->db->query($sql);
         exam_log($log_type, $log_content);
         die;
     }
 }
Esempio n. 2
0
 /**
  * 考生提交考试
  */
 public function submit()
 {
     // 获取提交问题
     // json格式
     /*
      *
      * post_data格式:
      * array(
      * 'uid'
      * =>
      * '考生ID',
      * 'place_id'
      * =>
      * '考试ID',
      * 'paper_data'=>
      * array(
      * array(
      * 'paper_id'
      * =>
      * '试卷ID',
      * 'etp_id'
      * =>
      * '当前考试记录ID',
      * 'question'
      * =>
      * array(
      * array(
      * 'etr_id'
      * =>
      * '问题结果ID',
      * 'answer'
      * =>
      * '答案',
      * )
      * )
      * ),
      * ...
      * )
      * )
      */
     $post_data = $this->input->post('post_data');
     $post_data = (array) @json_decode($post_data);
     if (!is_array($post_data) || !count($post_data)) {
         output_json(CODE_ERROR, '参数非法');
     }
     // 检查学生的合法性
     $exam_uid = $this->session->userdata('exam_uid');
     $post_uid = isset($post_data['uid']) ? intval($post_data['uid']) : 0;
     if (!$exam_uid || !$post_uid || $exam_uid != $post_uid) {
         output_json(CODE_ERROR, '您不是合法的考生');
     }
     // 检查
     // 当前考试是否合法
     $post_place_id = isset($post_data['place_id']) ? intval($post_data['place_id']) : 0;
     $current_exam = $this->exam_model->get_cookie_current_exam(true);
     if (!$post_place_id || $current_exam['place_id'] != $post_place_id) {
         output_json(CODE_ERROR, '不存在当前考试');
     }
     // 检查试卷是否合法
     $post_paper_data = isset($post_data['paper_data']) ? $post_data['paper_data'] : array();
     if (!count($post_paper_data)) {
         output_json(CODE_ERROR, '非法试题参数');
     }
     $this->load->model('exam/exam_test_paper_model');
     $this->load->model('exam/exam_test_result_model');
     $test_paper_model = $this->exam_test_paper_model;
     // 批量更新
     // 考试结果
     $etp_ids = array_filter(array_values(explode(',', $this->session->userdata('etp_id'))));
     $update_data = array();
     foreach ($post_paper_data as $paper_data) {
         $paper_data = (array) $paper_data;
         if (!isset($paper_data['paper_id']) || !isset($paper_data['etp_id']) || !isset($paper_data['question'])) {
             output_json(CODE_ERROR, '非法试题参数');
         }
         // 检查是否存在当前考试记录
         $current_etp_uid = $test_paper_model->get_test_paper_by_id($paper_data['etp_id'], 'uid');
         if ($current_etp_uid != $post_uid) {
             output_json(CODE_ERROR, '非法考试记录');
         }
         $paper_id = $paper_data['paper_id'];
         $etp_id = $paper_data['etp_id'];
         $questions = $paper_data['question'];
         foreach ($questions as $q) {
             $q = (array) $q;
             $etr_id = intval($q['etr_id']);
             if (!$etr_id) {
                 unset($update_data);
                 // output_json(CODE_ERROR,
                 // '非法试题参数');
                 continue;
             }
             $update_data[] = array('etr_id' => $etr_id, 'answer' => $q['answer']);
         }
         // $etp_ids
         // []
         // =
         // $etp_id;
     }
     if (count($update_data)) {
         if (!$this->exam_test_result_model->update_batch($update_data, 'id')) {
             output_json(CODE_ERROR, '交卷失败,请联系监考老师');
         }
     }
     /*
      *
      * todo
      * 将该学生该场考试状态标记为
      * 已考
      * 清除考生会话信息
      */
     // 查看该考生是否已经作弊
     $is_cheat = isset($post_data['is_c']) ? intval($post_data['is_c']) : 0;
     if ($is_cheat > 0) {
         $test_paper_model->update_student_test_status($etp_ids, '-1');
         $this->session->set_userdata(array('has_cheated' => '1'));
         // 作弊日志
         exam_log(EXAM_LOG_CHEAT, array('ip' => $this->input->ip_address()));
     } else {
         $test_paper_model->update_student_test_status($etp_ids);
         // 交卷日志
         exam_log(EXAM_LOG_SUBMIT, array('time' => date('Y-m-d H:i:s')));
     }
     $this->load->model('exam/student_model');
     $this->student_model->destory_exam_student_session();
     // 设置考生交卷标志
     $this->exam_model->set_test_submit_session();
     // session_destroy();
     output_json(CODE_SUCCESS, '交卷成功');
 }
Esempio n. 3
0
 /**
  * 检查考试状态
  * 1、是否已结束
  * 2、是否学生已交卷
  */
 function check_exam_status()
 {
     $segment_controller = $this->uri->rsegment(1);
     $segment_action = $this->uri->rsegment(2);
     //如果考生已经交卷,转到成功,提交成功等待页
     if ($this->is_valid_test_submit_session() && ($segment_controller != 'test' && $segment_action != 'success')) {
         $this->_redirect_test_success();
     }
     //必须先选择考场
     $current_exam = $this->get_cookie_current_exam();
     if (!$current_exam && ($segment_controller != 'index' && $segment_action != 'index')) {
         redirect('exam/index/index');
     }
     if (!$current_exam && !($uid = $this->session->userdata('exam_uid'))) {
         return false;
     }
     //检查本场考试是否已经结束(本场考试结束时间 + 缓冲时间)
     $finish_time = strtotime($current_exam['finish_time']);
     if (!$finish_time || $finish_time < time()) {
         //清除所有关联会话
         $this->destory_exam_session();
         message('抱歉,本场考试已经结束.', 'exam/index/index');
     }
     //检查本场考试是否已经结束(本场考试结束时间)
     $end_at = strtotime($current_exam['end_time']);
     if ($end_at < time() && ($segment_controller != 'index' && $segment_action != 'login')) {
         //预留 30秒钟交卷
         if (time() <= $end_at + 30 && ($segment_controller == 'test' && $segment_action == 'submit')) {
             return false;
         }
         //清除考生会话信息
         $this->load->model('exam/student_model');
         $this->student_model->destory_exam_student_session();
         message('抱歉,本场考试已经结束.', 'exam/index/login');
     }
     //检查该考生是否已经交卷
     $this->load->model('exam/exam_test_paper_model');
     $uid = $this->session->userdata('exam_uid');
     if ($uid > 0) {
         $student_place_status = $this->exam_test_paper_model->get_student_place_status($current_exam['place_id'], $uid);
         if ($student_place_status['flag'] !== false && $student_place_status['flag'] != 0 && ($segment_controller != 'index' && $segment_action != 'login')) {
             //踢出行为
             if ($student_place_status['flag'] == 1) {
                 message("抱歉,您在该场考试中有" . $student_place_status['why'] . "行为被踢出,本次考试无效.", 'exam/index/login');
             }
         }
         $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('exam/student_model');
             $this->student_model->destory_exam_student_session();
             //作弊行为
             if ($student_test_status < 0) {
                 message('抱歉,您在该场考试中有作弊行为,本次考试无效.', 'exam/index/login');
             } else {
                 message('抱歉,您已经交卷了.', 'exam/index/login');
             }
         } else {
             //判断该考生是否有离开考试界面嫌疑
             if ($uid) {
                 $this->load->model('exam/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(log_id) 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) {
                         exam_log($log_type);
                     }
                 }
             }
         }
     }
 }
Esempio n. 4
0
 /**
  * 学生登录检查
  */
 public function check_login()
 {
     // 获取当前
     $current_exam = $this->exam_model->get_cookie_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('exam/student_model');
     $student = $this->student_model->is_valid_student($exam_ticket, $password);
     if (!$student) {
         output_json(CODE_ERROR, '登陆帐号或密码不正确,请检查.');
     }
     // 检查学生是否在当前考场中
     $this->load->model('exam/exam_place_model');
     $exam_place_model = $this->exam_place_model;
     $place_id = $current_exam['place_id'];
     $user_id = $student['uid'];
     if (!$exam_place_model->check_exam_place_student($place_id, $user_id)) {
         output_json(CODE_ERROR, '很抱歉,您不在本场考试中,有问题请联系监考老师.');
     }
     // 设置考生考卷信息
     $place_id = $current_exam['place_id'];
     $uid = $student['uid'];
     $this->load->model('exam/exam_test_paper_model');
     $this->load->model('exam/exam_place_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);
     $place_subjects = $this->exam_place_model->get_exam_place_subject($place_id);
     if (count($test_papers) != count($place_subjects)) {
         $insert_ids = $test_paper_model->set_student_test_paper($place_id, $uid);
         // 设置考试记录
         if ($insert_ids === false) {
             message('抱歉,该场考试有科目未分配试卷.', 'exam/index/login');
         }
         if (count($insert_ids)) {
             $this->session->set_userdata(array('etp_id' => implode(',', $insert_ids)));
         }
     } else {
         $insert_ids1 = array();
         foreach ($test_papers as $item) {
             $etp_flag = $item['etp_flag'];
             if ($etp_flag < 0) {
                 message('抱歉,您在该场考试中有作弊行为,本次考试无效.', 'exam/index/login');
             } elseif ($etp_flag > 0) {
                 message('抱歉,您已经交卷了.', 'exam/index/login');
             }
             $insert_ids1[] = $item['etp_id'];
         }
         $this->session->set_userdata(array('etp_id' => implode(',', $insert_ids1)));
     }
     // 添加考场在考人员统计
     // 检查考生是否已经登录过
     $this->load->model('exam/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['exam_uid'] = $student['uid'];
     // 补齐当前考生的 学校 & 年级信息
     $this->load->model('exam/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('exam/student_log_stat_model', 'log_stat_model');
     // 如果考试未开始,将考生的活跃时间清零, 如果考生已经在某个当前考场中,移除
     if (strtotime($current_exam['start_time']) >= time()) {
         $this->log_stat_model->remove_student_last_active_time($current_exam['exam_id'], $current_exam['place_id'], $uid);
         $this->log_stat_model->remove_exam_place_member($current_exam['exam_id'], $current_exam['place_id'], $uid);
     }
     if ($this->log_stat_model->has_beyond_active_time($current_exam['exam_id'], $current_exam['place_id'], $uid)) {
         // 机考日志
         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 {
         // 机考日志
         exam_log(EXAM_LOG_LOGIN, array('ip' => $this->input->ip_address()));
     }
     output_json(CODE_SUCCESS);
 }