From: Peter Palfrader Date: Sun, 25 May 2008 16:05:17 +0000 (+0200) Subject: make summaryattrs sortable [zobel] X-Git-Tag: release-0.3.33~71 X-Git-Url: https://git.adam-barratt.org.uk/?p=mirror%2Fuserdir-ldap-cgi.git;a=commitdiff_plain;h=295f9baecdce2ac043eaf41833094b0435d932aa;hp=f1cce6d72917e0d399b178e373c0737ce0dcb59f make summaryattrs sortable [zobel] --- diff --git a/debian/changelog b/debian/changelog index 513d852..6026a60 100644 --- a/debian/changelog +++ b/debian/changelog @@ -2,8 +2,9 @@ userdir-ldap-cgi (0.3.10) unstable; urgency=low * Make machines.cgi display the purpose attribute from LDAP [HE]. * Add VoIP field to CGI [zobel]. + * make summaryattrs sortable [zobel]. - -- Peter Palfrader Sun, 25 May 2008 18:04:35 +0200 + -- Peter Palfrader Sun, 25 May 2008 18:05:06 +0200 userdir-ldap-cgi (0.3.9) unstable; urgency=low diff --git a/machines.cgi b/machines.cgi index 8fe4bfa..166c2ca 100755 --- a/machines.cgi +++ b/machines.cgi @@ -4,6 +4,7 @@ # (c) 1999 Randolph Chung. Licensed under the GPL. # (c) 2004 Martin Schulze. Licensed under the GPL. # (c) 2006 Ryan Murray. Licensed under the GPL. +# (c) 2008 Martin Zobel-Helas. Licensed under the GPL. use lib '.'; use strict vars; @@ -86,6 +87,8 @@ $SIG{__DIE__} = \&DieHandler; my $query = new CGI; my $host = lc($query->param('host')); +my $sortby = lc($query->param('sortby')) || "host"; +my $sortorder = lc($query->param('sortorder')) || "asc"; &Util::HTMLSendHeader; $ldap = Net::LDAP->new($config{ldaphost}) || &Util::HTMLError($!); @@ -180,11 +183,25 @@ if ($output{havehostdata}) { $hostdetails = "

Summary

\n"; $hostdetails .= "\n"; foreach $key (@summaryorder) { - $hostdetails .= ""; + if ($sortby ne $key) { + $hostdetails .= ""; + } else { + if ($sortorder ne "dsc") { + $hostdetails .= ""; + } else { + $hostdetails .= ""; + } + } } $hostdetails .= "\n"; - foreach $host (sort(keys(%summary))) { + my @sorted; + if ($sortorder eq "asc") { + @sorted = sort {($summary{$a}->{$sortby} cmp $summary{$b}->{$sortby}) || ($summary{$a}->{'host'} cmp $summary{$b}->{'host'})} keys(%summary) + } else { + @sorted = sort {($summary{$b}->{$sortby} cmp $summary{$a}->{$sortby}) || ($summary{$a}->{'host'} cmp $summary{$b}->{'host'})} keys(%summary) + } + foreach $host (@sorted) { $hostdetails .= ""; foreach $key (@summaryorder) { $hostdetails .= "";
$summaryattrs{$key}$summaryattrs{$key}$summaryattrs{$key}$summaryattrs{$key}
$summary{$host}{$key}