Bug 2524: Adding script to submit test reports to smolder server
[koha_fer] / admin / marc_subfields_structure.pl
index 22e887c..473e50a 100755 (executable)
@@ -19,7 +19,6 @@
 
 use strict;
 use C4::Output;
-use C4::Interface::CGI::Output;
 use C4::Auth;
 use CGI;
 use C4::Context;
@@ -104,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;
@@ -127,6 +126,7 @@ if ( $op eq 'add_form' ) {
     }
     push( @authorised_values, "branches" );
     push( @authorised_values, "itemtypes" );
+    push( @authorised_values, "cn_source" );
 
     # build thesaurus categories list
     $sth2->finish;
@@ -156,6 +156,7 @@ if ( $op eq 'add_form' ) {
             push( @value_builder, $line );
         }
     }
+    @value_builder= sort {$a cmp $b} @value_builder;
     closedir DIR;
 
     # build values list
@@ -204,8 +205,9 @@ 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{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'} );
@@ -278,8 +280,11 @@ if ( $op eq 'add_form' ) {
     }
 
     # add more_subfields empty lines for add if needed
-    for ( my $j = $i ; $j <= $more_subfields + $i ; $j++ ) {
+    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(
             -name   => 'tab',
             -id     => "tab$j",
@@ -307,7 +312,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}      = "";
@@ -374,13 +379,13 @@ if ( $op eq 'add_form' ) {
         $row_data{toggle} = $toggle;
         $row_data{row}    = $j;
         push( @loop_data, \%row_data );
+        use Data::Dumper;
     }
     $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
@@ -414,6 +419,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;
@@ -469,8 +475,7 @@ elsif ( $op eq 'delete_confirm' ) {
 "select * from marc_subfield_structure where tagfield=? and tagsubfield=? and frameworkcode=?"
       );
 
-    #FIXME : called with 2 bind variables when 3 are needed
-    $sth->execute( $tagfield, $tagsubfield );
+    $sth->execute( $tagfield, $tagsubfield, $frameworkcode );
     my $data = $sth->fetchrow_hashref;
     $sth->finish;
     $template->param(
@@ -538,7 +543,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 ) {
@@ -556,12 +561,12 @@ else {    # DEFAULT
     if ( $offset > 0 ) {
         my $prevpage = $offset - $pagesize;
         $template->param(
-            prev => "<a href=\"$script_name?offset=$prevpage\">" );
+            prev => "<a href=\"$script_name?offset=$prevpage\&tagfield=$tagfield\&frameworkcode=$frameworkcode \">" );
     }
     if ( $offset + $pagesize < $count ) {
         my $nextpage = $offset + $pagesize;
         $template->param(
-            next => "<a href=\"$script_name?offset=$nextpage\">" );
+            next => "<a href=\"$script_name?offset=$nextpage\&tagfield=$tagfield\&frameworkcode=$frameworkcode \">" );
     }
 }    #---- END $OP eq DEFAULT