All patches to Koha 3 beta to date. All work with branches.
[koha.git] / admin / marc_subfields_structure.pl
index 137a609..0a414e6 100755 (executable)
 
 use strict;
 use C4::Output;
-use C4::Interface::CGI::Output;
 use C4::Auth;
 use CGI;
 use C4::Context;
 
 
 sub StringSearch {
-    my ( $env, $searchstring, $frameworkcode ) = @_;
+    my ( $searchstring, $frameworkcode ) = @_;
     my $dbh = C4::Context->dbh;
     $searchstring =~ s/\'/\\\'/g;
     my @data  = split( ' ', $searchstring );
@@ -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;
@@ -156,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
@@ -175,6 +175,7 @@ if ( $op eq 'add_form' ) {
         else {
             $toggle = 1;
         }
+        $row_data{defaultvalue} = $data->{defaultvalue};
         $row_data{tab} = CGI::scrolling_list(
             -name   => 'tab',
             -id     => "tab$i",
@@ -203,7 +204,8 @@ if ( $op eq 'add_form' ) {
             $data->{'tagsubfield'}
           . "<input type=\"hidden\" name=\"tagsubfield\" value=\""
           . $data->{'tagsubfield'}
-          . "\" id=\"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'} );
@@ -270,14 +272,17 @@ if ( $op eq 'add_form' ) {
         );
         $row_data{row}    = $i;
         $row_data{toggle} = $toggle;
-        $row_data{link}   = CGI::escapeHTML( $data->{'link'} );
+        $row_data{link}   = CGI::escapeHTML( $data->{'link'} ); 
         push( @loop_data, \%row_data );
         $i++;
     }
 
     # 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",
@@ -305,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}      = "";
@@ -372,13 +377,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
@@ -392,8 +397,8 @@ 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)
-                                    values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)"
+"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 @tagsubfield       = $input->param('tagsubfield');
     my @liblibrarian      = $input->param('liblibrarian');
@@ -406,11 +411,13 @@ elsif ( $op eq 'add_validate' ) {
     my @authtypecodes     = $input->param('authtypecode');
     my @value_builder     = $input->param('value_builder');
     my @link              = $input->param('link');
-
+    my @defaultvalue      = $input->param('defaultvalue');
+    
     for ( my $i = 0 ; $i <= $#tagsubfield ; $i++ ) {
         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;
@@ -424,7 +431,8 @@ elsif ( $op eq 'add_validate' ) {
         my $hidden = $hidden[$i];                     #input->param("hidden$i");
         my $isurl  = $input->param("isurl$i") ? 1 : 0;
         my $link   = $link[$i];
-
+        my $defaultvalue = $defaultvalue[$i];
+        
         if ($liblibrarian) {
             unless ( C4::Context->config('demo') eq 1 ) {
                 $sth->execute(
@@ -443,8 +451,8 @@ elsif ( $op eq 'add_validate' ) {
                     $hidden,
                     $isurl,
                     $frameworkcode,
-
                     $link,
+                    $defaultvalue,
                 );
             }
         }
@@ -465,8 +473,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(
@@ -501,8 +508,7 @@ elsif ( $op eq 'delete_confirmed' ) {
 ################## DEFAULT ##################################
 }
 else {    # DEFAULT
-    my $env;
-    my ( $count, $results ) = StringSearch( $env, $tagfield, $frameworkcode );
+    my ( $count, $results ) = StringSearch( $tagfield, $frameworkcode );
     my $toggle    = 1;
     my @loop_data = ();
     for (
@@ -535,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 ) {
@@ -561,10 +567,5 @@ else {    # DEFAULT
             next => "<a href=\"$script_name?offset=$nextpage\">" );
     }
 }    #---- END $OP eq DEFAULT
-$template->param(
-    intranetcolorstylesheet =>
-      C4::Context->preference("intranetcolorstylesheet"),
-    intranetstylesheet => C4::Context->preference("intranetstylesheet"),
-    IntranetNav        => C4::Context->preference("IntranetNav"),
-);
+
 output_html_with_http_headers $input, $cookie, $template->output;