Exemplo n.º 1
0
    /**

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

        }

    }
Exemplo n.º 2
0
<?php

$licensedFeatures =& PMLicensedFeatures::getSingleton();
if (!$licensedFeatures->verifyfeature('7qhYmF1eDJWcEdwcUZpT0k4S0xTRStvdz09')) {
    G::SendTemporalMessage('ID_USER_HAVENT_RIGHTS_PAGE', 'error', 'labels');
    G::header('location: ../login/login');
    die;
}
$caseId = $_SESSION['APPLICATION'];
$usrUid = $_SESSION['USER_LOGGED'];
$usrName = $_SESSION['USR_FULLNAME'];
$actualIndex = $_SESSION['INDEX'];
$cont = 0;
use ProcessMaker\Services\Api;
$appDel = new AppDelegation();
$actualThread = $appDel->Load($caseId, $actualIndex);
$actualLastIndex = $actualThread['DEL_PREVIOUS'];
$appDelPrev = $appDel->LoadParallel($caseId);
if ($appDelPrev == array()) {
    $appDelPrev['0'] = $actualThread;
}
$Pmgmail = new \ProcessMaker\BusinessModel\Pmgmail();
foreach ($appDelPrev as $app) {
    if ($app['DEL_INDEX'] != $actualIndex && $app['DEL_PREVIOUS'] != $actualLastIndex) {
        //Sending the email to all threads of the case except the actual thread
        $response = $Pmgmail->sendEmail($caseId, "", $app['DEL_INDEX']);
    }
}
require_once PATH_HOME . "engine" . PATH_SEP . "classes" . PATH_SEP . "class.labelsGmail.php";
$oLabels = new labelsGmail();
$oResponse = $oLabels->setLabels($caseId, $actualIndex, $actualLastIndex, false);
Exemplo n.º 3
0
    public function reassignCase($sApplicationUID, $iDelegation, $sUserUID, $newUserUID, $sType = 'REASSIGN')

    {

        $this->CloseCurrentDelegation($sApplicationUID, $iDelegation);

        $oAppDelegation = new AppDelegation();

        $aFieldsDel = $oAppDelegation->Load($sApplicationUID, $iDelegation);

        $iIndex = $oAppDelegation->createAppDelegation(

                $aFieldsDel['PRO_UID'], $aFieldsDel['APP_UID'], $aFieldsDel['TAS_UID'], $aFieldsDel['USR_UID'], $aFieldsDel['DEL_THREAD']

        );

        $aData = array();

        $aData['APP_UID'] = $aFieldsDel['APP_UID'];

        $aData['DEL_INDEX'] = $iIndex;

        $aData['DEL_PREVIOUS'] = $aFieldsDel['DEL_PREVIOUS'];

        $aData['DEL_TYPE'] = $aFieldsDel['DEL_TYPE'];

        $aData['DEL_PRIORITY'] = $aFieldsDel['DEL_PRIORITY'];

        $aData['DEL_DELEGATE_DATE'] = $aFieldsDel['DEL_DELEGATE_DATE'];

        $aData['USR_UID'] = $newUserUID;

        $aData['DEL_INIT_DATE'] = null;

        $aData['DEL_FINISH_DATE'] = null;

        $oAppDelegation->update($aData);

        $oAppThread = new AppThread();

        $oAppThread->update(

                array(

                    'APP_UID' => $sApplicationUID,

                    'APP_THREAD_INDEX' => $aFieldsDel['DEL_THREAD'],

                    'DEL_INDEX' => $iIndex)

        );



        //Save in APP_DELAY

        $oApplication = new Application();

        $aFields = $oApplication->Load($sApplicationUID);

        $aData['PRO_UID'] = $aFieldsDel['PRO_UID'];

        $aData['APP_UID'] = $sApplicationUID;

        $aData['APP_THREAD_INDEX'] = $aFieldsDel['DEL_THREAD'];

        $aData['APP_DEL_INDEX'] = $iDelegation;

        $aData['APP_TYPE'] = ($sType != '' ? $sType : 'REASSIGN');

        $aData['APP_STATUS'] = $aFields['APP_STATUS'];

        $aData['APP_DELEGATION_USER'] = $sUserUID;

        $aData['APP_ENABLE_ACTION_USER'] = $sUserUID;

        $aData['APP_ENABLE_ACTION_DATE'] = date('Y-m-d H:i:s');

        $oAppDelay = new AppDelay();

        $oAppDelay->create($aData);



        //update searchindex

        if ($this->appSolr != null) {

            $this->appSolr->updateApplicationSearchIndex($sApplicationUID);

        }



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

        $this->getExecuteTriggerProcess($sApplicationUID, 'REASSIGNED');

        return true;

    }
G::LoadClass('case');
$oCase = new Cases();
$Fields = $oCase->loadCase($_SESSION['APPLICATION'], $_SESSION['INDEX']);
/* Render page */
require_once 'classes/model/Process.php';
require_once 'classes/model/Task.php';
$objProc = new Process();
$aProc = $objProc->load($Fields['PRO_UID']);
$Fields['PRO_TITLE'] = $aProc['PRO_TITLE'];
$objTask = new Task();
$aTask = $objTask->load($Fields['TAS_UID']);
$Fields['TAS_TITLE'] = $aTask['TAS_TITLE'];
$Fields['STATUS'] .= ' ( ' . G::LoadTranslation('ID_UNASSIGNED') . ' )';
//now getting information about the PREVIOUS task. If is the first task then no preious, use 1
$oAppDel = new AppDelegation();
$oAppDel->Load($Fields['APP_UID'], $Fields['DEL_PREVIOUS'] == 0 ? $Fields['DEL_PREVIOUS'] = 1 : $Fields['DEL_PREVIOUS']);
$aAppDel = $oAppDel->toArray(BasePeer::TYPE_FIELDNAME);
try {
    $oCurUser = new Users();
    $oCurUser->load($aAppDel['USR_UID']);
    $Fields['PREVIOUS_USER'] = $oCurUser->getUsrFirstname() . ' ' . $oCurUser->getUsrLastname();
} catch (Exception $oError) {
    $Fields['PREVIOUS_USER'] = '';
}
$objTask = new Task();
$aTask = $objTask->load($aAppDel['TAS_UID']);
$Fields['PREVIOUS_TASK'] = $aTask['TAS_TITLE'];
//To enable information (dynaforms, steps) before claim a case
$_SESSION['bNoShowSteps'] = true;
$G_MAIN_MENU = 'processmaker';
$G_SUB_MENU = 'caseOptions';