#!/usr/bin/perl
-# $Id$
# Copyright 2000-2002 Katipo Communications
#
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
LEFT JOIN itemtypes ON itemtypes.itemtype = biblioitems.itemtype
$whereclause
GROUP BY biblio.biblionumber
+ HAVING tot >0
ORDER BY tot DESC
LIMIT $limit
";
# load the branches
my $branches = GetBranches();
my @branch_loop;
-for my $branch_hash ( keys %$branches ) {
+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: $branch_hash",
+ value => "$branch_hash",
branchname => $branches->{$branch_hash}->{'branchname'},
selected => $selected
};