3 # Copyright 2000-2002 Katipo Communications
4 # Copyright 2017 Rijksmuseum
6 # This file is part of Koha.
8 # Koha is free software; you can redistribute it and/or modify it
9 # under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 3 of the License, or
11 # (at your option) any later version.
13 # Koha is distributed in the hope that it will be useful, but
14 # WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with Koha; if not, see <http://www.gnu.org/licenses>.
25 use C4::Auth qw( get_template_and_user );
26 use C4::Output qw( output_html_with_http_headers );
27 use Koha::BiblioFrameworks;
29 use Koha::MarcSubfieldStructures;
32 my $op = $input->param('op') // q{};
34 my ( $template, $borrowernumber, $cookie ) = get_template_and_user (
36 template_name => "admin/koha2marclinks.tt",
39 flagsrequired => { parameters => 'manage_marc_frameworks' },
43 my $schema = Koha::Database->new->schema;
44 my $cache = Koha::Caches->get_instance();
46 # Update data before showing the form
49 if( $input->param('add_field') && $op eq 'cud-save' ) {
50 # add a mapping to all frameworks
51 my ($kohafield, $tag, $sub) = split /,/, $input->param('add_field'), 3;
52 my $rs = Koha::MarcSubfieldStructures->search({ tagfield => $tag, tagsubfield => $sub });
54 $rs->update({ kohafield => $kohafield });
56 $template->param( error_add => 1, error_info => "$tag, $sub" );
59 } elsif( $input->param('remove_field') && $op eq 'cud-save' ) {
60 # remove a mapping from all frameworks
61 my ($tag, $sub) = split /,/, $input->param('remove_field'), 2;
62 Koha::MarcSubfieldStructures->search({ tagfield => $tag, tagsubfield => $sub })->update({ kohafield => undef });
68 # Clear the cache when needed
70 $cache->clear_from_cache("MarcSubfieldStructure-");
75 # Koha to MARC mappings are found in only three tables
77 biblioitems => 'Biblioitem',
81 foreach my $tbl ( sort keys %{$dbix_map} ) {
83 map { "$tbl.$_" } $schema->source( $dbix_map->{$tbl} )->columns;
85 my $kohafields = Koha::MarcSubfieldStructures->search({
87 kohafield => { '>', '' },
90 foreach my $col ( @cols ) {
92 my $readonly = $col =~ /\.(biblio|biblioitem|item)number$/;
93 foreach my $row ( $kohafields->search({ kohafield => $col })->as_list ) {
97 tagfield => $row->tagfield,
98 tagsubfield => $row->tagsubfield,
99 liblibrarian => $row->liblibrarian,
100 readonly => $readonly,
105 readonly => $readonly,
113 output_html_with_http_headers $input, $cookie, $template->output;