Bug 3962: Fixes XHTML errors in aqbudgets.tmpl.
[koha.git] / circ / waitingreserves.pl
blob812027fe8feb944209660c206f51ad4b5e33c97b
1 #!/usr/bin/perl
3 # Copyright 2000-2002 Katipo Communications
5 # This file is part of Koha.
7 # Koha is free software; you can redistribute it and/or modify it under the
8 # terms of the GNU General Public License as published by the Free Software
9 # Foundation; either version 2 of the License, or (at your option) any later
10 # version.
12 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License along with
17 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
18 # Suite 330, Boston, MA 02111-1307 USA
20 use strict;
21 use warnings;
22 use CGI;
23 use C4::Context;
24 use C4::Output;
25 use C4::Branch; # GetBranchName
26 use C4::Auth;
27 use C4::Dates qw/format_date/;
28 use C4::Circulation;
29 use C4::Members;
30 use C4::Biblio;
31 use C4::Items;
33 use Date::Calc qw(
34 Today
35 Add_Delta_Days
36 Date_to_Days
38 use C4::Reserves;
39 use C4::Koha;
41 my $input = new CGI;
43 my $item = $input->param('itemnumber');
44 my $borrowernumber = $input->param('borrowernumber');
45 my $fbr = $input->param('fbr') || '';
46 my $tbr = $input->param('tbr') || '';
48 my $cancel;
50 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
52 template_name => "circ/waitingreserves.tmpl",
53 query => $input,
54 type => "intranet",
55 authnotrequired => 0,
56 flagsrequired => { circulate => "circulate_remaining_permissions" },
57 debug => 1,
61 my $default = C4::Context->userenv->{'branch'};
63 # if we have a return from the form we launch the subroutine CancelReserve
64 if ($item) {
65 my ( $messages, $nextreservinfo ) = ModReserveCancelAll( $item, $borrowernumber );
66 # if we have a result
67 if ($nextreservinfo) {
68 my $borrowerinfo = GetMemberDetails( $nextreservinfo );
69 my $iteminfo = GetBiblioFromItemNumber($item);
70 if ( $messages->{'transfert'} ) {
71 $template->param(
72 messagetransfert => $messages->{'transfert'},
73 branchname => GetBranchName($messages->{'transfert'}),
77 $template->param(
78 message => 1,
79 nextreservnumber => $nextreservinfo,
80 nextreservsurname => $borrowerinfo->{'surname'},
81 nextreservfirstname => $borrowerinfo->{'firstname'},
82 nextreservitem => $item,
83 nextreservtitle => $iteminfo->{'title'},
84 waiting => ($messages->{'waiting'}) ? 1 : 0,
88 # if the document is not in his homebranch location and there is not reservation after, we transfer it
89 if ($fbr ne $tbr and not $nextreservinfo) {
90 ModItemTransfer( $item, $fbr, $tbr );
94 my @reservloop;
95 my @getreserves = C4::Context->preference('IndependantBranches') ? GetReservesForBranch($default) : GetReservesForBranch();
96 # get reserves for the branch we are logged into, or for all branches
98 my $today = Date_to_Days(&Today);
99 foreach my $num (@getreserves) {
100 next unless ($num->{'waitingdate'} && $num->{'waitingdate'} ne '0000-00-00');
101 my %getreserv;
102 my $gettitle = GetBiblioFromItemNumber( $num->{'itemnumber'} );
103 # fix up item type for display
104 $gettitle->{'itemtype'} = C4::Context->preference('item-level_itypes') ? $gettitle->{'itype'} : $gettitle->{'itemtype'};
105 my $getborrower = GetMemberDetails( $num->{'borrowernumber'} );
106 my $itemtypeinfo = getitemtypeinfo( $gettitle->{'itemtype'} ); # using the fixed up itype/itemtype
107 $getreserv{'waitingdate'} = format_date( $num->{'waitingdate'} );
109 my ( $waiting_year, $waiting_month, $waiting_day ) = split /-/, $num->{'waitingdate'};
110 ( $waiting_year, $waiting_month, $waiting_day ) =
111 Add_Delta_Days( $waiting_year, $waiting_month, $waiting_day,
112 C4::Context->preference('ReservesMaxPickUpDelay'));
113 my $calcDate = Date_to_Days( $waiting_year, $waiting_month, $waiting_day );
115 if ($today > $calcDate) {
116 $getreserv{'messcompa'} = 1;
118 $getreserv{'itemtype'} = $itemtypeinfo->{'description'};
119 $getreserv{'title'} = $gettitle->{'title'};
120 $getreserv{'itemnumber'} = $gettitle->{'itemnumber'};
121 $getreserv{'biblionumber'} = $gettitle->{'biblionumber'};
122 $getreserv{'barcode'} = $gettitle->{'barcode'};
123 $getreserv{'homebranch'} = $gettitle->{'homebranch'};
124 $getreserv{'holdingbranch'} = $gettitle->{'holdingbranch'};
125 $getreserv{'itemcallnumber'} = $gettitle->{'itemcallnumber'};
126 if ( $gettitle->{'homebranch'} ne $gettitle->{'holdingbranch'} ) {
127 $getreserv{'dotransfer'} = 1;
129 $getreserv{'borrowernum'} = $getborrower->{'borrowernumber'};
130 $getreserv{'borrowername'} = $getborrower->{'surname'};
131 $getreserv{'borrowerfirstname'} = $getborrower->{'firstname'};
132 $getreserv{'borrowerphone'} = $getborrower->{'phone'};
133 if ( $getborrower->{'emailaddress'} ) {
134 $getreserv{'borrowermail'} = $getborrower->{'emailaddress'};
136 push @reservloop, \%getreserv;
139 $template->param(
140 reserveloop => \@reservloop,
141 show_date => format_date(C4::Dates->today('iso')),
142 dateformat => C4::Context->preference("dateformat"),
145 output_html_with_http_headers $input, $cookie, $template->output;