rel_3_0 moved to HEAD (introducing new files)
[koha.git] / circ / overdue.pl
1 #!/usr/bin/perl
2
3 # $Id$
4
5 # Copyright 2000-2002 Katipo Communications
6 #
7 # This file is part of Koha.
8 #
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
12 # version.
13 #
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.
17 #
18 # You should have received a copy of the GNU General Public License along with
19 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
20 # Suite 330, Boston, MA  02111-1307 USA
21
22 use strict;
23 use C4::Context;
24 use C4::Output;
25 use C4::Interface::CGI::Output;
26 use CGI;
27 use C4::Auth;
28 use C4::Date;
29
30 my $input = new CGI;
31 my $type  = $input->param('type');
32
33 my $theme = $input->param('theme');    # only used if allowthemeoverride is set
34
35 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
36     {
37         template_name   => "circ/overdue.tmpl",
38         query           => $input,
39         type            => "intranet",
40         authnotrequired => 0,
41         flagsrequired   => { reports => 1 },
42         debug           => 1,
43     }
44 );
45 my $duedate;
46 my $borrowernumber;
47 my $itemnum;
48 my $data1;
49 my $data2;
50 my $data3;
51 my $name;
52 my $phone;
53 my $email;
54 my $biblionumber;
55 my $title;
56 my $author;
57 my @datearr    = localtime( time() );
58 my $todaysdate =
59     ( 1900 + $datearr[5] ) . '-'
60   . sprintf( "%0.2d", ( $datearr[4] + 1 ) ) . '-'
61   . sprintf( "%0.2d", $datearr[3] );
62
63 my $dbh = C4::Context->dbh;
64
65 my $sth =
66   $dbh->prepare(
67     "select date_due,borrowernumber,itemnumber
68      from issues
69      where isnull(returndate) && date_due<? order by date_due,borrowernumber"
70   );
71 $sth->execute($todaysdate);
72
73 my @overduedata;
74 while ( my $data = $sth->fetchrow_hashref ) {
75     $duedate        = format_date($data->{'date_due'});
76     $borrowernumber = $data->{'borrowernumber'};
77     $itemnum        = $data->{'itemnumber'};
78
79     my $sth1 =
80       $dbh->prepare(
81 "select concat(firstname,' ',surname),phone,email from borrowers where borrowernumber=?"
82       );
83     $sth1->execute($borrowernumber);
84     $data1 = $sth1->fetchrow_hashref;
85     $name  = $data1->{'concat(firstname,\' \',surname)'};
86     $phone = $data1->{'phone'};
87     $email = $data1->{'email'};
88     $sth1->finish;
89
90     my $sth2 =
91       $dbh->prepare("select biblionumber from items where itemnumber=?");
92     $sth2->execute($itemnum);
93     $data2        = $sth2->fetchrow_hashref;
94     $biblionumber = $data2->{'biblionumber'};
95     $sth2->finish;
96
97     my $sth3 =
98       $dbh->prepare("select title,author from biblio where biblionumber=?");
99     $sth3->execute($biblionumber);
100     $data3  = $sth3->fetchrow_hashref;
101     $title  = $data3->{'title'};
102     $author = $data3->{'author'};
103     $sth3->finish;
104     push(
105         @overduedata,
106         {
107             duedate        => $duedate,
108             borrowernumber => $borrowernumber,
109             itemnum        => $itemnum,
110             name           => $name,
111             phone          => $phone,
112             email          => $email,
113             biblionumber   => $biblionumber,
114             title          => $title,
115             author         => $author
116         }
117     );
118 }
119
120 $template->param(
121     todaysdate  => $todaysdate,
122     overdueloop => \@overduedata
123 );
124
125 output_html_with_http_headers $input, $cookie, $template->output;