コード例 #1
0
ファイル: notify_lists.php プロジェクト: caiorasec/thold
function templates($header_label)
{
    global $colors, $thold_bgcolors, $config, $item_rows;
    $thold_actions = array(1 => 'Associate', 2 => 'Disassociate');
    thold_template_request_validation();
    $alert_num_rows = read_config_option('alert_num_rows');
    if ($alert_num_rows < 1 || $alert_num_rows > 5000) {
        db_execute("REPLACE INTO settings VALUES ('alert_num_rows', 30)");
        /* pull it again so it updates the cache */
        $alert_num_rows = read_config_option('alert_num_rows', true);
    }
    $sql_where = '';
    $sort = $_REQUEST['sort_column'];
    $limit = ' LIMIT ' . $alert_num_rows * ($_REQUEST['page'] - 1) . ",{$alert_num_rows}";
    if ($_REQUEST["associated"] == 'true') {
        $sql_where .= (!strlen($sql_where) ? 'WHERE ' : ' AND ') . "(notify_warning=" . get_request_var_request('id') . " OR notify_alert=" . get_request_var_request('id') . ")";
    }
    if (strlen($_REQUEST['filter'])) {
        $sql_where .= (!strlen($sql_where) ? 'WHERE ' : ' AND ') . "thold_template.name LIKE '%" . $_REQUEST['filter'] . "%'";
    }
    $sql = "SELECT * FROM thold_template\n\t\t{$sql_where}\n\t\tORDER BY {$sort} " . $_REQUEST['sort_direction'] . $limit;
    $result = db_fetch_assoc($sql);
    ?>
	<script type="text/javascript">
	<!--
	function applyTHoldFilterChange(objForm) {
		strURL = '?action=edit&tab=templates&id=<?php 
    print get_request_var_request('id');
    ?>
'
		strURL = strURL + '&associated=' + objForm.associated.checked;
		strURL = strURL + '&rows=' + objForm.rows.value;
		strURL = strURL + '&filter=' + objForm.filter.value;
		document.location = strURL;
	}

	function clearTHoldFilterChange(objForm) {
		strURL = '?action=edit&tab=templates&id=<?php 
    print get_request_var_request('id');
    ?>
&clearf=true'
		document.location = strURL;
	}

	-->
	</script>
	<?php 
    html_start_box('<strong>Associated Templates</strong> ' . htmlspecialchars($header_label), '100%', $colors['header'], '3', 'center', '');
    ?>
	<tr bgcolor='#<?php 
    print $colors["panel"];
    ?>
' class='noprint'>
		<td class='noprint'>
			<form name="listthold" method="get" action="notify_lists.php">
			<table cellpadding='0' cellspacing='0'>
				<tr class='noprint'>
					<td nowrap style='white-space: nowrap;' width="20">
						&nbsp;Search:&nbsp;
					</td>
					<td width="1">
						<input type="text" name="filter" size="20" value="<?php 
    print htmlspecialchars(get_request_var_request("filter"));
    ?>
" onChange="applyTHoldFilterChange(document.listthold)">
					</td>
					<td nowrap style='white-space: nowrap;' width="50">
						&nbsp;Rows:&nbsp;
					</td>
					<td width="1">
						<select name="rows" onChange="applyTHoldFilterChange(document.listthold)">
							<option value="-1"<?php 
    if (get_request_var_request("rows") == "-1") {
        ?>
 selected<?php 
    }
    ?>
>Default</option>
							<?php 
    if (sizeof($item_rows) > 0) {
        foreach ($item_rows as $key => $value) {
            print "<option value='" . $key . "'";
            if (get_request_var_request("rows") == $key) {
                print " selected";
            }
            print ">" . htmlspecialchars($value) . "</option>\n";
        }
    }
    ?>
						</select>
					</td>
					<td>
						<input type='checkbox' name='associated' id='associated' onChange='applyTHoldFilterChange(document.listthold)' <?php 
    print $_REQUEST['associated'] == 'true' || $_REQUEST['associated'] == 'on' ? 'checked' : '';
    ?>
>
					</td>
					<td>
						<label for='associated'>Associated</label>
					</td>
					<td nowrap>
						&nbsp;<input type="button" value="Go" onClick='applyTHoldFilterChange(document.listthold)' title="Set/Refresh Filters">
					</td>
					<td nowrap>
						<input type="button" name="clearf" value="Clear" onClick='clearTHoldFilterChange(document.listthold)' title="Clear Filters">
					</td>
				</tr>
			</table>
			<input type='hidden' name='page' value='1'>
			<input type='hidden' name='action' value='edit'>
			<input type='hidden' name='tab' value='templates'>
			<input type='hidden' name='id' value='<?php 
    print get_request_var_request('id');
    ?>
'>
			</form>
		</td>
	</tr>
	<?php 
    html_end_box();
    $total_rows = db_fetch_cell("SELECT count(*)\n\t\tFROM thold_template\n\t\t{$sql_where}");
    $url_page_select = get_page_list($_REQUEST['page'], MAX_DISPLAY_PAGES, $alert_num_rows, $total_rows, 'notify_lists.php?action=edit&tab=templates');
    /* print checkbox form for validation */
    print "<form name='chk' method='post' action='notify_lists.php'>\n";
    html_start_box('', '100%', $colors['header'], '4', 'center', '');
    if ($total_rows) {
        $nav = "<tr bgcolor='#" . $colors['header'] . "'>\n\t\t\t\t<td colspan='8'>\n\t\t\t\t\t<table width='100%' cellspacing='0' cellpadding='0' border='0'>\n\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t<td align='left' class='textHeaderDark'>\n\t\t\t\t\t\t\t\t<strong>&lt;&lt; ";
        if ($_REQUEST["page"] > 1) {
            $nav .= "<a class='linkOverDark' href='" . htmlspecialchars("notify_lists.php?page=" . ($_REQUEST["page"] - 1)) . "'>";
        }
        $nav .= "Previous";
        if ($_REQUEST["page"] > 1) {
            $nav .= "</a>";
        }
        $nav .= "</strong>\n\t\t\t\t\t\t\t</td>\n\n\t\t\t\t\t\t\t<td align='center' class='textHeaderDark'>\n\t\t\t\t\t\t\t\tShowing Rows " . ($alert_num_rows * ($_REQUEST["page"] - 1) + 1) . " to " . ($total_rows < $alert_num_rows || $total_rows < $alert_num_rows * $_REQUEST["page"] ? $total_rows : $alert_num_rows * $_REQUEST["page"]) . " of {$total_rows} [{$url_page_select}]\n\t\t\t\t\t\t\t</td>\n\n\t\t\t\t\t\t\t<td align='right' class='textHeaderDark'>\n\t\t\t\t\t\t\t\t<strong>";
        if ($_REQUEST["page"] * $alert_num_rows < $total_rows) {
            $nav .= "<a class='linkOverDark' href='" . htmlspecialchars("notify_lists.php?page=" . ($_REQUEST["page"] + 1)) . "'>";
        }
        $nav .= "Next";
        if ($_REQUEST["page"] * $alert_num_rows < $total_rows) {
            $nav .= "</a>";
        }
        $nav .= " &gt;&gt;</strong>\n\t\t\t\t\t\t\t</td>\n\n\t\t\t\t\t\t</tr>\n\t\t\t\t\t</table>\n\t\t\t\t</td>\n\t\t\t</tr>\n";
    } else {
        $nav = "<tr bgcolor='#" . $colors['header'] . "'>\n\t\t\t\t<td colspan='8'>\n\t\t\t\t\t<table width='100%' cellspacing='0' cellpadding='0' border='0'>\n\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t<td align='center' class='textHeaderDark'>\n\t\t\t\t\t\t\t\tNo Rows Found\n\t\t\t\t\t\t\t</td>\n\n\t\t\t\t\t\t</tr>\n\t\t\t\t\t</table>\n\t\t\t\t</td>\n\t\t\t</tr>\n";
    }
    print $nav;
    $display_text = array('name' => array('Name', 'ASC'), 'id' => array('ID', 'ASC'), 'nosort1' => array('Warning Lists', 'ASC'), 'nosort2' => array('Alert Lists', 'ASC'), 'thold_type' => array('Type', 'ASC'));
    html_header_sort_checkbox($display_text, $_REQUEST['sort_column'], $_REQUEST['sort_direction'], false);
    $c = 0;
    $i = 0;
    $types = array('High/Low', 'Baseline Deviation', 'Time Based');
    if (count($result)) {
        foreach ($result as $row) {
            $c++;
            /* show alert stats first */
            $alert_stat = '';
            $list = db_fetch_cell("SELECT count(*) FROM plugin_thold_template_contact WHERE template_id=" . $row["id"]);
            if ($list > 0) {
                $alert_stat = "<span style='font-weight:bold;color:green;'>Select Users</span>";
            }
            if (strlen($row["notify_extra"])) {
                $alert_stat .= (strlen($alert_stat) ? ", " : "") . "<span style='font-weight:bold;color:purple;'>Specific Emails</span>";
            }
            if (!empty($row["notify_alert"])) {
                if (get_request_var_request('id') == $row["notify_alert"]) {
                    $alert_stat .= (strlen($alert_stat) ? ", " : "") . "<span style='font-weight:bold;color:green;'>Current List</span>";
                } else {
                    $alert_list = db_fetch_cell("SELECT name FROM plugin_notification_lists WHERE id=" . $row["notify_alert"]);
                    $alert_stat .= (strlen($alert_stat) ? ", " : "") . "<span style='font-weight:bold;color:red;'>" . $alert_list . "</span>";
                }
            }
            if (!strlen($alert_stat)) {
                $alert_stat = "<span style='font-weight:bold;color:blue;'>Log Only</span>";
            }
            /* show warning stats first */
            $warn_stat = '';
            if (strlen($row["notify_warning_extra"])) {
                $warn_stat .= (strlen($warn_stat) ? ", " : "") . "<span style='font-weight:bold;color:purple;'>Specific Emails</span>";
            }
            if (!empty($row["notify_warning"])) {
                if (get_request_var_request('id') == $row["notify_warning"]) {
                    $warn_stat .= (strlen($warn_stat) ? ", " : "") . "<span style='font-weight:bold;color:green;'>Current List</span>";
                } else {
                    $warn_list = db_fetch_cell("SELECT name FROM plugin_notification_lists WHERE id=" . $row["notify_warning"]);
                    $warn_stat .= (strlen($warn_stat) ? ", " : "") . "<span style='font-weight:bold;color:red;'>" . $warn_list . "</span>";
                }
            }
            if (!strlen($warn_stat) && ($row["thold_type"] == 0 && $row["thold_warning_hi"] == '' && $row["thold_warning_low"] == '' || $row["thold_type"] == 2 && $row["thold_time_warning_hi"] == '' && $row["thold_time_warning_low"] == '')) {
                $warn_stat = "<span style='font-weight:bold;color:red;'>None</span>";
            } elseif (!strlen($warn_stat)) {
                $warn_stat = "<span style='font-weight:bold;color:blue;'>Log Only</span>";
            }
            form_alternate_row_color($colors["alternate"], $colors["light"], $i, 'line' . $row["id"]);
            $i++;
            form_selectable_cell(strlen(get_request_var_request("filter")) ? preg_replace("/(" . preg_quote(get_request_var_request("filter")) . ")/i", "<span style='background-color: #F8D93D;'>\\1</span>", htmlspecialchars($row['name'])) : htmlspecialchars($row['name']), $row['id']);
            form_selectable_cell($row['id'], $row["id"]);
            form_selectable_cell($warn_stat, $row["id"]);
            form_selectable_cell($alert_stat, $row["id"]);
            form_selectable_cell($types[$row['thold_type']], $row["id"]);
            form_checkbox_cell($row['name'], $row['id']);
            form_end_row();
        }
        print $nav;
    } else {
        form_alternate_row_color($colors['alternate'], $colors['light'], 0);
        print '<td colspan="8"><i>No Templates</i></td></tr>';
    }
    html_end_box(false);
    form_hidden_box("action", "edit", "");
    form_hidden_box("tab", "templates", "");
    form_hidden_box("id", get_request_var_request("id"), "");
    form_hidden_box("save_templates", "1", "");
    draw_actions_dropdown($thold_actions);
    print "</form>\n";
}
コード例 #2
0
ファイル: notify_lists.php プロジェクト: Cacti/plugin_thold
function templates($header_label)
{
    global $config, $item_rows;
    include $config['base_path'] . '/plugins/thold/includes/arrays.php';
    $thold_actions = array(1 => __('Associate'), 2 => __('Disassociate'));
    thold_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');
    }
    $sql_where = '';
    $sort = get_request_var('sort_column');
    $limit = ' LIMIT ' . $rows * (get_request_var('page') - 1) . ", {$rows}";
    if (get_request_var('associated') == 'true') {
        $sql_where .= (!strlen($sql_where) ? 'WHERE ' : ' AND ') . '(notify_warning=' . get_request_var('id') . ' OR notify_alert=' . get_request_var('id') . ')';
    }
    if (strlen(get_request_var('filter'))) {
        $sql_where .= (!strlen($sql_where) ? 'WHERE ' : ' AND ') . "thold_template.name LIKE '%" . get_request_var('filter') . "%'";
    }
    $sql = "SELECT * FROM thold_template\n\t\t{$sql_where}\n\t\tORDER BY {$sort} " . get_request_var('sort_direction') . $limit;
    $result = db_fetch_assoc($sql);
    html_start_box(__('Associated Templates') . ' ' . htmlspecialchars($header_label), '100%', '', '3', 'center', '');
    ?>
	<tr class='even'>
		<td>
		<form id='listthold' method='get' action='notify_lists.php'>
			<table class='filterTable'>
				<tr>
					<td>
						<?php 
    print __('Search');
    ?>
					</td>
					<td>
						<input type='text' id='filter' size='25' value='<?php 
    print htmlspecialchars(get_request_var('filter'));
    ?>
' onChange='applyFilter()'>
					</td>
					<td>
						<?php 
    print __('Rows');
    ?>
					</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) > 0) {
        foreach ($item_rows as $key => $value) {
            print "<option value='" . $key . "'";
            if (get_request_var('rows') == $key) {
                print ' selected';
            }
            print '>' . htmlspecialchars($value) . "</option>\n";
        }
    }
    ?>
						</select>
					</td>
					<td>
						<input type='checkbox' id='associated' onChange='applyFilter()' <?php 
    print get_request_var('associated') == 'true' || get_request_var('associated') == 'on' ? 'checked' : '';
    ?>
>
					</td>
					<td>
						<label for='associated'><?php 
    print __('Associated');
    ?>
</label>
					</td>
					<td>
						<input type='button' value='<?php 
    print __('Go');
    ?>
' onClick='applyFilter()' title='<?php 
    print __('Set/Refresh Filters');
    ?>
'>
					</td>
					<td>
						<input type='button' id='clearf' value='<?php 
    print __('Clear');
    ?>
' onClick='clearFilter()' title='<?php 
    print __('Clear Filters');
    ?>
'>
					</td>
				</tr>
			</table>
			<input type='hidden' id='page' value='<?php 
    print get_filter_request_var('page');
    ?>
'>
			<input type='hidden' id='action' value='edit'>
			<input type='hidden' id='tab' value='templates'>
			<input type='hidden' id='id' value='<?php 
    print get_request_var('id');
    ?>
'>
		</form>
		<script type='text/javascript'>

		function applyFilter() {
			strURL  = 'notify_lists.php?header=false&action=edit&tab=templates&id=<?php 
    print get_request_var('id');
    ?>
'
			strURL += '&associated=' + $('#associated').is(':checked');
			strURL += '&rows=' + $('#rows').val();
			strURL += '&filter=' + $('#filter').val();
			loadPageNoHeader(strURL);
		}

		function clearFilter() {
			strURL = 'notify_lists.php?header=false&action=edit&tab=templates&id=<?php 
    print get_request_var('id');
    ?>
&clearf=true'
			loadPageNoHeader(strURL);
		}

		$(function() {
			$('#listthold').submit(function(event) {
				event.preventDefault();
				applyFilter();
			});
		});
	
		</script>
		</td>
	</tr>
	<?php 
    html_end_box();
    $total_rows = db_fetch_cell("SELECT count(*)\n\t\tFROM thold_template\n\t\t{$sql_where}");
    $nav = html_nav_bar('notify_lists.php?action=edit&tab=templates&id=' . get_filter_request_var('id'), MAX_DISPLAY_PAGES, get_request_var('page'), $rows, $total_rows, 10, 'Lists', 'page', 'main');
    form_start('notify_lists.php', 'chk');
    print $nav;
    html_start_box('', '100%', '', '4', 'center', '');
    $display_text = array('name' => array(__('Name'), 'ASC'), 'id' => array(__('ID'), 'ASC'), 'nosort1' => array(__('Warning Lists'), 'ASC'), 'nosort2' => array(__('Alert Lists'), 'ASC'), 'thold_type' => array(__('Type'), 'ASC'));
    html_header_sort_checkbox($display_text, get_request_var('sort_column'), get_request_var('sort_direction'), false, 'notify_lists.php?action=edit&tab=templates&id=' . get_filter_request_var('id'));
    $c = 0;
    $i = 0;
    if (sizeof($result)) {
        foreach ($result as $row) {
            $c++;
            /* show alert stats first */
            $alert_stat = '';
            $list = db_fetch_cell("SELECT count(*) FROM plugin_thold_template_contact WHERE template_id=" . $row["id"]);
            if ($list > 0) {
                $alert_stat = "<span style='font-weight:bold;color:green;'>" . __('Select Users') . "</span>";
            }
            if (strlen($row['notify_extra'])) {
                $alert_stat .= (strlen($alert_stat) ? ', ' : '') . "<span style='font-weight:bold;color:purple;'>" . __('Specific Emails') . "</span>";
            }
            if (!empty($row['notify_alert'])) {
                if (get_request_var('id') == $row['notify_alert']) {
                    $alert_stat .= (strlen($alert_stat) ? ', ' : '') . "<span style='font-weight:bold;color:green;'>" . __('Current List') . "</span>";
                } else {
                    $alert_list = db_fetch_cell('SELECT name FROM plugin_notification_lists WHERE id=' . $row['notify_alert']);
                    $alert_stat .= (strlen($alert_stat) ? ', ' : '') . "<span style='font-weight:bold;color:red;'>" . $alert_list . '</span>';
                }
            }
            if (!strlen($alert_stat)) {
                $alert_stat = "<span style='font-weight:bold;color:blue;'>" . __('Log Only') . "</span>";
            }
            /* show warning stats first */
            $warn_stat = '';
            if (strlen($row['notify_warning_extra'])) {
                $warn_stat .= (strlen($warn_stat) ? ', ' : '') . "<span style='font-weight:bold;color:purple;'>" . __('Specific Emails') . "</span>";
            }
            if (!empty($row['notify_warning'])) {
                if (get_request_var('id') == $row['notify_warning']) {
                    $warn_stat .= (strlen($warn_stat) ? ', ' : '') . "<span style='font-weight:bold;color:green;'>" . __('Current List') . "</span>";
                } else {
                    $warn_list = db_fetch_cell('SELECT name FROM plugin_notification_lists WHERE id=' . $row['notify_warning']);
                    $warn_stat .= (strlen($warn_stat) ? ', ' : '') . "<span style='font-weight:bold;color:red;'>" . $warn_list . '</span>';
                }
            }
            if (!strlen($warn_stat) && ($row['thold_type'] == 0 && $row['thold_warning_hi'] == '' && $row['thold_warning_low'] == '' || $row['thold_type'] == 2 && $row['thold_time_warning_hi'] == '' && $row['thold_time_warning_low'] == '')) {
                $warn_stat = "<span style='font-weight:bold;color:red;'>" . __('None') . "</span>";
            } elseif (!strlen($warn_stat)) {
                $warn_stat = "<span style='font-weight:bold;color:blue;'>" . __('Log Only') . "</span>";
            }
            form_alternate_row('line' . $row['id'], true);
            form_selectable_cell(filter_value($row['name'], get_request_var('filter')), $row['id']);
            form_selectable_cell($row['id'], $row['id']);
            form_selectable_cell($warn_stat, $row['id']);
            form_selectable_cell($alert_stat, $row['id']);
            form_selectable_cell($thold_types[$row['thold_type']], $row['id']);
            form_checkbox_cell($row['name'], $row['id']);
            form_end_row();
        }
    } else {
        print "<tr class='even'><td colspan='8'><i>" . __('No Templates') . "</i></td></tr>\n";
    }
    html_end_box(false);
    if (sizeof($result)) {
        print $nav;
    }
    form_hidden_box('tab', 'templates', '');
    form_hidden_box('id', get_request_var('id'), '');
    form_hidden_box('save_templates', '1', '');
    draw_actions_dropdown($thold_actions);
    form_end();
}