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;
25 use Koha::AdditionalFields;
30 $flagsrequired{parameters} = 'manage_additional_fields';
32 my $tablename = $input->param('tablename');
33 my $op = $input->param('op') // ( $tablename ? 'list' : 'list_tables' );
35 if( $op ne 'list_tables' ){
36 $flagsrequired{acquisition} = 'order_manage' if $tablename eq 'aqbasket';
37 $flagsrequired{serials} = 'edit_subscription' if $tablename eq 'subscription';
40 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
42 template_name => "admin/additional-fields.tt",
46 flagsrequired => \%flagsrequired,
51 my $field_id = $input->param('field_id');
55 my $name = $input->param('name') // q{};
56 my $authorised_value_category = $input->param('authorised_value_category') // q{};
57 my $marcfield = $input->param('marcfield') // q{};
58 my $searchable = $input->param('searchable') ? 1 : 0;
59 if ( $field_id and $name ) {
62 my $af = Koha::AdditionalFields->find($field_id);
65 authorised_value_category => $authorised_value_category,
66 marcfield => $marcfield,
67 searchable => $searchable,
69 $updated = $af->store ? 1 : 0;
78 my $af = Koha::AdditionalField->new({
79 tablename => $tablename,
81 authorised_value_category => $authorised_value_category,
82 marcfield => $marcfield,
83 searchable => $searchable,
85 $inserted = $af->store ? 1 : 0;
100 if ( $op eq 'delete' ) {
103 my $af = Koha::AdditionalFields->find($field_id);
104 $deleted = $af->delete;
113 if ( $op eq 'add_form' ) {
116 $field = Koha::AdditionalFields->find($field_id);
119 $tablename = $field->tablename if $field;
126 if ( $op eq 'list' ) {
127 my $fields = Koha::AdditionalFields->search( { tablename => $tablename } );
128 $template->param( fields => $fields );
133 tablename => $tablename,
134 messages => \@messages,
137 output_html_with_http_headers $input, $cookie, $template->output;