. -------------------------------------------------------------------------- */ // ---------------------------------------------------------------------- // Original Author of file: Olivier Moron // Purpose of file: // ---------------------------------------------------------------------- // Direct access to file if (strpos($_SERVER['PHP_SELF'], "task_users.php")) { include ("../../../inc/includes.php"); header("Content-Type: text/html; charset=UTF-8"); Html::header_nocache(); } if (!defined('GLPI_ROOT')) { die("Can not access directly to this file"); } Session::checkLoginUser(); $rand = rand(); $commoninputs = "". "". "". "". "". "". "". "". ""; $PM_SOAP = new PluginProcessmakerProcessmaker; $PM_DB = new PluginProcessmakerDB; echo "
"; echo __('Re-assign task to', 'processmaker')." "; echo ""; echo ""; echo $commoninputs; $can_unclaim = false; // by default $grp = false; $query = "SELECT TAS_GROUP_VARIABLE FROM TASK WHERE TAS_UID='".$_REQUEST['taskGuid']."' AND TAS_ASSIGN_TYPE='SELF_SERVICE';"; $res = $PM_DB->query($query); if ($PM_DB->numrows($res) > 0 && $row = $PM_DB->fetchAssoc($res)) { $can_unclaim = true; if ($row['TAS_GROUP_VARIABLE'] != '') { //self-service value based assignment $PM_SOAP->login(true); // needs to be logged in to be able to call SOAP $grp = $PM_SOAP->getGLPIGroupIdForSelfServiceTask($_REQUEST['caseGuid'], $_REQUEST['taskGuid']); } } $res = $DB->request([ 'SELECT' => [ 'pm.is_reassignreason_mandatory AS pm_is_reassignreason_mandatory', 'gppp.is_reassignreason_mandatory AS gppp_is_reassignreason_mandatory' ], 'FROM' => 'glpi_plugin_processmaker_taskcategories AS pm', 'LEFT JOIN' => [ 'glpi_plugin_processmaker_processes AS gppp' => [ 'FKEY' => [ 'gppp' => 'id', 'pm' => 'plugin_processmaker_processes_id' ] ] ], 'WHERE' => [ 'pm.pm_task_guid' => $_REQUEST['taskGuid'] ] ]); // there is only one row $taskCat = $res->current(); $ask_for_reason = PluginProcessmakerTaskCategory::inheritedReAssignReason($taskCat['pm_is_reassignreason_mandatory'], $taskCat['gppp_is_reassignreason_mandatory']); PluginProcessmakerUser::dropdown( ['name' => 'users_id_recipient', 'value' => $_REQUEST['users_id'], //'used' => $_REQUEST['used'], // not set to be able to alert when trying to re-assigned to the same user 'entity' => 0, //$item->fields["entities_id"], // not used, as any user can be assigned to any tasks 'entity_sons' => false, // not used, as any user can be assigned to any tasks 'right' => 'all', 'all' => ($can_unclaim ? 0 : -1), 'rand' => $rand, 'width' => '', 'specific_tags' => ['taskGuid' => $_REQUEST['taskGuid'], 'grpGuid' => ($grp !== false ? $grp['uid'] : 0)] ]); echo "  "; echo ""; echo ""; echo HTML::scriptBlock(" $(function () { // Dialog helpers // Create the dialog with \"Re-assign\" button function showCommentDlg(title, content, alttext) { modalId = title.replaceAll(' ', '_') var modal = $('#'+title); if (modal && modal.length == 0) { var modal = '
' + '
' + '
' + '
' + '
'+ title +'
' + '' + '
' + '
' + '
' + '
' + '' + '
' + '
' + '
'; $('body').append(modal); } $('#'+modalId).modal('show'); $('#'+modalId+' .modal-body').append('

".addslashes(__('Input at least 10 words to justify.','processmaker'))."'); $('#commenttxtarea$rand').focus(); $('#commenttxtarea$rand').on('keydown keyup', function(e) { if ($('#commenttxtarea$rand').val().split(/\W+/).length > 10) { $('#submit$rand').prop('disabled', false); } else { $('#submit$rand').prop('disabled', true); } }); $('#'+modalId).on('hide.bs.modal', function () { $('#'+modalId).remove(); }) $('#submit$rand').click(() => { $('#comment$rand').val($('#commenttxtarea$rand').val()); $('#reassign$rand').click(); $('#submit$rand').button('disable'); $('#'+modalId).modal('hide').remove(); }); }; $('input[name=reassign$rand]').click(function (e) { //debugger; let post = true; e.preventDefault(); let users_id_val = $('#users_id$rand').val(); let users_id_recipient_val = $('#dropdown_users_id_recipient$rand').val(); if (users_id_val == users_id_recipient_val) { // task is already assigned to this user if (users_id_val == 0) { alert('".addslashes(__('Task is already un-assigned!', 'processmaker'))."', '".addslashes(__('Re-assign task', 'processmaker'))."'); } else { alert('".addslashes(__('Task is already assigned to this user!', 'processmaker'))."', '".addslashes(__('Re-assign task', 'processmaker'))."'); } post = false; } else if (users_id_recipient_val == 0) { // un-claim if (".($can_unclaim ? 1 : 0)." && users_id_val != 0) { if (" . ($ask_for_reason ? 1 : 0) . ") { showCommentDlg('".addslashes(__('Un-claim task', 'processmaker'))."', '".addslashes(__('Please input reason to un-claim
(task will be re-assigned to former group):', 'processmaker'))."', '".addslashes(__('Un-claim', 'processmaker'))."'); post = false; } } else { // task can't be unclaimed because it isn't SELF_SERVICE alert('".addslashes(__("Can't un-assign task!", 'processmaker'))."', '".addslashes(__('Un-claim task', 'processmaker'))."'); post = false; } } else if (" . ($ask_for_reason ? 1 : 0) . ") { showCommentDlg('".addslashes(__('Re-assign task', 'processmaker'))."', '".addslashes(__('Please input reason to re-assign:', 'processmaker'))."', '".addslashes(__('Re-assign', 'processmaker'))."'); post = false; } if (post) { // here we must click on the reassign button to force POST $('#reassign$rand').click(); } return false; }); }) "); if (Session::getLoginUserID() != $_REQUEST['users_id']) { echo "  "; echo ""; } Html::closeForm(true);