source: Dev/branches/jQueryUI/setQuestion.php @ 243

Last change on this file since 243 was 240, checked in by fpvanagthoven, 13 years ago
File size: 1.5 KB
Line 
1<?php
2
3require 'classes/master.php'; //should be at top of every page
4
5if (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
11if (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)) {
15        $question = $question_results[0];
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;
24    if (isset($input->category) ) $question->category = null;
25    if (isset($input->answers)) $question->answers = null;
26    $question->save();
27    $outputArray = array("created"=>false, "uid"=>$question->uid);
28    echo JSON_encode($outputArray);
29}
30else {
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?>
Note: See TracBrowser for help on using the repository browser.