/**
  * upload file
  */
 function uploadFile()
 {
     global $lng;
     // determine directory
     $cur_subdir = str_replace(".", "", ilUtil::stripSlashes($_GET["cdir"]));
     $cur_dir = !empty($cur_subdir) ? $this->main_dir . "/" . $cur_subdir : $this->main_dir;
     include_once 'Services/FileSystem/classes/class.ilUploadFiles.php';
     if (is_file($_FILES["new_file"]["tmp_name"])) {
         move_uploaded_file($_FILES["new_file"]["tmp_name"], $cur_dir . "/" . ilUtil::stripSlashes($_FILES["new_file"]["name"]));
         if (is_file($cur_dir . "/" . ilUtil::stripSlashes($_FILES["new_file"]["name"]))) {
             ilUtil::sendSuccess($lng->txt("cont_file_created"), true);
             $this->setPerformedCommand("create_file", array("name" => ilUtil::stripSlashes($_FILES["new_file"]["name"])));
         }
     } elseif ($_POST["uploaded_file"]) {
         // check if the file is in the ftp directory and readable
         if (ilUploadFiles::_checkUploadFile($_POST["uploaded_file"])) {
             // copy uploaded file to data directory
             ilUploadFiles::_copyUploadFile($_POST["uploaded_file"], $cur_dir . "/" . ilUtil::stripSlashes($_POST["uploaded_file"]));
         }
         if (is_file($cur_dir . "/" . ilUtil::stripSlashes($_POST["uploaded_file"]))) {
             ilUtil::sendSuccess($lng->txt("cont_file_created"), true);
             $this->setPerformedCommand("create_file", array("name" => ilUtil::stripSlashes($_POST["uploaded_file"])));
         }
     } else {
         if (trim($_FILES["new_file"]["name"]) == "") {
             ilUtil::sendFailure($lng->txt("cont_enter_a_file"), true);
         }
     }
     $this->ctrl->saveParameter($this, "cdir");
     ilUtil::renameExecutables($this->main_dir);
     $this->ctrl->redirect($this, "listFiles");
 }
 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();
     }
 }
 /**
  * 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());
 }
Пример #4
0
 /**
  * upload file
  */
 function uploadFile()
 {
     global $lng;
     // determine directory
     $cur_subdir = str_replace(".", "", ilUtil::stripSlashes($_GET["cdir"]));
     $cur_dir = !empty($cur_subdir) ? $this->main_dir . "/" . $cur_subdir : $this->main_dir;
     $tgt_file = null;
     if (is_file($_FILES["new_file"]["tmp_name"])) {
         $tgt_file = $cur_dir . "/" . ilUtil::stripSlashes($_FILES["new_file"]["name"]);
         move_uploaded_file($_FILES["new_file"]["tmp_name"], $tgt_file);
     } elseif ($_POST["uploaded_file"]) {
         include_once 'Services/FileSystem/classes/class.ilUploadFiles.php';
         // check if the file is in the ftp directory and readable
         if (ilUploadFiles::_checkUploadFile($_POST["uploaded_file"])) {
             $tgt_file = $cur_dir . "/" . ilUtil::stripSlashes($_POST["uploaded_file"]);
             // copy uploaded file to data directory
             ilUploadFiles::_copyUploadFile($_POST["uploaded_file"], $tgt_file);
         }
     } else {
         if (trim($_FILES["new_file"]["name"]) == "") {
             ilUtil::sendFailure($lng->txt("cont_enter_a_file"), true);
         }
     }
     if ($tgt_file && is_file($tgt_file)) {
         $unzip = null;
         // extract zip?
         include_once "./Services/Utilities/classes/class.ilMimeTypeUtil.php";
         if (ilMimeTypeUtil::getMimeType($tgt_file) == "application/zip") {
             $this->ctrl->setParameter($this, "upfile", basename($tgt_file));
             $url = $this->ctrl->getLinkTarget($this, "unzipFile");
             $this->ctrl->setParameter($this, "upfile", "");
             include_once "Services/UIComponent/Button/classes/class.ilLinkButton.php";
             $unzip = ilLinkButton::getInstance();
             $unzip->setCaption("unzip");
             $unzip->setUrl($url);
             $unzip = " " . $unzip->render();
         }
         ilUtil::sendSuccess($lng->txt("cont_file_created") . $unzip, true);
         $this->setPerformedCommand("create_file", array("name" => substr($tgt_file, strlen($this->main_dir) + 1)));
     }
     $this->ctrl->saveParameter($this, "cdir");
     ilUtil::renameExecutables($this->main_dir);
     $this->ctrl->redirect($this, "listFiles");
 }