X-Git-Url: http://koha-dev.rot13.org:8081/gitweb/?a=blobdiff_plain;f=opac%2Fopac-topissues.pl;h=0afc69221c79fba9e699cd769db18ef217dc3c17;hb=6310c992bf23d164f013ead7c0b2182226279454;hp=6899215cc7cb9cd40d44e074faf8cd1e571ca3fd;hpb=6be9d2b27dd47c859eb6ab0cfd873b2059206986;p=koha_fer diff --git a/opac/opac-topissues.pl b/opac/opac-topissues.pl index 6899215cc7..0afc69221c 100755 --- a/opac/opac-topissues.pl +++ b/opac/opac-topissues.pl @@ -2,6 +2,7 @@ # Copyright 2000-2002 Katipo Communications +# Parts Copyright Catalyst IT 2011 # # This file is part of Koha. # @@ -39,6 +40,13 @@ plugin that shows a stats on borrowers =cut my $input = new CGI; + +# if OpacTopissue is disabled, leave immediately +if ( ! C4::Context->preference('OpacTopissue') ) { + print $input->redirect("/cgi-bin/koha/errors/404.pl"); + exit; +} + my $branches = GetBranches(); my $itemtypes = GetItemTypes(); @@ -51,8 +59,14 @@ my ($template, $borrowernumber, $cookie) }); my $dbh = C4::Context->dbh; # Displaying results -my $limit = $input->param('limit') || 10; +my $do_it = $input->param('do_it') || 0; # as form been posted +my $limit = $input->param('limit'); +$limit = 10 unless ($limit && $limit =~ /^\d+$/); # control user input for SQL query +$limit = 100 if $limit > 100; my $branch = $input->param('branch') || ''; +if (!$do_it && C4::Context->userenv && C4::Context->userenv->{'branch'} ) { + $branch = C4::Context->userenv->{'branch'}; # select user branch by default +} my $itemtype = $input->param('itemtype') || ''; my $timeLimit = $input->param('timeLimit') || 3; my $advanced_search_types = C4::Context->preference('AdvancedSearchTypes'); @@ -67,8 +81,8 @@ if($advanced_search_types eq 'ccode'){ $whereclause .= ' AND authorised_values.authorised_value='.$dbh->quote($itemtype) if $itemtype; $query = "SELECT datecreated, biblio.biblionumber, title, author, sum( items.issues ) AS tot, biblioitems.itemtype, - biblioitems.publishercode,biblioitems.publicationyear, - authorised_values.lib as description + biblioitems.publishercode, biblioitems.place, biblioitems.publicationyear, biblio.copyrightdate, + authorised_values.lib as description, biblioitems.pages, biblioitems.size FROM biblio LEFT JOIN items USING (biblionumber) LEFT JOIN biblioitems USING (biblionumber) @@ -79,15 +93,22 @@ if($advanced_search_types eq 'ccode'){ GROUP BY biblio.biblionumber HAVING tot >0 ORDER BY tot DESC - LIMIT $limit + LIMIT ? "; $template->param(ccodesearch => 1); }else{ - $whereclause .= ' AND biblioitems.itemtype='.$dbh->quote($itemtype) if $itemtype; + if ($itemtype){ + if (C4::Context->preference('item-level_itypes')){ + $whereclause .= ' AND items.itype = ' . $dbh->quote($itemtype); + } + else { + $whereclause .= ' AND biblioitems.itemtype='.$dbh->quote($itemtype); + } + } $query = "SELECT datecreated, biblio.biblionumber, title, author, sum( items.issues ) AS tot, biblioitems.itemtype, - biblioitems.publishercode,biblioitems.publicationyear, - itemtypes.description + biblioitems.publishercode, biblioitems.place, biblioitems.publicationyear, biblio.copyrightdate, + itemtypes.description, biblioitems.pages, biblioitems.size FROM biblio LEFT JOIN items USING (biblionumber) LEFT JOIN biblioitems USING (biblionumber) @@ -97,13 +118,13 @@ if($advanced_search_types eq 'ccode'){ GROUP BY biblio.biblionumber HAVING tot >0 ORDER BY tot DESC - LIMIT $limit + LIMIT ? "; $template->param(itemtypesearch => 1); } my $sth = $dbh->prepare($query); -$sth->execute(); +$sth->execute($limit); my @results; while (my $line= $sth->fetchrow_hashref) { push @results, $line; @@ -114,14 +135,14 @@ if($timeLimit eq 999){ $timeLimitFinite = 0 }; $template->param(do_it => 1, limit => $limit, - branch => $branches->{$branch}->{branchname} || 'all locations', - itemtype => $itemtypes->{$itemtype}->{description} || 'item types', + branch => $branches->{$branch}->{branchname}, + itemtype => $itemtypes->{$itemtype}->{description}, timeLimit => $timeLimit, - timeLimitFinite => $timeLimit, + timeLimitFinite => $timeLimitFinite, results_loop => \@results, ); -$template->param( branchloop => GetBranchesLoop(C4::Context->userenv->{'branch'})); +$template->param( branchloop => GetBranchesLoop($branch)); # the index parameter is different for item-level itemtypes my $itype_or_itemtype = (C4::Context->preference("item-level_itypes"))?'itype':'itemtype'; @@ -138,7 +159,8 @@ if (!$advanced_search_types or $advanced_search_types eq 'itemtypes') { } else { my $advsearchtypes = GetAuthorisedValues($advanced_search_types, '', 'opac'); for my $thisitemtype (@$advsearchtypes) { - my $selected = 1 if $thisitemtype->{authorised_value} eq $itemtype; + my $selected; + $selected = 1 if $thisitemtype->{authorised_value} eq $itemtype; my %row =( value => $thisitemtype->{authorised_value}, selected => $thisitemtype eq $itemtype, description => $thisitemtype->{'lib'}, @@ -149,7 +171,6 @@ if (!$advanced_search_types or $advanced_search_types eq 'itemtypes') { $template->param( itemtypeloop =>\@itemtypesloop, - dateformat => C4::Context->preference("dateformat"), ); output_html_with_http_headers $input, $cookie, $template->output;