4 # Copyright 2000-2002 Katipo Communications
6 # This file is part of Koha.
8 # Koha is free software; you can redistribute it and/or modify it under the
9 # terms of the GNU General Public License as published by the Free Software
10 # Foundation; either version 2 of the License, or (at your option) any later
13 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
14 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
15 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License along with
18 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
19 # Suite 330, Boston, MA 02111-1307 USA
30 my $type = $input->param('type');
32 my $theme = $input->param('theme'); # only used if allowthemeoverride is set
33 my $order=$input->param('order');
34 my $bornamefilter=$input->param('borname');
35 my $borcatfilter=$input->param('borcat');
36 my $itemtypefilter=$input->param('itemtype');
37 my $borflagsfilter=$input->param('borflags') || " ";
38 my $branchfilter=$input->param('branch');
39 my $showall=$input->param('showall');
40 my $theme = $input->param('theme'); # only used if allowthemeoverride is set
43 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
45 template_name => "circ/overdue.tmpl",
49 flagsrequired => { reports => 1, circulate => 1 },
53 my $dbh = C4::Context->dbh;
56 $req = $dbh->prepare( "select categorycode, description from categories order by description");
59 while (my ($catcode, $description) =$req->fetchrow) {
60 my $selected = 1 if $catcode eq $borcatfilter;
61 my %row =(value => $catcode,
62 selected => $selected,
63 catname => $description,
65 push @borcatloop, \%row;
68 $req = $dbh->prepare( "select itemtype, description from itemtypes order by description");
71 while (my ($itemtype, $description) =$req->fetchrow) {
72 my $selected = 1 if $itemtype eq $itemtypefilter;
73 my %row =(value => $itemtype,
74 selected => $selected,
75 itemtypename => $description,
77 push @itemtypeloop, \%row;
79 my $onlymine=C4::Context->preference('IndependantBranches') &&
80 C4::Context->userenv &&
81 C4::Context->userenv->{flags}!=1 &&
82 C4::Context->userenv->{branch};
83 my $branches = GetBranches($onlymine);
86 push @selectflags, " ";#
87 push @selectflags,"gonenoaddress";#
88 push @selectflags,"debarred";#
89 push @selectflags,"lost";#
90 my $CGIflags=CGI::scrolling_list( -name => 'borflags',
92 -values => \@selectflags,
96 foreach my $thisbranch ( sort keys %$branches ) {
99 branchname => $branches->{$thisbranch}->{'branchname'},
100 selected => (C4::Context->userenv && $branches->{$thisbranch}->{'branchcode'} eq C4::Context->userenv->{'branch'})
102 push @branchloop, \%row;
104 $branchfilter=C4::Context->userenv->{'branch'} if ($onlymine && !$branchfilter);
106 $template->param( branchloop => \@branchloop );
107 $template->param(borcatloop=> \@borcatloop,
108 itemtypeloop => \@itemtypeloop,
109 branchloop=> \@branchloop,
110 CGIflags => $CGIflags,
111 borname => $bornamefilter,
113 showall => $showall);
127 my @datearr = localtime( time() );
129 ( 1900 + $datearr[5] ) . '-'
130 . sprintf( "%0.2d", ( $datearr[4] + 1 ) ) . '-'
131 . sprintf( "%0.2d", $datearr[3] );
134 $bornamefilter =~s/\*/\%/g;
135 $bornamefilter =~s/\?/\_/g;
137 my $strsth="select date_due,concat(surname,' ', firstname) as borrower,
138 borrowers.phone, borrowers.email,issues.itemnumber, items.barcode, biblio.title, biblio.author,borrowers.borrowernumber
140 LEFT JOIN borrowers ON (issues.borrowernumber=borrowers.borrowernumber )
141 LEFT JOIN items ON (issues.itemnumber=items.itemnumber)
142 LEFT JOIN biblioitems ON (biblioitems.biblioitemnumber=items.biblioitemnumber)
143 LEFT JOIN biblio ON (biblio.biblionumber=items.biblionumber )
144 where isnull(returndate) ";
145 $strsth.= " && date_due<'".$todaysdate."' " unless ($showall);
146 $strsth.=" && (borrowers.firstname like '".$bornamefilter."%' or borrowers.surname like '".$bornamefilter."%' or borrowers.cardnumber like '".$bornamefilter."%')" if($bornamefilter) ;
147 $strsth.=" && borrowers.categorycode = '".$borcatfilter."' " if($borcatfilter) ;
148 $strsth.=" && biblioitems.itemtype = '".$itemtypefilter."' " if($itemtypefilter) ;
149 $strsth.=" && borrowers.flags = '".$borflagsfilter."' " if ($borflagsfilter ne " ") ;
150 $strsth.=" && issues.branchcode = '".$branchfilter."' " if($branchfilter) ;
151 if ($order eq "borrower"){
152 $strsth.=" order by borrower,date_due " ;
153 } elsif ($order eq "title"){
154 $strsth.=" order by title,date_due,borrower ";
155 } elsif ($order eq "barcode"){
156 $strsth.=" order by items.barcode,date_due,borrower ";
157 }elsif ($order eq "borrower desc"){
158 $strsth.=" order by borrower desc,date_due " ;
159 } elsif ($order eq "title desc"){
160 $strsth.=" order by title desc,date_due,borrower ";
161 } elsif ($order eq "barcode desc"){
162 $strsth.=" order by items.barcode desc,date_due,borrower ";
163 } elsif ($order eq "date_due desc"){
164 $strsth.=" order by date_due desc,borrower ";
166 $strsth.=" order by date_due,borrower ";
168 my $sth=$dbh->prepare($strsth);
169 #warn "overdue.pl : query string ".$strsth;
173 while (my $data=$sth->fetchrow_hashref) {
174 $duedate=$data->{'date_due'};
175 $duedate = format_date($duedate);
176 $itemnum=$data->{'itemnumber'};
178 $name=$data->{'borrower'};
179 $phone=$data->{'phone'};
180 $email=$data->{'email'};
182 $title=$data->{'title'};
183 $author=$data->{'author'};
184 push (@overduedata, { duedate => $duedate,
185 bornum => $data->{borrowernumber},
186 barcode => $data->{barcode},
191 biblionumber => $biblionumber,
193 author => $author });
198 todaysdate => $todaysdate,
199 overdueloop => \@overduedata
202 output_html_with_http_headers $input, $cookie, $template->output;