CODE STYLE, changes...

FILES:
workflow/engine/classes/class.derivation.php
workflow/engine/classes/class.popupMenu.php
workflow/engine/classes/class.processes.php
workflow/engine/classes/class.xmlDb.php
workflow/engine/classes/triggers/api/class.zimbraApi.php
This commit is contained in:
jennylee
2012-10-22 15:45:47 -04:00
parent d7de707543
commit ef66773130
5 changed files with 5155 additions and 5126 deletions

View File

@@ -232,10 +232,10 @@ class Derivation
} }
/* get all users, from any task, if the task have Groups, the function expand the group /* get all users, from any task, if the task have Groups, the function expand the group
* *
* @param string $sTasUid the task uidUser * @param string $sTasUid the task uidUser
* @return Array $users an array with userID order by USR_UID * @return Array $users an array with userID order by USR_UID
*/ */
function getAllUsersFromAnyTask ($sTasUid) function getAllUsersFromAnyTask ($sTasUid)
{ {
$users = array (); $users = array ();
@@ -288,10 +288,10 @@ class Derivation
} }
/* get an array of users, and returns the same arrays with User's fullname and other fields /* get an array of users, and returns the same arrays with User's fullname and other fields
* *
* @param Array $aUsers the task uidUser * @param Array $aUsers the task uidUser
* @return Array $aUsersData an array with with User's fullname * @return Array $aUsersData an array with with User's fullname
*/ */
function getUsersFullNameFromArray ($aUsers) function getUsersFullNameFromArray ($aUsers)
{ {
$oUser = new Users(); $oUser = new Users();
@@ -339,10 +339,10 @@ class Derivation
} }
/* get next assigned user /* get next assigned user
* *
* @param Array $tasInfo * @param Array $tasInfo
* @return Array $userFields * @return Array $userFields
*/ */
function getNextAssignedUser ($tasInfo) function getNextAssignedUser ($tasInfo)
{ {
$oUser = new Users(); $oUser = new Users();
@@ -369,8 +369,9 @@ class Derivation
$uidUser = $users[0]; $uidUser = $users[0];
$i = count( $users ) - 1; $i = count( $users ) - 1;
while ($i > 0) { while ($i > 0) {
if ($lastAssigned < $users[$i]) if ($lastAssigned < $users[$i]) {
$uidUser = $users[$i]; $uidUser = $users[$i];
}
$i --; $i --;
} }
} else { } else {
@@ -397,10 +398,10 @@ class Derivation
} else { } else {
throw (new Exception( "Task doesn't have a valid user in variable $variable." )); throw (new Exception( "Task doesn't have a valid user in variable $variable." ));
} }
} else } else {
throw (new Exception( "Task doesn't have a valid user in variable $variable or this variable doesn't exist." )); throw (new Exception( "Task doesn't have a valid user in variable $variable or this variable doesn't exist." ));
}
break; break;
case 'REPORT_TO': case 'REPORT_TO':
//default error user when the reportsTo is not assigned to that user //default error user when the reportsTo is not assigned to that user
//look for USR_REPORTS_TO to this user //look for USR_REPORTS_TO to this user
@@ -423,7 +424,6 @@ class Derivation
throw (new Exception( G::LoadTranslation( 'ID_MSJ_REPORSTO' ) )); // "The current user does not have a valid Reports To user. Please contact administrator.") ) ; throw (new Exception( G::LoadTranslation( 'ID_MSJ_REPORSTO' ) )); // "The current user does not have a valid Reports To user. Please contact administrator.") ) ;
} }
break; break;
case 'SELF_SERVICE': case 'SELF_SERVICE':
//look for USR_REPORTS_TO to this user //look for USR_REPORTS_TO to this user
$userFields['USR_UID'] = ''; $userFields['USR_UID'] = '';
@@ -433,7 +433,6 @@ class Derivation
$userFields['USR_LASTNAME'] = ''; $userFields['USR_LASTNAME'] = '';
$userFields['USR_EMAIL'] = ''; $userFields['USR_EMAIL'] = '';
break; break;
default: default:
throw (new Exception( 'Invalid Task Assignment method for Next Task ' )); throw (new Exception( 'Invalid Task Assignment method for Next Task ' ));
} }
@@ -441,29 +440,30 @@ class Derivation
} }
/* getDenpendentUser /* getDenpendentUser
* *
* @param string $USR_UID * @param string $USR_UID
* @return string $aRow['USR_REPORTS_TO'] * @return string $aRow['USR_REPORTS_TO']
*/ */
function getDenpendentUser($USR_UID) { function getDenpendentUser ($USR_UID)
{
//Here the uid to next user //Here the uid to next user
$oC = new Criteria(); $oC = new Criteria();
$oC->addSelectColumn(UsersPeer::USR_REPORTS_TO); $oC->addSelectColumn( UsersPeer::USR_REPORTS_TO );
$oC->add(UsersPeer::USR_UID, $USR_UID); $oC->add( UsersPeer::USR_UID, $USR_UID );
$oDataset = UsersPeer::doSelectRS($oC); $oDataset = UsersPeer::doSelectRS( $oC );
$oDataset->setFetchmode(ResultSet::FETCHMODE_ASSOC); $oDataset->setFetchmode( ResultSet::FETCHMODE_ASSOC );
$oDataset->next(); $oDataset->next();
$aRow = $oDataset->getRow(); $aRow = $oDataset->getRow();
return $aRow['USR_REPORTS_TO'] != '' ? $aRow['USR_REPORTS_TO'] : $USR_UID; return $aRow['USR_REPORTS_TO'] != '' ? $aRow['USR_REPORTS_TO'] : $USR_UID;
} }
/* setTasLastAssigned /* setTasLastAssigned
* *
* @param string $tasUid * @param string $tasUid
* @param string $usrUid * @param string $usrUid
* @throws Exception $e * @throws Exception $e
* @return void * @return void
*/ */
function setTasLastAssigned ($tasUid, $usrUid) function setTasLastAssigned ($tasUid, $usrUid)
{ {
try { try {
@@ -476,18 +476,20 @@ class Derivation
} }
/* derivate /* derivate
* *
* @param array $currentDelegation * @param array $currentDelegation
* @param array $nextDelegations * @param array $nextDelegations
* @return void * @return void
*/ */
function derivate ($currentDelegation = array(), $nextDelegations = array()) function derivate ($currentDelegation = array(), $nextDelegations = array())
{ {
//define this... //define this...
if (! defined( 'TASK_FINISH_PROCESS' )) if (! defined( 'TASK_FINISH_PROCESS' )) {
define( 'TASK_FINISH_PROCESS', - 1 ); define( 'TASK_FINISH_PROCESS', - 1 );
if (! defined( 'TASK_FINISH_TASK' )) }
if (! defined( 'TASK_FINISH_TASK' )) {
define( 'TASK_FINISH_TASK', - 2 ); define( 'TASK_FINISH_TASK', - 2 );
}
$this->case = new cases(); $this->case = new cases();
@@ -532,17 +534,15 @@ class Derivation
} }
switch ($nextDel['TAS_UID']) { switch ($nextDel['TAS_UID']) {
case TASK_FINISH_PROCESS: case TASK_FINISH_PROCESS:
/*Close all delegations of $currentDelegation['APP_UID'] */ /*Close all delegations of $currentDelegation['APP_UID'] */
$this->case->closeAllDelegations( $currentDelegation['APP_UID'] ); $this->case->closeAllDelegations( $currentDelegation['APP_UID'] );
$this->case->closeAllThreads( $currentDelegation['APP_UID'] ); $this->case->closeAllThreads( $currentDelegation['APP_UID'] );
//I think we need to change the APP_STATUS to completed, //I think we need to change the APP_STATUS to completed,
break; break;
case TASK_FINISH_TASK: case TASK_FINISH_TASK:
$iAppThreadIndex = $appFields['DEL_THREAD']; $iAppThreadIndex = $appFields['DEL_THREAD'];
$this->case->closeAppThread( $currentDelegation['APP_UID'], $iAppThreadIndex ); $this->case->closeAppThread( $currentDelegation['APP_UID'], $iAppThreadIndex );
break; break;
default: default:
// get all siblingThreads // get all siblingThreads
//if($currentDelegation['TAS_ASSIGN_TYPE'] == 'STATIC_MI') //if($currentDelegation['TAS_ASSIGN_TYPE'] == 'STATIC_MI')
@@ -552,39 +552,42 @@ class Derivation
$siblingThreads = $this->case->GetAllOpenDelegation( $currentDelegation ); $siblingThreads = $this->case->GetAllOpenDelegation( $currentDelegation );
$aData = $this->case->loadCase( $currentDelegation['APP_UID'] ); $aData = $this->case->loadCase( $currentDelegation['APP_UID'] );
if (isset( $aData['APP_DATA'][str_replace( '@@', '', $currentDelegation['TAS_MI_INSTANCE_VARIABLE'] )] )) if (isset( $aData['APP_DATA'][str_replace( '@@', '', $currentDelegation['TAS_MI_INSTANCE_VARIABLE'] )] )) {
$sMIinstanceVar = $aData['APP_DATA'][str_replace( '@@', '', $currentDelegation['TAS_MI_INSTANCE_VARIABLE'] )]; $sMIinstanceVar = $aData['APP_DATA'][str_replace( '@@', '', $currentDelegation['TAS_MI_INSTANCE_VARIABLE'] )];
else } else {
$sMIinstanceVar = $aData['APP_DATA']['TAS_MI_INSTANCE_VARIABLE']; $sMIinstanceVar = $aData['APP_DATA']['TAS_MI_INSTANCE_VARIABLE'];
}
if (isset( $aData['APP_DATA'][str_replace( '@@', '', $currentDelegation['TAS_MI_COMPLETE_VARIABLE'] )] )) if (isset( $aData['APP_DATA'][str_replace( '@@', '', $currentDelegation['TAS_MI_COMPLETE_VARIABLE'] )] )) {
$sMIcompleteVar = $aData['APP_DATA'][str_replace( '@@', '', $currentDelegation['TAS_MI_COMPLETE_VARIABLE'] )]; $sMIcompleteVar = $aData['APP_DATA'][str_replace( '@@', '', $currentDelegation['TAS_MI_COMPLETE_VARIABLE'] )];
else } else {
$sMIcompleteVar = $aData['APP_DATA']['TAS_MI_COMPLETE_VARIABLE']; $sMIcompleteVar = $aData['APP_DATA']['TAS_MI_COMPLETE_VARIABLE'];
}
$discriminateThread = $sMIinstanceVar - $sMIcompleteVar; $discriminateThread = $sMIinstanceVar - $sMIcompleteVar;
// -1 because One App Delegation is closed by above Code // -1 because One App Delegation is closed by above Code
if ($discriminateThread == count( $siblingThreads )) if ($discriminateThread == count( $siblingThreads )) {
$canDerivate = true; $canDerivate = true;
else } else {
$canDerivate = false; $canDerivate = false;
}
break; break;
default: default:
if ($currentDelegation['ROU_TYPE'] == 'SEC-JOIN') { if ($currentDelegation['ROU_TYPE'] == 'SEC-JOIN') {
$siblingThreads = $this->case->getOpenSiblingThreads( $nextDel['TAS_UID'], $currentDelegation['APP_UID'], $currentDelegation['DEL_INDEX'], $currentDelegation['TAS_UID'], $currentDelegation['ROU_TYPE'] ); $siblingThreads = $this->case->getOpenSiblingThreads( $nextDel['TAS_UID'], $currentDelegation['APP_UID'], $currentDelegation['DEL_INDEX'], $currentDelegation['TAS_UID'], $currentDelegation['ROU_TYPE'] );
$canDerivate = count( $siblingThreads ) == 0; $canDerivate = count( $siblingThreads ) == 0;
} else if ($currentDelegation['ROU_TYPE'] == 'DISCRIMINATOR') { } elseif ($currentDelegation['ROU_TYPE'] == 'DISCRIMINATOR') {
//First get the total threads of Next Task where route type='Discriminator' //First get the total threads of Next Task where route type='Discriminator'
$siblingThreads = $this->case->getOpenSiblingThreads( $nextDel['TAS_UID'], $currentDelegation['APP_UID'], $currentDelegation['DEL_INDEX'], $currentDelegation['TAS_UID'], $currentDelegation['ROU_TYPE'] ); $siblingThreads = $this->case->getOpenSiblingThreads( $nextDel['TAS_UID'], $currentDelegation['APP_UID'], $currentDelegation['DEL_INDEX'], $currentDelegation['TAS_UID'], $currentDelegation['ROU_TYPE'] );
$siblingThreadsCount = count( $siblingThreads ); $siblingThreadsCount = count( $siblingThreads );
$discriminateThread = $currentDelegation['ROU_CONDITION']; $discriminateThread = $currentDelegation['ROU_CONDITION'];
//$checkThread = count($totalThreads) - $cond; //$checkThread = count($totalThreads) - $cond;
if ($discriminateThread == $siblingThreadsCount) if ($discriminateThread == $siblingThreadsCount) {
$canDerivate = true; $canDerivate = true;
else } else {
$canDerivate = false; $canDerivate = false;
}
} else { } else {
$canDerivate = true; $canDerivate = true;
} }
@@ -594,7 +597,8 @@ class Derivation
if ($canDerivate) { if ($canDerivate) {
$aSP = isset( $aSP ) ? $aSP : null; $aSP = isset( $aSP ) ? $aSP : null;
$iNewDelIndex = $this->doDerivation( $currentDelegation, $nextDel, $appFields, $aSP ); $iNewDelIndex = $this->doDerivation( $currentDelegation, $nextDel, $appFields, $aSP );
} else { //when the task doesnt generate a new AppDelegation } else {
//when the task doesnt generate a new AppDelegation
$iAppThreadIndex = $appFields['DEL_THREAD']; $iAppThreadIndex = $appFields['DEL_THREAD'];
switch ($currentDelegation['ROU_TYPE']) { switch ($currentDelegation['ROU_TYPE']) {
case 'DISCRIMINATOR': case 'DISCRIMINATOR':
@@ -602,8 +606,9 @@ class Derivation
$this->case->closeAppThread( $currentDelegation['APP_UID'], $iAppThreadIndex ); $this->case->closeAppThread( $currentDelegation['APP_UID'], $iAppThreadIndex );
break; break;
default: default:
if ($currentDelegation['TAS_ASSIGN_TYPE'] == 'STATIC_MI' || $currentDelegation['TAS_ASSIGN_TYPE'] == 'CANCEL_MI') if ($currentDelegation['TAS_ASSIGN_TYPE'] == 'STATIC_MI' || $currentDelegation['TAS_ASSIGN_TYPE'] == 'CANCEL_MI') {
$this->case->closeAppThread( $currentDelegation['APP_UID'], $iAppThreadIndex ); $this->case->closeAppThread( $currentDelegation['APP_UID'], $iAppThreadIndex );
}
} //switch } //switch
} }
} }
@@ -674,15 +679,14 @@ class Derivation
$iNewThreadIndex = $this->case->newAppThread( $currentDelegation['APP_UID'], $iMIDelIndex, $iAppThreadIndex ); $iNewThreadIndex = $this->case->newAppThread( $currentDelegation['APP_UID'], $iMIDelIndex, $iAppThreadIndex );
//Setting the del Index for Updating the AppThread delIndex //Setting the del Index for Updating the AppThread delIndex
if ($key == 0) if ($key == 0) {
$iNewDelIndex = $iMIDelIndex - 1; $iNewDelIndex = $iMIDelIndex - 1;
}
} //end foreach } //end foreach
break; break;
case 'BALANCED': case 'BALANCED':
$this->setTasLastAssigned( $nextDel['TAS_UID'], $nextDel['USR_UID'] ); $this->setTasLastAssigned( $nextDel['TAS_UID'], $nextDel['USR_UID'] );
//No Break, need no execute the default ones.... //No Break, need no execute the default ones....
default: default:
// Create new delegation // Create new delegation
$iNewDelIndex = $this->case->newAppDelegation( $appFields['PRO_UID'], $currentDelegation['APP_UID'], $nextDel['TAS_UID'], (isset( $nextDel['USR_UID'] ) ? $nextDel['USR_UID'] : ''), $currentDelegation['DEL_INDEX'], $nextDel['DEL_PRIORITY'], $delType, $iAppThreadIndex, $nextDel ); $iNewDelIndex = $this->case->newAppDelegation( $appFields['PRO_UID'], $currentDelegation['APP_UID'], $nextDel['TAS_UID'], (isset( $nextDel['USR_UID'] ) ? $nextDel['USR_UID'] : ''), $currentDelegation['DEL_INDEX'], $nextDel['DEL_PRIORITY'], $delType, $iAppThreadIndex, $nextDel );
@@ -699,13 +703,10 @@ class Derivation
$this->case->updateAppDelegation( $currentDelegation['APP_UID'], $iNewDelIndex, $iNewThreadIndex ); $this->case->updateAppDelegation( $currentDelegation['APP_UID'], $iNewDelIndex, $iNewThreadIndex );
//print " this->case->updateAppDelegation ( " . $currentDelegation['APP_UID'] .", " . $iNewDelIndex ." , " . $iNewThreadIndex . " )<br>"; //print " this->case->updateAppDelegation ( " . $currentDelegation['APP_UID'] .", " . $iNewDelIndex ." , " . $iNewThreadIndex . " )<br>";
break; break;
case 'DISCRIMINATOR': case 'DISCRIMINATOR':
if ($currentDelegation['ROU_OPTIONAL'] == 'TRUE') { if ($currentDelegation['ROU_OPTIONAL'] == 'TRUE') {
$this->case->discriminateCases( $currentDelegation ); $this->case->discriminateCases( $currentDelegation );
} //No Break, executing Default Condition } //No Break, executing Default Condition
default: default:
switch ($currentDelegation['TAS_ASSIGN_TYPE']) { switch ($currentDelegation['TAS_ASSIGN_TYPE']) {
case 'CANCEL_MI': case 'CANCEL_MI':
@@ -784,10 +785,10 @@ class Derivation
} }
/* verifyIsCaseChild /* verifyIsCaseChild
* *
* @param string $sApplicationUID * @param string $sApplicationUID
* @return void * @return void
*/ */
function verifyIsCaseChild ($sApplicationUID) function verifyIsCaseChild ($sApplicationUID)
{ {
//Obtain the related row in the table SUB_APPLICATION //Obtain the related row in the table SUB_APPLICATION
@@ -855,14 +856,14 @@ class Derivation
} }
/* getDerivatedCases /* getDerivatedCases
* get all derivated cases and subcases from any task, * get all derivated cases and subcases from any task,
* this function is useful to know who users have been assigned and what task they do. * this function is useful to know who users have been assigned and what task they do.
* *
* @param string $sParentUid * @param string $sParentUid
* @param string $sDelIndexParent * @param string $sDelIndexParent
* @return array $derivation * @return array $derivation
* *
*/ */
function getDerivatedCases ($sParentUid, $sDelIndexParent) function getDerivatedCases ($sParentUid, $sDelIndexParent)
{ {
$oCriteria = new Criteria( 'workflow' ); $oCriteria = new Criteria( 'workflow' );
@@ -968,5 +969,5 @@ class Derivation
} }
} }
} }
}
}

View File

@@ -1,11 +1,13 @@
<?php <?php
/** /**
* class.popupMenu.php * class.popupMenu.php
*
* @package workflow.engine.ProcessMaker * @package workflow.engine.ProcessMaker
* *
* ProcessMaker Open Source Edition * ProcessMaker Open Source Edition
* Copyright (C) 2004 - 2011 Colosa Inc. * Copyright (C) 2004 - 2011 Colosa Inc.
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as * it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the * published by the Free Software Foundation, either version 3 of the
@@ -13,89 +15,85 @@
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details. * GNU Affero General Public License for more details.
* *
* You should have received a copy of the GNU Affero General Public License * 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/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
* *
* For more information, contact Colosa Inc, 2566 Le Jeune Rd., * For more information, contact Colosa Inc, 2566 Le Jeune Rd.,
* Coral Gables, FL, 33134, USA, or email info@colosa.com. * Coral Gables, FL, 33134, USA, or email info@colosa.com.
* *
*/ */
/** /**
* popupMenu - popupMenu class * popupMenu - popupMenu class
*
* @package workflow.engine.ProcessMaker * @package workflow.engine.ProcessMaker
* @copyright COLOSA * @copyright COLOSA
*/ */
class popupMenu extends form
{
var $type = 'popupMenu';
var $theme = 'processmaker';
/** class popupMenu extends form
* Print the popup {
* @param string $tableId var $type = 'popupMenu';
* @param array $tableFields var $theme = 'processmaker';
* @return array
*/ /**
function renderPopup( $tableId, $tableFields ) * Print the popup
{ *
$this->name =$tableId; * @param string $tableId
$fields = array_keys( $tableFields); * @param array $tableFields
foreach( $fields as $f ) { * @return array
switch ( strtolower($tableFields[$f]['Type'])) { */
case 'javascript': function renderPopup ($tableId, $tableFields)
case 'button': {
case 'private': $this->name = $tableId;
case 'hidden': $fields = array_keys( $tableFields );
case 'cellmark': foreach ($fields as $f) {
break; switch (strtolower( $tableFields[$f]['Type'] )) {
default: case 'javascript':
$label = ($tableFields[$f]['Label'] !='' ) ? $tableFields[$f]['Label'] : $f; case 'button':
$label = str_replace("\n", ' ', $label); case 'private':
$pmXmlNode = new Xml_Node( $f, case 'hidden':
'complete', case 'cellmark':
'', break;
array ( 'label' => $label, default:
'type' => 'popupOption', $label = ($tableFields[$f]['Label'] != '') ? $tableFields[$f]['Label'] : $f;
'launch' => $tableId . '.showHideField("' . $f . '")' $label = str_replace( "\n", ' ', $label );
) $pmXmlNode = new Xml_Node( $f, 'complete', '', array ('label' => $label,'type' => 'popupOption','launch' => $tableId . '.showHideField("' . $f . '")'
); ) );
$this->fields[$f] = new XmlForm_Field_popupOption( $pmXmlNode ); $this->fields[$f] = new XmlForm_Field_popupOption( $pmXmlNode );
$this->values[$f]=''; $this->values[$f] = '';
}
} }
} $scTemp = '';
$scTemp = ''; $this->values['PAGED_TABLE_ID'] = $tableId;
$this->values['PAGED_TABLE_ID'] = $tableId; print (parent::render( PATH_CORE . 'templates/popupMenu.html', $scTemp )) ;
print( parent::render( PATH_CORE . 'templates/popupMenu.html', $scTemp)); $sc = "<script type=\"text/javascript\">\n$scTemp\n loadPopupMenu_$tableId(); \n</script>";
$sc = "<script type=\"text/javascript\">\n$scTemp\n loadPopupMenu_$tableId(); \n</script>" ; return $sc;
return $sc; }
}
} }
/** /**
* XmlForm_Field_popupOption - XmlForm_Field_popupOption class * XmlForm_Field_popupOption - XmlForm_Field_popupOption class
*
* @package workflow.engine.ProcessMaker * @package workflow.engine.ProcessMaker
* @copyright COLOSA * @copyright COLOSA
*/ */
class XmlForm_Field_popupOption extends XmlForm_Field class XmlForm_Field_popupOption extends XmlForm_Field
{ {
var $launch = ''; var $launch = '';
/** /**
* Get Events * Get Events
* @return string *
*/ * @return string
function getEvents( ) */
{ function getEvents ()
$script = '{name:"' . $this->name . '",text:"' . addcslashes($this->label,'\\"') . {
'", launch:leimnud.closure({Function:function(target){' . $this->launch . '}, args:target})}'; $script = '{name:"' . $this->name . '",text:"' . addcslashes( $this->label, '\\"' ) . '", launch:leimnud.closure({Function:function(target){' . $this->launch . '}, args:target})}';
return $script; return $script;
} }
} }
?>

File diff suppressed because it is too large Load Diff

View File

@@ -44,7 +44,7 @@ class XMLDB
* @param string $dsn * @param string $dsn
* @return array $options * @return array $options
*/ */
function &connect ($dsn, $options = array()) public function &connect ($dsn, $options = array())
{ {
//Needed for $mysql_real_escape_string //Needed for $mysql_real_escape_string
$mresdbc = new DBConnection(); $mresdbc = new DBConnection();
@@ -63,7 +63,7 @@ class XMLDB
* @param string $result * @param string $result
* @return boolean is_a($result, 'DB_Error') * @return boolean is_a($result, 'DB_Error')
*/ */
function isError ($result) public function isError ($result)
{ {
return is_a( $result, 'DB_Error' ); return is_a( $result, 'DB_Error' );
} }
@@ -82,7 +82,7 @@ class XMLConnection
{ {
var $phptype = 'myxml'; var $phptype = 'myxml';
var $caseFolding = true; var $caseFolding = true;
var $xmldoc = NULL; var $xmldoc = null;
var $xmlFile = ''; var $xmlFile = '';
/** /**
@@ -91,7 +91,7 @@ class XMLConnection
* @param string $file * @param string $file
* @return void * @return void
*/ */
function XMLConnection ($file) public function XMLConnection ($file)
{ {
$this->xmldoc = new Xml_Document(); $this->xmldoc = new Xml_Document();
$this->xmldoc->parseXmlFile( $file ); $this->xmldoc->parseXmlFile( $file );
@@ -105,7 +105,7 @@ class XMLConnection
* @param string $sql * @param string $sql
* @return object(XMLResult) $result * @return object(XMLResult) $result
*/ */
function &query ($sql) public function &query ($sql)
{ {
if (! isset( $this->xmldoc )) { if (! isset( $this->xmldoc )) {
$err = new DB_Error( "Error: Closed xmlConnection." ); $err = new DB_Error( "Error: Closed xmlConnection." );
@@ -127,8 +127,8 @@ class XMLConnection
$fieldsList[$name] = $match[1][$r][0]; $fieldsList[$name] = $match[1][$r][0];
} }
/* End Block */ /* End Block */
/* Start Block: Order list */ /* Start Block: Order list */
$count = preg_match_all( '/\s*(\*|[\w\.]+)(\s+ASC|\s+DESC)?\s*,?/im', $sqlOrderBy, $match, PREG_PATTERN_ORDER | PREG_OFFSET_CAPTURE ); $count = preg_match_all( '/\s*(\*|[\w\.]+)(\s+ASC|\s+DESC)?\s*,?/im', $sqlOrderBy, $match, PREG_PATTERN_ORDER | PREG_OFFSET_CAPTURE );
$orderList = array (); $orderList = array ();
for ($r = $count - 1; $r >= 0; $r --) { for ($r = $count - 1; $r >= 0; $r --) {
$direction = (is_array( $match[2][$r] ) && $match[2][$r][0] !== '') ? $match[2][$r][0] : 'ASC'; $direction = (is_array( $match[2][$r] ) && $match[2][$r][0] !== '') ? $match[2][$r][0] : 'ASC';
@@ -173,21 +173,22 @@ class XMLConnection
for ($r = 0; $r < sizeof( $res ); $r ++) { for ($r = 0; $r < sizeof( $res ); $r ++) {
$evalWhere = false; $evalWhere = false;
@eval( '$evalWhere = ' . $sqlWhere . ';' ); @eval( '$evalWhere = ' . $sqlWhere . ';' );
if ($evalWhere) if ($evalWhere) {
$newRes[] = $res[$r]; $newRes[] = $res[$r];
}
} }
$res = $newRes; $res = $newRes;
} }
/* End Block */ /* End Block */
/* Start Block: Expands the resultant data according to fill an array /* Start Block: Expands the resultant data according to fill an array
* with the required fields in the query. * with the required fields in the query.
*/ */
for ($r = 0; $r < sizeof( $res ); $r ++) { for ($r = 0; $r < sizeof( $res ); $r ++) {
$res[$r] = $this->expandFields( $res[$r], $fieldsList ); $res[$r] = $this->expandFields( $res[$r], $fieldsList );
} }
/* End Block */ /* End Block */
/* Start Block: ORDER BY*/ /* Start Block: ORDER BY*/
foreach ($orderList as $field => $direction) { foreach ($orderList as $field => $direction) {
for ($i = 0; $i < sizeof( $res ); $i ++) { for ($i = 0; $i < sizeof( $res ); $i ++) {
for ($j = $i + 1; $j < sizeof( $res ); $j ++) { for ($j = $i + 1; $j < sizeof( $res ); $j ++) {
$condition = ($direction === 'ASC') ? ($res[$j] < $res[$i]) : ($res[$j] > $res[$i]); $condition = ($direction === 'ASC') ? ($res[$j] < $res[$i]) : ($res[$j] > $res[$i]);
@@ -200,8 +201,8 @@ class XMLConnection
} }
} }
/* End Block */ /* End Block */
/* Start Block: Apply limits */ /* Start Block: Apply limits */
if ($sqlLowLimit != '' && $sqlHighLimit != '') { if ($sqlLowLimit != '' && $sqlHighLimit != '') {
$sqlLowLimit = (int) $sqlLowLimit; $sqlLowLimit = (int) $sqlLowLimit;
$sqlHighLimit = (int) $sqlHighLimit; $sqlHighLimit = (int) $sqlHighLimit;
$res = array_slice( $res, $sqlLowLimit, $sqlHighLimit ); $res = array_slice( $res, $sqlLowLimit, $sqlHighLimit );
@@ -213,8 +214,8 @@ class XMLConnection
$sqlFrom = isset( $matches[1] ) ? $matches[1] : ''; $sqlFrom = isset( $matches[1] ) ? $matches[1] : '';
$sqlWhere = isset( $matches[2] ) ? $matches[2] : '1'; $sqlWhere = isset( $matches[2] ) ? $matches[2] : '1';
/* Start Block: WHERE*/ /* Start Block: WHERE*/
/*Start Block: Replace the operator */ /*Start Block: Replace the operator */
$blocks = preg_split( '/("(?:(?:[^"]|"")*)"|\'(?:(?:[^\']|\'\')*)\')/im', $sqlWhere, - 1, PREG_SPLIT_DELIM_CAPTURE ); $blocks = preg_split( '/("(?:(?:[^"]|"")*)"|\'(?:(?:[^\']|\'\')*)\')/im', $sqlWhere, - 1, PREG_SPLIT_DELIM_CAPTURE );
$sqlWhere = ''; $sqlWhere = '';
for ($r = 0; $r < sizeof( $blocks ); $r ++) { for ($r = 0; $r < sizeof( $blocks ); $r ++) {
if (($r % 2) === 0) { if (($r % 2) === 0) {
@@ -274,8 +275,8 @@ class XMLConnection
$fieldsList[] = $match[1][$r][0]; $fieldsList[] = $match[1][$r][0];
} }
/* End Block */ /* End Block */
/* Start Block: Fields Values */ /* Start Block: Fields Values */
$count = preg_match_all( '/("(?:(?:[^"]|"")*)"|\'(?:(?:[^\']|\'\')*)\'|\d+)/im', $sqlValues, $match, PREG_PATTERN_ORDER | PREG_OFFSET_CAPTURE ); $count = preg_match_all( '/("(?:(?:[^"]|"")*)"|\'(?:(?:[^\']|\'\')*)\'|\d+)/im', $sqlValues, $match, PREG_PATTERN_ORDER | PREG_OFFSET_CAPTURE );
$fieldsValues = array (); $fieldsValues = array ();
for ($r = 0; $r < $count; $r ++) { for ($r = 0; $r < $count; $r ++) {
if (substr( $match[1][$r][0], 0, 1 ) === '"') { if (substr( $match[1][$r][0], 0, 1 ) === '"') {
@@ -318,8 +319,8 @@ class XMLConnection
$fieldsValues[$match[1][$r][0]] = $match[2][$r][0]; $fieldsValues[$match[1][$r][0]] = $match[2][$r][0];
} }
/* Start Block: WHERE*/ /* Start Block: WHERE*/
/*Start Block: Replace the operator */ /*Start Block: Replace the operator */
$blocks = preg_split( '/("(?:(?:[^"]|"")*)"|\'(?:(?:[^\']|\'\')*)\')/im', $sqlWhere, - 1, PREG_SPLIT_DELIM_CAPTURE ); $blocks = preg_split( '/("(?:(?:[^"]|"")*)"|\'(?:(?:[^\']|\'\')*)\')/im', $sqlWhere, - 1, PREG_SPLIT_DELIM_CAPTURE );
$sqlWhere = ''; $sqlWhere = '';
for ($r = 0; $r < sizeof( $blocks ); $r ++) { for ($r = 0; $r < sizeof( $blocks ); $r ++) {
if (($r % 2) === 0) { if (($r % 2) === 0) {
@@ -377,7 +378,7 @@ class XMLConnection
* @param string $a * @param string $a
* @return void $b * @return void $b
*/ */
function sqlLike ($a, $b) public function sqlLike ($a, $b)
{ {
$b = addcslashes( $b, '[]()\/{}.?' ); $b = addcslashes( $b, '[]()\/{}.?' );
$b = str_replace( "%", '.*', $b ); $b = str_replace( "%", '.*', $b );
@@ -392,15 +393,16 @@ class XMLConnection
* @param string $fieldsList * @param string $fieldsList
* @return array $res * @return array $res
*/ */
function expandFields ($resRow, $fieldsList) public function expandFields ($resRow, $fieldsList)
{ {
$res = array (); $res = array ();
foreach ($fieldsList as $key => $value) { foreach ($fieldsList as $key => $value) {
if ($key === '*') { if ($key === '*') {
foreach ($resRow as $k => $v) foreach ($resRow as $k => $v) {
$res[$k] = $v; $res[$k] = $v;
}
} else { } else {
$res[$key] = array_key_exists( $value, $resRow ) ? $resRow[$value] : NULL; $res[$key] = array_key_exists( $value, $resRow ) ? $resRow[$value] : null;
} }
} }
return $res; return $res;
@@ -412,13 +414,14 @@ class XMLConnection
* @param object &$node * @param object &$node
* @return array $res * @return array $res
*/ */
function fetchNode (&$node) public function fetchNode (&$node)
{ {
$res = array ('XMLNODE_NAME' => $node->name,'XMLNODE_TYPE' => $node->type,'XMLNODE_VALUE' => $node->value $res = array ('XMLNODE_NAME' => $node->name,'XMLNODE_TYPE' => $node->type,'XMLNODE_VALUE' => $node->value
); );
foreach ($node->attributes as $name => $value) { foreach ($node->attributes as $name => $value) {
if ($this->caseFolding) if ($this->caseFolding) {
$name = strtoupper( $name ); $name = strtoupper( $name );
}
$res[$name] = $value; $res[$name] = $value;
} }
return $res; return $res;
@@ -430,7 +433,7 @@ class XMLConnection
* @param string &$node * @param string &$node
* @return array $res * @return array $res
*/ */
function fetchChildren (&$node) public function fetchChildren (&$node)
{ {
$res = array (); $res = array ();
foreach ($node->children as $name => $child) { foreach ($node->children as $name => $child) {
@@ -444,7 +447,7 @@ class XMLConnection
* *
* @return void * @return void
*/ */
function disconnect () public function disconnect ()
{ {
unset( $this->xmldoc ); unset( $this->xmldoc );
} }
@@ -454,7 +457,7 @@ class XMLConnection
* @param array $match * @param array $match
* @return object(DB_Error) $err * @return object(DB_Error) $err
*/ */
function sqlWhereLike ($match) public function sqlWhereLike ($match)
{ {
switch (substr( $match[2], 0, 1 )) { switch (substr( $match[2], 0, 1 )) {
case '"': case '"':
@@ -476,7 +479,7 @@ class XMLConnection
* @param array $match * @param array $match
* @return object(DB_Error) $err * @return object(DB_Error) $err
*/ */
function sqlString ($match) public function sqlString ($match)
{ {
switch (substr( $match[0], 0, 1 )) { switch (substr( $match[0], 0, 1 )) {
case '"': case '"':
@@ -507,7 +510,7 @@ class XMLConnection
* @param object $values * @param object $values
* @return void * @return void
*/ */
function insertRow (&$node, $values) public function insertRow (&$node, $values)
{ {
$attributes = array (); $attributes = array ();
foreach ($values as $field => $value) { foreach ($values as $field => $value) {
@@ -533,7 +536,7 @@ class XMLConnection
* @param object $values * @param object $values
* @return void * @return void
*/ */
function updateRow (&$node, $values) public function updateRow (&$node, $values)
{ {
foreach ($values as $field => $value) { foreach ($values as $field => $value) {
switch ($field) { switch ($field) {
@@ -573,7 +576,7 @@ class XMLResult
* @param array $result * @param array $result
* @return void * @return void
*/ */
function XMLResult ($result = array()) public function XMLResult ($result = array())
{ {
$this->result = $result; $this->result = $result;
$this->cursor = 0; $this->cursor = 0;
@@ -584,7 +587,7 @@ class XMLResult
* *
* @return integer sizeof($this->result) * @return integer sizeof($this->result)
*/ */
function numRows () public function numRows ()
{ {
return sizeof( $this->result ); return sizeof( $this->result );
} }
@@ -595,10 +598,11 @@ class XMLResult
* @param string $const * @param string $const
* @return integer $this->result[ $this->cursor-1 ]; * @return integer $this->result[ $this->cursor-1 ];
*/ */
function fetchRow ($const) public function fetchRow ($const)
{ {
if ($this->cursor >= $this->numRows()) if ($this->cursor >= $this->numRows()) {
return NULL; return null;
}
$this->cursor ++; $this->cursor ++;
return $this->result[$this->cursor - 1]; return $this->result[$this->cursor - 1];
} }
@@ -621,4 +625,3 @@ function getNames ($children)
return $names; return $names;
} }
?>

File diff suppressed because it is too large Load Diff