From 28190f8d0d2408aa53fe0729b9e552d4d0f98e1c Mon Sep 17 00:00:00 2001
From: ajt <>
Date: Sat, 18 Nov 2000 03:22:49 -0800
Subject: [PATCH] [project @ 2000-11-18 03:22:49 by ajt] add sortby=count and
 sortby=alpha to pkgindex.cgi

---
 cgi/pkgindex.cgi | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)

diff --git a/cgi/pkgindex.cgi b/cgi/pkgindex.cgi
index b4e1a9d9..f1dea013 100755
--- a/cgi/pkgindex.cgi
+++ b/cgi/pkgindex.cgi
@@ -17,12 +17,17 @@ nice(5);
 my %param = readparse();
 
 my $indexon = $param{'indexon'} || 'pkg';
-if ($indexon !~ m/^(pkg|maint|submitter)/) {
+if ($indexon !~ m/^(pkg|maint|submitter)$/) {
     quit("You have to choose something to index on");
 }
 
 my $repeatmerged = ($param{'repeatmerged'} || "yes") eq "yes";
 my $archive = ($param{'archive'} || "no") eq "yes";
+my $sortby = $param{'sortby'} || 'alpha';
+if ($sortby !~ m/^(alpha|count)$/) {
+    quit("Don't know how to sort like that");
+}
+
 #my $include = $param{'include'} || "";
 #my $exclude = $param{'exclude'} || "";
 
@@ -104,7 +109,13 @@ if ($indexon eq "pkg") {
 }
 
 my $result = "<ul>\n";
-foreach my $x (sort { $sortkey{$a} cmp $sortkey{$b} } keys %count) {
+my @orderedentries;
+if ($sortby eq "count") {
+  @orderedentries = sort { $count{$a} <=> $count{$b} } keys %count;
+} else { # sortby alpha
+  @orderedentries = sort { $sortkey{$a} cmp $sortkey{$b} } keys %count;
+}
+foreach my $x (@orderedentries) {
   $result .= "<li>" . $htmldescrip{$x} . " has $count{$x} " .
             ($count{$x} == 1 ? "bug" : "bugs") . "</li>\n";
 }
-- 
2.39.5