adding query_inputs to build the query as a set of hidden inputs
authorJoshua Ferraro <jmf@liblime.com>
Wed, 21 Nov 2007 23:57:16 +0000 (17:57 -0600)
committerJoshua Ferraro <jmf@liblime.com>
Thu, 22 Nov 2007 00:08:31 +0000 (18:08 -0600)
Signed-off-by: Chris Cormack <crc@liblime.com>
Signed-off-by: Joshua Ferraro <jmf@liblime.com>
C4/Search.pm
catalogue/search.pl
koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/results.tmpl

index ad7a9b7..b84a528 100644 (file)
@@ -702,7 +702,7 @@ sub buildQuery {
     }
 
 # FIXME: this is bound to be broken now
-    if ( $query =~ /(\(|\)|:|=)/ ) {    # sorry, too complex, assume CCL
+    if ( $query =~ /(\(|\))/ ) {    # sorry, too complex, assume CCL
         return ( undef, $query, $query_cgi, $query_search_desc, $limit, $limit_cgi, $limit_desc, 'ccl' );
     }
 
@@ -719,7 +719,13 @@ sub buildQuery {
 
             # COMBINE OPERANDS, INDEXES AND OPERATORS
             if ( $operands[$i] ) {
+
+                               $weight_fields = 0 if $operands[$i] =~ /(:|=)/;
                 my $operand = $operands[$i];
+
+                               my $sanatized_operand = $operands[$i];
+                               $sanatized_operand =~ s/://g;
+
                 my $index   = $indexes[$i];
 
                 # if there's no index, don't use one, it will throw a CCL error
@@ -788,7 +794,7 @@ sub buildQuery {
                         $query .= " $operand";
                                                $query_cgi .="&op=$operators[$i-1]";
                                                $query_cgi .="&idx=$index" if $index;
-                                               $query_cgi .="&q=$operands[$i]" if $operand;
+                                               $query_cgi .="&q=$sanatized_operand" if $sanatized_operand;
                                                $query_search_desc .=" $operators[$i-1] $index_plus $operands[$i]";
                     }
 
@@ -798,7 +804,7 @@ sub buildQuery {
                         $query .= "$index_plus " unless $indexes_set;
                         $query .= "$operand";
                                                $query_cgi .="&op=and&idx=$index" if $index;
-                                               $query_cgi .="&q=$operands[$i]" if $operand;
+                                               $query_cgi .="&q=$sanatized_operand" if $sanatized_operand;
                         $query_search_desc .= " and $index_plus $operands[$i]";
                     }
                 }
@@ -809,7 +815,7 @@ sub buildQuery {
                                        $query .= $operand;
                                        $query_search_desc .= " $index_plus $operands[$i]";
                                        $query_cgi.="&idx=$index" if $index;
-                                       $query_cgi.="&q=$operands[$i]" if $operand;
+                                       $query_cgi.="&q=$sanatized_operand" if $sanatized_operand;
 
                     $previous_operand = 1;
                 }
index 6fa3d8a..9329f99 100755 (executable)
@@ -335,10 +335,9 @@ my $params = $cgi->Vars;
 
 # Params that can have more than one value
 # sort by is used to sort the query
+# in theory can have more than one but generally there's just one
 my @sort_by;
 @sort_by = split("\0",$params->{'sort_by'}) if $params->{'sort_by'};
-
-# FIXME: this is a quick hack
 foreach my $sort (@sort_by) {
        $template->param($sort => 1);
 }
@@ -402,6 +401,30 @@ my @results;
 ## I. BUILD THE QUERY
 ( $error,$query,$simple_query,$query_cgi,$query_search_desc,$limit,$limit_cgi,$limit_desc,$query_type) = buildQuery(\@operators,\@operands,\@indexes,\@limits,\@sort_by);
 
+## parse the query_cgi string and put it into a form suitable for <input>s
+my @query_inputs;
+for my $this_cgi ( split('&',$query_cgi) ) {
+       next unless $this_cgi;
+       $this_cgi =~ m/(.*=)(.*)/;
+       my $input_name = $1;
+       my $input_value = $2;
+       $input_name =~ s/=$//;
+       push @query_inputs, { input_name => $input_name, input_value => $input_value };
+}
+$template->param ( QUERY_INPUTS => \@query_inputs );
+
+## parse the limit_cgi string and put it into a form suitable for <input>s
+my @limit_inputs;
+for my $this_cgi ( split('&',$limit_cgi) ) {
+       next unless $this_cgi;
+    $this_cgi =~ m/(.*=)(.*)/;
+    my $input_name = $1;
+    my $input_value = $2;
+    $input_name =~ s/=$//;
+    push @limit_inputs, { input_name => $input_name, input_value => $input_value };
+}
+$template->param ( LIMIT_INPUTS => \@limit_inputs );
+
 ## II. DO THE SEARCH AND GET THE RESULTS
 my $total; # the total results for the whole set
 my $facets; # this object stores the faceted results that display on the left-hand of the results page
index 66c5f8a..4060533 100644 (file)
             <div id="searchresults">
                                <form action="/cgi-bin/koha/catalogue/search.pl" method="get" name="myform" id="mainform">
                 <!-- TMPL_IF NAME="searchdesc" -->
-                    <input type="hidden" name="q" value="<!-- TMPL_VAR NAME="searchdesc" escape="html" -->" />
+                                       <!-- TMPL_LOOP NAME="QUERY_INPUTS"-->
+                                       <input type="hidden" name="<!-- TMPL_VAR NAME="input_name" -->" value="<!-- TMPL_VAR NAME="input_value" -->"/>
+                                       <!-- /TMPL_LOOP -->
+                                       <!-- TMPL_LOOP NAME="LIMIT_INPUTS"-->
+                                       <input type="hidden" name="<!-- TMPL_VAR NAME="input_name" -->" value="<!-- TMPL_VAR NAME="input_value" -->"/>
+                    <!-- /TMPL_LOOP -->
+
+
                 <!-- /TMPL_IF -->
                                <!-- RE-SORT START -->
                     <p>