diff --git a/pandora_console/include/functions.php b/pandora_console/include/functions.php index b9a1cdde92..c2d2714d46 100644 --- a/pandora_console/include/functions.php +++ b/pandora_console/include/functions.php @@ -5597,3 +5597,63 @@ function ui_print_integria_incident_priority($priority, $priority_label) return $output; } + + +/** + * Get tickets from Integria IMS. + * + * @param array $tickets_filters Filters to send to API. + * + * @return array Tickets returned by API call. + */ +function get_tickets_integriaims($tickets_filters) +{ + global $config; + + // Filters. + $incident_text = $tickets_filters['incident_text']; + $incident_status = $tickets_filters['incident_status']; + $incident_group = $tickets_filters['incident_group']; + $incident_owner = $tickets_filters['incident_owner']; + $incident_creator = $tickets_filters['incident_creator']; + $incident_priority = $tickets_filters['incident_priority']; + $incident_resolution = $tickets_filters['incident_resolution']; + $incident_date = $tickets_filters['incident_date']; + + // API call. + $result_api_call_list = integria_api_call( + $config['integria_hostname'], + $config['integria_user'], + $config['integria_pass'], + $config['integria_api_pass'], + 'get_incidents', + [ + $incident_text, + $incident_status, + $incident_group, + $incident_priority, + '0', + $incident_owner, + $incident_creator, + ] + ); + + // Return array of api call 'get_incidents'. + $array_get_incidents = []; + get_array_from_csv_data_all($result_api_call_list, $array_get_incidents); + + // Modify $array_get_incidents if filter for resolution exists. + $filter_resolution = []; + foreach ($array_get_incidents as $key => $value) { + if ($incident_resolution !== '' && ($array_get_incidents[$key][12] == $incident_resolution)) { + $filter_resolution[$key] = $array_get_incidents[$key]; + continue; + } + } + + if ($incident_resolution !== '') { + $array_get_incidents = $filter_resolution; + } + + return $array_get_incidents; +} diff --git a/pandora_console/include/functions_html.php b/pandora_console/include/functions_html.php index 9c3f96f53a..f006520b38 100644 --- a/pandora_console/include/functions_html.php +++ b/pandora_console/include/functions_html.php @@ -3423,7 +3423,6 @@ function html_print_autocomplete_users_from_integria( timeout: 10000, dataType: "json", success: function (data) { - console.log(data); temp = []; $.each(data, function (id, module) { temp.push({ diff --git a/pandora_console/operation/incidents/integriaims_export_csv.php b/pandora_console/operation/incidents/integriaims_export_csv.php new file mode 100644 index 0000000000..c474b3eb94 --- /dev/null +++ b/pandora_console/operation/incidents/integriaims_export_csv.php @@ -0,0 +1,138 @@ + $value) { + // Status. + if ($tickets_csv_array[$key][6] == 0) { + $tickets_csv_array[$key][6] = 'None'; + } else { + $tickets_csv_array[$key][6] = $status_incident[$tickets_csv_array[$key][6]]; + } + + // Priority. + $tickets_csv_array[$key][7] = $priority_incident[$tickets_csv_array[$key][7]]; + + // Group. + $tickets_csv_array[$key][8] = $group_incident[$tickets_csv_array[$key][8]]; + + // Resolution. + if ($tickets_csv_array[$key][12] == 0) { + $tickets_csv_array[$key][12] = 'None'; + } else { + $tickets_csv_array[$key][12] = $resolution_incident[$tickets_csv_array[$key][12]]; + } + + $tickets_csv_array_filter[$key] = [ + 'id_incidencia' => $tickets_csv_array[$key][0], + 'titulo' => $tickets_csv_array[$key][3], + 'id_grupo' => $tickets_csv_array[$key][8], + 'estado_resolution' => $tickets_csv_array[$key][6].' / '.$tickets_csv_array[$key][12], + 'prioridad' => $tickets_csv_array[$key][7], + 'actualizacion' => $tickets_csv_array[$key][9], + 'id_creator' => $tickets_csv_array[$key][10], + 'owner' => $tickets_csv_array[$key][5], + ]; +} + + +// Header for CSV file. +$header = [ + __('ID Ticket'), + __('Title'), + __('Group/Company'), + __('Status/Resolution'), + __('Priority'), + __('Updated/Started'), + __('Creator'), + __('Owner'), +]; + +$header_csv = ''; +foreach ($header as $key => $value) { + $header_csv .= $value.','; +} + +$header_csv = io_safe_output($header_csv).PHP_EOL; + + +// Join header and content. +$tickets_csv = ''; +foreach ($tickets_csv_array_filter as $key => $value) { + $tickets_csv .= implode(',', $tickets_csv_array_filter[$key]).PHP_EOL; +} + +$tickets_csv = $header_csv.$tickets_csv; + + +// Create csv file. +$filename = 'tickets_export-'.date('Ymd').'-'.date('His').'.csv'; + +ob_clean(); + +header('Content-Type: text/csv; charset=utf-8'); +header('Content-Disposition: attachment; filename='.$filename); + +// BOM. +echo pack('C*', 0xEF, 0xBB, 0xBF); + +// CSV file. +echo io_safe_output($tickets_csv); diff --git a/pandora_console/operation/incidents/list_integriaims_incidents.php b/pandora_console/operation/incidents/list_integriaims_incidents.php index fc57a5b08f..41323ae91e 100644 --- a/pandora_console/operation/incidents/list_integriaims_incidents.php +++ b/pandora_console/operation/incidents/list_integriaims_incidents.php @@ -40,7 +40,7 @@ if ($has_connection === false) { } // Get parameters for filters. -$incident_text = (string) get_parameter('text_filter', ''); +$incident_text = (string) get_parameter('incident_text', ''); $incident_status = (int) get_parameter('incident_status', 0); $incident_group = (int) get_parameter('incident_group', 1); $incident_owner = (string) get_parameter('incident_owner', ''); @@ -109,7 +109,7 @@ $table->cellspacing = '0'; $table->data = []; $table->data[0][0] = __('Text filter'); -$table->data[0][1] = html_print_input_text('text_filter', $text_filter, '', 20, 40, true); +$table->data[0][1] = html_print_input_text('incident_text', $incident_text, '', 30, 100, true); $table->data[0][2] = __('Status'); $table->data[0][3] = html_print_select( @@ -163,17 +163,64 @@ $table->data[2][1] = html_print_select( // TODO: field type date. $table->data[2][2] = __('Date'); -$table->data[2][3] = 'FECHA'; +$table->data[2][3] = html_print_input_text_extended( + 'created_from', + '', + 'created_from', + '', + 12, + 50, + false, + '', + 'placeholder="'.__('Created from').'"', + true +); +$table->data[2][3] .= html_print_input_text_extended( + 'created_to', + '', + 'created_to', + '', + 12, + 50, + false, + '', + 'style="margin-left:5px;" placeholder="'.__('Created to').'"', + true +); // TODO: image of Integria IMS. $table->data[2][4] = 'Imagen:'; $table->data[2][5] = 'IMAGEN'; +// Send filters to get_tickets_integriaims(). +$tickets_filters = [ + 'incident_text' => $incident_text, + 'incident_status' => $incident_status, + 'incident_group' => $incident_group, + 'incident_owner' => $incident_owner, + 'incident_creator' => $incident_creator, + 'incident_priority' => $incident_priority, + 'incident_resolution' => $incident_resolution, + 'incident_date' => $incident_date, +]; + +// Data to export to csv file. +$decode_csv = base64_encode(json_encode($tickets_filters)); + + +// ---- PRINT TABLE FILTERS ---- $integria_incidents_form = '
'; @@ -181,43 +228,6 @@ $integria_incidents_form .= ''; // ui_toggle($integria_incidents_form, __('Add Custom filter')); echo $integria_incidents_form; -// ---- LIST OF INCIDENTS ---- -$result_api_call_list = integria_api_call( - $config['integria_hostname'], - $config['integria_user'], - $config['integria_pass'], - $config['integria_api_pass'], - 'get_incidents', - [ - $incident_text, - $incident_status, - $incident_group, - $incident_priority, - '0', - $incident_owner, - $incident_creator, - ] -); -// 'get_incidents', ['', '0', '1', '-1', '0', 'admin', 'admin']); -// http://192.168.70.124/integria/include/api.php?user=admin&user_pass=integria&pass=1234&op=get_incidents¶ms=,0,1,-1 -$array_get_incidents = []; - -// Return array of api call 'get_incidents'. -get_array_from_csv_data_all($result_api_call_list, $array_get_incidents); - -// Modify $array_get_incidents if filter for resolution exists. -$filter_resolution = []; -foreach ($array_get_incidents as $key => $value) { - if ($incident_resolution !== '' && ($array_get_incidents[$key][12] == $incident_resolution)) { - $filter_resolution[$key] = $array_get_incidents[$key]; - continue; - } -} - -if ($incident_resolution !== '') { - $array_get_incidents = $filter_resolution; -} - /* * Order api call 'get_incidents'. * @@ -232,6 +242,10 @@ if ($incident_resolution !== '') { * */ +// ---- LIST OF INCIDENTS ---- +// Get list of incidents. +$array_get_incidents = get_tickets_integriaims($tickets_filters); + // Prepare pagination. $incidents_limit = $config['block_size']; $incidents_paginated = array_slice($array_get_incidents, $offset, $incidents_limit, true); @@ -273,7 +287,7 @@ foreach ($incidents_paginated as $key => $value) { $table->data[$i][4] = ui_print_integria_incident_priority($array_get_incidents[$key][7], $priority_incident[$array_get_incidents[$key][7]]); $table->data[$i][5] = $array_get_incidents[$key][9]; $table->data[$i][6] = $array_get_incidents[$key][10]; - $table->data[$i][7] = $array_get_incidents[$key][0]; + $table->data[$i][7] = $array_get_incidents[$key][5]; $table->data[$i][8] = ''; $table->cellclass[$i][8] = 'action_buttons'; if (check_acl($config['id_user'], 0, 'IW')) { @@ -301,7 +315,7 @@ ui_pagination(count($array_get_incidents), $url, $offset, 0, false, 'offset', tr if (check_acl($config['id_user'], 0, 'IR')) { echo ''; }