Added case information on the main tab on the case form

Added cancel feature (like former plugin version) on the main tab
Moved sorting of tasks into case.class.php
This commit is contained in:
tomolimo
2018-07-27 16:13:15 +02:00
parent 02be646379
commit 53d6535d2c
6 changed files with 224 additions and 60 deletions

View File

@@ -40,6 +40,22 @@ if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'delete') {
$locCase->redirectToList();
} else
if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'cancel') {
// cancel case from PM
$locCase = new PluginProcessmakerCase;
$locCase->getFromDB($_POST['cases_id']);
$resultPM = $PM_SOAP->cancelCase($locCase->fields['case_guid']);
if ($resultPM->status_code === 0) {
if ($locCase->cancelCase()) {
Session::addMessageAfterRedirect($LANG['processmaker']['item']['case']['cancelled'], true, INFO);
} else {
Session::addMessageAfterRedirect($LANG['processmaker']['item']['case']['errorcancelled'], true, ERROR);
}
} else {
Session::addMessageAfterRedirect($LANG['processmaker']['item']['case']['errorcancelled'], true, ERROR);
}
Html::back();
} else
if (isset( $_REQUEST['form'] ) && isset( $_REQUEST['form']['BTN_CATCH'] ) && isset( $_REQUEST['form']['APP_UID'])) {
// Claim task management
// here we are in a Claim request

View File

@@ -61,6 +61,10 @@ class PluginProcessmakerCase extends CommonDBTM {
return $this->canDeleteItem();
}
static function canCancel() {
return plugin_processmaker_haveRight('case', CANCEL);
}
/**
* Summary of getTabNameForItem
* @param CommonGLPI $item is the item
@@ -259,33 +263,205 @@ class PluginProcessmakerCase extends CommonDBTM {
/**
* Summary of showCaseInfoTab
* Will show information about the current case
* @param CommonGLPI $item is a PluginProcessmakerCase object
* @param mixed $tabnum
* @param mixed $withtemplate
* Summary of showCaseProperties
*/
static function showCaseInfoTab(CommonGLPI $item, $tabnum=1, $withtemplate=0) {
echo 'The idea is to show here the GLPI ITIL item to which it is linked, and to give a resume of the current case status, and to give possibility to delete or cancel the case.';
function showCaseProperties() {
global $PM_DB;
$caseInfo = $this->getCaseInfo();
if (property_exists($caseInfo, 'currentUsers')) {
$caseInfo->currentUsers = $this->sortTasks($caseInfo->currentUsers, PluginProcessmakerUser::getPMUserId(Session::getLoginUserID()));
}
$query = "SELECT `DEL_INDEX`, `DEL_DELEGATE_DATE` FROM `APP_DELEGATION` WHERE `APP_UID`='{$caseInfo->caseId}'";
$tasks = [];
foreach($PM_DB->request($query) as $row){
$tasks[$row['DEL_INDEX']] = $row['DEL_DELEGATE_DATE'];
}
echo "<p></p>";
$rand = rand();
// will not show delete button if case is a sub-process
// will show it if it is also a draft or if current glpi user has the right to delete cases and session is central
if ($item->fields['plugin_processmaker_cases_id'] == 0
&& ($item->fields['case_status'] == self::DRAFT
|| (plugin_processmaker_haveRight("case", DELETE)
&& $_SESSION['glpiactiveprofile']['interface'] == 'central'))) {
// then propose a button to delete case
echo "<form style='margin-bottom: 0px' name='processmaker_case_form$rand' id='processmaker_case_form$rand' method='post' action='".Toolbox::getItemTypeFormURL("PluginProcessmakerCase")."'>";
echo "<div class='center'>";
echo "<table style='margin-bottom: 0px' class='tab_cadre_fixe'>";
echo "<tr><th colspan='4'>".__('Case Deletion', 'processmaker')."</th></tr>";
echo "<td class='tab_bg_2' colspan=3>&nbsp;</td>";
echo "<td class='tab_bg_2'>";
echo "<tr><th colspan=4>".__('Case properties', 'processmaker')."</th></tr>";
echo "<tr><td class='tab_bg_2' style='font-weight: bold;'>".__('Process', 'processmaker')."</td>";
echo "<td class='tab_bg_2' colspan=3>".$caseInfo->processName."</td></tr>";
echo "<tr><td class='tab_bg_2' style='font-weight: bold;'>".__('Case title', 'processmaker')."</td>";
echo "<td class='tab_bg_2' colspan=3>".$caseInfo->caseName."</td></tr>";
echo "<tr><td class='tab_bg_2' style='font-weight: bold;'>".__('Case number', 'processmaker')."</td>";
echo "<td class='tab_bg_2' colspan=3>".$caseInfo->caseNumber."</td></tr>";
echo "<tr><td class='tab_bg_2' style='font-weight: bold;'>".__('Case status', 'processmaker')."</td>";
echo "<td class='tab_bg_2' colspan=3>".self::getStatus($caseInfo->caseStatus)."</td></tr>";
echo "<tr><td class='tab_bg_2' style='font-weight: bold;'>".__('Case guid', 'processmaker')."</td>";
echo "<td class='tab_bg_2' colspan=3>".$caseInfo->caseId."</td></tr>";
echo "<tr><td class='tab_bg_2' style='font-weight: bold;'>".__('Creator', 'processmaker')."</td>";
echo "<td class='tab_bg_2' colspan=3>".$caseInfo->caseCreatorUserName."</td></tr>";
echo "<tr><td class='tab_bg_2' style='font-weight: bold;'>".__('Creation date', 'processmaker')."</td>";
echo "<td class='tab_bg_2' colspan=3>".$caseInfo->createDate."</td></tr>";
echo "<tr><td class='tab_bg_2' style='font-weight: bold;'>".__('Last update', 'processmaker')."</td>";
echo "<td class='tab_bg_2' colspan=3>".$caseInfo->updateDate."</td></tr>";
//echo "<tr><td class='tab_bg_2' style='font-weight: bold;'>".__('Case description', 'processmaker')."</td>";
//echo "<td class='tab_bg_2' colspan=3>".$caseInfo->????."</td></tr>";
echo "</table>";
echo "</div>";
echo "<p></p>";
echo "<div class='center'>";
echo "<table style='margin-bottom: 0px' class='tab_cadre_fixe'>";
echo "<tr><th colspan=4>".__('Current task(s) properties', 'processmaker')."</th></tr>";
if (count($caseInfo->currentUsers) > 0) {
echo "<tr style='font-weight: bold;'>
<td>".__('Task', 'processmaker')."</td>
<td>".__('Task guid', 'processmaker')."</td>
<td>".__('Current user', 'processmaker')."</td>
<td>".__('Task delegation date', 'processmaker')."</td>
</tr>";
foreach($caseInfo->currentUsers as $currentTask) {
echo "<tr>";
echo "<td class='tab_bg_2'>".$currentTask->taskName."</td>";
echo "<td class='tab_bg_2'>".$currentTask->taskId."</td>";
if ($currentTask->userName == '') {
echo "<td class='tab_bg_2'>".__('To be claimed', 'processmaker')."</td>";
} else {
echo "<td class='tab_bg_2'>".$currentTask->userName."</td>";
}
echo "<td class='tab_bg_2'>".$tasks[$currentTask->delIndex]."</td>";
echo "</tr>";
}
} else {
echo "<td colspan=4>".__('None')."</td>";
}
echo "</table>";
echo "</div>";
}
/**
* Summary of sortTasks
* @param mixed $tasks is the array of tasks from a getCaseInfo->currentUsers
* @param mixed $GLPICurrentPMUserId
* @return array sorted $tasks
*/
public function sortTasks($tasks, $GLPICurrentPMUserId) {
function localSortTasks ($a, $b) {
return $a->delIndex - $b->delIndex;
};
$tbctasks = [];
$utasks = [];
$infotasks = [];
foreach ($tasks as $caseUser) {
if ($caseUser->userId == $GLPICurrentPMUserId) {
$utasks[] = $caseUser;
} else {
if ($caseUser->userId == '') { // task to be claimed
$tbctasks[] = $caseUser;
} else
$infotasks[] = $caseUser;
}
}
// order task by "current user", then by "to be claimed", and then push to end "tasks assigned to another user"
// then by delindex ASC in these three parts
usort($utasks, 'localSortTasks');
usort($tbctasks, 'localSortTasks');
usort($infotasks, 'localSortTasks');
return array_merge($utasks, $tbctasks, $infotasks);
}
/**
* Summary of showCaseInfoTab
* Will show information about the current case
* @param CommonGLPI $case is a PluginProcessmakerCase object
* @param mixed $tabnum
* @param mixed $withtemplate
*/
static function showCaseInfoTab(CommonGLPI $case, $tabnum=1, $withtemplate=0) {
// echo 'The idea is to show here the GLPI ITIL item to which it is linked, and to give a resume of the current case status, and to give possibility to delete or cancel the case.';
echo "<table style='margin-bottom: 0px' class='tab_cadre_fixe'>";
echo "<tr><th colspan=2>".__('Case item', 'processmaker')."</th></tr>";
$itemtype = $case->fields['itemtype'];
$item = new $itemtype;
$item->getFromDB($case->fields['items_id']);
echo "<tr><td class='tab_bg_2' style='font-weight: bold;'>".$itemtype::getTypeName(1)."</td>";
// echo "<td class='tab_bg_2' >".$item->getID()."</td>";
echo "<td class='tab_bg_2'>".$item->getLink(['forceid' => 1])."</td></tr>";
echo "</table>";
//echo "</div>";
// show case properties
$case->showCaseProperties();
if ($case->fields['plugin_processmaker_cases_id'] == 0 && self::canCancel() && $case->fields['case_status'] == self::TO_DO) {
// it's a main case, not a sub-case
// and we have the rightr to cancel cases
// show a form to be able to cancel the case
$rand = rand();
echo "<p></p>";
echo "<form style='margin-bottom: 0px' name='processmaker_case_cancelform$rand' id='processmaker_case_cancelform$rand' method='post' action='".Toolbox::getItemTypeFormURL("PluginProcessmakerCase")."'>";
echo "<div class='center'>";
echo "<table style='margin-bottom: 0px' class='tab_cadre_fixe'>";
echo "<tr><th colspan='2'>".__('Case cancellation', 'processmaker')."</th></tr>";
echo "<tr><td class='tab_bg_2' style='width: 10%'>".__('Cancel case', 'processmaker')."</td>";
echo "<td class='tab_bg_2' >";
echo "<input type='hidden' name='action' value='cancel'>";
echo "<input type='hidden' name='cases_id' value='".$case->getID()."'>";
echo "<input onclick='return confirm(\"".__('Confirm cancellation?')."\");' type='submit' name='cancel' value='".__('Cancel')."' class='submit' >";
echo "</td></tr></table>";
Html::closeForm();
}
// will not show delete button if case is a sub-process
// and will show it only if it is a draft or if current glpi user has the right to delete cases and session is central
if ($case->fields['plugin_processmaker_cases_id'] == 0
&& ($case->fields['case_status'] == self::DRAFT
|| (plugin_processmaker_haveRight("case", DELETE)
&& $_SESSION['glpiactiveprofile']['interface'] == 'central'))) {
// then propose a button to delete case
$rand = rand();
echo "<p></p>";
echo "<form style='margin-bottom: 0px' name='processmaker_case_deleteform$rand' id='processmaker_case_deleteform$rand' method='post' action='".Toolbox::getItemTypeFormURL("PluginProcessmakerCase")."'>";
echo "<div class='center'>";
echo "<table style='margin-bottom: 0px' class='tab_cadre_fixe'>";
echo "<th colspan='2'>".__('Case deletion', 'processmaker')."</th>";
echo "<tr><td class='tab_bg_2' style='width: 10%'>".__('Delete case', 'processmaker')."</td>";
echo "<td class='tab_bg_2' >";
echo "<input type='hidden' name='action' value='delete'>";
echo "<input type='hidden' name='cases_id' value='".$item->getID()."'>";
echo "<input onclick='ret = confirm(\"".__('Confirm expunge?')."\"); cancelMyMask = !ret ; return ret;' type='submit' name='delete' value='".__('Delete permanently')."' class='submit' >";
echo "<input type='hidden' name='cases_id' value='".$case->getID()."'>";
echo "<input onclick='return confirm(\"".__('Confirm expunge?')."\");' type='submit' name='delete' value='".__('Delete permanently')."' class='submit' >";
echo "</td></tr></table>";
Html::closeForm();
@@ -887,7 +1063,6 @@ class PluginProcessmakerCase extends CommonDBTM {
}
/**
* Summary of cancelTasks
* will mark as information all to_do tasks

View File

@@ -43,7 +43,7 @@ class PluginProcessmakerCasedynaform extends CommonDBTM {
var tabIndex = loctabs.find('a[href=\"#'+name+'\"]').parent().index();
loctabs.tabs( 'option', 'active', tabIndex) ; // to activate it
} });
} else { // only acitvate it
} else { // only activate it
var tabIndex = loctabs.find('a[href=\"#'+name+'\"]').parent().index();
loctabs.tabs( 'option', 'active', tabIndex) ; // to activate it
}

View File

@@ -1,6 +1,5 @@
<?php
if (!defined('GLPI_ROOT')) {
die("Sorry. You can't access directly to this file");
}
@@ -23,7 +22,7 @@ class PluginProcessmakerProfile extends CommonDBTM {
array('itemtype' => 'PluginProcessmakerConfig',
'label' => $LANG['processmaker']['profile']['case'],
'field' => 'plugin_processmaker_case',
'rights' => array(READ => __('Read'), DELETE => __('Delete')))
'rights' => array(READ => __('Read'), CANCEL => __('Cancel', 'processmaker'), DELETE => __('Delete')))
);
return $rights;
@@ -72,9 +71,7 @@ class PluginProcessmakerProfile extends CommonDBTM {
* @param mixed $ID
*/
static function createAdminAccess($ID) {
self::addDefaultProfileInfos($ID, array('plugin_processmaker_config' => READ + UPDATE, 'plugin_processmaker_deletecase' => DELETE), true);
self::addDefaultProfileInfos($ID, array('plugin_processmaker_config' => READ + UPDATE, 'plugin_processmaker_case' => READ + DELETE + CANCEL), true);
}
/**
@@ -107,7 +104,7 @@ class PluginProcessmakerProfile extends CommonDBTM {
$prof = new self();
self::addDefaultProfileInfos($ID,
array('plugin_processmaker_config' => 0,
'plugin_processmaker_deletecase' => 0
'plugin_processmaker_case' => 0
));
$prof->showForm($ID);

View File

@@ -154,35 +154,9 @@ class PluginProcessmakerTask extends CommonITILTask
$sub_tasks[$task['plugin_processmaker_cases_id']][$task['del_index']] = $task;
}
$caseInfo->currentUsers = $case->sortTasks($caseInfo->currentUsers, $GLPICurrentPMUserId);
$tab = [];
function sortTasks ($a, $b) {
return $a->delIndex - $b->delIndex;
};
$tbctasks = [];
$utasks = [];
$infotasks = [];
foreach ($caseInfo->currentUsers as $caseUser) {
if ($caseUser->userId == $GLPICurrentPMUserId) {
$utasks[] = $caseUser;
} else {
if ($caseUser->userId == '') { // task to be claimed
$tbctasks[] = $caseUser;
} else
$infotasks[] = $caseUser;
}
}
// order task by "current user", then by "to be claimed", and then push to end "tasks assigned to another user"
// then by delindex ASC in these three parts
usort($utasks, 'sortTasks');
usort($tbctasks, 'sortTasks');
usort($infotasks, 'sortTasks');
$caseInfo->currentUsers = array_merge($utasks, $tbctasks, $infotasks);
foreach ($caseInfo->currentUsers as $key => $caseUser) {
$title = $caseUser->taskName;
if (isset($tasks[$caseUser->delIndex])) {

View File

@@ -1,5 +1,7 @@
<?php
// used for case cancellation
define("CANCEL", 256);
// Init the hooks of the plugins -Needed
function plugin_init_processmaker() {
@@ -146,7 +148,7 @@ function plugin_processmaker_check_config($verbose = false) {
}
function plugin_processmaker_haveRight($module,$right) {
function plugin_processmaker_haveRight($module, $right) {
return Session::haveRight("plugin_processmaker_".$module, $right);
}