Adding tabs and new functions - #4644

This commit is contained in:
Tatiana Llorente 2019-09-23 13:14:20 +02:00
parent be3de8dcfb
commit f9a903319c
7 changed files with 214 additions and 107 deletions

View File

@ -5412,7 +5412,6 @@ function get_help_info($section_name)
break;
}
// hd($result);
return $result;
}
@ -5456,7 +5455,7 @@ if (!function_exists('getallheaders')) {
function integria_api_call($api_hostname, $user, $user_pass, $api_pass, $operation, $params_array=[], $show_credentials_error_msg=false)
{
$params_string = implode(',', $params_array);
hd($params_string, true);
$url_data = [
'user' => $user,
'user_pass' => $user_pass,

View File

@ -0,0 +1,145 @@
<?php
// Pandora FMS - http://pandorafms.com
// ==================================================
// Copyright (c) 2005-2009 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 Lesser General Public License
// as published by the Free Software Foundation; 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.
/**
* @package Include
* @subpackage Incidents
*/
global $config;
require_once $config['homedir'].'/include/functions_ui.php';
require_once $config['homedir'].'/include/functions_html.php';
require_once $config['homedir'].'/include/functions.php';
/**
* Show header tabs.
*
* @param string $active_tab Current tab or id_incident.
*
* @return html Print tabs in header.
*/
function integriaims_tabs($active_tab=false)
{
$url_tabs = ui_get_full_url('index.php?sec=incident&sec2=operation/incidents/');
$setup_tab['text'] = '<a href="'.ui_get_full_url('index.php?sec=general&sec2=godmode/setup/setup&section=integria').'">'.html_print_image('images/setup.png', true, ['title' => __('Configure Integria IMS')]).'</a>';
$list_tab['text'] = '<a href="'.$url_tabs.'list_integriaims_incidents">'.html_print_image('images/list.png', true, ['title' => __('List incidents')]).'</a>';
$create_tab['text'] = '<a href="'.$url_tabs.'configure_integriaims_incident">'.html_print_image('images/pencil.png', true, ['title' => __('New incident')]).'</a>';
if ($active_tab) {
switch ($active_tab) {
case 'setup_tab':
$setup_tab['active'] = true;
$list_tab['active'] = false;
$create_tab['active'] = false;
break;
case 'list_tab':
$setup_tab['active'] = false;
$list_tab['active'] = true;
$create_tab['active'] = false;
break;
case 'create_tab':
$setup_tab['active'] = false;
$list_tab['active'] = false;
$create_tab['active'] = true;
break;
case is_numeric($active_tab):
$create_tab['text'] = '<a href="'.$url_tabs.'configure_integriaims_incident&incident_id='.$active_tab.'">'.html_print_image('images/pencil.png', true, ['title' => __('Edit incident')]).'</a>';
$view_tab['text'] = '<a href="'.$url_tabs.'dashboard_detail_integriaims_incident&incident_id='.$active_tab.'">'.html_print_image('images/operation.png', true, ['title' => __('View incident')]).'</a>';
$setup_tab['active'] = false;
$list_tab['active'] = false;
$create_tab['active'] = false;
$view_tab['active'] = true;
break;
default:
$setup_tab['active'] = false;
$list_tab['active'] = false;
$create_tab['active'] = false;
break;
}
} else {
$setup_tab['active'] = false;
$list_tab['active'] = false;
$create_tab['active'] = false;
}
$onheader = [
'view' => $view_tab,
'configure' => $setup_tab,
'list' => $list_tab,
'create' => $create_tab,
];
return $onheader;
}
/**
* Gets all the details of Integria IMS API
*
* @param string $details Type of API call.
* @param number $detail_index Send index if you want return the text.
*
* @return string or array with result of API call.
*/
function integriaims_get_details($details, $detail_index=false)
{
global $config;
switch ($details) {
case 'status':
$operation = 'get_incidents_status';
break;
case 'group':
$operation = 'get_groups';
break;
case 'priority':
$operation = 'get_incident_priorities';
break;
case 'resolution':
$operation = 'get_incidents_resolutions';
break;
case 'type':
$operation = 'get_types';
break;
default:
// code...
break;
}
$api_call = integria_api_call($config['integria_hostname'], $config['integria_user'], $config['integria_pass'], $config['integria_api_pass'], $operation);
$result = [];
get_array_from_csv_data_pair($api_call, $result);
if ($detail_index !== false) {
if ($result[$detail_index] == '' || $result[$detail_index] === null) {
return __('None');
} else {
return $result[$detail_index];
}
} else {
return $result;
}
}

View File

@ -13,7 +13,7 @@ div.priority {
div.integria_details {
display: grid;
grid-column-gap: 10px;
grid-template-columns: repeat(3, 1fr);
grid-template-columns: repeat(3, minmax(min-content, auto));
grid-auto-rows: 1fr;
}
@ -47,11 +47,12 @@ div.integria_details_row_three {
div.integria_details_description {
width: 100%;
}
div.integria_details_description textarea {
width: 100%;
background-color: #fbfbfb;
border: 1px solid #cbcbcb;
border-radius: 3px;
padding: 5px 10px 5px 5px;
min-height: 100px;
resize: vertical;
}
.integriaims_details_box {

View File

@ -14,6 +14,8 @@
// Load global vars
global $config;
require_once 'include/functions_integriaims.php';
check_login();
if (!(check_acl($config['id_user'], 0, 'IW') && check_acl($config['id_user'], 0, 'IR'))) {
@ -25,10 +27,11 @@ if (!(check_acl($config['id_user'], 0, 'IW') && check_acl($config['id_user'], 0,
$update = (isset($_GET['incident_id']) === true);
$onheader = integriaims_tabs('create_tab');
if ($update) {
ui_print_page_header(__('Update Integria IMS Incident'), '', false, '', false, '');
ui_print_page_header(__('Update Integria IMS Incident'), '', false, '', false, $onheader);
} else {
ui_print_page_header(__('Create Integria IMS Incident'), '', false, '', false, '');
ui_print_page_header(__('Create Integria IMS Incident'), '', false, '', false, $onheader);
}
// Check if Integria integration enabled.

View File

@ -14,6 +14,8 @@
// Load global vars
global $config;
require_once 'include/functions_integriaims.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')) {
@ -58,7 +60,11 @@ get_array_from_csv_data_all($result_api_call_list, $array_get_incidents);
// Remove index (id)
$array_get_incidents = $array_get_incidents[$incident_id];
ui_print_page_header($array_get_incidents[3].__(' - Details'), '', false, '', false, '');
// Header tabs.
$onheader = integriaims_tabs($incident_id);
ui_print_page_header($array_get_incidents[3].' - '.__('Details'), '', false, '', false, $onheader);
// Data.
$status = $array_get_incidents[6];
@ -84,49 +90,11 @@ if ($closed_by == '') {
// API calls.
// 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);
if ($status_incident[$status] == '') {
$status_text = __('None');
} else {
$status_text = $status_incident[$status];
}
// 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);
$group_text = $group_incident[$group];
// 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);
$priority_text = $priority_incident[$priority];
// 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);
if ($resolution_incident[$resolution] == '') {
$resolution_text = __('None');
} else {
$resolution_text = $resolution_incident[$resolution];
}
// Get types.
$type_api_call = integria_api_call($config['integria_hostname'], $config['integria_user'], $config['integria_pass'], $config['integria_api_pass'], 'get_types');
$type_incident = [];
get_array_from_csv_data_pair($type_api_call, $type_incident);
if ($type_incident[$type] == '') {
$type_text = __('None');
} else {
$type_text = $type_incident[$type];
}
$status_text = integriaims_get_details('status', $status);
$group_text = integriaims_get_details('group', $group);
$priority_text = integriaims_get_details('priority', $priority);
$resolution_text = integriaims_get_details('resolution', $resolution);
$type_text = integriaims_get_details('type', $type);
// Details box.
@ -141,7 +109,7 @@ $details_box .= '
<div>'.html_print_image('images/heart.png', true).'</div>
<div>'.html_print_image('images/builder.png', true).'</div>
<div>'.html_print_image('images/user_green.png', true).'</div>
<div>'.ui_print_integria_incident_priority($priority, $priority_incident[$priority]).'</div>
<div>'.ui_print_integria_incident_priority($priority, $priority_text).'</div>
<div>'.html_print_image('images/incidents.png', true).'</div>';
$details_box .= '
<div>'.$status_text.'</div>
@ -194,7 +162,14 @@ echo '<div class="integria_details">';
echo '</div>';
// Show description.
$description_box = '<div class="integria_details_description">'.$description.'</div>';
$description_box = '<div class="integria_details_description">'.html_print_textarea(
'integria_details_description',
3,
0,
$description,
'disabled="disabled"',
true
).'</div>';
ui_toggle($description_box, __('Description'), '', '', false);
?>

View File

@ -16,6 +16,7 @@ global $config;
require_once '../../include/config.php';
require_once '../../include/functions.php';
require_once '../../include/functions_integriaims.php';
check_login();
@ -26,25 +27,12 @@ if (! check_acl($config['id_user'], 0, 'IR') && ! check_acl($config['id_user'],
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);
// API calls.
$status_incident = integriaims_get_details('status');
$group_incident = integriaims_get_details('group');
$priority_incident = integriaims_get_details('priority');
$resolution_incident = integriaims_get_details('resolution');
// Get data to export.
@ -82,26 +70,29 @@ foreach ($tickets_csv_array as $key => $value) {
}
$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],
'id_incidencia' => $tickets_csv_array[$key][0],
'titulo' => $tickets_csv_array[$key][3],
'id_grupo' => $tickets_csv_array[$key][8],
'estado' => $tickets_csv_array[$key][6],
'resolution' => $tickets_csv_array[$key][12],
'prioridad' => $tickets_csv_array[$key][7],
'actualizacion' => $tickets_csv_array[$key][9],
'inicio' => $tickets_csv_array[$key][1],
'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'),
__('Status'),
__('Resolution'),
__('Priority'),
__('Updated/Started'),
__('Updated'),
__('Started'),
__('Creator'),
__('Owner'),
];

View File

@ -14,6 +14,8 @@
// Load global vars
global $config;
require_once 'include/functions_integriaims.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')) {
@ -23,7 +25,9 @@ if (! check_acl($config['id_user'], 0, 'IR') && ! check_acl($config['id_user'],
exit;
}
ui_print_page_header(__('Integria IMS Incidents'), '', false, '', false, '');
// Header tabs.
$onheader = integriaims_tabs('list_tab');
ui_print_page_header(__('Integria IMS Incidents'), '', false, '', false, $onheader);
// Check if Integria integration enabled.
if ($config['integria_enabled'] == 0) {
@ -84,25 +88,11 @@ $url = ui_get_full_url(
// ---- FILTERS ----
// API calls to fill the filters.
// 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);
$status_incident = integriaims_get_details('status');
$group_incident = integriaims_get_details('group');
$priority_incident = integriaims_get_details('priority');
$resolution_incident = integriaims_get_details('resolution');
// 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);
// TABLE FILTERS.
$table = new StdClass();
@ -230,8 +220,7 @@ $integria_incidents_form .= '<div>'.html_print_submit_button(__('Filter'), 'filt
$integria_incidents_form .= '</div>';
$integria_incidents_form .= '</form>';
// ui_toggle($integria_incidents_form, __('Add Custom filter'));
echo $integria_incidents_form;
ui_toggle($integria_incidents_form, __('Add Custom filter'), '', '', false);
/*
* Order api call 'get_incidents'.
@ -315,8 +304,12 @@ foreach ($incidents_paginated as $key => $value) {
// Show table incidents.
ui_pagination(count($array_get_incidents), $url, $offset);
html_print_table($table);
ui_pagination(count($array_get_incidents), $url, $offset, 0, false, 'offset', true, 'pagination-bottom');
if (empty($table->data) === true) {
ui_print_info_message(['no_close' => true, 'message' => __('No incidents to show').'.' ]);
} else {
html_print_table($table);
ui_pagination(count($array_get_incidents), $url, $offset, 0, false, 'offset', true, 'pagination-bottom');
}
// Show button to create incident.
if (check_acl($config['id_user'], 0, 'IR')) {