/**
  * Get xml representation
  *
  * @param	string		entity
  * @param	string		target release
  * @param	string		id
  * @return	string		xml string
  */
 public function getXmlRepresentation($a_entity, $a_schema_version, $a_id)
 {
     $refs = ilObject::_getAllReferences($a_id);
     $svy_ref_id = current($refs);
     include_once './Modules/Survey/classes/class.ilObjSurvey.php';
     $svy = new ilObjSurvey($a_id, false);
     $svy->loadFromDb();
     include_once "./Modules/Survey/classes/class.ilSurveyExport.php";
     $svy_exp = new ilSurveyExport($svy, 'xml');
     $zip = $svy_exp->buildExportFile();
     // Unzip, since survey deletes this dir
     ilUtil::unzip($zip);
     $GLOBALS['ilLog']->write(__METHOD__ . ': Created zip file ' . $zip);
 }
 /**
  * Download all submitted files of an assignment (all user)
  *
  * @param	$members		array of user names, key is user id
  */
 function downloadAllDeliveredFiles($a_exc_id, $a_ass_id, $members)
 {
     global $lng, $ilObjDataCache, $ilias;
     include_once "./Services/Utilities/classes/class.ilUtil.php";
     include_once "./Modules/Exercise/classes/class.ilFSStorageExercise.php";
     $storage = new ilFSStorageExercise($a_exc_id, $a_ass_id);
     $storage->create();
     ksort($members);
     //$savepath = $this->getExercisePath() . "/" . $this->obj_id . "/";
     $savepath = $storage->getAbsoluteSubmissionPath();
     $cdir = getcwd();
     // important check: if the directory does not exist
     // ILIAS stays in the current directory (echoing only a warning)
     // and the zip command below archives the whole ILIAS directory
     // (including the data directory) and sends a mega file to the user :-o
     if (!is_dir($savepath)) {
         return;
     }
     // Safe mode fix
     //		chdir($this->getExercisePath());
     chdir($storage->getTempPath());
     $zip = PATH_TO_ZIP;
     // check first, if we have enough free disk space to copy all files to temporary directory
     $tmpdir = ilUtil::ilTempnam();
     ilUtil::makeDir($tmpdir);
     chdir($tmpdir);
     $dirsize = 0;
     foreach ($members as $id => $object) {
         $directory = $savepath . DIRECTORY_SEPARATOR . $id;
         $dirsize += ilUtil::dirsize($directory);
     }
     if ($dirsize > disk_free_space($tmpdir)) {
         return -1;
     }
     $ass_type = self::lookupType($a_ass_id);
     // copy all member directories to the temporary folder
     // switch from id to member name and append the login if the member name is double
     // ensure that no illegal filenames will be created
     // remove timestamp from filename
     $cache = array();
     foreach ($members as $id => $user) {
         $sourcedir = $savepath . DIRECTORY_SEPARATOR . $id;
         if (!is_dir($sourcedir)) {
             continue;
         }
         $userName = ilObjUser::_lookupName($id);
         $directory = ilUtil::getASCIIFilename(trim($userName["lastname"]) . "_" . trim($userName["firstname"]));
         if (array_key_exists($directory, $cache)) {
             // first try is to append the login;
             $directory = ilUtil::getASCIIFilename($directory . "_" . trim(ilObjUser::_lookupLogin($id)));
             if (array_key_exists($directory, $cache)) {
                 // second and secure: append the user id as well.
                 $directory .= "_" . $id;
             }
         }
         $cache[$directory] = $directory;
         ilUtil::makeDir($directory);
         $sourcefiles = scandir($sourcedir);
         foreach ($sourcefiles as $sourcefile) {
             if ($sourcefile == "." || $sourcefile == "..") {
                 continue;
             }
             $targetfile = trim(basename($sourcefile));
             $pos = strpos($targetfile, "_");
             if ($pos !== false) {
                 $targetfile = substr($targetfile, $pos + 1);
             }
             $targetfile = $directory . DIRECTORY_SEPARATOR . $targetfile;
             $sourcefile = $sourcedir . DIRECTORY_SEPARATOR . $sourcefile;
             if (!copy($sourcefile, $targetfile)) {
                 //echo 'Could not copy '.$sourcefile.' to '.$targetfile;
                 $ilias->raiseError('Could not copy ' . basename($sourcefile) . " to '" . $targetfile . "'.", $ilias->error_obj->MESSAGE);
             } else {
                 // preserve time stamp
                 touch($targetfile, filectime($sourcefile));
                 // blogs and portfolios are stored as zip and have to be unzipped
                 if ($ass_type == ilExAssignment::TYPE_PORTFOLIO || $ass_type == ilExAssignment::TYPE_BLOG) {
                     ilUtil::unzip($targetfile);
                     unlink($targetfile);
                 }
             }
         }
     }
     $tmpfile = ilUtil::ilTempnam();
     $tmpzipfile = $tmpfile . ".zip";
     // Safe mode fix
     $zipcmd = $zip . " -r " . ilUtil::escapeShellArg($tmpzipfile) . " .";
     exec($zipcmd);
     ilUtil::delDir($tmpdir);
     $assTitle = ilExAssignment::lookupTitle($a_ass_id);
     chdir($cdir);
     ilUtil::deliverFile($tmpzipfile, (strlen($assTitle) == 0 ? strtolower($lng->txt("exc_assignment")) : $assTitle) . ".zip", "", false, true);
 }
Beispiel #3
0
 /**
  * imports test and question(s)
  */
 function uploadTstObject()
 {
     if ($_FILES["xmldoc"]["error"] > UPLOAD_ERR_OK) {
         ilUtil::sendFailure($this->lng->txt("error_upload"));
         $this->createObject();
         return;
     }
     include_once "./Modules/Test/classes/class.ilObjTest.php";
     // create import directory
     $basedir = ilObjTest::_createImportDirectory();
     // copy uploaded file to import directory
     $file = pathinfo($_FILES["xmldoc"]["name"]);
     $full_path = $basedir . "/" . $_FILES["xmldoc"]["name"];
     ilUtil::moveUploadedFile($_FILES["xmldoc"]["tmp_name"], $_FILES["xmldoc"]["name"], $full_path);
     // unzip file
     ilUtil::unzip($full_path);
     // determine filenames of xml files
     $subdir = basename($file["basename"], "." . $file["extension"]);
     ilObjTest::_setImportDirectory($basedir);
     $xml_file = ilObjTest::_getImportDirectory() . '/' . $subdir . '/' . $subdir . ".xml";
     $qti_file = ilObjTest::_getImportDirectory() . '/' . $subdir . '/' . preg_replace("/test|tst/", "qti", $subdir) . ".xml";
     $results_file = ilObjTest::_getImportDirectory() . '/' . $subdir . '/' . preg_replace("/test|tst/", "results", $subdir) . ".xml";
     if (!is_file($qti_file)) {
         ilUtil::delDir($basedir);
         ilUtil::sendFailure($this->lng->txt("tst_import_non_ilias_zip"));
         $this->createObject();
         return;
     }
     // 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::sendInfo($this->lng->txt("tst_import_no_items"));
         $this->createObject();
         return;
     }
     $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::sendInfo($this->lng->txt("qpl_import_non_ilias_files"));
         $this->createObject();
         return;
     }
     $_SESSION["tst_import_results_file"] = $results_file;
     $_SESSION["tst_import_xml_file"] = $xml_file;
     $_SESSION["tst_import_qti_file"] = $qti_file;
     $_SESSION["tst_import_subdir"] = $subdir;
     // display of found questions
     $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.tst_import_verification.html", "Modules/Test");
     $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 "MULTIPLE CHOICE QUESTION":
             case QT_MULTIPLE_CHOICE_MR:
                 //$this->tpl->setVariable("QUESTION_TYPE", $this->lng->txt("qt_multiple_choice"));
                 $this->tpl->setVariable("QUESTION_TYPE", $this->lng->txt("assMultipleChoice"));
                 break;
             case "SINGLE CHOICE QUESTION":
             case QT_MULTIPLE_CHOICE_SR:
                 $this->tpl->setVariable("QUESTION_TYPE", $this->lng->txt("assSingleChoice"));
                 break;
             case KPRIM_CHOICE_QUESTION_IDENTIFIER:
             case QT_KPRIM_CHOICE:
                 $this->tpl->setVariable("QUESTION_TYPE", $this->lng->txt("assKprimChoice"));
                 break;
             case "NUMERIC QUESTION":
             case QT_NUMERIC:
                 $this->tpl->setVariable("QUESTION_TYPE", $this->lng->txt("assNumeric"));
                 break;
             case "TEXTSUBSET QUESTION":
             case QT_TEXTSUBSET:
                 $this->tpl->setVariable("QUESTION_TYPE", $this->lng->txt("assTextSubset"));
                 break;
             case "CLOZE QUESTION":
             case QT_CLOZE:
                 $this->tpl->setVariable("QUESTION_TYPE", $this->lng->txt("assClozeTest"));
                 break;
             case "IMAGE MAP QUESTION":
             case QT_IMAGEMAP:
                 $this->tpl->setVariable("QUESTION_TYPE", $this->lng->txt("assImagemapQuestion"));
                 break;
             case "JAVA APPLET QUESTION":
             case QT_JAVAAPPLET:
                 $this->tpl->setVariable("QUESTION_TYPE", $this->lng->txt("assJavaApplet"));
                 break;
             case "MATCHING QUESTION":
             case QT_MATCHING:
                 $this->tpl->setVariable("QUESTION_TYPE", $this->lng->txt("assMatchingQuestion"));
                 break;
             case "ORDERING QUESTION":
             case QT_ORDERING:
                 $this->tpl->setVariable("QUESTION_TYPE", $this->lng->txt("assOrderingQuestion"));
                 break;
             case "TEXT QUESTION":
             case QT_TEXT:
                 $this->tpl->setVariable("QUESTION_TYPE", $this->lng->txt("assTextQuestion"));
                 break;
         }
         $this->tpl->parseCurrentBlock();
     }
     // on import creation screen the pool was chosen (-1 for no pool)
     // BUT when no pool is available the input on creation screen is missing, so the field value -1 for no pool is not submitted.
     $QplOrTstID = isset($_POST["qpl"]) && (int) $_POST["qpl"] != 0 ? $_POST["qpl"] : -1;
     $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("tst_import_verify_found_questions"));
     $this->tpl->setVariable("VERIFICATION_HEADING", $this->lng->txt("import_tst"));
     $this->tpl->setVariable("FORMACTION", $this->ctrl->getFormAction($this));
     $this->tpl->setVariable("ARROW", ilUtil::getImagePath("arrow_downright.svg"));
     $this->tpl->setVariable("QUESTIONPOOL_ID", $QplOrTstID);
     $this->tpl->setVariable("VALUE_IMPORT", $this->lng->txt("import"));
     $this->tpl->setVariable("VALUE_CANCEL", $this->lng->txt("cancel"));
     $this->tpl->parseCurrentBlock();
 }
 /**
  * Add subitems
  * @param object $a_id
  * @param object $a_type
  * @return 
  */
 protected function addSubitems($a_id, $a_type, $a_target_release)
 {
     $GLOBALS['ilLog']->write(__METHOD__);
     $set_number = 1;
     foreach ($this->eo->getSubitemsForExport() as $ref_id) {
         // get last export file
         $obj_id = ilObject::_lookupObjId($ref_id);
         $expi = ilExportFileInfo::lookupLastExport($obj_id, 'xml', $a_target_release);
         if (!$expi instanceof ilExportFileInfo) {
             $GLOBALS['ilLog']->write(__METHOD__ . ': Cannot find export file for refId ' . $ref_id . ', type ' . ilObject::_lookupType($a_id));
             continue;
         }
         $exp_dir = ilExport::_getExportDirectory($obj_id, 'xml', ilObject::_lookupType($obj_id));
         $exp_full = $exp_dir . DIRECTORY_SEPARATOR . $expi->getFilename();
         $GLOBALS['ilLog']->write(__METHOD__ . ': zip path ' . $exp_full);
         // Unzip
         ilUtil::unzip($exp_full, true, false);
         // create set directory
         ilUtil::makeDirParents($this->cont_export_dir . DIRECTORY_SEPARATOR . 'set_' . $set_number);
         // cut .zip
         $new_path_rel = 'set_' . $set_number . DIRECTORY_SEPARATOR . $expi->getBasename();
         $new_path_abs = $this->cont_export_dir . DIRECTORY_SEPARATOR . $new_path_rel;
         $GLOBALS['ilLog']->write(__METHOD__ . ': ' . $new_path_rel . ' ' . $new_path_abs);
         // Move export
         rename($exp_dir . DIRECTORY_SEPARATOR . $expi->getBasename(), $new_path_abs);
         $GLOBALS['ilLog']->write($exp_dir . DIRECTORY_SEPARATOR . $expi->getBasename() . ' -> ' . $new_path_abs);
         // Delete latest container xml of source
         if ($a_id == $obj_id) {
             $expi->delete();
             if (file_exists($exp_full)) {
                 $GLOBALS['ilLog']->write(__METHOD__ . ': Deleting' . $exp_full);
                 unlink($exp_full);
             }
         }
         $this->cont_manifest_writer->xmlElement('ExportSet', array('Path' => $new_path_rel, 'Type' => ilObject::_lookupType($obj_id)));
         ++$set_number;
     }
 }
 /**
  * display form for user import
  */
 function importUserRoleAssignmentObject()
 {
     global $ilUser, $rbacreview, $tpl, $lng, $ilCtrl;
     // Blind out tabs for local user import
     if ($_GET["baseClass"] == 'ilRepositoryGUI') {
         $this->tabs_gui->clearTargets();
     }
     $this->initUserImportForm();
     if ($this->form->checkInput()) {
         include_once './Services/AccessControl/classes/class.ilObjRole.php';
         include_once './Services/User/classes/class.ilUserImportParser.php';
         global $rbacreview, $rbacsystem, $tree, $lng;
         $this->tpl->addBlockfile("ADM_CONTENT", "adm_content", "tpl.usr_import_roles.html", "Services/User");
         $import_dir = $this->getImportDir();
         // recreate user import directory
         if (@is_dir($import_dir)) {
             ilUtil::delDir($import_dir);
         }
         ilUtil::makeDir($import_dir);
         // move uploaded file to user import directory
         $file_name = $_FILES["importFile"]["name"];
         $parts = pathinfo($file_name);
         $full_path = $import_dir . "/" . $file_name;
         // check if import file exists
         if (!is_file($_FILES["importFile"]["tmp_name"])) {
             ilUtil::delDir($import_dir);
             $this->ilias->raiseError($this->lng->txt("no_import_file_found"), $this->ilias->error_obj->MESSAGE);
         }
         ilUtil::moveUploadedFile($_FILES["importFile"]["tmp_name"], $_FILES["importFile"]["name"], $full_path);
         // handle zip file
         if (strtolower($parts["extension"]) == "zip") {
             // unzip file
             ilUtil::unzip($full_path);
             $xml_file = null;
             $file_list = ilUtil::getDir($import_dir);
             foreach ($file_list as $a_file) {
                 if (substr($a_file['entry'], -4) == '.xml') {
                     $xml_file = $import_dir . "/" . $a_file['entry'];
                     break;
                 }
             }
             if (is_null($xml_file)) {
                 $subdir = basename($parts["basename"], "." . $parts["extension"]);
                 $xml_file = $import_dir . "/" . $subdir . "/" . $subdir . ".xml";
             }
         } else {
             $xml_file = $full_path;
         }
         // check xml file
         if (!is_file($xml_file)) {
             ilUtil::delDir($import_dir);
             $this->ilias->raiseError($this->lng->txt("no_xml_file_found_in_zip") . " " . $subdir . "/" . $subdir . ".xml", $this->ilias->error_obj->MESSAGE);
         }
         require_once "./Services/User/classes/class.ilUserImportParser.php";
         // Verify the data
         // ---------------
         $importParser = new ilUserImportParser($xml_file, IL_VERIFY);
         $importParser->startParsing();
         switch ($importParser->getErrorLevel()) {
             case IL_IMPORT_SUCCESS:
                 break;
             case IL_IMPORT_WARNING:
                 $this->tpl->setVariable("IMPORT_LOG", $importParser->getProtocolAsHTML($lng->txt("verification_warning_log")));
                 break;
             case IL_IMPORT_FAILURE:
                 ilUtil::delDir($import_dir);
                 $this->ilias->raiseError($lng->txt("verification_failed") . $importParser->getProtocolAsHTML($lng->txt("verification_failure_log")), $this->ilias->error_obj->MESSAGE);
                 return;
         }
         // Create the role selection form
         // ------------------------------
         $this->tpl->setCurrentBlock("role_selection_form");
         $this->tpl->setVariable("FORMACTION", $this->ctrl->getFormAction($this));
         $this->tpl->setVariable("TXT_IMPORT_USERS", $this->lng->txt("import_users"));
         $this->tpl->setVariable("TXT_IMPORT_FILE", $this->lng->txt("import_file"));
         $this->tpl->setVariable("IMPORT_FILE", $file_name);
         $this->tpl->setVariable("TXT_USER_ELEMENT_COUNT", $this->lng->txt("num_users"));
         $this->tpl->setVariable("USER_ELEMENT_COUNT", $importParser->getUserCount());
         $this->tpl->setVariable("TXT_ROLE_ASSIGNMENT", $this->lng->txt("role_assignment"));
         $this->tpl->setVariable("BTN_IMPORT", $this->lng->txt("import"));
         $this->tpl->setVariable("BTN_CANCEL", $this->lng->txt("cancel"));
         $this->tpl->setVariable("XML_FILE_NAME", $xml_file);
         // Extract the roles
         $importParser = new ilUserImportParser($xml_file, IL_EXTRACT_ROLES);
         $importParser->startParsing();
         $roles = $importParser->getCollectedRoles();
         // get global roles
         $all_gl_roles = $rbacreview->getRoleListByObject(ROLE_FOLDER_ID);
         $gl_roles = array();
         $roles_of_user = $rbacreview->assignedRoles($ilUser->getId());
         foreach ($all_gl_roles as $obj_data) {
             // check assignment permission if called from local admin
             if ($this->object->getRefId() != USER_FOLDER_ID) {
                 if (!in_array(SYSTEM_ROLE_ID, $roles_of_user) && !ilObjRole::_getAssignUsersStatus($obj_data['obj_id'])) {
                     continue;
                 }
             }
             // exclude anonymous role from list
             if ($obj_data["obj_id"] != ANONYMOUS_ROLE_ID) {
                 // do not allow to assign users to administrator role if current user does not has SYSTEM_ROLE_ID
                 if ($obj_data["obj_id"] != SYSTEM_ROLE_ID or in_array(SYSTEM_ROLE_ID, $roles_of_user)) {
                     $gl_roles[$obj_data["obj_id"]] = $obj_data["title"];
                 }
             }
         }
         // global roles
         $got_globals = false;
         foreach ($roles as $role_id => $role) {
             if ($role["type"] == "Global") {
                 if (!$got_globals) {
                     $got_globals = true;
                     $this->tpl->setCurrentBlock("global_role_section");
                     $this->tpl->setVariable("TXT_GLOBAL_ROLES_IMPORT", $this->lng->txt("roles_of_import_global"));
                     $this->tpl->setVariable("TXT_GLOBAL_ROLES", $this->lng->txt("assign_global_role"));
                 }
                 // pre selection for role
                 $pre_select = array_search($role[name], $gl_roles);
                 if (!$pre_select) {
                     switch ($role["name"]) {
                         case "Administrator":
                             // ILIAS 2/3 Administrator
                             $pre_select = array_search("Administrator", $gl_roles);
                             break;
                         case "Autor":
                             // ILIAS 2 Author
                             $pre_select = array_search("User", $gl_roles);
                             break;
                         case "Lerner":
                             // ILIAS 2 Learner
                             $pre_select = array_search("User", $gl_roles);
                             break;
                         case "Gast":
                             // ILIAS 2 Guest
                             $pre_select = array_search("Guest", $gl_roles);
                             break;
                         default:
                             $pre_select = array_search("User", $gl_roles);
                             break;
                     }
                 }
                 $this->tpl->setCurrentBlock("global_role");
                 $role_select = ilUtil::formSelect($pre_select, "role_assign[" . $role_id . "]", $gl_roles, false, true);
                 $this->tpl->setVariable("TXT_IMPORT_GLOBAL_ROLE", $role["name"] . " [" . $role_id . "]");
                 $this->tpl->setVariable("SELECT_GLOBAL_ROLE", $role_select);
                 $this->tpl->parseCurrentBlock();
             }
         }
         // Check if local roles need to be assigned
         $got_locals = false;
         foreach ($roles as $role_id => $role) {
             if ($role["type"] == "Local") {
                 $got_locals = true;
                 break;
             }
         }
         if ($got_locals) {
             $this->tpl->setCurrentBlock("local_role_section");
             $this->tpl->setVariable("TXT_LOCAL_ROLES_IMPORT", $this->lng->txt("roles_of_import_local"));
             $this->tpl->setVariable("TXT_LOCAL_ROLES", $this->lng->txt("assign_local_role"));
             // get local roles
             if ($this->object->getRefId() == USER_FOLDER_ID) {
                 // The import function has been invoked from the user folder
                 // object. In this case, we show only matching roles,
                 // because the user folder object is considered the parent of all
                 // local roles and may contains thousands of roles on large ILIAS
                 // installations.
                 $loc_roles = array();
                 foreach ($roles as $role_id => $role) {
                     if ($role["type"] == "Local") {
                         $searchName = substr($role['name'], 0, 1) == '#' ? $role['name'] : '#' . $role['name'];
                         $matching_role_ids = $rbacreview->searchRolesByMailboxAddressList($searchName);
                         foreach ($matching_role_ids as $mid) {
                             if (!in_array($mid, $loc_roles)) {
                                 $loc_roles[] = array('obj_id' => $mid);
                             }
                         }
                     }
                 }
             } else {
                 // The import function has been invoked from a locally
                 // administrated category. In this case, we show all roles
                 // contained in the subtree of the category.
                 $loc_roles = $rbacreview->getAssignableRolesInSubtree($this->object->getRefId());
             }
             $l_roles = array();
             // create a search array with  .
             $l_roles_mailbox_searcharray = array();
             foreach ($loc_roles as $key => $loc_role) {
                 // fetch context path of role
                 $rolf = $rbacreview->getFoldersAssignedToRole($loc_role["obj_id"], true);
                 // only process role folders that are not set to status "deleted"
                 // and for which the user has write permissions.
                 // We also don't show the roles which are in the ROLE_FOLDER_ID folder.
                 // (The ROLE_FOLDER_ID folder contains the global roles).
                 if (!$rbacreview->isDeleted($rolf[0]) && $rbacsystem->checkAccess('write', $tree->getParentId($rolf[0])) && $rolf[0] != ROLE_FOLDER_ID) {
                     // A local role is only displayed, if it is contained in the subtree of
                     // the localy administrated category. If the import function has been
                     // invoked from the user folder object, we show all local roles, because
                     // the user folder object is considered the parent of all local roles.
                     // Thus, if we start from the user folder object, we initialize the
                     // isInSubtree variable with true. In all other cases it is initialized
                     // with false, and only set to true if we find the object id of the
                     // locally administrated category in the tree path to the local role.
                     $isInSubtree = $this->object->getRefId() == USER_FOLDER_ID;
                     $path = "";
                     if ($this->tree->isInTree($rolf[0])) {
                         // Create path. Paths which have more than 4 segments
                         // are truncated in the middle.
                         $tmpPath = $this->tree->getPathFull($rolf[0]);
                         for ($i = 1, $n = count($tmpPath) - 1; $i < $n; $i++) {
                             if ($i > 1) {
                                 $path = $path . ' > ';
                             }
                             if ($i < 3 || $i > $n - 3) {
                                 $path = $path . $tmpPath[$i]['title'];
                             } else {
                                 if ($i == 3 || $i == $n - 3) {
                                     $path = $path . '...';
                                 }
                             }
                             $isInSubtree |= $tmpPath[$i]['obj_id'] == $this->object->getId();
                         }
                     } else {
                         $path = "<b>Rolefolder " . $rolf[0] . " not found in tree! (Role " . $loc_role["obj_id"] . ")</b>";
                     }
                     $roleMailboxAddress = $rbacreview->getRoleMailboxAddress($loc_role['obj_id']);
                     $l_roles[$loc_role['obj_id']] = $roleMailboxAddress . ', ' . $path;
                 }
             }
             //foreach role
             $l_roles[""] = "";
             natcasesort($l_roles);
             $l_roles[""] = $this->lng->txt("usrimport_ignore_role");
             foreach ($roles as $role_id => $role) {
                 if ($role["type"] == "Local") {
                     $this->tpl->setCurrentBlock("local_role");
                     $this->tpl->setVariable("TXT_IMPORT_LOCAL_ROLE", $role["name"]);
                     $searchName = substr($role['name'], 0, 1) == '#' ? $role['name'] : '#' . $role['name'];
                     $matching_role_ids = $rbacreview->searchRolesByMailboxAddressList($searchName);
                     $pre_select = count($matching_role_ids) == 1 ? $matching_role_ids[0] : "";
                     if ($this->object->getRefId() == USER_FOLDER_ID) {
                         // There are too many roles in a large ILIAS installation
                         // that's why whe show only a choice with the the option "ignore",
                         // and the matching roles.
                         $selectable_roles = array();
                         $selectable_roles[""] = $this->lng->txt("usrimport_ignore_role");
                         foreach ($matching_role_ids as $id) {
                             $selectable_roles[$id] = $l_roles[$id];
                         }
                         $role_select = ilUtil::formSelect($pre_select, "role_assign[" . $role_id . "]", $selectable_roles, false, true);
                     } else {
                         $role_select = ilUtil::formSelect($pre_select, "role_assign[" . $role_id . "]", $l_roles, false, true);
                     }
                     $this->tpl->setVariable("SELECT_LOCAL_ROLE", $role_select);
                     $this->tpl->parseCurrentBlock();
                 }
             }
         }
         //
         $this->tpl->setVariable("TXT_CONFLICT_HANDLING", $lng->txt("conflict_handling"));
         $handlers = array(IL_IGNORE_ON_CONFLICT => "ignore_on_conflict", IL_UPDATE_ON_CONFLICT => "update_on_conflict");
         $this->tpl->setVariable("TXT_CONFLICT_HANDLING_INFO", str_replace('\\n', '<br>', $this->lng->txt("usrimport_conflict_handling_info")));
         $this->tpl->setVariable("TXT_CONFLICT_CHOICE", $lng->txt("conflict_handling"));
         $this->tpl->setVariable("SELECT_CONFLICT", ilUtil::formSelect(IL_IGNORE_ON_CONFLICT, "conflict_handling_choice", $handlers, false, false));
         // new account mail
         $this->lng->loadLanguageModule("mail");
         include_once './Services/User/classes/class.ilObjUserFolder.php';
         $amail = ilObjUserFolder::_lookupNewAccountMail($this->lng->getDefaultLanguage());
         if (trim($amail["body"]) != "" && trim($amail["subject"]) != "") {
             $this->tpl->setCurrentBlock("inform_user");
             $this->tpl->setVariable("TXT_ACCOUNT_MAIL", $lng->txt("mail_account_mail"));
             if (true) {
                 $this->tpl->setVariable("SEND_MAIL", " checked=\"checked\"");
             }
             $this->tpl->setVariable("TXT_INFORM_USER_MAIL", $this->lng->txt("user_send_new_account_mail"));
             $this->tpl->parseCurrentBlock();
         }
     } else {
         $this->form->setValuesByPost();
         $tpl->setContent($this->form->getHtml());
     }
 }
Beispiel #6
0
 /**
  * Import repository object export file
  *
  * @param	string		absolute filename of temporary upload file
  */
 public final function importObject($a_new_obj, $a_tmp_file, $a_filename, $a_type, $a_comp = "", $a_copy_file = false)
 {
     // create temporary directory
     $tmpdir = ilUtil::ilTempnam();
     ilUtil::makeDir($tmpdir);
     if ($a_copy_file) {
         copy($a_tmp_file, $tmpdir . "/" . $a_filename);
     } else {
         ilUtil::moveUploadedFile($a_tmp_file, $a_filename, $tmpdir . "/" . $a_filename);
     }
     ilUtil::unzip($tmpdir . "/" . $a_filename);
     $dir = $tmpdir . "/" . substr($a_filename, 0, strlen($a_filename) - 4);
     $GLOBALS['ilLog']->write(__METHOD__ . ': do import with dir ' . $dir);
     $new_id = $this->doImportObject($dir, $a_type, $a_comp, $tmpdir);
     // delete temporary directory
     ilUtil::delDir($tmpdir);
     return $new_id;
 }
 /**
  * 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;
 }
 /**
  * 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;
 }
 /**
  * delete object file
  */
 function unzipFile()
 {
     global $lng;
     if (isset($_GET["upfile"])) {
         $file = basename($_GET["upfile"]);
     } else {
         if (!isset($_POST["file"])) {
             $this->ilias->raiseError($this->lng->txt("no_checkbox"), $this->ilias->error_obj->MESSAGE);
         }
         if (count($_POST["file"]) > 1) {
             $this->ilias->raiseError($this->lng->txt("cont_select_max_one_item"), $this->ilias->error_obj->MESSAGE);
         }
         $file = basename($_POST["file"][0]);
     }
     $cur_subdir = str_replace(".", "", ilUtil::stripSlashes($_GET["cdir"]));
     $cur_dir = !empty($cur_subdir) ? $this->main_dir . "/" . $cur_subdir : $this->main_dir;
     $file = $cur_dir . "/" . ilUtil::stripSlashes($file);
     if (@is_file($file)) {
         $cur_files = array_keys(ilUtil::getDir($cur_dir));
         if ($this->getAllowDirectories()) {
             ilUtil::unzip($file, true);
         } else {
             ilUtil::unzip($file, true, true);
         }
         $new_files = array_keys(ilUtil::getDir($cur_dir));
         $diff = array_diff($new_files, $cur_files);
         if (sizeof($diff)) {
             if ($this->getAllowDirectories()) {
                 include_once "./Services/Utilities/classes/class.ilFileUtils.php";
                 $new_files = array();
                 foreach ($diff as $new_item) {
                     if (is_dir($cur_dir . "/" . $new_item)) {
                         ilFileUtils::recursive_dirscan($cur_dir . "/" . $new_item, $new_files);
                     }
                 }
                 if (is_array($new_files["path"])) {
                     foreach ($new_files["path"] as $idx => $path) {
                         $path = substr($path, strlen($this->main_dir) + 1);
                         $diff[] = $path . $new_files["file"][$idx];
                     }
                 }
             }
             $this->setPerformedCommand("unzip_file", array("name" => substr($file, strlen($this->main_dir) + 1), "added" => $diff));
         }
     }
     ilUtil::renameExecutables($this->main_dir);
     $this->ctrl->saveParameter($this, "cdir");
     ilUtil::sendSuccess($lng->txt("cont_file_unzipped"), true);
     $this->ctrl->redirect($this, "listFiles");
 }
 /**
  * Reads an import ZIP file and creates a certificate of it
  *
  * @return boolean TRUE if the import succeeds, FALSE otherwise
  */
 public function importCertificate($zipfile, $filename)
 {
     include_once "./Services/Utilities/classes/class.ilUtil.php";
     $importpath = $this->createArchiveDirectory();
     if (!ilUtil::moveUploadedFile($zipfile, $filename, $importpath . $filename)) {
         ilUtil::delDir($importpath);
         return FALSE;
     }
     ilUtil::unzip($importpath . $filename, TRUE);
     $subdir = str_replace(".zip", "", strtolower($filename)) . "/";
     $copydir = "";
     if (is_dir($importpath . $subdir)) {
         $dirinfo = ilUtil::getDir($importpath . $subdir);
         $copydir = $importpath . $subdir;
     } else {
         $dirinfo = ilUtil::getDir($importpath);
         $copydir = $importpath;
     }
     $xmlfiles = 0;
     $otherfiles = 0;
     foreach ($dirinfo as $file) {
         if (strcmp($file["type"], "file") == 0) {
             if (strpos($file["entry"], ".xml") !== FALSE) {
                 $xmlfiles++;
             } else {
                 if (strpos($file["entry"], ".zip") !== FALSE) {
                 } else {
                     $otherfiles++;
                 }
             }
         }
     }
     // if one XML file is in the archive, we try to import it
     if ($xmlfiles == 1) {
         foreach ($dirinfo as $file) {
             if (strcmp($file["type"], "file") == 0) {
                 if (strpos($file["entry"], ".xml") !== FALSE) {
                     $xsl = file_get_contents($copydir . $file["entry"]);
                     // as long as we cannot make RPC calls in a given directory, we have
                     // to add the complete path to every url
                     $xsl = preg_replace("/url\\([']{0,1}(.*?)[']{0,1}\\)/", "url(" . $this->getAdapter()->getCertificatePath() . "\${1})", $xsl);
                     $this->saveCertificate($xsl);
                 } else {
                     if (strpos($file["entry"], ".zip") !== FALSE) {
                     } else {
                         @copy($copydir . $file["entry"], $this->getAdapter()->getCertificatePath() . $file["entry"]);
                         if (strcmp($this->getBackgroundImagePath(), $this->getAdapter()->getCertificatePath() . $file["entry"]) == 0) {
                             // upload of the background image, create a preview
                             ilUtil::convertImage($this->getBackgroundImagePath(), $this->getBackgroundImageThumbPath(), "JPEG", 100);
                         }
                     }
                 }
             }
         }
     } else {
         ilUtil::delDir($importpath);
         return FALSE;
     }
     ilUtil::delDir($importpath);
     return TRUE;
 }
 /**
  * import categories (static, also called by RootFolderGUI)
  */
 function _importCategories($a_ref_id, $withrol_tmp)
 {
     global $lng;
     require_once "./Modules/Category/classes/class.ilCategoryImportParser.php";
     $import_dir = ilObjCategoryGUI::_getImportDir();
     // create user import directory if necessary
     if (!@is_dir($import_dir)) {
         ilUtil::createDirectory($import_dir);
     }
     // move uploaded file to user import directory
     $file_name = $_FILES["importFile"]["name"];
     // added to prevent empty file names
     if (!strcmp($file_name, "")) {
         ilUtil::sendFailure($lng->txt("no_import_file_found"), true);
         $this->ctrl->redirect($this);
     }
     $parts = pathinfo($file_name);
     $full_path = $import_dir . "/" . $file_name;
     //move_uploaded_file($_FILES["importFile"]["tmp_name"], $full_path);
     ilUtil::moveUploadedFile($_FILES["importFile"]["tmp_name"], $file_name, $full_path);
     // unzip file
     ilUtil::unzip($full_path);
     $subdir = basename($parts["basename"], "." . $parts["extension"]);
     $xml_file = $import_dir . "/" . $subdir . "/" . $subdir . ".xml";
     // CategoryImportParser
     //var_dump($_POST);
     $importParser = new ilCategoryImportParser($xml_file, $a_ref_id, $withrol_tmp);
     $importParser->startParsing();
     ilUtil::sendSuccess($lng->txt("categories_imported"), true);
     $this->ctrl->redirect($this);
 }
 function unzip()
 {
     foreach ($this->getFiles() as $file_data) {
         ilUtil::unzip($file_data["abs_path"]);
         return true;
     }
     return false;
 }
 /**
  * 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());
 }
 function unpackImportFile()
 {
     return ilUtil::unzip($this->getCoursePath() . '/import/crs_' . $this->course_id . '/' . $this->import_file_info['basename']);
 }
 function unpackImportFile()
 {
     return ilUtil::unzip($this->getGroupPath() . '/import/' . $this->import_file_info['basename']);
 }
 /**
  * Upload multi feedback file
  *
  * @param array 
  * @return
  */
 function uploadMultiFeedbackFile($a_file)
 {
     global $lng, $ilUser;
     include_once "./Modules/Exercise/exceptions/class.ilExerciseException.php";
     if (!is_file($a_file["tmp_name"])) {
         throw new ilExerciseException($lng->txt("exc_feedback_file_could_not_be_uploaded"));
     }
     include_once "./Modules/Exercise/classes/class.ilFSStorageExercise.php";
     $storage = new ilFSStorageExercise($this->getExerciseId(), $this->getId());
     $mfu = $storage->getMultiFeedbackUploadPath($ilUser->getId());
     ilUtil::delDir($mfu, true);
     ilUtil::moveUploadedFile($a_file["tmp_name"], "multi_feedback.zip", $mfu . "/" . "multi_feedback.zip");
     ilUtil::unzip($mfu . "/multi_feedback.zip", true);
     $subdirs = ilUtil::getDir($mfu);
     $subdir = "notfound";
     foreach ($subdirs as $s => $j) {
         if ($j["type"] == "dir" && substr($s, 0, 14) == "multi_feedback") {
             $subdir = $s;
         }
     }
     if (!is_dir($mfu . "/" . $subdir)) {
         throw new ilExerciseException($lng->txt("exc_no_feedback_dir_found_in_zip"));
     }
     return true;
 }
 function importSave()
 {
     global $_FILES, $rbacsystem;
     global $ilias, $lng;
     // check if file was uploaded
     $source = $_FILES["scormfile"]["tmp_name"];
     if ($source == 'none' || !$source) {
         $ilias->raiseError("No file selected!", $ilias->error_obj->MESSAGE);
     }
     // check create permission
     if (!$rbacsystem->checkAccess("create", $_GET["ref_id"], "sahs")) {
         $ilias->raiseError($lng->txt("no_create_permission"), $ilias->error_obj->WARNING);
     }
     // get_cfg_var("upload_max_filesize"); // get the may filesize form t he php.ini
     switch ($__FILES["scormfile"]["error"]) {
         case UPLOAD_ERR_INI_SIZE:
             $ilias->raiseError($lng->txt("err_max_file_size_exceeds"), $ilias->error_obj->MESSAGE);
             break;
         case UPLOAD_ERR_FORM_SIZE:
             $ilias->raiseError($lng->txt("err_max_file_size_exceeds"), $ilias->error_obj->MESSAGE);
             break;
         case UPLOAD_ERR_PARTIAL:
             $ilias->raiseError($lng->txt("err_partial_file_upload"), $ilias->error_obj->MESSAGE);
             break;
         case UPLOAD_ERR_NO_FILE:
             $ilias->raiseError($lng->txt("err_no_file_uploaded"), $ilias->error_obj->MESSAGE);
             break;
     }
     $file = pathinfo($_FILES["scormfile"]["name"]);
     $name = substr($file["basename"], 0, strlen($file["basename"]) - strlen($file["extension"]) - 1);
     $file_path = $this->slm_object->getDataDirectory() . "/" . $this->node_object->getId() . "/" . $_FILES["scormfile"]["name"];
     ilUtil::createDirectory($this->slm_object->getDataDirectory() . "/" . $this->node_object->getId());
     ilUtil::moveUploadedFile($_FILES["scormfile"]["tmp_name"], $_FILES["scormfile"]["name"], $file_path);
     ilUtil::unzip($file_path);
     ilUtil::renameExecutables($this->slm_object->getDataDirectory() . "/" . $this->node_object->getId());
     include_once "./Modules/Scorm2004/classes/ilSCORM13Package.php";
     $newPack = new ilSCORM13Package();
     $newPack->il_importSco($this->slm_object->getId(), $this->node_object->getId(), $this->slm_object->getDataDirectory() . "/" . $this->node_object->getId());
     $this->ctrl->redirect($this, "showOrganization");
 }
 /**
  * display status information or report errors messages
  * in case of error
  *
  * @access	public
  */
 function uploadObject()
 {
     global $_FILES, $rbacsystem;
     include_once 'Services/FileSystem/classes/class.ilUploadFiles.php';
     // check create permission
     if (!$rbacsystem->checkAccess("create", $_GET["ref_id"], "sahs")) {
         $this->ilias->raiseError($this->lng->txt("no_create_permission"), $this->ilias->error_obj->WARNING);
     } elseif ($_FILES["scormfile"]["name"]) {
         // check if file was uploaded
         $source = $_FILES["scormfile"]["tmp_name"];
         if ($source == 'none' || !$source) {
             $this->ilias->raiseError($this->lng->txt("msg_no_file"), $this->ilias->error_obj->MESSAGE);
         }
         // get_cfg_var("upload_max_filesize"); // get the may filesize form t he php.ini
         switch ($__FILES["scormfile"]["error"]) {
             case UPLOAD_ERR_INI_SIZE:
                 $this->ilias->raiseError($this->lng->txt("err_max_file_size_exceeds"), $this->ilias->error_obj->MESSAGE);
                 break;
             case UPLOAD_ERR_FORM_SIZE:
                 $this->ilias->raiseError($this->lng->txt("err_max_file_size_exceeds"), $this->ilias->error_obj->MESSAGE);
                 break;
             case UPLOAD_ERR_PARTIAL:
                 $this->ilias->raiseError($this->lng->txt("err_partial_file_upload"), $this->ilias->error_obj->MESSAGE);
                 break;
             case UPLOAD_ERR_NO_FILE:
                 $this->ilias->raiseError($this->lng->txt("err_no_file_uploaded"), $this->ilias->error_obj->MESSAGE);
                 break;
         }
         $file = pathinfo($_FILES["scormfile"]["name"]);
     } elseif ($_POST["uploaded_file"]) {
         // check if the file is in the upload directory and readable
         if (!ilUploadFiles::_checkUploadFile($_POST["uploaded_file"])) {
             $this->ilias->raiseError($this->lng->txt("upload_error_file_not_found"), $this->ilias->error_obj->MESSAGE);
         }
         $file = pathinfo($_POST["uploaded_file"]);
     } else {
         $this->ilias->raiseError($this->lng->txt("msg_no_file"), $this->ilias->error_obj->MESSAGE);
     }
     $name = substr($file["basename"], 0, strlen($file["basename"]) - strlen($file["extension"]) - 1);
     if ($name == "") {
         $name = $this->lng->txt("no_title");
     }
     // create and insert object in objecttree
     switch ($_POST["sub_type"]) {
         case "scorm2004":
             include_once "./Modules/Scorm2004/classes/class.ilObjSCORM2004LearningModule.php";
             $newObj = new ilObjSCORM2004LearningModule();
             $newObj->setEditable($_POST["editable"] == 'y');
             $newObj->setImportSequencing($_POST["import_sequencing"]);
             $newObj->setSequencingExpertMode($_POST["import_sequencing"]);
             break;
         case "scorm":
             include_once "./Modules/ScormAicc/classes/class.ilObjSCORMLearningModule.php";
             $newObj = new ilObjSCORMLearningModule();
             break;
         case "aicc":
             include_once "./Modules/ScormAicc/classes/class.ilObjAICCLearningModule.php";
             $newObj = new ilObjAICCLearningModule();
             break;
         case "hacp":
             include_once "./Modules/ScormAicc/classes/class.ilObjHACPLearningModule.php";
             $newObj = new ilObjHACPLearningModule();
             break;
     }
     $newObj->setTitle($name);
     $newObj->setSubType($_POST["sub_type"]);
     $newObj->setDescription("");
     $newObj->create(true);
     $newObj->createReference();
     $newObj->putInTree($_GET["ref_id"]);
     $newObj->setPermissions($_GET["ref_id"]);
     $newObj->notify("new", $_GET["ref_id"], $_GET["parent_non_rbac_id"], $_GET["ref_id"], $newObj->getRefId());
     // create data directory, copy file to directory
     $newObj->createDataDirectory();
     if ($_FILES["scormfile"]["name"]) {
         // copy uploaded file to data directory
         $file_path = $newObj->getDataDirectory() . "/" . $_FILES["scormfile"]["name"];
         ilUtil::moveUploadedFile($_FILES["scormfile"]["tmp_name"], $_FILES["scormfile"]["name"], $file_path);
     } else {
         // copy uploaded file to data directory
         $file_path = $newObj->getDataDirectory() . "/" . $_POST["uploaded_file"];
         ilUploadFiles::_copyUploadFile($_POST["uploaded_file"], $file_path);
     }
     ilUtil::unzip($file_path);
     ilUtil::renameExecutables($newObj->getDataDirectory());
     $title = $newObj->readObject();
     if ($title != "") {
         ilObject::_writeTitle($newObj->getId(), $title);
         /*$md = new ilMD($newObj->getId(),0, $newObj->getType());
         		if(is_object($md_gen = $md->getGeneral()))
         		{
         			$md_gen->setTitle($title);
         			$md_gen->update();
         		}*/
     }
     ilUtil::sendInfo($this->lng->txt($newObj->getType() . "_added"), true);
     ilUtil::redirect("ilias.php?baseClass=ilSAHSEditGUI&ref_id=" . $newObj->getRefId());
 }
 function newModuleVersionUpload()
 {
     global $_FILES, $rbacsystem;
     $unzip = PATH_TO_UNZIP;
     $tocheck = "imsmanifest.xml";
     include_once 'Services/FileSystem/classes/class.ilUploadFiles.php';
     // check create permission before because the uploaded file will be copied
     if (!$rbacsystem->checkAccess("write", $_GET["ref_id"])) {
         $this->ilias->raiseError($this->lng->txt("no_create_permission"), $this->ilias->error_obj->WARNING);
     } elseif ($_FILES["scormfile"]["name"]) {
         // check if file was uploaded
         $source = $_FILES["scormfile"]["tmp_name"];
         if ($source == 'none' || !$source) {
             ilUtil::sendInfo($this->lng->txt("upload_error_file_not_found"), true);
             $this->newModuleVersion();
             return;
         }
     } elseif ($_POST["uploaded_file"]) {
         // check if the file is in the ftp directory and readable
         if (!ilUploadFiles::_checkUploadFile($_POST["uploaded_file"])) {
             $this->ilias->raiseError($this->lng->txt("upload_error_file_not_found"), $this->ilias->error_obj->MESSAGE);
         }
         // copy the uploaded file to the client web dir to analyze the imsmanifest
         // the copy will be moved to the lm directory or deleted
         $source = CLIENT_WEB_DIR . "/" . $_POST["uploaded_file"];
         ilUploadFiles::_copyUploadFile($_POST["uploaded_file"], $source);
         $source_is_copy = true;
     } else {
         ilUtil::sendInfo($this->lng->txt("upload_error_file_not_found"), true);
         $this->newModuleVersion();
         return;
     }
     // fim.
     //unzip the imsmanifest-file from new uploaded file
     $pathinfo = pathinfo($source);
     $dir = $pathinfo["dirname"];
     $file = $pathinfo["basename"];
     $cdir = getcwd();
     chdir($dir);
     //we need more flexible unzip here than ILIAS standard classes allow
     $unzipcmd = $unzip . " -o " . ilUtil::escapeShellArg($source) . " " . $tocheck;
     exec($unzipcmd);
     chdir($cdir);
     $tmp_file = $dir . "/" . $tocheck . "." . $_GET["ref_id"];
     rename($dir . "/" . $tocheck, $tmp_file);
     $new_manifest = file_get_contents($tmp_file);
     //remove temp file
     unlink($tmp_file);
     //get old manifest file
     $old_manifest = file_get_contents($this->object->getDataDirectory() . "/" . $tocheck);
     //reload fixed version of file
     $check = '/xmlns="http:\\/\\/www.imsglobal.org\\/xsd\\/imscp_v1p1"/';
     $replace = "xmlns=\"http://www.imsproject.org/xsd/imscp_rootv1p1p2\"";
     $reload_manifest = preg_replace($check, $replace, $new_manifest);
     //do testing for converted versions as well as earlier ILIAS version messed up utf8 conversion
     if (strcmp($new_manifest, $old_manifest) == 0 || strcmp(utf8_encode($new_manifest), $old_manifest) == 0 || strcmp($reload_manifest, $old_manifest) == 0 || strcmp(utf8_encode($reload_manifest), $old_manifest) == 0) {
         //get exisiting module version
         $module_version = $this->object->getModuleVersion();
         if ($_FILES["scormfile"]["name"]) {
             //build targetdir in lm_data
             $file_path = $this->object->getDataDirectory() . "/" . $_FILES["scormfile"]["name"] . "." . $module_version;
             //move to data directory and add subfix for versioning
             ilUtil::moveUploadedFile($_FILES["scormfile"]["tmp_name"], $_FILES["scormfile"]["name"], $file_path);
         } else {
             //build targetdir in lm_data
             $file_path = $this->object->getDataDirectory() . "/" . $_POST["uploaded_file"] . "." . $module_version;
             // move the already copied file to the lm_data directory
             rename($source, $file_path);
         }
         //unzip and replace old extracted files
         ilUtil::unzip($file_path, true);
         ilUtil::renameExecutables($this->object->getDataDirectory());
         //(security)
         //increase module version
         $this->object->setModuleVersion($module_version + 1);
         $this->object->update();
         //redirect to properties and display success
         ilUtil::sendInfo($this->lng->txt("cont_new_module_added"), true);
         ilUtil::redirect("ilias.php?baseClass=ilSAHSEditGUI&ref_id=" . $_GET["ref_id"]);
         exit;
     } else {
         if ($source_is_copy) {
             unlink($source);
         }
         ilUtil::sendInfo($this->lng->txt("cont_invalid_new_module"), true);
         $this->newModuleVersion();
     }
 }
 /**
  * Import 
  */
 function import($a_file)
 {
     parent::create();
     $im_dir = $this->createImportDirectory();
     // handle uploaded files
     if (is_array($a_file)) {
         ilUtil::moveUploadedFile($a_file["tmp_name"], $a_file["name"], $im_dir . "/" . $a_file["name"]);
         $file_name = $a_file["name"];
     } else {
         $pi = pathinfo($a_file);
         $file_name = $pi["basename"];
         copy($a_file, $im_dir . "/" . $file_name);
     }
     $file = pathinfo($file_name);
     // unzip file
     if (strtolower($file["extension"] == "zip")) {
         ilUtil::unzip($im_dir . "/" . $file_name);
         $subdir = basename($file["basename"], "." . $file["extension"]);
         if (!is_dir($im_dir . "/" . $subdir)) {
             $subdir = "style";
             // check style subdir
         }
         $xml_file = $im_dir . "/" . $subdir . "/style.xml";
     } else {
         $xml_file = $im_dir . "/" . $file_name;
     }
     // load information from xml file
     //echo "-$xml_file-";
     $this->createFromXMLFile($xml_file, true);
     // copy images
     $this->createImagesDirectory();
     if (is_dir($im_dir . "/" . $subdir . "/images")) {
         ilUtil::rCopy($im_dir . "/" . $subdir . "/images", $this->getImagesDirectory());
     }
     ilObjStyleSheet::_addMissingStyleClassesToStyle($this->getId());
     $this->read();
     $this->writeCSSFile();
 }
 /**
  * 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;
 }
 /**
  * delete object file
  */
 function unzipFile()
 {
     global $lng;
     if (!isset($_POST["file"])) {
         $this->ilias->raiseError($this->lng->txt("no_checkbox"), $this->ilias->error_obj->MESSAGE);
     }
     if (count($_POST["file"]) > 1) {
         $this->ilias->raiseError($this->lng->txt("cont_select_max_one_item"), $this->ilias->error_obj->MESSAGE);
     }
     $cur_subdir = str_replace(".", "", ilUtil::stripSlashes($_GET["cdir"]));
     $cur_dir = !empty($cur_subdir) ? $this->main_dir . "/" . $cur_subdir : $this->main_dir;
     $file = $cur_dir . "/" . ilUtil::stripSlashes($_POST["file"][0]);
     if (@is_file($file)) {
         if ($this->getAllowDirectories()) {
             ilUtil::unzip($file, true);
         } else {
             ilUtil::unzip($file, true, true);
         }
     }
     ilUtil::renameExecutables($this->main_dir);
     $this->ctrl->saveParameter($this, "cdir");
     ilUtil::sendSuccess($lng->txt("cont_file_unzipped"), true);
     $this->ctrl->redirect($this, "listFiles");
 }
 function preview()
 {
     global $ilias;
     $export = new ilScorm2004Export($this->object, 'SCORM 2004 3rd');
     $zipfile = $export->buildExportFile();
     $zipPathinfo = pathinfo($zipfile);
     $file_path = $this->object->getDataDirectory() . "/" . $zipPathinfo["basename"];
     copy($zipfile, $file_path);
     unlink($zipfile);
     ilUtil::unzip($file_path, true);
     ilUtil::renameExecutables($this->object->getDataDirectory());
     unlink($file_path);
     include_once "./Modules/Scorm2004/classes/ilSCORM13Package.php";
     $rte_pkg = new ilSCORM13Package();
     $rte_pkg->il_import($this->object->getDataDirectory(), $this->object->getId(), $ilias, false, true);
     //increase module version is it necessary?
     //$this->object->setModuleVersion($module_version+1);
     //$this->object->update();
     //redirect to view player
     ilUtil::redirect("ilias.php?baseClass=ilSAHSPresentationGUI&ref_id=" . $this->object->getRefID() . "&envEditor=1");
 }
 /**
  * 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();
         }
     }
 }
Beispiel #25
0
 /**
  * unzips in given directory and processes uploaded zip for use as single files
  *
  * @author Jan Hippchen
  * @version 1.6.9.07
  * @param string $a_directory Directory to unzip 
  * @param string $a_file Filename of archive
  * @param boolean structure  True if archive structure is to be overtaken
  * @param integer $ref_id ref_id of parent object, if null, files wont be included in system (just checked)
  * @param string containerType object type of created containerobjects (folder or category)
  * @throws ilFileUtilsException
  */
 function processZipFile($a_directory, $a_file, $structure, $ref_id = null, $containerType = null, $tree = null, $access_handler = null)
 {
     global $lng;
     include_once "Services/Utilities/classes/class.ilUtil.php";
     self::$new_files = array();
     $pathinfo = pathinfo($a_file);
     $file = $pathinfo["basename"];
     // Copy zip-file to new directory, unzip and remove it
     // TODO: check archive for broken file
     //copy ($a_file, $a_directory . "/" . $file);
     move_uploaded_file($a_file, $a_directory . "/" . $file);
     ilUtil::unzip($a_directory . "/" . $file);
     unlink($a_directory . "/" . $file);
     //echo "-".$a_directory . "/" . $file."-";
     // Stores filename and paths into $filearray to check for viruses
     // Checks if filenames can be read, else -> throw exception and leave
     ilFileUtils::recursive_dirscan($a_directory, $filearray);
     // if there are no files unziped (->broken file!)
     if (empty($filearray)) {
         throw new ilFileUtilsException($lng->txt("archive_broken"), ilFileUtilsException::$BROKEN_FILE);
         break;
     }
     // virus handling
     foreach ($filearray["file"] as $key => $value) {
         // remove "invisible" files
         if (substr($value, 0, 1) == "." || stristr($filearray["path"][$key], "/__MACOSX/")) {
             unlink($filearray["path"][$key] . $value);
             unset($filearray["path"][$key]);
             unset($filearray["file"][$key]);
             continue;
         }
         $vir = ilUtil::virusHandling($filearray["path"][$key], $value);
         if (!$vir[0]) {
             // Unlink file and throw exception
             unlink($filearray[path][$key]);
             throw new ilFileUtilsException($lng->txt("file_is_infected") . "<br />" . $vir[1], ilFileUtilsException::$INFECTED_FILE);
             break;
         } else {
             if ($vir[1] != "") {
                 throw new ilFileUtilsException($vir[1], ilFileUtilsException::$INFECTED_FILE);
                 break;
             }
         }
     }
     // If archive is to be used "flat"
     if (!$structure) {
         foreach (array_count_values($filearray["file"]) as $key => $value) {
             // Archive contains same filenames in different directories
             if ($value != "1") {
                 $doublettes .= " '" . ilFileUtils::utf8_encode($key) . "'";
             }
         }
         if (isset($doublettes)) {
             throw new ilFileUtilsException($lng->txt("exc_upload_error") . "<br />" . $lng->txt("zip_structure_error") . $doublettes, ilFileUtilsException::$DOUBLETTES_FOUND);
             break;
         }
     } else {
         $mac_dir = $a_directory . "/__MACOSX";
         if (file_exists($mac_dir)) {
             ilUtil::delDir($mac_dir);
         }
     }
     // Everything fine since we got here; so we can store files and folders into the system (if ref_id is given)
     if ($ref_id != null) {
         ilFileUtils::createObjects($a_directory, $structure, $ref_id, $containerType, $tree, $access_handler);
     }
 }