fix input selection with operators
[webpac2] / vhost / webpac2.cgi
index 8b9d844..f09b0e4 100755 (executable)
@@ -142,13 +142,8 @@ my @style = ( '../../style.css' );
 push @style, "../../$path/$path.css" if -e "$dir/$path/$path.css";
 dump_yaml( 'style', \@style );
 
-print
-       start_html(
-               -title => $db->{name},
-               -style => [ @style ],
-       ),
-       h1( $db->{name} ),
-       qq|<div id=description>|, $db->{description}, qq|</div>|,
+sub search_form {
+       qq|<a name="form"></a>|,
        start_form( -action => self_url( query => 0 ) ),
                radio_group(
                        -name => 'attr',
@@ -170,14 +165,26 @@ print
                        -linebreak=> 'true',
                ),
                qq|</div>|,
+               end_form,
+       ;
+}
 
-;
 
-print  end_form;
+print
+       start_html(
+               -title => $db->{name},
+               -style => [ @style ],
+       ),
+       h1( $db->{name} ),
+       qq|<div id=description>|, $db->{description}, qq|</div>|,
+;
 
 if ( my $search = param('search') ) {
 
-       print qq|<div id="results">|;
+       print qq|
+               <a href="#form" class="skip" title="skip to search form">#</a>
+               <div id="results">
+       |;
 
        my $swish = SWISH::API->new( "$dir/../var/swish/$database" );
        $swish->abort_last_error if $swish->Error;
@@ -202,12 +209,18 @@ if ( my $search = param('search') ) {
                                $attr . '="' . $template . '"';
                                ;
                };
-               $v =~ s{(\s*)(\S+)}{rewrite($1,$2)}ge;
+               if ( $op =~ m{\s} ) {
+                       my $template = $op;
+                          $template =~ s{Q}{$v};
+                       $v = $attr . '="' . $template . '"';
+               } else {
+                       $v =~ s{(\s*)(\S+)}{rewrite($1,$2)}ge;
+               }
 
                push @search, $v;
        
                my @only_input = param('only_input');
-               push @search, '(' . join(') OR (', map { "input=$_" } @only_input) . ')' if @only_input;
+               push @search, '((' . join(') OR (', map { "input=\"$_\"" } @only_input) . '))' if @only_input;
        } else {
                push @search, "all=\"$search\"";
        }
@@ -245,13 +258,17 @@ if ( my $search = param('search') ) {
 
                my $limit = $pager->entries_on_this_page;
 
+               my $nr = 1;
+
                while ( my $result = $swish_results->next_result ) {
 
                        my $data = from_json $result->property('data');
 
                        dump_yaml( 'data', $data );
 
-                       print qq|<li>|;
+                       my $li_class = '';
+                       $li_class = qq| class="z"| if $nr % 2 == 0;
+                       print qq|<li$li_class>|;
                        foreach my $attr ( @attr ) {
                                next unless defined $data->{$attr};
                                my $v = $data->{$attr};
@@ -279,6 +296,8 @@ if ( my $search = param('search') ) {
 
 }
 
+print search_form;
+
 dump_yaml( "config databases $database", $db );
 dump_yaml( 'html_markup_skip', $html_markup_skip );