Fixed missed buttons, improve code and added go back button when create-update

This commit is contained in:
Jose Gonzalez 2021-06-03 15:37:11 +02:00
parent 5040b4b265
commit 08c945d91d
3 changed files with 82 additions and 42 deletions

View File

@ -73,7 +73,7 @@ if (! check_acl($config['id_user'], 0, 'RW')
exit; exit;
} }
if ($edit_graph) { if ($edit_graph === true) {
$graphInTgraph = db_get_row_sql( $graphInTgraph = db_get_row_sql(
'SELECT * FROM tgraph WHERE id_graph = '.$id_graph 'SELECT * FROM tgraph WHERE id_graph = '.$id_graph
); );
@ -113,18 +113,18 @@ if ($edit_graph) {
// ----------------------- // -----------------------
// CREATE/EDIT GRAPH FORM // CREATE/EDIT GRAPH FORM
// ----------------------- // -----------------------
$url = 'index.php?sec=reporting&sec2=godmode/reporting/graph_builder'; $url = 'index.php?sec=reporting&sec2=godmode/reporting/graph_builder&edit_graph=1';
if ($edit_graph) { if ($edit_graph === true) {
$output = "<form method='post' action='".$url.'&edit_graph=1&update_graph=1&id='.$id_graph."'>"; $output = "<form method='post' action='".$url.'&update_graph=1&id='.$id_graph."'>";
} else { } else {
$output = "<form method='post' action='".$url."&edit_graph=1&add_graph=1'>"; $output = "<form method='post' action='".$url."&add_graph=1'>";
} }
$output .= "<table width='100%' cellpadding=4 cellspacing=4 class='databox filters'>"; $output .= "<table width='100%' cellpadding=4 cellspacing=4 class='databox filters'>";
$output .= '<tr>'; $output .= '<tr>';
$output .= "<td class='datos'><b>".__('Name').'</b></td>'; $output .= "<td class='datos'><b>".__('Name').'</b></td>';
$output .= "<td class='datos'><input type='text' name='name' size='25' "; $output .= "<td class='datos'><input type='text' name='name' size='25' ";
if ($edit_graph) { if ($edit_graph === true) {
$output .= "value='".$graphInTgraph['name']."' "; $output .= "value='".$graphInTgraph['name']."' ";
} }
@ -179,7 +179,7 @@ $output .= '</td></tr>';
$output .= '<tr>'; $output .= '<tr>';
$output .= "<td class='datos2'><b>".__('Description').'</b></td>'; $output .= "<td class='datos2'><b>".__('Description').'</b></td>';
$output .= "<td class='datos2' colspan=3><textarea name='description' class='height_45px' cols=55 rows=2>"; $output .= "<td class='datos2' colspan=3><textarea name='description' class='height_45px' cols=55 rows=2>";
if ($edit_graph) { if ($edit_graph === true) {
$output .= $graphInTgraph['description']; $output .= $graphInTgraph['description'];
} }
@ -291,15 +291,30 @@ $output .= '</tr>';
$output .= '</table>'; $output .= '</table>';
if ($edit_graph) { $stringButton = ($edit_graph === true) ? __('Update') : __('Create');
$output .= "<div class='w100p'>";
$output .= "<input type=submit name='store' class='sub upd right' value='".__('Update')."'>"; $output .= html_print_div(
$output .= '</div>'; [
} else { 'class' => 'w100p',
$output .= "<div class='w100p'>"; 'content' => "<input type=submit name='store' class='sub next right databox' value='".$stringButton."'>",
$output .= "<input type=submit name='store' class='sub next right' value='".__('Create')."'>"; ],
$output .= '</div>'; true
} );
$output .= html_print_div(
[
'class' => 'w100p',
'content' => html_print_button(
__('Go back'),
'go_back',
false,
'window.location.href = \'index.php?sec=reporting&sec2=godmode/reporting/graphs\'',
'class="sub cancel right"',
true
),
],
true
);
$output .= '</form>'; $output .= '</form>';

View File

@ -109,7 +109,7 @@ if ($id_graph !== 0) {
} }
if ($add_graph) { if ($add_graph === true) {
$name = get_parameter_post('name'); $name = get_parameter_post('name');
$description = get_parameter_post('description'); $description = get_parameter_post('description');
$module_number = get_parameter_post('module_number'); $module_number = get_parameter_post('module_number');
@ -178,7 +178,7 @@ if ($update_graph) {
$stacked = $threshold; $stacked = $threshold;
} }
if (trim($name) != '') { if (empty(trim($name)) === false) {
$success = db_process_sql_update( $success = db_process_sql_update(
'tgraph', 'tgraph',
[ [
@ -220,7 +220,7 @@ function add_quotes($item)
} }
if ($add_module) { if ($add_module === true) {
$id_graph = get_parameter('id'); $id_graph = get_parameter('id');
$id_modules = get_parameter('module'); $id_modules = get_parameter('module');
$id_agents = get_parameter('id_agents'); $id_agents = get_parameter('id_agents');
@ -251,7 +251,7 @@ if ($add_module) {
} }
} }
if ($delete_module) { if ($delete_module === true) {
$id_graph = get_parameter('id'); $id_graph = get_parameter('id');
$deleteGraph = get_parameter('delete'); $deleteGraph = get_parameter('delete');
@ -260,7 +260,7 @@ if ($delete_module) {
db_process_sql('UPDATE tgraph_source SET field_order=field_order-1 WHERE id_graph='.$id_graph.' AND field_order>'.$order_val); db_process_sql('UPDATE tgraph_source SET field_order=field_order-1 WHERE id_graph='.$id_graph.' AND field_order>'.$order_val);
} }
if ($change_weight) { if ($change_weight === true) {
$weight = get_parameter('weight'); $weight = get_parameter('weight');
$id_gs = get_parameter('graph'); $id_gs = get_parameter('graph');
db_process_sql_update( db_process_sql_update(
@ -280,7 +280,7 @@ if ($change_label) {
); );
} }
if ($edit_graph) { if ($edit_graph === true) {
$buttons = [ $buttons = [
'graph_list' => [ 'graph_list' => [
'active' => false, 'active' => false,
@ -334,7 +334,7 @@ if ($edit_graph) {
$graphInTgraph = db_get_row_sql('SELECT name FROM tgraph WHERE id_graph = '.$id_graph); $graphInTgraph = db_get_row_sql('SELECT name FROM tgraph WHERE id_graph = '.$id_graph);
$name = $graphInTgraph['name']; $name = $graphInTgraph['name'];
} else { } else {
$buttons = ''; $buttons = [];
} }
$head = __('Graph builder'); $head = __('Graph builder');
@ -363,7 +363,7 @@ ui_print_standard_header(
false, false,
$headerHelp, $headerHelp,
false, false,
[$buttons], $buttons,
[ [
[ [
'link' => '', 'link' => '',
@ -410,12 +410,12 @@ if ($delete_module) {
// Parse CHUNK information into showable information. // Parse CHUNK information into showable information.
// Split id to get all parameters. // Split id to get all parameters.
if (!$delete_module) { if ($delete_module === false) {
if (isset($_POST['period'])) { if (isset($_POST['period']) === true) {
$period = $_POST['period']; $period = $_POST['period'];
} }
if ((isset($chunkdata) ) && ($chunkdata != '')) { if ((isset($chunkdata) === true) && (empty($chunkdata) === false)) {
$module_array = []; $module_array = [];
$weight_array = []; $weight_array = [];
$agent_array = []; $agent_array = [];

View File

@ -1,17 +1,32 @@
<?php <?php
/**
* Graph viewer.
*
* @category Reporting
* @package Pandora FMS
* @subpackage Community
* @version 1.0.0
* @license See below
*
* ______ ___ _______ _______ ________
* | __ \.-----.--.--.--| |.-----.----.-----. | ___| | | __|
* | __/| _ | | _ || _ | _| _ | | ___| |__ |
* |___| |___._|__|__|_____||_____|__| |___._| |___| |__|_|__|_______|
*
* ============================================================================
* Copyright (c) 2005-2021 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.
* ============================================================================
*/
// Pandora FMS - http://pandorafms.com // Begin.
// ==================================================
// Copyright (c) 2005-2021 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.
// Login check
global $config; global $config;
check_login(); check_login();
@ -231,14 +246,24 @@ if ($view_graph) {
]; ];
} }
// Header // Header.
ui_print_page_header( ui_print_standard_header(
$graph['name'], $graph['name'],
'images/chart.png', 'images/chart.png',
false, false,
'', '',
false, false,
$options $options,
[
[
'link' => '',
'label' => __('Reporting'),
],
[
'link' => '',
'label' => __('Custom graphs'),
],
]
); );
$width = null; $width = null;