Exemple #1
0
function FupdateAPPDATATYPO3($APP_UID, $new = 0)
{
    $_SESSION["PM_RUN_OUTSIDE_MAIN_APP"] = true;
    G::LoadClass("case");
    $caseInstance = new Cases();
    $newFields = $caseInstance->loadCase($APP_UID);
    $newFields['APP_DATA']['FLAGTYPO3'] = 'On';
    $newFields['APP_DATA']['FLAG_ACTIONTYPO3'] = 'actionCreateCase';
    if ($_REQUEST['redirect']) {
        $newFields['APP_DATA']['FLAG_REDIRECT_PAGE'] = urldecode($_REQUEST['redirect']);
    }
    if ($new == 1) {
        $newFields['APP_DATA']['NUM_DOSSIER'] = $newFields['APP_NUMBER'];
    }
    PMFSendVariables($APP_UID, $newFields['APP_DATA']);
    $caseInstance->updateCase($APP_UID, $newFields);
}
    /**

     * execute Trigger, executes a ProcessMaker trigger.

     * Note that triggers which are tied to case derivation

     * will executing automatically.

     *

     * @param string $userId

     * @param string $caseId

     * @param string $delIndex

     * @return $result will return an object

     */

    public function executeTrigger ($userId, $caseId, $triggerIndex, $delIndex)

    {

        $g = new G();



        try {

            $g->sessionVarSave();



            $_SESSION["APPLICATION"] = $caseId;

            $_SESSION["INDEX"] = $delIndex;

            $_SESSION["USER_LOGGED"] = $userId;



            $oAppDel = new AppDelegation();

            $appdel = $oAppDel->Load( $caseId, $delIndex );



            if ($userId != $appdel['USR_UID']) {

                $result = new wsResponse( 17, G::loadTranslation( 'ID_CASE_ASSIGNED_ANOTHER_USER' ) );



                $g->sessionVarRestore();



                return $result;

            }



            if ($appdel['DEL_FINISH_DATE'] != null) {

                $result = new wsResponse( 18, G::loadTranslation( 'ID_CASE_DELEGATION_ALREADY_CLOSED' ) );



                $g->sessionVarRestore();



                return $result;

            }



            $oCriteria = new Criteria( 'workflow' );

            $oCriteria->addSelectColumn( AppDelayPeer::APP_UID );

            $oCriteria->addSelectColumn( AppDelayPeer::APP_DEL_INDEX );

            $oCriteria->addSelectColumn( AppDelayPeer::APP_DISABLE_ACTION_USER );

            $oCriteria->addSelectColumn( AppDelayPeer::APP_DISABLE_ACTION_DATE );

            $oCriteria->add( AppDelayPeer::APP_TYPE, '' );

            $oCriteria->add( $oCriteria->getNewCriterion( AppDelayPeer::APP_TYPE, 'PAUSE' )->addOr( $oCriteria->getNewCriterion( AppDelayPeer::APP_TYPE, 'CANCEL' ) ) );

            $oCriteria->addAscendingOrderByColumn( AppDelayPeer::APP_ENABLE_ACTION_DATE );

            $oDataset = AppDelayPeer::doSelectRS( $oCriteria );

            $oDataset->setFetchmode( ResultSet::FETCHMODE_ASSOC );

            $oDataset->next();

            $aRow = $oDataset->getRow();



            if (is_array( $aRow )) {

                if ($aRow['APP_DISABLE_ACTION_USER'] != 0 && $aRow['APP_DISABLE_ACTION_DATE'] != '') {

                    $result = new wsResponse( 19, G::loadTranslation( 'ID_CASE_IN_STATUS' ) . " " . $aRow['APP_TYPE'] );



                    $g->sessionVarRestore();



                    return $result;

                }

            }



            //Load data

            $oCase = new Cases();

            $appFields = $oCase->loadCase( $caseId );



            $appFields["APP_DATA"]["APPLICATION"] = $caseId;



            if (! isset( $_SESSION["PROCESS"] )) {

                $_SESSION["PROCESS"] = $appFields["PRO_UID"];

            }



            //executeTrigger

            $aTriggers = array ();

            $c = new Criteria();

            $c->add( TriggersPeer::TRI_UID, $triggerIndex );

            $rs = TriggersPeer::doSelectRS( $c );

            $rs->setFetchmode( ResultSet::FETCHMODE_ASSOC );

            $rs->next();

            $row = $rs->getRow();



            if (is_array( $row ) && $row['TRI_TYPE'] == 'SCRIPT') {

                $aTriggers[] = $row;



                $oPMScript = new PMScript();

                $oPMScript->setFields( $appFields['APP_DATA'] );

                $oPMScript->setScript( $row['TRI_WEBBOT'] );

                $oPMScript->execute();



                if (isset($oPMScript->aFields["__ERROR__"]) && trim($oPMScript->aFields["__ERROR__"]) != "" && $oPMScript->aFields["__ERROR__"] != "none") {

                    throw new Exception($oPMScript->aFields["__ERROR__"]);

                }



                //Save data - Start

                $appFields['APP_DATA'] = $oPMScript->aFields;

                unset($appFields['APP_STATUS']);

                unset($appFields['APP_PROC_STATUS']);

                unset($appFields['APP_PROC_CODE']);

                unset($appFields['APP_PIN']);

                //$appFields = $oCase->loadCase($caseId);

                $oCase->updateCase( $caseId, $appFields );

                //Save data - End

            } else {

                $data['TRIGGER_INDEX'] = $triggerIndex;

                $result = new wsResponse( 100, G::loadTranslation( 'ID_INVALID_TRIGGER', SYS_LANG, $data ) );



                $g->sessionVarRestore();



                return $result;

            }



            $result = new wsResponse( 0, G::loadTranslation( 'ID_EXECUTED' ) . ": " . trim( $row['TRI_WEBBOT'] ) );

            //$result = new wsResponse(0, 'executed: ' . print_r($oPMScript, 1));



            $g->sessionVarRestore();



            return $result;

        } catch (Exception $e) {

            $result = new wsResponse( 100, $e->getMessage() );



            $g->sessionVarRestore();



            return $result;

        }

    }
 public function saveDataInTable($sUID, $aFields)
 {
     try {
         $aData = $this->load($sUID, true);
         $sPath = PATH_DB . SYS_SYS . PATH_SEP . 'classes' . PATH_SEP;
         $sClassName = ($aData['ADD_TAB_CLASS_NAME'] != ''
                       ? $aData['ADD_TAB_CLASS_NAME']
                       : $this->getPHPName($aData['ADD_TAB_NAME']));
         // $oConnection = Propel::getConnection(FieldsPeer::DATABASE_NAME);
         $oConnection = Propel::getConnection($aData['DBS_UID']);
         $stmt = $oConnection->createStatement();
         require_once $sPath . $sClassName . '.php';
         $sKeys = '';
         $keysAutoIncrement = 0;
         $keyUIDAutoIncrement = '';
         foreach ($aData['FIELDS'] as $aField) {
             if ($aField['FLD_KEY'] == 1) {
                 if ($aField['FLD_AUTO_INCREMENT'] == 1) {
                     if ($keysAutoIncrement == 0) {
                         $keyUIDAutoIncrement = $aField['FLD_NAME'];
                     }
                     $keysAutoIncrement++;
                 }
                 $vValue = $aFields[$aField['FLD_NAME']];
                 eval('$' . $aField['FLD_NAME'] . ' = $vValue;');
                 $sKeys .= '$' . $aField['FLD_NAME'] . ',';
             }
         }
         $sKeys = substr($sKeys, 0, -1);
         $oClass = new $sClassName;
         foreach ($aFields as $sKey => $sValue) {
             if (!preg_match("/\(?\)/", $sKey)) {
                 eval('$oClass->set' . $this->getPHPName($sKey) . '($aFields["' . $sKey . '"]);');
             }
         }
         if ($oClass->validate()) {
             $iResult = $oClass->save();
             if ($keysAutoIncrement == 1 && $aFields[$keyUIDAutoIncrement] == '' && isset($_SESSION['APPLICATION']) && $_SESSION['APPLICATION'] != '') {
                 G::LoadClass('case');
                 $oCaseKeyAuto = new Cases();
                 $newId = $oClass->getId();
                 $aFields = $oCaseKeyAuto->loadCase($_SESSION['APPLICATION']);
                 $aFields['APP_DATA'][$keyUIDAutoIncrement] = $newId;
                 if (isset($_POST['form'])) {
                     $_POST['form'][$keyUIDAutoIncrement] = $newId;
                 }
                 $oCaseKeyAuto->updateCase($_SESSION['APPLICATION'], $aFields);
             }
         }
         return true;
     } catch (Exception $oError) {
         throw($oError);
     }
 }
if (isset($_FILES) && isset($_FILES["form"]) && count($_FILES["form"]) > 0) {
    $appDocUid = $case->addInputDocument($inputDocumentUid, $appDocUid, $docVersion, $appDocType, $appDocComment, $actionType, $_SESSION["APPLICATION"], $_SESSION["INDEX"], $_SESSION["TASK"], $_SESSION["USER_LOGGED"], "xmlform", $_FILES["form"]["name"]["APP_DOC_FILENAME"], $_FILES["form"]["error"]["APP_DOC_FILENAME"], $_FILES["form"]["tmp_name"]["APP_DOC_FILENAME"]);
}
if ($_SESSION["TRIGGER_DEBUG"]["NUM_TRIGGERS"] > 0) {
    //Trigger - Execute after - Start
    $arrayField["APP_DATA"] = $case->executeTriggers($_SESSION["TASK"], "INPUT_DOCUMENT", $inputDocumentUid, "AFTER", $arrayField["APP_DATA"]);
    //Trigger - Execute after - End
}
//Save data
$arrayData = array();
$arrayData["APP_NUMBER"] = $arrayField["APP_NUMBER"];
//$arrayData["APP_PROC_STATUS"] = $arrayField["APP_PROC_STATUS"];
$arrayData["APP_DATA"] = $arrayField["APP_DATA"];
$arrayData["DEL_INDEX"] = $_SESSION["INDEX"];
$arrayData["TAS_UID"] = $_SESSION["TASK"];
$case->updateCase($_SESSION["APPLICATION"], $arrayData);
//go to the next step
//if (!isset($_POST['form']['MORE'])) {
if (false) {
    $aNextStep = $case->getNextStep($_SESSION["PROCESS"], $_SESSION["APPLICATION"], $_SESSION["INDEX"], $_SESSION["STEP_POSITION"]);
    $_SESSION['STEP_POSITION'] = $aNextStep['POSITION'];
    if ($_SESSION['TRIGGER_DEBUG']['ISSET']) {
        $_SESSION['TRIGGER_DEBUG']['BREAKPAGE'] = $aNextStep['PAGE'];
        G::header('location: ' . $aNextStep['PAGE'] . '&breakpoint=triggerdebug');
        die;
    }
    G::header('location: ' . $aNextStep['PAGE']);
    die;
} else {
    if (isset($_SERVER['HTTP_REFERER'])) {
        if ($_SERVER['HTTP_REFERER'] != '') {
 function verifyIsCaseChild($sApplicationUID)
 {
     //Obtain the related row in the table SUB_APPLICATION
     $oCriteria = new Criteria('workflow');
     $oCriteria->add(SubApplicationPeer::APP_UID, $sApplicationUID);
     $oDataset = SubApplicationPeer::doSelectRS($oCriteria);
     $oDataset->setFetchmode(ResultSet::FETCHMODE_ASSOC);
     $oDataset->next();
     $aSA = $oDataset->getRow();
     if ($aSA) {
         //Obtain the related row in the table SUB_PROCESS
         $oCase = new Cases();
         $aParentCase = $oCase->loadCase($aSA['APP_PARENT'], $aSA['DEL_INDEX_PARENT']);
         $oCriteria = new Criteria('workflow');
         $oCriteria->add(SubProcessPeer::PRO_PARENT, $aParentCase['PRO_UID']);
         $oCriteria->add(SubProcessPeer::TAS_PARENT, $aParentCase['TAS_UID']);
         $oDataset = SubProcessPeer::doSelectRS($oCriteria);
         $oDataset->setFetchmode(ResultSet::FETCHMODE_ASSOC);
         $oDataset->next();
         $aSP = $oDataset->getRow();
         if ($aSP['SP_SYNCHRONOUS'] == 1) {
             $appFields = $oCase->loadCase($sApplicationUID);
             //Copy case variables to parent case
             $aFields = unserialize($aSP['SP_VARIABLES_IN']);
             $aNewFields = array();
             foreach ($aFields as $sOriginField => $sTargetField) {
                 $sOriginField = str_replace('@', '', $sOriginField);
                 $sOriginField = str_replace('#', '', $sOriginField);
                 $sTargetField = str_replace('@', '', $sTargetField);
                 $sTargetField = str_replace('#', '', $sTargetField);
                 $aNewFields[$sTargetField] = isset($appFields['APP_DATA'][$sOriginField]) ? $appFields['APP_DATA'][$sOriginField] : '';
             }
             $aParentCase['APP_DATA'] = array_merge($aParentCase['APP_DATA'], $aNewFields);
             $oCase->updateCase($aSA['APP_PARENT'], $aParentCase);
             //Update table SUB_APPLICATION
             $oSubApplication = new SubApplication();
             $oSubApplication->update(array('APP_UID' => $sApplicationUID, 'APP_PARENT' => $aSA['APP_PARENT'], 'DEL_INDEX_PARENT' => $aSA['DEL_INDEX_PARENT'], 'DEL_THREAD_PARENT' => $aSA['DEL_THREAD_PARENT'], 'SA_STATUS' => 'FINISHED', 'SA_VALUES_IN' => serialize($aNewFields), 'SA_FINISH_DATE' => date('Y-m-d H:i:s')));
             //Derive the parent case
             $aDeriveTasks = $this->prepareInformation(array('USER_UID' => -1, 'APP_UID' => $aSA['APP_PARENT'], 'DEL_INDEX' => $aSA['DEL_INDEX_PARENT']));
             if (isset($aDeriveTasks[1])) {
                 if ($aDeriveTasks[1]['ROU_TYPE'] != 'SELECT') {
                     $nextDelegations2 = array();
                     foreach ($aDeriveTasks as $aDeriveTask) {
                         if (!isset($aDeriveTask['NEXT_TASK']['USER_ASSIGNED']['USR_UID'])) {
                             $selectedUser = $aDeriveTask['NEXT_TASK']['USER_ASSIGNED'][0];
                             unset($aDeriveTask['NEXT_TASK']['USER_ASSIGNED']);
                             $aDeriveTask['NEXT_TASK']['USER_ASSIGNED'] = $selectedUser;
                             $myLabels = array($aDeriveTask['NEXT_TASK']['TAS_TITLE'], $aParentCase['APP_NUMBER'], $selectedUser['USR_USERNAME'], $selectedUser['USR_FIRSTNAME'], $selectedUser['USR_LASTNAME']);
                             G::SendTemporalMessage('ID_TASK_WAS_ASSIGNED_TO_USER', 'warning', 'labels', 10, null, $myLabels);
                         }
                         $nextDelegations2[] = array('TAS_UID' => $aDeriveTask['NEXT_TASK']['TAS_UID'], 'USR_UID' => $aDeriveTask['NEXT_TASK']['USER_ASSIGNED']['USR_UID'], 'TAS_ASSIGN_TYPE' => $aDeriveTask['NEXT_TASK']['TAS_ASSIGN_TYPE'], 'TAS_DEF_PROC_CODE' => $aDeriveTask['NEXT_TASK']['TAS_DEF_PROC_CODE'], 'DEL_PRIORITY' => 3, 'TAS_PARENT' => $aDeriveTask['NEXT_TASK']['TAS_PARENT']);
                     }
                     $currentDelegation2 = array('APP_UID' => $aSA['APP_PARENT'], 'DEL_INDEX' => $aSA['DEL_INDEX_PARENT'], 'APP_STATUS' => 'TO_DO', 'TAS_UID' => $aParentCase['TAS_UID'], 'ROU_TYPE' => $aDeriveTasks[1]['ROU_TYPE']);
                     $this->derivate($currentDelegation2, $nextDelegations2);
                 }
             }
         }
     }
 }
             }
             $oDataset->next();
         }
         if (count($aDynaforms) > 0) {
             require_once "classes/model/Dynaform.php";
             $dynInstance = new Dynaform();
             foreach ($aDynaforms as $key => $value) {
                 $aAllFields = $dynInstance->getDynaformFields($value);
                 if (is_array($aAllFields)) {
                     foreach ($aAllFields as $kInput => $input) {
                         if (!isset($input->input)) {
                             continue;
                         }
                         if ($input->type == 'file' && $input->input == $_GET['UID'] && !empty($aAppDataFields['APP_DATA'][$kInput])) {
                             $aAppDataFields['APP_DATA'][$kInput] = $sOriginalName;
                             $oCase->updateCase($_GET['APP_UID'], $aAppDataFields);
                         }
                     }
                     unset($input);
                 }
             }
             unset($value);
         }
         //End Update AppData with the current file uploaded
     }
 }
 //go to the next step
 if (!isset($_POST['form']['MORE'])) {
     $oCase = new Cases();
     $aFields = $oCase->loadCase($_GET['APP_UID']);
     $aNextStep = $oCase->getNextSupervisorStep($aFields['PRO_UID'], $_GET['position'], 'INPUT_DOCUMENT');
 /**
  * Execute Script
  *
  * @param string $activityUid          Unique id of Event
  * @param array  $arrayApplicationData Case data
  *
  * return array
  */
 public function execScriptByActivityUid($activityUid, array $arrayApplicationData)
 {
     try {
         $task = \TaskPeer::retrieveByPK($activityUid);
         if (!is_null($task) && $task->getTasType() == "SCRIPT-TASK") {
             $criteria = new \Criteria("workflow");
             $criteria->addSelectColumn(\ScriptTaskPeer::SCRTAS_OBJ_UID);
             $criteria->add(\ScriptTaskPeer::ACT_UID, $activityUid, \Criteria::EQUAL);
             $rsCriteria = \ScriptTaskPeer::doSelectRS($criteria);
             $rsCriteria->setFetchmode(\ResultSet::FETCHMODE_ASSOC);
             if ($rsCriteria->next()) {
                 $row = $rsCriteria->getRow();
                 $scriptTasObjUid = $row["SCRTAS_OBJ_UID"];
                 $trigger = \TriggersPeer::retrieveByPK($scriptTasObjUid);
                 if (!is_null($trigger)) {
                     $pmScript = new \PMScript();
                     $pmScript->setFields($arrayApplicationData["APP_DATA"]);
                     $pmScript->setScript($trigger->getTriWebbot());
                     $result = $pmScript->execute();
                     if (isset($pmScript->aFields["__ERROR__"])) {
                         \G::log("Case Uid: " . $arrayApplicationData["APP_UID"] . ", Error: " . $pmScript->aFields["__ERROR__"], PATH_DATA . "log/ScriptTask.log");
                     }
                     $arrayApplicationData["APP_DATA"] = $pmScript->aFields;
                     $case = new \Cases();
                     $result = $case->updateCase($arrayApplicationData["APP_UID"], $arrayApplicationData);
                 }
             }
         }
         //Return
         return $arrayApplicationData["APP_DATA"];
     } catch (\Exception $e) {
         throw $e;
     }
 }
    function verifyIsCaseChild ($sApplicationUID, $delIndex = 0)

    {

        //Obtain the related row in the table SUB_APPLICATION

        $oCriteria = new Criteria( 'workflow' );

        $oCriteria->add( SubApplicationPeer::APP_UID, $sApplicationUID );

        $oDataset = SubApplicationPeer::doSelectRS( $oCriteria );

        $oDataset->setFetchmode( ResultSet::FETCHMODE_ASSOC );

        $oDataset->next();

        $aSA = $oDataset->getRow();

        if ($aSA) {

            //Obtain the related row in the table SUB_PROCESS

            $oCase = new Cases();

            $aParentCase = $oCase->loadCase( $aSA['APP_PARENT'], $aSA['DEL_INDEX_PARENT'] );

            $oCriteria = new Criteria( 'workflow' );

            $oCriteria->add( SubProcessPeer::PRO_PARENT, $aParentCase['PRO_UID'] );

            $oCriteria->add( SubProcessPeer::TAS_PARENT, $aParentCase['TAS_UID'] );

            $oDataset = SubProcessPeer::doSelectRS( $oCriteria );

            $oDataset->setFetchmode( ResultSet::FETCHMODE_ASSOC );

            $oDataset->next();

            $aSP = $oDataset->getRow();

            if ($aSP['SP_SYNCHRONOUS'] == 1) {

                $appFields = $oCase->loadCase($sApplicationUID, $delIndex);

                //Copy case variables to parent case

                $aFields = unserialize( $aSP['SP_VARIABLES_IN'] );

                $aNewFields = array ();

                foreach ($aFields as $sOriginField => $sTargetField) {

                    $sOriginField = str_replace( '@', '', $sOriginField );

                    $sOriginField = str_replace( '#', '', $sOriginField );

                    $sOriginField = str_replace( '%', '', $sOriginField );

                    $sOriginField = str_replace( '?', '', $sOriginField );

                    $sOriginField = str_replace( '$', '', $sOriginField );

                    $sOriginField = str_replace( '=', '', $sOriginField );

                    $sTargetField = str_replace( '@', '', $sTargetField );

                    $sTargetField = str_replace( '#', '', $sTargetField );

                    $sTargetField = str_replace( '%', '', $sTargetField );

                    $sTargetField = str_replace( '?', '', $sTargetField );

                    $sTargetField = str_replace( '$', '', $sTargetField );

                    $sTargetField = str_replace( '=', '', $sTargetField );

                    $aNewFields[$sTargetField] = isset( $appFields['APP_DATA'][$sOriginField] ) ? $appFields['APP_DATA'][$sOriginField] : '';

                    if(isset($aParentCase['APP_DATA'][$sTargetField.'_label'])){

                        $aNewFields[$sTargetField.'_label'] = isset( $appFields['APP_DATA'][$sOriginField.'_label'] ) ? $appFields['APP_DATA'][$sOriginField.'_label'] : '';

                    }

                }

                $aParentCase['APP_DATA'] = array_merge( $aParentCase['APP_DATA'], $aNewFields );

                $oCase->updateCase( $aSA['APP_PARENT'], $aParentCase );

                /*----------------------------------********---------------------------------*/



                //Update table SUB_APPLICATION

                $oSubApplication = new SubApplication();

                $oSubApplication->update( array ('APP_UID' => $sApplicationUID,'APP_PARENT' => $aSA['APP_PARENT'],'DEL_INDEX_PARENT' => $aSA['DEL_INDEX_PARENT'],'DEL_THREAD_PARENT' => $aSA['DEL_THREAD_PARENT'],'SA_STATUS' => 'FINISHED','SA_VALUES_IN' => serialize( $aNewFields ),'SA_FINISH_DATE' => date( 'Y-m-d H:i:s' )

                ) );



                //Derive the parent case

                $aDeriveTasks = $this->prepareInformation( array ('USER_UID' => - 1,'APP_UID' => $aSA['APP_PARENT'],'DEL_INDEX' => $aSA['DEL_INDEX_PARENT']

                ) );

                if (isset( $aDeriveTasks[1] )) {

                    if ($aDeriveTasks[1]['ROU_TYPE'] != 'SELECT') {

                        $nextDelegations2 = array ();

                        foreach ($aDeriveTasks as $aDeriveTask) {

                            if (! isset( $aDeriveTask['NEXT_TASK']['USER_ASSIGNED']['USR_UID'] )) {

                                $selectedUser = $aDeriveTask['NEXT_TASK']['USER_ASSIGNED'][0];

                                unset( $aDeriveTask['NEXT_TASK']['USER_ASSIGNED'] );

                                $aDeriveTask['NEXT_TASK']['USER_ASSIGNED'] = $selectedUser;

                                $myLabels = array ($aDeriveTask['NEXT_TASK']['TAS_TITLE'],$aParentCase['APP_NUMBER'],$selectedUser['USR_USERNAME'],$selectedUser['USR_FIRSTNAME'],$selectedUser['USR_LASTNAME']

                                );

                                G::SendTemporalMessage( 'ID_TASK_WAS_ASSIGNED_TO_USER', 'warning', 'labels', 10, null, $myLabels );



                            }

                            $nextDelegations2[] = array ('TAS_UID' => $aDeriveTask['NEXT_TASK']['TAS_UID'],'USR_UID' => $aDeriveTask['NEXT_TASK']['USER_ASSIGNED']['USR_UID'],'TAS_ASSIGN_TYPE' => $aDeriveTask['NEXT_TASK']['TAS_ASSIGN_TYPE'],'TAS_DEF_PROC_CODE' => $aDeriveTask['NEXT_TASK']['TAS_DEF_PROC_CODE'],'DEL_PRIORITY' => 3,'TAS_PARENT' => $aDeriveTask['NEXT_TASK']['TAS_PARENT']

                            );

                        }

                        $currentDelegation2 = array ('APP_UID' => $aSA['APP_PARENT'],'DEL_INDEX' => $aSA['DEL_INDEX_PARENT'],'APP_STATUS' => 'TO_DO','TAS_UID' => $aParentCase['TAS_UID'],'ROU_TYPE' => $aDeriveTasks[1]['ROU_TYPE']

                        );

                        $this->derivate( $currentDelegation2, $nextDelegations2 );



                        if($delIndex > 0 ) {

                            // Send notifications - Start

                            $oUser = new Users();

                            $aUser = $oUser->load($appFields["CURRENT_USER_UID"]);



                            $sFromName = $aUser["USR_FIRSTNAME"] . " " . $aUser["USR_LASTNAME"] . ($aUser["USR_EMAIL"] != "" ? " <" . $aUser["USR_EMAIL"] . ">" : "");



                            try {

                                $oCase->sendNotifications($appFields["TAS_UID"],

                                                          $nextDelegations2,

                                                          $appFields["APP_DATA"],

                                                          $sApplicationUID,

                                                          $delIndex,

                                                          $sFromName);



                            } catch (Exception $e) {

                                G::SendTemporalMessage(G::loadTranslation("ID_NOTIFICATION_ERROR") . " - " . $e->getMessage(), "warning", "string", null, "100%");

                            }

                            // Send notifications - End

                        }

                    }

                }

            }

        }

    }
 
         $rsSQL->next();
 
         $row = $rsSQL->getRow();
         $currentUsrName = $row["USR_USERNAME"];
 
         $casesFields["APP_DATA"]["USER_LOGGED"]  = $current_user_uid;
         $casesFields["APP_DATA"]["USR_USERNAME"] = $currentUsrName;
     }
 
     foreach ($casesFields["APP_DATA"] as $index => $value) {
         $_SESSION[$index] = $value;
     }
 
     //Update case info
     $case->updateCase($_REQUEST['APP_UID'], $casesFields);
 
     G::LoadClass('wsBase');
 
     $wsBaseInstance = new wsBase();
     $result = $wsBaseInstance->derivateCase($casesFields['CURRENT_USER_UID'], $_REQUEST['APP_UID'], $_REQUEST ['DEL_INDEX'], true);
     $code = (is_array($result) ? $result['status_code'] : $result->status_code);
 
     $dataResponses = array();
     $dataResponses['ABE_REQ_UID'] = $_REQUEST['ABER'];
     $dataResponses['ABE_RES_CLIENT_IP'] = $_SERVER['REMOTE_ADDR'];
     $dataResponses['ABE_RES_DATA'] = serialize($_REQUEST['form']);
     $dataResponses['ABE_RES_STATUS'] = 'PENDING';
     $dataResponses['ABE_RES_MESSAGE'] = '';
 
     try {
 $dataField[$_REQUEST['FIELD']] = $_REQUEST['VALUE'];
 $caseFieldsABE['APP_DATA'] = array_merge($caseFieldsABE['APP_DATA'], $dataField);
 $dataResponses = array();
 $dataResponses['ABE_REQ_UID'] = $_REQUEST['ABER'];
 $dataResponses['ABE_RES_CLIENT_IP'] = $_SERVER['REMOTE_ADDR'];
 $dataResponses['ABE_RES_DATA'] = serialize($_REQUEST['VALUE']);
 $dataResponses['ABE_RES_STATUS'] = 'PENDING';
 $dataResponses['ABE_RES_MESSAGE'] = '';
 try {
     require_once 'classes/model/AbeResponses.php';
     $abeAbeResponsesInstance = new AbeResponses();
     $dataResponses['ABE_RES_UID'] = $abeAbeResponsesInstance->createOrUpdate($dataResponses);
 } catch (Exception $error) {
     throw $error;
 }
 $cases->updateCase($_REQUEST['APP_UID'], $caseFieldsABE);
 G::LoadClass('wsBase');
 $ws = new wsBase();
 $result = $ws->derivateCase($caseFieldsABE['CURRENT_USER_UID'], $_REQUEST['APP_UID'], $_REQUEST['DEL_INDEX'], true);
 $code = is_array($result) ? $result['status_code'] : $result->status_code;
 if ($code != 0) {
     throw new Exception('An error occurred while the application was being processed.<br /><br />
              Error code: ' . $result->status_code . '<br />
              Error message: ' . $result->message . '<br /><br />');
 }
 // Update
 $dataResponses['ABE_RES_STATUS'] = $code == 0 ? 'SENT' : 'ERROR';
 $dataResponses['ABE_RES_MESSAGE'] = $code == 0 ? '-' : $result->message;
 try {
     $abeAbeResponsesInstance = new AbeResponses();
     $abeAbeResponsesInstance->createOrUpdate($dataResponses);
 $oTask = new Task();
 $TaskFields = $oTask->load($_POST['TASKS']);
 $aDerivation['NEXT_TASK'] = $TaskFields;
 $oDerivation = new Derivation();
 $deriva = $oDerivation->getNextAssignedUser($aDerivation);
 $oCase = new Cases();
 $aData = $oCase->startCase($_POST['TASKS'], $deriva['USR_UID']);
 $case = $oCase->loadCase($aData['APPLICATION'], 1);
 $Fields = array();
 $Fields['APP_NUMBER'] = $case['APP_NUMBER'];
 $Fields['APP_PROC_STATUS'] = 'draft';
 $Fields['APP_DATA'] = $_POST['form'];
 $Fields['DEL_INDEX'] = 1;
 $Fields['TAS_UID'] = $_POST['TASKS'];
 //$Fields = $oCase->loadCase($aData['APPLICATION'], 1);
 $oCase->updateCase($aData['APPLICATION'], $Fields);
 $s = 0;
 if (isset($_SERVER['HTTP_REFERER'])) {
     $dir = explode('?', $_SERVER['HTTP_REFERER']);
     if ($dir[1] == '__flag__=1') {
         $s = 1;
     } else {
         $dire = explode('&', $dir[1]);
         for ($i = 0; $i <= count($dire); $i++) {
             if ($dire[$i] == '__flag__=1') {
                 $s = 1;
             }
         }
     }
     //if(strpos($_SERVER['HTTP_REFERER'],'?') !== false)
     if ($s == 1) {
/**
 *
 * @method
 *
 * Redirects a case to any step in the current task. In order for the step to
 * be executed, the specified step much exist and if it contains a condition,
 * it must evaluate to true.
 *
 * @name PMFRedirectToStep
 * @label PMF Redirect To Step
 * @link http://wiki.processmaker.com/index.php/ProcessMaker_Functions#PMFRedirectToStep.28.29
 *
 * @param string(32) | $sApplicationUID | Case ID | The unique ID for a case,
 * @param int | $iDelegation | Delegation index | The delegation index of a case.
 * @param string(32) | $sStepType | Type of Step | The type of step, which can be "DYNAFORM", "INPUT_DOCUMENT" or "OUTPUT_DOCUMENT".
 * @param string(32) | $sStepUid | Step ID | The unique ID for the step.
 * @return none | $none | None | None
 *
 */
function PMFRedirectToStep($sApplicationUID, $iDelegation, $sStepType, $sStepUid)
{
    $g = new G();
    $g->sessionVarSave();
    $iDelegation = intval($iDelegation);
    $_SESSION["APPLICATION"] = $sApplicationUID;
    $_SESSION["INDEX"] = $iDelegation;
    require_once 'classes/model/AppDelegation.php';
    $oCriteria = new Criteria('workflow');
    $oCriteria->addSelectColumn(AppDelegationPeer::TAS_UID);
    $oCriteria->add(AppDelegationPeer::APP_UID, $sApplicationUID);
    $oCriteria->add(AppDelegationPeer::DEL_INDEX, $iDelegation);
    $oDataset = AppDelegationPeer::doSelectRS($oCriteria);
    $oDataset->setFetchmode(ResultSet::FETCHMODE_ASSOC);
    $oDataset->next();
    global $oPMScript;
    $aRow = $oDataset->getRow();
    if ($aRow) {
        require_once 'classes/model/Step.php';
        $oStep = new Step();
        $oTheStep = $oStep->loadByType($aRow['TAS_UID'], $sStepType, $sStepUid);
        $bContinue = true;
        G::LoadClass('case');
        $oCase = new Cases();
        $aFields = $oCase->loadCase($sApplicationUID);
        if ($oTheStep->getStepCondition() != '') {
            G::LoadClass('pmScript');
            $pmScript = new PMScript();
            $pmScript->setFields($aFields['APP_DATA']);
            $pmScript->setScript($oTheStep->getStepCondition());
            $bContinue = $pmScript->evaluate();
        }
        if ($bContinue) {
            switch ($oTheStep->getStepTypeObj()) {
                case 'DYNAFORM':
                    $sAction = 'EDIT';
                    break;
                case 'OUTPUT_DOCUMENT':
                    $sAction = 'GENERATE';
                    break;
                case 'INPUT_DOCUMENT':
                    $sAction = 'ATTACH';
                    break;
                case 'EXTERNAL':
                    $sAction = 'EDIT';
                    break;
                case 'MESSAGE':
                    $sAction = '';
                    break;
            }
            // save data
            if (!is_null($oPMScript)) {
                $aFields['APP_DATA'] = $oPMScript->aFields;
                $oCase->updateCase($sApplicationUID, $aFields);
            }
            $g->sessionVarRestore();
            G::header('Location: ' . 'cases_Step?TYPE=' . $sStepType . '&UID=' . $sStepUid . '&POSITION=' . $oTheStep->getStepPosition() . '&ACTION=' . $sAction);
            die;
        }
    }
    $g->sessionVarRestore();
}
Exemple #13
0
function executeCaseSelfService()
{
    try {
        global $sFilter;
        if ($sFilter != "" && strpos($sFilter, "unassigned-case") === false) {
            return false;
        }
        $criteria = new Criteria("workflow");
        //SELECT
        $criteria->addSelectColumn(AppCacheViewPeer::APP_UID);
        $criteria->addSelectColumn(AppCacheViewPeer::DEL_INDEX);
        $criteria->addSelectColumn(AppCacheViewPeer::DEL_DELEGATE_DATE);
        $criteria->addSelectColumn(AppCacheViewPeer::APP_NUMBER);
        $criteria->addSelectColumn(AppCacheViewPeer::PRO_UID);
        $criteria->addSelectColumn(TaskPeer::TAS_UID);
        $criteria->addSelectColumn(TaskPeer::TAS_SELFSERVICE_TIME);
        $criteria->addSelectColumn(TaskPeer::TAS_SELFSERVICE_TIME_UNIT);
        $criteria->addSelectColumn(TaskPeer::TAS_SELFSERVICE_TRIGGER_UID);
        //FROM
        $condition = array();
        $condition[] = array(AppCacheViewPeer::TAS_UID, TaskPeer::TAS_UID);
        $condition[] = array(TaskPeer::TAS_SELFSERVICE_TIMEOUT, 1);
        $criteria->addJoinMC($condition, Criteria::LEFT_JOIN);
        //WHERE
        $criteria->add(AppCacheViewPeer::USR_UID, "");
        $criteria->add(AppCacheViewPeer::DEL_THREAD_STATUS, "OPEN");
        //QUERY
        $rsCriteria = AppCacheViewPeer::doSelectRS($criteria);
        $rsCriteria->setFetchmode(ResultSet::FETCHMODE_ASSOC);
        setExecutionMessage("Unassigned case");
        saveLog("unassignedCase", "action", "Unassigned case", "c");
        $date = new dates();
        while ($rsCriteria->next()) {
            $row = $rsCriteria->getRow();
            $appcacheAppUid = $row["APP_UID"];
            $appcacheDelIndex = $row["DEL_INDEX"];
            $appcacheDelDelegateDate = $row["DEL_DELEGATE_DATE"];
            $appcacheAppNumber = $row["APP_NUMBER"];
            $appcacheProUid = $row["PRO_UID"];
            $taskUid = $row["TAS_UID"];
            $taskSelfServiceTime = intval($row["TAS_SELFSERVICE_TIME"]);
            $taskSelfServiceTimeUnit = $row["TAS_SELFSERVICE_TIME_UNIT"];
            $taskSelfServiceTriggerUid = $row["TAS_SELFSERVICE_TRIGGER_UID"];
            $dueDate = $date->calculateDate($appcacheDelDelegateDate, $taskSelfServiceTime, $taskSelfServiceTimeUnit, 1);
            if (time() > $dueDate["DUE_DATE_SECONDS"]) {
                $sessProcess = null;
                $sessProcessSw = 0;
                //Load data
                $case = new Cases();
                $appFields = $case->loadCase($appcacheAppUid);
                $appFields["APP_DATA"]["APPLICATION"] = $appcacheAppUid;
                if (isset($_SESSION["PROCESS"])) {
                    $sessProcess = $_SESSION["PROCESS"];
                    $sessProcessSw = 1;
                }
                $_SESSION["PROCESS"] = $appFields["PRO_UID"];
                //Execute trigger
                $criteriaTgr = new Criteria();
                $criteriaTgr->add(TriggersPeer::TRI_UID, $taskSelfServiceTriggerUid);
                $rsCriteriaTgr = TriggersPeer::doSelectRS($criteriaTgr);
                $rsCriteriaTgr->setFetchmode(ResultSet::FETCHMODE_ASSOC);
                if ($rsCriteriaTgr->next()) {
                    $row = $rsCriteriaTgr->getRow();
                    if (is_array($row) && $row["TRI_TYPE"] == "SCRIPT") {
                        $arrayCron = unserialize(trim(@file_get_contents(PATH_DATA . "cron")));
                        $arrayCron["processcTimeProcess"] = 60;
                        //Minutes
                        $arrayCron["processcTimeStart"] = time();
                        @file_put_contents(PATH_DATA . "cron", serialize($arrayCron));
                        //Trigger
                        global $oPMScript;
                        $oPMScript = new PMScript();
                        $oPMScript->setFields($appFields["APP_DATA"]);
                        $oPMScript->setScript($row["TRI_WEBBOT"]);
                        $oPMScript->execute();
                        $appFields["APP_DATA"] = array_merge($appFields["APP_DATA"], $oPMScript->aFields);
                        $case->updateCase($appFields["APP_UID"], $appFields);
                        saveLog("unassignedCase", "action", "OK Executed tigger to the case {$appcacheAppNumber}");
                    }
                }
                unset($_SESSION["PROCESS"]);
                if ($sessProcessSw == 1) {
                    $_SESSION["PROCESS"] = $sessProcess;
                }
            }
        }
        setExecutionResultMessage("DONE");
    } catch (Exception $e) {
        setExecutionResultMessage("WITH ERRORS", "error");
        eprintln("  '-" . $e->getMessage(), "red");
        saveLog("unassignedCase", "error", "Error in unassigned case: " . $e->getMessage());
    }
}
 /**
  * Catch Message-Events for the Cases
  *
  * @param bool $frontEnd Flag to represent progress bar
  *
  * @return void
  */
 public function catchMessageEvent($frontEnd = false)
 {
     try {
         \G::LoadClass("wsBase");
         //Set variables
         $ws = new \wsBase();
         $case = new \Cases();
         $common = new \ProcessMaker\Util\Common();
         $common->setFrontEnd($frontEnd);
         //Get data
         $totalMessageEvent = 0;
         $counterStartMessageEvent = 0;
         $counterIntermediateCatchMessageEvent = 0;
         $counter = 0;
         $flagFirstTime = false;
         $common->frontEndShow("START");
         do {
             $flagNextRecords = false;
             $arrayMessageApplicationUnread = $this->getMessageApplications(array("messageApplicationStatus" => "UNREAD"), null, null, 0, 1000);
             if (!$flagFirstTime) {
                 $totalMessageEvent = $arrayMessageApplicationUnread["total"];
                 $flagFirstTime = true;
             }
             foreach ($arrayMessageApplicationUnread["data"] as $value) {
                 if ($counter + 1 > $totalMessageEvent) {
                     $flagNextRecords = false;
                     break;
                 }
                 $arrayMessageApplicationData = $value;
                 $processUid = $arrayMessageApplicationData["PRJ_UID"];
                 $taskUid = $arrayMessageApplicationData["TAS_UID"];
                 $messageApplicationUid = $arrayMessageApplicationData["MSGAPP_UID"];
                 $messageApplicationCorrelation = $arrayMessageApplicationData["MSGAPP_CORRELATION"];
                 $messageEventDefinitionUserUid = $arrayMessageApplicationData["MSGED_USR_UID"];
                 $messageEventDefinitionCorrelation = $arrayMessageApplicationData["MSGED_CORRELATION"];
                 $arrayVariable = $this->mergeVariables($arrayMessageApplicationData["MSGED_VARIABLES"], $arrayMessageApplicationData["MSGAPP_VARIABLES"]);
                 $flagCatched = false;
                 switch ($arrayMessageApplicationData["EVN_TYPE"]) {
                     case "START":
                         if ($messageEventDefinitionCorrelation == $messageApplicationCorrelation && $messageEventDefinitionUserUid != "") {
                             //Start and derivate new Case
                             $result = $ws->newCase($processUid, $messageEventDefinitionUserUid, $taskUid, $arrayVariable);
                             $arrayResult = json_decode(json_encode($result), true);
                             if ($arrayResult["status_code"] == 0) {
                                 $applicationUid = $arrayResult["caseId"];
                                 $result = $ws->derivateCase($messageEventDefinitionUserUid, $applicationUid, 1);
                                 $flagCatched = true;
                                 //Counter
                                 $counterStartMessageEvent++;
                             }
                         }
                         break;
                     case "INTERMEDIATE":
                         $criteria = new \Criteria("workflow");
                         $criteria->addSelectColumn(\AppDelegationPeer::APP_UID);
                         $criteria->addSelectColumn(\AppDelegationPeer::DEL_INDEX);
                         $criteria->addSelectColumn(\AppDelegationPeer::USR_UID);
                         $criteria->add(\AppDelegationPeer::PRO_UID, $processUid, \Criteria::EQUAL);
                         $criteria->add(\AppDelegationPeer::TAS_UID, $taskUid, \Criteria::EQUAL);
                         $criteria->add(\AppDelegationPeer::DEL_THREAD_STATUS, "OPEN", \Criteria::EQUAL);
                         $criteria->add(\AppDelegationPeer::DEL_FINISH_DATE, null, \Criteria::ISNULL);
                         $rsCriteria = \AppDelegationPeer::doSelectRS($criteria);
                         $rsCriteria->setFetchmode(\ResultSet::FETCHMODE_ASSOC);
                         while ($rsCriteria->next()) {
                             $row = $rsCriteria->getRow();
                             $applicationUid = $row["APP_UID"];
                             $delIndex = $row["DEL_INDEX"];
                             $userUid = $row["USR_UID"];
                             $arrayApplicationData = $case->loadCase($applicationUid);
                             if (\G::replaceDataField($messageEventDefinitionCorrelation, $arrayApplicationData["APP_DATA"]) == $messageApplicationCorrelation) {
                                 //"Unpause" and derivate Case
                                 $arrayApplicationData["APP_DATA"] = array_merge($arrayApplicationData["APP_DATA"], $arrayVariable);
                                 $arrayResult = $case->updateCase($applicationUid, $arrayApplicationData);
                                 $result = $ws->derivateCase($userUid, $applicationUid, $delIndex);
                                 $flagCatched = true;
                             }
                         }
                         //Counter
                         if ($flagCatched) {
                             $counterIntermediateCatchMessageEvent++;
                         }
                         break;
                 }
                 //Message-Application catch
                 if ($flagCatched) {
                     $result = $this->update($messageApplicationUid, array("MSGAPP_STATUS" => "READ"));
                 }
                 $counter++;
                 //Progress bar
                 $common->frontEndShow("BAR", "Message-Events (unread): " . $counter . "/" . $totalMessageEvent . " " . $common->progressBar($totalMessageEvent, $counter));
                 $flagNextRecords = true;
             }
         } while ($flagNextRecords);
         $common->frontEndShow("TEXT", "Total Message-Events unread: " . $totalMessageEvent);
         $common->frontEndShow("TEXT", "Total cases started: " . $counterStartMessageEvent);
         $common->frontEndShow("TEXT", "Total cases continued: " . $counterIntermediateCatchMessageEvent);
         $common->frontEndShow("TEXT", "Total Message-Events pending: " . ($totalMessageEvent - ($counterStartMessageEvent + $counterIntermediateCatchMessageEvent)));
         $common->frontEndShow("END");
     } catch (\Exception $e) {
         throw $e;
     }
 }
        $_SESSION['TRIGGER_DEBUG']['info'][0]['TRIGGERS_NAMES'] = $oCase->getTriggerNames( $triggers );
        $_SESSION['TRIGGER_DEBUG']['info'][0]['TRIGGERS_VALUES'] = $triggers;
    }

    unset($appFields['APP_STATUS']);
    unset($appFields['APP_PROC_STATUS']);
    unset($appFields['APP_PROC_CODE']);
    unset($appFields['APP_PIN']);

    $appFields["DEL_INDEX"] = $_SESSION["INDEX"];
    $appFields["TAS_UID"]   = $_SESSION["TASK"];
    $appFields["USER_UID"]  = $_SESSION["USER_LOGGED"];
    $appFields["CURRENT_DYNAFORM"] = "-2";
    $appFields["OBJECT_TYPE"]      = "ASSIGN_TASK";

    $oCase->updateCase($_SESSION["APPLICATION"], $appFields); //Save data

    //derivate case
    $oDerivation = new Derivation();
    $aCurrentDerivation = array ('APP_UID' => $_SESSION['APPLICATION'],'DEL_INDEX' => $_SESSION['INDEX'],'APP_STATUS' => $sStatus,'TAS_UID' => $_SESSION['TASK'],'ROU_TYPE' => $_POST['form']['ROU_TYPE']
    );

    $oDerivation->derivate( $aCurrentDerivation, $_POST['form']['TASKS'] );

    $appFields = $oCase->loadCase( $_SESSION['APPLICATION'] ); //refresh appFields, because in derivations should change some values
    $triggers = $oCase->loadTriggers( $_SESSION['TASK'], 'ASSIGN_TASK', - 2, 'AFTER' ); //load the triggers after derivation
    if (sizeof( $triggers ) > 0) {
        $appFields['APP_DATA'] = $oCase->ExecuteTriggers( $_SESSION['TASK'], 'ASSIGN_TASK', - 2, 'AFTER', $appFields['APP_DATA'] ); //Execute triggers after derivation


        $_SESSION['TRIGGER_DEBUG']['info'][1]['NUM_TRIGGERS'] = sizeof( $triggers );
function handleFatalErrors($buffer)
{
    G::LoadClass('case');
    $oCase = new Cases();
    if (preg_match('/(error<\\/b>:)(.+)(<br)/', $buffer, $regs)) {
        $err = preg_replace('/<.*?>/', '', $regs[2]);
        $aAux = explode(' in ', $err);
        $sCode = $_SESSION['_CODE_'];
        unset($_SESSION['_CODE_']);
        registerError(2, $aAux[0], 0, $sCode);
        if (strpos($_SERVER['REQUEST_URI'], '/cases/cases_Step') !== false) {
            if (strpos($_SERVER['REQUEST_URI'], '&ACTION=GENERATE') !== false) {
                $aNextStep = $oCase->getNextStep($_SESSION['PROCESS'], $_SESSION['APPLICATION'], $_SESSION['INDEX'], $_SESSION['STEP_POSITION']);
                if ($_SESSION['TRIGGER_DEBUG']['ISSET']) {
                    $_SESSION['TRIGGER_DEBUG']['TIME'] = 'AFTER';
                    $_SESSION['TRIGGER_DEBUG']['BREAKPAGE'] = $aNextStep['PAGE'];
                    $aNextStep['PAGE'] = $aNextStep['PAGE'] . '&breakpoint=triggerdebug';
                }
                global $oPMScript;
                if (isset($oPMScript) && isset($_SESSION['APPLICATION'])) {
                    $oPMScript->aFields['__ERROR__'] = $aAux[0];
                    $oCase->updateCase($_SESSION['APPLICATION'], array('APP_DATA' => $oPMScript->aFields));
                }
                G::header('Location: ' . $aNextStep['PAGE']);
                die;
            }
            $_SESSION['_NO_EXECUTE_TRIGGERS_'] = 1;
            global $oPMScript;
            if (isset($oPMScript) && isset($_SESSION['APPLICATION'])) {
                $oPMScript->aFields['__ERROR__'] = $aAux[0];
                $oCase->updateCase($_SESSION['APPLICATION'], array('APP_DATA' => $oPMScript->aFields));
            }
            G::header('Location: ' . $_SERVER['REQUEST_URI']);
            die;
        } else {
            $aNextStep = $oCase->getNextStep($_SESSION['PROCESS'], $_SESSION['APPLICATION'], $_SESSION['INDEX'], $_SESSION['STEP_POSITION']);
            if ($_SESSION['TRIGGER_DEBUG']['ISSET']) {
                $_SESSION['TRIGGER_DEBUG']['TIME'] = 'AFTER';
                $_SESSION['TRIGGER_DEBUG']['BREAKPAGE'] = $aNextStep['PAGE'];
                $aNextStep['PAGE'] = $aNextStep['PAGE'] . '&breakpoint=triggerdebug';
            }
            if (strpos($aNextStep['PAGE'], 'TYPE=ASSIGN_TASK&UID=-1') !== false) {
                G::SendMessageText('Fatal error in trigger', 'error');
            }
            global $oPMScript;
            if (isset($oPMScript) && isset($_SESSION['APPLICATION'])) {
                $oPMScript->aFields['__ERROR__'] = $aAux[0];
                $oCase->updateCase($_SESSION['APPLICATION'], array('APP_DATA' => $oPMScript->aFields));
            }
            G::header('Location: ' . $aNextStep['PAGE']);
            die;
        }
    }
    return $buffer;
}
Exemple #17
0
 /**
  * Get data of Cases InputDocument
  *
  * @param string $applicationUid
  * @param string $taskUid
  * @param string $appDocComment
  * @param string $inputDocumentUid
  * @param string $userUid
  *
  * return array Return an array with data of an InputDocument
  */
 public function addCasesInputDocument($applicationUid, $taskUid, $appDocComment, $inputDocumentUid, $userUid)
 {
     try {
         if ((isset( $_FILES['form'] )) && ($_FILES['form']['error'] != 0)) {
             $code = $_FILES['form']['error'];
             switch ($code) {
                 case UPLOAD_ERR_INI_SIZE:
                     $message = \G::LoadTranslation( 'ID_UPLOAD_ERR_INI_SIZE' );
                     break;
                 case UPLOAD_ERR_FORM_SIZE:
                     $message = \G::LoadTranslation( 'ID_UPLOAD_ERR_FORM_SIZE' );
                     break;
                 case UPLOAD_ERR_PARTIAL:
                     $message = \G::LoadTranslation( 'ID_UPLOAD_ERR_PARTIAL' );
                     break;
                 case UPLOAD_ERR_NO_FILE:
                     $message = \G::LoadTranslation( 'ID_UPLOAD_ERR_NO_FILE' );
                     break;
                 case UPLOAD_ERR_NO_TMP_DIR:
                     $message = \G::LoadTranslation( 'ID_UPLOAD_ERR_NO_TMP_DIR' );
                     break;
                 case UPLOAD_ERR_CANT_WRITE:
                     $message = \G::LoadTranslation( 'ID_UPLOAD_ERR_CANT_WRITE' );
                     break;
                 case UPLOAD_ERR_EXTENSION:
                     $message = \G::LoadTranslation( 'ID_UPLOAD_ERR_EXTENSION' );
                     break;
                 default:
                     $message = \G::LoadTranslation( 'ID_UPLOAD_ERR_UNKNOWN' );
                     break;
             }
             \G::SendMessageText( $message, "ERROR" );
             $backUrlObj = explode( "sys" . SYS_SYS, $_SERVER['HTTP_REFERER'] );
             \G::header( "location: " . "/sys" . SYS_SYS . $backUrlObj[1] );
             die();
         }
         \G::LoadClass("case");
         $appDocUid = \G::generateUniqueID();
         $docVersion = '';
         $appDocType = 'INPUT';
         $case = new \Cases();
         $delIndex = \AppDelegation::getCurrentIndex($applicationUid);
         $case->thisIsTheCurrentUser($applicationUid, $delIndex, $userUid, "REDIRECT", "casesListExtJs");
         //Load the fields
         $arrayField = $case->loadCase($applicationUid);
         $arrayField["APP_DATA"] = array_merge($arrayField["APP_DATA"], \G::getSystemConstants());
         //Triggers
         $arrayTrigger = $case->loadTriggers($taskUid, "INPUT_DOCUMENT", $inputDocumentUid, "AFTER");
         //Add Input Document
         if (empty($_FILES)) {
             throw new \Exception(\G::LoadTranslation("ID_CASES_INPUT_FILENAME_DOES_NOT_EXIST"));
         }
         if (!$_FILES["form"]["error"]) {
             $_FILES["form"]["error"] = 0;
         }
         if (isset($_FILES) && isset($_FILES["form"]) && count($_FILES["form"]) > 0) {
             $appDocUid = $case->addInputDocument($inputDocumentUid,
                 $appDocUid,
                 $docVersion,
                 $appDocType,
                 $appDocComment,
                 '',
                 $applicationUid,
                 $delIndex,
                 $taskUid,
                 $userUid,
                 "xmlform",
                 $_FILES["form"]["name"],
                 $_FILES["form"]["error"],
                 $_FILES["form"]["tmp_name"]);
         }
         //Trigger - Execute after - Start
         $arrayField["APP_DATA"] = $case->executeTriggers ($taskUid,
             "INPUT_DOCUMENT",
             $inputDocumentUid,
             "AFTER",
             $arrayField["APP_DATA"]);
         //Trigger - Execute after - End
         //Save data
         $arrayData = array();
         $arrayData["APP_NUMBER"] = $arrayField["APP_NUMBER"];
         //$arrayData["APP_PROC_STATUS"] = $arrayField["APP_PROC_STATUS"];
         $arrayData["APP_DATA"]  = $arrayField["APP_DATA"];
         $arrayData["DEL_INDEX"] = $delIndex;
         $arrayData["TAS_UID"]   = $taskUid;
         $case->updateCase($applicationUid, $arrayData);
         return($this->getCasesInputDocument($applicationUid, $userUid, $appDocUid));
     } catch (\Exception $e) {
         throw $e;
     }
 }
             }
         }
     }
 }
 //save data
 $aData = array();
 $aData['APP_NUMBER'] = $Fields['APP_NUMBER'];
 $aData['APP_PROC_STATUS'] = $Fields['APP_PROC_STATUS'];
 $aData['APP_DATA'] = $Fields['APP_DATA'];
 $aData['DEL_INDEX'] = $_SESSION['INDEX'];
 $aData['TAS_UID'] = $_SESSION['TASK'];
 $aData['CURRENT_DYNAFORM'] = $_GET['UID'];
 $aData['USER_UID'] = $_SESSION['USER_LOGGED'];
 $aData['APP_STATUS'] = $Fields['APP_STATUS'];
 $aData['PRO_UID'] = $_SESSION['PROCESS'];
 $oCase->updateCase($_SESSION['APPLICATION'], $aData);
 // saving the data ina pm table in case that is a new record
 if (!empty($newValues)) {
     $id = key($newValues);
     if (!$oAdditionalTables->updateDataInTable($oForm->fields[$oForm->fields[$id]->pmconnection]->pmtable, $newValues)) {
         //<--This is to know if it is a new registry on the PM Table
         $oAdditionalTables->saveDataInTable($oForm->fields[$oForm->fields[$id]->pmconnection]->pmtable, $newValues);
     }
 }
 //Save files
 //require_once ("classes/model/AppDocument.php");
 if (isset($_FILES["form"]["name"]) && count($_FILES["form"]["name"]) > 0) {
     $arrayField = array();
     $arrayFileName = array();
     $arrayFileTmpName = array();
     $arrayFileError = array();
         $util->setOutputPath($javaOutput);
         copy(PATH_DYNAFORM . $aOD['PRO_UID'] . PATH_SEP . $aOD['OUT_DOC_UID'] . '.pdf', $javaInput . $aOD['OUT_DOC_UID'] . '.pdf');
         $outputFile = $javaOutput . $sFilename . '.pdf';
         print $util->writeVarsToAcroFields($aOD['OUT_DOC_UID'] . '.pdf', $xmlData);
         copy($javaOutput . $aOD['OUT_DOC_UID'] . '.pdf', $pathOutput . $sFilename . '.pdf');
         break;
     default:
         throw new Exception('invalid output document');
 }
 //Execute after triggers - Start
 $Fields['APP_DATA'] = $oCase->ExecuteTriggers($_SESSION['TASK'], 'OUTPUT_DOCUMENT', $_GET['UID'], 'AFTER', $Fields['APP_DATA']);
 $Fields['DEL_INDEX'] = $_SESSION['INDEX'];
 $Fields['TAS_UID'] = $_SESSION['TASK'];
 //Execute after triggers - End
 //Save data - Start
 $oCase->updateCase($_SESSION['APPLICATION'], $Fields);
 //Save data - End
 //Plugin Hook PM_UPLOAD_DOCUMENT for upload document
 $oPluginRegistry =& PMPluginRegistry::getSingleton();
 if ($oPluginRegistry->existsTrigger(PM_UPLOAD_DOCUMENT) && class_exists('uploadDocumentData')) {
     $triggerDetail = $oPluginRegistry->getTriggerInfo(PM_UPLOAD_DOCUMENT);
     $sPathName = PATH_DOCUMENT . $_SESSION['APPLICATION'] . PATH_SEP;
     $oData['APP_UID'] = $_SESSION['APPLICATION'];
     $oData['ATTACHMENT_FOLDER'] = true;
     switch ($aOD['OUT_DOC_GENERATE']) {
         case "BOTH":
             $documentData = new uploadDocumentData($_SESSION['APPLICATION'], $_SESSION['USER_LOGGED'], $pathOutput . $sFilename . '.pdf', $sFilenameOriginal . '.pdf', $sDocUID, $oAppDocument->getDocVersion());
             $documentData->sFileType = "PDF";
             $documentData->bUseOutputFolder = true;
             $uploadReturn = $oPluginRegistry->executeTriggers(PM_UPLOAD_DOCUMENT, $documentData);
             if ($uploadReturn) {
Exemple #20
0
 public function executeEvents($sNow, $debug = false, &$log = array(), $cron = 0)
 {
     require_once 'classes/model/Configuration.php';
     require_once 'classes/model/Triggers.php';
     G::LoadClass('case');
     $debug = 1;
     $oCase = new Cases();
     try {
         $oCriteria = new Criteria('workflow');
         $oCriteria->addSelectColumn(AppEventPeer::APP_UID);
         $oCriteria->addSelectColumn(AppEventPeer::DEL_INDEX);
         $oCriteria->addSelectColumn(AppEventPeer::EVN_UID);
         $oCriteria->addSelectColumn(AppEventPeer::APP_EVN_ACTION_DATE);
         $oCriteria->addSelectColumn(AppEventPeer::APP_EVN_ATTEMPTS);
         $oCriteria->addSelectColumn(AppEventPeer::APP_EVN_LAST_EXECUTION_DATE);
         $oCriteria->addSelectColumn(AppEventPeer::APP_EVN_STATUS);
         $oCriteria->addSelectColumn(EventPeer::PRO_UID);
         $oCriteria->addSelectColumn(EventPeer::EVN_ACTION);
         $oCriteria->addSelectColumn(EventPeer::TRI_UID);
         $oCriteria->addSelectColumn(EventPeer::EVN_ACTION_PARAMETERS);
         $oCriteria->addSelectColumn(EventPeer::EVN_RELATED_TO);
         $oCriteria->addSelectColumn(AppDelegationPeer::TAS_UID);
         $oCriteria->addSelectColumn(AppDelegationPeer::USR_UID);
         $oCriteria->addSelectColumn(AppDelegationPeer::DEL_TASK_DUE_DATE);
         $oCriteria->addSelectColumn(AppDelegationPeer::DEL_FINISH_DATE);
         $oCriteria->addJoin(AppEventPeer::EVN_UID, EventPeer::EVN_UID, Criteria::JOIN);
         $aConditions = array();
         array_push($aConditions, array(AppEventPeer::APP_UID, AppDelegationPeer::APP_UID));
         array_push($aConditions, array(AppEventPeer::DEL_INDEX, AppDelegationPeer::DEL_INDEX));
         $oCriteria->addJoinMC($aConditions, Criteria::LEFT_JOIN);
         $oCriteria->addJoin(ApplicationPeer::APP_UID, AppEventPeer::APP_UID);
         $oCriteria->add(AppDelegationPeer::DEL_FINISH_DATE, null, Criteria::ISNULL);
         //by me
         $oCriteria->add(AppEventPeer::APP_EVN_STATUS, 'OPEN');
         $oCriteria->add(AppEventPeer::APP_EVN_ACTION_DATE, $sNow, Criteria::LESS_EQUAL);
         $oDataset = AppEventPeer::doSelectRS($oCriteria);
         $oDataset->setFetchmode(ResultSet::FETCHMODE_ASSOC);
         $c = 0;
         while ($oDataset->next()) {
             if ($cron == 1) {
                 $arrayCron = unserialize(trim(@file_get_contents(PATH_DATA . "cron")));
                 $arrayCron["processcTimeStart"] = time();
                 @file_put_contents(PATH_DATA . "cron", serialize($arrayCron));
             }
             $c++;
             $aRow = $oDataset->getRow();
             $oTrigger = new Triggers();
             $aFields = $oCase->loadCase($aRow['APP_UID']);
             $oAppEvent = AppEventPeer::retrieveByPK($aRow['APP_UID'], $aRow['DEL_INDEX'], $aRow['EVN_UID']);
             //g::pr($aRow); //die;
             if ($debug) {
                 require_once 'classes/model/Application.php';
                 $oApp = ApplicationPeer::retrieveByPk($aRow['APP_UID']);
                 $oEv = EventPeer::retrieveByPk($aRow['EVN_UID']);
                 $log[] = 'Event ' . $oEv->getEvnDescription() . ' with ID ' . $aRow['EVN_UID'];
                 println("\nOK+ event \"" . $oEv->getEvnDescription() . "\" with ID {} was found");
                 println(" - PROCESS................" . $aRow['PRO_UID']);
                 println(" - APPLICATION............" . $aRow['APP_UID'] . " CASE #" . $oApp->getAppNumber());
                 println(" - ACTION DATE............" . $aRow['APP_EVN_ACTION_DATE']);
                 println(" - ATTEMPTS..............." . $aRow['APP_EVN_ATTEMPTS']);
                 println(" - INTERVAL WITH TASKS...." . $aRow['EVN_RELATED_TO']);
             }
             if ($aRow['TRI_UID'] == '') {
                 //a rare case when the tri_uid is not set.
                 $log[] = " (!) Any trigger was set................................SKIPPED and will be CLOSED";
                 if ($debug) {
                     println(" (!) Any trigger was set................................SKIPPED and will be CLOSED");
                 }
                 $oAppEvent->setAppEvnStatus('CLOSE');
                 $oAppEvent->save();
                 continue;
             }
             $oTrigger = TriggersPeer::retrieveByPk($aRow['TRI_UID']);
             if (!is_object($oTrigger)) {
                 //the trigger record doesn't exist..
                 $log[] = ' (!) The trigger ' . $aRow['TRI_UID'] . ' ' . $oTrigger->getTriTitle() . " doesn't exist.......SKIPPED and will be CLOSED";
                 if ($debug) {
                     println(" (!) The trigger {$aRow['TRI_UID']} {$oTrigger->getTriTitle()} doesn't exist.......SKIPPED and will be CLOSED");
                 }
                 $oAppEvent->setAppEvnStatus('CLOSE');
                 $oAppEvent->save();
                 continue;
             }
             global $oPMScript;
             $oPMScript = new PMScript();
             $task = new Task();
             $taskFields = $task->Load($aRow['TAS_UID']);
             $aFields['APP_DATA']['APP_NUMBER'] = $aFields['APP_NUMBER'];
             $aFields['APP_DATA']['TAS_TITLE'] = $taskFields['TAS_TITLE'];
             $aFields['APP_DATA']['DEL_TASK_DUE_DATE'] = $aRow['DEL_TASK_DUE_DATE'];
             $oPMScript->setFields($aFields['APP_DATA']);
             $oPMScript->setScript($oTrigger->getTriWebbot());
             $oPMScript->execute();
             $oAppEvent->setAppEvnLastExecutionDate(date('Y-m-d H:i:s'));
             if (sizeof($_SESSION['TRIGGER_DEBUG']['ERRORS']) == 0) {
                 $log[] = ' - The trigger ' . $oTrigger->getTriTitle() . ' was executed successfully!';
                 if ($debug) {
                     println(" - The trigger '{$oTrigger->getTriTitle()}' was executed successfully!");
                     //g::pr($aFields);
                 }
                 $aFields['APP_DATA'] = $oPMScript->aFields;
                 $oCase->updateCase($aRow['APP_UID'], $aFields);
                 $oAppEvent->setAppEvnStatus('CLOSE');
             } else {
                 if ($debug) {
                     $log[] = ' - The trigger ' . $aRow['TRI_UID'] . ' throw some errors!';
                     println(" - The trigger {$aRow['TRI_UID']} throw some errors!");
                     print_r($_SESSION['TRIGGER_DEBUG']['ERRORS']);
                 }
                 if ($oAppEvent->getAppEvnAttempts() > 0) {
                     $oAppEvent->setAppEvnAttempts($oAppEvent->getAppEvnAttempts() - 1);
                 } else {
                     $oAppEvent->setAppEvnStatus('CLOSE');
                 }
             }
             $oAppEvent->save();
         }
         return $c;
     } catch (Exception $oError) {
         $log[] = ' Error execute event : ' . $oError->getMessage();
         die($oError->getMessage());
         return $oError->getMessage();
     }
 }