HowTo: Sort Columns in graph_thold.php

Support questions about the Threshold plugin

Moderators: Developers, Moderators

Post Reply
Decombej
Posts: 20
Joined: Fri Jun 23, 2006 9:51 am
Location: Lyon, France

HowTo: Sort Columns in graph_thold.php

Post by Decombej »

I had to make the graph_thold.php page a little more user-friendly, so let's share it!
It's based on cacti's sorting which will be in the v0.8.6i.
It's pretty simple:

First -> Add this in /cacti/lib/html.php

Code: Select all

function html_header_sort_thold($header_items, $sort_column, $sort_direction, $form_action = "") {
	global $colors;

	/* reverse the sort direction */
	if ($sort_direction == "ASC") {
		$new_sort_direction = "DESC";
	}else{
		$new_sort_direction = "ASC";
	}

	/* default to the 'current' file */
	if ($form_action == "") { $form_action = basename($_SERVER["PHP_SELF"]); }

	print "<tr bgcolor='#a0a0ff'>\n";

	foreach($header_items as $db_column => $display_array) {
		/* by default, you will always sort ascending, with the exception of an already sorted column */
		if ($sort_column == $db_column) {
			$direction = $new_sort_direction;
			$display_text = $display_array[0] . "**";
		}else{
			$display_text = $display_array[0];
			$direction = $display_array[1];
		}

		if ($db_column == "") {
			print "<td bgcolor='#a0a0ff'>" . $display_text . "</td>\n";
		}else{
			print "<td>";
			print "<a class='textSubHeaderDark' href=" . $_SERVER["PHP_SELF"] . "?sort_column=" . $db_column . "&sort_direction=" . $direction . ">" . $display_text . "</a>";
			print "</td>\n";
		}
	}

	//print "<td width='1%' align='right' bgcolor='#a0a0ff' style='" . get_checkbox_style() . "'><input type='checkbox' style='margin: 0px;' name='all' title='Select All' onClick='SelectAll(\"chk_\",this.checked)'></td>\n<form name='chk' method='post' action='$form_action'>\n";
	print "</tr>\n";
}
Then, edit /cacti/plugins/thold/graph_thold.php->
(i added the Availability and Last-fail columns...)
Comment this (with <?// or /* blabla */) at line 63:

Code: Select all

<?/*    
<thead>
    <tr bgcolor="#a0a0ff">
    <td>Host</td>
    <td>Status</td>
    <td>Availability</td>
    <td>Last Fail</td>
    </tr>
    </thead>
    <tbody>
*/
and ->

Code: Select all

//$host_table = db_fetch_assoc("select * from host order by status asc, description asc");
then copy this following code after <table width="100%" class="list" align="center" cellpadding="3"> (don't forget a <?):

Code: Select all

if (isset($_REQUEST["sort_column"])) {
	$_REQUEST["sort_column"] = sanitize_search_string(get_request_var("sort_column"));}
if (isset($_REQUEST["sort_direction"])) {
	$_REQUEST["sort_direction"] = sanitize_search_string(get_request_var("sort_direction"));}
load_current_session_value("sort_column", "sess_thold_sort_column", "status");
load_current_session_value("sort_direction", "sess_thold_sort_direction", "ASC");
	
$display_text = array(
		"Description" => array("Host", "ASC"),
		"Status" => array("Status", "ASC"),
		"Availability" => array("Availability", "ASC"),
		"status_fail_date" => array("Last Fail", "DESC"),);
html_header_sort_thold($display_text, $_REQUEST["sort_column"], $_REQUEST["sort_direction"]);

$host_table = db_fetch_assoc("select * from host order by ".$_REQUEST["sort_column"]." ".$_REQUEST["sort_direction"].", description asc");
Well that's it, i didn't spent much time on this, so i'm sure it could be better, but it's working.
Don't hesitate to improve it, and post it here.
[[color=darkblue]Debian 3.1 | Cacti 0.8.6h | Cactid 0.8.6g | Mysql 4.0.24 | PHP 4.3 with eAccelerator v0.9.4 | Apache 1.3 | Plugin Arch...[/color]]
cigamit
Developer
Posts: 3369
Joined: Thu Apr 07, 2005 3:29 pm
Location: B/CS Texas
Contact:

Post by cigamit »

This will be updated for the upcoming cacti v0.8.6i release. As soon as Cacti supports it, I will have a version of thold out that supports it too.
Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests