replacing links to bookfunds into budgets
[koha.git] / acqui / basketheader.pl
blob56f2483ad32c17065f6e37450c5c8b94ac6a1347
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 under the
11 # terms of the GNU General Public License as published by the Free Software
12 # Foundation; either version 2 of the License, or (at your option) any later
13 # version.
15 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
16 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
17 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
19 # You should have received a copy of the GNU General Public License along with
20 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
21 # Suite 330, Boston, MA 02111-1307 USA
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 supplierid
38 C<$supplierid> 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 strict;
49 use warnings;
50 use CGI;
51 use C4::Context;
52 use C4::Auth;
53 use C4::Output;
54 use C4::Acquisition qw/GetBasket NewBasket GetContracts ModBasketHeader/;
55 use C4::Bookseller qw/GetBookSellerFromId/;
58 my $input = new CGI;
59 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
61 template_name => "acqui/basketheader.tmpl",
62 query => $input,
63 type => "intranet",
64 authnotrequired => 0,
65 flagsrequired => { acquisition => 'order_manage' },
66 debug => 1,
70 #parameters:
71 my $booksellerid;
72 $booksellerid = $input->param('booksellerid');
73 my $basketno = $input->param('basketno');
74 my $basket;
75 my $op = $input ->param('op');
76 my $is_an_edit= $input ->param('is_an_edit');
78 if ( $op eq 'add_form' ) {
79 my @contractloop;
80 if ( $basketno ) {
81 #this is an edit
82 $basket = GetBasket($basketno);
83 if (! $booksellerid) {
84 $booksellerid=$basket->{'booksellerid'};
86 @contractloop = &GetContracts($booksellerid, 1);
87 for (@contractloop) {
88 if ( $basket->{'contractnumber'} eq $_->{'contractnumber'} ) {
89 $_->{'selected'} = 1;
92 $template->param( is_an_edit => 1);
93 } else {
94 #new basket
95 my $basket;
96 push(@contractloop, &GetContracts($booksellerid, 1));
98 my $bookseller = GetBookSellerFromId($booksellerid);
99 my $count = scalar @contractloop;
100 if ( $count > 0) {
101 $template->param(contractloop => \@contractloop,
102 basketcontractnumber => $basket->{'contractnumber'});
104 $template->param( add_form => 1,
105 basketname => $basket->{'basketname'},
106 basketnote => $basket->{'note'},
107 basketbooksellernote => $basket->{'booksellernote'},
108 booksellername => $bookseller->{'name'},
109 booksellerid => $booksellerid,
110 basketno => $basketno
112 #End Edit
113 } elsif ( $op eq 'add_validate' ) {
114 #we are confirming the changes, save the basket
115 $template->param(add_validate => 1);
116 if ( $is_an_edit ) {
117 ModBasketHeader($input->param('basketno'),$input->param('basketname'),$input->param('basketnote'),$input->param('basketbooksellernote'),$input->param('basketcontractnumber'));
118 $template->param( basketno => $basketno );
119 } else { #New basket
120 my $basketno = NewBasket($booksellerid, $loggedinuser, $input->param('basketname'), $input->param('basketnote'), $input->param('basketbooksellernote'), $input->param('basketcontractnumber'));
121 $template->param( basketno => $basketno );
124 output_html_with_http_headers $input, $cookie, $template->output;