[237] | 1 | <?php |
---|
| 2 | |
---|
| 3 | require 'classes/master.php'; //should be at top of every page |
---|
| 4 | |
---|
| 5 | if (isset($_POST['args']) && !empty($_POST['args'])) { |
---|
| 6 | $input = JSON_decode($_POST['args']) or die("Invalid input!"); |
---|
| 7 | } else { |
---|
| 8 | die("No or invalid input!"); |
---|
| 9 | } |
---|
| 10 | |
---|
| 11 | if (isset($input->uid) && $input->uid != null) { |
---|
| 12 | // This concerns an edit of an existing question, not creation of a new one. |
---|
| 13 | $question_results = Question::get(array("uid" => $input->uid)); |
---|
| 14 | if (!empty($question_results)) { |
---|
[240] | 15 | $question = $question_results[0]; |
---|
[237] | 16 | } else { |
---|
| 17 | die("Error: attempt to edit a non-existing database object!"); |
---|
| 18 | } |
---|
| 19 | |
---|
| 20 | if ($input->answerType) $question->type = $input->answerType; |
---|
| 21 | if ($input->code) $question->code = $input->code; |
---|
| 22 | if ($input->title) $question->title = $input->title; |
---|
| 23 | if ($input->description) $question->description = $input->description; |
---|
[240] | 24 | if (isset($input->category) ) $question->category = null; |
---|
| 25 | if (isset($input->answers)) $question->answers = null; |
---|
[237] | 26 | $question->save(); |
---|
| 27 | $outputArray = array("created"=>false, "uid"=>$question->uid); |
---|
| 28 | echo JSON_encode($outputArray); |
---|
| 29 | } |
---|
| 30 | else { |
---|
| 31 | // Obviously, this call does not save most of the data entered into the question Editor, because the database has not place to store these values as of yet. |
---|
| 32 | $question = new Question(null, $input->code, $input->title, $input->answerType, $input->description, null, null); |
---|
| 33 | $question->save(); |
---|
| 34 | $outputArray = array("created"=>true, "uid"=>$question->uid); |
---|
| 35 | echo JSON_encode($outputArray); |
---|
| 36 | } |
---|
| 37 | ?> |
---|