]> git.koha-community.org Git - koha.git/blob - acqui/booksellers.pl
Bug 11715: Update POD for get_template_and_user
[koha.git] / acqui / booksellers.pl
1 #!/usr/bin/perl
2
3 #script to show suppliers and orders
4
5 # Copyright 2000-2002 Katipo Communications
6 # Copyright 2008-2009 BibLibre SARL
7 # Copyright 2010 PTFS Europe
8 #
9 # This file is part of Koha.
10 #
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.
15 #
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.
19 #
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.
23
24 =head1 NAME
25
26 booksellers.pl
27
28 =head1 DESCRIPTION
29
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.
33
34 =head1 CGI PARAMETERS
35
36 =over 4
37
38 =item supplier
39
40 C<$supplier> is the string with which we search for a supplier
41
42 =back
43
44 =over 4
45
46 =item id or booksellerid
47
48 The id of the supplier whose baskets we will display
49
50 =back
51
52 =cut
53
54 use strict;
55 use warnings;
56 use C4::Auth;
57 use C4::Biblio;
58 use C4::Output;
59 use CGI;
60
61 use C4::Acquisition qw/ GetBasketsInfosByBookseller /;
62 use C4::Bookseller qw/ GetBookSellerFromId GetBookSeller /;
63 use C4::Members qw/GetMember/;
64 use C4::Context;
65
66 my $query = CGI->new;
67 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
68     {   template_name   => 'acqui/booksellers.tmpl',
69         query           => $query,
70         type            => 'intranet',
71         authnotrequired => 0,
72         flagsrequired   => { acquisition => '*' },
73         debug           => 1,
74     }
75 );
76
77 #parameters
78 my $supplier = $query->param('supplier');
79 my $booksellerid = $query->param('booksellerid');
80 my $allbaskets= $query->param('allbaskets')||0;
81 my @suppliers;
82
83 if ($booksellerid) {
84     push @suppliers, GetBookSellerFromId($booksellerid);
85 } else {
86     @suppliers = GetBookSeller($supplier);
87 }
88
89 my $supplier_count = @suppliers;
90 if ( $supplier_count == 1 ) {
91     $template->param(
92         supplier_name => $suppliers[0]->{'name'},
93         booksellerid  => $suppliers[0]->{'id'},
94         basketcount   => $suppliers[0]->{'basketcount'}
95     );
96 }
97
98 my $uid;
99 if ($loggedinuser) {
100     $uid = GetMember( borrowernumber => $loggedinuser )->{userid};
101 }
102
103 my $userenv = C4::Context::userenv;
104 my $viewbaskets = C4::Context->preference('AcqViewBaskets');
105
106 my $userbranch = $userenv->{branch};
107
108 #build result page
109 my $loop_suppliers = [];
110
111 for my $vendor (@suppliers) {
112     my $baskets = GetBasketsInfosByBookseller( $vendor->{id}, $allbaskets );
113
114     my $loop_basket = [];
115
116     for my $basket ( @{$baskets} ) {
117         my $authorisedby = $basket->{authorisedby};
118         my $basketbranch = ''; # set a blank branch to start with
119         my $member = GetMember( borrowernumber => $authorisedby );
120         if ( $member ) {
121            $basketbranch = $member->{branchcode};
122         }
123
124         if ($userenv->{'flags'} & 1 || #user is superlibrarian
125                (haspermission( $uid, { acquisition => q{*} } ) && #user has acq permissions and
126                    ($viewbaskets eq 'all' || #user is allowed to see all baskets
127                    ($viewbaskets eq 'branch' && $authorisedby && $userbranch eq $basketbranch) || #basket belongs to user's branch
128                    ($basket->{authorisedby} &&  $viewbaskets eq 'user' && $authorisedby == $loggedinuser) #user created this basket
129                    ) 
130                 ) 
131            ) { 
132             foreach (qw(total_items total_biblios expected_items)) {
133                 $basket->{$_} ||= 0;
134             }
135             if($member) {
136                 $basket->{authorisedby_firstname} = $member->{firstname};
137                 $basket->{authorisedby_surname} = $member->{surname};
138             }
139             push @{$loop_basket}, $basket; 
140         }
141     }
142
143     push @{$loop_suppliers},
144       { loop_basket => $loop_basket,
145         booksellerid  => $vendor->{id},
146         name        => $vendor->{name},
147         active      => $vendor->{active},
148       };
149
150 }
151 $template->param(
152     loop_suppliers => $loop_suppliers,
153     supplier       => ( $booksellerid || $supplier ),
154     count          => $supplier_count,
155 );
156 $template->{VARS}->{'allbaskets'} = $allbaskets;
157
158 output_html_with_http_headers $query, $cookie, $template->output;