4 # Copyright 2000-2002 Katipo Communications
5 # Parts Copyright Catalyst IT 2011
7 # This file is part of Koha.
9 # Koha is free software; you can redistribute it and/or modify it
10 # under the terms of the GNU General Public License as published by
11 # the Free Software Foundation; either version 3 of the License, or
12 # (at your option) any later version.
14 # Koha is distributed in the hope that it will be useful, but
15 # WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 # GNU General Public License for more details.
19 # You should have received a copy of the GNU General Public License
20 # along with Koha; if not, see <http://www.gnu.org/licenses>.
36 plugin that shows a stats on borrowers
44 # if OpacTopissue is disabled, leave immediately
45 if ( ! C4
::Context
->preference('OpacTopissue') ) {
46 print $input->redirect("/cgi-bin/koha/errors/404.pl");
50 my $branches = GetBranches
();
51 my $itemtypes = GetItemTypes
();
53 my ($template, $borrowernumber, $cookie) = get_template_and_user
(
55 template_name
=> 'opac-topissues.tt',
58 authnotrequired
=> ( C4
::Context
->preference("OpacPublic") ?
1 : 0 ),
62 my $dbh = C4
::Context
->dbh;
64 my $do_it = $input->param('do_it') || 0; # as form been posted
65 my $limit = $input->param('limit');
66 $limit = 10 unless ($limit && $limit =~ /^\d+$/); # control user input for SQL query
67 $limit = 100 if $limit > 100;
68 my $branch = $input->param('branch') || '';
69 if (!$do_it && C4
::Context
->userenv && C4
::Context
->userenv->{'branch'} ) {
70 $branch = C4
::Context
->userenv->{'branch'}; # select user branch by default
72 my $itemtype = $input->param('itemtype') || '';
73 my $timeLimit = $input->param('timeLimit') || 3;
74 my $advanced_search_types = C4
::Context
->preference('AdvancedSearchTypes');
77 $whereclause .= ' AND items.homebranch='.$dbh->quote($branch) if ($branch);
78 $whereclause .= ' AND TO_DAYS(NOW()) - TO_DAYS(biblio.datecreated) <= '.($timeLimit*30) if $timeLimit < 999;
79 $whereclause =~ s/ AND $// if $whereclause;
82 if($advanced_search_types eq 'ccode'){
83 $whereclause .= ' AND authorised_values.authorised_value='.$dbh->quote($itemtype) if $itemtype;
84 $query = "SELECT datecreated, biblio.biblionumber, title,
85 author, sum( items.issues ) AS tot, biblioitems.itemtype,
86 biblioitems.publishercode, biblioitems.place, biblioitems.publicationyear, biblio.copyrightdate,
87 authorised_values.lib as description, biblioitems.pages, biblioitems.size
89 LEFT JOIN items USING (biblionumber)
90 LEFT JOIN biblioitems USING (biblionumber)
91 LEFT JOIN authorised_values ON items.ccode = authorised_values.authorised_value
94 AND authorised_values.category = 'ccode'
95 GROUP BY biblio.biblionumber
100 $template->param(ccodesearch
=> 1);
103 if (C4
::Context
->preference('item-level_itypes')){
104 $whereclause .= ' AND items.itype = ' . $dbh->quote($itemtype);
107 $whereclause .= ' AND biblioitems.itemtype='.$dbh->quote($itemtype);
110 $query = "SELECT datecreated, biblio.biblionumber, title,
111 author, sum( items.issues ) AS tot, biblioitems.itemtype,
112 biblioitems.publishercode, biblioitems.place, biblioitems.publicationyear, biblio.copyrightdate,
113 itemtypes.description, biblioitems.pages, biblioitems.size
115 LEFT JOIN items USING (biblionumber)
116 LEFT JOIN biblioitems USING (biblionumber)
117 LEFT JOIN itemtypes ON itemtypes.itemtype = biblioitems.itemtype
120 GROUP BY biblio.biblionumber
125 $template->param(itemtypesearch
=> 1);
128 my $sth = $dbh->prepare($query);
129 $sth->execute($limit);
131 while (my $line= $sth->fetchrow_hashref) {
132 push @results, $line;
135 my $timeLimitFinite = $timeLimit;
136 if($timeLimit eq 999){ $timeLimitFinite = 0 };
138 $template->param(do_it
=> 1,
140 branch
=> $branches->{$branch}->{branchname
},
141 itemtype
=> $itemtypes->{$itemtype}->{description
},
142 timeLimit
=> $timeLimit,
143 timeLimitFinite
=> $timeLimitFinite,
144 results_loop
=> \
@results,
147 $template->param( branchloop
=> GetBranchesLoop
($branch));
149 # the index parameter is different for item-level itemtypes
150 my $itype_or_itemtype = (C4
::Context
->preference("item-level_itypes"))?
'itype':'itemtype';
151 $itemtypes = GetItemTypes
;
153 if (!$advanced_search_types or $advanced_search_types eq 'itemtypes') {
154 foreach my $thisitemtype ( sort {$itemtypes->{$a}->{'description'} cmp $itemtypes->{$b}->{'description'} } keys %$itemtypes ) {
155 my %row =( value
=> $thisitemtype,
156 description
=> $itemtypes->{$thisitemtype}->{'description'},
157 selected
=> $thisitemtype eq $itemtype,
159 push @itemtypesloop, \
%row;
162 my $advsearchtypes = GetAuthorisedValues
($advanced_search_types, '', 'opac');
163 for my $thisitemtype (@
$advsearchtypes) {
165 $selected = 1 if $thisitemtype->{authorised_value
} eq $itemtype;
166 my %row =( value
=> $thisitemtype->{authorised_value
},
167 selected
=> $thisitemtype eq $itemtype,
168 description
=> $thisitemtype->{'lib'},
170 push @itemtypesloop, \
%row;
175 itemtypeloop
=>\
@itemtypesloop,
177 output_html_with_http_headers
$input, $cookie, $template->output;