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