diff --git a/workflow/engine/classes/class.derivation.php b/workflow/engine/classes/class.derivation.php index ed26dfa38..d12e2816d 100755 --- a/workflow/engine/classes/class.derivation.php +++ b/workflow/engine/classes/class.derivation.php @@ -232,10 +232,10 @@ class Derivation } /* get all users, from any task, if the task have Groups, the function expand the group - * - * @param string $sTasUid the task uidUser - * @return Array $users an array with userID order by USR_UID - */ + * + * @param string $sTasUid the task uidUser + * @return Array $users an array with userID order by USR_UID + */ function getAllUsersFromAnyTask ($sTasUid) { $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 - * - * @param Array $aUsers the task uidUser - * @return Array $aUsersData an array with with User's fullname - */ + * + * @param Array $aUsers the task uidUser + * @return Array $aUsersData an array with with User's fullname + */ function getUsersFullNameFromArray ($aUsers) { $oUser = new Users(); @@ -339,10 +339,10 @@ class Derivation } /* get next assigned user - * - * @param Array $tasInfo - * @return Array $userFields - */ + * + * @param Array $tasInfo + * @return Array $userFields + */ function getNextAssignedUser ($tasInfo) { $oUser = new Users(); @@ -369,8 +369,9 @@ class Derivation $uidUser = $users[0]; $i = count( $users ) - 1; while ($i > 0) { - if ($lastAssigned < $users[$i]) + if ($lastAssigned < $users[$i]) { $uidUser = $users[$i]; + } $i --; } } else { @@ -397,10 +398,10 @@ class Derivation } else { 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." )); + } break; - case 'REPORT_TO': //default error user when the reportsTo is not assigned to that 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.") ) ; } break; - case 'SELF_SERVICE': //look for USR_REPORTS_TO to this user $userFields['USR_UID'] = ''; @@ -433,7 +433,6 @@ class Derivation $userFields['USR_LASTNAME'] = ''; $userFields['USR_EMAIL'] = ''; break; - default: throw (new Exception( 'Invalid Task Assignment method for Next Task ' )); } @@ -441,29 +440,30 @@ class Derivation } /* getDenpendentUser - * - * @param string $USR_UID - * @return string $aRow['USR_REPORTS_TO'] - */ - function getDenpendentUser($USR_UID) { + * + * @param string $USR_UID + * @return string $aRow['USR_REPORTS_TO'] + */ + function getDenpendentUser ($USR_UID) + { //Here the uid to next user $oC = new Criteria(); - $oC->addSelectColumn(UsersPeer::USR_REPORTS_TO); - $oC->add(UsersPeer::USR_UID, $USR_UID); - $oDataset = UsersPeer::doSelectRS($oC); - $oDataset->setFetchmode(ResultSet::FETCHMODE_ASSOC); + $oC->addSelectColumn( UsersPeer::USR_REPORTS_TO ); + $oC->add( UsersPeer::USR_UID, $USR_UID ); + $oDataset = UsersPeer::doSelectRS( $oC ); + $oDataset->setFetchmode( ResultSet::FETCHMODE_ASSOC ); $oDataset->next(); $aRow = $oDataset->getRow(); return $aRow['USR_REPORTS_TO'] != '' ? $aRow['USR_REPORTS_TO'] : $USR_UID; } /* setTasLastAssigned - * - * @param string $tasUid - * @param string $usrUid - * @throws Exception $e - * @return void - */ + * + * @param string $tasUid + * @param string $usrUid + * @throws Exception $e + * @return void + */ function setTasLastAssigned ($tasUid, $usrUid) { try { @@ -476,18 +476,20 @@ class Derivation } /* derivate - * - * @param array $currentDelegation - * @param array $nextDelegations - * @return void - */ + * + * @param array $currentDelegation + * @param array $nextDelegations + * @return void + */ function derivate ($currentDelegation = array(), $nextDelegations = array()) { //define this... - if (! defined( 'TASK_FINISH_PROCESS' )) + if (! defined( 'TASK_FINISH_PROCESS' )) { define( 'TASK_FINISH_PROCESS', - 1 ); - if (! defined( 'TASK_FINISH_TASK' )) + } + if (! defined( 'TASK_FINISH_TASK' )) { define( 'TASK_FINISH_TASK', - 2 ); + } $this->case = new cases(); @@ -532,17 +534,15 @@ class Derivation } switch ($nextDel['TAS_UID']) { case TASK_FINISH_PROCESS: - /*Close all delegations of $currentDelegation['APP_UID'] */ - $this->case->closeAllDelegations( $currentDelegation['APP_UID'] ); + /*Close all delegations of $currentDelegation['APP_UID'] */ + $this->case->closeAllDelegations( $currentDelegation['APP_UID'] ); $this->case->closeAllThreads( $currentDelegation['APP_UID'] ); //I think we need to change the APP_STATUS to completed, break; - case TASK_FINISH_TASK: $iAppThreadIndex = $appFields['DEL_THREAD']; $this->case->closeAppThread( $currentDelegation['APP_UID'], $iAppThreadIndex ); break; - default: // get all siblingThreads //if($currentDelegation['TAS_ASSIGN_TYPE'] == 'STATIC_MI') @@ -552,39 +552,42 @@ class Derivation $siblingThreads = $this->case->GetAllOpenDelegation( $currentDelegation ); $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'] )]; - else + } else { $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'] )]; - else + } else { $sMIcompleteVar = $aData['APP_DATA']['TAS_MI_COMPLETE_VARIABLE']; + } $discriminateThread = $sMIinstanceVar - $sMIcompleteVar; // -1 because One App Delegation is closed by above Code - if ($discriminateThread == count( $siblingThreads )) + if ($discriminateThread == count( $siblingThreads )) { $canDerivate = true; - else + } else { $canDerivate = false; + } break; - default: 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'] ); $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' $siblingThreads = $this->case->getOpenSiblingThreads( $nextDel['TAS_UID'], $currentDelegation['APP_UID'], $currentDelegation['DEL_INDEX'], $currentDelegation['TAS_UID'], $currentDelegation['ROU_TYPE'] ); $siblingThreadsCount = count( $siblingThreads ); $discriminateThread = $currentDelegation['ROU_CONDITION']; //$checkThread = count($totalThreads) - $cond; - if ($discriminateThread == $siblingThreadsCount) + if ($discriminateThread == $siblingThreadsCount) { $canDerivate = true; - else + } else { $canDerivate = false; + } } else { $canDerivate = true; } @@ -594,7 +597,8 @@ class Derivation if ($canDerivate) { $aSP = isset( $aSP ) ? $aSP : null; $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']; switch ($currentDelegation['ROU_TYPE']) { case 'DISCRIMINATOR': @@ -602,8 +606,9 @@ class Derivation $this->case->closeAppThread( $currentDelegation['APP_UID'], $iAppThreadIndex ); break; 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 ); + } } //switch } } @@ -674,15 +679,14 @@ class Derivation $iNewThreadIndex = $this->case->newAppThread( $currentDelegation['APP_UID'], $iMIDelIndex, $iAppThreadIndex ); //Setting the del Index for Updating the AppThread delIndex - if ($key == 0) + if ($key == 0) { $iNewDelIndex = $iMIDelIndex - 1; - + } } //end foreach break; - case 'BALANCED': $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: // 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 ); @@ -699,13 +703,10 @@ class Derivation $this->case->updateAppDelegation( $currentDelegation['APP_UID'], $iNewDelIndex, $iNewThreadIndex ); //print " this->case->updateAppDelegation ( " . $currentDelegation['APP_UID'] .", " . $iNewDelIndex ." , " . $iNewThreadIndex . " )
"; break; - case 'DISCRIMINATOR': if ($currentDelegation['ROU_OPTIONAL'] == 'TRUE') { $this->case->discriminateCases( $currentDelegation ); } //No Break, executing Default Condition - - default: switch ($currentDelegation['TAS_ASSIGN_TYPE']) { case 'CANCEL_MI': @@ -784,10 +785,10 @@ class Derivation } /* verifyIsCaseChild - * - * @param string $sApplicationUID - * @return void - */ + * + * @param string $sApplicationUID + * @return void + */ function verifyIsCaseChild ($sApplicationUID) { //Obtain the related row in the table SUB_APPLICATION @@ -855,14 +856,14 @@ class Derivation } /* getDerivatedCases - * 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. - * - * @param string $sParentUid - * @param string $sDelIndexParent - * @return array $derivation - * - */ + * 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. + * + * @param string $sParentUid + * @param string $sDelIndexParent + * @return array $derivation + * + */ function getDerivatedCases ($sParentUid, $sDelIndexParent) { $oCriteria = new Criteria( 'workflow' ); @@ -968,5 +969,5 @@ class Derivation } } } +} -} \ No newline at end of file diff --git a/workflow/engine/classes/class.popupMenu.php b/workflow/engine/classes/class.popupMenu.php index ed029a702..7739ddc89 100755 --- a/workflow/engine/classes/class.popupMenu.php +++ b/workflow/engine/classes/class.popupMenu.php @@ -1,11 +1,13 @@ . - * - * For more information, contact Colosa Inc, 2566 Le Jeune Rd., + * along with this program. If not, see . + * + * For more information, contact Colosa Inc, 2566 Le Jeune Rd., * Coral Gables, FL, 33134, USA, or email info@colosa.com. - * + * */ - - + /** * popupMenu - popupMenu class + * * @package workflow.engine.ProcessMaker * @copyright COLOSA */ - -class popupMenu extends form -{ - var $type = 'popupMenu'; - var $theme = 'processmaker'; -/** - * Print the popup - * @param string $tableId - * @param array $tableFields - * @return array - */ - function renderPopup( $tableId, $tableFields ) - { - $this->name =$tableId; - $fields = array_keys( $tableFields); - foreach( $fields as $f ) { - switch ( strtolower($tableFields[$f]['Type'])) { - case 'javascript': - case 'button': - case 'private': - case 'hidden': - case 'cellmark': - break; - default: - $label = ($tableFields[$f]['Label'] !='' ) ? $tableFields[$f]['Label'] : $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->values[$f]=''; +class popupMenu extends form +{ + var $type = 'popupMenu'; + var $theme = 'processmaker'; + + /** + * Print the popup + * + * @param string $tableId + * @param array $tableFields + * @return array + */ + function renderPopup ($tableId, $tableFields) + { + $this->name = $tableId; + $fields = array_keys( $tableFields ); + foreach ($fields as $f) { + switch (strtolower( $tableFields[$f]['Type'] )) { + case 'javascript': + case 'button': + case 'private': + case 'hidden': + case 'cellmark': + break; + default: + $label = ($tableFields[$f]['Label'] != '') ? $tableFields[$f]['Label'] : $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->values[$f] = ''; + } } - } - $scTemp = ''; - $this->values['PAGED_TABLE_ID'] = $tableId; - print( parent::render( PATH_CORE . 'templates/popupMenu.html', $scTemp)); - $sc = "" ; - return $sc; - } + $scTemp = ''; + $this->values['PAGED_TABLE_ID'] = $tableId; + print (parent::render( PATH_CORE . 'templates/popupMenu.html', $scTemp )) ; + $sc = ""; + return $sc; + } } /** * XmlForm_Field_popupOption - XmlForm_Field_popupOption class + * * @package workflow.engine.ProcessMaker * @copyright COLOSA */ class XmlForm_Field_popupOption extends XmlForm_Field { - var $launch = ''; - -/** - * Get Events - * @return string - */ - function getEvents( ) - { - $script = '{name:"' . $this->name . '",text:"' . addcslashes($this->label,'\\"') . - '", launch:leimnud.closure({Function:function(target){' . $this->launch . '}, args:target})}'; - return $script; - } + var $launch = ''; + + /** + * Get Events + * + * @return string + */ + function getEvents () + { + $script = '{name:"' . $this->name . '",text:"' . addcslashes( $this->label, '\\"' ) . '", launch:leimnud.closure({Function:function(target){' . $this->launch . '}, args:target})}'; + return $script; + } } -?> + diff --git a/workflow/engine/classes/class.processes.php b/workflow/engine/classes/class.processes.php index a63a0b1d9..08916118c 100755 --- a/workflow/engine/classes/class.processes.php +++ b/workflow/engine/classes/class.processes.php @@ -1,2756 +1,2760 @@ -. - * - * For more information, contact Colosa Inc, 2566 Le Jeune Rd., - * Coral Gables, FL, 33134, USA, or email info@colosa.com. - */ - -require_once 'classes/model/Content.php'; -require_once 'classes/model/Process.php'; -require_once 'classes/model/Task.php'; -require_once 'classes/model/Route.php'; -require_once 'classes/model/SwimlanesElements.php'; -require_once 'classes/model/InputDocument.php'; -require_once 'classes/model/ObjectPermission.php'; -require_once 'classes/model/OutputDocument.php'; -require_once 'classes/model/Step.php'; -require_once 'classes/model/StepTrigger.php'; -require_once 'classes/model/Dynaform.php'; -require_once 'classes/model/Triggers.php'; -require_once 'classes/model/Groupwf.php'; -require_once 'classes/model/ReportTable.php'; -require_once 'classes/model/ReportVar.php'; -require_once 'classes/model/DbSource.php'; -require_once 'classes/model/StepSupervisor.php'; -require_once 'classes/model/SubProcess.php'; -require_once 'classes/model/CaseTracker.php'; -require_once 'classes/model/CaseTrackerObject.php'; -require_once 'classes/model/Stage.php'; -require_once 'classes/model/TaskUser.php'; -require_once 'classes/model/FieldCondition.php'; -require_once 'classes/model/Event.php'; -require_once 'classes/model/CaseScheduler.php'; -require_once 'classes/model/ProcessCategory.php'; - -G::LoadClass( 'tasks' ); -G::LoadClass( 'reportTables' ); -G::LoadClass( 'processMap' ); -G::LoadThirdParty( 'pear/json', 'class.json' ); - -class Processes -{ - /** - * change Status of any Process - * - * @param string $sProUid - * @return boolean - * @package workflow.engine.ProcessMaker - */ - public function changeStatus ($sProUid = '') - { - $oProcess = new Process(); - $Fields = $oProcess->Load( $sProUid ); - $proFields['PRO_UID'] = $sProUid; - if ($Fields['PRO_STATUS'] == 'ACTIVE') { - $proFields['PRO_STATUS'] = 'INACTIVE'; - } else { - $proFields['PRO_STATUS'] = 'ACTIVE'; - } - $oProcess->Update( $proFields ); - } - - /** - * change debug mode of any Process - * - * @param string $sProUid - * @return boolean - * @package workflow.engine.ProcessMaker - */ - public function changeDebugMode ($sProUid = '') - { - $oProcess = new Process(); - $Fields = $oProcess->Load( $sProUid ); - $proFields['PRO_UID'] = $sProUid; - if ($Fields['PRO_DEBUG'] == '1') { - $proFields['PRO_DEBUG'] = '0'; - } else { - $proFields['PRO_DEBUG'] = '1'; - } - $oProcess->Update( $proFields ); - } - - /** - * changes in DB the parent GUID - * - * @param $sProUid process uid - * @param $sParentUid process parent uid - * @return $sProUid - */ - public function changeProcessParent ($sProUid, $sParentUid) - { - $oProcess = new Process(); - $Fields = $oProcess->Load( $sProUid ); - $proFields['PRO_UID'] = $sProUid; - $Fields['PRO_PARENT'] == $sParentUid; - $oProcess->Update( $proFields ); - } - - /** - * verify if the process $sProUid exists - * - * @param string $sProUid - * @return boolean - */ - public function processExists ($sProUid = '') - { - $oProcess = new Process(); - return $oProcess->processExists( $sProUid ); - } - - /** - * get an unused process GUID - * - * @return $sProUid - */ - public function getUnusedProcessGUID () - { - do { - $sNewProUid = G::generateUniqueID(); - } while ($this->processExists( $sNewProUid )); - return $sNewProUid; - } - - /** - * verify if the task $sTasUid exists - * - * @param string $sTasUid - * @return boolean - */ - public function taskExists ($sTasUid = '') - { - $oTask = new Task(); - return $oTask->taskExists( $sTasUid ); - } - - /** - * get an unused task GUID - * - * @return $sTasUid - */ - public function getUnusedTaskGUID () - { - do { - $sNewTasUid = G::generateUniqueID(); - } while ($this->taskExists( $sNewTasUid )); - return $sNewTasUid; - } - - /** - * verify if the dynaform $sDynUid exists - * - * @param string $sDynUid - * @return boolean - */ - public function dynaformExists ($sDynUid = '') - { - $oDynaform = new Dynaform(); - return $oDynaform->dynaformExists( $sDynUid ); - } - - /** - * verify if the object exists - * - * @param string $sUid - * @return boolean - */ - public function inputExists ($sUid = '') - { - $oInput = new InputDocument(); - return $oInput->inputExists( $sUid ); - } - - /** - * verify if the object exists - * - * @param string $sUid - * @return boolean - */ - public function outputExists ($sUid = '') - { - $oOutput = new OutputDocument(); - return $oOutput->outputExists( $sUid ); - } - - /** - * verify if the object exists - * - * @param string $sUid - * @return boolean - */ - public function triggerExists ($sUid = '') - { - $oTrigger = new Triggers(); - return $oTrigger->triggerExists( $sUid ); - } - - /** - * verify if the object exists - * - * @param string $sUid - * @return boolean - */ - public function SubProcessExists ($sUid = '') - { - $oSubProcess = new SubProcess(); - return $oSubProcess->subProcessExists( $sUid ); - } - - /** - * verify if a caseTrackerObject object exists - * - * @param string $sUid - * @return boolean - */ - public function caseTrackerObjectExists ($sUid = '') - { - $oCaseTrackerObject = new CaseTrackerObject(); - return $oCaseTrackerObject->caseTrackerObjectExists( $sUid ); - } - - /** - * verify if a caseTracker Object exists - * - * @param string $sUid - * @return boolean - */ - public function caseTrackerExists ($sUid = '') - { - $oCaseTracker = new CaseTracker(); - return $oCaseTracker->caseTrackerExists( $sUid ); - } - - /** - * verify if a dbconnection exists - * - * @param string $sUid - * @return boolean - */ - public function dbConnectionExists ($sUid = '') - { - $oDBSource = new DbSource(); - return $oDBSource->Exists( $sUid ); - } - - /** - * verify if a objectPermission exists - * - * @param string $sUid - * @return boolean - */ - public function objectPermissionExists ($sUid = '') - { - $oObjectPermission = new ObjectPermission(); - return $oObjectPermission->Exists( $sUid ); - } - - /** - * verify if a route exists - * - * @param string $sUid - * @return boolean - */ - public function routeExists ($sUid = '') - { - $oRoute = new Route(); - return $oRoute->routeExists( $sUid ); - } - - /** - * verify if a stage exists - * - * @param string $sUid - * @return boolean - */ - public function stageExists ($sUid = '') - { - $oStage = new Stage(); - return $oStage->Exists( $sUid ); - } - - /** - * verify if a swimlane exists - * - * @param string $sUid - * @return boolean - */ - public function slExists ($sUid = '') - { - $oSL = new SwimlanesElements(); - return $oSL->swimlanesElementsExists( $sUid ); - } - - /** - * verify if a reportTable exists - * - * @param string $sUid - * @return boolean - */ - public function reportTableExists ($sUid = '') - { - $oReportTable = new ReportTable(); - return $oReportTable->reportTableExists( $sUid ); - } - - /** - * verify if a reportVar exists - * - * @param string $sUid - * @return boolean - */ - public function reportVarExists ($sUid = '') - { - $oReportVar = new ReportVar(); - return $oReportVar->reportVarExists( $sUid ); - } - - /** - * verify if a caseTrackerObject exists - * - * @param string $sUid - * @return boolean - */ - public function fieldsConditionsExists ($sUid = '') - { - $oFieldCondition = new FieldCondition(); - return $oFieldCondition->Exists( $sUid ); - } - - /** - * verify if an event exists - * - * @param string $sUid - * @return boolean - */ - public function eventExists ($sUid = '') - { - $oEvent = new Event(); - return $oEvent->Exists( $sUid ); - } - - /** - * verify if a caseScheduler exists - * - * @param string $sUid - * @return boolean - */ - public function caseSchedulerExists ($sUid = '') - { - $oCaseScheduler = new CaseScheduler(); - return $oCaseScheduler->Exists( $sUid ); - } - - /** - * get an unused input GUID - * - * @return $sProUid - */ - public function getUnusedInputGUID () - { - do { - $sNewUid = G::generateUniqueID(); - } while ($this->inputExists( $sNewUid )); - return $sNewUid; - } - - /** - * get an unused output GUID - * - * @return $sProUid - */ - public function getUnusedOutputGUID () - { - do { - $sNewUid = G::generateUniqueID(); - } while ($this->outputExists( $sNewUid )); - return $sNewUid; - } - - /** - * get an unused trigger GUID - * - * @return $sProUid - */ - public function getUnusedTriggerGUID () - { - do { - $sNewUid = G::generateUniqueID(); - } while ($this->triggerExists( $sNewUid )); - return $sNewUid; - } - - /** - * get an unused trigger GUID - * - * @return $sProUid - */ - public function getUnusedSubProcessGUID () - { - do { - $sNewUid = G::generateUniqueID(); - } while ($this->subProcessExists( $sNewUid )); - return $sNewUid; - } - - /** - * get a Unused CaseTrackerObject GUID - * - * @return $sNewUid a new generated Uid - */ - public function getUnusedCaseTrackerObjectGUID () - { - do { - $sNewUid = G::generateUniqueID(); - } while ($this->caseTrackerObjectExists( $sNewUid )); - return $sNewUid; - } - - /** - * get a Unused Database Source GUID - * - * @return $sNewUid a new generated Uid - */ - public function getUnusedDBSourceGUID () - { - do { - $sNewUid = G::generateUniqueID(); - } while ($this->dbConnectionExists( $sNewUid )); - return $sNewUid; - } - - /** - * get a Unused Object Permission GUID - * - * @return $sNewUid a new generated Uid - */ - public function getUnusedObjectPermissionGUID () - { - do { - $sNewUid = G::generateUniqueID(); - } while ($this->objectPermissionExists( $sNewUid )); - return $sNewUid; - } - - /** - * get a Unused Route GUID - * - * @return $sNewUid a new generated Uid - */ - public function getUnusedRouteGUID () - { - do { - $sNewUid = G::generateUniqueID(); - } while ($this->routeExists( $sNewUid )); - return $sNewUid; - } - - /** - * get a Unused Stage GUID - * - * @return $sNewUid a new generated Uid - */ - public function getUnusedStageGUID () - { - do { - $sNewUid = G::generateUniqueID(); - } while ($this->stageExists( $sNewUid )); - return $sNewUid; - } - - /** - * get a Unused SL GUID - * - * @return $sNewUid a new generated Uid - */ - public function getUnusedSLGUID () - { - do { - $sNewUid = G::generateUniqueID(); - } while ($this->slExists( $sNewUid )); - return $sNewUid; - } - - /** - * get a Unused Report Table GUID - * - * @return $sNewUid a new generated Uid - */ - public function getUnusedRTGUID () - { - do { - $sNewUid = G::generateUniqueID(); - } while ($this->reportTableExists( $sNewUid )); - return $sNewUid; - } - - /** - * get a Unused Report Var GUID - * - * @return $sNewUid a new generated Uid - */ - public function getUnusedRTVGUID () - { - do { - $sNewUid = G::generateUniqueID(); - } while ($this->reportVarExists( $sNewUid )); - return $sNewUid; - } - - /** - * verify if the object exists - * - * @param string $sUid - * @return boolean - */ - public function stepExists ($sUid = '') - { - $oStep = new Step(); - return $oStep->stepExists( $sUid ); - } - - /** - * get an unused step GUID - * - * @return $sUid - */ - public function getUnusedStepGUID () - { - do { - $sNewUid = G::generateUniqueID(); - } while ($this->stepExists( $sNewUid )); - return $sNewUid; - } - +. + * + * For more information, contact Colosa Inc, 2566 Le Jeune Rd., + * Coral Gables, FL, 33134, USA, or email info@colosa.com. + */ + +require_once 'classes/model/Content.php'; +require_once 'classes/model/Process.php'; +require_once 'classes/model/Task.php'; +require_once 'classes/model/Route.php'; +require_once 'classes/model/SwimlanesElements.php'; +require_once 'classes/model/InputDocument.php'; +require_once 'classes/model/ObjectPermission.php'; +require_once 'classes/model/OutputDocument.php'; +require_once 'classes/model/Step.php'; +require_once 'classes/model/StepTrigger.php'; +require_once 'classes/model/Dynaform.php'; +require_once 'classes/model/Triggers.php'; +require_once 'classes/model/Groupwf.php'; +require_once 'classes/model/ReportTable.php'; +require_once 'classes/model/ReportVar.php'; +require_once 'classes/model/DbSource.php'; +require_once 'classes/model/StepSupervisor.php'; +require_once 'classes/model/SubProcess.php'; +require_once 'classes/model/CaseTracker.php'; +require_once 'classes/model/CaseTrackerObject.php'; +require_once 'classes/model/Stage.php'; +require_once 'classes/model/TaskUser.php'; +require_once 'classes/model/FieldCondition.php'; +require_once 'classes/model/Event.php'; +require_once 'classes/model/CaseScheduler.php'; +require_once 'classes/model/ProcessCategory.php'; + +G::LoadClass( 'tasks' ); +G::LoadClass( 'reportTables' ); +G::LoadClass( 'processMap' ); +G::LoadThirdParty( 'pear/json', 'class.json' ); + +class Processes +{ + + /** + * change Status of any Process + * + * @param string $sProUid + * @return boolean + * @package workflow.engine.ProcessMaker + */ + public function changeStatus ($sProUid = '') + { + $oProcess = new Process(); + $Fields = $oProcess->Load( $sProUid ); + $proFields['PRO_UID'] = $sProUid; + if ($Fields['PRO_STATUS'] == 'ACTIVE') { + $proFields['PRO_STATUS'] = 'INACTIVE'; + } else { + $proFields['PRO_STATUS'] = 'ACTIVE'; + } + $oProcess->Update( $proFields ); + } + + /** + * change debug mode of any Process + * + * @param string $sProUid + * @return boolean + * @package workflow.engine.ProcessMaker + */ + public function changeDebugMode ($sProUid = '') + { + $oProcess = new Process(); + $Fields = $oProcess->Load( $sProUid ); + $proFields['PRO_UID'] = $sProUid; + if ($Fields['PRO_DEBUG'] == '1') { + $proFields['PRO_DEBUG'] = '0'; + } else { + $proFields['PRO_DEBUG'] = '1'; + } + $oProcess->Update( $proFields ); + } + + /** + * changes in DB the parent GUID + * + * @param $sProUid process uid + * @param $sParentUid process parent uid + * @return $sProUid + */ + public function changeProcessParent ($sProUid, $sParentUid) + { + $oProcess = new Process(); + $Fields = $oProcess->Load( $sProUid ); + $proFields['PRO_UID'] = $sProUid; + $Fields['PRO_PARENT'] == $sParentUid; + $oProcess->Update( $proFields ); + } + + /** + * verify if the process $sProUid exists + * + * @param string $sProUid + * @return boolean + */ + public function processExists ($sProUid = '') + { + $oProcess = new Process(); + return $oProcess->processExists( $sProUid ); + } + + /** + * get an unused process GUID + * + * @return $sProUid + */ + public function getUnusedProcessGUID () + { + do { + $sNewProUid = G::generateUniqueID(); + } while ($this->processExists( $sNewProUid )); + return $sNewProUid; + } + + /** + * verify if the task $sTasUid exists + * + * @param string $sTasUid + * @return boolean + */ + public function taskExists ($sTasUid = '') + { + $oTask = new Task(); + return $oTask->taskExists( $sTasUid ); + } + + /** + * get an unused task GUID + * + * @return $sTasUid + */ + public function getUnusedTaskGUID () + { + do { + $sNewTasUid = G::generateUniqueID(); + } while ($this->taskExists( $sNewTasUid )); + return $sNewTasUid; + } + + /** + * verify if the dynaform $sDynUid exists + * + * @param string $sDynUid + * @return boolean + */ + public function dynaformExists ($sDynUid = '') + { + $oDynaform = new Dynaform(); + return $oDynaform->dynaformExists( $sDynUid ); + } + + /** + * verify if the object exists + * + * @param string $sUid + * @return boolean + */ + public function inputExists ($sUid = '') + { + $oInput = new InputDocument(); + return $oInput->inputExists( $sUid ); + } + + /** + * verify if the object exists + * + * @param string $sUid + * @return boolean + */ + public function outputExists ($sUid = '') + { + $oOutput = new OutputDocument(); + return $oOutput->outputExists( $sUid ); + } + + /** + * verify if the object exists + * + * @param string $sUid + * @return boolean + */ + public function triggerExists ($sUid = '') + { + $oTrigger = new Triggers(); + return $oTrigger->triggerExists( $sUid ); + } + + /** + * verify if the object exists + * + * @param string $sUid + * @return boolean + */ + public function SubProcessExists ($sUid = '') + { + $oSubProcess = new SubProcess(); + return $oSubProcess->subProcessExists( $sUid ); + } + + /** + * verify if a caseTrackerObject object exists + * + * @param string $sUid + * @return boolean + */ + public function caseTrackerObjectExists ($sUid = '') + { + $oCaseTrackerObject = new CaseTrackerObject(); + return $oCaseTrackerObject->caseTrackerObjectExists( $sUid ); + } + + /** + * verify if a caseTracker Object exists + * + * @param string $sUid + * @return boolean + */ + public function caseTrackerExists ($sUid = '') + { + $oCaseTracker = new CaseTracker(); + return $oCaseTracker->caseTrackerExists( $sUid ); + } + + /** + * verify if a dbconnection exists + * + * @param string $sUid + * @return boolean + */ + public function dbConnectionExists ($sUid = '') + { + $oDBSource = new DbSource(); + return $oDBSource->Exists( $sUid ); + } + + /** + * verify if a objectPermission exists + * + * @param string $sUid + * @return boolean + */ + public function objectPermissionExists ($sUid = '') + { + $oObjectPermission = new ObjectPermission(); + return $oObjectPermission->Exists( $sUid ); + } + + /** + * verify if a route exists + * + * @param string $sUid + * @return boolean + */ + public function routeExists ($sUid = '') + { + $oRoute = new Route(); + return $oRoute->routeExists( $sUid ); + } + + /** + * verify if a stage exists + * + * @param string $sUid + * @return boolean + */ + public function stageExists ($sUid = '') + { + $oStage = new Stage(); + return $oStage->Exists( $sUid ); + } + + /** + * verify if a swimlane exists + * + * @param string $sUid + * @return boolean + */ + public function slExists ($sUid = '') + { + $oSL = new SwimlanesElements(); + return $oSL->swimlanesElementsExists( $sUid ); + } + + /** + * verify if a reportTable exists + * + * @param string $sUid + * @return boolean + */ + public function reportTableExists ($sUid = '') + { + $oReportTable = new ReportTable(); + return $oReportTable->reportTableExists( $sUid ); + } + + /** + * verify if a reportVar exists + * + * @param string $sUid + * @return boolean + */ + public function reportVarExists ($sUid = '') + { + $oReportVar = new ReportVar(); + return $oReportVar->reportVarExists( $sUid ); + } + + /** + * verify if a caseTrackerObject exists + * + * @param string $sUid + * @return boolean + */ + public function fieldsConditionsExists ($sUid = '') + { + $oFieldCondition = new FieldCondition(); + return $oFieldCondition->Exists( $sUid ); + } + + /** + * verify if an event exists + * + * @param string $sUid + * @return boolean + */ + public function eventExists ($sUid = '') + { + $oEvent = new Event(); + return $oEvent->Exists( $sUid ); + } + + /** + * verify if a caseScheduler exists + * + * @param string $sUid + * @return boolean + */ + public function caseSchedulerExists ($sUid = '') + { + $oCaseScheduler = new CaseScheduler(); + return $oCaseScheduler->Exists( $sUid ); + } + + /** + * get an unused input GUID + * + * @return $sProUid + */ + public function getUnusedInputGUID () + { + do { + $sNewUid = G::generateUniqueID(); + } while ($this->inputExists( $sNewUid )); + return $sNewUid; + } + + /** + * get an unused output GUID + * + * @return $sProUid + */ + public function getUnusedOutputGUID () + { + do { + $sNewUid = G::generateUniqueID(); + } while ($this->outputExists( $sNewUid )); + return $sNewUid; + } + + /** + * get an unused trigger GUID + * + * @return $sProUid + */ + public function getUnusedTriggerGUID () + { + do { + $sNewUid = G::generateUniqueID(); + } while ($this->triggerExists( $sNewUid )); + return $sNewUid; + } + + /** + * get an unused trigger GUID + * + * @return $sProUid + */ + public function getUnusedSubProcessGUID () + { + do { + $sNewUid = G::generateUniqueID(); + } while ($this->subProcessExists( $sNewUid )); + return $sNewUid; + } + + /** + * get a Unused CaseTrackerObject GUID + * + * @return $sNewUid a new generated Uid + */ + public function getUnusedCaseTrackerObjectGUID () + { + do { + $sNewUid = G::generateUniqueID(); + } while ($this->caseTrackerObjectExists( $sNewUid )); + return $sNewUid; + } + + /** + * get a Unused Database Source GUID + * + * @return $sNewUid a new generated Uid + */ + public function getUnusedDBSourceGUID () + { + do { + $sNewUid = G::generateUniqueID(); + } while ($this->dbConnectionExists( $sNewUid )); + return $sNewUid; + } + + /** + * get a Unused Object Permission GUID + * + * @return $sNewUid a new generated Uid + */ + public function getUnusedObjectPermissionGUID () + { + do { + $sNewUid = G::generateUniqueID(); + } while ($this->objectPermissionExists( $sNewUid )); + return $sNewUid; + } + + /** + * get a Unused Route GUID + * + * @return $sNewUid a new generated Uid + */ + public function getUnusedRouteGUID () + { + do { + $sNewUid = G::generateUniqueID(); + } while ($this->routeExists( $sNewUid )); + return $sNewUid; + } + + /** + * get a Unused Stage GUID + * + * @return $sNewUid a new generated Uid + */ + public function getUnusedStageGUID () + { + do { + $sNewUid = G::generateUniqueID(); + } while ($this->stageExists( $sNewUid )); + return $sNewUid; + } + + /** + * get a Unused SL GUID + * + * @return $sNewUid a new generated Uid + */ + public function getUnusedSLGUID () + { + do { + $sNewUid = G::generateUniqueID(); + } while ($this->slExists( $sNewUid )); + return $sNewUid; + } + + /** + * get a Unused Report Table GUID + * + * @return $sNewUid a new generated Uid + */ + public function getUnusedRTGUID () + { + do { + $sNewUid = G::generateUniqueID(); + } while ($this->reportTableExists( $sNewUid )); + return $sNewUid; + } + + /** + * get a Unused Report Var GUID + * + * @return $sNewUid a new generated Uid + */ + public function getUnusedRTVGUID () + { + do { + $sNewUid = G::generateUniqueID(); + } while ($this->reportVarExists( $sNewUid )); + return $sNewUid; + } + + /** + * verify if the object exists + * + * @param string $sUid + * @return boolean + */ + public function stepExists ($sUid = '') + { + $oStep = new Step(); + return $oStep->stepExists( $sUid ); + } + + /** + * get an unused step GUID + * + * @return $sUid + */ + public function getUnusedStepGUID () + { + do { + $sNewUid = G::generateUniqueID(); + } while ($this->stepExists( $sNewUid )); + return $sNewUid; + } + /* - * get an unused Dynaform GUID - * @return $sDynUid - */ - public function getUnusedDynaformGUID () - { - do { - $sNewUid = G::generateUniqueID(); - } while ($this->dynaformExists( $sNewUid )); - return $sNewUid; - } - - /** - * get a Unused Field Condition GUID - * - * @return $sNewUid a new generated Uid - */ - public function getUnusedFieldConditionGUID () - { - do { - $sNewUid = G::generateUniqueID(); - } while ($this->fieldsConditionsExists( $sNewUid )); - return $sNewUid; - } - - /** - * get a Unused Event GUID - * - * @return $sNewUid a new generated Uid - */ - public function getUnusedEventGUID () - { - do { - $sNewUid = G::generateUniqueID(); - } while ($this->eventExists( $sNewUid )); - return $sNewUid; - } - - /** - * get a Unused Case Scheduler GUID - * - * @return $sNewUid a new generated Uid - */ - public function getUnusedCaseSchedulerGUID () - { - do { - $sNewUid = G::generateUniqueID(); - } while ($this->caseSchedulerExists( $sNewUid )); - return $sNewUid; - } - - /** - * change the GUID for a serialized process - * - * @param string $sProUid - * @return boolean - */ - public function setProcessGUID (&$oData, $sNewProUid) - { - $sProUid = $oData->process['PRO_UID']; - $oData->process['PRO_UID'] = $sNewProUid; - - if (isset( $oData->tasks ) && is_array( $oData->tasks )) { - foreach ($oData->tasks as $key => $val) { - $oData->tasks[$key]['PRO_UID'] = $sNewProUid; - } - } - - if (isset( $oData->routes ) && is_array( $oData->routes )) { - foreach ($oData->routes as $key => $val) { - $oData->routes[$key]['PRO_UID'] = $sNewProUid; - } - } - - if (isset( $oData->lanes ) && is_array( $oData->lanes )) { - foreach ($oData->lanes as $key => $val) { - $oData->lanes[$key]['PRO_UID'] = $sNewProUid; - } - } - - if (isset( $oData->inputs ) && is_array( $oData->inputs )) { - foreach ($oData->inputs as $key => $val) { - $oData->inputs[$key]['PRO_UID'] = $sNewProUid; - } - } - - if (isset( $oData->outputs ) && is_array( $oData->outputs )) { - foreach ($oData->outputs as $key => $val) { - $oData->outputs[$key]['PRO_UID'] = $sNewProUid; - } - } - - if (isset( $oData->steps ) && is_array( $oData->steps )) { - foreach ($oData->steps as $key => $val) { - $oData->steps[$key]['PRO_UID'] = $sNewProUid; - } - } - - if (isset( $oData->dynaforms ) && is_array( $oData->dynaforms )) { - foreach ($oData->dynaforms as $key => $val) { - $oData->dynaforms[$key]['PRO_UID'] = $sNewProUid; - } - } - - if (isset( $oData->triggers ) && is_array( $oData->triggers )) { - foreach ($oData->triggers as $key => $val) { - $oData->triggers[$key]['PRO_UID'] = $sNewProUid; - } - } - - if (isset( $oData->reportTables ) && is_array( $oData->reportTables )) { - foreach ($oData->reportTables as $key => $val) { - $oData->reportTables[$key]['PRO_UID'] = $sNewProUid; - } - } - - if (isset( $oData->reportTablesVars ) && is_array( $oData->reportTablesVars )) { - foreach ($oData->reportTablesVars as $key => $val) { - $oData->reportTablesVars[$key]['PRO_UID'] = $sNewProUid; - } - } - - if (isset( $oData->dbconnections ) && is_array( $oData->dbconnections )) { - foreach ($oData->dbconnections as $key => $val) { - $oData->dbconnections[$key]['PRO_UID'] = $sNewProUid; - } - } - - if (isset( $oData->stepSupervisor ) && is_array( $oData->stepSupervisor )) { - foreach ($oData->stepSupervisor as $key => $val) { - $oData->stepSupervisor[$key]['PRO_UID'] = $sNewProUid; - } - } - - if (isset( $oData->objectPermissions ) && is_array( $oData->objectPermissions )) { - foreach ($oData->objectPermissions as $key => $val) { - $oData->objectPermissions[$key]['PRO_UID'] = $sNewProUid; - } - } - - if (isset( $oData->caseTracker ) && is_array( $oData->caseTracker )) { - foreach ($oData->caseTracker as $key => $val) { - $oData->caseTracker[$key]['PRO_UID'] = $sNewProUid; - } - } - - if (isset( $oData->caseTrackerObject ) && is_array( $oData->caseTrackerObject )) { - foreach ($oData->caseTrackerObject as $key => $val) { - $oData->caseTrackerObject[$key]['PRO_UID'] = $sNewProUid; - } - } - - if (isset( $oData->stage ) && is_array( $oData->stage )) { - foreach ($oData->stage as $key => $val) { - $oData->stage[$key]['PRO_UID'] = $sNewProUid; - } - } - - if (isset( $oData->subProcess ) && is_array( $oData->subProcess )) { - foreach ($oData->subProcess as $key => $val) { - $oData->subProcess[$key]['PRO_PARENT'] = $sNewProUid; - } - } - - if (isset( $oData->event ) && is_array( $oData->event )) { - foreach ($oData->event as $key => $val) { - $oData->event[$key]['PRO_UID'] = $sNewProUid; - } - } - - if (isset( $oData->caseScheduler ) && is_array( $oData->caseScheduler )) { - foreach ($oData->caseScheduler as $key => $val) { - $oData->caseScheduler[$key]['PRO_UID'] = $sNewProUid; - } - } - return true; - } - - /** - * change the GUID Parent for a serialized process, only in serialized data - * - * @param string $sProUid - * @return boolean - */ - public function setProcessParent (&$oData, $sParentUid) - { - $oData->process['PRO_PARENT'] = $sParentUid; - $oData->process['PRO_CREATE_DATE'] = date( 'Y-m-d H:i:s' ); - $oData->process['PRO_UPDATE_DATE'] = date( 'Y-m-d H:i:s' ); - return true; - } - - /** - * change and Renew all Task GUID, because the process needs to have a new set of tasks - * - * @param string $oData - * @return boolean - */ - public function renewAllTaskGuid (&$oData) - { - $map = array (); - foreach ($oData->tasks as $key => $val) { - $newGuid = $this->getUnusedTaskGUID(); - $map[$val['TAS_UID']] = $newGuid; - $oData->tasks[$key]['TAS_UID'] = $newGuid; - } - if (isset( $oData->routes ) && is_array( $oData->routes )) { - foreach ($oData->routes as $key => $val) { - $newGuid = $map[$val['TAS_UID']]; - $oData->routes[$key]['TAS_UID'] = $newGuid; - if (strlen( $val['ROU_NEXT_TASK'] ) > 0 && $val['ROU_NEXT_TASK'] > 0) { - $newGuid = $map[$val['ROU_NEXT_TASK']]; - $oData->routes[$key]['ROU_NEXT_TASK'] = $newGuid; - } - } - } - - if (isset( $oData->steps ) && is_array( $oData->steps )) { - foreach ($oData->steps as $key => $val) { - $newGuid = $map[$val['TAS_UID']]; - $oData->steps[$key]['TAS_UID'] = $newGuid; - } - } - - if (isset( $oData->steptriggers ) && is_array( $oData->steptriggers )) { - foreach ($oData->steptriggers as $key => $val) { - $newGuid = $map[$val['TAS_UID']]; - $oData->steptriggers[$key]['TAS_UID'] = $newGuid; - } - } - - if (isset( $oData->taskusers ) && is_array( $oData->taskusers )) { - foreach ($oData->taskusers as $key => $val) { - $newGuid = $map[$val['TAS_UID']]; - $oData->taskusers[$key]['TAS_UID'] = $newGuid; - } - } - - if (isset( $oData->subProcess ) && is_array( $oData->subProcess )) { - foreach ($oData->subProcess as $key => $val) { - $newGuid = $map[$val['TAS_PARENT']]; - $oData->subProcess[$key]['TAS_PARENT'] = $newGuid; - if (isset( $map[$val['TAS_UID']] )) { - $newGuid = $map[$val['TAS_UID']]; - $oData->subProcess[$key]['TAS_UID'] = $newGuid; - } - } - } - - if (isset( $oData->objectPermissions ) && is_array( $oData->objectPermissions )) { - foreach ($oData->objectPermissions as $key => $val) { - if (isset( $map[$val['TAS_UID']] )) { - $newGuid = $map[$val['TAS_UID']]; - $oData->objectPermissions[$key]['TAS_UID'] = $newGuid; - } - } - } - + * get an unused Dynaform GUID + * @return $sDynUid + */ + public function getUnusedDynaformGUID () + { + do { + $sNewUid = G::generateUniqueID(); + } while ($this->dynaformExists( $sNewUid )); + return $sNewUid; + } + + /** + * get a Unused Field Condition GUID + * + * @return $sNewUid a new generated Uid + */ + public function getUnusedFieldConditionGUID () + { + do { + $sNewUid = G::generateUniqueID(); + } while ($this->fieldsConditionsExists( $sNewUid )); + return $sNewUid; + } + + /** + * get a Unused Event GUID + * + * @return $sNewUid a new generated Uid + */ + public function getUnusedEventGUID () + { + do { + $sNewUid = G::generateUniqueID(); + } while ($this->eventExists( $sNewUid )); + return $sNewUid; + } + + /** + * get a Unused Case Scheduler GUID + * + * @return $sNewUid a new generated Uid + */ + public function getUnusedCaseSchedulerGUID () + { + do { + $sNewUid = G::generateUniqueID(); + } while ($this->caseSchedulerExists( $sNewUid )); + return $sNewUid; + } + + /** + * change the GUID for a serialized process + * + * @param string $sProUid + * @return boolean + */ + public function setProcessGUID (&$oData, $sNewProUid) + { + $sProUid = $oData->process['PRO_UID']; + $oData->process['PRO_UID'] = $sNewProUid; + + if (isset( $oData->tasks ) && is_array( $oData->tasks )) { + foreach ($oData->tasks as $key => $val) { + $oData->tasks[$key]['PRO_UID'] = $sNewProUid; + } + } + + if (isset( $oData->routes ) && is_array( $oData->routes )) { + foreach ($oData->routes as $key => $val) { + $oData->routes[$key]['PRO_UID'] = $sNewProUid; + } + } + + if (isset( $oData->lanes ) && is_array( $oData->lanes )) { + foreach ($oData->lanes as $key => $val) { + $oData->lanes[$key]['PRO_UID'] = $sNewProUid; + } + } + + if (isset( $oData->inputs ) && is_array( $oData->inputs )) { + foreach ($oData->inputs as $key => $val) { + $oData->inputs[$key]['PRO_UID'] = $sNewProUid; + } + } + + if (isset( $oData->outputs ) && is_array( $oData->outputs )) { + foreach ($oData->outputs as $key => $val) { + $oData->outputs[$key]['PRO_UID'] = $sNewProUid; + } + } + + if (isset( $oData->steps ) && is_array( $oData->steps )) { + foreach ($oData->steps as $key => $val) { + $oData->steps[$key]['PRO_UID'] = $sNewProUid; + } + } + + if (isset( $oData->dynaforms ) && is_array( $oData->dynaforms )) { + foreach ($oData->dynaforms as $key => $val) { + $oData->dynaforms[$key]['PRO_UID'] = $sNewProUid; + } + } + + if (isset( $oData->triggers ) && is_array( $oData->triggers )) { + foreach ($oData->triggers as $key => $val) { + $oData->triggers[$key]['PRO_UID'] = $sNewProUid; + } + } + + if (isset( $oData->reportTables ) && is_array( $oData->reportTables )) { + foreach ($oData->reportTables as $key => $val) { + $oData->reportTables[$key]['PRO_UID'] = $sNewProUid; + } + } + + if (isset( $oData->reportTablesVars ) && is_array( $oData->reportTablesVars )) { + foreach ($oData->reportTablesVars as $key => $val) { + $oData->reportTablesVars[$key]['PRO_UID'] = $sNewProUid; + } + } + + if (isset( $oData->dbconnections ) && is_array( $oData->dbconnections )) { + foreach ($oData->dbconnections as $key => $val) { + $oData->dbconnections[$key]['PRO_UID'] = $sNewProUid; + } + } + + if (isset( $oData->stepSupervisor ) && is_array( $oData->stepSupervisor )) { + foreach ($oData->stepSupervisor as $key => $val) { + $oData->stepSupervisor[$key]['PRO_UID'] = $sNewProUid; + } + } + + if (isset( $oData->objectPermissions ) && is_array( $oData->objectPermissions )) { + foreach ($oData->objectPermissions as $key => $val) { + $oData->objectPermissions[$key]['PRO_UID'] = $sNewProUid; + } + } + + if (isset( $oData->caseTracker ) && is_array( $oData->caseTracker )) { + foreach ($oData->caseTracker as $key => $val) { + $oData->caseTracker[$key]['PRO_UID'] = $sNewProUid; + } + } + + if (isset( $oData->caseTrackerObject ) && is_array( $oData->caseTrackerObject )) { + foreach ($oData->caseTrackerObject as $key => $val) { + $oData->caseTrackerObject[$key]['PRO_UID'] = $sNewProUid; + } + } + + if (isset( $oData->stage ) && is_array( $oData->stage )) { + foreach ($oData->stage as $key => $val) { + $oData->stage[$key]['PRO_UID'] = $sNewProUid; + } + } + + if (isset( $oData->subProcess ) && is_array( $oData->subProcess )) { + foreach ($oData->subProcess as $key => $val) { + $oData->subProcess[$key]['PRO_PARENT'] = $sNewProUid; + } + } + + if (isset( $oData->event ) && is_array( $oData->event )) { + foreach ($oData->event as $key => $val) { + $oData->event[$key]['PRO_UID'] = $sNewProUid; + } + } + + if (isset( $oData->caseScheduler ) && is_array( $oData->caseScheduler )) { + foreach ($oData->caseScheduler as $key => $val) { + $oData->caseScheduler[$key]['PRO_UID'] = $sNewProUid; + } + } + return true; + } + + /** + * change the GUID Parent for a serialized process, only in serialized data + * + * @param string $sProUid + * @return boolean + */ + public function setProcessParent (&$oData, $sParentUid) + { + $oData->process['PRO_PARENT'] = $sParentUid; + $oData->process['PRO_CREATE_DATE'] = date( 'Y-m-d H:i:s' ); + $oData->process['PRO_UPDATE_DATE'] = date( 'Y-m-d H:i:s' ); + return true; + } + + /** + * change and Renew all Task GUID, because the process needs to have a new set of tasks + * + * @param string $oData + * @return boolean + */ + public function renewAllTaskGuid (&$oData) + { + $map = array (); + foreach ($oData->tasks as $key => $val) { + $newGuid = $this->getUnusedTaskGUID(); + $map[$val['TAS_UID']] = $newGuid; + $oData->tasks[$key]['TAS_UID'] = $newGuid; + } + if (isset( $oData->routes ) && is_array( $oData->routes )) { + foreach ($oData->routes as $key => $val) { + $newGuid = $map[$val['TAS_UID']]; + $oData->routes[$key]['TAS_UID'] = $newGuid; + if (strlen( $val['ROU_NEXT_TASK'] ) > 0 && $val['ROU_NEXT_TASK'] > 0) { + $newGuid = $map[$val['ROU_NEXT_TASK']]; + $oData->routes[$key]['ROU_NEXT_TASK'] = $newGuid; + } + } + } + + if (isset( $oData->steps ) && is_array( $oData->steps )) { + foreach ($oData->steps as $key => $val) { + $newGuid = $map[$val['TAS_UID']]; + $oData->steps[$key]['TAS_UID'] = $newGuid; + } + } + + if (isset( $oData->steptriggers ) && is_array( $oData->steptriggers )) { + foreach ($oData->steptriggers as $key => $val) { + $newGuid = $map[$val['TAS_UID']]; + $oData->steptriggers[$key]['TAS_UID'] = $newGuid; + } + } + + if (isset( $oData->taskusers ) && is_array( $oData->taskusers )) { + foreach ($oData->taskusers as $key => $val) { + $newGuid = $map[$val['TAS_UID']]; + $oData->taskusers[$key]['TAS_UID'] = $newGuid; + } + } + + if (isset( $oData->subProcess ) && is_array( $oData->subProcess )) { + foreach ($oData->subProcess as $key => $val) { + $newGuid = $map[$val['TAS_PARENT']]; + $oData->subProcess[$key]['TAS_PARENT'] = $newGuid; + if (isset( $map[$val['TAS_UID']] )) { + $newGuid = $map[$val['TAS_UID']]; + $oData->subProcess[$key]['TAS_UID'] = $newGuid; + } + } + } + + if (isset( $oData->objectPermissions ) && is_array( $oData->objectPermissions )) { + foreach ($oData->objectPermissions as $key => $val) { + if (isset( $map[$val['TAS_UID']] )) { + $newGuid = $map[$val['TAS_UID']]; + $oData->objectPermissions[$key]['TAS_UID'] = $newGuid; + } + } + } + // New process bpmn - if (isset( $oData->event ) && is_array( $oData->event )) { - foreach ($oData->event as $key => $val) { - if (isset( $val['EVN_TAS_UID_FROM'] ) && isset( $map[$val['EVN_TAS_UID_FROM']] )) { - $newGuid = $map[$val['EVN_TAS_UID_FROM']]; - $oData->event[$key]['EVN_TAS_UID_FROM'] = $newGuid; - } - } - } - - if (isset( $oData->caseScheduler ) && is_array( $oData->caseScheduler )) { - foreach ($oData->caseScheduler as $key => $val) { - if (isset( $map[$val['TAS_UID']] )) { - $newGuid = $map[$val['TAS_UID']]; - $oData->caseScheduler[$key]['TAS_UID'] = $newGuid; - } - } - } - - } - - /** - * change and Renew all Dynaform GUID, because the process needs to have a new set of dynaforms - * - * @param string $oData - * @return boolean - */ - public function renewAllDynaformGuid (&$oData) - { - $map = array (); - foreach ($oData->dynaforms as $key => $val) { - $newGuid = $this->getUnusedDynaformGUID(); - $map[$val['DYN_UID']] = $newGuid; - $oData->dynaforms[$key]['DYN_UID'] = $newGuid; - } - - if (isset( $oData->process['PRO_DYNAFORMS'] ) && ! is_array( $oData->process['PRO_DYNAFORMS'] )) { - $oData->process['PRO_DYNAFORMS'] = @unserialize( $oData->process['PRO_DYNAFORMS'] ); - } - - if (! isset( $oData->process['PRO_DYNAFORMS']['PROCESS'] )) { - $oData->process['PRO_DYNAFORMS']['PROCESS'] = ''; - } - - if ($oData->process['PRO_DYNAFORMS']['PROCESS'] != '') { - $oData->process['PRO_DYNAFORMS']['PROCESS'] = $map[$oData->process['PRO_DYNAFORMS']['PROCESS']]; - } - - foreach ($oData->steps as $key => $val) { - if ($val['STEP_TYPE_OBJ'] == 'DYNAFORM') { - $newGuid = $map[$val['STEP_UID_OBJ']]; - $oData->steps[$key]['STEP_UID_OBJ'] = $newGuid; - } - } - - if (isset( $oData->caseTrackerObject ) && is_array( $oData->caseTrackerObject )) { - foreach ($oData->caseTrackerObject as $key => $val) { - if ($val['CTO_TYPE_OBJ'] == 'DYNAFORM') { - $newGuid = $map[$val['CTO_UID_OBJ']]; - $oData->steps[$key]['CTO_UID_OBJ'] = $newGuid; - } - } - } - if (isset( $oData->objectPermissions ) && is_array( $oData->objectPermissions )) { - foreach ($oData->objectPermissions as $key => $val) { - if ($val['OP_OBJ_TYPE'] == 'DYNAFORM') { - if (isset( $map[$val['OP_OBJ_UID']] )) { - $newGuid = $map[$val['OP_OBJ_UID']]; - $oData->objectPermissions[$key]['OP_OBJ_UID'] = $newGuid; - } - } - } - } - if (isset( $oData->stepSupervisor ) && is_array( $oData->stepSupervisor )) { - foreach ($oData->stepSupervisor as $key => $val) { - if ($val['STEP_TYPE_OBJ'] == 'DYNAFORM') { - $newGuid = $map[$val['STEP_UID_OBJ']]; - $oData->stepSupervisor[$key]['STEP_UID_OBJ'] = $newGuid; - } - } - foreach ($oData->dynaformFiles as $key => $val) { - $newGuid = $map[$key]; - $oData->dynaformFiles[$key] = $newGuid; - } - } - if (isset( $oData->gridFiles )) { - foreach ($oData->gridFiles as $key => $val) { - $newGuid = $map[$key]; - $oData->gridFiles[$key] = $newGuid; - } - } - if (isset( $oData->fieldCondition ) && is_array( $oData->fieldCondition )) { - foreach ($oData->fieldCondition as $key => $val) { - $newGuid = $map[$val['FCD_DYN_UID']]; - $oData->fieldCondition[$key]['FCD_DYN_UID'] = $newGuid; - } - } - - } - - /** - * get a Process with a search based in the process Uid - * - * @param $sProUid string process Uid - * @return $oProcess Process object - */ - public function getProcessRow ($sProUid, $getAllLang = false) - { - $oProcess = new Process(); - return $oProcess->Load( $sProUid, $getAllLang ); - } - - /** - * creates a process new process if a process exists with the same uid of the - * $row['PRO_UID'] parameter then deletes it from the database and creates - * a new one based on the $row parameter - * - * @param $row array parameter with the process data - * @return $oProcess Process object - */ - public function createProcessRow ($row) - { - $oProcess = new Process(); - if ($oProcess->processExists( $row['PRO_UID'] )) { - $oProcess->remove( $row['PRO_UID'] ); - } - return $oProcess->createRow( $row ); - } - - /** - * Update a Process register in DB, if the process doesn't exist with the same - * uid of the $row['PRO_UID'] parameter the function creates a new one based - * on the $row parameter data. - * - * @param $row array parameter with the process data - * @return $oProcess Process object - */ - public function updateProcessRow ($row) - { - $oProcess = new Process(); - if ($oProcess->processExists( $row['PRO_UID'] )) { - $oProcess->update( $row ); - } else { - $oProcess->create( $row ); - } - } - - /** - * Gets the subprocess data from a process and returns it in an array. - * - * @param $sProUid string for the process Uid - * @return $aSubProcess array - */ - public function getSubProcessRow ($sProUid) - { - try { - $aSubProcess = array (); - $oCriteria = new Criteria( 'workflow' ); - $oCriteria->add( SubProcessPeer::PRO_PARENT, $sProUid ); - $oDataset = SubProcessPeer::doSelectRS( $oCriteria ); - $oDataset->setFetchmode( ResultSet::FETCHMODE_ASSOC ); - $oDataset->next(); - while ($aRow = $oDataset->getRow()) { - $aSubProcess[] = $aRow; - $oDataset->next(); - } - return $aSubProcess; - } catch (Exception $oError) { - throw ($oError); - } - } - - /** - * Gets a case Tracker Row from a process and returns it in an array. - * - * @param $sProUid string for the process Uid - * @return $aCaseTracker array - */ - - public function getCaseTrackerRow ($sProUid) - { - try { - $aCaseTracker = array (); - $oCriteria = new Criteria( 'workflow' ); - $oCriteria->add( CaseTrackerPeer::PRO_UID, $sProUid ); - $oDataset = CaseTrackerPeer::doSelectRS( $oCriteria ); - $oDataset->setFetchmode( ResultSet::FETCHMODE_ASSOC ); - $oDataset->next(); - while ($aRow = $oDataset->getRow()) { - $aCaseTracker[] = $aRow; - $oDataset->next(); - } - return $aCaseTracker; - } catch (Exception $oError) { - throw ($oError); - } - } - - /** - * Gets a case TrackerObject Row from a process and returns it in an array. - * - * @param $sProUid string for the process Uid - * @return $aCaseTracker array - */ - public function getCaseTrackerObjectRow ($sProUid) - { - try { - $aCaseTrackerObject = array (); - $oCriteria = new Criteria( 'workflow' ); - $oCriteria->add( CaseTrackerObjectPeer::PRO_UID, $sProUid ); - $oDataset = CaseTrackerObjectPeer::doSelectRS( $oCriteria ); - $oDataset->setFetchmode( ResultSet::FETCHMODE_ASSOC ); - $oDataset->next(); - while ($aRow = $oDataset->getRow()) { - $aCaseTrackerObject[] = $aRow; - $oDataset->next(); - } - return $aCaseTrackerObject; - } catch (Exception $oError) { - throw ($oError); - } - } - - /** - * Gets a Stage Row from a process and returns it in an array. - * - * @param $sProUid string for the process Uid - * @return $aStage array - */ - public function getStageRow ($sProUid) - { - try { - $aStage = array (); - $oCriteria = new Criteria( 'workflow' ); - $oCriteria->add( StagePeer::PRO_UID, $sProUid ); - $oDataset = StagePeer::doSelectRS( $oCriteria ); - $oDataset->setFetchmode( ResultSet::FETCHMODE_ASSOC ); - $oDataset->next(); - while ($aRow = $oDataset->getRow()) { - $oStage = new Stage(); - $aStage[] = $oStage->load( $aRow['STG_UID'] ); - $oDataset->next(); - } - return $aStage; - } catch (Exception $oError) { - throw ($oError); - } - } - - /** - * Gets the Field Conditions from a process and returns those in an array. - * - * @param $sProUid string for the process Uid - * @return $aFieldCondition array - */ - - public function getFieldCondition ($sProUid) - { - try { - $aFieldCondition = array (); - $oCriteria = new Criteria( 'workflow' ); - $oCriteria->add( DynaformPeer::PRO_UID, $sProUid ); - $oCriteria->addJoin( DynaformPeer::DYN_UID, FieldConditionPeer::FCD_DYN_UID ); - $oDataset = FieldConditionPeer::doSelectRS( $oCriteria ); - $oDataset->setFetchmode( ResultSet::FETCHMODE_ASSOC ); - $oDataset->next(); - while ($aRow = $oDataset->getRow()) { - $aFieldCondition[] = $aRow; - $oDataset->next(); - } - return $aFieldCondition; - } catch (Exception $oError) { - throw ($oError); - } - } - - /** - * Gets the Event rows from a process and returns those in an array. - * - * @param $sProUid string for the process Uid - * @return $aEvent array - */ - public function getEventRow ($sProUid) - { - try { - $aEvent = array (); - $oCriteria = new Criteria( 'workflow' ); - - $oCriteria->add( EventPeer::PRO_UID, $sProUid ); - $oDataset = EventPeer::doSelectRS( $oCriteria ); - $oDataset->setFetchmode( ResultSet::FETCHMODE_ASSOC ); - $oDataset->next(); - while ($aRow = $oDataset->getRow()) { - $oEvent = new Event(); - $aEvent[] = $oEvent->load( $aRow['EVN_UID'] ); - $oDataset->next(); - } - return $aEvent; - } catch (Exception $oError) { - throw ($oError); - } - } - - /** - * Gets the Cases Scheduler rows from a process and returns those in an array. - * - * @param $sProUid string for the process Uid - * @return $aCaseScheduler array - */ - public function getCaseSchedulerRow ($sProUid) - { - try { - $aCaseScheduler = array (); - $oCriteria = new Criteria( 'workflow' ); - - $oCriteria->add( CaseSchedulerPeer::PRO_UID, $sProUid ); - $oDataset = CaseSchedulerPeer::doSelectRS( $oCriteria ); - $oDataset->setFetchmode( ResultSet::FETCHMODE_ASSOC ); - $oDataset->next(); - while ($aRow = $oDataset->getRow()) { - $oCaseScheduler = new CaseScheduler(); - $aCaseScheduler[] = $oCaseScheduler->load( $aRow['SCH_UID'] ); - $oDataset->next(); - } - return $aCaseScheduler; - } catch (Exception $oError) { - throw ($oError); - } - } - - /** - * Gets processCategory record, if the process had one - * - * @param $sProUid string for the process Uid - * @return $processCategory array - */ - public function getProcessCategoryRow ($sProUid) - { - $process = ProcessPeer::retrieveByPK( $sProUid ); - - if ($process->getProCategory() == '') { - return null; - } - - $oCriteria = new Criteria( 'workflow' ); - $oCriteria->add( ProcessCategoryPeer::CATEGORY_UID, $process->getProCategory() ); - $oDataset = ProcessCategoryPeer::doSelectRS( $oCriteria ); - $oDataset->setFetchmode( ResultSet::FETCHMODE_ASSOC ); - $oDataset->next(); - - return $oDataset->getRow(); - } - - /** - * Get all Swimlanes Elements for any Process - * - * @param string $sProUid - * @return array - */ - public function getAllLanes ($sProUid) - { - try { - $aLanes = array (); - $oCriteria = new Criteria( 'workflow' ); - $oCriteria->add( SwimlanesElementsPeer::PRO_UID, $sProUid ); - $oDataset = SwimlanesElementsPeer::doSelectRS( $oCriteria ); - $oDataset->setFetchmode( ResultSet::FETCHMODE_ASSOC ); - $oDataset->next(); - while ($aRow = $oDataset->getRow()) { - $oSwim = new SwimlanesElements(); - $aLanes[] = $oSwim->Load( $aRow['SWI_UID'] ); - $oDataset->next(); - } - return $aLanes; - } catch (Exception $oError) { - throw ($oError); - } - } - - /** - * Get Task Rows from a process and returns those in an array. - * - * @param $sProUid string for the process Uid - * @return $oTask array - */ - public function getTaskRows ($sProUid) - { - $oTask = new Tasks(); - return $oTask->getAllTasks( $sProUid ); - } - - /** - * Create Task Rows from a $aTasks array data and returns those in an array. - * - * @param $aTasks array - * @return $oTask array - */ - public function createTaskRows ($aTasks) - { - $oTask = new Tasks(); - return $oTask->createTaskRows( $aTasks ); - } - - /** - * Update Task Rows from a $aTasks array data and returns those in an array. - * - * @param $aTasks array - * @return $oTask array - */ - public function updateTaskRows ($aTasks) - { - $oTask = new Tasks(); - return $oTask->updateTaskRows( $aTasks ); - } - - /** - * Gets all Route rows from a Process and returns those in an array. - * - * @param $sProUid string for the process Uid - * @return $oTask Tasks array - */ - public function getRouteRows ($sProUid) - { - $oTask = new Tasks(); - return $oTask->getAllRoutes( $sProUid ); - } - - /** - * Create Route Rows from a $aRoutes array data and returns those in an array. - * - * @param $aRoutes array - * @return $oTask Tasks array - */ - public function createRouteRows ($aRoutes) - { - $oTask = new Tasks(); - return $oTask->createRouteRows( $aRoutes ); - } - - /** - * Update Route Rows from a $aRoutes array data and returns those in an array. - * - * @param $aRoutes array - * @return $oTask Tasks array - */ - public function updateRouteRows ($aRoutes) - { - $oTask = new Tasks(); - return $oTask->updateRouteRows( $aRoutes ); - } - - /** - * Get Lane Rows from a Process and returns those in an array. - * - * @param $sProUid string for the process Uid - * @return array - */ - public function getLaneRows ($sProUid) - { - return $this->getAllLanes( $sProUid ); - } - - /** - * Get Gateway Rows from a process and returns those in an array. - * - * @param $sProUid string for the process Uid - * @return $oTask array - */ - public function getGatewayRows ($sProUid) - { - $oTask = new Tasks(); - return $oTask->getAllGateways( $sProUid ); - } - - /** - * Create Gateway Rows from a $aGateways array data and returns those in an array. - * - * @param $aGateways array - * @return $oGateway array - */ - public function createGatewayRows ($aGateways) - { - $oTask = new Tasks(); - return $oTask->createGatewayRows( $aGateways ); - } - - /** - * Create Lane Rows from a $aLanes array data and returns those in an array. - * - * @param $aLanes array. - * @return void - */ - public function createLaneRows ($aLanes) - { - foreach ($aLanes as $key => $row) { - $oLane = new SwimlanesElements(); - if ($oLane->swimlanesElementsExists( $row['SWI_UID'] )) { - $oLane->remove( $row['SWI_UID'] ); - } - $res = $oLane->create( $row ); - } - return; - } - - /** - * Create Sub Process rows from an array, removing those subprocesses with - * the same UID. - * - * @param $SubProcess array - * @return void. - */ - public function createSubProcessRows ($SubProcess) - { - foreach ($SubProcess as $key => $row) { - $oSubProcess = new SubProcess(); - if ($oSubProcess->subProcessExists( $row['SP_UID'] )) { - $oSubProcess->remove( $row['SP_UID'] ); - } - $res = $oSubProcess->create( $row ); - } - return; - } - - /** - * Create Case Tracker rows from an array, removing those Trackers with - * the same UID. - * - * @param $CaseTracker array. - * @return void - */ - public function createCaseTrackerRows ($CaseTracker) - { - if (is_array( $CaseTracker )) { - foreach ($CaseTracker as $key => $row) { - $oCaseTracker = new CaseTracker(); - if ($oCaseTracker->caseTrackerExists( $row['PRO_UID'] )) { - $oCaseTracker->remove( $row['PRO_UID'] ); - } - $res = $oCaseTracker->create( $row ); - } - } - return; - } - - /** - * Create Case Tracker Objects rows from an array, removing those Objects - * with the same UID, and recreaiting those from the array data. - * - * @param $CaseTrackerObject array. - * @return void - */ - public function createCaseTrackerObjectRows ($CaseTrackerObject) - { - foreach ($CaseTrackerObject as $key => $row) { - $oCaseTrackerObject = new CaseTrackerObject(); - if ($oCaseTrackerObject->caseTrackerObjectExists( $row['CTO_UID'] )) { - $oCaseTrackerObject->remove( $row['CTO_UID'] ); - } - $res = $oCaseTrackerObject->create( $row ); - } - return; - } - - /** - * Create Object Permissions rows from an array, removing those Objects - * with the same UID, and recreaiting the records from the array data. - * - * @param $sProUid string for the process Uid. - * @return void - */ - public function createObjectPermissionsRows ($ObjectPermissions) - { - foreach ($ObjectPermissions as $key => $row) { - $oObjectPermissions = new ObjectPermission(); - if ($oObjectPermissions->Exists( $row['OP_UID'] )) { - $oObjectPermissions->remove( $row['OP_UID'] ); - } - $res = $oObjectPermissions->create( $row ); - } - return; - } - - /** - * Create Stage rows from an array, removing those Objects - * with the same UID, and recreaiting the records from the array data. - * - * @param $Stage array. - * @return void - */ - public function createStageRows ($Stage) - { - foreach ($Stage as $key => $row) { - $oStage = new Stage(); - if ($oStage->Exists( $row['STG_UID'] )) { - $oStage->remove( $row['STG_UID'] ); - } - $res = $oStage->create( $row ); - } - return; - } - - /** - * Create Field Conditions from an array of Field Conditions and Dynaforms, - * removing those Objects with the same UID, and recreaiting the records - * from the arrays data. - * - * @param $aFieldCondition array. - * @param $aDynaform array. - * @return void - */ - public function createFieldCondition ($aFieldCondition, $aDynaform) - { - if (is_array( $aFieldCondition )) { - foreach ($aFieldCondition as $key => $row) { - $oFieldCondition = new FieldCondition(); - if ($oFieldCondition->fieldConditionExists( $row['FCD_UID'], $aDynaform )) { - $oFieldCondition->remove( $row['FCD_UID'] ); - } - $res = $oFieldCondition->create( $row ); - } - } - return; - } - - /** - * Create Event rows from an array, removing those Objects - * with the same UID, and recreaiting the records from the array data. - * - * @param $Event array. - * @return void - */ - public function createEventRows ($Event) - { - foreach ($Event as $key => $row) { - $oEvent = new Event(); - if ($oEvent->Exists( $row['EVN_UID'] )) { - $oEvent->remove( $row['EVN_UID'] ); - } - $res = $oEvent->create( $row ); - } - return; - } - - /** - * Create Case Scheduler Rows from an array, removing those Objects - * with the same UID, and recreaiting the records from the array data. - * - * @param $CaseScheduler array. - * @return void - */ - public function createCaseSchedulerRows ($CaseScheduler) - { - foreach ($CaseScheduler as $key => $row) { - $oCaseScheduler = new CaseScheduler(); - if ($oCaseScheduler->Exists( $row['SCH_UID'] )) { - $oCaseScheduler->remove( $row['SCH_UID'] ); - } - $res = $oCaseScheduler->create( $row ); - } - return; - } - - /** - * Create ProcessCategory record - * - * @param $ProcessCategory array. - * @return void - */ - public function createProcessCategoryRow ($row) - { - if ($row && is_array( $row ) && isset( $row['CATEGORY_UID'] )) { - $record = ProcessCategoryPeer::retrieveByPK( $row['CATEGORY_UID'] ); + if (isset( $oData->event ) && is_array( $oData->event )) { + foreach ($oData->event as $key => $val) { + if (isset( $val['EVN_TAS_UID_FROM'] ) && isset( $map[$val['EVN_TAS_UID_FROM']] )) { + $newGuid = $map[$val['EVN_TAS_UID_FROM']]; + $oData->event[$key]['EVN_TAS_UID_FROM'] = $newGuid; + } + } + } + + if (isset( $oData->caseScheduler ) && is_array( $oData->caseScheduler )) { + foreach ($oData->caseScheduler as $key => $val) { + if (isset( $map[$val['TAS_UID']] )) { + $newGuid = $map[$val['TAS_UID']]; + $oData->caseScheduler[$key]['TAS_UID'] = $newGuid; + } + } + } + + } + + /** + * change and Renew all Dynaform GUID, because the process needs to have a new set of dynaforms + * + * @param string $oData + * @return boolean + */ + public function renewAllDynaformGuid (&$oData) + { + $map = array (); + foreach ($oData->dynaforms as $key => $val) { + $newGuid = $this->getUnusedDynaformGUID(); + $map[$val['DYN_UID']] = $newGuid; + $oData->dynaforms[$key]['DYN_UID'] = $newGuid; + } + + if (isset( $oData->process['PRO_DYNAFORMS'] ) && ! is_array( $oData->process['PRO_DYNAFORMS'] )) { + $oData->process['PRO_DYNAFORMS'] = @unserialize( $oData->process['PRO_DYNAFORMS'] ); + } + + if (! isset( $oData->process['PRO_DYNAFORMS']['PROCESS'] )) { + $oData->process['PRO_DYNAFORMS']['PROCESS'] = ''; + } + + if ($oData->process['PRO_DYNAFORMS']['PROCESS'] != '') { + $oData->process['PRO_DYNAFORMS']['PROCESS'] = $map[$oData->process['PRO_DYNAFORMS']['PROCESS']]; + } + + foreach ($oData->steps as $key => $val) { + if ($val['STEP_TYPE_OBJ'] == 'DYNAFORM') { + $newGuid = $map[$val['STEP_UID_OBJ']]; + $oData->steps[$key]['STEP_UID_OBJ'] = $newGuid; + } + } + + if (isset( $oData->caseTrackerObject ) && is_array( $oData->caseTrackerObject )) { + foreach ($oData->caseTrackerObject as $key => $val) { + if ($val['CTO_TYPE_OBJ'] == 'DYNAFORM') { + $newGuid = $map[$val['CTO_UID_OBJ']]; + $oData->steps[$key]['CTO_UID_OBJ'] = $newGuid; + } + } + } + if (isset( $oData->objectPermissions ) && is_array( $oData->objectPermissions )) { + foreach ($oData->objectPermissions as $key => $val) { + if ($val['OP_OBJ_TYPE'] == 'DYNAFORM') { + if (isset( $map[$val['OP_OBJ_UID']] )) { + $newGuid = $map[$val['OP_OBJ_UID']]; + $oData->objectPermissions[$key]['OP_OBJ_UID'] = $newGuid; + } + } + } + } + if (isset( $oData->stepSupervisor ) && is_array( $oData->stepSupervisor )) { + foreach ($oData->stepSupervisor as $key => $val) { + if ($val['STEP_TYPE_OBJ'] == 'DYNAFORM') { + $newGuid = $map[$val['STEP_UID_OBJ']]; + $oData->stepSupervisor[$key]['STEP_UID_OBJ'] = $newGuid; + } + } + foreach ($oData->dynaformFiles as $key => $val) { + $newGuid = $map[$key]; + $oData->dynaformFiles[$key] = $newGuid; + } + } + if (isset( $oData->gridFiles )) { + foreach ($oData->gridFiles as $key => $val) { + $newGuid = $map[$key]; + $oData->gridFiles[$key] = $newGuid; + } + } + if (isset( $oData->fieldCondition ) && is_array( $oData->fieldCondition )) { + foreach ($oData->fieldCondition as $key => $val) { + $newGuid = $map[$val['FCD_DYN_UID']]; + $oData->fieldCondition[$key]['FCD_DYN_UID'] = $newGuid; + } + } + + } + + /** + * get a Process with a search based in the process Uid + * + * @param $sProUid string process Uid + * @return $oProcess Process object + */ + public function getProcessRow ($sProUid, $getAllLang = false) + { + $oProcess = new Process(); + return $oProcess->Load( $sProUid, $getAllLang ); + } + + /** + * creates a process new process if a process exists with the same uid of the + * $row['PRO_UID'] parameter then deletes it from the database and creates + * a new one based on the $row parameter + * + * @param $row array parameter with the process data + * @return $oProcess Process object + */ + public function createProcessRow ($row) + { + $oProcess = new Process(); + if ($oProcess->processExists( $row['PRO_UID'] )) { + $oProcess->remove( $row['PRO_UID'] ); + } + return $oProcess->createRow( $row ); + } + + /** + * Update a Process register in DB, if the process doesn't exist with the same + * uid of the $row['PRO_UID'] parameter the function creates a new one based + * on the $row parameter data. + * + * @param $row array parameter with the process data + * @return $oProcess Process object + */ + public function updateProcessRow ($row) + { + $oProcess = new Process(); + if ($oProcess->processExists( $row['PRO_UID'] )) { + $oProcess->update( $row ); + } else { + $oProcess->create( $row ); + } + } + + /** + * Gets the subprocess data from a process and returns it in an array. + * + * @param $sProUid string for the process Uid + * @return $aSubProcess array + */ + public function getSubProcessRow ($sProUid) + { + try { + $aSubProcess = array (); + $oCriteria = new Criteria( 'workflow' ); + $oCriteria->add( SubProcessPeer::PRO_PARENT, $sProUid ); + $oDataset = SubProcessPeer::doSelectRS( $oCriteria ); + $oDataset->setFetchmode( ResultSet::FETCHMODE_ASSOC ); + $oDataset->next(); + while ($aRow = $oDataset->getRow()) { + $aSubProcess[] = $aRow; + $oDataset->next(); + } + return $aSubProcess; + } catch (Exception $oError) { + throw ($oError); + } + } + + /** + * Gets a case Tracker Row from a process and returns it in an array. + * + * @param $sProUid string for the process Uid + * @return $aCaseTracker array + */ + + public function getCaseTrackerRow ($sProUid) + { + try { + $aCaseTracker = array (); + $oCriteria = new Criteria( 'workflow' ); + $oCriteria->add( CaseTrackerPeer::PRO_UID, $sProUid ); + $oDataset = CaseTrackerPeer::doSelectRS( $oCriteria ); + $oDataset->setFetchmode( ResultSet::FETCHMODE_ASSOC ); + $oDataset->next(); + while ($aRow = $oDataset->getRow()) { + $aCaseTracker[] = $aRow; + $oDataset->next(); + } + return $aCaseTracker; + } catch (Exception $oError) { + throw ($oError); + } + } + + /** + * Gets a case TrackerObject Row from a process and returns it in an array. + * + * @param $sProUid string for the process Uid + * @return $aCaseTracker array + */ + public function getCaseTrackerObjectRow ($sProUid) + { + try { + $aCaseTrackerObject = array (); + $oCriteria = new Criteria( 'workflow' ); + $oCriteria->add( CaseTrackerObjectPeer::PRO_UID, $sProUid ); + $oDataset = CaseTrackerObjectPeer::doSelectRS( $oCriteria ); + $oDataset->setFetchmode( ResultSet::FETCHMODE_ASSOC ); + $oDataset->next(); + while ($aRow = $oDataset->getRow()) { + $aCaseTrackerObject[] = $aRow; + $oDataset->next(); + } + return $aCaseTrackerObject; + } catch (Exception $oError) { + throw ($oError); + } + } + + /** + * Gets a Stage Row from a process and returns it in an array. + * + * @param $sProUid string for the process Uid + * @return $aStage array + */ + public function getStageRow ($sProUid) + { + try { + $aStage = array (); + $oCriteria = new Criteria( 'workflow' ); + $oCriteria->add( StagePeer::PRO_UID, $sProUid ); + $oDataset = StagePeer::doSelectRS( $oCriteria ); + $oDataset->setFetchmode( ResultSet::FETCHMODE_ASSOC ); + $oDataset->next(); + while ($aRow = $oDataset->getRow()) { + $oStage = new Stage(); + $aStage[] = $oStage->load( $aRow['STG_UID'] ); + $oDataset->next(); + } + return $aStage; + } catch (Exception $oError) { + throw ($oError); + } + } + + /** + * Gets the Field Conditions from a process and returns those in an array. + * + * @param $sProUid string for the process Uid + * @return $aFieldCondition array + */ + + public function getFieldCondition ($sProUid) + { + try { + $aFieldCondition = array (); + $oCriteria = new Criteria( 'workflow' ); + $oCriteria->add( DynaformPeer::PRO_UID, $sProUid ); + $oCriteria->addJoin( DynaformPeer::DYN_UID, FieldConditionPeer::FCD_DYN_UID ); + $oDataset = FieldConditionPeer::doSelectRS( $oCriteria ); + $oDataset->setFetchmode( ResultSet::FETCHMODE_ASSOC ); + $oDataset->next(); + while ($aRow = $oDataset->getRow()) { + $aFieldCondition[] = $aRow; + $oDataset->next(); + } + return $aFieldCondition; + } catch (Exception $oError) { + throw ($oError); + } + } + + /** + * Gets the Event rows from a process and returns those in an array. + * + * @param $sProUid string for the process Uid + * @return $aEvent array + */ + public function getEventRow ($sProUid) + { + try { + $aEvent = array (); + $oCriteria = new Criteria( 'workflow' ); + + $oCriteria->add( EventPeer::PRO_UID, $sProUid ); + $oDataset = EventPeer::doSelectRS( $oCriteria ); + $oDataset->setFetchmode( ResultSet::FETCHMODE_ASSOC ); + $oDataset->next(); + while ($aRow = $oDataset->getRow()) { + $oEvent = new Event(); + $aEvent[] = $oEvent->load( $aRow['EVN_UID'] ); + $oDataset->next(); + } + return $aEvent; + } catch (Exception $oError) { + throw ($oError); + } + } + + /** + * Gets the Cases Scheduler rows from a process and returns those in an array. + * + * @param $sProUid string for the process Uid + * @return $aCaseScheduler array + */ + public function getCaseSchedulerRow ($sProUid) + { + try { + $aCaseScheduler = array (); + $oCriteria = new Criteria( 'workflow' ); + + $oCriteria->add( CaseSchedulerPeer::PRO_UID, $sProUid ); + $oDataset = CaseSchedulerPeer::doSelectRS( $oCriteria ); + $oDataset->setFetchmode( ResultSet::FETCHMODE_ASSOC ); + $oDataset->next(); + while ($aRow = $oDataset->getRow()) { + $oCaseScheduler = new CaseScheduler(); + $aCaseScheduler[] = $oCaseScheduler->load( $aRow['SCH_UID'] ); + $oDataset->next(); + } + return $aCaseScheduler; + } catch (Exception $oError) { + throw ($oError); + } + } + + /** + * Gets processCategory record, if the process had one + * + * @param $sProUid string for the process Uid + * @return $processCategory array + */ + public function getProcessCategoryRow ($sProUid) + { + $process = ProcessPeer::retrieveByPK( $sProUid ); + + if ($process->getProCategory() == '') { + return null; + } + + $oCriteria = new Criteria( 'workflow' ); + $oCriteria->add( ProcessCategoryPeer::CATEGORY_UID, $process->getProCategory() ); + $oDataset = ProcessCategoryPeer::doSelectRS( $oCriteria ); + $oDataset->setFetchmode( ResultSet::FETCHMODE_ASSOC ); + $oDataset->next(); + + return $oDataset->getRow(); + } + + /** + * Get all Swimlanes Elements for any Process + * + * @param string $sProUid + * @return array + */ + public function getAllLanes ($sProUid) + { + try { + $aLanes = array (); + $oCriteria = new Criteria( 'workflow' ); + $oCriteria->add( SwimlanesElementsPeer::PRO_UID, $sProUid ); + $oDataset = SwimlanesElementsPeer::doSelectRS( $oCriteria ); + $oDataset->setFetchmode( ResultSet::FETCHMODE_ASSOC ); + $oDataset->next(); + while ($aRow = $oDataset->getRow()) { + $oSwim = new SwimlanesElements(); + $aLanes[] = $oSwim->Load( $aRow['SWI_UID'] ); + $oDataset->next(); + } + return $aLanes; + } catch (Exception $oError) { + throw ($oError); + } + } + + /** + * Get Task Rows from a process and returns those in an array. + * + * @param $sProUid string for the process Uid + * @return $oTask array + */ + public function getTaskRows ($sProUid) + { + $oTask = new Tasks(); + return $oTask->getAllTasks( $sProUid ); + } + + /** + * Create Task Rows from a $aTasks array data and returns those in an array. + * + * @param $aTasks array + * @return $oTask array + */ + public function createTaskRows ($aTasks) + { + $oTask = new Tasks(); + return $oTask->createTaskRows( $aTasks ); + } + + /** + * Update Task Rows from a $aTasks array data and returns those in an array. + * + * @param $aTasks array + * @return $oTask array + */ + public function updateTaskRows ($aTasks) + { + $oTask = new Tasks(); + return $oTask->updateTaskRows( $aTasks ); + } + + /** + * Gets all Route rows from a Process and returns those in an array. + * + * @param $sProUid string for the process Uid + * @return $oTask Tasks array + */ + public function getRouteRows ($sProUid) + { + $oTask = new Tasks(); + return $oTask->getAllRoutes( $sProUid ); + } + + /** + * Create Route Rows from a $aRoutes array data and returns those in an array. + * + * @param $aRoutes array + * @return $oTask Tasks array + */ + public function createRouteRows ($aRoutes) + { + $oTask = new Tasks(); + return $oTask->createRouteRows( $aRoutes ); + } + + /** + * Update Route Rows from a $aRoutes array data and returns those in an array. + * + * @param $aRoutes array + * @return $oTask Tasks array + */ + public function updateRouteRows ($aRoutes) + { + $oTask = new Tasks(); + return $oTask->updateRouteRows( $aRoutes ); + } + + /** + * Get Lane Rows from a Process and returns those in an array. + * + * @param $sProUid string for the process Uid + * @return array + */ + public function getLaneRows ($sProUid) + { + return $this->getAllLanes( $sProUid ); + } + + /** + * Get Gateway Rows from a process and returns those in an array. + * + * @param $sProUid string for the process Uid + * @return $oTask array + */ + public function getGatewayRows ($sProUid) + { + $oTask = new Tasks(); + return $oTask->getAllGateways( $sProUid ); + } + + /** + * Create Gateway Rows from a $aGateways array data and returns those in an array. + * + * @param $aGateways array + * @return $oGateway array + */ + public function createGatewayRows ($aGateways) + { + $oTask = new Tasks(); + return $oTask->createGatewayRows( $aGateways ); + } + + /** + * Create Lane Rows from a $aLanes array data and returns those in an array. + * + * @param $aLanes array. + * @return void + */ + public function createLaneRows ($aLanes) + { + foreach ($aLanes as $key => $row) { + $oLane = new SwimlanesElements(); + if ($oLane->swimlanesElementsExists( $row['SWI_UID'] )) { + $oLane->remove( $row['SWI_UID'] ); + } + $res = $oLane->create( $row ); + } + return; + } + + /** + * Create Sub Process rows from an array, removing those subprocesses with + * the same UID. + * + * @param $SubProcess array + * @return void. + */ + public function createSubProcessRows ($SubProcess) + { + foreach ($SubProcess as $key => $row) { + $oSubProcess = new SubProcess(); + if ($oSubProcess->subProcessExists( $row['SP_UID'] )) { + $oSubProcess->remove( $row['SP_UID'] ); + } + $res = $oSubProcess->create( $row ); + } + return; + } + + /** + * Create Case Tracker rows from an array, removing those Trackers with + * the same UID. + * + * @param $CaseTracker array. + * @return void + */ + public function createCaseTrackerRows ($CaseTracker) + { + if (is_array( $CaseTracker )) { + foreach ($CaseTracker as $key => $row) { + $oCaseTracker = new CaseTracker(); + if ($oCaseTracker->caseTrackerExists( $row['PRO_UID'] )) { + $oCaseTracker->remove( $row['PRO_UID'] ); + } + $res = $oCaseTracker->create( $row ); + } + } + return; + } + + /** + * Create Case Tracker Objects rows from an array, removing those Objects + * with the same UID, and recreaiting those from the array data. + * + * @param $CaseTrackerObject array. + * @return void + */ + public function createCaseTrackerObjectRows ($CaseTrackerObject) + { + foreach ($CaseTrackerObject as $key => $row) { + $oCaseTrackerObject = new CaseTrackerObject(); + if ($oCaseTrackerObject->caseTrackerObjectExists( $row['CTO_UID'] )) { + $oCaseTrackerObject->remove( $row['CTO_UID'] ); + } + $res = $oCaseTrackerObject->create( $row ); + } + return; + } + + /** + * Create Object Permissions rows from an array, removing those Objects + * with the same UID, and recreaiting the records from the array data. + * + * @param $sProUid string for the process Uid. + * @return void + */ + public function createObjectPermissionsRows ($ObjectPermissions) + { + foreach ($ObjectPermissions as $key => $row) { + $oObjectPermissions = new ObjectPermission(); + if ($oObjectPermissions->Exists( $row['OP_UID'] )) { + $oObjectPermissions->remove( $row['OP_UID'] ); + } + $res = $oObjectPermissions->create( $row ); + } + return; + } + + /** + * Create Stage rows from an array, removing those Objects + * with the same UID, and recreaiting the records from the array data. + * + * @param $Stage array. + * @return void + */ + public function createStageRows ($Stage) + { + foreach ($Stage as $key => $row) { + $oStage = new Stage(); + if ($oStage->Exists( $row['STG_UID'] )) { + $oStage->remove( $row['STG_UID'] ); + } + $res = $oStage->create( $row ); + } + return; + } + + /** + * Create Field Conditions from an array of Field Conditions and Dynaforms, + * removing those Objects with the same UID, and recreaiting the records + * from the arrays data. + * + * @param $aFieldCondition array. + * @param $aDynaform array. + * @return void + */ + public function createFieldCondition ($aFieldCondition, $aDynaform) + { + if (is_array( $aFieldCondition )) { + foreach ($aFieldCondition as $key => $row) { + $oFieldCondition = new FieldCondition(); + if ($oFieldCondition->fieldConditionExists( $row['FCD_UID'], $aDynaform )) { + $oFieldCondition->remove( $row['FCD_UID'] ); + } + $res = $oFieldCondition->create( $row ); + } + } + return; + } + + /** + * Create Event rows from an array, removing those Objects + * with the same UID, and recreaiting the records from the array data. + * + * @param $Event array. + * @return void + */ + public function createEventRows ($Event) + { + foreach ($Event as $key => $row) { + $oEvent = new Event(); + if ($oEvent->Exists( $row['EVN_UID'] )) { + $oEvent->remove( $row['EVN_UID'] ); + } + $res = $oEvent->create( $row ); + } + return; + } + + /** + * Create Case Scheduler Rows from an array, removing those Objects + * with the same UID, and recreaiting the records from the array data. + * + * @param $CaseScheduler array. + * @return void + */ + public function createCaseSchedulerRows ($CaseScheduler) + { + foreach ($CaseScheduler as $key => $row) { + $oCaseScheduler = new CaseScheduler(); + if ($oCaseScheduler->Exists( $row['SCH_UID'] )) { + $oCaseScheduler->remove( $row['SCH_UID'] ); + } + $res = $oCaseScheduler->create( $row ); + } + return; + } + + /** + * Create ProcessCategory record + * + * @param $ProcessCategory array. + * @return void + */ + public function createProcessCategoryRow ($row) + { + if ($row && is_array( $row ) && isset( $row['CATEGORY_UID'] )) { + $record = ProcessCategoryPeer::retrieveByPK( $row['CATEGORY_UID'] ); // create only if the category doesn't exists - if (! $record) { - $processCategory = new ProcessCategory(); - $processCategory->fromArray( $row, BasePeer::TYPE_FIELDNAME ); - $processCategory->save(); - } - } - } - - /** - * Gets Input Documents Rows from aProcess. - * - * @param $sProUid string. - * @return void - */ - public function getInputRows ($sProUid) - { - try { - $aInput = array (); - $oCriteria = new Criteria( 'workflow' ); - $oCriteria->add( InputdocumentPeer::PRO_UID, $sProUid ); - $oDataset = InputdocumentPeer::doSelectRS( $oCriteria ); - $oDataset->setFetchmode( ResultSet::FETCHMODE_ASSOC ); - $oDataset->next(); - while ($aRow = $oDataset->getRow()) { - $oInput = new Inputdocument(); - $aInput[] = $oInput->Load( $aRow['INP_DOC_UID'] ); - $oDataset->next(); - } - return $aInput; - } catch (Exception $oError) { - throw ($oError); - } - } - - /** - * Create Input Documents Rows from an array, removing those Objects - * with the same UID, and recreaiting the records from the array data. - * - * @param $aInput array. - * @return void - */ - public function createInputRows ($aInput) - { - foreach ($aInput as $key => $row) { - $oInput = new Inputdocument(); + if (! $record) { + $processCategory = new ProcessCategory(); + $processCategory->fromArray( $row, BasePeer::TYPE_FIELDNAME ); + $processCategory->save(); + } + } + } + + /** + * Gets Input Documents Rows from aProcess. + * + * @param $sProUid string. + * @return void + */ + public function getInputRows ($sProUid) + { + try { + $aInput = array (); + $oCriteria = new Criteria( 'workflow' ); + $oCriteria->add( InputdocumentPeer::PRO_UID, $sProUid ); + $oDataset = InputdocumentPeer::doSelectRS( $oCriteria ); + $oDataset->setFetchmode( ResultSet::FETCHMODE_ASSOC ); + $oDataset->next(); + while ($aRow = $oDataset->getRow()) { + $oInput = new Inputdocument(); + $aInput[] = $oInput->Load( $aRow['INP_DOC_UID'] ); + $oDataset->next(); + } + return $aInput; + } catch (Exception $oError) { + throw ($oError); + } + } + + /** + * Create Input Documents Rows from an array, removing those Objects + * with the same UID, and recreaiting the records from the array data. + * + * @param $aInput array. + * @return void + */ + public function createInputRows ($aInput) + { + foreach ($aInput as $key => $row) { + $oInput = new Inputdocument(); //unset ($row['TAS_UID']); - if ($oInput->InputExists( $row['INP_DOC_UID'] )) { - $oInput->remove( $row['INP_DOC_UID'] ); - } - $res = $oInput->create( $row ); - } - return; - } - - /** - * change and Renew all Input GUID, because the process needs to have a new set of Inputs - * - * @param string $oData - * @return boolean - */ - public function renewAllInputGuid (&$oData) - { - $map = array (); - foreach ($oData->inputs as $key => $val) { - $newGuid = $this->getUnusedInputGUID(); - $map[$val['INP_DOC_UID']] = $newGuid; - $oData->inputs[$key]['INP_DOC_UID'] = $newGuid; - } - foreach ($oData->steps as $key => $val) { - if (isset( $val['STEP_TYPE_OBJ'] )) { - if ($val['STEP_TYPE_OBJ'] == 'INPUT_DOCUMENT') { - $newGuid = $map[$val['STEP_UID_OBJ']]; - $oData->steps[$key]['STEP_UID_OBJ'] = $newGuid; - } - } - } - if (isset( $oData->caseTrackerObject ) && is_array( $oData->caseTrackerObject )) { - foreach ($oData->caseTrackerObject as $key => $val) { - if ($val['CTO_TYPE_OBJ'] == 'INPUT_DOCUMENT') { - $newGuid = $map[$val['CTO_UID_OBJ']]; - $oData->steps[$key]['CTO_UID_OBJ'] = $newGuid; - } - } - } - if (isset( $oData->objectPermissions ) && is_array( $oData->objectPermissions )) { - foreach ($oData->objectPermissions as $key => $val) { - if ($val['OP_OBJ_TYPE'] == 'INPUT_DOCUMENT') { - if (isset( $map[$val['OP_OBJ_UID']] )) { - $newGuid = $map[$val['OP_OBJ_UID']]; - $oData->objectPermissions[$key]['OP_OBJ_UID'] = $newGuid; - } - } - } - } - if (isset( $oData->stepSupervisor ) && is_array( $oData->stepSupervisor )) { - foreach ($oData->stepSupervisor as $key => $val) { - if ($val['STEP_TYPE_OBJ'] == 'INPUT_DOCUMENT') { - $newGuid = $map[$val['STEP_UID_OBJ']]; - $oData->stepSupervisor[$key]['STEP_UID_OBJ'] = $newGuid; - } - } - } - } - - /** - * Gets the Output Documents Rows from a Process. - * - * @param $sProUid string. - * @return $aOutput array - */ - public function getOutputRows ($sProUid) - { - try { - $aOutput = array (); - $oCriteria = new Criteria( 'workflow' ); - $oCriteria->add( OutputdocumentPeer::PRO_UID, $sProUid ); - $oDataset = OutputdocumentPeer::doSelectRS( $oCriteria ); - $oDataset->setFetchmode( ResultSet::FETCHMODE_ASSOC ); - $oDataset->next(); - while ($aRow = $oDataset->getRow()) { - $oOutput = new Outputdocument(); - $aOutput[] = $oOutput->Load( $aRow['OUT_DOC_UID'] ); - $oDataset->next(); - } - return $aOutput; - } catch (Exception $oError) { - throw ($oError); - } - } - - /** - * Create Input Documents Rows from an array, removing those Objects - * with the same UID, and recreaiting the records from the array data. - * - * @param $aOutput array. - * @return void - */ - public function createOutputRows ($aOutput) - { - foreach ($aOutput as $key => $row) { - $oOutput = new Outputdocument(); + if ($oInput->InputExists( $row['INP_DOC_UID'] )) { + $oInput->remove( $row['INP_DOC_UID'] ); + } + $res = $oInput->create( $row ); + } + return; + } + + /** + * change and Renew all Input GUID, because the process needs to have a new set of Inputs + * + * @param string $oData + * @return boolean + */ + public function renewAllInputGuid (&$oData) + { + $map = array (); + foreach ($oData->inputs as $key => $val) { + $newGuid = $this->getUnusedInputGUID(); + $map[$val['INP_DOC_UID']] = $newGuid; + $oData->inputs[$key]['INP_DOC_UID'] = $newGuid; + } + foreach ($oData->steps as $key => $val) { + if (isset( $val['STEP_TYPE_OBJ'] )) { + if ($val['STEP_TYPE_OBJ'] == 'INPUT_DOCUMENT') { + $newGuid = $map[$val['STEP_UID_OBJ']]; + $oData->steps[$key]['STEP_UID_OBJ'] = $newGuid; + } + } + } + if (isset( $oData->caseTrackerObject ) && is_array( $oData->caseTrackerObject )) { + foreach ($oData->caseTrackerObject as $key => $val) { + if ($val['CTO_TYPE_OBJ'] == 'INPUT_DOCUMENT') { + $newGuid = $map[$val['CTO_UID_OBJ']]; + $oData->steps[$key]['CTO_UID_OBJ'] = $newGuid; + } + } + } + if (isset( $oData->objectPermissions ) && is_array( $oData->objectPermissions )) { + foreach ($oData->objectPermissions as $key => $val) { + if ($val['OP_OBJ_TYPE'] == 'INPUT_DOCUMENT') { + if (isset( $map[$val['OP_OBJ_UID']] )) { + $newGuid = $map[$val['OP_OBJ_UID']]; + $oData->objectPermissions[$key]['OP_OBJ_UID'] = $newGuid; + } + } + } + } + if (isset( $oData->stepSupervisor ) && is_array( $oData->stepSupervisor )) { + foreach ($oData->stepSupervisor as $key => $val) { + if ($val['STEP_TYPE_OBJ'] == 'INPUT_DOCUMENT') { + $newGuid = $map[$val['STEP_UID_OBJ']]; + $oData->stepSupervisor[$key]['STEP_UID_OBJ'] = $newGuid; + } + } + } + } + + /** + * Gets the Output Documents Rows from a Process. + * + * @param $sProUid string. + * @return $aOutput array + */ + public function getOutputRows ($sProUid) + { + try { + $aOutput = array (); + $oCriteria = new Criteria( 'workflow' ); + $oCriteria->add( OutputdocumentPeer::PRO_UID, $sProUid ); + $oDataset = OutputdocumentPeer::doSelectRS( $oCriteria ); + $oDataset->setFetchmode( ResultSet::FETCHMODE_ASSOC ); + $oDataset->next(); + while ($aRow = $oDataset->getRow()) { + $oOutput = new Outputdocument(); + $aOutput[] = $oOutput->Load( $aRow['OUT_DOC_UID'] ); + $oDataset->next(); + } + return $aOutput; + } catch (Exception $oError) { + throw ($oError); + } + } + + /** + * Create Input Documents Rows from an array, removing those Objects + * with the same UID, and recreaiting the records from the array data. + * + * @param $aOutput array. + * @return void + */ + public function createOutputRows ($aOutput) + { + foreach ($aOutput as $key => $row) { + $oOutput = new Outputdocument(); //unset ($row['TAS_UID']); - if ($oOutput->OutputExists( $row['OUT_DOC_UID'] )) { - $oOutput->remove( $row['OUT_DOC_UID'] ); - } - $res = $oOutput->create( $row ); - } - return; - } - - /** - * change and Renew all Output GUID, because the process needs to have a new set of Outputs - * - * @param string $oData - * @return boolean - */ - public function renewAllOutputGuid (&$oData) - { - $map = array (); - foreach ($oData->outputs as $key => $val) { - $newGuid = $this->getUnusedOutputGUID(); - $map[$val['OUT_DOC_UID']] = $newGuid; - $oData->outputs[$key]['OUT_DOC_UID'] = $newGuid; - } - foreach ($oData->steps as $key => $val) { - if (isset( $val['STEP_TYPE_OBJ'] )) { - if ($val['STEP_TYPE_OBJ'] == 'OUTPUT_DOCUMENT') { - $newGuid = $map[$val['STEP_UID_OBJ']]; - $oData->steps[$key]['STEP_UID_OBJ'] = $newGuid; - } - } - } - foreach ($oData->caseTrackerObject as $key => $val) { - if ($val['CTO_TYPE_OBJ'] == 'OUTPUT_DOCUMENT') { - $newGuid = $map[$val['CTO_UID_OBJ']]; - $oData->steps[$key]['CTO_UID_OBJ'] = $newGuid; - } - } - foreach ($oData->objectPermissions as $key => $val) { - if ($val['OP_OBJ_TYPE'] == 'OUTPUT_DOCUMENT') { - $newGuid = $map[$val['OP_OBJ_UID']]; - $oData->objectPermissions[$key]['OP_OBJ_UID'] = $newGuid; - } - } - foreach ($oData->stepSupervisor as $key => $val) { - if ($val['STEP_TYPE_OBJ'] == 'OUTPUT_DOCUMENT') { - $newGuid = $map[$val['STEP_UID_OBJ']]; - $oData->stepSupervisor[$key]['STEP_UID_OBJ'] = $newGuid; - } - } - } - - /** - * change and Renew all Trigger GUID, because the process needs to have a new set of Triggers - * - * @param string $oData - * @return boolean - */ - public function renewAllTriggerGuid (&$oData) - { - $map = array (); - foreach ($oData->triggers as $key => $val) { - $newGuid = $this->getUnusedTriggerGUID(); - $map[$val['TRI_UID']] = $newGuid; - $oData->triggers[$key]['TRI_UID'] = $newGuid; - } - foreach ($oData->steptriggers as $key => $val) { - if (isset( $map[$val['TRI_UID']] )) { - $newGuid = $map[$val['TRI_UID']]; - $oData->steptriggers[$key]['TRI_UID'] = $newGuid; - } else { - $oData->steptriggers[$key]['TRI_UID'] = $this->getUnusedTriggerGUID(); - } - } - } - - /** - * Renew all the GUID's for Subprocesses - * - * @param $oData array. - * @return void - */ - public function renewAllSubProcessGuid (&$oData) - { - $map = array (); - foreach ($oData->subProcess as $key => $val) { - $newGuid = $this->getUnusedSubProcessGUID(); - $map[$val['SP_UID']] = $newGuid; - $oData->subProcess[$key]['SP_UID'] = $newGuid; - } - } - - /** - * Renew all the GUID's for Case Tracker Objects - * - * @param $oData array. - * @return void - */ - public function renewAllCaseTrackerObjectGuid (&$oData) - { - $map = array (); - foreach ($oData->caseTrackerObject as $key => $val) { - $newGuid = $this->getUnusedCaseTrackerObjectGUID(); - $map[$val['CTO_UID']] = $newGuid; - $oData->caseTrackerObject[$key]['CTO_UID'] = $newGuid; - } - } - - /** - * Renew all the GUID's for DB Sources - * - * @param $oData array. - * @return void - */ - public function renewAllDBSourceGuid (&$oData) - { - $map = array (); - $aSqlConnections = array (); - foreach ($oData->dbconnections as $key => $val) { + if ($oOutput->OutputExists( $row['OUT_DOC_UID'] )) { + $oOutput->remove( $row['OUT_DOC_UID'] ); + } + $res = $oOutput->create( $row ); + } + return; + } + + /** + * change and Renew all Output GUID, because the process needs to have a new set of Outputs + * + * @param string $oData + * @return boolean + */ + public function renewAllOutputGuid (&$oData) + { + $map = array (); + foreach ($oData->outputs as $key => $val) { + $newGuid = $this->getUnusedOutputGUID(); + $map[$val['OUT_DOC_UID']] = $newGuid; + $oData->outputs[$key]['OUT_DOC_UID'] = $newGuid; + } + foreach ($oData->steps as $key => $val) { + if (isset( $val['STEP_TYPE_OBJ'] )) { + if ($val['STEP_TYPE_OBJ'] == 'OUTPUT_DOCUMENT') { + $newGuid = $map[$val['STEP_UID_OBJ']]; + $oData->steps[$key]['STEP_UID_OBJ'] = $newGuid; + } + } + } + foreach ($oData->caseTrackerObject as $key => $val) { + if ($val['CTO_TYPE_OBJ'] == 'OUTPUT_DOCUMENT') { + $newGuid = $map[$val['CTO_UID_OBJ']]; + $oData->steps[$key]['CTO_UID_OBJ'] = $newGuid; + } + } + foreach ($oData->objectPermissions as $key => $val) { + if ($val['OP_OBJ_TYPE'] == 'OUTPUT_DOCUMENT') { + $newGuid = $map[$val['OP_OBJ_UID']]; + $oData->objectPermissions[$key]['OP_OBJ_UID'] = $newGuid; + } + } + foreach ($oData->stepSupervisor as $key => $val) { + if ($val['STEP_TYPE_OBJ'] == 'OUTPUT_DOCUMENT') { + $newGuid = $map[$val['STEP_UID_OBJ']]; + $oData->stepSupervisor[$key]['STEP_UID_OBJ'] = $newGuid; + } + } + } + + /** + * change and Renew all Trigger GUID, because the process needs to have a new set of Triggers + * + * @param string $oData + * @return boolean + */ + public function renewAllTriggerGuid (&$oData) + { + $map = array (); + foreach ($oData->triggers as $key => $val) { + $newGuid = $this->getUnusedTriggerGUID(); + $map[$val['TRI_UID']] = $newGuid; + $oData->triggers[$key]['TRI_UID'] = $newGuid; + } + foreach ($oData->steptriggers as $key => $val) { + if (isset( $map[$val['TRI_UID']] )) { + $newGuid = $map[$val['TRI_UID']]; + $oData->steptriggers[$key]['TRI_UID'] = $newGuid; + } else { + $oData->steptriggers[$key]['TRI_UID'] = $this->getUnusedTriggerGUID(); + } + } + } + + /** + * Renew all the GUID's for Subprocesses + * + * @param $oData array. + * @return void + */ + public function renewAllSubProcessGuid (&$oData) + { + $map = array (); + foreach ($oData->subProcess as $key => $val) { + $newGuid = $this->getUnusedSubProcessGUID(); + $map[$val['SP_UID']] = $newGuid; + $oData->subProcess[$key]['SP_UID'] = $newGuid; + } + } + + /** + * Renew all the GUID's for Case Tracker Objects + * + * @param $oData array. + * @return void + */ + public function renewAllCaseTrackerObjectGuid (&$oData) + { + $map = array (); + foreach ($oData->caseTrackerObject as $key => $val) { + $newGuid = $this->getUnusedCaseTrackerObjectGUID(); + $map[$val['CTO_UID']] = $newGuid; + $oData->caseTrackerObject[$key]['CTO_UID'] = $newGuid; + } + } + + /** + * Renew all the GUID's for DB Sources + * + * @param $oData array. + * @return void + */ + public function renewAllDBSourceGuid (&$oData) + { + $map = array (); + $aSqlConnections = array (); + foreach ($oData->dbconnections as $key => $val) { $newGuid = $val['DBS_UID']; ///-- $this->getUnusedDBSourceGUID(); - $map[$val['DBS_UID']] = $newGuid; - $oData->dbconnections[$key]['DBS_UID'] = $newGuid; - } - $oData->sqlConnections = $map; - } - - /** - * Renew all the GUID's for Object Permissions - * - * @param $oData array. - * @return void - */ - public function renewAllObjectPermissionGuid (&$oData) - { - $map = array (); - foreach ($oData->objectPermissions as $key => $val) { - $newGuid = $this->getUnusedObjectPermissionGUID(); - $map[$val['OP_UID']] = $newGuid; - $oData->objectPermissions[$key]['OP_UID'] = $newGuid; - } - } - - /** - * Renew all the GUID's for Routes Objects - * - * @param $oData array. - * @return void - */ - public function renewAllRouteGuid (&$oData) - { - $map = array (); - if (isset( $oData->routes ) && is_array( $oData->routes )) { - foreach ($oData->routes as $key => $val) { - $newGuid = $this->getUnusedRouteGUID(); - $map[$val['ROU_UID']] = $newGuid; - $oData->routes[$key]['ROU_UID'] = $newGuid; - } - } - } - - /** - * Renew all the GUID's for Stage Objects - * - * @param $oData array. - * @return void - */ - public function renewAllStageGuid (&$oData) - { - $map = array (); - foreach ($oData->stage as $key => $val) { - $newGuid = $this->getUnusedStageGUID(); - $map[$val['STG_UID']] = $newGuid; - $oData->stage[$key]['STG_UID'] = $newGuid; - } - foreach ($oData->tasks as $key => $val) { - if (isset( $map[$val['STG_UID']] )) { - $newGuid = $map[$val['STG_UID']]; - $oData->tasks[$key]['STG_UID'] = $newGuid; - } - } - } - - /** - * Renew all the GUID's for Swimlanes Elements Objects - * - * @param $oData array. - * @return void - */ - public function renewAllSwimlanesElementsGuid (&$oData) - { - $map = array (); - foreach ($oData->lanes as $key => $val) { - $newGuid = $this->getUnusedSLGUID(); - $map[$val['SWI_UID']] = $newGuid; - $oData->lanes[$key]['SWI_UID'] = $newGuid; - } - } - - /** - * Renew the GUID's for all the Report Tables Objects - * - * @param $oData array. - * @return void - */ - public function renewAllReportTableGuid (&$oData) - { - $map = array (); - foreach ($oData->reportTables as $key => $val) { - $newGuid = $this->getUnusedRTGUID(); - $map[$val['REP_TAB_UID']] = $newGuid; - $oData->reportTables[$key]['REP_TAB_UID'] = $newGuid; - } - foreach ($oData->reportTablesVars as $key => $val) { - if (isset( $map[$val['REP_TAB_UID']] )) { + $map[$val['DBS_UID']] = $newGuid; + $oData->dbconnections[$key]['DBS_UID'] = $newGuid; + } + $oData->sqlConnections = $map; + } + + /** + * Renew all the GUID's for Object Permissions + * + * @param $oData array. + * @return void + */ + public function renewAllObjectPermissionGuid (&$oData) + { + $map = array (); + foreach ($oData->objectPermissions as $key => $val) { + $newGuid = $this->getUnusedObjectPermissionGUID(); + $map[$val['OP_UID']] = $newGuid; + $oData->objectPermissions[$key]['OP_UID'] = $newGuid; + } + } + + /** + * Renew all the GUID's for Routes Objects + * + * @param $oData array. + * @return void + */ + public function renewAllRouteGuid (&$oData) + { + $map = array (); + if (isset( $oData->routes ) && is_array( $oData->routes )) { + foreach ($oData->routes as $key => $val) { + $newGuid = $this->getUnusedRouteGUID(); + $map[$val['ROU_UID']] = $newGuid; + $oData->routes[$key]['ROU_UID'] = $newGuid; + } + } + } + + /** + * Renew all the GUID's for Stage Objects + * + * @param $oData array. + * @return void + */ + public function renewAllStageGuid (&$oData) + { + $map = array (); + foreach ($oData->stage as $key => $val) { + $newGuid = $this->getUnusedStageGUID(); + $map[$val['STG_UID']] = $newGuid; + $oData->stage[$key]['STG_UID'] = $newGuid; + } + foreach ($oData->tasks as $key => $val) { + if (isset( $map[$val['STG_UID']] )) { + $newGuid = $map[$val['STG_UID']]; + $oData->tasks[$key]['STG_UID'] = $newGuid; + } + } + } + + /** + * Renew all the GUID's for Swimlanes Elements Objects + * + * @param $oData array. + * @return void + */ + public function renewAllSwimlanesElementsGuid (&$oData) + { + $map = array (); + foreach ($oData->lanes as $key => $val) { + $newGuid = $this->getUnusedSLGUID(); + $map[$val['SWI_UID']] = $newGuid; + $oData->lanes[$key]['SWI_UID'] = $newGuid; + } + } + + /** + * Renew the GUID's for all the Report Tables Objects + * + * @param $oData array. + * @return void + */ + public function renewAllReportTableGuid (&$oData) + { + $map = array (); + foreach ($oData->reportTables as $key => $val) { + $newGuid = $this->getUnusedRTGUID(); + $map[$val['REP_TAB_UID']] = $newGuid; + $oData->reportTables[$key]['REP_TAB_UID'] = $newGuid; + } + foreach ($oData->reportTablesVars as $key => $val) { + if (isset( $map[$val['REP_TAB_UID']] )) { /*TODO: Why this can be not defined?? The scenario was when - * imported an existing process but as a new one - */ - $newGuid = $map[$val['REP_TAB_UID']]; - $oData->reportTablesVars[$key]['REP_TAB_UID'] = $newGuid; - } - } - } - - /** - * Renew all the GUID's for All The Report Vars Objects - * - * @param $oData array. - * @return void - */ - public function renewAllReportVarGuid (&$oData) - { - $map = array (); - foreach ($oData->reportTablesVars as $key => $val) { - $newGuid = $this->getUnusedRTVGUID(); - $map[$val['REP_VAR_UID']] = $newGuid; - $oData->reportTablesVars[$key]['REP_VAR_UID'] = $newGuid; - } - } - - /** - * Renew the GUID's for all the Field Conditions Objects - * - * @param $oData array. - * @return void - */ - public function renewAllFieldCondition (&$oData) - { - $map = array (); - foreach ($oData->fieldCondition as $key => $val) { - $newGuid = $this->getUnusedFieldConditionGUID(); - $map[$val['FCD_UID']] = $newGuid; - $oData->fieldCondition[$key]['FCD_UID'] = $newGuid; - } - } - - /** - * Renew the GUID's for all the Events Objects - * - * @param $oData array. - * @return void - */ - public function renewAllEvent (&$oData) - { - $map = array (); - foreach ($oData->event as $key => $val) { - $newGuid = $this->getUnusedEventGUID(); - $map[$val['EVN_UID']] = $newGuid; - $oData->event[$key]['EVN_UID'] = $newGuid; - } - } - - /** - * Renew the GUID's for all Case Scheduler Objects - * - * @param $oData array. - * @return void - */ - public function renewAllCaseScheduler (&$oData) - { - $map = array (); - foreach ($oData->caseScheduler as $key => $val) { - $newGuid = $this->getUnusedCaseSchedulerGUID(); - $map[$val['SCH_UID']] = $newGuid; - $oData->caseScheduler[$key]['SCH_UID'] = $newGuid; - } - } - - /** - * Renew the GUID's for all the Uids for all the elements - * - * @param $oData array. - * @return void - */ - public function renewAll (&$oData) - { - $this->renewAllTaskGuid( $oData ); - $this->renewAllDynaformGuid( $oData ); - $this->renewAllInputGuid( $oData ); - $this->renewAllOutputGuid( $oData ); - $this->renewAllStepGuid( $oData ); - $this->renewAllTriggerGuid( $oData ); - $this->renewAllSubProcessGuid( $oData ); - $this->renewAllCaseTrackerObjectGuid( $oData ); - $this->renewAllDBSourceGuid( $oData ); - $this->renewAllObjectPermissionGuid( $oData ); - $this->renewAllRouteGuid( $oData ); - $this->renewAllStageGuid( $oData ); - $this->renewAllSwimlanesElementsGuid( $oData ); - $this->renewAllReportTableGuid( $oData ); - $this->renewAllReportVarGuid( $oData ); - $this->renewAllFieldCondition( $oData ); - $this->renewAllEvent( $oData ); - $this->renewAllCaseScheduler( $oData ); - } - - /** - * Get Step Rows from a Process - * - * @param $sProUid array. - * @return array $aStep. - */ - public function getStepRows ($sProUid) - { - try { - $aStep = array (); - $oCriteria = new Criteria( 'workflow' ); - $oCriteria->add( StepPeer::PRO_UID, $sProUid ); - $oDataset = StepPeer::doSelectRS( $oCriteria ); - $oDataset->setFetchmode( ResultSet::FETCHMODE_ASSOC ); - $oDataset->next(); - while ($aRow = $oDataset->getRow()) { - $oStep = new Step(); - $aStep[] = $oStep->Load( $aRow['STEP_UID'] ); - $oDataset->next(); - } - return $aStep; - } catch (Exception $oError) { - throw ($oError); - } - } - - /** - * Create Step Rows from a Process - * - * @param $aStep array. - * @return void. - */ - public function createStepRows ($aStep) - { - foreach ($aStep as $key => $row) { - $oStep = new Step(); - if (isset( $row['STEP_UID'] )) { - if ($oStep->StepExists( $row['STEP_UID'] )) { - $oStep->remove( $row['STEP_UID'] ); - } - $res = $oStep->create( $row ); - } - } - return; - } - - /** - * Create Step Supervisor Rows for a Process from an array of data - * - * @param $aStepSupervisor array. - * @return void. - */ - public function createStepSupervisorRows ($aStepSupervisor) - { - foreach ($aStepSupervisor as $key => $row) { - $oStepSupervisor = new StepSupervisor(); - if ($oStepSupervisor->Exists( $row['STEP_UID'] )) { - $oStepSupervisor->remove( $row['STEP_UID'] ); - } - $oStepSupervisor->create( $row ); - } + * imported an existing process but as a new one + */ + $newGuid = $map[$val['REP_TAB_UID']]; + $oData->reportTablesVars[$key]['REP_TAB_UID'] = $newGuid; + } + } + } + + /** + * Renew all the GUID's for All The Report Vars Objects + * + * @param $oData array. + * @return void + */ + public function renewAllReportVarGuid (&$oData) + { + $map = array (); + foreach ($oData->reportTablesVars as $key => $val) { + $newGuid = $this->getUnusedRTVGUID(); + $map[$val['REP_VAR_UID']] = $newGuid; + $oData->reportTablesVars[$key]['REP_VAR_UID'] = $newGuid; + } + } + + /** + * Renew the GUID's for all the Field Conditions Objects + * + * @param $oData array. + * @return void + */ + public function renewAllFieldCondition (&$oData) + { + $map = array (); + foreach ($oData->fieldCondition as $key => $val) { + $newGuid = $this->getUnusedFieldConditionGUID(); + $map[$val['FCD_UID']] = $newGuid; + $oData->fieldCondition[$key]['FCD_UID'] = $newGuid; + } + } + + /** + * Renew the GUID's for all the Events Objects + * + * @param $oData array. + * @return void + */ + public function renewAllEvent (&$oData) + { + $map = array (); + foreach ($oData->event as $key => $val) { + $newGuid = $this->getUnusedEventGUID(); + $map[$val['EVN_UID']] = $newGuid; + $oData->event[$key]['EVN_UID'] = $newGuid; + } + } + + /** + * Renew the GUID's for all Case Scheduler Objects + * + * @param $oData array. + * @return void + */ + public function renewAllCaseScheduler (&$oData) + { + $map = array (); + foreach ($oData->caseScheduler as $key => $val) { + $newGuid = $this->getUnusedCaseSchedulerGUID(); + $map[$val['SCH_UID']] = $newGuid; + $oData->caseScheduler[$key]['SCH_UID'] = $newGuid; + } + } + + /** + * Renew the GUID's for all the Uids for all the elements + * + * @param $oData array. + * @return void + */ + public function renewAll (&$oData) + { + $this->renewAllTaskGuid( $oData ); + $this->renewAllDynaformGuid( $oData ); + $this->renewAllInputGuid( $oData ); + $this->renewAllOutputGuid( $oData ); + $this->renewAllStepGuid( $oData ); + $this->renewAllTriggerGuid( $oData ); + $this->renewAllSubProcessGuid( $oData ); + $this->renewAllCaseTrackerObjectGuid( $oData ); + $this->renewAllDBSourceGuid( $oData ); + $this->renewAllObjectPermissionGuid( $oData ); + $this->renewAllRouteGuid( $oData ); + $this->renewAllStageGuid( $oData ); + $this->renewAllSwimlanesElementsGuid( $oData ); + $this->renewAllReportTableGuid( $oData ); + $this->renewAllReportVarGuid( $oData ); + $this->renewAllFieldCondition( $oData ); + $this->renewAllEvent( $oData ); + $this->renewAllCaseScheduler( $oData ); + } + + /** + * Get Step Rows from a Process + * + * @param $sProUid array. + * @return array $aStep. + */ + public function getStepRows ($sProUid) + { + try { + $aStep = array (); + $oCriteria = new Criteria( 'workflow' ); + $oCriteria->add( StepPeer::PRO_UID, $sProUid ); + $oDataset = StepPeer::doSelectRS( $oCriteria ); + $oDataset->setFetchmode( ResultSet::FETCHMODE_ASSOC ); + $oDataset->next(); + while ($aRow = $oDataset->getRow()) { + $oStep = new Step(); + $aStep[] = $oStep->Load( $aRow['STEP_UID'] ); + $oDataset->next(); + } + return $aStep; + } catch (Exception $oError) { + throw ($oError); + } + } + + /** + * Create Step Rows from a Process + * + * @param $aStep array. + * @return void. + */ + public function createStepRows ($aStep) + { + foreach ($aStep as $key => $row) { + $oStep = new Step(); + if (isset( $row['STEP_UID'] )) { + if ($oStep->StepExists( $row['STEP_UID'] )) { + $oStep->remove( $row['STEP_UID'] ); + } + $res = $oStep->create( $row ); + } + } + return; + } + + /** + * Create Step Supervisor Rows for a Process from an array of data + * + * @param $aStepSupervisor array. + * @return void. + */ + public function createStepSupervisorRows ($aStepSupervisor) + { + foreach ($aStepSupervisor as $key => $row) { + $oStepSupervisor = new StepSupervisor(); + if ($oStepSupervisor->Exists( $row['STEP_UID'] )) { + $oStepSupervisor->remove( $row['STEP_UID'] ); + } + $oStepSupervisor->create( $row ); + } } #@!Neyek - - - /** - * change and Renew all Step GUID, because the process needs to have a new set of Steps - * - * @param string $oData - * @return boolean - */ - public function renewAllStepGuid (&$oData) - { - $map = array (); - foreach ($oData->steps as $key => $val) { - if (isset( $val['STEP_UID'] )) { - $newGuid = $this->getUnusedStepGUID(); - $map[$val['STEP_UID']] = $newGuid; - $oData->steps[$key]['STEP_UID'] = $newGuid; - } - } - foreach ($oData->steptriggers as $key => $val) { - if ($val['STEP_UID'] > 0) { - if (isset( $map[$val['STEP_UID']] )) { - $newGuid = $map[$val['STEP_UID']]; - $oData->steptriggers[$key]['STEP_UID'] = $newGuid; - } else { - $oData->steptriggers[$key]['STEP_UID'] = $this->getUnusedStepGUID(); - } - } - } - foreach ($oData->stepSupervisor as $key => $val) { - if ($val['STEP_UID'] > 0) { - if (isset( $map[$val['STEP_UID']] )) { - $newGuid = $map[$val['STEP_UID']]; - $oData->stepSupervisor[$key]['STEP_UID'] = $newGuid; - } else { - $oData->stepSupervisor[$key]['STEP_UID'] = $this->getUnusedStepGUID(); - } - } - } - } - - /** - * Get Dynaform Rows from a Process - * - * @param string $sProUid - * @return $aDynaform array - */ - public function getDynaformRows ($sProUid) - { - try { - $aDynaform = array (); - $oCriteria = new Criteria( 'workflow' ); - $oCriteria->add( DynaformPeer::PRO_UID, $sProUid ); - $oDataset = DynaformPeer::doSelectRS( $oCriteria ); - $oDataset->setFetchmode( ResultSet::FETCHMODE_ASSOC ); - $oDataset->next(); - while ($aRow = $oDataset->getRow()) { - $oDynaform = new Dynaform(); - $aDynaform[] = $oDynaform->Load( $aRow['DYN_UID'] ); - $oDataset->next(); - } - return $aDynaform; - } catch (Exception $oError) { - throw ($oError); - } - } - - /** - * Get Object Permission Rows from a Process - * - * @param string $sProUid - * @return $aDynaform array - */ - public function getObjectPermissionRows ($sProUid) - { + + + /** + * change and Renew all Step GUID, because the process needs to have a new set of Steps + * + * @param string $oData + * @return boolean + */ + public function renewAllStepGuid (&$oData) + { + $map = array (); + foreach ($oData->steps as $key => $val) { + if (isset( $val['STEP_UID'] )) { + $newGuid = $this->getUnusedStepGUID(); + $map[$val['STEP_UID']] = $newGuid; + $oData->steps[$key]['STEP_UID'] = $newGuid; + } + } + foreach ($oData->steptriggers as $key => $val) { + if ($val['STEP_UID'] > 0) { + if (isset( $map[$val['STEP_UID']] )) { + $newGuid = $map[$val['STEP_UID']]; + $oData->steptriggers[$key]['STEP_UID'] = $newGuid; + } else { + $oData->steptriggers[$key]['STEP_UID'] = $this->getUnusedStepGUID(); + } + } + } + foreach ($oData->stepSupervisor as $key => $val) { + if ($val['STEP_UID'] > 0) { + if (isset( $map[$val['STEP_UID']] )) { + $newGuid = $map[$val['STEP_UID']]; + $oData->stepSupervisor[$key]['STEP_UID'] = $newGuid; + } else { + $oData->stepSupervisor[$key]['STEP_UID'] = $this->getUnusedStepGUID(); + } + } + } + } + + /** + * Get Dynaform Rows from a Process + * + * @param string $sProUid + * @return $aDynaform array + */ + public function getDynaformRows ($sProUid) + { + try { + $aDynaform = array (); + $oCriteria = new Criteria( 'workflow' ); + $oCriteria->add( DynaformPeer::PRO_UID, $sProUid ); + $oDataset = DynaformPeer::doSelectRS( $oCriteria ); + $oDataset->setFetchmode( ResultSet::FETCHMODE_ASSOC ); + $oDataset->next(); + while ($aRow = $oDataset->getRow()) { + $oDynaform = new Dynaform(); + $aDynaform[] = $oDynaform->Load( $aRow['DYN_UID'] ); + $oDataset->next(); + } + return $aDynaform; + } catch (Exception $oError) { + throw ($oError); + } + } + + /** + * Get Object Permission Rows from a Process + * + * @param string $sProUid + * @return $aDynaform array + */ + public function getObjectPermissionRows ($sProUid) + { // by erik - try { - $oPermissions = array (); - $oCriteria = new Criteria( 'workflow' ); - $oCriteria->add( ObjectPermissionPeer::PRO_UID, $sProUid ); - $oCriteria->add( ObjectPermissionPeer::OP_USER_RELATION, 2 ); - $oDataset = ObjectPermissionPeer::doSelectRS( $oCriteria ); - $oDataset->setFetchmode( ResultSet::FETCHMODE_ASSOC ); - $oDataset->next(); - while ($aRow = $oDataset->getRow()) { - $o = new ObjectPermission(); - $oPermissions[] = $o->Load( $aRow['OP_UID'] ); - $oDataset->next(); - } - return $oPermissions; - } catch (Exception $oError) { - throw ($oError); - } - } + try { + $oPermissions = array (); + $oCriteria = new Criteria( 'workflow' ); + $oCriteria->add( ObjectPermissionPeer::PRO_UID, $sProUid ); + $oCriteria->add( ObjectPermissionPeer::OP_USER_RELATION, 2 ); + $oDataset = ObjectPermissionPeer::doSelectRS( $oCriteria ); + $oDataset->setFetchmode( ResultSet::FETCHMODE_ASSOC ); + $oDataset->next(); + while ($aRow = $oDataset->getRow()) { + $o = new ObjectPermission(); + $oPermissions[] = $o->Load( $aRow['OP_UID'] ); + $oDataset->next(); + } + return $oPermissions; + } catch (Exception $oError) { + throw ($oError); + } + } #@!neyek - - - /** - * Create Dynaform Rows for a Process form an array - * - * @param array $aDynaform - * @return void - */ - public function createDynaformRows ($aDynaform) - { - foreach ($aDynaform as $key => $row) { - $oDynaform = new Dynaform(); + + + /** + * Create Dynaform Rows for a Process form an array + * + * @param array $aDynaform + * @return void + */ + public function createDynaformRows ($aDynaform) + { + foreach ($aDynaform as $key => $row) { + $oDynaform = new Dynaform(); //unset ($row['TAS_UID']); - if ($oDynaform->exists( $row['DYN_UID'] )) { - $oDynaform->remove( $row['DYN_UID'] ); - } - $res = $oDynaform->create( $row ); - } - return; - } + if ($oDynaform->exists( $row['DYN_UID'] )) { + $oDynaform->remove( $row['DYN_UID'] ); + } + $res = $oDynaform->create( $row ); + } + return; + } #@!neyek - - - /** - * Create Step Trigger Rows for a Process form an array - * - * @param array $aStepTrigger - * @return void - */ - public function createStepTriggerRows ($aStepTrigger) - { - foreach ($aStepTrigger as $key => $row) { - $oStepTrigger = new StepTrigger(); + + + /** + * Create Step Trigger Rows for a Process form an array + * + * @param array $aStepTrigger + * @return void + */ + public function createStepTriggerRows ($aStepTrigger) + { + foreach ($aStepTrigger as $key => $row) { + $oStepTrigger = new StepTrigger(); //unset ($row['TAS_UID']); - if ($oStepTrigger->stepTriggerExists( $row['STEP_UID'], $row['TAS_UID'], $row['TRI_UID'], $row['ST_TYPE'] )) { - $oStepTrigger->remove( $row['STEP_UID'], $row['TAS_UID'], $row['TRI_UID'], $row['ST_TYPE'] ); - } - $res = $oStepTrigger->createRow( $row ); - } - return; - } - - /** - * Get Step Trigger Rows for a Process form an array - * - * @param array $aTask - * @return array $aStepTrigger - */ - public function getStepTriggerRows ($aTask) - { - try { - $aInTasks = array (); - foreach ($aTask as $key => $val) { - $aInTasks[] = $val['TAS_UID']; - } - - $aTrigger = array (); - $oCriteria = new Criteria( 'workflow' ); - $oCriteria->add( StepTriggerPeer::TAS_UID, $aInTasks, Criteria::IN ); - $oDataset = StepTriggerPeer::doSelectRS( $oCriteria ); - $oDataset->setFetchmode( ResultSet::FETCHMODE_ASSOC ); - $oDataset->next(); - $aStepTrigger = array (); - while ($aRow = $oDataset->getRow()) { - $aStepTrigger[] = $aRow; - $oDataset->next(); - } - return $aStepTrigger; - } catch (Exception $oError) { - throw ($oError); - } - } - - /** - * Get Step Trigger Rows for a Process form an array - * - * @param array $aTask - * @return array $aStepTrigger - */ - public function getTriggerRows ($sProUid) - { - try { - $aTrigger = array (); - $oCriteria = new Criteria( 'workflow' ); - $oCriteria->add( TriggersPeer::PRO_UID, $sProUid ); - $oDataset = TriggersPeer::doSelectRS( $oCriteria ); - $oDataset->setFetchmode( ResultSet::FETCHMODE_ASSOC ); - $oDataset->next(); - while ($aRow = $oDataset->getRow()) { - $oTrigger = new Triggers(); - $aTrigger[] = $oTrigger->Load( $aRow['TRI_UID'] ); - $oDataset->next(); - } - return $aTrigger; - } catch (Exception $oError) { - throw ($oError); - } - } - - /** - * Create Step Trigger Rows for a Process form an array - * - * @param array $aTrigger - * @return void - */ - public function createTriggerRows ($aTrigger) - { - foreach ($aTrigger as $key => $row) { - $oTrigger = new Triggers(); + if ($oStepTrigger->stepTriggerExists( $row['STEP_UID'], $row['TAS_UID'], $row['TRI_UID'], $row['ST_TYPE'] )) { + $oStepTrigger->remove( $row['STEP_UID'], $row['TAS_UID'], $row['TRI_UID'], $row['ST_TYPE'] ); + } + $res = $oStepTrigger->createRow( $row ); + } + return; + } + + /** + * Get Step Trigger Rows for a Process form an array + * + * @param array $aTask + * @return array $aStepTrigger + */ + public function getStepTriggerRows ($aTask) + { + try { + $aInTasks = array (); + foreach ($aTask as $key => $val) { + $aInTasks[] = $val['TAS_UID']; + } + + $aTrigger = array (); + $oCriteria = new Criteria( 'workflow' ); + $oCriteria->add( StepTriggerPeer::TAS_UID, $aInTasks, Criteria::IN ); + $oDataset = StepTriggerPeer::doSelectRS( $oCriteria ); + $oDataset->setFetchmode( ResultSet::FETCHMODE_ASSOC ); + $oDataset->next(); + $aStepTrigger = array (); + while ($aRow = $oDataset->getRow()) { + $aStepTrigger[] = $aRow; + $oDataset->next(); + } + return $aStepTrigger; + } catch (Exception $oError) { + throw ($oError); + } + } + + /** + * Get Step Trigger Rows for a Process form an array + * + * @param array $aTask + * @return array $aStepTrigger + */ + public function getTriggerRows ($sProUid) + { + try { + $aTrigger = array (); + $oCriteria = new Criteria( 'workflow' ); + $oCriteria->add( TriggersPeer::PRO_UID, $sProUid ); + $oDataset = TriggersPeer::doSelectRS( $oCriteria ); + $oDataset->setFetchmode( ResultSet::FETCHMODE_ASSOC ); + $oDataset->next(); + while ($aRow = $oDataset->getRow()) { + $oTrigger = new Triggers(); + $aTrigger[] = $oTrigger->Load( $aRow['TRI_UID'] ); + $oDataset->next(); + } + return $aTrigger; + } catch (Exception $oError) { + throw ($oError); + } + } + + /** + * Create Step Trigger Rows for a Process form an array + * + * @param array $aTrigger + * @return void + */ + public function createTriggerRows ($aTrigger) + { + foreach ($aTrigger as $key => $row) { + $oTrigger = new Triggers(); //unset ($row['TAS_UID']); - if ($oTrigger->TriggerExists( $row['TRI_UID'] )) { - $oTrigger->remove( $row['TRI_UID'] ); - } - $res = $oTrigger->create( $row ); - } - return; - } - - /** - * Get Groupwf Rows for a Process form an array - * - * @param array $aGroups - * @return array $aGroupwf - */ - public function getGroupwfRows ($aGroups) - { - try { - $aInGroups = array (); - foreach ($aGroups as $key => $val) { - $aInGroups[] = $val['USR_UID']; - } - - $aGroupwf = array (); - $oCriteria = new Criteria( 'workflow' ); - $oCriteria->add( GroupwfPeer::GRP_UID, $aInGroups, Criteria::IN ); - $oDataset = GroupwfPeer::doSelectRS( $oCriteria ); - $oDataset->setFetchmode( ResultSet::FETCHMODE_ASSOC ); - $oDataset->next(); - while ($aRow = $oDataset->getRow()) { - $oGroupwf = new Groupwf(); - $aGroupwf[] = $oGroupwf->Load( $aRow['GRP_UID'] ); - $oDataset->next(); - } - return $aGroupwf; - } catch (Exception $oError) { - throw ($oError); - } - } - - /** - * Get DB Connections Rows for a Process - * - * @param array $sProUid - * @return array $aConnections - */ - public function getDBConnectionsRows ($sProUid) - { - try { - $aConnections = array (); - $oCriteria = new Criteria( 'workflow' ); - $oCriteria->add( DbSourcePeer::PRO_UID, $sProUid ); - $oDataset = DbSourcePeer::doSelectRS( $oCriteria ); - $oDataset->setFetchmode( ResultSet::FETCHMODE_ASSOC ); - $oDataset->next(); - while ($aRow = $oDataset->getRow()) { - $oConnection = new DbSource(); - $aConnections[] = $oConnection->Load( $aRow['DBS_UID'], $aRow['PRO_UID'] ); - $oDataset->next(); - } - return $aConnections; - } catch (Exception $oError) { - throw $oError; - } - } - - /** - * Get Step Supervisor Rows for a Process form an array - * - * @param array $sProUid - * @return array $aStepSup - */ - public function getStepSupervisorRows ($sProUid) - { - try { - $aConnections = array (); - $oCriteria = new Criteria( 'workflow' ); - $oCriteria->add( StepSupervisorPeer::PRO_UID, $sProUid ); - $oDataset = StepSupervisorPeer::doSelectRS( $oCriteria ); - $oDataset->setFetchmode( ResultSet::FETCHMODE_ASSOC ); - $oDataset->next(); - $aStepSup = array (); - while ($aRow = $oDataset->getRow()) { - $aStepSup[] = $aRow; - $oDataset->next(); - } - return $aStepSup; - } catch (Exception $oError) { - throw $oError; - } - } - - /** - * Get Report Tables Rows for a Process form an array - * - * @param array $aTask - * @return array $aReps - */ - public function getReportTablesRows ($sProUid) - { - try { - $aReps = array (); - $oCriteria = new Criteria( 'workflow' ); - $oCriteria->add( ReportTablePeer::PRO_UID, $sProUid ); - $oDataset = ReportTablePeer::doSelectRS( $oCriteria ); - $oDataset->setFetchmode( ResultSet::FETCHMODE_ASSOC ); - $oDataset->next(); - while ($aRow = $oDataset->getRow()) { - $oRep = new ReportTable(); - $aReps[] = $oRep->load( $aRow['REP_TAB_UID'] ); - $oDataset->next(); - } - return $aReps; - } catch (Exception $oError) { - throw $oError; - } - } - - /** - * Get Report Tables Vars Rows for a Process - * - * @param string $sProUid - * @return array $aRepVars - */ - public function getReportTablesVarsRows ($sProUid) - { - try { - $aRepVars = array (); - $oCriteria = new Criteria( 'workflow' ); - $oCriteria->add( ReportVarPeer::PRO_UID, $sProUid ); - $oDataset = ReportVarPeer::doSelectRS( $oCriteria ); - $oDataset->setFetchmode( ResultSet::FETCHMODE_ASSOC ); - $oDataset->next(); - while ($aRow = $oDataset->getRow()) { - $oRepVar = new ReportVar(); - $aRepVars[] = $oRepVar->load( $aRow['REP_VAR_UID'] ); - $oDataset->next(); - } - return $aRepVars; - } catch (Exception $oError) { - throw $oError; - } - } - - /** - * Get Task User Rows for a Process - * - * @param array $aTask - * @return array $aStepTrigger - */ - public function getTaskUserRows ($aTask) - { - try { - $aInTasks = array (); - foreach ($aTask as $key => $val) { - $aInTasks[] = $val['TAS_UID']; - } - - $aTaskUser = array (); - $oCriteria = new Criteria( 'workflow' ); - $oCriteria->add( TaskUserPeer::TAS_UID, $aInTasks, Criteria::IN ); - $oCriteria->add( TaskUserPeer::TU_RELATION, 2 ); - $oDataset = TaskUserPeer::doSelectRS( $oCriteria ); - $oDataset->setFetchmode( ResultSet::FETCHMODE_ASSOC ); - $oDataset->next(); - while ($aRow = $oDataset->getRow()) { - $oCriteria2 = new Criteria( 'workflow' ); - $oCriteria2->clearSelectColumns(); - $oCriteria2->addSelectColumn( 'COUNT(*)' ); - $oCriteria2->add( GroupwfPeer::GRP_UID, $aRow['USR_UID'] ); - $oCriteria2->add( GroupwfPeer::GRP_STATUS, 'ACTIVE' ); - $oDataset2 = GroupwfPeer::doSelectRS( $oCriteria2 ); + if ($oTrigger->TriggerExists( $row['TRI_UID'] )) { + $oTrigger->remove( $row['TRI_UID'] ); + } + $res = $oTrigger->create( $row ); + } + return; + } + + /** + * Get Groupwf Rows for a Process form an array + * + * @param array $aGroups + * @return array $aGroupwf + */ + public function getGroupwfRows ($aGroups) + { + try { + $aInGroups = array (); + foreach ($aGroups as $key => $val) { + $aInGroups[] = $val['USR_UID']; + } + + $aGroupwf = array (); + $oCriteria = new Criteria( 'workflow' ); + $oCriteria->add( GroupwfPeer::GRP_UID, $aInGroups, Criteria::IN ); + $oDataset = GroupwfPeer::doSelectRS( $oCriteria ); + $oDataset->setFetchmode( ResultSet::FETCHMODE_ASSOC ); + $oDataset->next(); + while ($aRow = $oDataset->getRow()) { + $oGroupwf = new Groupwf(); + $aGroupwf[] = $oGroupwf->Load( $aRow['GRP_UID'] ); + $oDataset->next(); + } + return $aGroupwf; + } catch (Exception $oError) { + throw ($oError); + } + } + + /** + * Get DB Connections Rows for a Process + * + * @param array $sProUid + * @return array $aConnections + */ + public function getDBConnectionsRows ($sProUid) + { + try { + $aConnections = array (); + $oCriteria = new Criteria( 'workflow' ); + $oCriteria->add( DbSourcePeer::PRO_UID, $sProUid ); + $oDataset = DbSourcePeer::doSelectRS( $oCriteria ); + $oDataset->setFetchmode( ResultSet::FETCHMODE_ASSOC ); + $oDataset->next(); + while ($aRow = $oDataset->getRow()) { + $oConnection = new DbSource(); + $aConnections[] = $oConnection->Load( $aRow['DBS_UID'], $aRow['PRO_UID'] ); + $oDataset->next(); + } + return $aConnections; + } catch (Exception $oError) { + throw $oError; + } + } + + /** + * Get Step Supervisor Rows for a Process form an array + * + * @param array $sProUid + * @return array $aStepSup + */ + public function getStepSupervisorRows ($sProUid) + { + try { + $aConnections = array (); + $oCriteria = new Criteria( 'workflow' ); + $oCriteria->add( StepSupervisorPeer::PRO_UID, $sProUid ); + $oDataset = StepSupervisorPeer::doSelectRS( $oCriteria ); + $oDataset->setFetchmode( ResultSet::FETCHMODE_ASSOC ); + $oDataset->next(); + $aStepSup = array (); + while ($aRow = $oDataset->getRow()) { + $aStepSup[] = $aRow; + $oDataset->next(); + } + return $aStepSup; + } catch (Exception $oError) { + throw $oError; + } + } + + /** + * Get Report Tables Rows for a Process form an array + * + * @param array $aTask + * @return array $aReps + */ + public function getReportTablesRows ($sProUid) + { + try { + $aReps = array (); + $oCriteria = new Criteria( 'workflow' ); + $oCriteria->add( ReportTablePeer::PRO_UID, $sProUid ); + $oDataset = ReportTablePeer::doSelectRS( $oCriteria ); + $oDataset->setFetchmode( ResultSet::FETCHMODE_ASSOC ); + $oDataset->next(); + while ($aRow = $oDataset->getRow()) { + $oRep = new ReportTable(); + $aReps[] = $oRep->load( $aRow['REP_TAB_UID'] ); + $oDataset->next(); + } + return $aReps; + } catch (Exception $oError) { + throw $oError; + } + } + + /** + * Get Report Tables Vars Rows for a Process + * + * @param string $sProUid + * @return array $aRepVars + */ + public function getReportTablesVarsRows ($sProUid) + { + try { + $aRepVars = array (); + $oCriteria = new Criteria( 'workflow' ); + $oCriteria->add( ReportVarPeer::PRO_UID, $sProUid ); + $oDataset = ReportVarPeer::doSelectRS( $oCriteria ); + $oDataset->setFetchmode( ResultSet::FETCHMODE_ASSOC ); + $oDataset->next(); + while ($aRow = $oDataset->getRow()) { + $oRepVar = new ReportVar(); + $aRepVars[] = $oRepVar->load( $aRow['REP_VAR_UID'] ); + $oDataset->next(); + } + return $aRepVars; + } catch (Exception $oError) { + throw $oError; + } + } + + /** + * Get Task User Rows for a Process + * + * @param array $aTask + * @return array $aStepTrigger + */ + public function getTaskUserRows ($aTask) + { + try { + $aInTasks = array (); + foreach ($aTask as $key => $val) { + $aInTasks[] = $val['TAS_UID']; + } + + $aTaskUser = array (); + $oCriteria = new Criteria( 'workflow' ); + $oCriteria->add( TaskUserPeer::TAS_UID, $aInTasks, Criteria::IN ); + $oCriteria->add( TaskUserPeer::TU_RELATION, 2 ); + $oDataset = TaskUserPeer::doSelectRS( $oCriteria ); + $oDataset->setFetchmode( ResultSet::FETCHMODE_ASSOC ); + $oDataset->next(); + while ($aRow = $oDataset->getRow()) { + $oCriteria2 = new Criteria( 'workflow' ); + $oCriteria2->clearSelectColumns(); + $oCriteria2->addSelectColumn( 'COUNT(*)' ); + $oCriteria2->add( GroupwfPeer::GRP_UID, $aRow['USR_UID'] ); + $oCriteria2->add( GroupwfPeer::GRP_STATUS, 'ACTIVE' ); + $oDataset2 = GroupwfPeer::doSelectRS( $oCriteria2 ); //$oDataset->setFetchmode(ResultSet::FETCHMODE_ASSOC); - $oDataset2->next(); - $aRow2 = $oDataset2->getRow(); - $bActiveGroup = $aRow2[0]; - if ($bActiveGroup == 1) { - $aTaskUser[] = $aRow; - } - $oDataset->next(); - } - return $aTaskUser; - } catch (Exception $oError) { - throw ($oError); - } - } - - /** - * Get Task User Rows from an array of data - * - * @param array $aTaskUser - * @return array $aStepTrigger - */ - public function createTaskUserRows ($aTaskUser) - { - foreach ($aTaskUser as $key => $row) { - $oTaskUser = new TaskUser(); - if ($oTaskUser->TaskUserExists( $row['TAS_UID'], $row['USR_UID'], $row['TU_TYPE'], $row['TU_RELATION'] )) { - $oTaskUser->remove( $row['TAS_UID'], $row['USR_UID'], $row['TU_TYPE'], $row['TU_RELATION'] ); - } - $res = $oTaskUser->create( $row ); - } - return; - } - - /** - * Get Task User Rows from an array of data - * - * @param array $aTaskUser - * @return array $aStepTrigger - */ - public function createGroupRow ($aGroupwf) - { - foreach ($aGroupwf as $key => $row) { - $oGroupwf = new Groupwf(); - if ($oGroupwf->GroupwfExists( $row['GRP_UID'] )) { - $oGroupwf->remove( $row['GRP_UID'] ); - } - $res = $oGroupwf->create( $row ); - } - } - - /** - * Create DB Connections rows from an array of data - * - * @param array $aConnections - * @return void - */ - public function createDBConnectionsRows ($aConnections) - { - foreach ($aConnections as $sKey => $aRow) { - $oConnection = new DbSource(); - if ($oConnection->Exists( $aRow['DBS_UID'], $aRow['PRO_UID'] )) { - $oConnection->remove( $aRow['DBS_UID'], $aRow['PRO_UID'] ); - } - $oConnection->create( $aRow ); - + $oDataset2->next(); + $aRow2 = $oDataset2->getRow(); + $bActiveGroup = $aRow2[0]; + if ($bActiveGroup == 1) { + $aTaskUser[] = $aRow; + } + $oDataset->next(); + } + return $aTaskUser; + } catch (Exception $oError) { + throw ($oError); + } + } + + /** + * Get Task User Rows from an array of data + * + * @param array $aTaskUser + * @return array $aStepTrigger + */ + public function createTaskUserRows ($aTaskUser) + { + foreach ($aTaskUser as $key => $row) { + $oTaskUser = new TaskUser(); + if ($oTaskUser->TaskUserExists( $row['TAS_UID'], $row['USR_UID'], $row['TU_TYPE'], $row['TU_RELATION'] )) { + $oTaskUser->remove( $row['TAS_UID'], $row['USR_UID'], $row['TU_TYPE'], $row['TU_RELATION'] ); + } + $res = $oTaskUser->create( $row ); + } + return; + } + + /** + * Get Task User Rows from an array of data + * + * @param array $aTaskUser + * @return array $aStepTrigger + */ + public function createGroupRow ($aGroupwf) + { + foreach ($aGroupwf as $key => $row) { + $oGroupwf = new Groupwf(); + if ($oGroupwf->GroupwfExists( $row['GRP_UID'] )) { + $oGroupwf->remove( $row['GRP_UID'] ); + } + $res = $oGroupwf->create( $row ); + } + } + + /** + * Create DB Connections rows from an array of data + * + * @param array $aConnections + * @return void + */ + public function createDBConnectionsRows ($aConnections) + { + foreach ($aConnections as $sKey => $aRow) { + $oConnection = new DbSource(); + if ($oConnection->Exists( $aRow['DBS_UID'], $aRow['PRO_UID'] )) { + $oConnection->remove( $aRow['DBS_UID'], $aRow['PRO_UID'] ); + } + $oConnection->create( $aRow ); + // Update information in the table of contents - $oContent = new Content(); - $ConCategory = 'DBS_DESCRIPTION'; - $ConParent = ''; - $ConId = $aRow['DBS_UID']; - $ConLang = SYS_LANG; - if ($oContent->Exists( $ConCategory, $ConParent, $ConId, $ConLang )) { - $oContent->removeContent( $ConCategory, $ConParent, $ConId ); - } - $oContent->addContent( $ConCategory, $ConParent, $ConId, $ConLang, "" ); - } + $oContent = new Content(); + $ConCategory = 'DBS_DESCRIPTION'; + $ConParent = ''; + $ConId = $aRow['DBS_UID']; + $ConLang = SYS_LANG; + if ($oContent->Exists( $ConCategory, $ConParent, $ConId, $ConLang )) { + $oContent->removeContent( $ConCategory, $ConParent, $ConId ); + } + $oContent->addContent( $ConCategory, $ConParent, $ConId, $ConLang, "" ); + } } #@!neyek - - - /** - * Create Report Tables from an array of data - * - * @param array $aReportTables - * @param array $aReportTablesVars - * @return void - */ - public function createReportTables ($aReportTables, $aReportTablesVars) - { - $this->createReportTablesVars( $aReportTablesVars ); - $oReportTables = new ReportTables(); - foreach ($aReportTables as $sKey => $aRow) { - $bExists = true; - $sTable = $aRow['REP_TAB_NAME']; - $iCounter = 1; - while ($bExists) { - $oCriteria = new Criteria( 'workflow' ); - $oCriteria->add( ReportTablePeer::REP_TAB_NAME, $sTable ); - $oDataset = ReportTablePeer::doSelectRS( $oCriteria ); - $oDataset->setFetchmode( ResultSet::FETCHMODE_ASSOC ); - $oDataset->next(); - $bExists = ($aRow2 = $oDataset->getRow()); - if ($bExists) { - $sTable = $aRow['REP_TAB_NAME'] . '_' . $iCounter; - $iCounter ++; - } else { - $aRow['REP_TAB_NAME'] = $sTable; - } - } - $aFields = $oReportTables->getTableVars( $aRow['REP_TAB_UID'], true ); - $oReportTables->createTable( $aRow['REP_TAB_NAME'], $aRow['REP_TAB_CONNECTION'], $aRow['REP_TAB_TYPE'], $aFields ); - $oReportTables->populateTable( $aRow['REP_TAB_NAME'], $aRow['REP_TAB_CONNECTION'], $aRow['REP_TAB_TYPE'], $aFields, $aRow['PRO_UID'], $aRow['REP_TAB_GRID'] ); - $aReportTables[$sKey]['REP_TAB_NAME'] = $aRow['REP_TAB_NAME']; - $oRep = new ReportTable(); - if ($oRep->reportTableExists( $aRow['REP_TAB_UID'] )) { - $oRep->remove( $aRow['REP_TAB_UID'] ); - } - $oRep->create( $aRow ); - } - } + + + /** + * Create Report Tables from an array of data + * + * @param array $aReportTables + * @param array $aReportTablesVars + * @return void + */ + public function createReportTables ($aReportTables, $aReportTablesVars) + { + $this->createReportTablesVars( $aReportTablesVars ); + $oReportTables = new ReportTables(); + foreach ($aReportTables as $sKey => $aRow) { + $bExists = true; + $sTable = $aRow['REP_TAB_NAME']; + $iCounter = 1; + while ($bExists) { + $oCriteria = new Criteria( 'workflow' ); + $oCriteria->add( ReportTablePeer::REP_TAB_NAME, $sTable ); + $oDataset = ReportTablePeer::doSelectRS( $oCriteria ); + $oDataset->setFetchmode( ResultSet::FETCHMODE_ASSOC ); + $oDataset->next(); + $bExists = ($aRow2 = $oDataset->getRow()); + if ($bExists) { + $sTable = $aRow['REP_TAB_NAME'] . '_' . $iCounter; + $iCounter ++; + } else { + $aRow['REP_TAB_NAME'] = $sTable; + } + } + $aFields = $oReportTables->getTableVars( $aRow['REP_TAB_UID'], true ); + $oReportTables->createTable( $aRow['REP_TAB_NAME'], $aRow['REP_TAB_CONNECTION'], $aRow['REP_TAB_TYPE'], $aFields ); + $oReportTables->populateTable( $aRow['REP_TAB_NAME'], $aRow['REP_TAB_CONNECTION'], $aRow['REP_TAB_TYPE'], $aFields, $aRow['PRO_UID'], $aRow['REP_TAB_GRID'] ); + $aReportTables[$sKey]['REP_TAB_NAME'] = $aRow['REP_TAB_NAME']; + $oRep = new ReportTable(); + if ($oRep->reportTableExists( $aRow['REP_TAB_UID'] )) { + $oRep->remove( $aRow['REP_TAB_UID'] ); + } + $oRep->create( $aRow ); + } + } #@!neyek - - /** - * Update Report Tables from an array of data - * - * @param array $aReportTables - * @param array $aReportTablesVars - * @return void - */ - public function updateReportTables ($aReportTables, $aReportTablesVars) - { - $this->cleanupReportTablesReferences( $aReportTables ); - $this->createReportTables( $aReportTables, $aReportTablesVars ); + + + /** + * Update Report Tables from an array of data + * + * @param array $aReportTables + * @param array $aReportTablesVars + * @return void + */ + public function updateReportTables ($aReportTables, $aReportTablesVars) + { + $this->cleanupReportTablesReferences( $aReportTables ); + $this->createReportTables( $aReportTables, $aReportTablesVars ); } #@!neyek - - - /** - * Create Report Tables Vars from an array of data - * - * @param array $aReportTablesVars - * @return void - */ - public function createReportTablesVars ($aReportTablesVars) - { - foreach ($aReportTablesVars as $sKey => $aRow) { - $oRep = new ReportVar(); - if ($oRep->reportVarExists( $aRow['REP_VAR_UID'] )) { - $oRep->remove( $aRow['REP_VAR_UID'] ); - } - $oRep->create( $aRow ); - } + + + /** + * Create Report Tables Vars from an array of data + * + * @param array $aReportTablesVars + * @return void + */ + public function createReportTablesVars ($aReportTablesVars) + { + foreach ($aReportTablesVars as $sKey => $aRow) { + $oRep = new ReportVar(); + if ($oRep->reportVarExists( $aRow['REP_VAR_UID'] )) { + $oRep->remove( $aRow['REP_VAR_UID'] ); + } + $oRep->create( $aRow ); + } } #@!neyek - - - /** - * Cleanup Report Tables References from an array of data - * - * @param array $aReportTables - * @return void - */ - public function cleanupReportTablesReferences ($aReportTables) - { - foreach ($aReportTables as $sKey => $aRow) { - $oReportTables = new ReportTables(); - $oReportTables->deleteReportTable( $aRow['REP_TAB_UID'] ); - $oReportTables->deleteAllReportVars( $aRow['REP_TAB_UID'] ); - $oReportTables->dropTable( $aRow['REP_TAB_NAME'] ); - } + + + /** + * Cleanup Report Tables References from an array of data + * + * @param array $aReportTables + * @return void + */ + public function cleanupReportTablesReferences ($aReportTables) + { + foreach ($aReportTables as $sKey => $aRow) { + $oReportTables = new ReportTables(); + $oReportTables->deleteReportTable( $aRow['REP_TAB_UID'] ); + $oReportTables->deleteAllReportVars( $aRow['REP_TAB_UID'] ); + $oReportTables->dropTable( $aRow['REP_TAB_NAME'] ); + } } #@!neyek - - - /** - * change Status of any Process - * - * @param string $sProUid - * @return boolean - */ - public function serializeProcess ($sProUid = '') - { - $oProcess = new Process(); - $oData->process = $this->getProcessRow( $sProUid, false ); - $oData->tasks = $this->getTaskRows( $sProUid ); - $oData->routes = $this->getRouteRows( $sProUid ); - $oData->lanes = $this->getLaneRows( $sProUid ); - $oData->gateways = $this->getGatewayRows( $sProUid ); - $oData->inputs = $this->getInputRows( $sProUid ); - $oData->outputs = $this->getOutputRows( $sProUid ); - $oData->dynaforms = $this->getDynaformRows( $sProUid ); - $oData->steps = $this->getStepRows( $sProUid ); - $oData->triggers = $this->getTriggerRows( $sProUid ); - $oData->taskusers = $this->getTaskUserRows( $oData->tasks ); - $oData->groupwfs = $this->getGroupwfRows( $oData->taskusers ); - $oData->steptriggers = $this->getStepTriggerRows( $oData->tasks ); - $oData->dbconnections = $this->getDBConnectionsRows( $sProUid ); - $oData->reportTables = $this->getReportTablesRows( $sProUid ); - $oData->reportTablesVars = $this->getReportTablesVarsRows( $sProUid ); - $oData->stepSupervisor = $this->getStepSupervisorRows( $sProUid ); - $oData->objectPermissions = $this->getObjectPermissionRows( $sProUid ); - $oData->subProcess = $this->getSubProcessRow( $sProUid ); - $oData->caseTracker = $this->getCaseTrackerRow( $sProUid ); - $oData->caseTrackerObject = $this->getCaseTrackerObjectRow( $sProUid ); - $oData->stage = $this->getStageRow( $sProUid ); - $oData->fieldCondition = $this->getFieldCondition( $sProUid ); - $oData->event = $this->getEventRow( $sProUid ); - $oData->caseScheduler = $this->getCaseSchedulerRow( $sProUid ); - $oData->processCategory = $this->getProcessCategoryRow( $sProUid ); - + + + /** + * change Status of any Process + * + * @param string $sProUid + * @return boolean + */ + public function serializeProcess ($sProUid = '') + { + $oProcess = new Process(); + $oData->process = $this->getProcessRow( $sProUid, false ); + $oData->tasks = $this->getTaskRows( $sProUid ); + $oData->routes = $this->getRouteRows( $sProUid ); + $oData->lanes = $this->getLaneRows( $sProUid ); + $oData->gateways = $this->getGatewayRows( $sProUid ); + $oData->inputs = $this->getInputRows( $sProUid ); + $oData->outputs = $this->getOutputRows( $sProUid ); + $oData->dynaforms = $this->getDynaformRows( $sProUid ); + $oData->steps = $this->getStepRows( $sProUid ); + $oData->triggers = $this->getTriggerRows( $sProUid ); + $oData->taskusers = $this->getTaskUserRows( $oData->tasks ); + $oData->groupwfs = $this->getGroupwfRows( $oData->taskusers ); + $oData->steptriggers = $this->getStepTriggerRows( $oData->tasks ); + $oData->dbconnections = $this->getDBConnectionsRows( $sProUid ); + $oData->reportTables = $this->getReportTablesRows( $sProUid ); + $oData->reportTablesVars = $this->getReportTablesVarsRows( $sProUid ); + $oData->stepSupervisor = $this->getStepSupervisorRows( $sProUid ); + $oData->objectPermissions = $this->getObjectPermissionRows( $sProUid ); + $oData->subProcess = $this->getSubProcessRow( $sProUid ); + $oData->caseTracker = $this->getCaseTrackerRow( $sProUid ); + $oData->caseTrackerObject = $this->getCaseTrackerObjectRow( $sProUid ); + $oData->stage = $this->getStageRow( $sProUid ); + $oData->fieldCondition = $this->getFieldCondition( $sProUid ); + $oData->event = $this->getEventRow( $sProUid ); + $oData->caseScheduler = $this->getCaseSchedulerRow( $sProUid ); + $oData->processCategory = $this->getProcessCategoryRow( $sProUid ); + //krumo ($oData);die; //$oJSON = new Services_JSON(); //krumo ( $oJSON->encode($oData) ); //return $oJSON->encode($oData); - return serialize( $oData ); - } - - /** - * Save a Serialized Process from an object - * - * @param array $oData - * @return $result an array - */ - public function saveSerializedProcess ($oData) - { + return serialize( $oData ); + } + + /** + * Save a Serialized Process from an object + * + * @param array $oData + * @return $result an array + */ + public function saveSerializedProcess ($oData) + { //$oJSON = new Services_JSON(); //$data = $oJSON->decode($oData); //$sProUid = $data->process->PRO_UID; - $data = unserialize( $oData ); - $sProUid = $data->process['PRO_UID']; - $path = PATH_DOCUMENT . 'output' . PATH_SEP; - - if (! is_dir( $path )) { - G::verifyPath( $path, true ); - } - - $proTitle = (substr( G::inflect( $data->process['PRO_TITLE'] ), 0, 245 )); - $proTitle = preg_replace( "/[^A-Za-z0-9_]/", "", $proTitle ); + $data = unserialize( $oData ); + $sProUid = $data->process['PRO_UID']; + $path = PATH_DOCUMENT . 'output' . PATH_SEP; + + if (! is_dir( $path )) { + G::verifyPath( $path, true ); + } + + $proTitle = (substr( G::inflect( $data->process['PRO_TITLE'] ), 0, 245 )); + $proTitle = preg_replace( "/[^A-Za-z0-9_]/", "", $proTitle ); //Calculating the maximum length of file name - $pathLength = strlen( PATH_DATA . "sites" . PATH_SEP . SYS_SYS . PATH_SEP . "files" . PATH_SEP . "output" . PATH_SEP ); - $length = strlen( $proTitle ) + $pathLength; - if ($length >= 250) { - $proTitle = myTruncate( $proTitle, 250 - $pathLength, '_', '' ); - } - $index = ''; - - $lastIndex = ''; - - do { - $filename = $path . $proTitle . $index . '.pm'; - $lastIndex = $index; - - if ($index == '') { - $index = 1; - } else { - $index ++; - } - } while (file_exists( $filename )); - - $proTitle .= $lastIndex; - - $filenameOnly = $proTitle . '.pm'; - - $fp = fopen( $filename . 'tpm', "wb" ); - - $fsData = sprintf( "%09d", strlen( $oData ) ); + $pathLength = strlen( PATH_DATA . "sites" . PATH_SEP . SYS_SYS . PATH_SEP . "files" . PATH_SEP . "output" . PATH_SEP ); + $length = strlen( $proTitle ) + $pathLength; + if ($length >= 250) { + $proTitle = myTruncate( $proTitle, 250 - $pathLength, '_', '' ); + } + $index = ''; + + $lastIndex = ''; + + do { + $filename = $path . $proTitle . $index . '.pm'; + $lastIndex = $index; + + if ($index == '') { + $index = 1; + } else { + $index ++; + } + } while (file_exists( $filename )); + + $proTitle .= $lastIndex; + + $filenameOnly = $proTitle . '.pm'; + + $fp = fopen( $filename . 'tpm', "wb" ); + + $fsData = sprintf( "%09d", strlen( $oData ) ); $bytesSaved = fwrite( $fp, $fsData ); //writing the size of $oData $bytesSaved += fwrite( $fp, $oData ); //writing the $oData - - - foreach ($data->dynaforms as $key => $val) { - $sFileName = PATH_DYNAFORM . $val['DYN_FILENAME'] . '.xml'; - if (file_exists( $sFileName )) { - $xmlGuid = $val['DYN_UID']; - $fsXmlGuid = sprintf( "%09d", strlen( $xmlGuid ) ); + + + foreach ($data->dynaforms as $key => $val) { + $sFileName = PATH_DYNAFORM . $val['DYN_FILENAME'] . '.xml'; + if (file_exists( $sFileName )) { + $xmlGuid = $val['DYN_UID']; + $fsXmlGuid = sprintf( "%09d", strlen( $xmlGuid ) ); $bytesSaved += fwrite( $fp, $fsXmlGuid ); //writing the size of xml file $bytesSaved += fwrite( $fp, $xmlGuid ); //writing the xmlfile - - $xmlContent = file_get_contents( $sFileName ); - $fsXmlContent = sprintf( "%09d", strlen( $xmlContent ) ); + + + $xmlContent = file_get_contents( $sFileName ); + $fsXmlContent = sprintf( "%09d", strlen( $xmlContent ) ); $bytesSaved += fwrite( $fp, $fsXmlContent ); //writing the size of xml file $bytesSaved += fwrite( $fp, $xmlContent ); //writing the xmlfile - } - - $sFileName2 = PATH_DYNAFORM . $val['DYN_FILENAME'] . '.html'; - if (file_exists( $sFileName2 )) { - $htmlGuid = $val['DYN_UID']; - $fsHtmlGuid = sprintf( "%09d", strlen( $htmlGuid ) ); + } + + $sFileName2 = PATH_DYNAFORM . $val['DYN_FILENAME'] . '.html'; + if (file_exists( $sFileName2 )) { + $htmlGuid = $val['DYN_UID']; + $fsHtmlGuid = sprintf( "%09d", strlen( $htmlGuid ) ); $bytesSaved += fwrite( $fp, $fsHtmlGuid ); //writing size dynaform id $bytesSaved += fwrite( $fp, $htmlGuid ); //writing dynaform id - - - $htmlContent = file_get_contents( $sFileName2 ); - $fsHtmlContent = sprintf( "%09d", strlen( $htmlContent ) ); + + + $htmlContent = file_get_contents( $sFileName2 ); + $fsHtmlContent = sprintf( "%09d", strlen( $htmlContent ) ); $bytesSaved += fwrite( $fp, $fsHtmlContent ); //writing the size of xml file $bytesSaved += fwrite( $fp, $htmlContent ); //writing the htmlfile - } - } - /** - * By - * here we should work for the new functionalities - * we have a many files for attach into this file - * - * here we go with the anothers files ;) - */ + } + } + /** + * By + * here we should work for the new functionalities + * we have a many files for attach into this file + * + * here we go with the anothers files ;) + */ //before to do something we write a header into pm file for to do a differentiation between document types - - + + //create the store object //$file_objects = new ObjectCellection(); - - + + // for mailtemplates files - $MAILS_ROOT_PATH = PATH_DATA . 'sites' . PATH_SEP . SYS_SYS . PATH_SEP . 'mailTemplates' . PATH_SEP . $data->process['PRO_UID']; - - $isMailTempSent = false; - $isPublicSent = false; + $MAILS_ROOT_PATH = PATH_DATA . 'sites' . PATH_SEP . SYS_SYS . PATH_SEP . 'mailTemplates' . PATH_SEP . $data->process['PRO_UID']; + + $isMailTempSent = false; + $isPublicSent = false; //if this process have any mailfile - if (is_dir( $MAILS_ROOT_PATH )) { - + if (is_dir( $MAILS_ROOT_PATH )) { + //get mail files list from this directory - $file_list = scandir( $MAILS_ROOT_PATH ); - - foreach ($file_list as $filename) { + $file_list = scandir( $MAILS_ROOT_PATH ); + + foreach ($file_list as $filename) { // verify if this filename is a valid file, because it could be . or .. on *nix systems - if ($filename != '.' && $filename != '..') { - if (@is_readable( $MAILS_ROOT_PATH . PATH_SEP . $filename )) { - $sFileName = $MAILS_ROOT_PATH . PATH_SEP . $filename; - if (file_exists( $sFileName )) { - if (! $isMailTempSent) { - $bytesSaved += fwrite( $fp, 'MAILTEMPL' ); - $isMailTempSent = true; - } + if ($filename != '.' && $filename != '..') { + if (@is_readable( $MAILS_ROOT_PATH . PATH_SEP . $filename )) { + $sFileName = $MAILS_ROOT_PATH . PATH_SEP . $filename; + if (file_exists( $sFileName )) { + if (! $isMailTempSent) { + $bytesSaved += fwrite( $fp, 'MAILTEMPL' ); + $isMailTempSent = true; + } //$htmlGuid = $val['DYN_UID']; - $fsFileName = sprintf( "%09d", strlen( $filename ) ); + $fsFileName = sprintf( "%09d", strlen( $filename ) ); $bytesSaved += fwrite( $fp, $fsFileName ); //writing the fileName size $bytesSaved += fwrite( $fp, $filename ); //writing the fileName size - - $fileContent = file_get_contents( $sFileName ); - $fsFileContent = sprintf( "%09d", strlen( $fileContent ) ); + + + $fileContent = file_get_contents( $sFileName ); + $fsFileContent = sprintf( "%09d", strlen( $fileContent ) ); $bytesSaved += fwrite( $fp, $fsFileContent ); //writing the size of xml file $bytesSaved += fwrite( $fp, $fileContent ); //writing the htmlfile - } - } - } - } - } - + } + } + } + } + } + // for public files - $PUBLIC_ROOT_PATH = PATH_DATA . 'sites' . PATH_SEP . SYS_SYS . PATH_SEP . 'public' . PATH_SEP . $data->process['PRO_UID']; - + $PUBLIC_ROOT_PATH = PATH_DATA . 'sites' . PATH_SEP . SYS_SYS . PATH_SEP . 'public' . PATH_SEP . $data->process['PRO_UID']; + //if this process have any mailfile - if (is_dir( $PUBLIC_ROOT_PATH )) { + if (is_dir( $PUBLIC_ROOT_PATH )) { //get mail files list from this directory - $file_list = scandir( $PUBLIC_ROOT_PATH ); - foreach ($file_list as $filename) { + $file_list = scandir( $PUBLIC_ROOT_PATH ); + foreach ($file_list as $filename) { // verify if this filename is a valid file, because it could be . or .. on *nix systems - if ($filename != '.' && $filename != '..') { - if (@is_readable( $PUBLIC_ROOT_PATH . PATH_SEP . $filename )) { - $sFileName = $PUBLIC_ROOT_PATH . PATH_SEP . $filename; - if (file_exists( $sFileName )) { - if (! $isPublicSent) { - $bytesSaved += fwrite( $fp, 'PUBLIC ' ); - $isPublicSent = true; - } + if ($filename != '.' && $filename != '..') { + if (@is_readable( $PUBLIC_ROOT_PATH . PATH_SEP . $filename )) { + $sFileName = $PUBLIC_ROOT_PATH . PATH_SEP . $filename; + if (file_exists( $sFileName )) { + if (! $isPublicSent) { + $bytesSaved += fwrite( $fp, 'PUBLIC ' ); + $isPublicSent = true; + } //$htmlGuid = $val['DYN_UID']; - $fsFileName = sprintf( "%09d", strlen( $filename ) ); - $bytesSaved += fwrite( $fp, $fsFileName ); + $fsFileName = sprintf( "%09d", strlen( $filename ) ); + $bytesSaved += fwrite( $fp, $fsFileName ); //writing the fileName size - $bytesSaved += fwrite( $fp, $filename ); + $bytesSaved += fwrite( $fp, $filename ); //writing the fileName size - $fileContent = file_get_contents( $sFileName ); - $fsFileContent = sprintf( "%09d", strlen( $fileContent ) ); - $bytesSaved += fwrite( $fp, $fsFileContent ); + $fileContent = file_get_contents( $sFileName ); + $fsFileContent = sprintf( "%09d", strlen( $fileContent ) ); + $bytesSaved += fwrite( $fp, $fsFileContent ); //writing the size of xml file - $bytesSaved += fwrite( $fp, $fileContent ); + $bytesSaved += fwrite( $fp, $fileContent ); //writing the htmlfile - } - } - } - } - } - + } + } + } + } + } + /* // for public files $PUBLIC_ROOT_PATH = PATH_DATA.'sites'.PATH_SEP.SYS_SYS.PATH_SEP.'public'.PATH_SEP.$data->process['PRO_UID']; @@ -2775,703 +2779,708 @@ class Processes //So,. we write the store object into pm export file $extended_data = serialize($file_objects); - $bytesSaved += fwrite( $fp, $extended_data ); - */ + $bytesSaved += fwrite( $fp, $extended_data ); + */ /* under here, I've not modified those lines */ - fclose( $fp ); + fclose( $fp ); //$bytesSaved = file_put_contents ( $filename , $oData ); - $filenameLink = 'processes_DownloadFile?p=' . $proTitle . '&r=' . rand( 100, 1000 ); - $result['PRO_UID'] = $data->process['PRO_UID']; - $result['PRO_TITLE'] = $data->process['PRO_TITLE']; - $result['PRO_DESCRIPTION'] = $data->process['PRO_DESCRIPTION']; - $result['SIZE'] = $bytesSaved; - $result['FILENAME'] = $filenameOnly; - $result['FILENAME_LINK'] = $filenameLink; - return $result; - } - - /** - * Get the process Data form a filename - * - * @param array $pmFilename - * @return void - */ - public function getProcessData ($pmFilename) - { - $oProcess = new Process(); - if (! file_exists( $pmFilename )) { - throw (new Exception( 'Unable to read uploaded file, please check permissions. ' )); - } - if (! filesize( $pmFilename ) >= 9) { - throw (new Exception( 'Uploaded file is corrupted, please check the file before continuing. ' )); - } - clearstatcache(); - $fp = fopen( $pmFilename, "rb" ); + $filenameLink = 'processes_DownloadFile?p=' . $proTitle . '&r=' . rand( 100, 1000 ); + $result['PRO_UID'] = $data->process['PRO_UID']; + $result['PRO_TITLE'] = $data->process['PRO_TITLE']; + $result['PRO_DESCRIPTION'] = $data->process['PRO_DESCRIPTION']; + $result['SIZE'] = $bytesSaved; + $result['FILENAME'] = $filenameOnly; + $result['FILENAME_LINK'] = $filenameLink; + return $result; + } + + /** + * Get the process Data form a filename + * + * @param array $pmFilename + * @return void + */ + public function getProcessData ($pmFilename) + { + $oProcess = new Process(); + if (! file_exists( $pmFilename )) { + throw (new Exception( 'Unable to read uploaded file, please check permissions. ' )); + } + if (! filesize( $pmFilename ) >= 9) { + throw (new Exception( 'Uploaded file is corrupted, please check the file before continuing. ' )); + } + clearstatcache(); + $fp = fopen( $pmFilename, "rb" ); $fsData = intval( fread( $fp, 9 ) ); //reading the size of $oData - $contents = ''; + $contents = ''; $contents = @fread( $fp, $fsData ); //reading string $oData - - if ($contents != '') { - $oData = unserialize( $contents ); - if ($oData === false) { - throw new Exception( "Process file is not valid" ); - } - foreach ($oData->dynaforms as $key => $value) { - if ($value['DYN_TYPE'] == 'grid') { - $oData->gridFiles[$value['DYN_UID']] = $value['DYN_UID']; - } - } - - $oData->dynaformFiles = array (); - $sIdentifier = 0; - while (! feof( $fp ) && is_numeric( $sIdentifier )) { - $sIdentifier = fread( $fp, 9 );//reading the block identifier - if (is_numeric( $sIdentifier )) { + + + if ($contents != '') { + $oData = unserialize( $contents ); + if ($oData === false) { + throw new Exception( "Process file is not valid" ); + } + foreach ($oData->dynaforms as $key => $value) { + if ($value['DYN_TYPE'] == 'grid') { + $oData->gridFiles[$value['DYN_UID']] = $value['DYN_UID']; + } + } + + $oData->dynaformFiles = array (); + $sIdentifier = 0; + while (! feof( $fp ) && is_numeric( $sIdentifier )) { + $sIdentifier = fread( $fp, 9 ); //reading the block identifier + if (is_numeric( $sIdentifier )) { $fsXmlGuid = intval( $sIdentifier ); //reading the size of $filename - if ($fsXmlGuid > 0) { + if ($fsXmlGuid > 0) { $XmlGuid = fread( $fp, $fsXmlGuid ); //reading string $XmlGuid - } - + } + $fsXmlContent = intval( fread( $fp, 9 ) ); //reading the size of $XmlContent - if ($fsXmlContent > 0) { - $oData->dynaformFiles[$XmlGuid] = $XmlGuid; + if ($fsXmlContent > 0) { + $oData->dynaformFiles[$XmlGuid] = $XmlGuid; $XmlContent = fread( $fp, $fsXmlContent ); //reading string $XmlContent - unset( $XmlContent ); - } - } - } - } else { - $oData = null; - } - fclose( $fp ); - return $oData; - } - + unset( $XmlContent ); + } + } + } + } else { + $oData = null; + } + fclose( $fp ); + return $oData; + } + // import process related functions - - - /** - * function checkExistingGroups - * checkExistingGroups check if any of the groups listed in the parameter - * array exist and wich are those, that is the result $sFilteredGroups array. - * - * @author gustavo cruz gustavo-at-colosa.com - * @param $sGroupList array of a group list - * @return $existingGroupList array of existing groups or null - */ - public function checkExistingGroups ($sGroupList) - { - $aGroupwf = array (); - $oCriteria = new Criteria( 'workflow' ); - $oCriteria->addSelectColumn( GroupwfPeer::GRP_UID ); - $oCriteria->addSelectColumn( ContentPeer::CON_ID ); - $oCriteria->addSelectColumn( ContentPeer::CON_VALUE ); - $oCriteria->add( ContentPeer::CON_CATEGORY, 'GRP_TITLE' ); - $oCriteria->add( ContentPeer::CON_LANG, 'en' ); - $oCriteria->addJoin( ContentPeer::CON_ID, GroupwfPeer::GRP_UID ); - $oDataset = ContentPeer::doSelectRS( $oCriteria ); - $oDataset->setFetchmode( ResultSet::FETCHMODE_ASSOC ); - $oDataset->next(); - while ($aRow = $oDataset->getRow()) { - $aGroupwf[] = $aRow; - $oDataset->next(); - } + + + /** + * function checkExistingGroups + * checkExistingGroups check if any of the groups listed in the parameter + * array exist and wich are those, that is the result $sFilteredGroups array. + * + * @author gustavo cruz gustavo-at-colosa.com + * @param $sGroupList array of a group list + * @return $existingGroupList array of existing groups or null + */ + public function checkExistingGroups ($sGroupList) + { + $aGroupwf = array (); + $oCriteria = new Criteria( 'workflow' ); + $oCriteria->addSelectColumn( GroupwfPeer::GRP_UID ); + $oCriteria->addSelectColumn( ContentPeer::CON_ID ); + $oCriteria->addSelectColumn( ContentPeer::CON_VALUE ); + $oCriteria->add( ContentPeer::CON_CATEGORY, 'GRP_TITLE' ); + $oCriteria->add( ContentPeer::CON_LANG, 'en' ); + $oCriteria->addJoin( ContentPeer::CON_ID, GroupwfPeer::GRP_UID ); + $oDataset = ContentPeer::doSelectRS( $oCriteria ); + $oDataset->setFetchmode( ResultSet::FETCHMODE_ASSOC ); + $oDataset->next(); + while ($aRow = $oDataset->getRow()) { + $aGroupwf[] = $aRow; + $oDataset->next(); + } //check if any group name exists in the dbase - if (is_array( $sGroupList )) { - foreach ($aGroupwf as $groupBase) { - foreach ($sGroupList as $group) { - if ($groupBase['CON_VALUE'] == $group['GRP_TITLE'] && $groupBase['CON_ID'] != $group['GRP_UID']) { - $existingGroupList[] = $group; - } - } - } - } + if (is_array( $sGroupList )) { + foreach ($aGroupwf as $groupBase) { + foreach ($sGroupList as $group) { + if ($groupBase['CON_VALUE'] == $group['GRP_TITLE'] && $groupBase['CON_ID'] != $group['GRP_UID']) { + $existingGroupList[] = $group; + } + } + } + } //return $sGroupList; - if (isset( $existingGroupList )) { - return $existingGroupList; - } else { - return null; - } - } - - /** - * function renameExistingGroups - * renameExistingGroups check if any of the groups listed in the parameter - * array exist and wich are those, then rename the file adding a number - * suffix to the title atribute of each element of the $renamedGroupList array. - * - * @author gustavo cruz gustavo-at-colosa.com - * @param $sGroupList array of a group list - * @return $renamedGroupList array of existing groups - */ - - public function renameExistingGroups ($sGroupList) - { - $checkedGroup = $this->checkExistingGroups( $sGroupList ); - foreach ($sGroupList as $groupBase) { - foreach ($checkedGroup as $group) { - if ($groupBase['GRP_TITLE'] == $group['GRP_TITLE']) { - $index = substr( $groupBase['GRP_TITLE'], - 1, 0 ); - if (is_int( $index )) { - $index ++; - } else { - $index = 1; - } - $groupBase['GRP_TITLE'] = $groupBase['GRP_TITLE'] . $index; - } - - } - $renamedGroupList[] = $groupBase; - } - - if (isset( $renamedGroupList )) { - return $renamedGroupList; - } else { - return null; - } - } - - /** - * function mergeExistingGroups - * mergeExistingGroups check if any of the groups listed in the parameter - * array exist and wich are those, then replaces the id of the elements in - * in the $mergedGroupList array. - * - * @author gustavo cruz gustavo-at-colosa.com - * @param $sGroupList array of a group list - * @return $mergedGroupList array of existing groups - */ - public function mergeExistingGroups ($sGroupList) - { - $oCriteria = new Criteria( 'workflow' ); - $oCriteria->addSelectColumn( GroupwfPeer::GRP_UID ); - $oCriteria->addSelectColumn( ContentPeer::CON_ID ); - $oCriteria->addSelectColumn( ContentPeer::CON_VALUE ); - $oCriteria->add( ContentPeer::CON_CATEGORY, 'GRP_TITLE' ); - $oCriteria->add( ContentPeer::CON_LANG, 'en' ); - $oCriteria->addJoin( ContentPeer::CON_ID, GroupwfPeer::GRP_UID ); - $oDataset = ContentPeer::doSelectRS( $oCriteria ); - $oDataset->setFetchmode( ResultSet::FETCHMODE_ASSOC ); - $oDataset->next(); - while ($aRow = $oDataset->getRow()) { - $aGroupwf[] = $aRow; - $oDataset->next(); - } + if (isset( $existingGroupList )) { + return $existingGroupList; + } else { + return null; + } + } + + /** + * function renameExistingGroups + * renameExistingGroups check if any of the groups listed in the parameter + * array exist and wich are those, then rename the file adding a number + * suffix to the title atribute of each element of the $renamedGroupList array. + * + * @author gustavo cruz gustavo-at-colosa.com + * @param $sGroupList array of a group list + * @return $renamedGroupList array of existing groups + */ + + public function renameExistingGroups ($sGroupList) + { + $checkedGroup = $this->checkExistingGroups( $sGroupList ); + foreach ($sGroupList as $groupBase) { + foreach ($checkedGroup as $group) { + if ($groupBase['GRP_TITLE'] == $group['GRP_TITLE']) { + $index = substr( $groupBase['GRP_TITLE'], - 1, 0 ); + if (is_int( $index )) { + $index ++; + } else { + $index = 1; + } + $groupBase['GRP_TITLE'] = $groupBase['GRP_TITLE'] . $index; + } + + } + $renamedGroupList[] = $groupBase; + } + + if (isset( $renamedGroupList )) { + return $renamedGroupList; + } else { + return null; + } + } + + /** + * function mergeExistingGroups + * mergeExistingGroups check if any of the groups listed in the parameter + * array exist and wich are those, then replaces the id of the elements in + * in the $mergedGroupList array. + * + * @author gustavo cruz gustavo-at-colosa.com + * @param $sGroupList array of a group list + * @return $mergedGroupList array of existing groups + */ + public function mergeExistingGroups ($sGroupList) + { + $oCriteria = new Criteria( 'workflow' ); + $oCriteria->addSelectColumn( GroupwfPeer::GRP_UID ); + $oCriteria->addSelectColumn( ContentPeer::CON_ID ); + $oCriteria->addSelectColumn( ContentPeer::CON_VALUE ); + $oCriteria->add( ContentPeer::CON_CATEGORY, 'GRP_TITLE' ); + $oCriteria->add( ContentPeer::CON_LANG, 'en' ); + $oCriteria->addJoin( ContentPeer::CON_ID, GroupwfPeer::GRP_UID ); + $oDataset = ContentPeer::doSelectRS( $oCriteria ); + $oDataset->setFetchmode( ResultSet::FETCHMODE_ASSOC ); + $oDataset->next(); + while ($aRow = $oDataset->getRow()) { + $aGroupwf[] = $aRow; + $oDataset->next(); + } //check if any group name exists in the dbase - foreach ($sGroupList as $group) { - $merged = false; - foreach ($aGroupwf as $groupBase) { - if ($groupBase['CON_VALUE'] == $group['GRP_TITLE'] && $groupBase['CON_ID'] != $group['GRP_UID']) { - $group['GRP_UID'] = $groupBase['CON_ID']; - $mergedGroupList[] = $group; - $merged = true; - } - } - - if (! $merged) { - $mergedGroupList[] = $group; - } - } - - if (isset( $mergedGroupList )) { - return $mergedGroupList; - } else { - return null; - } - } - - /** - * function mergeExistingUsers - * mergeExistingGroups check if any of the groups listed in the parameter - * array exist and wich are those, then replaces the id of the elements in - * in the $mergedGroupList array. - * - * @author gustavo cruz gustavo-at-colosa.com - * @param $sBaseGroupList array of a group list with the original group list - * @param $sGroupList array of a group list with the merged group list - * @param $sTaskUserList array of the task user list, it contents the link between - * the task and the group list - * @return $mergedTaskUserList array of the merged task user list - */ - public function mergeExistingUsers ($sBaseGroupList, $sGroupList, $sTaskUserList) - { - foreach ($sTaskUserList as $taskuser) { - $merged = false; - foreach ($sBaseGroupList as $groupBase) { - foreach ($sGroupList as $group) { + foreach ($sGroupList as $group) { + $merged = false; + foreach ($aGroupwf as $groupBase) { + if ($groupBase['CON_VALUE'] == $group['GRP_TITLE'] && $groupBase['CON_ID'] != $group['GRP_UID']) { + $group['GRP_UID'] = $groupBase['CON_ID']; + $mergedGroupList[] = $group; + $merged = true; + } + } + + if (! $merged) { + $mergedGroupList[] = $group; + } + } + + if (isset( $mergedGroupList )) { + return $mergedGroupList; + } else { + return null; + } + } + + /** + * function mergeExistingUsers + * mergeExistingGroups check if any of the groups listed in the parameter + * array exist and wich are those, then replaces the id of the elements in + * in the $mergedGroupList array. + * + * @author gustavo cruz gustavo-at-colosa.com + * @param $sBaseGroupList array of a group list with the original group list + * @param $sGroupList array of a group list with the merged group list + * @param $sTaskUserList array of the task user list, it contents the link between + * the task and the group list + * @return $mergedTaskUserList array of the merged task user list + */ + public function mergeExistingUsers ($sBaseGroupList, $sGroupList, $sTaskUserList) + { + foreach ($sTaskUserList as $taskuser) { + $merged = false; + foreach ($sBaseGroupList as $groupBase) { + foreach ($sGroupList as $group) { // check if the group has been merged - if ($groupBase['GRP_TITLE'] == $group['GRP_TITLE'] && $groupBase['GRP_UID'] != $group['GRP_UID'] && $groupBase['GRP_UID'] == $taskuser['USR_UID']) { + if ($groupBase['GRP_TITLE'] == $group['GRP_TITLE'] && $groupBase['GRP_UID'] != $group['GRP_UID'] && $groupBase['GRP_UID'] == $taskuser['USR_UID']) { // merging the user id to match the merged group - $taskuser['USR_UID'] = $group['GRP_UID']; - $mergedTaskUserList[] = $taskuser; - $merged = true; - } - } - } + $taskuser['USR_UID'] = $group['GRP_UID']; + $mergedTaskUserList[] = $taskuser; + $merged = true; + } + } + } //if hasn't been merged set the default value - if (! $merged) { - $mergedTaskUserList[] = $taskuser; - } - } - if (isset( $mergedTaskUserList )) { - return $mergedTaskUserList; - } else { - return null; - } - } - + if (! $merged) { + $mergedTaskUserList[] = $taskuser; + } + } + if (isset( $mergedTaskUserList )) { + return $mergedTaskUserList; + } else { + return null; + } + } + // end of import process related functions - - - /** - * disable all previous process with the parent $sProUid - * - * @param $sProUid process uid - * @return void - */ - public function disablePreviousProcesses ($sProUid) - { + + + /** + * disable all previous process with the parent $sProUid + * + * @param $sProUid process uid + * @return void + */ + public function disablePreviousProcesses ($sProUid) + { //change status of process - $oCriteria = new Criteria( 'workflow' ); - $oCriteria->add( ProcessPeer::PRO_PARENT, $sProUid ); - $oDataset = ProcessPeer::doSelectRS( $oCriteria ); - $oDataset->setFetchmode( ResultSet::FETCHMODE_ASSOC ); - $oDataset->next(); - $oProcess = new Process(); - while ($aRow = $oDataset->getRow()) { - $aRow['PRO_STATUS'] = 'DISABLED'; - $aRow['PRO_UPDATE_DATE'] = 'now'; - $oProcess->update( $aRow ); - $oDataset->next(); - } - } - - /** - * create the files from a . - * - * pm file - * - * @param $oData process data - * @param $pmFilename process file name - * @return boolean true - */ - public function createFiles ($oData, $pmFilename) - { - if (! file_exists( $pmFilename )) { - throw (new Exception( 'Unable to read uploaded .pm file, please check permissions. ' )); - } - if (! filesize( $pmFilename ) >= 9) { - throw (new Exception( 'Uploaded .pm file is corrupted, please check the file before continue. ' )); - } - $fp = fopen( $pmFilename, "rb" ); + $oCriteria = new Criteria( 'workflow' ); + $oCriteria->add( ProcessPeer::PRO_PARENT, $sProUid ); + $oDataset = ProcessPeer::doSelectRS( $oCriteria ); + $oDataset->setFetchmode( ResultSet::FETCHMODE_ASSOC ); + $oDataset->next(); + $oProcess = new Process(); + while ($aRow = $oDataset->getRow()) { + $aRow['PRO_STATUS'] = 'DISABLED'; + $aRow['PRO_UPDATE_DATE'] = 'now'; + $oProcess->update( $aRow ); + $oDataset->next(); + } + } + + /** + * create the files from a . + * + * + * pm file + * + * @param $oData process data + * @param $pmFilename process file name + * @return boolean true + */ + public function createFiles ($oData, $pmFilename) + { + if (! file_exists( $pmFilename )) { + throw (new Exception( 'Unable to read uploaded .pm file, please check permissions. ' )); + } + if (! filesize( $pmFilename ) >= 9) { + throw (new Exception( 'Uploaded .pm file is corrupted, please check the file before continue. ' )); + } + $fp = fopen( $pmFilename, "rb" ); $fsData = intval( fread( $fp, 9 ) ); //reading the size of $oData $contents = fread( $fp, $fsData ); //reading string $oData - - $path = PATH_DYNAFORM . $oData->process['PRO_UID'] . PATH_SEP; - if (! is_dir( $path )) { - G::verifyPath( $path, true ); - } - - $sIdentifier = 1; - while (! feof( $fp ) && is_numeric( $sIdentifier )) { + + + $path = PATH_DYNAFORM . $oData->process['PRO_UID'] . PATH_SEP; + if (! is_dir( $path )) { + G::verifyPath( $path, true ); + } + + $sIdentifier = 1; + while (! feof( $fp ) && is_numeric( $sIdentifier )) { $sIdentifier = fread( $fp, 9 ); //reading the size of $filename - if (is_numeric( $sIdentifier )) { + if (is_numeric( $sIdentifier )) { $fsXmlGuid = intval( $sIdentifier ); //reading the size of $filename - if ($fsXmlGuid > 0) + if ($fsXmlGuid > 0) { $XmlGuid = fread( $fp, $fsXmlGuid ); //reading string $XmlGuid + } $fsXmlContent = intval( fread( $fp, 9 ) ); //reading the size of $XmlContent - if ($fsXmlContent > 0) { - $newXmlGuid = $oData->dynaformFiles[$XmlGuid]; - if (isset( $oData->process['PRO_UID_OLD'] )) { + if ($fsXmlContent > 0) { + $newXmlGuid = $oData->dynaformFiles[$XmlGuid]; + if (isset( $oData->process['PRO_UID_OLD'] )) { $XmlContent = fread( $fp, $fsXmlContent ); //reading string $XmlContent - $XmlContent = str_replace( $oData->process['PRO_UID_OLD'], $oData->process['PRO_UID'], $XmlContent ); - $XmlContent = str_replace( $XmlGuid, $newXmlGuid, $XmlContent ); - + $XmlContent = str_replace( $oData->process['PRO_UID_OLD'], $oData->process['PRO_UID'], $XmlContent ); + $XmlContent = str_replace( $XmlGuid, $newXmlGuid, $XmlContent ); + //foreach - if (isset( $oData->gridFiles )) { - if (is_array( $oData->gridFiles )) { - foreach ($oData->gridFiles as $key => $value) { - $XmlContent = str_replace( $key, $value, $XmlContent ); - } - } - } - - if (isset( $oData->sqlConnections )) { - foreach ($oData->sqlConnections as $key => $value) { - $XmlContent = str_replace( $key, $value, $XmlContent ); - } - - } - + if (isset( $oData->gridFiles )) { + if (is_array( $oData->gridFiles )) { + foreach ($oData->gridFiles as $key => $value) { + $XmlContent = str_replace( $key, $value, $XmlContent ); + } + } + } + + if (isset( $oData->sqlConnections )) { + foreach ($oData->sqlConnections as $key => $value) { + $XmlContent = str_replace( $key, $value, $XmlContent ); + } + + } + #here we verify if is adynaform or a html - $aAux = explode( ' ', $XmlContent ); - $ext = (strpos( $aAux[0], 'process['PRO_UID'] . PATH_SEP; - $pathMailTem = PATH_DATA_SITE . 'mailTemplates' . PATH_SEP . $oData->process['PRO_UID'] . PATH_SEP; - G::mk_dir( $pathPublic ); - G::mk_dir( $pathMailTem ); - - if ($sIdentifier == 'MAILTEMPL') { - $sIdentifier = 1; - while (! feof( $fp ) && is_numeric( $sIdentifier )) { + $pathPublic = PATH_DATA_SITE . 'public' . PATH_SEP . $oData->process['PRO_UID'] . PATH_SEP; + $pathMailTem = PATH_DATA_SITE . 'mailTemplates' . PATH_SEP . $oData->process['PRO_UID'] . PATH_SEP; + G::mk_dir( $pathPublic ); + G::mk_dir( $pathMailTem ); + + if ($sIdentifier == 'MAILTEMPL') { + $sIdentifier = 1; + while (! feof( $fp ) && is_numeric( $sIdentifier )) { $sIdentifier = fread( $fp, 9 ); //reading the size of $filename - if (is_numeric( $sIdentifier )) { + if (is_numeric( $sIdentifier )) { $fsFileName = intval( $sIdentifier ); //reading the size of $filename - if ($fsFileName > 0) { + if ($fsFileName > 0) { $sFileName = fread( $fp, $fsFileName ); //reading filename string - } + } $fsContent = function_exists( 'mb_strlen' ) ? mb_strlen( fread( $fp, 9 ) ) : strlen( fread( $fp, 9 ) ); //reading the size of $Content - if ($fsContent > 0) { + if ($fsContent > 0) { $fileContent = fread( $fp, $fsContent ); //reading string $XmlContent - $newFileName = $pathMailTem . $sFileName; - $bytesSaved = @file_put_contents( $newFileName, $fileContent ); - if ($bytesSaved != $fsContent) { - throw (new Exception( 'Error writing MailTemplate file in directory : ' . $pathMailTem )); - } - } - } - } - } - - if (trim( $sIdentifier ) == 'PUBLIC') { - $sIdentifier = 1; - while (! feof( $fp ) && is_numeric( $sIdentifier )) { + $newFileName = $pathMailTem . $sFileName; + $bytesSaved = @file_put_contents( $newFileName, $fileContent ); + if ($bytesSaved != $fsContent) { + throw (new Exception( 'Error writing MailTemplate file in directory : ' . $pathMailTem )); + } + } + } + } + } + + if (trim( $sIdentifier ) == 'PUBLIC') { + $sIdentifier = 1; + while (! feof( $fp ) && is_numeric( $sIdentifier )) { $sIdentifier = fread( $fp, 9 ); //reading the size of $filename - if (is_numeric( $sIdentifier )) { + if (is_numeric( $sIdentifier )) { $fsFileName = intval( $sIdentifier ); //reading the size of $filename - if ($fsFileName > 0) { + if ($fsFileName > 0) { $sFileName = fread( $fp, $fsFileName ); //reading filename string - } + } $fsContent = function_exists( 'mb_strlen' ) ? mb_strlen( fread( $fp, 9 ) ) : strlen( fread( $fp, 9 ) ); //reading the size of $Content - if ($fsContent > 0) { + if ($fsContent > 0) { $fileContent = fread( $fp, $fsContent ); //reading string $XmlContent - $newFileName = $pathPublic . $sFileName; - $bytesSaved = @file_put_contents( $newFileName, $fileContent ); - if ($bytesSaved != $fsContent) { - throw (new Exception( 'Error writing Public file in directory : ' . $pathPublic )); - } - } - } - } - } - - fclose( $fp ); - - return true; - - } - - /** - * this function remove all Process except the PROCESS ROW - * - * @param string $sProUid - * @return boolean - */ - public function removeProcessRows ($sProUid) - { - try { + $newFileName = $pathPublic . $sFileName; + $bytesSaved = @file_put_contents( $newFileName, $fileContent ); + if ($bytesSaved != $fsContent) { + throw (new Exception( 'Error writing Public file in directory : ' . $pathPublic )); + } + } + } + } + } + + fclose( $fp ); + + return true; + + } + + /** + * this function remove all Process except the PROCESS ROW + * + * @param string $sProUid + * @return boolean + */ + public function removeProcessRows ($sProUid) + { + try { //Instance all classes necesaries - $oProcess = new Process(); - $oDynaform = new Dynaform(); - $oInputDocument = new InputDocument(); - $oOutputDocument = new OutputDocument(); - $oTrigger = new Triggers(); - $oStepTrigger = new StepTrigger(); - $oRoute = new Route(); - $oStep = new Step(); - $oSubProcess = new SubProcess(); - $oCaseTracker = new CaseTracker(); - $oCaseTrackerObject = new CaseTrackerObject(); - $oObjectPermission = new ObjectPermission(); - $oSwimlaneElement = new SwimlanesElements(); - $oConnection = new DbSource(); - $oStage = new Stage(); - $oEvent = new Event(); - $oCaseScheduler = new CaseScheduler(); - + $oProcess = new Process(); + $oDynaform = new Dynaform(); + $oInputDocument = new InputDocument(); + $oOutputDocument = new OutputDocument(); + $oTrigger = new Triggers(); + $oStepTrigger = new StepTrigger(); + $oRoute = new Route(); + $oStep = new Step(); + $oSubProcess = new SubProcess(); + $oCaseTracker = new CaseTracker(); + $oCaseTrackerObject = new CaseTrackerObject(); + $oObjectPermission = new ObjectPermission(); + $oSwimlaneElement = new SwimlanesElements(); + $oConnection = new DbSource(); + $oStage = new Stage(); + $oEvent = new Event(); + $oCaseScheduler = new CaseScheduler(); + //Delete the tasks of process - $oCriteria = new Criteria( 'workflow' ); - $oCriteria->add( TaskPeer::PRO_UID, $sProUid ); - $oDataset = TaskPeer::doSelectRS( $oCriteria ); - $oDataset->setFetchmode( ResultSet::FETCHMODE_ASSOC ); - $oDataset->next(); - $oTask = new Task(); - while ($aRow = $oDataset->getRow()) { - $oCriteria = new Criteria( 'workflow' ); - $oCriteria->add( StepTriggerPeer::TAS_UID, $aRow['TAS_UID'] ); - StepTriggerPeer::doDelete( $oCriteria ); - if ($oTask->taskExists( $aRow['TAS_UID'] )) { - $oTask->remove( $aRow['TAS_UID'] ); - } - $oDataset->next(); - } - + $oCriteria = new Criteria( 'workflow' ); + $oCriteria->add( TaskPeer::PRO_UID, $sProUid ); + $oDataset = TaskPeer::doSelectRS( $oCriteria ); + $oDataset->setFetchmode( ResultSet::FETCHMODE_ASSOC ); + $oDataset->next(); + $oTask = new Task(); + while ($aRow = $oDataset->getRow()) { + $oCriteria = new Criteria( 'workflow' ); + $oCriteria->add( StepTriggerPeer::TAS_UID, $aRow['TAS_UID'] ); + StepTriggerPeer::doDelete( $oCriteria ); + if ($oTask->taskExists( $aRow['TAS_UID'] )) { + $oTask->remove( $aRow['TAS_UID'] ); + } + $oDataset->next(); + } + //Delete the dynaforms of process - $oCriteria = new Criteria( 'workflow' ); - $oCriteria->add( DynaformPeer::PRO_UID, $sProUid ); - $oDataset = DynaformPeer::doSelectRS( $oCriteria ); - $oDataset->setFetchmode( ResultSet::FETCHMODE_ASSOC ); - $oDataset->next(); - while ($aRow = $oDataset->getRow()) { - $sWildcard = PATH_DYNAFORM . $aRow['PRO_UID'] . PATH_SEP . $aRow['DYN_UID'] . '_tmp*'; - foreach (glob( $sWildcard ) as $fn) { - @unlink( $fn ); - } - $sWildcard = PATH_DYNAFORM . $aRow['PRO_UID'] . PATH_SEP . $aRow['DYN_UID'] . '.*'; - foreach (glob( $sWildcard ) as $fn) { - @unlink( $fn ); - } - if ($oDynaform->dynaformExists( $aRow['DYN_UID'] )) { - $oDynaform->remove( $aRow['DYN_UID'] ); - } - $oDataset->next(); - } - + $oCriteria = new Criteria( 'workflow' ); + $oCriteria->add( DynaformPeer::PRO_UID, $sProUid ); + $oDataset = DynaformPeer::doSelectRS( $oCriteria ); + $oDataset->setFetchmode( ResultSet::FETCHMODE_ASSOC ); + $oDataset->next(); + while ($aRow = $oDataset->getRow()) { + $sWildcard = PATH_DYNAFORM . $aRow['PRO_UID'] . PATH_SEP . $aRow['DYN_UID'] . '_tmp*'; + foreach (glob( $sWildcard ) as $fn) { + @unlink( $fn ); + } + $sWildcard = PATH_DYNAFORM . $aRow['PRO_UID'] . PATH_SEP . $aRow['DYN_UID'] . '.*'; + foreach (glob( $sWildcard ) as $fn) { + @unlink( $fn ); + } + if ($oDynaform->dynaformExists( $aRow['DYN_UID'] )) { + $oDynaform->remove( $aRow['DYN_UID'] ); + } + $oDataset->next(); + } + //Delete the input documents of process - $oCriteria = new Criteria( 'workflow' ); - $oCriteria->add( InputDocumentPeer::PRO_UID, $sProUid ); - $oDataset = InputDocumentPeer::doSelectRS( $oCriteria ); - $oDataset->setFetchmode( ResultSet::FETCHMODE_ASSOC ); - $oDataset->next(); - while ($aRow = $oDataset->getRow()) { - if ($oInputDocument->InputExists( $aRow['INP_DOC_UID'] )) { - $oInputDocument->remove( $aRow['INP_DOC_UID'] ); - } - $oDataset->next(); - } - + $oCriteria = new Criteria( 'workflow' ); + $oCriteria->add( InputDocumentPeer::PRO_UID, $sProUid ); + $oDataset = InputDocumentPeer::doSelectRS( $oCriteria ); + $oDataset->setFetchmode( ResultSet::FETCHMODE_ASSOC ); + $oDataset->next(); + while ($aRow = $oDataset->getRow()) { + if ($oInputDocument->InputExists( $aRow['INP_DOC_UID'] )) { + $oInputDocument->remove( $aRow['INP_DOC_UID'] ); + } + $oDataset->next(); + } + //Delete the output documents of process - $oCriteria = new Criteria( 'workflow' ); - $oCriteria->add( OutputDocumentPeer::PRO_UID, $sProUid ); - $oDataset = OutputDocumentPeer::doSelectRS( $oCriteria ); - $oDataset->setFetchmode( ResultSet::FETCHMODE_ASSOC ); - $oDataset->next(); - while ($aRow = $oDataset->getRow()) { - if ($oOutputDocument->OutputExists( $aRow['OUT_DOC_UID'] )) { - $oOutputDocument->remove( $aRow['OUT_DOC_UID'] ); - } - $oDataset->next(); - } - + $oCriteria = new Criteria( 'workflow' ); + $oCriteria->add( OutputDocumentPeer::PRO_UID, $sProUid ); + $oDataset = OutputDocumentPeer::doSelectRS( $oCriteria ); + $oDataset->setFetchmode( ResultSet::FETCHMODE_ASSOC ); + $oDataset->next(); + while ($aRow = $oDataset->getRow()) { + if ($oOutputDocument->OutputExists( $aRow['OUT_DOC_UID'] )) { + $oOutputDocument->remove( $aRow['OUT_DOC_UID'] ); + } + $oDataset->next(); + } + //Delete the steps - $oCriteria = new Criteria( 'workflow' ); - $oCriteria->add( StepPeer::PRO_UID, $sProUid ); - $oDataset = StepPeer::doSelectRS( $oCriteria ); - $oDataset->setFetchmode( ResultSet::FETCHMODE_ASSOC ); - $oDataset->next(); - while ($aRow = $oDataset->getRow()) { - //Delete the steptrigger of process - /*$oCriteria = new Criteria('workflow'); - $oCriteria->add(StepTriggerPeer::STEP_UID, $aRow['STEP_UID']); - $oDataseti = StepTriggerPeer::doSelectRS($oCriteria); - $oDataseti->setFetchmode(ResultSet::FETCHMODE_ASSOC); - $oDataseti->next(); - while ($aRowi = $oDataseti->getRow()) { - if ($oStepTrigger->stepTriggerExists($aRowi['STEP_UID'], $aRowi['TAS_UID'], $aRowi['TRI_UID'], $aRowi['ST_TYPE'])) - $oStepTrigger->remove($aRowi['STEP_UID'], $aRowi['TAS_UID'], $aRowi['TRI_UID'], $aRowi['ST_TYPE']); - $oDataseti->next(); - }*/ - $oStep->remove( $aRow['STEP_UID'] ); - $oDataset->next(); - } - + $oCriteria = new Criteria( 'workflow' ); + $oCriteria->add( StepPeer::PRO_UID, $sProUid ); + $oDataset = StepPeer::doSelectRS( $oCriteria ); + $oDataset->setFetchmode( ResultSet::FETCHMODE_ASSOC ); + $oDataset->next(); + while ($aRow = $oDataset->getRow()) { + //Delete the steptrigger of process + /*$oCriteria = new Criteria('workflow'); + $oCriteria->add(StepTriggerPeer::STEP_UID, $aRow['STEP_UID']); + $oDataseti = StepTriggerPeer::doSelectRS($oCriteria); + $oDataseti->setFetchmode(ResultSet::FETCHMODE_ASSOC); + $oDataseti->next(); + while ($aRowi = $oDataseti->getRow()) { + if ($oStepTrigger->stepTriggerExists($aRowi['STEP_UID'], $aRowi['TAS_UID'], $aRowi['TRI_UID'], $aRowi['ST_TYPE'])) + $oStepTrigger->remove($aRowi['STEP_UID'], $aRowi['TAS_UID'], $aRowi['TRI_UID'], $aRowi['ST_TYPE']); + $oDataseti->next(); + }*/ + $oStep->remove( $aRow['STEP_UID'] ); + $oDataset->next(); + } + //Delete the StepSupervisor - $oCriteria = new Criteria( 'workflow' ); - $oCriteria->add( StepSupervisorPeer::PRO_UID, $sProUid ); - $oDataset = StepSupervisorPeer::doSelectRS( $oCriteria ); - $oDataset->setFetchmode( ResultSet::FETCHMODE_ASSOC ); - $oDataset->next(); - while ($aRow = $oDataset->getRow()) { - if ($oStep->StepExists( $aRow['STEP_UID'] )) { - $oStep->remove( $aRow['STEP_UID'] ); - } - $oDataset->next(); - } - + $oCriteria = new Criteria( 'workflow' ); + $oCriteria->add( StepSupervisorPeer::PRO_UID, $sProUid ); + $oDataset = StepSupervisorPeer::doSelectRS( $oCriteria ); + $oDataset->setFetchmode( ResultSet::FETCHMODE_ASSOC ); + $oDataset->next(); + while ($aRow = $oDataset->getRow()) { + if ($oStep->StepExists( $aRow['STEP_UID'] )) { + $oStep->remove( $aRow['STEP_UID'] ); + } + $oDataset->next(); + } + //Delete the triggers of process - $oCriteria = new Criteria( 'workflow' ); - $oCriteria->add( TriggersPeer::PRO_UID, $sProUid ); - $oDataset = TriggersPeer::doSelectRS( $oCriteria ); - $oDataset->setFetchmode( ResultSet::FETCHMODE_ASSOC ); - $oDataset->next(); - while ($aRow = $oDataset->getRow()) { - if ($oTrigger->TriggerExists( $aRow['TRI_UID'] )) { - $oTrigger->remove( $aRow['TRI_UID'] ); - } - $oDataset->next(); - } - //Delete the routes of process - $oCriteria = new Criteria( 'workflow' ); - $oCriteria->add( RoutePeer::PRO_UID, $sProUid ); - $oDataset = RoutePeer::doSelectRS( $oCriteria ); - $oDataset->setFetchmode( ResultSet::FETCHMODE_ASSOC ); - $oDataset->next(); - while ($aRow = $oDataset->getRow()) { - if ($oRoute->routeExists( $aRow['ROU_UID'] )) { - $oRoute->remove( $aRow['ROU_UID'] ); - } - $oDataset->next(); - } + $oCriteria = new Criteria( 'workflow' ); + $oCriteria->add( TriggersPeer::PRO_UID, $sProUid ); + $oDataset = TriggersPeer::doSelectRS( $oCriteria ); + $oDataset->setFetchmode( ResultSet::FETCHMODE_ASSOC ); + $oDataset->next(); + while ($aRow = $oDataset->getRow()) { + if ($oTrigger->TriggerExists( $aRow['TRI_UID'] )) { + $oTrigger->remove( $aRow['TRI_UID'] ); + } + $oDataset->next(); + } + //Delete the routes of process + $oCriteria = new Criteria( 'workflow' ); + $oCriteria->add( RoutePeer::PRO_UID, $sProUid ); + $oDataset = RoutePeer::doSelectRS( $oCriteria ); + $oDataset->setFetchmode( ResultSet::FETCHMODE_ASSOC ); + $oDataset->next(); + while ($aRow = $oDataset->getRow()) { + if ($oRoute->routeExists( $aRow['ROU_UID'] )) { + $oRoute->remove( $aRow['ROU_UID'] ); + } + $oDataset->next(); + } //Delete the swimlanes elements of process - $oCriteria = new Criteria( 'workflow' ); - $oCriteria->add( SwimlanesElementsPeer::PRO_UID, $sProUid ); - $oDataset = SwimlanesElementsPeer::doSelectRS( $oCriteria ); - $oDataset->setFetchmode( ResultSet::FETCHMODE_ASSOC ); - $oDataset->next(); - while ($aRow = $oDataset->getRow()) { - if ($oSwimlaneElement->swimlanesElementsExists( $aRow['SWI_UID'] )) { - $oSwimlaneElement->remove( $aRow['SWI_UID'] ); - } - $oDataset->next(); - } - + $oCriteria = new Criteria( 'workflow' ); + $oCriteria->add( SwimlanesElementsPeer::PRO_UID, $sProUid ); + $oDataset = SwimlanesElementsPeer::doSelectRS( $oCriteria ); + $oDataset->setFetchmode( ResultSet::FETCHMODE_ASSOC ); + $oDataset->next(); + while ($aRow = $oDataset->getRow()) { + if ($oSwimlaneElement->swimlanesElementsExists( $aRow['SWI_UID'] )) { + $oSwimlaneElement->remove( $aRow['SWI_UID'] ); + } + $oDataset->next(); + } + //Delete the DB connections of process - $oCriteria = new Criteria( 'workflow' ); - $oCriteria->add( DbSourcePeer::PRO_UID, $sProUid ); - $oDataset = DbSourcePeer::doSelectRS( $oCriteria ); - $oDataset->setFetchmode( ResultSet::FETCHMODE_ASSOC ); - $oDataset->next(); - while ($aRow = $oDataset->getRow()) { - if ($oConnection->Exists( $aRow['DBS_UID'], $aRow['PRO_UID'] )) { - $oConnection->remove( $aRow['DBS_UID'], $aRow['PRO_UID'] ); - } - $oDataset->next(); - } - + $oCriteria = new Criteria( 'workflow' ); + $oCriteria->add( DbSourcePeer::PRO_UID, $sProUid ); + $oDataset = DbSourcePeer::doSelectRS( $oCriteria ); + $oDataset->setFetchmode( ResultSet::FETCHMODE_ASSOC ); + $oDataset->next(); + while ($aRow = $oDataset->getRow()) { + if ($oConnection->Exists( $aRow['DBS_UID'], $aRow['PRO_UID'] )) { + $oConnection->remove( $aRow['DBS_UID'], $aRow['PRO_UID'] ); + } + $oDataset->next(); + } + //Delete the sub process of process - $oCriteria = new Criteria( 'workflow' ); - $oCriteria->add( SubProcessPeer::PRO_PARENT, $sProUid ); - $oDataset = SubProcessPeer::doSelectRS( $oCriteria ); - $oDataset->setFetchmode( ResultSet::FETCHMODE_ASSOC ); - $oDataset->next(); - while ($aRow = $oDataset->getRow()) { - if ($oSubProcess->subProcessExists( $aRow['SP_UID'] )) { - $oSubProcess->remove( $aRow['SP_UID'] ); - } - $oDataset->next(); - } - + $oCriteria = new Criteria( 'workflow' ); + $oCriteria->add( SubProcessPeer::PRO_PARENT, $sProUid ); + $oDataset = SubProcessPeer::doSelectRS( $oCriteria ); + $oDataset->setFetchmode( ResultSet::FETCHMODE_ASSOC ); + $oDataset->next(); + while ($aRow = $oDataset->getRow()) { + if ($oSubProcess->subProcessExists( $aRow['SP_UID'] )) { + $oSubProcess->remove( $aRow['SP_UID'] ); + } + $oDataset->next(); + } + //Delete the caseTracker of process - $oCriteria = new Criteria( 'workflow' ); - $oCriteria->add( CaseTrackerPeer::PRO_UID, $sProUid ); - $oDataset = CaseTrackerPeer::doSelectRS( $oCriteria ); - $oDataset->setFetchmode( ResultSet::FETCHMODE_ASSOC ); - $oDataset->next(); - while ($aRow = $oDataset->getRow()) { - if ($oCaseTracker->caseTrackerExists( $aRow['PRO_UID'] )) { - $oCaseTracker->remove( $aRow['PRO_UID'] ); - } - $oDataset->next(); - } - + $oCriteria = new Criteria( 'workflow' ); + $oCriteria->add( CaseTrackerPeer::PRO_UID, $sProUid ); + $oDataset = CaseTrackerPeer::doSelectRS( $oCriteria ); + $oDataset->setFetchmode( ResultSet::FETCHMODE_ASSOC ); + $oDataset->next(); + while ($aRow = $oDataset->getRow()) { + if ($oCaseTracker->caseTrackerExists( $aRow['PRO_UID'] )) { + $oCaseTracker->remove( $aRow['PRO_UID'] ); + } + $oDataset->next(); + } + //Delete the caseTrackerObject of process - $oCriteria = new Criteria( 'workflow' ); - $oCriteria->add( CaseTrackerObjectPeer::PRO_UID, $sProUid ); - $oDataset = CaseTrackerObjectPeer::doSelectRS( $oCriteria ); - $oDataset->setFetchmode( ResultSet::FETCHMODE_ASSOC ); - $oDataset->next(); - while ($aRow = $oDataset->getRow()) { - if ($oCaseTrackerObject->caseTrackerObjectExists( $aRow['CTO_UID'] )) { - $oCaseTrackerObject->remove( $aRow['CTO_UID'] ); - } - $oDataset->next(); - } - + $oCriteria = new Criteria( 'workflow' ); + $oCriteria->add( CaseTrackerObjectPeer::PRO_UID, $sProUid ); + $oDataset = CaseTrackerObjectPeer::doSelectRS( $oCriteria ); + $oDataset->setFetchmode( ResultSet::FETCHMODE_ASSOC ); + $oDataset->next(); + while ($aRow = $oDataset->getRow()) { + if ($oCaseTrackerObject->caseTrackerObjectExists( $aRow['CTO_UID'] )) { + $oCaseTrackerObject->remove( $aRow['CTO_UID'] ); + } + $oDataset->next(); + } + //Delete the ObjectPermission of process - $oCriteria = new Criteria( 'workflow' ); - $oCriteria->add( ObjectPermissionPeer::PRO_UID, $sProUid ); - $oDataset = ObjectPermissionPeer::doSelectRS( $oCriteria ); - $oDataset->setFetchmode( ResultSet::FETCHMODE_ASSOC ); - $oDataset->next(); - while ($aRow = $oDataset->getRow()) { - if ($oObjectPermission->Exists( $aRow['OP_UID'] )) { - $oObjectPermission->remove( $aRow['OP_UID'] ); - } - $oDataset->next(); - } - + $oCriteria = new Criteria( 'workflow' ); + $oCriteria->add( ObjectPermissionPeer::PRO_UID, $sProUid ); + $oDataset = ObjectPermissionPeer::doSelectRS( $oCriteria ); + $oDataset->setFetchmode( ResultSet::FETCHMODE_ASSOC ); + $oDataset->next(); + while ($aRow = $oDataset->getRow()) { + if ($oObjectPermission->Exists( $aRow['OP_UID'] )) { + $oObjectPermission->remove( $aRow['OP_UID'] ); + } + $oDataset->next(); + } + //Delete the Stage of process - $oCriteria = new Criteria( 'workflow' ); - $oCriteria->add( StagePeer::PRO_UID, $sProUid ); - $oDataset = StagePeer::doSelectRS( $oCriteria ); - $oDataset->setFetchmode( ResultSet::FETCHMODE_ASSOC ); - $oDataset->next(); - while ($aRow = $oDataset->getRow()) { - if ($oStage->Exists( $aRow['STG_UID'] )) { - $oStage->remove( $aRow['STG_UID'] ); - } - $oDataset->next(); - } - + $oCriteria = new Criteria( 'workflow' ); + $oCriteria->add( StagePeer::PRO_UID, $sProUid ); + $oDataset = StagePeer::doSelectRS( $oCriteria ); + $oDataset->setFetchmode( ResultSet::FETCHMODE_ASSOC ); + $oDataset->next(); + while ($aRow = $oDataset->getRow()) { + if ($oStage->Exists( $aRow['STG_UID'] )) { + $oStage->remove( $aRow['STG_UID'] ); + } + $oDataset->next(); + } + //Delete the Event of process - $oCriteria = new Criteria( 'workflow' ); - $oCriteria->add( EventPeer::PRO_UID, $sProUid ); - $oDataset = EventPeer::doSelectRS( $oCriteria ); - $oDataset->setFetchmode( ResultSet::FETCHMODE_ASSOC ); - $oDataset->next(); - while ($aRow = $oDataset->getRow()) { - if ($oEvent->Exists( $aRow['EVN_UID'] )) { - $oEvent->remove( $aRow['EVN_UID'] ); - } - $oDataset->next(); - if ($oEvent->existsByTaskUidFrom( $aRow['TAS_UID'] )) { - $aRowEvent = $oEvent->getRowByTaskUidFrom( $aRow['TAS_UID'] ); - $oEvent->remove( $aRowEvent['EVN_UID'] ); - } - $oDataset->next(); - } - + $oCriteria = new Criteria( 'workflow' ); + $oCriteria->add( EventPeer::PRO_UID, $sProUid ); + $oDataset = EventPeer::doSelectRS( $oCriteria ); + $oDataset->setFetchmode( ResultSet::FETCHMODE_ASSOC ); + $oDataset->next(); + while ($aRow = $oDataset->getRow()) { + if ($oEvent->Exists( $aRow['EVN_UID'] )) { + $oEvent->remove( $aRow['EVN_UID'] ); + } + $oDataset->next(); + if ($oEvent->existsByTaskUidFrom( $aRow['TAS_UID'] )) { + $aRowEvent = $oEvent->getRowByTaskUidFrom( $aRow['TAS_UID'] ); + $oEvent->remove( $aRowEvent['EVN_UID'] ); + } + $oDataset->next(); + } + //Delete the CaseScheduler of process - $oCriteria = new Criteria( 'workflow' ); - $oCriteria->add( CaseSchedulerPeer::PRO_UID, $sProUid ); - $oDataset = CaseSchedulerPeer::doSelectRS( $oCriteria ); - $oDataset->setFetchmode( ResultSet::FETCHMODE_ASSOC ); - $oDataset->next(); - while ($aRow = $oDataset->getRow()) { - if ($oCaseScheduler->Exists( $aRow['SCH_UID'] )) { - $oCaseScheduler->remove( $aRow['SCH_UID'] ); - } - $oDataset->next(); - } - - return true; - } catch (Exception $oError) { - throw ($oError); - } - } - - /** - * this function creates a new Process, defined in the object $oData - * - * @param string $sProUid - * @return boolean - */ - public function createProcessFromData ($oData, $pmFilename) - { - $this->removeProcessRows( $oData->process['PRO_UID'] ); - + $oCriteria = new Criteria( 'workflow' ); + $oCriteria->add( CaseSchedulerPeer::PRO_UID, $sProUid ); + $oDataset = CaseSchedulerPeer::doSelectRS( $oCriteria ); + $oDataset->setFetchmode( ResultSet::FETCHMODE_ASSOC ); + $oDataset->next(); + while ($aRow = $oDataset->getRow()) { + if ($oCaseScheduler->Exists( $aRow['SCH_UID'] )) { + $oCaseScheduler->remove( $aRow['SCH_UID'] ); + } + $oDataset->next(); + } + + return true; + } catch (Exception $oError) { + throw ($oError); + } + } + + /** + * this function creates a new Process, defined in the object $oData + * + * @param string $sProUid + * @return boolean + */ + public function createProcessFromData ($oData, $pmFilename) + { + $this->removeProcessRows( $oData->process['PRO_UID'] ); + // (*) Creating process dependencies // creating the process category - $this->createProcessCategoryRow( isset( $oData->processCategory ) ? $oData->processCategory : null ); - + $this->createProcessCategoryRow( isset( $oData->processCategory ) ? $oData->processCategory : null ); + // create the process - $this->createProcessRow( $oData->process ); - $this->createTaskRows( $oData->tasks ); + $this->createProcessRow( $oData->process ); + $this->createTaskRows( $oData->tasks ); //it was commented becuase it seems to be working fine //$this->createEventRows(isset($oData->event) ? $oData->event : array()); - - $aRoutesUID = $this->createRouteRows( $oData->routes ); - $this->createLaneRows( $oData->lanes ); - + + + $aRoutesUID = $this->createRouteRows( $oData->routes ); + $this->createLaneRows( $oData->lanes ); + /*if(!isset($oData->gateways)){ //Adding gateway information while importing processes from older version //Making compatible with old export process @@ -3492,436 +3501,444 @@ class Processes $oRoute->update($aData); } } - } - else*/ - - if (isset( $oData->gateways )) { - $this->createGatewayRows( $oData->gateways ); - } - $this->createDynaformRows( $oData->dynaforms ); - $this->createInputRows( $oData->inputs ); - $this->createOutputRows( $oData->outputs ); - $this->createStepRows( $oData->steps ); - $this->createStepSupervisorRows( isset( $oData->stepSupervisor ) ? $oData->stepSupervisor : array () ); - $this->createTriggerRows( $oData->triggers ); - $this->createStepTriggerRows( $oData->steptriggers ); - $this->createTaskUserRows( $oData->taskusers ); - $this->createGroupRow( $oData->groupwfs ); - $this->createDBConnectionsRows( isset( $oData->dbconnections ) ? $oData->dbconnections : array () ); - $this->createReportTables( isset( $oData->reportTables ) ? $oData->reportTables : array (), isset( $oData->reportTablesVars ) ? $oData->reportTablesVars : array () ); - $this->createSubProcessRows( isset( $oData->subProcess ) ? $oData->subProcess : array () ); - $this->createCaseTrackerRows( isset( $oData->caseTracker ) ? $oData->caseTracker : array () ); - $this->createCaseTrackerObjectRows( isset( $oData->caseTrackerObject ) ? $oData->caseTrackerObject : array () ); - $this->createObjectPermissionsRows( isset( $oData->objectPermissions ) ? $oData->objectPermissions : array () ); - $this->createStageRows( isset( $oData->stage ) ? $oData->stage : array () ); - - $this->createFieldCondition( isset( $oData->fieldCondition ) ? $oData->fieldCondition : array (), $oData->dynaforms ); - + } + else*/ + + if (isset( $oData->gateways )) { + $this->createGatewayRows( $oData->gateways ); + } + $this->createDynaformRows( $oData->dynaforms ); + $this->createInputRows( $oData->inputs ); + $this->createOutputRows( $oData->outputs ); + $this->createStepRows( $oData->steps ); + $this->createStepSupervisorRows( isset( $oData->stepSupervisor ) ? $oData->stepSupervisor : array () ); + $this->createTriggerRows( $oData->triggers ); + $this->createStepTriggerRows( $oData->steptriggers ); + $this->createTaskUserRows( $oData->taskusers ); + $this->createGroupRow( $oData->groupwfs ); + $this->createDBConnectionsRows( isset( $oData->dbconnections ) ? $oData->dbconnections : array () ); + $this->createReportTables( isset( $oData->reportTables ) ? $oData->reportTables : array (), isset( $oData->reportTablesVars ) ? $oData->reportTablesVars : array () ); + $this->createSubProcessRows( isset( $oData->subProcess ) ? $oData->subProcess : array () ); + $this->createCaseTrackerRows( isset( $oData->caseTracker ) ? $oData->caseTracker : array () ); + $this->createCaseTrackerObjectRows( isset( $oData->caseTrackerObject ) ? $oData->caseTrackerObject : array () ); + $this->createObjectPermissionsRows( isset( $oData->objectPermissions ) ? $oData->objectPermissions : array () ); + $this->createStageRows( isset( $oData->stage ) ? $oData->stage : array () ); + + $this->createFieldCondition( isset( $oData->fieldCondition ) ? $oData->fieldCondition : array (), $oData->dynaforms ); + // Create before to createRouteRows for avoid duplicates - $this->createEventRows( isset( $oData->event ) ? $oData->event : array () ); - - $this->createCaseSchedulerRows( isset( $oData->caseScheduler ) ? $oData->caseScheduler : array () ); - + $this->createEventRows( isset( $oData->event ) ? $oData->event : array () ); + + $this->createCaseSchedulerRows( isset( $oData->caseScheduler ) ? $oData->caseScheduler : array () ); + // and finally create the files, dynaforms (xml and html), emailTemplates and Public files - $this->createFiles( $oData, $pmFilename ); - } - - /** - * this function creates a new Process, defined in the object $oData - * - * @param string $sProUid - * @return boolean - */ - public function updateProcessFromData ($oData, $pmFilename) - { - $this->updateProcessRow( $oData->process ); - $this->removeProcessRows( $oData->process['PRO_UID'] ); - $this->createTaskRows( $oData->tasks ); - $this->createRouteRows( $oData->routes ); - $this->createLaneRows( $oData->lanes ); - $this->createDynaformRows( $oData->dynaforms ); - $this->createInputRows( $oData->inputs ); - $this->createOutputRows( $oData->outputs ); - $this->createStepRows( $oData->steps ); - $this->createStepSupervisorRows( $oData->stepSupervisor ); - $this->createTriggerRows( $oData->triggers ); - $this->createStepTriggerRows( $oData->steptriggers ); - $this->createTaskUserRows( $oData->taskusers ); - $this->createGroupRow( $oData->groupwfs ); - $this->createDBConnectionsRows( $oData->dbconnections ); - $this->updateReportTables( $oData->reportTables, $oData->reportTablesVars ); - $this->createFiles( $oData, $pmFilename ); - $this->createSubProcessRows( $oData->subProcess ); - $this->createCaseTrackerRows( $oData->caseTracker ); - $this->createCaseTrackerObjectRows( $oData->caseTrackerObject ); - $this->createObjectPermissionsRows( $oData->objectPermissions ); - $this->createStageRows( $oData->stage ); - $this->createFieldCondition( $oData->fieldCondition, $oData->dynaforms ); - $this->createEventRows( $oData->event ); - $this->createCaseSchedulerRows( $oData->caseScheduler ); - $this->createProcessCategoryRow( isset( $oData->processCategory ) ? $oData->processCategory : null ); - } - - /** - * get the starting task for a user but from a Tasks object - * - * @param $sProUid process uid - * @param $sUserUid user uid - * @return an array of tasks - */ - public function getStartingTaskForUser ($sProUid, $sUsrUid) - { - $oTask = new Tasks(); - return $oTask->getStartingTaskForUser( $sProUid, $sUsrUid ); - } - - /** - * *********************************************** - * functions to enable open ProcessMaker Library - * *********************************************** - */ - /** - * Open a WebService connection - * - * @param $user username for pm - * @param $pass password for the user - * @return 1 integer. - */ - public function ws_open ($user, $pass) - { - global $sessionId; - global $client; - $endpoint = PML_WSDL_URL; - $sessionId = ''; - $proxy = array (); - $sysConf = System::getSystemConfiguration(); - if ($sysConf['proxy_host'] != '') { - $proxy['proxy_host'] = $sysConf['proxy_host']; - if ($sysConf['proxy_port'] != '') { - $proxy['proxy_port'] = $sysConf['proxy_port']; - } - if ($sysConf['proxy_user'] != '') { - $proxy['proxy_login'] = $sysConf['proxy_user']; - } - if ($sysConf['proxy_pass'] != '') { - $proxy['proxy_password'] = $sysConf['proxy_pass']; - } - } - $client = new SoapClient( $endpoint, $proxy ); - $params = array ('userid' => $user,'password' => $pass); - $result = $client->__SoapCall( 'login', array ($params) ); - if ($result->status_code == 0) { - $sessionId = $result->message; - return 1; - } - throw (new Exception( $result->message )); - return 1; - } - - /** - * Open a WebService public connection - * - * @param $user username for pm - * @param $pass password for the user - * @return 1 integer. - */ - public function ws_open_public () - { - global $sessionId; - global $client; - $endpoint = PML_WSDL_URL; - $sessionId = ''; + $this->createFiles( $oData, $pmFilename ); + } + + /** + * this function creates a new Process, defined in the object $oData + * + * @param string $sProUid + * @return boolean + */ + public function updateProcessFromData ($oData, $pmFilename) + { + $this->updateProcessRow( $oData->process ); + $this->removeProcessRows( $oData->process['PRO_UID'] ); + $this->createTaskRows( $oData->tasks ); + $this->createRouteRows( $oData->routes ); + $this->createLaneRows( $oData->lanes ); + $this->createDynaformRows( $oData->dynaforms ); + $this->createInputRows( $oData->inputs ); + $this->createOutputRows( $oData->outputs ); + $this->createStepRows( $oData->steps ); + $this->createStepSupervisorRows( $oData->stepSupervisor ); + $this->createTriggerRows( $oData->triggers ); + $this->createStepTriggerRows( $oData->steptriggers ); + $this->createTaskUserRows( $oData->taskusers ); + $this->createGroupRow( $oData->groupwfs ); + $this->createDBConnectionsRows( $oData->dbconnections ); + $this->updateReportTables( $oData->reportTables, $oData->reportTablesVars ); + $this->createFiles( $oData, $pmFilename ); + $this->createSubProcessRows( $oData->subProcess ); + $this->createCaseTrackerRows( $oData->caseTracker ); + $this->createCaseTrackerObjectRows( $oData->caseTrackerObject ); + $this->createObjectPermissionsRows( $oData->objectPermissions ); + $this->createStageRows( $oData->stage ); + $this->createFieldCondition( $oData->fieldCondition, $oData->dynaforms ); + $this->createEventRows( $oData->event ); + $this->createCaseSchedulerRows( $oData->caseScheduler ); + $this->createProcessCategoryRow( isset( $oData->processCategory ) ? $oData->processCategory : null ); + } + + /** + * get the starting task for a user but from a Tasks object + * + * @param $sProUid process uid + * @param $sUserUid user uid + * @return an array of tasks + */ + public function getStartingTaskForUser ($sProUid, $sUsrUid) + { + $oTask = new Tasks(); + return $oTask->getStartingTaskForUser( $sProUid, $sUsrUid ); + } + + /** + * *********************************************** + * functions to enable open ProcessMaker Library + * *********************************************** + */ + /** + * Open a WebService connection + * + * @param $user username for pm + * @param $pass password for the user + * @return 1 integer. + */ + public function ws_open ($user, $pass) + { + global $sessionId; + global $client; + $endpoint = PML_WSDL_URL; + $sessionId = ''; + $proxy = array (); + $sysConf = System::getSystemConfiguration(); + if ($sysConf['proxy_host'] != '') { + $proxy['proxy_host'] = $sysConf['proxy_host']; + if ($sysConf['proxy_port'] != '') { + $proxy['proxy_port'] = $sysConf['proxy_port']; + } + if ($sysConf['proxy_user'] != '') { + $proxy['proxy_login'] = $sysConf['proxy_user']; + } + if ($sysConf['proxy_pass'] != '') { + $proxy['proxy_password'] = $sysConf['proxy_pass']; + } + } + $client = new SoapClient( $endpoint, $proxy ); + $params = array ('userid' => $user,'password' => $pass + ); + $result = $client->__SoapCall( 'login', array ($params + ) ); + if ($result->status_code == 0) { + $sessionId = $result->message; + return 1; + } + throw (new Exception( $result->message )); + return 1; + } + + /** + * Open a WebService public connection + * + * @param $user username for pm + * @param $pass password for the user + * @return 1 integer. + */ + public function ws_open_public () + { + global $sessionId; + global $client; + $endpoint = PML_WSDL_URL; + $sessionId = ''; ini_set( "soap.wsdl_cache_enabled", "0" ); // enabling WSDL cache - try { - $proxy = array (); - $sysConf = System::getSystemConfiguration(); - if ($sysConf['proxy_host'] != '') { - $proxy['proxy_host'] = $sysConf['proxy_host']; - if ($sysConf['proxy_port'] != '') { - $proxy['proxy_port'] = $sysConf['proxy_port']; - } - if ($sysConf['proxy_user'] != '') { - $proxy['proxy_login'] = $sysConf['proxy_user']; - } - if ($sysConf['proxy_pass'] != '') { - $proxy['proxy_password'] = $sysConf['proxy_pass']; - } - } - $client = @new SoapClient( $endpoint, $proxy ); - } catch (Exception $e) { - throw (new Exception( $e->getMessage() )); - } - return 1; - } - - /** - * Consume the processList WebService - * - * @return $result process list. - */ - public function ws_processList () - { - global $sessionId; - global $client; - - $endpoint = PML_WSDL_URL; - $proxy = array (); - $sysConf = System::getSystemConfiguration(); - - if ($sysConf['proxy_host'] != '') { - $proxy['proxy_host'] = $sysConf['proxy_host']; - if ($sysConf['proxy_port'] != '') { - $proxy['proxy_port'] = $sysConf['proxy_port']; - } - if ($sysConf['proxy_user'] != '') { - $proxy['proxy_login'] = $sysConf['proxy_user']; - } - if ($sysConf['proxy_pass'] != '') { - $proxy['proxy_password'] = $sysConf['proxy_pass']; - } - } - - $client = new SoapClient( $endpoint, $proxy ); - $sessionId = ''; - $params = array ('sessionId' => $sessionId); - $result = $client->__SoapCall( 'processList', array ($params) ); - if ($result->status_code == 0) { - return $result; - } - throw (new Exception( $result->message )); - } - - /** - * download a File - * - * @param $file file to download - * @param $local_path path of the file - * @param $newfilename - * @return $errorMsg process list. - */ - public function downloadFile ($file, $local_path, $newfilename) - { - $err_msg = ''; - $out = fopen( $local_path . $newfilename, 'wb' ); - if ($out == false) { - throw (new Exception( "File $newfilename not opened" )); - } - - if (! function_exists( 'curl_init' )) { - G::SendTemporalMessage( 'ID_CURLFUN_ISUNDEFINED', "warning", 'LABEL', '', '100%', '' ); - G::header( 'location: ../processes/processes_Library' ); - die(); - } - $ch = curl_init(); - - curl_setopt( $ch, CURLOPT_FILE, $out ); - curl_setopt( $ch, CURLOPT_HEADER, 0 ); - curl_setopt( $ch, CURLOPT_URL, $file ); - - curl_exec( $ch ); - $errorMsg = curl_error( $ch ); - fclose( $out ); - - curl_close( $ch ); - return $errorMsg; - + try { + $proxy = array (); + $sysConf = System::getSystemConfiguration(); + if ($sysConf['proxy_host'] != '') { + $proxy['proxy_host'] = $sysConf['proxy_host']; + if ($sysConf['proxy_port'] != '') { + $proxy['proxy_port'] = $sysConf['proxy_port']; + } + if ($sysConf['proxy_user'] != '') { + $proxy['proxy_login'] = $sysConf['proxy_user']; + } + if ($sysConf['proxy_pass'] != '') { + $proxy['proxy_password'] = $sysConf['proxy_pass']; + } + } + $client = @new SoapClient( $endpoint, $proxy ); + } catch (Exception $e) { + throw (new Exception( $e->getMessage() )); + } + return 1; + } + + /** + * Consume the processList WebService + * + * @return $result process list. + */ + public function ws_processList () + { + global $sessionId; + global $client; + + $endpoint = PML_WSDL_URL; + $proxy = array (); + $sysConf = System::getSystemConfiguration(); + + if ($sysConf['proxy_host'] != '') { + $proxy['proxy_host'] = $sysConf['proxy_host']; + if ($sysConf['proxy_port'] != '') { + $proxy['proxy_port'] = $sysConf['proxy_port']; + } + if ($sysConf['proxy_user'] != '') { + $proxy['proxy_login'] = $sysConf['proxy_user']; + } + if ($sysConf['proxy_pass'] != '') { + $proxy['proxy_password'] = $sysConf['proxy_pass']; + } + } + + $client = new SoapClient( $endpoint, $proxy ); + $sessionId = ''; + $params = array ('sessionId' => $sessionId + ); + $result = $client->__SoapCall( 'processList', array ($params + ) ); + if ($result->status_code == 0) { + return $result; + } + throw (new Exception( $result->message )); + } + + /** + * download a File + * + * @param $file file to download + * @param $local_path path of the file + * @param $newfilename + * @return $errorMsg process list. + */ + public function downloadFile ($file, $local_path, $newfilename) + { + $err_msg = ''; + $out = fopen( $local_path . $newfilename, 'wb' ); + if ($out == false) { + throw (new Exception( "File $newfilename not opened" )); + } + + if (! function_exists( 'curl_init' )) { + G::SendTemporalMessage( 'ID_CURLFUN_ISUNDEFINED', "warning", 'LABEL', '', '100%', '' ); + G::header( 'location: ../processes/processes_Library' ); + die(); + } + $ch = curl_init(); + + curl_setopt( $ch, CURLOPT_FILE, $out ); + curl_setopt( $ch, CURLOPT_HEADER, 0 ); + curl_setopt( $ch, CURLOPT_URL, $file ); + + curl_exec( $ch ); + $errorMsg = curl_error( $ch ); + fclose( $out ); + + curl_close( $ch ); + return $errorMsg; + } //end function - - - /** - * get the process Data from a process - * - * @param $proId process Uid - * @return $result - */ - public function ws_processGetData ($proId) - { - global $sessionId; - global $client; - - $endpoint = PML_WSDL_URL; - $proxy = array (); - $sysConf = System::getSystemConfiguration(); - if ($sysConf['proxy_host'] != '') { - $proxy['proxy_host'] = $sysConf['proxy_host']; - if ($sysConf['proxy_port'] != '') { - $proxy['proxy_port'] = $sysConf['proxy_port']; - } - if ($sysConf['proxy_user'] != '') { - $proxy['proxy_login'] = $sysConf['proxy_user']; - } - if ($sysConf['proxy_pass'] != '') { - $proxy['proxy_password'] = $sysConf['proxy_pass']; - } - } - $client = new SoapClient( $endpoint, $proxy ); - - $sessionId = ''; - $params = array ('sessionId' => $sessionId,'processId' => $proId); - $result = $client->__SoapCall( 'processGetData', array ($params) ); - if ($result->status_code == 0) { - return $result; - } - throw (new Exception( $result->message )); - } - - /** - * parse an array of Items - * - * @param $proId process Uid - * @return $result - */ - public function parseItemArray ($array) - { - if (! isset( $array->item ) && ! is_array( $array )) { - return null; - } - - $result = array (); - if (isset( $array->item )) { - foreach ($array->item as $key => $value) { - $result[$value->key] = $value->value; - } - } else { - foreach ($array as $key => $value) { - $result[$value->key] = $value->value; - } - } - return $result; - } - - public function getProcessFiles ($proUid, $type) - { - $filesList = array (); - - switch ($type) { - case "mail": - case "email": - $basePath = PATH_DATA_MAILTEMPLATES; - break; - case "public": - $basePath = PATH_DATA_PUBLIC; - break; - default: - throw new Exception( "Unknow Process Files Type \"$type\"." ); - break; - } - - $dir = $basePath . $proUid . PATH_SEP; - + + + /** + * get the process Data from a process + * + * @param $proId process Uid + * @return $result + */ + public function ws_processGetData ($proId) + { + global $sessionId; + global $client; + + $endpoint = PML_WSDL_URL; + $proxy = array (); + $sysConf = System::getSystemConfiguration(); + if ($sysConf['proxy_host'] != '') { + $proxy['proxy_host'] = $sysConf['proxy_host']; + if ($sysConf['proxy_port'] != '') { + $proxy['proxy_port'] = $sysConf['proxy_port']; + } + if ($sysConf['proxy_user'] != '') { + $proxy['proxy_login'] = $sysConf['proxy_user']; + } + if ($sysConf['proxy_pass'] != '') { + $proxy['proxy_password'] = $sysConf['proxy_pass']; + } + } + $client = new SoapClient( $endpoint, $proxy ); + + $sessionId = ''; + $params = array ('sessionId' => $sessionId,'processId' => $proId + ); + $result = $client->__SoapCall( 'processGetData', array ($params + ) ); + if ($result->status_code == 0) { + return $result; + } + throw (new Exception( $result->message )); + } + + /** + * parse an array of Items + * + * @param $proId process Uid + * @return $result + */ + public function parseItemArray ($array) + { + if (! isset( $array->item ) && ! is_array( $array )) { + return null; + } + + $result = array (); + if (isset( $array->item )) { + foreach ($array->item as $key => $value) { + $result[$value->key] = $value->value; + } + } else { + foreach ($array as $key => $value) { + $result[$value->key] = $value->value; + } + } + return $result; + } + + public function getProcessFiles ($proUid, $type) + { + $filesList = array (); + + switch ($type) { + case "mail": + case "email": + $basePath = PATH_DATA_MAILTEMPLATES; + break; + case "public": + $basePath = PATH_DATA_PUBLIC; + break; + default: + throw new Exception( "Unknow Process Files Type \"$type\"." ); + break; + } + + $dir = $basePath . $proUid . PATH_SEP; + G::verifyPath( $dir, true ); //Create if it does not exist - + + //Creating the default template (if not exists) - if (! file_exists( $dir . "alert_message.html" )) { - @copy( PATH_TPL . "mails" . PATH_SEP . "alert_message.html", $dir . "alert_message.html" ); - } - - if (! file_exists( $dir . "unassignedMessage.html" )) { - @copy( PATH_TPL . "mails" . PATH_SEP . "unassignedMessage.html", $dir . "unassignedMessage.html" ); - } - - $files = glob( $dir . "*.*" ); - - foreach ($files as $file) { - $fileName = basename( $file ); - - if ($fileName != "alert_message.html" && $fileName != "unassignedMessage.html") { - $filesList[] = array ("filepath" => $file,"filename" => $fileName); - } - } - return $filesList; - } - -} //end class processes - - -/** - * Object Document class - * - * @package workflow.engine.ProcessMaker - */ -class ObjectDocument -{ - public $type; - public $name; - public $data; - public $origin; - - /** - * Constructor - */ - public function __construct () - { - $this->type = ''; - $this->name = ''; - $this->data = ''; - $this->origin = ''; - } -} - -/** - * ObjectDocument Collection - * - * @package workflow.engine.ProcessMaker - */ -class ObjectCellection -{ - public $num; - public $swapc; - public $objects; - - /** - * Constructor - */ - public function __construct () - { - $this->objects = Array (); - $this->num = 0; - $this->swapc = $this->num; - array_push( $this->objects, 'void' ); - } - - /** - * add in the collecetion a new object Document - * - * @param $name name object document - * @param $type type object document - * @param $data data object document - * @param $origin origin object document - * @return void - */ - public function add ($name, $type, $data, $origin) - { - $o = new ObjectDocument(); - $o->name = $name; - $o->type = $type; - $o->data = $data; - $o->origin = $origin; - - $this->num ++; - array_push( $this->objects, $o ); - $this->swapc = $this->num; - } - - /** - * get the collection of ObjectDocument - * - * @param $name name object document - * @param $type type object document - * @param $data data object document - * @param $origin origin object document - * @return void - */ - public function get () - { - if ($this->swapc > 0) { - $e = $this->objects[$this->swapc]; - $this->swapc --; - return $e; - } else { - $this->swapc = $this->num; - return false; - } - } -} - + if (! file_exists( $dir . "alert_message.html" )) { + @copy( PATH_TPL . "mails" . PATH_SEP . "alert_message.html", $dir . "alert_message.html" ); + } + + if (! file_exists( $dir . "unassignedMessage.html" )) { + @copy( PATH_TPL . "mails" . PATH_SEP . "unassignedMessage.html", $dir . "unassignedMessage.html" ); + } + + $files = glob( $dir . "*.*" ); + + foreach ($files as $file) { + $fileName = basename( $file ); + + if ($fileName != "alert_message.html" && $fileName != "unassignedMessage.html") { + $filesList[] = array ("filepath" => $file,"filename" => $fileName + ); + } + } + return $filesList; + } +} +//end class processes + + +/** + * Object Document class + * + * @package workflow.engine.ProcessMaker + */ +class ObjectDocument +{ + public $type; + public $name; + public $data; + public $origin; + + /** + * Constructor + */ + public function __construct () + { + $this->type = ''; + $this->name = ''; + $this->data = ''; + $this->origin = ''; + } +} + +/** + * ObjectDocument Collection + * + * @package workflow.engine.ProcessMaker + */ +class ObjectCellection +{ + public $num; + public $swapc; + public $objects; + + /** + * Constructor + */ + public function __construct () + { + $this->objects = Array (); + $this->num = 0; + $this->swapc = $this->num; + array_push( $this->objects, 'void' ); + } + + /** + * add in the collecetion a new object Document + * + * @param $name name object document + * @param $type type object document + * @param $data data object document + * @param $origin origin object document + * @return void + */ + public function add ($name, $type, $data, $origin) + { + $o = new ObjectDocument(); + $o->name = $name; + $o->type = $type; + $o->data = $data; + $o->origin = $origin; + + $this->num ++; + array_push( $this->objects, $o ); + $this->swapc = $this->num; + } + + /** + * get the collection of ObjectDocument + * + * @param $name name object document + * @param $type type object document + * @param $data data object document + * @param $origin origin object document + * @return void + */ + public function get () + { + if ($this->swapc > 0) { + $e = $this->objects[$this->swapc]; + $this->swapc --; + return $e; + } else { + $this->swapc = $this->num; + return false; + } + } +} + diff --git a/workflow/engine/classes/class.xmlDb.php b/workflow/engine/classes/class.xmlDb.php index b56c00f41..c24af1a20 100755 --- a/workflow/engine/classes/class.xmlDb.php +++ b/workflow/engine/classes/class.xmlDb.php @@ -44,7 +44,7 @@ class XMLDB * @param string $dsn * @return array $options */ - function &connect ($dsn, $options = array()) + public function &connect ($dsn, $options = array()) { //Needed for $mysql_real_escape_string $mresdbc = new DBConnection(); @@ -63,7 +63,7 @@ class XMLDB * @param string $result * @return boolean is_a($result, 'DB_Error') */ - function isError ($result) + public function isError ($result) { return is_a( $result, 'DB_Error' ); } @@ -82,7 +82,7 @@ class XMLConnection { var $phptype = 'myxml'; var $caseFolding = true; - var $xmldoc = NULL; + var $xmldoc = null; var $xmlFile = ''; /** @@ -91,7 +91,7 @@ class XMLConnection * @param string $file * @return void */ - function XMLConnection ($file) + public function XMLConnection ($file) { $this->xmldoc = new Xml_Document(); $this->xmldoc->parseXmlFile( $file ); @@ -105,7 +105,7 @@ class XMLConnection * @param string $sql * @return object(XMLResult) $result */ - function &query ($sql) + public function &query ($sql) { if (! isset( $this->xmldoc )) { $err = new DB_Error( "Error: Closed xmlConnection." ); @@ -127,8 +127,8 @@ class XMLConnection $fieldsList[$name] = $match[1][$r][0]; } /* End Block */ - /* Start Block: Order list */ - $count = preg_match_all( '/\s*(\*|[\w\.]+)(\s+ASC|\s+DESC)?\s*,?/im', $sqlOrderBy, $match, PREG_PATTERN_ORDER | PREG_OFFSET_CAPTURE ); + /* Start Block: Order list */ + $count = preg_match_all( '/\s*(\*|[\w\.]+)(\s+ASC|\s+DESC)?\s*,?/im', $sqlOrderBy, $match, PREG_PATTERN_ORDER | PREG_OFFSET_CAPTURE ); $orderList = array (); for ($r = $count - 1; $r >= 0; $r --) { $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 ++) { $evalWhere = false; @eval( '$evalWhere = ' . $sqlWhere . ';' ); - if ($evalWhere) + if ($evalWhere) { $newRes[] = $res[$r]; + } } $res = $newRes; } /* End Block */ - /* Start Block: Expands the resultant data according to fill an array - * with the required fields in the query. - */ - for ($r = 0; $r < sizeof( $res ); $r ++) { + /* Start Block: Expands the resultant data according to fill an array + * with the required fields in the query. + */ + for ($r = 0; $r < sizeof( $res ); $r ++) { $res[$r] = $this->expandFields( $res[$r], $fieldsList ); } /* End Block */ - /* Start Block: ORDER BY*/ - foreach ($orderList as $field => $direction) { + /* Start Block: ORDER BY*/ + foreach ($orderList as $field => $direction) { for ($i = 0; $i < sizeof( $res ); $i ++) { for ($j = $i + 1; $j < sizeof( $res ); $j ++) { $condition = ($direction === 'ASC') ? ($res[$j] < $res[$i]) : ($res[$j] > $res[$i]); @@ -200,8 +201,8 @@ class XMLConnection } } /* End Block */ - /* Start Block: Apply limits */ - if ($sqlLowLimit != '' && $sqlHighLimit != '') { + /* Start Block: Apply limits */ + if ($sqlLowLimit != '' && $sqlHighLimit != '') { $sqlLowLimit = (int) $sqlLowLimit; $sqlHighLimit = (int) $sqlHighLimit; $res = array_slice( $res, $sqlLowLimit, $sqlHighLimit ); @@ -213,8 +214,8 @@ class XMLConnection $sqlFrom = isset( $matches[1] ) ? $matches[1] : ''; $sqlWhere = isset( $matches[2] ) ? $matches[2] : '1'; /* Start Block: WHERE*/ - /*Start Block: Replace the operator */ - $blocks = preg_split( '/("(?:(?:[^"]|"")*)"|\'(?:(?:[^\']|\'\')*)\')/im', $sqlWhere, - 1, PREG_SPLIT_DELIM_CAPTURE ); + /*Start Block: Replace the operator */ + $blocks = preg_split( '/("(?:(?:[^"]|"")*)"|\'(?:(?:[^\']|\'\')*)\')/im', $sqlWhere, - 1, PREG_SPLIT_DELIM_CAPTURE ); $sqlWhere = ''; for ($r = 0; $r < sizeof( $blocks ); $r ++) { if (($r % 2) === 0) { @@ -274,8 +275,8 @@ class XMLConnection $fieldsList[] = $match[1][$r][0]; } /* End Block */ - /* Start Block: Fields Values */ - $count = preg_match_all( '/("(?:(?:[^"]|"")*)"|\'(?:(?:[^\']|\'\')*)\'|\d+)/im', $sqlValues, $match, PREG_PATTERN_ORDER | PREG_OFFSET_CAPTURE ); + /* Start Block: Fields Values */ + $count = preg_match_all( '/("(?:(?:[^"]|"")*)"|\'(?:(?:[^\']|\'\')*)\'|\d+)/im', $sqlValues, $match, PREG_PATTERN_ORDER | PREG_OFFSET_CAPTURE ); $fieldsValues = array (); for ($r = 0; $r < $count; $r ++) { if (substr( $match[1][$r][0], 0, 1 ) === '"') { @@ -318,8 +319,8 @@ class XMLConnection $fieldsValues[$match[1][$r][0]] = $match[2][$r][0]; } /* Start Block: WHERE*/ - /*Start Block: Replace the operator */ - $blocks = preg_split( '/("(?:(?:[^"]|"")*)"|\'(?:(?:[^\']|\'\')*)\')/im', $sqlWhere, - 1, PREG_SPLIT_DELIM_CAPTURE ); + /*Start Block: Replace the operator */ + $blocks = preg_split( '/("(?:(?:[^"]|"")*)"|\'(?:(?:[^\']|\'\')*)\')/im', $sqlWhere, - 1, PREG_SPLIT_DELIM_CAPTURE ); $sqlWhere = ''; for ($r = 0; $r < sizeof( $blocks ); $r ++) { if (($r % 2) === 0) { @@ -377,7 +378,7 @@ class XMLConnection * @param string $a * @return void $b */ - function sqlLike ($a, $b) + public function sqlLike ($a, $b) { $b = addcslashes( $b, '[]()\/{}.?' ); $b = str_replace( "%", '.*', $b ); @@ -392,15 +393,16 @@ class XMLConnection * @param string $fieldsList * @return array $res */ - function expandFields ($resRow, $fieldsList) + public function expandFields ($resRow, $fieldsList) { $res = array (); foreach ($fieldsList as $key => $value) { if ($key === '*') { - foreach ($resRow as $k => $v) + foreach ($resRow as $k => $v) { $res[$k] = $v; + } } else { - $res[$key] = array_key_exists( $value, $resRow ) ? $resRow[$value] : NULL; + $res[$key] = array_key_exists( $value, $resRow ) ? $resRow[$value] : null; } } return $res; @@ -412,13 +414,14 @@ class XMLConnection * @param object &$node * @return array $res */ - function fetchNode (&$node) + public function fetchNode (&$node) { $res = array ('XMLNODE_NAME' => $node->name,'XMLNODE_TYPE' => $node->type,'XMLNODE_VALUE' => $node->value ); foreach ($node->attributes as $name => $value) { - if ($this->caseFolding) + if ($this->caseFolding) { $name = strtoupper( $name ); + } $res[$name] = $value; } return $res; @@ -430,7 +433,7 @@ class XMLConnection * @param string &$node * @return array $res */ - function fetchChildren (&$node) + public function fetchChildren (&$node) { $res = array (); foreach ($node->children as $name => $child) { @@ -444,7 +447,7 @@ class XMLConnection * * @return void */ - function disconnect () + public function disconnect () { unset( $this->xmldoc ); } @@ -454,7 +457,7 @@ class XMLConnection * @param array $match * @return object(DB_Error) $err */ - function sqlWhereLike ($match) + public function sqlWhereLike ($match) { switch (substr( $match[2], 0, 1 )) { case '"': @@ -476,7 +479,7 @@ class XMLConnection * @param array $match * @return object(DB_Error) $err */ - function sqlString ($match) + public function sqlString ($match) { switch (substr( $match[0], 0, 1 )) { case '"': @@ -507,7 +510,7 @@ class XMLConnection * @param object $values * @return void */ - function insertRow (&$node, $values) + public function insertRow (&$node, $values) { $attributes = array (); foreach ($values as $field => $value) { @@ -533,7 +536,7 @@ class XMLConnection * @param object $values * @return void */ - function updateRow (&$node, $values) + public function updateRow (&$node, $values) { foreach ($values as $field => $value) { switch ($field) { @@ -573,7 +576,7 @@ class XMLResult * @param array $result * @return void */ - function XMLResult ($result = array()) + public function XMLResult ($result = array()) { $this->result = $result; $this->cursor = 0; @@ -584,7 +587,7 @@ class XMLResult * * @return integer sizeof($this->result) */ - function numRows () + public function numRows () { return sizeof( $this->result ); } @@ -595,10 +598,11 @@ class XMLResult * @param string $const * @return integer $this->result[ $this->cursor-1 ]; */ - function fetchRow ($const) + public function fetchRow ($const) { - if ($this->cursor >= $this->numRows()) - return NULL; + if ($this->cursor >= $this->numRows()) { + return null; + } $this->cursor ++; return $this->result[$this->cursor - 1]; } @@ -621,4 +625,3 @@ function getNames ($children) return $names; } -?> \ No newline at end of file diff --git a/workflow/engine/classes/triggers/api/class.zimbraApi.php b/workflow/engine/classes/triggers/api/class.zimbraApi.php index f226df271..de01eda37 100644 --- a/workflow/engine/classes/triggers/api/class.zimbraApi.php +++ b/workflow/engine/classes/triggers/api/class.zimbraApi.php @@ -1,20 +1,20 @@ - - * @GPL 2007, Plymouth State University, ITS - */ -class Zimbra -{ - - public $debug = false; - public $error; + + * @GPL 2007, Plymouth State University, ITS + */ +class Zimbra +{ + + public $debug = false; + public $error; protected $_connected = false; // boolean to determine if the connect function has been called protected static $_num_soap_calls = 0; // the number of times a SOAP call has been made protected $_preAuthKey; // key for doing pre-authentication @@ -24,352 +24,353 @@ class Zimbra protected $_protocol; // which protocol to use when building the URL protected $_server1; // = 'ip-10-73-18-235.ec2.internal'; // hostname of zimbra server protected $_server; // displayname of zimbra server - protected $_path = '/service/soap'; - protected $_timestamp; - protected $_account_info; + protected $_path = '/service/soap'; + protected $_timestamp; + protected $_account_info; protected $_admin = false; // operating as an admin - protected $_curl; + protected $_curl; protected $_auth_token; // used for repeat calls to zimbra through soap protected $_session_id; // used for repeat calls to zimbra through soap protected $_idm; // IDMObject protected $_username; // the user we are operating as - - - /** - * __construct - * - * constructor sets up connectivity to servers - * - * @since version 1.0 - * @acess public - * @param string $username username - * @param string $which defaults to prod - */ - - public function __construct ($username, $serverUrl, $preAuthKey, $which = 'prod') - { - if ($which == 'dev') { - $which = 'zimbra_dev'; - $this->_dev = true; - } else { - $which = 'zimbra'; - } - - $this->_preAuthKey = $preAuthKey; + + + /** + * __construct + * + * constructor sets up connectivity to servers + * + * @since version 1.0 + * @acess public + * @param string $username username + * @param string $which defaults to prod + */ + + public function __construct ($username, $serverUrl, $preAuthKey, $which = 'prod') + { + if ($which == 'dev') { + $which = 'zimbra_dev'; + $this->_dev = true; + } else { + $which = 'zimbra'; + } + + $this->_preAuthKey = $preAuthKey; $this->_protocol = "http://"; // could also be http:// $this->_server = $serverUrl; //'zimbra.hostname.edu'; $this->_server1 = $serverUrl; //'zimbra.hostname.edu'; - $this->_username = $username; - $this->_timestamp = time() . '000'; - } - + $this->_username = $username; + $this->_timestamp = time() . '000'; + } + // end __construct - - - /** - * sso - * - * sso to Zimbra - * - * @since version 1.0 - * @access public - * @param string $options options for sso - * @return boolean - */ - public function sso ($options = '') - { - if ($this->_username) { - setcookie( 'ZM_SKIN', 'plymouth', time() + 60 * 60 * 24 * 30, '/', '.plymouth.edu' ); - - $pre_auth = $this->getPreAuth( $this->_username ); + + + /** + * sso + * + * sso to Zimbra + * + * @since version 1.0 + * @access public + * @param string $options options for sso + * @return boolean + */ + public function sso ($options = '') + { + if ($this->_username) { + setcookie( 'ZM_SKIN', 'plymouth', time() + 60 * 60 * 24 * 30, '/', '.plymouth.edu' ); + + $pre_auth = $this->getPreAuth( $this->_username ); $url = $this->_protocol . '/service/preauth?account=' . $this->_username . '@' . $this->_server . '&expires=' . $this->_preauth_expiration . '×tamp=' . $this->_timestamp . '&preauth=' . $pre_auth; //.'&'.$options; - header( "Location: $url" ); - exit(); - } else { - return false; - } - } - + header( "Location: $url" ); + exit(); + } else { + return false; + } + } + // end sso - - - /** - * createAccount - * - * @param string $name account name - * @param string $password password - * @return string account id - */ - function createAccount ($name, $password) - { - $option_string = ''; - - try { - + + + /** + * createAccount + * + * @param string $name account name + * @param string $password password + * @return string account id + */ + function createAccount ($name, $password) + { + $option_string = ''; + + try { + $soap = ' ' . $name . '@' . $this->_server1 . ' ' . $password . '' . $option_string . ' - '; - - $response = $this->soapRequest( $soap ); - } catch (SoapFault $exception) { - print_exception( $exception ); - } - - return $result['SOAP:ENVELOPE']['SOAP:BODY']['CREATEACCOUNTRESPONSE']['ACCOUNT']['ID']; - } - - /** - * getPreAuth - * - * get the preauth key needed for single-sign on - * - * @since version1.0 - * @access public - * @param string $username username - * @return string preauthentication key in hmacsha1 format - */ - private function getPreAuth ($username) - { - $account_identifier = $username . '@' . $this->_server1; - $by_value = 'name'; - $expires = $this->_preauth_expiration; - $timestamp = $this->_timestamp; - - $string = $account_identifier . '|' . $by_value . '|' . $expires . '|' . $timestamp; - - return $this->hmacsha1( $this->_preAuthKey, $string ); - } - + '; + + $response = $this->soapRequest( $soap ); + } catch (SoapFault $exception) { + print_exception( $exception ); + } + + return $result['SOAP:ENVELOPE']['SOAP:BODY']['CREATEACCOUNTRESPONSE']['ACCOUNT']['ID']; + } + + /** + * getPreAuth + * + * get the preauth key needed for single-sign on + * + * @since version1.0 + * @access public + * @param string $username username + * @return string preauthentication key in hmacsha1 format + */ + private function getPreAuth ($username) + { + $account_identifier = $username . '@' . $this->_server1; + $by_value = 'name'; + $expires = $this->_preauth_expiration; + $timestamp = $this->_timestamp; + + $string = $account_identifier . '|' . $by_value . '|' . $expires . '|' . $timestamp; + + return $this->hmacsha1( $this->_preAuthKey, $string ); + } + // end getPreAuth - - - /** - * hmacsha1 - * - * generate an HMAC using SHA1, required for preauth - * - * @since version 1.0 - * @access public - * @param int $key encryption key - * @param string $data data to encrypt - * @return string converted to hmac sha1 format - */ - private function hmacsha1 ($key, $data) - { - $blocksize = 64; - $hashfunc = 'sha1'; - if (strlen( $key ) > $blocksize) { - $key = pack( 'H*', $hashfunc( $key ) ); - } - $key = str_pad( $key, $blocksize, chr( 0x00 ) ); - $ipad = str_repeat( chr( 0x36 ), $blocksize ); - $opad = str_repeat( chr( 0x5c ), $blocksize ); - $hmac = pack( 'H*', $hashfunc( ($key ^ $opad) . pack( 'H*', $hashfunc( ($key ^ $ipad) . $data ) ) ) ); - return bin2hex( $hmac ); - } - + + + /** + * hmacsha1 + * + * generate an HMAC using SHA1, required for preauth + * + * @since version 1.0 + * @access public + * @param int $key encryption key + * @param string $data data to encrypt + * @return string converted to hmac sha1 format + */ + private function hmacsha1 ($key, $data) + { + $blocksize = 64; + $hashfunc = 'sha1'; + if (strlen( $key ) > $blocksize) { + $key = pack( 'H*', $hashfunc( $key ) ); + } + $key = str_pad( $key, $blocksize, chr( 0x00 ) ); + $ipad = str_repeat( chr( 0x36 ), $blocksize ); + $opad = str_repeat( chr( 0x5c ), $blocksize ); + $hmac = pack( 'H*', $hashfunc( ($key ^ $opad) . pack( 'H*', $hashfunc( ($key ^ $ipad) . $data ) ) ) ); + return bin2hex( $hmac ); + } + // end hmacsha1 - - - /** - * connect - * - * connect to the Zimbra SOAP service - * - * @since version 1.0 - * @access public - * @return array associative array of account information - */ - public function connect () - { - if ($this->_connected) { - return $this->_account_info; - } - $completeurl = $this->_protocol . $this->_server . $this->_path; - $this->_curl = curl_init(); - curl_setopt( $this->_curl, CURLOPT_URL, $this->_protocol . $this->_server . $this->_path ); - curl_setopt( $this->_curl, CURLOPT_POST, true ); - curl_setopt( $this->_curl, CURLOPT_RETURNTRANSFER, true ); - curl_setopt( $this->_curl, CURLOPT_SSL_VERIFYPEER, false ); - curl_setopt( $this->_curl, CURLOPT_SSL_VERIFYHOST, false ); - + + + /** + * connect + * + * connect to the Zimbra SOAP service + * + * @since version 1.0 + * @access public + * @return array associative array of account information + */ + public function connect () + { + if ($this->_connected) { + return $this->_account_info; + } + $completeurl = $this->_protocol . $this->_server . $this->_path; + $this->_curl = curl_init(); + curl_setopt( $this->_curl, CURLOPT_URL, $this->_protocol . $this->_server . $this->_path ); + curl_setopt( $this->_curl, CURLOPT_POST, true ); + curl_setopt( $this->_curl, CURLOPT_RETURNTRANSFER, true ); + curl_setopt( $this->_curl, CURLOPT_SSL_VERIFYPEER, false ); + curl_setopt( $this->_curl, CURLOPT_SSL_VERIFYHOST, false ); + //Apply proxy settings - $sysConf = System::getSystemConfiguration(); - if ($sysConf['proxy_host'] != '') { - curl_setopt( $this->_curl, CURLOPT_PROXY, $sysConf['proxy_host'] . ($sysConf['proxy_port'] != '' ? ':' . $sysConf['proxy_port'] : '') ); - if ($sysConf['proxy_port'] != '') { - curl_setopt( $this->_curl, CURLOPT_PROXYPORT, $sysConf['proxy_port'] ); - } - if ($sysConf['proxy_user'] != '') { - curl_setopt( $this->_curl, CURLOPT_PROXYUSERPWD, $sysConf['proxy_user'] . ($sysConf['proxy_pass'] != '' ? ':' . $sysConf['proxy_pass'] : '') ); - } - curl_setopt( $this->_curl, CURLOPT_HTTPHEADER, array ('Expect:') ); - } - - $preauth = $this->getPreAuth( $this->_username ); - $header = ''; - - if ($this->_admin) { + $sysConf = System::getSystemConfiguration(); + if ($sysConf['proxy_host'] != '') { + curl_setopt( $this->_curl, CURLOPT_PROXY, $sysConf['proxy_host'] . ($sysConf['proxy_port'] != '' ? ':' . $sysConf['proxy_port'] : '') ); + if ($sysConf['proxy_port'] != '') { + curl_setopt( $this->_curl, CURLOPT_PROXYPORT, $sysConf['proxy_port'] ); + } + if ($sysConf['proxy_user'] != '') { + curl_setopt( $this->_curl, CURLOPT_PROXYUSERPWD, $sysConf['proxy_user'] . ($sysConf['proxy_pass'] != '' ? ':' . $sysConf['proxy_pass'] : '') ); + } + curl_setopt( $this->_curl, CURLOPT_HTTPHEADER, array ('Expect:' + ) ); + } + + $preauth = $this->getPreAuth( $this->_username ); + $header = ''; + + if ($this->_admin) { $body = ' ' . $this->_admin_username . ' ' . $this->_admin_password . ' - '; - } else { + '; + } else { $body = ' ' . $this->_username . '@' . $this->_server1 . ' ' . $preauth . ' - '; - } - - $response = $this->soapRequest( $body, $header, true ); - if ($response) { - $tmp = $this->makeXMLTree( $response ); - $this->_account_info = $tmp['soap:Envelope'][0]['soap:Header'][0]['context'][0]['refresh'][0]['folder'][0]; - - $this->session_id = $this->extractSessionID( $response ); - $this->auth_token = $this->extractAuthToken( $response ); - - $this->_connected = true; - + '; + } + + $response = $this->soapRequest( $body, $header, true ); + if ($response) { + $tmp = $this->makeXMLTree( $response ); + $this->_account_info = $tmp['soap:Envelope'][0]['soap:Header'][0]['context'][0]['refresh'][0]['folder'][0]; + + $this->session_id = $this->extractSessionID( $response ); + $this->auth_token = $this->extractAuthToken( $response ); + + $this->_connected = true; + //return $this->_account_info; - return $this->_connected; - } else { - $this->_connected = false; - return false; - } - } - + return $this->_connected; + } else { + $this->_connected = false; + return false; + } + } + // end connect - - - /** - * administerUser - * - * set the user you are administering (experimental) - * - * @since version 1.0 - * @access public - * @param string $username username to administer - * @return boolean - */ - public function administerUser ($username) - { - if (! $this->_admin) { - return false; - } - - $this->_username = $username; - + + + /** + * administerUser + * + * set the user you are administering (experimental) + * + * @since version 1.0 + * @access public + * @param string $username username to administer + * @return boolean + */ + public function administerUser ($username) + { + if (! $this->_admin) { + return false; + } + + $this->_username = $username; + $body = ' ' . $this->_username . '@' . $this->_server . ' - '; - $response = $this->soapRequest( $body, $header ); - if ($response) { - $tmp = $this->makeXMLTree( $response ); - $this->_account_info = $tmp['soap:Envelope'][0]['soap:Header'][0]['context'][0]['refresh'][0]['folder'][0]; - - $this->session_id = $this->extractSessionID( $response ); - $this->auth_token = $this->extractAuthToken( $response ); - - return true; - } else { - return false; - } - } - + '; + $response = $this->soapRequest( $body, $header ); + if ($response) { + $tmp = $this->makeXMLTree( $response ); + $this->_account_info = $tmp['soap:Envelope'][0]['soap:Header'][0]['context'][0]['refresh'][0]['folder'][0]; + + $this->session_id = $this->extractSessionID( $response ); + $this->auth_token = $this->extractAuthToken( $response ); + + return true; + } else { + return false; + } + } + // end administerUser - - - /** - * getInfo - * - * generic function to get information on mailbox, preferences, attributes, properties, and more! - * - * @since version 1.0 - * @access public - * @param string $options options for info retrieval, defaults to null - * @return array information - */ - public function getInfo ($options = '') - { + + + /** + * getInfo + * + * generic function to get information on mailbox, preferences, attributes, properties, and more! + * + * @since version 1.0 + * @access public + * @param string $options options for info retrieval, defaults to null + * @return array information + */ + public function getInfo ($options = '') + { // valid sections: mbox,prefs,attrs,zimlets,props,idents,sigs,dsrcs,children - $option_string = $this->buildOptionString( $options ); - - $soap = ''; - $response = $this->soapRequest( $soap ); - if ($response) { - $array = $this->makeXMLTree( $response ); - return $array['soap:Envelope'][0]['soap:Body'][0]['GetInfoResponse'][0]; - } else { - return false; - } - } - + $option_string = $this->buildOptionString( $options ); + + $soap = ''; + $response = $this->soapRequest( $soap ); + if ($response) { + $array = $this->makeXMLTree( $response ); + return $array['soap:Envelope'][0]['soap:Body'][0]['GetInfoResponse'][0]; + } else { + return false; + } + } + // end getInfo - - - /** - * getMessages - * - * get the messages in folder, deafults to inbox - * - * @since version 1.0 - * @access public - * @param string $search folder to retrieve from, defaults to in:inbox - * @param array $options options to apply to retrieval - * @return array array of messages - */ - public function getMessages ($search = 'in:inbox', $options = array('limit' => 5, 'fetch' => 'none')) - { - $option_string = $this->buildOptionString( $options ); - + + + /** + * getMessages + * + * get the messages in folder, deafults to inbox + * + * @since version 1.0 + * @access public + * @param string $search folder to retrieve from, defaults to in:inbox + * @param array $options options to apply to retrieval + * @return array array of messages + */ + public function getMessages ($search = 'in:inbox', $options = array('limit' => 5, 'fetch' => 'none')) + { + $option_string = $this->buildOptionString( $options ); + $soap = ' ' . $search . ' - '; - $response = $this->soapRequest( $soap ); - if ($response) { - $array = $this->makeXMLTree( $response ); - return $array['soap:Envelope'][0]['soap:Body'][0]['SearchResponse'][0]; - } else { - return false; - } - } - + '; + $response = $this->soapRequest( $soap ); + if ($response) { + $array = $this->makeXMLTree( $response ); + return $array['soap:Envelope'][0]['soap:Body'][0]['SearchResponse'][0]; + } else { + return false; + } + } + // end getMessages - - - /** - * getContacts - * - * get the Contacts in folder, deafults to inbox - * - * @since version 1.0 - * @access public - * @param string $search folder to retrieve from, defaults to in:inbox - * @param array $options options to apply to retrieval - * @return array array of messages - */ - public function getContacts ($search = 'in:contacts', $options = array('limit' => 5, 'fetch' => 'none')) - { - $option_string = $this->buildOptionString( $options ); - + + + /** + * getContacts + * + * get the Contacts in folder, deafults to inbox + * + * @since version 1.0 + * @access public + * @param string $search folder to retrieve from, defaults to in:inbox + * @param array $options options to apply to retrieval + * @return array array of messages + */ + public function getContacts ($search = 'in:contacts', $options = array('limit' => 5, 'fetch' => 'none')) + { + $option_string = $this->buildOptionString( $options ); + $soap = ' ' . $search . ' - '; - $response = $this->soapRequest( $soap ); - if ($response) { - $array = $this->makeXMLTree( $response ); - return $array['soap:Envelope'][0]['soap:Body'][0]['SearchResponse'][0]; - } else { - return false; - } - } - + '; + $response = $this->soapRequest( $soap ); + if ($response) { + $array = $this->makeXMLTree( $response ); + return $array['soap:Envelope'][0]['soap:Body'][0]['SearchResponse'][0]; + } else { + return false; + } + } + // end getContacts - - + + /* getAppointments * * get the Appointments in folder @@ -379,27 +380,27 @@ class Zimbra * @param string $search folder to retrieve from * @param array $options options to apply to retrieval * @return array array of messages - */ - - public function getAppointments ($search = 'in:calendar', $options = array('limit' => 50, 'fetch' => 'none')) - { - $option_string = $this->buildOptionString( $options ); - + */ + + public function getAppointments ($search = 'in:calendar', $options = array('limit' => 50, 'fetch' => 'none')) + { + $option_string = $this->buildOptionString( $options ); + $soap = ' ' . $search . ' - '; - $response = $this->soapRequest( $soap ); - if ($response) { - $array = $this->makeXMLTree( $response ); - return $array['soap:Envelope'][0]['soap:Body'][0]['SearchResponse'][0]; - } else { - return false; - } - } - + '; + $response = $this->soapRequest( $soap ); + if ($response) { + $array = $this->makeXMLTree( $response ); + return $array['soap:Envelope'][0]['soap:Body'][0]['SearchResponse'][0]; + } else { + return false; + } + } + // end getAppointments - - + + /* getTasks * * get the Tasks in folder @@ -409,660 +410,661 @@ class Zimbra * @param string $search folder to retrieve from * @param array $options options to apply to retrieval * @return array array of messages - */ - - public function getTasks ($search = 'in:tasks', $options = array('limit' => 50, 'fetch' => 'none')) - { - $option_string = $this->buildOptionString( $options ); - + */ + + public function getTasks ($search = 'in:tasks', $options = array('limit' => 50, 'fetch' => 'none')) + { + $option_string = $this->buildOptionString( $options ); + $soap = ' ' . $search . ' - '; - $response = $this->soapRequest( $soap ); - if ($response) { - $array = $this->makeXMLTree( $response ); - return $array['soap:Envelope'][0]['soap:Body'][0]['SearchResponse'][0]; - } else { - return false; - } - } - + '; + $response = $this->soapRequest( $soap ); + if ($response) { + $array = $this->makeXMLTree( $response ); + return $array['soap:Envelope'][0]['soap:Body'][0]['SearchResponse'][0]; + } else { + return false; + } + } + // end getTasks - - - /** - * getMessageContent - * - * get the content from a message - * - * @since version 1.0 - * @access public - * @param int $id id number of message to retrieve content of - * @return array associative array with message content, valid for tasks, calendar entries, and email messages. - */ - public function getMessageContent ($id) - { + + + /** + * getMessageContent + * + * get the content from a message + * + * @since version 1.0 + * @access public + * @param int $id id number of message to retrieve content of + * @return array associative array with message content, valid for tasks, calendar entries, and email messages. + */ + public function getMessageContent ($id) + { $soap = ' * - '; - $response = $this->soapRequest( $soap ); - - if ($response) { - $array = $this->makeXMLTree( $response ); - $temp = $array['soap:Envelope'][0]['soap:Body'][0]['GetMsgResponse'][0]['m'][0]; - - $message = $temp['inv'][0]['comp'][0]; - + '; + $response = $this->soapRequest( $soap ); + + if ($response) { + $array = $this->makeXMLTree( $response ); + $temp = $array['soap:Envelope'][0]['soap:Body'][0]['GetMsgResponse'][0]['m'][0]; + + $message = $temp['inv'][0]['comp'][0]; + // content with no attachment - $message['content'] = $temp['mp'][0]['mp'][1]['content'][0]; - + $message['content'] = $temp['mp'][0]['mp'][1]['content'][0]; + // content with attachment - $message['content'] .= $temp['mp'][0]['mp'][0]['mp'][1]['content'][0]; - - return $message; - } else { - return false; - } - } - - /** - * getSubscribedCalendars - * - * get the calendars the user is subscribed to - * - * @since version 1.0 - * @access public - * @return array $subscribed - */ - public function getSubscribedCalendars () - { - $subscribed = array (); - if (is_array( $this->_account_info['link_attribute_name'] )) { - foreach ($this->_account_info['link_attribute_name'] as $i => $name) { - if ($this->_account_info['link_attribute_view'][$i] == 'appointment') { - $subscribed[$this->_account_info['link_attribute_id'][$i]] = $name; - } - } - } - return $subscribed; - } - + $message['content'] .= $temp['mp'][0]['mp'][0]['mp'][1]['content'][0]; + + return $message; + } else { + return false; + } + } + + /** + * getSubscribedCalendars + * + * get the calendars the user is subscribed to + * + * @since version 1.0 + * @access public + * @return array $subscribed + */ + public function getSubscribedCalendars () + { + $subscribed = array (); + if (is_array( $this->_account_info['link_attribute_name'] )) { + foreach ($this->_account_info['link_attribute_name'] as $i => $name) { + if ($this->_account_info['link_attribute_view'][$i] == 'appointment') { + $subscribed[$this->_account_info['link_attribute_id'][$i]] = $name; + } + } + } + return $subscribed; + } + // end getSubscribedCalendars - - - /** - * getSubscribedTaskLists - * - * get the task lists the user is subscribed to - * - * @since version 1.0 - * @access public - * @return array $subscribed or false - */ - public function getSubscribedTaskLists () - { - $subscribed = array (); - if (is_array( $this->_account_info['link_attribute_name'] )) { - foreach ($this->_account_info['link_attribute_name'] as $i => $name) { - if ($this->_account_info['link_attribute_view'][$i] == 'task') { - $subscribed[$this->_account_info['link_attribute_id'][$i]] = $name; - } - } - } - return $subscribed; - } - + + + /** + * getSubscribedTaskLists + * + * get the task lists the user is subscribed to + * + * @since version 1.0 + * @access public + * @return array $subscribed or false + */ + public function getSubscribedTaskLists () + { + $subscribed = array (); + if (is_array( $this->_account_info['link_attribute_name'] )) { + foreach ($this->_account_info['link_attribute_name'] as $i => $name) { + if ($this->_account_info['link_attribute_view'][$i] == 'task') { + $subscribed[$this->_account_info['link_attribute_id'][$i]] = $name; + } + } + } + return $subscribed; + } + // end getSubscribedCalendars - - - /** - * getFolder - * - * get a folder (experimental) - * - * @since version 1.0 - * @access public - * @param string $folder_options options for folder retrieval - * @return array $folder or false - */ - public function getFolder ($folderName, $folder_options = '') - { - + + + /** + * getFolder + * + * get a folder (experimental) + * + * @since version 1.0 + * @access public + * @param string $folder_options options for folder retrieval + * @return array $folder or false + */ + public function getFolder ($folderName, $folder_options = '') + { + //$folder_option_string = $this->buildOptionString($folder_options); - - + + $soap = ' - '; - $response = $this->soapRequest( $soap ); - if ($response) { - $array = $this->makeXMLTree( $response ); - - $folder = (is_array( $array['soap:Envelope'][0]['soap:Body'][0]['GetFolderResponse'][0]['folder'][0] )) ? $array['soap:Envelope'][0]['soap:Body'][0]['GetFolderResponse'][0]['folder'][0] : $array['soap:Envelope'][0]['soap:Body'][0]['GetFolderResponse'][0]; - - $folder['u'] = (! isset( $folder['u'] )) ? $folder['folder_attribute_u'][0] : $folder['u']; - $folder['n'] = (! isset( $folder['n'] )) ? $folder['folder_attribute_n'][0] : $folder['n']; - - return $folder; - } else { - return false; - } - } - + '; + $response = $this->soapRequest( $soap ); + if ($response) { + $array = $this->makeXMLTree( $response ); + + $folder = (is_array( $array['soap:Envelope'][0]['soap:Body'][0]['GetFolderResponse'][0]['folder'][0] )) ? $array['soap:Envelope'][0]['soap:Body'][0]['GetFolderResponse'][0]['folder'][0] : $array['soap:Envelope'][0]['soap:Body'][0]['GetFolderResponse'][0]; + + $folder['u'] = (! isset( $folder['u'] )) ? $folder['folder_attribute_u'][0] : $folder['u']; + $folder['n'] = (! isset( $folder['n'] )) ? $folder['folder_attribute_n'][0] : $folder['n']; + + return $folder; + } else { + return false; + } + } + // end getFolder - - - /** - * getPrefrences - * - * get preferences - * - * @since version 1.0 - * @access public - * @example example XML: [ ] - * @return array $prefs or false - */ - public function getPreferences () - { - $soap = ''; - $response = $this->soapRequest( $soap ); - if ($response) { - $prefs = array (); - $array = $this->makeXMLTree( $response ); - foreach ($array['soap:Envelope'][0]['soap:Body'][0]['GetPrefsResponse'][0]['pref'] as $k => $value) { - $prefs[$array['soap:Envelope'][0]['soap:Body'][0]['GetPrefsResponse'][0]['pref_attribute_name'][$k]] = $value; - } - return $prefs; - } else { - return false; - } - } - + + + /** + * getPrefrences + * + * get preferences + * + * @since version 1.0 + * @access public + * @example example XML: [ ] + * @return array $prefs or false + */ + public function getPreferences () + { + $soap = ''; + $response = $this->soapRequest( $soap ); + if ($response) { + $prefs = array (); + $array = $this->makeXMLTree( $response ); + foreach ($array['soap:Envelope'][0]['soap:Body'][0]['GetPrefsResponse'][0]['pref'] as $k => $value) { + $prefs[$array['soap:Envelope'][0]['soap:Body'][0]['GetPrefsResponse'][0]['pref_attribute_name'][$k]] = $value; + } + return $prefs; + } else { + return false; + } + } + // end getPreferences - - - /** - * setPrefrences - * - * modify preferences - * - * @since version 1.0 - * @access public - * @param string $options options to set the prefrences - * @example example XML: [{value}...]+ - * @return boolean - */ - public function setPreferences ($options = '') - { - $option_string = ''; - foreach ($options as $name => $value) { - $option_string .= '' . $value . ''; - } - + + + /** + * setPrefrences + * + * modify preferences + * + * @since version 1.0 + * @access public + * @param string $options options to set the prefrences + * @example example XML: [{value}...]+ + * @return boolean + */ + public function setPreferences ($options = '') + { + $option_string = ''; + foreach ($options as $name => $value) { + $option_string .= '' . $value . ''; + } + $soap = ' ' . $option_string . ' - '; - $response = $this->soapRequest( $soap ); - if ($response) { - return true; - } else { - return false; - } - } - + '; + $response = $this->soapRequest( $soap ); + if ($response) { + return true; + } else { + return false; + } + } + // end setPreferences - - - /** - * emailChannel - * - * build the email channel - * - * @since version 1.0 - * @access public - */ - public function emailChannel () - { - require_once 'xtemplate.php'; - $tpl = new XTemplate( '/web/pscpages/webapp/portal/channel/email/templates/index.tpl' ); - - $tpl->parse( 'main.transition' ); - - $total_messages = 0; - $unread_messages = 0; - - $messages = $this->getMessages( 'in:inbox' ); - if (is_array( $messages )) { - $more = $messages['more']; - foreach ($messages['m'] as $message) { - $clean_message = array (); - - $clean_message['subject'] = (isset( $message['su'][0] ) && $message['su'][0] != '') ? htmlentities( $message['su'][0] ) : '[None]'; - $clean_message['subject'] = (strlen( $clean_message['subject'] ) > 20) ? substr( $clean_message['subject'], 0, 17 ) . '...' : $clean_message['subject']; - - $clean_message['body_fragment'] = $message['fr'][0]; - $clean_message['from_email'] = $message['e_attribute_a'][0]; - $clean_message['from'] = ($message['e_attribute_p'][0]) ? htmlspecialchars( $message['e_attribute_p'][0] ) : $clean_message['from_email']; - $clean_message['size'] = $this->makeBytesPretty( $message['s'], 40 * 1024 * 1024 ); - $clean_message['date'] = date( 'n/j/y', ($message['d'] / 1000) ); - $clean_message['id'] = $message['id']; - $clean_message['url'] = 'http://go.plymouth.edu/mymail/msg/' . $clean_message['id']; - - $clean_message['attachment'] = false; - $clean_message['status'] = 'read'; - $clean_message['deleted'] = false; - $clean_message['flagged'] = false; - if (isset( $message['f'] )) { - $clean_message['attachment'] = (strpos( $message['f'], 'a' ) !== false) ? true : false; - $clean_message['status'] = (strpos( $message['f'], 'u' ) !== false) ? 'unread' : 'read'; - ; - $clean_message['deleted'] = (strpos( $message['f'], '2' ) !== false) ? true : false; - $clean_message['flagged'] = (strpos( $message['f'], 'f' ) !== false) ? true : false; - } - - $tpl->assign( 'message', $clean_message ); - $tpl->parse( 'main.message' ); - } - $inbox = $this->getFolder( array ('l' => 2 - ) ); - - $total_messages = (int) $inbox['n']; - $unread_messages = (int) $inbox['u']; - } - - $tpl->assign( 'total_messages', $total_messages ); - $tpl->assign( 'unread_messages', $unread_messages ); - - $info = $this->getInfo( array ('sections' => 'mbox') ); - if (is_array( $info['attrs'][0]['attr_attribute_name'] )) { - $quota = $info['attrs'][0]['attr'][array_search( 'zimbraMailQuota', $info['attrs'][0]['attr_attribute_name'] )]; - $size_text = $this->makeBytesPretty( $info['used'][0], ($quota * 0.75) ) . ' out of ' . $this->makeBytesPretty( $quota ); - $tpl->assign( 'size', $size_text ); - } - + + + /** + * emailChannel + * + * build the email channel + * + * @since version 1.0 + * @access public + */ + public function emailChannel () + { + require_once 'xtemplate.php'; + $tpl = new XTemplate( '/web/pscpages/webapp/portal/channel/email/templates/index.tpl' ); + + $tpl->parse( 'main.transition' ); + + $total_messages = 0; + $unread_messages = 0; + + $messages = $this->getMessages( 'in:inbox' ); + if (is_array( $messages )) { + $more = $messages['more']; + foreach ($messages['m'] as $message) { + $clean_message = array (); + + $clean_message['subject'] = (isset( $message['su'][0] ) && $message['su'][0] != '') ? htmlentities( $message['su'][0] ) : '[None]'; + $clean_message['subject'] = (strlen( $clean_message['subject'] ) > 20) ? substr( $clean_message['subject'], 0, 17 ) . '...' : $clean_message['subject']; + + $clean_message['body_fragment'] = $message['fr'][0]; + $clean_message['from_email'] = $message['e_attribute_a'][0]; + $clean_message['from'] = ($message['e_attribute_p'][0]) ? htmlspecialchars( $message['e_attribute_p'][0] ) : $clean_message['from_email']; + $clean_message['size'] = $this->makeBytesPretty( $message['s'], 40 * 1024 * 1024 ); + $clean_message['date'] = date( 'n/j/y', ($message['d'] / 1000) ); + $clean_message['id'] = $message['id']; + $clean_message['url'] = 'http://go.plymouth.edu/mymail/msg/' . $clean_message['id']; + + $clean_message['attachment'] = false; + $clean_message['status'] = 'read'; + $clean_message['deleted'] = false; + $clean_message['flagged'] = false; + if (isset( $message['f'] )) { + $clean_message['attachment'] = (strpos( $message['f'], 'a' ) !== false) ? true : false; + $clean_message['status'] = (strpos( $message['f'], 'u' ) !== false) ? 'unread' : 'read'; + ; + $clean_message['deleted'] = (strpos( $message['f'], '2' ) !== false) ? true : false; + $clean_message['flagged'] = (strpos( $message['f'], 'f' ) !== false) ? true : false; + } + + $tpl->assign( 'message', $clean_message ); + $tpl->parse( 'main.message' ); + } + $inbox = $this->getFolder( array ('l' => 2 + ) ); + + $total_messages = (int) $inbox['n']; + $unread_messages = (int) $inbox['u']; + } + + $tpl->assign( 'total_messages', $total_messages ); + $tpl->assign( 'unread_messages', $unread_messages ); + + $info = $this->getInfo( array ('sections' => 'mbox' + ) ); + if (is_array( $info['attrs'][0]['attr_attribute_name'] )) { + $quota = $info['attrs'][0]['attr'][array_search( 'zimbraMailQuota', $info['attrs'][0]['attr_attribute_name'] )]; + $size_text = $this->makeBytesPretty( $info['used'][0], ($quota * 0.75) ) . ' out of ' . $this->makeBytesPretty( $quota ); + $tpl->assign( 'size', $size_text ); + } + /* include_once 'portal_functions.php'; $roles = getRoles($this->_username); if(in_array('faculty', $roles) || in_array('employee', $roles)) { $tpl->parse('main.away_message'); - } */ - - $tpl->parse( 'main' ); - $tpl->out( 'main' ); - } - + } */ + + $tpl->parse( 'main' ); + $tpl->out( 'main' ); + } + // end emailChannel - - - /** - * builOptionString - * - * make an option string that will be placed as attributes inside an XML tag - * - * @since version 1.0 - * @access public - * @param array $options array of options to be parsed into a string - * @return string $options_string - */ - protected function buildOptionString ($options) - { - $options_string = ''; - foreach ($options as $k => $v) { - $options_string .= ' ' . $k . '="' . $v . '"'; - } - return $options_string; - } - + + + /** + * builOptionString + * + * make an option string that will be placed as attributes inside an XML tag + * + * @since version 1.0 + * @access public + * @param array $options array of options to be parsed into a string + * @return string $options_string + */ + protected function buildOptionString ($options) + { + $options_string = ''; + foreach ($options as $k => $v) { + $options_string .= ' ' . $k . '="' . $v . '"'; + } + return $options_string; + } + // end buildOptionString - - - /** - * extractAuthToken - * - * get the Auth Token out of the XML - * - * @since version 1.0 - * @access public - * @param string $xml xml to have the auth token pulled from - * @return string $auth_token - */ - private function extractAuthToken ($xml) - { - $auth_token = strstr( $xml, "" ); - $auth_token = substr( $auth_token, 1, strpos( $auth_token, "<" ) - 1 ); - return $auth_token; - } - - /** - * extractSessionID - * - * get the Session ID out of the XML - * - * @since version 1.0 - * @access public - * @param string $xml xml to have the session id pulled from - * @return int $session_id - */ - private function extractSessionID ($xml) - { - + + + /** + * extractAuthToken + * + * get the Auth Token out of the XML + * + * @since version 1.0 + * @access public + * @param string $xml xml to have the auth token pulled from + * @return string $auth_token + */ + private function extractAuthToken ($xml) + { + $auth_token = strstr( $xml, "" ); + $auth_token = substr( $auth_token, 1, strpos( $auth_token, "<" ) - 1 ); + return $auth_token; + } + + /** + * extractSessionID + * + * get the Session ID out of the XML + * + * @since version 1.0 + * @access public + * @param string $xml xml to have the session id pulled from + * @return int $session_id + */ + private function extractSessionID ($xml) + { + //for testing purpose we are extracting lifetime instead of sessionid //$session_id = strstr($xml, "" ); - $session_id = substr( $session_id, 1, strpos( $session_id, "<" ) - 1 ); - return $session_id; - } - + $session_id = strstr( $xml, "" ); + $session_id = substr( $session_id, 1, strpos( $session_id, "<" ) - 1 ); + return $session_id; + } + // end extractSessionID - - - /** - * extractErrorCode - * - * get the error code out of the XML - * - * @since version 1.0 - * @access public - * @param string $xml xml to have the error code pulled from - * @return int $session_id - */ - private function extractErrorCode ($xml) - { - $session_id = strstr( $xml, "" ); - $session_id = substr( $session_id, 1, strpos( $session_id, "<" ) - 1 ); - return $session_id; - } - + + + /** + * extractErrorCode + * + * get the error code out of the XML + * + * @since version 1.0 + * @access public + * @param string $xml xml to have the error code pulled from + * @return int $session_id + */ + private function extractErrorCode ($xml) + { + $session_id = strstr( $xml, "" ); + $session_id = substr( $session_id, 1, strpos( $session_id, "<" ) - 1 ); + return $session_id; + } + // end extractErrorCode - - - /** - * makeBytesPretty - * - * turns byte numbers into a more readable format with KB or MB - * - * @since version 1.0 - * @access public - * @param int $bytes bytes to be worked with - * @param boolean $redlevel - * @return int $size - */ - private function makeBytesPretty ($bytes, $redlevel = false) - { - if ($bytes < 1024) { - $size = $bytes . ' B'; - } elseif ($bytes < 1024 * 1024) { - $size = round( $bytes / 1024, 1 ) . ' KB'; - } else { - $size = round( ($bytes / 1024) / 1024, 1 ) . ' MB'; - } - if ($redlevel && $bytes > $redlevel) { - $size = '' . $size . ''; - } - - return $size; - } - + + + /** + * makeBytesPretty + * + * turns byte numbers into a more readable format with KB or MB + * + * @since version 1.0 + * @access public + * @param int $bytes bytes to be worked with + * @param boolean $redlevel + * @return int $size + */ + private function makeBytesPretty ($bytes, $redlevel = false) + { + if ($bytes < 1024) { + $size = $bytes . ' B'; + } elseif ($bytes < 1024 * 1024) { + $size = round( $bytes / 1024, 1 ) . ' KB'; + } else { + $size = round( ($bytes / 1024) / 1024, 1 ) . ' MB'; + } + if ($redlevel && $bytes > $redlevel) { + $size = '' . $size . ''; + } + + return $size; + } + // end makeBytesPretty - - - /** - * message - * - * if debug is on, show a message - * - * @since version 1.0 - * @access public - * @param string $message message for debug - */ - protected function message ($message) - { - if ($this->debug) { - echo $message; - } - } - + + + /** + * message + * + * if debug is on, show a message + * + * @since version 1.0 + * @access public + * @param string $message message for debug + */ + protected function message ($message) + { + if ($this->debug) { + echo $message; + } + } + // end message - - - /** - * soapRequest - * - * make a SOAP request to Zimbra server, returns the XML - * - * @since version 1.0 - * @access public - * @param string $body body of page - * @param boolean $header - * @param boolean $footer - * @return string $response - */ - protected function soapRequest ($body, $header = false, $connecting = false) - { - if (! $connecting && ! $this->_connected) { - throw new Exception( 'zimbra.class: soapRequest called without a connection to Zimbra server' ); - } - - if ($header == false) { + + + /** + * soapRequest + * + * make a SOAP request to Zimbra server, returns the XML + * + * @since version 1.0 + * @access public + * @param string $body body of page + * @param boolean $header + * @param boolean $footer + * @return string $response + */ + protected function soapRequest ($body, $header = false, $connecting = false) + { + if (! $connecting && ! $this->_connected) { + throw new Exception( 'zimbra.class: soapRequest called without a connection to Zimbra server' ); + } + + if ($header == false) { $header = ' ' . $this->auth_token . ' ' . $this->session_id . ' - '; - } - + '; + } + $soap_message = ' ' . $header . ' ' . $body . ' - '; - $this->message( 'SOAP message:' ); - - curl_setopt( $this->_curl, CURLOPT_POSTFIELDS, $soap_message ); - - if (! ($response = curl_exec( $this->_curl ))) { - $this->error = 'ERROR: curl_exec - (' . curl_errno( $this->_curl ) . ') ' . curl_error( $this->_curl ); - return false; - } elseif (strpos( $response, '' ) !== false) { - $error_code = $this->extractErrorCode( $response ); - $this->error = 'ERROR: ' . $error_code . ':'; - $this->message( $this->error ); - $aError = array ('error' => $error_code - ); - return $aError; + '; + $this->message( 'SOAP message:' ); + + curl_setopt( $this->_curl, CURLOPT_POSTFIELDS, $soap_message ); + + if (! ($response = curl_exec( $this->_curl ))) { + $this->error = 'ERROR: curl_exec - (' . curl_errno( $this->_curl ) . ') ' . curl_error( $this->_curl ); + return false; + } elseif (strpos( $response, '' ) !== false) { + $error_code = $this->extractErrorCode( $response ); + $this->error = 'ERROR: ' . $error_code . ':'; + $this->message( $this->error ); + $aError = array ('error' => $error_code + ); + return $aError; //return false; - } - $this->message( 'SOAP response:

' ); - - $this->_num_soap_calls ++; - return $response; - } - + } + $this->message( 'SOAP response:

' ); + + $this->_num_soap_calls ++; + return $response; + } + // end soapRequest - - - /** - * getNumSOAPCalls - * - * get the number of SOAP calls that have been made. This is for debugging and performancing - * - * @since version 1.0 - * @access public - * @return int $this->_num_soap_calls - */ - public function getNumSOAPCalls () - { - return $this->_num_soap_calls; - } - + + + /** + * getNumSOAPCalls + * + * get the number of SOAP calls that have been made. This is for debugging and performancing + * + * @since version 1.0 + * @access public + * @return int $this->_num_soap_calls + */ + public function getNumSOAPCalls () + { + return $this->_num_soap_calls; + } + // end getNumSOAPCalls - - - /** - * makeXMLTree - * - * turns XML into an array - * - * @since version 1.0 - * @access public - * @param string $data data to be built into an array - * @return array $ret - */ - protected function makeXMLTree ($data) - { + + + /** + * makeXMLTree + * + * turns XML into an array + * + * @since version 1.0 + * @access public + * @param string $data data to be built into an array + * @return array $ret + */ + protected function makeXMLTree ($data) + { // create parser - $parser = xml_parser_create(); - xml_parser_set_option( $parser, XML_OPTION_CASE_FOLDING, 0 ); - xml_parser_set_option( $parser, XML_OPTION_SKIP_WHITE, 1 ); - xml_parse_into_struct( $parser, $data, $values, $tags ); - xml_parser_free( $parser ); - + $parser = xml_parser_create(); + xml_parser_set_option( $parser, XML_OPTION_CASE_FOLDING, 0 ); + xml_parser_set_option( $parser, XML_OPTION_SKIP_WHITE, 1 ); + xml_parse_into_struct( $parser, $data, $values, $tags ); + xml_parser_free( $parser ); + // we store our path here - $hash_stack = array (); - + $hash_stack = array (); + // this is our target - $ret = array (); - foreach ($values as $key => $val) { - - switch ($val['type']) { - case 'open': - array_push( $hash_stack, $val['tag'] ); - if (isset( $val['attributes'] )) - $ret = $this->composeArray( $ret, $hash_stack, $val['attributes'] ); - else - $ret = $this->composeArray( $ret, $hash_stack ); - break; - - case 'close': - array_pop( $hash_stack ); - break; - - case 'complete': - array_push( $hash_stack, $val['tag'] ); - $ret = $this->composeArray( $ret, $hash_stack, $val['value'] ); - array_pop( $hash_stack ); - + $ret = array (); + foreach ($values as $key => $val) { + + switch ($val['type']) { + case 'open': + array_push( $hash_stack, $val['tag'] ); + if (isset( $val['attributes'] )) { + $ret = $this->composeArray( $ret, $hash_stack, $val['attributes'] ); + } else { + $ret = $this->composeArray( $ret, $hash_stack ); + } + break; + case 'close': + array_pop( $hash_stack ); + break; + case 'complete': + array_push( $hash_stack, $val['tag'] ); + $ret = $this->composeArray( $ret, $hash_stack, $val['value'] ); + array_pop( $hash_stack ); + // handle attributes - if (isset( $val['attributes'] )) { - foreach ($val['attributes'] as $a_k => $a_v) { - $hash_stack[] = $val['tag'] . '_attribute_' . $a_k; - $ret = $this->composeArray( $ret, $hash_stack, $a_v ); - array_pop( $hash_stack ); - } - } - - break; - } - } - - return $ret; - } - + if (isset( $val['attributes'] )) { + foreach ($val['attributes'] as $a_k => $a_v) { + $hash_stack[] = $val['tag'] . '_attribute_' . $a_k; + $ret = $this->composeArray( $ret, $hash_stack, $a_v ); + array_pop( $hash_stack ); + } + } + break; + } + } + return $ret; + } + // end makeXMLTree - - - /** - * &composeArray - * - * function used exclusively by makeXMLTree to help turn XML into an array - * - * @since version 1.0 - * @access public - * @param array $array - * @param array $elements - * @param array $value - * @return array $array - */ - private function &composeArray ($array, $elements, $value = array()) - { - global $XML_LIST_ELEMENTS; - + + + /** + * &composeArray + * + * function used exclusively by makeXMLTree to help turn XML into an array + * + * @since version 1.0 + * @access public + * @param array $array + * @param array $elements + * @param array $value + * @return array $array + */ + private function &composeArray ($array, $elements, $value = array()) + { + global $XML_LIST_ELEMENTS; + // get current element - $element = array_shift( $elements ); - + $element = array_shift( $elements ); + // does the current element refer to a list - if (sizeof( $elements ) > 0) { - $array[$element][sizeof( $array[$element] ) - 1] = &$this->composeArray( $array[$element][sizeof( $array[$element] ) - 1], $elements, $value ); - } else { // if (is_array($value)) - $array[$element][sizeof( $array[$element] )] = $value; - } - - return $array; - } - + if (sizeof( $elements ) > 0) { + $array[$element][sizeof( $array[$element] ) - 1] = &$this->composeArray( $array[$element][sizeof( $array[$element] ) - 1], $elements, $value ); + } else { + // if (is_array($value)) + $array[$element][sizeof( $array[$element] )] = $value; + } + + return $array; + } + // end composeArray - - - /** - * noop - * - * keeps users session alive - * - * @since version 1.0 - * @access public - * @return string xml response from the noop - */ - public function noop () - { - return $this->soapRequest( '' ); - } - - /** - * addAppointments - * - * add appointments in a calendar - * - * @since version 1.0 - * @access public - * @param - * - * @return - * - */ - public function addAppointment ($serializeOp1) - { - $unserializeOp1 = unserialize( $serializeOp1 ); - - $username = $unserializeOp1['username']; - $subject = $unserializeOp1['subject']; - $appointmentName = $unserializeOp1['appointmentName']; - $friendlyName = $unserializeOp1['friendlyName']; - $userEmail = $unserializeOp1['userEmail']; - $domainName = $unserializeOp1['domainName']; - $schedule = $unserializeOp1['schedule']; - $cutype = $unserializeOp1['cutype']; - $allDay = $unserializeOp1['allDay']; - $isOrg = $unserializeOp1['isOrg']; - $rsvp = $unserializeOp1['rsvp']; - $atFriendlyName = $unserializeOp1['atFriendlyName']; - $role = $unserializeOp1['role']; - $location = $unserializeOp1['location']; - $ptst = $unserializeOp1['ptst']; - - $dateFormat = $allDay == "1" ? "Ymd" : "Ymd\THis"; - $startDate = date( $dateFormat, strtotime( $unserializeOp1['startDate'] ) ); - $endDate = date( $dateFormat, strtotime( $unserializeOp1['endDate'] ) ); - $timeZone = $allDay == "1" ? "" : $unserializeOp1['tz']; - - $explodeEmail = explode( ';', $userEmail ); - $explodeFriendlyName = explode( ';', $atFriendlyName ); - $countExplodeEmail = count( $explodeEmail ); - + + + /** + * noop + * + * keeps users session alive + * + * @since version 1.0 + * @access public + * @return string xml response from the noop + */ + public function noop () + { + return $this->soapRequest( '' ); + } + + /** + * addAppointments + * + * add appointments in a calendar + * + * @since version 1.0 + * @access public + * @param + * + * + * @return + * + * + */ + public function addAppointment ($serializeOp1) + { + $unserializeOp1 = unserialize( $serializeOp1 ); + + $username = $unserializeOp1['username']; + $subject = $unserializeOp1['subject']; + $appointmentName = $unserializeOp1['appointmentName']; + $friendlyName = $unserializeOp1['friendlyName']; + $userEmail = $unserializeOp1['userEmail']; + $domainName = $unserializeOp1['domainName']; + $schedule = $unserializeOp1['schedule']; + $cutype = $unserializeOp1['cutype']; + $allDay = $unserializeOp1['allDay']; + $isOrg = $unserializeOp1['isOrg']; + $rsvp = $unserializeOp1['rsvp']; + $atFriendlyName = $unserializeOp1['atFriendlyName']; + $role = $unserializeOp1['role']; + $location = $unserializeOp1['location']; + $ptst = $unserializeOp1['ptst']; + + $dateFormat = $allDay == "1" ? "Ymd" : "Ymd\THis"; + $startDate = date( $dateFormat, strtotime( $unserializeOp1['startDate'] ) ); + $endDate = date( $dateFormat, strtotime( $unserializeOp1['endDate'] ) ); + $timeZone = $allDay == "1" ? "" : $unserializeOp1['tz']; + + $explodeEmail = explode( ';', $userEmail ); + $explodeFriendlyName = explode( ';', $atFriendlyName ); + $countExplodeEmail = count( $explodeEmail ); + $soap = ' - ' . $subject . ''; - for ($i = 0; $i < $countExplodeEmail; $i ++) { - $soap .= ''; - } + ' . $subject . ''; + for ($i = 0; $i < $countExplodeEmail; $i ++) { + $soap .= ''; + } $soap .= ' - '; - for ($i = 0; $i < $countExplodeEmail; $i ++) { - $soap .= ''; - } + '; + for ($i = 0; $i < $countExplodeEmail; $i ++) { + $soap .= ''; + } $soap .= ' @@ -1073,47 +1075,47 @@ class Zimbra - '; + '; //G::pr($soap);die; - $response = $this->soapRequest( $soap ); - if ($response) { - $array = $this->makeXMLTree( $response ); - - return $array['soap:Envelope'][0]['soap:Body'][0]['CreateAppointmentResponse']; - } else { - return false; - } - } - + $response = $this->soapRequest( $soap ); + if ($response) { + $array = $this->makeXMLTree( $response ); + + return $array['soap:Envelope'][0]['soap:Body'][0]['CreateAppointmentResponse']; + } else { + return false; + } + } + // end addAppointments - - - /** - * addTask - * - * add Task in a Task Tab - * - * @since version 1.0 - * @access public - * @param array $options array of options to apply to retrieval from calendar - * @return array associative array of appointments - */ - public function addTask ($serializeOp1) - { - $unserializeOp1 = unserialize( $serializeOp1 ); - - $subject = $unserializeOp1['subject']; - $taskName = $unserializeOp1['taskName']; - $friendlyName = $unserializeOp1['friendlyName']; - $userEmail = $unserializeOp1['userEmail']; - $priority = $unserializeOp1['priority']; - $allDay = $unserializeOp1['allDay']; - $class = $unserializeOp1['class']; - $location = $unserializeOp1['location']; - $dueDate = date( "Ymd", strtotime( $unserializeOp1['dueDate'] ) ); - $status = $unserializeOp1['status']; - $percent = $unserializeOp1['percent']; - + + + /** + * addTask + * + * add Task in a Task Tab + * + * @since version 1.0 + * @access public + * @param array $options array of options to apply to retrieval from calendar + * @return array associative array of appointments + */ + public function addTask ($serializeOp1) + { + $unserializeOp1 = unserialize( $serializeOp1 ); + + $subject = $unserializeOp1['subject']; + $taskName = $unserializeOp1['taskName']; + $friendlyName = $unserializeOp1['friendlyName']; + $userEmail = $unserializeOp1['userEmail']; + $priority = $unserializeOp1['priority']; + $allDay = $unserializeOp1['allDay']; + $class = $unserializeOp1['class']; + $location = $unserializeOp1['location']; + $dueDate = date( "Ymd", strtotime( $unserializeOp1['dueDate'] ) ); + $status = $unserializeOp1['status']; + $percent = $unserializeOp1['percent']; + $soap = ' ' . $subject . ' @@ -1135,44 +1137,46 @@ class Zimbra - '; - $response = $this->soapRequest( $soap ); - - if ($response) { - $array = $this->makeXMLTree( $response ); - + '; + $response = $this->soapRequest( $soap ); + + if ($response) { + $array = $this->makeXMLTree( $response ); + //return $array['soap:Envelope'][0]['soap:Body'][0]['BatchResponse'][0]['CreateTaskRequest'][0]['appt']; - return $array['soap:Envelope'][0]['soap:Body'][0]['CreateTaskResponse']; - } else { - return false; - } - } - + return $array['soap:Envelope'][0]['soap:Body'][0]['CreateTaskResponse']; + } else { + return false; + } + } + // end addTask - - - /** - * addContacts - * - * add contact in a AddressBook - * - * @since version 1.0 - * @access public - * @param - * - * @return - * - */ - public function addContacts ($serializeOp1) - { - $unserializeOp1 = unserialize( $serializeOp1 ); - - $firstName = $unserializeOp1['firstName']; - $lastName = $unserializeOp1['lastName']; - $email = $unserializeOp1['email']; - $otherData = $unserializeOp1['otherData']; - $otherDataValue = $unserializeOp1['otherDataValue']; - + + + /** + * addContacts + * + * add contact in a AddressBook + * + * @since version 1.0 + * @access public + * @param + * + * + * @return + * + * + */ + public function addContacts ($serializeOp1) + { + $unserializeOp1 = unserialize( $serializeOp1 ); + + $firstName = $unserializeOp1['firstName']; + $lastName = $unserializeOp1['lastName']; + $email = $unserializeOp1['email']; + $otherData = $unserializeOp1['otherData']; + $otherDataValue = $unserializeOp1['otherDataValue']; + $soap = ' ' . $firstName . ' @@ -1180,192 +1184,198 @@ class Zimbra ' . $email . ' ' . $otherDataValue . ' - '; - - $response = $this->soapRequest( $soap ); - if ($response) { - $array = $this->makeXMLTree( $response ); - - return $array['soap:Envelope'][0]['soap:Body'][0]['CreateContactResponse']; - } else { - return false; - } - } - + '; + + $response = $this->soapRequest( $soap ); + if ($response) { + $array = $this->makeXMLTree( $response ); + + return $array['soap:Envelope'][0]['soap:Body'][0]['CreateContactResponse']; + } else { + return false; + } + } + // end addContacts - /** - * addFolder - * - * add Folder in a BriefCase - * - * @since version 1.0 - * @access public - * @param - * - * @return - * - */ - - public function addFolder ($serializeOp1) - { - $unserializeOp1 = unserialize( $serializeOp1 ); - - $folderName = $unserializeOp1['folderName']; - $folderColor = $unserializeOp1['color']; - + /** + * addFolder + * + * add Folder in a BriefCase + * + * @since version 1.0 + * @access public + * @param + * + * + * @return + * + * + */ + + public function addFolder ($serializeOp1) + { + $unserializeOp1 = unserialize( $serializeOp1 ); + + $folderName = $unserializeOp1['folderName']; + $folderColor = $unserializeOp1['color']; + $soap = ' - '; - - $response = $this->soapRequest( $soap ); - if ($response) { - $array = $this->makeXMLTree( $response ); - - return $array['soap:Envelope'][0]['soap:Body'][0]['CreateFolderResponse']; - } else { - return false; - } - } - + '; + + $response = $this->soapRequest( $soap ); + if ($response) { + $array = $this->makeXMLTree( $response ); + + return $array['soap:Envelope'][0]['soap:Body'][0]['CreateFolderResponse']; + } else { + return false; + } + } + // end addFolder - /** - * uploadDocument - * - * add Folder in a BriefCase - * - * @since version 1.0 - * @access public - * @param - * - * @return - * - */ - - public function upload ($folderId, $UploadId, $fileVersion = '', $docId = '') - { - if ($fileVersion == '' && $docId == '') { + /** + * uploadDocument + * + * add Folder in a BriefCase + * + * @since version 1.0 + * @access public + * @param + * + * + * @return + * + * + */ + + public function upload ($folderId, $UploadId, $fileVersion = '', $docId = '') + { + if ($fileVersion == '' && $docId == '') { $soap = ' - '; - } else { + '; + } else { $soap = ' - '; - } - - $response = $this->soapRequest( $soap ); - if (is_array( $response )) { - if (isset( $response['error'] )) { - return $response; - } - } else { - $array = $this->makeXMLTree( $response ); - - return $array['soap:Envelope'][0]['soap:Body'][0]['SaveDocumentResponse']; - } - } - + '; + } + + $response = $this->soapRequest( $soap ); + if (is_array( $response )) { + if (isset( $response['error'] )) { + return $response; + } + } else { + $array = $this->makeXMLTree( $response ); + + return $array['soap:Envelope'][0]['soap:Body'][0]['SaveDocumentResponse']; + } + } + // end uploadDocument - - - /** - * getDocId - * - * Get ID of File in Zimbra. - * - * @since version 1.0 - * @access public - * @param - * - * @return - * - */ - public function getDocId ($folderId, $fileName) - { + + + /** + * getDocId + * + * Get ID of File in Zimbra. + * + * @since version 1.0 + * @access public + * @param + * + * + * @return + * + * + */ + public function getDocId ($folderId, $fileName) + { $soap = ' - '; - - $response = $this->soapRequest( $soap ); - if (is_array( $response )) { - if ($response['error']) { - return false; - } - } else { - $array = $this->makeXMLTree( $response ); - - return $array['soap:Envelope'][0]['soap:Body'][0]['GetItemResponse'][0]; - } - } - + '; + + $response = $this->soapRequest( $soap ); + if (is_array( $response )) { + if ($response['error']) { + return false; + } + } else { + $array = $this->makeXMLTree( $response ); + + return $array['soap:Envelope'][0]['soap:Body'][0]['GetItemResponse'][0]; + } + } + // end getDocId -} - +} + // end Zimbra class // annoying sorting functions for getTasks... // I don't know how to make usort calls to internal OO functions // if someone knows how, please fix this :) - - -/** - * zimbra_startSort - * - * sort of zimbra elements - * - * @since version 1.0 - * @access public - * @param array $task_a - * @param array $task_b - * @return int (($task_a['dueDate']-$task_a['dur']) < ($task_b['dueDate']-$task_b['dur'])) ? -1 : 1 - */ -function zimbra_startSort ($task_a, $task_b) -{ - if (($task_a['dueDate'] - $task_a['dur']) == ($task_b['dueDate'] - $task_b['dur'])) { - return ($task_a['name'] < $task_b['name']) ? - 1 : 1; - } - return (($task_a['dueDate'] - $task_a['dur']) < ($task_b['dueDate'] - $task_b['dur'])) ? - 1 : 1; -} - -/** - * zimbra_dueSort - * - * sort by dueDate - * - * @since version 1.0 - * @access public - * @param array $task_a - * @param array $task_b - * @return int ($task_a['dueDate'] < $task_b['dueDate']) ? -1 : 1 - */ -function zimbra_dueSort ($task_a, $task_b) -{ - if ($task_a['dueDate'] == $task_b['dueDate']) { - return ($task_a['name'] < $task_b['name']) ? - 1 : 1; - } - return ($task_a['dueDate'] < $task_b['dueDate']) ? - 1 : 1; -} - -/** - * zimbra_nameSort - * - * sort by name - * - * @since version 1.0 - * @access public - * @param array $task_a - * @param array $task_b - * @return int ($task_a['name'] < $task_b['name']) ? -1 : 1 - */ -function zimbra_nameSort ($task_a, $task_b) -{ - if ($task_a['name'] == $task_b['name']) { - return 0; - } - return ($task_a['name'] < $task_b['name']) ? - 1 : 1; -} - + + +/** + * zimbra_startSort + * + * sort of zimbra elements + * + * @since version 1.0 + * @access public + * @param array $task_a + * @param array $task_b + * @return int (($task_a['dueDate']-$task_a['dur']) < ($task_b['dueDate']-$task_b['dur'])) ? -1 : 1 + */ +function zimbra_startSort ($task_a, $task_b) +{ + if (($task_a['dueDate'] - $task_a['dur']) == ($task_b['dueDate'] - $task_b['dur'])) { + return ($task_a['name'] < $task_b['name']) ? - 1 : 1; + } + return (($task_a['dueDate'] - $task_a['dur']) < ($task_b['dueDate'] - $task_b['dur'])) ? - 1 : 1; +} + +/** + * zimbra_dueSort + * + * sort by dueDate + * + * @since version 1.0 + * @access public + * @param array $task_a + * @param array $task_b + * @return int ($task_a['dueDate'] < $task_b['dueDate']) ? -1 : 1 + */ +function zimbra_dueSort ($task_a, $task_b) +{ + if ($task_a['dueDate'] == $task_b['dueDate']) { + return ($task_a['name'] < $task_b['name']) ? - 1 : 1; + } + return ($task_a['dueDate'] < $task_b['dueDate']) ? - 1 : 1; +} + +/** + * zimbra_nameSort + * + * sort by name + * + * @since version 1.0 + * @access public + * @param array $task_a + * @param array $task_b + * @return int ($task_a['name'] < $task_b['name']) ? -1 : 1 + */ +function zimbra_nameSort ($task_a, $task_b) +{ + if ($task_a['name'] == $task_b['name']) { + return 0; + } + return ($task_a['name'] < $task_b['name']) ? - 1 : 1; +} +