if (count($questions_to_import) == 0) { array_push($MSG, getstring('import.quiz.error.nosuppportedquestions')); } if (count($MSG) == 0) { // now do the actual import if ($format == 'gift') { $quizdraft = optional_param("quizdraft", 0, PARAM_INT); // update title and content $API->updateQuiz($ref, $title, $quizdraft, $description); $API->setProp('quiz', $q->quizid, 'content', $content); $API->updateQuizTags($q->quizid, $tags); // remove current questions/responses (will add them again below) $API->removeQuiz($q->quizid); $importer = new GIFTImporter(); $importer->quizid = $q->quizid; $importer->import($questions_to_import); $API->setProp('quiz', $q->quizid, 'maxscore', $importer->quizmaxscore); } $q = $API->getQuizById($q->quizid); // store JSON object for quiz (for caching) $json = json_encode($API->getQuizObject($q->ref)); $API->setProp('quiz', $q->quizid, 'json', $json); header(sprintf("Location: %squiz/options.php?qref=%s&new=false", $CONFIG->homeAddress, $q->ref)); die; } } include_once "../../includes/header.php"; ?> <h1><?php
function createQuizfromGIFT($content, $title, $quizdraft, $description, $tags) { global $IMPORT_INFO, $MSG, $CONFIG, $USER; //first check if this quiz already exists $sql = sprintf("SELECT q.qref FROM quizprop qp\n\t\t\t\t\t\tINNER JOIN quiz q ON q.quizid = qp.quizid\n\t\t\t\t\t\tWHERE qp.quizpropname='content' \n\t\t\t\t\t\tAND qp.quizpropvalue='%s'\n\t\t\t\t\t\tAND q.createdby=%d", $content, $USER->userid); $result = _mysql_query($sql, $this->DB); while ($o = mysql_fetch_object($result)) { // store JSON object for quiz (for caching) $obj = $this->getQuizObject($o->qref); return $obj; } $supported_qtypes = array('truefalse', 'multichoice', 'essay', 'shortanswer', 'numerical'); $questions_to_import = array(); include_once $CONFIG->homePath . 'quiz/import/gift/import.php'; $import = new qformat_gift(); $lines = explode("\n", $content); $questions = $import->readquestions($lines); foreach ($questions as $q) { if (in_array($q->qtype, $supported_qtypes)) { array_push($questions_to_import, $q); } else { if ($q->qtype != 'category') { array_push($IMPORT_INFO, $q->qtype . " question type not yet supported ('" . $q->questiontext . "')"); } } } if (count($questions_to_import) == 0) { array_push($MSG, getstring('import.quiz.error.nosuppportedquestions')); return; } if (count($MSG) == 0) { // now do the actual import // setup quiz with default props $quizid = $this->addQuiz($title, $quizdraft, $description); $this->setProp('quiz', $quizid, 'generatedby', 'import'); $this->setProp('quiz', $quizid, 'content', $content); $this->updateQuizTags($quizid, $tags); $importer = new GIFTImporter(); $importer->quizid = $quizid; $importer->import($questions_to_import); $this->setProp('quiz', $quizid, 'maxscore', $importer->quizmaxscore); $q = $this->getQuizById($quizid); // store JSON object for quiz (for caching) $obj = $this->getQuizObject($q->ref); $json = json_encode($obj); $this->setProp('quiz', $quizid, 'json', $json); return $obj; } return; }