예제 #1
0
 /**
  * Import a container
  * @param object $dir
  * @param object $type
  * @return 
  */
 protected function doImportObject($dir, $type)
 {
     $manifest_file = $dir . "/manifest.xml";
     if (!file_exists($manifest_file)) {
         return false;
     }
     include_once "./Services/Export/classes/class.ilManifestParser.php";
     $parser = new ilManifestParser($manifest_file);
     // Handling single containers without subitems
     if (!$parser->getExportSets()) {
         $this->createDummy($type);
         $new_id = parent::doImportObject($dir, $type);
         return $new_id;
     }
     // Handling containers with subitems
     $first = true;
     foreach ($parser->getExportSets() as $set) {
         $GLOBALS['ilLog']->write(__METHOD__ . ': do import with dir ' . $dir . DIRECTORY_SEPARATOR . $set['path'] . ' and type ' . $set['type']);
         $new_id = parent::doImportObject($dir . DIRECTORY_SEPARATOR . $set['path'], $set['type']);
         if ($first) {
             $ret = $new_id;
             $first = false;
         }
     }
     return $ret;
 }
예제 #2
0
 /**
  * Import
  */
 protected function importFileObject($parent_id = null)
 {
     global $objDefinition, $tpl, $ilErr;
     if (!$parent_id) {
         $parent_id = $_GET["ref_id"];
     }
     $new_type = $_REQUEST["new_type"];
     // create permission is already checked in createObject. This check here is done to prevent hacking attempts
     if (!$this->checkPermissionBool("create", "", $new_type)) {
         $ilErr->raiseError($this->lng->txt("no_create_permission"));
     }
     $this->lng->loadLanguageModule($new_type);
     $this->ctrl->setParameter($this, "new_type", $new_type);
     $form = $this->initImportForm($new_type);
     if ($form->checkInput()) {
         // :todo: make some check on manifest file
         if ($objDefinition->isContainer($new_type)) {
             include_once './Services/Export/classes/class.ilImportContainer.php';
             $imp = new ilImportContainer((int) $parent_id);
         } else {
             include_once "./Services/Export/classes/class.ilImport.php";
             $imp = new ilImport((int) $parent_id);
         }
         $new_id = $imp->importObject(null, $_FILES["importfile"]["tmp_name"], $_FILES["importfile"]["name"], $new_type);
         if ($new_id > 0) {
             $this->ctrl->setParameter($this, "new_type", "");
             $newObj = ilObjectFactory::getInstanceByObjId($new_id);
             // put new object id into tree - already done in import for containers
             if (!$objDefinition->isContainer($new_type)) {
                 $this->putObjectInTree($newObj);
             }
             $this->afterImport($newObj);
         } else {
             if ($objDefinition->isContainer($new_type)) {
                 ilUtil::sendFailure($this->lng->txt("container_import_zip_file_invalid"));
             } else {
                 // not enough information here...
                 return;
             }
         }
     }
     // display form to correct errors
     $form->setValuesByPost();
     $tpl->setContent($form->getHtml());
 }
 /**
  * Import lm from zip file
  *
  * @param
  * @return
  */
 function importFromZipFile($a_tmp_file, $a_filename, $a_validate = true, $a_import_into_help_module = 0)
 {
     global $lng;
     // create import directory
     $this->createImportDirectory();
     // copy uploaded file to import directory
     $file = pathinfo($a_filename);
     $full_path = $this->getImportDirectory() . "/" . $a_filename;
     ilUtil::moveUploadedFile($a_tmp_file, $a_filename, $full_path);
     // unzip file
     ilUtil::unzip($full_path);
     $subdir = basename($file["basename"], "." . $file["extension"]);
     $mess = $this->importFromDirectory($this->getImportDirectory() . "/" . $subdir, $a_validate);
     // this should only be true for help modules
     if ($a_import_into_help_module > 0) {
         // search the zip file
         $dir = $this->getImportDirectory() . "/" . $subdir;
         $files = ilUtil::getDir($dir);
         foreach ($files as $file) {
             if (is_int(strpos($file["entry"], "__help_")) && is_int(strpos($file["entry"], ".zip"))) {
                 include_once "./Services/Export/classes/class.ilImport.php";
                 $imp = new ilImport();
                 $imp->getMapping()->addMapping('Services/Help', 'help_module', 0, $a_import_into_help_module);
                 include_once "./Modules/LearningModule/classes/class.ilLMObject.php";
                 $chaps = ilLMObject::getObjectList($this->getId(), "st");
                 foreach ($chaps as $chap) {
                     $chap_arr = explode("_", $chap["import_id"]);
                     $imp->getMapping()->addMapping('Services/Help', 'help_chap', $chap_arr[count($chap_arr) - 1], $chap["obj_id"]);
                 }
                 $imp->importEntity($dir . "/" . $file["entry"], $file["entry"], "help", "Services/Help", true);
             }
         }
     }
     // delete import directory
     ilUtil::delDir($this->getImportDirectory());
     return $mess;
 }
 /**
  * Import page layout
  *
  * @param string $a_filename file name
  * @param string $a_fiepath complete path (incl. name) to file
  *
  * @return object new object
  */
 static function import($a_filename, $a_filepath)
 {
     include_once "./Services/Export/classes/class.ilImport.php";
     $imp = new ilImport();
     $imp->importEntity($a_filepath, $a_filename, "pgtp", "Services/COPage");
 }
 /**
  * Import
  *
  * @access	public
  */
 function importFile()
 {
     global $rbacsystem, $objDefinition, $tpl, $lng;
     $new_type = $_POST["new_type"] ? $_POST["new_type"] : $_GET["new_type"];
     // create permission is already checked in createObject. This check here is done to prevent hacking attempts
     if (!$rbacsystem->checkAccess("create", $_GET["ref_id"], $new_type)) {
         $this->ilias->raiseError($this->lng->txt("no_create_permission"), $this->ilias->error_obj->MESSAGE);
     }
     $this->ctrl->setParameter($this, "new_type", $new_type);
     $this->initImportForm($new_type);
     if ($this->form->checkInput()) {
         // todo: make some check on manifest file
         include_once "./Services/Export/classes/class.ilImport.php";
         $imp = new ilImport((int) $_GET['ref_id']);
         $new_id = $imp->importObject($newObj, $_FILES["importfile"]["tmp_name"], $_FILES["importfile"]["name"], $new_type);
         // put new object id into tree
         if ($new_id > 0) {
             $newObj = ilObjectFactory::getInstanceByObjId($new_id);
             $newObj->createReference();
             $newObj->putInTree($_GET["ref_id"]);
             $newObj->setPermissions($_GET["ref_id"]);
             ilUtil::sendSuccess($lng->txt("msg_obj_modified"), true);
             $this->exitSaveFeedBlock();
         }
         return;
     }
     $this->form->setValuesByPost();
     $tpl->setContent($this->form->getHtml());
 }
예제 #6
0
 /**
  * Import personal data
  *
  * @param
  * @return
  */
 function importPersonalData($a_file, $a_profile_data, $a_settings, $a_bookmarks, $a_notes, $a_calendar)
 {
     include_once "./Services/Export/classes/class.ilImport.php";
     $imp = new ilImport();
     if (!$a_profile_data) {
         $imp->addSkipEntity("Services/User", "usr_profile");
     }
     if (!$a_settings) {
         $imp->addSkipEntity("Services/User", "usr_setting");
     }
     if (!$a_bookmarks) {
         $imp->addSkipEntity("Services/Bookmarks", "bookmarks");
     }
     if (!$a_notes) {
         $imp->addSkipEntity("Services/Notes", "user_notes");
     }
     if (!$a_calendar) {
         $imp->addSkipEntity("Services/Calendar", "calendar");
     }
     $imp->importEntity($a_file["tmp_name"], $a_file["name"], "personal_data", "Services/User");
 }
 /**
  * Perform import
  */
 protected function doImportRole()
 {
     global $rbacreview;
     $form = $this->initImportForm();
     if ($form->checkInput()) {
         try {
             include_once './Services/Export/classes/class.ilImport.php';
             // For global roles set import id to parent of current ref_id (adm)
             if ($this->isAdminRoleFolder()) {
                 $parent_ref = $GLOBALS['tree']->getParentId($this->getCurrentObject()->getRefId());
             } else {
                 $parent_ref = $this->getCurrentObject()->getRefId();
             }
             $imp = new ilImport($parent_ref);
             $imp->getMapping()->addMapping('Services/AccessControl', 'rolf', 0, $rbacreview->getRoleFolderIdOfObject($parent_ref));
             $imp->importObject(null, $_FILES["importfile"]["tmp_name"], $_FILES["importfile"]["name"], 'role');
             ilUtil::sendSuccess($this->lng->txt('rbac_role_imported'), true);
             $this->ctrl->redirect($this, 'perm');
             return;
         } catch (Exception $e) {
             ilUtil::sendFailure($e->getMessage());
             $form->setValuesByPost();
             $this->displayImportRoleForm($form);
             return;
         }
     }
     $form->setValuesByPost();
     ilUtil::sendFailure($this->lng->txt('err_check_input'));
     $this->displayImportRoleForm($form);
 }
예제 #8
0
 /**
  * display status information or report errors messages
  * in case of error
  *
  * @access	public
  */
 function importFileObject()
 {
     $new_type = $_REQUEST["new_type"];
     // create permission is already checked in createObject. This check here is done to prevent hacking attempts
     if (!$this->checkPermissionBool("create", "", $new_type)) {
         $ilErr->raiseError($this->lng->txt("no_create_permission"));
     }
     $this->lng->loadLanguageModule($new_type);
     $this->ctrl->setParameter($this, "new_type", $new_type);
     $form = $this->initImportForm($new_type);
     if ($form->checkInput()) {
         $this->ctrl->setParameter($this, "new_type", "");
         $upload = $_FILES["importfile"];
         // create and insert object in objecttree
         include_once "./Modules/Glossary/classes/class.ilObjGlossary.php";
         $newObj = new ilObjGlossary();
         $newObj->setType($new_type);
         $newObj->setTitle($upload["name"]);
         $newObj->create(true);
         $this->putObjectInTree($newObj);
         // create import directory
         $newObj->createImportDirectory();
         // copy uploaded file to import directory
         $file = pathinfo($upload["name"]);
         $full_path = $newObj->getImportDirectory() . "/" . $upload["name"];
         ilUtil::moveUploadedFile($upload["tmp_name"], $upload["name"], $full_path);
         // unzip file
         ilUtil::unzip($full_path);
         // determine filename of xml file
         $subdir = basename($file["basename"], "." . $file["extension"]);
         $xml_file = $newObj->getImportDirectory() . "/" . $subdir . "/" . $subdir . ".xml";
         // check whether this is a new export file.
         // this is the case if manifest.xml exits
         //echo "1-".$newObj->getImportDirectory()."/".$subdir."/manifest.xml"."-";
         if (is_file($newObj->getImportDirectory() . "/" . $subdir . "/manifest.xml")) {
             include_once "./Services/Export/classes/class.ilImport.php";
             $imp = new ilImport((int) $_GET["ref_id"]);
             $map = $imp->getMapping();
             $map->addMapping("Modules/Glossary", "glo", "new_id", $newObj->getId());
             $imp->importObject($newObj, $full_path, $upload["name"], "glo", "Modules/Glossary", true);
             ilUtil::sendSuccess($this->lng->txt("glo_added"), true);
             ilUtil::redirect("ilias.php?baseClass=ilGlossaryEditorGUI&ref_id=" . $newObj->getRefId());
         }
         // check whether subdirectory exists within zip file
         if (!is_dir($newObj->getImportDirectory() . "/" . $subdir)) {
             $this->ilias->raiseError(sprintf($this->lng->txt("cont_no_subdir_in_zip"), $subdir), $this->ilias->error_obj->MESSAGE);
         }
         // check whether xml file exists within zip file
         if (!is_file($xml_file)) {
             $this->ilias->raiseError(sprintf($this->lng->txt("cont_zip_file_invalid"), $subdir . "/" . $subdir . ".xml"), $this->ilias->error_obj->MESSAGE);
         }
         include_once "./Modules/LearningModule/classes/class.ilContObjParser.php";
         $contParser = new ilContObjParser($newObj, $xml_file, $subdir);
         $contParser->startParsing();
         ilObject::_writeImportId($newObj->getId(), $newObj->getImportId());
         // delete import directory
         ilUtil::delDir($newObj->getImportDirectory());
         ilUtil::sendSuccess($this->lng->txt("glo_added"), true);
         ilUtil::redirect("ilias.php?baseClass=ilGlossaryEditorGUI&ref_id=" . $newObj->getRefId());
     }
     // display form to correct errors
     $form->setValuesByPost();
     $tpl->setContent($form->getHtml());
 }