Skip to content

Commit

Permalink
Cherry pick from 3.5.10 to 3.6.16
Browse files Browse the repository at this point in the history
Added feature GLPI_TASK_PREVENT_REASSIGN to prevent assignment of a list of users (can be PM UID, GLPI id, GLPI logon) to a specific task (can be task list)

Cherry pick from 3.4.24 to 3.6.15

Cherry pick from 3.4.23
Added a proxy and SSL mangement to external application calls Added an escape DB for ticket name and ticket solution description Updated translation
Added swingcall.php file (to test swing api)
Set version to 3.6.14

Cherry pick from version 3.4.22
Added a new case variable to be able to create information tasks GLPI_ITEM_INFORMATION_TASK

Cherry pick from 3.4.21
Revert back $_REQUEST into $_POST

cherry pick from version 3.4.20
Added Send reminder Added unclaim task
Rewrite some code for clearer maintenance

commented line HTTPROXY setup

Bugfixe : remove the default setting of a followup

bugfixes:
- list the processes according to the type of ticket (request or incident).
- set variable 'content' according to the variable sent by processmaker in the addItemFollowup function
- logged error information of curl

Set content to tinymce content field

Bugfixes : Update the taskId (value and letter case)

Bugfixes requests. bad syntax with the new ORM

Changed folder properties

Changed text Deleted unused param

Added a hook to manage the change of user login
Cleaning of unused code Set version to 3.6.8

add condition to set user = admin when script is run in crontask fixes
  • Loading branch information
tomolimo committed Oct 7, 2020
1 parent 7a31eef commit ca197c9
Show file tree
Hide file tree
Showing 22 changed files with 1,477 additions and 585 deletions.
5 changes: 0 additions & 5 deletions ajax/dropdownUsers.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,6 @@
}
//}

if (!function_exists('dpuser_cmp')) {
function dpuser_cmp($a, $b) {
return strcasecmp($a, $b);
}
}

$datas = [];

Expand Down
125 changes: 107 additions & 18 deletions ajax/task_users.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,31 +18,120 @@

Session::checkLoginUser();

$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']."'>".
"<input type='hidden' name='users_id' value='".$_REQUEST['users_id']."'>".
"<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; // not used in this context, just here to define the type of $PM_SOAP
$PM_DB = new PluginProcessmakerDB;
$rand = rand();

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')."&nbsp;";
echo "<input type='hidden' name='action' value='unpausecase_or_reassign_or_delete'>";
echo "<input type='hidden' name='items_id' value='".$_REQUEST['items_id']."'>";
echo "<input type='hidden' name='itemtype' value='".$_REQUEST['itemtype']."'>";
echo "<input type='hidden' name='cases_id' value='".$_REQUEST['cases_id']."'>";
echo "<input type='hidden' name='delIndex' value='".$_REQUEST['delIndex']."'>";
echo "<input type='hidden' name='users_id' value='".$_REQUEST['users_id']."'>";
echo "<input type='hidden' name='taskGuid' value='".$_REQUEST['taskGuid']."'>";
echo "<input type='hidden' name='delThread' value='".$_REQUEST['delThread']."'>";
echo "<input type='hidden' name='action' value='reassign_reminder'>";
echo "<input type='hidden' name='comment' value=''>";
echo $commoninputs;

$can_unclaim = false; // by default
$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) {
$can_unclaim = true;
}

PluginProcessmakerUser::dropdown( ['name' => 'users_id_recipient',
'value' => $_REQUEST['users_id'],
'used' => [$_REQUEST['users_id']],
'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',
'rand' => $rand,
'width' => '',
'specific_tags' => ['taskGuid' => $_REQUEST['taskGuid']]]);
'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',
'rand' => $rand,
'width' => '',
'specific_tags' => ['taskGuid' => $_REQUEST['taskGuid']]
]);

echo "&nbsp;&nbsp;";
echo "<input type='submit' name='reassign' value='".__('Re-assign', 'processmaker')."' class='submit'>";
Html::closeForm(true);
echo "<input type='submit' name='reassign$rand' value='".__('Re-assign', 'processmaker')."' class='submit'>";
echo "<input type='submit' name='reassign' value='".__('Re-assign', 'processmaker')."' class='submit' style='display:none'>";

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() {
$('#processmaker_form_task$rand-".$_REQUEST['delIndex']." input[name=comment]').val($('#comment$rand').val());
//$('#processmaker_form_task$rand-".$_REQUEST['delIndex']."').submit();
$('input[name=reassign').click();
$('#submit$rand').button('disable');
}
}],
show: true,
hide: true
}
$('<div id=reassign$rand></div>').appendTo($('#processmaker_form_task$rand-".$_REQUEST['delIndex']."'));
var locDlg = $('#reassign$rand').html(content + '<p><textarea id=comment$rand rows=6 cols=60></textarea></p><font color=red>Input at least 10 words in English to justify.</font>').dialog(dlgContents);
$('#comment$rand').focus();
$('#comment$rand').on('keydown keyup', function(e) {
if ($('#comment$rand').val().split(/\W+/).length > 10) {
$('#submit$rand').button('enable');
} else {
$('#submit$rand').button('disable');
}
});
return locDlg;
};
$('input[name=reassign$rand]').click(function (e) {
e.preventDefault();
if ($('input[name=users_id]').val() == $('input[name=users_id_recipient]').val()) {
// task is already assigned to this user
alert('".__('Task is already assigned to this user or group!', 'processmaker')."', '".__('Re-assign task', 'processmaker')."');
} else if ($('input[name=users_id_recipient]').val() == 0) {
// un-claim
if (".($can_unclaim ? 1 : 0)." && $('input[name=users_id]').val() != 0) {
showCommentDlg('".__('Un-claim task', 'processmaker')."',
'".__('Please input reason to un-claim<br/>(task will be re-assigned to former group):', 'processmaker')."',
'".__('Un-claim', 'processmaker')."');
} else {
// task can't be unclaim because it isn't SELF_SERVICE
alert('".__('Can\\\'t un-assign Task!', 'processmaker')."', '".__('Un-claim task', 'processmaker')."');
}
} else {
showCommentDlg('".__('Re-assign task', 'processmaker')."',
'".__('Please input reason to re-assign:', 'processmaker')."',
'".__('Re-assign', 'processmaker')."');
}
return false;
});
})
");


if (Session::getLoginUserID() != $_REQUEST['users_id']) {
echo "&nbsp;&nbsp;";
echo "<input type='submit' name='reminder' value='".__('Send reminder', 'processmaker')."' class='submit'>";
}

Html::closeForm(true);
105 changes: 33 additions & 72 deletions front/processmaker.form.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,102 +62,63 @@
// Must show it...
//
$rand = rand( );
Html::redirect($CFG_GLPI['root_doc']."/plugins/processmaker/front/processmaker.helpdesk.form.php?processes_id=".$_POST['plugin_processmaker_processes_id']."&case_guid=".$resultCase->caseId."&rand=$rand&itilcategories_id=".$_POST["itilcategories_id"]."&type=".$_REQUEST["type"]."&entities_id=".$_REQUEST['entities_id']);
Html::redirect($CFG_GLPI['root_doc']."/plugins/processmaker/front/processmaker.helpdesk.form.php?processes_id=".$_POST['plugin_processmaker_processes_id']."&case_guid=".$resultCase->caseId."&rand=$rand&itilcategories_id=".$_POST["itilcategories_id"]."&type=".$_POST["type"]."&entities_id=".$_POST['entities_id']);

} else {
Session::addMessageAfterRedirect( PluginProcessmakerProcessmaker::getPMErrorMessage($resultCase->status_code)."<br>$resultCase->message ($resultCase->status_code)", true, ERROR);
Html::redirect($CFG_GLPI["root_doc"]."/front/helpdesk.public.php?create_ticket=1");
}

}
break;
break;

case 'unpausecase_or_reassign_or_delete' :
if (isset($_POST['unpause'])) {
case 'reassign_reminder' :
if (isset($_POST['reassign'])) {
// here we should re-assign the current task to $_POST['users_id_recipient']
$locCase = new PluginProcessmakerCase;
$locCase->getFromDB($_POST['cases_id']);
$pmResultUnpause = $locCase->unpauseCase($_POST['delIndex'], $_POST['users_id']);
if ($pmResultUnpause->status_code == 0) {
Html::back();
} else {
echo "Error unpausing case: ".$pmResultUnpause->message." \n";
}
} else if (isset($_POST['reassign'])) {
// here we should re-assign the current task to $_POST['users_id_recipient']
//$GLPINewPMUserId = PluginProcessmakerUser::getPMUserId( $_POST['users_id_recipient'] );
if ($_POST['users_id'] != $_POST['users_id_recipient'] && $_POST['users_id_recipient'] != 0) { // normally should be different as of the dropdown prevents already used
$locCase = new PluginProcessmakerCase;
$locCase->getFromDB($_POST['cases_id']);

if ($_POST['users_id_recipient'] != 0) {
// we are assigning a new tech to a task
$pmResponse = $locCase->reassignCase($_POST['delIndex'],
$_POST['taskGuid'],
$_POST['delThread'],
$_POST['users_id'],
$_POST['users_id_recipient']);
$_POST['users_id_recipient'],
['comment' => $_POST['comment']]);
if ($pmResponse) {
Session::addMessageAfterRedirect(__('Task re-assigned!', 'processmaker'), true, INFO);
} else {
Session::addMessageAfterRedirect(__('Error re-assigning task: ', 'processmaker').$pmResponse->message, true, ERROR);
}
} else {
if ($_POST['users_id_recipient'] == 0) {
Session::addMessageAfterRedirect(__('Can\'t un-assign Task!', 'processmaker'), true, ERROR);
} elseif ($_POST['users_id_recipient'] == 0) {
// we are unassigning a task, i.e.: task un-claim
$pmResponse = $locCase->unassignCase($_POST['delIndex'],
$_POST['taskGuid'],
$_POST['tasktype'],
$_POST['tasks_id'],
$_POST['itemtype'],
['comment' => $_POST['comment']]);
if ($pmResponse) {
Session::addMessageAfterRedirect(__('Task un-claimed!', 'processmaker'), true, INFO);
} else {
if ($_POST['users_id'] === $_POST['users_id_recipient'] ) { // normally should be different as of the dropdown prevents already used
Session::addMessageAfterRedirect(__('Task already assigned to this person!', 'processmaker'), true, ERROR);
}
Session::addMessageAfterRedirect(__("Can't un-claim task! Verify 'Assignement Rules' in the process definition.", 'processmaker'), true, ERROR);
}
}
//} else if (isset($_POST['delete'])) {
// // delete case from case table, this will also delete the tasks
// $locCase = new PluginProcessmakerCase;
// if ($locCase->getFromDB($_POST['cases_id']) && $locCase->deleteCase()) {
// // request delete from pm itself
// $PM_SOAP->login(true);

// $resultPM = $PM_SOAP->deleteCase($locCase->fields['case_guid']);

// if ($resultPM->status_code == 0) {
// Session::addMessageAfterRedirect($LANG['processmaker']['item']['case']['deleted'], true, INFO);
// } else {
// Session::addMessageAfterRedirect($LANG['processmaker']['item']['case']['errordeleted'], true, ERROR);
// }
// } else {
// Session::addMessageAfterRedirect($LANG['processmaker']['item']['case']['errordeleted'], true, ERROR);
// }
//} else if (isset($_POST['cancel'])) {
// // cancel case from PM
// $locCase = new PluginProcessmakerCase;
// $locCase->getFromDB($_POST['cases_id']);
// $resultPM = $PM_SOAP->cancelCase($locCase->fields['case_guid']); //, $_POST['plugin_processmaker_del_index'], $_POST['plugin_processmaker_users_id'] ) ;
// if ($resultPM->status_code === 0) {
// //$locCase = new PluginProcessmakerCase;
// //$locCase->getFromDB($_POST['cases_id']);
// if ($locCase->cancelCase()) {
// Session::addMessageAfterRedirect($LANG['processmaker']['item']['case']['cancelled'], true, INFO);
// } else {
// Session::addMessageAfterRedirect($LANG['processmaker']['item']['case']['errorcancelled'], true, ERROR);
// }
// } else {
// if ($resultPM->status_code == 100 && $locCase->deleteCase()) { // case is draft then delete it
// // request delete from pm itself
// $PM_SOAP->login(true);
} elseif (isset($_POST['reminder'])) {
// send notification remider as requested for this task

// $resultPM = $PM_SOAP->deleteCase($locCase->fields['case_guid']);

// if ($resultPM->status_code == 0) {
// Session::addMessageAfterRedirect($LANG['processmaker']['item']['case']['deleted'], true, INFO);
// } else {
// Session::addMessageAfterRedirect($LANG['processmaker']['item']['case']['errordeleted'], true, ERROR);
// }
// } else {
// Session::addMessageAfterRedirect($LANG['processmaker']['item']['case']['errorcancelled']. " " . $resultPM->message, true, ERROR);
// }
// }
$locCase = new PluginProcessmakerCase;
$locCase->getFromDB($_POST['cases_id']);
$glpi_item = new $_POST['itemtype'];
$glpi_item->getFromDB($_POST['items_id']);
$pm_task = new PluginProcessmakerTask($_POST['tasktype']);
$pm_task->getFromDB($_POST['tasks_id']);
$glpi_task = new $_POST['tasktype'];
$glpi_task->getFromDB($_POST['tasks_id']);

// send notification now!
$pm_task->sendNotification('task_reminder', $glpi_task, $glpi_item, $locCase);
}

break;

}

// to return to item
Expand Down
2 changes: 1 addition & 1 deletion front/processmaker.helpdesk.form.php
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ function in_array_recursive($needle, $haystack) {
if (isset($_REQUEST['case_guid'])) {
$res = $DB->request(
'glpi_plugin_processmaker_cases', [
' case_guid'=>$_REQUEST['case_guid']
'case_guid'=>$_REQUEST['case_guid']
]);
$query = "SELECT * FROM glpi_plugin_processmaker_cases WHERE case_guid='".$_REQUEST['case_guid']."'";
//$res = $DB->query( $query );
Expand Down
51 changes: 44 additions & 7 deletions hook.php
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,10 @@ function plugin_pre_item_update_processmaker(CommonITILObject $parm) {
* @param mixed $parm is the object
*/
function plugin_item_update_processmaker_satisfaction($parm) {

global $PM_SOAP;
if (Session::isCron()) { // Task cron log with user admin
$PM_SOAP->login(true);
}
$cases = PluginProcessmakerCase::getIDsFromItem('Ticket', $parm->fields['tickets_id']);
foreach ($cases as $cases_id) {
$locCase = new PluginProcessmakerCase;
Expand All @@ -192,6 +195,33 @@ function plugin_item_update_processmaker_satisfaction($parm) {
}


/**
* Summary of plugin_item_update_processmaker_user
* When a user login is changed, then must change it in the PM tables
* @param User $param is the user being changed
*/
function plugin_item_update_processmaker_user(User $param) {
// Must test if user login has been changed
// if yes, must change the login in the PM tables:
// USERS and RBAC_USERS, othewise the link in the processmaker_users table will be invalid
if (in_array('name', $param->updates)) {
// check if user is in the processmaker_user table
$pm_user = PluginProcessmakerUser::getPMUserId($param->getID());
if ($pm_user) {
// must update the user in PM tables
global $PM_SOAP;
if ($param->fields['is_active'] == 0 || $param->fields['is_deleted'] == 1) {
$status = "INACTIVE";
} else {
$status = "ACTIVE";
}
$PM_SOAP->login(true);
$pmResult = $PM_SOAP->updateUser( $pm_user, $param->fields['name'], $param->fields['firstname'], $param->fields['realname'], $status );
}
}
}


function plugin_processmaker_post_init() {
global $PM_DB, $PM_SOAP;
if (!isset($PM_DB)) {
Expand Down Expand Up @@ -376,15 +406,22 @@ function plugin_item_update_processmaker_tasks($parm) {
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json', 'Content-Length: ' . strlen($externalapplicationparams), 'Expect:']);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1 );
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, $pmconfig->fields['ssl_verify']);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, $pmconfig->fields['ssl_verify']);

//curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, 1 ) ;
//curl_setopt($ch, CURLOPT_PROXY, "localhost:8889");
if (isset($externalapplication['ssl_verify'])) {
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, $externalapplication['ssl_verify']);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, $externalapplication['ssl_verify']);
}

$response = curl_exec ($ch);
if (isset($externalapplication['proxy'])) {
curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, 1 ) ;
curl_setopt($ch, CURLOPT_PROXY, $externalapplication['proxy']);
}

//Toolbox::logDebug( $response ) ;
$response = curl_exec ($ch);
if ($response === false) {
//throw new Exception(curl_error($ch), curl_errno($ch));
Toolbox::logDebug( curl_error($ch).":".curl_errno($ch) );
}

curl_close ($ch);
}
Expand Down
Loading

0 comments on commit ca197c9

Please sign in to comment.