bugfixing for displaying the maxpicking delays for reservations, now the method of...
[koha.git] / circ / reserve.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 use C4::Interface::CGI::Output;
29
30 my $input = new CGI;
31 my $order = $input->param('order');
32 my $startdate=$input->param('from');
33 my $enddate=$input->param('to');
34
35 my $theme = $input->param('theme');    # only used if allowthemeoverride is set
36
37 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
38     {
39         template_name   => "circ/reserve.tmpl",
40         query           => $input,
41         type            => "intranet",
42         authnotrequired => 0,
43         flagsrequired   => { circulate => 1 },
44         debug           => 1,
45     }
46 );
47
48 my $duedate;
49 my $borrowernumber;
50 my $itemnum;
51 my $data1;
52 my $data2;
53 my $data3;
54 my $name;
55 my $phone;
56 my $email;
57 my $biblionumber;
58 my $title;
59 my $author;
60
61 my @datearr    = localtime( time() );
62 my $todaysdate =
63     ( 1900 + $datearr[5] ) . '-'
64   . sprintf( "%0.2d", ( $datearr[4] + 1 ) ) . '-'
65   . sprintf( "%0.2d", $datearr[3] );
66
67 my $dbh    = C4::Context->dbh;
68 my ($sqlorderby, $sqldatewhere) = ("","");
69
70 $sqldatewhere .= " && reservedate >= " . $dbh->quote($startdate)  if ($startdate) ;
71 $sqldatewhere .= " && reservedate <= " . $dbh->quote($enddate)  if ($enddate) ;
72
73 if ($order eq "borrower") {
74         $sqlorderby = " order by  borrower, reservedate";
75 } elsif ($order eq "biblio") {
76         $sqlorderby = " order by biblio.title, priority,reservedate";
77 } elsif ($order eq "priority") {
78     $sqlorderby = "order by priority DESC";
79 } else {
80         $sqlorderby = " order by reservedate, borrower";
81 }
82 my $strsth =
83 "SELECT reservedate,
84         reserves.borrowernumber as borrowernumber,
85         concat(firstname,' ',surname) as borrower,
86         borrowers.phone,
87         borrowers.email,
88         reserves.biblionumber,
89         reserves.branchcode as branch,
90         items.holdingbranch,
91         items.itemcallnumber,
92         items.itemnumber,
93         notes,
94         notificationdate,
95         reminderdate,
96         priority,
97         reserves.found,
98         biblio.title,
99         biblio.author
100  FROM  reserves
101  LEFT JOIN items ON items.biblionumber=reserves.biblionumber,
102   borrowers,biblio
103  WHERE isnull(cancellationdate)
104   && reserves.borrowernumber=borrowers.borrowernumber 
105   && reserves.biblionumber=biblio.biblionumber
106   && reserves.found is NULL
107   && items.holdingbranch=?
108  ";
109
110 $strsth .= $sqlorderby;
111
112 my $sth = $dbh->prepare($strsth);
113
114 $sth->execute(C4::Context->userenv->{'branch'});
115
116 my @reservedata;
117 my $previous;
118 my $this;
119 while ( my $data = $sth->fetchrow_hashref ) {
120     $this=$data->{biblionumber}.":".$data->{borrowernumber};
121     my @itemlist;
122     push(
123         @reservedata,
124         {
125             reservedate      => $previous eq $this?"":format_date( $data->{reservedate} ),
126             priority         => $previous eq $this?"":$data->{priority},
127             name             => $previous eq $this?"":$data->{borrower},
128             title            => $previous eq $this?"":$data->{title},
129             author           => $previous eq $this?"":$data->{author},
130             borrowernumber   => $previous eq $this?"":$data->{borrowernumber},
131             itemnum          => $previous eq $this?"":$data->{itemnumber},
132             phone            => $previous eq $this?"":$data->{phone},
133             email            => $previous eq $this?"":$data->{email},
134             biblionumber     => $previous eq $this?"":$data->{biblionumber},
135             statusw          => ( $data->{found} eq "w" ),
136             statusf          => ( $data->{found} eq "f" ),
137             holdingbranch    => $data->{holdingbranch},
138             branch           => $previous eq $this?"":$data->{branch},
139             itemcallnumber   => $data->{itemcallnumber},
140             notes            => $previous eq $this?"":$data->{notes},
141             notificationdate => $previous eq $this?"":$data->{notificationdate},
142             reminderdate     => $previous eq $this?"":$data->{reminderdate}
143         }
144     );
145     $previous=$this;
146 }
147
148 $sth->finish;
149
150 $template->param(
151     todaysdate              => format_date($todaysdate),
152         from                        => $startdate,
153         to                                  => $enddate,
154     reserveloop             => \@reservedata,
155     intranetcolorstylesheet =>
156       C4::Context->preference("intranetcolorstylesheet"),
157     intranetstylesheet => C4::Context->preference("intranetstylesheet"),
158     IntranetNav        => C4::Context->preference("IntranetNav"),
159     "BiblioDefaultView".C4::Context->preference("BiblioDefaultView") => 1,
160 );
161
162 output_html_with_http_headers $input, $cookie, $template->output;