/** * Imports survey questions into ILIAS * * @param string $source The filename of an XML import file * @access public */ function importObject($source, $spl_exists = FALSE) { if (is_file($source)) { $isZip = strcmp(strtolower(substr($source, -3)), 'zip') == 0; if ($isZip) { // unzip file ilUtil::unzip($source); // determine filenames of xml files $subdir = basename($source, ".zip"); $source = dirname($source) . "/" . $subdir . "/" . $subdir . ".xml"; } $fh = fopen($source, "r") or die(""); $xml = fread($fh, filesize($source)); fclose($fh) or die(""); if ($isZip) { $subdir = basename($source, ".zip"); if (@is_dir(dirname($source) . "/" . $subdir)) { ilUtil::delDir(dirname($source) . "/" . $subdir); } } if (strpos($xml, "questestinterop") > 0) { // survey questions for ILIAS < 3.8 include_once "./Services/Survey/classes/class.SurveyImportParserPre38.php"; $import = new SurveyImportParserPre38($this->getId(), "", $spl_exists); $import->setXMLContent($xml); $import->startParsing(); } else { // survey questions for ILIAS >= 3.8 include_once "./Services/Survey/classes/class.SurveyImportParser.php"; $import = new SurveyImportParser($this->getId(), "", $spl_exists); $import->setXMLContent($xml); $import->startParsing(); } } }
/** * Imports a survey from XML into the ILIAS database * * @return boolean True, if the import succeeds, false otherwise * @access public */ function importObject($file_info, $svy_qpl_id) { if ($svy_qpl_id < 1) { $svy_qpl_id = -1; } // check if file was uploaded $source = $file_info["tmp_name"]; $error = ""; if ($source == 'none' || !$source || $file_info["error"] > UPLOAD_ERR_OK) { $error = $this->lng->txt("import_no_file_selected"); } // check correct file type $isXml = FALSE; $isZip = FALSE; if (strcmp($file_info["type"], "text/xml") == 0 || strcmp($file_info["type"], "application/xml") == 0) { $isXml = TRUE; } // too many different mime-types, so we use the suffix $suffix = pathinfo($file_info["name"]); if (strcmp(strtolower($suffix["extension"]), "zip") == 0) { $isZip = TRUE; } if (!$isXml && !$isZip) { $error = $this->lng->txt("import_wrong_file_type"); global $ilLog; $ilLog->write("Survey: Import error. Filetype was \"" . $file_info["type"] . "\""); } if (strlen($error) == 0) { // import file as a survey $import_dir = $this->getImportDirectory(); $import_subdir = ""; $importfile = ""; include_once "./Services/Utilities/classes/class.ilUtil.php"; if ($isZip) { $importfile = $import_dir . "/" . $file_info["name"]; ilUtil::moveUploadedFile($source, $file_info["name"], $importfile); ilUtil::unzip($importfile); $found = $this->locateImportFiles($import_dir); if (!(strlen($found["dir"]) > 0 && strlen($found["xml"]) > 0)) { $error = $this->lng->txt("wrong_import_file_structure"); return $error; } $importfile = $found["xml"]; $import_subdir = $found["dir"]; } else { $importfile = tempnam($import_dir, "survey_import"); ilUtil::moveUploadedFile($source, $file_info["name"], $importfile); } $fh = fopen($importfile, "r"); if (!$fh) { $error = $this->lng->txt("import_error_opening_file"); return $error; } $xml = fread($fh, filesize($importfile)); $result = fclose($fh); if (!$result) { $error = $this->lng->txt("import_error_closing_file"); return $error; } unset($_SESSION["import_mob_xhtml"]); if (strpos($xml, "questestinterop")) { include_once "./Services/Survey/classes/class.SurveyImportParserPre38.php"; $import = new SurveyImportParserPre38($svy_qpl_id, "", TRUE); $import->setSurveyObject($this); $import->setXMLContent($xml); $import->startParsing(); } else { include_once "./Services/Survey/classes/class.SurveyImportParser.php"; $import = new SurveyImportParser($svy_qpl_id, "", TRUE); $import->setSurveyObject($this); $import->setXMLContent($xml); $import->startParsing(); } if (is_array($_SESSION["import_mob_xhtml"])) { include_once "./Services/MediaObjects/classes/class.ilObjMediaObject.php"; include_once "./Services/RTE/classes/class.ilRTE.php"; include_once "./Modules/TestQuestionPool/classes/class.ilObjQuestionPool.php"; foreach ($_SESSION["import_mob_xhtml"] as $mob) { $importfile = $import_subdir . "/" . $mob["uri"]; if (file_exists($importfile)) { $media_object =& ilObjMediaObject::_saveTempFileAsMediaObject(basename($importfile), $importfile, FALSE); ilObjMediaObject::_saveUsage($media_object->getId(), "svy:html", $this->getId()); $this->setIntroduction(str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $this->getIntroduction())); $this->setOutro(str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $this->getOutro())); } else { global $ilLog; $ilLog->write("Error: Could not open XHTML mob file for test introduction during test import. File {$importfile} does not exist!"); } } $this->setIntroduction(ilRTE::_replaceMediaObjectImageSrc($this->getIntroduction(), 1)); $this->setOutro(ilRTE::_replaceMediaObjectImageSrc($this->getOutro(), 1)); $this->saveToDb(); } // delete import directory ilUtil::delDir($this->getImportDirectory()); } return $error; }