Bug 14285: Bengali locale needs to be re-defined
[koha.git] / admin / aqcontract.pl
blob095d70c6225c97ec1ffe555b44b0b115c11329a7
1 #!/usr/bin/perl
3 #script to administer the contract table
4 #written 02/09/2008 by john.soros@biblibre.com
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 use strict;
24 use warnings;
25 use CGI qw ( -utf8 );
26 use C4::Context;
27 use C4::Auth;
28 use C4::Output;
29 use C4::Dates qw/format_date format_date_in_iso/;
30 use C4::Contract;
32 use Koha::Acquisition::Bookseller;
34 my $input = new CGI;
35 my $contractnumber = $input->param('contractnumber');
36 my $booksellerid = $input->param('booksellerid');
37 my $op = $input->param('op') || 'list';
39 my $bookseller = Koha::Acquisition::Bookseller->fetch({ id => $booksellerid });
41 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
42 { template_name => "admin/aqcontract.tt",
43 query => $input,
44 type => "intranet",
45 authnotrequired => 0,
46 flagsrequired => { acquisition => 'contracts_manage' },
47 debug => 1,
51 $template->param(
52 contractnumber => $contractnumber,
53 booksellerid => $booksellerid,
54 booksellername => $bookseller->{name},
55 basketcount => $bookseller->{'basketcount'},
56 subscriptioncount => $bookseller->{'subscriptioncount'},
59 #ADD_FORM: called if $op is 'add_form'. Used to create form to add or modify a record
60 if ( $op eq 'add_form' ) {
61 $template->param( add_form => 1 );
63 # if contractnumber exists, it's a modify action, so read values to modify...
64 if ($contractnumber) {
65 my $contract = GetContract({
66 contractnumber => $contractnumber
67 });
69 $template->param(
70 contractnumber => $contract->{contractnumber},
71 contractname => $contract->{contractname},
72 contractdescription => $contract->{contractdescription},
73 contractstartdate => format_date( $contract->{contractstartdate} ),
74 contractenddate => format_date( $contract->{contractenddate} ),
76 } else {
77 $template->param(
78 contractnumber => undef,
79 contractname => undef,
80 contractdescription => undef,
81 contractstartdate => undef,
82 contractenddate => undef,
86 # END $OP eq ADD_FORM
88 #ADD_VALIDATE: called by add_form, used to insert/modify data in DB
89 elsif ( $op eq 'add_validate' ) {
90 ## Please see file perltidy.ERR
91 $template->param( add_validate => 1 );
93 my $is_a_modif = $input->param("is_a_modif");
95 if ( $is_a_modif ) {
96 ModContract({
97 contractstartdate => format_date_in_iso( $input->param('contractstartdate') ),
98 contractenddate => format_date_in_iso( $input->param('contractenddate') ),
99 contractname => $input->param('contractname'),
100 contractdescription => $input->param('contractdescription'),
101 booksellerid => $input->param('booksellerid'),
102 contractnumber => $input->param('contractnumber'),
104 } else {
105 AddContract({
106 contractname => $input->param('contractname'),
107 contractdescription => $input->param('contractdescription'),
108 booksellerid => $input->param('booksellerid'),
109 contractstartdate => format_date_in_iso( $input->param('contractstartdate') ),
110 contractenddate => format_date_in_iso( $input->param('contractenddate') ),
114 print $input->redirect("/cgi-bin/koha/acqui/supplier.pl?booksellerid=$booksellerid");
115 exit;
117 # END $OP eq ADD_VALIDATE
119 #DELETE_CONFIRM: called by default form, used to confirm deletion of data in DB
120 elsif ( $op eq 'delete_confirm' ) {
121 $template->param( delete_confirm => 1 );
123 my $contract = GetContract( { contractnumber => $contractnumber } );
125 $template->param(
126 contractnumber => $$contract{contractnumber},
127 contractname => $$contract{contractname},
128 contractdescription => $$contract{contractdescription},
129 contractstartdate => format_date( $$contract{contractstartdate} ),
130 contractenddate => format_date( $$contract{contractenddate} ),
133 # END $OP eq DELETE_CONFIRM
135 #DELETE_CONFIRMED: called by delete_confirm, used to effectively confirm deletion of data in DB
136 elsif ( $op eq 'delete_confirmed' ) {
137 my $deleted = DelContract( { contractnumber => $contractnumber } );
139 if ( $deleted ) {
140 print $input->redirect("/cgi-bin/koha/acqui/supplier.pl?booksellerid=$booksellerid");
141 exit;
142 } else {
143 $template->param( error => 'not_deleted' );
144 $op = 'list';
147 # END $OP eq LIST
149 # DEFAULT: Builds a list of contracts and displays them
150 if ( $op eq 'list' ) {
151 $template->param(else => 1);
153 # get contracts
154 my @contracts = @{GetContracts( { booksellerid => $booksellerid } )};
156 # format dates
157 for ( @contracts ) {
158 $$_{contractstartdate} = format_date($$_{contractstartdate});
159 $$_{contractenddate} = format_date($$_{contractenddate});
162 $template->param(loop => \@contracts);
164 #---- END $OP eq DEFAULT
167 output_html_with_http_headers $input, $cookie, $template->output;