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') || 10;
56 my $branch = $input->param('branch') || '';
57 my $itemtype = $input->param('itemtype') || '';
58 my $timeLimit = $input->param('timeLimit') || 3;
59 my $advanced_search_types = C4
::Context
->preference('AdvancedSearchTypes');
62 $whereclause .= ' AND items.homebranch='.$dbh->quote($branch) if ($branch);
63 $whereclause .= ' AND TO_DAYS(NOW()) - TO_DAYS(biblio.datecreated) <= '.($timeLimit*30) if $timeLimit < 999;
64 $whereclause =~ s/ AND $// if $whereclause;
67 if($advanced_search_types eq 'ccode'){
68 $whereclause .= ' AND authorised_values.authorised_value='.$dbh->quote($itemtype) if $itemtype;
69 $query = "SELECT datecreated, biblio.biblionumber, title,
70 author, sum( items.issues ) AS tot, biblioitems.itemtype,
71 biblioitems.publishercode,biblioitems.publicationyear,
72 authorised_values.lib as description
74 LEFT JOIN items USING (biblionumber)
75 LEFT JOIN biblioitems USING (biblionumber)
76 LEFT JOIN authorised_values ON items.ccode = authorised_values.authorised_value
79 AND authorised_values.category = 'ccode'
80 GROUP BY biblio.biblionumber
85 $template->param(ccodesearch
=> 1);
88 if (C4
::Context
->preference('item-level_itypes')){
89 $whereclause .= ' AND items.itype = ' . $dbh->quote($itemtype);
92 $whereclause .= ' AND biblioitems.itemtype='.$dbh->quote($itemtype);
95 $query = "SELECT datecreated, biblio.biblionumber, title,
96 author, sum( items.issues ) AS tot, biblioitems.itemtype,
97 biblioitems.publishercode,biblioitems.publicationyear,
100 LEFT JOIN items USING (biblionumber)
101 LEFT JOIN biblioitems USING (biblionumber)
102 LEFT JOIN itemtypes ON itemtypes.itemtype = biblioitems.itemtype
105 GROUP BY biblio.biblionumber
110 $template->param(itemtypesearch
=> 1);
113 my $sth = $dbh->prepare($query);
116 while (my $line= $sth->fetchrow_hashref) {
117 push @results, $line;
120 my $timeLimitFinite = $timeLimit;
121 if($timeLimit eq 999){ $timeLimitFinite = 0 };
123 $template->param(do_it
=> 1,
125 branch
=> $branches->{$branch}->{branchname
},
126 itemtype
=> $itemtypes->{$itemtype}->{description
},
127 timeLimit
=> $timeLimit,
128 timeLimitFinite
=> $timeLimit,
129 results_loop
=> \
@results,
132 $template->param( branchloop
=> GetBranchesLoop
(C4
::Context
->userenv?C4
::Context
->userenv->{'branch'}:''));
134 # the index parameter is different for item-level itemtypes
135 my $itype_or_itemtype = (C4
::Context
->preference("item-level_itypes"))?
'itype':'itemtype';
136 $itemtypes = GetItemTypes
;
138 if (!$advanced_search_types or $advanced_search_types eq 'itemtypes') {
139 foreach my $thisitemtype ( sort {$itemtypes->{$a}->{'description'} cmp $itemtypes->{$b}->{'description'} } keys %$itemtypes ) {
140 my %row =( value
=> $thisitemtype,
141 description
=> $itemtypes->{$thisitemtype}->{'description'},
142 selected
=> $thisitemtype eq $itemtype,
144 push @itemtypesloop, \
%row;
147 my $advsearchtypes = GetAuthorisedValues
($advanced_search_types, '', 'opac');
148 for my $thisitemtype (@
$advsearchtypes) {
150 $selected = 1 if $thisitemtype->{authorised_value
} eq $itemtype;
151 my %row =( value
=> $thisitemtype->{authorised_value
},
152 selected
=> $thisitemtype eq $itemtype,
153 description
=> $thisitemtype->{'lib'},
155 push @itemtypesloop, \
%row;
160 itemtypeloop
=>\
@itemtypesloop,
162 output_html_with_http_headers
$input, $cookie, $template->output;