X-Git-Url: http://git.rot13.org/?a=blobdiff_plain;f=admin%2Fmarc_subfields_structure.pl;h=24c8005800a8c96b0cf953509e90af5ff5bf8666;hb=8dad1582c100017f8ad3e331c9a9b9cc9ed4e4d6;hp=c8b7815fec6804f0727d3772b6493f4f80ac4aad;hpb=a6c9bd0eb55c32d5632625144775271f20aa15f7;p=koha.git diff --git a/admin/marc_subfields_structure.pl b/admin/marc_subfields_structure.pl index c8b7815fec..24c8005800 100755 --- a/admin/marc_subfields_structure.pl +++ b/admin/marc_subfields_structure.pl @@ -17,13 +17,16 @@ # You should have received a copy of the GNU General Public License # along with Koha; if not, see . -use strict; -#use warnings; FIXME - Bug 2505 +use Modern::Perl; use C4::Output; use C4::Auth; use CGI qw ( -utf8 ); use C4::Context; +use Koha::Authority::Types; +use Koha::AuthorisedValueCategories; + +use List::MoreUtils qw( uniq ); sub string_search { my ( $searchstring, $frameworkcode ) = @_; @@ -62,7 +65,7 @@ my $tagfield = $input->param('tagfield'); my $tagsubfield = $input->param('tagsubfield'); my $frameworkcode = $input->param('frameworkcode'); my $pkfield = "tagfield"; -my $offset = $input->param('offset'); +my $offset = $input->param('offset') || 0; my $script_name = "/cgi-bin/koha/admin/marc_subfields_structure.pl"; my ( $template, $borrowernumber, $cookie ) = get_template_and_user( @@ -75,9 +78,9 @@ my ( $template, $borrowernumber, $cookie ) = get_template_and_user( debug => 1, } ); -my $cache = Koha::Cache->get_instance(); +my $cache = Koha::Caches->get_instance(); -my $op = $input->param('op'); +my $op = $input->param('op') || ""; $tagfield =~ s/\,//g; if ($op) { @@ -100,9 +103,7 @@ else { ################## ADD_FORM ################################## # called by default. Used to create form to add or modify a record if ( $op eq 'add_form' ) { - my $data; my $dbh = C4::Context->dbh; - my $more_subfields = $input->param("more_subfields") + 1; # builds kohafield tables my @kohafields; @@ -128,24 +129,11 @@ if ( $op eq 'add_form' ) { $sth2->finish; $sth2 = $dbh->prepare("select distinct category from authorised_values"); $sth2->execute; - my @authorised_values; - push @authorised_values, ""; - while ( ( my $category ) = $sth2->fetchrow_array ) { - push @authorised_values, $category; - } - push( @authorised_values, "branches" ); - push( @authorised_values, "itemtypes" ); - push( @authorised_values, "cn_source" ); + my @av_cat = Koha::AuthorisedValueCategories->search; + my @authorised_values = map { $_->category_name } @av_cat; # build thesaurus categories list - $sth2->finish; - $sth2 = $dbh->prepare("select authtypecode from auth_types"); - $sth2->execute; - my @authtypes; - push @authtypes, ""; - while ( ( my $authtypecode ) = $sth2->fetchrow_array ) { - push @authtypes, $authtypecode; - } + my @authtypes = uniq( "", map { $_->authtypecode } Koha::Authority::Types->search ); # build value_builder list my @value_builder = (''); @@ -154,9 +142,9 @@ if ( $op eq 'add_form' ) { # 2 cases here : on CVS install, $cgidir does not need a /cgi-bin # on a standard install, /cgi-bin need to be added. # test one, then the other - my $cgidir = C4::Context->intranetdir . "/cgi-bin"; + my $cgidir = C4::Context->config('intranetdir') . "/cgi-bin"; unless ( opendir( DIR, "$cgidir/cataloguing/value_builder" ) ) { - $cgidir = C4::Context->intranetdir; + $cgidir = C4::Context->config('intranetdir'); opendir( DIR, "$cgidir/cataloguing/value_builder" ) || die "can't opendir $cgidir/value_builder: $!"; } @@ -177,135 +165,56 @@ if ( $op eq 'add_form' ) { $sth->execute( $tagfield, $frameworkcode ); my @loop_data = (); my $i = 0; - while ( $data = $sth->fetchrow_hashref ) { + while ( my $data = $sth->fetchrow_hashref ) { my %row_data; # get a fresh hash for the row data - $row_data{defaultvalue} = $data->{defaultvalue}; - $row_data{maxlength} = $data->{maxlength}; - $row_data{tab} = { - id => "tab$i", - default => $data->{'tab'}, - }; - - $row_data{tagsubfield} = - $data->{'tagsubfield'} - . "{'tagsubfield'} - . "\" id=\"tagsubfield\" />"; - $row_data{subfieldcode} = $data->{'tagsubfield'} eq '@'?'_':$data->{'tagsubfield'}; - $row_data{urisubfieldcode} = $row_data{subfieldcode} eq '%' ? 'pct' : $row_data{subfieldcode}; - $row_data{liblibrarian} = CGI::escapeHTML( $data->{'liblibrarian'} ); - $row_data{libopac} = CGI::escapeHTML( $data->{'libopac'} ); - $row_data{seealso} = CGI::escapeHTML( $data->{'seealso'} ); - $row_data{kohafield} = { - id => "kohafield$i", - values => \@kohafields, - default => "$data->{'kohafield'}", - }; - $row_data{authorised_value} = { - id => "authorised_value$i", - values => \@authorised_values, - default => $data->{'authorised_value'}, - }; - $row_data{value_builder} = { - id => "value_builder$i", - values => \@value_builder, - default => $data->{'value_builder'}, - }; - $row_data{authtypes} = { - id => "authtypecode$i", - values => \@authtypes, - default => $data->{'authtypecode'}, - }; - $row_data{repeatable} = CGI::checkbox( - -name => "repeatable$i", - -checked => $data->{'repeatable'} ? 'checked' : '', - -value => 1, - -label => '', - -id => "repeatable$i" - ); - $row_data{mandatory} = CGI::checkbox( - -name => "mandatory$i", - -checked => $data->{'mandatory'} ? 'checked' : '', - -value => 1, - -label => '', - -id => "mandatory$i" - ); - $row_data{hidden} = CGI::escapeHTML( $data->{hidden} ); - $row_data{isurl} = CGI::checkbox( - -name => "isurl$i", - -id => "isurl$i", - -checked => $data->{'isurl'} ? 'checked' : '', - -value => 1, - -label => '' - ); - $row_data{row} = $i; - $row_data{link} = CGI::escapeHTML( $data->{'link'} ); + $row_data{defaultvalue} = $data->{defaultvalue}; + $row_data{maxlength} = $data->{maxlength}; + $row_data{tab} = $data->{tab}; + $row_data{tagsubfield} = $data->{tagsubfield}; + $row_data{subfieldcode} = $data->{'tagsubfield'} eq '@' ? '_' : $data->{'tagsubfield'}; + $row_data{urisubfieldcode} = $row_data{subfieldcode} eq '%' ? 'pct' : $row_data{subfieldcode}; + $row_data{liblibrarian} = $data->{'liblibrarian'}; + $row_data{libopac} = $data->{'libopac'}; + $row_data{seealso} = $data->{'seealso'}; + $row_data{kohafields} = \@kohafields; + $row_data{kohafield} = $data->{kohafield}; + $row_data{authorised_values} = \@authorised_values; + $row_data{authorised_value} = $data->{authorised_value}; + $row_data{value_builders} = \@value_builder; + $row_data{value_builder} = $data->{'value_builder'}; + $row_data{authtypes} = \@authtypes; + $row_data{authtypecode} = $data->{'authtypecode'}; + $row_data{repeatable} = $data->{repeatable}; + $row_data{mandatory} = $data->{mandatory}; + $row_data{hidden} = $data->{hidden}; + $row_data{isurl} = $data->{isurl}; + $row_data{row} = $i; + $row_data{link} = $data->{'link'}; push( @loop_data, \%row_data ); $i++; } - # add more_subfields empty lines for add if needed - my %row_data; # get a fresh hash for the row data - $row_data{'new_subfield'} = 1; - $row_data{'subfieldcode'} = ''; - $row_data{'maxlength'} = 9999; - - $row_data{tab} = { - id => "tab$i", - default => $data->{'tab'}, - }; - $row_data{tagsubfield} = - "{'tagsubfield'} - . "\" size=\"1\" id=\"tagsubfield\" maxlength=\"1\" />"; - $row_data{liblibrarian} = ""; - $row_data{libopac} = ""; - $row_data{seealso} = ""; - $row_data{kohafield} = { - id => "kohafield$i", - values => \@kohafields, - default => "$data->{'kohafield'}", - }; - $row_data{hidden} = ""; - $row_data{repeatable} = CGI::checkbox( - -name => "repeatable$i", - -id => "repeatable$i", - -checked => '', - -value => 1, - -label => '' - ); - $row_data{mandatory} = CGI::checkbox( - -name => "mandatory$i", - -id => "mandatory$i", - -checked => '', - -value => 1, - -label => '' - ); - $row_data{isurl} = CGI::checkbox( - -name => "isurl$i", - -id => "isurl$i", - -checked => '', - -value => 1, - -label => '' - ); - $row_data{value_builder} = { - id => "value_builder$i", - values => \@value_builder, - default => $data->{'value_builder'}, - }; - $row_data{authorised_value} = { - id => "authorised_value$i", - values => \@authorised_values, - default => $data->{'authorised_value'}, - }; - $row_data{authtypes} = { - id => "authtypecode$i", - values => \@authtypes, - default => $data->{'authtypecode'}, - }; - $row_data{link} = CGI::escapeHTML( $data->{'link'} ); - $row_data{row} = $i; - push( @loop_data, \%row_data ); + # Add a new row for the "New" tab + my %row_data; # get a fresh hash for the row data + $row_data{'new_subfield'} = 1; + $row_data{'subfieldcode'} = ''; + $row_data{'maxlength'} = 9999; + $row_data{tab} = -1; #ignore + $row_data{tagsubfield} = ""; + $row_data{liblibrarian} = ""; + $row_data{libopac} = ""; + $row_data{seealso} = ""; + $row_data{hidden} = ""; + $row_data{repeatable} = 0; + $row_data{mandatory} = 0; + $row_data{isurl} = 0; + $row_data{kohafields} = \@kohafields; + $row_data{authorised_values} = \@authorised_values; + $row_data{value_builders} = \@value_builder; + $row_data{authtypes} = \@authtypes; + $row_data{link} = ""; + $row_data{row} = $i; + push( @loop_data, \%row_data ); $template->param( 'use_heading_flags_p' => 1 ); $template->param( 'heading_edit_subfields_p' => 1 ); @@ -313,7 +222,6 @@ if ( $op eq 'add_form' ) { action => "Edit subfields", tagfield => $tagfield, loop => \@loop_data, - more_subfields => $more_subfields, more_tag => $tagfield ); @@ -336,19 +244,19 @@ elsif ( $op eq 'add_validate' ) { update marc_subfield_structure set tagfield=?, tagsubfield=?, liblibrarian=?, libopac=?, repeatable=?, mandatory=?, kohafield=?, tab=?, seealso=?, authorised_value=?, authtypecode=?, value_builder=?, hidden=?, isurl=?, frameworkcode=?, link=?, defaultvalue=?, maxlength=? where tagfield=? and tagsubfield=? and frameworkcode=? }); - my @tagsubfield = $input->param('tagsubfield'); - my @liblibrarian = $input->param('liblibrarian'); - my @libopac = $input->param('libopac'); - my @kohafield = $input->param('kohafield'); - my @tab = $input->param('tab'); - my @seealso = $input->param('seealso'); - my @hidden = $input->param('hidden'); - my @authorised_values = $input->param('authorised_value'); - my @authtypecodes = $input->param('authtypecode'); - my @value_builder = $input->param('value_builder'); - my @link = $input->param('link'); - my @defaultvalue = $input->param('defaultvalue'); - my @maxlength = $input->param('maxlength'); + my @tagsubfield = $input->multi_param('tagsubfield'); + my @liblibrarian = $input->multi_param('liblibrarian'); + my @libopac = $input->multi_param('libopac'); + my @kohafield = $input->multi_param('kohafield'); + my @tab = $input->multi_param('tab'); + my @seealso = $input->multi_param('seealso'); + my @hidden = $input->multi_param('hidden'); + my @authorised_values = $input->multi_param('authorised_value'); + my @authtypecodes = $input->multi_param('authtypecode'); + my @value_builder = $input->multi_param('value_builder'); + my @link = $input->multi_param('link'); + my @defaultvalue = $input->multi_param('defaultvalue'); + my @maxlength = $input->multi_param('maxlength'); for ( my $i = 0 ; $i <= $#tagsubfield ; $i++ ) { my $tagfield = $input->param('tagfield'); @@ -372,7 +280,8 @@ elsif ( $op eq 'add_validate' ) { my $maxlength = $maxlength[$i] ? $maxlength[$i] : 9999; if (defined($liblibrarian) && $liblibrarian ne "") { - unless ( C4::Context->config('demo') eq 1 ) { + my $is_demo = C4::Context->config('demo') || ''; + if ( $is_demo ne '1' ) { if (marc_subfield_structure_exists($tagfield, $tagsubfield, $frameworkcode)) { $sth_update->execute( $tagfield, @@ -428,6 +337,8 @@ elsif ( $op eq 'add_validate' ) { $sth_update->finish; $cache->clear_from_cache("MarcStructure-0-$frameworkcode"); $cache->clear_from_cache("MarcStructure-1-$frameworkcode"); + $cache->clear_from_cache("default_value_for_mod_marc-$frameworkcode"); + $cache->clear_from_cache("MarcSubfieldStructure-$frameworkcode"); print $input->redirect("/cgi-bin/koha/admin/marc_subfields_structure.pl?tagfield=$tagfield&frameworkcode=$frameworkcode"); exit; @@ -461,7 +372,8 @@ elsif ( $op eq 'delete_confirm' ) { } elsif ( $op eq 'delete_confirmed' ) { my $dbh = C4::Context->dbh; - unless ( C4::Context->config('demo') eq 1 ) { + my $is_demo = C4::Context->config('demo') || ''; + if ( $is_demo ne '1' ) { my $sth = $dbh->prepare( "delete from marc_subfield_structure where tagfield=? and tagsubfield=? and frameworkcode=?" @@ -471,6 +383,8 @@ elsif ( $op eq 'delete_confirmed' ) { } $cache->clear_from_cache("MarcStructure-0-$frameworkcode"); $cache->clear_from_cache("MarcStructure-1-$frameworkcode"); + $cache->clear_from_cache("default_value_for_mod_marc-$frameworkcode"); + $cache->clear_from_cache("MarcSubfieldStructure-$frameworkcode"); print $input->redirect("/cgi-bin/koha/admin/marc_subfields_structure.pl?tagfield=$tagfield&frameworkcode=$frameworkcode"); exit;