示例#1
0
function templates()
{
    global $colors, $thold_actions, $item_rows;
    template_request_validation();
    ?>
	<script type="text/javascript">
	<!--
	function applyTHoldFilterChange(objForm) {
		strURL = '?rows=' + objForm.rows.value;
		strURL = strURL + '&filter=' + objForm.filter.value;
		document.location = strURL;
	}

	function importTemplate() {
		strURL = '?action=import';
		document.location = strURL;
	}
	-->
	</script>
	<?php 
    html_start_box('<strong>Threshold Templates</strong>', '100%', $colors['header'], '3', 'center', 'thold_templates.php?action=add');
    ?>
	<tr bgcolor='#<?php 
    print $colors["panel"];
    ?>
' class='noprint'>
		<td class='noprint'>
			<form name='listthold' action='thold_templates.php'>
			<table cellpadding='0' cellspacing='0'>
				<tr class='noprint'>
					<td width='20'>
						&nbsp;Search:&nbsp;
					</td>
					<td width='144'>
						<input type='text' name='filter' size='20' value='<?php 
    print $_REQUEST["filter"];
    ?>
'>
					</td>
					<td width='1'>
						&nbsp;Rows:&nbsp;
					</td>
					<td width='1'>
						<select name='rows' onChange='applyTHoldFilterChange(document.listthold)'>
							<option value='-1'<?php 
    if ($_REQUEST["rows"] == "-1") {
        ?>
 selected<?php 
    }
    ?>
>Default</option>
							<?php 
    if (sizeof($item_rows)) {
        foreach ($item_rows as $key => $value) {
            print "<option value='" . $key . "'";
            if ($_REQUEST["rows"] == $key) {
                print " selected";
            }
            print ">" . $value . "</option>\n";
        }
    }
    ?>
						</select>
					</td>
					<td width='1'>
						<input type="submit" value="Go">
					</td>
					<td width='1'>
						<input id="clear" name="clear" type="submit" value="Clear">
					</td>
					<td width='1'>
						<input id="import" name="import" type="button" value="Import" onClick="importTemplate()">
					</td>
				</tr>
			</table>
			</form>
		</td>
	</tr>
	<?php 
    html_end_box();
    $sql_where = '';
    $limit = ' LIMIT ' . $_REQUEST["rows"] * ($_REQUEST['page'] - 1) . "," . $_REQUEST["rows"];
    $order = "ORDER BY " . $_REQUEST['sort_column'] . " " . $_REQUEST['sort_direction'];
    if (strlen($_REQUEST["filter"])) {
        $sql_where .= (strlen($sql_where) ? " AND" : "WHERE") . " thold_template.name LIKE '%%" . $_REQUEST["filter"] . "%%'";
    }
    define('MAX_DISPLAY_PAGES', 21);
    $total_rows = db_fetch_cell("SELECT count(*) FROM thold_template");
    $template_list = db_fetch_assoc("SELECT * FROM thold_template {$sql_where} {$order} {$limit}");
    if ($total_rows) {
        /* generate page list */
        $url_page_select = get_page_list($_REQUEST["page"], MAX_DISPLAY_PAGES, $_REQUEST["rows"], $total_rows, "thold_templates.php?tab=thold");
        $nav = "<tr bgcolor='#" . $colors["header"] . "'>\r\n\t\t\t\t<td colspan='10'>\r\n\t\t\t\t\t<table width='100%' cellspacing='0' cellpadding='0' border='0'>\r\n\t\t\t\t\t\t<tr>\r\n\t\t\t\t\t\t\t<td align='left' class='textHeaderDark'>\r\n\t\t\t\t\t\t\t\t<strong>&lt;&lt; ";
        if ($_REQUEST["page"] > 1) {
            $nav .= "<a class='linkOverDark' href='" . htmlspecialchars("thold_templates.php?filter=" . $_REQUEST["filter"] . "&page=" . ($_REQUEST["page"] - 1)) . "'>";
        }
        $nav .= "Previous";
        if ($_REQUEST["page"] > 1) {
            $nav .= "</a>";
        }
        $nav .= "</strong>\r\n\t\t\t\t\t\t\t</td>\n\r\n\t\t\t\t\t\t\t<td align='center' class='textHeaderDark'>\r\n\t\t\t\t\t\t\t\tShowing Rows " . ($_REQUEST["rows"] * ($_REQUEST["page"] - 1) + 1) . " to " . ($total_rows < read_config_option("num_rows_device") || $total_rows < $_REQUEST["rows"] * $_REQUEST["page"] ? $total_rows : $_REQUEST["rows"] * $_REQUEST["page"]) . " of {$total_rows} [{$url_page_select}]\r\n\t\t\t\t\t\t\t</td>\n\r\n\t\t\t\t\t\t\t<td align='right' class='textHeaderDark'>\r\n\t\t\t\t\t\t\t\t<strong>";
        if ($_REQUEST["page"] * $_REQUEST["rows"] < $total_rows) {
            $nav .= "<a class='linkOverDark' href='" . htmlspecialchars("thold_templates.php?filter=" . $_REQUEST["filter"] . "&page=" . ($_REQUEST["page"] + 1)) . "'>";
        }
        $nav .= "Next";
        if ($_REQUEST["page"] * $_REQUEST["rows"] < $total_rows) {
            $nav .= "</a>";
        }
        $nav .= " &gt;&gt;</strong>\r\n\t\t\t\t\t\t\t</td>\n\r\n\t\t\t\t\t\t</tr>\r\n\t\t\t\t\t</table>\r\n\t\t\t\t</td>\r\n\t\t\t</tr>\n";
    } else {
        $nav = "<tr bgcolor='#" . $colors["header"] . "'>\r\n\t\t\t\t<td colspan='10'>\r\n\t\t\t\t\t<table width='100%' cellspacing='0' cellpadding='0' border='0'>\r\n\t\t\t\t\t\t<tr>\r\n\t\t\t\t\t\t\t<td align='center' class='textHeaderDark'>\r\n\t\t\t\t\t\t\t\tNo Rows Found\r\n\t\t\t\t\t\t\t</td>\n\r\n\t\t\t\t\t\t</tr>\r\n\t\t\t\t\t</table>\r\n\t\t\t\t</td>\r\n\t\t\t</tr>\n";
    }
    /* print checkbox form for validation */
    print "<form name='chk' method='post' action='thold_templates.php'>\n";
    html_start_box('', '100%', $colors['header'], '3', 'center', '');
    print $nav;
    html_header_sort_checkbox(array('name' => array('Name', 'ASC'), 'data_template_name' => array('Data Template', 'ASC'), 'data_source_name' => array('DS Name', 'ASC'), 'thold_type' => array('Type', 'ASC'), 'nosort1' => array('High/Up', ''), 'nosort2' => array('Low/Down', ''), 'nosort3' => array('Trigger', ''), 'nosort4' => array('Duration', ''), 'nosort5' => array('Repeat', '')), $_REQUEST['sort_column'], $_REQUEST['sort_direction'], false);
    $i = 0;
    $types = array('High/Low', 'Baseline Deviation', 'Time Based');
    if (sizeof($template_list)) {
        foreach ($template_list as $template) {
            switch ($template['thold_type']) {
                case 0:
                    # hi/lo
                    $value_hi = thold_format_number($template['thold_hi']);
                    $value_lo = thold_format_number($template['thold_low']);
                    $value_trig = $template['thold_fail_trigger'];
                    $value_duration = '';
                    $value_warning_hi = thold_format_number($template['thold_warning_hi']);
                    $value_warning_lo = thold_format_number($template['thold_warning_low']);
                    $value_warning_trig = $template['thold_warning_fail_trigger'];
                    $value_warning_duration = '';
                    break;
                case 1:
                    # baseline
                    $value_hi = $template['bl_pct_up'] . (strlen($template['bl_pct_up']) ? '%' : '-');
                    $value_lo = $template['bl_pct_down'] . (strlen($template['bl_pct_down']) ? '%' : '-');
                    $value_trig = $template['bl_fail_trigger'];
                    $step = db_fetch_cell("SELECT rrd_step \r\n\t\t\t\t\t\tFROM data_template_data \r\n\t\t\t\t\t\tWHERE data_template_id=" . $template['data_template_id'] . "\r\n\t\t\t\t\t\tLIMIT 1");
                    $value_duration = $template['bl_ref_time_range'] / $step;
                    break;
                case 2:
                    #time
                    $value_hi = thold_format_number($template['time_hi']);
                    $value_lo = thold_format_number($template['time_low']);
                    $value_trig = $template['time_fail_trigger'];
                    $value_duration = $template['time_fail_length'];
                    break;
            }
            form_alternate_row_color($colors["alternate"], $colors["light"], $i, 'line' . $template["id"]);
            $i++;
            form_selectable_cell('<a class="linkEditMain" href="' . htmlspecialchars('thold_templates.php?action=edit&id=' . $template['id']) . '">' . ($template['name'] == '' ? $template['data_template_name'] . ' [' . $template['data_source_name'] . ']' : $template['name']) . '</a>', $template["id"]);
            form_selectable_cell($template['data_template_name'], $template["id"]);
            form_selectable_cell($template['data_source_name'], $template["id"]);
            form_selectable_cell($types[$template['thold_type']], $template["id"]);
            form_selectable_cell($value_hi, $template["id"]);
            form_selectable_cell($value_lo, $template["id"]);
            $trigger = plugin_thold_duration_convert($template['data_template_id'], $value_trig, 'alert', 'data_template_id');
            form_selectable_cell(strlen($trigger) ? "<i>" . $trigger . "</i>" : "-", $template["id"]);
            $duration = plugin_thold_duration_convert($template['data_template_id'], $value_duration, 'time', 'data_template_id');
            form_selectable_cell(strlen($duration) ? $duration : "-", $template["id"]);
            form_selectable_cell(plugin_thold_duration_convert($template['data_template_id'], $template['repeat_alert'], 'repeat', 'data_template_id'), $template['id']);
            form_checkbox_cell($template['data_template_name'], $template["id"]);
            form_end_row();
        }
        print $nav;
    } else {
        print "<tr><td><em>No Threshold Templates</em></td></tr>\n";
    }
    html_end_box(false);
    /* draw the dropdown containing a list of available actions for this form */
    draw_actions_dropdown($thold_actions);
    print "</form>\n";
}
示例#2
0
function templates()
{
    global $config, $thold_actions, $item_rows;
    include $config['base_path'] . '/plugins/thold/includes/arrays.php';
    template_request_validation();
    /* if the number of rows is -1, set it to the default */
    if (get_request_var('rows') == -1) {
        $rows = read_config_option('num_rows_table');
    } else {
        $rows = get_request_var('rows');
    }
    html_start_box(__('Threshold Templates'), '100%', '', '3', 'center', 'thold_templates.php?action=add');
    ?>
	<tr class='even'>
		<td>
			<form id='listthold' action='thold_templates.php'>
			<table class='filterTable'>
				<tr>
					<td>
						<?php 
    print __('Search');
    ?>
					</td>
					<td>
						<input type='text' id='filter' size='25' value='<?php 
    print get_request_var('filter');
    ?>
'>
					</td>
					<td>
						<?php 
    print __('Templates');
    ?>
					</td>
					<td>
						<select id='rows' onChange='applyFilter()'>
							<option value='-1'<?php 
    if (get_request_var('rows') == '-1') {
        ?>
 selected<?php 
    }
    ?>
><?php 
    print __('Default');
    ?>
</option>
							<?php 
    if (sizeof($item_rows)) {
        foreach ($item_rows as $key => $value) {
            print "<option value='" . $key . "'";
            if (get_request_var('rows') == $key) {
                print ' selected';
            }
            print '>' . $value . "</option>\n";
        }
    }
    ?>
						</select>
					</td>
					<td>
						<input id='refresh' type='button' value='<?php 
    print __('Go');
    ?>
' onClick='applyFilter()'>
					</td>
					<td>
						<input id='clear' type='button' value='<?php 
    print __('Clear');
    ?>
' onClick='clearFilter()'>
					</td>
					<td>
						<input id='import' type='button' value='<?php 
    print __('Import');
    ?>
' onClick='importTemplate()'>
					</td>
				</tr>
			</table>
			</form>
			<script type='text/javascript'>

			function applyFilter() {
				strURL  = 'thold_templates.php?header=false&rows=' + $('#rows').val();
				strURL += '&filter=' + $('#filter').val();
				loadPageNoHeader(strURL);
			}

			function clearFilter() {
				strURL  = 'thold_templates.php?header=false&clear=1';
				loadPageNoHeader(strURL);
			}

			function importTemplate() {
				strURL = 'thold_templates.php?header=false&action=import';
				loadPageNoHeader(strURL);
			}

			$(function() {
				$('#listthold').submit(function(event) {
					event.preventDefault();
					applyFilter();
				});
			});

			</script>
		</td>
	</tr>
	<?php 
    html_end_box();
    $sql_where = '';
    $limit = ' LIMIT ' . $rows * (get_request_var('page') - 1) . ',' . $rows;
    $order = 'ORDER BY ' . get_request_var('sort_column') . ' ' . get_request_var('sort_direction');
    if (strlen(get_request_var('filter'))) {
        $sql_where .= (strlen($sql_where) ? ' AND' : 'WHERE') . " thold_template.name LIKE '%" . get_request_var('filter') . "%'";
    }
    $total_rows = db_fetch_cell('SELECT count(*) FROM thold_template');
    $template_list = db_fetch_assoc("SELECT * FROM thold_template {$sql_where} {$order} {$limit}");
    $nav = html_nav_bar('thold_templates.php?filter=' . get_request_var('filter'), MAX_DISPLAY_PAGES, get_request_var('page'), $rows, $total_rows, 10, __('Templates'), 'page', 'main');
    form_start('thold_templates.php', 'chk');
    print $nav;
    html_start_box('', '100%', '', '3', 'center', '');
    $display_text = array('name' => array(__('Name'), 'ASC'), 'data_template_name' => array(__('Data Template'), 'ASC'), 'data_source_name' => array(__('DS Name'), 'ASC'), 'thold_type' => array(__('Type'), 'ASC'), 'nosort1' => array(__('High/Up'), ''), 'nosort2' => array(__('Low/Down'), ''), 'nosort3' => array(__('Trigger'), ''), 'nosort4' => array(__('Duration'), ''), 'nosort5' => array(__('Repeat'), ''));
    html_header_sort_checkbox($display_text, get_request_var('sort_column'), get_request_var('sort_direction'), false);
    $i = 0;
    if (sizeof($template_list)) {
        foreach ($template_list as $template) {
            switch ($template['thold_type']) {
                case 0:
                    # hi/lo
                    $value_hi = thold_format_number($template['thold_hi']);
                    $value_lo = thold_format_number($template['thold_low']);
                    $value_trig = $template['thold_fail_trigger'];
                    $value_duration = '';
                    $value_warning_hi = thold_format_number($template['thold_warning_hi']);
                    $value_warning_lo = thold_format_number($template['thold_warning_low']);
                    $value_warning_trig = $template['thold_warning_fail_trigger'];
                    $value_warning_duration = '';
                    break;
                case 1:
                    # baseline
                    $value_hi = $template['bl_pct_up'] . (strlen($template['bl_pct_up']) ? '%' : '-');
                    $value_lo = $template['bl_pct_down'] . (strlen($template['bl_pct_down']) ? '%' : '-');
                    $value_trig = $template['bl_fail_trigger'];
                    $step = db_fetch_cell_prepared('SELECT rrd_step
					FROM data_template_data
					WHERE data_template_id = ?
					LIMIT 1', array($template['data_template_id']));
                    $value_duration = $template['bl_ref_time_range'] / $step;
                    break;
                case 2:
                    #time
                    $value_hi = thold_format_number($template['time_hi']);
                    $value_lo = thold_format_number($template['time_low']);
                    $value_trig = $template['time_fail_trigger'];
                    $value_duration = $template['time_fail_length'];
                    break;
            }
            $name = $template['name'] == '' ? $template['data_template_name'] . ' [' . $template['data_source_name'] . ']' : $template['name'];
            $name = filter_value($name, get_request_var('filter'));
            form_alternate_row('line' . $template['id']);
            form_selectable_cell('<a class="linkEditMain" href="' . htmlspecialchars('thold_templates.php?action=edit&id=' . $template['id']) . '">' . $name . '</a>', $template['id']);
            form_selectable_cell(filter_value($template['data_template_name'], get_request_var('filter')), $template['id']);
            form_selectable_cell($template['data_source_name'], $template['id']);
            form_selectable_cell($thold_types[$template['thold_type']], $template['id']);
            form_selectable_cell($value_hi, $template['id']);
            form_selectable_cell($value_lo, $template['id']);
            $trigger = plugin_thold_duration_convert($template['data_template_id'], $value_trig, 'alert', 'data_template_id');
            form_selectable_cell(strlen($trigger) ? '<i>' . $trigger . '</i>' : '-', $template['id']);
            $duration = plugin_thold_duration_convert($template['data_template_id'], $value_duration, 'time', 'data_template_id');
            form_selectable_cell(strlen($duration) ? $duration : '-', $template['id']);
            form_selectable_cell(plugin_thold_duration_convert($template['data_template_id'], $template['repeat_alert'], 'repeat', 'data_template_id'), $template['id']);
            form_checkbox_cell($template['data_template_name'], $template['id']);
            form_end_row();
        }
    } else {
        print "<tr><td><em>" . __('No Threshold Templates') . "</em></td></tr>\n";
    }
    html_end_box(false);
    if (sizeof($template_list)) {
        print $nav;
    }
    /* draw the dropdown containing a list of available actions for this form */
    draw_actions_dropdown($thold_actions);
    form_end();
}