/**
  * imports question(s) into the questionpool
  */
 function uploadQplObject($questions_only = false)
 {
     $this->ctrl->setParameter($this, 'new_type', $_REQUEST['new_type']);
     if ($_FILES["xmldoc"]["error"] > UPLOAD_ERR_OK) {
         ilUtil::sendFailure($this->lng->txt("error_upload"), true);
         if (!$questions_only) {
             $this->ctrl->redirect($this, 'create');
         }
         return false;
     }
     // create import directory
     include_once "./Modules/TestQuestionPool/classes/class.ilObjQuestionPool.php";
     $basedir = ilObjQuestionPool::_createImportDirectory();
     // copy uploaded file to import directory
     $file = pathinfo($_FILES["xmldoc"]["name"]);
     $full_path = $basedir . "/" . $_FILES["xmldoc"]["name"];
     $GLOBALS['ilLog']->write(__METHOD__ . ": full path " . $full_path);
     include_once "./Services/Utilities/classes/class.ilUtil.php";
     ilUtil::moveUploadedFile($_FILES["xmldoc"]["tmp_name"], $_FILES["xmldoc"]["name"], $full_path);
     $GLOBALS['ilLog']->write(__METHOD__ . ": full path " . $full_path);
     if (strcmp($_FILES["xmldoc"]["type"], "text/xml") == 0) {
         $qti_file = $full_path;
         ilObjTest::_setImportDirectory($basedir);
     } else {
         // unzip file
         ilUtil::unzip($full_path);
         // determine filenames of xml files
         $subdir = basename($file["basename"], "." . $file["extension"]);
         ilObjQuestionPool::_setImportDirectory($basedir);
         $xml_file = ilObjQuestionPool::_getImportDirectory() . '/' . $subdir . '/' . $subdir . ".xml";
         $qti_file = ilObjQuestionPool::_getImportDirectory() . '/' . $subdir . '/' . str_replace("qpl", "qti", $subdir) . ".xml";
     }
     // start verification of QTI files
     include_once "./Services/QTI/classes/class.ilQTIParser.php";
     $qtiParser = new ilQTIParser($qti_file, IL_MO_VERIFY_QTI, 0, "");
     $result = $qtiParser->startParsing();
     $founditems =& $qtiParser->getFoundItems();
     if (count($founditems) == 0) {
         // nothing found
         // delete import directory
         ilUtil::delDir($basedir);
         ilUtil::sendFailure($this->lng->txt("qpl_import_no_items"), true);
         if (!$questions_only) {
             $this->ctrl->redirect($this, 'create');
         }
         return false;
     }
     $complete = 0;
     $incomplete = 0;
     foreach ($founditems as $item) {
         if (strlen($item["type"])) {
             $complete++;
         } else {
             $incomplete++;
         }
     }
     if ($complete == 0) {
         // delete import directory
         ilUtil::delDir($basedir);
         ilUtil::sendFailure($this->lng->txt("qpl_import_non_ilias_files"), true);
         if (!$questions_only) {
             $this->ctrl->redirect($this, 'create');
         }
         return false;
     }
     $_SESSION["qpl_import_xml_file"] = $xml_file;
     $_SESSION["qpl_import_qti_file"] = $qti_file;
     $_SESSION["qpl_import_subdir"] = $subdir;
     // display of found questions
     $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.qpl_import_verification.html", "Modules/TestQuestionPool");
     $row_class = array("tblrow1", "tblrow2");
     $counter = 0;
     foreach ($founditems as $item) {
         $this->tpl->setCurrentBlock("verification_row");
         $this->tpl->setVariable("ROW_CLASS", $row_class[$counter++ % 2]);
         $this->tpl->setVariable("QUESTION_TITLE", $item["title"]);
         $this->tpl->setVariable("QUESTION_IDENT", $item["ident"]);
         include_once "./Services/QTI/classes/class.ilQTIItem.php";
         switch ($item["type"]) {
             case CLOZE_TEST_IDENTIFIER:
                 $type = $this->lng->txt("assClozeTest");
                 break;
             case IMAGEMAP_QUESTION_IDENTIFIER:
                 $type = $this->lng->txt("assImagemapQuestion");
                 break;
             case JAVAAPPLET_QUESTION_IDENTIFIER:
                 $type = $this->lng->txt("assJavaApplet");
                 break;
             case MATCHING_QUESTION_IDENTIFIER:
                 $type = $this->lng->txt("assMatchingQuestion");
                 break;
             case MULTIPLE_CHOICE_QUESTION_IDENTIFIER:
                 $type = $this->lng->txt("assMultipleChoice");
                 break;
             case KPRIM_CHOICE_QUESTION_IDENTIFIER:
                 $type = $this->lng->txt("assKprimChoice");
                 break;
             case SINGLE_CHOICE_QUESTION_IDENTIFIER:
                 $type = $this->lng->txt("assSingleChoice");
                 break;
             case ORDERING_QUESTION_IDENTIFIER:
                 $type = $this->lng->txt("assOrderingQuestion");
                 break;
             case TEXT_QUESTION_IDENTIFIER:
                 $type = $this->lng->txt("assTextQuestion");
                 break;
             case NUMERIC_QUESTION_IDENTIFIER:
                 $type = $this->lng->txt("assNumeric");
                 break;
             case TEXTSUBSET_QUESTION_IDENTIFIER:
                 $type = $this->lng->txt("assTextSubset");
                 break;
             default:
                 $type = $this->lng->txt($item["type"]);
                 break;
         }
         if (strcmp($type, "-" . $item["type"] . "-") == 0) {
             global $ilPluginAdmin;
             $pl_names = $ilPluginAdmin->getActivePluginsForSlot(IL_COMP_MODULE, "TestQuestionPool", "qst");
             foreach ($pl_names as $pl_name) {
                 $pl = ilPlugin::getPluginObject(IL_COMP_MODULE, "TestQuestionPool", "qst", $pl_name);
                 if (strcmp($pl->getQuestionType(), $item["type"]) == 0) {
                     $type = $pl->getQuestionTypeTranslation();
                 }
             }
         }
         $this->tpl->setVariable("QUESTION_TYPE", $type);
         $this->tpl->parseCurrentBlock();
     }
     $this->tpl->setCurrentBlock("import_qpl");
     if (is_file($xml_file)) {
         // read file into a string
         $fh = @fopen($xml_file, "r") or die("");
         $xml = @fread($fh, filesize($xml_file));
         @fclose($fh);
         if (preg_match("/<ContentObject.*?MetaData.*?General.*?Title[^>]*?>([^<]*?)</", $xml, $matches)) {
             $this->tpl->setVariable("VALUE_NEW_QUESTIONPOOL", $matches[1]);
         }
     }
     $this->tpl->setVariable("TEXT_CREATE_NEW_QUESTIONPOOL", $this->lng->txt("qpl_import_create_new_qpl"));
     $this->tpl->parseCurrentBlock();
     $this->tpl->setCurrentBlock("adm_content");
     $this->tpl->setVariable("TEXT_TYPE", $this->lng->txt("question_type"));
     $this->tpl->setVariable("TEXT_TITLE", $this->lng->txt("question_title"));
     $this->tpl->setVariable("FOUND_QUESTIONS_INTRODUCTION", $this->lng->txt("qpl_import_verify_found_questions"));
     if ($questions_only) {
         $this->tpl->setVariable("VERIFICATION_HEADING", $this->lng->txt("import_questions_into_qpl"));
         $this->tpl->setVariable("FORMACTION", $this->ctrl->getFormAction($this));
     } else {
         $this->tpl->setVariable("VERIFICATION_HEADING", $this->lng->txt("import_qpl"));
         $this->ctrl->setParameter($this, "new_type", $this->type);
         $this->tpl->setVariable("FORMACTION", $this->ctrl->getFormAction($this));
         //$this->tpl->setVariable("FORMACTION", $this->getFormAction("save","adm_object.php?cmd=gateway&ref_id=".$_GET["ref_id"]."&new_type=".$this->type));
     }
     $this->tpl->setVariable("ARROW", ilUtil::getImagePath("arrow_downright.svg"));
     $this->tpl->setVariable("VALUE_IMPORT", $this->lng->txt("import"));
     $this->tpl->setVariable("VALUE_CANCEL", $this->lng->txt("cancel"));
     $value_questions_only = 0;
     if ($questions_only) {
         $value_questions_only = 1;
     }
     $this->tpl->setVariable("VALUE_QUESTIONS_ONLY", $value_questions_only);
     $this->tpl->parseCurrentBlock();
     return true;
 }