Creates a question from a QTI file. 
        {
                
                $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" => "",
                                                                        "points_unchecked" => 0
                                                                );
                                                        }
                                                        break;
                                        }
                                        break;
                        }
                }
                $responses = array();
                $feedbacks = array();
                $feedbacksgeneric = array();
                foreach ($item->resprocessing as $resprocessing)
                {
                        foreach ($resprocessing->respcondition as $respcondition)
                        {
                                $coordinates = "";
                                $correctness = 1;
                                $conditionvar = $respcondition->getConditionvar();
                                foreach ($conditionvar->order as $order)
                                {
                                        switch ($order["field"])
                                        {
                                                case "arr_not":
                                                        $correctness = 0;
                                                        break;
                                                case "varinside":
                                                        $coordinates = $conditionvar->varinside[$order["index"]]->getContent();
                                                        break;
                                                case "varequal":
                                                        $coordinates = $conditionvar->varequal[$order["index"]]->getContent();
                                                        break;
                                        }
                                }
                                foreach ($respcondition->setvar as $setvar)
                                {
                                        foreach ($answers as $ident => $answer)
                                        {
                                                if (strcmp($answer["coordinates"], $coordinates) == 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)
                                                                                                {
                                                                                                        
                                                                                                        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)
                                                                                                {
                                                                                                        
                                                                                                        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)
                                                                                                {
                                                                                                        
                                                                                                        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->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->setIsMultipleChoice($item->getMetadataEntry("IS_MULTIPLE_CHOICE"));
                $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"]], $answer["points_unchecked"]);
                }
                
                $this->object->setAdditionalContentEditingMode(
                );              
                $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";
                }
                $imagepath .=  $questionimage["label"];
                $fh = fopen($imagepath, "wb");
                if ($fh == false)
                {
                }
                else
                {
                        $imagefile = fwrite($fh, $image);
                        fclose($fh);
                }
                
                foreach ($feedbacks as $ident => $material)
                {
                        $m = $this->object->QTIMaterialToString($material);
                        $feedbacks[$ident] = $m;
                }
                foreach ($feedbacksgeneric as $correctness => $material)
                {
                        $m = $this->object->QTIMaterialToString($material);
                        $feedbacksgeneric[$correctness] = $m;
                }
                $questiontext = $this->object->getQuestion();
                {
                        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)
                                {
                                }
                                else
                                {
                                }
                                
                                $GLOBALS[
'ilLog']->write(__METHOD__.
': import mob from dir: '. $importfile);
 
                                
                                $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);
                                }
                        }
                }
                foreach ($feedbacks as $ident => $material)
                {
                        $this->object->feedbackOBJ->importSpecificAnswerFeedback(
                        );
                }
                foreach ($feedbacksgeneric as $correctness => $material)
                {
                        $this->object->feedbackOBJ->importGenericFeedback(
                        );
                }
                $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);
                }
        }