oups... typo fix in z3950random field definition
[koha.git] / 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 HTML::Template;
27 use C4::Auth;
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)
35       = get_template_and_user({template_name => "overdue.tmpl",
36                                          query => $input,
37                                          type => "intranet",
38                                          authnotrequired => 0,
39                                          flagsrequired => {borrowers => 1},
40                                          debug => 1,
41                                          });
42 my $duedate;
43 my $bornum;
44 my $itemnum;
45 my $data1;
46 my $data2;
47 my $data3;
48 my $name;
49 my $phone;
50 my $email;
51 my $biblionumber;
52 my $title;
53 my $author;
54 my @datearr = localtime(time());
55 my $todaysdate = (1900+$datearr[5]).'-'.sprintf ("%0.2d", ($datearr[4]+1)).'-'.sprintf ("%0.2d", $datearr[3]);
56
57 my $dbh = C4::Context->dbh;
58
59 my $query="select date_due,borrowernumber,itemnumber from issues where isnull(returndate) && date_due<'$todaysdate' order by date_due,borrowernumber";
60 my $sth=$dbh->prepare($query);
61 $sth->execute;
62
63 my @overduedata;
64 while (my $data=$sth->fetchrow_hashref) {
65   $duedate=$data->{'date_due'};
66   $bornum=$data->{'borrowernumber'};
67   $itemnum=$data->{'itemnumber'};
68
69   my $query="select concat(firstname,' ',surname),phone,emailaddress from borrowers where borrowernumber='$bornum'";
70   my $sth1=$dbh->prepare($query);
71   $sth1->execute;
72   $data1=$sth1->fetchrow_hashref;
73   $name=$data1->{'concat(firstname,\' \',surname)'};
74   $phone=$data1->{'phone'};
75   $email=$data1->{'emailaddress'};
76   $sth1->finish;
77
78   # FIXME - There's already a $query in this scope.
79   my $query="select biblionumber from items where itemnumber='$itemnum'";
80   my $sth2=$dbh->prepare($query);
81   $sth2->execute;
82   $data2=$sth2->fetchrow_hashref;
83   $biblionumber=$data2->{'biblionumber'};
84   $sth2->finish;
85
86   # FIXME - There's already a $query in this scope.
87   my $query="select title,author from biblio where biblionumber='$biblionumber'";
88   my $sth3=$dbh->prepare($query);
89   $sth3->execute;
90   $data3=$sth3->fetchrow_hashref;
91   $title=$data3->{'title'};
92   $author=$data3->{'author'};
93   $sth3->finish;
94   push (@overduedata, { duedate      => $duedate,
95                         bornum       => $bornum,
96                         itemnum      => $itemnum,
97                         name         => $name,
98                         phone        => $phone,
99                         email        => $email,
100                         biblionumber => $biblionumber,
101                         title        => $title,
102                         author       => $author });
103
104 }
105
106 $sth->finish;
107
108 $template->param(               todaysdate        => $todaysdate,
109                 overdueloop       => \@overduedata );
110
111 print "Content-Type: text/html\n\n", $template->output;