3 # This file is part of Koha.
5 # Copyright 2013 BibLibre
7 # Koha is free software; you can redistribute it and/or modify it under the
8 # terms of the GNU General Public License as published by the Free Software
9 # Foundation; either version 3 of the License, or (at your option) any later
12 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License along
17 # with Koha; if not, see <http://www.gnu.org/licenses>.
24 use Koha::AdditionalField;
28 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
30 template_name => "admin/additional-fields.tt",
34 flagsrequired => { parameters => 1 },
39 my $tablename = $input->param('tablename');
40 my $op = $input->param('op') // ( $tablename ? 'list' : 'list_tables' );
41 my $field_id = $input->param('field_id');
45 my $name = $input->param('name') // q{};
46 my $authorised_value_category = $input->param('authorised_value_category') // q{};
47 my $marcfield = $input->param('marcfield') // q{};
48 my $searchable = $input->param('searchable') ? 1 : 0;
49 if ( $field_id and $name ) {
52 my $af = Koha::AdditionalField->new({
55 authorised_value_category => $authorised_value_category,
56 marcfield => $marcfield,
57 searchable => $searchable,
59 $updated = $af->update;
68 my $af = Koha::AdditionalField->new({
69 tablename => $tablename,
71 authorised_value_category => $authorised_value_category,
72 marcfield => $marcfield,
73 searchable => $searchable,
75 $inserted = $af->insert;
90 if ( $op eq 'delete' ) {
93 my $af = Koha::AdditionalField->new( { id => $field_id } );
94 $deleted = $af->delete;
95 $deleted = 0 if $deleted eq '0E0';
104 if ( $op eq 'add_form' ) {
107 $field = Koha::AdditionalField->new( { id => $field_id } )->fetch;
110 $tablename = $field->{tablename} if $field;
117 if ( $op eq 'list' ) {
118 my $fields = Koha::AdditionalField->all( { tablename => $tablename } );
119 $template->param( fields => $fields );
124 tablename => $tablename,
125 messages => \@messages,
128 output_html_with_http_headers $input, $cookie, $template->output;