2010-12-02 23:34:41 +00:00
|
|
|
|
<?php
|
2012-07-03 17:54:36 -04:00
|
|
|
|
|
2010-12-02 23:34:41 +00:00
|
|
|
|
/**
|
|
|
|
|
|
* class.pmScript.php
|
2012-10-09 12:59:01 -04:00
|
|
|
|
*
|
2011-02-01 12:49:40 +00:00
|
|
|
|
* @package workflow.engine.ProcessMaker
|
2010-12-02 23:34:41 +00:00
|
|
|
|
*
|
|
|
|
|
|
* ProcessMaker Open Source Edition
|
2011-02-01 12:49:40 +00:00
|
|
|
|
* Copyright (C) 2004 - 2011 Colosa Inc.
|
2010-12-02 23:34:41 +00:00
|
|
|
|
*
|
|
|
|
|
|
* 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
|
2012-10-09 12:59:01 -04:00
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2010-12-02 23:34:41 +00:00
|
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
|
|
*
|
|
|
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
2012-10-09 12:59:01 -04:00
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2010-12-02 23:34:41 +00:00
|
|
|
|
*
|
|
|
|
|
|
* 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
|
|
|
|
|
|
////////////////////////////////////////////////////
|
|
|
|
|
|
|
2012-10-09 12:59:01 -04:00
|
|
|
|
|
2010-12-02 23:34:41 +00:00
|
|
|
|
/**
|
2012-07-03 17:54:36 -04:00
|
|
|
|
* PMScript - PMScript class
|
2012-10-09 12:59:01 -04:00
|
|
|
|
*
|
2010-12-02 23:34:41 +00:00
|
|
|
|
* @author Julio Cesar Laura Avenda<EFBFBD>o <juliocesar@colosa.com>
|
2011-02-03 11:13:21 +00:00
|
|
|
|
* last modify 2008.08.13 by Erik Amaru Ortiz <erik@colosa.com>
|
|
|
|
|
|
* last modify comment was added and adapted the catch errors
|
2010-12-02 23:34:41 +00:00
|
|
|
|
* @copyright 2007 COLOSA
|
|
|
|
|
|
*/
|
2012-10-09 12:59:01 -04:00
|
|
|
|
function __autoload ($sClassName)
|
2010-12-02 23:34:41 +00:00
|
|
|
|
{
|
2012-10-09 12:59:01 -04:00
|
|
|
|
if (defined( 'SYS_SYS' )) {
|
2012-07-03 17:54:36 -04:00
|
|
|
|
$sPath = PATH_DB . SYS_SYS . PATH_SEP . 'classes' . PATH_SEP;
|
2012-10-09 12:59:01 -04:00
|
|
|
|
if (file_exists( $sPath . $sClassName . '.php' )) {
|
2012-07-03 17:54:36 -04:00
|
|
|
|
require_once $sPath . $sClassName . '.php';
|
|
|
|
|
|
}
|
2010-12-02 23:34:41 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-02-13 15:51:05 -04:00
|
|
|
|
if (defined('SYS_SYS') && (!defined('PATH_DATA_SITE') || !defined('PATH_WORKSPACE'))) {
|
2017-02-13 11:19:58 -04:00
|
|
|
|
Bootstrap::setConstantsRelatedWs(SYS_SYS);
|
2016-10-19 16:31:32 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
2010-12-02 23:34:41 +00:00
|
|
|
|
//Start - Custom functions
|
2012-10-09 12:59:01 -04:00
|
|
|
|
G::LoadClass( 'pmFunctions' );
|
2010-12-02 23:34:41 +00:00
|
|
|
|
//End - Custom functions
|
|
|
|
|
|
//call plugin
|
2012-10-09 12:59:01 -04:00
|
|
|
|
if (class_exists( 'folderData' )) {
|
2012-07-03 17:54:36 -04:00
|
|
|
|
//$folderData = new folderData($sProUid, $proFields['PRO_TITLE'], $sAppUid, $Fields['APP_TITLE'], $sUsrUid);
|
|
|
|
|
|
$oPluginRegistry = &PMPluginRegistry::getSingleton();
|
|
|
|
|
|
$aAvailablePmFunctions = $oPluginRegistry->getPmFunctions();
|
|
|
|
|
|
foreach ($aAvailablePmFunctions as $key => $class) {
|
|
|
|
|
|
$filePlugin = PATH_PLUGINS . $class . PATH_SEP . 'classes' . PATH_SEP . 'class.pmFunctions.php';
|
2012-10-09 12:59:01 -04:00
|
|
|
|
if (file_exists( $filePlugin )) {
|
|
|
|
|
|
include_once ($filePlugin);
|
2012-07-03 17:54:36 -04:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2010-12-02 23:34:41 +00:00
|
|
|
|
}
|
|
|
|
|
|
//end plugin
|
|
|
|
|
|
//Add External Triggers
|
2012-10-09 12:59:01 -04:00
|
|
|
|
$dir = G::ExpandPath( "classes" ) . 'triggers';
|
|
|
|
|
|
$filesArray = array ();
|
|
|
|
|
|
if (file_exists( $dir )) {
|
|
|
|
|
|
if ($handle = opendir( $dir )) {
|
|
|
|
|
|
while (false !== ($file = readdir( $handle ))) {
|
2012-07-03 17:54:36 -04:00
|
|
|
|
if (($file != ".") && ($file != "..")) {
|
2012-10-09 12:59:01 -04:00
|
|
|
|
$extFile = explode( ".", $file );
|
|
|
|
|
|
if ($extFile[sizeof( $extFile ) - 1] == 'php') {
|
|
|
|
|
|
include_once ($dir . PATH_SEP . $file);
|
2012-07-03 17:54:36 -04:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2012-10-09 12:59:01 -04:00
|
|
|
|
closedir( $handle );
|
2012-07-03 17:54:36 -04:00
|
|
|
|
}
|
2010-12-02 23:34:41 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* PMScript - PMScript class
|
2012-10-09 12:59:01 -04:00
|
|
|
|
*
|
2010-12-02 23:34:41 +00:00
|
|
|
|
* @copyright 2007 COLOSA
|
2011-02-01 12:49:40 +00:00
|
|
|
|
* @package workflow.engine.ProcessMaker
|
2010-12-02 23:34:41 +00:00
|
|
|
|
*/
|
|
|
|
|
|
class PMScript
|
|
|
|
|
|
{
|
2017-04-19 11:30:54 -04:00
|
|
|
|
/**
|
|
|
|
|
|
* @var array $dataTrigger
|
|
|
|
|
|
*/
|
|
|
|
|
|
public $dataTrigger = array();
|
2012-07-03 17:54:36 -04:00
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* Original fields
|
|
|
|
|
|
*/
|
2012-10-09 12:59:01 -04:00
|
|
|
|
public $aOriginalFields = array ();
|
2012-07-03 17:54:36 -04:00
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* Fields to use
|
|
|
|
|
|
*/
|
2012-10-09 12:59:01 -04:00
|
|
|
|
public $aFields = array ();
|
2012-07-03 17:54:36 -04:00
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* Script
|
|
|
|
|
|
*/
|
|
|
|
|
|
public $sScript = '';
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* Error has happened?
|
|
|
|
|
|
*/
|
|
|
|
|
|
public $bError = false;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* Affected fields
|
|
|
|
|
|
*/
|
|
|
|
|
|
public $affected_fields;
|
|
|
|
|
|
|
2016-07-19 14:26:51 -04:00
|
|
|
|
public $scriptExecutionTime = 0;
|
|
|
|
|
|
|
2016-11-17 06:54:34 -05:00
|
|
|
|
public $sRegexp = '/\@(?:([\@\%\#\?\$\=\&])([a-zA-Z\_]\w*)|([a-zA-Z\_][\w\-\>\:]*)\(((?:[^\\\\\)]*(?:[\\\\][\w\W])?)*)\))((?:\s*\[[\'"]?\w+[\'"]?\])+|\-\>([a-zA-Z\_]\w*))?/';
|
|
|
|
|
|
|
2012-07-03 17:54:36 -04:00
|
|
|
|
/**
|
|
|
|
|
|
* Constructor of the class PMScript
|
2012-10-09 12:59:01 -04:00
|
|
|
|
*
|
2012-07-03 17:54:36 -04:00
|
|
|
|
* @return void
|
|
|
|
|
|
*/
|
2012-10-09 12:59:01 -04:00
|
|
|
|
public function PMScript ()
|
2012-07-03 17:54:36 -04:00
|
|
|
|
{
|
|
|
|
|
|
$this->aFields['__ERROR__'] = 'none';
|
2010-12-02 23:34:41 +00:00
|
|
|
|
}
|
2012-07-03 17:54:36 -04:00
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* Set the fields to use
|
2012-10-09 12:59:01 -04:00
|
|
|
|
*
|
2012-07-03 17:54:36 -04:00
|
|
|
|
* @param array $aFields
|
|
|
|
|
|
* @return void
|
|
|
|
|
|
*/
|
2012-10-09 12:59:01 -04:00
|
|
|
|
public function setFields ($aFields = array())
|
2012-07-03 17:54:36 -04:00
|
|
|
|
{
|
2012-10-09 12:59:01 -04:00
|
|
|
|
if (! is_array( $aFields )) {
|
|
|
|
|
|
$aFields = array ();
|
2010-12-02 23:34:41 +00:00
|
|
|
|
}
|
2012-07-03 17:54:36 -04:00
|
|
|
|
$this->aOriginalFields = $this->aFields = $aFields;
|
2010-12-02 23:34:41 +00:00
|
|
|
|
}
|
2012-07-03 17:54:36 -04:00
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* Set the current script
|
2012-10-09 12:59:01 -04:00
|
|
|
|
*
|
2012-07-03 17:54:36 -04:00
|
|
|
|
* @param string $sScript
|
|
|
|
|
|
* @return void
|
|
|
|
|
|
*/
|
2012-10-09 12:59:01 -04:00
|
|
|
|
public function setScript ($sScript = '')
|
2012-07-03 17:54:36 -04:00
|
|
|
|
{
|
2014-03-18 10:29:57 -04:00
|
|
|
|
if (!defined("T_ML_COMMENT")) {
|
|
|
|
|
|
define("T_ML_COMMENT", T_COMMENT);
|
|
|
|
|
|
} else {
|
2014-04-10 12:52:13 -04:00
|
|
|
|
if (!defined("T_DOC_COMMENT")) {
|
|
|
|
|
|
define("T_DOC_COMMENT", T_ML_COMMENT);
|
|
|
|
|
|
}
|
2014-03-14 14:10:22 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
2014-03-18 10:29:57 -04:00
|
|
|
|
$script = "<?php " . $sScript;
|
|
|
|
|
|
$tokens = token_get_all($script);
|
|
|
|
|
|
$result = "";
|
|
|
|
|
|
|
|
|
|
|
|
foreach ($tokens as $token) {
|
|
|
|
|
|
if (is_string($token)) {
|
2014-04-10 12:52:13 -04:00
|
|
|
|
$result .= $token;
|
2014-03-18 10:29:57 -04:00
|
|
|
|
} else {
|
|
|
|
|
|
list($id, $text) = $token;
|
|
|
|
|
|
|
|
|
|
|
|
switch ($id) {
|
2014-03-18 12:13:37 -04:00
|
|
|
|
case T_OPEN_TAG:
|
|
|
|
|
|
case T_CLOSE_TAG:
|
2014-03-18 10:29:57 -04:00
|
|
|
|
case T_COMMENT:
|
|
|
|
|
|
case T_ML_COMMENT: //we've defined this
|
|
|
|
|
|
case T_DOC_COMMENT: //and this
|
2014-04-10 12:52:13 -04:00
|
|
|
|
if ($text != '<?php ' && $text != '<?php' && $text != '<? ' && $text != '<?' && $text != '<% ' && $text != '<%') {
|
|
|
|
|
|
$result .= $text;
|
|
|
|
|
|
}
|
2014-03-18 10:29:57 -04:00
|
|
|
|
break;
|
|
|
|
|
|
default:
|
2014-04-10 12:52:13 -04:00
|
|
|
|
$result .= $text;
|
2014-03-18 10:29:57 -04:00
|
|
|
|
break;
|
|
|
|
|
|
}
|
2014-03-14 14:10:22 -04:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2014-04-10 12:52:13 -04:00
|
|
|
|
$this->sScript = trim($result);
|
2010-12-02 23:34:41 +00:00
|
|
|
|
}
|
2012-07-03 17:54:36 -04:00
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* Verify the syntax
|
2012-10-09 12:59:01 -04:00
|
|
|
|
*
|
2012-07-03 17:54:36 -04:00
|
|
|
|
* @param string $sScript
|
|
|
|
|
|
* @return boolean
|
|
|
|
|
|
*/
|
2012-10-09 12:59:01 -04:00
|
|
|
|
public function validSyntax ($sScript)
|
2012-07-03 17:54:36 -04:00
|
|
|
|
{
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-04-19 11:30:54 -04:00
|
|
|
|
/**
|
|
|
|
|
|
* @param $dataTrigger
|
|
|
|
|
|
*/
|
|
|
|
|
|
public function setDataTrigger($dataTrigger)
|
2012-07-03 17:54:36 -04:00
|
|
|
|
{
|
2017-04-19 11:30:54 -04:00
|
|
|
|
$this->dataTrigger = is_array($dataTrigger) ? $dataTrigger : array();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @param $sScript
|
|
|
|
|
|
* @param $sCode
|
|
|
|
|
|
*/
|
|
|
|
|
|
public function executeAndCatchErrors($sScript, $sCode)
|
|
|
|
|
|
{
|
|
|
|
|
|
ob_start('handleFatalErrors');
|
|
|
|
|
|
set_error_handler('handleErrors');
|
2012-07-03 17:54:36 -04:00
|
|
|
|
$_SESSION['_CODE_'] = $sCode;
|
2017-04-19 11:30:54 -04:00
|
|
|
|
$_SESSION['_DATA_TRIGGER_'] = $this->dataTrigger;
|
|
|
|
|
|
$_SESSION['_DATA_TRIGGER_']['_EXECUTION_TIME_'] = microtime(true);
|
|
|
|
|
|
eval($sScript);
|
|
|
|
|
|
$this->scriptExecutionTime = round(microtime(true) -
|
|
|
|
|
|
$_SESSION['_DATA_TRIGGER_']['_EXECUTION_TIME_'], 5);
|
2015-11-27 11:48:24 -04:00
|
|
|
|
$this->evaluateVariable();
|
2012-07-03 17:54:36 -04:00
|
|
|
|
ob_end_flush();
|
2017-04-19 11:30:54 -04:00
|
|
|
|
|
|
|
|
|
|
//log trigger execution in processmaker.log
|
|
|
|
|
|
G::logTriggerExecution($_SESSION, '', '', $this->scriptExecutionTime);
|
|
|
|
|
|
unset($_SESSION['_CODE_']);
|
|
|
|
|
|
unset($_SESSION['_DATA_TRIGGER_']);
|
2012-07-03 17:54:36 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* Execute the current script
|
2012-10-09 12:59:01 -04:00
|
|
|
|
*
|
2012-07-03 17:54:36 -04:00
|
|
|
|
* @return void
|
|
|
|
|
|
*/
|
2012-10-09 12:59:01 -04:00
|
|
|
|
public function execute ()
|
2012-07-03 17:54:36 -04:00
|
|
|
|
{
|
|
|
|
|
|
$sScript = "";
|
|
|
|
|
|
$iAux = 0;
|
2016-11-17 06:54:34 -05:00
|
|
|
|
$iOcurrences = preg_match_all( $this->sRegexp, $this->sScript, $aMatch, PREG_PATTERN_ORDER | PREG_OFFSET_CAPTURE );
|
2012-07-03 17:54:36 -04:00
|
|
|
|
if ($iOcurrences) {
|
2012-10-09 12:59:01 -04:00
|
|
|
|
for ($i = 0; $i < $iOcurrences; $i ++) {
|
2014-08-29 15:44:41 -04:00
|
|
|
|
$bEqual = false;
|
2012-10-09 12:59:01 -04:00
|
|
|
|
$sAux = substr( $this->sScript, $iAux, $aMatch[0][$i][1] - $iAux );
|
|
|
|
|
|
if (! $bEqual) {
|
2014-08-29 15:44:41 -04:00
|
|
|
|
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) {
|
2012-07-03 17:54:36 -04:00
|
|
|
|
$bEqual = false;
|
|
|
|
|
|
} else {
|
2014-08-29 15:44:41 -04:00
|
|
|
|
if (strpos($sAux, "=") !== false || strpos($sAux, "+=") !== false || strpos($sAux, "-=") !== false || strpos($sAux, "*=") !== false || strpos($sAux, "/=") !== false || strpos($sAux, "%=") !== false || strpos($sAux, ".=") !== false) {
|
2012-07-03 17:54:36 -04:00
|
|
|
|
$bEqual = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
if ($bEqual) {
|
2012-10-09 12:59:01 -04:00
|
|
|
|
if (strpos( $sAux, ';' ) !== false) {
|
2012-07-03 17:54:36 -04:00
|
|
|
|
$bEqual = false;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
if ($bEqual) {
|
2012-10-09 12:59:01 -04:00
|
|
|
|
if (! isset( $aMatch[5][$i][0] )) {
|
2016-11-17 06:54:34 -05:00
|
|
|
|
eval( "if (!isset(\$this->aFields['" . $aMatch[2][$i][0] . "'])) { \$this->aFields['" . $aMatch[2][$i][0] . "'] = " . ($aMatch[1][$i][0] == "&" ? "new stdclass()" : "null") . "; }" );
|
2012-07-03 17:54:36 -04:00
|
|
|
|
} else {
|
2016-11-17 06:54:34 -05:00
|
|
|
|
if ($aMatch[1][$i][0] == "&") {
|
|
|
|
|
|
eval( "if (!isset(\$this->aFields['" . $aMatch[2][$i][0] . "'])) { \$this->aFields['" . $aMatch[2][$i][0] . "'] = new stdclass(); }" );
|
|
|
|
|
|
}
|
2012-10-09 12:59:01 -04:00
|
|
|
|
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; }" );
|
2012-07-03 17:54:36 -04:00
|
|
|
|
}
|
2016-11-23 10:21:43 -05:00
|
|
|
|
} else {
|
|
|
|
|
|
if ($aMatch[1][$i][0] == "&") {
|
|
|
|
|
|
eval( "if (!isset(\$this->aFields['" . $aMatch[2][$i][0] . "'])) { \$this->aFields['" . $aMatch[2][$i][0] . "'] = new stdclass(); }" );
|
|
|
|
|
|
}
|
2012-07-03 17:54:36 -04:00
|
|
|
|
}
|
|
|
|
|
|
$sScript .= $sAux;
|
2012-10-09 12:59:01 -04:00
|
|
|
|
$iAux = $aMatch[0][$i][1] + strlen( $aMatch[0][$i][0] );
|
2012-07-03 17:54:36 -04:00
|
|
|
|
switch ($aMatch[1][$i][0]) {
|
|
|
|
|
|
case '@':
|
|
|
|
|
|
if ($bEqual) {
|
2012-10-09 12:59:01 -04:00
|
|
|
|
if (! isset( $aMatch[5][$i][0] )) {
|
2012-07-03 17:54:36 -04:00
|
|
|
|
$sScript .= "pmToString(\$this->aFields['" . $aMatch[2][$i][0] . "'])";
|
|
|
|
|
|
} else {
|
2012-10-09 12:59:01 -04:00
|
|
|
|
$sScript .= "pmToString(\$this->aFields" . (isset( $aMatch[2][$i][0] ) ? "['" . $aMatch[2][$i][0] . "']" : '') . $aMatch[5][$i][0] . ")";
|
2012-07-03 17:54:36 -04:00
|
|
|
|
}
|
|
|
|
|
|
} else {
|
2012-10-09 12:59:01 -04:00
|
|
|
|
if (! isset( $aMatch[5][$i][0] )) {
|
2012-07-03 17:54:36 -04:00
|
|
|
|
$sScript .= "\$this->aFields['" . $aMatch[2][$i][0] . "']";
|
|
|
|
|
|
} else {
|
2012-10-09 12:59:01 -04:00
|
|
|
|
$sScript .= "\$this->aFields" . (isset( $aMatch[2][$i][0] ) ? "['" . $aMatch[2][$i][0] . "']" : '') . $aMatch[5][$i][0];
|
2012-07-03 17:54:36 -04:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
break;
|
|
|
|
|
|
case '%':
|
|
|
|
|
|
if ($bEqual) {
|
2012-10-09 12:59:01 -04:00
|
|
|
|
if (! isset( $aMatch[5][$i][0] )) {
|
2012-07-03 17:54:36 -04:00
|
|
|
|
$sScript .= "pmToInteger(\$this->aFields['" . $aMatch[2][$i][0] . "'])";
|
|
|
|
|
|
} else {
|
2012-10-09 12:59:01 -04:00
|
|
|
|
$sScript .= "pmToInteger(\$this->aFields" . (isset( $aMatch[2][$i][0] ) ? "['" . $aMatch[2][$i][0] . "']" : '') . $aMatch[5][$i][0] . ")";
|
2012-07-03 17:54:36 -04:00
|
|
|
|
}
|
|
|
|
|
|
} else {
|
2012-10-09 12:59:01 -04:00
|
|
|
|
if (! isset( $aMatch[5][$i][0] )) {
|
2012-07-03 17:54:36 -04:00
|
|
|
|
$sScript .= "\$this->aFields['" . $aMatch[2][$i][0] . "']";
|
|
|
|
|
|
} else {
|
2012-10-09 12:59:01 -04:00
|
|
|
|
$sScript .= "\$this->aFields" . (isset( $aMatch[2][$i][0] ) ? "['" . $aMatch[2][$i][0] . "']" : '') . $aMatch[5][$i][0];
|
2012-07-03 17:54:36 -04:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
break;
|
|
|
|
|
|
case '#':
|
|
|
|
|
|
if ($bEqual) {
|
2012-10-09 12:59:01 -04:00
|
|
|
|
if (! isset( $aMatch[5][$i][0] )) {
|
2012-07-03 17:54:36 -04:00
|
|
|
|
$sScript .= "pmToFloat(\$this->aFields['" . $aMatch[2][$i][0] . "'])";
|
|
|
|
|
|
} else {
|
2012-10-09 12:59:01 -04:00
|
|
|
|
$sScript .= "pmToFloat(\$this->aFields" . (isset( $aMatch[2][$i][0] ) ? "['" . $aMatch[2][$i][0] . "']" : '') . $aMatch[5][$i][0] . ")";
|
2012-07-03 17:54:36 -04:00
|
|
|
|
}
|
|
|
|
|
|
} else {
|
2012-10-09 12:59:01 -04:00
|
|
|
|
if (! isset( $aMatch[5][$i][0] )) {
|
2012-07-03 17:54:36 -04:00
|
|
|
|
$sScript .= "\$this->aFields['" . $aMatch[2][$i][0] . "']";
|
|
|
|
|
|
} else {
|
2012-10-09 12:59:01 -04:00
|
|
|
|
$sScript .= "\$this->aFields" . (isset( $aMatch[2][$i][0] ) ? "['" . $aMatch[2][$i][0] . "']" : '') . $aMatch[5][$i][0];
|
2012-07-03 17:54:36 -04:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
break;
|
|
|
|
|
|
case '?':
|
|
|
|
|
|
if ($bEqual) {
|
2012-10-09 12:59:01 -04:00
|
|
|
|
if (! isset( $aMatch[5][$i][0] )) {
|
2012-07-03 17:54:36 -04:00
|
|
|
|
$sScript .= "pmToUrl(\$this->aFields['" . $aMatch[2][$i][0] . "'])";
|
|
|
|
|
|
} else {
|
2012-10-09 12:59:01 -04:00
|
|
|
|
$sScript .= "pmToUrl(\$this->aFields" . (isset( $aMatch[2][$i][0] ) ? "['" . $aMatch[2][$i][0] . "']" : '') . $aMatch[5][$i][0] . ")";
|
2012-07-03 17:54:36 -04:00
|
|
|
|
}
|
|
|
|
|
|
} else {
|
2012-10-09 12:59:01 -04:00
|
|
|
|
if (! isset( $aMatch[5][$i][0] )) {
|
2012-07-03 17:54:36 -04:00
|
|
|
|
$sScript .= "\$this->aFields['" . $aMatch[2][$i][0] . "']";
|
|
|
|
|
|
} else {
|
2012-10-09 12:59:01 -04:00
|
|
|
|
$sScript .= "\$this->aFields" . (isset( $aMatch[2][$i][0] ) ? "['" . $aMatch[2][$i][0] . "']" : '') . $aMatch[5][$i][0];
|
2012-07-03 17:54:36 -04:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
break;
|
|
|
|
|
|
case '$':
|
|
|
|
|
|
if ($bEqual) {
|
2012-10-09 12:59:01 -04:00
|
|
|
|
if (! isset( $aMatch[5][$i][0] )) {
|
2012-07-03 17:54:36 -04:00
|
|
|
|
$sScript .= "pmSqlEscape(\$this->aFields['" . $aMatch[2][$i][0] . "'])";
|
|
|
|
|
|
} else {
|
2012-10-09 12:59:01 -04:00
|
|
|
|
$sScript .= "pmSqlEscape(\$this->aFields" . (isset( $aMatch[2][$i][0] ) ? "['" . $aMatch[2][$i][0] . "']" : '') . $aMatch[5][$i][0] . ")";
|
2012-07-03 17:54:36 -04:00
|
|
|
|
}
|
|
|
|
|
|
} else {
|
2012-10-09 12:59:01 -04:00
|
|
|
|
if (! isset( $aMatch[5][$i][0] )) {
|
2012-07-03 17:54:36 -04:00
|
|
|
|
$sScript .= "\$this->aFields['" . $aMatch[2][$i][0] . "']";
|
|
|
|
|
|
} else {
|
2012-10-09 12:59:01 -04:00
|
|
|
|
$sScript .= "\$this->aFields" . (isset( $aMatch[2][$i][0] ) ? "['" . $aMatch[2][$i][0] . "']" : '') . $aMatch[5][$i][0];
|
2012-07-03 17:54:36 -04:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
break;
|
|
|
|
|
|
case '=':
|
2016-11-17 06:54:34 -05:00
|
|
|
|
case '&':
|
2012-07-03 17:54:36 -04:00
|
|
|
|
if ($bEqual) {
|
2012-10-09 12:59:01 -04:00
|
|
|
|
if (! isset( $aMatch[5][$i][0] )) {
|
2012-07-03 17:54:36 -04:00
|
|
|
|
$sScript .= "\$this->aFields['" . $aMatch[2][$i][0] . "']";
|
|
|
|
|
|
} else {
|
2012-10-09 12:59:01 -04:00
|
|
|
|
$sScript .= "\$this->aFields" . (isset( $aMatch[2][$i][0] ) ? "['" . $aMatch[2][$i][0] . "']" : '') . $aMatch[5][$i][0];
|
2012-07-03 17:54:36 -04:00
|
|
|
|
}
|
|
|
|
|
|
} else {
|
2012-10-09 12:59:01 -04:00
|
|
|
|
if (! isset( $aMatch[5][$i][0] )) {
|
2012-07-03 17:54:36 -04:00
|
|
|
|
$sScript .= "\$this->aFields['" . $aMatch[2][$i][0] . "']";
|
|
|
|
|
|
} else {
|
2012-10-09 12:59:01 -04:00
|
|
|
|
$sScript .= "\$this->aFields" . (isset( $aMatch[2][$i][0] ) ? "['" . $aMatch[2][$i][0] . "']" : '') . $aMatch[5][$i][0];
|
2012-07-03 17:54:36 -04:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
$this->affected_fields[] = $aMatch[2][$i][0];
|
|
|
|
|
|
}
|
2010-12-02 23:34:41 +00:00
|
|
|
|
}
|
2012-10-09 12:59:01 -04:00
|
|
|
|
$sScript .= substr( $this->sScript, $iAux );
|
|
|
|
|
|
$sScript = "try {\n" . $sScript . "\n} catch (Exception \$oException) {\n " . " \$this->aFields['__ERROR__'] = utf8_encode(\$oException->getMessage());\n}";
|
2012-07-03 17:54:36 -04:00
|
|
|
|
//echo '<pre>-->'; print_r($this->aFields); echo '<---</pre>';
|
2016-07-19 14:26:51 -04:00
|
|
|
|
|
|
|
|
|
|
$this->executeAndCatchErrors($sScript, $this->sScript);
|
|
|
|
|
|
|
2015-07-27 15:13:45 -04:00
|
|
|
|
$this->aFields["__VAR_CHANGED__"] = implode(",", $this->affected_fields);
|
2012-10-09 12:59:01 -04:00
|
|
|
|
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]] : ''
|
2012-07-03 17:54:36 -04:00
|
|
|
|
);
|
2010-12-02 23:34:41 +00:00
|
|
|
|
}
|
2012-07-03 17:54:36 -04:00
|
|
|
|
//echo '<pre>-->'; print_r($_SESSION['TRIGGER_DEBUG']['DATA']); echo '<---</pre>';
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* Evaluate the current script
|
2012-10-09 12:59:01 -04:00
|
|
|
|
*
|
2016-08-02 11:22:27 -04:00
|
|
|
|
* @return boolean
|
2012-07-03 17:54:36 -04:00
|
|
|
|
*/
|
2012-10-09 12:59:01 -04:00
|
|
|
|
public function evaluate ()
|
2012-07-03 17:54:36 -04:00
|
|
|
|
{
|
|
|
|
|
|
$bResult = null;
|
|
|
|
|
|
$sScript = '';
|
|
|
|
|
|
$iAux = 0;
|
|
|
|
|
|
$bEqual = false;
|
|
|
|
|
|
$variableIsDefined = true;
|
2016-11-17 06:54:34 -05:00
|
|
|
|
$iOcurrences = preg_match_all( $this->sRegexp, $this->sScript, $aMatch, PREG_PATTERN_ORDER | PREG_OFFSET_CAPTURE );
|
2012-07-03 17:54:36 -04:00
|
|
|
|
if ($iOcurrences) {
|
2012-10-09 12:59:01 -04:00
|
|
|
|
for ($i = 0; $i < $iOcurrences; $i ++) {
|
2012-07-03 17:54:36 -04:00
|
|
|
|
// if the variables for that condition has not been previously defined then $variableIsDefined
|
|
|
|
|
|
// is set to false
|
2013-04-22 13:31:19 -04:00
|
|
|
|
if (!isset($this->aFields[$aMatch[2][$i][0]]) && !isset($aMatch[5][$i][0])) {
|
2016-11-17 06:54:34 -05:00
|
|
|
|
eval( "if (!isset(\$this->aFields['" . $aMatch[2][$i][0] . "'])) { \$this->aFields['" . $aMatch[2][$i][0] . "'] = " . ($aMatch[1][$i][0] == "&" ? "new stdclass()" : "null") . "; }" );
|
2013-04-22 13:31:19 -04:00
|
|
|
|
} else {
|
2016-11-17 06:54:34 -05:00
|
|
|
|
if ($aMatch[1][$i][0] == "&") {
|
|
|
|
|
|
eval( "if (!isset(\$this->aFields['" . $aMatch[2][$i][0] . "'])) { \$this->aFields['" . $aMatch[2][$i][0] . "'] = new stdclass(); }" );
|
|
|
|
|
|
}
|
2013-04-22 13:31:19 -04:00
|
|
|
|
if (!isset($this->aFields[$aMatch[2][$i][0]])) {
|
|
|
|
|
|
eval("\$this->aFields['" . $aMatch[2][$i][0] . "']" . $aMatch[5][$i][0] . " = '';");
|
2016-11-17 06:54:34 -05:00
|
|
|
|
|
2013-04-24 15:36:08 -04:00
|
|
|
|
} else {
|
2013-05-02 16:24:25 -04:00
|
|
|
|
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 {
|
2016-11-17 06:54:34 -05:00
|
|
|
|
eval("if (!isset(\$this->aFields['" . $aMatch[2][$i][0] . "'])) {\$this->aFields['" . $aMatch[2][$i][0] . "'] = " . ($aMatch[1][$i][0] == "&" ? "new stdclass()" : "''") . ";}");
|
2013-05-02 16:24:25 -04:00
|
|
|
|
}
|
2013-04-22 13:31:19 -04:00
|
|
|
|
}
|
2012-07-03 17:54:36 -04:00
|
|
|
|
}
|
2012-10-09 12:59:01 -04:00
|
|
|
|
$sAux = substr( $this->sScript, $iAux, $aMatch[0][$i][1] - $iAux );
|
|
|
|
|
|
if (! $bEqual) {
|
|
|
|
|
|
if (strpos( $sAux, '=' ) !== false) {
|
2012-07-03 17:54:36 -04:00
|
|
|
|
$bEqual = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
if ($bEqual) {
|
2012-10-09 12:59:01 -04:00
|
|
|
|
if (strpos( $sAux, ';' ) !== false) {
|
2012-07-03 17:54:36 -04:00
|
|
|
|
$bEqual = false;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
$sScript .= $sAux;
|
2012-10-09 12:59:01 -04:00
|
|
|
|
$iAux = $aMatch[0][$i][1] + strlen( $aMatch[0][$i][0] );
|
2012-07-03 17:54:36 -04:00
|
|
|
|
switch ($aMatch[1][$i][0]) {
|
|
|
|
|
|
case '@':
|
|
|
|
|
|
if ($bEqual) {
|
2012-10-09 12:59:01 -04:00
|
|
|
|
if (! isset( $aMatch[5][$i][0] )) {
|
2012-07-03 17:54:36 -04:00
|
|
|
|
$sScript .= "pmToString(\$this->aFields['" . $aMatch[2][$i][0] . "'])";
|
|
|
|
|
|
} else {
|
2012-10-09 12:59:01 -04:00
|
|
|
|
$sScript .= "pmToString(\$this->aFields" . (isset( $aMatch[2][$i][0] ) ? "['" . $aMatch[2][$i][0] . "']" : '') . $aMatch[5][$i][0] . ")";
|
2012-07-03 17:54:36 -04:00
|
|
|
|
}
|
|
|
|
|
|
} else {
|
2012-10-09 12:59:01 -04:00
|
|
|
|
if (! isset( $aMatch[5][$i][0] )) {
|
2012-07-03 17:54:36 -04:00
|
|
|
|
$sScript .= "\$this->aFields['" . $aMatch[2][$i][0] . "']";
|
|
|
|
|
|
} else {
|
2012-10-09 12:59:01 -04:00
|
|
|
|
$sScript .= "\$this->aFields" . (isset( $aMatch[2][$i][0] ) ? "['" . $aMatch[2][$i][0] . "']" : '') . $aMatch[5][$i][0];
|
2012-07-03 17:54:36 -04:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
break;
|
|
|
|
|
|
case '%':
|
|
|
|
|
|
if ($bEqual) {
|
2012-10-09 12:59:01 -04:00
|
|
|
|
if (! isset( $aMatch[5][$i][0] )) {
|
2012-07-03 17:54:36 -04:00
|
|
|
|
$sScript .= "pmToInteger(\$this->aFields['" . $aMatch[2][$i][0] . "'])";
|
|
|
|
|
|
} else {
|
2012-10-09 12:59:01 -04:00
|
|
|
|
$sScript .= "pmToInteger(\$this->aFields" . (isset( $aMatch[2][$i][0] ) ? "['" . $aMatch[2][$i][0] . "']" : '') . $aMatch[5][$i][0] . ")";
|
2012-07-03 17:54:36 -04:00
|
|
|
|
}
|
|
|
|
|
|
} else {
|
2012-10-09 12:59:01 -04:00
|
|
|
|
if (! isset( $aMatch[5][$i][0] )) {
|
2012-07-03 17:54:36 -04:00
|
|
|
|
$sScript .= "\$this->aFields['" . $aMatch[2][$i][0] . "']";
|
|
|
|
|
|
} else {
|
2012-10-09 12:59:01 -04:00
|
|
|
|
$sScript .= "\$this->aFields" . (isset( $aMatch[2][$i][0] ) ? "['" . $aMatch[2][$i][0] . "']" : '') . $aMatch[5][$i][0];
|
2012-07-03 17:54:36 -04:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
break;
|
|
|
|
|
|
case '#':
|
|
|
|
|
|
if ($bEqual) {
|
2012-10-09 12:59:01 -04:00
|
|
|
|
if (! isset( $aMatch[5][$i][0] )) {
|
2012-07-03 17:54:36 -04:00
|
|
|
|
$sScript .= "pmToFloat(\$this->aFields['" . $aMatch[2][$i][0] . "'])";
|
|
|
|
|
|
} else {
|
2012-10-09 12:59:01 -04:00
|
|
|
|
$sScript .= "pmToFloat(\$this->aFields" . (isset( $aMatch[2][$i][0] ) ? "['" . $aMatch[2][$i][0] . "']" : '') . $aMatch[5][$i][0] . ")";
|
2012-07-03 17:54:36 -04:00
|
|
|
|
}
|
|
|
|
|
|
} else {
|
2012-10-09 12:59:01 -04:00
|
|
|
|
if (! isset( $aMatch[5][$i][0] )) {
|
2012-07-03 17:54:36 -04:00
|
|
|
|
$sScript .= "\$this->aFields['" . $aMatch[2][$i][0] . "']";
|
|
|
|
|
|
} else {
|
2012-10-09 12:59:01 -04:00
|
|
|
|
$sScript .= "\$this->aFields" . (isset( $aMatch[2][$i][0] ) ? "['" . $aMatch[2][$i][0] . "']" : '') . $aMatch[5][$i][0];
|
2012-07-03 17:54:36 -04:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
break;
|
|
|
|
|
|
case '?':
|
|
|
|
|
|
if ($bEqual) {
|
2012-10-09 12:59:01 -04:00
|
|
|
|
if (! isset( $aMatch[5][$i][0] )) {
|
2012-07-03 17:54:36 -04:00
|
|
|
|
$sScript .= "pmToUrl(\$this->aFields['" . $aMatch[2][$i][0] . "'])";
|
|
|
|
|
|
} else {
|
2012-10-09 12:59:01 -04:00
|
|
|
|
$sScript .= "pmToUrl(\$this->aFields" . (isset( $aMatch[2][$i][0] ) ? "['" . $aMatch[2][$i][0] . "']" : '') . $aMatch[5][$i][0] . ")";
|
2012-07-03 17:54:36 -04:00
|
|
|
|
}
|
|
|
|
|
|
} else {
|
2012-10-09 12:59:01 -04:00
|
|
|
|
if (! isset( $aMatch[5][$i][0] )) {
|
2012-07-03 17:54:36 -04:00
|
|
|
|
$sScript .= "\$this->aFields['" . $aMatch[2][$i][0] . "']";
|
|
|
|
|
|
} else {
|
2012-10-09 12:59:01 -04:00
|
|
|
|
$sScript .= "\$this->aFields" . (isset( $aMatch[2][$i][0] ) ? "['" . $aMatch[2][$i][0] . "']" : '') . $aMatch[5][$i][0];
|
2012-07-03 17:54:36 -04:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
break;
|
|
|
|
|
|
case '$':
|
|
|
|
|
|
if ($bEqual) {
|
2012-10-09 12:59:01 -04:00
|
|
|
|
if (! isset( $aMatch[5][$i][0] )) {
|
2012-07-03 17:54:36 -04:00
|
|
|
|
$sScript .= "pmSqlEscape(\$this->aFields['" . $aMatch[2][$i][0] . "'])";
|
|
|
|
|
|
} else {
|
2012-10-09 12:59:01 -04:00
|
|
|
|
$sScript .= "pmSqlEscape(\$this->aFields" . (isset( $aMatch[2][$i][0] ) ? "['" . $aMatch[2][$i][0] . "']" : '') . $aMatch[5][$i][0] . ")";
|
2012-07-03 17:54:36 -04:00
|
|
|
|
}
|
|
|
|
|
|
} else {
|
2012-10-09 12:59:01 -04:00
|
|
|
|
if (! isset( $aMatch[5][$i][0] )) {
|
2012-07-03 17:54:36 -04:00
|
|
|
|
$sScript .= "\$this->aFields['" . $aMatch[2][$i][0] . "']";
|
|
|
|
|
|
} else {
|
2012-10-09 12:59:01 -04:00
|
|
|
|
$sScript .= "\$this->aFields" . (isset( $aMatch[2][$i][0] ) ? "['" . $aMatch[2][$i][0] . "']" : '') . $aMatch[5][$i][0];
|
2012-07-03 17:54:36 -04:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
break;
|
|
|
|
|
|
case '=':
|
2016-11-17 06:54:34 -05:00
|
|
|
|
case '&':
|
2012-07-03 17:54:36 -04:00
|
|
|
|
if ($bEqual) {
|
2012-10-09 12:59:01 -04:00
|
|
|
|
if (! isset( $aMatch[5][$i][0] )) {
|
2012-07-03 17:54:36 -04:00
|
|
|
|
$sScript .= "\$this->aFields['" . $aMatch[2][$i][0] . "']";
|
|
|
|
|
|
} else {
|
2012-10-09 12:59:01 -04:00
|
|
|
|
$sScript .= "\$this->aFields" . (isset( $aMatch[2][$i][0] ) ? "['" . $aMatch[2][$i][0] . "']" : '') . $aMatch[5][$i][0];
|
2012-07-03 17:54:36 -04:00
|
|
|
|
}
|
|
|
|
|
|
} else {
|
2012-10-09 12:59:01 -04:00
|
|
|
|
if (! isset( $aMatch[5][$i][0] )) {
|
2012-07-03 17:54:36 -04:00
|
|
|
|
$sScript .= "\$this->aFields['" . $aMatch[2][$i][0] . "']";
|
|
|
|
|
|
} else {
|
2012-10-09 12:59:01 -04:00
|
|
|
|
$sScript .= "\$this->aFields" . (isset( $aMatch[2][$i][0] ) ? "['" . $aMatch[2][$i][0] . "']" : '') . $aMatch[5][$i][0];
|
2012-07-03 17:54:36 -04:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
2010-12-02 23:34:41 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2012-10-09 12:59:01 -04:00
|
|
|
|
$sScript .= substr( $this->sScript, $iAux );
|
2015-02-20 13:10:58 -04:00
|
|
|
|
if(preg_match('/\b(or|and|xor)\b/i' , $sScript)) {
|
|
|
|
|
|
$sScript = "( ".$sScript." )";
|
2015-06-01 13:58:50 -04:00
|
|
|
|
}
|
2012-07-03 17:54:36 -04:00
|
|
|
|
$sScript = '$bResult = ' . $sScript . ';';
|
|
|
|
|
|
// checks if the syntax is valid or if the variables in that condition has been previously defined
|
2012-10-09 12:59:01 -04:00
|
|
|
|
if ($this->validSyntax( $sScript ) && $variableIsDefined) {
|
2012-07-03 17:54:36 -04:00
|
|
|
|
$this->bError = false;
|
2012-10-09 12:59:01 -04:00
|
|
|
|
eval( $sScript );
|
2012-07-03 17:54:36 -04:00
|
|
|
|
} else {
|
|
|
|
|
|
// echo "<script> alert('".G::loadTranslation('MSG_CONDITION_NOT_DEFINED')."'); </script>";
|
2012-10-09 12:59:01 -04:00
|
|
|
|
G::SendTemporalMessage( 'MSG_CONDITION_NOT_DEFINED', 'error', 'labels' );
|
2012-07-03 17:54:36 -04:00
|
|
|
|
$this->bError = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
return $bResult;
|
2010-12-02 23:34:41 +00:00
|
|
|
|
}
|
2016-07-19 14:26:51 -04:00
|
|
|
|
|
2015-11-27 11:48:24 -04:00
|
|
|
|
Public function evaluateVariable ()
|
|
|
|
|
|
{
|
|
|
|
|
|
$process = new Process();
|
|
|
|
|
|
if(!$process->isBpmnProcess($_SESSION['PROCESS'])) {
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
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);
|
|
|
|
|
|
$variables = $this->affected_fields;
|
2016-03-02 15:33:15 -04:00
|
|
|
|
$variables = (is_array($variables))? array_unique($variables) : $variables;
|
2015-11-27 11:48:24 -04:00
|
|
|
|
$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]) ) {
|
2016-07-19 14:26:51 -04:00
|
|
|
|
$varLabel = $var.'_label';
|
2015-11-27 11:48:24 -04:00
|
|
|
|
$arrayValue = $this->aFields[$var];
|
|
|
|
|
|
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)) {
|
|
|
|
|
|
$varType = $varInfo['VAR_FIELD_TYPE'];
|
|
|
|
|
|
switch($varType) {
|
|
|
|
|
|
case 'array':
|
2016-07-19 14:26:51 -04:00
|
|
|
|
$arrayLabels = '["'.implode('","',$arrayLabels).'"]';
|
2015-11-27 11:48:24 -04:00
|
|
|
|
$newFields[$var] = $arrayValues;
|
|
|
|
|
|
$newFields[$varLabel] = $arrayLabels;
|
|
|
|
|
|
break;
|
|
|
|
|
|
case 'string':
|
|
|
|
|
|
$newFields[$var] = $arrayValues[0];
|
|
|
|
|
|
$newFields[$varLabel] = $arrayLabels[0];
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
2016-07-19 14:26:51 -04:00
|
|
|
|
$this->affected_fields[] = $varLabel;
|
2015-11-27 11:48:24 -04:00
|
|
|
|
$this->aFields = array_merge($this->aFields,$newFields);
|
|
|
|
|
|
unset($newFields);
|
|
|
|
|
|
unset($arrayValues);
|
|
|
|
|
|
unset($arrayLabels);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2015-12-07 17:53:33 -04:00
|
|
|
|
if (isset($this->aFields[$var]) && is_string($this->aFields[$var])) {
|
|
|
|
|
|
$varInfo = $variableModule->getVariableTypeByName($_SESSION['PROCESS'], $var);
|
|
|
|
|
|
$options = G::json_decode($varInfo["VAR_ACCEPTED_VALUES"]);
|
|
|
|
|
|
$no = count($options);
|
|
|
|
|
|
for ($io = 0; $io < $no; $io++) {
|
|
|
|
|
|
if ($options[$io]->value === $this->aFields[$var]) {
|
|
|
|
|
|
$this->aFields[$var . "_label"] = $options[$io]->label;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
if ($varInfo["VAR_DBCONNECTION"] !== "" && $varInfo["VAR_DBCONNECTION"] !== "none" && $varInfo["VAR_SQL"] !== "") {
|
|
|
|
|
|
try {
|
|
|
|
|
|
$cnn = Propel::getConnection($varInfo["VAR_DBCONNECTION"]);
|
|
|
|
|
|
$stmt = $cnn->createStatement();
|
|
|
|
|
|
$sql = G::replaceDataField($varInfo["VAR_SQL"], $this->aFields);
|
|
|
|
|
|
$rs = $stmt->executeQuery($sql, \ResultSet::FETCHMODE_NUM);
|
|
|
|
|
|
while ($rs->next()) {
|
|
|
|
|
|
$row = $rs->getRow();
|
|
|
|
|
|
if ($row[0] === $this->aFields[$var]) {
|
|
|
|
|
|
$this->aFields[$var . "_label"] = isset($row[1]) ? $row[1] : $row[0];
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
} catch (Exception $e) {
|
2016-07-19 14:26:51 -04:00
|
|
|
|
|
2015-12-07 17:53:33 -04:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2015-11-27 11:48:24 -04:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2016-07-19 14:26:51 -04:00
|
|
|
|
}
|
2015-11-27 11:48:24 -04:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2010-12-02 23:34:41 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//Start - Private functions
|
|
|
|
|
|
|
2012-10-09 12:59:01 -04:00
|
|
|
|
|
2010-12-02 23:34:41 +00:00
|
|
|
|
/**
|
|
|
|
|
|
* Convert to string
|
2012-10-09 12:59:01 -04:00
|
|
|
|
*
|
2010-12-02 23:34:41 +00:00
|
|
|
|
* @param variant $vValue
|
|
|
|
|
|
* @return string
|
|
|
|
|
|
*/
|
2012-10-09 12:59:01 -04:00
|
|
|
|
function pmToString ($vValue)
|
2010-12-02 23:34:41 +00:00
|
|
|
|
{
|
2012-07-03 17:54:36 -04:00
|
|
|
|
return (string) $vValue;
|
2010-12-02 23:34:41 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* Convert to integer
|
2012-10-09 12:59:01 -04:00
|
|
|
|
*
|
2010-12-02 23:34:41 +00:00
|
|
|
|
* @param variant $vValue
|
|
|
|
|
|
* @return integer
|
|
|
|
|
|
*/
|
2012-10-09 12:59:01 -04:00
|
|
|
|
function pmToInteger ($vValue)
|
2010-12-02 23:34:41 +00:00
|
|
|
|
{
|
2012-07-03 17:54:36 -04:00
|
|
|
|
return (int) $vValue;
|
2010-12-02 23:34:41 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* Convert to float
|
2012-10-09 12:59:01 -04:00
|
|
|
|
*
|
2010-12-02 23:34:41 +00:00
|
|
|
|
* @param variant $vValue
|
|
|
|
|
|
* @return float
|
|
|
|
|
|
*/
|
2012-10-09 12:59:01 -04:00
|
|
|
|
function pmToFloat ($vValue)
|
2010-12-02 23:34:41 +00:00
|
|
|
|
{
|
2012-07-03 17:54:36 -04:00
|
|
|
|
return (float) $vValue;
|
2010-12-02 23:34:41 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* Convert to Url
|
2012-10-09 12:59:01 -04:00
|
|
|
|
*
|
2010-12-02 23:34:41 +00:00
|
|
|
|
* @param variant $vValue
|
|
|
|
|
|
* @return url
|
|
|
|
|
|
*/
|
2012-10-09 12:59:01 -04:00
|
|
|
|
function pmToUrl ($vValue)
|
2010-12-02 23:34:41 +00:00
|
|
|
|
{
|
2012-10-09 12:59:01 -04:00
|
|
|
|
return urlencode( $vValue );
|
2010-12-02 23:34:41 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* Convert to data base escaped string
|
2012-10-09 12:59:01 -04:00
|
|
|
|
*
|
2010-12-02 23:34:41 +00:00
|
|
|
|
* @param variant $vValue
|
|
|
|
|
|
* @return string
|
|
|
|
|
|
*/
|
2012-10-09 12:59:01 -04:00
|
|
|
|
function pmSqlEscape ($vValue)
|
2010-12-02 23:34:41 +00:00
|
|
|
|
{
|
2012-10-09 12:59:01 -04:00
|
|
|
|
return G::sqlEscape( $vValue );
|
2010-12-02 23:34:41 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//End - Private functions
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-07-03 17:54:36 -04:00
|
|
|
|
/* * *************************************************************************
|
|
|
|
|
|
* Error handler
|
|
|
|
|
|
* author: Julio Cesar Laura Avenda<EFBFBD>o <juliocesar@colosa.com>
|
|
|
|
|
|
* date: 2009-10-01
|
|
|
|
|
|
* ************************************************************************* */
|
2017-04-19 11:30:54 -04:00
|
|
|
|
/**
|
|
|
|
|
|
* @param $errno
|
|
|
|
|
|
* @param $errstr
|
|
|
|
|
|
* @param $errfile
|
|
|
|
|
|
* @param $errline
|
2010-12-02 23:34:41 +00:00
|
|
|
|
*/
|
2017-04-19 11:30:54 -04:00
|
|
|
|
function handleErrors($errno, $errstr, $errfile, $errline)
|
2010-12-02 23:34:41 +00:00
|
|
|
|
{
|
2017-04-19 11:30:54 -04:00
|
|
|
|
if ($errno != 2048 && isset($_SESSION['_DATA_TRIGGER_']['_EXECUTION_TIME_'])) {
|
|
|
|
|
|
G::logTriggerExecution($_SESSION, $errstr, '', round(microtime(true) -
|
|
|
|
|
|
$_SESSION['_DATA_TRIGGER_']['_EXECUTION_TIME_'], 5));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2012-07-03 17:54:36 -04:00
|
|
|
|
if ($errno != '' && ($errno != 8) && ($errno != 2048)) {
|
2012-10-09 12:59:01 -04:00
|
|
|
|
if (isset( $_SESSION['_CODE_'] )) {
|
2012-07-03 17:54:36 -04:00
|
|
|
|
$sCode = $_SESSION['_CODE_'];
|
2012-10-09 12:59:01 -04:00
|
|
|
|
unset( $_SESSION['_CODE_'] );
|
2012-11-19 11:29:17 -04:00
|
|
|
|
global $oPMScript;
|
|
|
|
|
|
if (isset($oPMScript) && isset($_SESSION['APPLICATION'])) {
|
2012-11-19 12:13:26 -04:00
|
|
|
|
G::LoadClass( 'case' );
|
|
|
|
|
|
$oCase = new Cases();
|
2012-11-19 15:45:30 -04:00
|
|
|
|
$oPMScript->aFields['__ERROR__'] = $errstr;
|
2012-11-19 11:29:17 -04:00
|
|
|
|
$oCase->updateCase($_SESSION['APPLICATION'], array('APP_DATA' => $oPMScript->aFields));
|
|
|
|
|
|
}
|
2012-10-09 12:59:01 -04:00
|
|
|
|
registerError( 1, $errstr, $errline - 1, $sCode );
|
2012-07-03 17:54:36 -04:00
|
|
|
|
}
|
2010-12-02 23:34:41 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
* Handle Fatal Errors
|
|
|
|
|
|
* @param variant $buffer
|
|
|
|
|
|
* @return buffer
|
|
|
|
|
|
*/
|
2012-07-03 17:54:36 -04:00
|
|
|
|
|
2012-10-09 12:59:01 -04:00
|
|
|
|
function handleFatalErrors ($buffer)
|
2010-12-02 23:34:41 +00:00
|
|
|
|
{
|
2017-04-19 11:30:54 -04:00
|
|
|
|
if (!empty($buffer)) {
|
|
|
|
|
|
G::logTriggerExecution($_SESSION, $buffer, 'FATAL_ERROR');
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2012-10-09 12:59:01 -04:00
|
|
|
|
if (preg_match( '/(error<\/b>:)(.+)(<br)/', $buffer, $regs )) {
|
2017-04-19 11:30:54 -04:00
|
|
|
|
G::LoadClass( 'case' );
|
|
|
|
|
|
$oCase = new Cases();
|
2012-10-09 12:59:01 -04:00
|
|
|
|
$err = preg_replace( '/<.*?>/', '', $regs[2] );
|
|
|
|
|
|
$aAux = explode( ' in ', $err );
|
2013-10-08 08:59:49 -04:00
|
|
|
|
$sCode = isset($_SESSION['_CODE_']) ? $_SESSION['_CODE_'] : null;
|
2012-10-09 12:59:01 -04:00
|
|
|
|
unset( $_SESSION['_CODE_'] );
|
|
|
|
|
|
registerError( 2, $aAux[0], 0, $sCode );
|
|
|
|
|
|
if (strpos( $_SERVER['REQUEST_URI'], '/cases/cases_Step' ) !== false) {
|
|
|
|
|
|
if (strpos( $_SERVER['REQUEST_URI'], '&ACTION=GENERATE' ) !== false) {
|
|
|
|
|
|
$aNextStep = $oCase->getNextStep( $_SESSION['PROCESS'], $_SESSION['APPLICATION'], $_SESSION['INDEX'], $_SESSION['STEP_POSITION'] );
|
2012-07-03 17:54:36 -04:00
|
|
|
|
if ($_SESSION['TRIGGER_DEBUG']['ISSET']) {
|
2014-02-12 16:08:10 -04:00
|
|
|
|
$_SESSION['TRIGGER_DEBUG']['TIME'] = G::toUpper(G::loadTranslation('ID_AFTER'));
|
2012-07-03 17:54:36 -04:00
|
|
|
|
$_SESSION['TRIGGER_DEBUG']['BREAKPAGE'] = $aNextStep['PAGE'];
|
|
|
|
|
|
$aNextStep['PAGE'] = $aNextStep['PAGE'] . '&breakpoint=triggerdebug';
|
|
|
|
|
|
}
|
2012-11-19 11:29:17 -04:00
|
|
|
|
global $oPMScript;
|
|
|
|
|
|
if (isset($oPMScript) && isset($_SESSION['APPLICATION'])) {
|
2012-11-19 15:16:29 -04:00
|
|
|
|
$oPMScript->aFields['__ERROR__'] = $aAux[0];
|
2012-11-19 11:29:17 -04:00
|
|
|
|
$oCase->updateCase($_SESSION['APPLICATION'], array('APP_DATA' => $oPMScript->aFields));
|
|
|
|
|
|
}
|
2012-10-09 12:59:01 -04:00
|
|
|
|
G::header( 'Location: ' . $aNextStep['PAGE'] );
|
|
|
|
|
|
die();
|
2012-07-03 17:54:36 -04:00
|
|
|
|
}
|
|
|
|
|
|
$_SESSION['_NO_EXECUTE_TRIGGERS_'] = 1;
|
2012-11-19 11:29:17 -04:00
|
|
|
|
global $oPMScript;
|
2012-11-19 12:13:26 -04:00
|
|
|
|
if (isset($oPMScript) && isset($_SESSION['APPLICATION'])) {
|
2012-11-19 15:16:29 -04:00
|
|
|
|
$oPMScript->aFields['__ERROR__'] = $aAux[0];
|
2012-11-19 12:13:26 -04:00
|
|
|
|
$oCase->updateCase($_SESSION['APPLICATION'], array('APP_DATA' => $oPMScript->aFields));
|
|
|
|
|
|
}
|
2012-10-09 12:59:01 -04:00
|
|
|
|
G::header( 'Location: ' . $_SERVER['REQUEST_URI'] );
|
|
|
|
|
|
die();
|
2012-07-03 17:54:36 -04:00
|
|
|
|
} else {
|
2012-10-09 12:59:01 -04:00
|
|
|
|
$aNextStep = $oCase->getNextStep( $_SESSION['PROCESS'], $_SESSION['APPLICATION'], $_SESSION['INDEX'], $_SESSION['STEP_POSITION'] );
|
2013-10-08 08:59:49 -04:00
|
|
|
|
if (isset($_SESSION['TRIGGER_DEBUG']['ISSET']) && $_SESSION['TRIGGER_DEBUG']['ISSET']) {
|
2014-02-12 16:08:10 -04:00
|
|
|
|
$_SESSION['TRIGGER_DEBUG']['TIME'] = G::toUpper(G::loadTranslation('ID_AFTER'));
|
2012-07-03 17:54:36 -04:00
|
|
|
|
$_SESSION['TRIGGER_DEBUG']['BREAKPAGE'] = $aNextStep['PAGE'];
|
|
|
|
|
|
$aNextStep['PAGE'] = $aNextStep['PAGE'] . '&breakpoint=triggerdebug';
|
|
|
|
|
|
}
|
2012-10-09 12:59:01 -04:00
|
|
|
|
if (strpos( $aNextStep['PAGE'], 'TYPE=ASSIGN_TASK&UID=-1' ) !== false) {
|
|
|
|
|
|
G::SendMessageText( 'Fatal error in trigger', 'error' );
|
2012-07-03 17:54:36 -04:00
|
|
|
|
}
|
2012-11-19 11:29:17 -04:00
|
|
|
|
global $oPMScript;
|
|
|
|
|
|
if (isset($oPMScript) && isset($_SESSION['APPLICATION'])) {
|
2012-11-19 15:16:29 -04:00
|
|
|
|
$oPMScript->aFields['__ERROR__'] = $aAux[0];
|
2012-11-19 11:29:17 -04:00
|
|
|
|
$oCase->updateCase($_SESSION['APPLICATION'], array('APP_DATA' => $oPMScript->aFields));
|
|
|
|
|
|
}
|
2012-10-09 12:59:01 -04:00
|
|
|
|
G::header( 'Location: ' . $aNextStep['PAGE'] );
|
|
|
|
|
|
die();
|
2010-12-02 23:34:41 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2012-07-03 17:54:36 -04:00
|
|
|
|
return $buffer;
|
2010-12-02 23:34:41 +00:00
|
|
|
|
}
|
2012-07-03 17:54:36 -04:00
|
|
|
|
|
2010-12-02 23:34:41 +00:00
|
|
|
|
/*
|
|
|
|
|
|
* Register Error
|
|
|
|
|
|
* @param string $iType
|
|
|
|
|
|
* @param string $sError
|
|
|
|
|
|
* @param string $iLine
|
|
|
|
|
|
* @param string $sCode
|
|
|
|
|
|
* @return void
|
|
|
|
|
|
*/
|
2012-07-03 17:54:36 -04:00
|
|
|
|
|
2012-10-09 12:59:01 -04:00
|
|
|
|
function registerError ($iType, $sError, $iLine, $sCode)
|
2010-12-02 23:34:41 +00:00
|
|
|
|
{
|
2012-07-03 17:54:36 -04:00
|
|
|
|
$sType = ($iType == 1 ? 'ERROR' : 'FATAL');
|
2012-10-09 12:59:01 -04:00
|
|
|
|
$_SESSION['TRIGGER_DEBUG']['ERRORS'][][$sType] = $sError . ($iLine > 0 ? ' (line ' . $iLine . ')' : '') . ':<br /><br />' . $sCode;
|
2012-06-12 17:18:57 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* Obtain engine Data Base name
|
|
|
|
|
|
*
|
|
|
|
|
|
* @param type $connection
|
|
|
|
|
|
* @return type
|
|
|
|
|
|
*/
|
2012-10-09 12:59:01 -04:00
|
|
|
|
function getEngineDataBaseName ($connection)
|
2012-06-12 17:18:57 -04:00
|
|
|
|
{
|
2012-07-03 17:54:36 -04:00
|
|
|
|
$aDNS = $connection->getDSN();
|
|
|
|
|
|
return $aDNS["phptype"];
|
2012-06-12 17:18:57 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* Execute Queries for Oracle Database
|
|
|
|
|
|
*
|
|
|
|
|
|
* @param type $sql
|
|
|
|
|
|
* @param type $connection
|
|
|
|
|
|
*/
|
2015-06-01 13:58:50 -04:00
|
|
|
|
function executeQueryOci ($sql, $connection, $aParameter = array(), $dbsEncode = "")
|
2012-06-12 17:18:57 -04:00
|
|
|
|
{
|
2012-07-03 17:54:36 -04:00
|
|
|
|
$aDNS = $connection->getDSN();
|
2014-05-22 10:09:33 -04:00
|
|
|
|
|
2012-07-03 17:54:36 -04:00
|
|
|
|
$sUsername = $aDNS["username"];
|
|
|
|
|
|
$sPassword = $aDNS["password"];
|
|
|
|
|
|
$sHostspec = $aDNS["hostspec"];
|
|
|
|
|
|
$sDatabse = $aDNS["database"];
|
|
|
|
|
|
$sPort = $aDNS["port"];
|
|
|
|
|
|
|
|
|
|
|
|
if ($sPort != "1521") {
|
2014-05-22 10:09:33 -04:00
|
|
|
|
$flagTns = ($sDatabse == "" && ($sPort . "" == "" || $sPort . "" == "0"))? 1 : 0;
|
|
|
|
|
|
|
|
|
|
|
|
if ($flagTns == 0) {
|
|
|
|
|
|
// if not default port
|
2015-06-01 13:58:50 -04:00
|
|
|
|
$conn = oci_connect($sUsername, $sPassword, $sHostspec . ":" . $sPort . "/" . $sDatabse, $dbsEncode);
|
2014-05-22 10:09:33 -04:00
|
|
|
|
} else {
|
2015-06-01 13:58:50 -04:00
|
|
|
|
$conn = oci_connect($sUsername, $sPassword, $sHostspec, $dbsEncode);
|
2014-05-22 10:09:33 -04:00
|
|
|
|
}
|
2012-07-03 17:54:36 -04:00
|
|
|
|
} else {
|
2015-06-01 13:58:50 -04:00
|
|
|
|
$conn = oci_connect( $sUsername, $sPassword, $sHostspec . "/" . $sDatabse, $dbsEncode);
|
2012-07-03 17:54:36 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
2012-10-09 12:59:01 -04:00
|
|
|
|
if (! $conn) {
|
2012-07-03 17:54:36 -04:00
|
|
|
|
$e = oci_error();
|
2012-10-09 12:59:01 -04:00
|
|
|
|
trigger_error( htmlentities( $e['message'], ENT_QUOTES ), E_USER_ERROR );
|
2012-07-03 17:54:36 -04:00
|
|
|
|
return $e;
|
|
|
|
|
|
}
|
2012-06-12 17:18:57 -04:00
|
|
|
|
|
2012-07-03 17:54:36 -04:00
|
|
|
|
switch (true) {
|
2012-10-09 12:59:01 -04:00
|
|
|
|
case preg_match( "/^(SELECT|SHOW|DESCRIBE|DESC|WITH)\s/i", $sql ):
|
|
|
|
|
|
$stid = oci_parse( $conn, $sql );
|
2014-05-22 10:09:33 -04:00
|
|
|
|
|
2012-10-09 12:59:01 -04:00
|
|
|
|
if (count( $aParameter ) > 0) {
|
2012-07-03 17:54:36 -04:00
|
|
|
|
foreach ($aParameter as $key => $val) {
|
2012-10-09 12:59:01 -04:00
|
|
|
|
oci_bind_by_name( $stid, $key, $val );
|
2012-07-03 17:54:36 -04:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2012-10-09 12:59:01 -04:00
|
|
|
|
oci_execute( $stid, OCI_DEFAULT );
|
2012-07-03 17:54:36 -04:00
|
|
|
|
|
2012-10-09 12:59:01 -04:00
|
|
|
|
$result = Array ();
|
2012-07-03 17:54:36 -04:00
|
|
|
|
$i = 1;
|
2012-10-09 12:59:01 -04:00
|
|
|
|
while ($row = oci_fetch_array( $stid, OCI_ASSOC + OCI_RETURN_NULLS )) {
|
|
|
|
|
|
$result[$i ++] = $row;
|
2012-07-03 17:54:36 -04:00
|
|
|
|
}
|
2012-10-09 12:59:01 -04:00
|
|
|
|
oci_free_statement( $stid );
|
|
|
|
|
|
oci_close( $conn );
|
2012-07-03 17:54:36 -04:00
|
|
|
|
return $result;
|
|
|
|
|
|
break;
|
2012-10-09 12:59:01 -04:00
|
|
|
|
case preg_match( "/^(INSERT|UPDATE|DELETE)\s/i", $sql ):
|
|
|
|
|
|
$stid = oci_parse( $conn, $sql );
|
2012-07-03 17:54:36 -04:00
|
|
|
|
$isValid = true;
|
2012-10-09 12:59:01 -04:00
|
|
|
|
if (count( $aParameter ) > 0) {
|
2012-07-03 17:54:36 -04:00
|
|
|
|
foreach ($aParameter as $key => $val) {
|
2012-10-09 12:59:01 -04:00
|
|
|
|
oci_bind_by_name( $stid, $key, $val );
|
2012-07-03 17:54:36 -04:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2012-10-09 12:59:01 -04:00
|
|
|
|
$objExecute = oci_execute( $stid, OCI_DEFAULT );
|
2012-10-12 16:57:47 -04:00
|
|
|
|
$result = oci_num_rows ($stid);
|
2012-07-03 17:54:36 -04:00
|
|
|
|
if ($objExecute) {
|
2012-10-09 12:59:01 -04:00
|
|
|
|
oci_commit( $conn );
|
2012-07-03 17:54:36 -04:00
|
|
|
|
} else {
|
2012-10-09 12:59:01 -04:00
|
|
|
|
oci_rollback( $conn );
|
2012-07-03 17:54:36 -04:00
|
|
|
|
$isValid = false;
|
|
|
|
|
|
}
|
2012-10-09 12:59:01 -04:00
|
|
|
|
oci_free_statement( $stid );
|
|
|
|
|
|
oci_close( $conn );
|
2012-07-03 17:54:36 -04:00
|
|
|
|
if ($isValid) {
|
2012-10-12 16:57:47 -04:00
|
|
|
|
return $result;
|
2012-07-03 17:54:36 -04:00
|
|
|
|
} else {
|
|
|
|
|
|
return oci_error();
|
|
|
|
|
|
}
|
|
|
|
|
|
break;
|
|
|
|
|
|
default:
|
|
|
|
|
|
// Stored procedures
|
2012-10-09 12:59:01 -04:00
|
|
|
|
$stid = oci_parse( $conn, $sql );
|
|
|
|
|
|
$aParameterRet = array ();
|
|
|
|
|
|
if (count( $aParameter ) > 0) {
|
2012-07-03 17:54:36 -04:00
|
|
|
|
foreach ($aParameter as $key => $val) {
|
|
|
|
|
|
$aParameterRet[$key] = $val;
|
|
|
|
|
|
// The third parameter ($aParameterRet[$key]) returned a value by reference.
|
2012-10-09 12:59:01 -04:00
|
|
|
|
oci_bind_by_name( $stid, $key, $aParameterRet[$key] );
|
2012-07-03 17:54:36 -04:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2012-10-09 12:59:01 -04:00
|
|
|
|
$objExecute = oci_execute( $stid, OCI_DEFAULT );
|
|
|
|
|
|
oci_free_statement( $stid );
|
|
|
|
|
|
oci_close( $conn );
|
2012-07-03 17:54:36 -04:00
|
|
|
|
return $aParameterRet;
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
2012-06-12 17:18:57 -04:00
|
|
|
|
}
|