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
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.
29 use C4
::Dates qw
/format_date format_date_in_iso/;
32 use Koha
::Acquisition
::Bookseller
;
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",
46 flagsrequired
=> { acquisition
=> 'contracts_manage' },
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
70 contractnumber
=> $contract->{contractnumber
},
71 contractname
=> $contract->{contractname
},
72 contractdescription
=> $contract->{contractdescription
},
73 contractstartdate
=> format_date
( $contract->{contractstartdate
} ),
74 contractenddate
=> format_date
( $contract->{contractenddate
} ),
78 contractnumber
=> undef,
79 contractname
=> undef,
80 contractdescription
=> undef,
81 contractstartdate
=> undef,
82 contractenddate
=> undef,
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");
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'),
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");
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 } );
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 } );
140 print $input->redirect("/cgi-bin/koha/acqui/supplier.pl?booksellerid=$booksellerid");
143 $template->param( error
=> 'not_deleted' );
149 # DEFAULT: Builds a list of contracts and displays them
150 if ( $op eq 'list' ) {
151 $template->param(else => 1);
154 my @contracts = @
{GetContracts
( { booksellerid
=> $booksellerid } )};
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;