2014-01-22 17:18:33 -04:00
< ? php
2014-04-02 16:51:28 -04:00
namespace ProcessMaker\BusinessModel ;
2014-01-22 17:18:33 -04:00
class WebEntry
{
2014-02-07 14:52:35 -04:00
private $arrayFieldDefinition = array (
2014-04-22 13:11:32 -04:00
" WE_UID " => array ( " type " => " string " , " required " => false , " empty " => false , " defaultValues " => array (), " fieldNameAux " => " webEntryUid " ),
" TAS_UID " => array ( " type " => " string " , " required " => true , " empty " => false , " defaultValues " => array (), " fieldNameAux " => " taskUid " ),
" DYN_UID " => array ( " type " => " string " , " required " => true , " empty " => false , " defaultValues " => array (), " fieldNameAux " => " dynaFormUid " ),
" USR_UID " => array ( " type " => " string " , " required " => false , " empty " => false , " defaultValues " => array (), " fieldNameAux " => " userUid " ),
" WE_TITLE " => array ( " type " => " string " , " required " => true , " empty " => false , " defaultValues " => array (), " fieldNameAux " => " webEntryTitle " ),
" WE_DESCRIPTION " => array ( " type " => " string " , " required " => false , " empty " => true , " defaultValues " => array (), " fieldNameAux " => " webEntryDescription " ),
" WE_METHOD " => array ( " type " => " string " , " required " => true , " empty " => false , " defaultValues " => array ( " WS " , " HTML " ), " fieldNameAux " => " webEntryMethod " ),
" WE_INPUT_DOCUMENT_ACCESS " => array ( " type " => " int " , " required " => true , " empty " => false , " defaultValues " => array ( 0 , 1 ), " fieldNameAux " => " webEntryInputDocumentAccess " )
2014-02-14 11:53:49 -04:00
);
private $arrayUserFieldDefinition = array (
2014-04-22 13:11:32 -04:00
" USR_UID " => array ( " type " => " string " , " required " => true , " empty " => false , " defaultValues " => array (), " fieldNameAux " => " userUid " )
2014-02-07 14:52:35 -04:00
);
private $formatFieldNameInUppercase = true ;
private $arrayFieldNameForException = array (
2014-04-22 13:11:32 -04:00
" processUid " => " PRO_UID " ,
" userUid " => " USR_UID "
2014-02-07 14:52:35 -04:00
);
/**
* Constructor of the class
*
* return void
*/
public function __construct ()
{
try {
foreach ( $this -> arrayFieldDefinition as $key => $value ) {
$this -> arrayFieldNameForException [ $value [ " fieldNameAux " ]] = $key ;
}
} catch ( \Exception $e ) {
throw $e ;
}
}
/**
* Set the format of the fields name ( uppercase , lowercase )
*
* @ param bool $flag Value that set the format
*
* return void
*/
public function setFormatFieldNameInUppercase ( $flag )
{
try {
$this -> formatFieldNameInUppercase = $flag ;
$this -> setArrayFieldNameForException ( $this -> arrayFieldNameForException );
} catch ( \Exception $e ) {
throw $e ;
}
}
/**
* Set exception messages for fields
*
* @ param array $arrayData Data with the fields
*
* return void
*/
public function setArrayFieldNameForException ( $arrayData )
{
try {
foreach ( $arrayData as $key => $value ) {
$this -> arrayFieldNameForException [ $key ] = $this -> getFieldNameByFormatFieldName ( $value );
}
} catch ( \Exception $e ) {
throw $e ;
}
}
/**
* Get the name of the field according to the format
*
* @ param string $fieldName Field name
*
* return string Return the field name according the format
*/
public function getFieldNameByFormatFieldName ( $fieldName )
{
try {
return ( $this -> formatFieldNameInUppercase ) ? strtoupper ( $fieldName ) : strtolower ( $fieldName );
} catch ( \Exception $e ) {
throw $e ;
}
}
2014-01-24 16:06:50 -04:00
/**
* Sanitizes a filename
*
* @ param string $name Filename
*
* return string Return the filename sanitizes
*/
public function sanitizeFilename ( $name )
{
$name = trim ( $name );
2014-05-06 09:57:34 -04:00
$arraySpecialCharSearch = array ( " / " , " \\ " , " " );
$arraySpecialCharReplace = array ( " _ " , " _ " , " _ " );
2014-01-24 16:06:50 -04:00
$newName = str_replace ( $arraySpecialCharSearch , $arraySpecialCharReplace , $name );
2014-05-06 09:57:34 -04:00
$arraySpecialCharSearch = array ( " /[ \ !- \ ) \ :- \ @]/ " , " /[ \ { \ } \ [ \ ] \ ¿ \ ? \ +]/ " );
$arraySpecialCharReplace = array ( " " , " " );
$newName = preg_replace ( $arraySpecialCharSearch , $arraySpecialCharReplace , $newName );
2014-01-24 16:06:50 -04:00
return $newName ;
}
2014-01-22 17:18:33 -04:00
/**
2014-04-22 13:11:32 -04:00
* Verify if exists the title of a Web Entry
2014-01-22 17:18:33 -04:00
*
2014-04-22 13:11:32 -04:00
* @ param string $processUid Unique id of Process
* @ param string $webEntryTitle Title
* @ param string $webEntryUidExclude Unique id of Web Entry to exclude
2014-01-22 17:18:33 -04:00
*
2014-04-22 13:11:32 -04:00
* return bool Return true if exists the title of a Web Entry , false otherwise
2014-01-22 17:18:33 -04:00
*/
2014-04-22 13:11:32 -04:00
public function existsTitle ( $processUid , $webEntryTitle , $webEntryUidExclude = " " )
2014-01-22 17:18:33 -04:00
{
try {
2014-04-22 13:11:32 -04:00
$delimiter = \DBAdapter :: getStringDelimiter ();
2014-01-22 17:18:33 -04:00
2014-04-22 13:11:32 -04:00
$criteria = new \Criteria ( " workflow " );
2014-02-07 14:52:35 -04:00
2014-04-22 13:11:32 -04:00
$criteria -> addSelectColumn ( \WebEntryPeer :: WE_UID );
2014-02-07 14:52:35 -04:00
2014-04-22 13:11:32 -04:00
$criteria -> addAlias ( " CT " , \ContentPeer :: TABLE_NAME );
2014-02-07 14:52:35 -04:00
2014-04-22 13:11:32 -04:00
$arrayCondition = array ();
$arrayCondition [] = array ( \WebEntryPeer :: WE_UID , " CT.CON_ID " , \Criteria :: EQUAL );
$arrayCondition [] = array ( " CT.CON_CATEGORY " , $delimiter . " WE_TITLE " . $delimiter , \Criteria :: EQUAL );
$arrayCondition [] = array ( " CT.CON_LANG " , $delimiter . SYS_LANG . $delimiter , \Criteria :: EQUAL );
$criteria -> addJoinMC ( $arrayCondition , \Criteria :: LEFT_JOIN );
$criteria -> add ( \WebEntryPeer :: PRO_UID , $processUid , \Criteria :: EQUAL );
2014-02-12 12:32:04 -04:00
2014-04-22 13:11:32 -04:00
if ( $webEntryUidExclude != " " ) {
$criteria -> add ( \WebEntryPeer :: WE_UID , $webEntryUidExclude , \Criteria :: NOT_EQUAL );
2014-02-07 14:52:35 -04:00
}
2014-04-22 13:11:32 -04:00
$criteria -> add ( " CT.CON_VALUE " , $webEntryTitle , \Criteria :: EQUAL );
2014-01-22 17:18:33 -04:00
2014-04-22 13:11:32 -04:00
$rsCriteria = \WebEntryPeer :: doSelectRS ( $criteria );
2014-01-22 17:18:33 -04:00
2014-04-22 13:11:32 -04:00
if ( $rsCriteria -> next ()) {
return true ;
} else {
return false ;
}
} catch ( \Exception $e ) {
throw $e ;
}
}
2014-01-22 17:18:33 -04:00
2014-04-22 13:11:32 -04:00
/**
* Verify if does not exist the Web Entry in table WEB_ENTRY
*
* @ param string $webEntryUid Unique id of Web Entry
* @ param string $fieldNameForException Field name for the exception
*
* return void Throw exception if does not exist the Web Entry in table WEB_ENTRY
*/
public function throwExceptionIfNotExistsWebEntry ( $webEntryUid , $fieldNameForException )
{
try {
$webEntry = \WebEntryPeer :: retrieveByPK ( $webEntryUid );
2014-01-22 17:18:33 -04:00
2014-04-22 13:11:32 -04:00
if ( is_null ( $webEntry )) {
$msg = str_replace ( array ( " { 0} " , " { 1} " ), array ( $fieldNameForException , $webEntryUid ), " The web entry with { 0}: { 1} does not exist. " );
2014-01-22 17:18:33 -04:00
2014-04-22 13:11:32 -04:00
throw ( new \Exception ( $msg ));
2014-01-22 17:18:33 -04:00
}
} catch ( \Exception $e ) {
throw $e ;
}
}
/**
2014-04-22 13:11:32 -04:00
* Verify if exists the title of a Web Entry
2014-01-22 17:18:33 -04:00
*
2014-04-22 13:11:32 -04:00
* @ param string $processUid Unique id of Process
* @ param string $webEntryTitle Title
* @ param string $fieldNameForException Field name for the exception
* @ param string $webEntryUidExclude Unique id of Web Entry to exclude
2014-01-22 17:18:33 -04:00
*
2014-04-22 13:11:32 -04:00
* return void Throw exception if exists the title of a Web Entry
2014-01-22 17:18:33 -04:00
*/
2014-04-22 13:11:32 -04:00
public function throwExceptionIfExistsTitle ( $processUid , $webEntryTitle , $fieldNameForException , $webEntryUidExclude = " " )
2014-01-22 17:18:33 -04:00
{
try {
2014-04-22 13:11:32 -04:00
if ( $this -> existsTitle ( $processUid , $webEntryTitle , $webEntryUidExclude )) {
$msg = str_replace ( array ( " { 0} " , " { 1} " ), array ( $fieldNameForException , $webEntryTitle ), " The web entry title with { 0}: \" { 1} \" already exists " );
2014-01-24 16:06:50 -04:00
2014-04-22 13:11:32 -04:00
throw ( new \Exception ( $msg ));
}
} catch ( \Exception $e ) {
throw $e ;
}
}
2014-01-24 16:06:50 -04:00
2014-04-22 13:11:32 -04:00
/**
* Validate the data if they are invalid ( INSERT and UPDATE )
*
* @ param string $webEntryUid Unique id of Web Entry
* @ param string $processUid Unique id of Process
* @ param array $arrayData Data
*
* return void Throw exception if data has an invalid value
*/
public function throwExceptionIfDataIsInvalid ( $webEntryUid , $processUid , $arrayData )
{
try {
//Set variables
$arrayWebEntryData = ( $webEntryUid == " " ) ? array () : $this -> getWebEntry ( $webEntryUid , true );
$flagInsert = ( $webEntryUid == " " ) ? true : false ;
2014-01-24 16:06:50 -04:00
2014-04-22 13:11:32 -04:00
$arrayDataMain = array_merge ( $arrayWebEntryData , $arrayData );
2014-01-24 16:06:50 -04:00
2014-04-22 13:11:32 -04:00
//Verify data - Field definition
$process = new \ProcessMaker\BusinessModel\Process ();
2014-01-24 16:06:50 -04:00
2014-04-22 13:11:32 -04:00
$process -> throwExceptionIfDataNotMetFieldDefinition ( $arrayData , $this -> arrayFieldDefinition , $this -> arrayFieldNameForException , $flagInsert );
2014-01-24 16:06:50 -04:00
2014-04-22 13:11:32 -04:00
if ( $arrayDataMain [ " WE_METHOD " ] == " WS " ) {
$process -> throwExceptionIfDataNotMetFieldDefinition ( $arrayData , $this -> arrayUserFieldDefinition , $this -> arrayFieldNameForException , $flagInsert );
}
2014-01-24 16:06:50 -04:00
2014-04-22 13:11:32 -04:00
//Verify data
if ( isset ( $arrayData [ " WE_TITLE " ])) {
$this -> throwExceptionIfExistsTitle ( $processUid , $arrayData [ " WE_TITLE " ], $this -> arrayFieldNameForException [ " webEntryTitle " ], $webEntryUid );
2014-01-24 16:06:50 -04:00
}
2014-04-22 13:11:32 -04:00
if ( isset ( $arrayData [ " TAS_UID " ])) {
$process -> throwExceptionIfNotExistsTask ( $processUid , $arrayData [ " TAS_UID " ], $this -> arrayFieldNameForException [ " taskUid " ]);
}
2014-02-12 12:32:04 -04:00
2014-04-22 13:11:32 -04:00
if ( isset ( $arrayData [ " DYN_UID " ])) {
$dynaForm = new \ProcessMaker\BusinessModel\DynaForm ();
2014-02-12 12:32:04 -04:00
2014-04-22 13:11:32 -04:00
$dynaForm -> throwExceptionIfNotExistsDynaForm ( $arrayData [ " DYN_UID " ], $processUid , $this -> arrayFieldNameForException [ " dynaFormUid " ]);
}
2014-01-24 16:06:50 -04:00
2014-04-22 13:11:32 -04:00
if ( $arrayDataMain [ " WE_METHOD " ] == " WS " && isset ( $arrayData [ " USR_UID " ])) {
$process -> throwExceptionIfNotExistsUser ( $arrayData [ " USR_UID " ], $this -> arrayFieldNameForException [ " userUid " ]);
}
2014-01-24 16:06:50 -04:00
2014-04-22 13:11:32 -04:00
$task = new \Task ();
2014-01-24 16:06:50 -04:00
2014-04-22 13:11:32 -04:00
$arrayTaskData = $task -> load ( $arrayDataMain [ " TAS_UID " ]);
2014-02-27 11:55:49 -04:00
2014-04-22 13:11:32 -04:00
if ( isset ( $arrayData [ " TAS_UID " ])) {
if ( $arrayTaskData [ " TAS_START " ] == " FALSE " ) {
throw ( new \Exception ( str_replace ( array ( " { 0} " ), array ( $arrayTaskData [ " TAS_TITLE " ]), " The task \" { 0} \" is not initial task " )));
}
2014-01-24 16:06:50 -04:00
2014-04-22 13:11:32 -04:00
if ( $arrayTaskData [ " TAS_ASSIGN_TYPE " ] != " BALANCED " ) {
throw ( new \Exception ( str_replace ( array ( " { 0} " ), array ( $arrayTaskData [ " TAS_TITLE " ]), " Web Entry only works with tasks which have \" Cyclical Assignment \" , the task \" { 0} \" does not have a valid assignment type. Please change the Assignment Rules " )));
}
2014-01-24 16:06:50 -04:00
}
2014-04-22 13:11:32 -04:00
if ( $arrayDataMain [ " WE_METHOD " ] == " WS " && isset ( $arrayData [ " TAS_UID " ])) {
2014-02-07 14:52:35 -04:00
$task = new \Tasks ();
2014-01-24 16:06:50 -04:00
2014-02-07 14:52:35 -04:00
if ( $task -> assignUsertoTask ( $arrayData [ " TAS_UID " ]) == 0 ) {
2014-03-05 11:17:44 -04:00
throw ( new \Exception ( str_replace ( array ( " { 0} " ), array ( $arrayTaskData [ " TAS_TITLE " ]), " The task \" { 0} \" does not have users " )));
2014-02-07 14:52:35 -04:00
}
2014-01-24 16:06:50 -04:00
}
2014-04-22 13:11:32 -04:00
if ( isset ( $arrayData [ " DYN_UID " ])) {
$dynaForm = new \Dynaform ();
2014-01-24 16:06:50 -04:00
2014-04-22 13:11:32 -04:00
$arrayDynaFormData = $dynaForm -> Load ( $arrayData [ " DYN_UID " ]);
2014-01-24 16:06:50 -04:00
2014-04-22 13:11:32 -04:00
$step = new \ProcessMaker\BusinessModel\Step ();
2014-01-24 16:06:50 -04:00
2014-04-22 13:11:32 -04:00
if ( ! $step -> existsRecord ( $arrayDataMain [ " TAS_UID " ], " DYNAFORM " , $arrayData [ " DYN_UID " ])) {
throw ( new \Exception ( str_replace ( array ( " { 0} " , " { 1} " ), array ( $arrayDynaFormData [ " DYN_TITLE " ], $arrayTaskData [ " TAS_TITLE " ]), " The DynaForm \" { 0} \" isn't assigned to the task \" { 1} \" " )));
}
2014-01-24 16:06:50 -04:00
}
2014-04-22 13:11:32 -04:00
if ( $arrayDataMain [ " WE_METHOD " ] == " WS " && isset ( $arrayData [ " USR_UID " ])) {
$user = new \Users ();
2014-01-24 16:06:50 -04:00
2014-04-22 13:11:32 -04:00
$arrayUserData = $user -> load ( $arrayData [ " USR_UID " ]);
2014-01-24 16:06:50 -04:00
//Verify if User is assigned to Task
2014-04-22 13:11:32 -04:00
$projectUser = new \ProcessMaker\BusinessModel\ProjectUser ();
2014-01-24 16:06:50 -04:00
2014-04-22 13:11:32 -04:00
if ( ! $projectUser -> userIsAssignedToTask ( $arrayData [ " USR_UID " ], $arrayDataMain [ " TAS_UID " ])) {
throw ( new \Exception ( str_replace ( array ( " { 0} " , " { 1} " ), array ( $arrayUserData [ " USR_USERNAME " ], $arrayTaskData [ " TAS_TITLE " ]), " The user \" { 0} \" does not have the task \" { 1} \" assigned " )));
}
}
} catch ( \Exception $e ) {
throw $e ;
}
}
2014-01-24 16:06:50 -04:00
2014-04-22 13:11:32 -04:00
/**
* Set value in WE_DATA
*
* @ param string $webEntryUid Unique id of Web Entry
*
* return void
*/
public function setWeData ( $webEntryUid )
{
try {
//Verify data
$this -> throwExceptionIfNotExistsWebEntry ( $webEntryUid , $this -> arrayFieldNameForException [ " webEntryUid " ]);
2014-01-24 16:06:50 -04:00
2014-04-22 13:11:32 -04:00
//Set variables
$arrayWebEntryData = $this -> getWebEntry ( $webEntryUid , true );
2014-01-24 16:06:50 -04:00
2014-04-22 13:11:32 -04:00
$processUid = $arrayWebEntryData [ " PRO_UID " ];
$taskUid = $arrayWebEntryData [ " TAS_UID " ];
$dynaFormUid = $arrayWebEntryData [ " DYN_UID " ];
$webEntryMethod = $arrayWebEntryData [ " WE_METHOD " ];
$webEntryInputDocumentAccess = $arrayWebEntryData [ " WE_INPUT_DOCUMENT_ACCESS " ];
$webEntryData = " " ;
$wsRoundRobin = 0 ; //0, 1 //0 - Cyclical Assignment
$pathDataPublicProcess = PATH_DATA_PUBLIC . $processUid ;
2014-01-24 16:06:50 -04:00
2014-04-22 13:11:32 -04:00
//Delete previous files
if ( trim ( $arrayWebEntryData [ " WE_DATA " ]) != " " ) {
$fileName = str_replace ( " .php " , " " , trim ( $arrayWebEntryData [ " WE_DATA " ]));
$file = $pathDataPublicProcess . PATH_SEP . $fileName . " .php " ;
if ( is_file ( $file ) && file_exists ( $file )) {
unlink ( $file );
unlink ( $pathDataPublicProcess . PATH_SEP . $fileName . " Post.php " );
2014-01-24 16:06:50 -04:00
}
}
2014-04-22 13:11:32 -04:00
//Create files
\G :: mk_dir ( $pathDataPublicProcess , 0777 );
2014-01-24 16:06:50 -04:00
2014-04-22 13:11:32 -04:00
$http = ( \G :: is_https ()) ? " https:// " : " http:// " ;
2014-01-24 16:06:50 -04:00
2014-04-22 13:11:32 -04:00
switch ( $webEntryMethod ) {
case " WS " :
2014-05-07 17:09:09 -04:00
require_once ( PATH_RBAC . " model " . PATH_SEP . " RbacUsers.php " );
$user = new \RbacUsers ();
2014-01-24 16:06:50 -04:00
2014-04-22 13:11:32 -04:00
$arrayUserData = $user -> load ( $arrayWebEntryData [ " USR_UID " ]);
2014-01-24 16:06:50 -04:00
2014-04-22 13:11:32 -04:00
$usrUsername = $arrayUserData [ " USR_USERNAME " ];
$usrPassword = $arrayUserData [ " USR_PASSWORD " ];
2014-01-24 16:06:50 -04:00
2014-04-22 13:11:32 -04:00
$dynaForm = new \Dynaform ();
$arrayDynaFormData = $dynaForm -> Load ( $arrayWebEntryData [ " DYN_UID " ]);
2014-01-24 16:06:50 -04:00
//Creating sys.info;
2014-04-22 13:11:32 -04:00
$sitePublicPath = " " ;
2014-01-24 16:06:50 -04:00
2014-04-22 13:11:32 -04:00
if ( file_exists ( $sitePublicPath . " " )) {
2014-01-24 16:06:50 -04:00
}
//Creating the first file
2014-04-22 13:11:32 -04:00
$weTitle = $this -> sanitizeFilename ( $arrayWebEntryData [ " WE_TITLE " ]);
$fileName = $weTitle ;
2014-01-24 16:06:50 -04:00
$fileContent = " <?php \n " ;
$fileContent .= " global \$ _DBArray; \n " ;
$fileContent .= " if (!isset( \$ _DBArray)) { \n " ;
$fileContent .= " \$ _DBArray = array(); \n " ;
$fileContent .= " } \n " ;
2014-04-22 13:11:32 -04:00
$fileContent .= " \$ _SESSION[ \" PROCESS \" ] = \" " . $processUid . " \" ; \n " ;
$fileContent .= " \$ _SESSION[ \" CURRENT_DYN_UID \" ] = \" " . $dynaFormUid . " \" ; \n " ;
$fileContent .= " \$ G_PUBLISH = new Publisher(); \n " ;
$fileContent .= " \$ G_PUBLISH->AddContent( \" dynaform \" , \" xmlform \" , \" " . $processUid . " / " . $dynaFormUid . " \" , \" \" , array(), \" " . $fileName . " Post.php \" ); \n " ;
$fileContent .= " G::RenderPage( \" publish \" , \" blank \" ); " ;
2014-01-24 16:06:50 -04:00
2014-04-22 13:11:32 -04:00
file_put_contents ( $pathDataPublicProcess . PATH_SEP . $fileName . " .php " , $fileContent );
2014-01-24 16:06:50 -04:00
//Creating the second file, the post file who receive the post form.
2014-04-22 13:11:32 -04:00
$pluginTpl = PATH_TPL . " processes " . PATH_SEP . " webentryPost.tpl " ;
2014-01-24 16:06:50 -04:00
$template = new \TemplatePower ( $pluginTpl );
$template -> prepare ();
$template -> assign ( " wsdlUrl " , $http . $_SERVER [ " HTTP_HOST " ] . " /sys " . SYS_SYS . " / " . SYS_LANG . " / " . SYS_SKIN . " /services/wsdl2 " );
$template -> assign ( " wsUploadUrl " , $http . $_SERVER [ " HTTP_HOST " ] . " /sys " . SYS_SYS . " / " . SYS_LANG . " / " . SYS_SKIN . " /services/upload " );
$template -> assign ( " processUid " , $processUid );
$template -> assign ( " dynaformUid " , $dynaFormUid );
$template -> assign ( " taskUid " , $taskUid );
$template -> assign ( " wsUser " , $usrUsername );
2014-05-07 17:09:09 -04:00
$template -> assign ( " wsPass " , " md5: " . $usrPassword );
2014-01-24 16:06:50 -04:00
$template -> assign ( " wsRoundRobin " , $wsRoundRobin );
2014-04-22 13:11:32 -04:00
if ( $webEntryInputDocumentAccess == 0 ) {
2014-01-24 16:06:50 -04:00
//Restricted to process permissions
$template -> assign ( " USR_VAR " , " \$ cInfo = ws_getCaseInfo( \$ caseId); \n \t \$ USR_UID = \$ cInfo->currentUsers->userId; " );
} else {
//No Restriction
$template -> assign ( " USR_VAR " , " \$ USR_UID = -1; " );
}
2014-04-22 13:11:32 -04:00
$template -> assign ( " dynaform " , $arrayDynaFormData [ " DYN_TITLE " ]);
2014-01-24 16:06:50 -04:00
$template -> assign ( " timestamp " , date ( " l jS \ of F Y h:i:s A " ));
$template -> assign ( " ws " , SYS_SYS );
$template -> assign ( " version " , \System :: getVersion ());
2014-04-22 13:11:32 -04:00
$fileName = $pathDataPublicProcess . PATH_SEP . $weTitle . " Post.php " ;
2014-01-24 16:06:50 -04:00
file_put_contents ( $fileName , $template -> getOutputContent ());
//Creating the third file, only if this wsClient.php file doesn't exist.
2014-04-22 13:11:32 -04:00
$fileName = $pathDataPublicProcess . PATH_SEP . " wsClient.php " ;
$pluginTpl = PATH_TEST . " unit " . PATH_SEP . " ws " . PATH_SEP . " wsClient.php " ;
2014-01-24 16:06:50 -04:00
if ( file_exists ( $fileName )) {
if ( filesize ( $fileName ) != filesize ( $pluginTpl )) {
2014-04-22 13:11:32 -04:00
copy ( $fileName , $pathDataPublicProcess . PATH_SEP . " wsClient.php.bak " );
unlink ( $fileName );
2014-01-24 16:06:50 -04:00
$template = new \TemplatePower ( $pluginTpl );
$template -> prepare ();
file_put_contents ( $fileName , $template -> getOutputContent ());
}
} else {
$template = new \TemplatePower ( $pluginTpl );
$template -> prepare ();
file_put_contents ( $fileName , $template -> getOutputContent ());
}
//Event
2014-04-22 13:11:32 -04:00
$task = new \Task ();
$arrayTaskData = $task -> load ( $arrayWebEntryData [ " TAS_UID " ]);
$weEventUid = $task -> getStartingEvent ();
2014-02-27 12:15:56 -04:00
if ( $weEventUid != " " ) {
2014-02-27 11:55:49 -04:00
$event = new \Event ();
2014-01-24 16:06:50 -04:00
2014-02-27 11:55:49 -04:00
$arrayEventData = array ();
2014-01-24 16:06:50 -04:00
2014-02-27 11:55:49 -04:00
$arrayEventData [ " EVN_UID " ] = $weEventUid ;
$arrayEventData [ " EVN_RELATED_TO " ] = " MULTIPLE " ;
$arrayEventData [ " EVN_ACTION " ] = $dynaFormUid ;
$arrayEventData [ " EVN_CONDITIONS " ] = $usrUsername ;
2014-01-24 16:06:50 -04:00
2014-02-27 11:55:49 -04:00
$result = $event -> update ( $arrayEventData );
}
2014-01-24 16:06:50 -04:00
2014-04-22 13:11:32 -04:00
//WE_DATA
$webEntryData = $weTitle . " .php " ;
2014-01-24 16:06:50 -04:00
break ;
case " HTML " :
global $G_FORM ;
2014-03-20 13:15:12 -04:00
if ( ! class_exists ( " Smarty " )) {
$loader = \Maveriks\Util\ClassLoader :: getInstance ();
2014-04-22 13:11:32 -04:00
$loader -> addClass ( " Smarty " , PATH_THIRDPARTY . " smarty " . PATH_SEP . " libs " . PATH_SEP . " Smarty.class.php " );
2014-03-20 13:15:12 -04:00
}
2014-01-24 16:06:50 -04:00
$G_FORM = new \Form ( $processUid . " / " . $dynaFormUid , PATH_DYNAFORM , SYS_LANG , false );
$G_FORM -> action = $http . $_SERVER [ " HTTP_HOST " ] . " /sys " . SYS_SYS . " / " . SYS_LANG . " / " . SYS_SKIN . " /services/cases_StartExternal.php " ;
$scriptCode = " " ;
2014-04-22 13:11:32 -04:00
$scriptCode = $G_FORM -> render ( PATH_TPL . " xmlform " . " .html " , $scriptCode );
2014-01-24 16:06:50 -04:00
$scriptCode = str_replace ( " /controls/ " , $http . $_SERVER [ " HTTP_HOST " ] . " /controls/ " , $scriptCode );
$scriptCode = str_replace ( " /js/maborak/core/images/ " , $http . $_SERVER [ " HTTP_HOST " ] . " /js/maborak/core/images/ " , $scriptCode );
//Render the template
2014-04-22 13:11:32 -04:00
$pluginTpl = PATH_TPL . " processes " . PATH_SEP . " webentry.tpl " ;
2014-01-24 16:06:50 -04:00
$template = new \TemplatePower ( $pluginTpl );
$template -> prepare ();
$step = new \Step ();
$sUidGrids = $step -> lookingforUidGrids ( $processUid , $dynaFormUid );
$template -> assign ( " URL_MABORAK_JS " , \G :: browserCacheFilesUrl ( " /js/maborak/core/maborak.js " ));
$template -> assign ( " URL_TRANSLATION_ENV_JS " , \G :: browserCacheFilesUrl ( " /jscore/labels/ " . SYS_LANG . " .js " ));
$template -> assign ( " siteUrl " , $http . $_SERVER [ " HTTP_HOST " ]);
$template -> assign ( " sysSys " , SYS_SYS );
$template -> assign ( " sysLang " , SYS_LANG );
$template -> assign ( " sysSkin " , SYS_SKIN );
$template -> assign ( " processUid " , $processUid );
$template -> assign ( " dynaformUid " , $dynaFormUid );
$template -> assign ( " taskUid " , $taskUid );
$template -> assign ( " dynFileName " , $processUid . " / " . $dynaFormUid );
$template -> assign ( " formId " , $G_FORM -> id );
$template -> assign ( " scriptCode " , $scriptCode );
if ( sizeof ( $sUidGrids ) > 0 ) {
foreach ( $sUidGrids as $k => $v ) {
$template -> newBlock ( " grid_uids " );
$template -> assign ( " siteUrl " , $http . $_SERVER [ " HTTP_HOST " ]);
$template -> assign ( " gridFileName " , $processUid . " / " . $v );
}
}
2014-04-22 13:11:32 -04:00
//WE_DATA
2014-01-24 16:06:50 -04:00
$html = str_replace ( " </body> " , " </form></body> " , str_replace ( " </form> " , " " , $template -> getOutputContent ()));
2014-04-22 13:11:32 -04:00
$webEntryData = $html ;
2014-01-24 16:06:50 -04:00
break ;
}
2014-04-22 13:11:32 -04:00
//Update
//Update where
$criteriaWhere = new \Criteria ( " workflow " );
$criteriaWhere -> add ( \WebEntryPeer :: WE_UID , $webEntryUid );
//Update set
$criteriaSet = new \Criteria ( " workflow " );
$criteriaSet -> add ( \WebEntryPeer :: WE_DATA , $webEntryData );
\BasePeer :: doUpdate ( $criteriaWhere , $criteriaSet , \Propel :: getConnection ( " workflow " ));
} catch ( \Exception $e ) {
throw $e ;
}
}
/**
* Create Web Entry for a Process
*
* @ param string $processUid Unique id of Process
* @ param string $userUidCreator Unique id of creator User
* @ param array $arrayData Data
*
* return array Return data of the new Web Entry created
*/
public function create ( $processUid , $userUidCreator , $arrayData )
{
try {
//Verify data
$process = new \ProcessMaker\BusinessModel\Process ();
$validator = new \ProcessMaker\BusinessModel\Validator ();
$validator -> throwExceptionIfDataIsNotArray ( $arrayData , " \$ arrayData " );
$validator -> throwExceptionIfDataIsEmpty ( $arrayData , " \$ arrayData " );
//Set data
$arrayData = array_change_key_case ( $arrayData , CASE_UPPER );
unset ( $arrayData [ " WE_UID " ]);
unset ( $arrayData [ " WE_DATA " ]);
//Verify data
$process -> throwExceptionIfNotExistsProcess ( $processUid , $this -> arrayFieldNameForException [ " processUid " ]);
2014-02-07 14:52:35 -04:00
2014-04-22 13:11:32 -04:00
$this -> throwExceptionIfDataIsInvalid ( " " , $processUid , $arrayData );
//Create
$cnn = \Propel :: getConnection ( " workflow " );
try {
$webEntry = new \WebEntry ();
$webEntry -> fromArray ( $arrayData , \BasePeer :: TYPE_FIELDNAME );
$webEntryUid = \G :: generateUniqueID ();
$webEntry -> setWeUid ( $webEntryUid );
$webEntry -> setProUid ( $processUid );
$webEntry -> setWeCreateUsrUid ( $userUidCreator );
$webEntry -> setWeCreateDate ( " now " );
if ( $webEntry -> validate ()) {
$cnn -> begin ();
$result = $webEntry -> save ();
$cnn -> commit ();
//Set WE_TITLE
if ( isset ( $arrayData [ " WE_TITLE " ])) {
$result = \Content :: addContent ( " WE_TITLE " , " " , $webEntryUid , SYS_LANG , $arrayData [ " WE_TITLE " ]);
}
if ( isset ( $arrayData [ " WE_DESCRIPTION " ])) {
$result = \Content :: addContent ( " WE_DESCRIPTION " , " " , $webEntryUid , SYS_LANG , $arrayData [ " WE_DESCRIPTION " ]);
}
//Set WE_DATA
$this -> setWeData ( $webEntryUid );
//Return
return $this -> getWebEntry ( $webEntryUid );
} else {
$msg = " " ;
foreach ( $webEntry -> getValidationFailures () as $validationFailure ) {
$msg = $msg . (( $msg != " " ) ? " \n " : " " ) . $validationFailure -> getMessage ();
}
throw ( new \Exception ( " The registry cannot be created!. \n " . $msg ));
}
} catch ( \Exception $e ) {
$cnn -> rollback ();
throw $e ;
2014-02-07 14:52:35 -04:00
}
2014-04-22 13:11:32 -04:00
} catch ( \Exception $e ) {
throw $e ;
}
}
/**
* Update Web Entry
*
* @ param string $webEntryUid Unique id of Web Entry
* @ param string $userUidUpdater Unique id of updater User
* @ param array $arrayData Data
*
* return array Return data of the Web Entry updated
*/
public function update ( $webEntryUid , $userUidUpdater , $arrayData )
{
try {
//Verify data
$process = new \ProcessMaker\BusinessModel\Process ();
$validator = new \ProcessMaker\BusinessModel\Validator ();
$validator -> throwExceptionIfDataIsNotArray ( $arrayData , " \$ arrayData " );
$validator -> throwExceptionIfDataIsEmpty ( $arrayData , " \$ arrayData " );
//Set data
$arrayData = array_change_key_case ( $arrayData , CASE_UPPER );
//Set variables
$arrayWebEntryData = $this -> getWebEntry ( $webEntryUid , true );
//Verify data
$this -> throwExceptionIfNotExistsWebEntry ( $webEntryUid , $this -> arrayFieldNameForException [ " webEntryUid " ]);
$this -> throwExceptionIfDataIsInvalid ( $webEntryUid , $arrayWebEntryData [ " PRO_UID " ], $arrayData );
//Update
$cnn = \Propel :: getConnection ( " workflow " );
try {
$webEntry = \WebEntryPeer :: retrieveByPK ( $webEntryUid );
$webEntry -> fromArray ( $arrayData , \BasePeer :: TYPE_FIELDNAME );
$webEntry -> setWeUpdateUsrUid ( $userUidUpdater );
$webEntry -> setWeUpdateDate ( " now " );
if ( $webEntry -> validate ()) {
$cnn -> begin ();
$result = $webEntry -> save ();
$cnn -> commit ();
2014-01-24 16:06:50 -04:00
2014-04-22 13:11:32 -04:00
//Set WE_TITLE
if ( isset ( $arrayData [ " WE_TITLE " ])) {
$result = \Content :: addContent ( " WE_TITLE " , " " , $webEntryUid , SYS_LANG , $arrayData [ " WE_TITLE " ]);
}
if ( isset ( $arrayData [ " WE_DESCRIPTION " ])) {
$result = \Content :: addContent ( " WE_DESCRIPTION " , " " , $webEntryUid , SYS_LANG , $arrayData [ " WE_DESCRIPTION " ]);
}
//Set WE_DATA
$this -> setWeData ( $webEntryUid );
//Return
if ( ! $this -> formatFieldNameInUppercase ) {
$arrayData = array_change_key_case ( $arrayData , CASE_LOWER );
}
return $arrayData ;
} else {
$msg = " " ;
foreach ( $webEntry -> getValidationFailures () as $validationFailure ) {
$msg = $msg . (( $msg != " " ) ? " \n " : " " ) . $validationFailure -> getMessage ();
}
throw ( new \Exception ( " The registry cannot be created!. \n " . $msg ));
}
} catch ( \Exception $e ) {
$cnn -> rollback ();
throw $e ;
}
2014-01-22 17:18:33 -04:00
} catch ( \Exception $e ) {
throw $e ;
}
}
/**
* Delete Web Entry
*
2014-04-22 13:11:32 -04:00
* @ param string $webEntryUid Unique id of Web Entry
2014-01-22 17:18:33 -04:00
*
* return void
*/
2014-04-22 13:11:32 -04:00
public function delete ( $webEntryUid )
2014-01-22 17:18:33 -04:00
{
try {
//Verify data
2014-04-22 13:11:32 -04:00
$this -> throwExceptionIfNotExistsWebEntry ( $webEntryUid , $this -> arrayFieldNameForException [ " webEntryUid " ]);
2014-01-22 17:18:33 -04:00
2014-04-22 13:11:32 -04:00
//Set variables
$arrayWebEntryData = $this -> getWebEntry ( $webEntryUid , true );
//Delete content
\Content :: removeContent ( " WE_TITLE " , " " , $webEntryUid );
\Content :: removeContent ( " WE_DESCRIPTION " , " " , $webEntryUid );
//Delete web entry
$criteria = new \Criteria ( " workflow " );
$criteria -> add ( \WebEntryPeer :: WE_UID , $webEntryUid );
2014-01-22 17:18:33 -04:00
2014-04-22 13:11:32 -04:00
$result = \WebEntryPeer :: doDelete ( $criteria );
2014-01-22 17:18:33 -04:00
2014-04-22 13:11:32 -04:00
//Delete files
if ( $arrayWebEntryData [ " WE_METHOD " ] == " WS " ) {
$pathDataPublicProcess = PATH_DATA_PUBLIC . $arrayWebEntryData [ " PRO_UID " ];
$fileName = str_replace ( " .php " , " " , trim ( $arrayWebEntryData [ " WE_DATA " ]));
$file = $pathDataPublicProcess . PATH_SEP . $fileName . " .php " ;
if ( is_file ( $file ) && file_exists ( $file )) {
unlink ( $file );
unlink ( $pathDataPublicProcess . PATH_SEP . $fileName . " Post.php " );
}
}
} catch ( \Exception $e ) {
throw $e ;
}
}
/**
* Get criteria for Web Entry
*
* return object
*/
public function getWebEntryCriteria ()
{
try {
$delimiter = \DBAdapter :: getStringDelimiter ();
$criteria = new \Criteria ( " workflow " );
$criteria -> addSelectColumn ( \WebEntryPeer :: WE_UID );
$criteria -> addSelectColumn ( \WebEntryPeer :: PRO_UID );
$criteria -> addSelectColumn ( \WebEntryPeer :: TAS_UID );
$criteria -> addSelectColumn ( \WebEntryPeer :: DYN_UID );
$criteria -> addSelectColumn ( \WebEntryPeer :: USR_UID );
$criteria -> addAsColumn ( " WE_TITLE " , " CT.CON_VALUE " );
$criteria -> addAsColumn ( " WE_DESCRIPTION " , " CD.CON_VALUE " );
$criteria -> addSelectColumn ( \WebEntryPeer :: WE_METHOD );
$criteria -> addSelectColumn ( \WebEntryPeer :: WE_INPUT_DOCUMENT_ACCESS );
$criteria -> addSelectColumn ( \WebEntryPeer :: WE_DATA );
$criteria -> addSelectColumn ( \WebEntryPeer :: WE_CREATE_USR_UID );
$criteria -> addSelectColumn ( \WebEntryPeer :: WE_UPDATE_USR_UID );
$criteria -> addSelectColumn ( \WebEntryPeer :: WE_CREATE_DATE );
$criteria -> addSelectColumn ( \WebEntryPeer :: WE_UPDATE_DATE );
$criteria -> addAlias ( " CT " , \ContentPeer :: TABLE_NAME );
$criteria -> addAlias ( " CD " , \ContentPeer :: TABLE_NAME );
$arrayCondition = array ();
$arrayCondition [] = array ( \WebEntryPeer :: WE_UID , " CT.CON_ID " , \Criteria :: EQUAL );
$arrayCondition [] = array ( " CT.CON_CATEGORY " , $delimiter . " WE_TITLE " . $delimiter , \Criteria :: EQUAL );
$arrayCondition [] = array ( " CT.CON_LANG " , $delimiter . SYS_LANG . $delimiter , \Criteria :: EQUAL );
$criteria -> addJoinMC ( $arrayCondition , \Criteria :: LEFT_JOIN );
$arrayCondition = array ();
$arrayCondition [] = array ( \WebEntryPeer :: WE_UID , " CD.CON_ID " , \Criteria :: EQUAL );
$arrayCondition [] = array ( " CD.CON_CATEGORY " , $delimiter . " WE_DESCRIPTION " . $delimiter , \Criteria :: EQUAL );
$arrayCondition [] = array ( " CD.CON_LANG " , $delimiter . SYS_LANG . $delimiter , \Criteria :: EQUAL );
$criteria -> addJoinMC ( $arrayCondition , \Criteria :: LEFT_JOIN );
return $criteria ;
2014-01-22 17:18:33 -04:00
} catch ( \Exception $e ) {
throw $e ;
}
}
/**
* Get data of a Web Entry from a record
*
* @ param array $record Record
*
2014-04-22 13:11:32 -04:00
* return array Return an array with data Web Entry
2014-01-22 17:18:33 -04:00
*/
public function getWebEntryDataFromRecord ( $record )
{
try {
2014-04-22 13:11:32 -04:00
if ( $record [ " WE_METHOD " ] == " WS " ) {
$http = ( \G :: is_https ()) ? " https:// " : " http:// " ;
$url = $http . $_SERVER [ " HTTP_HOST " ] . " /sys " . SYS_SYS . " / " . SYS_LANG . " / " . SYS_SKIN . " / " . $record [ " PRO_UID " ];
$record [ " WE_DATA " ] = $url . " / " . $record [ " WE_DATA " ];
}
$conf = new \Configurations ();
$confEnvSetting = $conf -> getFormats ();
$dateTime = new \DateTime ( $record [ " WE_CREATE_DATE " ]);
$webEntryCreateDate = $dateTime -> format ( $confEnvSetting [ " dateFormat " ]);
$webEntryUpdateDate = " " ;
if ( ! empty ( $record [ " WE_UPDATE_DATE " ])) {
$dateTime = new \DateTime ( $record [ " WE_UPDATE_DATE " ]);
$webEntryUpdateDate = $dateTime -> format ( $confEnvSetting [ " dateFormat " ]);
}
2014-01-22 17:18:33 -04:00
return array (
2014-04-22 13:11:32 -04:00
$this -> getFieldNameByFormatFieldName ( " WE_UID " ) => $record [ " WE_UID " ],
$this -> getFieldNameByFormatFieldName ( " TAS_UID " ) => $record [ " TAS_UID " ],
$this -> getFieldNameByFormatFieldName ( " DYN_UID " ) => $record [ " DYN_UID " ],
$this -> getFieldNameByFormatFieldName ( " USR_UID " ) => $record [ " USR_UID " ] . " " ,
$this -> getFieldNameByFormatFieldName ( " WE_TITLE " ) => $record [ " WE_TITLE " ] . " " ,
$this -> getFieldNameByFormatFieldName ( " WE_DESCRIPTION " ) => $record [ " WE_DESCRIPTION " ] . " " ,
$this -> getFieldNameByFormatFieldName ( " WE_METHOD " ) => $record [ " WE_METHOD " ],
$this -> getFieldNameByFormatFieldName ( " WE_INPUT_DOCUMENT_ACCESS " ) => ( int )( $record [ " WE_INPUT_DOCUMENT_ACCESS " ]),
$this -> getFieldNameByFormatFieldName ( " WE_DATA " ) => $record [ " WE_DATA " ],
$this -> getFieldNameByFormatFieldName ( " WE_CREATE_USR_UID " ) => $record [ " WE_CREATE_USR_UID " ],
$this -> getFieldNameByFormatFieldName ( " WE_UPDATE_USR_UID " ) => $record [ " WE_UPDATE_USR_UID " ] . " " ,
$this -> getFieldNameByFormatFieldName ( " WE_CREATE_DATE " ) => $webEntryCreateDate ,
$this -> getFieldNameByFormatFieldName ( " WE_UPDATE_DATE " ) => $webEntryUpdateDate . " "
2014-01-22 17:18:33 -04:00
);
} catch ( \Exception $e ) {
throw $e ;
}
}
2014-04-22 13:11:32 -04:00
/**
* Get all Web Entries
*
* @ param string $processUid Unique id of Process
*
* return array Return an array with all Web Entries
*/
public function getWebEntries ( $processUid )
{
try {
$arrayWebEntry = array ();
//Verify data
$process = new \ProcessMaker\BusinessModel\Process ();
$process -> throwExceptionIfNotExistsProcess ( $processUid , $this -> arrayFieldNameForException [ " processUid " ]);
//Get data
$criteria = $this -> getWebEntryCriteria ();
$criteria -> add ( \WebEntryPeer :: PRO_UID , $processUid , \Criteria :: EQUAL );
$criteria -> addAscendingOrderByColumn ( " WE_TITLE " );
$rsCriteria = \WebEntryPeer :: doSelectRS ( $criteria );
$rsCriteria -> setFetchmode ( \ResultSet :: FETCHMODE_ASSOC );
while ( $rsCriteria -> next ()) {
$row = $rsCriteria -> getRow ();
$arrayWebEntry [] = $this -> getWebEntryDataFromRecord ( $row );
}
//Return
return $arrayWebEntry ;
} catch ( \Exception $e ) {
throw $e ;
}
}
2014-01-22 17:18:33 -04:00
/**
* Get data of a Web Entry
*
2014-04-22 13:11:32 -04:00
* @ param string $webEntryUid Unique id of Web Entry
* @ param bool $flagGetRecord Value that set the getting
2014-01-22 17:18:33 -04:00
*
* return array Return an array with data of a Web Entry
*/
2014-04-22 13:11:32 -04:00
public function getWebEntry ( $webEntryUid , $flagGetRecord = false )
2014-01-22 17:18:33 -04:00
{
try {
//Verify data
2014-04-22 13:11:32 -04:00
$this -> throwExceptionIfNotExistsWebEntry ( $webEntryUid , $this -> arrayFieldNameForException [ " webEntryUid " ]);
2014-02-07 14:52:35 -04:00
//Get data
2014-04-22 13:11:32 -04:00
//SQL
$criteria = $this -> getWebEntryCriteria ();
2014-01-22 17:18:33 -04:00
2014-04-22 13:11:32 -04:00
$criteria -> add ( \WebEntryPeer :: WE_UID , $webEntryUid , \Criteria :: EQUAL );
$rsCriteria = \WebEntryPeer :: doSelectRS ( $criteria );
$rsCriteria -> setFetchmode ( \ResultSet :: FETCHMODE_ASSOC );
$rsCriteria -> next ();
$row = $rsCriteria -> getRow ();
2014-01-22 17:18:33 -04:00
//Return
2014-04-22 13:11:32 -04:00
return ( ! $flagGetRecord ) ? $this -> getWebEntryDataFromRecord ( $row ) : $row ;
2014-01-22 17:18:33 -04:00
} catch ( \Exception $e ) {
throw $e ;
}
}
}