Example #1
0
         case 'setmod':
             $response = Group::setModerator($_POST['gid'], $_POST['uid'], $_POST['mod']);
             break;
     }
     break;
 case 'question':
     switch ($action) {
         case 'add':
             $_POST['question'] = array_key_exists('question', $_POST) ? $_POST['question'] : '';
             $_POST['correct'] = array_key_exists('correct', $_POST) ? $_POST['correct'] : null;
             $_POST['answer-explanation'] = array_key_exists('answer-explanation', $_POST) ? $_POST['answer-explanation'] : '';
             $alternatives = array();
             for ($i = 0; $i < 4; $i++) {
                 $alternatives[] = $_POST['alt-' . $i];
             }
             $response = Question::add($_POST['question'], $alternatives, $_POST['correct'], $_POST['answer-explanation'], $_POST['gid']);
             break;
         case 'get':
             $response = Question::get($params[0], $params[1]);
             break;
         case 'my':
             $params[0] = count($params) >= 1 ? $params[0] : null;
             $response = Question::getMine($params[0]);
             break;
         case 'answer':
             $_POST['qid'] = array_key_exists('qid', $_POST) ? $_POST['qid'] : '';
             $_POST['aid'] = array_key_exists('aid', $_POST) ? $_POST['aid'] : '';
             $response = Question::answer($_POST['qid'], $_POST['aid']);
             break;
     }
     break;
<?php

require_once "Question.php";
require_once "db.php";
@Database::connect();
if (!Database::$link) {
    Database::error();
}
if (!isset($_POST["text"]) || !isset($_POST["trueAnswer"]) || !isset($_POST["falseAnswer1"]) || !isset($_POST["falseAnswer2"])) {
    die;
}
$text = $_POST["text"];
$trueAnswer = $_POST["trueAnswer"];
$falseAnswer1 = $_POST["falseAnswer1"];
$falseAnswer2 = $_POST["falseAnswer2"];
$question = new Question($text, $trueAnswer, $falseAnswer1, $falseAnswer2);
$question->add();
header("Location: ../front-end/moviesChallenge.html");
Example #3
0
 function init()
 {
     $question = new Question();
     $func = array_shift($this->param);
     if (is_numeric($func)) {
         $this->id = $func;
     } else {
         if ($func != '') {
             $_SERVER['REQUEST_METHOD'] = 'POST';
             $course_id = array_shift($this->param);
             Security::checkEditor($course_id);
             switch ($func) {
                 case 'save':
                     $data['course_id'] = $course_id;
                     $data['type_id'] = $_POST['type_id'];
                     $data['data'] = $_POST['data'];
                     $data['count'] = $_POST['count'];
                     $data['answer'] = $_POST['answer'];
                     $id = $_POST['id'];
                     try {
                         $question->update($id, $data);
                     } catch (Exception $e) {
                     }
                     header('Location: /admin_questions/' . $data['course_id']);
                     exit;
                     break;
                 case 'delete':
                     try {
                         $question_id = array_shift($this->param);
                         $question->delete($question_id);
                         echo "ok";
                     } catch (Exception $e) {
                         echo $e;
                     }
                     header('Location: /admin_questions/' . $course_id);
                     exit;
                     break;
                 case 'find':
                     try {
                         $data = array('course_id' => $course_id, 'type_id' => 0, 'data' => '', 'answer' => '');
                         $q_id = $question->add($data);
                         $data['id'] = $q_id;
                         echo json_encode($data);
                     } catch (Exception $e) {
                         echo $e;
                     }
                     exit;
                     break;
                 case 'load':
                     try {
                         $question_id = array_shift($this->param);
                         $data = $question->get(array('course_id' => $course_id, 'id' => $question_id));
                         echo json_encode($data);
                     } catch (Exception $e) {
                         echo $e;
                     }
                     exit;
                     break;
                 default:
             }
         } else {
             header('Location: /404');
             exit;
         }
     }
 }