changeset 546:82f9cc69709e

Added a search function
author xi
date Fri, 30 Jun 2006 19:50:52 +1000
parents ecac9738ba4f
children ccba16f72354
files contrib/web/perl-admin/htdocs/subscribers.cgi contrib/web/perl-admin/templates/subscribers.html
diffstat 2 files changed, 31 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/contrib/web/perl-admin/htdocs/subscribers.cgi	Thu Jun 22 07:50:48 2006 +1000
+++ b/contrib/web/perl-admin/htdocs/subscribers.cgi	Fri Jun 30 19:50:52 2006 +1000
@@ -1,6 +1,6 @@
 #!/usr/bin/perl -w
 
-# Copyright (C) 2004 Christian Laursen <christian@pil.dk>
+# Copyright (C) 2004, 2005, 2006 Christian Laursen <christian@pil.dk>
 #
 # $Id$
 #
@@ -44,8 +44,22 @@
 
 my $q = new CGI;
 $list = $q->param("list");
-my $subscribe = $q->param("subscribe");
 my $update = $q->param("update");
+my $search = $q->param("search");
+my $email = $q->param("email");
+
+# Everything is submitted from the same form so a little hackery is needed
+# to pick the right action to perform. When doing subscribe and search we
+# don't depend on the submit buttons since hitting enter in either of the
+# text fields will pick the "Subscribe" button.
+#
+# If an email has been entered for subscription, clear the search field.
+
+if (defined $email && $email !~ /^$/) {
+	$search = undef;
+} else {
+	$email = undef;
+}
 
 die "no list specified" unless $list;
 die "non-existent list" unless -d("$topdir/$list");
@@ -57,8 +71,7 @@
 
 my $subscribers;
 
-if (defined $subscribe) {
-	my $email = $q->param("email");
+if (defined $email) {
 	my $subscriber = $q->param("subscriber");
 	my $digester = $q->param("digester");
 	my $nomailsub = $q->param("nomailsub");
@@ -135,7 +148,8 @@
 }
 
 $tpl->assign(LIST => encode_entities($list),
-			 MAXID => scalar(keys %$subscribers));
+			 MAXID => scalar(keys %$subscribers),
+			 SEARCH => defined $search ? $search : '');
 
 print "Content-type: text/html\n\n";
 
@@ -153,6 +167,12 @@
 	chomp @digesters;
 	chomp @nomailsubs;
 
+	if (defined $search) {
+		@subscribers = grep {index($_, $search) != -1} @subscribers;
+		@digesters = grep {index($_, $search) != -1} @digesters;
+		@nomailsubs = grep {index($_, $search) != -1} @nomailsubs;
+	}
+
 	for my $address (@subscribers) {
 		$subscribers{$address}->{subscriber} = 1;
 	}
--- a/contrib/web/perl-admin/templates/subscribers.html	Thu Jun 22 07:50:48 2006 +1000
+++ b/contrib/web/perl-admin/templates/subscribers.html	Fri Jun 30 19:50:52 2006 +1000
@@ -9,12 +9,16 @@
 <form action="subscribers.cgi" method="post">
 <input type="hidden" name="list" value="$LIST">
 <input type="hidden" name="maxid" value="$MAXID">
-<table><tr><td rowspan="4" valign="top">Add subscriber:&nbsp;&nbsp;</td>
+<table><tr><td rowspan="5" valign="top">Add subscriber:&nbsp;&nbsp;</td>
 <td>Email address: <input type="text" name="email"></td></tr>
 <tr><td>Normal subscriber: <input type="checkbox" name="subscriber" value="1" checked></td></tr>
 <tr><td>Digest subscriber: <input type="checkbox" name="digester" value="1"></td></tr>
 <tr><td>No-mail subscriber: <input type="checkbox" name="nomailsub" value="1"></td></tr>
-<tr><td>&nbsp;</td><td><input type="submit" name="subscribe" value="Subscribe"></td></tr>
+<tr><td><input type="submit" name="subscribe" value="Subscribe"></td></tr>
+
+<tr><td rowspan="2" valign="top">Search for subscriber:</td>
+<td>Email address: <input type="text" name="search" value="$SEARCH"></td></tr>
+<tr><td><input type="submit" name="searchsubmit" value="Search"></td></tr>
 </table>
 <hr>
 <table border="1">