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";
}
(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>
*/
Code: Select all
//$host_table = db_fetch_assoc("select * from host order by status asc, description asc");
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");
Don't hesitate to improve it, and post it here.