All patches to Koha 3 beta to date. All work with branches.
[koha.git] / admin / marc_subfields_structure.pl
index 376273e..0a414e6 100755 (executable)
@@ -103,13 +103,13 @@ if ( $op eq 'add_form' ) {
     while ( ( my $field ) = $sth2->fetchrow_array ) {
         push @kohafields, "biblio." . $field;
     }
-    my $sth2 = $dbh->prepare("SHOW COLUMNS from biblioitems");
+    $sth2 = $dbh->prepare("SHOW COLUMNS from biblioitems");
     $sth2->execute;
     while ( ( my $field ) = $sth2->fetchrow_array ) {
         if ( $field eq 'notes' ) { $field = 'bnotes'; }
         push @kohafields, "biblioitems." . $field;
     }
-    my $sth2 = $dbh->prepare("SHOW COLUMNS from items");
+    $sth2 = $dbh->prepare("SHOW COLUMNS from items");
     $sth2->execute;
     while ( ( my $field ) = $sth2->fetchrow_array ) {
         push @kohafields, "items." . $field;
@@ -155,6 +155,7 @@ if ( $op eq 'add_form' ) {
             push( @value_builder, $line );
         }
     }
+    @value_builder= sort {$a cmp $b} @value_builder;
     closedir DIR;
 
     # build values list
@@ -203,8 +204,8 @@ if ( $op eq 'add_form' ) {
             $data->{'tagsubfield'}
           . "<input type=\"hidden\" name=\"tagsubfield\" value=\""
           . $data->{'tagsubfield'}
-          . "\" id=\"tagsubfield\">";
-        $row_data{subfieldcode} = $data->{'tagsubfield'};
+          . "\" id=\"tagsubfield\" />";
+        $row_data{subfieldcode} = $data->{'tagsubfield'} eq '@'?'_':$data->{'tagsubfield'};
         $row_data{liblibrarian} = CGI::escapeHTML( $data->{'liblibrarian'} );
         $row_data{libopac}      = CGI::escapeHTML( $data->{'libopac'} );
         $row_data{seealso}      = CGI::escapeHTML( $data->{'seealso'} );
@@ -279,6 +280,7 @@ if ( $op eq 'add_form' ) {
     # add more_subfields empty lines for add if needed
     for ( my $j = 1 ; $j <= 1 ; $j++ ) {
         my %row_data;    # get a fresh hash for the row data
+        $row_data{'new_subfield'} = 1;
         $row_data{'subfieldcode'} = '';
 
         $row_data{tab} = CGI::scrolling_list(
@@ -308,7 +310,7 @@ if ( $op eq 'add_form' ) {
         $row_data{tagsubfield} =
             "<input type=\"text\" name=\"tagsubfield\" value=\""
           . $data->{'tagsubfield'}
-          . "\" size=\"1\" id=\"tagsubfield\" maxlength=\"1\">";
+          . "\" size=\"1\" id=\"tagsubfield\" maxlength=\"1\" />";
         $row_data{liblibrarian} = "";
         $row_data{libopac}      = "";
         $row_data{seealso}      = "";
@@ -376,14 +378,12 @@ if ( $op eq 'add_form' ) {
         $row_data{row}    = $j;
         push( @loop_data, \%row_data );
         use Data::Dumper;
-        warn "push : ".Dumper(%row_data);
     }
     $template->param( 'use-heading-flags-p'      => 1 );
     $template->param( 'heading-edit-subfields-p' => 1 );
     $template->param(
         action   => "Edit subfields",
-        tagfield =>
-"<input type=\"hidden\" name=\"tagfield\" value=\"$tagfield\">$tagfield",
+        tagfield => $tagfield,
         loop           => \@loop_data,
         more_subfields => $more_subfields,
         more_tag       => $tagfield
@@ -417,6 +417,7 @@ elsif ( $op eq 'add_validate' ) {
         my $tagfield    = $input->param('tagfield');
         my $tagsubfield = $tagsubfield[$i];
         $tagsubfield = "@" unless $tagsubfield ne '';
+        $tagsubfield = "@" if $tagsubfield eq '_';
         my $liblibrarian     = $liblibrarian[$i];
         my $libopac          = $libopac[$i];
         my $repeatable       = $input->param("repeatable$i") ? 1 : 0;
@@ -540,7 +541,7 @@ else {    # DEFAULT
         $row_data{delete}           =
 "$script_name?op=delete_confirm&amp;tagfield=$tagfield&amp;tagsubfield="
           . $results->[$i]{'tagsubfield'}
-          . "&frameworkcode=$frameworkcode";
+          . "&amp;frameworkcode=$frameworkcode";
         $row_data{toggle} = $toggle;
 
         if ( $row_data{tab} eq -1 ) {