} else {
    $_SESSION['TRIGGER_DEBUG']['ISSET'] = 0;
    $_SESSION['PMDEBUGGER'] = false;
}
//cleaning debug variables
if (!isset($_GET['breakpoint'])) {
    if (isset($_SESSION['TRIGGER_DEBUG']['info'])) {
        unset($_SESSION['TRIGGER_DEBUG']['info']);
    }
    if (!isset($_SESSION['_NO_EXECUTE_TRIGGERS_'])) {
        $_SESSION['TRIGGER_DEBUG']['ERRORS'] = array();
    }
    $_SESSION['TRIGGER_DEBUG']['DATA'] = array();
    $_SESSION['TRIGGER_DEBUG']['TRIGGERS_NAMES'] = array();
    $_SESSION['TRIGGER_DEBUG']['TRIGGERS_VALUES'] = array();
    $triggers = $oCase->loadTriggers($_SESSION['TASK'], $_GET['TYPE'], $_GET['UID'], 'BEFORE');
    $_SESSION['TRIGGER_DEBUG']['NUM_TRIGGERS'] = count($triggers);
    $_SESSION['TRIGGER_DEBUG']['TIME'] = 'BEFORE';
    if ($_SESSION['TRIGGER_DEBUG']['NUM_TRIGGERS'] != 0) {
        $_SESSION['TRIGGER_DEBUG']['TRIGGERS_NAMES'] = $oCase->getTriggerNames($triggers);
        $_SESSION['TRIGGER_DEBUG']['TRIGGERS_VALUES'] = $triggers;
    }
    if (!isset($_SESSION['_NO_EXECUTE_TRIGGERS_'])) {
        //Execute before triggers - Start
        $Fields['APP_DATA'] = $oCase->ExecuteTriggers($_SESSION['TASK'], $_GET['TYPE'], $_GET['UID'], 'BEFORE', $Fields['APP_DATA']);
        $Fields['DEL_INDEX'] = $_SESSION['INDEX'];
        $Fields['TAS_UID'] = $_SESSION['TASK'];
        //Execute before triggers - End
    } else {
        unset($_SESSION['_NO_EXECUTE_TRIGGERS_']);
        $Fields['DEL_INDEX'] = $_SESSION['INDEX'];
    /**

     * derivate Case moves the case to the next task in the process according to the routing rules

     *

     * @param string $userId

     * @param string $caseId

     * @param string $delIndex

     * @param array $tasks

     * @param bool   $bExecuteTriggersBeforeAssignment

     * @return $result will return an object

     */

    public function derivateCase ($userId, $caseId, $delIndex, $bExecuteTriggersBeforeAssignment = false, $tasks = array())

    {

        $g = new G();



        try {

            $g->sessionVarSave();



            $_SESSION["APPLICATION"] = $caseId;

            $_SESSION["INDEX"] = $delIndex;

            $_SESSION["USER_LOGGED"] = $userId;



            $sStatus = 'TO_DO';



            $varResponse = '';

            $varTriggers = "\n";



            if ($delIndex == '') {

                $oCriteria = new Criteria( 'workflow' );

                $oCriteria->addSelectColumn( AppDelegationPeer::DEL_INDEX );

                $oCriteria->add( AppDelegationPeer::APP_UID, $caseId );

                $oCriteria->add( AppDelegationPeer::DEL_FINISH_DATE, null, Criteria::ISNULL );



                if (AppDelegationPeer::doCount( $oCriteria ) > 1) {

                    $result = new wsResponse( 20, G::loadTranslation( 'ID_SPECIFY_DELEGATION_INDEX' ) );

                    return $result;

                }



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

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

                $oDataset->next();

                $aRow = $oDataset->getRow();

                $delIndex = $aRow['DEL_INDEX'];

            }



            $oAppDel = new AppDelegation();

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



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

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



                return $result;

            }



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

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



                return $result;

            }



            $oCriteria = new Criteria( 'workflow' );

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

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

            $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 (isset( $aRow['APP_DISABLE_ACTION_USER'] ) && $aRow['APP_DISABLE_ACTION_USER'] != 0 && isset( $aRow['APP_DISABLE_ACTION_DATE'] ) && $aRow['APP_DISABLE_ACTION_DATE'] != '') {

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



                    return $result;

                }

            }



            $aData = array();

            $aData['APP_UID'] = $caseId;

            $aData['DEL_INDEX'] = $delIndex;

            $aData['USER_UID'] = $userId;



            //Load data

            $oCase = new Cases();

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



            if (is_null( $appFields["DEL_INIT_DATE"] )) {

                $oCase->setDelInitDate( $caseId, $delIndex );

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

            }



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



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

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

            }



            if ($bExecuteTriggersBeforeAssignment) {

                //Execute triggers before assignment

                $aTriggers = $oCase->loadTriggers( $appdel['TAS_UID'], 'ASSIGN_TASK', - 1, 'BEFORE' );



                if (count( $aTriggers ) > 0) {

                    $varTriggers = $varTriggers . "<br /><b>-= Before Assignment =-</b><br />";



                    $oPMScript = new PMScript();



                    foreach ($aTriggers as $aTrigger) {

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

                        //$appFields['APP_DATA']['APPLICATION'] = $caseId;





                        //Set variables

                        $params = new stdClass();

                        $params->appData = $appFields["APP_DATA"];



                        if ($this->stored_system_variables) {

                            $params->option = "STORED SESSION";

                            $params->SID = $this->wsSessionId;

                        }



                        $appFields["APP_DATA"] = array_merge( $appFields["APP_DATA"], G::getSystemConstants( $params ) );



                        //PMScript

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

                        $bExecute = true;



                        if ($aTrigger['ST_CONDITION'] !== '') {

                            $oPMScript->setScript( $aTrigger['ST_CONDITION'] );

                            $bExecute = $oPMScript->evaluate();

                        }



                        if ($bExecute) {

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

                            $oPMScript->execute();



                            $trigger = TriggersPeer::retrieveByPk($aTrigger["TRI_UID"]);

                            $varTriggers = $varTriggers . "&nbsp;- " . nl2br(htmlentities($trigger->getTriTitle(), ENT_QUOTES)) . "<br />";



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

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

                            unset($appFields['APP_STATUS']);

                            unset($appFields['APP_PROC_STATUS']);

                            unset($appFields['APP_PROC_CODE']);

                            unset($appFields['APP_PIN']);

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

                        }

                    }

                }

            }



            //Execute triggers before derivation BEFORE_ROUTING

            $aTriggers = $oCase->loadTriggers( $appdel['TAS_UID'], 'ASSIGN_TASK', - 2, 'BEFORE' );



            if (count( $aTriggers ) > 0) {

                $varTriggers .= "<b>-= Before Derivation =-</b><br/>";



                $oPMScript = new PMScript();



                foreach ($aTriggers as $aTrigger) {

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

                    //$appFields['APP_DATA']['APPLICATION'] = $caseId;





                    //Set variables

                    $params = new stdClass();

                    $params->appData = $appFields["APP_DATA"];



                    if ($this->stored_system_variables) {

                        $params->option = "STORED SESSION";

                        $params->SID = $this->wsSessionId;

                    }



                    $appFields["APP_DATA"] = array_merge( $appFields["APP_DATA"], G::getSystemConstants( $params ) );



                    //PMScript

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

                    $bExecute = true;



                    if ($aTrigger['ST_CONDITION'] !== '') {

                        $oPMScript->setScript( $aTrigger['ST_CONDITION'] );

                        $bExecute = $oPMScript->evaluate();

                    }



                    if ($bExecute) {

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

                        $oPMScript->execute();



                        $oTrigger = TriggersPeer::retrieveByPk( $aTrigger['TRI_UID'] );

                        $varTriggers .= "&nbsp;- " . nl2br( htmlentities( $oTrigger->getTriTitle(), ENT_QUOTES ) ) . "<br/>";

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

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

                        unset($appFields['APP_STATUS']);

                        unset($appFields['APP_PROC_STATUS']);

                        unset($appFields['APP_PROC_CODE']);

                        unset($appFields['APP_PIN']);

                        //$appFields['APP_DATA']['APPLICATION'] = $caseId;

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

                    }

                }

            }



            $oDerivation = new Derivation();

            if (!empty($tasks)) {

                $nextDelegations = $tasks;

            } else {

                $derive = $oDerivation->prepareInformation($aData);



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

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

                        $result = new wsResponse(21, G::loadTranslation('ID_CAN_NOT_ROUTE_CASE_USING_WEBSERVICES'));



                        return $result;

                    }

                } else {

                    $result = new wsResponse(22, G::loadTranslation('ID_TASK_DOES_NOT_HAVE_ROUTING_RULE'));



                    return $result;

                }



                foreach ($derive as $key => $val) {

                    if ($val['NEXT_TASK']['TAS_ASSIGN_TYPE'] == 'MANUAL') {

                        $result = new wsResponse(15, G::loadTranslation('ID_TASK_DEFINED_MANUAL_ASSIGNMENT'));



                        return $result;

                    }



                    //Routed to the next task, if end process then not exist user

                    $nodeNext = array();

                    $usrasgdUid = null;

                    $usrasgdUserName = null;



                    if (isset($val['NEXT_TASK']['USER_ASSIGNED'])) {

                        $usrasgdUid = $val['NEXT_TASK']['USER_ASSIGNED']['USR_UID'];

                        $usrasgdUserName = '******' . $val['NEXT_TASK']['USER_ASSIGNED']['USR_USERNAME'] . ')';

                    }



                    $nodeNext['TAS_UID'] = $val['NEXT_TASK']['TAS_UID'];

                    $nodeNext['USR_UID'] = $usrasgdUid;

                    $nodeNext['TAS_ASSIGN_TYPE'] = $val['NEXT_TASK']['TAS_ASSIGN_TYPE'];

                    $nodeNext['TAS_DEF_PROC_CODE'] = $val['NEXT_TASK']['TAS_DEF_PROC_CODE'];

                    $nodeNext['DEL_PRIORITY'] = $appdel['DEL_PRIORITY'];

                    $nodeNext['TAS_PARENT'] = $val['NEXT_TASK']['TAS_PARENT'];



                    $nextDelegations[] = $nodeNext;

                    $varResponse = $varResponse . (($varResponse != '') ? ',' : '') . $val['NEXT_TASK']['TAS_TITLE'] . $usrasgdUserName;

                }

            }

            $appFields['DEL_INDEX'] = $delIndex;



            if (isset( $derive['TAS_UID'] )) {

                $appFields['TAS_UID'] = $derive['TAS_UID'];

            }



            //Save data - Start

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

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

            //Save data - End





            $row = array ();

            $oCriteria = new Criteria( 'workflow' );

            $del = DBAdapter::getStringDelimiter();

            $oCriteria->addSelectColumn( RoutePeer::ROU_TYPE );

            $oCriteria->addSelectColumn( RoutePeer::ROU_NEXT_TASK );

            $oCriteria->add( RoutePeer::TAS_UID, $appdel['TAS_UID'] );

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

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

            $oDataset->next();



            while ($aRow = $oDataset->getRow()) {

                $row[] = array ('ROU_TYPE' => $aRow['ROU_TYPE'],'ROU_NEXT_TASK' => $aRow['ROU_NEXT_TASK']

                );

                $oDataset->next();

            }



            //derivate case

            $aCurrentDerivation = array ('APP_UID' => $caseId,'DEL_INDEX' => $delIndex,'APP_STATUS' => $sStatus,'TAS_UID' => $appdel['TAS_UID'],'ROU_TYPE' => $row[0]['ROU_TYPE']

            );



            $oDerivation->derivate( $aCurrentDerivation, $nextDelegations );

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



            //Execute triggers after derivation

            $aTriggers = $oCase->loadTriggers( $appdel['TAS_UID'], 'ASSIGN_TASK', - 2, 'AFTER' );



            if (count( $aTriggers ) > 0) {

                //$appFields['APP_DATA']['APPLICATION'] = $caseId;





                //Set variables

                $params = new stdClass();

                $params->appData = $appFields["APP_DATA"];



                if ($this->stored_system_variables) {

                    $params->option = "STORED SESSION";

                    $params->SID = $this->wsSessionId;

                }



                $appFields["APP_DATA"] = array_merge( $appFields["APP_DATA"], G::getSystemConstants( $params ) );



                //PMScript

                $oPMScript = new PMScript();

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



                $varTriggers .= "<b>-= After Derivation =-</b><br/>";



                foreach ($aTriggers as $aTrigger) {

                    $bExecute = true;



                    if ($aTrigger['ST_CONDITION'] !== '') {

                        $oPMScript->setScript( $aTrigger['ST_CONDITION'] );

                        $bExecute = $oPMScript->evaluate();

                    }



                    if ($bExecute) {

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

                        $oPMScript->execute();



                        $oTrigger = TriggersPeer::retrieveByPk( $aTrigger['TRI_UID'] );

                        $varTriggers .= "&nbsp;- " . nl2br( htmlentities( $oTrigger->getTriTitle(), ENT_QUOTES ) ) . "<br/>";

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

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

                        //$appFields['APP_DATA']['APPLICATION'] = $caseId;

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

                        unset($aFields['APP_STATUS']);

                        unset($aFields['APP_PROC_STATUS']);

                        unset($aFields['APP_PROC_CODE']);

                        unset($aFields['APP_PIN']);

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

                    }

                }

            }



            $sFromName = "";



            if ($userId != "") {

                $user = new Users();



                $arrayUserData = $user->load($userId);



                if (trim($arrayUserData["USR_EMAIL"]) == "") {

                    $arrayUserData["USR_EMAIL"] = "info@" . $_SERVER["HTTP_HOST"];

                }



                $sFromName = "\"" . $arrayUserData["USR_FIRSTNAME"] . " " . $arrayUserData["USR_LASTNAME"] . "\" <" . $arrayUserData["USR_EMAIL"] . ">";

            }



            $oCase->sendNotifications( $appdel['TAS_UID'], $nextDelegations, $appFields['APP_DATA'], $caseId, $delIndex, $sFromName );



            // Send notifications Mobile - Start

            try {

                $oLight = new \ProcessMaker\BusinessModel\Light();

                $nextIndex = $oLight->getInformationDerivatedCase($appFields['APP_UID'], $delIndex);

                $notificationMobile = new \ProcessMaker\BusinessModel\Light\NotificationDevice();

                $notificationMobile->routeCaseNotification($userId, $_SESSION["PROCESS"], $appdel['TAS_UID'], $appFields, $nextDelegations, $nextIndex);

            } catch (Exception $e) {

                \G::log(G::loadTranslation( 'ID_NOTIFICATION_ERROR' ) . '|' . $e->getMessage() , PATH_DATA, "mobile.log");

            }

            // Send notifications Mobile - End



            //Save data - Start

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

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

            //Save data - End





            $oProcess = new Process();

            $oProcessFieds = $oProcess->Load( $appFields['PRO_UID'] );

            //here dubug mode in web entry





            if (isset( $oProcessFieds['PRO_DEBUG'] ) && $oProcessFieds['PRO_DEBUG']) {

                $result = new wsResponse( 0, $varResponse . "

                        <br><br><table width='100%' cellpadding='0' cellspacing='0'><tr><td class='FormTitle'>

                    " . G::LoadTranslation( 'ID_DEBUG_MESSAGE' ) . "</td></tr></table>" . $varTriggers );

            } else {

                $result = new wsResponse( 0, $varResponse . " --- " . $oProcessFieds['PRO_DEBUG'] );

            }



            $res = $result->getPayloadArray();



            //now fill the array of AppDelegationPeer

            $oCriteria = new Criteria( 'workflow' );

            $oCriteria->addSelectColumn( AppDelegationPeer::DEL_INDEX );

            $oCriteria->addSelectColumn( AppDelegationPeer::USR_UID );

            $oCriteria->addSelectColumn( AppDelegationPeer::TAS_UID );

            $oCriteria->addSelectColumn( AppDelegationPeer::DEL_THREAD );

            $oCriteria->addSelectColumn( AppDelegationPeer::DEL_THREAD_STATUS );

            $oCriteria->addSelectColumn( AppDelegationPeer::DEL_FINISH_DATE );

            $oCriteria->add( AppDelegationPeer::APP_UID, $caseId );

            $oCriteria->add( AppDelegationPeer::DEL_PREVIOUS, $delIndex );

            $oCriteria->addAscendingOrderByColumn( AppDelegationPeer::DEL_INDEX );

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

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



            $aCurrentUsers = array ();



            while ($oDataset->next()) {

                $aAppDel = $oDataset->getRow();



                $oUser = new Users();



                try {

                    $oUser->load( $aAppDel['USR_UID'] );

                    $uFields = $oUser->toArray( BasePeer::TYPE_FIELDNAME );

                    $currentUserName = $oUser->getUsrFirstname() . ' ' . $oUser->getUsrLastname();

                } catch (Exception $e) {

                    $currentUserName = '';

                }



                $oTask = new Task();



                try {

                    $uFields = $oTask->load( $aAppDel['TAS_UID'] );

                    $taskName = $uFields['TAS_TITLE'];

                } catch (Exception $e) {

                    $taskName = '';

                }



                // execute events

                $eventPro = $_SESSION["PROCESS"];

                $eventApp = $caseId;

                $eventInd = $aAppDel['DEL_INDEX'];

                $eventTas = $aAppDel['TAS_UID'];



                $oEvent = new Event();

                $oEvent->createAppEvents( $eventPro, $eventApp, $eventInd, $eventTas );

                // end events





                $currentUser = new stdClass();

                $currentUser->userId = $aAppDel['USR_UID'];

                $currentUser->userName = $currentUserName;

                $currentUser->taskId = $aAppDel['TAS_UID'];

                $currentUser->taskName = $taskName;

                $currentUser->delIndex = $aAppDel['DEL_INDEX'];

                $currentUser->delThread = $aAppDel['DEL_THREAD'];

                $currentUser->delThreadStatus = $aAppDel['DEL_THREAD_STATUS'];

                $aCurrentUsers[] = $currentUser;

            }



            $res['routing'] = $aCurrentUsers;



            $g->sessionVarRestore();



            return $res;

        } catch (Exception $e) {

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



            $g->sessionVarRestore();



            return $result;

        }

    }
Exemple #3
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;
     }
 }
}
G::LoadClass("case");
$inputDocumentUid = $_GET["UID"];
//$_POST["form"]["DOC_UID"]
$appDocUid = $_POST["form"]["APP_DOC_UID"];
$docVersion = intval($_POST["form"]["docVersion"]);
$appDocType = $_POST["form"]["APP_DOC_TYPE"];
$appDocComment = isset($_POST["form"]["APP_DOC_COMMENT"]) ? $_POST["form"]["APP_DOC_COMMENT"] : "";
$actionType = $_POST["form"]["actionType"];
$case = new Cases();
$case->thisIsTheCurrentUser($_SESSION["APPLICATION"], $_SESSION["INDEX"], $_SESSION["USER_LOGGED"], "REDIRECT", "casesListExtJs");
//Load the fields
$arrayField = $case->loadCase($_SESSION["APPLICATION"]);
$arrayField["APP_DATA"] = array_merge($arrayField["APP_DATA"], G::getSystemConstants());
//Triggers
$arrayTrigger = $case->loadTriggers($_SESSION["TASK"], "INPUT_DOCUMENT", $inputDocumentUid, "AFTER");
//Trigger debug routines
//Cleaning debug variables
$_SESSION["TRIGGER_DEBUG"]["ERRORS"] = array();
$_SESSION["TRIGGER_DEBUG"]["DATA"] = array();
$_SESSION["TRIGGER_DEBUG"]["TRIGGERS_NAMES"] = array();
$_SESSION["TRIGGER_DEBUG"]["TRIGGERS_VALUES"] = array();
$_SESSION["TRIGGER_DEBUG"]["NUM_TRIGGERS"] = count($arrayTrigger);
$_SESSION["TRIGGER_DEBUG"]["TIME"] = "AFTER";
if ($_SESSION["TRIGGER_DEBUG"]["NUM_TRIGGERS"] > 0) {
    $_SESSION["TRIGGER_DEBUG"]["TRIGGERS_NAMES"] = $case->getTriggerNames($arrayTrigger);
    $_SESSION["TRIGGER_DEBUG"]["TRIGGERS_VALUES"] = $arrayTrigger;
}
//Add Input Document
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"]);
 //Load the variables
 $oCase = new Cases();
 $oCase->thisIsTheCurrentUser($_SESSION["APPLICATION"], $_SESSION["INDEX"], $_SESSION["USER_LOGGED"], "REDIRECT", "casesListExtJs");
 $Fields = $oCase->loadCase($_SESSION["APPLICATION"]);
 $Fields["APP_DATA"] = array_merge($Fields["APP_DATA"], G::getSystemConstants());
 $Fields["APP_DATA"] = array_merge($Fields["APP_DATA"], $_POST["form"]);
 #here we must verify if is a debug session
 $trigger_debug_session = $_SESSION['TRIGGER_DEBUG']['ISSET'];
 #here we must verify if is a debugg session
 #trigger debug routines...
 //cleaning debug variables
 $_SESSION['TRIGGER_DEBUG']['ERRORS'] = array();
 $_SESSION['TRIGGER_DEBUG']['DATA'] = array();
 $_SESSION['TRIGGER_DEBUG']['TRIGGERS_NAMES'] = array();
 $_SESSION['TRIGGER_DEBUG']['TRIGGERS_VALUES'] = array();
 $triggers = $oCase->loadTriggers($_SESSION['TASK'], 'DYNAFORM', $_GET['UID'], 'AFTER');
 $_SESSION['TRIGGER_DEBUG']['NUM_TRIGGERS'] = count($triggers);
 $_SESSION['TRIGGER_DEBUG']['TIME'] = 'AFTER';
 if ($_SESSION['TRIGGER_DEBUG']['NUM_TRIGGERS'] != 0) {
     $_SESSION['TRIGGER_DEBUG']['TRIGGERS_NAMES'] = $oCase->getTriggerNames($triggers);
     $_SESSION['TRIGGER_DEBUG']['TRIGGERS_VALUES'] = $triggers;
 }
 if ($_SESSION['TRIGGER_DEBUG']['NUM_TRIGGERS'] != 0) {
     //Execute after triggers - Start
     $Fields['APP_DATA'] = $oCase->ExecuteTriggers($_SESSION['TASK'], 'DYNAFORM', $_GET['UID'], 'AFTER', $Fields['APP_DATA']);
     //Execute after triggers - End
 }
 //save data in PM Tables if necessary
 $newValues = array();
 foreach ($_POST['form'] as $sField => $sAux) {
     if (isset($oForm->fields[$sField]->pmconnection) && isset($oForm->fields[$sField]->pmfield)) {
$appDocUid = $_POST['form']['APP_DOC_UID'];
$docVersion = $_POST['form']['docVersion'];
$actionType = $_POST['form']['actionType'];
//load the variables
G::LoadClass('case');
$oCase = new Cases();
$oCase->thisIsTheCurrentUser($_SESSION['APPLICATION'], $_SESSION['INDEX'], $_SESSION['USER_LOGGED'], 'REDIRECT', 'cases_List');
$Fields = $oCase->loadCase($_SESSION['APPLICATION']);
$Fields['APP_DATA'] = array_merge($Fields['APP_DATA'], G::getSystemConstants());
#trigger debug routines...
//cleaning debug variables
$_SESSION['TRIGGER_DEBUG']['ERRORS'] = array();
$_SESSION['TRIGGER_DEBUG']['DATA'] = array();
$_SESSION['TRIGGER_DEBUG']['TRIGGERS_NAMES'] = array();
$_SESSION['TRIGGER_DEBUG']['TRIGGERS_VALUES'] = array();
$triggers = $oCase->loadTriggers($_SESSION['TASK'], 'INPUT_DOCUMENT', $_GET['UID'], 'AFTER');
$_SESSION['TRIGGER_DEBUG']['NUM_TRIGGERS'] = count($triggers);
$_SESSION['TRIGGER_DEBUG']['TIME'] = 'AFTER';
if ($_SESSION['TRIGGER_DEBUG']['NUM_TRIGGERS'] != 0) {
    $_SESSION['TRIGGER_DEBUG']['TRIGGERS_NAMES'] = $oCase->getTriggerNames($triggers);
    $_SESSION['TRIGGER_DEBUG']['TRIGGERS_VALUES'] = $triggers;
}
if ($_SESSION['TRIGGER_DEBUG']['NUM_TRIGGERS'] != 0) {
    //Execute after triggers - Start
    $Fields['APP_DATA'] = $oCase->ExecuteTriggers($_SESSION['TASK'], 'INPUT_DOCUMENT', $_GET['UID'], 'AFTER', $Fields['APP_DATA']);
    //Execute after triggers - End
}
//save data
$aData = array();
$aData['APP_NUMBER'] = $Fields['APP_NUMBER'];
$aData['APP_PROC_STATUS'] = $Fields['APP_PROC_STATUS'];
/* Process the info */
$sStatus = 'TO_DO';
foreach ($_POST['form']['TASKS'] as $aValues) {
}
try {
    //load data
    $oCase = new Cases();
    //warning: we are not using the result value of function thisIsTheCurrentUser, so I'm commenting to optimize speed.
    //$oCase->thisIsTheCurrentUser( $_SESSION['APPLICATION'], $_SESSION['INDEX'], $_SESSION['USER_LOGGED'], 'REDIRECT', 'casesListExtJs');
    $appFields = $oCase->loadCase($_SESSION['APPLICATION']);
    $appFields['APP_DATA'] = array_merge($appFields['APP_DATA'], G::getSystemConstants());
    //cleaning debug variables
    $_SESSION['TRIGGER_DEBUG']['DATA'] = array();
    $_SESSION['TRIGGER_DEBUG']['TRIGGERS_NAMES'] = array();
    $_SESSION['TRIGGER_DEBUG']['TRIGGERS_VALUES'] = array();
    $triggers = $oCase->loadTriggers($_SESSION['TASK'], 'ASSIGN_TASK', -2, 'BEFORE');
    //if there are some triggers to execute
    if (sizeof($triggers) > 0) {
        //Execute triggers before derivation
        $appFields['APP_DATA'] = $oCase->ExecuteTriggers($_SESSION['TASK'], 'ASSIGN_TASK', -2, 'BEFORE', $appFields['APP_DATA']);
        //save trigger variables for debugger
        $_SESSION['TRIGGER_DEBUG']['info'][0]['NUM_TRIGGERS'] = sizeof($triggers);
        $_SESSION['TRIGGER_DEBUG']['info'][0]['TIME'] = 'BEFORE';
        $_SESSION['TRIGGER_DEBUG']['info'][0]['TRIGGERS_NAMES'] = $oCase->getTriggerNames($triggers);
        $_SESSION['TRIGGER_DEBUG']['info'][0]['TRIGGERS_VALUES'] = $triggers;
    }
    $appFields['DEL_INDEX'] = $_SESSION['INDEX'];
    $appFields['TAS_UID'] = $_SESSION['TASK'];
    $oCase->updateCase($_SESSION['APPLICATION'], $appFields);
    //Save data
    //derivate case
foreach ($_POST['form']['TASKS'] as $aValues) {
}

try {
    //load data
    $oCase = new Cases();
    //warning: we are not using the result value of function thisIsTheCurrentUser, so I'm commenting to optimize speed.
    //$oCase->thisIsTheCurrentUser( $_SESSION['APPLICATION'], $_SESSION['INDEX'], $_SESSION['USER_LOGGED'], 'REDIRECT', 'casesListExtJs');
    $appFields = $oCase->loadCase( $_SESSION['APPLICATION'] );
    $appFields['APP_DATA'] = array_merge( $appFields['APP_DATA'], G::getSystemConstants() );
    //cleaning debug variables
    $_SESSION['TRIGGER_DEBUG']['DATA'] = Array ();
    $_SESSION['TRIGGER_DEBUG']['TRIGGERS_NAMES'] = Array ();
    $_SESSION['TRIGGER_DEBUG']['TRIGGERS_VALUES'] = Array ();

    $triggers = $oCase->loadTriggers( $_SESSION['TASK'], 'ASSIGN_TASK', - 2, 'BEFORE' );

    //if there are some triggers to execute
    if (sizeof( $triggers ) > 0) {
        //Execute triggers before derivation
        $appFields['APP_DATA'] = $oCase->ExecuteTriggers( $_SESSION['TASK'], 'ASSIGN_TASK', - 2, 'BEFORE', $appFields['APP_DATA'] );

        //save trigger variables for debugger
        $_SESSION['TRIGGER_DEBUG']['info'][0]['NUM_TRIGGERS'] = sizeof( $triggers );
        $_SESSION['TRIGGER_DEBUG']['info'][0]['TIME'] = G::toUpper(G::loadTranslation('ID_BEFORE'));
        $_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']);