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