コード例 #1
0
ファイル: cases_Open.php プロジェクト: hpx2206/processmaker-1
                if ($oCase->isSelfService( $_SESSION['USER_LOGGED'], $aFields['TAS_UID'], $sAppUid )) {
                    require_once (PATH_METHODS . 'cases' . PATH_SEP . 'cases_CatchSelfService.php');
                } else {
                    require_once (PATH_METHODS . 'cases' . PATH_SEP . 'cases_Resume.php');
                }

                exit();
            }

            //if the current users is in the AppDelegation row, then open the case
            if (($aDelegation['USR_UID'] == $_SESSION['USER_LOGGED']) && $_action != 'sent') {
                $_SESSION['APPLICATION'] = $sAppUid;
                $_SESSION['INDEX'] = $iDelIndex;

                if (is_null( $aFields['DEL_INIT_DATE'] )) {
                    $oCase->setDelInitDate( $sAppUid, $iDelIndex );
                    $aFields = $oCase->loadCase( $sAppUid, $iDelIndex );
                }

                $_SESSION['PROCESS'] = $aFields['PRO_UID'];
                $_SESSION['TASK'] = $aFields['TAS_UID'];
                $_SESSION['STEP_POSITION'] = 0;

                /* Redirect to next step */
                unset( $_SESSION['bNoShowSteps'] );
                $aNextStep = $oCase->getNextStep( $_SESSION['PROCESS'], $_SESSION['APPLICATION'], $_SESSION['INDEX'], $_SESSION['STEP_POSITION'] );
                $sPage = $aNextStep['PAGE'];
                G::header( 'location: ' . $sPage );

            } else {
                //when the case have another user or current user doesn't have rights to this self-service,
コード例 #2
0
    /**

     * 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;

        }

    }