/**
  * Creates a question from a QTI file
  *
  * Receives parameters from a QTI parser and creates a valid ILIAS question object
  *
  * @param object $item The QTI item object
  * @param integer $questionpool_id The id of the parent questionpool
  * @param integer $tst_id The id of the parent test if the question is part of a test
  * @param object $tst_object A reference to the parent test object
  * @param integer $question_counter A reference to a question counter to count the questions of an imported question pool
  * @param array $import_mapping An array containing references to included ILIAS objects
  * @access public
  */
 function fromXML(&$item, $questionpool_id, &$tst_id, &$tst_object, &$question_counter, &$import_mapping)
 {
     global $ilUser;
     // empty session variable for imported xhtml mobs
     unset($_SESSION["import_mob_xhtml"]);
     $presentation = $item->getPresentation();
     $duration = $item->getDuration();
     $now = getdate();
     $created = sprintf("%04d%02d%02d%02d%02d%02d", $now['year'], $now['mon'], $now['mday'], $now['hours'], $now['minutes'], $now['seconds']);
     $feedbacksgeneric = array();
     $this->addGeneralMetadata($item);
     $this->object->setTitle($item->getTitle());
     $this->object->setNrOfTries($item->getMaxattempts());
     $this->object->setComment($item->getComment());
     $this->object->setAuthor($item->getAuthor());
     $this->object->setOwner($ilUser->getId());
     $this->object->setQuestion($this->object->QTIMaterialToString($item->getQuestiontext()));
     $this->object->setObjId($questionpool_id);
     $this->object->setEstimatedWorkingTime($duration["h"], $duration["m"], $duration["s"]);
     $this->object->setPoints($item->getMetadataEntry("points"));
     $this->object->setOrderText($item->getMetadataEntry("ordertext"));
     $this->object->setTextSize($item->getMetadataEntry("textsize"));
     $this->object->setSeparator($item->getMetadataEntry("separator"));
     // additional content editing mode information
     $this->object->setAdditionalContentEditingMode($this->fetchAdditionalContentEditingModeInformation($item));
     $this->object->saveToDb();
     // handle the import of media objects in XHTML code
     $questiontext = $this->object->getQuestion();
     if (is_array($_SESSION["import_mob_xhtml"])) {
         include_once "./Services/MediaObjects/classes/class.ilObjMediaObject.php";
         include_once "./Services/RTE/classes/class.ilRTE.php";
         foreach ($_SESSION["import_mob_xhtml"] as $mob) {
             if ($tst_id > 0) {
                 $importfile = $this->getTstImportArchivDirectory() . '/' . $mob["uri"];
             } else {
                 $importfile = $this->getQplImportArchivDirectory() . '/' . $mob["uri"];
             }
             $GLOBALS['ilLog']->write(__METHOD__ . ': import mob from dir: ' . $importfile);
             $media_object =& ilObjMediaObject::_saveTempFileAsMediaObject(basename($importfile), $importfile, FALSE);
             ilObjMediaObject::_saveUsage($media_object->getId(), "qpl:html", $this->object->getId());
             $questiontext = str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $questiontext);
         }
     }
     $this->object->setQuestion(ilRTE::_replaceMediaObjectImageSrc($questiontext, 1));
     $this->object->saveToDb();
     if (count($item->suggested_solutions)) {
         foreach ($item->suggested_solutions as $suggested_solution) {
             $this->object->setSuggestedSolution($suggested_solution["solution"]->getContent(), $suggested_solution["gap_index"], true);
         }
         $this->object->saveToDb();
     }
     if ($tst_id > 0) {
         $q_1_id = $this->object->getId();
         $question_id = $this->object->duplicate(true, null, null, null, $tst_id);
         $tst_object->questions[$question_counter++] = $question_id;
         $import_mapping[$item->getIdent()] = array("pool" => $q_1_id, "test" => $question_id);
     } else {
         $import_mapping[$item->getIdent()] = array("pool" => $this->object->getId(), "test" => 0);
     }
 }
 /**
  * Import XML
  *
  * @param
  * @return
  */
 function importXmlRepresentation($a_entity, $a_id, $a_xml, $a_mapping)
 {
     // Container import => test object already created
     if ($new_id = $a_mapping->getMapping('Services/Container', 'objs', $a_id)) {
         $newObj = ilObjectFactory::getInstanceByObjId($new_id, false);
         #$newObj->setImportDirectory(dirname(rtrim($this->getImportDirectory(),'/')));
     } else {
         // Shouldn't happen
         $GLOBALS['ilLog']->write(__METHOD__ . ': Called in non container mode');
         return false;
     }
     include_once "./Services/Survey/classes/class.SurveyImportParser.php";
     list($xml_file) = $this->parseXmlFileNames();
     if (!@file_exists($xml_file)) {
         $GLOBALS['ilLog']->write(__METHOD__ . ': Cannot find xml definition: ' . $xml_file);
         return false;
     }
     $import = new SurveyImportParser(-1, $xml_file, TRUE);
     $import->setSurveyObject($newObj);
     $import->startParsing();
     if (is_array($_SESSION["import_mob_xhtml"])) {
         include_once "./Services/MediaObjects/classes/class.ilObjMediaObject.php";
         include_once "./Services/RTE/classes/class.ilRTE.php";
         include_once "./Modules/TestQuestionPool/classes/class.ilObjQuestionPool.php";
         foreach ($_SESSION["import_mob_xhtml"] as $mob) {
             $importfile = dirname($xml_file) . "/" . $mob["uri"];
             if (file_exists($importfile)) {
                 $media_object =& ilObjMediaObject::_saveTempFileAsMediaObject(basename($importfile), $importfile, FALSE);
                 ilObjMediaObject::_saveUsage($media_object->getId(), "svy:html", $newObj->getId());
                 $newObj->setIntroduction(str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $newObj->getIntroduction()));
                 $newObj->setOutro(str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $newObj->getOutro()));
             } else {
                 global $ilLog;
                 $ilLog->write("Error: Could not open XHTML mob file for test introduction during test import. File {$importfile} does not exist!");
             }
         }
         $newObj->setIntroduction(ilRTE::_replaceMediaObjectImageSrc($newObj->getIntroduction(), 1));
         $newObj->setOutro(ilRTE::_replaceMediaObjectImageSrc($newObj->getOutro(), 1));
         $newObj->saveToDb();
     }
     $a_mapping->addMapping("Modules/Survey", "svy", $a_id, $newObj->getId());
     return true;
 }
 /**
  * Imports a survey from XML into the ILIAS database
  *
  * @return boolean True, if the import succeeds, false otherwise
  * @access public
  */
 function importObject($file_info, $svy_qpl_id)
 {
     if ($svy_qpl_id < 1) {
         $svy_qpl_id = -1;
     }
     // check if file was uploaded
     $source = $file_info["tmp_name"];
     $error = "";
     if ($source == 'none' || !$source || $file_info["error"] > UPLOAD_ERR_OK) {
         $error = $this->lng->txt("import_no_file_selected");
     }
     // check correct file type
     $isXml = FALSE;
     $isZip = FALSE;
     if (strcmp($file_info["type"], "text/xml") == 0 || strcmp($file_info["type"], "application/xml") == 0) {
         $isXml = TRUE;
     }
     // too many different mime-types, so we use the suffix
     $suffix = pathinfo($file_info["name"]);
     if (strcmp(strtolower($suffix["extension"]), "zip") == 0) {
         $isZip = TRUE;
     }
     if (!$isXml && !$isZip) {
         $error = $this->lng->txt("import_wrong_file_type");
         global $ilLog;
         $ilLog->write("Survey: Import error. Filetype was \"" . $file_info["type"] . "\"");
     }
     if (strlen($error) == 0) {
         // import file as a survey
         $import_dir = $this->getImportDirectory();
         $import_subdir = "";
         $importfile = "";
         include_once "./Services/Utilities/classes/class.ilUtil.php";
         if ($isZip) {
             $importfile = $import_dir . "/" . $file_info["name"];
             ilUtil::moveUploadedFile($source, $file_info["name"], $importfile);
             ilUtil::unzip($importfile);
             $found = $this->locateImportFiles($import_dir);
             if (!(strlen($found["dir"]) > 0 && strlen($found["xml"]) > 0)) {
                 $error = $this->lng->txt("wrong_import_file_structure");
                 return $error;
             }
             $importfile = $found["xml"];
             $import_subdir = $found["dir"];
         } else {
             $importfile = tempnam($import_dir, "survey_import");
             ilUtil::moveUploadedFile($source, $file_info["name"], $importfile);
         }
         $fh = fopen($importfile, "r");
         if (!$fh) {
             $error = $this->lng->txt("import_error_opening_file");
             return $error;
         }
         $xml = fread($fh, filesize($importfile));
         $result = fclose($fh);
         if (!$result) {
             $error = $this->lng->txt("import_error_closing_file");
             return $error;
         }
         unset($_SESSION["import_mob_xhtml"]);
         if (strpos($xml, "questestinterop")) {
             include_once "./Services/Survey/classes/class.SurveyImportParserPre38.php";
             $import = new SurveyImportParserPre38($svy_qpl_id, "", TRUE);
             $import->setSurveyObject($this);
             $import->setXMLContent($xml);
             $import->startParsing();
         } else {
             include_once "./Services/Survey/classes/class.SurveyImportParser.php";
             $import = new SurveyImportParser($svy_qpl_id, "", TRUE);
             $import->setSurveyObject($this);
             $import->setXMLContent($xml);
             $import->startParsing();
         }
         if (is_array($_SESSION["import_mob_xhtml"])) {
             include_once "./Services/MediaObjects/classes/class.ilObjMediaObject.php";
             include_once "./Services/RTE/classes/class.ilRTE.php";
             include_once "./Modules/TestQuestionPool/classes/class.ilObjQuestionPool.php";
             foreach ($_SESSION["import_mob_xhtml"] as $mob) {
                 $importfile = $import_subdir . "/" . $mob["uri"];
                 if (file_exists($importfile)) {
                     $media_object =& ilObjMediaObject::_saveTempFileAsMediaObject(basename($importfile), $importfile, FALSE);
                     ilObjMediaObject::_saveUsage($media_object->getId(), "svy:html", $this->getId());
                     $this->setIntroduction(str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $this->getIntroduction()));
                     $this->setOutro(str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $this->getOutro()));
                 } else {
                     global $ilLog;
                     $ilLog->write("Error: Could not open XHTML mob file for test introduction during test import. File {$importfile} does not exist!");
                 }
             }
             $this->setIntroduction(ilRTE::_replaceMediaObjectImageSrc($this->getIntroduction(), 1));
             $this->setOutro(ilRTE::_replaceMediaObjectImageSrc($this->getOutro(), 1));
             $this->saveToDb();
         }
         // delete import directory
         ilUtil::delDir($this->getImportDirectory());
     }
     return $error;
 }
 /**
  * Creates a question from a QTI file
  *
  * Receives parameters from a QTI parser and creates a valid ILIAS question object
  *
  * @param object $item The QTI item object
  * @param integer $questionpool_id The id of the parent questionpool
  * @param integer $tst_id The id of the parent test if the question is part of a test
  * @param object $tst_object A reference to the parent test object
  * @param integer $question_counter A reference to a question counter to count the questions of an imported question pool
  * @param array $import_mapping An array containing references to included ILIAS objects
  * @access public
  */
 function fromXML(&$item, $questionpool_id, &$tst_id, &$tst_object, &$question_counter, &$import_mapping)
 {
     global $ilUser;
     // empty session variable for imported xhtml mobs
     unset($_SESSION["import_mob_xhtml"]);
     $presentation = $item->getPresentation();
     $duration = $item->getDuration();
     $now = getdate();
     $applet = NULL;
     $maxpoints = 0;
     $javacode = "";
     $javacodebase = "";
     $javaarchive = "";
     $params = array();
     $created = sprintf("%04d%02d%02d%02d%02d%02d", $now['year'], $now['mon'], $now['mday'], $now['hours'], $now['minutes'], $now['seconds']);
     $answers = array();
     foreach ($presentation->order as $entry) {
         switch ($entry["type"]) {
             case "material":
                 $material = $presentation->material[$entry["index"]];
                 for ($i = 0; $i < $material->getMaterialCount(); $i++) {
                     $mat = $material->getMaterial($i);
                     if (strcmp($mat["type"], "mattext") == 0) {
                         $mattext = $mat["material"];
                         if (strlen($mattext->getLabel()) == 0 && strlen($this->object->QTIMaterialToString($item->getQuestiontext())) == 0) {
                             $item->setQuestiontext($mattext->getContent());
                         }
                         if (strcmp($mattext->getLabel(), "points") == 0) {
                             $maxpoints = $mattext->getContent();
                         } else {
                             if (strcmp($mattext->getLabel(), "java_code") == 0) {
                                 $javacode = $mattext->getContent();
                             } else {
                                 if (strcmp($mattext->getLabel(), "java_codebase") == 0) {
                                     $javacodebase = $mattext->getContent();
                                 } else {
                                     if (strcmp($mattext->getLabel(), "java_archive") == 0) {
                                         $javaarchive = $mattext->getContent();
                                     } else {
                                         if (strlen($mattext->getLabel()) > 0) {
                                             array_push($params, array("key" => $mattext->getLabel(), "value" => $mattext->getContent()));
                                         }
                                     }
                                 }
                             }
                         }
                     } elseif (strcmp($mat["type"], "matapplet") == 0) {
                         $applet = $mat["material"];
                     }
                 }
                 break;
         }
     }
     $feedbacksgeneric = array();
     foreach ($item->resprocessing as $resprocessing) {
         foreach ($resprocessing->respcondition as $respcondition) {
             foreach ($respcondition->displayfeedback as $feedbackpointer) {
                 if (strlen($feedbackpointer->getLinkrefid())) {
                     foreach ($item->itemfeedback as $ifb) {
                         if (strcmp($ifb->getIdent(), "response_allcorrect") == 0) {
                             // found a feedback for the identifier
                             if (count($ifb->material)) {
                                 foreach ($ifb->material as $material) {
                                     $feedbacksgeneric[1] = $material;
                                 }
                             }
                             if (count($ifb->flow_mat) > 0) {
                                 foreach ($ifb->flow_mat as $fmat) {
                                     if (count($fmat->material)) {
                                         foreach ($fmat->material as $material) {
                                             $feedbacksgeneric[1] = $material;
                                         }
                                     }
                                 }
                             }
                         } else {
                             if (strcmp($ifb->getIdent(), "response_onenotcorrect") == 0) {
                                 // found a feedback for the identifier
                                 if (count($ifb->material)) {
                                     foreach ($ifb->material as $material) {
                                         $feedbacksgeneric[0] = $material;
                                     }
                                 }
                                 if (count($ifb->flow_mat) > 0) {
                                     foreach ($ifb->flow_mat as $fmat) {
                                         if (count($fmat->material)) {
                                             foreach ($fmat->material as $material) {
                                                 $feedbacksgeneric[0] = $material;
                                             }
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     $this->object->setTitle($item->getTitle());
     $this->object->setNrOfTries($item->getMaxattempts());
     $this->object->setComment($item->getComment());
     $this->object->setAuthor($item->getAuthor());
     $this->object->setOwner($ilUser->getId());
     $this->object->setQuestion($this->object->QTIMaterialToString($item->getQuestiontext()));
     $this->object->setObjId($questionpool_id);
     $this->object->setEstimatedWorkingTime($duration["h"], $duration["m"], $duration["s"]);
     $this->object->setJavaAppletFilename($applet->getUri());
     $this->object->setJavaWidth($applet->getWidth());
     $this->object->setJavaHeight($applet->getHeight());
     $this->object->setJavaCode($javacode);
     $this->object->setJavaCodebase($javacodebase);
     $this->object->setJavaArchive($javaarchive);
     $this->object->setPoints($maxpoints);
     foreach ($params as $pair) {
         $this->object->addParameter($pair["key"], $pair["value"]);
     }
     $this->object->saveToDb();
     if (count($item->suggested_solutions)) {
         foreach ($item->suggested_solutions as $suggested_solution) {
             $this->object->setSuggestedSolution($suggested_solution["solution"]->getContent(), $suggested_solution["gap_index"], true);
         }
         $this->object->saveToDb();
     }
     $javaapplet =& base64_decode($applet->getContent());
     $javapath = $this->object->getJavaPath();
     if (!file_exists($javapath)) {
         include_once "./Services/Utilities/classes/class.ilUtil.php";
         ilUtil::makeDirParents($javapath);
     }
     $javapath .= $this->object->getJavaAppletFilename();
     $fh = fopen($javapath, "wb");
     if ($fh == false) {
         //									global $ilErr;
         //									$ilErr->raiseError($this->object->lng->txt("error_save_image_file") . ": $php_errormsg", $ilErr->MESSAGE);
         //									return;
     } else {
         $javafile = fwrite($fh, $javaapplet);
         fclose($fh);
     }
     // handle the import of media objects in XHTML code
     foreach ($feedbacksgeneric as $correctness => $material) {
         $m = $this->object->QTIMaterialToString($material);
         $feedbacksgeneric[$correctness] = $m;
     }
     $questiontext = $this->object->getQuestion();
     if (is_array($_SESSION["import_mob_xhtml"])) {
         include_once "./Services/MediaObjects/classes/class.ilObjMediaObject.php";
         include_once "./Services/RTE/classes/class.ilRTE.php";
         foreach ($_SESSION["import_mob_xhtml"] as $mob) {
             if ($tst_id > 0) {
                 $importfile = $this->getTstImportArchivDirectory() . '/' . $mob["uri"];
             } else {
                 $importfile = $this->getQplImportArchivDirectory() . '/' . $mob["uri"];
             }
             $GLOBALS['ilLog']->write(__METHOD__ . ': import mob from dir: ' . $importfile);
             $media_object =& ilObjMediaObject::_saveTempFileAsMediaObject(basename($importfile), $importfile, FALSE);
             ilObjMediaObject::_saveUsage($media_object->getId(), "qpl:html", $this->object->getId());
             $questiontext = str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $questiontext);
             foreach ($feedbacksgeneric as $correctness => $material) {
                 $feedbacksgeneric[$correctness] = str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $material);
             }
         }
     }
     $this->object->setQuestion(ilRTE::_replaceMediaObjectImageSrc($questiontext, 1));
     foreach ($feedbacksgeneric as $correctness => $material) {
         $this->object->saveFeedbackGeneric($correctness, ilRTE::_replaceMediaObjectImageSrc($material, 1));
     }
     $this->object->saveToDb();
     if ($tst_id > 0) {
         $q_1_id = $this->object->getId();
         $question_id = $this->object->duplicate(true, null, null, null, $tst_id);
         $tst_object->questions[$question_counter++] = $question_id;
         $import_mapping[$item->getIdent()] = array("pool" => $q_1_id, "test" => $question_id);
     } else {
         $import_mapping[$item->getIdent()] = array("pool" => $this->object->getId(), "test" => 0);
     }
 }
 public function fromXML(&$item, &$questionpool_id, &$tst_id, &$tst_object, &$question_counter, &$import_mapping)
 {
     global $ilUser;
     unset($_SESSION["import_mob_xhtml"]);
     $duration = $item->getDuration();
     $shuffle = 0;
     $answers = array();
     $presentation = $item->getPresentation();
     foreach ($presentation->order as $entry) {
         switch ($entry["type"]) {
             case "response":
                 $response = $presentation->response[$entry["index"]];
                 $rendertype = $response->getRenderType();
                 switch (strtolower(get_class($response->getRenderType()))) {
                     case "ilqtirenderchoice":
                         $shuffle = $rendertype->getShuffle();
                         $answerorder = 0;
                         $foundimage = FALSE;
                         foreach ($rendertype->response_labels as $response_label) {
                             $ident = $response_label->getIdent();
                             $answertext = "";
                             $answerimage = array();
                             foreach ($response_label->material as $mat) {
                                 $embedded = false;
                                 for ($m = 0; $m < $mat->getMaterialCount(); $m++) {
                                     $foundmat = $mat->getMaterial($m);
                                     if (strcmp($foundmat["type"], "mattext") == 0) {
                                     }
                                     if (strcmp($foundmat["type"], "matimage") == 0) {
                                         if (strlen($foundmat["material"]->getEmbedded())) {
                                             $embedded = true;
                                         }
                                     }
                                 }
                                 if ($embedded) {
                                     for ($m = 0; $m < $mat->getMaterialCount(); $m++) {
                                         $foundmat = $mat->getMaterial($m);
                                         if (strcmp($foundmat["type"], "mattext") == 0) {
                                             $answertext .= $foundmat["material"]->getContent();
                                         }
                                         if (strcmp($foundmat["type"], "matimage") == 0) {
                                             $foundimage = TRUE;
                                             $answerimage = array("imagetype" => $foundmat["material"]->getImageType(), "label" => $foundmat["material"]->getLabel(), "content" => $foundmat["material"]->getContent());
                                         }
                                     }
                                 } else {
                                     $answertext = $this->object->QTIMaterialToString($mat);
                                 }
                             }
                             $answers[$ident] = array("answertext" => $answertext, "imagefile" => $answerimage, "answerorder" => $ident);
                         }
                         break;
                 }
                 break;
         }
     }
     $feedbacks = array();
     $feedbacksgeneric = array();
     foreach ($item->resprocessing as $resprocessing) {
         foreach ($resprocessing->outcomes->decvar as $decvar) {
             if ($decvar->getVarname() == 'SCORE') {
                 $this->object->setPoints($decvar->getMaxvalue());
                 if ($decvar->getMinvalue() > 0) {
                     $this->object->setScorePartialSolutionEnabled(true);
                 }
             }
         }
         foreach ($resprocessing->respcondition as $respcondition) {
             if (!count($respcondition->setvar)) {
                 foreach ($respcondition->getConditionvar()->varequal as $varequal) {
                     $ident = $varequal->respident;
                     $answers[$ident]['correctness'] = (bool) $varequal->getContent();
                     break;
                 }
                 foreach ($respcondition->displayfeedback as $feedbackpointer) {
                     if (strlen($feedbackpointer->getLinkrefid())) {
                         foreach ($item->itemfeedback as $ifb) {
                             if (strcmp($ifb->getIdent(), $feedbackpointer->getLinkrefid()) == 0) {
                                 // found a feedback for the identifier
                                 if (count($ifb->material)) {
                                     foreach ($ifb->material as $material) {
                                         $feedbacks[$ident] = $material;
                                     }
                                 }
                                 if (count($ifb->flow_mat) > 0) {
                                     foreach ($ifb->flow_mat as $fmat) {
                                         if (count($fmat->material)) {
                                             foreach ($fmat->material as $material) {
                                                 $feedbacks[$ident] = $material;
                                             }
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             } else {
                 foreach ($respcondition->displayfeedback as $feedbackpointer) {
                     if (strlen($feedbackpointer->getLinkrefid())) {
                         foreach ($item->itemfeedback as $ifb) {
                             if ($ifb->getIdent() == "response_allcorrect") {
                                 // found a feedback for the identifier
                                 if (count($ifb->material)) {
                                     foreach ($ifb->material as $material) {
                                         $feedbacksgeneric[1] = $material;
                                     }
                                 }
                                 if (count($ifb->flow_mat) > 0) {
                                     foreach ($ifb->flow_mat as $fmat) {
                                         if (count($fmat->material)) {
                                             foreach ($fmat->material as $material) {
                                                 $feedbacksgeneric[1] = $material;
                                             }
                                         }
                                     }
                                 }
                             } else {
                                 if ($ifb->getIdent() == "response_onenotcorrect") {
                                     // found a feedback for the identifier
                                     if (count($ifb->material)) {
                                         foreach ($ifb->material as $material) {
                                             $feedbacksgeneric[0] = $material;
                                         }
                                     }
                                     if (count($ifb->flow_mat) > 0) {
                                         foreach ($ifb->flow_mat as $fmat) {
                                             if (count($fmat->material)) {
                                                 foreach ($fmat->material as $material) {
                                                     $feedbacksgeneric[0] = $material;
                                                 }
                                             }
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     $this->addGeneralMetadata($item);
     $this->object->setTitle($item->getTitle());
     $this->object->setNrOfTries($item->getMaxattempts());
     $this->object->setComment($item->getComment());
     $this->object->setAuthor($item->getAuthor());
     $this->object->setOwner($ilUser->getId());
     $this->object->setQuestion($this->object->QTIMaterialToString($item->getQuestiontext()));
     $this->object->setObjId($questionpool_id);
     $this->object->setEstimatedWorkingTime($duration["h"], $duration["m"], $duration["s"]);
     $this->object->setShuffleAnswersEnabled($shuffle);
     $this->object->setAnswerType($item->getMetadataEntry("answer_type"));
     $this->object->setOptionLabel($item->getMetadataEntry("option_label_setting"));
     $this->object->setCustomTrueOptionLabel($item->getMetadataEntry("custom_true_option_label"));
     $this->object->setCustomFalseOptionLabel($item->getMetadataEntry("custom_false_option_label"));
     $this->object->setThumbSize($item->getMetadataEntry("thumb_size"));
     $this->object->saveToDb();
     foreach ($answers as $answerData) {
         $answer = new ilAssKprimChoiceAnswer();
         $answer->setImageFsDir($this->object->getImagePath());
         $answer->setImageWebDir($this->object->getImagePathWeb());
         $answer->setPosition($answerData['answerorder']);
         $answer->setAnswertext($answerData['answertext']);
         $answer->setCorrectness($answerData['correctness']);
         if (isset($answerData['imagefile']['label'])) {
             $answer->setImageFile($answerData['imagefile']['label']);
         }
         $this->object->addAnswer($answer);
     }
     // additional content editing mode information
     $this->object->setAdditionalContentEditingMode($this->fetchAdditionalContentEditingModeInformation($item));
     $this->object->saveToDb();
     foreach ($answers as $answer) {
         if (is_array($answer["imagefile"]) && count($answer["imagefile"]) > 0) {
             $image =& base64_decode($answer["imagefile"]["content"]);
             $imagepath = $this->object->getImagePath();
             include_once "./Services/Utilities/classes/class.ilUtil.php";
             if (!file_exists($imagepath)) {
                 ilUtil::makeDirParents($imagepath);
             }
             $imagepath .= $answer["imagefile"]["label"];
             if ($fh = fopen($imagepath, "wb")) {
                 $imagefile = fwrite($fh, $image);
                 fclose($fh);
             }
         }
     }
     $feedbackSetting = $item->getMetadataEntry('feedback_setting');
     if (!is_null($feedbackSetting)) {
         $this->object->feedbackOBJ->saveSpecificFeedbackSetting($this->object->getId(), $feedbackSetting);
     }
     // handle the import of media objects in XHTML code
     foreach ($feedbacks as $ident => $material) {
         $m = $this->object->QTIMaterialToString($material);
         $feedbacks[$ident] = $m;
     }
     foreach ($feedbacksgeneric as $correctness => $material) {
         $m = $this->object->QTIMaterialToString($material);
         $feedbacksgeneric[$correctness] = $m;
     }
     $questiontext = $this->object->getQuestion();
     $answers =& $this->object->getAnswers();
     if (is_array($_SESSION["import_mob_xhtml"])) {
         include_once "./Services/MediaObjects/classes/class.ilObjMediaObject.php";
         include_once "./Services/RTE/classes/class.ilRTE.php";
         foreach ($_SESSION["import_mob_xhtml"] as $mob) {
             if ($tst_id > 0) {
                 $importfile = $this->getTstImportArchivDirectory() . '/' . $mob["uri"];
             } else {
                 $importfile = $this->getQplImportArchivDirectory() . '/' . $mob["uri"];
             }
             $GLOBALS['ilLog']->write(__METHOD__ . ': import mob from dir: ' . $importfile);
             $media_object =& ilObjMediaObject::_saveTempFileAsMediaObject(basename($importfile), $importfile, FALSE);
             ilObjMediaObject::_saveUsage($media_object->getId(), "qpl:html", $this->object->getId());
             $questiontext = str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $questiontext);
             foreach ($answers as $key => $value) {
                 $answer_obj =& $answers[$key];
                 $answer_obj->setAnswertext(str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $answer_obj->getAnswertext()));
             }
             foreach ($feedbacks as $ident => $material) {
                 $feedbacks[$ident] = str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $material);
             }
             foreach ($feedbacksgeneric as $correctness => $material) {
                 $feedbacksgeneric[$correctness] = str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $material);
             }
         }
     }
     $this->object->setQuestion(ilRTE::_replaceMediaObjectImageSrc($questiontext, 1));
     foreach ($answers as $key => $value) {
         $answer_obj =& $answers[$key];
         $answer_obj->setAnswertext(ilRTE::_replaceMediaObjectImageSrc($answer_obj->getAnswertext(), 1));
     }
     foreach ($feedbacks as $ident => $material) {
         $this->object->feedbackOBJ->importSpecificAnswerFeedback($this->object->getId(), $ident, ilRTE::_replaceMediaObjectImageSrc($material, 1));
     }
     foreach ($feedbacksgeneric as $correctness => $material) {
         $this->object->feedbackOBJ->importGenericFeedback($this->object->getId(), $correctness, ilRTE::_replaceMediaObjectImageSrc($material, 1));
     }
     $this->object->saveToDb();
     if (count($item->suggested_solutions)) {
         foreach ($item->suggested_solutions as $suggested_solution) {
             $this->object->setSuggestedSolution($suggested_solution["solution"]->getContent(), $suggested_solution["gap_index"], true);
         }
         $this->object->saveToDb();
     }
     if ($tst_id > 0) {
         $q_1_id = $this->object->getId();
         $question_id = $this->object->duplicate(true, null, null, null, $tst_id);
         $tst_object->questions[$question_counter++] = $question_id;
         $import_mapping[$item->getIdent()] = array("pool" => $q_1_id, "test" => $question_id);
     } else {
         $import_mapping[$item->getIdent()] = array("pool" => $this->object->getId(), "test" => 0);
     }
     //$ilLog->write(strftime("%D %T") . ": finished import multiple choice question (single response)");
 }
 /**
  * Creates a question from a QTI file
  *
  * Receives parameters from a QTI parser and creates a valid ILIAS question object
  *
  * @param object $item The QTI item object
  * @param integer $questionpool_id The id of the parent questionpool
  * @param integer $tst_id The id of the parent test if the question is part of a test
  * @param object $tst_object A reference to the parent test object
  * @param integer $question_counter A reference to a question counter to count the questions of an imported question pool
  * @param array $import_mapping An array containing references to included ILIAS objects
  * @access public
  */
 function fromXML(&$item, $questionpool_id, &$tst_id, &$tst_object, &$question_counter, &$import_mapping)
 {
     global $ilUser, $ilLog;
     // empty session variable for imported xhtml mobs
     unset($_SESSION["import_mob_xhtml"]);
     $presentation = $item->getPresentation();
     $duration = $item->getDuration();
     $now = getdate();
     $created = sprintf("%04d%02d%02d%02d%02d%02d", $now['year'], $now['mon'], $now['mday'], $now['hours'], $now['minutes'], $now['seconds']);
     // get the generic feedbach
     $feedbacksgeneric = array();
     if (isset($item->itemfeedback)) {
         foreach ($item->itemfeedback as $ifb) {
             if (strcmp($ifb->getIdent(), "response_allcorrect") == 0) {
                 // found a feedback for the identifier
                 if (count($ifb->material)) {
                     foreach ($ifb->material as $material) {
                         $feedbacksgeneric[1] = $material;
                     }
                 }
                 if (count($ifb->flow_mat) > 0) {
                     foreach ($ifb->flow_mat as $fmat) {
                         if (count($fmat->material)) {
                             foreach ($fmat->material as $material) {
                                 $feedbacksgeneric[1] = $material;
                             }
                         }
                     }
                 }
             } else {
                 if (strcmp($ifb->getIdent(), "response_onenotcorrect") == 0) {
                     // found a feedback for the identifier
                     if (count($ifb->material)) {
                         foreach ($ifb->material as $material) {
                             $feedbacksgeneric[0] = $material;
                         }
                     }
                     if (count($ifb->flow_mat) > 0) {
                         foreach ($ifb->flow_mat as $fmat) {
                             if (count($fmat->material)) {
                                 foreach ($fmat->material as $material) {
                                     $feedbacksgeneric[0] = $material;
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     // set question properties
     $this->addGeneralMetadata($item);
     $this->object->setTitle($item->getTitle());
     $this->object->setNrOfTries($item->getMaxattempts());
     $this->object->setComment($item->getComment());
     $this->object->setAuthor($item->getAuthor());
     $this->object->setOwner($ilUser->getId());
     $this->object->setQuestion($this->object->QTIMaterialToString($item->getQuestiontext()));
     $this->object->setObjId($questionpool_id);
     $this->object->setEstimatedWorkingTime($duration["h"], $duration["m"], $duration["s"]);
     $this->object->setAccountsXML(base64_decode($item->getMetadataEntry('accounts_content')));
     $this->object->setPoints($item->getMetadataEntry("points"));
     // additional content editing mode information
     $this->object->setAdditionalContentEditingMode($this->fetchAdditionalContentEditingModeInformation($item));
     // first save the question  without its parts (to get a new question id)
     $this->object->saveToDb('', false);
     // then create the parts
     $parts = unserialize($item->getMetadataEntry('booking_parts'));
     if (is_array($parts)) {
         for ($i = 0; $i < count($parts); $i++) {
             $part = $parts[$i];
             // since plugin version 1.1.7 the text of the questions parts is added as material to the presentation
             // this enables images in the parts text
             // the material index 0 is used for the question text
             if (isset($item->presentation->material[$i + 1])) {
                 $part['text'] = $this->object->QTIMaterialToString($item->presentation->material[$i + 1]);
             }
             // create and add a new part
             $part_obj = $this->object->getPart();
             $part_obj->setPosition($part['position']);
             $part_obj->setText($part['text']);
             $part_obj->setMaxPoints($part['max_points']);
             $part_obj->setMaxLines($part['max_lines']);
             $part_obj->setBookingXML(base64_decode($part['booking_def']));
             $part_obj->write();
         }
     }
     // convert the generic feedback
     foreach ($feedbacksgeneric as $correctness => $material) {
         $m = $this->object->QTIMaterialToString($material);
         $feedbacksgeneric[$correctness] = $m;
     }
     // handle the import of media objects in XHTML code
     $questiontext = $this->object->getQuestion();
     if (is_array($_SESSION["import_mob_xhtml"])) {
         include_once "./Services/MediaObjects/classes/class.ilObjMediaObject.php";
         include_once "./Services/RTE/classes/class.ilRTE.php";
         foreach ($_SESSION["import_mob_xhtml"] as $mob) {
             if ($tst_id > 0) {
                 $importfile = $this->getTstImportArchivDirectory() . '/' . $mob["uri"];
             } else {
                 $importfile = $this->getQplImportArchivDirectory() . '/' . $mob["uri"];
             }
             global $ilLog;
             $ilLog->write($importfile);
             $media_object =& ilObjMediaObject::_saveTempFileAsMediaObject(basename($importfile), $importfile, FALSE);
             ilObjMediaObject::_saveUsage($media_object->getId(), "qpl:html", $this->object->getId());
             // images in question text
             $questiontext = str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $questiontext);
             // images in question parts
             foreach ($this->object->getParts() as $part_obj) {
                 $part_obj->setText(str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $part_obj->getText()));
             }
             // images in feedback
             foreach ($feedbacksgeneric as $correctness => $material) {
                 $feedbacksgeneric[$correctness] = str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $material);
             }
         }
     }
     $this->object->setQuestion(ilRTE::_replaceMediaObjectImageSrc($questiontext, 1));
     foreach ($this->object->getParts() as $part_obj) {
         $part_obj->setText(ilRTE::_replaceMediaObjectImageSrc($part_obj->getText(), 1));
         $part_obj->write();
     }
     foreach ($feedbacksgeneric as $correctness => $material) {
         $this->object->feedbackOBJ->importGenericFeedback($this->object->getId(), $correctness, ilRTE::_replaceMediaObjectImageSrc($material, 1));
     }
     if (count($item->suggested_solutions)) {
         foreach ($item->suggested_solutions as $suggested_solution) {
             $this->object->setSuggestedSolution($suggested_solution["solution"]->getContent(), $suggested_solution["gap_index"], true);
         }
     }
     // Now save the question again
     // (this also recalculates the maximum points)
     $this->object->saveToDb('', true);
     // import mapping for tests
     if ($tst_id > 0) {
         $q_1_id = $this->object->getId();
         $question_id = $this->object->duplicate(true, null, null, null, $tst_id);
         $tst_object->questions[$question_counter++] = $question_id;
         $import_mapping[$item->getIdent()] = array("pool" => $q_1_id, "test" => $question_id);
     } else {
         $import_mapping[$item->getIdent()] = array("pool" => $this->object->getId(), "test" => 0);
     }
 }
 /**
  * Creates a question from a QTI file
  *
  * Receives parameters from a QTI parser and creates a valid ILIAS question object
  *
  * @param object $item The QTI item object
  * @param integer $questionpool_id The id of the parent questionpool
  * @param integer $tst_id The id of the parent test if the question is part of a test
  * @param object $tst_object A reference to the parent test object
  * @param integer $question_counter A reference to a question counter to count the questions of an imported question pool
  * @param array $import_mapping An array containing references to included ILIAS objects
  * @access public
  */
 function fromXML(&$item, $questionpool_id, &$tst_id, &$tst_object, &$question_counter, &$import_mapping)
 {
     global $ilUser;
     // empty session variable for imported xhtml mobs
     unset($_SESSION["import_mob_xhtml"]);
     $presentation = $item->getPresentation();
     $duration = $item->getDuration();
     $shuffle = 0;
     $now = getdate();
     $created = sprintf("%04d%02d%02d%02d%02d%02d", $now['year'], $now['mon'], $now['mday'], $now['hours'], $now['minutes'], $now['seconds']);
     $answers = array();
     foreach ($presentation->order as $entry) {
         switch ($entry["type"]) {
             case "response":
                 $response = $presentation->response[$entry["index"]];
                 $rendertype = $response->getRenderType();
                 switch (strtolower(get_class($response->getRenderType()))) {
                     case "ilqtirenderchoice":
                         $shuffle = $rendertype->getShuffle();
                         $answerorder = 0;
                         $foundimage = FALSE;
                         foreach ($rendertype->response_labels as $response_label) {
                             $ident = $response_label->getIdent();
                             $answertext = "";
                             $answerimage = array();
                             foreach ($response_label->material as $mat) {
                                 $embedded = false;
                                 for ($m = 0; $m < $mat->getMaterialCount(); $m++) {
                                     $foundmat = $mat->getMaterial($m);
                                     if (strcmp($foundmat["type"], "mattext") == 0) {
                                     }
                                     if (strcmp($foundmat["type"], "matimage") == 0) {
                                         if (strlen($foundmat["material"]->getEmbedded())) {
                                             $embedded = true;
                                         }
                                     }
                                 }
                                 if ($embedded) {
                                     for ($m = 0; $m < $mat->getMaterialCount(); $m++) {
                                         $foundmat = $mat->getMaterial($m);
                                         if (strcmp($foundmat["type"], "mattext") == 0) {
                                             $answertext .= $foundmat["material"]->getContent();
                                         }
                                         if (strcmp($foundmat["type"], "matimage") == 0) {
                                             $foundimage = TRUE;
                                             $answerimage = array("imagetype" => $foundmat["material"]->getImageType(), "label" => $foundmat["material"]->getLabel(), "content" => $foundmat["material"]->getContent());
                                         }
                                     }
                                 } else {
                                     $answertext = $this->object->QTIMaterialToString($mat);
                                 }
                             }
                             $answers[$ident] = array("answertext" => $answertext, "imagefile" => $answerimage, "points" => 0, "answerorder" => $answerorder++, "points_unchecked" => 0, "action" => "");
                         }
                         break;
                 }
                 break;
         }
     }
     $responses = array();
     $feedbacks = array();
     $feedbacksgeneric = array();
     foreach ($item->resprocessing as $resprocessing) {
         foreach ($resprocessing->respcondition as $respcondition) {
             $ident = "";
             $correctness = 1;
             $conditionvar = $respcondition->getConditionvar();
             foreach ($conditionvar->order as $order) {
                 switch ($order["field"]) {
                     case "arr_not":
                         $correctness = 0;
                         break;
                     case "varequal":
                         $ident = $conditionvar->varequal[$order["index"]]->getContent();
                         break;
                 }
             }
             foreach ($respcondition->setvar as $setvar) {
                 if (strcmp($ident, "") != 0) {
                     if ($correctness) {
                         $answers[$ident]["action"] = $setvar->getAction();
                         $answers[$ident]["points"] = $setvar->getContent();
                         if (count($respcondition->displayfeedback)) {
                             foreach ($respcondition->displayfeedback as $feedbackpointer) {
                                 if (strlen($feedbackpointer->getLinkrefid())) {
                                     foreach ($item->itemfeedback as $ifb) {
                                         if (strcmp($ifb->getIdent(), "response_allcorrect") == 0) {
                                             // found a feedback for the identifier
                                             if (count($ifb->material)) {
                                                 foreach ($ifb->material as $material) {
                                                     $feedbacksgeneric[1] = $material;
                                                 }
                                             }
                                             if (count($ifb->flow_mat) > 0) {
                                                 foreach ($ifb->flow_mat as $fmat) {
                                                     if (count($fmat->material)) {
                                                         foreach ($fmat->material as $material) {
                                                             $feedbacksgeneric[1] = $material;
                                                         }
                                                     }
                                                 }
                                             }
                                         } else {
                                             if (strcmp($ifb->getIdent(), "response_onenotcorrect") == 0) {
                                                 // found a feedback for the identifier
                                                 if (count($ifb->material)) {
                                                     foreach ($ifb->material as $material) {
                                                         $feedbacksgeneric[0] = $material;
                                                     }
                                                 }
                                                 if (count($ifb->flow_mat) > 0) {
                                                     foreach ($ifb->flow_mat as $fmat) {
                                                         if (count($fmat->material)) {
                                                             foreach ($fmat->material as $material) {
                                                                 $feedbacksgeneric[0] = $material;
                                                             }
                                                         }
                                                     }
                                                 }
                                             }
                                         }
                                         if (strcmp($ifb->getIdent(), $feedbackpointer->getLinkrefid()) == 0) {
                                             // found a feedback for the identifier
                                             if (count($ifb->material)) {
                                                 foreach ($ifb->material as $material) {
                                                     $feedbacks[$ident] = $material;
                                                 }
                                             }
                                             if (count($ifb->flow_mat) > 0) {
                                                 foreach ($ifb->flow_mat as $fmat) {
                                                     if (count($fmat->material)) {
                                                         foreach ($fmat->material as $material) {
                                                             $feedbacks[$ident] = $material;
                                                         }
                                                     }
                                                 }
                                             }
                                         }
                                     }
                                 }
                             }
                         }
                     } else {
                         $answers[$ident]["action"] = $setvar->getAction();
                         $answers[$ident]["points_unchecked"] = $setvar->getContent();
                     }
                 }
             }
         }
     }
     $this->addGeneralMetadata($item);
     $this->object->setTitle($item->getTitle());
     $this->object->setNrOfTries($item->getMaxattempts());
     $this->object->setComment($item->getComment());
     $this->object->setAuthor($item->getAuthor());
     $this->object->setOwner($ilUser->getId());
     $this->object->setQuestion($this->object->QTIMaterialToString($item->getQuestiontext()));
     $this->object->setObjId($questionpool_id);
     $this->object->setEstimatedWorkingTime($duration["h"], $duration["m"], $duration["s"]);
     $this->object->setShuffle($shuffle);
     $this->object->setThumbSize($item->getMetadataEntry("thumb_size"));
     foreach ($answers as $answer) {
         if (is_array($answer["imagefile"]) && count($answer["imagefile"]) > 0) {
             $this->object->isSingleline = true;
         }
         $this->object->addAnswer($answer["answertext"], $answer["points"], $answer["answerorder"], $answer["imagefile"]["label"]);
     }
     // additional content editing mode information
     $this->object->setAdditionalContentEditingMode($this->fetchAdditionalContentEditingModeInformation($item));
     $this->object->saveToDb();
     foreach ($answers as $answer) {
         if (is_array($answer["imagefile"]) && count($answer["imagefile"]) > 0) {
             $image =& base64_decode($answer["imagefile"]["content"]);
             $imagepath = $this->object->getImagePath();
             include_once "./Services/Utilities/classes/class.ilUtil.php";
             if (!file_exists($imagepath)) {
                 ilUtil::makeDirParents($imagepath);
             }
             $imagepath .= $answer["imagefile"]["label"];
             $fh = fopen($imagepath, "wb");
             if ($fh == false) {
             } else {
                 $imagefile = fwrite($fh, $image);
                 fclose($fh);
             }
         }
     }
     foreach ($feedbacks as $ident => $material) {
         $m = $this->object->QTIMaterialToString($material);
         $feedbacks[$ident] = $m;
     }
     foreach ($feedbacksgeneric as $correctness => $material) {
         $m = $this->object->QTIMaterialToString($material);
         $feedbacksgeneric[$correctness] = $m;
     }
     // handle the import of media objects in XHTML code
     $questiontext = $this->object->getQuestion();
     $answers =& $this->object->getAnswers();
     if (is_array($_SESSION["import_mob_xhtml"])) {
         include_once "./Services/MediaObjects/classes/class.ilObjMediaObject.php";
         include_once "./Services/RTE/classes/class.ilRTE.php";
         foreach ($_SESSION["import_mob_xhtml"] as $mob) {
             if ($tst_id > 0) {
                 $importfile = $this->getTstImportArchivDirectory() . '/' . $mob["uri"];
             } else {
                 $importfile = $this->getQplImportArchivDirectory() . '/' . $mob["uri"];
             }
             $GLOBALS['ilLog']->write(__METHOD__ . ': import mob from dir: ' . $importfile);
             $media_object =& ilObjMediaObject::_saveTempFileAsMediaObject(basename($importfile), $importfile, FALSE);
             ilObjMediaObject::_saveUsage($media_object->getId(), "qpl:html", $this->object->getId());
             $questiontext = str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $questiontext);
             foreach ($answers as $key => $value) {
                 $answer_obj = $answers[$key];
                 $answer_obj->setAnswertext(str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $answer_obj->getAnswertext()));
             }
             foreach ($feedbacks as $ident => $material) {
                 $feedbacks[$ident] = str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $material);
             }
             foreach ($feedbacksgeneric as $correctness => $material) {
                 $feedbacksgeneric[$correctness] = str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $material);
             }
         }
     }
     $this->object->setQuestion(ilRTE::_replaceMediaObjectImageSrc($questiontext, 1));
     foreach ($answers as $key => $value) {
         $answer_obj =& $answers[$key];
         $answer_obj->setAnswertext(ilRTE::_replaceMediaObjectImageSrc($answer_obj->getAnswertext(), 1));
     }
     foreach ($feedbacks as $ident => $material) {
         $this->object->feedbackOBJ->importSpecificAnswerFeedback($this->object->getId(), $ident, ilRTE::_replaceMediaObjectImageSrc($material, 1));
     }
     foreach ($feedbacksgeneric as $correctness => $material) {
         $this->object->feedbackOBJ->importGenericFeedback($this->object->getId(), $correctness, ilRTE::_replaceMediaObjectImageSrc($material, 1));
     }
     $this->object->saveToDb();
     if (count($item->suggested_solutions)) {
         foreach ($item->suggested_solutions as $suggested_solution) {
             $this->object->setSuggestedSolution($suggested_solution["solution"]->getContent(), $suggested_solution["gap_index"], true);
         }
         $this->object->saveToDb();
     }
     if ($tst_id > 0) {
         $q_1_id = $this->object->getId();
         $question_id = $this->object->duplicate(true, null, null, null, $tst_id);
         $tst_object->questions[$question_counter++] = $question_id;
         $import_mapping[$item->getIdent()] = array("pool" => $q_1_id, "test" => $question_id);
     } else {
         $import_mapping[$item->getIdent()] = array("pool" => $this->object->getId(), "test" => 0);
     }
 }
 /**
  * Creates a question from a QTI file
  *
  * Receives parameters from a QTI parser and creates a valid ILIAS question object
  *
  * @param object $item The QTI item object
  * @param integer $questionpool_id The id of the parent questionpool
  * @param integer $tst_id The id of the parent test if the question is part of a test
  * @param object $tst_object A reference to the parent test object
  * @param integer $question_counter A reference to a question counter to count the questions of an imported question pool
  * @param array $import_mapping An array containing references to included ILIAS objects
  * @access public
  */
 function fromXML(&$item, $questionpool_id, &$tst_id, &$tst_object, &$question_counter, &$import_mapping)
 {
     global $ilUser;
     // empty session variable for imported xhtml mobs
     unset($_SESSION["import_mob_xhtml"]);
     $presentation = $item->getPresentation();
     $duration = $item->getDuration();
     $now = getdate();
     $created = sprintf("%04d%02d%02d%02d%02d%02d", $now['year'], $now['mon'], $now['mday'], $now['hours'], $now['minutes'], $now['seconds']);
     $feedbacksgeneric = array();
     $this->object->setTitle($item->getTitle());
     $this->object->setComment($item->getComment());
     $this->object->setAuthor($item->getAuthor());
     $this->object->setOwner($ilUser->getId());
     $this->object->setQuestion($this->object->QTIMaterialToString($item->getQuestiontext()));
     $this->object->setObjId($questionpool_id);
     $this->object->setEstimatedWorkingTime($duration["h"], $duration["m"], $duration["s"]);
     $this->object->setPoints($item->getMetadataEntry("points"));
     $this->object->setOptionString($item->getMetadataEntry("option_string"));
     $this->object->setSampleSolution($item->getMetadataEntry("sample_solution"));
     $this->object->saveToDb('', false);
     // handle the import of media objects in XHTML code
     $questiontext = $this->object->getQuestion();
     if (is_array($_SESSION["import_mob_xhtml"])) {
         include_once "./Services/MediaObjects/classes/class.ilObjMediaObject.php";
         include_once "./Services/RTE/classes/class.ilRTE.php";
         foreach ($_SESSION["import_mob_xhtml"] as $mob) {
             if ($tst_id > 0) {
                 include_once "./Modules/Test/classes/class.ilObjTest.php";
                 $importfile = ilObjTest::_getImportDirectory() . '/' . $mob["uri"];
             } else {
                 include_once "./Modules/TestQuestionPool/classes/class.ilObjQuestionPool.php";
                 $importfile = ilObjQuestionPool::_getImportDirectory() . '/' . $mob["uri"];
             }
             $media_object =& ilObjMediaObject::_saveTempFileAsMediaObject(basename($importfile), $importfile, FALSE);
             ilObjMediaObject::_saveUsage($media_object->getId(), "qpl:html", $this->object->getId());
             $questiontext = str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $questiontext);
         }
     }
     $this->object->setQuestion(ilRTE::_replaceMediaObjectImageSrc($questiontext, 1));
     // feedback
     $feedbacksgeneric = array();
     foreach ($item->itemfeedback as $ifb) {
         if (strcmp($ifb->getIdent(), "response_allcorrect") == 0) {
             // found a feedback for the identifier
             if (count($ifb->material)) {
                 foreach ($ifb->material as $material) {
                     $feedbacksgeneric[1] = $material;
                 }
             }
             if (count($ifb->flow_mat) > 0) {
                 foreach ($ifb->flow_mat as $fmat) {
                     if (count($fmat->material)) {
                         foreach ($fmat->material as $material) {
                             $feedbacksgeneric[1] = $material;
                         }
                     }
                 }
             }
         } else {
             if (strcmp($ifb->getIdent(), "response_onenotcorrect") == 0) {
                 // found a feedback for the identifier
                 if (count($ifb->material)) {
                     foreach ($ifb->material as $material) {
                         $feedbacksgeneric[0] = $material;
                     }
                 }
                 if (count($ifb->flow_mat) > 0) {
                     foreach ($ifb->flow_mat as $fmat) {
                         if (count($fmat->material)) {
                             foreach ($fmat->material as $material) {
                                 $feedbacksgeneric[0] = $material;
                             }
                         }
                     }
                 }
             }
         }
     }
     // genericFeedback
     foreach ($feedbacksgeneric as $correctness => $material) {
         $m = $this->object->QTIMaterialToString($material);
         $feedbacksgeneric[$correctness] = $m;
     }
     foreach ($feedbacksgeneric as $correctness => $material) {
         //$this->object->saveFeedbackGeneric($correctness, ilRTE::_replaceMediaObjectImageSrc($material, 1));
         $this->object->feedbackOBJ->importGenericFeedback($this->object->getId(), $correctness, ilRTE::_replaceMediaObjectImageSrc($material, 1));
     }
     $this->object->saveToDb();
     if ($tst_id > 0) {
         $q_1_id = $this->object->getId();
         $question_id = $this->object->duplicate(true);
         $tst_object->questions[$question_counter++] = $question_id;
         $import_mapping[$item->getIdent()] = array("pool" => $q_1_id, "test" => $question_id);
     } else {
         $import_mapping[$item->getIdent()] = array("pool" => $this->object->getId(), "test" => 0);
     }
 }
 /**
  * Creates a question from a QTI file
  *
  * Receives parameters from a QTI parser and creates a valid ILIAS question object
  *
  * @param object $item The QTI item object
  * @param integer $questionpool_id The id of the parent questionpool
  * @param integer $tst_id The id of the parent test if the question is part of a test
  * @param object $tst_object A reference to the parent test object
  * @param integer $question_counter A reference to a question counter to count the questions of an imported question pool
  * @param array $import_mapping An array containing references to included ILIAS objects
  * @access public
  */
 function fromXML(&$item, $questionpool_id, &$tst_id, &$tst_object, &$question_counter, &$import_mapping)
 {
     global $ilUser;
     // empty session variable for imported xhtml mobs
     unset($_SESSION["import_mob_xhtml"]);
     $presentation = $item->getPresentation();
     $duration = $item->getDuration();
     $shuffle = 0;
     $idents = array();
     $now = getdate();
     $created = sprintf("%04d%02d%02d%02d%02d%02d", $now['year'], $now['mon'], $now['mday'], $now['hours'], $now['minutes'], $now['seconds']);
     $gaps = array();
     foreach ($presentation->order as $entry) {
         switch ($entry["type"]) {
             case "response":
                 $response = $presentation->response[$entry["index"]];
                 if ($response->getResponseType() == RT_RESPONSE_STR) {
                     array_push($idents, $response->getIdent());
                 }
                 break;
         }
     }
     $responses = array();
     $feedbacksgeneric = array();
     foreach ($item->resprocessing as $resprocessing) {
         foreach ($resprocessing->respcondition as $respcondition) {
             $ident = "";
             $correctness = 1;
             $conditionvar = $respcondition->getConditionvar();
             foreach ($conditionvar->order as $order) {
                 switch ($order["field"]) {
                     case "varsubset":
                         $respident = $conditionvar->varsubset[$order["index"]]->getRespident();
                         $content = $conditionvar->varsubset[$order["index"]]->getContent();
                         if (!is_array($responses[$respident])) {
                             $responses[$respident] = array();
                         }
                         $vars = split(",", $content);
                         foreach ($vars as $var) {
                             array_push($responses[$respident], array("solution" => $var, "points" => ""));
                         }
                         break;
                 }
             }
             foreach ($respcondition->setvar as $setvar) {
                 if (strcmp($setvar->getVarname(), "matches") == 0 && $setvar->getAction() == ACTION_ADD) {
                     foreach ($responses[$respident] as $idx => $solutionarray) {
                         if (strlen($solutionarray["points"] == 0)) {
                             $responses[$respident][$idx]["points"] = $setvar->getContent();
                         }
                     }
                 }
             }
             foreach ($resprocessing->respcondition as $respcondition) {
                 foreach ($respcondition->displayfeedback as $feedbackpointer) {
                     if (strlen($feedbackpointer->getLinkrefid())) {
                         foreach ($item->itemfeedback as $ifb) {
                             if (strcmp($ifb->getIdent(), "response_allcorrect") == 0) {
                                 // found a feedback for the identifier
                                 if (count($ifb->material)) {
                                     foreach ($ifb->material as $material) {
                                         $feedbacksgeneric[1] = $material;
                                     }
                                 }
                                 if (count($ifb->flow_mat) > 0) {
                                     foreach ($ifb->flow_mat as $fmat) {
                                         if (count($fmat->material)) {
                                             foreach ($fmat->material as $material) {
                                                 $feedbacksgeneric[1] = $material;
                                             }
                                         }
                                     }
                                 }
                             } else {
                                 if (strcmp($ifb->getIdent(), "response_onenotcorrect") == 0) {
                                     // found a feedback for the identifier
                                     if (count($ifb->material)) {
                                         foreach ($ifb->material as $material) {
                                             $feedbacksgeneric[0] = $material;
                                         }
                                     }
                                     if (count($ifb->flow_mat) > 0) {
                                         foreach ($ifb->flow_mat as $fmat) {
                                             if (count($fmat->material)) {
                                                 foreach ($fmat->material as $material) {
                                                     $feedbacksgeneric[0] = $material;
                                                 }
                                             }
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     $this->object->setTitle($item->getTitle());
     $this->object->setNrOfTries($item->getMaxattempts());
     $this->object->setComment($item->getComment());
     $this->object->setAuthor($item->getAuthor());
     $this->object->setOwner($ilUser->getId());
     $this->object->setQuestion($this->object->QTIMaterialToString($item->getQuestiontext()));
     $this->object->setObjId($questionpool_id);
     $this->object->setEstimatedWorkingTime($duration["h"], $duration["m"], $duration["s"]);
     $textrating = $item->getMetadataEntry("textrating");
     if (strlen($textrating) == 0) {
         $textrating = "ci";
     }
     $this->object->setTextRating($textgap_rating);
     $this->object->setCorrectAnswers($item->getMetadataEntry("correctanswers"));
     $response = current($responses);
     $counter = 0;
     if (is_array($response)) {
         foreach ($response as $answer) {
             $this->object->addAnswer($answer["solution"], $answer["points"], $counter);
             $counter++;
         }
     }
     $this->object->saveToDb();
     if (count($item->suggested_solutions)) {
         foreach ($item->suggested_solutions as $suggested_solution) {
             $this->object->setSuggestedSolution($suggested_solution["solution"]->getContent(), $suggested_solution["gap_index"], true);
         }
         $this->object->saveToDb();
     }
     foreach ($feedbacksgeneric as $correctness => $material) {
         $m = $this->object->QTIMaterialToString($material);
         $feedbacksgeneric[$correctness] = $m;
     }
     // handle the import of media objects in XHTML code
     $questiontext = $this->object->getQuestion();
     if (is_array($_SESSION["import_mob_xhtml"])) {
         include_once "./Services/MediaObjects/classes/class.ilObjMediaObject.php";
         include_once "./Services/RTE/classes/class.ilRTE.php";
         foreach ($_SESSION["import_mob_xhtml"] as $mob) {
             if ($tst_id > 0) {
                 $importfile = $this->getTstImportArchivDirectory() . '/' . $mob["uri"];
             } else {
                 $importfile = $this->getQplImportArchivDirectory() . '/' . $mob["uri"];
             }
             $GLOBALS['ilLog']->write(__METHOD__ . ': import mob from dir: ' . $importfile);
             $media_object =& ilObjMediaObject::_saveTempFileAsMediaObject(basename($importfile), $importfile, FALSE);
             ilObjMediaObject::_saveUsage($media_object->getId(), "qpl:html", $this->object->getId());
             $questiontext = str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $questiontext);
             foreach ($feedbacksgeneric as $correctness => $material) {
                 $feedbacksgeneric[$correctness] = str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $material);
             }
         }
     }
     $this->object->setQuestion(ilRTE::_replaceMediaObjectImageSrc($questiontext, 1));
     foreach ($feedbacksgeneric as $correctness => $material) {
         $this->object->saveFeedbackGeneric($correctness, ilRTE::_replaceMediaObjectImageSrc($material, 1));
     }
     $this->object->saveToDb();
     if ($tst_id > 0) {
         $q_1_id = $this->object->getId();
         $question_id = $this->object->duplicate(true, null, null, null, $tst_id);
         $tst_object->questions[$question_counter++] = $question_id;
         $import_mapping[$item->getIdent()] = array("pool" => $q_1_id, "test" => $question_id);
     } else {
         $import_mapping[$item->getIdent()] = array("pool" => $this->object->getId(), "test" => 0);
     }
 }
 /**
  * Receives parameters from a QTI parser and creates a valid ILIAS test object
  *
  * @param object $assessment The QTI assessment object
  * @access public
  */
 function fromXML(&$assessment)
 {
     unset($_SESSION["import_mob_xhtml"]);
     $this->setDescription($assessment->getComment());
     $this->setTitle($assessment->getTitle());
     foreach ($assessment->objectives as $objectives) {
         foreach ($objectives->materials as $material) {
             $this->setIntroduction($this->QTIMaterialToString($material));
         }
     }
     if ($assessment->getPresentationMaterial()) {
         $this->setFinalStatement($this->QTIMaterialToString($assessment->getPresentationMaterial()->getMaterial(0)));
     }
     foreach ($assessment->assessmentcontrol as $assessmentcontrol) {
         switch ($assessmentcontrol->getSolutionswitch()) {
             case "Yes":
                 $this->setInstantFeedbackSolution(1);
                 break;
             default:
                 $this->setInstantFeedbackSolution(0);
                 break;
         }
     }
     foreach ($assessment->qtimetadata as $metadata) {
         switch ($metadata["label"]) {
             case "test_type":
                 // for old tests with a test type
                 $type = $metadata["entry"];
                 switch ($type) {
                     case 1:
                         // assessment
                         $this->setAnonymity(1);
                         break;
                     case 2:
                         // self assessment
                         break;
                     case 4:
                         // online exam
                         $this->setFixedParticipants(1);
                         $this->setListOfQuestionsSettings(7);
                         $this->setShowSolutionPrintview(1);
                         break;
                     case 5:
                         // varying random test
                         break;
                 }
                 break;
             case "sequence_settings":
                 $this->setSequenceSettings($metadata["entry"]);
                 break;
             case "author":
                 $this->setAuthor($metadata["entry"]);
                 break;
             case "nr_of_tries":
                 $this->setNrOfTries($metadata["entry"]);
                 break;
             case "kiosk":
                 $this->setKiosk($metadata["entry"]);
                 break;
             case "showfinalstatement":
                 $this->setShowFinalStatement($metadata["entry"]);
                 break;
             case "showinfo":
                 $this->setShowInfo($metadata["entry"]);
                 break;
             case "forcejs":
                 $this->setForceJS($metadata["entry"]);
                 break;
             case "customstyle":
                 $this->setCustomStyle($metadata["entry"]);
                 break;
             case "hide_previous_results":
                 if ($metadata["entry"] == 0) {
                     $this->setUsePreviousAnswers(1);
                 } else {
                     $this->setUsePreviousAnswers(0);
                 }
                 break;
             case "use_previous_answers":
                 $this->setUsePreviousAnswers($metadata["entry"]);
                 break;
             case "answer_feedback":
                 $this->setAnswerFeedback($metadata["entry"]);
                 break;
             case "hide_title_points":
                 $this->setTitleOutput($metadata["entry"]);
                 break;
             case "title_output":
                 $this->setTitleOutput($metadata["entry"]);
                 break;
             case "random_test":
                 $this->setRandomTest($metadata["entry"]);
                 break;
             case "random_question_count":
                 $this->setRandomQuestionCount($metadata["entry"]);
                 break;
             case "results_presentation":
                 $this->setResultsPresentation($metadata["entry"]);
                 break;
             case "reset_processing_time":
                 $this->setResetProcessingTime($metadata["entry"]);
                 break;
             case "instant_verification":
                 $this->setInstantFeedbackSolution($metadata["entry"]);
                 break;
             case "answer_feedback_points":
                 $this->setAnswerFeedbackPoints($metadata["entry"]);
                 break;
             case "anonymity":
                 $this->setAnonymity($metadata["entry"]);
                 break;
             case "show_cancel":
                 $this->setShowCancel($metadata["entry"]);
                 break;
             case "show_marker":
                 $this->setShowMarker($metadata["entry"]);
                 break;
             case "fixed_participants":
                 $this->setFixedParticipants($metadata["entry"]);
                 break;
             case "score_reporting":
                 $this->setScoreReporting($metadata["entry"]);
                 break;
             case "shuffle_questions":
                 $this->setShuffleQuestions($metadata["entry"]);
                 break;
             case "count_system":
                 $this->setCountSystem($metadata["entry"]);
                 break;
             case "mc_scoring":
                 $this->setMCScoring($metadata["entry"]);
                 break;
             case "mailnotification":
                 $this->setMailNotification($metadata["entry"]);
                 break;
             case "mailnottype":
                 $this->setMailNotificationType($metadata["entry"]);
                 break;
             case "exportsettings":
                 $this->setExportSettings($metadata['exportsettings']);
                 break;
             case "score_cutting":
                 $this->setScoreCutting($metadata["entry"]);
                 break;
             case "password":
                 $this->setPassword($metadata["entry"]);
                 break;
             case "allowedUsers":
                 $this->setAllowedUsers($metadata["entry"]);
                 break;
             case "allowedUsersTimeGap":
                 $this->setAllowedUsersTimeGap($metadata["entry"]);
                 break;
             case "pass_scoring":
                 $this->setPassScoring($metadata["entry"]);
                 break;
             case "show_summary":
                 $this->setListOfQuestionsSettings($metadata["entry"]);
                 break;
             case "reporting_date":
                 $iso8601period = $metadata["entry"];
                 if (preg_match("/P(\\d+)Y(\\d+)M(\\d+)DT(\\d+)H(\\d+)M(\\d+)S/", $iso8601period, $matches)) {
                     $this->setReportingDate(sprintf("%02d%02d%02d%02d%02d%02d", $matches[1], $matches[2], $matches[3], $matches[4], $matches[5], $matches[6]));
                 }
                 break;
             case "processing_time":
                 $this->setProcessingTime($metadata['entry']);
                 break;
             case "starting_time":
                 $iso8601period = $metadata["entry"];
                 if (preg_match("/P(\\d+)Y(\\d+)M(\\d+)DT(\\d+)H(\\d+)M(\\d+)S/", $iso8601period, $matches)) {
                     $this->setStartingTime(sprintf("%02d%02d%02d%02d%02d%02d", $matches[1], $matches[2], $matches[3], $matches[4], $matches[5], $matches[6]));
                 }
                 break;
             case "ending_time":
                 $iso8601period = $metadata["entry"];
                 if (preg_match("/P(\\d+)Y(\\d+)M(\\d+)DT(\\d+)H(\\d+)M(\\d+)S/", $iso8601period, $matches)) {
                     $this->setEndingTime(sprintf("%02d%02d%02d%02d%02d%02d", $matches[1], $matches[2], $matches[3], $matches[4], $matches[5], $matches[6]));
                 }
                 break;
         }
         if (preg_match("/mark_step_\\d+/", $metadata["label"])) {
             $xmlmark = $metadata["entry"];
             preg_match("/<short>(.*?)<\\/short>/", $xmlmark, $matches);
             $mark_short = $matches[1];
             preg_match("/<official>(.*?)<\\/official>/", $xmlmark, $matches);
             $mark_official = $matches[1];
             preg_match("/<percentage>(.*?)<\\/percentage>/", $xmlmark, $matches);
             $mark_percentage = $matches[1];
             preg_match("/<passed>(.*?)<\\/passed>/", $xmlmark, $matches);
             $mark_passed = $matches[1];
             $this->mark_schema->addMarkStep($mark_short, $mark_official, $mark_percentage, $mark_passed);
         }
     }
     // handle the import of media objects in XHTML code
     if (is_array($_SESSION["import_mob_xhtml"])) {
         include_once "./Services/MediaObjects/classes/class.ilObjMediaObject.php";
         include_once "./Services/RTE/classes/class.ilRTE.php";
         include_once "./Modules/TestQuestionPool/classes/class.ilObjQuestionPool.php";
         foreach ($_SESSION["import_mob_xhtml"] as $mob) {
             $importfile = ilObjTest::_getImportDirectory() . '/' . $mob["uri"];
             if (file_exists($importfile)) {
                 $media_object =& ilObjMediaObject::_saveTempFileAsMediaObject(basename($importfile), $importfile, FALSE);
                 ilObjMediaObject::_saveUsage($media_object->getId(), "tst:html", $this->getId());
                 $this->setIntroduction(ilRTE::_replaceMediaObjectImageSrc(str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $this->getIntroduction()), 1));
                 $this->setFinalStatement(ilRTE::_replaceMediaObjectImageSrc(str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $this->getFinalStatement()), 1));
             } else {
                 global $ilLog;
                 $ilLog->write("Error: Could not open XHTML mob file for test introduction during test import. File {$importfile} does not exist!");
             }
         }
         $this->saveToDb();
     }
 }
 /**
  * handler for end of element
  *
  * @param	resource	$a_xml_parser		xml parser
  * @param	string		$a_name				element name
  */
 public function handlerEndTag($a_xml_parser, $a_name)
 {
     global $ilDB, $ilUser;
     $this->cdata = trim($this->cdata);
     $arrayname = strtolower($this->entity) . 'Array';
     $x =& $this->{$arrayname};
     switch ($a_name) {
         case 'Forum':
             $query_num_posts = "SELECT COUNT(pos_pk) cnt\n\t\t\t\t\t\t\t\t\t\tFROM frm_posts\n\t\t\t\t\t\t\t\t\tWHERE pos_top_fk = " . $ilDB->quote($this->lastHandledForumId, 'integer');
             $res_pos = $ilDB->query($query_num_posts);
             $data_pos = $ilDB->fetchAssoc($res_pos);
             $num_posts = $data_pos['cnt'];
             $query_num_threads = "SELECT COUNT(thr_pk) cnt\n\t\t\t\t\t\t\t\t\t\tFROM frm_threads\n\t\t\t\t\t\t\t\t\t  WHERE thr_top_fk = " . $ilDB->quote($this->lastHandledForumId, 'integer');
             $res_thr = $ilDB->query($query_num_threads);
             $data_thr = $ilDB->fetchAssoc($res_thr);
             $num_threads = $data_thr['cnt'];
             $update_str = "{$this->lastHandledForumId}#{$this->lastHandledThreadId}#{$this->lastHandledPostId}";
             $ilDB->manipulateF("UPDATE frm_data \n\t\t\t\t\t\tSET top_last_post = %s,\n\t\t\t\t\t\t\ttop_num_posts = %s,\n\t\t\t\t\t\t\ttop_num_threads = %s\n\t\t\t\t\tWHERE top_frm_fk = %s", array('text', 'integer', 'integer', 'integer'), array($update_str, $num_posts, $num_threads, $this->forum_obj_id));
             break;
         case 'Id':
             $x['Id'] = $this->cdata;
             break;
         case 'ObjId':
             $x['ObjId'] = $this->cdata;
             break;
         case 'Title':
             $x['Title'] = $this->cdata;
             break;
         case 'Description':
             $x['Description'] = $this->cdata;
             break;
         case 'DefaultView':
             $x['DefaultView'] = $this->cdata;
             break;
         case 'Pseudonyms':
             $x['Pseudonyms'] = $this->cdata;
             break;
         case 'Statistics':
             $x['Statistics'] = $this->cdata;
             break;
         case 'PostingActivation':
             $x['PostingActivation'] = $this->cdata;
             break;
         case 'PresetSubject':
             $x['PresetSubject'] = $this->cdata;
             break;
         case 'PresetRe':
             $x['PresetRe'] = $this->cdata;
             break;
         case 'NotificationType':
             $x['NotificationType'] = $this->cdata;
             break;
         case 'ForceNotification':
             $x['ForceNotification'] = $this->cdata;
             break;
         case 'ToggleNotification':
             $x['ToggleNotification'] = $this->cdata;
             break;
         case 'LastPost':
             $x['LastPost'] = $this->cdata;
             break;
         case 'Moderator':
             $x['Moderator'] = $this->cdata;
             break;
         case 'CreateDate':
             $x['CreateDate'] = $this->cdata;
             break;
         case 'UpdateDate':
             $x['UpdateDate'] = $this->cdata;
             break;
         case 'UpdateUserId':
             $x['UpdateUserId'] = $this->cdata;
             break;
         case 'UserId':
             $x['UserId'] = $this->cdata;
             if ($this->entity == 'forum' && $this->forumArray) {
                 //// @todo: Maybe problems if the forum xml is imported as content of a course
                 // createSettings accesses superglobal $_GET  array, which can cause problems
                 // with public_notifications of block settings
                 $this->forum->createSettings();
                 $forum_array = $this->getUserIdAndAlias($this->forumArray['UserId'], '');
                 // Store old user id
                 $oldUsrId = $ilUser->getId();
                 // Manipulate user object
                 $ilUser->setId($forum_array['usr_id']);
                 // create frm_data
                 $this->forum->saveData(array());
                 // Restore old user id
                 $ilUser->setId($oldUsrId);
                 $update_forum_array = $this->getUserIdAndAlias($this->forumArray['UpdateUserId'], '');
                 // Store old user id
                 $oldUsrId = $_SESSION["AccountId"];
                 // Manipulate user object
                 $_SESSION["AccountId"] = $update_forum_array['usr_id'];
                 $this->forum->setTitle($this->forumArray["Title"]);
                 $this->forum->setDescription($this->forumArray["Description"]);
                 $this->forum->update();
                 // Restore old user id
                 $_SESSION["AccountId"] = $oldUsrId;
                 // create frm_settings
                 $newObjProp = ilForumProperties::getInstance($this->forum->getId());
                 $newObjProp->setDefaultView((int) $this->forumArray['DefaultView']);
                 $newObjProp->setAnonymisation((int) $this->forumArray['Pseudonyms']);
                 $newObjProp->setStatisticsStatus((int) $this->forumArray['Statistics']);
                 $newObjProp->setPostActivation((int) $this->forumArray['PostingActivation']);
                 $newObjProp->setPresetSubject((int) $this->forumArray['PresetSubject']);
                 $newObjProp->setAddReSubject((int) $this->forumArray['PresetRe']);
                 $newObjProp->setNotificationType($this->forumArray['NotificationType'] ? $this->forumArray['NotificationType'] : 'all_users');
                 $newObjProp->setAdminForceNoti((int) $this->forumArray['ForceNotification']);
                 $newObjProp->setUserToggleNoti((int) $this->forumArray['ToggleNotification']);
                 $newObjProp->insert();
                 $id = $this->getNewForumPk();
                 $this->forum_obj_id = $newObjProp->getObjId();
                 $this->mapping['frm'][$this->forumArray['Id']] = $id;
                 $this->lastHandledForumId = $id;
                 unset($this->forumArray);
             }
             break;
         case 'Thread':
             $update_str = "{$this->lastHandledForumId}#{$this->lastHandledThreadId}#{$this->lastHandledPostId}";
             $ilDB->manipulateF("UPDATE frm_threads\n\t\t\t\t\t\tSET thr_last_post = %s\n\t\t\t\t\tWHERE thr_pk = %s", array('text', 'integer'), array($update_str, $this->lastHandledThreadId));
             break;
         case 'Subject':
             $x['Subject'] = $this->cdata;
             break;
         case 'Alias':
             $x['Alias'] = $this->cdata;
             break;
         case 'Sticky':
             $x['Sticky'] = $this->cdata;
             break;
         case 'Closed':
             $x['Closed'] = $this->cdata;
             if ($this->entity == 'thread' && $this->threadArray) {
                 require_once 'Modules/Forum/classes/class.ilForumTopic.php';
                 $this->forumThread = new ilForumTopic();
                 $this->forumThread->setId($this->threadArray['Id']);
                 $this->forumThread->setForumId($this->lastHandledForumId);
                 $this->forumThread->setSubject($this->threadArray['Subject']);
                 $this->forumThread->setSticky($this->threadArray['Sticky']);
                 $this->forumThread->setClosed($this->threadArray['Closed']);
                 $this->forumThread->setCreateDate($this->threadArray['CreateDate']);
                 $this->forumThread->setChangeDate($this->threadArray['UpdateDate']);
                 $this->forumThread->setImportName($this->threadArray['ImportName']);
                 $usr_data = $this->getUserIdAndAlias($this->threadArray['UserId'], $this->threadArray['Alias']);
                 $this->forumThread->setUserId($usr_data['usr_id']);
                 $this->forumThread->setUserAlias($usr_data['usr_alias']);
                 $this->forumThread->insert();
                 $this->mapping['thr'][$this->threadArray['Id']] = $this->forumThread->getId();
                 $this->lastHandledThreadId = $this->forumThread->getId();
                 unset($this->threadArray);
             }
             break;
         case 'Post':
             break;
         case 'Censorship':
             $x['Censorship'] = $this->cdata;
             break;
         case 'CensorshipMessage':
             $x['CensorshipMessage'] = $this->cdata;
             break;
         case 'Notification':
             $x['Notification'] = $this->cdata;
             break;
         case 'ImportName':
             $x['ImportName'] = $this->cdata;
             break;
         case 'Status':
             $x['Status'] = $this->cdata;
             break;
         case 'Message':
             $x['Message'] = $this->cdata;
             break;
         case 'Lft':
             $x['Lft'] = $this->cdata;
             break;
         case 'Rgt':
             $x['Rgt'] = $this->cdata;
             break;
         case 'Depth':
             $x['Depth'] = $this->cdata;
             break;
         case 'ParentId':
             $x['ParentId'] = $this->cdata;
             if ($this->entity == 'post' && $this->postArray) {
                 require_once 'Modules/Forum/classes/class.ilForumPost.php';
                 $this->forumPost = new ilForumPost();
                 $this->forumPost->setId($this->postArray['Id']);
                 $this->forumPost->setCensorship($this->postArray['Censorship']);
                 $this->forumPost->setCensorshipComment($this->postArray['CensorshipMessage']);
                 $this->forumPost->setNotification($this->postArray['Notification']);
                 $this->forumPost->setImportName($this->postArray['ImportName']);
                 $this->forumPost->setStatus($this->postArray['Status']);
                 $this->forumPost->setMessage($this->postArray['Message']);
                 $this->forumPost->setSubject($this->postArray['Subject']);
                 $this->forumPost->setLft($this->postArray['Lft']);
                 $this->forumPost->setRgt($this->postArray['Rgt']);
                 $this->forumPost->setDepth($this->postArray['Depth']);
                 $this->forumPost->setParentId($this->postArray['ParentId']);
                 $this->forumPost->setThread($this->forumThread);
                 $this->forumPost->setThreadId($this->lastHandledThreadId);
                 $this->forumPost->setForumId($this->lastHandledForumId);
                 $this->forumPost->setCreateDate($this->postArray['CreateDate']);
                 $this->forumPost->setChangeDate($this->postArray['UpdateDate']);
                 $usr_data = $this->getUserIdAndAlias($this->postArray['UserId'], $this->postArray['Alias']);
                 $update_usr_data = $this->getUserIdAndAlias($this->postArray['UpdateUserId']);
                 $this->forumPost->setUserId($usr_data['usr_id']);
                 $this->forumPost->setUserAlias($usr_data['usr_alias']);
                 $this->forumPost->setUpdateUserId($update_usr_data['usr_id']);
                 $this->forumPost->insert();
                 if ($this->mapping['pos'][$this->postArray['ParentId']]) {
                     $parentId = $this->mapping['pos'][$this->postArray['ParentId']];
                 } else {
                     $parentId = 0;
                 }
                 $postTreeNodeId = $ilDB->nextId('frm_posts_tree');
                 $ilDB->insert('frm_posts_tree', array('fpt_pk' => array('integer', $postTreeNodeId), 'thr_fk' => array('integer', $this->lastHandledThreadId), 'pos_fk' => array('integer', $this->forumPost->getId()), 'parent_pos' => array('integer', $parentId), 'lft' => array('integer', $this->postArray['Lft']), 'rgt' => array('integer', $this->postArray['Rgt']), 'depth' => array('integer', $this->postArray['Depth']), 'fpt_date' => array('timestamp', date('Y-m-d H:i:s'))));
                 $this->mapping['pos'][$this->postArray['Id']] = $this->forumPost->getId();
                 $this->lastHandledPostId = $this->forumPost->getId();
                 $media_objects_found = false;
                 foreach ($this->mediaObjects as $mob_attr) {
                     $importfile = $this->getImportDirectory() . '/' . $mob_attr['uri'];
                     if (file_exists($importfile)) {
                         $mob = ilObjMediaObject::_saveTempFileAsMediaObject(basename($importfile), $importfile, false);
                         ilObjMediaObject::_saveUsage($mob->getId(), "frm:html", $this->forumPost->getId());
                         $this->forumPost->setMessage(str_replace(array("src=\"" . $mob_attr["label"] . "\"", "src=\"" . preg_replace("/(il)_[\\d]+_(mob)_([\\d]+)/", "\$1_0_\$2_\$3", $mob_attr["label"]) . "\""), "src=\"" . "il_" . IL_INST_ID . "_mob_" . $mob->getId() . "\"", $this->forumPost->getMessage()));
                         $media_objects_found = true;
                     }
                 }
                 if ($media_objects_found) {
                     $this->forumPost->update();
                 }
                 unset($this->postArray);
             }
             break;
         case 'Content':
             $x['content'] = $this->cdata;
             break;
         case 'Attachment':
             $filedata = new ilFileDataForum($this->forum->getId(), $this->lastHandledPostId);
             $importPath = $this->contentArray['content'];
             if (strlen($importPath)) {
                 $importPath = $this->getImportDirectory() . '/' . $importPath;
                 $newFilename = preg_replace("/^\\d+_\\d+(_.*)/ims", $this->forum->getId() . "_" . $this->lastHandledPostId . "\$1", basename($importPath));
                 $path = $filedata->getForumPath();
                 $newPath = $path . '/' . $newFilename;
                 @copy($importPath, $newPath);
             }
             break;
     }
     $this->cdata = '';
     return;
 }
 /**
  * Creates a question from a QTI file
  *
  * Receives parameters from a QTI parser and creates a valid ILIAS question object
  *
  * @param object $item The QTI item object
  * @param integer $questionpool_id The id of the parent questionpool
  * @param integer $tst_id The id of the parent test if the question is part of a test
  * @param object $tst_object A reference to the parent test object
  * @param integer $question_counter A reference to a question counter to count the questions of an imported question pool
  * @param array $import_mapping An array containing references to included ILIAS objects
  * @access public
  */
 function fromXML(&$item, $questionpool_id, &$tst_id, &$tst_object, &$question_counter, &$import_mapping)
 {
     global $ilUser;
     // empty session variable for imported xhtml mobs
     unset($_SESSION["import_mob_xhtml"]);
     $presentation = $item->getPresentation();
     $duration = $item->getDuration();
     $now = getdate();
     $questionimage = array();
     $created = sprintf("%04d%02d%02d%02d%02d%02d", $now['year'], $now['mon'], $now['mday'], $now['hours'], $now['minutes'], $now['seconds']);
     $answers = array();
     foreach ($presentation->order as $entry) {
         switch ($entry["type"]) {
             case "response":
                 $response = $presentation->response[$entry["index"]];
                 $rendertype = $response->getRenderType();
                 switch (strtolower(get_class($rendertype))) {
                     case "ilqtirenderhotspot":
                         foreach ($rendertype->material as $mat) {
                             for ($i = 0; $i < $mat->getMaterialCount(); $i++) {
                                 $m = $mat->getMaterial($i);
                                 if (strcmp($m["type"], "matimage") == 0) {
                                     $questionimage = array("imagetype" => $m["material"]->getImageType(), "label" => $m["material"]->getLabel(), "content" => $m["material"]->getContent());
                                 }
                             }
                         }
                         foreach ($rendertype->response_labels as $response_label) {
                             $ident = $response_label->getIdent();
                             $answerhint = "";
                             foreach ($response_label->material as $mat) {
                                 $answerhint .= $this->object->QTIMaterialToString($mat);
                             }
                             $answers[$ident] = array("answerhint" => $answerhint, "areatype" => $response_label->getRarea(), "coordinates" => $response_label->getContent(), "points" => 0, "answerorder" => $response_label->getIdent(), "correctness" => "1", "action" => "");
                         }
                         break;
                 }
                 break;
         }
     }
     $responses = array();
     $feedbacks = array();
     $feedbacksgeneric = array();
     foreach ($item->resprocessing as $resprocessing) {
         foreach ($resprocessing->respcondition as $respcondition) {
             $coordinates = "";
             $conditionvar = $respcondition->getConditionvar();
             foreach ($conditionvar->order as $order) {
                 switch ($order["field"]) {
                     case "varinside":
                         $coordinates = $conditionvar->varinside[$order["index"]]->getContent();
                         break;
                 }
             }
             foreach ($respcondition->setvar as $setvar) {
                 foreach ($answers as $ident => $answer) {
                     if (strcmp($answer["coordinates"], $coordinates) == 0) {
                         $answers[$ident]["action"] = $setvar->getAction();
                         $answers[$ident]["points"] = $setvar->getContent();
                         if (count($respcondition->displayfeedback)) {
                             foreach ($respcondition->displayfeedback as $feedbackpointer) {
                                 if (strlen($feedbackpointer->getLinkrefid())) {
                                     foreach ($item->itemfeedback as $ifb) {
                                         if (strcmp($ifb->getIdent(), "response_allcorrect") == 0) {
                                             // found a feedback for the identifier
                                             if (count($ifb->material)) {
                                                 foreach ($ifb->material as $material) {
                                                     $feedbacksgeneric[1] = $material;
                                                 }
                                             }
                                             if (count($ifb->flow_mat) > 0) {
                                                 foreach ($ifb->flow_mat as $fmat) {
                                                     if (count($fmat->material)) {
                                                         foreach ($fmat->material as $material) {
                                                             $feedbacksgeneric[1] = $material;
                                                         }
                                                     }
                                                 }
                                             }
                                         } else {
                                             if (strcmp($ifb->getIdent(), "response_onenotcorrect") == 0) {
                                                 // found a feedback for the identifier
                                                 if (count($ifb->material)) {
                                                     foreach ($ifb->material as $material) {
                                                         $feedbacksgeneric[0] = $material;
                                                     }
                                                 }
                                                 if (count($ifb->flow_mat) > 0) {
                                                     foreach ($ifb->flow_mat as $fmat) {
                                                         if (count($fmat->material)) {
                                                             foreach ($fmat->material as $material) {
                                                                 $feedbacksgeneric[0] = $material;
                                                             }
                                                         }
                                                     }
                                                 }
                                             }
                                         }
                                         if (strcmp($ifb->getIdent(), $feedbackpointer->getLinkrefid()) == 0) {
                                             // found a feedback for the identifier
                                             if (count($ifb->material)) {
                                                 foreach ($ifb->material as $material) {
                                                     $feedbacks[$ident] = $material;
                                                 }
                                             }
                                             if (count($ifb->flow_mat) > 0) {
                                                 foreach ($ifb->flow_mat as $fmat) {
                                                     if (count($fmat->material)) {
                                                         foreach ($fmat->material as $material) {
                                                             $feedbacks[$ident] = $material;
                                                         }
                                                     }
                                                 }
                                             }
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     $this->object->setTitle($item->getTitle());
     $this->object->setNrOfTries($item->getMaxattempts());
     $this->object->setComment($item->getComment());
     $this->object->setAuthor($item->getAuthor());
     $this->object->setOwner($ilUser->getId());
     $this->object->setQuestion($this->object->QTIMaterialToString($item->getQuestiontext()));
     $this->object->setObjId($questionpool_id);
     $this->object->setEstimatedWorkingTime($duration["h"], $duration["m"], $duration["s"]);
     $areas = array("2" => "rect", "1" => "circle", "3" => "poly");
     $this->object->setImageFilename($questionimage["label"]);
     foreach ($answers as $answer) {
         $this->object->addAnswer($answer["answerhint"], $answer["points"], $answer["answerorder"], $answer["coordinates"], $areas[$answer["areatype"]]);
     }
     $this->object->saveToDb();
     if (count($item->suggested_solutions)) {
         foreach ($item->suggested_solutions as $suggested_solution) {
             $this->object->setSuggestedSolution($suggested_solution["solution"]->getContent(), $suggested_solution["gap_index"], true);
         }
         $this->object->saveToDb();
     }
     $image =& base64_decode($questionimage["content"]);
     $imagepath = $this->object->getImagePath();
     if (!file_exists($imagepath)) {
         include_once "./Services/Utilities/classes/class.ilUtil.php";
         ilUtil::makeDirParents($imagepath);
     }
     $imagepath .= $questionimage["label"];
     $fh = fopen($imagepath, "wb");
     if ($fh == false) {
         //									global $ilErr;
         //									$ilErr->raiseError($this->object->lng->txt("error_save_image_file") . ": $php_errormsg", $ilErr->MESSAGE);
         //									return;
     } else {
         $imagefile = fwrite($fh, $image);
         fclose($fh);
     }
     // handle the import of media objects in XHTML code
     foreach ($feedbacks as $ident => $material) {
         $m = $this->object->QTIMaterialToString($material);
         $feedbacks[$ident] = $m;
     }
     foreach ($feedbacksgeneric as $correctness => $material) {
         $m = $this->object->QTIMaterialToString($material);
         $feedbacksgeneric[$correctness] = $m;
     }
     $questiontext = $this->object->getQuestion();
     if (is_array($_SESSION["import_mob_xhtml"])) {
         include_once "./Services/MediaObjects/classes/class.ilObjMediaObject.php";
         include_once "./Services/RTE/classes/class.ilRTE.php";
         foreach ($_SESSION["import_mob_xhtml"] as $mob) {
             if ($tst_id > 0) {
                 $importfile = $this->getTstImportArchivDirectory() . '/' . $mob["uri"];
             } else {
                 $importfile = $this->getQplImportArchivDirectory() . '/' . $mob["uri"];
             }
             $GLOBALS['ilLog']->write(__METHOD__ . ': import mob from dir: ' . $importfile);
             $media_object =& ilObjMediaObject::_saveTempFileAsMediaObject(basename($importfile), $importfile, FALSE);
             ilObjMediaObject::_saveUsage($media_object->getId(), "qpl:html", $this->object->getId());
             $questiontext = str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $questiontext);
             foreach ($feedbacks as $ident => $material) {
                 $feedbacks[$ident] = str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $material);
             }
             foreach ($feedbacksgeneric as $correctness => $material) {
                 $feedbacksgeneric[$correctness] = str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $material);
             }
         }
     }
     $this->object->setQuestion(ilRTE::_replaceMediaObjectImageSrc($questiontext, 1));
     foreach ($feedbacks as $ident => $material) {
         $this->object->saveFeedbackSingleAnswer($ident, ilRTE::_replaceMediaObjectImageSrc($material, 1));
     }
     foreach ($feedbacksgeneric as $correctness => $material) {
         $this->object->saveFeedbackGeneric($correctness, ilRTE::_replaceMediaObjectImageSrc($material, 1));
     }
     $this->object->saveToDb();
     if ($tst_id > 0) {
         $q_1_id = $this->object->getId();
         $question_id = $this->object->duplicate(true, null, null, null, $tst_id);
         $tst_object->questions[$question_counter++] = $question_id;
         $import_mapping[$item->getIdent()] = array("pool" => $q_1_id, "test" => $question_id);
     } else {
         $import_mapping[$item->getIdent()] = array("pool" => $this->object->getId(), "test" => 0);
     }
 }
 /**
  * Creates a question from a QTI file
  *
  * Receives parameters from a QTI parser and creates a valid ILIAS question object
  *
  * @param object $item The QTI item object
  * @param integer $questionpool_id The id of the parent questionpool
  * @param integer $tst_id The id of the parent test if the question is part of a test
  * @param object $tst_object A reference to the parent test object
  * @param integer $question_counter A reference to a question counter to count the questions of an imported question pool
  * @param array $import_mapping An array containing references to included ILIAS objects
  * @access public
  */
 function fromXML(&$item, $questionpool_id, &$tst_id, &$tst_object, &$question_counter, &$import_mapping)
 {
     global $ilUser;
     // empty session variable for imported xhtml mobs
     unset($_SESSION["import_mob_xhtml"]);
     $presentation = $item->getPresentation();
     $duration = $item->getDuration();
     $shuffle = 0;
     $now = getdate();
     $created = sprintf("%04d%02d%02d%02d%02d%02d", $now['year'], $now['mon'], $now['mday'], $now['hours'], $now['minutes'], $now['seconds']);
     $definitions = array();
     $terms = array();
     $foundimage = FALSE;
     foreach ($presentation->order as $entry) {
         switch ($entry["type"]) {
             case "response":
                 $response = $presentation->response[$entry["index"]];
                 $rendertype = $response->getRenderType();
                 switch (strtolower(get_class($rendertype))) {
                     case "ilqtirenderchoice":
                         $shuffle = $rendertype->getShuffle();
                         $answerorder = 0;
                         foreach ($rendertype->response_labels as $response_label) {
                             $ident = $response_label->getIdent();
                             $answertext = "";
                             $answerimage = array();
                             foreach ($response_label->material as $mat) {
                                 for ($m = 0; $m < $mat->getMaterialCount(); $m++) {
                                     $foundmat = $mat->getMaterial($m);
                                     if (strcmp($foundmat["type"], "mattext") == 0) {
                                         $answertext .= $foundmat["material"]->getContent();
                                     }
                                     if (strcmp($foundmat["type"], "matimage") == 0) {
                                         $foundimage = TRUE;
                                         $answerimage = array("imagetype" => $foundmat["material"]->getImageType(), "label" => $foundmat["material"]->getLabel(), "content" => $foundmat["material"]->getContent());
                                     }
                                 }
                             }
                             if ($response_label->getMatchMax() == 1 && strlen($response_label->getMatchGroup())) {
                                 $definitions[$ident] = array("answertext" => $answertext, "answerimage" => $answerimage, "points" => 0, "answerorder" => $ident, "action" => "");
                             } else {
                                 $terms[$ident] = array("term" => $answertext, "answerimage" => $answerimage, "points" => 0, "ident" => $ident, "action" => "");
                             }
                         }
                         break;
                 }
                 break;
         }
     }
     $responses = array();
     $feedbacksgeneric = array();
     foreach ($item->resprocessing as $resprocessing) {
         foreach ($resprocessing->respcondition as $respcondition) {
             $subset = array();
             $correctness = 1;
             $conditionvar = $respcondition->getConditionvar();
             foreach ($conditionvar->order as $order) {
                 switch ($order["field"]) {
                     case "varsubset":
                         $subset = split(",", $conditionvar->varsubset[$order["index"]]->getContent());
                         break;
                 }
             }
             foreach ($respcondition->setvar as $setvar) {
                 array_push($responses, array("subset" => $subset, "action" => $setvar->getAction(), "points" => $setvar->getContent()));
             }
             if (count($respcondition->displayfeedback)) {
                 foreach ($respcondition->displayfeedback as $feedbackpointer) {
                     if (strlen($feedbackpointer->getLinkrefid())) {
                         foreach ($item->itemfeedback as $ifb) {
                             if (strcmp($ifb->getIdent(), "response_allcorrect") == 0) {
                                 // found a feedback for the identifier
                                 if (count($ifb->material)) {
                                     foreach ($ifb->material as $material) {
                                         $feedbacksgeneric[1] = $material;
                                     }
                                 }
                                 if (count($ifb->flow_mat) > 0) {
                                     foreach ($ifb->flow_mat as $fmat) {
                                         if (count($fmat->material)) {
                                             foreach ($fmat->material as $material) {
                                                 $feedbacksgeneric[1] = $material;
                                             }
                                         }
                                     }
                                 }
                             } else {
                                 if (strcmp($ifb->getIdent(), "response_onenotcorrect") == 0) {
                                     // found a feedback for the identifier
                                     if (count($ifb->material)) {
                                         foreach ($ifb->material as $material) {
                                             $feedbacksgeneric[0] = $material;
                                         }
                                     }
                                     if (count($ifb->flow_mat) > 0) {
                                         foreach ($ifb->flow_mat as $fmat) {
                                             if (count($fmat->material)) {
                                                 foreach ($fmat->material as $material) {
                                                     $feedbacksgeneric[0] = $material;
                                                 }
                                             }
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     include_once "./Modules/TestQuestionPool/classes/class.assAnswerMatchingTerm.php";
     include_once "./Modules/TestQuestionPool/classes/class.assAnswerMatchingDefinition.php";
     include_once "./Modules/TestQuestionPool/classes/class.assAnswerMatchingPair.php";
     $this->object->createNewQuestion();
     $this->addGeneralMetadata($item);
     $this->object->setTitle($item->getTitle());
     $this->object->setNrOfTries($item->getMaxattempts());
     $this->object->setComment($item->getComment());
     $this->object->setAuthor($item->getAuthor());
     $this->object->setOwner($ilUser->getId());
     $this->object->setQuestion($this->object->QTIMaterialToString($item->getQuestiontext()));
     $this->object->setObjId($questionpool_id);
     $this->object->setEstimatedWorkingTime($duration["h"], $duration["m"], $duration["s"]);
     $extended_shuffle = $item->getMetadataEntry("shuffle");
     $this->object->setThumbGeometry($item->getMetadataEntry("thumb_geometry"));
     $this->object->setElementHeight($item->getMetadataEntry("element_height"));
     // save images
     foreach ($terms as $term) {
         if (count($term['answerimage'])) {
             $this->saveImage($term['answerimage']['content'], $term['answerimage']['label']);
         }
     }
     foreach ($definitions as $definition) {
         if (count($definition['answerimage'])) {
             $this->saveImage($definition['answerimage']['content'], $definition['answerimage']['label']);
         }
     }
     foreach ($terms as $termindex => $term) {
         $this->object->addTerm(new assAnswerMatchingTerm($term["term"], $term['answerimage']['label'], $term["ident"]));
     }
     foreach ($definitions as $definitionindex => $definition) {
         $this->object->addDefinition(new assAnswerMatchingDefinition($definition["answertext"], $definition['answerimage']['label'], $definition["answerorder"]));
     }
     if (strlen($extended_shuffle) > 0) {
         $shuffle = $extended_shuffle;
     }
     $this->object->setShuffle($shuffle);
     foreach ($responses as $response) {
         $subset = $response["subset"];
         foreach ($subset as $ident) {
             if (array_key_exists($ident, $definitions)) {
                 $definition = $definitions[$ident];
             }
             if (array_key_exists($ident, $terms)) {
                 $term = $terms[$ident];
             }
         }
         $this->object->addMatchingPair(new assAnswerMatchingTerm('', '', $term["ident"]), new assAnswerMatchingDefinition('', '', $definition["answerorder"]), $response['points']);
     }
     // additional content editing mode information
     $this->object->setAdditionalContentEditingMode($this->fetchAdditionalContentEditingModeInformation($item));
     $this->object->saveToDb();
     if (count($item->suggested_solutions)) {
         foreach ($item->suggested_solutions as $suggested_solution) {
             $this->object->setSuggestedSolution($suggested_solution["solution"]->getContent(), $suggested_solution["gap_index"], true);
         }
         $this->object->saveToDb();
     }
     foreach ($responses as $response) {
         $subset = $response["subset"];
         foreach ($subset as $ident) {
             if (array_key_exists($ident, $definitions)) {
                 $definition = $definitions[$ident];
             }
             if (array_key_exists($ident, $terms)) {
                 $term = $terms[$ident];
             }
         }
     }
     foreach ($feedbacksgeneric as $correctness => $material) {
         $m = $this->object->QTIMaterialToString($material);
         $feedbacksgeneric[$correctness] = $m;
     }
     // handle the import of media objects in XHTML code
     $questiontext = $this->object->getQuestion();
     if (is_array($_SESSION["import_mob_xhtml"])) {
         include_once "./Services/MediaObjects/classes/class.ilObjMediaObject.php";
         include_once "./Services/RTE/classes/class.ilRTE.php";
         foreach ($_SESSION["import_mob_xhtml"] as $mob) {
             if ($tst_id > 0) {
                 $importfile = $this->getTstImportArchivDirectory() . '/' . $mob["uri"];
             } else {
                 $importfile = $this->getQplImportArchivDirectory() . '/' . $mob["uri"];
             }
             $GLOBALS['ilLog']->write(__METHOD__ . ': import mob from dir: ' . $importfile);
             $media_object =& ilObjMediaObject::_saveTempFileAsMediaObject(basename($importfile), $importfile, FALSE);
             ilObjMediaObject::_saveUsage($media_object->getId(), "qpl:html", $this->object->getId());
             $questiontext = str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $questiontext);
             foreach ($feedbacksgeneric as $correctness => $material) {
                 $feedbacksgeneric[$correctness] = str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $material);
             }
         }
     }
     $this->object->setQuestion(ilRTE::_replaceMediaObjectImageSrc($questiontext, 1));
     foreach ($feedbacksgeneric as $correctness => $material) {
         $this->object->feedbackOBJ->importGenericFeedback($this->object->getId(), $correctness, ilRTE::_replaceMediaObjectImageSrc($material, 1));
     }
     $this->object->saveToDb();
     if ($tst_id > 0) {
         $q_1_id = $this->object->getId();
         $question_id = $this->object->duplicate(true, null, null, null, $tst_id);
         $tst_object->questions[$question_counter++] = $question_id;
         $import_mapping[$item->getIdent()] = array("pool" => $q_1_id, "test" => $question_id);
     } else {
         $import_mapping[$item->getIdent()] = array("pool" => $this->object->getId(), "test" => 0);
     }
 }
 /**
  * Creates a question from a QTI file
  *
  * Receives parameters from a QTI parser and creates a valid ILIAS question object
  *
  * @param object $item The QTI item object
  * @param integer $questionpool_id The id of the parent questionpool
  * @param integer $tst_id The id of the parent test if the question is part of a test
  * @param object $tst_object A reference to the parent test object
  * @param integer $question_counter A reference to a question counter to count the questions of an imported question pool
  * @param array $import_mapping An array containing references to included ILIAS objects
  * @access public
  */
 function fromXML(&$item, $questionpool_id, &$tst_id, &$tst_object, &$question_counter, &$import_mapping)
 {
     global $ilUser;
     // empty session variable for imported xhtml mobs
     unset($_SESSION["import_mob_xhtml"]);
     $presentation = $item->getPresentation();
     $duration = $item->getDuration();
     $now = getdate();
     $created = sprintf("%04d%02d%02d%02d%02d%02d", $now['year'], $now['mon'], $now['mday'], $now['hours'], $now['minutes'], $now['seconds']);
     $feedbacksgeneric = array();
     $this->object->setTitle($item->getTitle());
     $this->object->setComment($item->getComment());
     $this->object->setAuthor($item->getAuthor());
     $this->object->setOwner($ilUser->getId());
     $this->object->setQuestion($this->object->QTIMaterialToString($item->getQuestiontext()));
     $this->object->setObjId($questionpool_id);
     $this->object->setEstimatedWorkingTime($duration["h"], $duration["m"], $duration["s"]);
     if (preg_match_all("/(\\\$v\\d+)/ims", $this->object->getQuestion(), $matches)) {
         foreach ($matches[1] as $variable) {
             $data = unserialize($item->getMetadataEntry($variable));
             $unit = $this->object->getUnitRepository()->getUnit($data["unitvalue"]);
             require_once 'Modules/TestQuestionPool/classes/class.assFormulaQuestionVariable.php';
             $varObj = new assFormulaQuestionVariable($variable, $data["rangemin"], $data["rangemax"], $unit, $data["precision"], $data["intprecision"]);
             $this->object->addVariable($varObj);
         }
     }
     if (preg_match_all("/(\\\$r\\d+)/ims", $this->object->getQuestion(), $rmatches)) {
         foreach ($rmatches[1] as $result) {
             $data = unserialize($item->getMetadataEntry($result));
             $unit = $this->object->getUnitRepository()->getUnit($data["unitvalue"]);
             require_once 'Modules/TestQuestionPool/classes/class.assFormulaQuestionResult.php';
             if (!is_array($data["rating"])) {
                 $resObj = new assFormulaQuestionResult($result, $data["rangemin"], $data["rangemax"], $data["tolerance"], $unit, $data["formula"], $data["points"], $data["precision"], TRUE);
             } else {
                 $resObj = new assFormulaQuestionResult($result, $data["rangemin"], $data["rangemax"], $data["tolerance"], $unit, $data["formula"], $data["points"], $data["precision"], FALSE, $data["rating"]["sign"], $data["rating"]["value"], $data["rating"]["unit"]);
             }
             $this->object->addResult($resObj);
             if (is_array($data["resultunits"])) {
                 foreach ($data["resultunits"] as $resu) {
                     $ru = $this->object->getUnitRepository()->getUnit($resu["unitvalue"]);
                     if (is_object($ru)) {
                         $this->object->addResultUnit($resObj, $ru);
                     }
                 }
             }
         }
     }
     $this->object->setPoints($item->getMetadataEntry("points"));
     $this->addGeneralMetadata($item);
     // additional content editing mode information
     $this->object->setAdditionalContentEditingMode($this->fetchAdditionalContentEditingModeInformation($item));
     $this->object->saveToDb();
     // handle the import of media objects in XHTML code
     $questiontext = $this->object->getQuestion();
     if (is_array($_SESSION["import_mob_xhtml"])) {
         include_once "./Services/MediaObjects/classes/class.ilObjMediaObject.php";
         include_once "./Services/RTE/classes/class.ilRTE.php";
         foreach ($_SESSION["import_mob_xhtml"] as $mob) {
             if ($tst_id > 0) {
                 include_once "./Modules/Test/classes/class.ilObjTest.php";
                 $importfile = ilObjTest::_getImportDirectory() . "/" . $_SESSION["tst_import_subdir"] . "/" . $mob["uri"];
             } else {
                 include_once "./Modules/TestQuestionPool/classes/class.ilObjQuestionPool.php";
                 $importfile = ilObjQuestionPool::_getImportDirectory() . "/" . $_SESSION["qpl_import_subdir"] . "/" . $mob["uri"];
             }
             $media_object =& ilObjMediaObject::_saveTempFileAsMediaObject(basename($importfile), $importfile, FALSE);
             ilObjMediaObject::_saveUsage($media_object->getId(), "qpl:html", $this->object->getId());
             $questiontext = str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $questiontext);
         }
     }
     $this->object->setQuestion(ilRTE::_replaceMediaObjectImageSrc($questiontext, 1));
     // additional content editing mode information
     $this->object->setAdditionalContentEditingMode($this->fetchAdditionalContentEditingModeInformation($item));
     $this->object->saveToDb();
     if (count($item->suggested_solutions)) {
         foreach ($item->suggested_solutions as $suggested_solution) {
             $this->object->setSuggestedSolution($suggested_solution["solution"]->getContent(), $suggested_solution["gap_index"], true);
         }
         $this->object->saveToDb();
     }
     if ($tst_id > 0) {
         $q_1_id = $this->object->getId();
         $question_id = $this->object->duplicate(true);
         $tst_object->questions[$question_counter++] = $question_id;
         $import_mapping[$item->getIdent()] = array("pool" => $q_1_id, "test" => $question_id);
     } else {
         $import_mapping[$item->getIdent()] = array("pool" => $this->object->getId(), "test" => 0);
     }
 }
 function saveTempFileAsMediaObject($sid, $name, $tmp_name)
 {
     $this->initAuth($sid);
     $this->initIlias();
     if (!$this->__checkSession($sid)) {
         return $this->__raiseError($this->__getMessage(), $this->__getMessageCode());
     }
     include_once "./Services/MediaObjects/classes/class.ilObjMediaObject.php";
     return ilObjMediaObject::_saveTempFileAsMediaObject($name, $tmp_name);
 }
 /**
  * Creates a question from a QTI file
  *
  * Receives parameters from a QTI parser and creates a valid ILIAS question object
  *
  * @param object $item The QTI item object
  * @param integer $questionpool_id The id of the parent questionpool
  * @param integer $tst_id The id of the parent test if the question is part of a test
  * @param object $tst_object A reference to the parent test object
  * @param integer $question_counter A reference to a question counter to count the questions of an imported question pool
  * @param array $import_mapping An array containing references to included ILIAS objects
  * @access public
  */
 function fromXML(&$item, $questionpool_id, &$tst_id, &$tst_object, &$question_counter, &$import_mapping)
 {
     global $ilUser;
     // empty session variable for imported xhtml mobs
     unset($_SESSION["import_mob_xhtml"]);
     $presentation = $item->getPresentation();
     $duration = $item->getDuration();
     $now = getdate();
     $created = sprintf("%04d%02d%02d%02d%02d%02d", $now['year'], $now['mon'], $now['mday'], $now['hours'], $now['minutes'], $now['seconds']);
     $feedbacksgeneric = array();
     $this->object->setTitle($item->getTitle());
     $this->object->setNrOfTries($item->getMaxattempts());
     $this->object->setComment($item->getComment());
     $this->object->setAuthor($item->getAuthor());
     $this->object->setOwner($ilUser->getId());
     $this->object->setQuestion($this->object->QTIMaterialToString($item->getQuestiontext()));
     $this->object->setObjId($questionpool_id);
     $this->object->setEstimatedWorkingTime($duration["h"], $duration["m"], $duration["s"]);
     $this->object->setWidth($item->getMetadataEntry("width"));
     $this->object->setHeight($item->getMetadataEntry("height"));
     $this->object->setApplet($item->getMetadataEntry("applet"));
     $this->object->setParameters(unserialize($item->getMetadataEntry("params")));
     $this->object->setPoints($item->getMetadataEntry("points"));
     $this->object->saveToDb();
     $flashapplet =& base64_decode($item->getMetadataEntry("swf"));
     if (!file_exists($this->object->getFlashPath())) {
         include_once "./Services/Utilities/classes/class.ilUtil.php";
         ilUtil::makeDirParents($this->object->getFlashPath());
     }
     $filename = $this->object->getFlashPath() . $this->object->getApplet();
     $fh = fopen($filename, "wb");
     if ($fh == false) {
         //									global $ilErr;
         //									$ilErr->raiseError($this->object->lng->txt("error_save_image_file") . ": $php_errormsg", $ilErr->MESSAGE);
         //									return;
     } else {
         fwrite($fh, $flashapplet);
         fclose($fh);
     }
     $feedbacksgeneric = $this->getFeedbackGeneric($item);
     // handle the import of media objects in XHTML code
     $questiontext = $this->object->getQuestion();
     if (is_array($_SESSION["import_mob_xhtml"])) {
         include_once "./Services/MediaObjects/classes/class.ilObjMediaObject.php";
         include_once "./Services/RTE/classes/class.ilRTE.php";
         foreach ($_SESSION["import_mob_xhtml"] as $mob) {
             if ($tst_id > 0) {
                 $importfile = $this->getTstImportArchivDirectory() . '/' . $mob["uri"];
             } else {
                 $importfile = $this->getQplImportArchivDirectory() . '/' . $mob["uri"];
             }
             $GLOBALS['ilLog']->write(__METHOD__ . ': import mob from dir: ' . $importfile);
             $media_object =& ilObjMediaObject::_saveTempFileAsMediaObject(basename($importfile), $importfile, FALSE);
             ilObjMediaObject::_saveUsage($media_object->getId(), "qpl:html", $this->object->getId());
             $questiontext = str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $questiontext);
             foreach ($feedbacksgeneric as $correctness => $material) {
                 $feedbacksgeneric[$correctness] = str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $material);
             }
         }
     }
     $this->object->setQuestion(ilRTE::_replaceMediaObjectImageSrc($questiontext, 1));
     foreach ($feedbacksgeneric as $correctness => $material) {
         $this->object->saveFeedbackGeneric($correctness, ilRTE::_replaceMediaObjectImageSrc($material, 1));
     }
     $this->object->saveToDb();
     if (count($item->suggested_solutions)) {
         foreach ($item->suggested_solutions as $suggested_solution) {
             $this->object->setSuggestedSolution($suggested_solution["solution"]->getContent(), $suggested_solution["gap_index"], true);
         }
         $this->object->saveToDb();
     }
     if ($tst_id > 0) {
         $q_1_id = $this->object->getId();
         $question_id = $this->object->duplicate(true, null, null, null, $tst_id);
         $tst_object->questions[$question_counter++] = $question_id;
         $import_mapping[$item->getIdent()] = array("pool" => $q_1_id, "test" => $question_id);
     } else {
         $import_mapping[$item->getIdent()] = array("pool" => $this->object->getId(), "test" => 0);
     }
 }
Beispiel #17
0
 /**
  * Receives parameters from a QTI parser and creates a valid ILIAS test object
  * @param ilQTIAssessment $assessment
  */
 public function fromXML(ilQTIAssessment $assessment)
 {
     unset($_SESSION["import_mob_xhtml"]);
     $this->setDescription($assessment->getComment());
     $this->setTitle($assessment->getTitle());
     $this->setIntroductionEnabled(false);
     foreach ($assessment->objectives as $objectives) {
         foreach ($objectives->materials as $material) {
             $intro = $this->QTIMaterialToString($material);
             $this->setIntroduction($intro);
             $this->setIntroductionEnabled(strlen($intro) > 0);
         }
     }
     if ($assessment->getPresentationMaterial() && $assessment->getPresentationMaterial()->getFlowMat(0) && $assessment->getPresentationMaterial()->getFlowMat(0)->getMaterial(0)) {
         $this->setFinalStatement($this->QTIMaterialToString($assessment->getPresentationMaterial()->getFlowMat(0)->getMaterial(0)));
     }
     foreach ($assessment->assessmentcontrol as $assessmentcontrol) {
         switch ($assessmentcontrol->getSolutionswitch()) {
             case "Yes":
                 $this->setInstantFeedbackSolution(1);
                 break;
             default:
                 $this->setInstantFeedbackSolution(0);
                 break;
         }
     }
     $this->setStartingTimeEnabled(false);
     $this->setEndingTimeEnabled(false);
     $this->setPasswordEnabled(false);
     $this->setLimitUsersEnabled(false);
     foreach ($assessment->qtimetadata as $metadata) {
         switch ($metadata["label"]) {
             case "test_type":
                 // for old tests with a test type
                 $type = $metadata["entry"];
                 switch ($type) {
                     case 1:
                         // assessment
                         $this->setAnonymity(1);
                         break;
                     case 2:
                         // self assessment
                         break;
                     case 4:
                         // online exam
                         $this->setFixedParticipants(1);
                         $this->setListOfQuestionsSettings(7);
                         $this->setShowSolutionPrintview(1);
                         break;
                     case 5:
                         // varying random test
                         break;
                 }
                 break;
             case "sequence_settings":
                 $this->setSequenceSettings($metadata["entry"]);
                 break;
             case "author":
                 $this->setAuthor($metadata["entry"]);
                 break;
             case "nr_of_tries":
                 $this->setNrOfTries($metadata["entry"]);
                 break;
             case "kiosk":
                 $this->setKiosk($metadata["entry"]);
                 break;
             case "showfinalstatement":
                 $this->setShowFinalStatement($metadata["entry"]);
                 break;
             case "showinfo":
                 $this->setShowInfo($metadata["entry"]);
                 break;
             case "forcejs":
                 $this->setForceJS($metadata["entry"]);
                 break;
             case "customstyle":
                 $this->setCustomStyle($metadata["entry"]);
                 break;
             case "highscore_enabled":
                 $this->setHighscoreEnabled($metadata["entry"]);
                 break;
             case "highscore_anon":
                 $this->setHighscoreAnon($metadata["entry"]);
                 break;
             case "highscore_achieved_ts":
                 $this->setHighscoreAchievedTS($metadata["entry"]);
                 break;
             case "highscore_score":
                 $this->setHighscoreScore($metadata["entry"]);
                 break;
             case "highscore_percentage":
                 $this->setHighscorePercentage($metadata["entry"]);
                 break;
             case "highscore_hints":
                 $this->setHighscoreHints($metadata["entry"]);
                 break;
             case "highscore_wtime":
                 $this->setHighscoreWTime($metadata["entry"]);
                 break;
             case "highscore_own_table":
                 $this->setHighscoreOwnTable($metadata["entry"]);
                 break;
             case "highscore_top_table":
                 $this->setHighscoreTopTable($metadata["entry"]);
                 break;
             case "highscore_top_num":
                 $this->setHighscoreTopNum($metadata["entry"]);
                 break;
             case "hide_previous_results":
                 if ($metadata["entry"] == 0) {
                     $this->setUsePreviousAnswers(1);
                 } else {
                     $this->setUsePreviousAnswers(0);
                 }
                 break;
             case "use_previous_answers":
                 $this->setUsePreviousAnswers($metadata["entry"]);
                 break;
             case "answer_feedback":
                 $this->setAnswerFeedback($metadata["entry"]);
                 break;
             case "hide_title_points":
                 $this->setTitleOutput($metadata["entry"]);
                 break;
             case "title_output":
                 $this->setTitleOutput($metadata["entry"]);
                 break;
             case "question_set_type":
                 $this->setQuestionSetType($metadata["entry"]);
                 break;
             case "random_test":
                 if ($metadata["entry"]) {
                     $this->setQuestionSetType(self::QUESTION_SET_TYPE_RANDOM);
                 } else {
                     $this->setQuestionSetType(self::QUESTION_SET_TYPE_FIXED);
                 }
                 break;
             case "results_presentation":
                 $this->setResultsPresentation($metadata["entry"]);
                 break;
             case "reset_processing_time":
                 $this->setResetProcessingTime($metadata["entry"]);
                 break;
             case "instant_verification":
                 $this->setInstantFeedbackSolution($metadata["entry"]);
                 break;
             case "answer_feedback_points":
                 $this->setAnswerFeedbackPoints($metadata["entry"]);
                 break;
             case "anonymity":
                 $this->setAnonymity($metadata["entry"]);
                 break;
             case "show_cancel":
                 $this->setShowCancel($metadata["entry"]);
                 break;
             case "show_marker":
                 $this->setShowMarker($metadata["entry"]);
                 break;
             case "fixed_participants":
                 $this->setFixedParticipants($metadata["entry"]);
                 break;
             case "score_reporting":
                 $this->setScoreReporting($metadata["entry"]);
                 break;
             case "shuffle_questions":
                 $this->setShuffleQuestions($metadata["entry"]);
                 break;
             case "count_system":
                 $this->setCountSystem($metadata["entry"]);
                 break;
             case "mc_scoring":
                 $this->setMCScoring($metadata["entry"]);
                 break;
             case "mailnotification":
                 $this->setMailNotification($metadata["entry"]);
                 break;
             case "mailnottype":
                 $this->setMailNotificationType($metadata["entry"]);
                 break;
             case "exportsettings":
                 $this->setExportSettings($metadata['exportsettings']);
                 break;
             case "score_cutting":
                 $this->setScoreCutting($metadata["entry"]);
                 break;
             case "password":
                 $this->setPassword($metadata["entry"]);
                 $this->setPasswordEnabled(strlen($metadata["entry"]) > 0);
                 break;
             case "allowedUsers":
                 $this->setAllowedUsers($metadata["entry"]);
                 $this->setLimitUsersEnabled(strlen($metadata["entry"]) > 0);
                 break;
             case "allowedUsersTimeGap":
                 $this->setAllowedUsersTimeGap($metadata["entry"]);
                 break;
             case "pass_scoring":
                 $this->setPassScoring($metadata["entry"]);
                 break;
             case "show_summary":
                 $this->setListOfQuestionsSettings($metadata["entry"]);
                 break;
             case "reporting_date":
                 $iso8601period = $metadata["entry"];
                 if (preg_match("/P(\\d+)Y(\\d+)M(\\d+)DT(\\d+)H(\\d+)M(\\d+)S/", $iso8601period, $matches)) {
                     $this->setReportingDate(sprintf("%02d%02d%02d%02d%02d%02d", $matches[1], $matches[2], $matches[3], $matches[4], $matches[5], $matches[6]));
                 }
                 break;
             case "processing_time":
                 $this->setProcessingTime($metadata['entry']);
                 break;
             case "starting_time":
                 $iso8601period = $metadata["entry"];
                 if (preg_match("/P(\\d+)Y(\\d+)M(\\d+)DT(\\d+)H(\\d+)M(\\d+)S/", $iso8601period, $matches)) {
                     $this->setStartingTime(sprintf("%02d%02d%02d%02d%02d%02d", $matches[1], $matches[2], $matches[3], $matches[4], $matches[5], $matches[6]));
                     $this->setStartingTimeEnabled(true);
                 }
                 break;
             case "ending_time":
                 $iso8601period = $metadata["entry"];
                 if (preg_match("/P(\\d+)Y(\\d+)M(\\d+)DT(\\d+)H(\\d+)M(\\d+)S/", $iso8601period, $matches)) {
                     $this->setEndingTime(sprintf("%02d%02d%02d%02d%02d%02d", $matches[1], $matches[2], $matches[3], $matches[4], $matches[5], $matches[6]));
                     $this->setEndingTimeEnabled(true);
                 }
                 break;
             case "enable_examview":
                 $this->setEnableExamview($metadata["entry"]);
                 break;
             case 'show_examview_html':
                 $this->setShowExamviewHtml($metadata['entry']);
                 break;
             case 'show_examview_pdf':
                 $this->setShowExamviewPdf($metadata['entry']);
                 break;
             case 'redirection_mode':
                 $this->setRedirectionMode($metadata['entry']);
                 break;
             case 'redirection_url':
                 $this->setRedirectionUrl($metadata['entry']);
                 break;
             case 'examid_in_kiosk':
             case 'examid_in_test_pass':
                 $this->setShowExamIdInTestPassEnabled($metadata['entry']);
                 break;
             case 'show_exam_id':
             case 'examid_in_test_res':
                 $this->setShowExamIdInTestResultsEnabled($metadata['entry']);
                 break;
             case 'enable_archiving':
                 $this->setEnableArchiving($metadata['entry']);
                 break;
             case 'sign_submission':
                 $this->setSignSubmission($metadata['entry']);
                 break;
             case 'char_selector_availability':
                 $this->setCharSelectorAvailability($metadata['entry']);
                 break;
             case 'char_selector_definition':
                 $this->setCharSelectorDefinition($metadata['entry']);
                 break;
             case 'skill_service':
                 $this->setSkillServiceEnabled((bool) $metadata['entry']);
                 break;
             case 'result_tax_filters':
                 $this->setResultFilterTaxIds(strlen($metadata['entry']) ? unserialize($metadata['entry']) : array());
                 break;
             case 'show_grading_status':
                 $this->setShowGradingStatusEnabled((bool) $metadata['entry']);
                 break;
             case 'show_grading_mark':
                 $this->setShowGradingMarkEnabled((bool) $metadata['entry']);
                 break;
         }
         if (preg_match("/mark_step_\\d+/", $metadata["label"])) {
             $xmlmark = $metadata["entry"];
             preg_match("/<short>(.*?)<\\/short>/", $xmlmark, $matches);
             $mark_short = $matches[1];
             preg_match("/<official>(.*?)<\\/official>/", $xmlmark, $matches);
             $mark_official = $matches[1];
             preg_match("/<percentage>(.*?)<\\/percentage>/", $xmlmark, $matches);
             $mark_percentage = $matches[1];
             preg_match("/<passed>(.*?)<\\/passed>/", $xmlmark, $matches);
             $mark_passed = $matches[1];
             $this->mark_schema->addMarkStep($mark_short, $mark_official, $mark_percentage, $mark_passed);
         }
     }
     // handle the import of media objects in XHTML code
     if (is_array($_SESSION["import_mob_xhtml"])) {
         include_once "./Services/MediaObjects/classes/class.ilObjMediaObject.php";
         include_once "./Services/RTE/classes/class.ilRTE.php";
         include_once "./Modules/TestQuestionPool/classes/class.ilObjQuestionPool.php";
         foreach ($_SESSION["import_mob_xhtml"] as $mob) {
             $importfile = ilObjTest::_getImportDirectory() . '/' . $mob["uri"];
             if (file_exists($importfile)) {
                 $media_object =& ilObjMediaObject::_saveTempFileAsMediaObject(basename($importfile), $importfile, FALSE);
                 ilObjMediaObject::_saveUsage($media_object->getId(), "tst:html", $this->getId());
                 $this->setIntroduction(ilRTE::_replaceMediaObjectImageSrc(str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $this->getIntroduction()), 1));
                 $this->setFinalStatement(ilRTE::_replaceMediaObjectImageSrc(str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $this->getFinalStatement()), 1));
             } else {
                 global $ilLog;
                 $ilLog->write("Error: Could not open XHTML mob file for test introduction during test import. File {$importfile} does not exist!");
             }
         }
         $this->saveToDb();
     }
 }
 /**
  * Creates a question from a QTI file
  *
  * Receives parameters from a QTI parser and creates a valid ILIAS question object
  *
  * @param object $item The QTI item object
  * @param integer $questionpool_id The id of the parent questionpool
  * @param integer $tst_id The id of the parent test if the question is part of a test
  * @param object $tst_object A reference to the parent test object
  * @param integer $question_counter A reference to a question counter to count the questions of an imported question pool
  * @param array $import_mapping An array containing references to included ILIAS objects
  * @access public
  */
 function fromXML(&$item, $questionpool_id, &$tst_id, &$tst_object, &$question_counter, &$import_mapping)
 {
     global $ilUser;
     // empty session variable for imported xhtml mobs
     unset($_SESSION["import_mob_xhtml"]);
     $presentation = $item->getPresentation();
     $duration = $item->getDuration();
     $packageIliasVersion = $item->getIliasSourceVersion('ILIAS_VERSION');
     $seperate_question_field = $item->getMetadataEntry("question");
     $questiontext = null;
     if (!$packageIliasVersion || version_compare($packageIliasVersion, '5.0.0', '<')) {
         $questiontext = '&nbsp';
     } elseif ($seperate_question_field) {
         $questiontext = $this->processNonAbstractedImageReferences($seperate_question_field, $item->getIliasSourceNic());
     }
     $clozetext = array();
     $shuffle = 0;
     $now = getdate();
     $created = sprintf("%04d%02d%02d%02d%02d%02d", $now['year'], $now['mon'], $now['mday'], $now['hours'], $now['minutes'], $now['seconds']);
     $gaps = array();
     foreach ($presentation->order as $entry) {
         switch ($entry["type"]) {
             case "material":
                 $materialString = $this->object->QTIMaterialToString($presentation->material[$entry["index"]]);
                 if ($questiontext === null) {
                     $questiontext = $materialString;
                 } else {
                     array_push($clozetext, $materialString);
                 }
                 break;
             case "response":
                 $response = $presentation->response[$entry["index"]];
                 $rendertype = $response->getRenderType();
                 array_push($clozetext, "<<" . $response->getIdent() . ">>");
                 switch (strtolower(get_class($response->getRenderType()))) {
                     case "ilqtirenderfib":
                         switch ($response->getRenderType()->getFibtype()) {
                             case FIBTYPE_DECIMAL:
                             case FIBTYPE_INTEGER:
                                 array_push($gaps, array("ident" => $response->getIdent(), "type" => CLOZE_NUMERIC, "answers" => array(), "minnumber" => $response->getRenderType()->getMinnumber(), "maxnumber" => $response->getRenderType()->getMaxnumber(), 'gap_size' => $response->getRenderType()->getColumns()));
                                 break;
                             default:
                             case FIBTYPE_STRING:
                                 array_push($gaps, array("ident" => $response->getIdent(), "type" => CLOZE_TEXT, "answers" => array(), 'gap_size' => $response->getRenderType()->getColumns()));
                                 break;
                         }
                         break;
                     case "ilqtirenderchoice":
                         $answers = array();
                         $shuffle = $rendertype->getShuffle();
                         $answerorder = 0;
                         foreach ($rendertype->response_labels as $response_label) {
                             $ident = $response_label->getIdent();
                             $answertext = "";
                             foreach ($response_label->material as $mat) {
                                 $answertext .= $this->object->QTIMaterialToString($mat);
                             }
                             $answers[$ident] = array("answertext" => $answertext, "points" => 0, "answerorder" => $answerorder++, "action" => "", "shuffle" => $rendertype->getShuffle());
                         }
                         array_push($gaps, array("ident" => $response->getIdent(), "type" => CLOZE_SELECT, "shuffle" => $rendertype->getShuffle(), "answers" => $answers));
                         break;
                 }
                 break;
         }
     }
     $responses = array();
     $feedbacks = array();
     $feedbacksgeneric = array();
     foreach ($item->resprocessing as $resprocessing) {
         foreach ($resprocessing->respcondition as $respcondition) {
             $ident = "";
             $correctness = 1;
             $conditionvar = $respcondition->getConditionvar();
             foreach ($conditionvar->order as $order) {
                 switch ($order["field"]) {
                     case "varequal":
                         $equals = $conditionvar->varequal[$order["index"]]->getContent();
                         $gapident = $conditionvar->varequal[$order["index"]]->getRespident();
                         break;
                 }
             }
             foreach ($respcondition->setvar as $setvar) {
                 if (strcmp($gapident, "") != 0) {
                     foreach ($gaps as $gi => $g) {
                         if (strcmp($g["ident"], $gapident) == 0) {
                             if ($g["type"] == CLOZE_SELECT) {
                                 foreach ($gaps[$gi]["answers"] as $ai => $answer) {
                                     if (strcmp($answer["answertext"], $equals) == 0) {
                                         $gaps[$gi]["answers"][$ai]["action"] = $setvar->getAction();
                                         $gaps[$gi]["answers"][$ai]["points"] = $setvar->getContent();
                                     }
                                 }
                             } else {
                                 if ($g["type"] == CLOZE_TEXT) {
                                     array_push($gaps[$gi]["answers"], array("answertext" => $equals, "points" => $setvar->getContent(), "answerorder" => count($gaps[$gi]["answers"]), "action" => $setvar->getAction()));
                                 } else {
                                     if ($g["type"] == CLOZE_NUMERIC) {
                                         array_push($gaps[$gi]["answers"], array("answertext" => $equals, "points" => $setvar->getContent(), "answerorder" => count($gaps[$gi]["answers"]), "action" => $setvar->getAction()));
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
             if (count($respcondition->displayfeedback)) {
                 foreach ($respcondition->displayfeedback as $feedbackpointer) {
                     if (strlen($feedbackpointer->getLinkrefid())) {
                         foreach ($item->itemfeedback as $ifb) {
                             if (strcmp($ifb->getIdent(), "response_allcorrect") == 0) {
                                 // found a feedback for the identifier
                                 if (count($ifb->material)) {
                                     foreach ($ifb->material as $material) {
                                         $feedbacksgeneric[1] = $material;
                                     }
                                 }
                                 if (count($ifb->flow_mat) > 0) {
                                     foreach ($ifb->flow_mat as $fmat) {
                                         if (count($fmat->material)) {
                                             foreach ($fmat->material as $material) {
                                                 $feedbacksgeneric[1] = $material;
                                             }
                                         }
                                     }
                                 }
                             } else {
                                 if (strcmp($ifb->getIdent(), "response_onenotcorrect") == 0) {
                                     // found a feedback for the identifier
                                     if (count($ifb->material)) {
                                         foreach ($ifb->material as $material) {
                                             $feedbacksgeneric[0] = $material;
                                         }
                                     }
                                     if (count($ifb->flow_mat) > 0) {
                                         foreach ($ifb->flow_mat as $fmat) {
                                             if (count($fmat->material)) {
                                                 foreach ($fmat->material as $material) {
                                                     $feedbacksgeneric[0] = $material;
                                                 }
                                             }
                                         }
                                     }
                                 } else {
                                     // found a feedback for the identifier
                                     if (count($ifb->material)) {
                                         foreach ($ifb->material as $material) {
                                             $feedbacks[$ifb->getIdent()] = $material;
                                         }
                                     }
                                     if (count($ifb->flow_mat) > 0) {
                                         foreach ($ifb->flow_mat as $fmat) {
                                             if (count($fmat->material)) {
                                                 foreach ($fmat->material as $material) {
                                                     $feedbacks[$ifb->getIdent()] = $material;
                                                 }
                                             }
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     $this->addGeneralMetadata($item);
     $this->object->setTitle($item->getTitle());
     $this->object->setNrOfTries($item->getMaxattempts());
     $this->object->setComment($item->getComment());
     $this->object->setAuthor($item->getAuthor());
     $this->object->setOwner($ilUser->getId());
     $this->object->setObjId($questionpool_id);
     $this->object->setEstimatedWorkingTime($duration["h"], $duration["m"], $duration["s"]);
     $textgap_rating = $item->getMetadataEntry("textgaprating");
     $this->object->setFixedTextLength($item->getMetadataEntry("fixedTextLength"));
     $this->object->setIdenticalScoring($item->getMetadataEntry("identicalScoring"));
     $combination = json_decode(base64_decode($item->getMetadataEntry("combinations")));
     if (strlen($textgap_rating) == 0) {
         $textgap_rating = "ci";
     }
     $this->object->setTextgapRating($textgap_rating);
     $gaptext = array();
     foreach ($gaps as $gapidx => $gap) {
         $gapcontent = array();
         include_once "./Modules/TestQuestionPool/classes/class.assClozeGap.php";
         $clozegap = new assClozeGap($gap["type"]);
         foreach ($gap["answers"] as $index => $answer) {
             include_once "./Modules/TestQuestionPool/classes/class.assAnswerCloze.php";
             $gapanswer = new assAnswerCloze($answer["answertext"], $answer["points"], $answer["answerorder"]);
             $gapanswer->setGapSize($gap["gap_size"]);
             switch ($clozegap->getType()) {
                 case CLOZE_SELECT:
                     $clozegap->setShuffle($answer["shuffle"]);
                     break;
                 case CLOZE_NUMERIC:
                     $gapanswer->setLowerBound($gap["minnumber"]);
                     $gapanswer->setUpperBound($gap["maxnumber"]);
                     break;
             }
             $clozegap->setGapSize($gap["gap_size"]);
             $clozegap->addItem($gapanswer);
             array_push($gapcontent, $answer["answertext"]);
         }
         $this->object->addGapAtIndex($clozegap, $gapidx);
         $gaptext[$gap["ident"]] = "[gap]" . join(",", $gapcontent) . "[/gap]";
     }
     $this->object->setQuestion($questiontext);
     $clozetext = join("", $clozetext);
     foreach ($gaptext as $idx => $val) {
         $clozetext = str_replace("<<" . $idx . ">>", $val, $clozetext);
     }
     $this->object->setClozeTextValue($clozetext);
     // additional content editing mode information
     $this->object->setAdditionalContentEditingMode($this->fetchAdditionalContentEditingModeInformation($item));
     $this->object->saveToDb();
     // handle the import of media objects in XHTML code
     foreach ($feedbacks as $ident => $material) {
         $m = $this->object->QTIMaterialToString($material);
         $feedbacks[$ident] = $m;
     }
     foreach ($feedbacksgeneric as $correctness => $material) {
         $m = $this->object->QTIMaterialToString($material);
         $feedbacksgeneric[$correctness] = $m;
     }
     $questiontext = $this->object->getQuestion();
     $clozetext = $this->object->getClozeText();
     if (is_array($_SESSION["import_mob_xhtml"])) {
         include_once "./Services/MediaObjects/classes/class.ilObjMediaObject.php";
         include_once "./Services/RTE/classes/class.ilRTE.php";
         foreach ($_SESSION["import_mob_xhtml"] as $mob) {
             if ($tst_id > 0) {
                 $importfile = $this->getTstImportArchivDirectory() . '/' . $mob["uri"];
             } else {
                 $importfile = $this->getQplImportArchivDirectory() . '/' . $mob["uri"];
             }
             $GLOBALS['ilLog']->write(__METHOD__ . ': import mob from dir: ' . $importfile);
             $media_object =& ilObjMediaObject::_saveTempFileAsMediaObject(basename($importfile), $importfile, FALSE);
             $questiontext = str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $questiontext);
             $clozetext = str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $clozetext);
             foreach ($feedbacks as $ident => $material) {
                 $feedbacks[$ident] = str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $material);
             }
             foreach ($feedbacksgeneric as $correctness => $material) {
                 $feedbacksgeneric[$correctness] = str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $material);
             }
         }
     }
     $this->object->setQuestion(ilRTE::_replaceMediaObjectImageSrc($questiontext, 1));
     $this->object->setClozeTextValue(ilRTE::_replaceMediaObjectImageSrc($clozetext, 1));
     foreach ($feedbacks as $ident => $material) {
         $this->object->feedbackOBJ->importSpecificAnswerFeedback($this->object->getId(), $ident, ilRTE::_replaceMediaObjectImageSrc($material, 1));
     }
     foreach ($feedbacksgeneric as $correctness => $material) {
         $this->object->feedbackOBJ->importGenericFeedback($this->object->getId(), $correctness, ilRTE::_replaceMediaObjectImageSrc($material, 1));
     }
     $this->object->saveToDb();
     if (count($item->suggested_solutions)) {
         foreach ($item->suggested_solutions as $suggested_solution) {
             $this->object->setSuggestedSolution($suggested_solution["solution"]->getContent(), $suggested_solution["gap_index"], true);
         }
         $this->object->saveToDb();
     }
     if ($tst_id > 0) {
         $q_1_id = $this->object->getId();
         $question_id = $this->object->duplicate(true, null, null, null, $tst_id);
         $tst_object->questions[$question_counter++] = $question_id;
         $import_mapping[$item->getIdent()] = array("pool" => $q_1_id, "test" => $question_id);
     } else {
         $import_mapping[$item->getIdent()] = array("pool" => $this->object->getId(), "test" => 0);
     }
     $this->object->saveToDb();
     if (count($combination) > 0) {
         require_once './Modules/TestQuestionPool/classes/class.assClozeGapCombination.php';
         assClozeGapCombination::clearGapCombinationsFromDb($this->object->getId());
         assClozeGapCombination::importGapCombinationToDb($this->object->getId(), $combination);
     }
     $this->object->saveToDb();
 }
 /**
  * Creates a question from a QTI file
  *
  * Receives parameters from a QTI parser and creates a valid ILIAS question object
  *
  * @param object $item The QTI item object
  * @param integer $questionpool_id The id of the parent questionpool
  * @param integer $tst_id The id of the parent test if the question is part of a test
  * @param object $tst_object A reference to the parent test object
  * @param integer $question_counter A reference to a question counter to count the questions of an imported question pool
  * @param array $import_mapping An array containing references to included ILIAS objects
  * @access public
  */
 function fromXML(&$item, $questionpool_id, &$tst_id, &$tst_object, &$question_counter, &$import_mapping)
 {
     global $ilUser;
     // empty session variable for imported xhtml mobs
     unset($_SESSION["import_mob_xhtml"]);
     $presentation = $item->getPresentation();
     $duration = $item->getDuration();
     $now = getdate();
     $maxchars = 0;
     $points = 0;
     $upperlimit = 0;
     $lowerlimit = 0;
     $feedbacksgeneric = array();
     $created = sprintf("%04d%02d%02d%02d%02d%02d", $now['year'], $now['mon'], $now['mday'], $now['hours'], $now['minutes'], $now['seconds']);
     foreach ($presentation->order as $entry) {
         switch ($entry["type"]) {
             case "response":
                 $response = $presentation->response[$entry["index"]];
                 $rendertype = $response->getRenderType();
                 switch (strtolower(get_class($rendertype))) {
                     case "ilqtirenderfib":
                         $maxchars = $rendertype->getMaxchars();
                         break;
                 }
                 break;
         }
     }
     foreach ($item->resprocessing as $resprocessing) {
         foreach ($resprocessing->respcondition as $respcondition) {
             $conditionvar = $respcondition->getConditionvar();
             foreach ($conditionvar->order as $order) {
                 switch ($order["field"]) {
                     case "varlte":
                         $upperlimit = $conditionvar->varlte[$order["index"]]->getContent();
                         break;
                     case "vargte":
                         $lowerlimit = $conditionvar->vargte[$order["index"]]->getContent();
                         break;
                 }
             }
             foreach ($respcondition->setvar as $setvar) {
                 $points = $setvar->getContent();
             }
             if (count($respcondition->displayfeedback)) {
                 foreach ($respcondition->displayfeedback as $feedbackpointer) {
                     if (strlen($feedbackpointer->getLinkrefid())) {
                         foreach ($item->itemfeedback as $ifb) {
                             if (strcmp($ifb->getIdent(), "response_allcorrect") == 0) {
                                 // found a feedback for the identifier
                                 if (count($ifb->material)) {
                                     foreach ($ifb->material as $material) {
                                         $feedbacksgeneric[1] = $material;
                                     }
                                 }
                                 if (count($ifb->flow_mat) > 0) {
                                     foreach ($ifb->flow_mat as $fmat) {
                                         if (count($fmat->material)) {
                                             foreach ($fmat->material as $material) {
                                                 $feedbacksgeneric[1] = $material;
                                             }
                                         }
                                     }
                                 }
                             } else {
                                 if (strcmp($ifb->getIdent(), "response_onenotcorrect") == 0) {
                                     // found a feedback for the identifier
                                     if (count($ifb->material)) {
                                         foreach ($ifb->material as $material) {
                                             $feedbacksgeneric[0] = $material;
                                         }
                                     }
                                     if (count($ifb->flow_mat) > 0) {
                                         foreach ($ifb->flow_mat as $fmat) {
                                             if (count($fmat->material)) {
                                                 foreach ($fmat->material as $material) {
                                                     $feedbacksgeneric[0] = $material;
                                                 }
                                             }
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     $this->object->setTitle($item->getTitle());
     $this->object->setNrOfTries($item->getMaxattempts());
     $this->object->setComment($item->getComment());
     $this->object->setAuthor($item->getAuthor());
     $this->object->setOwner($ilUser->getId());
     $this->object->setQuestion($this->object->QTIMaterialToString($item->getQuestiontext()));
     $this->object->setObjId($questionpool_id);
     $this->object->setEstimatedWorkingTime($duration["h"], $duration["m"], $duration["s"]);
     $this->object->setMaxChars($maxchars);
     $this->object->setPoints($points);
     $this->object->setLowerLimit($lowerlimit);
     $this->object->setUpperLimit($upperlimit);
     $this->object->saveToDb();
     if (count($item->suggested_solutions)) {
         foreach ($item->suggested_solutions as $suggested_solution) {
             $this->object->setSuggestedSolution($suggested_solution["solution"]->getContent(), $suggested_solution["gap_index"], true);
         }
         $this->object->saveToDb();
     }
     foreach ($feedbacksgeneric as $correctness => $material) {
         $m = $this->object->QTIMaterialToString($material);
         $feedbacksgeneric[$correctness] = $m;
     }
     // handle the import of media objects in XHTML code
     $questiontext = $this->object->getQuestion();
     if (is_array($_SESSION["import_mob_xhtml"])) {
         include_once "./Services/MediaObjects/classes/class.ilObjMediaObject.php";
         include_once "./Services/RTE/classes/class.ilRTE.php";
         foreach ($_SESSION["import_mob_xhtml"] as $mob) {
             if ($tst_id > 0) {
                 $importfile = $this->getTstImportArchivDirectory() . '/' . $mob["uri"];
             } else {
                 $importfile = $this->getQplImportArchivDirectory() . '/' . $mob["uri"];
             }
             $GLOBALS['ilLog']->write(__METHOD__ . ': import mob from dir: ' . $importfile);
             $media_object =& ilObjMediaObject::_saveTempFileAsMediaObject(basename($importfile), $importfile, FALSE);
             ilObjMediaObject::_saveUsage($media_object->getId(), "qpl:html", $this->object->getId());
             $questiontext = str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $questiontext);
             foreach ($feedbacksgeneric as $correctness => $material) {
                 $feedbacksgeneric[$correctness] = str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $material);
             }
         }
     }
     $this->object->setQuestion(ilRTE::_replaceMediaObjectImageSrc($questiontext, 1));
     foreach ($feedbacksgeneric as $correctness => $material) {
         $this->object->saveFeedbackGeneric($correctness, ilRTE::_replaceMediaObjectImageSrc($material, 1));
     }
     $this->object->saveToDb();
     if ($tst_id > 0) {
         $q_1_id = $this->object->getId();
         $question_id = $this->object->duplicate(true, null, null, null, $tst_id);
         $tst_object->questions[$question_counter++] = $question_id;
         $import_mapping[$item->getIdent()] = array("pool" => $q_1_id, "test" => $question_id);
     } else {
         $import_mapping[$item->getIdent()] = array("pool" => $this->object->getId(), "test" => 0);
     }
 }
 /**
  * Creates a question from a QTI file
  *
  * Receives parameters from a QTI parser and creates a valid ILIAS question object
  *
  * @param object $item The QTI item object
  * @param integer $questionpool_id The id of the parent questionpool
  * @param integer $tst_id The id of the parent test if the question is part of a test
  * @param object $tst_object A reference to the parent test object
  * @param integer $question_counter A reference to a question counter to count the questions of an imported question pool
  * @param array $import_mapping An array containing references to included ILIAS objects
  * @access public
  */
 function fromXML(&$item, $questionpool_id, &$tst_id, &$tst_object, &$question_counter, &$import_mapping)
 {
     global $ilUser;
     // empty session variable for imported xhtml mobs
     unset($_SESSION["import_mob_xhtml"]);
     $presentation = $item->getPresentation();
     $duration = $item->getDuration();
     $now = getdate();
     $maxchars = 0;
     $maxpoints = 0;
     $created = sprintf("%04d%02d%02d%02d%02d%02d", $now['year'], $now['mon'], $now['mday'], $now['hours'], $now['minutes'], $now['seconds']);
     foreach ($presentation->order as $entry) {
         switch ($entry["type"]) {
             case "response":
                 $response = $presentation->response[$entry["index"]];
                 $rendertype = $response->getRenderType();
                 switch (strtolower(get_class($rendertype))) {
                     case "ilqtirenderfib":
                         $maxchars = $rendertype->getMaxchars();
                         break;
                 }
                 break;
         }
     }
     $feedbacksgeneric = array();
     foreach ($item->resprocessing as $resprocessing) {
         $outcomes = $resprocessing->getOutcomes();
         foreach ($outcomes->decvar as $decvar) {
             $maxpoints = $decvar->getMaxvalue();
         }
         foreach ($resprocessing->respcondition as $respcondition) {
             foreach ($respcondition->displayfeedback as $feedbackpointer) {
                 if (strlen($feedbackpointer->getLinkrefid())) {
                     foreach ($item->itemfeedback as $ifb) {
                         if (strcmp($ifb->getIdent(), "response_allcorrect") == 0) {
                             // found a feedback for the identifier
                             if (count($ifb->material)) {
                                 foreach ($ifb->material as $material) {
                                     $feedbacksgeneric[1] = $material;
                                 }
                             }
                             if (count($ifb->flow_mat) > 0) {
                                 foreach ($ifb->flow_mat as $fmat) {
                                     if (count($fmat->material)) {
                                         foreach ($fmat->material as $material) {
                                             $feedbacksgeneric[1] = $material;
                                         }
                                     }
                                 }
                             }
                         } else {
                             if (strcmp($ifb->getIdent(), "response_onenotcorrect") == 0) {
                                 // found a feedback for the identifier
                                 if (count($ifb->material)) {
                                     foreach ($ifb->material as $material) {
                                         $feedbacksgeneric[0] = $material;
                                     }
                                 }
                                 if (count($ifb->flow_mat) > 0) {
                                     foreach ($ifb->flow_mat as $fmat) {
                                         if (count($fmat->material)) {
                                             foreach ($fmat->material as $material) {
                                                 $feedbacksgeneric[0] = $material;
                                             }
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     $this->addGeneralMetadata($item);
     $this->object->setTitle($item->getTitle());
     $this->object->setNrOfTries($item->getMaxattempts());
     $this->object->setComment($item->getComment());
     $this->object->setAuthor($item->getAuthor());
     $this->object->setOwner($ilUser->getId());
     $this->object->setQuestion($this->object->QTIMaterialToString($item->getQuestiontext()));
     $this->object->setObjId($questionpool_id);
     $this->object->setEstimatedWorkingTime($duration["h"], $duration["m"], $duration["s"]);
     $this->object->setPoints($maxpoints);
     $this->object->setMaxNumOfChars($maxchars);
     $textrating = $item->getMetadataEntry("textrating");
     if (strlen($textrating)) {
         $this->object->setTextRating($textrating);
     }
     $this->object->matchcondition = strlen($item->getMetadataEntry('matchcondition')) ? $item->getMetadataEntry('matchcondition') : 0;
     require_once './Modules/TestQuestionPool/classes/class.assAnswerMultipleResponseImage.php';
     $termscoring = unserialize(base64_decode($item->getMetadataEntry('termscoring')));
     $termscoring = is_array($termscoring) ? $termscoring : array();
     for ($i = 0; $i < count($termscoring); $i++) {
         $this->object->addAnswer($termscoring[$i]->getAnswertext(), $termscoring[$i]->getPoints());
     }
     $this->object->setKeywordRelation($item->getMetadataEntry('termrelation'));
     $keywords = $item->getMetadataEntry("keywords");
     if (strlen($keywords)) {
         #$this->object->setKeywords($keywords);
         $answers = explode(' ', $keywords);
         foreach ($answers as $answer) {
             $this->object->addAnswer($answer, $maxpoints / count($answers));
         }
         $this->object->setKeywordRelation('one');
     }
     // additional content editing mode information
     $this->object->setAdditionalContentEditingMode($this->fetchAdditionalContentEditingModeInformation($item));
     $this->object->saveToDb();
     if (count($item->suggested_solutions)) {
         foreach ($item->suggested_solutions as $suggested_solution) {
             $this->object->setSuggestedSolution($suggested_solution["solution"]->getContent(), $suggested_solution["gap_index"], true);
         }
         $this->object->saveToDb();
     }
     foreach ($feedbacksgeneric as $correctness => $material) {
         $m = $this->object->QTIMaterialToString($material);
         $feedbacksgeneric[$correctness] = $m;
     }
     // handle the import of media objects in XHTML code
     $questiontext = $this->object->getQuestion();
     if (is_array($_SESSION["import_mob_xhtml"])) {
         include_once "./Services/MediaObjects/classes/class.ilObjMediaObject.php";
         include_once "./Services/RTE/classes/class.ilRTE.php";
         foreach ($_SESSION["import_mob_xhtml"] as $mob) {
             if ($tst_id > 0) {
                 $importfile = $this->getTstImportArchivDirectory() . '/' . $mob["uri"];
             } else {
                 $importfile = $this->getQplImportArchivDirectory() . '/' . $mob["uri"];
             }
             $GLOBALS['ilLog']->write(__METHOD__ . ': import mob from dir: ' . $importfile);
             $media_object =& ilObjMediaObject::_saveTempFileAsMediaObject(basename($importfile), $importfile, FALSE);
             ilObjMediaObject::_saveUsage($media_object->getId(), "qpl:html", $this->object->getId());
             $questiontext = str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $questiontext);
             foreach ($feedbacksgeneric as $correctness => $material) {
                 $feedbacksgeneric[$correctness] = str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $material);
             }
         }
     }
     $this->object->setQuestion(ilRTE::_replaceMediaObjectImageSrc($questiontext, 1));
     foreach ($feedbacksgeneric as $correctness => $material) {
         $this->object->feedbackOBJ->importGenericFeedback($this->object->getId(), $correctness, ilRTE::_replaceMediaObjectImageSrc($material, 1));
     }
     $this->object->saveToDb();
     if ($tst_id > 0) {
         $q_1_id = $this->object->getId();
         $question_id = $this->object->duplicate(true, null, null, null, $tst_id);
         $tst_object->questions[$question_counter++] = $question_id;
         $import_mapping[$item->getIdent()] = array("pool" => $q_1_id, "test" => $question_id);
     } else {
         $import_mapping[$item->getIdent()] = array("pool" => $this->object->getId(), "test" => 0);
     }
 }