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 under the
10 # terms of the GNU General Public License as published by the Free Software
11 # Foundation; either version 2 of the License, or (at your option) any later
14 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
15 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
16 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License along
19 # with Koha; if not, write to the Free Software Foundation, Inc.,
20 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
36 plugin that shows a stats on borrowers
43 my $branches = GetBranches();
44 my $itemtypes = GetItemTypes();
46 my ($template, $borrowernumber, $cookie)
47 = get_template_and_user({template_name => 'opac-topissues.tmpl',
50 authnotrequired => ( C4::Context->preference("OpacPublic") ? 1 : 0 ),
53 my $dbh = C4::Context->dbh;
55 my $limit = $input->param('limit');
56 $limit = 10 unless ($limit && $limit =~ /^\d+$/); # control user input for SQL query
57 $limit = 100 if $limit > 100;
58 my $branch = $input->param('branch') || '';
59 my $itemtype = $input->param('itemtype') || '';
60 my $timeLimit = $input->param('timeLimit') || 3;
61 my $advanced_search_types = C4::Context->preference('AdvancedSearchTypes');
64 $whereclause .= ' AND items.homebranch='.$dbh->quote($branch) if ($branch);
65 $whereclause .= ' AND TO_DAYS(NOW()) - TO_DAYS(biblio.datecreated) <= '.($timeLimit*30) if $timeLimit < 999;
66 $whereclause =~ s/ AND $// if $whereclause;
69 if($advanced_search_types eq 'ccode'){
70 $whereclause .= ' AND authorised_values.authorised_value='.$dbh->quote($itemtype) if $itemtype;
71 $query = "SELECT datecreated, biblio.biblionumber, title,
72 author, sum( items.issues ) AS tot, biblioitems.itemtype,
73 biblioitems.publishercode,biblioitems.publicationyear,
74 authorised_values.lib as description
76 LEFT JOIN items USING (biblionumber)
77 LEFT JOIN biblioitems USING (biblionumber)
78 LEFT JOIN authorised_values ON items.ccode = authorised_values.authorised_value
81 AND authorised_values.category = 'ccode'
82 GROUP BY biblio.biblionumber
87 $template->param(ccodesearch => 1);
90 if (C4::Context->preference('item-level_itypes')){
91 $whereclause .= ' AND items.itype = ' . $dbh->quote($itemtype);
94 $whereclause .= ' AND biblioitems.itemtype='.$dbh->quote($itemtype);
97 $query = "SELECT datecreated, biblio.biblionumber, title,
98 author, sum( items.issues ) AS tot, biblioitems.itemtype,
99 biblioitems.publishercode,biblioitems.publicationyear,
100 itemtypes.description
102 LEFT JOIN items USING (biblionumber)
103 LEFT JOIN biblioitems USING (biblionumber)
104 LEFT JOIN itemtypes ON itemtypes.itemtype = biblioitems.itemtype
107 GROUP BY biblio.biblionumber
112 $template->param(itemtypesearch => 1);
115 my $sth = $dbh->prepare($query);
116 $sth->execute($limit);
118 while (my $line= $sth->fetchrow_hashref) {
119 push @results, $line;
122 my $timeLimitFinite = $timeLimit;
123 if($timeLimit eq 999){ $timeLimitFinite = 0 };
125 $template->param(do_it => 1,
127 branch => $branches->{$branch}->{branchname},
128 itemtype => $itemtypes->{$itemtype}->{description},
129 timeLimit => $timeLimit,
130 timeLimitFinite => $timeLimitFinite,
131 results_loop => \@results,
134 $template->param( branchloop => GetBranchesLoop(C4::Context->userenv?C4::Context->userenv->{'branch'}:''));
136 # the index parameter is different for item-level itemtypes
137 my $itype_or_itemtype = (C4::Context->preference("item-level_itypes"))?'itype':'itemtype';
138 $itemtypes = GetItemTypes;
140 if (!$advanced_search_types or $advanced_search_types eq 'itemtypes') {
141 foreach my $thisitemtype ( sort {$itemtypes->{$a}->{'description'} cmp $itemtypes->{$b}->{'description'} } keys %$itemtypes ) {
142 my %row =( value => $thisitemtype,
143 description => $itemtypes->{$thisitemtype}->{'description'},
144 selected => $thisitemtype eq $itemtype,
146 push @itemtypesloop, \%row;
149 my $advsearchtypes = GetAuthorisedValues($advanced_search_types, '', 'opac');
150 for my $thisitemtype (@$advsearchtypes) {
152 $selected = 1 if $thisitemtype->{authorised_value} eq $itemtype;
153 my %row =( value => $thisitemtype->{authorised_value},
154 selected => $thisitemtype eq $itemtype,
155 description => $thisitemtype->{'lib'},
157 push @itemtypesloop, \%row;
162 itemtypeloop =>\@itemtypesloop,
164 output_html_with_http_headers $input, $cookie, $template->output;