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