use CGI qw ( -utf8 );
use Koha::Database;
-use C4::Auth;
-use C4::Biblio;
-use C4::Output;
+use C4::Auth qw( get_template_and_user );
+use C4::Output qw( output_html_with_http_headers );
use Koha::BiblioFrameworks;
use Koha::Caches;
use Koha::MarcSubfieldStructures;
-my $input = new CGI;
+my $input = CGI->new;
my ( $template, $borrowernumber, $cookie ) = get_template_and_user (
{
template_name => "admin/koha2marclinks.tt",
query => $input,
type => "intranet",
- authnotrequired => 0,
- flagsrequired => { parameters => 'parameters_remaining_permissions' },
- debug => 1,
+ flagsrequired => { parameters => 'manage_marc_frameworks' },
}
);
# Update data before showing the form
my $no_upd;
-if( $input->param('add_field') ) {
+if( $input->param('add_field') && $input->request_method eq 'POST' ) {
# add a mapping to all frameworks
my ($kohafield, $tag, $sub) = split /,/, $input->param('add_field'), 3;
- Koha::MarcSubfieldStructures->search({ tagfield => $tag, tagsubfield => $sub })->update({ kohafield => $kohafield });
+ my $rs = Koha::MarcSubfieldStructures->search({ tagfield => $tag, tagsubfield => $sub });
+ if( $rs->count ) {
+ $rs->update({ kohafield => $kohafield });
+ } else {
+ $template->param( error_add => 1, error_info => "$tag, $sub" );
+ }
-} elsif( $input->param('remove_field') ) {
+} elsif( $input->param('remove_field') && $input->request_method eq 'POST' ) {
# remove a mapping from all frameworks
my ($tag, $sub) = split /,/, $input->param('remove_field'), 2;
Koha::MarcSubfieldStructures->search({ tagfield => $tag, tagsubfield => $sub })->update({ kohafield => undef });
foreach my $col ( @cols ) {
my $found;
my $readonly = $col =~ /\.(biblio|biblioitem|item)number$/;
- foreach my $row ( $kohafields->search({ kohafield => $col }) ) {
+ foreach my $row ( $kohafields->search({ kohafield => $col })->as_list ) {
$found = 1;
push @loop_data, {
kohafield => $col,