Added button for export to csv - #4642
This commit is contained in:
parent
f2a6dbb60e
commit
eb271a93eb
|
@ -5597,3 +5597,63 @@ function ui_print_integria_incident_priority($priority, $priority_label)
|
||||||
|
|
||||||
return $output;
|
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;
|
||||||
|
}
|
||||||
|
|
|
@ -3423,7 +3423,6 @@ function html_print_autocomplete_users_from_integria(
|
||||||
timeout: 10000,
|
timeout: 10000,
|
||||||
dataType: "json",
|
dataType: "json",
|
||||||
success: function (data) {
|
success: function (data) {
|
||||||
console.log(data);
|
|
||||||
temp = [];
|
temp = [];
|
||||||
$.each(data, function (id, module) {
|
$.each(data, function (id, module) {
|
||||||
temp.push({
|
temp.push({
|
||||||
|
|
|
@ -0,0 +1,138 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
// Pandora FMS - http://pandorafms.com
|
||||||
|
// ==================================================
|
||||||
|
// Copyright (c) 2005-2019 Artica Soluciones Tecnologicas
|
||||||
|
// Please see http://pandorafms.org for full contribution list
|
||||||
|
// This program 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 for version 2.
|
||||||
|
// This program 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.
|
||||||
|
// Load global vars
|
||||||
|
global $config;
|
||||||
|
|
||||||
|
require_once '../../include/config.php';
|
||||||
|
require_once '../../include/functions.php';
|
||||||
|
|
||||||
|
check_login();
|
||||||
|
|
||||||
|
if (! check_acl($config['id_user'], 0, 'IR') && ! check_acl($config['id_user'], 0, 'IW') && ! check_acl($config['id_user'], 0, 'IM')) {
|
||||||
|
// Doesn't have access to this page.
|
||||||
|
db_pandora_audit('ACL Violation', 'Trying to access IntegriaIMS ticket creation');
|
||||||
|
include 'general/noaccess.php';
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get status.
|
||||||
|
$status_api_call = integria_api_call($config['integria_hostname'], $config['integria_user'], $config['integria_pass'], $config['integria_api_pass'], 'get_incidents_status');
|
||||||
|
$status_incident = [];
|
||||||
|
get_array_from_csv_data_pair($status_api_call, $status_incident);
|
||||||
|
|
||||||
|
// Get group.
|
||||||
|
$group_api_call = integria_api_call($config['integria_hostname'], $config['integria_user'], $config['integria_pass'], $config['integria_api_pass'], 'get_groups');
|
||||||
|
$group_incident = [];
|
||||||
|
get_array_from_csv_data_pair($group_api_call, $group_incident);
|
||||||
|
|
||||||
|
// Get priority.
|
||||||
|
$priority_api_call = integria_api_call($config['integria_hostname'], $config['integria_user'], $config['integria_pass'], $config['integria_api_pass'], 'get_incident_priorities');
|
||||||
|
$priority_incident = [];
|
||||||
|
get_array_from_csv_data_pair($priority_api_call, $priority_incident);
|
||||||
|
|
||||||
|
// Get resolution.
|
||||||
|
$resolution_api_call = integria_api_call($config['integria_hostname'], $config['integria_user'], $config['integria_pass'], $config['integria_api_pass'], 'get_incidents_resolutions');
|
||||||
|
$resolution_incident = [];
|
||||||
|
get_array_from_csv_data_pair($resolution_api_call, $resolution_incident);
|
||||||
|
|
||||||
|
|
||||||
|
// Get data to export.
|
||||||
|
$tickets_filters = json_decode(
|
||||||
|
base64_decode(
|
||||||
|
get_parameter('tickets_filters', '')
|
||||||
|
),
|
||||||
|
true
|
||||||
|
);
|
||||||
|
|
||||||
|
$tickets_csv_array = get_tickets_integriaims($tickets_filters);
|
||||||
|
|
||||||
|
|
||||||
|
// Build a new array to show only the fields in the table.
|
||||||
|
$tickets_csv_array_filter = [];
|
||||||
|
foreach ($tickets_csv_array as $key => $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);
|
|
@ -40,7 +40,7 @@ if ($has_connection === false) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get parameters for filters.
|
// 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_status = (int) get_parameter('incident_status', 0);
|
||||||
$incident_group = (int) get_parameter('incident_group', 1);
|
$incident_group = (int) get_parameter('incident_group', 1);
|
||||||
$incident_owner = (string) get_parameter('incident_owner', '');
|
$incident_owner = (string) get_parameter('incident_owner', '');
|
||||||
|
@ -109,7 +109,7 @@ $table->cellspacing = '0';
|
||||||
$table->data = [];
|
$table->data = [];
|
||||||
|
|
||||||
$table->data[0][0] = __('Text filter');
|
$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][2] = __('Status');
|
||||||
$table->data[0][3] = html_print_select(
|
$table->data[0][3] = html_print_select(
|
||||||
|
@ -163,17 +163,64 @@ $table->data[2][1] = html_print_select(
|
||||||
|
|
||||||
// TODO: field type date.
|
// TODO: field type date.
|
||||||
$table->data[2][2] = __('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.
|
// TODO: image of Integria IMS.
|
||||||
$table->data[2][4] = 'Imagen:';
|
$table->data[2][4] = 'Imagen:';
|
||||||
$table->data[2][5] = '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 = '<form method="post" action="'.$url.'">';
|
$integria_incidents_form = '<form method="post" action="'.$url.'">';
|
||||||
$integria_incidents_form .= html_print_table($table, true);
|
$integria_incidents_form .= html_print_table($table, true);
|
||||||
$integria_incidents_form .= '<div style="width:100%; text-align:right;">';
|
$integria_incidents_form .= '<div style="width:100%; text-align:right;">';
|
||||||
$integria_incidents_form .= '<div style="float:right; margin-left: 5px;">'.html_print_submit_button(__('Export to CSV'), 'csv_button', false, 'class="sub next"', true).'</div>';
|
$integria_incidents_form .= '<div style="float:right; margin-left: 5px;">'.html_print_button(
|
||||||
|
__('Export to CSV'),
|
||||||
|
'csv_export',
|
||||||
|
false,
|
||||||
|
"location.href='operation/incidents/integriaims_export_csv.php?tickets_filters=$decode_csv'",
|
||||||
|
'class="sub next"',
|
||||||
|
true
|
||||||
|
).'</div>';
|
||||||
$integria_incidents_form .= '<div>'.html_print_submit_button(__('Filter'), 'filter_button', false, 'class="sub filter"', true).'</div>';
|
$integria_incidents_form .= '<div>'.html_print_submit_button(__('Filter'), 'filter_button', false, 'class="sub filter"', true).'</div>';
|
||||||
$integria_incidents_form .= '</div>';
|
$integria_incidents_form .= '</div>';
|
||||||
$integria_incidents_form .= '</form>';
|
$integria_incidents_form .= '</form>';
|
||||||
|
@ -181,43 +228,6 @@ $integria_incidents_form .= '</form>';
|
||||||
// ui_toggle($integria_incidents_form, __('Add Custom filter'));
|
// ui_toggle($integria_incidents_form, __('Add Custom filter'));
|
||||||
echo $integria_incidents_form;
|
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'.
|
* 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.
|
// Prepare pagination.
|
||||||
$incidents_limit = $config['block_size'];
|
$incidents_limit = $config['block_size'];
|
||||||
$incidents_paginated = array_slice($array_get_incidents, $offset, $incidents_limit, true);
|
$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][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][5] = $array_get_incidents[$key][9];
|
||||||
$table->data[$i][6] = $array_get_incidents[$key][10];
|
$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->data[$i][8] = '';
|
||||||
$table->cellclass[$i][8] = 'action_buttons';
|
$table->cellclass[$i][8] = 'action_buttons';
|
||||||
if (check_acl($config['id_user'], 0, 'IW')) {
|
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')) {
|
if (check_acl($config['id_user'], 0, 'IR')) {
|
||||||
echo '<form method="POST" action="'.ui_get_full_url('index.php?sec=incident&sec2=operation/incidents/configure_integriaims_incident').'">';
|
echo '<form method="POST" action="'.ui_get_full_url('index.php?sec=incident&sec2=operation/incidents/configure_integriaims_incident').'">';
|
||||||
echo '<div style="width: 100%; text-align:right;">';
|
echo '<div style="width: 100%; text-align:right;">';
|
||||||
html_print_submit_button(__('Create'), 'create_new_incident', false, 'class="sub wand"');
|
html_print_submit_button(__('Create'), 'create_new_incident', false, 'class="sub next"');
|
||||||
echo '</div>';
|
echo '</div>';
|
||||||
echo '</form>';
|
echo '</form>';
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue