Ejemplo n.º 1
0
 public static function import($id, $file)
 {
     $newForm = array();
     $content = FileUtil::readFile($file);
     $printModel = str_replace("'", "\\'", $content);
     if (preg_match_all("'<script[^>]*?>.*?</script>'si", $printModel, $script)) {
         $scriptStr = implode("\n\r", $script[0]);
         $scriptStr = preg_replace("'<script[^>]*?>'", "", $scriptStr);
         $scriptStr = str_ireplace("</script>", "", $scriptStr);
         $newForm["script"] = $scriptStr;
         $printModel = preg_replace("'<script[^>]*?>.*?</script>'si", "", $printModel);
     }
     if (preg_match_all("'<style[^>]*?>.*?</style>'si", $printModel, $css)) {
         $cssStr = implode("\n\r", $css[0]);
         $cssStr = preg_replace("'<style[^>]*?>'", "", $cssStr);
         $cssStr = str_ireplace("</style>", "", $cssStr);
         $newForm["css"] = $cssStr;
         $printModel = preg_replace("'<style[^>]*?>.*?</style>'si", "", $printModel);
     }
     $newForm["printmodel"] = $printModel;
     FlowFormType::model()->modify($id, $newForm);
     $form = new ICFlowForm($id);
     $form->getParser()->parse();
     FileUtil::deleteFile($file);
 }
Ejemplo n.º 2
0
 public static function import($id, $file, $importUser = false)
 {
     $content = FileUtil::readFile($file);
     $xml = XmlUtil::xmlToArray($content);
     unset($xml["base"]["flowid"]);
     unset($xml["base"]["name"]);
     unset($xml["base"]["formid"]);
     unset($xml["base"]["sort"]);
     $user = array("newuser", "deptid", "uid", "positionid", "autouserop", "autouser", "mailto");
     $data = array();
     foreach ($xml["base"] as $key => $value) {
         $key = strtolower($key);
         if (!$importUser && in_array($key, $user)) {
             continue;
         }
         $data[$key] = $value;
     }
     FlowType::model()->modify($id, $data);
     unset($xml["base"]);
     unset($data);
     FlowProcess::model()->deleteAllByAttributes(array("flowid" => $id));
     if (!empty($xml)) {
         foreach ($xml as $process) {
             unset($process["id"]);
             $data = array();
             $process["flowid"] = $id;
             foreach ($process as $k => $v) {
                 if (!$importUser && in_array($k, $user)) {
                     continue;
                 }
                 $data[$k] = $v;
             }
             FlowProcess::model()->add($data);
         }
     }
     FileUtil::deleteFile($file);
 }
Ejemplo n.º 3
0
 public static function exportEml($id)
 {
     $data = Email::model()->fetchById($id);
     if ($data) {
         $users = UserUtil::loadUser();
         $data["copytoname"] = self::joinStringByArray($data["copytoids"], $users, "realname", ";");
         $filecontent = "Date: " . ConvertUtil::formatDate($data["sendtime"]) . "\n";
         $data["fromname"] = isset($users[$data["fromid"]]) ? $users[$data["fromid"]]["realname"] : "";
         $filecontent .= "From: \"" . $data["fromname"] . "\"\n";
         $filecontent .= "MIME-Version: 1.0\n";
         $data["toname"] = self::joinStringByArray($data["toids"], $users, "realname", ";");
         $filecontent .= "To: \"" . $data["toname"] . "\"\n";
         if ($data["copytoids"] != "") {
             $filecontent .= "Cc: \"" . $data["copytoname"] . "\" <" . $data["copytoids"] . ">\n";
         }
         $filecontent .= "subject: " . $data["subject"] . "\n";
         $filecontent .= "Content-Type: multipart/mixed; boundary=\"==========myOA==========\"\n\n";
         $filecontent .= "This is a multi-part message in MIME format.\n";
         $filecontent .= "--==========myOA==========\n";
         $filecontent .= "Content-Type: text/html;\tcharset=\"utf-8\"\n";
         $filecontent .= "Content-Transfer-Encoding: base64\n\n";
         $filecontent .= chunk_split(base64_encode($data["content"])) . "\n";
         if ($data["attachmentid"] !== "") {
             $tempdata = AttachUtil::getAttach($data["attachmentid"], true, true, false, false, true);
             foreach ($tempdata as $value) {
                 $filecontent .= "--==========myOA==========\n";
                 $filecontent .= "Content-Type: application/octet-stream; name=\"" . $value["filename"] . "\"\n";
                 $filecontent .= "Content-Transfer-Encoding: base64\n";
                 $filecontent .= "Content-Disposition: attachment; filename=\"" . $value["filename"] . "\"\n\n";
                 $filecontent .= chunk_split(base64_encode(FileUtil::readFile($value["attachment"]))) . "\n";
             }
         }
         $filecontent .= "--==========myOA==========--";
         if (ob_get_length()) {
             ob_end_clean();
         }
         header("Cache-control: private");
         header("Content-type: message/rfc822");
         header("Accept-Ranges: bytes");
         header("Content-Disposition: attachment; filename=" . $data["subject"] . "(" . date("Y-m-d") . ").eml");
         echo $filecontent;
     }
 }
Ejemplo n.º 4
0
 /**
  * Creates upload folder including a subfolder for thumbnail and an .htaccess file within it.
  *
  * @param string $objectType        Name of treated entity type.
  * @param string $fieldName         Name of upload field.
  * @param string $allowedExtensions String with list of allowed file extensions (separated by ", ").
  *
  * @return Boolean whether everything went okay or not.
  */
 protected function checkAndCreateUploadFolder($objectType, $fieldName, $allowedExtensions = '')
 {
     $uploadPath = $this->getFileBaseFolder($objectType, $fieldName, true);
     // Check if directory exist and try to create it if needed
     if (!is_dir($uploadPath) && !FileUtil::mkdirs($uploadPath, 0777)) {
         LogUtil::registerStatus($this->__f('The upload directory "%s" does not exist and could not be created. Try to create it yourself and make sure that this folder is accessible via the web and writable by the webserver.', array($uploadPath)));
         return false;
     }
     // Check if directory is writable and change permissions if needed
     if (!is_writable($uploadPath) && !chmod($uploadPath, 0777)) {
         LogUtil::registerStatus($this->__f('Warning! The upload directory at "%s" exists but is not writable by the webserver.', array($uploadPath)));
         return false;
     }
     // Write a htaccess file into the upload directory
     $htaccessFilePath = $uploadPath . '/.htaccess';
     $htaccessFileTemplate = 'modules/Reviews/docs/htaccessTemplate';
     if (!file_exists($htaccessFilePath) && file_exists($htaccessFileTemplate)) {
         $extensions = str_replace(',', '|', str_replace(' ', '', $allowedExtensions));
         $htaccessContent = str_replace('__EXTENSIONS__', $extensions, FileUtil::readFile($htaccessFileTemplate));
         if (!FileUtil::writeFile($htaccessFilePath, $htaccessContent)) {
             LogUtil::registerStatus($this->__f('Warning! Could not write the .htaccess file at "%s".', array($htaccessFilePath)));
             return false;
         }
     }
     return true;
 }
Ejemplo n.º 5
0
    /**
     * Edit a file.
     * @author: Albert Pérez Monfort & Robert Barrera
     * @param:  folder where the action have begined, file that must be edited, confirmation parameter
     * @return: True if success and false if not
     */
    public function editFile($args) {
        $fileName = FormUtil::getPassedValue('fileName', isset($args['fileName']) ? $args['fileName'] : null, 'POST');
        $fileContent = FormUtil::getPassedValue('fileContent', isset($args['fileContent']) ? $args['fileContent'] : null, 'POST');
        $folder = FormUtil::getPassedValue('folder', isset($args['folder']) ? $args['folder'] : null, 'REQUEST');
        $folder = str_replace("|", "/", $folder);
        $confirm = FormUtil::getPassedValue('confirm', isset($args['confirm']) ? $args['confirm'] : null, 'POST');
        $external = FormUtil::getPassedValue('external', isset($args['external']) ? $args['external'] : null, 'GETPOST');
        $editor  = FormUtil::getPassedValue('editor', isset($args['editor']) ? $args['editor'] : null, 'GET');

        // security check
        if (!SecurityUtil::checkPermission('Files::', "::", ACCESS_ADD)) {
            return LogUtil::registerError($this->__('Error! You are not authorized to access this module.'), 403);
        }

        $check = ModUtil::func('Files', 'user', 'checkingModule');
        if ($check['status'] != 'ok') {
	    $this->view->assign('check', $check);
            return $this->view->fetch('Files_user_failedConf.tpl');
        }
        $initFolderPath = $check['initFolderPath'];
        // protection. User can not navigate out their root folder
        if ($folder == ".." || $folder == "." || strpos($folder, "..") !== false) {
            $errorMsg = $this->__('Invalid folder') . ': ' . $folder;
            $this->view->assign('errorMsg', $errorMsg);
            return $this->view->fetch('Files_user_errorMsg.tpl');
        }

        //checks if it is an editable file
        // set editable extensions
        $editableExtensions = ModUtil::getVar('Files', 'editableExtensions');
        // get file extension
        $fileExtension = FileUtil::getExtension($fileName);
        if (strpos($editableExtensions, strtolower($fileExtension)) === false) {
            $errorMsg = $this->__f('Sorry! The file %s is not editable.', $fileName);
            $this->view->assign('errorMsg', $errorMsg);
            return $this->view->fetch('Files_user_errorMsg.tpl');
        }

        // checks if file exists
        $file = $initFolderPath . '/' . $folder . '/' . $fileName;
        if (!file_exists($file)) {
            $errorMsg = $this->__f('Sorry! The file %s has not been found.', $fileName);
            $this->view->assign('errorMsg', $errorMsg);
            return $this->view->fetch('Files_user_errorMsg.tpl');
        }

        if (!$confirm) {
            // load the edit form
            // get file content
            if (!$fileContent = FileUtil::readFile($file, true)) {
                // error reading the file
                $errorMsg = $this->__f('Error! It has not been possible to read the content of the file %s.', $fileName);
                $this->view->assign('errorMsg', $errorMsg);
                return $this->view->fetch('Files_user_errorMsg.tpl');
            }
            // create output object
            $this->view->assign('folder', DataUtil::formatForDisplay($folder));
            $this->view->assign('fileName', DataUtil::formatForDisplay($fileName));
            $this->view->assign('fileContent', DataUtil::formatForDisplay($fileContent));
            if ($external == 1) {
                $this->view->assign('external', 1);
                $content = $this->view->fetch('Files_user_editFile.tpl');
                echo $content;
                exit();
            } else {
                $this->view->assign('external', 0);
                return $this->view->fetch('Files_user_editFile.tpl');
            }
        }
        $returnType = ($external == 1) ? 'external' : 'user';
        $returnFunc = ($external == 1) ? 'getFiles' : 'main';

        // confirm authorisation code
        $this->checkCsrfToken();

        // the file has been edited. Update its content
        if (!FileUtil::writeFile($file, $fileContent, true)) {
            // error writing the file
            $errorMsg = $this->__f('Error! It has not been possible to write the content to the file %s.', $fileName);
            $this->view->assign('errorMsg', $errorMsg);
            return $this->view->fetch('Files_user_errorMsg.tpl');
        }

        // update the number of bytes used by user
        ModUtil::apiFunc('Files', 'user', 'updateUsedSpace');
        LogUtil::registerStatus($this->__('File successfully edited'));
        $folder = str_replace("/", "|", $folder);
        return System::redirect(ModUtil::url('Files', $returnType, $returnFunc, array('folder' => $folder,'editor'=>$editor)));
    }
Ejemplo n.º 6
0
 /**
  * Create a directory for news pics
  * @param string $dir
  */
 public static function mkdir($dir) {
     $dom = ZLanguage::getModuleDomain('News');
     if ($dir[0] == '/') {
         LogUtil::registerError(__f("Warning! The image upload directory at [%s] appears to be 'above' the DOCUMENT_ROOT. Please choose a path relative to the webserver (e.g. images/news_picupload).", $dir, $dom));
     } else {
         if (is_dir($dir)) {
             if (!is_writable($dir)) {
                 LogUtil::registerError(__f('Warning! The image upload directory at [%s] exists but is not writable by the webserver.', $dir, $dom));
             }
         } else {
             // Try to create the specified directory
             if (FileUtil::mkdirs($dir, 0777)) {
                 // write a htaccess file in the image upload directory
                 $htaccessContent = FileUtil::readFile('modules/News/docs/htaccess');
                 if (FileUtil::writeFile($dir . '/.htaccess', $htaccessContent)) {
                     LogUtil::registerStatus(__f('News publisher created the image upload directory successfully at [%s] and wrote an .htaccess file there for security.', $dir, $dom));
                 } else {
                     LogUtil::registerStatus(__f('News publisher created the image upload directory successfully at [%s], but could not write the .htaccess file there.', $dir, $dom));
                 }
             } else {
                 LogUtil::registerStatus(__f('Warning! News publisher could not create the specified image upload directory [%s]. Try to create it yourself and make sure that this folder is accessible via the web and writable by the webserver.', $dir, $dom));
             }
         }
     }
 }