Bug 26265: (QA follow-up) Remove g option from regex, add few dirs
[koha.git] / circ / branchoverdues.pl
1 #!/usr/bin/perl
2
3 #
4 # This file is part of Koha.
5 #
6 # Koha is free software; you can redistribute it and/or modify it
7 # under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 3 of the License, or
9 # (at your option) any later version.
10 #
11 # Koha is distributed in the hope that it will be useful, but
12 # WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License
17 # along with Koha; if not, see <http://www.gnu.org/licenses>.
18
19 use Modern::Perl;
20 use C4::Context;
21 use CGI qw ( -utf8 );
22 use C4::Output;
23 use C4::Auth;
24 use C4::Overdues;
25 use C4::Biblio;
26 use C4::Koha;
27 use C4::Debug;
28 use Koha::DateUtils;
29 use Koha::BiblioFrameworks;
30 use Data::Dumper;
31
32 =head1 branchoverdues.pl
33
34 This view is used to display all overdue items to the librarian.
35
36 It is automatically filtered by branch and can optionally be filtered
37 by item location.
38
39 =cut
40
41 my $input       = new CGI;
42 my $dbh = C4::Context->dbh;
43
44 my ( $template, $loggedinuser, $cookie, $flags ) = get_template_and_user({
45         template_name   => "circ/branchoverdues.tt",
46         query           => $input,
47         type            => "intranet",
48         authnotrequired => 0,
49         flagsrequired   => { circulate => "circulate_remaining_permissions" },
50         debug           => 1,
51 });
52
53 my $default = C4::Context->userenv->{'branch'};
54
55 # Deal with the vars recept from the template
56 my $borrowernumber = $input->param('borrowernumber');
57 my $itemnumber     = $input->param('itemnumber');
58 my $method         = $input->param('method');
59 my $overduelevel   = $input->param('overduelevel');
60 my $location       = $input->param('location');
61
62 # FIXME: better check that borrowernumber is defined and valid.
63 # FIXME: same for itemnumber and other variables passed in here.
64
65 my @overduesloop;
66 my @getoverdues = GetOverduesForBranch( $default, $location );
67 $debug and warn "HERE : $default / $location" . Dumper(@getoverdues);
68 # search for location authorised value
69 my ($tag,$subfield) = GetMarcFromKohaField( 'items.location' );
70 my $tagslib = &GetMarcStructure(1,'');
71 if ($tagslib->{$tag}->{$subfield}->{authorised_value}) {
72     my $values= GetAuthorisedValues($tagslib->{$tag}->{$subfield}->{authorised_value});
73     for (@$values) { $_->{selected} = 1 if $location eq $_->{authorised_value} }
74     $template->param(locationsloop => $values);
75 }
76 # now display infos
77 foreach my $num (@getoverdues) {
78     my %overdueforbranch;
79     my $record = GetMarcBiblio({ biblionumber => $num->{biblionumber} });
80     if ($record){
81         $overdueforbranch{'subtitle'} = GetRecordValue('subtitle',$record,'')->[0]->{subfield};
82     }
83     my $dt = dt_from_string($num->{date_due}, 'sql');
84     $overdueforbranch{'date_due'}          = output_pref($dt);
85     $overdueforbranch{'title'}             = $num->{'title'};
86     $overdueforbranch{'description'}       = $num->{'description'};
87     $overdueforbranch{'barcode'}           = $num->{'barcode'};
88     $overdueforbranch{'biblionumber'}      = $num->{'biblionumber'};
89     $overdueforbranch{'author'}            = $num->{'author'};
90     $overdueforbranch{'borrowersurname'}   = $num->{'surname'};
91     $overdueforbranch{'borrowerfirstname'} = $num->{'firstname'};
92     $overdueforbranch{'borrowerphone'}     = $num->{'phone'};
93     $overdueforbranch{'borroweremail'}     = $num->{'email'};
94     $overdueforbranch{'homebranch'}        = $num->{'homebranch'};
95     $overdueforbranch{'itemcallnumber'}    = $num->{'itemcallnumber'};
96     $overdueforbranch{'borrowernumber'}    = $num->{'borrowernumber'};
97     $overdueforbranch{'itemnumber'}        = $num->{'itemnumber'};
98     $overdueforbranch{'cardnumber'}        = $num->{'cardnumber'};
99
100     push( @overduesloop, \%overdueforbranch );
101 }
102
103 # initiate the templates for the overdueloop
104 $template->param(
105     overduesloop => \@overduesloop,
106     location     => $location,
107 );
108
109 # Checking if there is a Fast Cataloging Framework
110 $template->param( fast_cataloging => 1 ) if Koha::BiblioFrameworks->find( 'FA' );
111
112 output_html_with_http_headers $input, $cookie, $template->output;