if (!validate_string($text, CONS_MAX_LENGTH_TEXT))
return array('status' => FALSE, 'result' => CONS_INVALID_TEXT);
if (!$this->ExistSubject($subject_id))
return array('status' => FALSE, 'result' => CONS_NOT_FOUND);
if (!validate_json_array($careers))
return array('status' => FALSE, 'result' => CONS_INVALID_ARRAY);
if (!validate_string($answer1, CONS_MAX_LENGTH_SUBJECT))
return array('status' => FALSE, 'result' => CONS_INVALID_TEXT);
if (!validate_string($answer2, CONS_MAX_LENGTH_SUBJECT))
return array('status' => FALSE, 'result' => CONS_INVALID_TEXT);
if (!validate_string($answer3, CONS_MAX_LENGTH_SUBJECT))
return array('status' => FALSE, 'result' => CONS_INVALID_TEXT);
if (!validate_string($answer4, CONS_MAX_LENGTH_SUBJECT))
return array('status' => FALSE, 'result' => CONS_INVALID_TEXT);
if ($correct_answer != '1' && $correct_answer != '2' && $correct_answer != '3' && $correct_answer != '4')
return array('status' => FALSE, 'result' => CONS_INVALID_ANSWER_NUMBER);
if (validate_upload('picture')) {
if (!validate_picture($_FILES['picture']['tmp_name']))
return array('status' => FALSE, 'result' => CONS_INVALID_PICTURE);
if (!validate_upload_filesize($_FILES['picture']['tmp_name'], CONS_MAX_SIZE_PICTURE))
return array('status' => FALSE, 'result' => CONS_INVALID_FILE_SIZE);
}
$this->db->trans_start();
$this->db->set('sUsername',$current_user);
$this->db->set('sSubject',$subject);
$this->db->set('sText',$text);
$this->db->set('sSubjectTypeID',$subject_id);
$this->db->set('sCareerID',$careers);
$this->db->set('sAnswer1',$answer1);
$this->db->set('sAnswer2',$answer2);
$this->db->set('sAnswer3',$answer3);
$this->db->set('sAnswer4',$answer4);
$this->db->set('sCorrectAnswer',$correct_answer);
$this->db->insert('questions');
$id = $this->db->insert_id();
$this->db->trans_complete();
if ($this->db->trans_status() == TRUE) {
$path = CONS_QUESTION_DIRECTORY.$id;
@mkdir($path);
if (validate_upload('picture')) {
move_upload_files($_FILES['picture']['tmp_name'], $path . '/1.jpg');
$this->db->set('sHavePicture','1');
$this->db->where('sID',$id);
$this->db->update('questions');
}
$this->load->model('user');
$this->user->ChangeLevel($current_user,5);
return array('status' => TRUE);
} else {
return array('status' => FALSE, 'result' => CONS_INVALID_ADD);
}