more language improvements
[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 CGI;
26 use C4::Auth;
27 use C4::Date;
28
29 my $input = new CGI;
30 my $type  = $input->param('type');
31
32 my $theme = $input->param('theme');    # only used if allowthemeoverride is set
33
34 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
35     {
36         template_name   => "circ/overdue.tmpl",
37         query           => $input,
38         type            => "intranet",
39         authnotrequired => 0,
40         flagsrequired   => { reports => 1 },
41         debug           => 1,
42     }
43 );
44 my $duedate;
45 my $borrowernumber;
46 my $itemnum;
47 my $data1;
48 my $data2;
49 my $data3;
50 my $name;
51 my $phone;
52 my $email;
53 my $biblionumber;
54 my $title;
55 my $author;
56 my @datearr    = localtime( time() );
57 my $todaysdate =
58     ( 1900 + $datearr[5] ) . '-'
59   . sprintf( "%0.2d", ( $datearr[4] + 1 ) ) . '-'
60   . sprintf( "%0.2d", $datearr[3] );
61
62 my $dbh = C4::Context->dbh;
63
64 my $sth =
65   $dbh->prepare(
66     "select date_due,borrowernumber,itemnumber
67      from issues
68      where isnull(returndate) && date_due<? order by date_due,borrowernumber"
69   );
70 $sth->execute($todaysdate);
71
72 my @overduedata;
73 while ( my $data = $sth->fetchrow_hashref ) {
74     $duedate        = format_date($data->{'date_due'});
75     $borrowernumber = $data->{'borrowernumber'};
76     $itemnum        = $data->{'itemnumber'};
77
78     my $sth1 =
79       $dbh->prepare(
80 "select concat(firstname,' ',surname),phone,email from borrowers where borrowernumber=?"
81       );
82     $sth1->execute($borrowernumber);
83     $data1 = $sth1->fetchrow_hashref;
84     $name  = $data1->{'concat(firstname,\' \',surname)'};
85     $phone = $data1->{'phone'};
86     $email = $data1->{'email'};
87     $sth1->finish;
88
89     my $sth2 =
90       $dbh->prepare("select biblionumber from items where itemnumber=?");
91     $sth2->execute($itemnum);
92     $data2        = $sth2->fetchrow_hashref;
93     $biblionumber = $data2->{'biblionumber'};
94     $sth2->finish;
95
96     my $sth3 =
97       $dbh->prepare("select title,author from biblio where biblionumber=?");
98     $sth3->execute($biblionumber);
99     $data3  = $sth3->fetchrow_hashref;
100     $title  = $data3->{'title'};
101     $author = $data3->{'author'};
102     $sth3->finish;
103     push(
104         @overduedata,
105         {
106             duedate        => $duedate,
107             borrowernumber => $borrowernumber,
108             itemnum        => $itemnum,
109             name           => $name,
110             phone          => $phone,
111             email          => $email,
112             biblionumber   => $biblionumber,
113             title          => $title,
114             author         => $author
115         }
116     );
117 }
118
119 $template->param(
120     todaysdate  => $todaysdate,
121     overdueloop => \@overduedata
122 );
123
124 output_html_with_http_headers $input, $cookie, $template->output;