diff --git a/gulliver/system/class.bootstrap.php b/gulliver/system/class.bootstrap.php index 88a7c400a..ce6c4b9d1 100644 --- a/gulliver/system/class.bootstrap.php +++ b/gulliver/system/class.bootstrap.php @@ -2351,92 +2351,6 @@ class Bootstrap } } - /* Returns a sql string with @@parameters replaced with its values defined - * in array $result using the next notation: - * NOTATION: - * @@ Quoted parameter acording to the SYSTEM's Database - * @Q Double quoted parameter \\ \" - * @q Single quoted parameter \\ \' - * @% URL string - * @# Non-quoted parameter - * @! Evaluate string : Replace the parameters in value and then in the sql string - * @fn() Evaluate string with the function "fn" - * @author David Callizaya - */ - - public function replaceDataField($sqlString, $result, $DBEngine = 'mysql') - { - if (!is_array($result)) { - $result = array(); - } - $result = $result + Bootstrap::getSystemConstants(); - $__textoEval = ""; - $u = 0; - //$count=preg_match_all('/\@(?:([\@\%\#\!Qq])([a-zA-Z\_]\w*)|([a-zA-Z\_][\w\-\>\:]*)\(((?:[^\\\\\)]*(?:[\\\\][\w\W])?)*)\))/',$sqlString,$match,PREG_PATTERN_ORDER | PREG_OFFSET_CAPTURE); - $count = preg_match_all('/\@(?:([\@\%\#\=\!Qq])([a-zA-Z\_]\w*)|([a-zA-Z\_][\w\-\>\:]*)\(((?:[^\\\\\)]*?)*)\))/', $sqlString, $match, PREG_PATTERN_ORDER | PREG_OFFSET_CAPTURE); - if ($count) { - for ($r = 0; $r < $count; $r++) { - if (!isset($result[$match[2][$r][0]])) { - $result[$match[2][$r][0]] = ''; - } - if (!is_array($result[$match[2][$r][0]])) { - $__textoEval .= substr($sqlString, $u, $match[0][$r][1] - $u); - $u = $match[0][$r][1] + strlen($match[0][$r][0]); - //Mysql quotes scape - if (($match[1][$r][0] == '@') && (isset($result[$match[2][$r][0]]))) { - $__textoEval .= "\"" . Bootstrap::sqlEscape($result[$match[2][$r][0]], $DBEngine) . "\""; - continue; - } - //URL encode - if (($match[1][$r][0] == '%') && (isset($result[$match[2][$r][0]]))) { - $__textoEval.=urlencode($result[$match[2][$r][0]]); - continue; - } - //Double quoted parameter - if (($match[1][$r][0] == 'Q') && (isset($result[$match[2][$r][0]]))) { - $__textoEval.='"' . addcslashes($result[$match[2][$r][0]], '\\"') . '"'; - continue; - } - //Single quoted parameter - if (($match[1][$r][0] == 'q') && (isset($result[$match[2][$r][0]]))) { - $__textoEval.="'" . addcslashes($result[$match[2][$r][0]], '\\\'') . "'"; - continue; - } - //Substring (Sub replaceDataField) - if (($match[1][$r][0] == '!') && (isset($result[$match[2][$r][0]]))) { - $__textoEval.=Bootstrap::replaceDataField($result[$match[2][$r][0]], $result); - continue; - } - //Call function - if (($match[1][$r][0] === '') && ($match[2][$r][0] === '') && ($match[3][$r][0] !== '')) { - eval('$strAux = ' . $match[3][$r][0] . '(\'' . addcslashes(Bootstrap::replaceDataField(stripslashes($match[4][$r][0]), $result), '\\\'') . '\');'); - - if ($match[3][$r][0] == "Bootstrap::LoadTranslation") { - $arraySearch = array("'"); - $arrayReplace = array("\\'"); - $strAux = str_replace($arraySearch, $arrayReplace, $strAux); - } - - $__textoEval .= $strAux; - continue; - } - //Non-quoted - if (($match[1][$r][0] == '#') && (isset($result[$match[2][$r][0]]))) { - $__textoEval.=Bootstrap::replaceDataField($result[$match[2][$r][0]], $result); - continue; - } - //Non-quoted = - if (($match[1][$r][0] == '=') && (isset($result[$match[2][$r][0]]))) { - $__textoEval.=Bootstrap::replaceDataField($result[$match[2][$r][0]], $result); - continue; - } - } - } - } - $__textoEval.=substr($sqlString, $u); - return $__textoEval; - } - /** * microtime_float * diff --git a/gulliver/system/class.g.php b/gulliver/system/class.g.php index 2237e9c21..a84fc8fb2 100644 --- a/gulliver/system/class.g.php +++ b/gulliver/system/class.g.php @@ -1758,8 +1758,7 @@ class G $result = $result + G::getSystemConstants(); $__textoEval = ""; $u = 0; - //$count=preg_match_all('/\@(?:([\@\%\#\!Qq])([a-zA-Z\_]\w*)|([a-zA-Z\_][\w\-\>\:]*)\(((?:[^\\\\\)]*(?:[\\\\][\w\W])?)*)\))/',$sqlString,$match,PREG_PATTERN_ORDER | PREG_OFFSET_CAPTURE); - $count = preg_match_all( '/\@(?:([\@\%\#\=\!Qq])([a-zA-Z\_]\w*)|([a-zA-Z\_][\w\-\>\:]*)\(((?:[^\\\\\)]*?)*)\))/', $sqlString, $match, PREG_PATTERN_ORDER | PREG_OFFSET_CAPTURE ); + $count = preg_match_all( '/\@(?:([\@\%\#\?\$\=\&])([a-zA-Z\_]\w*)|([a-zA-Z\_][\w\-\>\:]*)\(((?:[^\\\\\)]*(?:[\\\\][\w\W])?)*)\))((?:\s*\[[\'"]?\w+[\'"]?\])+|\-\>([a-zA-Z\_]\w*))?/', $sqlString, $match, PREG_PATTERN_ORDER | PREG_OFFSET_CAPTURE ); if ($count) { for ($r = 0; $r < $count; $r ++) { if (! isset( $result[$match[2][$r][0]] )) { @@ -1816,6 +1815,13 @@ class G $__textoEval.=G::replaceDataField($result[$match[2][$r][0]],$result); continue; } + //Objects attributes + if (($match[1][$r][0]=='&')&&(isset($result[$match[2][$r][0]]))) { + if (isset($result[$match[2][$r][0]]->{$match[6][$r][0]})) { + $__textoEval.=$result[$match[2][$r][0]]->{$match[6][$r][0]}; + } + continue; + } } } } @@ -1891,7 +1897,7 @@ class G if ($nl2brRecursive) { foreach ($aFields as $sKey => $vValue) { - if (!is_array($vValue)) { + if (!is_array($vValue) && !is_object($vValue)) { $aFields[$sKey] = nl2br($aFields[$sKey]); } } diff --git a/workflow/engine/classes/class.case.php b/workflow/engine/classes/class.case.php index 7bf64894f..8a4e6923a 100644 --- a/workflow/engine/classes/class.case.php +++ b/workflow/engine/classes/class.case.php @@ -871,6 +871,24 @@ class Cases return $aReturn; } + public function array_key_intersect(&$a, &$b) { + $array = array(); + while (list($key, $value) = each($a)) { + if (isset($b[$key])) { + if (is_object($b[$key]) && is_object($value)) { + if (serialize($b[$key]) === serialize($value)) { + $array[$key] = $value; + } + } else { + if ($b[$key] === $value) { + $array[$key] = $value; + } + } + } + } + return $array; + } + /* * Update an existing case, this info is used in CaseResume * @@ -914,7 +932,7 @@ class Cases //only when that variable is set.. from Save $FieldsBefore = $this->loadCase($sAppUid); $FieldsDifference = $this->arrayRecursiveDiff($FieldsBefore['APP_DATA'], $aApplicationFields); - $fieldsOnBoth = @array_intersect_assoc($FieldsBefore['APP_DATA'], $aApplicationFields); + $fieldsOnBoth = $this->array_key_intersect($FieldsBefore['APP_DATA'], $aApplicationFields); //Add fields that weren't in previous version foreach ($aApplicationFields as $key => $value) { if (is_array($value) && isset($fieldsOnBoth[$key]) && is_array($fieldsOnBoth[$key])) { diff --git a/workflow/engine/classes/class.pmScript.php b/workflow/engine/classes/class.pmScript.php index 3389c5285..8b5cc9f6b 100644 --- a/workflow/engine/classes/class.pmScript.php +++ b/workflow/engine/classes/class.pmScript.php @@ -127,6 +127,8 @@ class PMScript public $scriptExecutionTime = 0; + public $sRegexp = '/\@(?:([\@\%\#\?\$\=\&])([a-zA-Z\_]\w*)|([a-zA-Z\_][\w\-\>\:]*)\(((?:[^\\\\\)]*(?:[\\\\][\w\W])?)*)\))((?:\s*\[[\'"]?\w+[\'"]?\])+|\-\>([a-zA-Z\_]\w*))?/'; + /** * Constructor of the class PMScript * @@ -228,7 +230,7 @@ class PMScript { $sScript = ""; $iAux = 0; - $iOcurrences = preg_match_all( '/\@(?:([\@\%\#\?\$\=])([a-zA-Z\_]\w*)|([a-zA-Z\_][\w\-\>\:]*)\(((?:[^\\\\\)]' . '*(?:[\\\\][\w\W])?)*)\))((?:\s*\[[\'"]?\w+[\'"]?\])+)?/', $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; @@ -249,8 +251,11 @@ class PMScript } if ($bEqual) { if (! isset( $aMatch[5][$i][0] )) { - eval( "if (!isset(\$this->aFields['" . $aMatch[2][$i][0] . "'])) { \$this->aFields['" . $aMatch[2][$i][0] . "'] = 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" . (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; }" ); } } @@ -333,6 +338,7 @@ class PMScript } break; case '=': + case '&': if ($bEqual) { if (! isset( $aMatch[5][$i][0] )) { $sScript .= "\$this->aFields['" . $aMatch[2][$i][0] . "']"; @@ -383,21 +389,25 @@ class PMScript $iAux = 0; $bEqual = false; $variableIsDefined = true; - $iOcurrences = preg_match_all( '/\@(?:([\@\%\#\?\$\=])([a-zA-Z\_]\w*)|([a-zA-Z\_][\w\-\>\:]*)\(((?:[^\\\\\)]' . '*(?:[\\\\][\w\W])?)*)\))((?:\s*\[[\'"]?\w+[\'"]?\])+)?/', $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])) { - $this->aFields[$aMatch[2][$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(); }" ); + } 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] . " = '';}"); } else { - eval("if (!isset(\$this->aFields['" . $aMatch[2][$i][0] . "'])) {\$this->aFields['" . $aMatch[2][$i][0] . "'] = '';}"); + eval("if (!isset(\$this->aFields['" . $aMatch[2][$i][0] . "'])) {\$this->aFields['" . $aMatch[2][$i][0] . "'] = " . ($aMatch[1][$i][0] == "&" ? "new stdclass()" : "''") . ";}"); } } } @@ -491,6 +501,7 @@ class PMScript } break; case '=': + case '&': if ($bEqual) { if (! isset( $aMatch[5][$i][0] )) { $sScript .= "\$this->aFields['" . $aMatch[2][$i][0] . "']";