2021-03-18 10:01:49 +01:00
|
|
|
<?php
|
2023-10-16 14:48:42 +02:00
|
|
|
/*
|
|
|
|
|
-------------------------------------------------------------------------
|
|
|
|
|
ProcessMaker plugin for GLPI
|
|
|
|
|
Copyright (C) 2014-2022 by Raynet SAS a company of A.Raymond Network.
|
2021-03-18 10:01:49 +01:00
|
|
|
|
2023-10-16 14:48:42 +02:00
|
|
|
https://www.araymond.com/
|
|
|
|
|
-------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
LICENSE
|
|
|
|
|
|
|
|
|
|
This file is part of ProcessMaker plugin for GLPI.
|
|
|
|
|
|
|
|
|
|
This file is free software; you can redistribute it and/or modify
|
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
|
|
This plugin is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
|
along with this plugin. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
--------------------------------------------------------------------------
|
|
|
|
|
*/
|
2021-03-18 10:01:49 +01:00
|
|
|
// ----------------------------------------------------------------------
|
|
|
|
|
// 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();
|
|
|
|
|
|
2023-10-16 14:48:42 +02:00
|
|
|
$rand = rand();
|
|
|
|
|
|
2021-03-18 10:01:49 +01:00
|
|
|
$commoninputs = "<input type='hidden' name='items_id' value='".$_REQUEST['items_id']."'>".
|
|
|
|
|
"<input type='hidden' name='itemtype' value='".$_REQUEST['itemtype']."'>".
|
|
|
|
|
"<input type='hidden' name='cases_id' value='".$_REQUEST['cases_id']."'>".
|
|
|
|
|
"<input type='hidden' name='delIndex' value='".$_REQUEST['delIndex']."'>".
|
2023-10-16 14:48:42 +02:00
|
|
|
"<input type='hidden' name='users_id' id='users_id$rand' value='".$_REQUEST['users_id']."'>".
|
2021-03-18 10:01:49 +01:00
|
|
|
"<input type='hidden' name='taskGuid' value='".$_REQUEST['taskGuid']."'>".
|
|
|
|
|
"<input type='hidden' name='delThread' value='".$_REQUEST['delThread']."'>".
|
|
|
|
|
"<input type='hidden' name='tasktype' value='".$_REQUEST['tasktype']."'>".
|
|
|
|
|
"<input type='hidden' name='tasks_id' value='".$_REQUEST['tasks_id']."'>";
|
|
|
|
|
|
|
|
|
|
$PM_SOAP = new PluginProcessmakerProcessmaker;
|
|
|
|
|
$PM_DB = new PluginProcessmakerDB;
|
|
|
|
|
|
|
|
|
|
echo "<form style='margin-bottom: 0px' name='processmaker_form_task$rand-".$_REQUEST['delIndex']."' id='processmaker_form_task$rand-".$_REQUEST['delIndex']."' method='post' action='".Toolbox::getItemTypeFormURL("PluginProcessmakerProcessmaker")."'>";
|
|
|
|
|
echo __('Re-assign task to', 'processmaker')." ";
|
|
|
|
|
echo "<input type='hidden' name='action' value='reassign_reminder'>";
|
2023-10-16 14:48:42 +02:00
|
|
|
echo "<input type='hidden' name='comment' id='comment$rand' value=''>";
|
2021-03-18 10:01:49 +01:00
|
|
|
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);
|
2021-06-23 12:20:12 +02:00
|
|
|
if ($PM_DB->numrows($res) > 0 && $row = $PM_DB->fetchAssoc($res)) {
|
2021-03-18 10:01:49 +01:00
|
|
|
$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']);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-16 14:48:42 +02:00
|
|
|
$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->next();
|
|
|
|
|
$ask_for_reason = PluginProcessmakerTaskCategory::inheritedReAssignReason($taskCat['pm_is_reassignreason_mandatory'], $taskCat['gppp_is_reassignreason_mandatory']);
|
|
|
|
|
|
2021-03-18 10:01:49 +01:00
|
|
|
PluginProcessmakerUser::dropdown( ['name' => 'users_id_recipient',
|
|
|
|
|
'value' => $_REQUEST['users_id'],
|
2023-10-16 14:48:42 +02:00
|
|
|
//'used' => $_REQUEST['used'], // not set to be able to alert when trying to re-assigned to the same user
|
2021-03-18 10:01:49 +01:00
|
|
|
'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 " ";
|
2023-10-16 14:48:42 +02:00
|
|
|
echo "<input type='submit' name='reassign$rand' value='".__('Re-assign', 'processmaker')."' class='submit'>";
|
|
|
|
|
echo "<input type='submit' name='reassign' id='reassign$rand' value='".__('Re-assign', 'processmaker')."' class='submit' style='display:none'>";
|
2021-03-18 10:01:49 +01:00
|
|
|
|
|
|
|
|
echo HTML::scriptBlock("
|
|
|
|
|
$(function () {
|
|
|
|
|
// Dialog helpers
|
|
|
|
|
// Create the dialog with \"Re-assign\" button
|
|
|
|
|
function showCommentDlg(title, content, alttext) {
|
|
|
|
|
|
|
|
|
|
var dlgContents = {
|
|
|
|
|
title: title,
|
|
|
|
|
modal: true,
|
|
|
|
|
width: 'auto',
|
|
|
|
|
height: 'auto',
|
|
|
|
|
resizable: false,
|
|
|
|
|
close: function (event, ui) {
|
|
|
|
|
$(this).dialog('destroy').remove();
|
|
|
|
|
},
|
|
|
|
|
buttons: [{
|
|
|
|
|
text: alttext,
|
|
|
|
|
id: 'submit$rand',
|
|
|
|
|
disabled: 'disabled',
|
|
|
|
|
click: function() {
|
2023-10-16 14:48:42 +02:00
|
|
|
$('#comment$rand').val($('#commenttxtarea$rand').val());
|
|
|
|
|
$('#reassign$rand').click();
|
2021-03-18 10:01:49 +01:00
|
|
|
$('#submit$rand').button('disable');
|
|
|
|
|
}
|
|
|
|
|
}],
|
|
|
|
|
show: true,
|
|
|
|
|
hide: true
|
|
|
|
|
}
|
2023-10-16 14:48:42 +02:00
|
|
|
$('<div id=divreassign$rand></div>').appendTo($('#processmaker_form_task$rand-".$_REQUEST['delIndex']."'));
|
|
|
|
|
var locDlg = $('#divreassign$rand').html(content + '<p><textarea id=commenttxtarea$rand rows=6 cols=60></textarea></p><font color=red>".addslashes(__('Input at least 10 words to justify.','processmaker'))."</font>').dialog(dlgContents);
|
|
|
|
|
$('#commenttxtarea$rand').focus();
|
|
|
|
|
$('#commenttxtarea$rand').on('keydown keyup', function(e) {
|
|
|
|
|
if ($('#commenttxtarea$rand').val().split(/\W+/).length > 10) {
|
2021-03-18 10:01:49 +01:00
|
|
|
$('#submit$rand').button('enable');
|
|
|
|
|
} else {
|
|
|
|
|
$('#submit$rand').button('disable');
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return locDlg;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
$('input[name=reassign$rand]').click(function (e) {
|
2023-10-16 14:48:42 +02:00
|
|
|
//debugger;
|
|
|
|
|
let post = true;
|
2021-03-18 10:01:49 +01:00
|
|
|
e.preventDefault();
|
2023-10-16 14:48:42 +02:00
|
|
|
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) {
|
2021-03-18 10:01:49 +01:00
|
|
|
// task is already assigned to this user
|
2023-10-16 14:48:42 +02:00
|
|
|
if (users_id_val == 0) {
|
2021-03-18 10:01:49 +01:00
|
|
|
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'))."');
|
|
|
|
|
}
|
2023-10-16 14:48:42 +02:00
|
|
|
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) . ") {
|
|
|
|
|
//e.preventDefault();
|
|
|
|
|
showCommentDlg('".addslashes(__('Un-claim task', 'processmaker'))."',
|
|
|
|
|
'".addslashes(__('Please input reason to un-claim<br/>(task will be re-assigned to former group):', 'processmaker'))."',
|
|
|
|
|
'".addslashes(__('Un-claim', 'processmaker'))."');
|
|
|
|
|
post = false;
|
|
|
|
|
}
|
2021-03-18 10:01:49 +01:00
|
|
|
} else {
|
2023-10-16 14:48:42 +02:00
|
|
|
// task can't be unclaimed because it isn't SELF_SERVICE
|
2021-03-18 10:01:49 +01:00
|
|
|
alert('".addslashes(__("Can't un-assign task!", 'processmaker'))."', '".addslashes(__('Un-claim task', 'processmaker'))."');
|
2023-10-16 14:48:42 +02:00
|
|
|
post = false;
|
2021-03-18 10:01:49 +01:00
|
|
|
}
|
2023-10-16 14:48:42 +02:00
|
|
|
} 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();
|
2021-03-18 10:01:49 +01:00
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
});
|
|
|
|
|
})
|
|
|
|
|
");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (Session::getLoginUserID() != $_REQUEST['users_id']) {
|
|
|
|
|
echo " ";
|
2023-10-16 14:48:42 +02:00
|
|
|
echo "<input type='submit' name='reminder' value='".__('Send reminder', 'processmaker')."' class='submit'>";
|
2021-03-18 10:01:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Html::closeForm(true);
|