/**
  * 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);
     }
 }
 /**
  * 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();
     $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);
     }
 }
 /**
  * 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);
     }
 }
 /**
  * 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);
     }
 }
 /**
  * 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);
     }
 }
 /**
  * cache_event function
  *
  * Creates a new entry in the cache table for each date that the event appears
  * (and does not already have an explicit RECURRENCE-ID instance, given its
  * iCalendar UID).
  *
  * @param object $event Event to generate cache table for
  *
  * @return void
  **/
 function cache_event(&$event)
 {
     global $wpdb;
     // Convert event's timestamps to local for correct calculations of
     // recurrence. Need to also remove PHP timezone offset for each date for
     // SG_iCal to calculate correct recurring instances.
     $event->start = $this->gmt_to_local($event->start) - date('Z', $event->start);
     $event->end = $this->gmt_to_local($event->end) - date('Z', $event->end);
     $evs = array();
     $e = array('post_id' => $event->post_id, 'start' => $event->start, 'end' => $event->end);
     $duration = $event->getDuration();
     // Timestamp of today's date + 3 years
     $tif = Ai1ec_Time_Utility::current_time(true) + 94608000;
     //94 608 000 = 3 years in seconds
     // Always cache initial instance
     $evs[] = $e;
     $_start = $event->start;
     $_end = $event->end;
     if ($event->recurrence_rules) {
         $start = $event->start;
         $wdate = $startdate = iCalUtilityFunctions::_timestamp2date($_start, 6);
         $enddate = iCalUtilityFunctions::_timestamp2date($tif, 6);
         $exclude_dates = array();
         $recurrence_dates = array();
         if ($event->exception_rules) {
             // creat an array for the rules
             $exception_rules = $this->build_recurrence_rules_array($event->exception_rules);
             $exception_rules = iCalUtilityFunctions::_setRexrule($exception_rules);
             $result = array();
             // The first array is the result and it's passed by reference
             iCalUtilityFunctions::_recur2date($exclude_dates, $exception_rules, $wdate, $startdate, $enddate);
         }
         $recurrence_rules = $this->build_recurrence_rules_array($event->recurrence_rules);
         $recurrence_rules = iCalUtilityFunctions::_setRexrule($recurrence_rules);
         iCalUtilityFunctions::_recur2date($recurrence_dates, $recurrence_rules, $wdate, $startdate, $enddate);
         // Add the instances
         foreach ($recurrence_dates as $date => $bool) {
             // The arrays are in the form timestamp => true so an isset call is what we need
             if (isset($exclude_dates[$date])) {
                 continue;
             }
             $e['start'] = $date;
             $e['end'] = $date + $duration;
             $excluded = false;
             // Check if exception dates match this occurence
             if ($event->exception_dates) {
                 if ($this->date_match_exdates($date, $event->exception_dates)) {
                     $excluded = true;
                 }
             }
             // Add event only if it is not excluded
             if ($excluded == false) {
                 $evs[] = $e;
             }
         }
     }
     foreach ($evs as $e) {
         // Find out if this event instance is already accounted for by an
         // overriding 'RECURRENCE-ID' of the same iCalendar feed (by comparing the
         // UID, start date, recurrence). If so, then do not create duplicate
         // instance of event.
         $matching_event_id = $event->ical_uid ? $this->get_matching_event_id($event->ical_uid, $event->ical_feed_url, $start = $this->local_to_gmt($e['start']) - date('Z', $e['start']), false, $event->post_id) : null;
         // If no other instance was found
         if (is_null($matching_event_id)) {
             $start = getdate($e['start']);
             $end = getdate($e['end']);
             /*
             // Commented out for now
             // If event spans a day and end time is not midnight, or spans more than
             // a day, then create instance for each spanning day
             if( ( $start['mday'] != $end['mday'] &&
             			( $end['hours'] || $end['minutes'] || $end['seconds'] ) )
             		|| $e['end'] - $e['start'] > 60 * 60 * 24 ) {
             	$this->create_cache_table_entries( $e );
             // Else cache single instance of event
             } else {
             	$this->insert_event_in_cache_table( $e );
             }
             */
             $this->insert_event_in_cache_table($e);
         }
     }
 }
 /**
  * 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["points_unchecked"], $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);
             }
         }
     }
     $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;
     // 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();
     $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);
     }
 }
 /**
  * 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();
     $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);
     }
 }