Skip to content

Commit c306c51

Browse files
committed
QA: Form Confirmation API for graph_templates.php
1 parent 589c4b2 commit c306c51

File tree

1 file changed

+20
-113
lines changed

1 file changed

+20
-113
lines changed

graph_templates.php

Lines changed: 20 additions & 113 deletions
Original file line numberDiff line numberDiff line change
@@ -368,8 +368,7 @@ function form_save() {
368368
$task_item_changed = true;
369369

370370
if (get_request_var('graph_template_item_id') > 0) {
371-
$task_item_id = db_fetch_cell_prepared(
372-
'SELECT task_item_id
371+
$task_item_id = db_fetch_cell_prepared('SELECT task_item_id
373372
FROM graph_templates_item
374373
WHERE id = ?',
375374
array(get_request_var('graph_template_item_id'))
@@ -474,8 +473,7 @@ function form_save() {
474473

475474
/* an input for the current data source does NOT currently exist, let's create one */
476475
if (!isset($orig_data_source_to_input[$save['task_item_id']])) {
477-
$ds_name = db_fetch_cell_prepared(
478-
'SELECT data_source_name
476+
$ds_name = db_fetch_cell_prepared('SELECT data_source_name
479477
FROM data_template_rrd
480478
WHERE id = ?',
481479
array(get_nfilter_request_var('task_item_id'))
@@ -490,8 +488,7 @@ function form_save() {
490488

491489
$graph_template_input_id = db_fetch_insert_id();
492490

493-
$graph_items = db_fetch_assoc_prepared(
494-
'SELECT id
491+
$graph_items = db_fetch_assoc_prepared('SELECT id
495492
FROM graph_templates_item
496493
WHERE graph_template_id = ?
497494
AND task_item_id = ?',
@@ -557,7 +554,13 @@ function form_save() {
557554
raise_message(1);
558555

559556
/* list all graph items from the db so we can compare them with the current form */
560-
$db_selected_graph_item = array_rekey(db_fetch_assoc_prepared('SELECT graph_template_item_id FROM graph_template_input_defs WHERE graph_template_input_id = ?', array($graph_template_input_id)), 'graph_template_item_id', 'graph_template_item_id');
557+
$db_selected_graph_item = array_rekey(
558+
db_fetch_assoc_prepared('SELECT graph_template_item_id
559+
FROM graph_template_input_defs
560+
WHERE graph_template_input_id = ?',
561+
array($graph_template_input_id)),
562+
'graph_template_item_id', 'graph_template_item_id'
563+
);
561564

562565
/* list all select graph items for use down below */
563566
foreach ($_POST as $var => $val) {
@@ -686,8 +689,7 @@ function item_remove() {
686689
db_execute_prepared('DELETE FROM graph_templates_item WHERE local_graph_template_item_id = ?', array(get_request_var('id')));
687690

688691
/* delete the graph item input if it is empty */
689-
$graph_item_inputs = db_fetch_assoc_prepared('SELECT
690-
graph_template_input.id
692+
$graph_item_inputs = db_fetch_assoc_prepared('SELECT graph_template_input.id
691693
FROM (graph_template_input, graph_template_input_defs)
692694
WHERE graph_template_input.id = graph_template_input_defs.graph_template_input_id
693695
AND graph_template_input.graph_template_id = ?
@@ -1033,7 +1035,7 @@ function form_actions() {
10331035
retemplate_graphs($selected_items[$i]);
10341036

10351037
$graph_template_name = db_fetch_cell_prepared('SELECT name
1036-
FROM graph_templates AS gt
1038+
FROM graph_templates
10371039
WHERE id = ?',
10381040
array($selected_items[$i]));
10391041

@@ -1154,98 +1156,6 @@ function form_actions() {
11541156

11551157
form_continue_confirmation($form_data);
11561158
}
1157-
exit;
1158-
1159-
top_header();
1160-
1161-
form_start('graph_templates.php');
1162-
1163-
html_start_box($actions[get_nfilter_request_var('drp_action')], '60%', '', '3', 'center', '');
1164-
1165-
if (isset($graph_array) && cacti_sizeof($graph_array)) {
1166-
if (get_request_var('drp_action') == '1') { // delete
1167-
print "<tr>
1168-
<td class='textArea'>
1169-
<p>" . __('Click \'Continue\' to delete the following Graph Template(s). Any Graph(s) associated with the Template(s) will become individual Graph(s).') . "</p>
1170-
<div class='itemlist'><ul>$graph_list</ul></div>
1171-
</td>
1172-
</tr>\n";
1173-
1174-
$save_html = "<input type='button' class='ui-button ui-corner-all ui-widget' value='" . __esc('Cancel') . "' onClick='cactiReturnTo()'>&nbsp;<input type='submit' class='ui-button ui-corner-all ui-widget' value='" . __esc('Continue') . "' title='" . __esc('Delete Graph Template(s)') . "'>";
1175-
} elseif (get_request_var('drp_action') == '2') { // duplicate
1176-
print "<tr>
1177-
<td class='textArea'>
1178-
<p>" . __('Click \'Continue\' to duplicate the following Graph Template(s). You can optionally change the title format for the new Graph Template(s).') . "</p>
1179-
<div class='itemlist'><ul>$graph_list</ul></div>
1180-
<p><strong>" . __('Title Format:'). '</strong><br>';
1181-
form_text_box('title_format', '<template_title> (1)', '', '255', '30', 'text');
1182-
print "</p>
1183-
</td>
1184-
</tr>\n";
1185-
1186-
$save_html = "<input type='button' class='ui-button ui-corner-all ui-widget' value='" . __esc('Cancel') . "' onClick='cactiReturnTo()'>&nbsp;<input type='submit' class='ui-button ui-corner-all ui-widget' value='" . __esc('Continue'). "' title='" . __esc('Duplicate Graph Template(s)') . "'>";
1187-
} elseif (get_request_var('drp_action') == '3') { // resize
1188-
print "<tr>
1189-
<td class='textArea'>
1190-
<p>" . __('Click \'Continue\' to resize the following Graph Template(s) and Graph(s) to the Height and Width below. The defaults below are maintained in Settings.') . "</p>
1191-
<div class='itemlist'><ul>$graph_list</ul></div>
1192-
</td>
1193-
</tr>
1194-
</table>
1195-
<table class='filterTable'>
1196-
<tr>
1197-
<td>";
1198-
1199-
print __('Graph Height') . '</td><td>';
1200-
form_text_box('graph_height', read_config_option('default_graph_height'), '', '5', '5', 'text');
1201-
print '</td></tr><tr><td>' . __('Graph Width') . '</td><td>';
1202-
form_text_box('graph_width', read_config_option('default_graph_width'), '', '5', '5', 'text');
1203-
print '</td></tr><tr><td>' . __('Image Format') . '</td><td>';
1204-
form_dropdown('image_format_id', $image_types, '', '', read_config_option('default_image_format'), '', '');
1205-
1206-
print "</td></tr></table><div class='break'></div><table style='width:100%'>\n";
1207-
1208-
$save_html = "<input type='button' class='ui-button ui-corner-all ui-widget' value='" . __esc('Cancel') . "' onClick='cactiReturnTo()'>&nbsp;<input type='submit' class='ui-button ui-corner-all ui-widget' value='" . __esc('Continue') . "' title='" . __esc('Resize Selected Graph Template(s)') . "'>";
1209-
} elseif (get_request_var('drp_action') == '4') { // retemplate
1210-
print "<tr>
1211-
<td class='textArea'>
1212-
<p>" . __('Click \'Continue\' to perform a Full Synchronization between your Graphs and the chosen Graph Templates(s). If you simply have a situation where the Graph Items don\'t match the Graph Template, try the Quick Sync Graphs option first as it will take much less time. This function is important if you have Graphs that exist with multiple versions of a Graph Template and wish to make them all common in appearance.') . "</p>
1213-
<div class='itemlist'><ul>$graph_list</ul></div>
1214-
</td>
1215-
</tr>\n";
1216-
1217-
$save_html = "<input type='button' class='ui-button ui-corner-all ui-widget' value='" . __esc('Cancel') . "' onClick='cactiReturnTo()'>&nbsp;<input type='submit' class='ui-button ui-corner-all ui-widget' value='" . __esc('Continue'). "' title='" . __esc('Synchronize Graphs to Graph Template(s)') . "'>";
1218-
} elseif (get_request_var('drp_action') == '5') { // retemplate only where sequences are off
1219-
print "<tr>
1220-
<td class='textArea'>
1221-
<p>" . __('Click \'Continue\' to perform a Quick Synchronization of your Graphs for the following Graph Template(s). Use this option if your Graphs have Graph Items that do not match your Graph Template. If this option does not work, use the Full Sync Graphs option, which will take more time to complete.') . "</p>
1222-
<div class='itemlist'><ul>$graph_list</ul></div>
1223-
</td>
1224-
</tr>\n";
1225-
1226-
$save_html = "<input type='button' class='ui-button ui-corner-all ui-widget' value='" . __esc('Cancel') . "' onClick='cactiReturnTo()'>&nbsp;<input type='submit' class='ui-button ui-corner-all ui-widget' value='" . __esc('Continue'). "' title='" . __esc('Synchronize Graphs to Graph Template(s)') . "'>";
1227-
}
1228-
} else {
1229-
raise_message(40);
1230-
header('Location: graph_templates.php');
1231-
1232-
exit;
1233-
}
1234-
1235-
print "<tr>
1236-
<td class='saveRow'>
1237-
<input type='hidden' name='action' value='actions'>
1238-
<input type='hidden' name='selected_items' value='" . (isset($graph_array) ? serialize($graph_array) : '') . "'>
1239-
<input type='hidden' name='drp_action' value='" . html_escape(get_nfilter_request_var('drp_action')) . "'>
1240-
$save_html
1241-
</td>
1242-
</tr>\n";
1243-
1244-
html_end_box();
1245-
1246-
form_end();
1247-
1248-
bottom_footer();
12491159
}
12501160

12511161
function item() {
@@ -1669,8 +1579,7 @@ function clearFilter() {
16691579
$sql_order = get_order_string();
16701580
$sql_limit = ' LIMIT ' . ($rows * (get_request_var('page') - 1)) . ',' . $rows;
16711581

1672-
$template_list = db_fetch_assoc("SELECT
1673-
gt.id, gt.name, gt.graphs,
1582+
$template_list = db_fetch_assoc("SELECT gt.id, gt.name, gt.graphs,
16741583
CONCAT(gtg.height, 'x', gtg.width) AS size, gtg.vertical_label, gtg.image_format_id
16751584
FROM graph_templates AS gt
16761585
INNER JOIN graph_templates_graph AS gtg
@@ -1824,13 +1733,9 @@ function input_edit() {
18241733

18251734
html_end_box(true, true);
18261735

1827-
$item_list = db_fetch_assoc_prepared("SELECT
1828-
CONCAT_WS(' - ', dtd.name, dtr.data_source_name) AS data_source_name,
1829-
gti.text_format,
1830-
gti.id AS graph_templates_item_id,
1831-
gti.graph_type_id,
1832-
gti.consolidation_function_id,
1833-
gtid.graph_template_input_id
1736+
$item_list = db_fetch_assoc_prepared("SELECT CONCAT_WS(' - ', dtd.name, dtr.data_source_name) AS data_source_name,
1737+
gti.text_format, gti.id AS graph_templates_item_id, gti.graph_type_id,
1738+
gti.consolidation_function_id, gtid.graph_template_input_id
18341739
FROM graph_templates_item AS gti
18351740
LEFT JOIN graph_template_input_defs AS gtid
18361741
ON gtid.graph_template_item_id = gti.id
@@ -1847,7 +1752,8 @@ function input_edit() {
18471752

18481753
html_start_box(__('Associated Graph Items'), '100%', false, '3', 'center', '');
18491754

1850-
$i = 0;
1755+
$i = 0;
1756+
18511757
$any_selected_item = '';
18521758

18531759
if (cacti_sizeof($item_list)) {
@@ -1857,7 +1763,8 @@ function input_edit() {
18571763
if ($item['graph_template_input_id'] == '') {
18581764
$old_value = '';
18591765
} else {
1860-
$old_value = 'on';
1766+
$old_value = 'on';
1767+
18611768
$any_selected_item = $item['graph_templates_item_id'];
18621769
}
18631770

0 commit comments

Comments
 (0)