diff --git a/front/case.form.php b/front/case.form.php index f331552..e2611dd 100644 --- a/front/case.form.php +++ b/front/case.form.php @@ -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 diff --git a/inc/case.class.php b/inc/case.class.php index 922712a..d6041a8 100644 --- a/inc/case.class.php +++ b/inc/case.class.php @@ -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 @@ -258,34 +262,206 @@ class PluginProcessmakerCase extends CommonDBTM { } + /** + * Summary of showCaseProperties + */ + 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 "

"; + + echo "
"; + echo ""; + + echo ""; + + echo ""; + echo ""; + + echo ""; + echo ""; + + echo ""; + echo ""; + + echo ""; + echo ""; + + echo ""; + echo ""; + + echo ""; + echo ""; + + echo ""; + echo ""; + + echo ""; + echo ""; + + //echo ""; + //echo ""; + + echo "
".__('Case properties', 'processmaker')."
".__('Process', 'processmaker')."".$caseInfo->processName."
".__('Case title', 'processmaker')."".$caseInfo->caseName."
".__('Case number', 'processmaker')."".$caseInfo->caseNumber."
".__('Case status', 'processmaker')."".self::getStatus($caseInfo->caseStatus)."
".__('Case guid', 'processmaker')."".$caseInfo->caseId."
".__('Creator', 'processmaker')."".$caseInfo->caseCreatorUserName."
".__('Creation date', 'processmaker')."".$caseInfo->createDate."
".__('Last update', 'processmaker')."".$caseInfo->updateDate."
".__('Case description', 'processmaker')."".$caseInfo->????."
"; + + echo "
"; + + echo "

"; + + echo "
"; + echo ""; + + echo ""; + + if (count($caseInfo->currentUsers) > 0) { + echo " + + + + + "; + + foreach($caseInfo->currentUsers as $currentTask) { + echo ""; + echo ""; + echo ""; + if ($currentTask->userName == '') { + echo ""; + } else { + echo ""; + } + echo ""; + echo ""; + } + } else { + echo ""; + } + + echo "
".__('Current task(s) properties', 'processmaker')."
".__('Task', 'processmaker')."".__('Task guid', 'processmaker')."".__('Current user', 'processmaker')."".__('Task delegation date', 'processmaker')."
".$currentTask->taskName."".$currentTask->taskId."".__('To be claimed', 'processmaker')."".$currentTask->userName."".$tasks[$currentTask->delIndex]."
".__('None')."
"; + + echo "
"; + + } + + + /** + * 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 $item is a PluginProcessmakerCase object + * @param CommonGLPI $case is a PluginProcessmakerCase object * @param mixed $tabnum * @param mixed $withtemplate */ - 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.'; + 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.'; - $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 "
"; + echo ""; + + echo ""; + + $itemtype = $case->fields['itemtype']; + $item = new $itemtype; + $item->getFromDB($case->fields['items_id']); + echo ""; +// echo ""; + echo ""; + + echo "
".__('Case item', 'processmaker')."
".$itemtype::getTypeName(1)."".$item->getID()."".$item->getLink(['forceid' => 1])."
"; + + //echo ""; + + // 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 "

"; + echo ""; echo "
"; echo ""; + echo ""; + echo ""; + echo "
".__('Case cancellation', 'processmaker')."
".__('Cancel case', 'processmaker').""; + echo ""; + echo ""; + echo ""; + echo "
"; - echo "".__('Case Deletion', 'processmaker').""; - echo " "; - echo ""; + 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 "

"; + echo ""; + echo "
"; + echo ""; + echo ""; + echo ""; + echo "
".__('Case deletion', 'processmaker')."
".__('Delete case', 'processmaker').""; echo ""; - echo ""; - echo ""; + echo ""; + echo ""; echo "
"; Html::closeForm(); @@ -887,7 +1063,6 @@ class PluginProcessmakerCase extends CommonDBTM { } - /** * Summary of cancelTasks * will mark as information all to_do tasks diff --git a/inc/casedynaform.class.php b/inc/casedynaform.class.php index bbb25d4..9ec2cab 100644 --- a/inc/casedynaform.class.php +++ b/inc/casedynaform.class.php @@ -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 } diff --git a/inc/profile.class.php b/inc/profile.class.php index 1db0cb1..d85baa7 100644 --- a/inc/profile.class.php +++ b/inc/profile.class.php @@ -1,6 +1,5 @@ 'PluginProcessmakerConfig', - 'label' => $LANG['processmaker']['profile']['process_config'], - 'field' => 'plugin_processmaker_config', - 'rights' => array(READ => __('Read'), UPDATE => __('Update'))), + 'label' => $LANG['processmaker']['profile']['process_config'], + 'field' => 'plugin_processmaker_config', + 'rights' => array(READ => __('Read'), UPDATE => __('Update'))), array('itemtype' => 'PluginProcessmakerConfig', - 'label' => $LANG['processmaker']['profile']['case'], - 'field' => 'plugin_processmaker_case', - 'rights' => array(READ => __('Read'), DELETE => __('Delete'))) + 'label' => $LANG['processmaker']['profile']['case'], + 'field' => 'plugin_processmaker_case', + '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); } /** @@ -106,8 +103,8 @@ class PluginProcessmakerProfile extends CommonDBTM { $ID = $item->getID(); $prof = new self(); self::addDefaultProfileInfos($ID, - array('plugin_processmaker_config' => 0, - 'plugin_processmaker_deletecase' => 0 + array('plugin_processmaker_config' => 0, + 'plugin_processmaker_case' => 0 )); $prof->showForm($ID); diff --git a/inc/task.class.php b/inc/task.class.php index 1353714..bb710e4 100644 --- a/inc/task.class.php +++ b/inc/task.class.php @@ -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])) { diff --git a/setup.php b/setup.php index d329476..64677f2 100644 --- a/setup.php +++ b/setup.php @@ -1,5 +1,7 @@