public function save()
 {
     if (!$this->check_power('comparison_manage')) {
         return;
     }
     $act = $this->input->post('act');
     $act = $act == 'add' ? 'add' : 'edit';
     $id = null;
     if ($act == 'edit') {
         $id = (int) $this->input->post('id');
         $id && ($old_info = ComparisonTypeModel::get_comparison_type_by_id($id));
         if (empty($old_info)) {
             message('分类信息不存在');
         }
     }
     $data = array('cmp_type_name' => html_escape(trim($this->input->post('type_name'))), 'grade_id' => (int) $this->input->post('grade_id'), 'class_id' => (int) $this->input->post('class_id'), 'subject_id' => (int) $this->input->post('subject_id'), 'introduce' => html_escape($this->input->post('introduce')));
     $message = array();
     if (empty($data['cmp_type_name'])) {
         message('请填写分类名称');
         return;
     } else {
         $tid = ComparisonTypeModel::get_comparison_type_by_name($data['cmp_type_name'], 'cmp_type_id');
         if ($tid && $tid != $id) {
             message('分类名称已存在');
             return;
         }
     }
     if (empty($data['grade_id'])) {
         message('请选择考试年级');
         return;
     }
     if (empty($data['class_id'])) {
         $message[] = '请选择考试类型';
         message('请选择考试类型');
         return;
     }
     if (empty($data['subject_id'])) {
         message('请选择考试学科');
         return;
     }
     if ($this->input->post('type_flag') !== FALSE) {
         $data['cmp_type_flag'] = $this->input->post('type_flag') ? 1 : 0;
     }
     $res = FALSE;
     if ($act == 'add') {
         $actname = '添加';
         $insert_id = 0;
         $res = ComparisonTypeModel::insert($data, $insert_id);
         if ($res) {
             $id = $insert_id;
         }
     } else {
         $actname = '编辑';
         $res = ComparisonTypeModel::update($id, $data);
     }
     if ($res) {
         admin_log($act, 'comparison_type', $id);
         message('分类' . $actname . '成功', 'admin/comparison_type/index');
     } else {
         message('分类' . $actname . '失败');
     }
 }