]> xenbits.xensource.com Git - people/aperard/emesinae.git/commitdiff
Simple search in bugs.pl
authorIan Campbell <ijc@hellion.org.uk>
Sun, 25 Nov 2012 16:22:58 +0000 (16:22 +0000)
committerIan Campbell <ijc@hellion.org.uk>
Sun, 25 Nov 2012 16:22:58 +0000 (16:22 +0000)
Bugs/Bug.pm
CGI/bugs.pl
TODO

index ae8ed3bc3203e921a319a4facd571109c59aa661..7e200e21389b96bdb93acbfacc5572fa659eb4df 100644 (file)
@@ -182,13 +182,26 @@ sub messages {
     return map { $_->{Message} } values %refs;
 }
 
-sub listall ($$) {
+sub listall ($$;%) {
     my $class = shift;
     my $dbh   = shift;
+    my %args  = @_;
 
-    my $sth = $dbh->prepare( "
-       SELECT $SELECT_FIELDS FROM bugs ORDER BY id
-    " );
+    my @where;
+
+    if    ( $args{State} eq "Open" )   { push @where, qq(open = "true" ) }
+    elsif ( $args{State} eq "Closed" ) { push @where, qq(open = "false" ) }
+
+    if ( $args{Severities} ) {
+        push @where,
+          join( " OR ", map { qq{severity = "$_"} } @{ $args{Severities} } );
+    }
+    my $select = "SELECT $SELECT_FIELDS FROM bugs ";
+    $select .= "WHERE " . join( " AND ", map { qq{($_)} } @where ) if @where;
+    $select .= " ORDER BY id";
+
+    #print "<p>$select</p>";
+    my $sth = $dbh->prepare($select);
     $sth->execute();
     my @r;
     while ( my @row = $sth->fetchrow_array ) {
index 0dcf12e6410eb972d83236921187597ae60de969..e15aa282c1eb90f0346eab837d8881fe15c9c5aa 100755 (executable)
@@ -17,19 +17,24 @@ my $dbh = opendb;
 
 my $ml = htmlsanit( $c{ListAddress} );
 
-my @all_bugs = Bugs::Bug->listall($dbh);
-
 my @index;
 my $lists;
 
+# Parameter defaults.
+param('severityfilter')
+  || param( -name => 'severityfilter', -value => $c{SeverityLevels} );
+param('state') or param( -name => 'state', -default => "Open" );
+
+my @bugs;
+
 sub buglist ($$) {
     my $open = shift;
     my $sev  = shift;
 
     my @bugs =
-      grep { $_->{open} == $open and $_->{severity} eq $sev } @all_bugs;
+      grep { $_->{open} == $open and $_->{severity} eq $sev } @bugs;
 
-    return "" unless @bugs;
+    return unless @bugs;
 
     sub bug($) {
         return (
@@ -49,10 +54,6 @@ sub buglist ($$) {
     $lists .= "\n";
 }
 
-foreach my $open ( 1, 0 ) {
-    foreach my $sev ( @{ $c{SeverityLevels} } ) { buglist( $open, $sev ); }
-}
-
 print header;
 
 print start_html(
@@ -71,12 +72,58 @@ print p(
     ]
 ) . "\n";
 
-print hr . "\n";
+@bugs = Bugs::Bug->listall(
+    $dbh,
+    State      => param('state'),
+    Severities => [ param('severityfilter') ],
+);
+
+foreach my $open ( 1, 0 ) {
+    foreach my $sev ( @{ $c{SeverityLevels} } ) { buglist( $open, $sev ); }
+}
 
-print ul (@index);
+print ul (@index) if @index;
 
-print hr . "\n";
+if ( !$lists ) {
+    $lists = h1("No bugs match the criteria.");
+}
+print hr(), "\n", $lists, hr(), "\n";
+
+print h2("Search");
+
+print
+  start_form( -method => "POST" ),
+  table(
+    Tr(
+        [
+            td(
+                [
+                    "State:",
+                    popup_menu(
+                        -name   => 'state',
+                        -values => [ "Any", "Open", "Closed" ]
+                    )
+                ]
+            ),
+            td( [ "Title contains:", textfield('titlefilter') ] ),
+            td(
+                [
+                    "Severities:",
+                    join(
+                        "",
+                        checkbox_group(
+                            -name   => 'severityfilter',
+                            -values => $c{SeverityLevels}
+                        )
+                    )
+                ]
+            ),
+        ]
+    ),
+  ),
+  submit, "\n",
+  end_form,
+  hr, "\n";
 
-print $lists;
 print end_html;
 
diff --git a/TODO b/TODO
index e5701197695779aeca4c31426b294d82534c99ac..ae4766301ea84adf9a29346b5c7e98a6a84d2987 100644 (file)
--- a/TODO
+++ b/TODO
@@ -23,7 +23,7 @@ bug.pl:
 
 bugs.pl:
  - summary of the status of the bugs
- - search
+ - search -- double check for XSS
  - header to describe how to file a bug
 
 meta: