Bug 22047: Fix opac/opac-passwd.pl call
[koha.git] / acqui / basketheader.pl
blobf4650e8aaafe73f62aae71319399a332ef3cd4ff
1 #!/usr/bin/perl
3 #script to add basket and edit header options (name, notes and contractnumber)
4 #written by john.soros@biblibre.com 15/09/2008
6 # Copyright 2008 - 2009 BibLibre SARL
8 # This file is part of Koha.
10 # Koha is free software; you can redistribute it and/or modify it
11 # under the terms of the GNU General Public License as published by
12 # the Free Software Foundation; either version 3 of the License, or
13 # (at your option) any later version.
15 # Koha is distributed in the hope that it will be useful, but
16 # WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 # GNU General Public License for more details.
20 # You should have received a copy of the GNU General Public License
21 # along with Koha; if not, see <http://www.gnu.org/licenses>.
23 =head1 NAME
25 basketheader.pl
27 =head1 DESCRIPTION
29 This script is used to edit the basket's "header", or add a new basket, the header contains the supplier ID,
30 notes to the supplier, local notes, and the contractnumber, which identifies the basket to a specific contract.
32 =head1 CGI PARAMETERS
34 =over 4
36 =item booksellerid
38 C<$booksellerid> is the id of the supplier we add the basket to.
40 =item basketid
42 If it exists, C<$basketno> is the basket we edit
44 =back
46 =cut
48 use Modern::Perl;
49 use CGI qw ( -utf8 );
50 use C4::Context;
51 use C4::Auth;
52 use C4::Output;
53 use C4::Acquisition qw/GetBasket NewBasket ModBasketHeader/;
54 use C4::Contract qw/GetContracts/;
56 use Koha::Acquisition::Booksellers;
58 my $input = new CGI;
59 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
61 template_name => "acqui/basketheader.tt",
62 query => $input,
63 type => "intranet",
64 authnotrequired => 0,
65 flagsrequired => { acquisition => 'order_manage' },
66 debug => 1,
70 #parameters:
71 my $booksellerid = $input->param('booksellerid');
72 my $basketno = $input->param('basketno');
73 my $basket;
74 my $op = $input->param('op');
75 my $is_an_edit = $input->param('is_an_edit');
77 if ( $op eq 'add_form' ) {
78 my @contractloop;
79 if ( $basketno ) {
80 #this is an edit
81 $basket = GetBasket($basketno);
82 if (! $booksellerid) {
83 $booksellerid=$basket->{'booksellerid'};
85 my $contracts = GetContracts({
86 booksellerid => $booksellerid,
87 activeonly => 1,
88 });
90 @contractloop = @$contracts;
91 for (@contractloop) {
92 if ( $basket->{'contractnumber'} eq $_->{'contractnumber'} ) {
93 $_->{'selected'} = 1;
96 $template->param( is_an_edit => 1);
97 } else {
98 #new basket
99 my $basket;
100 my $contracts = GetContracts({
101 booksellerid => $booksellerid,
102 activeonly => 1,
104 push(@contractloop, @$contracts);
106 my $bookseller = Koha::Acquisition::Booksellers->find( $booksellerid );
107 my $count = scalar @contractloop;
108 if ( $count > 0) {
109 $template->param(contractloop => \@contractloop,
110 basketcontractnumber => $basket->{'contractnumber'});
112 my @booksellers = Koha::Acquisition::Booksellers->search(
113 undef,
114 { order_by => { -asc => 'name' } } );
116 $template->param( add_form => 1,
117 basketname => $basket->{'basketname'},
118 basketnote => $basket->{'note'},
119 basketbooksellernote => $basket->{'booksellernote'},
120 booksellername => $bookseller->name,
121 booksellerid => $booksellerid,
122 basketno => $basketno,
123 booksellers => \@booksellers,
124 is_standing => $basket->{is_standing},
127 my $billingplace = $basket->{'billingplace'} || C4::Context->userenv->{"branch"};
128 my $deliveryplace = $basket->{'deliveryplace'} || C4::Context->userenv->{"branch"};
130 $template->param( billingplace => $billingplace );
131 $template->param( deliveryplace => $deliveryplace );
133 #End Edit
134 } elsif ( $op eq 'add_validate' ) {
135 #we are confirming the changes, save the basket
136 if ( $is_an_edit ) {
137 ModBasketHeader(
138 $basketno,
139 scalar $input->param('basketname'),
140 scalar $input->param('basketnote'),
141 scalar $input->param('basketbooksellernote'),
142 scalar $input->param('basketcontractnumber') || undef,
143 scalar $input->param('basketbooksellerid'),
144 scalar $input->param('deliveryplace'),
145 scalar $input->param('billingplace'),
146 scalar $input->param('is_standing') ? 1 : undef,
147 scalar $input->param('create_items')
149 } else { #New basket
150 $basketno = NewBasket(
151 $booksellerid,
152 $loggedinuser,
153 scalar $input->param('basketname'),
154 scalar $input->param('basketnote'),
155 scalar $input->param('basketbooksellernote'),
156 scalar $input->param('basketcontractnumber') || undef,
157 scalar $input->param('deliveryplace'),
158 scalar $input->param('billingplace'),
159 scalar $input->param('is_standing') ? 1 : undef,
160 scalar $input->param('create_items')
163 print $input->redirect('basket.pl?basketno='.$basketno);
164 exit 0;
166 output_html_with_http_headers $input, $cookie, $template->output;