コード例 #1
0
ファイル: exam.php プロジェクト: Vincent-Shen/origin
 /**
  * 调整考试学科顺序
  *
  * @param int $id 学科id
  * @return void
  */
 public function edit_index($id = 0, $type = 'forward')
 {
     if (!$this->check_power('exam_manage')) {
         return;
     }
     $exam = ExamModel::get_exam($id, 'exam_pid,exam_index');
     if ($exam === false or $exam['exam_pid'] == 0) {
         message('考试学科不存在');
         return;
     }
     if ($exam['exam_index'] < 1) {
         ExamModel::resort_index($exam['exam_pid']);
     } else {
         if ($type == 'forward') {
             if ($exam['exam_index'] > 1) {
                 $prev_where = array('exam_pid' => $exam['exam_pid'], 'exam_index' => $exam['exam_index'] - 1);
                 $query = $this->db->select('exam_id')->get_where('exam', $prev_where, 1);
                 $prev = $query->row_array();
                 if ($prev) {
                     $this->db->update('exam', array('exam_index' => $exam['exam_index'] - 1), array('exam_id' => $id));
                     $this->db->update('exam', array('exam_index' => $exam['exam_index']), array('exam_id' => $prev['exam_id']));
                 } else {
                     ExamModel::resort_index($exam['exam_pid']);
                 }
             }
         } else {
             $next_where = array('exam_pid' => $exam['exam_pid'], 'exam_index' => $exam['exam_index'] + 1);
             $query = $this->db->select('exam_id')->get_where('exam', $next_where, 1);
             $next = $query->row_array();
             if ($next) {
                 $this->db->update('exam', array('exam_index' => $exam['exam_index'] + 1), array('exam_id' => $id));
                 $this->db->update('exam', array('exam_index' => $exam['exam_index']), array('exam_id' => $next['exam_id']));
             }
         }
     }
     $back_url = empty($_SERVER['HTTP_REFERER']) ? 'admin/exam/index/' : $_SERVER['HTTP_REFERER'];
     redirect($back_url);
 }