z3950 support is coming...
[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
28 my $input = new CGI;
29 my $type=$input->param('type');
30
31 my $theme = $input->param('theme'); # only used if allowthemeoverride is set
32 my %tmpldata = pathtotemplate ( template => 'overdue.tmpl', theme => $theme);
33 my $template = HTML::Template->new( filename => $tmpldata{'path'},
34                                     die_on_bad_params => 0);
35 my $duedate;
36 my $bornum;
37 my $itemnum;
38 my $data1;
39 my $data2;
40 my $data3;
41 my $name;
42 my $phone;
43 my $email;
44 my $biblionumber;
45 my $title;
46 my $author;
47 my @datearr = localtime(time());
48 my $todaysdate = (1900+$datearr[5]).'-'.sprintf ("%0.2d", ($datearr[4]+1)).'-'.sprintf ("%0.2d", $datearr[3]);
49
50 my $dbh = C4::Context->dbh;
51
52 my $query="select date_due,borrowernumber,itemnumber from issues where isnull(returndate) && date_due<'$todaysdate' order by date_due,borrowernumber";
53 my $sth=$dbh->prepare($query);
54 $sth->execute;
55
56 my @overduedata;
57 while (my $data=$sth->fetchrow_hashref) {
58   $duedate=$data->{'date_due'};
59   $bornum=$data->{'borrowernumber'};
60   $itemnum=$data->{'itemnumber'};
61
62   my $query="select concat(firstname,' ',surname),phone,emailaddress from borrowers where borrowernumber='$bornum'";
63   my $sth1=$dbh->prepare($query);
64   $sth1->execute;
65   $data1=$sth1->fetchrow_hashref;
66   $name=$data1->{'concat(firstname,\' \',surname)'};
67   $phone=$data1->{'phone'};
68   $email=$data1->{'emailaddress'};
69   $sth1->finish;
70
71   # FIXME - There's already a $query in this scope.
72   my $query="select biblionumber from items where itemnumber='$itemnum'";
73   my $sth2=$dbh->prepare($query);
74   $sth2->execute;
75   $data2=$sth2->fetchrow_hashref;
76   $biblionumber=$data2->{'biblionumber'};
77   $sth2->finish;
78
79   # FIXME - There's already a $query in this scope.
80   my $query="select title,author from biblio where biblionumber='$biblionumber'";
81   my $sth3=$dbh->prepare($query);
82   $sth3->execute;
83   $data3=$sth3->fetchrow_hashref;
84   $title=$data3->{'title'};
85   $author=$data3->{'author'};
86   $sth3->finish;
87   push (@overduedata, { duedate      => $duedate,
88                         bornum       => $bornum,
89                         itemnum      => $itemnum,
90                         name         => $name,
91                         phone        => $phone,
92                         email        => $email,
93                         biblionumber => $biblionumber,
94                         title        => $title,
95                         author       => $author });
96
97 }
98
99 $sth->finish;
100
101 $template->param( startmenureport => join ('', startmenu('report')),
102                 endmenureport     => join ('', endmenu('report')),
103                 todaysdate        => $todaysdate,
104                 overdueloop       => \@overduedata );
105
106 print "Content-Type: text/html\n\n", $template->output;