diff --git a/admin/marctagstructure.pl b/admin/marctagstructure.pl index 96eeedfef2..1e89615e0d 100755 --- a/admin/marctagstructure.pl +++ b/admin/marctagstructure.pl @@ -28,6 +28,7 @@ use C4::Context; use Koha::Caches; use Koha::AuthorisedValues; use Koha::BiblioFrameworks; +use Koha::Database; # retrieve parameters my $input = CGI->new; @@ -120,6 +121,7 @@ if ($op eq 'add_form') { my $authorised_value = $input->param('authorised_value'); my $ind1_defaultvalue = $input->param('ind1_defaultvalue'); my $ind2_defaultvalue = $input->param('ind2_defaultvalue'); + my $error; if ($input->param('modif')) { $sth = $dbh->prepare( "UPDATE marc_tag_structure SET liblibrarian=? ,libopac=? ,repeatable=? ,mandatory=? ,important=? ,authorised_value=?, ind1_defaultvalue=?, ind2_defaultvalue=? WHERE frameworkcode=? AND tagfield=?" @@ -136,26 +138,40 @@ if ($op eq 'add_form') { $tagfield ); } else { - $sth = $dbh->prepare( - "INSERT INTO marc_tag_structure (tagfield,liblibrarian,libopac,repeatable,mandatory,important,authorised_value,ind1_defaultvalue,ind2_defaultvalue,frameworkcode) values (?,?,?,?,?,?,?,?,?,?)" - ); - $sth->execute($tagfield, - $liblibrarian, - $libopac, - $repeatable, - $mandatory, - $important, - $authorised_value, - $ind1_defaultvalue, - $ind2_defaultvalue, - $frameworkcode - ); + my $schema = Koha::Database->new()->schema(); + my $rs = $schema->resultset('MarcTagStructure'); + my $field = $rs->find( { tagfield => $tagfield, frameworkcode => $frameworkcode } ); + if ( !$field ) { + $sth = $dbh->prepare( + "INSERT INTO marc_tag_structure (tagfield,liblibrarian,libopac,repeatable,mandatory,important,authorised_value,ind1_defaultvalue,ind2_defaultvalue,frameworkcode) values (?,?,?,?,?,?,?,?,?,?)" + ); + $sth->execute( + $tagfield, + $liblibrarian, + $libopac, + $repeatable, + $mandatory, + $important, + $authorised_value, + $ind1_defaultvalue, + $ind2_defaultvalue, + $frameworkcode + ); + } else { + $error = 'duplicate_tagfield'; + } } - $cache->clear_from_cache("MarcStructure-0-$frameworkcode"); - $cache->clear_from_cache("MarcStructure-1-$frameworkcode"); - $cache->clear_from_cache("MarcSubfieldStructure-$frameworkcode"); - $cache->clear_from_cache("MarcCodedFields-$frameworkcode"); - print $input->redirect("/cgi-bin/koha/admin/marctagstructure.pl?searchfield=$tagfield&frameworkcode=$frameworkcode"); + if ( !$error ) { + $cache->clear_from_cache("MarcStructure-0-$frameworkcode"); + $cache->clear_from_cache("MarcStructure-1-$frameworkcode"); + $cache->clear_from_cache("MarcSubfieldStructure-$frameworkcode"); + $cache->clear_from_cache("MarcCodedFields-$frameworkcode"); + } + my $redirect_url = "/cgi-bin/koha/admin/marctagstructure.pl?searchfield=$tagfield&frameworkcode=$frameworkcode"; + if ($error) { + $redirect_url .= "&error=$error"; + } + print $input->redirect($redirect_url); exit; # END $OP eq ADD_VALIDATE ################## DELETE_CONFIRM ################################## @@ -200,6 +216,12 @@ if ($op eq 'add_form') { ################## DEFAULT ################################## } else { # DEFAULT + my $error_code = $input->param('error'); + if ($error_code){ + if ($error_code eq 'duplicate_tagfield'){ + $template->param('blocking_error' => $error_code); + } + } # here, $op can be unset or set to "cud-framework_create_confirm". if ($searchfield ne '') { $template->param(searchfield => $searchfield); diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/blocking_errors.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/blocking_errors.inc index a4fd22249e..20376d1ed8 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/blocking_errors.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/blocking_errors.inc @@ -22,9 +22,11 @@ [% CASE 'budget_is_locked' %]
[% CASE 'missing_es_modules' %] - + [% CASE 'insufficient_permission' %] + [% CASE 'duplicate_tagfield' %] + [% CASE %]