';
echo '| ';
echo "" . __('Re-assign task to', 'processmaker') . "";
echo ' | ';
$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']);
}
}
$task_table = getTableForItemType($_REQUEST['tasktype']);
$res = $DB->request([
'SELECT' => [
'pm.is_reassignreason_mandatory AS pm_is_reassignreason_mandatory',
'gppp.is_reassignreason_mandatory AS gppp_is_reassignreason_mandatory',
'pm.before_time AS pm_before_time',
'pm.after_time AS pm_after_time',
'pm.users_id AS pm_users_id',
'gpptr.before_time AS tr_before_time',
'gpptr.after_time AS tr_after_time',
'gpptr.users_id AS tr_users_id',
'gpptr.id AS plugin_processmaker_taskrecalls_id',
'gtt.begin AS task_begin',
'gtt.end AS task_end',
'gpptr.when AS tr_when',
'gppt.id AS pm_tasks_id'
],
'FROM' => 'glpi_plugin_processmaker_taskcategories AS pm',
'LEFT JOIN' => [
'glpi_plugin_processmaker_processes AS gppp' => [
'ON' => [
'gppp' => 'id',
'pm' => 'plugin_processmaker_processes_id'
]
],
'glpi_plugin_processmaker_tasks as gppt' => [
'ON' => [
'pm' => 'id',
'gppt' => 'plugin_processmaker_taskcategories_id',
['AND' => ['gppt.items_id' => $_REQUEST['tasks_id'],
'gppt.itemtype'=> $_REQUEST['tasktype']]
]
]
],
'glpi_plugin_processmaker_taskrecalls as gpptr' => [
'ON' => [
'gpptr' => 'plugin_processmaker_tasks_id',
'gppt' => 'id'
]
],
$task_table . ' as gtt' => [
'ON' => [
'gtt' => 'id',
'gppt' => 'items_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']);
echo '';
PluginProcessmakerUser::dropdown( ['name' => 'users_id_recipient',
'value' => $_REQUEST['users_id'],
'used' => $_REQUEST['used'] ?? [],
'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 "";
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 = ''
+ ' '
+ ' '
+ ''
+ ' '
+ ' '
+ ''
+ ' '
+ ' ';
$('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;
});
})
");
echo ' | ';
echo '';
echo ' | ';
echo '';
if (!isset($PM_SOAP->config)) {
$PM_SOAP->config = Config::getConfigurationValues('plugin:processmaker');
}
if (Session::getLoginUserID() != $_REQUEST['users_id']
&& $PM_SOAP->config['users_id'] != $_REQUEST['users_id']) {
echo "";
}
echo ' | ';
// check rights
$caneditreminders = Session::getCurrentInterface() == 'central' && $PM_SOAP->config['users_id'] != $_REQUEST['users_id'];
if ($caneditreminders) {
echo '';
echo ' Automatic reminder settings ';
echo Html::scriptBlock("
function showHideReminderSettings() {
if ($('.reminder_settings').css('display') == 'none') {
$('.reminder_settings').css('display', '');
} else {
$('.reminder_settings').css('display', 'none');
}
$('#reminder_arrow').toggleClass('fa-caret-up fa-caret-down');
}
");
echo ' | ';
}
echo '
';
echo '