2012-10-22 12:15:52 -04:00
|
|
|
<?php
|
|
|
|
|
/**
|
|
|
|
|
* proxySaveReassignCasesList.php
|
|
|
|
|
*
|
2019-07-25 16:12:48 -04:00
|
|
|
* Reassign functionality only from the cases list Review
|
|
|
|
|
* @see https://wiki.processmaker.com/3.0/Cases#Reassign
|
2012-10-22 12:15:52 -04:00
|
|
|
*/
|
2016-08-12 15:59:23 -04:00
|
|
|
|
2019-07-25 16:12:48 -04:00
|
|
|
use ProcessMaker\Model\Delegation;
|
2017-02-14 21:24:08 +00:00
|
|
|
|
2019-07-25 16:12:48 -04:00
|
|
|
// $_POST['data'] is information about the cases that will reassign
|
|
|
|
|
$dataPost = G::json_decode($_POST['data']);
|
|
|
|
|
|
|
|
|
|
$casesReassignedCount = 0;
|
|
|
|
|
$serverResponse = [];
|
2017-02-14 21:24:08 +00:00
|
|
|
|
2012-10-18 16:05:43 +00:00
|
|
|
// if there are no records to save return -1
|
2019-07-25 16:12:48 -04:00
|
|
|
if (empty($dataPost)) {
|
|
|
|
|
$serverResponse['TOTAL'] = -1;
|
2016-08-12 15:59:23 -04:00
|
|
|
|
2019-07-25 16:12:48 -04:00
|
|
|
echo G::json_encode($serverResponse);
|
|
|
|
|
die();
|
|
|
|
|
} elseif (is_array($dataPost)) {
|
|
|
|
|
$cases = new Cases();
|
2012-10-22 12:15:52 -04:00
|
|
|
$currentCasesReassigned = 0;
|
2019-07-25 16:12:48 -04:00
|
|
|
foreach ($dataPost as $data) {
|
|
|
|
|
// It was supposed will return only one thread related to the task
|
|
|
|
|
// todo: implement the reassign case for multi instance task
|
|
|
|
|
$openThreads = Delegation::getOpenThreads($data->APP_NUMBER, $data->TAS_UID);
|
|
|
|
|
if (!empty($openThreads)) {
|
|
|
|
|
// Get the user information assigned in the index
|
|
|
|
|
$currentUsrUid = Delegation::getCurrentUser($openThreads['APP_NUMBER'], $openThreads['DEL_INDEX']);
|
|
|
|
|
$flagReassign = true;
|
|
|
|
|
// Define the flag: it was supposed that the case was assigned another person
|
|
|
|
|
if (!empty($currentUsrUid)) {
|
|
|
|
|
if ($currentUsrUid === $data->APP_REASSIGN_USER_UID) {
|
2016-08-12 15:59:23 -04:00
|
|
|
$flagReassign = false;
|
|
|
|
|
}
|
2019-07-25 16:12:48 -04:00
|
|
|
} else {
|
|
|
|
|
// Return an error if the index was CLOSED
|
|
|
|
|
throw new Exception(G::LoadTranslation('ID_REASSIGNMENT_ERROR'));
|
|
|
|
|
}
|
|
|
|
|
// If the currentUsrUid is different to nextUser, create the thread
|
|
|
|
|
if ($flagReassign) {
|
|
|
|
|
$cases->reassignCase(
|
|
|
|
|
$openThreads['APP_UID'],
|
|
|
|
|
$openThreads['DEL_INDEX'],
|
|
|
|
|
(!empty($openThreads['USR_UID']) ? $openThreads['USR_UID'] : $_SESSION['USER_LOGGED']),
|
|
|
|
|
$data->APP_REASSIGN_USER_UID
|
|
|
|
|
);
|
2016-08-12 15:59:23 -04:00
|
|
|
}
|
|
|
|
|
|
2019-07-25 16:12:48 -04:00
|
|
|
$currentCasesReassigned++;
|
|
|
|
|
$casesReassignedCount++;
|
|
|
|
|
$serverResponse[] = [
|
|
|
|
|
'APP_REASSIGN_USER' => $data->APP_REASSIGN_USER,
|
|
|
|
|
'APP_TITLE' => $data->APP_TITLE,
|
|
|
|
|
'TAS_TITLE' => $data->APP_TAS_TITLE,
|
|
|
|
|
'REASSIGNED_CASES' => $currentCasesReassigned
|
|
|
|
|
];
|
2016-08-12 15:59:23 -04:00
|
|
|
|
2019-07-25 16:12:48 -04:00
|
|
|
// Save the note reassign reason
|
|
|
|
|
if (!empty($data->NOTE_REASON)) {
|
|
|
|
|
$appNotes = new AppNotes();
|
|
|
|
|
$noteContent = addslashes($data->NOTE_REASON);
|
|
|
|
|
$appNotes->postNewNote(
|
|
|
|
|
$openThreads['APP_UID'],
|
|
|
|
|
$_SESSION['USER_LOGGED'],
|
|
|
|
|
$noteContent,
|
|
|
|
|
isset($data->NOTIFY_REASSIGN) ? $data->NOTIFY_REASSIGN : false
|
|
|
|
|
);
|
2016-08-12 15:59:23 -04:00
|
|
|
}
|
|
|
|
|
} else {
|
2019-07-25 16:12:48 -04:00
|
|
|
// Return an error if the index was CLOSED
|
2016-08-12 15:59:23 -04:00
|
|
|
throw new Exception(G::LoadTranslation('ID_REASSIGNMENT_ERROR'));
|
|
|
|
|
}
|
2012-10-22 12:15:52 -04:00
|
|
|
}
|
|
|
|
|
}
|
2019-07-25 16:12:48 -04:00
|
|
|
|
2012-10-22 12:15:52 -04:00
|
|
|
$serverResponse['TOTAL'] = $casesReassignedCount;
|
2019-07-25 16:12:48 -04:00
|
|
|
echo G::json_encode($serverResponse);
|
2012-10-22 12:15:52 -04:00
|
|
|
|