Changed some hidden values, items labels, and changed the namespace from ASMP_*
[koha.git] / circ / waitingreservestransfers.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 use C4::Auth;
28 use C4::Date;
29 use C4::Circulation::Circ2;
30 use Date::Manip;
31 use C4::Koha;
32 use C4::Biblio;
33
34 my $input = new CGI;
35
36 my $theme = $input->param('theme'); # only used if allowthemeoverride is set
37
38 my ($template, $loggedinuser, $cookie)
39       = get_template_and_user({template_name => "circ/waitingreservestransfers.tmpl",
40                                          query => $input,
41                                          type => "intranet",
42                                          authnotrequired => 0,
43                                          flagsrequired => {borrowers => 1},
44                                          debug => 1,
45                                          });
46
47
48 # set the userenv branch
49 my $default = C4::Context->userenv->{'branch'};
50
51
52 my @datearr = localtime(time());
53 my $todaysdate = (1900+$datearr[5]).'-'.sprintf ("%0.2d", ($datearr[4]+1)).'-'.sprintf ("%0.2d", $datearr[3]);
54
55 my $item=$input->param('itemnumber');
56 my $fbr=$input->param('fbr');
57 my $tbr=$input->param('tbr');
58 # If we have a return of the form dotransfer, we launch the subroutine dotransfer
59 if ($item){
60         C4::Circulation::Circ2::dotransfer($item,$fbr,$tbr);
61 }
62
63 # get the all the branches for reference
64 my $branches = GetBranches();
65 my @branchesloop;
66 foreach my $br (keys %$branches) {
67         my @reservloop;
68         my %branchloop;
69         $branchloop{'branchname'} = $branches->{$br}->{'branchname'};
70         $branchloop{'branchcode'} = $branches->{$br}->{'branchcode'};
71         my @getreserves = GetReservesToBranch($branches->{$br}->{'branchcode'},$default);
72                 if (@getreserves){
73                 foreach my $num (@getreserves) {
74                         my %getreserv;
75                         my %env;
76                         my $gettitle = getiteminformation(\%env,$num->{'itemnumber'});
77                         my $itemtypeinfo = getitemtypeinfo($gettitle->{'itemtype'});
78                         if ($gettitle->{'holdingbranch'} eq $default){
79                                 my $getborrower = getpatroninformation (\%env,$num->{'borrowernumber'});
80                                 $getreserv{'reservedate'} = format_date($num->{'reservedate'});
81                                 my $calcDate=DateCalc($num->{'reservedate'},"+".C4::Context->preference('TransfersMaxDaysWarning')."  days");
82                                 my $warning=Date_Cmp(ParseDate("today"),$calcDate);
83                                 if ($warning>0){
84                                         $getreserv{'messcompa'} = 1;
85                                 }
86                                 $getreserv{'title'} = $gettitle->{'title'};
87                                 $getreserv{'biblionumber'} = $gettitle->{'biblionumber'};
88                                 $getreserv{'itemnumber'} = $gettitle->{'itemnumber'};
89                                 $getreserv{'barcode'} = $gettitle->{'barcode'};
90                                 $getreserv{'itemtype'} = $itemtypeinfo->{'description'};
91                                 $getreserv{'holdingbranch'} = $gettitle->{'holdingbranch'};
92                                 $getreserv{'itemcallnumber'} = $gettitle->{'itemcallnumber'};
93                                 $getreserv{'borrowernum'} = $getborrower->{'borrowernumber'};
94                                 $getreserv{'borrowername'} = $getborrower->{'surname'};
95                                 $getreserv{'borrowerfirstname'} =  $getborrower->{'firstname'} ;
96                                 if ($getborrower->{'emailaddress'}){
97                                         $getreserv{'borrowermail'} =  $getborrower->{'emailaddress'} ;
98                                 }
99                                 $getreserv{'borrowerphone'} = $getborrower->{'phone'};
100                                 push(@reservloop, \%getreserv);
101                         }
102                 }
103 #               If we have a return of reservloop we put it in the branchloop sequence
104                 if (@reservloop){
105                 $branchloop{'reserv'} = \@reservloop ;
106                 }
107 #               else, we unset the value of the branchcode .
108                 else{
109                 $branchloop{'branchcode'} = 0;
110                 }
111         }
112         else {
113 #       if we don't have a retrun from reservestobranch we unset branchname and branchcode
114         $branchloop{'branchname'} = 0;
115         $branchloop{'branchcode'} = 0;
116         }
117         push(@branchesloop, \%branchloop);
118 }
119
120         $template->param( branchesloop  => \@branchesloop,
121                         show_date       => format_date($todaysdate)     
122                          );
123         
124         print "Content-Type: text/html\n\n", $template->output;
125
126
127