Skip to content

Commit

Permalink
QA: Moving more pages to the Filter Class
Browse files Browse the repository at this point in the history
* There are just a few more easy ones.  Looking at a few more class improvements too.
  • Loading branch information
TheWitness committed Dec 17, 2024
1 parent d76ff9c commit a3a8d7a
Show file tree
Hide file tree
Showing 12 changed files with 62 additions and 1,182 deletions.
103 changes: 6 additions & 97 deletions aggregate_templates.php
Original file line number Diff line number Diff line change
Expand Up @@ -540,110 +540,19 @@ function changeTotalsType() {
function aggregate_template() {
global $actions, $item_rows, $config;

/* ================= input validation and session storage ================= */
$filters = array(
'rows' => array(
'filter' => FILTER_VALIDATE_INT,
'pageset' => true,
'default' => '-1'
),
'page' => array(
'filter' => FILTER_VALIDATE_INT,
'default' => '1'
),
'filter' => array(
'filter' => FILTER_DEFAULT,
'pageset' => true,
'default' => ''
),
'sort_column' => array(
'filter' => FILTER_CALLBACK,
'default' => 'pgt.name',
'options' => array('options' => 'sanitize_search_string')
),
'sort_direction' => array(
'filter' => FILTER_CALLBACK,
'default' => 'ASC',
'options' => array('options' => 'sanitize_search_string')
),
'has_graphs' => array(
'filter' => FILTER_VALIDATE_REGEXP,
'options' => array('options' => array('regexp' => '(true|false)')),
'pageset' => true,
'default' => read_config_option('default_has') == 'on' ? 'true' : 'false'
)
);
/* create the page filter */
$pageFilter = new CactiTableFilter(__('Aggregate Templates'), 'aggregate_templates.php', 'forms', 'sess_agg_tmp', 'aggregate_templates.php?action=edit');

validate_store_request_vars($filters, 'sess_agg_tmp');
/* ================= input validation ================= */
$pageFilter->rows_label = __('Templates');
$pageFilter->set_sort_array('pgt.name', 'ASC');
$pageFilter->render();

if (get_request_var('rows') == '-1') {
$rows = read_config_option('num_rows_table');
} else {
$rows = get_request_var('rows');
}

html_filter_start_box(__('Aggregate Templates'), 'aggregate_templates.php?action=edit');

$filter_html = '<tr class="even">
<td>
<form id="forms">
<table class="filterTable">
<tr>
<td>
' . __('Search') . '
</td>
<td>
<input type="text" class="ui-state-default ui-corner-all" id="filter" size="25" value="' . html_escape_request_var('filter') . '">
</td>
<td>
' . __('Templates') . '
</td>
<td>
<select id="rows" onChange="applyFilter()" data-defaultLabel="' . __('Templates') . '">
<option value="-1" ';

if (get_request_var('rows') == '-1') {
$filter_html .= 'selected';
}

$filter_html .= '>' . __('Default') . '</option>';

if (cacti_sizeof($item_rows)) {
foreach ($item_rows as $key => $value) {
$filter_html .= "<option value='" . $key . "'";

if (get_request_var('rows') == $key) {
$filter_html .= ' selected';
}
$filter_html .= '>' . $value . "</option>\n";
}
}

$filter_html .= '</select>
</td>
<td>
<span>
<input type="checkbox" id="has_graphs" ' . (get_request_var('has_graphs') == 'true' ? 'checked' : '') . ' onChange="applyFilter()">
<label for="has_graphs">' . __('Has Graphs') . '</label>
</span>
</td>
<td>
<span>
<input type="submit" class="ui-button ui-corner-all ui-widget" value="' . __esc('Go') . '" id="go">
<input type="button" class="ui-button ui-corner-all ui-widget" value="' . __esc('Clear') . '" id="clear">
</span>
</td>
</tr>
</table>
</form>
</td>
</tr>';

print $filter_html;

html_end_box();

/* form the 'where' clause for our main sql query */
$sql_where = '';

Expand Down Expand Up @@ -691,7 +600,7 @@ function aggregate_template() {
'align' => 'right',
'tip' => __('Aggregate Templates that are in use can not be Deleted. In use is defined as being referenced by an Aggregate.')
),
'graphs.graphs' => array(
'nosort1' => array(
'display' => __('Graphs Using'),
'align' => 'right',
'sort' => 'DESC'
Expand Down
115 changes: 5 additions & 110 deletions automation_snmp.php
Original file line number Diff line number Diff line change
Expand Up @@ -878,124 +878,19 @@ function automation_snmp_edit() {
function automation_snmp() {
global $config, $item_rows, $actions;

/* ================= input validation and session storage ================= */
$filters = array(
'rows' => array(
'filter' => FILTER_VALIDATE_INT,
'pageset' => true,
'default' => '-1'
),
'page' => array(
'filter' => FILTER_VALIDATE_INT,
'default' => '1'
),
'filter' => array(
'filter' => FILTER_DEFAULT,
'pageset' => true,
'default' => ''
),
'sort_column' => array(
'filter' => FILTER_CALLBACK,
'default' => 'name',
'options' => array('options' => 'sanitize_search_string')
),
'sort_direction' => array(
'filter' => FILTER_CALLBACK,
'default' => 'ASC',
'options' => array('options' => 'sanitize_search_string')
)
);
/* create the page filter */
$pageFilter = new CactiTableFilter(__('SNMP Options'), 'automation_snmp.php', 'snmp_form', 'sess_autom_snmp', 'automation_snmp.php?action=edit');

validate_store_request_vars($filters, 'sess_autom_snmp');
$pageFilter->rows_label = __('Rules');
$pageFilter->has_import = true;
$pageFilter->render();

if (get_request_var('rows') == -1) {
$rows = read_config_option('num_rows_table');
} else {
$rows = get_request_var('rows');
}

html_filter_start_box(__('SNMP Options'), 'automation_snmp.php?action=edit');

?>
<tr class='even'>
<td>
<form id='snmp_form'>
<table class='filterTable'>
<tr>
<td>
<?php print __('Search');?>
</td>
<td>
<input type='text' class='ui-state-default ui-corner-all' id='filter' size='25' value='<?php print html_escape_request_var('filter');?>'>
</td>
<td>
<?php print __('SNMP Rules');?>
</td>
<td>
<select id='rows' onChange='applyFilter()' data-defaultLabel='<?php print __('SNMP Rules');?>'>
<option value='-1'<?php print(get_request_var('rows') == '-1' ? ' selected>':'>') . __('Default');?></option>
<?php
if (cacti_sizeof($item_rows)) {
foreach ($item_rows as $key => $value) {
print "<option value='" . $key . "'" . (get_request_var('rows') == $key ? ' selected':'') . '>' . html_escape($value) . '</option>';
}
}
?>
</select>
</td>
<td>
<span>
<input type='button' class='ui-button ui-corner-all ui-widget' id='refresh' value='<?php print __esc('Go');?>' title='<?php print __esc('Set/Refresh Filters');?>'>
<input type='button' class='ui-button ui-corner-all ui-widget' id='clear' value='<?php print __esc('Clear');?>' title='<?php print __esc('Clear Filters');?>'>
<input type='button' class='ui-button ui-corner-all ui-widget' id='import' value='<?php print __esc('Import');?>' title='<?php print __esc('Import SNMP Options');?>'>
</span>
</td>
</tr>
</table>
</form>
</td>
</tr>
<script type='text/javascript'>
function applyFilter() {
strURL = 'automation_snmp.php';
strURL += '?filter='+$('#filter').val();
strURL += '&rows='+$('#rows').val();
loadUrl({url:strURL})
}

function clearFilter() {
strURL = 'automation_snmp.php?clear=1';
loadUrl({url:strURL})
}

function importTemplate() {
strURL = 'automation_snmp.php?action=import';
loadUrl({url:strURL})
}

$(function() {
$('#refresh').click(function() {
applyFilter();
});

$('#clear').click(function() {
clearFilter();
});

$('#import').click(function() {
importTemplate();
});

$('#snmp_form').submit(function(event) {
event.preventDefault();
applyFilter();
});
});
</script>
<?php

html_end_box();

/* form the 'where' clause for our main sql query */
if (get_request_var('filter') != '') {
$sql_where = 'WHERE asnmp.name LIKE ' . db_qstr('%' . get_request_var('filter') . '%');
Expand Down
111 changes: 5 additions & 106 deletions automation_templates.php
Original file line number Diff line number Diff line change
Expand Up @@ -1547,120 +1547,19 @@ function template() {

automation_update_hashes();

/* ================= input validation and session storage ================= */
$filters = array(
'rows' => array(
'filter' => FILTER_VALIDATE_INT,
'pageset' => true,
'default' => '-1'
),
'page' => array(
'filter' => FILTER_VALIDATE_INT,
'default' => '1'
),
'filter' => array(
'filter' => FILTER_DEFAULT,
'pageset' => true,
'default' => ''
)
);
/* create the page filter */
$pageFilter = new CactiTableFilter(__('Device Rules'), 'automation_templates.php', 'snmp_at', 'sess_autot', 'automation_templates.php?action=edit');

validate_store_request_vars($filters, 'sess_autot');
/* ================= input validation ================= */
$pageFilter->rows_label = __('Templates');
$pageFilter->has_import = true;
$pageFilter->render();

if (get_request_var('rows') == '-1') {
$rows = read_config_option('num_rows_table');
} else {
$rows = get_request_var('rows');
}

html_filter_start_box(__('Device Rules'), 'automation_templates.php?action=edit');

?>
<tr class='even'>
<td>
<form id='form_at' action='automation_templates.php'>
<table class='filterTable'>
<tr>
<td>
<?php print __('Search');?>
</td>
<td>
<input type='text' class='ui-state-default ui-corner-all' id='filter' size='25' value='<?php print html_escape_request_var('filter');?>'>
</td>
<td>
<?php print __('Templates');?>
</td>
<td>
<select id='rows' onChange='applyFilter()' data-defaultLabel='<?php print __('Templates');?>'>
<option value='-1'<?php print(get_request_var('rows') == '-1' ? ' selected>':'>') . __('Default');?></option>
<?php
if (cacti_sizeof($item_rows)) {
foreach ($item_rows as $key => $value) {
print "<option value='" . $key . "'";

if (get_request_var('rows') == $key) {
print ' selected';
} print '>' . html_escape($value) . '</option>';
}
}
?>
</select>
</td>
<td>
<span>
<input type='button' class='ui-button ui-corner-all ui-widget' id='refresh' value='<?php print __esc('Go');?>' title='<?php print __esc('Set/Refresh Filters');?>'>
<input type='button' class='ui-button ui-corner-all ui-widget' id='clear' value='<?php print __esc('Clear');?>' title='<?php print __esc('Clear Filters');?>'>
<input type='button' class='ui-button ui-corner-all ui-widget' id='import' value='<?php print __esc('Import');?>' title='<?php print __esc('Import Device Rules');?>'>
</span>
</td>
</tr>
</table>
</form>
<script type='text/javascript'>
function applyFilter() {
strURL = 'automation_templates.php' +
'?filter=' + $('#filter').val() +
'&rows=' + $('#rows').val() +
'&has_graphs=' + $('#has_graphs').is(':checked');
loadUrl({url:strURL})
}

function clearFilter() {
strURL = 'automation_templates.php?clear=1';
loadUrl({url:strURL})
}

function importTemplate() {
strURL = 'automation_templates.php?action=import';
loadUrl({url:strURL})
}

$(function() {
$('#refresh').click(function() {
applyFilter();
});

$('#clear').click(function() {
clearFilter();
});

$('#import').click(function() {
importTemplate();
});

$('#form_at').submit(function(event) {
event.preventDefault();
applyFilter();
});
});
</script>
</td>
</tr>
<?php

html_end_box();

/* form the 'where' clause for our main sql query */
if (get_request_var('filter') != '') {
$sql_where = 'WHERE (name LIKE ' . db_qstr('%' . get_request_var('filter') . '%') . ' OR ' .
Expand Down
Loading

0 comments on commit a3a8d7a

Please sign in to comment.