Exemplo n.º 1
0
 /**
  * 添加 考场 监考人员
  */
 public function insert()
 {
     if (!$this->check_power('exam_manage')) {
         return;
     }
     $place_id = (int) $this->input->post('place_id');
     if ($place_id) {
         $query = $this->db->select('p.*')->from('exam_place p')->join('exam e', 'p.exam_pid=e.exam_id')->join('school sch', 'p.school_id=sch.school_id')->where(array('p.place_id' => $place_id))->get();
         $place = $query->row_array();
     }
     if (empty($place)) {
         message('考场信息不存在', 'admin/exam/index');
         return;
     }
     $ids = $this->input->post('id');
     if (empty($ids) or !is_array($ids)) {
         message('请至少选择一项');
         return;
     }
     //控制考场只能在未开始考试操作
     $no_start = ExamPlaceModel::place_is_no_start($place_id);
     if (!$no_start) {
         message('该考场正在考试或已结束,无法做此操作');
     }
     $ids = my_intval($ids);
     $inserts = array();
     //获取未被分配考场的监考人员
     /*
      *  同一个监考人员不能同时出现在 相同时段的考场中
      */
     $place['start_time'] = $place['start_time'] + 1;
     $place['end_time'] = $place['end_time'] - 1;
     $sql = "SELECT i.invigilator_id FROM {pre}invigilator i \n                WHERE i.invigilator_flag=1 AND i.invigilator_id IN(" . my_implode($ids) . ")\n                AND NOT EXISTS(SELECT ps.invigilator_id FROM {pre}exam_place_invigilator ps,{pre}exam_place p WHERE ps.place_id=p.place_id AND ps.invigilator_id=i.invigilator_id and ((p.start_time >= {$place['start_time']} and p.start_time <= {$place['end_time']}) OR (p.end_time >= {$place['start_time']} and p.end_time <= {$place['end_time']}) OR (p.start_time <= {$place['start_time']} and p.end_time >= {$place['end_time']})))";
     //已经分配有考场的监考人员列表
     $failed_ids = array();
     $success_ids = array();
     $result = $this->db->query($sql)->result_array();
     foreach ($result as $row) {
         $inserts[] = array('place_id' => $place_id, 'invigilator_id' => $row['invigilator_id']);
         $success_ids[] = $row['invigilator_id'];
     }
     $failed_ids = array_diff($ids, $success_ids);
     $res = 0;
     if ($inserts) {
         // 关闭错误信息,防止 unique index 冲突出错
         $this->db->db_debug = false;
         $this->db->insert_batch('exam_place_invigilator', $inserts);
         $res = $this->db->affected_rows();
     }
     $back_url = 'admin/place_invigilator/index/' . $place_id;
     if ($res < 1) {
         message('监考人员添加失败', $back_url);
     } else {
         $failed_i_names = array();
         foreach ($failed_ids as $id) {
             $i_name = ExamInvigilatorModel::get_invigilator_by_id($id, 'name');
             if ($i_name) {
                 $failed_i_names[] = $i_name;
             }
         }
         $msg = array('监考人员添加成功');
         if (count($failed_i_names)) {
             $msg[] = '<hr/>以下监考人员已经分配了考场:<br/>' . implode('<br/>', $failed_i_names);
         }
         message(implode('', $msg), $back_url);
     }
 }
Exemplo n.º 2
0
 /**
  * 重置密码
  *
  * @return  void
  */
 public function reset_password()
 {
     if (!$this->check_power('exam_manage')) {
         return;
     }
     $new_password = $this->input->post('new_password');
     $new_confirm_password = $this->input->post('confirm_password');
     $invigilator_id = intval($this->input->post('uid'));
     if (is_string($passwd_msg = is_password($new_password))) {
         output_json(CODE_ERROR, $passwd_msg);
     }
     if (!strlen(trim($new_confirm_password))) {
         output_json(CODE_ERROR, '确认密码不能为空.');
     }
     if ($new_confirm_password != $new_password) {
         output_json(CODE_ERROR, '两次密码输入不一致.');
     }
     //检查旧密码是否正确
     $invigilater_passwd = ExamInvigilatorModel::get_invigilator_by_id($invigilator_id, 'invigilator_password');
     if (!count($invigilater_passwd)) {
         output_json(CODE_ERROR, '不存在该监考人员.');
     }
     //检查帐号密码是否正确
     $flag = ExamInvigilatorModel::reset_invigilator_password($invigilator_id, my_md5($new_password));
     if (!$flag) {
         output_json(CODE_ERROR, '密码修改失败,请重试');
     }
     output_json(CODE_SUCCESS, '密码修改成功.');
 }