source: Dev/branches/jos-branch/setQuestion.php @ 238

Last change on this file since 238 was 237, checked in by fpvanagthoven, 13 years ago
  • Faal met perongeluk de database committen-_- Maar is weer deleted, zou nu weer moeten werken.
  • QuestionEditor? werkt nu grotendeels, paar kleine afwerkingsfoutjes (en data die nog niet in de DB passen)
  • selectQuestion scherm gemaakt, is nog niet zo multifunctioneel als je zou hopen. Ideaal gezien zou dit ipv een statische PHP pagina, een JS driven widget worden die je bijvoorbeeld kan gebruiken voor "Add existing question" in de surveyEditor.
  • Zelfde voor selectApplication.php en selectSurvey.php.
  • objectSelectionWidget class maken voor dit doeleind? (Na demo!)
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 = $questions[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 ($input->category ) $question->category = null;
25    if ($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.