X-Git-Url: http://koha-dev.rot13.org:8081/gitweb/?a=blobdiff_plain;f=admin%2Fmarc_subfields_structure.pl;h=7884d0bc2b7700d1de0dd903a2f6fe984e8196db;hb=286c3c3a9e34f08da1fac8a48ce1925058a214ea;hp=0db96a3e3c8972438295a7cd8d7245fdd1cb49d7;hpb=bfec1aa5ae116b5ec5159d68be1c25e15f3c9430;p=koha_fer diff --git a/admin/marc_subfields_structure.pl b/admin/marc_subfields_structure.pl index 0db96a3e3c..7884d0bc2b 100755 --- a/admin/marc_subfields_structure.pl +++ b/admin/marc_subfields_structure.pl @@ -24,7 +24,7 @@ use CGI; use C4::Context; -sub StringSearch { +sub string_search { my ( $searchstring, $frameworkcode ) = @_; my $dbh = C4::Context->dbh; $searchstring =~ s/\'/\\\'/g; @@ -49,6 +49,14 @@ sub StringSearch { return ( $cnt, \@results ); } +sub marc_subfield_structure_exists { + my ($tagfield, $tagsubfield, $frameworkcode) = @_; + my $dbh = C4::Context->dbh; + my $sql = "select tagfield from marc_subfield_structure where tagfield = ? and tagsubfield = ? and frameworkcode = ?"; + my $rows = $dbh->selectall_arrayref($sql, {}, $tagfield, $tagsubfield, $frameworkcode); + return @$rows > 0; +} + my $input = new CGI; my $tagfield = $input->param('tagfield'); my $tagsubfield = $input->param('tagsubfield'); @@ -382,10 +390,18 @@ if ( $op eq 'add_form' ) { elsif ( $op eq 'add_validate' ) { my $dbh = C4::Context->dbh; $template->param( tagfield => "$input->param('tagfield')" ); - my $sth = $dbh->prepare( -"replace marc_subfield_structure (tagfield,tagsubfield,liblibrarian,libopac,repeatable,mandatory,kohafield,tab,seealso,authorised_value,authtypecode,value_builder,hidden,isurl,frameworkcode, link,defaultvalue) - values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)" - ); +# my $sth = $dbh->prepare( +# "replace marc_subfield_structure (tagfield,tagsubfield,liblibrarian,libopac,repeatable,mandatory,kohafield,tab,seealso,authorised_value,authtypecode,value_builder,hidden,isurl,frameworkcode, link,defaultvalue) +# values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)" +# ); + my $sth_insert = $dbh->prepare(qq{ + insert into marc_subfield_structure (tagfield,tagsubfield,liblibrarian,libopac,repeatable,mandatory,kohafield,tab,seealso,authorised_value,authtypecode,value_builder,hidden,isurl,frameworkcode, link,defaultvalue) + values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?) + }); + my $sth_update = $dbh->prepare(qq{ + update marc_subfield_structure set tagfield=?, tagsubfield=?, liblibrarian=?, libopac=?, repeatable=?, mandatory=?, kohafield=?, tab=?, seealso=?, authorised_value=?, authtypecode=?, value_builder=?, hidden=?, isurl=?, frameworkcode=?, link=?, defaultvalue=? + where tagfield=? and tagsubfield=? and frameworkcode=? + }); my @tagsubfield = $input->param('tagsubfield'); my @liblibrarian = $input->param('liblibrarian'); my @libopac = $input->param('libopac'); @@ -421,29 +437,57 @@ elsif ( $op eq 'add_validate' ) { if ($liblibrarian) { unless ( C4::Context->config('demo') eq 1 ) { - $sth->execute( - $tagfield, - $tagsubfield, - $liblibrarian, - $libopac, - $repeatable, - $mandatory, - $kohafield, - $tab, - $seealso, - $authorised_value, - $authtypecode, - $value_builder, - $hidden, - $isurl, - $frameworkcode, - $link, - $defaultvalue, - ); + if (marc_subfield_structure_exists($tagfield, $tagsubfield, $frameworkcode)) { + $sth_update->execute( + $tagfield, + $tagsubfield, + $liblibrarian, + $libopac, + $repeatable, + $mandatory, + $kohafield, + $tab, + $seealso, + $authorised_value, + $authtypecode, + $value_builder, + $hidden, + $isurl, + $frameworkcode, + $link, + $defaultvalue, + ( + $tagfield, + $tagsubfield, + $frameworkcode, + ), + ); + } else { + $sth_insert->execute( + $tagfield, + $tagsubfield, + $liblibrarian, + $libopac, + $repeatable, + $mandatory, + $kohafield, + $tab, + $seealso, + $authorised_value, + $authtypecode, + $value_builder, + $hidden, + $isurl, + $frameworkcode, + $link, + $defaultvalue, + ); + } } } } - $sth->finish; + $sth_insert->finish; + $sth_update->finish; print "Content-Type: text/html\n\n"; exit; @@ -494,7 +538,7 @@ elsif ( $op eq 'delete_confirmed' ) { ################## DEFAULT ################################## } else { # DEFAULT - my ( $count, $results ) = StringSearch( $tagfield, $frameworkcode ); + my ( $count, $results ) = string_search( $tagfield, $frameworkcode ); my $toggle = 1; my @loop_data = (); for (