Ejemplo n.º 1
0
 public function __construct($userid, $connection, $dbPrefix)
 {
     $GLOBALS["dbPrefix"] = $dbPrefix;
     $set = null;
     $setid = -1;
     $questionid = -1;
     $answerid = -1;
     foreach ($connection->query('SELECT * FROM ' . $GLOBALS["dbPrefix"] . 'question_set WHERE ownerid="' . $userid . '"') as $setRow) {
         $set = new cardSet(s);
         $set->setSetId($setRow['setid']);
         $setid = $setRow['setid'];
         $set->setSetName($setRow['setname']);
         $set->setSetDescription($setRow['setdescription']);
         foreach ($connection->query('SELECT * FROM ' . $GLOBALS["dbPrefix"] . 'question_question WHERE ' . $GLOBALS["dbPrefix"] . 'question_question.set="' . $setid . '";') as $questionRow) {
             $question = new question();
             $question->setId($questionRow['questionid']);
             $question->setQuestion($questionRow['question']);
             $question->setMode($questionRow['mode']);
             $question->setRightAnswered($questionRow['rightAnswered']);
             $question->setWrongAnswered($questionRow['wrongAnswered']);
             $questionid = $questionRow['questionid'];
             foreach ($connection->query('SELECT * FROM ' . $GLOBALS["dbPrefix"] . 'question_answer WHERE ' . $GLOBALS["dbPrefix"] . 'question_answer.ownerquestion=' . $questionid) as $answerRow) {
                 $answerobj = new answer();
                 $answerobj->setAnswer($answerRow['answertext']);
                 $answerobj->setAnswerId($answerRow['answerid']);
                 $question->addAnswer($answerobj);
             }
             $set->addQuestion($question);
         }
         array_push($this->sets, $set);
     }
 }
Ejemplo n.º 2
0
 public function __construct($userid, $connection)
 {
     $set = null;
     $setid = -1;
     $questionid = -1;
     $answerid = -1;
     foreach ($connection->query('SELECT * FROM fullQuestionSet WHERE ownerid="' . $userid . '"') as $row) {
         if ($row['setid'] != $setid) {
             $set = new cardSet();
             $set->setSetId($row['setid']);
             $set->setSetName($row['setname']);
             $set->setSetDescription($row['setdescription']);
         }
         if ($questionid != $row['questionid'] && $row['questionid'] != null) {
             $question = new question();
             $question->setId($row['questionid']);
             $question->setQuestion($row['question']);
             $question->setMode($row['mode']);
             $question->setRightAnswered($row['rightAnswered']);
             $question->setWrongAnswered($row['wrongAnswered']);
         }
         if ($answerid != $row['answerid'] && $row['answerid'] != null) {
             $answerobj = new answer();
             $answerobj->setAnswer($row['answertext']);
             $answerobj->setAnswerId($row['answerid']);
         }
         if ($answerid != $row['answerid'] && $row['answerid'] != null) {
             $question->addAnswer($answerobj);
             $answerid = $row['answerid'];
         }
         if ($questionid != $row['questionid'] && $row['questionid'] != null) {
             $set->addQuestion($question);
             $questionid = $row['questionid'];
         }
         if ($set != null && $row['setid'] != $setid) {
             $setid = $row['setid'];
             array_push($this->sets, $set);
         }
     }
 }
Ejemplo n.º 3
0
 public function start()
 {
     $this->connection->exec("CREATE TABLE IF NOT EXISTS `" . $this->getDbPrefix() . "question_set` (\r\n\t\t`setid` int(11) NOT NULL AUTO_INCREMENT,\r\n\t\t`setname` varchar(25) COLLATE utf8_unicode_ci NOT NULL,\r\n\t\t`setdescription` varchar(1000) COLLATE utf8_unicode_ci NOT NULL,\r\n\t\t`ownerid` int(11) NOT NULL,\r\n\t\t`editcount` int(11) NOT NULL,\r\n\t\t`lasttimestamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,\r\n\t\t`createtimestamp` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',\r\n\t\t`firstowner` int(11) NOT NULL,\r\n\t\t`tagsid` int(11) NOT NULL,\r\n\t\tPRIMARY KEY (`setid`)\r\n\t)");
     $this->connection->exec("CREATE TABLE IF NOT EXISTS `" . $this->getDbPrefix() . "question_question` (\r\n\t\t`questionid` int(11) NOT NULL AUTO_INCREMENT,\r\n\t\t`set` int(11) NOT NULL,\r\n\t\t`question` varchar(100) NOT NULL,\r\n\t\t`mode` text NOT NULL,\r\n\t\t`rightAnswered` int(11) NOT NULL DEFAULT '0',\r\n\t\t`wrongAnswered` int(11) NOT NULL DEFAULT '0',\r\n\t\tPRIMARY KEY (`questionid`)\r\n\t)");
     $this->connection->exec("CREATE TABLE IF NOT EXISTS `" . $this->getDbPrefix() . "question_answer` (\r\n\t\t`answerid` int(11) NOT NULL AUTO_INCREMENT,\r\n\t\t`ownerquestion` int(11) NOT NULL,\r\n\t\t`answertext` varchar(100) NOT NULL,\r\n\t\t`rightAnswer` tinyint(1) NOT NULL COMMENT 'true if it is the right answer, false if not (for multiple answers)',\r\n\t\tPRIMARY KEY (`answerid`)\r\n\t)");
     $connection = $this->connection;
     $template = $this->templateObject;
     $messages = array();
     $template->assign("pluginId", $_GET['plugin']);
     $template->assign("folder", $this->folder);
     require_once $this->folder . 'card.class.php';
     $allSets = new allCardSets($_SESSION["user"]->getId(), $connection, $this->getDbPrefix());
     switch ($_GET["action"]) {
         case "create":
             if (!isset($_GET['nrofquestions'])) {
                 $template->assign("nrofquestions", 3);
             } else {
                 $template->assign("nrofquestions", $_GET['nrofquestions']);
             }
             return $template->fetch($this->folder . 'templates/cardPlugin_create.tpl');
             break;
         case "mkcreatecardset":
             if (!empty($_POST["cardsetname"])) {
                 $newCardSet = new cardSet();
                 $newCardSet->setSetName($_POST["cardsetname"]);
                 $newCardSet->setSetDescription($_POST["cardsetdescription"]);
                 $template->assign("nrofquestions", 3);
                 $allSets->newSet($newCardSet, $_SESSION["user"]->getId(), $connection);
                 $index = 0;
                 while ($_GET['nrofquestions'] != $index) {
                     if ($_POST['question' . $index] != "" && $_POST['answer' . $index] != "") {
                         $question = new question();
                         $question->setQuestion($_POST['question' . $index]);
                         $question->setMode(1);
                         $answer = new answer();
                         $answer->setAnswer($_POST['answer' . $index]);
                         $newCardSet->newQuestion($question, $connection);
                         $question->newAnswer($answer, $connection);
                     }
                     $index = $index + 1;
                 }
                 //$newCardSet->newQuestion($question, $connection);
                 // $question->newAnswer($answer, $connection);
                 array_push($messages, "Create cardset successfull!");
                 $template->assign("messages", $messages);
                 $template->assign("cardsets", $allSets->getSets());
                 return $template->fetch($this->folder . 'templates/cardPlugin.tpl');
             }
             break;
         case "singlecardset":
             if (!empty($_GET["setid"])) {
                 $set = $allSets->getSetBySetId($_GET["setid"]);
                 $template->assign("setid", $_GET['setid']);
                 $template->assign("cardsettitle", $set->getSetName());
                 $template->assign("cardsetdescription", $set->getSetDescription());
                 $template->assign("dojorequire", array("dojox.charting.widget.Chart2D", "dojox.charting.themes.PurpleRain"));
                 $questions = $set->getQuestions();
                 // TODO may better use a empty()-method
                 if (count($questions) > 0) {
                     $template->assign("random", $_GET['random']);
                     if ($_GET['random'] == "yes") {
                         if (isset($_SESSION['lastid'])) {
                             $lastQuestionId = $_SESSION['lastid'];
                         }
                         $questionid = cardtools::randomArrayPosition($questions);
                         $question = $questions[$questionid];
                         $_SESSION['lastid'] = $questionid;
                         $template->assign("nextquestion", 1);
                     } else {
                         if (!empty($_GET['nextquestion'])) {
                             $questionid = cardtools::oneBeforeInArray($questions, $_GET['nextquestion']);
                             $lastQuestionId = cardtools::oneBeforeInArray($questions, $questionid);
                             $question = $questions[$questionid];
                             $template->assign("questionid", $question->getQuestionId());
                             if (count($questions) > $_GET['nextquestion']) {
                                 $template->assign("nextquestion", $_GET['nextquestion'] + 1);
                             } else {
                                 if (count($questions) == $_GET['nextquestion']) {
                                     $template->assign("question", $question->getQuestion());
                                     $template->assign("nextquestion", 1);
                                 }
                             }
                         } else {
                             $question = $questions[0];
                             $questionid = $question->getQuestionId();
                             $template->assign("questionid", $question->getQuestionId());
                             if (count($questions) > 1) {
                                 $template->assign("nextquestion", 2);
                             } else {
                                 $template->assign("nextquestion", 1);
                             }
                         }
                     }
                     $template->assign("question", $question->getQuestion());
                     if (!empty($_POST['answer'])) {
                         $answer = $question->getAnswers();
                         if ($questions[$lastQuestionId]->checkRightAnswer($_POST['answer'], $connection)) {
                             array_push($messages, "Answer " . $_POST['answer'] . " was right! :) (Question was: " . $questions[$lastQuestionId]->getQuestion() . ")");
                         } else {
                             $answer = $questions[$lastQuestionId]->getAnswers();
                             array_push($messages, "Answer was wrong! :( <br /> Question:" . $questions[$lastQuestionId]->getQuestion() . " and answer: " . $answer[0]->getAnswer());
                         }
                     }
                     if ($question->getRightAnswered() == 0 && $question->getWrongAnswered() == 0) {
                         $template->assign("rightAnswered", "0.1");
                         $template->assign("wrongAnswered", "0.1");
                     } else {
                         $template->assign("rightAnswered", $question->getRightAnswered());
                         $template->assign("wrongAnswered", $question->getWrongAnswered());
                     }
                 } else {
                     //FIXME why i don't come here in? why the array is 1 without having questions?
                     $template->assign("question", "There are no questions!");
                 }
                 $template->assign("messages", $messages);
                 return $template->fetch($this->folder . 'templates/cardPlugin_singlecardset.tpl');
                 break;
             }
         case "deletecardset":
             $template->assign("setid", $_GET['setid']);
             $set = $allSets->getSetBySetId($_GET["setid"]);
             if ($set == false) {
                 // TODO build a error-page
                 $template->assign("cardsetname", "There is no set with id " . $_GET["setid"]);
             } else {
                 $template->assign("what", "cardset");
                 $template->assign("cardsetname", $set->getSetName());
                 if (isset($_POST['sure'])) {
                     if ($_POST['sure'] == "yes") {
                         $set->deleteSet($connection);
                     }
                     header("Location: plugin.php?plugin=" . $_GET['plugin']);
                 }
             }
             return $template->fetch($this->folder . 'templates/cardPlugin_delete.tpl');
             break;
         case "editcardset":
             $noCardset = true;
             if (isset($_POST["setid"]) || isset($_GET["setid"])) {
                 // TODO build a error-page
                 $set = $allSets->getSetBySetId($_POST["setid"]);
                 if ($set != false) {
                     $noCardset = false;
                 } else {
                     $set = $allSets->getSetBySetId($_GET["setid"]);
                     if ($set != false) {
                         $noCardset = false;
                     }
                 }
             }
             if (!$noCardset) {
                 $template->assign("questions", $set->getQuestions());
                 $template->assign("setid", $set->getSetId());
                 $template->assign("cardsetname", $set->getSetName());
                 $template->assign("cardsetdescription", $set->getSetDescription());
                 if (isset($_POST['sure'])) {
                     if ($_POST['sure'] == "on") {
                         $set->updateSetDescription($_POST['cardsetdescripton'], $connection);
                         $set->updateSetName($_POST['cardsetname'], $connection);
                     }
                     header("Location: plugin.php?plugin=" . $_GET['plugin'] . "&action=singlecardset&setid=" . $set->getSetId());
                 }
             }
             if ($noCardset) {
                 $template->assign("cardsetname", gettext("There is no set with id ") . $_POST["setid"] . $_GET["setid"]);
             }
             return $template->fetch($this->folder . 'templates/cardPlugin_editcardset.tpl');
             break;
         case "editquestion":
             $noCardset = true;
             if (isset($_POST["setid"]) || isset($_GET["setid"])) {
                 // TODO build a error-page
                 $set = $allSets->getSetBySetId($_POST["setid"]);
                 if ($set != false) {
                     $template->assign("setid", $set->getSetId());
                     $noCardset = false;
                 } else {
                     $set = $allSets->getSetBySetId($_GET["setid"]);
                     if ($set != false) {
                         $template->assign("setid", $set->getSetId());
                         $noCardset = false;
                     }
                 }
                 $question = $set->getQuestionById($_GET['questionid']);
                 $template->assign("questionid", $question->getQuestionId());
             }
             if (!$noCardset) {
                 $template->assign("question", $question->getQuestion());
                 if (isset($_POST['sure'])) {
                     if ($_POST['sure'] == "on") {
                         $question->updateQuestion($_POST['question'], $connection);
                     }
                     header("Location: plugin.php?plugin=" . $_GET['plugin'] . "&action=singlecardset&setid=" . $_GET['setid']);
                 }
             }
             if ($noCardset) {
                 $template->assign("cardsetname", "There is no set with id " . $_POST["setid"] . $_GET["setid"]);
             }
             return $template->fetch($this->folder . 'templates/cardPlugin_editquestion.tpl');
             break;
         case "deletequestion":
             $template->assign("setid", $_GET['setid']);
             $set = $allSets->getSetBySetId($_GET["setid"]);
             if ($set == false) {
                 // TODO build a error-page
                 $template->assign("cardsetname", "There is no set with id " . $_GET["setid"]);
             } else {
                 $question = $set->getQuestionById($_GET["questionid"]);
                 if ($question == false) {
                     $template->assign("cardsetname", "There is no question with id " . $_GET["questionid"]);
                 } else {
                     $template->assign("questionid", $question->getQuestionId());
                     $template->assign("what", "question");
                     $template->assign("cardsetname", $question->getQuestion());
                     if (isset($_POST['sure'])) {
                         if ($_POST['sure'] == "yes") {
                             $question->deleteQuestion($connection);
                         }
                         header("Location: plugin.php?plugin=" . $_GET['plugin']);
                     }
                 }
             }
             return $template->fetch($this->folder . 'templates/cardPlugin_delete.tpl');
             break;
         case "addquestion":
             $template->assign("cardsets", $allSets->getSets());
             if (!empty($_POST["cardset"]) && !empty($_POST['question1']) && !empty($_POST['answer1'])) {
                 $set = $allSets->getSetBySetId($_POST["cardset"]);
                 $question = new question();
                 $question->setMode(1);
                 $question->setQuestion($_POST['question1']);
                 $answer = new answer();
                 $answer->setAnswer($_POST['answer1']);
                 $set->newQuestion($question, $connection);
                 $question->newAnswer($answer, $connection);
                 array_push($messages, "Add question successfull");
             }
             $template->assign("messages", $messages);
             return $template->fetch($this->folder . 'templates/cardPlugin_modify.tpl');
             break;
         default:
             $carding = new allCardSets($_SESSION["user"]->getId(), $connection, $this->getDbPrefix());
             $template->assign("cardsets", $carding->getSets());
             return $template->fetch($this->folder . 'templates/cardPlugin.tpl');
     }
 }
Ejemplo n.º 4
0
                    if ($_POST['sure'] == "yes") {
                        $question->deleteQuestion($connection);
                    }
                    header("Location: cards.php");
                }
            }
        }
        $template->display('cards_delete.tpl');
        break;
    case "addquestion":
        $template->assign("cardsets", $allSets->getSets());
        if (!empty($_POST["cardset"]) && !empty($_POST['question1']) && !empty($_POST['answer1'])) {
            $set = $allSets->getSetBySetId($_POST["cardset"]);
            $question = new question();
            $question->setMode(1);
            $question->setQuestion($_POST['question1']);
            $answer = new answer();
            $answer->setAnswer($_POST['answer1']);
            $set->newQuestion($question, $connection);
            $question->newAnswer($answer, $connection);
            array_push($messages, "Add question successfull");
        }
        $template->assign("messages", $messages);
        $template->display('cards_modify.tpl');
        break;
    default:
        $carding = new allCardSets($_SESSION["user"]->getId(), $connection);
        $template->assign("cardsets", $carding->getSets());
        $template->display('cards.tpl');
        break;
}