Files
luos/workflow/engine/methods/cases/cases_Open.php

254 lines
10 KiB
PHP
Raw Normal View History

<?php
2020-06-24 17:53:09 -04:00
use ProcessMaker\Model\Process;
/**
* cases_Open.php
*
2019-02-18 15:34:55 -04:00
* @see cases/casesList.js
* @see cases/cases_Step.php
* @see cases/cases_CatchSelfService.php
* @see cases/derivatedGmail.php
* @see cases/open.php
* @see controllers/Home::indexSingle()
* @see controllers/Home::startCase()
* @see pmGmail/sso.php
* @see webentry/access.php
*
2019-02-18 15:34:55 -04:00
* @link https://wiki.processmaker.com/3.2/Cases/Cases#Search_Criteria
*/
2020-06-24 17:53:09 -04:00
if (isset($_GET['gmail']) && $_GET['gmail'] == 1) {
2017-03-07 16:59:04 -04:00
$_SESSION['gmail'] = 1;
}
/* Permissions */
2020-06-24 17:53:09 -04:00
if ($RBAC->userCanAccess('PM_CASES') != 1) {
switch ($RBAC->userCanAccess('PM_CASES')) {
case -2:
G::SendTemporalMessage('ID_USER_HAVENT_RIGHTS_SYSTEM', 'error', 'labels');
G::header('location: ../login/login');
break;
2020-06-24 17:53:09 -04:00
case -1:
default:
2020-06-24 17:53:09 -04:00
G::SendTemporalMessage('ID_USER_HAVENT_RIGHTS_PAGE', 'error', 'labels');
G::header('location: ../login/login');
break;
}
}
2018-09-07 12:01:42 -04:00
$caseInstance = new Cases();
2022-08-24 14:07:12 -04:00
// Cleaning the case session data
Cases::clearCaseSessionData();
try {
2022-08-24 14:07:12 -04:00
// Loading data for a Jump request
2017-03-07 16:59:04 -04:00
if (!isset($_GET['APP_UID']) && isset($_GET['APP_NUMBER'])) {
2020-06-24 17:53:09 -04:00
$_GET['APP_UID'] = $caseInstance->getApplicationUIDByNumber($_GET['APP_NUMBER']);
2022-08-24 14:07:12 -04:00
// Get the index related to the userLogged but this thread can be OPEN or CLOSED
2020-06-24 17:53:09 -04:00
if (isset($_GET['actionFromList'])) {
if ($_GET['actionFromList'] == 'unassigned') {
$_SESSION['APPLICATION'] = $_GET['APP_UID'];
$_GET['DEL_INDEX'] = $caseInstance->getCurrentDelegation($_GET['APP_UID'], $_SESSION['USER_LOGGED'], true);
} else {
$_GET['DEL_INDEX'] = $caseInstance->getCurrentDelegation($_GET['APP_UID'], $_SESSION['USER_LOGGED']);
}
} else {
$_GET['DEL_INDEX'] = $caseInstance->getCurrentDelegation($_GET['APP_UID'], $_SESSION['USER_LOGGED']);
}
2022-08-24 14:07:12 -04:00
// If the application doesn't exist
2017-03-07 16:59:04 -04:00
if (is_null($_GET['APP_UID'])) {
2020-06-24 17:53:09 -04:00
G::SendMessageText(G::LoadTranslation('ID_CASE_DOES_NOT_EXISTS'), 'info');
G::header('location: casesListExtJs');
exit();
}
2022-08-24 14:07:12 -04:00
// If the application exists but the
2017-03-07 16:59:04 -04:00
if (is_null($_GET['DEL_INDEX'])) {
2020-06-24 17:53:09 -04:00
G::SendMessageText(G::LoadTranslation('ID_CASE_IS_CURRENTLY_WITH_ANOTHER_USER'), 'info');
G::header('location: casesListExtJs');
exit();
}
}
2019-02-18 15:34:55 -04:00
$appUid = $_GET['APP_UID'];
$delIndex = $_GET['DEL_INDEX'];
$action = isset($_GET['action']) ? $_GET['action'] : '';
2022-08-24 14:07:12 -04:00
// Loading application data
2019-02-18 15:34:55 -04:00
$fieldCase = $caseInstance->loadCase($appUid, $delIndex);
2017-03-07 16:59:04 -04:00
if (!Process::isActive($fieldCase['PRO_UID'], 'PRO_UID')) {
$G_PUBLISH = new Publisher();
$G_PUBLISH->AddContent('xmlform', 'xmlform', 'login/showMessage', '', [
'MESSAGE' => G::LoadTranslation('ID_THE_WEBSITE_CAN_NOT_BE_REACHED')
]);
G::RenderPage('publish', 'blank');
exit();
}
2015-02-12 16:08:51 -04:00
if (!isset($_SESSION['CURRENT_TASK'])) {
2019-02-18 15:34:55 -04:00
$_SESSION['CURRENT_TASK'] = $fieldCase['TAS_UID'];
2017-03-07 16:59:04 -04:00
} elseif ($_SESSION['CURRENT_TASK'] == '') {
2019-02-18 15:34:55 -04:00
$_SESSION['CURRENT_TASK'] = $fieldCase['TAS_UID'];
2015-02-11 16:56:27 -04:00
}
2017-03-07 16:59:04 -04:00
2017-07-12 15:55:02 -04:00
unset($_SESSION['ACTION']);
$flagJump = '';
2019-02-18 15:34:55 -04:00
if ($action == 'jump') {
2017-07-12 15:55:02 -04:00
$_SESSION['ACTION'] = 'jump';
$flagJump = 1;
}
2019-02-18 15:34:55 -04:00
switch ($fieldCase['APP_STATUS']) {
case 'DRAFT':
case 'TO_DO':
2022-08-24 14:07:12 -04:00
// Check if the case is in pause, check a valid record in table APP_DELAY
2019-02-18 15:34:55 -04:00
$isPaused = AppDelay::isPaused($appUid, $delIndex);
2017-05-09 16:28:46 -04:00
2022-08-24 14:07:12 -04:00
// Check if the case is a waiting for a SYNCHRONOUS subprocess
2019-02-18 15:34:55 -04:00
$subAppData = new SubApplication();
$caseSubprocessPending = $subAppData->isSubProcessWithCasePending($appUid, $delIndex);
2017-05-09 16:28:46 -04:00
if ($isPaused || $caseSubprocessPending) {
2022-08-24 14:07:12 -04:00
// Set as read when the pause thread or subprocess was open
if (is_null($fieldCase['DEL_INIT_DATE'])) {
$caseInstance->setDelInitDate($appUid, $delIndex);
}
// The case is paused show only the resume
2019-02-18 15:34:55 -04:00
$_SESSION['APPLICATION'] = $appUid;
$_SESSION['INDEX'] = $delIndex;
$_SESSION['PROCESS'] = $fieldCase['PRO_UID'];
$_SESSION['TASK'] = -1;
$_SESSION['STEP_POSITION'] = 0;
2019-02-18 15:34:55 -04:00
$_SESSION['CURRENT_TASK'] = $fieldCase['TAS_UID'];
2019-02-18 15:34:55 -04:00
require_once(PATH_METHODS . 'cases' . PATH_SEP . 'cases_Resume.php');
exit();
}
/**
2014-07-15 09:27:51 -04:00
* these routine is to verify if the case was acceded from advanced search list
*/
2019-02-18 15:34:55 -04:00
if ($action == 'search') {
2022-08-24 14:07:12 -04:00
// Verify if the case is with the current user
2019-02-18 15:34:55 -04:00
$delegationUsers = AppDelegation::getCurrentUsers($appUid, $delIndex);
if ($delegationUsers['USR_UID'] !== $_SESSION['USER_LOGGED'] && !empty($delegationUsers['USR_UID'])) {
$_SESSION['alreadyDerivated'] = true;
2019-02-18 15:34:55 -04:00
$_SESSION['APPLICATION'] = $appUid;
$_SESSION['INDEX'] = $delIndex;
$_SESSION['PROCESS'] = $fieldCase['PRO_UID'];
$_SESSION['TASK'] = -1;
$_SESSION['STEP_POSITION'] = 0;
2019-02-18 15:34:55 -04:00
require_once(PATH_METHODS . 'cases' . PATH_SEP . 'cases_Resume.php');
exit();
}
}
2022-08-24 14:07:12 -04:00
// Proceed and try to open the case
2019-02-18 15:34:55 -04:00
$appDelegation = new AppDelegation();
$delegationInfo = $appDelegation->load($appUid, $delIndex);
2022-08-24 14:07:12 -04:00
// If there are no user in the delegation row, this case is in selfservice
2019-02-18 15:34:55 -04:00
if (empty($delegationInfo['USR_UID'])) {
$_SESSION['APPLICATION'] = $appUid;
$_SESSION['INDEX'] = $delIndex;
$_SESSION['PROCESS'] = $fieldCase['PRO_UID'];
$_SESSION['TASK'] = -1;
$_SESSION['STEP_POSITION'] = 0;
2019-02-18 15:34:55 -04:00
$_SESSION['CURRENT_TASK'] = $fieldCase['TAS_UID'];
2022-08-24 14:07:12 -04:00
// If the task is in the valid selfservice tasks for this user, then catch the case, else just view the resume
2019-02-18 15:34:55 -04:00
if ($caseInstance->isSelfService($_SESSION['USER_LOGGED'], $fieldCase['TAS_UID'], $appUid)) {
2018-09-07 12:01:42 -04:00
require_once(PATH_METHODS . 'cases' . PATH_SEP . 'cases_CatchSelfService.php');
} else {
2018-09-07 12:01:42 -04:00
require_once(PATH_METHODS . 'cases' . PATH_SEP . 'cases_Resume.php');
}
exit();
}
2022-08-24 14:07:12 -04:00
// If the current users is in the AppDelegation row and the thread is open will be open the case
2019-02-18 15:34:55 -04:00
if (($delegationInfo['USR_UID'] == $_SESSION['USER_LOGGED'] && $delegationInfo['DEL_THREAD_STATUS'] === 'OPEN')
2020-06-24 17:53:09 -04:00
&& $action != 'sent'
) {
2019-02-18 15:34:55 -04:00
$_SESSION['APPLICATION'] = $appUid;
$_SESSION['INDEX'] = $delIndex;
2019-02-18 15:34:55 -04:00
if (is_null($fieldCase['DEL_INIT_DATE'])) {
$caseInstance->setDelInitDate($appUid, $delIndex);
$fieldCase = $caseInstance->loadCase($appUid, $delIndex);
}
2019-02-18 15:34:55 -04:00
$_SESSION['PROCESS'] = $fieldCase['PRO_UID'];
$_SESSION['TASK'] = $fieldCase['TAS_UID'];
$_SESSION['STEP_POSITION'] = 0;
/* Redirect to next step */
2019-02-18 15:34:55 -04:00
unset($_SESSION['bNoShowSteps']);
/** Execute a trigger when a case is open */
$caseInstance->getExecuteTriggerProcess($appUid, 'OPEN');
2017-03-07 16:59:04 -04:00
2019-02-18 15:34:55 -04:00
$nextStep = $caseInstance->getNextStep(
$_SESSION['PROCESS'],
$_SESSION['APPLICATION'],
$_SESSION['INDEX'],
$_SESSION['STEP_POSITION']
);
$pageOpenCase = $nextStep['PAGE'];
2017-03-07 16:59:04 -04:00
2019-02-18 15:34:55 -04:00
G::header('location: ' . $pageOpenCase);
} else {
2019-02-18 15:34:55 -04:00
$_SESSION['APPLICATION'] = $appUid;
$_SESSION['PROCESS'] = $fieldCase['PRO_UID'];
$_SESSION['TASK'] = -1;
2017-03-07 16:59:04 -04:00
$_SESSION['bNoShowSteps'] = 1;
$_SESSION['STEP_POSITION'] = 0;
2022-08-24 14:07:12 -04:00
// When the case have another user or current user doesn't have rights to this self-service,
// Just view the case Resume
2019-02-18 15:34:55 -04:00
if ($action === 'search' || $action === 'to_reassign') {
2022-08-24 14:07:12 -04:00
// We need to use the index sent with the corresponding record
2019-02-18 15:34:55 -04:00
$_SESSION['INDEX'] = $delIndex;
} else {
2022-08-24 14:07:12 -04:00
// Get last DEL_INDEX
2017-03-07 16:59:04 -04:00
$criteria = new Criteria('workflow');
$criteria->addSelectColumn(AppDelegationPeer::DEL_INDEX);
2019-02-18 15:34:55 -04:00
$criteria->add(AppDelegationPeer::APP_UID, $appUid);
$criteria->add(AppDelegationPeer::DEL_LAST_INDEX, 1);
2017-03-07 16:59:04 -04:00
$rs = AppDelegationPeer::doSelectRS($criteria);
$rs->setFetchmode(ResultSet::FETCHMODE_ASSOC);
$rs->next();
$row = $rs->getRow();
$_SESSION['INDEX'] = $row['DEL_INDEX'];
}
2017-03-07 16:59:04 -04:00
2019-02-18 15:34:55 -04:00
$fields = $caseInstance->loadCase($_SESSION['APPLICATION'], $_SESSION['INDEX'], $flagJump);
$_SESSION['CURRENT_TASK'] = $fields['TAS_UID'];
2017-03-07 16:59:04 -04:00
2019-02-18 15:34:55 -04:00
require_once(PATH_METHODS . 'cases' . PATH_SEP . 'cases_Resume.php');
}
break;
2022-08-24 14:07:12 -04:00
default: // APP_STATUS in (COMPLETED, CANCELLED)
2019-02-18 15:34:55 -04:00
$_SESSION['APPLICATION'] = $appUid;
$_SESSION['INDEX'] = $caseInstance->getCurrentDelegationCase($_GET['APP_UID']);
$_SESSION['PROCESS'] = $fieldCase['PRO_UID'];
$_SESSION['TASK'] = -1;
$_SESSION['STEP_POSITION'] = 0;
2019-02-18 15:34:55 -04:00
$fields = $caseInstance->loadCase($_SESSION['APPLICATION'], $_SESSION['INDEX'], $flagJump);
$_SESSION['CURRENT_TASK'] = $fields['TAS_UID'];
2019-02-18 15:34:55 -04:00
require_once(PATH_METHODS . 'cases' . PATH_SEP . 'cases_Resume.php');
}
} catch (Exception $e) {
2019-02-18 15:34:55 -04:00
$message = [];
$message['MESSAGE'] = $e->getMessage();
$G_PUBLISH = new Publisher();
2019-02-18 15:34:55 -04:00
$G_PUBLISH->AddContent('xmlform', 'xmlform', 'login/showMessage', '', $message);
G::RenderPage('publishBlank', 'blank');
2010-12-02 23:34:41 +00:00
}