/**
  * The real "download" or "upload" should be handled right here.
  * All packages have to be downloaded to /project/temp in order to be processed afterwards.
  *
  * @return string the filename of the package downloaded
  */
 public function processPackageUpload()
 {
     //fetch the upload, validate a few settings and copy the package to /project/temp
     $arrSource = class_carrier::getInstance()->getParam("provider_local_file");
     $strTarget = "/project/temp/" . generateSystemid() . ".zip";
     $objFilesystem = new class_filesystem();
     //Check file for correct filters
     $strSuffix = uniStrtolower(uniSubstr($arrSource["name"], uniStrrpos($arrSource["name"], ".")));
     if (in_array($strSuffix, array(".zip"))) {
         if ($objFilesystem->copyUpload($strTarget, $arrSource["tmp_name"])) {
             class_logger::getInstance(class_logger::PACKAGEMANAGEMENT)->addLogRow("uploaded package " . $arrSource["name"] . " to " . $strTarget, class_logger::$levelInfo);
             class_resourceloader::getInstance()->flushCache();
             class_classloader::getInstance()->flushCache();
             class_reflection::flushCache();
             return $strTarget;
         }
     }
     class_logger::getInstance(class_logger::PACKAGEMANAGEMENT)->addLogRow("error in uploaded package " . $arrSource["name"] . " either wrong format or not writeable target folder", class_logger::$levelInfo);
     @unlink($arrSource["tmp_name"]);
     return null;
 }
 /**
  * Tries to save the passed file.
  * Therefore, the following post-params should be given:
  * action = fileUpload
  * folder = the folder to store the file within
  * systemid = the filemanagers' repo-id
  * inputElement = name of the inputElement
  *
  * @return string
  * @permissions right1
  */
 protected function actionFileupload()
 {
     $strReturn = "";
     /** @var class_module_mediamanager_repo|class_module_mediamanager_file $objFile */
     $objFile = class_objectfactory::getInstance()->getObject($this->getSystemid());
     /**
      * @var class_module_mediamanager_repo
      */
     $objRepo = null;
     if ($objFile instanceof class_module_mediamanager_file) {
         $strFolder = $objFile->getStrFilename();
         if (!$objFile->rightEdit() || $objFile->getIntType() != class_module_mediamanager_file::$INT_TYPE_FOLDER) {
             class_response_object::getInstance()->setStrStatusCode(class_http_statuscodes::SC_UNAUTHORIZED);
             $strReturn .= "<message><error>" . xmlSafeString($this->getLang("commons_error_permissions")) . "</error></message>";
             return $strReturn;
         }
         $objRepo = class_objectfactory::getInstance()->getObject($objFile->getPrevId());
         while (!$objRepo instanceof class_module_mediamanager_repo) {
             $objRepo = class_objectfactory::getInstance()->getObject($objRepo->getPrevId());
         }
     } elseif ($objFile instanceof class_module_mediamanager_repo) {
         $objRepo = $objFile;
         $strFolder = $objFile->getStrPath();
         if (!$objFile->rightEdit()) {
             class_response_object::getInstance()->setStrStatusCode(class_http_statuscodes::SC_UNAUTHORIZED);
             $strReturn .= "<message><error>" . xmlSafeString($this->getLang("commons_error_permissions")) . "</error></message>";
             return $strReturn;
         }
     } else {
         class_response_object::getInstance()->setStrStatusCode(class_http_statuscodes::SC_UNAUTHORIZED);
         $strReturn .= "<message><error>" . xmlSafeString($this->getLang("commons_error_permissions")) . "</error></message>";
         return $strReturn;
     }
     //Handle the fileupload
     $arrSource = $this->getParam($this->getParam("inputElement"));
     $bitJsonResponse = $this->getParam("jsonResponse") != "";
     $bitPostData = false;
     if (is_array($arrSource)) {
         $strFilename = $arrSource["name"];
     } else {
         $bitPostData = getPostRawData() != "";
         $strFilename = $arrSource;
     }
     $strTarget = $strFolder . "/" . createFilename($strFilename);
     $objFilesystem = new class_filesystem();
     if (!file_exists(_realpath_ . "/" . $strFolder)) {
         $objFilesystem->folderCreate($strFolder, true);
     }
     if ($objFilesystem->isWritable($strFolder)) {
         //Check file for correct filters
         $arrAllowed = explode(",", $objRepo->getStrUploadFilter());
         $strSuffix = uniStrtolower(uniSubstr($strFilename, uniStrrpos($strFilename, ".")));
         if ($objRepo->getStrUploadFilter() == "" || in_array($strSuffix, $arrAllowed)) {
             if ($bitPostData) {
                 $objFilesystem = new class_filesystem();
                 $objFilesystem->openFilePointer($strTarget);
                 $bitCopySuccess = $objFilesystem->writeToFile(getPostRawData());
                 $objFilesystem->closeFilePointer();
             } else {
                 $bitCopySuccess = $objFilesystem->copyUpload($strTarget, $arrSource["tmp_name"]);
             }
             if ($bitCopySuccess) {
                 if ($bitJsonResponse) {
                     $strReturn = json_encode(array('success' => true));
                 } else {
                     $strReturn .= "<message>" . $this->getLang("xmlupload_success") . "</message>";
                 }
                 class_logger::getInstance()->addLogRow("uploaded file " . $strTarget, class_logger::$levelInfo);
                 $objRepo->syncRepo();
             } else {
                 if ($bitJsonResponse) {
                     $strReturn .= json_encode(array('error' => $this->getLang("xmlupload_error_copyUpload")));
                 } else {
                     $strReturn .= "<message><error>" . $this->getLang("xmlupload_error_copyUpload") . "</error></message>";
                 }
             }
         } else {
             class_response_object::getInstance()->setStrStatusCode(class_http_statuscodes::SC_BADREQUEST);
             if ($bitJsonResponse) {
                 $strReturn .= json_encode(array('error' => $this->getLang("xmlupload_error_filter")));
             } else {
                 $strReturn .= "<message><error>" . $this->getLang("xmlupload_error_filter") . "</error></message>";
             }
         }
     } else {
         class_response_object::getInstance()->setStrStatusCode(class_http_statuscodes::SC_INTERNAL_SERVER_ERROR);
         if ($bitJsonResponse) {
             $strReturn .= json_encode(array('error' => $this->getLang("xmlupload_error_notWritable")));
         } else {
             $strReturn .= "<message><error>" . xmlSafeString($this->getLang("xmlupload_error_notWritable")) . "</error></message>";
         }
     }
     if ($bitJsonResponse) {
         //disabled for ie. otherwise the upload won't work due to the headers.
         class_response_object::getInstance()->setStrResponseType(class_http_responsetypes::STR_TYPE_HTML);
         //class_response_object::getInstance()->setStResponseType(class_http_responsetypes::STR_TYPE_JSON);
     }
     @unlink($arrSource["tmp_name"]);
     return $strReturn;
 }
 /**
  * @see interface_admin_systemtask::getSubmitParams()
  * @return string
  */
 public function getSubmitParams()
 {
     $arrFile = $this->getParam("pageimport_file");
     $strError = "";
     $objFilesystem = new class_filesystem();
     $strTarget = "/import_" . generateSystemid() . ".xml";
     $strSuffix = uniStrtolower(uniSubstr($arrFile["name"], uniStrrpos($arrFile["name"], ".")));
     if ($strSuffix == ".xml") {
         if ($objFilesystem->copyUpload($strTarget, $arrFile["tmp_name"])) {
             class_logger::getInstance()->addLogRow("uploaded file " . $strTarget, class_logger::$levelInfo);
         } else {
             $strError = "upload";
         }
     } else {
         $strError = "suffix";
     }
     return "&pageimport_file=" . $strTarget . "&pageimport_error=" . $strError . "&pageimport_replace=" . $this->getParam("pageimport_replace");
 }
 /**
  * Will be kept for legacy compatibility
  *
  * @param bool $bitJsonResponse
  *
  * @return string
  */
 private function doUpload($bitJsonResponse = false)
 {
     $strReturn = "";
     //prepare the folder to be used as a target-folder for the upload
     $objFilemanagerRepo = new class_module_mediamanager_repo($this->arrElementData["char2"]);
     $objDownloadfolder = null;
     //add a special subfolder?
     $strPath = $objFilemanagerRepo->getStrPath();
     if ($this->getParam("portaluploadDlfolder") != "") {
         /** @var $objDownloadfolder class_module_mediamanager_file */
         $objDownloadfolder = class_objectfactory::getInstance()->getObject($this->getParam("portaluploadDlfolder"));
         //check if the folder is within the current repo
         /** @var $objTemp class_module_mediamanager_file */
         $objTemp = $objDownloadfolder;
         while (validateSystemid($objTemp->getSystemid()) && ($objTemp instanceof class_module_mediamanager_file || $objTemp instanceof class_module_mediamanager_repo)) {
             if ($objTemp->getSystemid() == $this->arrElementData["char2"]) {
                 $strPath = $objDownloadfolder->getStrFilename();
                 break;
             }
             $objTemp = class_objectfactory::getInstance()->getObject($objTemp->getPrevId());
         }
     }
     //upload the file...
     if ($objFilemanagerRepo->rightRight1()) {
         //Handle the fileupload
         $arrSource = $this->getParam("portaluploadFile");
         $strTarget = $strPath . "/" . createFilename($arrSource["name"]);
         $objFilesystem = new class_filesystem();
         if ($objFilesystem->isWritable($strPath)) {
             //Check file for correct filters
             $arrAllowed = explode(",", $objFilemanagerRepo->getStrUploadFilter());
             $strSuffix = uniStrtolower(uniSubstr($arrSource["name"], uniStrrpos($arrSource["name"], ".")));
             if ($objFilemanagerRepo->getStrUploadFilter() == "" || in_array($strSuffix, $arrAllowed)) {
                 if ($objFilesystem->copyUpload($strTarget, $arrSource["tmp_name"])) {
                     //upload was successfull. try to sync the downloads-archive.
                     if ($objDownloadfolder != null && $objDownloadfolder instanceof class_module_mediamanager_file) {
                         class_module_mediamanager_file::syncRecursive($objDownloadfolder->getSystemid(), $objDownloadfolder->getStrFilename());
                     } else {
                         $objFilemanagerRepo->syncRepo();
                     }
                     $this->flushCompletePagesCache();
                     if ($bitJsonResponse) {
                         return true;
                     }
                     //reload the site to display the new file
                     if (validateSystemid($this->getParam("portaluploadDlfolder"))) {
                         $this->portalReload(class_link::getLinkPortalHref($this->getPagename(), "", "mediaFolder", "uploadSuccess=1", $this->getParam("portaluploadDlfolder")));
                     } else {
                         $this->portalReload(class_link::getLinkPortalHref($this->getPagename(), "", "", $this->getAction(), "uploadSuccess=1", $this->getSystemid()));
                     }
                 } else {
                     $strReturn .= $this->uploadForm($this->getLang("portaluploadCopyUploadError"));
                 }
             } else {
                 @unlink($arrSource["tmp_name"]);
                 $strReturn .= $this->uploadForm($this->getLang("portaluploadFilterError"));
             }
         } else {
             $strReturn .= $this->uploadForm($this->getLang("portaluploadNotWritableError"));
         }
     } else {
         $strReturn .= $this->getLang("commons_error_permissions");
     }
     return $strReturn;
 }