HOR-4480
This commit is contained in:
@@ -1,76 +1,34 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* class.pmScript.php
|
||||
*
|
||||
* @package workflow.engine.ProcessMaker
|
||||
*
|
||||
* ProcessMaker Open Source Edition
|
||||
* Copyright (C) 2004 - 2011 Colosa Inc.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* For more information, contact Colosa Inc, 2566 Le Jeune Rd.,
|
||||
* Coral Gables, FL, 33134, USA, or email info@colosa.com.
|
||||
*
|
||||
*/
|
||||
////////////////////////////////////////////////////
|
||||
// Execute and evaluate PMScripts
|
||||
//
|
||||
// Copyright (C) 2007 COLOSA
|
||||
//
|
||||
// License: LGPL, see LICENSE
|
||||
////////////////////////////////////////////////////
|
||||
|
||||
use ProcessMaker\Plugins\PluginRegistry;
|
||||
|
||||
/**
|
||||
* PMScript - PMScript class
|
||||
*
|
||||
* @author Julio Cesar Laura Avenda<64>o <juliocesar@colosa.com>
|
||||
* last modify 2008.08.13 by Erik Amaru Ortiz <erik@colosa.com>
|
||||
* last modify comment was added and adapted the catch errors
|
||||
* @copyright 2007 COLOSA
|
||||
*/
|
||||
function __autoload ($sClassName)
|
||||
function __autoload($sClassName)
|
||||
{
|
||||
if (!empty(config("system.workspace"))) {
|
||||
$sPath = PATH_DB . config("system.workspace") . PATH_SEP . 'classes' . PATH_SEP;
|
||||
if (file_exists( $sPath . $sClassName . '.php' )) {
|
||||
if (file_exists($sPath . $sClassName . '.php')) {
|
||||
require_once $sPath . $sClassName . '.php';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty(config("system.workspace")) && (!defined('PATH_DATA_SITE') || !defined('PATH_WORKSPACE'))) {
|
||||
Bootstrap::setConstantsRelatedWs(config("system.workspace"));
|
||||
}
|
||||
|
||||
//Add External Triggers
|
||||
$dir = G::ExpandPath( "classes" ) . 'triggers';
|
||||
$filesArray = array ();
|
||||
if (file_exists( $dir )) {
|
||||
if ($handle = opendir( $dir )) {
|
||||
while (false !== ($file = readdir( $handle ))) {
|
||||
$dir = G::ExpandPath("classes") . 'triggers';
|
||||
$filesArray = [];
|
||||
if (file_exists($dir)) {
|
||||
if ($handle = opendir($dir)) {
|
||||
while (false !== ($file = readdir($handle))) {
|
||||
if (($file != ".") && ($file != "..")) {
|
||||
$extFile = explode( ".", $file );
|
||||
if ($extFile[sizeof( $extFile ) - 1] == 'php') {
|
||||
$extFile = explode(".", $file);
|
||||
if ($extFile[sizeof($extFile) - 1] == 'php') {
|
||||
include_once ($dir . PATH_SEP . $file);
|
||||
}
|
||||
}
|
||||
}
|
||||
closedir( $handle );
|
||||
closedir($handle);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -85,17 +43,17 @@ class PMScript
|
||||
/**
|
||||
* @var array $dataTrigger
|
||||
*/
|
||||
public $dataTrigger = array();
|
||||
public $dataTrigger = [];
|
||||
|
||||
/**
|
||||
* Original fields
|
||||
*/
|
||||
public $aOriginalFields = array ();
|
||||
public $aOriginalFields = [];
|
||||
|
||||
/**
|
||||
* Fields to use
|
||||
*/
|
||||
public $aFields = array ();
|
||||
public $aFields = [];
|
||||
|
||||
/**
|
||||
* Script
|
||||
@@ -111,9 +69,7 @@ class PMScript
|
||||
* Affected fields
|
||||
*/
|
||||
public $affected_fields = [];
|
||||
|
||||
public $scriptExecutionTime = 0;
|
||||
|
||||
public $sRegexp = '/\@(?:([\@\%\#\?\$\=\&])([a-zA-Z\_]\w*)|([a-zA-Z\_][\w\-\>\:]*)\(((?:[^\\\\\)]*(?:[\\\\][\w\W])?)*)\))((?:\s*\[[\'"]?\w+[\'"]?\])+|\-\>([a-zA-Z\_]\w*))?/';
|
||||
|
||||
/**
|
||||
@@ -121,7 +77,7 @@ class PMScript
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function PMScript ()
|
||||
public function PMScript()
|
||||
{
|
||||
$this->aFields['__ERROR__'] = 'none';
|
||||
}
|
||||
@@ -132,10 +88,10 @@ class PMScript
|
||||
* @param array $aFields
|
||||
* @return void
|
||||
*/
|
||||
public function setFields ($aFields = array())
|
||||
public function setFields($aFields = [])
|
||||
{
|
||||
if (! is_array( $aFields )) {
|
||||
$aFields = array ();
|
||||
if (!is_array($aFields)) {
|
||||
$aFields = [];
|
||||
}
|
||||
$this->aOriginalFields = $this->aFields = $aFields;
|
||||
}
|
||||
@@ -146,7 +102,7 @@ class PMScript
|
||||
* @param string $sScript
|
||||
* @return void
|
||||
*/
|
||||
public function setScript ($sScript = '')
|
||||
public function setScript($sScript = '')
|
||||
{
|
||||
if (!defined("T_ML_COMMENT")) {
|
||||
define("T_ML_COMMENT", T_COMMENT);
|
||||
@@ -192,7 +148,7 @@ class PMScript
|
||||
* @param string $sScript
|
||||
* @return boolean
|
||||
*/
|
||||
public function validSyntax ($sScript)
|
||||
public function validSyntax($sScript)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
@@ -202,7 +158,7 @@ class PMScript
|
||||
*/
|
||||
public function setDataTrigger($dataTrigger)
|
||||
{
|
||||
$this->dataTrigger = is_array($dataTrigger) ? $dataTrigger : array();
|
||||
$this->dataTrigger = is_array($dataTrigger) ? $dataTrigger : [];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -218,7 +174,7 @@ class PMScript
|
||||
$_SESSION['_DATA_TRIGGER_']['_EXECUTION_TIME_'] = microtime(true);
|
||||
eval($sScript);
|
||||
$this->scriptExecutionTime = round(microtime(true) -
|
||||
$_SESSION['_DATA_TRIGGER_']['_EXECUTION_TIME_'], 5);
|
||||
$_SESSION['_DATA_TRIGGER_']['_EXECUTION_TIME_'], 5);
|
||||
$this->evaluateVariable();
|
||||
ob_end_flush();
|
||||
|
||||
@@ -233,16 +189,16 @@ class PMScript
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function execute ()
|
||||
public function execute()
|
||||
{
|
||||
$sScript = "";
|
||||
$iAux = 0;
|
||||
$iOcurrences = preg_match_all( $this->sRegexp, $this->sScript, $aMatch, PREG_PATTERN_ORDER | PREG_OFFSET_CAPTURE );
|
||||
$iOcurrences = preg_match_all($this->sRegexp, $this->sScript, $aMatch, PREG_PATTERN_ORDER | PREG_OFFSET_CAPTURE);
|
||||
if ($iOcurrences) {
|
||||
for ($i = 0; $i < $iOcurrences; $i ++) {
|
||||
$bEqual = false;
|
||||
$sAux = substr( $this->sScript, $iAux, $aMatch[0][$i][1] - $iAux );
|
||||
if (! $bEqual) {
|
||||
$sAux = substr($this->sScript, $iAux, $aMatch[0][$i][1] - $iAux);
|
||||
if (!$bEqual) {
|
||||
if (strpos($sAux, "==") !== false || strpos($sAux, "!=") !== false || strpos($sAux, ">") !== false || strpos($sAux, "<") !== false || strpos($sAux, ">=") !== false || strpos($sAux, "<=") !== false || strpos($sAux, "<>") !== false || strpos($sAux, "===") !== false || strpos($sAux, "!==") !== false) {
|
||||
$bEqual = false;
|
||||
} else {
|
||||
@@ -252,115 +208,115 @@ class PMScript
|
||||
}
|
||||
}
|
||||
if ($bEqual) {
|
||||
if (strpos( $sAux, ';' ) !== false) {
|
||||
if (strpos($sAux, ';') !== false) {
|
||||
$bEqual = false;
|
||||
}
|
||||
}
|
||||
if ($bEqual) {
|
||||
if (! isset( $aMatch[5][$i][0] )) {
|
||||
eval( "if (!isset(\$this->aFields['" . $aMatch[2][$i][0] . "'])) { \$this->aFields['" . $aMatch[2][$i][0] . "'] = " . ($aMatch[1][$i][0] == "&" ? "new stdclass()" : "null") . "; }" );
|
||||
if (!isset($aMatch[5][$i][0])) {
|
||||
eval("if (!isset(\$this->aFields['" . $aMatch[2][$i][0] . "'])) { \$this->aFields['" . $aMatch[2][$i][0] . "'] = " . ($aMatch[1][$i][0] == "&" ? "new stdclass()" : "null") . "; }");
|
||||
} else {
|
||||
if ($aMatch[1][$i][0] == "&") {
|
||||
eval( "if (!isset(\$this->aFields['" . $aMatch[2][$i][0] . "'])) { \$this->aFields['" . $aMatch[2][$i][0] . "'] = new stdclass(); }" );
|
||||
eval("if (!isset(\$this->aFields['" . $aMatch[2][$i][0] . "'])) { \$this->aFields['" . $aMatch[2][$i][0] . "'] = new stdclass(); }");
|
||||
}
|
||||
eval( "if (!isset(\$this->aFields" . (isset( $aMatch[2][$i][0] ) ? "['" . $aMatch[2][$i][0] . "']" : '') . $aMatch[5][$i][0] . ")) { \$this->aFields" . (isset( $aMatch[2][$i][0] ) ? "['" . $aMatch[2][$i][0] . "']" : '') . $aMatch[5][$i][0] . " = null; }" );
|
||||
eval("if (!isset(\$this->aFields" . (isset($aMatch[2][$i][0]) ? "['" . $aMatch[2][$i][0] . "']" : '') . $aMatch[5][$i][0] . ")) { \$this->aFields" . (isset($aMatch[2][$i][0]) ? "['" . $aMatch[2][$i][0] . "']" : '') . $aMatch[5][$i][0] . " = null; }");
|
||||
}
|
||||
} else {
|
||||
if ($aMatch[1][$i][0] == "&") {
|
||||
eval( "if (!isset(\$this->aFields['" . $aMatch[2][$i][0] . "'])) { \$this->aFields['" . $aMatch[2][$i][0] . "'] = new stdclass(); }" );
|
||||
eval("if (!isset(\$this->aFields['" . $aMatch[2][$i][0] . "'])) { \$this->aFields['" . $aMatch[2][$i][0] . "'] = new stdclass(); }");
|
||||
}
|
||||
}
|
||||
$sScript .= $sAux;
|
||||
$iAux = $aMatch[0][$i][1] + strlen( $aMatch[0][$i][0] );
|
||||
$iAux = $aMatch[0][$i][1] + strlen($aMatch[0][$i][0]);
|
||||
switch ($aMatch[1][$i][0]) {
|
||||
case '@':
|
||||
if ($bEqual) {
|
||||
if (! isset( $aMatch[5][$i][0] )) {
|
||||
if (!isset($aMatch[5][$i][0])) {
|
||||
$sScript .= "pmToString(\$this->aFields['" . $aMatch[2][$i][0] . "'])";
|
||||
} else {
|
||||
$sScript .= "pmToString(\$this->aFields" . (isset( $aMatch[2][$i][0] ) ? "['" . $aMatch[2][$i][0] . "']" : '') . $aMatch[5][$i][0] . ")";
|
||||
$sScript .= "pmToString(\$this->aFields" . (isset($aMatch[2][$i][0]) ? "['" . $aMatch[2][$i][0] . "']" : '') . $aMatch[5][$i][0] . ")";
|
||||
}
|
||||
} else {
|
||||
if (! isset( $aMatch[5][$i][0] )) {
|
||||
if (!isset($aMatch[5][$i][0])) {
|
||||
$sScript .= "\$this->aFields['" . $aMatch[2][$i][0] . "']";
|
||||
} else {
|
||||
$sScript .= "\$this->aFields" . (isset( $aMatch[2][$i][0] ) ? "['" . $aMatch[2][$i][0] . "']" : '') . $aMatch[5][$i][0];
|
||||
$sScript .= "\$this->aFields" . (isset($aMatch[2][$i][0]) ? "['" . $aMatch[2][$i][0] . "']" : '') . $aMatch[5][$i][0];
|
||||
}
|
||||
}
|
||||
break;
|
||||
case '%':
|
||||
if ($bEqual) {
|
||||
if (! isset( $aMatch[5][$i][0] )) {
|
||||
if (!isset($aMatch[5][$i][0])) {
|
||||
$sScript .= "pmToInteger(\$this->aFields['" . $aMatch[2][$i][0] . "'])";
|
||||
} else {
|
||||
$sScript .= "pmToInteger(\$this->aFields" . (isset( $aMatch[2][$i][0] ) ? "['" . $aMatch[2][$i][0] . "']" : '') . $aMatch[5][$i][0] . ")";
|
||||
$sScript .= "pmToInteger(\$this->aFields" . (isset($aMatch[2][$i][0]) ? "['" . $aMatch[2][$i][0] . "']" : '') . $aMatch[5][$i][0] . ")";
|
||||
}
|
||||
} else {
|
||||
if (! isset( $aMatch[5][$i][0] )) {
|
||||
if (!isset($aMatch[5][$i][0])) {
|
||||
$sScript .= "\$this->aFields['" . $aMatch[2][$i][0] . "']";
|
||||
} else {
|
||||
$sScript .= "\$this->aFields" . (isset( $aMatch[2][$i][0] ) ? "['" . $aMatch[2][$i][0] . "']" : '') . $aMatch[5][$i][0];
|
||||
$sScript .= "\$this->aFields" . (isset($aMatch[2][$i][0]) ? "['" . $aMatch[2][$i][0] . "']" : '') . $aMatch[5][$i][0];
|
||||
}
|
||||
}
|
||||
break;
|
||||
case '#':
|
||||
if ($bEqual) {
|
||||
if (! isset( $aMatch[5][$i][0] )) {
|
||||
if (!isset($aMatch[5][$i][0])) {
|
||||
$sScript .= "pmToFloat(\$this->aFields['" . $aMatch[2][$i][0] . "'])";
|
||||
} else {
|
||||
$sScript .= "pmToFloat(\$this->aFields" . (isset( $aMatch[2][$i][0] ) ? "['" . $aMatch[2][$i][0] . "']" : '') . $aMatch[5][$i][0] . ")";
|
||||
$sScript .= "pmToFloat(\$this->aFields" . (isset($aMatch[2][$i][0]) ? "['" . $aMatch[2][$i][0] . "']" : '') . $aMatch[5][$i][0] . ")";
|
||||
}
|
||||
} else {
|
||||
if (! isset( $aMatch[5][$i][0] )) {
|
||||
if (!isset($aMatch[5][$i][0])) {
|
||||
$sScript .= "\$this->aFields['" . $aMatch[2][$i][0] . "']";
|
||||
} else {
|
||||
$sScript .= "\$this->aFields" . (isset( $aMatch[2][$i][0] ) ? "['" . $aMatch[2][$i][0] . "']" : '') . $aMatch[5][$i][0];
|
||||
$sScript .= "\$this->aFields" . (isset($aMatch[2][$i][0]) ? "['" . $aMatch[2][$i][0] . "']" : '') . $aMatch[5][$i][0];
|
||||
}
|
||||
}
|
||||
break;
|
||||
case '?':
|
||||
if ($bEqual) {
|
||||
if (! isset( $aMatch[5][$i][0] )) {
|
||||
if (!isset($aMatch[5][$i][0])) {
|
||||
$sScript .= "pmToUrl(\$this->aFields['" . $aMatch[2][$i][0] . "'])";
|
||||
} else {
|
||||
$sScript .= "pmToUrl(\$this->aFields" . (isset( $aMatch[2][$i][0] ) ? "['" . $aMatch[2][$i][0] . "']" : '') . $aMatch[5][$i][0] . ")";
|
||||
$sScript .= "pmToUrl(\$this->aFields" . (isset($aMatch[2][$i][0]) ? "['" . $aMatch[2][$i][0] . "']" : '') . $aMatch[5][$i][0] . ")";
|
||||
}
|
||||
} else {
|
||||
if (! isset( $aMatch[5][$i][0] )) {
|
||||
if (!isset($aMatch[5][$i][0])) {
|
||||
$sScript .= "\$this->aFields['" . $aMatch[2][$i][0] . "']";
|
||||
} else {
|
||||
$sScript .= "\$this->aFields" . (isset( $aMatch[2][$i][0] ) ? "['" . $aMatch[2][$i][0] . "']" : '') . $aMatch[5][$i][0];
|
||||
$sScript .= "\$this->aFields" . (isset($aMatch[2][$i][0]) ? "['" . $aMatch[2][$i][0] . "']" : '') . $aMatch[5][$i][0];
|
||||
}
|
||||
}
|
||||
break;
|
||||
case '$':
|
||||
if ($bEqual) {
|
||||
if (! isset( $aMatch[5][$i][0] )) {
|
||||
if (!isset($aMatch[5][$i][0])) {
|
||||
$sScript .= "pmSqlEscape(\$this->aFields['" . $aMatch[2][$i][0] . "'])";
|
||||
} else {
|
||||
$sScript .= "pmSqlEscape(\$this->aFields" . (isset( $aMatch[2][$i][0] ) ? "['" . $aMatch[2][$i][0] . "']" : '') . $aMatch[5][$i][0] . ")";
|
||||
$sScript .= "pmSqlEscape(\$this->aFields" . (isset($aMatch[2][$i][0]) ? "['" . $aMatch[2][$i][0] . "']" : '') . $aMatch[5][$i][0] . ")";
|
||||
}
|
||||
} else {
|
||||
if (! isset( $aMatch[5][$i][0] )) {
|
||||
if (!isset($aMatch[5][$i][0])) {
|
||||
$sScript .= "\$this->aFields['" . $aMatch[2][$i][0] . "']";
|
||||
} else {
|
||||
$sScript .= "\$this->aFields" . (isset( $aMatch[2][$i][0] ) ? "['" . $aMatch[2][$i][0] . "']" : '') . $aMatch[5][$i][0];
|
||||
$sScript .= "\$this->aFields" . (isset($aMatch[2][$i][0]) ? "['" . $aMatch[2][$i][0] . "']" : '') . $aMatch[5][$i][0];
|
||||
}
|
||||
}
|
||||
break;
|
||||
case '=':
|
||||
case '&':
|
||||
if ($bEqual) {
|
||||
if (! isset( $aMatch[5][$i][0] )) {
|
||||
if (!isset($aMatch[5][$i][0])) {
|
||||
$sScript .= "\$this->aFields['" . $aMatch[2][$i][0] . "']";
|
||||
} else {
|
||||
$sScript .= "\$this->aFields" . (isset( $aMatch[2][$i][0] ) ? "['" . $aMatch[2][$i][0] . "']" : '') . $aMatch[5][$i][0];
|
||||
$sScript .= "\$this->aFields" . (isset($aMatch[2][$i][0]) ? "['" . $aMatch[2][$i][0] . "']" : '') . $aMatch[5][$i][0];
|
||||
}
|
||||
} else {
|
||||
if (! isset( $aMatch[5][$i][0] )) {
|
||||
if (!isset($aMatch[5][$i][0])) {
|
||||
$sScript .= "\$this->aFields['" . $aMatch[2][$i][0] . "']";
|
||||
} else {
|
||||
$sScript .= "\$this->aFields" . (isset( $aMatch[2][$i][0] ) ? "['" . $aMatch[2][$i][0] . "']" : '') . $aMatch[5][$i][0];
|
||||
$sScript .= "\$this->aFields" . (isset($aMatch[2][$i][0]) ? "['" . $aMatch[2][$i][0] . "']" : '') . $aMatch[5][$i][0];
|
||||
}
|
||||
}
|
||||
break;
|
||||
@@ -368,18 +324,16 @@ class PMScript
|
||||
$this->affected_fields[] = $aMatch[2][$i][0];
|
||||
}
|
||||
}
|
||||
$sScript .= substr( $this->sScript, $iAux );
|
||||
$sScript .= substr($this->sScript, $iAux);
|
||||
$sScript = "try {\n" . $sScript . "\n} catch (Exception \$oException) {\n " . " \$this->aFields['__ERROR__'] = utf8_encode(\$oException->getMessage());\n}";
|
||||
//echo '<pre>-->'; print_r($this->aFields); echo '<---</pre>';
|
||||
|
||||
$this->executeAndCatchErrors($sScript, $this->sScript);
|
||||
|
||||
$this->aFields["__VAR_CHANGED__"] = implode(",", $this->affected_fields);
|
||||
for ($i = 0; $i < count( $this->affected_fields ); $i ++) {
|
||||
$_SESSION['TRIGGER_DEBUG']['DATA'][] = Array ('key' => $this->affected_fields[$i],'value' => isset( $this->aFields[$this->affected_fields[$i]] ) ? $this->aFields[$this->affected_fields[$i]] : ''
|
||||
for ($i = 0; $i < count($this->affected_fields); $i ++) {
|
||||
$_SESSION['TRIGGER_DEBUG']['DATA'][] = Array('key' => $this->affected_fields[$i], 'value' => isset($this->aFields[$this->affected_fields[$i]]) ? $this->aFields[$this->affected_fields[$i]] : ''
|
||||
);
|
||||
}
|
||||
//echo '<pre>-->'; print_r($_SESSION['TRIGGER_DEBUG']['DATA']); echo '<---</pre>';
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -387,27 +341,26 @@ class PMScript
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function evaluate ()
|
||||
public function evaluate()
|
||||
{
|
||||
$bResult = null;
|
||||
$sScript = '';
|
||||
$iAux = 0;
|
||||
$bEqual = false;
|
||||
$variableIsDefined = true;
|
||||
$iOcurrences = preg_match_all( $this->sRegexp, $this->sScript, $aMatch, PREG_PATTERN_ORDER | PREG_OFFSET_CAPTURE );
|
||||
$iOcurrences = preg_match_all($this->sRegexp, $this->sScript, $aMatch, PREG_PATTERN_ORDER | PREG_OFFSET_CAPTURE);
|
||||
if ($iOcurrences) {
|
||||
for ($i = 0; $i < $iOcurrences; $i ++) {
|
||||
// if the variables for that condition has not been previously defined then $variableIsDefined
|
||||
// is set to false
|
||||
if (!isset($this->aFields[$aMatch[2][$i][0]]) && !isset($aMatch[5][$i][0])) {
|
||||
eval( "if (!isset(\$this->aFields['" . $aMatch[2][$i][0] . "'])) { \$this->aFields['" . $aMatch[2][$i][0] . "'] = " . ($aMatch[1][$i][0] == "&" ? "new stdclass()" : "null") . "; }" );
|
||||
eval("if (!isset(\$this->aFields['" . $aMatch[2][$i][0] . "'])) { \$this->aFields['" . $aMatch[2][$i][0] . "'] = " . ($aMatch[1][$i][0] == "&" ? "new stdclass()" : "null") . "; }");
|
||||
} else {
|
||||
if ($aMatch[1][$i][0] == "&") {
|
||||
eval( "if (!isset(\$this->aFields['" . $aMatch[2][$i][0] . "'])) { \$this->aFields['" . $aMatch[2][$i][0] . "'] = new stdclass(); }" );
|
||||
eval("if (!isset(\$this->aFields['" . $aMatch[2][$i][0] . "'])) { \$this->aFields['" . $aMatch[2][$i][0] . "'] = new stdclass(); }");
|
||||
}
|
||||
if (!isset($this->aFields[$aMatch[2][$i][0]])) {
|
||||
eval("\$this->aFields['" . $aMatch[2][$i][0] . "']" . $aMatch[5][$i][0] . " = '';");
|
||||
|
||||
} else {
|
||||
if (isset($aMatch[5][$i][0])) {
|
||||
eval("if (!isset(\$this->aFields['" . $aMatch[2][$i][0] . "']" . $aMatch[5][$i][0] . ")) {\$this->aFields['" . $aMatch[2][$i][0] . "']" . $aMatch[5][$i][0] . " = '';}");
|
||||
@@ -416,179 +369,178 @@ class PMScript
|
||||
}
|
||||
}
|
||||
}
|
||||
$sAux = substr( $this->sScript, $iAux, $aMatch[0][$i][1] - $iAux );
|
||||
if (! $bEqual) {
|
||||
if (strpos( $sAux, '=' ) !== false) {
|
||||
$sAux = substr($this->sScript, $iAux, $aMatch[0][$i][1] - $iAux);
|
||||
if (!$bEqual) {
|
||||
if (strpos($sAux, '=') !== false) {
|
||||
$bEqual = true;
|
||||
}
|
||||
}
|
||||
if ($bEqual) {
|
||||
if (strpos( $sAux, ';' ) !== false) {
|
||||
if (strpos($sAux, ';') !== false) {
|
||||
$bEqual = false;
|
||||
}
|
||||
}
|
||||
$sScript .= $sAux;
|
||||
$iAux = $aMatch[0][$i][1] + strlen( $aMatch[0][$i][0] );
|
||||
$iAux = $aMatch[0][$i][1] + strlen($aMatch[0][$i][0]);
|
||||
switch ($aMatch[1][$i][0]) {
|
||||
case '@':
|
||||
if ($bEqual) {
|
||||
if (! isset( $aMatch[5][$i][0] )) {
|
||||
if (!isset($aMatch[5][$i][0])) {
|
||||
$sScript .= "pmToString(\$this->aFields['" . $aMatch[2][$i][0] . "'])";
|
||||
} else {
|
||||
$sScript .= "pmToString(\$this->aFields" . (isset( $aMatch[2][$i][0] ) ? "['" . $aMatch[2][$i][0] . "']" : '') . $aMatch[5][$i][0] . ")";
|
||||
$sScript .= "pmToString(\$this->aFields" . (isset($aMatch[2][$i][0]) ? "['" . $aMatch[2][$i][0] . "']" : '') . $aMatch[5][$i][0] . ")";
|
||||
}
|
||||
} else {
|
||||
if (! isset( $aMatch[5][$i][0] )) {
|
||||
if (!isset($aMatch[5][$i][0])) {
|
||||
$sScript .= "\$this->aFields['" . $aMatch[2][$i][0] . "']";
|
||||
} else {
|
||||
$sScript .= "\$this->aFields" . (isset( $aMatch[2][$i][0] ) ? "['" . $aMatch[2][$i][0] . "']" : '') . $aMatch[5][$i][0];
|
||||
$sScript .= "\$this->aFields" . (isset($aMatch[2][$i][0]) ? "['" . $aMatch[2][$i][0] . "']" : '') . $aMatch[5][$i][0];
|
||||
}
|
||||
}
|
||||
break;
|
||||
case '%':
|
||||
if ($bEqual) {
|
||||
if (! isset( $aMatch[5][$i][0] )) {
|
||||
if (!isset($aMatch[5][$i][0])) {
|
||||
$sScript .= "pmToInteger(\$this->aFields['" . $aMatch[2][$i][0] . "'])";
|
||||
} else {
|
||||
$sScript .= "pmToInteger(\$this->aFields" . (isset( $aMatch[2][$i][0] ) ? "['" . $aMatch[2][$i][0] . "']" : '') . $aMatch[5][$i][0] . ")";
|
||||
$sScript .= "pmToInteger(\$this->aFields" . (isset($aMatch[2][$i][0]) ? "['" . $aMatch[2][$i][0] . "']" : '') . $aMatch[5][$i][0] . ")";
|
||||
}
|
||||
} else {
|
||||
if (! isset( $aMatch[5][$i][0] )) {
|
||||
if (!isset($aMatch[5][$i][0])) {
|
||||
$sScript .= "\$this->aFields['" . $aMatch[2][$i][0] . "']";
|
||||
} else {
|
||||
$sScript .= "\$this->aFields" . (isset( $aMatch[2][$i][0] ) ? "['" . $aMatch[2][$i][0] . "']" : '') . $aMatch[5][$i][0];
|
||||
$sScript .= "\$this->aFields" . (isset($aMatch[2][$i][0]) ? "['" . $aMatch[2][$i][0] . "']" : '') . $aMatch[5][$i][0];
|
||||
}
|
||||
}
|
||||
break;
|
||||
case '#':
|
||||
if ($bEqual) {
|
||||
if (! isset( $aMatch[5][$i][0] )) {
|
||||
if (!isset($aMatch[5][$i][0])) {
|
||||
$sScript .= "pmToFloat(\$this->aFields['" . $aMatch[2][$i][0] . "'])";
|
||||
} else {
|
||||
$sScript .= "pmToFloat(\$this->aFields" . (isset( $aMatch[2][$i][0] ) ? "['" . $aMatch[2][$i][0] . "']" : '') . $aMatch[5][$i][0] . ")";
|
||||
$sScript .= "pmToFloat(\$this->aFields" . (isset($aMatch[2][$i][0]) ? "['" . $aMatch[2][$i][0] . "']" : '') . $aMatch[5][$i][0] . ")";
|
||||
}
|
||||
} else {
|
||||
if (! isset( $aMatch[5][$i][0] )) {
|
||||
if (!isset($aMatch[5][$i][0])) {
|
||||
$sScript .= "\$this->aFields['" . $aMatch[2][$i][0] . "']";
|
||||
} else {
|
||||
$sScript .= "\$this->aFields" . (isset( $aMatch[2][$i][0] ) ? "['" . $aMatch[2][$i][0] . "']" : '') . $aMatch[5][$i][0];
|
||||
$sScript .= "\$this->aFields" . (isset($aMatch[2][$i][0]) ? "['" . $aMatch[2][$i][0] . "']" : '') . $aMatch[5][$i][0];
|
||||
}
|
||||
}
|
||||
break;
|
||||
case '?':
|
||||
if ($bEqual) {
|
||||
if (! isset( $aMatch[5][$i][0] )) {
|
||||
if (!isset($aMatch[5][$i][0])) {
|
||||
$sScript .= "pmToUrl(\$this->aFields['" . $aMatch[2][$i][0] . "'])";
|
||||
} else {
|
||||
$sScript .= "pmToUrl(\$this->aFields" . (isset( $aMatch[2][$i][0] ) ? "['" . $aMatch[2][$i][0] . "']" : '') . $aMatch[5][$i][0] . ")";
|
||||
$sScript .= "pmToUrl(\$this->aFields" . (isset($aMatch[2][$i][0]) ? "['" . $aMatch[2][$i][0] . "']" : '') . $aMatch[5][$i][0] . ")";
|
||||
}
|
||||
} else {
|
||||
if (! isset( $aMatch[5][$i][0] )) {
|
||||
if (!isset($aMatch[5][$i][0])) {
|
||||
$sScript .= "\$this->aFields['" . $aMatch[2][$i][0] . "']";
|
||||
} else {
|
||||
$sScript .= "\$this->aFields" . (isset( $aMatch[2][$i][0] ) ? "['" . $aMatch[2][$i][0] . "']" : '') . $aMatch[5][$i][0];
|
||||
$sScript .= "\$this->aFields" . (isset($aMatch[2][$i][0]) ? "['" . $aMatch[2][$i][0] . "']" : '') . $aMatch[5][$i][0];
|
||||
}
|
||||
}
|
||||
break;
|
||||
case '$':
|
||||
if ($bEqual) {
|
||||
if (! isset( $aMatch[5][$i][0] )) {
|
||||
if (!isset($aMatch[5][$i][0])) {
|
||||
$sScript .= "pmSqlEscape(\$this->aFields['" . $aMatch[2][$i][0] . "'])";
|
||||
} else {
|
||||
$sScript .= "pmSqlEscape(\$this->aFields" . (isset( $aMatch[2][$i][0] ) ? "['" . $aMatch[2][$i][0] . "']" : '') . $aMatch[5][$i][0] . ")";
|
||||
$sScript .= "pmSqlEscape(\$this->aFields" . (isset($aMatch[2][$i][0]) ? "['" . $aMatch[2][$i][0] . "']" : '') . $aMatch[5][$i][0] . ")";
|
||||
}
|
||||
} else {
|
||||
if (! isset( $aMatch[5][$i][0] )) {
|
||||
if (!isset($aMatch[5][$i][0])) {
|
||||
$sScript .= "\$this->aFields['" . $aMatch[2][$i][0] . "']";
|
||||
} else {
|
||||
$sScript .= "\$this->aFields" . (isset( $aMatch[2][$i][0] ) ? "['" . $aMatch[2][$i][0] . "']" : '') . $aMatch[5][$i][0];
|
||||
$sScript .= "\$this->aFields" . (isset($aMatch[2][$i][0]) ? "['" . $aMatch[2][$i][0] . "']" : '') . $aMatch[5][$i][0];
|
||||
}
|
||||
}
|
||||
break;
|
||||
case '=':
|
||||
case '&':
|
||||
if ($bEqual) {
|
||||
if (! isset( $aMatch[5][$i][0] )) {
|
||||
if (!isset($aMatch[5][$i][0])) {
|
||||
$sScript .= "\$this->aFields['" . $aMatch[2][$i][0] . "']";
|
||||
} else {
|
||||
$sScript .= "\$this->aFields" . (isset( $aMatch[2][$i][0] ) ? "['" . $aMatch[2][$i][0] . "']" : '') . $aMatch[5][$i][0];
|
||||
$sScript .= "\$this->aFields" . (isset($aMatch[2][$i][0]) ? "['" . $aMatch[2][$i][0] . "']" : '') . $aMatch[5][$i][0];
|
||||
}
|
||||
} else {
|
||||
if (! isset( $aMatch[5][$i][0] )) {
|
||||
if (!isset($aMatch[5][$i][0])) {
|
||||
$sScript .= "\$this->aFields['" . $aMatch[2][$i][0] . "']";
|
||||
} else {
|
||||
$sScript .= "\$this->aFields" . (isset( $aMatch[2][$i][0] ) ? "['" . $aMatch[2][$i][0] . "']" : '') . $aMatch[5][$i][0];
|
||||
$sScript .= "\$this->aFields" . (isset($aMatch[2][$i][0]) ? "['" . $aMatch[2][$i][0] . "']" : '') . $aMatch[5][$i][0];
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
$sScript .= substr( $this->sScript, $iAux );
|
||||
if(preg_match('/\b(or|and|xor)\b/i' , $sScript)) {
|
||||
$sScript = "( ".$sScript." )";
|
||||
$sScript .= substr($this->sScript, $iAux);
|
||||
if (preg_match('/\b(or|and|xor)\b/i', $sScript)) {
|
||||
$sScript = "( " . $sScript . " )";
|
||||
}
|
||||
$sScript = '$bResult = ' . $sScript . ';';
|
||||
// checks if the syntax is valid or if the variables in that condition has been previously defined
|
||||
if ($this->validSyntax( $sScript ) && $variableIsDefined) {
|
||||
if ($this->validSyntax($sScript) && $variableIsDefined) {
|
||||
$this->bError = false;
|
||||
eval( $sScript );
|
||||
eval($sScript);
|
||||
} else {
|
||||
// echo "<script> alert('".G::loadTranslation('MSG_CONDITION_NOT_DEFINED')."'); </script>";
|
||||
G::SendTemporalMessage( 'MSG_CONDITION_NOT_DEFINED', 'error', 'labels' );
|
||||
G::SendTemporalMessage('MSG_CONDITION_NOT_DEFINED', 'error', 'labels');
|
||||
$this->bError = true;
|
||||
}
|
||||
return $bResult;
|
||||
}
|
||||
|
||||
Public function evaluateVariable ()
|
||||
Public function evaluateVariable()
|
||||
{
|
||||
$process = new Process();
|
||||
if(!$process->isBpmnProcess($_SESSION['PROCESS'])) {
|
||||
if (!$process->isBpmnProcess($_SESSION['PROCESS'])) {
|
||||
return;
|
||||
}
|
||||
require_once PATH_CORE.'controllers/pmTablesProxy.php';
|
||||
require_once PATH_CORE . 'controllers/pmTablesProxy.php';
|
||||
$pmTablesProxy = new pmTablesProxy();
|
||||
$variableModule = new ProcessMaker\BusinessModel\Variable();
|
||||
$searchTypes = array ('checkgroup','dropdown','suggest');
|
||||
$processVariables = $pmTablesProxy->getDynaformVariables($_SESSION['PROCESS'],$searchTypes,false);
|
||||
$searchTypes = array('checkgroup', 'dropdown', 'suggest');
|
||||
$processVariables = $pmTablesProxy->getDynaformVariables($_SESSION['PROCESS'], $searchTypes, false);
|
||||
$variables = $this->affected_fields;
|
||||
$variables = (is_array($variables))? array_unique($variables) : $variables;
|
||||
$newFields = array();
|
||||
$arrayValues = array();
|
||||
$arrayLabels = array();
|
||||
if(is_array($variables) && is_array($processVariables)) {
|
||||
foreach($variables as $var) {
|
||||
if(strpos($var, '_label') === false) {
|
||||
if(in_array($var,$processVariables)) {
|
||||
if(isset($this->aFields[$var]) && is_array($this->aFields[$var][1]) ) {
|
||||
$varLabel = $var.'_label';
|
||||
$variables = (is_array($variables)) ? array_unique($variables) : $variables;
|
||||
$newFields = [];
|
||||
$arrayValues = [];
|
||||
$arrayLabels = [];
|
||||
if (is_array($variables) && is_array($processVariables)) {
|
||||
foreach ($variables as $var) {
|
||||
if (strpos($var, '_label') === false) {
|
||||
if (in_array($var, $processVariables)) {
|
||||
if (isset($this->aFields[$var]) && is_array($this->aFields[$var][1])) {
|
||||
$varLabel = $var . '_label';
|
||||
$arrayValue = $this->aFields[$var];
|
||||
if(is_array($arrayValue) && sizeof($arrayValue)) {
|
||||
foreach($arrayValue as $val) {
|
||||
if(is_array($val)){
|
||||
if (is_array($arrayValue) && sizeof($arrayValue)) {
|
||||
foreach ($arrayValue as $val) {
|
||||
if (is_array($val)) {
|
||||
$val = array_values($val);
|
||||
$arrayValues[] = $val[0];
|
||||
$arrayLabels[] = $val[1];
|
||||
}
|
||||
}
|
||||
if(sizeof($arrayLabels)) {
|
||||
$varInfo = $variableModule->getVariableTypeByName($_SESSION['PROCESS'],$var);
|
||||
if(is_array($varInfo) && sizeof($varInfo)) {
|
||||
if (sizeof($arrayLabels)) {
|
||||
$varInfo = $variableModule->getVariableTypeByName($_SESSION['PROCESS'], $var);
|
||||
if (is_array($varInfo) && sizeof($varInfo)) {
|
||||
$varType = $varInfo['VAR_FIELD_TYPE'];
|
||||
switch($varType) {
|
||||
switch ($varType) {
|
||||
case 'array':
|
||||
$arrayLabels = '["'.implode('","',$arrayLabels).'"]';
|
||||
$arrayLabels = '["' . implode('","', $arrayLabels) . '"]';
|
||||
$newFields[$var] = $arrayValues;
|
||||
$newFields[$varLabel] = $arrayLabels;
|
||||
break;
|
||||
break;
|
||||
case 'string':
|
||||
$newFields[$var] = $arrayValues[0];
|
||||
$newFields[$varLabel] = $arrayLabels[0];
|
||||
break;
|
||||
break;
|
||||
}
|
||||
$this->affected_fields[] = $varLabel;
|
||||
$this->aFields = array_merge($this->aFields,$newFields);
|
||||
$this->aFields = array_merge($this->aFields, $newFields);
|
||||
unset($newFields);
|
||||
unset($arrayValues);
|
||||
unset($arrayLabels);
|
||||
@@ -618,7 +570,6 @@ class PMScript
|
||||
}
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -627,4 +578,4 @@ class PMScript
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user