Skip to content

Commit

Permalink
Fixing #4481 - Reports and Format Files
Browse files Browse the repository at this point in the history
When using a Cacti Format File for a Report, the Reports still use Legacy Font Size and Alignment Attributes
  • Loading branch information
TheWitness committed Nov 27, 2021
1 parent 5eee1a5 commit bfca170
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 31 deletions.
1 change: 1 addition & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Cacti CHANGELOG
-issue#4477: Remote pollers do not force connection when online
-issue#4479: As a repair tool, the rebuild poller cache scripts lacks critical options to reduce runtimes
-issue#4480: Saving a Data Template can damage Data Sources if the Data Template is not constructed properly
-issue#4481: When using a Cacti Format File for a Report, the Reports still use Legacy Font Size and Alignment Attributes

1.2.19
-security#4356: Further fixes for grave character security protection
Expand Down
54 changes: 38 additions & 16 deletions lib/html_reports.php
Original file line number Diff line number Diff line change
Expand Up @@ -1214,9 +1214,11 @@ function reports_edit() {
function changeFormat() {
if (cformat && cformat.checked) {
$('#row_font_size').hide();
$('#row_alignment').hide();
$('#row_format_file').show();
} else {
$('#row_font_size').show();
$('#row_alignment').show();
$('#row_format_file').hide();
}
}
Expand Down Expand Up @@ -1337,15 +1339,30 @@ function display_reports_items($report_id) {
switch ($item['item_type']) {
case REPORTS_ITEM_GRAPH:
$item_details = get_graph_title($item['local_graph_id']);
$align = ($item['align'] > 0 ? $alignment[$item['align']] : '');
$size = '';

if ($css == 'on') {
$align = __('Using CSS');
} else {
$align = ($item['align'] > 0 ? $alignment[$item['align']] : '');
}

$size = __('N/A');
$timespan = ($item['timespan'] > 0 ? $graph_timespans[$item['timespan']] : '');

break;
case REPORTS_ITEM_TEXT:
$item_details = $item['item_text'];
$align = ($item['align'] > 0 ? $alignment[$item['align']] : '');
$size = ($item['font_size'] > 0 ? $item['font_size'] : '');

if ($css == 'on') {
$align = __('Using CSS');
$size = __('Using CSS');
} else {
$align = ($item['align'] > 0 ? $alignment[$item['align']] : '');
$size = ($item['font_size'] > 0 ? $item['font_size'] : '');
}

$timespan = '';

break;
case REPORTS_ITEM_TREE:
if ($item['branch_id'] > 0) {
Expand Down Expand Up @@ -1382,19 +1399,23 @@ function display_reports_items($report_id) {
}
}

$align = ($item['align'] > 0 ? $alignment[$item['align']] : '');
$size = ($item['font_size'] > 0 ? $item['font_size'] : '');
if ($css == 'on') {
$align = __('Using CSS');
$size = __('Using CSS');
} else {
$align = ($item['align'] > 0 ? $alignment[$item['align']] : '');
$size = ($item['font_size'] > 0 ? $item['font_size'] : '');
}

$timespan = ($item['timespan'] > 0 ? $graph_timespans[$item['timespan']] : '');

break;
default:
$item_details = '';
$align = '';
$size = '';
$timespan = '';
}

if ($css == 'on') {
$size = '';
$align = __('N/A');
$size = __('N/A');
$timespan = __('N/A');
}

form_alternate_row('line' . $item['id'], false);
Expand All @@ -1407,14 +1428,15 @@ function display_reports_items($report_id) {
$form_data .= '<td>' . $size . '</td>';

if ($i == 1) {
$form_data .= '<td class="right nowrap"><a class="remover fa fa-caret-down moveArrow" title="' . __esc('Move Down') . '" href="' . html_escape(get_reports_page() . '?action=item_movedown&item_id=' . $item['id'] . '&id=' . $report_id) . '"></a>' . '<span class="moveArrowNone"</span></td>';
$form_data .= '<td class="right nowrap"><a class="pic remover fa fa-caret-down moveArrow" style="padding:3px" title="' . __esc('Move Down') . '" href="' . html_escape(get_reports_page() . '?action=item_movedown&item_id=' . $item['id'] . '&id=' . $report_id) . '"></a>' . '<span style="padding:5ps" class="moveArrowNone"></span>';
} elseif ($i > 1 && $i < cacti_sizeof($items)) {
$form_data .= '<td class="right nowrap"><a class="remover fa fa-caret-down moveArrow" title="' . __esc('Move Down') . '" href="' . html_escape(get_reports_page() . '?action=item_movedown&item_id=' . $item['id'] . '&id=' . $report_id) . '"></a>' . '<a class="remover fa fa-caret-up moveArrow" title="' . __esc('Move Up') . '" href="' . html_escape(get_reports_page() . '?action=item_moveup&item_id=' . $item['id'] . '&id=' . $report_id) . '"></a>' . '</td>';
$form_data .= '<td class="right nowrap"><a class="pic remover fa fa-caret-down moveArrow" style="padding:3px" title="' . __esc('Move Down') . '" href="' . html_escape(get_reports_page() . '?action=item_movedown&item_id=' . $item['id'] . '&id=' . $report_id) . '"></a>' . '<a class="remover fa fa-caret-up moveArrow" style="padding:3px" title="' . __esc('Move Up') . '" href="' . html_escape(get_reports_page() . '?action=item_moveup&item_id=' . $item['id'] . '&id=' . $report_id) . '"></a>';
} else {
$form_data .= '<td class="right nowrap"><span class="moveArrowNone"></span>' . '<a class="remover fa fa-caret-up moveArrow" title="' . __esc('Move Up') . '" href="' . html_escape(get_reports_page() . '?action=item_moveup&item_id=' . $item['id'] . '&id=' . $report_id) . '"></a>' . '</td>';
$form_data .= '<td class="right nowrap"><span style="padding:3px" class="moveArrowNone"></span>' . '<a class="remover fa fa-caret-up moveArrow" style="padding:3px" title="' . __esc('Move Up') . '" href="' . html_escape(get_reports_page() . '?action=item_moveup&item_id=' . $item['id'] . '&id=' . $report_id) . '"></a>';
}

$form_data .= '<td class="right"><a class="pic deleteMarker fa fa-times" href="' . html_escape(get_reports_page() . '?action=item_remove&item_id=' . $item['id'] . '&id=' . $report_id) . '" title="' . __esc('Delete') . '"></a>' . '</td></tr>';
$form_data .= '<a class="pic deleteMarker fa fa-times" style="padding:3px" href="' . html_escape(get_reports_page() . '?action=item_remove&item_id=' . $item['id'] . '&id=' . $report_id) . '" title="' . __esc('Delete') . '"></a>' . '</td></tr>';

print $form_data;

$i++;
Expand Down
45 changes: 30 additions & 15 deletions lib/reports.php
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,8 @@ function reports_load_format_file($format_file, &$output, &$report_tag_included,
if (file_exists($config['base_path'] . '/formats/' . $format_file)) {
$contents = file($config['base_path'] . '/formats/' . $format_file);
}
$output = '';

$output = '';
$report_tag_included = false;

if (cacti_sizeof($contents)) {
Expand Down Expand Up @@ -720,8 +721,9 @@ function reports_generate_html($reports_id, $output = REPORTS_OUTPUT_STDOUT, &$t
}

$outstr .= "\t\t<tr class='title_row'>" . PHP_EOL;

if ($format_ok) {
$outstr .= "\t\t\t<td class='title' style='text-align:" . $alignment[$report['alignment']] . ";'>" . PHP_EOL;
$outstr .= "\t\t\t<td class='title'>" . PHP_EOL;
} else {
$outstr .= "\t\t\t<td class='title' style='text-align:" . $alignment[$report['alignment']] . ";font-size:" . $report['font_size'] . "pt;'>" . PHP_EOL;
}
Expand Down Expand Up @@ -751,7 +753,11 @@ function reports_generate_html($reports_id, $output = REPORTS_OUTPUT_STDOUT, &$t

if ($column == 0) {
$outstr .= "\t\t<tr class='image_row'>" . PHP_EOL;
$outstr .= "\t\t\t<td style='text-align:" . $alignment[$item['align']] . ";'>" . PHP_EOL;
if ($format_ok) {
$outstr .= "\t\t\t<td>" . PHP_EOL;
} else {
$outstr .= "\t\t\t<td style='text-align:" . $alignment[$item['align']] . ";'>" . PHP_EOL;
}

if ($format_ok) {
$outstr .= "\t\t\t\t<table class='image_table'>" . PHP_EOL;
Expand All @@ -763,7 +769,7 @@ function reports_generate_html($reports_id, $output = REPORTS_OUTPUT_STDOUT, &$t
}

if ($format_ok) {
$outstr .= "\t\t\t\t\t\t<td class='image_column' style='text-align:" . $alignment[$item['align']] . ";'>" . PHP_EOL;
$outstr .= "\t\t\t\t\t\t<td class='image_column'>" . PHP_EOL;
} else {
$outstr .= "\t\t\t\t\t\t<td style='padding:5px;text-align:" . $alignment[$item['align']] . ";'>" . PHP_EOL;
}
Expand All @@ -784,11 +790,13 @@ function reports_generate_html($reports_id, $output = REPORTS_OUTPUT_STDOUT, &$t
}
} elseif ($item['item_type'] == REPORTS_ITEM_TEXT) {
$outstr .= "\t\t<tr class='text_row'>" . PHP_EOL;

if ($format_ok) {
$outstr .= "\t\t\t<td style='text-align:" . $alignment[$item['align']] . ";' class='text'>" . PHP_EOL;
$outstr .= "\t\t\t<td class='text'>" . PHP_EOL;
} else {
$outstr .= "\t\t\t<td style='text-align:" . $alignment[$item['align']] . ";font-size: " . $item['font_size'] . "pt;' class='text'>" . PHP_EOL;
}

$outstr .= "\t\t\t\t" . html_escape($item['item_text']) . PHP_EOL;
$outstr .= "\t\t\t</td>" . PHP_EOL;
$outstr .= "\t\t</tr>" . PHP_EOL;
Expand Down Expand Up @@ -1062,7 +1070,7 @@ function reports_expand_tree(&$report, $item, $parent, $output, $format_ok, $the
if ($title != '') {
$outstr .= "\t\t<tr class='text_row'>" . PHP_EOL;
if ($format_ok) {
$outstr .= "\t\t\t<td class='text' style='text-align:" . $alignment[$item['align']] . "'>" . PHP_EOL;
$outstr .= "\t\t\t<td class='text'>" . PHP_EOL;
} else {
$outstr .= "\t\t\t<td class='text' style='text-align:" . $alignment[$item['align']] . ";font-size: " . $item['font_size'] . "pt;'>" . PHP_EOL;
}
Expand Down Expand Up @@ -1103,7 +1111,7 @@ function reports_expand_tree(&$report, $item, $parent, $output, $format_ok, $the
if ($title != '') {
$outstr .= "\t\t<tr class='text_row'>" . PHP_EOL;
if ($format_ok) {
$outstr .= "\t\t\t<td class='text' style='text-align:" . $alignment[$item['align']] . ";'>" . PHP_EOL;
$outstr .= "\t\t\t<td class='text'>" . PHP_EOL;
} else {
$outstr .= "\t\t\t<td class='text' style='text-align:" . $alignment[$item['align']] . ";font-size: " . $item['font_size'] . "pt;'>" . PHP_EOL;
}
Expand Down Expand Up @@ -1183,7 +1191,7 @@ function reports_expand_tree(&$report, $item, $parent, $output, $format_ok, $the
$outstr .= "\t\t<tr class='text_row'>" . PHP_EOL;

if ($format_ok) {
$outstr .= "\t\t\t<td class='text' style='text-align:" . $alignment[$item['align']] . "';>" . PHP_EOL;
$outstr .= "\t\t\t<td class='text'>" . PHP_EOL;
} else {
$outstr .= "\t\t\t<td class='text' style='text-align:" . $alignment[$item['align']] . ";font-size: " . $item['font_size'] . "pt;'>" . PHP_EOL;
}
Expand Down Expand Up @@ -1249,7 +1257,7 @@ function reports_expand_tree(&$report, $item, $parent, $output, $format_ok, $the
if ($title != '') {
$outstr .= "\t\t<tr class='text_row'>" . PHP_EOL;
if ($format_ok) {
$outstr .= "\t\t\t<td class='text' style='text-align:" . $alignment[$item['align']] . ";'>" . PHP_EOL;
$outstr .= "\t\t\t<td class='text'>" . PHP_EOL;
} else {
$outstr .= "\t\t\t<td class='text' style='text-align:" . $alignment[$item['align']] . ";font-size: " . $item['font_size'] . "pt;'>" . PHP_EOL;
}
Expand All @@ -1262,7 +1270,7 @@ function reports_expand_tree(&$report, $item, $parent, $output, $format_ok, $the

$outstr .= "\t\t<tr class='text_row'>" . PHP_EOL;
if ($format_ok) {
$outstr .= "\t\t\t<td class='text' style='text-align:" . $alignment[$item['align']] . ";'><strong>" . __('Data Query:') . "</strong> " . $data_query['name'] . PHP_EOL;
$outstr .= "\t\t\t<td class='text'><strong>" . __('Data Query:') . "</strong> " . $data_query['name'] . PHP_EOL;
$outstr .= "\t\t\t</td>" . PHP_EOL;
$outstr .= "\t\t</tr>" . PHP_EOL;
} else {
Expand Down Expand Up @@ -1320,7 +1328,7 @@ function reports_expand_tree(&$report, $item, $parent, $output, $format_ok, $the
if ($title != '') {
$outstr .= "\t\t<tr class='text_row'>" . PHP_EOL;
if ($format_ok) {
$outstr .= "\t\t\t<td class='text' style='text-align:" . $alignment[$item['align']] . ";'>" . PHP_EOL;
$outstr .= "\t\t\t<td class='text'>" . PHP_EOL;
} else {
$outstr .= "\t\t\t<td class='text' style='text-align:" . $alignment[$item['align']] . ";font-size: " . $item['font_size'] . "pt;'>" . PHP_EOL;
}
Expand All @@ -1340,7 +1348,7 @@ function reports_expand_tree(&$report, $item, $parent, $output, $format_ok, $the
if ($title != '') {
$outstr .= "\t\t<tr class='text_row'>" . PHP_EOL;
if ($format_ok) {
$outstr .= "\t\t\t<td class='text' style='text-align:" . $alignment[$item['align']] . "'>" . PHP_EOL;
$outstr .= "\t\t\t<td class='text'>" . PHP_EOL;
} else {
$outstr .= "\t\t\t<td class='text' style='text-align:" . $alignment[$item['align']] . ";font-size: " . $item['font_size'] . "pt;'>" . PHP_EOL;
}
Expand Down Expand Up @@ -1390,13 +1398,20 @@ function reports_graph_area($graphs, &$report, $item, $timespan, $output, $forma

if ($column == 0) {
$outstr .= "\t\t<tr class='image_row'>" . PHP_EOL;
$outstr .= "\t\t\t<td style='text-align:" . $alignment[$item['align']] . ";'>" . PHP_EOL;
$outstr .= "\t\t\t\t<table style='width:100%;'>" . PHP_EOL;

if ($format_ok) {
$outstr .= "\t\t\t<td>" . PHP_EOL;
$outstr .= "\t\t\t\t<table>". PHP_EOL;
} else {
$outstr .= "\t\t\t<td style='text-align:" . $alignment[$item['align']] . ";'>" . PHP_EOL;
$outstr .= "\t\t\t\t<table style='width:100%;'>" . PHP_EOL;
}

$outstr .= "\t\t\t\t\t<tr>" . PHP_EOL;
}

if ($format_ok) {
$outstr .= "\t\t\t\t\t\t<td class='image_column' style='text-align:" . $alignment[$item['align']] . ";'>" . PHP_EOL;
$outstr .= "\t\t\t\t\t\t<td class='image_column'>" . PHP_EOL;
} else {
$outstr .= "\t\t\t\t\t\t<td style='padding:5px;text-align='" . $alignment[$item['align']] . ";'>" . PHP_EOL;
}
Expand Down

0 comments on commit bfca170

Please sign in to comment.