(bug #4363) Fix subscription search error when no results
authorJean-André Santoni <jeanandre.santoni@biblibre.com>
Tue, 24 Aug 2010 12:48:46 +0000 (14:48 +0200)
committerColin Campbell <colin.campbell@ptfs-europe.com>
Wed, 15 Dec 2010 12:52:09 +0000 (12:52 +0000)
There was a template param assignment before template is loaded.

Signed-off-by: Colin Campbell <colin.campbell@ptfs-europe.com>
serials/subscription-bib-search.pl

index d1b0f63..ab7ab80 100755 (executable)
@@ -76,6 +76,16 @@ my $query = $input->param('q');
 # don't run the search if no search term !
 if ($op eq "do_search" && $query) {
 
+    ( $template, $loggedinuser, $cookie ) = get_template_and_user(
+        {   template_name   => "serials/result.tmpl",
+            query           => $input,
+            type            => "intranet",
+            authnotrequired => 0,
+            flagsrequired => {catalogue => 1, serials => '*'},
+            debug           => 1,
+        }
+    );
+
     # add the itemtype limit if applicable
     my $itemtypelimit = $input->param('itemtypelimit');
     if ( $itemtypelimit ) {
@@ -90,7 +100,10 @@ if ($op eq "do_search" && $query) {
     $resultsperpage = 20 if(!defined $resultsperpage);
 
     my ($error, $marcrecords, $total_hits) = SimpleSearch($query, $startfrom*$resultsperpage, $resultsperpage);
-    my $total = scalar @$marcrecords;
+    my $total = 0;
+    if (defined $marcrecords ) {
+        $total = scalar @{$marcrecords};
+    }
 
     if (defined $error) {
         $template->param(query_error => $error);
@@ -117,15 +130,6 @@ if ($op eq "do_search" && $query) {
         push @results, \%resultsloop;
     }
 
-    ($template, $loggedinuser, $cookie)
-        = get_template_and_user({template_name => "serials/result.tmpl",
-                query => $input,
-                type => "intranet",
-                authnotrequired => 0,
-                flagsrequired => {catalogue => 1, serials => '*'},
-                debug => 1,
-                });
-
     # multi page display gestion
     my $displaynext=0;
     my $displayprev=$startfrom;
@@ -223,15 +227,6 @@ else {
        }
     }
 
-    ($template, $loggedinuser, $cookie)
-        = get_template_and_user({template_name => "serials/subscription-bib-search.tmpl",
-                query => $input,
-                type => "intranet",
-                authnotrequired => 0,
-                flagsrequired => {catalogue => 1, serials => '*'},
-                debug => 1,
-                });
-
 
     if ($op eq "do_search") {
        $template->param("no_query" => 1);