2014-01-28 16:31:20 -04:00
|
|
|
<?php
|
2014-04-02 16:51:28 -04:00
|
|
|
namespace ProcessMaker\BusinessModel;
|
2014-01-28 16:31:20 -04:00
|
|
|
|
|
|
|
|
use \G;
|
|
|
|
|
|
|
|
|
|
class FilesManager
|
|
|
|
|
{
|
|
|
|
|
/**
|
|
|
|
|
* Return the Process Files Manager
|
|
|
|
|
*
|
|
|
|
|
* @param string $sProcessUID {@min 32} {@max 32}
|
|
|
|
|
*
|
|
|
|
|
* return array
|
|
|
|
|
*
|
|
|
|
|
* @access public
|
|
|
|
|
*/
|
|
|
|
|
public function getProcessFilesManager($sProcessUID)
|
|
|
|
|
{
|
|
|
|
|
try {
|
|
|
|
|
$aDirectories[] = array('name' => "templates",
|
|
|
|
|
'type' => "folder",
|
2014-02-20 12:27:28 -04:00
|
|
|
'path' => "/",
|
2014-01-28 16:31:20 -04:00
|
|
|
'editable' => false);
|
|
|
|
|
$aDirectories[] = array('name' => "public",
|
|
|
|
|
'type' => "folder",
|
2014-02-20 12:27:28 -04:00
|
|
|
'path' => "/",
|
2014-01-28 16:31:20 -04:00
|
|
|
'editable' => false);
|
|
|
|
|
return $aDirectories;
|
|
|
|
|
} catch (Exception $e) {
|
|
|
|
|
throw $e;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Return the Process Files Manager Path
|
|
|
|
|
*
|
|
|
|
|
* @param string $sProcessUID {@min 32} {@max 32}
|
2014-02-12 12:35:03 -04:00
|
|
|
* @param string $path
|
2014-01-28 16:31:20 -04:00
|
|
|
*
|
|
|
|
|
* return array
|
|
|
|
|
*
|
|
|
|
|
* @access public
|
|
|
|
|
*/
|
2016-04-06 12:39:34 -04:00
|
|
|
public function getProcessFilesManagerPath($sProcessUID, $path, $getContent = true)
|
2014-01-28 16:31:20 -04:00
|
|
|
{
|
|
|
|
|
try {
|
2014-02-26 16:22:23 -04:00
|
|
|
$checkPath = substr($path, -1);
|
|
|
|
|
if ($checkPath == '/') {
|
|
|
|
|
$path = substr($path, 0, -1);
|
|
|
|
|
}
|
2014-02-12 12:35:03 -04:00
|
|
|
$sMainDirectory = current(explode("/", $path));
|
2014-02-14 09:39:24 -04:00
|
|
|
if (strstr($path,'/')) {
|
2014-02-12 17:09:51 -04:00
|
|
|
$sSubDirectory = substr($path, strpos($path, "/")+1). PATH_SEP ;
|
|
|
|
|
} else {
|
|
|
|
|
$sSubDirectory = '';
|
|
|
|
|
}
|
2014-01-28 16:31:20 -04:00
|
|
|
switch ($sMainDirectory) {
|
2014-02-12 12:35:03 -04:00
|
|
|
case 'templates':
|
2014-02-12 17:09:51 -04:00
|
|
|
$sDirectory = PATH_DATA_MAILTEMPLATES . $sProcessUID . PATH_SEP . $sSubDirectory;
|
2014-01-28 16:31:20 -04:00
|
|
|
break;
|
2014-02-13 14:56:52 -04:00
|
|
|
case 'public':
|
2014-02-12 17:09:51 -04:00
|
|
|
$sDirectory = PATH_DATA_PUBLIC . $sProcessUID . PATH_SEP . $sSubDirectory;
|
2014-01-28 16:31:20 -04:00
|
|
|
break;
|
|
|
|
|
default:
|
2014-05-22 09:12:35 -04:00
|
|
|
throw new \Exception(\G::LoadTranslation("ID_INVALID_VALUE_FOR", array('path')));
|
2014-01-28 16:31:20 -04:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
\G::verifyPath($sDirectory, true);
|
|
|
|
|
$aTheFiles = array();
|
|
|
|
|
$aFiles = array();
|
|
|
|
|
$oDirectory = dir($sDirectory);
|
|
|
|
|
while ($sObject = $oDirectory->read()) {
|
|
|
|
|
if (($sObject !== '.') && ($sObject !== '..')) {
|
|
|
|
|
$sPath = $sDirectory . $sObject;
|
|
|
|
|
if (is_dir($sPath)) {
|
2014-02-20 12:27:28 -04:00
|
|
|
$aTheFiles[] = array('prf_name' => $sObject,
|
|
|
|
|
'prf_type' => "folder",
|
|
|
|
|
'prf_path' => $sMainDirectory);
|
2014-01-28 16:31:20 -04:00
|
|
|
} else {
|
|
|
|
|
$aAux = pathinfo($sPath);
|
|
|
|
|
$aAux['extension'] = (isset($aAux['extension'])?$aAux['extension']:'');
|
|
|
|
|
$aFiles[] = array('FILE' => $sObject, 'EXT' => $aAux['extension'] );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
foreach ($aFiles as $aFile) {
|
2014-02-27 12:45:24 -04:00
|
|
|
$arrayFileUid = $this->getFileManagerUid($sDirectory.$aFile['FILE']);
|
2016-04-06 12:39:34 -04:00
|
|
|
$fcontent = "";
|
|
|
|
|
if ($getContent === true) {
|
|
|
|
|
$fcontent = file_get_contents($sDirectory . $aFile['FILE']);
|
|
|
|
|
}
|
2014-02-27 12:45:24 -04:00
|
|
|
$fileUid = $arrayFileUid["PRF_UID"];
|
|
|
|
|
if ($fileUid != null) {
|
|
|
|
|
$oProcessFiles = \ProcessFilesPeer::retrieveByPK($fileUid);
|
|
|
|
|
$editable = $oProcessFiles->getPrfEditable();
|
|
|
|
|
if ($editable == '1') {
|
|
|
|
|
$editable = 'true';
|
2014-01-30 12:01:54 -04:00
|
|
|
} else {
|
2014-02-27 12:45:24 -04:00
|
|
|
$editable = 'false';
|
2014-01-30 12:01:54 -04:00
|
|
|
}
|
2014-02-27 12:45:24 -04:00
|
|
|
$aTheFiles[] = array( 'prf_uid' => $oProcessFiles->getPrfUid(),
|
|
|
|
|
'prf_filename' => $aFile['FILE'],
|
|
|
|
|
'usr_uid' => $oProcessFiles->getUsrUid(),
|
|
|
|
|
'prf_update_usr_uid' => $oProcessFiles->getPrfUpdateUsrUid(),
|
|
|
|
|
'prf_path' => $sMainDirectory. PATH_SEP .$sSubDirectory,
|
|
|
|
|
'prf_type' => $oProcessFiles->getPrfType(),
|
|
|
|
|
'prf_editable' => $editable,
|
|
|
|
|
'prf_create_date' => $oProcessFiles->getPrfCreateDate(),
|
|
|
|
|
'prf_update_date' => $oProcessFiles->getPrfUpdateDate(),
|
|
|
|
|
'prf_content' => $fcontent);
|
|
|
|
|
} else {
|
|
|
|
|
$extention = end(explode(".", $aFile['FILE']));
|
|
|
|
|
if ($extention == 'docx' || $extention == 'doc' || $extention == 'html' || $extention == 'php' || $extention == 'jsp'
|
|
|
|
|
|| $extention == 'xlsx' || $extention == 'xls' || $extention == 'js' || $extention == 'css' || $extention == 'txt') {
|
|
|
|
|
$editable = 'true';
|
|
|
|
|
} else {
|
|
|
|
|
$editable = 'false';
|
|
|
|
|
}
|
|
|
|
|
$aTheFiles[] = array('prf_uid' => '',
|
|
|
|
|
'prf_filename' => $aFile['FILE'],
|
|
|
|
|
'usr_uid' => '',
|
|
|
|
|
'prf_update_usr_uid' => '',
|
|
|
|
|
'prf_path' => $sMainDirectory. PATH_SEP .$sSubDirectory,
|
|
|
|
|
'prf_type' => 'file',
|
|
|
|
|
'prf_editable' => $editable,
|
|
|
|
|
'prf_create_date' => '',
|
|
|
|
|
'prf_update_date' => '',
|
|
|
|
|
'prf_content' => $fcontent);
|
|
|
|
|
}
|
2014-02-12 17:09:51 -04:00
|
|
|
}
|
2014-01-28 16:31:20 -04:00
|
|
|
return $aTheFiles;
|
2014-03-10 11:46:05 -04:00
|
|
|
} catch (\Exception $e) {
|
2014-01-28 16:31:20 -04:00
|
|
|
throw $e;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-01-30 12:01:54 -04:00
|
|
|
/**
|
|
|
|
|
* Return the Process File Manager
|
|
|
|
|
*
|
|
|
|
|
* @param string $sProcessUID {@min 32} {@max 32}
|
2014-01-31 13:09:16 -04:00
|
|
|
* @param string $userUID {@min 32} {@max 32}
|
2014-01-30 12:01:54 -04:00
|
|
|
* @param array $aData
|
|
|
|
|
*
|
|
|
|
|
* return array
|
|
|
|
|
*
|
|
|
|
|
* @access public
|
|
|
|
|
*/
|
2014-01-31 13:09:16 -04:00
|
|
|
public function addProcessFilesManager($sProcessUID, $userUID, $aData)
|
2014-01-30 12:01:54 -04:00
|
|
|
{
|
|
|
|
|
try {
|
2014-02-20 12:27:28 -04:00
|
|
|
$aData['prf_path'] = rtrim($aData['prf_path'], '/') . '/';
|
2014-02-26 16:22:23 -04:00
|
|
|
if (!$aData['prf_filename']) {
|
2014-05-22 09:12:35 -04:00
|
|
|
throw new \Exception(\G::LoadTranslation("ID_INVALID_VALUE_FOR", array('prf_filename')));
|
2014-02-24 16:54:55 -04:00
|
|
|
}
|
2014-03-06 12:53:27 -04:00
|
|
|
$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;
|
|
|
|
|
}
|
2014-02-20 12:27:28 -04:00
|
|
|
$sMainDirectory = current(explode("/", $aData['prf_path']));
|
2014-02-13 14:56:52 -04:00
|
|
|
if ($sMainDirectory != 'public' && $sMainDirectory != 'templates') {
|
2014-05-22 09:12:35 -04:00
|
|
|
throw new \Exception(\G::LoadTranslation("ID_INVALID_PRF_PATH"));
|
2014-01-30 12:01:54 -04:00
|
|
|
}
|
2014-02-20 12:27:28 -04:00
|
|
|
if (strstr($aData['prf_path'],'/')) {
|
|
|
|
|
$sSubDirectory = substr($aData['prf_path'], strpos($aData['prf_path'], "/")+1) ;
|
2014-02-12 17:09:51 -04:00
|
|
|
} else {
|
|
|
|
|
$sSubDirectory = '';
|
|
|
|
|
}
|
|
|
|
|
switch ($sMainDirectory) {
|
|
|
|
|
case 'templates':
|
2014-02-20 12:27:28 -04:00
|
|
|
$sDirectory = PATH_DATA_MAILTEMPLATES . $sProcessUID . PATH_SEP . $sSubDirectory . $aData['prf_filename'];
|
2014-02-12 17:09:51 -04:00
|
|
|
$sCheckDirectory = PATH_DATA_MAILTEMPLATES . $sProcessUID . PATH_SEP . $sSubDirectory;
|
2014-06-24 10:57:07 -04:00
|
|
|
if ($extention != '.html') {
|
|
|
|
|
throw new \Exception(\G::LoadTranslation('ID_FILE_UPLOAD_INCORRECT_EXTENSION'));
|
|
|
|
|
}
|
2014-02-12 17:09:51 -04:00
|
|
|
break;
|
2014-02-13 14:56:52 -04:00
|
|
|
case 'public':
|
2014-02-20 12:27:28 -04:00
|
|
|
$sDirectory = PATH_DATA_PUBLIC . $sProcessUID . PATH_SEP . $sSubDirectory . $aData['prf_filename'];
|
2014-02-12 17:09:51 -04:00
|
|
|
$sCheckDirectory = PATH_DATA_PUBLIC . $sProcessUID . PATH_SEP . $sSubDirectory;
|
2014-03-06 12:53:27 -04:00
|
|
|
$sEditable = false;
|
2014-06-24 10:57:07 -04:00
|
|
|
if ($extention == '.exe') {
|
|
|
|
|
throw new \Exception(\G::LoadTranslation('ID_FILE_UPLOAD_INCORRECT_EXTENSION'));
|
|
|
|
|
}
|
2014-02-12 17:09:51 -04:00
|
|
|
break;
|
|
|
|
|
default:
|
2014-02-20 12:27:28 -04:00
|
|
|
$sDirectory = PATH_DATA_MAILTEMPLATES . $sProcessUID . PATH_SEP . $sSubDirectory . $aData['prf_filename'];
|
2014-02-12 17:09:51 -04:00
|
|
|
break;
|
2014-02-14 09:39:24 -04:00
|
|
|
}
|
2014-03-10 13:56:43 -04:00
|
|
|
$content = $aData['prf_content'];
|
2015-04-23 09:46:55 -04:00
|
|
|
if (file_exists($sDirectory) ) {
|
|
|
|
|
$directory = $sMainDirectory. PATH_SEP . $sSubDirectory . $aData['prf_filename'];
|
|
|
|
|
throw new \Exception(\G::LoadTranslation("ID_EXISTS_FILE", array($directory)));
|
2014-03-10 13:56:43 -04:00
|
|
|
}
|
2015-07-21 15:34:59 -04:00
|
|
|
|
2014-03-06 12:53:27 -04:00
|
|
|
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();
|
2014-01-30 12:01:54 -04:00
|
|
|
}
|
2014-02-12 17:09:51 -04:00
|
|
|
\G::verifyPath($sCheckDirectory, true);
|
2014-01-30 12:01:54 -04:00
|
|
|
$sPkProcessFiles = \G::generateUniqueID();
|
|
|
|
|
$oProcessFiles = new \ProcessFiles();
|
2014-02-20 12:27:28 -04:00
|
|
|
$sDate = date('Y-m-d H:i:s');
|
|
|
|
|
$oProcessFiles->setPrfUid($sPkProcessFiles);
|
|
|
|
|
$oProcessFiles->setProUid($sProcessUID);
|
|
|
|
|
$oProcessFiles->setUsrUid($userUID);
|
|
|
|
|
$oProcessFiles->setPrfUpdateUsrUid('');
|
|
|
|
|
$oProcessFiles->setPrfPath($sDirectory);
|
2014-02-12 17:09:51 -04:00
|
|
|
$oProcessFiles->setPrfType('file');
|
2014-02-20 12:27:28 -04:00
|
|
|
$oProcessFiles->setPrfEditable($sEditable);
|
|
|
|
|
$oProcessFiles->setPrfCreateDate($sDate);
|
2014-01-30 12:01:54 -04:00
|
|
|
$oProcessFiles->save();
|
|
|
|
|
$fp = fopen($sDirectory, 'w');
|
2015-04-10 13:01:56 -04:00
|
|
|
$content = stripslashes($aData['prf_content']);
|
|
|
|
|
$content = str_replace("@amp@", "&", $content);
|
2014-01-30 12:01:54 -04:00
|
|
|
fwrite($fp, $content);
|
|
|
|
|
fclose($fp);
|
|
|
|
|
$oProcessFile = array('prf_uid' => $oProcessFiles->getPrfUid(),
|
2014-02-26 16:22:23 -04:00
|
|
|
'prf_filename' => $aData['prf_filename'],
|
2014-01-30 12:01:54 -04:00
|
|
|
'usr_uid' => $oProcessFiles->getUsrUid(),
|
|
|
|
|
'prf_update_usr_uid' => $oProcessFiles->getPrfUpdateUsrUid(),
|
2014-02-20 12:27:28 -04:00
|
|
|
'prf_path' => $sMainDirectory. PATH_SEP . $sSubDirectory,
|
2014-01-30 12:01:54 -04:00
|
|
|
'prf_type' => $oProcessFiles->getPrfType(),
|
|
|
|
|
'prf_editable' => $oProcessFiles->getPrfEditable(),
|
|
|
|
|
'prf_create_date' => $oProcessFiles->getPrfCreateDate(),
|
2014-02-24 16:54:55 -04:00
|
|
|
'prf_update_date' => $oProcessFiles->getPrfUpdateDate(),
|
|
|
|
|
'prf_content' => $content);
|
2014-01-30 12:01:54 -04:00
|
|
|
return $oProcessFile;
|
|
|
|
|
} catch (Exception $e) {
|
|
|
|
|
throw $e;
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-07-21 15:34:59 -04:00
|
|
|
|
2016-04-06 10:53:47 -04:00
|
|
|
/**
|
|
|
|
|
* @param $aData
|
|
|
|
|
* @throws Exception
|
|
|
|
|
* @throws \Exception
|
|
|
|
|
*/
|
2015-06-25 14:31:38 -04:00
|
|
|
public function addProcessFilesManagerInDb($aData)
|
|
|
|
|
{
|
|
|
|
|
try {
|
|
|
|
|
$oProcessFiles = new \ProcessFiles();
|
|
|
|
|
$aData = array_change_key_case($aData, CASE_UPPER);
|
|
|
|
|
$oProcessFiles->fromArray($aData, \BasePeer::TYPE_FIELDNAME);
|
2015-07-21 15:34:59 -04:00
|
|
|
|
2016-04-06 10:53:47 -04:00
|
|
|
$path = $aData['PRF_PATH'];
|
|
|
|
|
|
2016-05-04 16:34:40 -04:00
|
|
|
$allDirectories = pathinfo($path);
|
|
|
|
|
$path = explode('/',$allDirectories['dirname']);
|
|
|
|
|
$fileDirectory = $path[count($path)-2];
|
2016-04-06 10:53:47 -04:00
|
|
|
|
|
|
|
|
switch ($fileDirectory) {
|
|
|
|
|
case 'mailTemplates':
|
|
|
|
|
$sDirectory = PATH_DATA_MAILTEMPLATES . $aData['PRO_UID'] . PATH_SEP . basename($aData['PRF_PATH']);
|
|
|
|
|
break;
|
|
|
|
|
case 'public':
|
|
|
|
|
$sDirectory = PATH_DATA_PUBLIC . $aData['PRO_UID'] . PATH_SEP . basename($aData['PRF_PATH']);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
2016-05-04 16:34:40 -04:00
|
|
|
if (strtoupper(substr(PHP_OS, 0, 3)) !== 'WIN') {
|
|
|
|
|
error_log(\G::LoadTranslation("ID_INVALID_VALUE_FOR", array($aData['PRF_PATH'])));
|
|
|
|
|
}
|
|
|
|
|
return;
|
2016-04-06 10:53:47 -04:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-28 14:09:49 -04:00
|
|
|
$oProcessFiles->setPrfPath($sDirectory);
|
|
|
|
|
|
2015-06-25 14:31:38 -04:00
|
|
|
if($this->existsProcessFile($aData['PRF_UID'])) {
|
|
|
|
|
$sPkProcessFiles = \G::generateUniqueID();
|
|
|
|
|
$oProcessFiles->setPrfUid($sPkProcessFiles);
|
2015-07-21 15:34:59 -04:00
|
|
|
|
2015-06-25 14:31:38 -04:00
|
|
|
$emailEvent = new \ProcessMaker\BusinessModel\EmailEvent();
|
|
|
|
|
$emailEvent->updatePrfUid($aData['PRF_UID'], $sPkProcessFiles, $aData['PRO_UID']);
|
|
|
|
|
}
|
2015-07-21 15:34:59 -04:00
|
|
|
|
2015-06-25 14:31:38 -04:00
|
|
|
$result = $oProcessFiles->save();
|
|
|
|
|
} catch (Exception $e) {
|
|
|
|
|
throw $e;
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-07-21 15:34:59 -04:00
|
|
|
|
2016-03-22 16:13:41 -04:00
|
|
|
/**
|
|
|
|
|
* @param $aData
|
|
|
|
|
* @throws Exception
|
|
|
|
|
*/
|
|
|
|
|
public function updateProcessFilesManagerInDb($aData)
|
|
|
|
|
{
|
|
|
|
|
try {
|
|
|
|
|
//update database
|
|
|
|
|
if ($this->existsProcessFile($aData['prf_uid'])) {
|
|
|
|
|
$aData = array_change_key_case($aData, CASE_UPPER);
|
|
|
|
|
$oProcessFiles = \ProcessFilesPeer::retrieveByPK($aData['PRF_UID']);
|
|
|
|
|
$sDate = date('Y-m-d H:i:s');
|
|
|
|
|
$oProcessFiles->setPrfUpdateDate($sDate);
|
|
|
|
|
$oProcessFiles->setProUid($aData['PRO_UID']);
|
|
|
|
|
$oProcessFiles->setPrfPath($aData['PRF_PATH']);
|
|
|
|
|
$oProcessFiles->save();
|
|
|
|
|
} else {
|
|
|
|
|
$this->addProcessFilesManagerInDb($aData);
|
|
|
|
|
}
|
|
|
|
|
} catch (Exception $e) {
|
|
|
|
|
throw $e;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-06-25 14:31:38 -04:00
|
|
|
public function existsProcessFile($prfUid)
|
|
|
|
|
{
|
|
|
|
|
try {
|
|
|
|
|
$obj = \ProcessFilesPeer::retrieveByPK($prfUid);
|
|
|
|
|
|
|
|
|
|
return (!is_null($obj))? true : false;
|
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
|
throw $e;
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-01-30 12:01:54 -04:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Return the Process Files Manager
|
|
|
|
|
*
|
2014-02-20 12:27:28 -04:00
|
|
|
* @param string $prjUid {@min 32} {@max 32}
|
2014-02-24 16:54:55 -04:00
|
|
|
* @param string $prfUid {@min 32} {@max 32}
|
2014-01-30 12:01:54 -04:00
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
* @access public
|
|
|
|
|
*/
|
2014-02-24 16:54:55 -04:00
|
|
|
public function uploadProcessFilesManager($prjUid, $prfUid)
|
2014-01-30 12:01:54 -04:00
|
|
|
{
|
|
|
|
|
try {
|
2014-02-20 12:27:28 -04:00
|
|
|
$path = '';
|
|
|
|
|
$criteria = new \Criteria("workflow");
|
|
|
|
|
$criteria->addSelectColumn(\ProcessFilesPeer::PRF_PATH);
|
|
|
|
|
$criteria->add(\ProcessFilesPeer::PRF_UID, $prfUid, \Criteria::EQUAL);
|
|
|
|
|
$rsCriteria = \ProcessFilesPeer::doSelectRS($criteria);
|
|
|
|
|
$rsCriteria->setFetchmode(\ResultSet::FETCHMODE_ASSOC);
|
|
|
|
|
$rsCriteria->next();
|
|
|
|
|
while ($aRow = $rsCriteria->getRow()) {
|
|
|
|
|
$path = $aRow['PRF_PATH'];
|
|
|
|
|
$rsCriteria->next();
|
|
|
|
|
}
|
2014-02-26 16:22:23 -04:00
|
|
|
if ($path == '') {
|
2014-02-20 12:27:28 -04:00
|
|
|
throw new \Exception(\G::LoadTranslation('ID_PMTABLE_UPLOADING_FILE_PROBLEM'));
|
|
|
|
|
}
|
2014-06-03 09:56:11 -04:00
|
|
|
$extention = strstr($_FILES['prf_file']['name'], '.');
|
|
|
|
|
if (!$extention) {
|
|
|
|
|
$extention = '.html';
|
|
|
|
|
$_FILES['prf_file']['name'] = $_FILES['prf_file']['name'].$extention;
|
|
|
|
|
}
|
2014-02-20 12:27:28 -04:00
|
|
|
$file = end(explode("/",$path));
|
2015-02-18 15:14:34 -04:00
|
|
|
if(strpos($file,"\\") > 0) {
|
|
|
|
|
$file = str_replace('\\', '/', $file);
|
|
|
|
|
$file = end(explode("/",$file));
|
|
|
|
|
}
|
2014-02-20 12:27:28 -04:00
|
|
|
$path = str_replace($file,'',$path);
|
2014-02-24 16:54:55 -04:00
|
|
|
if ($file == $_FILES['prf_file']['name']) {
|
|
|
|
|
if ($_FILES['prf_file']['error'] != 1) {
|
|
|
|
|
if ($_FILES['prf_file']['tmp_name'] != '') {
|
2014-02-26 12:22:22 -04:00
|
|
|
\G::uploadFile($_FILES['prf_file']['tmp_name'], $path, $_FILES['prf_file']['name']);
|
2014-02-24 16:54:55 -04:00
|
|
|
}
|
2014-02-26 16:22:23 -04:00
|
|
|
}
|
2014-02-24 16:54:55 -04:00
|
|
|
} else {
|
|
|
|
|
throw new \Exception(\G::LoadTranslation('ID_PMTABLE_UPLOADING_FILE_PROBLEM'));
|
2014-02-20 12:27:28 -04:00
|
|
|
}
|
2014-02-26 12:22:22 -04:00
|
|
|
$oProcessFile = array('prf_uid' => $prfUid);
|
|
|
|
|
return $oProcessFile;
|
2014-01-30 12:01:54 -04:00
|
|
|
} catch (Exception $e) {
|
|
|
|
|
throw $e;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-01-31 13:09:16 -04:00
|
|
|
/**
|
|
|
|
|
* Get data of unique ids of a file
|
|
|
|
|
*
|
|
|
|
|
* @param string $path
|
|
|
|
|
*
|
|
|
|
|
* return array
|
|
|
|
|
*/
|
|
|
|
|
public function getFileManagerUid($path)
|
|
|
|
|
{
|
|
|
|
|
try {
|
2015-06-30 12:17:41 -04:00
|
|
|
if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
|
|
|
|
|
$path = str_replace("/", DIRECTORY_SEPARATOR.DIRECTORY_SEPARATOR, $path);
|
|
|
|
|
}
|
|
|
|
|
$path = explode(DIRECTORY_SEPARATOR,$path);
|
2015-08-31 10:47:01 -04:00
|
|
|
$baseName = $path[count($path)-2]."\\\\".$path[count($path)-1];
|
2015-06-30 12:17:41 -04:00
|
|
|
$baseName2 = $path[count($path)-2]."/".$path[count($path)-1];
|
2014-01-31 13:09:16 -04:00
|
|
|
$criteria = new \Criteria("workflow");
|
|
|
|
|
$criteria->addSelectColumn(\ProcessFilesPeer::PRF_UID);
|
2015-08-31 10:47:01 -04:00
|
|
|
$criteria->add( $criteria->getNewCriterion( \ProcessFilesPeer::PRF_PATH, '%' . $baseName . '%', \Criteria::LIKE )->addOr( $criteria->getNewCriterion( \ProcessFilesPeer::PRF_PATH, '%' . $baseName2 . '%', \Criteria::LIKE )));
|
2014-01-31 13:09:16 -04:00
|
|
|
$rsCriteria = \ProcessFilesPeer::doSelectRS($criteria);
|
|
|
|
|
$rsCriteria->setFetchmode(\ResultSet::FETCHMODE_ASSOC);
|
|
|
|
|
$rsCriteria->next();
|
|
|
|
|
return $rsCriteria->getRow();
|
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
|
throw $e;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-01-30 14:53:30 -04:00
|
|
|
/**
|
|
|
|
|
* Return the Process Files Manager
|
|
|
|
|
*
|
|
|
|
|
* @param string $sProcessUID {@min 32} {@max 32}
|
2014-01-31 13:09:16 -04:00
|
|
|
* @param string $userUID {@min 32} {@max 32}
|
2014-01-30 14:53:30 -04:00
|
|
|
* @param array $aData
|
2014-02-26 12:22:22 -04:00
|
|
|
* @param string $prfUid {@min 32} {@max 32}
|
2014-01-30 14:53:30 -04:00
|
|
|
*
|
|
|
|
|
* return array
|
|
|
|
|
*
|
|
|
|
|
* @access public
|
|
|
|
|
*/
|
2014-02-26 12:22:22 -04:00
|
|
|
public function updateProcessFilesManager($sProcessUID, $userUID, $aData, $prfUid)
|
2014-01-30 14:53:30 -04:00
|
|
|
{
|
|
|
|
|
try {
|
2014-02-26 12:22:22 -04:00
|
|
|
$path = '';
|
|
|
|
|
$criteria = new \Criteria("workflow");
|
|
|
|
|
$criteria->addSelectColumn(\ProcessFilesPeer::PRF_PATH);
|
|
|
|
|
$criteria->add(\ProcessFilesPeer::PRF_UID, $prfUid, \Criteria::EQUAL);
|
|
|
|
|
$rsCriteria = \ProcessFilesPeer::doSelectRS($criteria);
|
|
|
|
|
$rsCriteria->setFetchmode(\ResultSet::FETCHMODE_ASSOC);
|
|
|
|
|
$rsCriteria->next();
|
|
|
|
|
while ($aRow = $rsCriteria->getRow()) {
|
|
|
|
|
$path = $aRow['PRF_PATH'];
|
|
|
|
|
$rsCriteria->next();
|
2014-02-12 17:09:51 -04:00
|
|
|
}
|
2014-02-26 16:22:23 -04:00
|
|
|
if ($path == '') {
|
2014-05-22 09:12:35 -04:00
|
|
|
throw new \Exception(\G::LoadTranslation("ID_INVALID_VALUE_FOR", array('prf_uid')));
|
2014-02-14 09:39:24 -04:00
|
|
|
}
|
2015-11-25 11:19:43 -04:00
|
|
|
$sFile = basename($path);
|
2014-02-26 12:22:22 -04:00
|
|
|
$sPath = str_replace($sFile,'',$path);
|
2014-03-05 16:02:35 -04:00
|
|
|
$sSubDirectory = substr(str_replace($sProcessUID,'',substr($sPath,(strpos($sPath, $sProcessUID)))),0,-1);
|
2014-02-26 12:22:22 -04:00
|
|
|
$sMainDirectory = str_replace(substr($sPath, strpos($sPath, $sProcessUID)),'', $sPath);
|
2014-02-26 16:22:23 -04:00
|
|
|
if ($sMainDirectory == PATH_DATA_MAILTEMPLATES) {
|
2014-02-26 12:22:22 -04:00
|
|
|
$sMainDirectory = 'mailTemplates';
|
|
|
|
|
} else {
|
|
|
|
|
$sMainDirectory = 'public';
|
2014-02-12 17:09:51 -04:00
|
|
|
}
|
2014-02-26 12:22:22 -04:00
|
|
|
$extention = end(explode(".", $sFile));
|
2014-01-31 13:09:16 -04:00
|
|
|
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;
|
|
|
|
|
}
|
2014-02-20 12:27:28 -04:00
|
|
|
if ($sEditable == false) {
|
2014-05-22 09:12:35 -04:00
|
|
|
throw new \Exception(\G::LoadTranslation("ID_UNABLE_TO_EDIT"));
|
2014-02-20 12:27:28 -04:00
|
|
|
}
|
2014-02-26 12:22:22 -04:00
|
|
|
$oProcessFiles = \ProcessFilesPeer::retrieveByPK($prfUid);
|
2014-02-20 12:27:28 -04:00
|
|
|
$sDate = date('Y-m-d H:i:s');
|
|
|
|
|
$oProcessFiles->setPrfUpdateUsrUid($userUID);
|
|
|
|
|
$oProcessFiles->setPrfUpdateDate($sDate);
|
2014-01-31 13:09:16 -04:00
|
|
|
$oProcessFiles->save();
|
2015-06-25 14:31:38 -04:00
|
|
|
|
|
|
|
|
$path = PATH_DATA_MAILTEMPLATES.$sProcessUID.DIRECTORY_SEPARATOR.$sFile;
|
|
|
|
|
|
2014-02-26 12:22:22 -04:00
|
|
|
$fp = fopen($path, 'w');
|
2015-04-10 13:01:56 -04:00
|
|
|
$content = stripslashes($aData['prf_content']);
|
|
|
|
|
$content = str_replace("@amp@", "&", $content);
|
2014-01-31 13:09:16 -04:00
|
|
|
fwrite($fp, $content);
|
|
|
|
|
fclose($fp);
|
|
|
|
|
$oProcessFile = array('prf_uid' => $oProcessFiles->getPrfUid(),
|
2014-02-26 12:22:22 -04:00
|
|
|
'prf_filename' => $sFile,
|
2014-01-31 13:09:16 -04:00
|
|
|
'usr_uid' => $oProcessFiles->getUsrUid(),
|
|
|
|
|
'prf_update_usr_uid' => $oProcessFiles->getPrfUpdateUsrUid(),
|
2014-03-06 12:53:27 -04:00
|
|
|
'prf_path' => $sMainDirectory.$sSubDirectory,
|
2014-01-31 13:09:16 -04:00
|
|
|
'prf_type' => $oProcessFiles->getPrfType(),
|
2014-02-20 12:27:28 -04:00
|
|
|
'prf_editable' => $sEditable,
|
2014-01-31 13:09:16 -04:00
|
|
|
'prf_create_date' => $oProcessFiles->getPrfCreateDate(),
|
2014-02-25 09:50:33 -04:00
|
|
|
'prf_update_date' => $oProcessFiles->getPrfUpdateDate(),
|
|
|
|
|
'prf_content' => $content);
|
2014-01-31 13:09:16 -04:00
|
|
|
return $oProcessFile;
|
2014-01-30 14:53:30 -04:00
|
|
|
} catch (Exception $e) {
|
|
|
|
|
throw $e;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-01-30 12:01:54 -04:00
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
* @param string $sProcessUID {@min 32} {@max 32}
|
2014-02-26 12:22:22 -04:00
|
|
|
* @param string $prfUid {@min 32} {@max 32}
|
2014-01-30 12:01:54 -04:00
|
|
|
*
|
|
|
|
|
*
|
2014-06-30 16:26:12 -04:00
|
|
|
* @access public
|
2014-01-30 12:01:54 -04:00
|
|
|
*/
|
2016-04-18 11:01:05 -04:00
|
|
|
public function deleteProcessFilesManager($sProcessUID, $prfUid, $verifyingRelationship = false)
|
2014-01-30 12:01:54 -04:00
|
|
|
{
|
|
|
|
|
try {
|
2014-02-26 12:22:22 -04:00
|
|
|
$path = '';
|
2016-05-04 16:34:40 -04:00
|
|
|
$criteriaPf = new \Criteria("workflow");
|
|
|
|
|
$criteriaPf->addSelectColumn(\ProcessFilesPeer::PRF_PATH);
|
|
|
|
|
$criteriaPf->add(\ProcessFilesPeer::PRF_UID, $prfUid, \Criteria::EQUAL);
|
|
|
|
|
$rsCriteria = \ProcessFilesPeer::doSelectRS($criteriaPf);
|
2014-02-26 12:22:22 -04:00
|
|
|
$rsCriteria->setFetchmode(\ResultSet::FETCHMODE_ASSOC);
|
|
|
|
|
$rsCriteria->next();
|
|
|
|
|
while ($aRow = $rsCriteria->getRow()) {
|
|
|
|
|
$path = $aRow['PRF_PATH'];
|
|
|
|
|
$rsCriteria->next();
|
2014-02-12 17:09:51 -04:00
|
|
|
}
|
2014-02-26 16:22:23 -04:00
|
|
|
if ($path == '') {
|
2014-05-22 09:12:35 -04:00
|
|
|
throw new \Exception(\G::LoadTranslation("ID_INVALID_VALUE_FOR", array('prf_uid')));
|
2014-02-12 17:09:51 -04:00
|
|
|
}
|
2015-07-21 15:34:59 -04:00
|
|
|
|
2016-04-18 11:01:05 -04:00
|
|
|
$relationshipEmailEvent = false;
|
|
|
|
|
$criteria = new \Criteria("workflow");
|
|
|
|
|
$criteria->addSelectColumn(\EmailEventPeer::PRF_UID);
|
|
|
|
|
$criteria->add(\EmailEventPeer::PRF_UID, $prfUid, \Criteria::EQUAL);
|
|
|
|
|
$rsCriteria = \EmailEventPeer::doSelectRS($criteria);
|
|
|
|
|
$rsCriteria->setFetchmode(\ResultSet::FETCHMODE_ASSOC);
|
|
|
|
|
$rsCriteria->next();
|
|
|
|
|
while ($aRow = $rsCriteria->getRow()) {
|
|
|
|
|
$relationshipEmailEvent = true;
|
|
|
|
|
$rsCriteria->next();
|
|
|
|
|
}
|
|
|
|
|
if ($relationshipEmailEvent && !$verifyingRelationship) {
|
|
|
|
|
throw new \Exception(\G::LoadTranslation(G::LoadTranslation('ID_CANNOT_REMOVE_TEMPLATE_EMAIL_EVENT',
|
|
|
|
|
array(end(explode(DIRECTORY_SEPARATOR,$path))))));
|
|
|
|
|
}
|
|
|
|
|
|
2015-08-31 10:47:01 -04:00
|
|
|
$sFile = end(explode(DIRECTORY_SEPARATOR,$path));
|
2015-06-25 14:31:38 -04:00
|
|
|
$path = PATH_DATA_MAILTEMPLATES.$sProcessUID.DIRECTORY_SEPARATOR.$sFile;
|
2015-07-21 15:34:59 -04:00
|
|
|
|
2015-06-25 14:31:38 -04:00
|
|
|
if (file_exists($path) && !is_dir($path)) {
|
2014-08-13 16:37:24 -04:00
|
|
|
unlink($path);
|
2015-08-21 12:48:54 -04:00
|
|
|
} else {
|
|
|
|
|
$path = PATH_DATA_PUBLIC.$sProcessUID.DIRECTORY_SEPARATOR.$sFile;
|
|
|
|
|
|
|
|
|
|
if (file_exists($path) && !is_dir($path)) {
|
|
|
|
|
unlink($path);
|
|
|
|
|
}
|
2016-05-04 16:34:40 -04:00
|
|
|
}
|
2014-08-13 16:37:24 -04:00
|
|
|
|
2016-05-04 16:34:40 -04:00
|
|
|
$rs = \ProcessFilesPeer::doDelete($criteriaPf);
|
2014-01-30 12:01:54 -04:00
|
|
|
} catch (Exception $e) {
|
|
|
|
|
throw $e;
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-02-11 17:03:25 -04:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
* @param string $sProcessUID {@min 32} {@max 32}
|
2014-02-25 12:43:18 -04:00
|
|
|
* @param string $prfUid {@min 32} {@max 32}
|
2014-02-11 17:03:25 -04:00
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
* @access public
|
|
|
|
|
*/
|
2014-02-25 12:43:18 -04:00
|
|
|
public function downloadProcessFilesManager($sProcessUID, $prfUid)
|
2014-02-11 17:03:25 -04:00
|
|
|
{
|
|
|
|
|
try {
|
2014-02-25 12:43:18 -04:00
|
|
|
$path = '';
|
|
|
|
|
$criteria = new \Criteria("workflow");
|
|
|
|
|
$criteria->addSelectColumn(\ProcessFilesPeer::PRF_PATH);
|
|
|
|
|
$criteria->add(\ProcessFilesPeer::PRF_UID, $prfUid, \Criteria::EQUAL);
|
|
|
|
|
$rsCriteria = \ProcessFilesPeer::doSelectRS($criteria);
|
|
|
|
|
$rsCriteria->setFetchmode(\ResultSet::FETCHMODE_ASSOC);
|
|
|
|
|
$rsCriteria->next();
|
|
|
|
|
while ($aRow = $rsCriteria->getRow()) {
|
|
|
|
|
$path = $aRow['PRF_PATH'];
|
|
|
|
|
$rsCriteria->next();
|
2014-02-12 17:09:51 -04:00
|
|
|
}
|
2014-02-26 16:22:23 -04:00
|
|
|
if ($path == '') {
|
2014-05-22 09:12:35 -04:00
|
|
|
throw new \Exception(\G::LoadTranslation("ID_INVALID_VALUE_FOR", array('prf_uid')));
|
2014-02-12 17:09:51 -04:00
|
|
|
}
|
2016-04-07 13:17:33 -04:00
|
|
|
$sFile = end(explode("/",str_replace('\\', '/',$path)));
|
2014-02-25 12:43:18 -04:00
|
|
|
$sPath = str_replace($sFile,'',$path);
|
2014-03-05 16:02:35 -04:00
|
|
|
$sSubDirectory = substr(str_replace($sProcessUID,'',substr($sPath,(strpos($sPath, $sProcessUID)))),0,-1);
|
2014-02-25 12:43:18 -04:00
|
|
|
$sMainDirectory = str_replace(substr($sPath, strpos($sPath, $sProcessUID)),'', $sPath);
|
2014-02-26 16:22:23 -04:00
|
|
|
if ($sMainDirectory == PATH_DATA_MAILTEMPLATES) {
|
2014-02-26 12:22:22 -04:00
|
|
|
$sMainDirectory = 'mailTemplates';
|
2014-02-12 17:09:51 -04:00
|
|
|
} else {
|
2014-02-25 12:43:18 -04:00
|
|
|
$sMainDirectory = 'public';
|
2014-02-14 09:39:24 -04:00
|
|
|
}
|
2014-02-25 12:43:18 -04:00
|
|
|
if (file_exists($path)) {
|
2014-02-21 16:10:09 -04:00
|
|
|
$oProcessMap = new \processMap(new \DBConnection());
|
2014-02-25 12:43:18 -04:00
|
|
|
$oProcessMap->downloadFile($sProcessUID,$sMainDirectory,$sSubDirectory,$sFile);
|
|
|
|
|
die();
|
2014-02-21 16:10:09 -04:00
|
|
|
} else {
|
2014-04-28 10:10:59 -04:00
|
|
|
throw (new \Exception( 'Invalid value specified for path.'));
|
2014-02-21 16:10:09 -04:00
|
|
|
}
|
2014-02-11 17:03:25 -04:00
|
|
|
} catch (Exception $e) {
|
|
|
|
|
throw $e;
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-03-05 16:02:35 -04:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
* @param string $sProcessUID {@min 32} {@max 32}
|
|
|
|
|
* @param array $path
|
|
|
|
|
*
|
|
|
|
|
* @access public
|
|
|
|
|
*/
|
|
|
|
|
public function deleteFolderProcessFilesManager($sProcessUID, $path)
|
|
|
|
|
{
|
|
|
|
|
try {
|
|
|
|
|
$sDirToDelete = end(explode("/",$path));
|
|
|
|
|
$sPath = str_replace($sDirToDelete,'',$path);
|
|
|
|
|
$sSubDirectory = substr(str_replace($sProcessUID,'',substr($sPath,(strpos($sPath, $sProcessUID)))),0,-1);
|
|
|
|
|
$sMainDirectory = current(explode("/", $path));
|
|
|
|
|
$sSubDirectory = substr(str_replace($sMainDirectory,'',$sSubDirectory),1);
|
|
|
|
|
switch ($sMainDirectory) {
|
|
|
|
|
case 'templates':
|
|
|
|
|
$sDirectory = PATH_DATA_MAILTEMPLATES . $sProcessUID . PATH_SEP . ($sSubDirectory != '' ? $sSubDirectory . PATH_SEP : '');
|
|
|
|
|
break;
|
|
|
|
|
case 'public':
|
|
|
|
|
$sDirectory = PATH_DATA_PUBLIC . $sProcessUID . PATH_SEP . ($sSubDirectory != '' ? $sSubDirectory . PATH_SEP : '');
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
die();
|
|
|
|
|
break;
|
|
|
|
|
}
|
2014-03-06 12:53:27 -04:00
|
|
|
if (file_exists($sDirectory.$sDirToDelete)) {
|
|
|
|
|
\G::rm_dir($sDirectory.$sDirToDelete);
|
2014-03-05 16:02:35 -04:00
|
|
|
} else {
|
2014-05-22 09:12:35 -04:00
|
|
|
throw new \Exception(\G::LoadTranslation("ID_INVALID_VALUE_FOR", array('path')));
|
2014-03-05 16:02:35 -04:00
|
|
|
}
|
2014-03-06 12:53:27 -04:00
|
|
|
$criteria = new \Criteria("workflow");
|
|
|
|
|
$criteria->addSelectColumn(\ProcessFilesPeer::PRF_PATH);
|
|
|
|
|
$criteria->add( \ProcessFilesPeer::PRF_PATH, '%' . $sDirectory.$sDirToDelete. PATH_SEP . '%', \Criteria::LIKE );
|
|
|
|
|
$rs = \ProcessFilesPeer::doDelete($criteria);
|
|
|
|
|
return $sDirectory.$sDirToDelete;
|
2014-03-05 16:02:35 -04:00
|
|
|
} catch (Exception $e) {
|
|
|
|
|
throw $e;
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-03-11 15:10:09 -04:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
* @param string $sProcessUID {@min 32} {@max 32}
|
|
|
|
|
* @param string $prfUid {@min 32} {@max 32}
|
|
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
* @access public
|
|
|
|
|
*/
|
|
|
|
|
public function getProcessFileManager($sProcessUID, $prfUid)
|
|
|
|
|
{
|
|
|
|
|
try {
|
|
|
|
|
$oProcessFiles = \ProcessFilesPeer::retrieveByPK($prfUid);
|
|
|
|
|
$fcontent = file_get_contents($oProcessFiles->getPrfPath());
|
2015-09-26 12:06:13 -04:00
|
|
|
$pth = $oProcessFiles->getPrfPath();
|
|
|
|
|
$pth = str_replace("\\","/",$pth);
|
|
|
|
|
$prfPath = explode("/",$pth);
|
|
|
|
|
$sFile = end($prfPath);
|
2014-03-11 15:10:09 -04:00
|
|
|
$path = $oProcessFiles->getPrfPath();
|
|
|
|
|
$sPath = str_replace($sFile,'',$path);
|
|
|
|
|
$sSubDirectory = substr(str_replace($sProcessUID,'',substr($sPath,(strpos($sPath, $sProcessUID)))),0,-1);
|
|
|
|
|
$sMainDirectory = str_replace(substr($sPath, strpos($sPath, $sProcessUID)),'', $sPath);
|
|
|
|
|
if ($sMainDirectory == PATH_DATA_MAILTEMPLATES) {
|
|
|
|
|
$sMainDirectory = 'templates';
|
|
|
|
|
} else {
|
|
|
|
|
$sMainDirectory = 'public';
|
|
|
|
|
}
|
|
|
|
|
$oProcessFile = array('prf_uid' => $oProcessFiles->getPrfUid(),
|
|
|
|
|
'prf_filename' => $sFile,
|
|
|
|
|
'usr_uid' => $oProcessFiles->getUsrUid(),
|
|
|
|
|
'prf_update_usr_uid' => $oProcessFiles->getPrfUpdateUsrUid(),
|
|
|
|
|
'prf_path' => $sMainDirectory.$sSubDirectory,
|
|
|
|
|
'prf_type' => $oProcessFiles->getPrfType(),
|
|
|
|
|
'prf_editable' => $oProcessFiles->getPrfEditable(),
|
|
|
|
|
'prf_create_date' => $oProcessFiles->getPrfCreateDate(),
|
|
|
|
|
'prf_update_date' => $oProcessFiles->getPrfUpdateDate(),
|
|
|
|
|
'prf_content' => $fcontent);
|
|
|
|
|
return $oProcessFile;
|
|
|
|
|
} catch (Exception $e) {
|
|
|
|
|
throw $e;
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-07-21 15:34:59 -04:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Process-Files upgrade
|
|
|
|
|
*
|
|
|
|
|
* @param string $projectUid Unique id of Project
|
|
|
|
|
*
|
|
|
|
|
* return void
|
|
|
|
|
*/
|
|
|
|
|
public function processFilesUpgrade($projectUid = "")
|
|
|
|
|
{
|
|
|
|
|
try {
|
|
|
|
|
//Set variables
|
|
|
|
|
$conf = new \Configuration();
|
|
|
|
|
|
|
|
|
|
//Create/Get PROCESS_FILES_CHECKED
|
|
|
|
|
$arrayProjectUid = array();
|
|
|
|
|
|
|
|
|
|
$configuration = \ConfigurationPeer::retrieveByPK("PROCESS_FILES_CHECKED", "", "", "", "");
|
|
|
|
|
|
|
|
|
|
if (is_null($configuration)) {
|
|
|
|
|
$result = $conf->create(array(
|
|
|
|
|
"CFG_UID" => "PROCESS_FILES_CHECKED",
|
|
|
|
|
"OBJ_UID" => "",
|
|
|
|
|
"CFG_VALUE" => serialize($arrayProjectUid),
|
|
|
|
|
"PRO_UID" => "",
|
|
|
|
|
"USR_UID" => "",
|
|
|
|
|
"APP_UID" => ""
|
|
|
|
|
));
|
|
|
|
|
} else {
|
|
|
|
|
$arrayProjectUid = unserialize($configuration->getCfgValue());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//Set variables
|
|
|
|
|
$arrayPath = array("templates" => PATH_DATA_MAILTEMPLATES, "public" => PATH_DATA_PUBLIC);
|
|
|
|
|
$flagProjectUid = false;
|
|
|
|
|
|
|
|
|
|
//Query
|
|
|
|
|
$criteria = new \Criteria("workflow");
|
|
|
|
|
|
|
|
|
|
$criteria->addSelectColumn(\BpmnProjectPeer::PRJ_UID);
|
|
|
|
|
|
|
|
|
|
if ($projectUid != "") {
|
|
|
|
|
$criteria->add(
|
|
|
|
|
$criteria->getNewCriterion(\BpmnProjectPeer::PRJ_UID, $arrayProjectUid, \Criteria::NOT_IN)->addAnd(
|
|
|
|
|
$criteria->getNewCriterion(\BpmnProjectPeer::PRJ_UID, $projectUid, \Criteria::EQUAL))
|
|
|
|
|
);
|
|
|
|
|
} else {
|
|
|
|
|
$criteria->add(\BpmnProjectPeer::PRJ_UID, $arrayProjectUid, \Criteria::NOT_IN);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$rsCriteria = \BpmnProjectPeer::doSelectRS($criteria);
|
|
|
|
|
$rsCriteria->setFetchmode(\ResultSet::FETCHMODE_ASSOC);
|
|
|
|
|
|
|
|
|
|
while ($rsCriteria->next()) {
|
|
|
|
|
$row = $rsCriteria->getRow();
|
|
|
|
|
|
|
|
|
|
foreach ($arrayPath as $key => $value) {
|
|
|
|
|
$path = $key;
|
|
|
|
|
$dir = $value . $row["PRJ_UID"];
|
|
|
|
|
|
|
|
|
|
if (is_dir($dir)) {
|
|
|
|
|
if ($dirh = opendir($dir)) {
|
|
|
|
|
while (($file = readdir($dirh)) !== false) {
|
|
|
|
|
if ($file != "" && $file != "." && $file != "..") {
|
|
|
|
|
$f = $dir . PATH_SEP . $file;
|
|
|
|
|
|
|
|
|
|
if (is_file($f)) {
|
|
|
|
|
$arrayProcessFilesData = $this->getFileManagerUid($f);
|
|
|
|
|
|
|
|
|
|
if (is_null($arrayProcessFilesData["PRF_UID"])) {
|
|
|
|
|
rename($dir . PATH_SEP . $file, $dir . PATH_SEP . $file . ".tmp");
|
|
|
|
|
|
|
|
|
|
$arrayData = array(
|
|
|
|
|
"prf_path" => $path,
|
|
|
|
|
"prf_filename" => $file,
|
|
|
|
|
"prf_content" => ""
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
$arrayData = $this->addProcessFilesManager($row["PRJ_UID"], "00000000000000000000000000000001", $arrayData);
|
|
|
|
|
|
|
|
|
|
rename($dir . PATH_SEP . $file . ".tmp", $dir . PATH_SEP . $file);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
closedir($dirh);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$arrayProjectUid[$row["PRJ_UID"]] = $row["PRJ_UID"];
|
|
|
|
|
$flagProjectUid = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//Update PROCESS_FILES_CHECKED
|
|
|
|
|
if ($flagProjectUid) {
|
|
|
|
|
$result = $conf->update(array(
|
|
|
|
|
"CFG_UID" => "PROCESS_FILES_CHECKED",
|
|
|
|
|
"OBJ_UID" => "",
|
|
|
|
|
"CFG_VALUE" => serialize($arrayProjectUid),
|
|
|
|
|
"PRO_UID" => "",
|
|
|
|
|
"USR_UID" => "",
|
|
|
|
|
"APP_UID" => ""
|
|
|
|
|
));
|
|
|
|
|
}
|
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
|
throw $e;
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-01-28 16:31:20 -04:00
|
|
|
}
|
2015-07-21 15:34:59 -04:00
|
|
|
|