Bug 6554 Fix error caused by modifying $_ in a map
[koha.git] / acqui / booksellers.pl
blob394ae92178c5c37fb1265f7112b0fb87fc539272
1 #!/usr/bin/perl
3 #script to show suppliers and orders
5 # Copyright 2000-2002 Katipo Communications
6 # Copyright 2008-2009 BibLibre SARL
7 # Copyright 2010 PTFS Europe
9 # This file is part of Koha.
11 # Koha is free software; you can redistribute it and/or modify it under the
12 # terms of the GNU General Public License as published by the Free Software
13 # Foundation; either version 2 of the License, or (at your option) any later
14 # version.
16 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
17 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
18 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
20 # You should have received a copy of the GNU General Public License along
21 # with Koha; if not, write to the Free Software Foundation, Inc.,
22 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 =head1 NAME
26 booksellers.pl
28 =head1 DESCRIPTION
30 this script displays the list of suppliers & baskets like C<$supplier> given on input arg.
31 thus, this page brings differents features like to display supplier's details,
32 to add an order for a specific supplier or to just add a new supplier.
34 =head1 CGI PARAMETERS
36 =over 4
38 =item supplier
40 C<$supplier> is the string with which we search for a supplier
42 =back
44 =item id or booksellerid
46 The id of the supplier whose baskets we will display
48 =back
50 =cut
52 use strict;
53 use warnings;
54 use C4::Auth;
55 use C4::Biblio;
56 use C4::Output;
57 use CGI;
59 use C4::Acquisition qw/ GetBasketsInfosByBookseller /;
60 use C4::Bookseller qw/ GetBookSellerFromId GetBookSeller /;
61 use C4::Members qw/GetMember/;
62 use C4::Context;
64 my $query = CGI->new;
65 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
66 { template_name => 'acqui/booksellers.tmpl',
67 query => $query,
68 type => 'intranet',
69 authnotrequired => 0,
70 flagsrequired => { acquisition => '*' },
71 debug => 1,
75 #parameters
76 my $supplier = $query->param('supplier');
77 utf8::decode($supplier);
78 my $booksellerid = $query->param('booksellerid');
79 my @suppliers;
81 if ($booksellerid) {
82 push @suppliers, GetBookSellerFromId($booksellerid);
83 } else {
84 @suppliers = GetBookSeller($supplier);
87 my $supplier_count = @suppliers;
88 if ( $supplier_count == 1 ) {
89 $template->param(
90 supplier_name => $suppliers[0]->{'name'},
91 booksellerid => $suppliers[0]->{'id'},
92 basketcount => $suppliers[0]->{'basketcount'}
96 my $uid;
97 if ($loggedinuser) {
98 $uid = GetMember( borrowernumber => $loggedinuser )->{userid};
101 my $userenv = C4::Context::userenv;
102 my $viewbaskets = C4::Context->preference('AcqViewBaskets');
104 my $userbranch = $userenv->{branch};
106 #build result page
107 my $loop_suppliers = [];
109 for my $vendor (@suppliers) {
110 my $baskets = GetBasketsInfosByBookseller( $vendor->{id} );
112 my $loop_basket = [];
114 for my $basket ( @{$baskets} ) {
115 my $authorisedby = $basket->{authorisedby};
116 my $basketbranch = ''; # set a blank branch to start with
117 my $member = GetMember( borrowernumber => $authorisedby );
118 if ( $member ) {
119 $basketbranch = $member->{branchcode};
122 if ($userenv->{'flags'} & 1 || #user is superlibrarian
123 (haspermission( $uid, { acquisition => q{*} } ) && #user has acq permissions and
124 ($viewbaskets eq 'all' || #user is allowed to see all baskets
125 ($viewbaskets eq 'branch' && $authorisedby && $userbranch eq $basketbranch) || #basket belongs to user's branch
126 ($basket->{authorisedby} && $viewbaskets eq 'user' && $authorisedby == $loggedinuser) #user created this basket
129 ) {
130 foreach (qw(total_items total_biblios expected_items)) {
131 $basket->{$_} ||= 0;
133 if($member) {
134 $basket->{authorisedby_firstname} = $member->{firstname};
135 $basket->{authorisedby_surname} = $member->{surname};
137 push @{$loop_basket}, $basket;
141 push @{$loop_suppliers},
142 { loop_basket => $loop_basket,
143 booksellerid => $vendor->{id},
144 name => $vendor->{name},
145 active => $vendor->{active},
149 $template->param(
150 loop_suppliers => $loop_suppliers,
151 supplier => ( $booksellerid || $supplier ),
152 count => $supplier_count,
155 output_html_with_http_headers $query, $cookie, $template->output;