Bug 3452: Additional patch that expands the branch name and category code in Suggesti...
[koha_fer] / opac / opac-topissues.pl
index c0c26c8..3371d1d 100755 (executable)
@@ -1,6 +1,5 @@
 #!/usr/bin/perl
 
-# $Id$
 
 # Copyright 2000-2002 Katipo Communications
 #
 # Suite 330, Boston, MA  02111-1307 USA
 
 use strict;
-use C4::Auth;
 use CGI;
+use C4::Auth;
 use C4::Context;
 use C4::Search;
 use C4::Output;
 use C4::Koha;
 use C4::Branch;
-use C4::Interface::CGI::Output;
 use Date::Manip;
 
 =head1 NAME
@@ -36,8 +34,7 @@ plugin that shows a stats on borrowers
 
 =head1 DESCRIPTION
 
-
-=over2
+=over 2
 
 =cut
 
@@ -59,12 +56,13 @@ my $branch = $input->param('branch');
 my $itemtype = $input->param('itemtype');
 my $timeLimit = $input->param('timeLimit') || 3;
 my $whereclause;
-$whereclause .= 'items.homebranch='.$dbh->quote($branch)." AND " if ($branch); 
+$whereclause .= 'items.homebranch='.$dbh->quote($branch)." AND " if ($branch);
 $whereclause .= 'biblioitems.itemtype='.$dbh->quote($itemtype)." AND " if $itemtype;
-$whereclause .= 'TO_DAYS(NOW()) - TO_DAYS(biblio.timestamp) <= '.$timeLimit*30 if $timeLimit;
+$whereclause .= ' TO_DAYS(NOW()) - TO_DAYS(biblio.datecreated) <= '.($timeLimit*30).' AND ' if $timeLimit < 999;
 $whereclause =~ s/ AND $//;
 $whereclause = " WHERE ".$whereclause if $whereclause;
-my $query = "SELECT biblio.timestamp, biblio.biblionumber, title, 
+
+my $query = "SELECT datecreated, biblio.biblionumber, title, 
                 author, sum( items.issues ) AS tot, biblioitems.itemtype,
                 biblioitems.publishercode,biblioitems.publicationyear,
                 itemtypes.description
@@ -74,6 +72,7 @@ my $query = "SELECT biblio.timestamp, biblio.biblionumber, title,
                 LEFT JOIN itemtypes ON itemtypes.itemtype = biblioitems.itemtype
                 $whereclause
                 GROUP BY biblio.biblionumber
+                HAVING tot >0
                 ORDER BY tot DESC
                 LIMIT $limit
                 ";
@@ -85,6 +84,8 @@ while (my $line= $sth->fetchrow_hashref) {
     push @results, $line;
 }
 
+if($timeLimit eq 999){ $timeLimit = 0 };
+
 $template->param(do_it => 1,
                 limit => $limit,
                 branch => $branches->{$branch}->{branchname},
@@ -93,17 +94,22 @@ $template->param(do_it => 1,
                 results_loop => \@results,
                 );
 
-my $branches = GetBranches;
-my @branchloop;
-foreach my $thisbranch (keys %$branches) {
-        my %row =(value => $thisbranch,
-                    branchname => $branches->{$thisbranch}->{'branchname'},
-                        );
-        push @branchloop, \%row;
+# load the branches            ## again??
+$branches = GetBranches();
+my @branch_loop;
+for my $branch_hash (sort keys %$branches ) {
+    my $selected=(C4::Context->userenv && ($branch_hash eq C4::Context->userenv->{branch})) if (C4::Context->preference('SearchMyLibraryFirst'));
+    push @branch_loop,
+      {
+        value      => "$branch_hash",
+        branchname => $branches->{$branch_hash}->{'branchname'},
+        selected => $selected
+      };
 }
+$template->param( branchloop => \@branch_loop, "mylibraryfirst"=>C4::Context->preference("SearchMyLibraryFirst"));
 
 #doctype
-my $itemtypes = GetItemTypes;
+$itemtypes = GetItemTypes;
 my @itemtypeloop;
 foreach my $thisitemtype (keys %$itemtypes) {
         my %row =(value => $thisitemtype,
@@ -113,8 +119,8 @@ foreach my $thisitemtype (keys %$itemtypes) {
 }
 
 $template->param(
-                branchloop =>\@branchloop,
-                itemtypeloop =>\@itemtypeloop,
+                 itemtypeloop =>\@itemtypeloop,
+                 dateformat    => C4::Context->preference("dateformat"),
                 );
 output_html_with_http_headers $input, $cookie, $template->output;