Exemplo n.º 1
0
 /**
  * Return the Process File Manager
  *
  * @param string $sProcessUID {@min 32} {@max 32}
  * @param string $userUID {@min 32} {@max 32}
  * @param array  $aData
  *
  * return array
  *
  * @access public
  */
 public function addProcessFilesManager($sProcessUID, $userUID, $aData)
 {
     try {
         $aData['prf_path'] = rtrim($aData['prf_path'], '/') . '/';
         if (!$aData['prf_filename']) {
             throw new \Exception(\G::LoadTranslation("ID_INVALID_VALUE_FOR", array('prf_filename')));
         }
         $extention = strstr($aData['prf_filename'], '.');
         if (!$extention) {
             $extention = '.html';
             $aData['prf_filename'] = $aData['prf_filename'].$extention;
         }
         if ($extention == '.docx' || $extention == '.doc' || $extention == '.html' || $extention == '.php' || $extention == '.jsp' ||
             $extention == '.xlsx' || $extention == '.xls' || $extention == '.js' || $extention == '.css' || $extention == '.txt') {
             $sEditable = true;
         } else {
             $sEditable = false;
         }
         $sMainDirectory = current(explode("/", $aData['prf_path']));
         if ($sMainDirectory != 'public' && $sMainDirectory != 'templates') {
             throw new \Exception(\G::LoadTranslation("ID_INVALID_PRF_PATH"));
         }
         if (strstr($aData['prf_path'],'/')) {
             $sSubDirectory = substr($aData['prf_path'], strpos($aData['prf_path'], "/")+1) ;
         } else {
             $sSubDirectory = '';
         }
         switch ($sMainDirectory) {
             case 'templates':
                 $sDirectory = PATH_DATA_MAILTEMPLATES . $sProcessUID . PATH_SEP . $sSubDirectory . $aData['prf_filename'];
                 $sCheckDirectory = PATH_DATA_MAILTEMPLATES . $sProcessUID . PATH_SEP . $sSubDirectory;
                 if ($extention != '.html') {
                     throw new \Exception(\G::LoadTranslation('ID_FILE_UPLOAD_INCORRECT_EXTENSION'));
                 }
                 break;
             case 'public':
                 $sDirectory = PATH_DATA_PUBLIC . $sProcessUID . PATH_SEP . $sSubDirectory . $aData['prf_filename'];
                 $sCheckDirectory = PATH_DATA_PUBLIC . $sProcessUID . PATH_SEP . $sSubDirectory;
                 $sEditable = false;
                 if ($extention == '.exe') {
                     throw new \Exception(\G::LoadTranslation('ID_FILE_UPLOAD_INCORRECT_EXTENSION'));
                 }
                 break;
             default:
                 $sDirectory = PATH_DATA_MAILTEMPLATES . $sProcessUID . PATH_SEP . $sSubDirectory . $aData['prf_filename'];
                 break;
         }
         $content = $aData['prf_content'];
         if (file_exists($sDirectory) ) {
             $directory = $sMainDirectory. PATH_SEP . $sSubDirectory . $aData['prf_filename'];
             throw new \Exception(\G::LoadTranslation("ID_EXISTS_FILE", array($directory)));
         }
         
         if (!file_exists($sCheckDirectory)) {
             $sPkProcessFiles = \G::generateUniqueID();
             $oProcessFiles = new \ProcessFiles();
             $sDate = date('Y-m-d H:i:s');
             $oProcessFiles->setPrfUid($sPkProcessFiles);
             $oProcessFiles->setProUid($sProcessUID);
             $oProcessFiles->setUsrUid($userUID);
             $oProcessFiles->setPrfUpdateUsrUid('');
             $oProcessFiles->setPrfPath($sCheckDirectory);
             $oProcessFiles->setPrfType('folder');
             $oProcessFiles->setPrfEditable('');
             $oProcessFiles->setPrfCreateDate($sDate);
             $oProcessFiles->save();
         }
         \G::verifyPath($sCheckDirectory, true);
         $sPkProcessFiles = \G::generateUniqueID();
         $oProcessFiles = new \ProcessFiles();
         $sDate = date('Y-m-d H:i:s');
         $oProcessFiles->setPrfUid($sPkProcessFiles);
         $oProcessFiles->setProUid($sProcessUID);
         $oProcessFiles->setUsrUid($userUID);
         $oProcessFiles->setPrfUpdateUsrUid('');
         $oProcessFiles->setPrfPath($sDirectory);
         $oProcessFiles->setPrfType('file');
         $oProcessFiles->setPrfEditable($sEditable);
         $oProcessFiles->setPrfCreateDate($sDate);
         $oProcessFiles->save();
         $fp = fopen($sDirectory, 'w');
         $content = stripslashes($aData['prf_content']);
         $content = str_replace("@amp@", "&", $content);
         fwrite($fp, $content);
         fclose($fp);
         $oProcessFile = array('prf_uid' => $oProcessFiles->getPrfUid(),
                               'prf_filename' => $aData['prf_filename'],
                               'usr_uid' => $oProcessFiles->getUsrUid(),
                               'prf_update_usr_uid' => $oProcessFiles->getPrfUpdateUsrUid(),
                               'prf_path' => $sMainDirectory. PATH_SEP . $sSubDirectory,
                               'prf_type' => $oProcessFiles->getPrfType(),
                               'prf_editable' => $oProcessFiles->getPrfEditable(),
                               'prf_create_date' => $oProcessFiles->getPrfCreateDate(),
                               'prf_update_date' => $oProcessFiles->getPrfUpdateDate(),
                               'prf_content' => $content);
         return $oProcessFile;
     } catch (Exception $e) {
         throw $e;
     }
 }
Exemplo n.º 2
0
    public function addProcessFilesManagerInDb($aData)
    {
        try {
            $oProcessFiles = new \ProcessFiles();
            $aData = array_change_key_case($aData, CASE_UPPER);
            $oProcessFiles->fromArray($aData, \BasePeer::TYPE_FIELDNAME);

            if($this->existsProcessFile($aData['PRF_UID'])) {
                $sPkProcessFiles = \G::generateUniqueID();
                $oProcessFiles->setPrfUid($sPkProcessFiles);

                $sDirectory = PATH_DATA_MAILTEMPLATES . $aData['PRO_UID'] . PATH_SEP . basename($aData['PRF_PATH']);
                $oProcessFiles->setPrfPath($sDirectory);

                $emailEvent = new \ProcessMaker\BusinessModel\EmailEvent();
                $emailEvent->updatePrfUid($aData['PRF_UID'], $sPkProcessFiles, $aData['PRO_UID']);
            }

            $result = $oProcessFiles->save();
        } catch (Exception $e) {
            throw $e;
        }
    }