added resolution field in creation and update operations

This commit is contained in:
alejandro.campos@artica.es 2021-11-16 14:13:45 +01:00
parent 9c290d917e
commit 3f0fd30eb8
1 changed files with 70 additions and 5 deletions

View File

@ -78,6 +78,10 @@ $integria_types_csv = integria_api_call(null, null, null, null, 'get_types');
get_array_from_csv_data_pair($integria_types_csv, $integria_types_values);
$integria_resolution_csv = integria_api_call(null, null, null, null, 'get_incidents_resolutions');
get_array_from_csv_data_pair($integria_resolution_csv, $integria_resolution_values);
$event_id = (int) get_parameter('from_event');
$incident_id_edit = (int) get_parameter('incident_id');
$create_incident = (bool) get_parameter('create_incident', 0);
@ -88,6 +92,7 @@ $incident_owner = get_parameter('owner');
$incident_type = (int) get_parameter('type');
$incident_creator = get_parameter('creator');
$incident_status = (int) get_parameter('status');
$incident_resolution = (int) get_parameter('resolution');
$incident_title = events_get_field_value_by_event_id($event_id, get_parameter('incident_title'));
$incident_content = events_get_field_value_by_event_id($event_id, get_parameter('incident_content'));
@ -97,8 +102,13 @@ $incident_content = str_replace(',', ':::', $incident_content);
// Perform action.
if ($create_incident === true) {
// Disregard incident resolution unless status is 'closed'.
if ($incident_status !== 7) {
$incident_resolution = 0;
}
// Call Integria IMS API method to create an incident.
$result_api_call = integria_api_call(null, null, null, null, 'create_incident', [$incident_title, $incident_group_id, $incident_criticity_id, $incident_content, '', $incident_type, '', $incident_owner, '0', $incident_status], false, '', ',');
$result_api_call = integria_api_call(null, null, null, null, 'create_incident', [$incident_title, $incident_group_id, $incident_criticity_id, $incident_content, '', $incident_type, '', $incident_owner, '0', $incident_status, '', $incident_resolution], false, '', ',');
// Necessary to explicitly set true if not false because function returns api call result in case of success instead of true value.
$incident_created_ok = ($result_api_call != false) ? true : false;
@ -109,8 +119,13 @@ if ($create_incident === true) {
__('Could not be created in Integria IMS')
);
} else if ($update_incident === true) {
// Disregard incident resolution unless status is 'closed'.
if ($incident_status !== 7) {
$incident_resolution = 0;
}
// Call Integria IMS API method to update an incident.
$result_api_call = integria_api_call(null, null, null, null, 'update_incident', [$incident_id_edit, $incident_title, $incident_content, '', $incident_group_id, $incident_criticity_id, 0, $incident_status, $incident_owner, 0, $incident_type], false, '', ',');
$result_api_call = integria_api_call(null, null, null, null, 'update_incident', [$incident_id_edit, $incident_title, $incident_content, '', $incident_group_id, $incident_criticity_id, $incident_resolution, $incident_status, $incident_owner, 0, $incident_type], false, '', ',');
// Necessary to explicitly set true if not false because function returns api call result in case of success instead of true value.
$incident_updated_ok = ($result_api_call != false) ? true : false;
@ -152,7 +167,7 @@ $table->style[0] = 'width: 33%; padding-right: 50px; padding-left: 100px;';
$table->style[1] = 'width: 33%; padding-right: 50px; padding-left: 50px;';
$table->style[2] = 'width: 33%; padding-right: 100px; padding-left: 50px;';
$table->colspan[0][0] = 2;
$table->colspan[3][0] = 3;
$table->colspan[4][0] = 3;
$help_macros = isset($_GET['from_event']) ? ui_print_help_icon('response_macros', true) : '';
@ -164,6 +179,7 @@ if ($update) {
$input_value_criticity = $incident_details[7];
$input_value_owner = $incident_details[5];
$input_value_content = $incident_details[4];
$input_value_resolution = $incident_details[12];
} else if (isset($_GET['from_event'])) {
$input_value_title = $config['cr_incident_title'];
$input_value_type = $config['cr_incident_type'];
@ -172,6 +188,7 @@ if ($update) {
$input_value_criticity = $config['cr_default_criticity'];
$input_value_owner = $config['cr_default_owner'];
$input_value_content = $config['cr_incident_content'];
$input_value_resolution = 0;
} else {
$input_value_title = '';
$input_value_type = '';
@ -180,6 +197,7 @@ if ($update) {
$input_value_criticity = '';
$input_value_owner = '';
$input_value_content = '';
$input_value_resolution = 0;
}
$table->data[0][0] = '<div class="label_select"><p class="input_label">'.__('Title').':&nbsp'.$help_macros.'</p>';
@ -293,8 +311,26 @@ $table->data[2][2] .= '<div class="label_select_parent">'.html_print_autocomplet
'w100p'
).'</div>';
$table->data[3][0] = '<div class="label_select"><p class="input_label">'.__('Description').':&nbsp'.$help_macros.'</p>';
$table->data[3][0] .= '<div class="label_select_parent">'.html_print_textarea(
$table->data[3][0] = '<div class="label_select"><p class="input_label">'.__('Resolution').': </p>';
$table->data[3][0] .= '<div class="label_select_parent">'.html_print_select(
$integria_resolution_values,
'resolution',
$input_value_resolution,
'',
__('Select'),
1,
true,
false,
true,
'',
false,
'width: 100%;'
).'</div>';
$table->data[4][0] = '<div class="label_select"><p class="input_label">'.__('Description').':&nbsp'.$help_macros.'</p>';
$table->data[4][0] .= '<div class="label_select_parent">'.html_print_textarea(
'incident_content',
3,
20,
@ -323,3 +359,32 @@ if ($update) {
}
echo '</div>';
?>
<script type="text/javascript">
$(document).ready(function () {
$('#add_alert_table-3').hide();
var input_value_status =
<?php
$status_value = ($input_value_status === '') ? 0 : $input_value_status;
echo $status_value;
?>
;
if (input_value_status === 7) {
$('#add_alert_table-3').show();
} else {
$('#add_alert_table-3').hide();
}
$('#status').on('change', function() {
if ($(this).val() === '7') {
$('#add_alert_table-3').show();
} else {
$('#add_alert_table-3').hide();
}
});
});
</script>