From ec78e2530e4407b8d6330993463b082a4344700f Mon Sep 17 00:00:00 2001 From: TheWitness Date: Mon, 20 Nov 2023 08:56:06 -0500 Subject: [PATCH] QA: Additional Fixes for #5555 --- aggregate_graphs.php | 4 ++-- aggregate_templates.php | 4 ++-- lib/api_aggregate.php | 21 +++++++++++++++------ 3 files changed, 19 insertions(+), 10 deletions(-) diff --git a/aggregate_graphs.php b/aggregate_graphs.php index 5145856675..02d502ffd2 100644 --- a/aggregate_graphs.php +++ b/aggregate_graphs.php @@ -1016,11 +1016,11 @@ function changeTotals() { function changeTotalsType() { if ($('#total_type').val() == ) { - if ($('#total_prefix').val() == '') { + if ($('#total_prefix').val() == '' && $('#id').val() == 0) { $('#total_prefix').attr('value', ''); } } else if ($('#total_type').val() == ) { - if ($('#total_prefix').val() == '') { + if ($('#total_prefix').val() == '' && $('#id').val() == 0) { $('#total_prefix').attr('value', ''); } } diff --git a/aggregate_templates.php b/aggregate_templates.php index dca2a24547..eb9d512320 100644 --- a/aggregate_templates.php +++ b/aggregate_templates.php @@ -518,11 +518,11 @@ function changeTotals() { function changeTotalsType() { if ($('#total_type').val() == ) { - if ($('#total_prefix').val() == '') { + if ($('#total_prefix').val() == '' && $('#id').val() == 0) { $('#total_prefix').attr('value', ''); } } else if ($('#total_type').val() == ) { - if ($('#total_prefix').val() == '') { + if ($('#total_prefix').val() == '' && $('#id').val() == 0) { $('#total_prefix').attr('value', ''); } } diff --git a/lib/api_aggregate.php b/lib/api_aggregate.php index 4e2a470617..6caa7dc8c8 100644 --- a/lib/api_aggregate.php +++ b/lib/api_aggregate.php @@ -1320,12 +1320,19 @@ function aggregate_handle_ptile_type($member_graphs, $skipped_items, $local_grap static $special_comments = null; static $special_hrules = null; + if (cacti_sizeof($member_graphs)) { + $template_graph[] = $member_graphs[0]; + } else { + $template_graph = array(); + } + $comments_hrules = db_fetch_assoc('SELECT * FROM graph_templates_item WHERE graph_type_id IN(' . GRAPH_ITEM_TYPE_COMMENT . ',' . GRAPH_ITEM_TYPE_HRULE . ')' . - (cacti_sizeof($member_graphs) ? ' AND ' . array_to_sql_or($member_graphs, 'local_graph_id'):'') . + (cacti_sizeof($template_graph) ? ' AND ' . array_to_sql_or($template_graph, 'local_graph_id'):'') . (cacti_sizeof($skipped_items) ? ' AND local_graph_id NOT IN(' . implode(',', $skipped_items) . ')':'') . ' - ORDER BY graph_type_id DESC'); + AND (text_format != "" || value != "") + ORDER BY local_graph_id, sequence ASC'); $next_item_sequence = db_fetch_cell_prepared('SELECT MAX(sequence) FROM graph_templates_item @@ -1456,10 +1463,12 @@ function aggregate_handle_ptile_type($member_graphs, $skipped_items, $local_grap } } - // add an empty line before nth percentile - db_execute_prepared("INSERT INTO graph_templates_item - (local_graph_id, graph_type_id, consolidation_function_id, text_format, value, hard_return, gprint_id, sequence) - VALUES (?, 1, 1, '', '', 'on', 2, ?)", array($local_graph_id, $next_item_sequence++)); + // add an empty line before nth percentile for the first item only + if (cacti_sizeof($special_hrules) == 1) { + db_execute_prepared("INSERT INTO graph_templates_item + (local_graph_id, graph_type_id, consolidation_function_id, text_format, value, hard_return, gprint_id, sequence) + VALUES (?, 1, 1, '', '', 'on', 2, ?)", array($local_graph_id, $next_item_sequence++)); + } db_execute_prepared("INSERT INTO graph_templates_item (local_graph_id, graph_type_id, color_id, consolidation_function_id, text_format, value, hard_return, gprint_id, sequence)