bug_10781: Remove C4::ILSDI::Utility
[koha.git] / admin / aqcontract.pl
blobab513e7fe6afcfe6e36eb6ef1278f668867c98d4
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 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
20 # with Koha; if not, write to the Free Software Foundation, Inc.,
21 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 use strict;
24 use warnings;
25 use CGI;
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::Bookseller qw/GetBookSellerFromId/;
31 use C4::Contract;
33 my $input = new CGI;
34 my $contractnumber = $input->param('contractnumber');
35 my $booksellerid = $input->param('booksellerid');
36 my $op = $input->param('op') || '';
38 my $bookseller = GetBookSellerFromId($booksellerid);
40 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
41 { template_name => "admin/aqcontract.tmpl",
42 query => $input,
43 type => "intranet",
44 authnotrequired => 0,
45 flagsrequired => { acquisition => 'contracts_manage' },
46 debug => 1,
50 $template->param(
51 contractnumber => $contractnumber,
52 booksellerid => $booksellerid,
53 booksellername => $bookseller->{name},
54 basketcount => $bookseller->{'basketcount'},
55 subscriptioncount => $bookseller->{'subscriptioncount'},
58 #ADD_FORM: called if $op is 'add_form'. Used to create form to add or modify a record
59 if ( $op eq 'add_form' ) {
60 $template->param( add_form => 1 );
62 # if contractnumber exists, it's a modify action, so read values to modify...
63 if ($contractnumber) {
64 my $contract =
65 @{ GetContract( { contractnumber => $contractnumber } ) }[0];
67 $template->param(
68 contractnumber => $contract->{contractnumber},
69 contractname => $contract->{contractname},
70 contractdescription => $contract->{contractdescription},
71 contractstartdate => format_date( $contract->{contractstartdate} ),
72 contractenddate => format_date( $contract->{contractenddate} ),
74 } else {
75 $template->param(
76 contractnumber => undef,
77 contractname => undef,
78 contractdescription => undef,
79 contractstartdate => undef,
80 contractenddate => undef,
84 # END $OP eq ADD_FORM
86 #ADD_VALIDATE: called by add_form, used to insert/modify data in DB
87 elsif ( $op eq 'add_validate' ) {
88 ## Please see file perltidy.ERR
89 $template->param( add_validate => 1 );
91 my $is_a_modif = $input->param("is_a_modif");
93 if ( $is_a_modif ) {
94 ModContract({
95 contractstartdate => format_date_in_iso( $input->param('contractstartdate') ),
96 contractenddate => format_date_in_iso( $input->param('contractenddate') ),
97 contractname => $input->param('contractname'),
98 contractdescription => $input->param('contractdescription'),
99 booksellerid => $input->param('booksellerid'),
100 contractnumber => $input->param('contractnumber'),
102 } else {
103 AddContract({
104 contractname => $input->param('contractname'),
105 contractdescription => $input->param('contractdescription'),
106 booksellerid => $input->param('booksellerid'),
107 contractstartdate => format_date_in_iso( $input->param('contractstartdate') ),
108 contractenddate => format_date_in_iso( $input->param('contractenddate') ),
112 print $input->redirect("/cgi-bin/koha/acqui/supplier.pl?booksellerid=$booksellerid");
113 exit;
115 # END $OP eq ADD_VALIDATE
117 #DELETE_CONFIRM: called by default form, used to confirm deletion of data in DB
118 elsif ( $op eq 'delete_confirm' ) {
119 $template->param( delete_confirm => 1 );
121 my $contract = @{GetContract( { contractnumber => $contractnumber } )}[0];
123 $template->param(
124 contractnumber => $$contract{contractnumber},
125 contractname => $$contract{contractname},
126 contractdescription => $$contract{contractdescription},
127 contractstartdate => format_date( $$contract{contractstartdate} ),
128 contractenddate => format_date( $$contract{contractenddate} ),
131 # END $OP eq DELETE_CONFIRM
133 #DELETE_CONFIRMED: called by delete_confirm, used to effectively confirm deletion of data in DB
134 elsif ( $op eq 'delete_confirmed' ) {
135 $template->param( delete_confirmed => 1 );
137 DelContract( { contractnumber => $contractnumber } );
139 print $input->redirect("/cgi-bin/koha/acqui/supplier.pl?booksellerid=$booksellerid");
140 exit;
142 # END $OP eq DELETE_CONFIRMED
144 # DEFAULT: Builds a list of contracts and displays them
145 else {
146 $template->param(else => 1);
148 # get contracts
149 my @contracts = @{GetContract( { booksellerid => $booksellerid } )};
151 # format dates
152 for ( @contracts ) {
153 $$_{contractstartdate} = format_date($$_{contractstartdate});
154 $$_{contractenddate} = format_date($$_{contractenddate});
157 $template->param(loop => \@contracts);
159 #---- END $OP eq DEFAULT
162 output_html_with_http_headers $input, $cookie, $template->output;