#1444: Porting marcEditor to authorities (tab management)
authorPaul POULAIN <paul@koha-fr.org>
Tue, 9 Oct 2007 21:46:38 +0000 (16:46 -0500)
committerJoshua Ferraro <jmf@liblime.com>
Wed, 10 Oct 2007 00:01:59 +0000 (19:01 -0500)
+ reindenting some code

Signed-off-by: Chris Cormack <crc@liblime.com>
Signed-off-by: Joshua Ferraro <jmf@liblime.com>
C4/AuthoritiesMarc.pm
admin/auth_subfields_structure.pl
authorities/authorities.pl
authorities/blinddetail-biblio-search.pl
authorities/detail.pl
koha-tmpl/intranet-tmpl/prog/en/modules/admin/auth_subfields_structure.tmpl
koha-tmpl/intranet-tmpl/prog/en/modules/authorities/authorities.tmpl
koha-tmpl/intranet-tmpl/prog/en/modules/authorities/blinddetail-biblio-search.tmpl
koha-tmpl/intranet-tmpl/prog/en/modules/authorities/detail.tmpl

index a48aaf3..71e9c04 100644 (file)
@@ -418,7 +418,7 @@ sub GetTagsLabels {
   my ($total) = $sth->fetchrow;
   $authtypecode="" unless ($total >0);
   $sth= $dbh->prepare(
-"SELECT tagfield,liblibrarian,libopac,mandatory,repeatable 
+"SELECT auth_tag_structure.tagfield,auth_tag_structure.liblibrarian,auth_tag_structure.libopac,auth_tag_structure.mandatory,auth_tag_structure.repeatable 
  FROM auth_tag_structure 
  WHERE authtypecode=? 
  ORDER BY tagfield"
@@ -434,7 +434,7 @@ sub GetTagsLabels {
         $res->{$tag}->{repeatable} = $repeatable;
   }
   $sth=      $dbh->prepare(
-"SELECT tagfield,tagsubfield,liblibrarian,libopac,tab, mandatory, repeatable,authorised_value,authtypecode,value_builder,kohafield,seealso,hidden,isurl 
+"SELECT tagfield,tagsubfield,liblibrarian,libopac,tab, mandatory, repeatable,authorised_value,frameworkcode as authtypecode,value_builder,kohafield,seealso,hidden,isurl 
 FROM auth_subfield_structure 
 WHERE authtypecode=? 
 ORDER BY tagfield,tagsubfield"
index 295c7ae..eefc481 100755 (executable)
@@ -151,9 +151,21 @@ if ($op eq 'add_form') {
                }
                $row_data{tab} = CGI::scrolling_list(-name=>'tab',
                                        -id=>"tab$i",
-                                       -values=>['-1','0'],
-                                       -labels => {'-1' =>'ignore','0'=>'0',
-                                                                       },
+                                        -values =>
+                                        [ '-1', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '10' ],
+                                        -labels => {
+                                            '-1' => 'ignore',
+                                            '0'  => '0',
+                                            '1'  => '1',
+                                            '2'  => '2',
+                                            '3'  => '3',
+                                            '4'  => '4',
+                                            '5'  => '5',
+                                            '6'  => '6',
+                                            '7'  => '7',
+                                            '8'  => '8',
+                                            '9'  => '9',
+                                        },
                                        -default=>$data->{'tab'},
                                        -size=>1,
                                        -tabindex=>'',
@@ -251,9 +263,21 @@ if ($op eq 'add_form') {
                my %row_data;  # get a fresh hash for the row data
                $row_data{tab} = CGI::scrolling_list(-name=>'tab',
                                        -id => "tab$i",
-                                       -values=>['-1','0'],
-                                       -labels => {'-1' =>'ignore','0'=>'0',
-                                                                       },
+                                        -values =>
+                                        [ '-1', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '10' ],
+                                        -labels => {
+                                            '-1' => 'ignore',
+                                            '0'  => '0',
+                                            '1'  => '1',
+                                            '2'  => '2',
+                                            '3'  => '3',
+                                            '4'  => '4',
+                                            '5'  => '5',
+                                            '6'  => '6',
+                                            '7'  => '7',
+                                            '8'  => '8',
+                                            '9'  => '9',
+                                        },
                                        -default=>"",
                                        -size=>1,
                                        -tabindex=>'',
index 3fca416..064dcf0 100755 (executable)
@@ -26,7 +26,7 @@ use C4::Output;
 use C4::AuthoritiesMarc;
 use C4::Context;
 use C4::Koha; # XXX subfield_is_koha_internal_p
-
+use Date::Calc qw(Today);
 use MARC::File::USMARC;
 use MARC::File::XML;
 use C4::Biblio;
@@ -35,7 +35,7 @@ use vars qw( $authorised_values_sth);
 use vars qw( $is_a_modif );
 
 my $itemtype; # created here because it can be used in build_authorized_values_list sub
-
+our($authorised_values_sth,$is_a_modif,$usedTagsLib,$mandatory_z3950);
 =item find_value
 
     ($indicators, $value) = find_value($tag, $subfield, $record,$encoding);
@@ -76,234 +76,417 @@ sub find_value {
 
 =cut
 
-sub build_authorized_values_list ($$$$$) {
-       my($tag, $subfield, $value, $dbh,$authorised_values_sth) = @_;
+sub build_authorized_values_list ($$$$$$$) {
+    my ( $tag, $subfield, $value, $dbh, $authorised_values_sth,$index_tag,$index_subfield ) = @_;
 
-       my @authorised_values;
-       my %authorised_lib;
+    my @authorised_values;
+    my %authorised_lib;
 
-       # builds list, depending on authorised value...
+    # builds list, depending on authorised value...
 
-       #---- branch
-       if ($tagslib->{$tag}->{$subfield}->{'authorised_value'} eq "branches" ) {
-       my $sth=$dbh->prepare("select branchcode,branchname from branches order by branchname");
-       $sth->execute;
-       push @authorised_values, ""
-               unless ($tagslib->{$tag}->{$subfield}->{mandatory});
+    #---- branch
+    if ( $tagslib->{$tag}->{$subfield}->{'authorised_value'} eq "branches" ) {
+        my $sth =
+          $dbh->prepare(
+            "select branchcode,branchname from branches order by branchname");
+        $sth->execute;
+        push @authorised_values, ""
+          unless ( $tagslib->{$tag}->{$subfield}->{mandatory} );
 
-       while (my ($branchcode,$branchname) = $sth->fetchrow_array) {
-               push @authorised_values, $branchcode;
-               $authorised_lib{$branchcode}=$branchname;
-       }
+        while ( my ( $branchcode, $branchname ) = $sth->fetchrow_array ) {
+            push @authorised_values, $branchcode;
+            $authorised_lib{$branchcode} = $branchname;
+        }
 
-       #----- itemtypes
-       } elsif ($tagslib->{$tag}->{$subfield}->{authorised_value} eq "itemtypes") {
-               my $sth=$dbh->prepare("select itemtype,description from itemtypes order by description");
-               $sth->execute;
-               push @authorised_values, "" unless ($tagslib->{$tag}->{$subfield}->{mandatory});
-       
-               while (my ($itemtype,$description) = $sth->fetchrow_array) {
-                       push @authorised_values, $itemtype;
-                       $authorised_lib{$itemtype}=$description;
-               }
-               $value=$itemtype unless ($value);
+        #----- itemtypes
+    }
+    elsif ( $tagslib->{$tag}->{$subfield}->{authorised_value} eq "itemtypes" ) {
+        my $sth =
+          $dbh->prepare(
+            "select itemtype,description from itemtypes order by description");
+        $sth->execute;
+        push @authorised_values, ""
+          unless ( $tagslib->{$tag}->{$subfield}->{mandatory} );
+          
+        my $itemtype;
+        
+        while ( my ( $itemtype, $description ) = $sth->fetchrow_array ) {
+            push @authorised_values, $itemtype;
+            $authorised_lib{$itemtype} = $description;
+        }
+        $value = $itemtype unless ($value);
+
+        #---- "true" authorised value
+    }
+    else {
+        $authorised_values_sth->execute(
+            $tagslib->{$tag}->{$subfield}->{authorised_value} );
 
-       #---- "true" authorised value
-       } else {
-               $authorised_values_sth->execute($tagslib->{$tag}->{$subfield}->{authorised_value});
+        push @authorised_values, ""
+          unless ( $tagslib->{$tag}->{$subfield}->{mandatory} );
 
-               push @authorised_values, "" unless ($tagslib->{$tag}->{$subfield}->{mandatory});
-       
-               while (my ($value,$lib) = $authorised_values_sth->fetchrow_array) {
-                       push @authorised_values, $value;
-                       $authorised_lib{$value}=$lib;
-               }
+        while ( my ( $value, $lib ) = $authorised_values_sth->fetchrow_array ) {
+            push @authorised_values, $value;
+            $authorised_lib{$value} = $lib;
+        }
     }
-    return CGI::scrolling_list( -name     => 'field_value',
-                               -values   => \@authorised_values,
-                               -default  => $value,
-                               -labels   => \%authorised_lib,
-                               -override => 1,
-                               -size     => 1,
-                               -tabindex=>'',
-                               -multiple => 0 );
+    return CGI::scrolling_list(
+        -name     => "tag_".$tag."_subfield_".$subfield."_".$index_tag."_".$index_subfield,
+        -values   => \@authorised_values,
+        -default  => $value,
+        -labels   => \%authorised_lib,
+        -override => 1,
+        -size     => 1,
+        -multiple => 0,
+        -tabindex => 1,
+        -id       => "tag_".$tag."_subfield_".$subfield."_".$index_tag."_".$index_subfield,
+        -class    => "input_marceditor",
+    );
 }
 
 
 =item create_input
  builds the <input ...> entry for a subfield.
 =cut
-sub create_input () {
-       my ($tag,$subfield,$value,$i,$tabloop,$rec,$authorised_values_sth) = @_;
-       # must be encoded as utf-8 before it reaches the editor
-       my $dbh=C4::Context->dbh;
-       $value =~ s/"/&quot;/g;
-       my %subfield_data;
-       $subfield_data{tag}=$tag;
-       $subfield_data{subfield}=$subfield;
-       $subfield_data{marc_lib}="<span id=\"error$i\">".$tagslib->{$tag}->{$subfield}->{lib}."</span>";
-       $subfield_data{marc_lib_plain}=$tagslib->{$tag}->{$subfield}->{lib};
-       $subfield_data{tag_mandatory}=$tagslib->{$tag}->{mandatory};
-       $subfield_data{mandatory}=$tagslib->{$tag}->{$subfield}->{mandatory};
-       $subfield_data{repeatable}=$tagslib->{$tag}->{$subfield}->{repeatable};
-       $subfield_data{kohafield}=$tagslib->{$tag}->{$subfield}->{kohafield};
-       $subfield_data{index} = $i;
-       $subfield_data{visibility} = "display:none" if (substr($tagslib->{$tag}->{$subfield}->{hidden},2,1) gt "0") ; #check parity
-       # it's an authorised field
-       if ($tagslib->{$tag}->{$subfield}->{authorised_value}) {
-               $subfield_data{marc_value}= build_authorized_values_list($tag, $subfield, $value, $dbh,$authorised_values_sth);
-       # it's a thesaurus / authority field
-       } elsif ($tagslib->{$tag}->{$subfield}->{frameworkcode}) {
-               $subfield_data{marc_value}="<input type=\"text\" name=\"field_value\" value=\"$value\" size=\"67\" maxlength=\"255\" DISABLE READONLY> <a href=\"javascript:Dopop('../authorities/auth_finder.pl?authtypecode=".$tagslib->{$tag}->{$subfield}->{frameworkcode}."&index=$i',$i)\">...</a>";
-       } elsif ($tagslib->{$tag}->{$subfield}->{link}) {
-               $subfield_data{marc_value}="<input onblur=\"this.style.backgroundColor='#ffffff';\" onfocus=\"this.style.backgroundColor='#ffffff;'\" tabindex=\"1\" type=\"text\" name=\"field_value\" value=\"$value\" size=\"40\" maxlength=\"255\" DISABLE READONLY> <a  style=\"cursor: help;\" href=\"javascript:Dopop('../authorities/auth_linker.pl?index=$i',$i)\">...</a>";
-       
-               # it's a plugin field
-       } elsif ($tagslib->{$tag}->{$subfield}->{'value_builder'}) {
-               # opening plugin. Just check wether we are on a developper computer on a production one
-               # (the cgidir differs)
-               my $cgidir = C4::Context->intranetdir ."/cgi-bin/cataloguing/value_builder";
-               unless (opendir(DIR, "$cgidir")) {
-                       $cgidir = C4::Context->intranetdir."/cataloguing/value_builder";
-               } 
-               my $plugin=$cgidir."/".$tagslib->{$tag}->{$subfield}->{'value_builder'}; 
-               require $plugin;
-               my $extended_param = plugin_parameters($dbh,$rec,$tagslib,$i,$tabloop);
-               my ($function_name,$javascript) = plugin_javascript($dbh,$rec,$tagslib,$i,$tabloop);
-               $subfield_data{marc_value}="<input tabindex=\"1\" type=\"text\" name=\"field_value\"  value=\"$value\" size=\"40\" maxlength=\"255\" OnFocus=\"javascript:Focus$function_name($i)\" OnBlur=\"javascript:Blur$function_name($i); \"> <a  style=\"cursor: help;\" href=\"javascript:Clic$function_name($i)\">...</a> $javascript";
-       # it's an hidden field
-       } elsif  ($tag eq '') {
-               $subfield_data{marc_value}="<input onblur=\"this.style.backgroundColor='#ffffff';\" onfocus=\"this.style.backgroundColor='#ffffff'; \" tabindex=\"1\" type=\"hidden\" name=\"field_value\" value=\"$value\">";
-       } elsif  (substr($tagslib->{$tag}->{$subfield}->{'hidden'},2,1) gt "1") {
-
-               $subfield_data{marc_value}="<input onblur=\"this.style.backgroundColor='#ffffff';\" onfocus=\"this.style.backgroundColor='#ffffff'; \" tabindex=\"1\" type=\"text\" name=\"field_value\" value=\"$value\" size=\"40\" maxlength=\"255\" >";
-       # it's a standard field
-       } else {
-               if (length($value) >100) {
-                       $subfield_data{marc_value}="<textarea tabindex=\"1\" name=\"field_value\" cols=\"40\" rows=\"5\" >$value</textarea>";
-               } else {
-                       $subfield_data{marc_value}="<input onblur=\"this.style.backgroundColor='#ffffff';\" onfocus=\"this.style.backgroundColor='#ffffff'; \" tabindex=\"1\" type=\"text\" name=\"field_value\" value=\"$value\" size=\"50\">"; #"
-               }
-       }
-       return \%subfield_data;
+
+sub create_input {
+    my ( $tag, $subfield, $value, $index_tag, $tabloop, $rec, $authorised_values_sth,$cgi ) = @_;
+    
+    my $index_subfield = CreateKey(); # create a specifique key for each subfield
+
+    $value =~ s/"/&quot;/g;
+
+    # if there is no value provided but a default value in parameters, get it
+    unless ($value) {
+        $value = $tagslib->{$tag}->{$subfield}->{defaultvalue};
+
+        # get today date & replace YYYY, MM, DD if provided in the default value
+        my ( $year, $month, $day ) = Today();
+        $month = sprintf( "%02d", $month );
+        $day   = sprintf( "%02d", $day );
+        $value =~ s/YYYY/$year/g;
+        $value =~ s/MM/$month/g;
+        $value =~ s/DD/$day/g;
+    }
+    my $dbh = C4::Context->dbh;
+    my %subfield_data = (
+        tag        => $tag,
+        subfield   => $subfield,
+        marc_lib   => substr( $tagslib->{$tag}->{$subfield}->{lib}, 0, 22 ),
+        marc_lib_plain => $tagslib->{$tag}->{$subfield}->{lib}, 
+        tag_mandatory  => $tagslib->{$tag}->{mandatory},
+        mandatory      => $tagslib->{$tag}->{$subfield}->{mandatory},
+        repeatable     => $tagslib->{$tag}->{$subfield}->{repeatable},
+        kohafield      => $tagslib->{$tag}->{$subfield}->{kohafield},
+        index          => $index_tag,
+        id             => "tag_".$tag."_subfield_".$subfield."_".$index_tag."_".$index_subfield,
+        value          => $value,
+    );
+    if($subfield eq '@'){
+        $subfield_data{id} = "tag_".$tag."_subfield_00_".$index_tag."_".$index_subfield;
+    } else {
+         $subfield_data{id} = "tag_".$tag."_subfield_".$subfield."_".$index_tag."_".$index_subfield;
+    }
+
+    if(exists $mandatory_z3950->{$tag.$subfield}){
+        $subfield_data{z3950_mandatory} = $mandatory_z3950->{$tag.$subfield};
+    }
+    
+    $subfield_data{visibility} = "display:none;"
+        if (    ($tagslib->{$tag}->{$subfield}->{hidden} % 2 == 1) and $value ne ''
+            or ($value eq '' and !$tagslib->{$tag}->{$subfield}->{mandatory})
+        );
+    
+    # it's an authorised field
+    if ( $tagslib->{$tag}->{$subfield}->{authorised_value} ) {
+        $subfield_data{marc_value} =
+          build_authorized_values_list( $tag, $subfield, $value, $dbh,
+            $authorised_values_sth,$index_tag,$index_subfield );
+
+    # it's a thesaurus / authority field
+    }
+    elsif ( $tagslib->{$tag}->{$subfield}->{authtypecode} ) {
+        $subfield_data{marc_value} =
+    "<input type=\"text\"
+                        id=\"".$subfield_data{id}."\"
+                        name=\"".$subfield_data{id}."\"
+      value=\"$value\"
+      class=\"input_marceditor\"
+                        tabindex=\"1\"                     
+      DISABLE READONLY \/>
+      <span class=\"buttonDot\"
+        onclick=\"Dopop('/cgi-bin/koha/authorities/auth_finder.pl?authtypecode=".$tagslib->{$tag}->{$subfield}->{authtypecode}."&index=$subfield_data{id}','$subfield_data{id}')\">...</span>
+    ";
+    # it's a plugin field
+    }
+    elsif ( $tagslib->{$tag}->{$subfield}->{'value_builder'} ) {
+
+        # opening plugin. Just check wether we are on a developper computer on a production one
+        # (the cgidir differs)
+        my $cgidir = C4::Context->intranetdir . "/cgi-bin/cataloguing/value_builder";
+        unless ( opendir( DIR, "$cgidir" ) ) {
+            $cgidir = C4::Context->intranetdir . "/cataloguing/value_builder";
+        }
+        my $plugin = $cgidir . "/" . $tagslib->{$tag}->{$subfield}->{'value_builder'};
+        do $plugin || die "Plugin Failed: ".$plugin;
+        my $extended_param = plugin_parameters( $dbh, $rec, $tagslib, $subfield_data{id}, $tabloop );
+        my ( $function_name, $javascript ) = plugin_javascript( $dbh, $rec, $tagslib, $subfield_data{id}, $tabloop );
+#         my ( $function_name, $javascript,$extended_param );
+        
+        $subfield_data{marc_value} =
+    "<input tabindex=\"1\"
+                        type=\"text\"
+                        id=".$subfield_data{id}."
+      name=".$subfield_data{id}."
+      value=\"$value\"
+                        class=\"input_marceditor\"
+      onfocus=\"javascript:Focus$function_name($index_tag)\"
+      onblur=\"javascript:Blur$function_name($index_tag); \" \/>
+    <span class=\"buttonDot\"
+      onclick=\"Clic$function_name('$subfield_data{id}')\">...</a>
+    $javascript";
+        # it's an hidden field
+    }
+    elsif ( $tag eq '' ) {
+        $subfield_data{marc_value} =
+            "<input tabindex=\"1\"
+                    type=\"hidden\"
+                    id=".$subfield_data{id}."
+                    name=".$subfield_data{id}."
+                    value=\"$value\" \/>
+            ";
+    }
+    elsif ( $tagslib->{$tag}->{$subfield}->{'hidden'} ) {
+        $subfield_data{marc_value} =
+            "<input type=\"text\"
+                    id=".$subfield_data{id}."
+                    name=".$subfield_data{id}."
+                    class=\"input_marceditor\"
+                    tabindex=\"1\"
+                    value=\"$value\"
+            \/>";
+
+        # it's a standard field
+    }
+    else {
+        if (
+            length($value) > 100
+            or
+            ( C4::Context->preference("marcflavour") eq "UNIMARC" && $tag >= 300
+                and $tag < 400 && $subfield eq 'a' )
+            or (    $tag >= 500
+                and $tag < 600
+                && C4::Context->preference("marcflavour") eq "MARC21" )
+          )
+        {
+            $subfield_data{marc_value} =
+                "<textarea cols=\"70\"
+                           rows=\"4\"
+                           id=".$subfield_data{id}."
+                           name=".$subfield_data{id}."
+                           class=\"input_marceditor\"
+                           tabindex=\"1\"
+                           >$value</textarea>
+                ";
+        }
+        else {
+            $subfield_data{marc_value} =
+                "<input type=\"text\"
+                        id=".$subfield_data{id}."
+                        name=".$subfield_data{id}."
+                        value=\"$value\"
+                        tabindex=\"1\"
+                        class=\"input_marceditor\"
+                \/>
+                ";
+        }
+    }
+    $subfield_data{'index_subfield'} = $index_subfield;
+    return \%subfield_data;
+}
+
+=item CreateKey
+
+    Create a random value to set it into the input name
+
+=cut
+
+sub CreateKey(){
+    return int(rand(1000000));
 }
 
-sub build_tabs ($$$$) {
-    my($template, $record, $dbh,$encoding) = @_;
+sub build_tabs ($$$$$) {
+    my ( $template, $record, $dbh, $encoding,$input ) = @_;
+
     # fill arrays
-    my @loop_data =();
+    my @loop_data = ();
     my $tag;
-    my $i=0;
-       my $authorised_values_sth = $dbh->prepare("select authorised_value,lib
-               from authorised_values
-               where category=? order by lib");
-
-# loop through each tab 0 through 9
-       for (my $tabloop = 0; $tabloop <= 9; $tabloop++) {
-               my @loop_data = ();
-               foreach my $tag (sort(keys (%{$tagslib}))) {
-                       my $indicator;
-       # if MARC::Record is not empty => use it as master loop, then add missing subfields that should be in the tab.
-       # if MARC::Record is empty => use tab as master loop.
-                       if ($record ne -1 && ($record->field($tag) || $tag eq '000')) {
-                               my @fields;
-                               if ($tag ne '000') {
-                                       @fields = $record->field($tag);
-                               } else {
-                                       push @fields,$record->leader();
-                               }
-                               foreach my $field (@fields)  {
-                                       my @subfields_data;
-                                       if ($tag<10) {
-                                               my ($value,$subfield);
-                                               if ($tag ne '000') {
-                                                       $value=$field->data();
-                                                       $subfield="@";
-                                               } else {
-                                                       $value = $field;
-                                                       $subfield='@';
-                                               }
-                                               next if ($tagslib->{$tag}->{$subfield}->{tab} ne $tabloop);
-                                       #       next if ($tagslib->{$tag}->{$subfield}->{kohafield} eq 'auth_header.authid');
-                                               push(@subfields_data, &create_input($tag,$subfield,$value,$i,$tabloop,$record,$authorised_values_sth));
-                                               $i++;
-                                       } else {
-                                               my @subfields=$field->subfields();
-                                               foreach my $subfieldcount (0..$#subfields) {
-                                                       my $subfield=$subfields[$subfieldcount][0];
-                                                       my $value=$subfields[$subfieldcount][1];
-                                                       next if (length $subfield !=1);
-                                                       next if ($tagslib->{$tag}->{$subfield}->{tab} ne $tabloop);
-                                                       push(@subfields_data, &create_input($tag,$subfield,$value,$i,$tabloop,$record,$authorised_values_sth));
-                                                       $i++;
-                                               }
-                                       }
-# now, loop again to add parameter subfield that are not in the MARC::Record
-                                       foreach my $subfield (sort( keys %{$tagslib->{$tag}})) {
-                                               next if (length $subfield !=1);
-                                               next if ($tagslib->{$tag}->{$subfield}->{tab} ne $tabloop);
-                                               next if ($tag<10);
-                                               next if ((substr($tagslib->{$tag}->{$subfield}->{hidden},2,1) gt "1")  ); #check for visibility flag
-                                               next if (defined($field->subfield($subfield)));
-                                               push(@subfields_data, &create_input($tag,$subfield,'',$i,$tabloop,$record,$authorised_values_sth));
-                                               $i++;
-                                       }
-                                       if ($#subfields_data >= 0) {
-                                               my %tag_data;
-                                               $tag_data{tag} = $tag;
-                                               $tag_data{tag_lib} = $tagslib->{$tag}->{lib};
-                                               $tag_data{repeatable} = $tagslib->{$tag}->{repeatable};
-                                               $tag_data{indicator} = $record->field($tag)->indicator(1). $record->field($tag)->indicator(2) if ($tag>=10);
-                                               $tag_data{subfield_loop} = \@subfields_data;
-                                               if ($tag<10) {
-                                                       $tag_data{fixedfield} = 1;
-                                               }
-
-                                               push (@loop_data, \%tag_data);
-                                       }
-# If there is more than 1 field, add an empty hidden field as separator.
-                                       if ($#fields >=1 && $#loop_data >=0 && $loop_data[$#loop_data]->{'tag'} eq $tag) {
-                                               my @subfields_data;
-                                               my %tag_data;
-                                               push(@subfields_data, &create_input('','','',$i,$tabloop,$record,$authorised_values_sth));
-                                               $tag_data{tag} = '';
-                                               $tag_data{tag_lib} = '';
-                                               $tag_data{indicator} = '';
-                                               $tag_data{subfield_loop} = \@subfields_data;
-                                               if ($tag<10) {
-                                                               $tag_data{fixedfield} = 1;
-                                               }
-                                               push (@loop_data, \%tag_data);
-                                               $i++;
-                                       }
-                               }
-       
-                       } else {
-                               my @subfields_data;
-                               foreach my $subfield (sort(keys %{$tagslib->{$tag}})) {
-                                       next if (length $subfield !=1);
-                                       next if ((substr($tagslib->{$tag}->{$subfield}->{hidden},2,1) gt "1")  ); #check for visibility flag
-                                       next if ($tagslib->{$tag}->{$subfield}->{tab} ne $tabloop);
-                                       push(@subfields_data, &create_input($tag,$subfield,'',$i,$tabloop,$record,$authorised_values_sth));
-                                       $i++;
-                               }
-                               if ($#subfields_data >= 0) {
-                                       my %tag_data;
-                                       $tag_data{tag} = $tag;
-                                       $tag_data{tag_lib} = $tagslib->{$tag}->{lib};
-                                       $tag_data{repeatable} = $tagslib->{$tag}->{repeatable};
-                                       $tag_data{indicator} = $indicator;
-                                       $tag_data{subfield_loop} = \@subfields_data;
-                                       $tag_data{tagfirstsubfield} = $tag_data{subfield_loop}[0];
-                                       if ($tag<10) {
-                                               $tag_data{fixedfield} = 1;
-                                       }
-                                       push (@loop_data, \%tag_data);
-                               }
-                       }
-               }
-               $template->param($tabloop."XX" =>\@loop_data);
-       }
+
+    my $authorised_values_sth = $dbh->prepare(
+        "select authorised_value,lib
+        from authorised_values
+        where category=? order by lib"
+    );
+    
+    # in this array, we will push all the 10 tabs
+    # to avoid having 10 tabs in the template : they will all be in the same BIG_LOOP
+    my @BIG_LOOP;
+    my %seen;
+    my @tab_data; # all tags to display
+    
+    foreach my $used ( keys %$tagslib ){
+        push @tab_data,$used if not $seen{$used};
+        $seen{$used}++;
+    }
+        
+    my $max_num_tab=9;
+    # loop through each tab 0 through 9
+    for ( my $tabloop = 0 ; $tabloop <= $max_num_tab ; $tabloop++ ) {
+        my @loop_data = (); #innerloop in the template.
+        my $i = 0;
+        foreach my $tag (@tab_data) {
+            $i++;
+            next if ! $tag;
+            my $indicator;
+            my $index_tag = CreateKey;
+
+            # if MARC::Record is not empty =>use it as master loop, then add missing subfields that should be in the tab.
+            # if MARC::Record is empty => use tab as master loop.
+            if ( $record ne -1 && ( $record->field($tag) || $tag eq '000' ) ) {
+                my @fields;
+    if ( $tag ne '000' ) {
+                    @fields = $record->field($tag);
+    }
+    else {
+       push @fields, $record->leader(); # if tag == 000
+    }
+    # loop through each field
+                foreach my $field (@fields) {
+                    
+                    my @subfields_data;
+                    if ( $tag < 10 ) {
+                        my ( $value, $subfield );
+                        if ( $tag ne '000' ) {
+                            $value    = $field->data();
+                            $subfield = "@";
+                        }
+                        else {
+                            $value    = $field;
+                            $subfield = '@';
+                        }
+                        next if ( $tagslib->{$tag}->{$subfield}->{tab} ne $tabloop );
+                        next
+                          if ( $tagslib->{$tag}->{$subfield}->{kohafield} eq
+                            'biblio.biblionumber' );
+                        push(
+                            @subfields_data,
+                            &create_input(
+                                $tag, $subfield, $value, $index_tag, $tabloop, $record,
+                                $authorised_values_sth,$input
+                            )
+                        );
+                    }
+                    else {
+                        my @subfields = $field->subfields();
+                        foreach my $subfieldcount ( 0 .. $#subfields ) {
+                            my $subfield = $subfields[$subfieldcount][0];
+                            my $value    = $subfields[$subfieldcount][1];
+                            next if ( length $subfield != 1 );
+                            next if ( $tagslib->{$tag}->{$subfield}->{tab} ne $tabloop );
+                            push(
+                                @subfields_data,
+                                &create_input(
+                                    $tag, $subfield, $value, $index_tag, $tabloop,
+                                    $record, $authorised_values_sth,$input
+                                )
+                            );
+                        }
+                    }
+
+                    # now, loop again to add parameter subfield that are not in the MARC::Record
+                    foreach my $subfield ( sort( keys %{ $tagslib->{$tag} } ) )
+                    {
+                        next if ( length $subfield != 1 );
+                        next if ( $tagslib->{$tag}->{$subfield}->{tab} ne $tabloop );
+                        next if ( $tag < 10 );
+                        next
+                          if ( ( $tagslib->{$tag}->{$subfield}->{hidden} <= -4 )
+                            or ( $tagslib->{$tag}->{$subfield}->{hidden} >= 5 )
+                          );    #check for visibility flag
+                        next if ( defined( $field->subfield($subfield) ) );
+                        push(
+                            @subfields_data,
+                            &create_input(
+                                $tag, $subfield, '', $index_tag, $tabloop, $record,
+                                $authorised_values_sth,$input
+                            )
+                        );
+                    }
+                    if ( $#subfields_data >= 0 ) {
+                        # build the tag entry.
+                        # note that the random() field is mandatory. Otherwise, on repeated fields, you'll 
+                        # have twice the same "name" value, and cgi->param() will return only one, making
+                        # all subfields to be merged in a single field.
+                        my %tag_data = (
+                            tag           => $tag,
+                            index         => $index_tag,
+                            tag_lib       => $tagslib->{$tag}->{lib},
+                            repeatable       => $tagslib->{$tag}->{repeatable},
+                            subfield_loop => \@subfields_data,
+                            fixedfield    => ($tag < 10)?(1):(0),
+                            random        => CreateKey,
+                        );
+                        if ($tag >= 010){ # no indicator for theses tag
+                           $tag_data{indicator} = $field->indicator(1).$field->indicator(2);
+                        }
+                        push( @loop_data, \%tag_data );
+                    }
+                 } # foreach $field end
+
+            # if breeding is empty
+            }
+            else {
+                my @subfields_data;
+                foreach my $subfield ( sort( keys %{ $tagslib->{$tag} } ) ) {
+                    next if ( length $subfield != 1 );
+                    next
+                      if ( ( $tagslib->{$tag}->{$subfield}->{hidden} <= -5 )
+                        or ( $tagslib->{$tag}->{$subfield}->{hidden} >= 4 ) )
+                      ;    #check for visibility flag
+                    next
+                      if ( $tagslib->{$tag}->{$subfield}->{tab} ne $tabloop );
+                    push(
+                        @subfields_data,
+                        &create_input(
+                            $tag, $subfield, '', $index_tag, $tabloop, $record,
+                            $authorised_values_sth,$input
+                        )
+                    );
+                }
+                if ( $#subfields_data >= 0 ) {
+                    my %tag_data = (
+                        tag              => $tag,
+                        index            => $index_tag,
+                        tag_lib          => $tagslib->{$tag}->{lib},
+                        repeatable       => $tagslib->{$tag}->{repeatable},
+                        indicator        => $indicator,
+                        subfield_loop    => \@subfields_data,
+                        tagfirstsubfield => $subfields_data[0],
+                        fixedfield       => ($tag < 10)?(1):(0)
+                    );
+                    
+                    push @loop_data, \%tag_data ;
+                }
+            }
+        }
+        if ( $#loop_data >= 0 ) {
+            push @BIG_LOOP, {
+                number    => $tabloop,
+                innerloop => \@loop_data,
+            };
+        }
+    }
+    $template->param( singletab => (scalar(@BIG_LOOP)==1), BIG_LOOP => \@BIG_LOOP );
 }
 
 
@@ -382,10 +565,23 @@ if ($op eq "add") {
        # build indicator hash.
        my @ind_tag = $input->param('ind_tag');
        my @indicator = $input->param('indicator');
-       my $xml = TransformHtmlToXml(\@tags,\@subfields,\@values,\@indicator,\@ind_tag,'UNIMARCAUTH');
-#     warn $record->as_formatted;
-       my $record=MARC::Record->new_from_xml($xml,'UTF-8',(C4::Context->preference("marcflavour") eq "UNIMARC"?"UNIMARCAUTH":C4::Context->preference("marcflavour")));
-       $record->encoding('UTF-8');
+  my @params = $input->param();
+  my $record = TransformHtmlToMarc(\@params,$input);
+  if  (C4::Context->preference("marcflavour") eq "UNIMARC"){
+    unless ($record->field('100')){
+      use POSIX qw(strftime);
+      my $string = strftime( "%Y%m%d", localtime(time) );
+      # set 50 to position 26 is biblios, 13 if authorities
+      my $pos=13;
+      $string = sprintf( "%-*s", 35, $string );
+      substr( $string, $pos , 2, "50" );
+      $record->append_fields(MARC::Field->new('100','','',"a"=>$string));
+    }    
+  }
+    
+#   warn $record->as_formatted;  
+#      my $record=MARC::Record->new_from_xml($xml,'UTF-8',(C4::Context->preference("marcflavour") eq "UNIMARC"?"UNIMARCAUTH":C4::Context->preference("marcflavour")));
+#      $record->encoding('UTF-8');
        #warn $record->as_formatted;
        # check for a duplicate
        my ($duplicateauthid,$duplicateauthvalue) = FindDuplicateAuthority($record,$authtypecode) if ($op eq "add") && (!$is_a_modif);
@@ -402,35 +598,35 @@ if ($op eq "add") {
           exit;
        } else {
        # it may be a duplicate, warn the user and do nothing
-            build_tabs($template, $record, $dbh, $encoding);
+            build_tabs($template, $record, $dbh, $encoding,$input);
             build_hidden_data;
             $template->param(authid =>$authid,
                             duplicateauthid     => $duplicateauthid,
                             duplicateauthvalue  => $duplicateauthvalue,
                             );
        }
-#------------------------------------------------------------------------------------------------------------------------------
-} elsif ($op eq "addfield") {
-#------------------------------------------------------------------------------------------------------------------------------
-       my $addedfield = $input->param('addfield_field');
-       my $tagaddfield_subfield = $input->param('addfield_subfield');
-       my @tags = $input->param('tag');
-       my @subfields = $input->param('subfield');
-       my @values = $input->param('field_value');
-       # build indicator hash.
-       my @ind_tag = $input->param('ind_tag');
-       my @indicator = $input->param('indicator');
-       my $xml = TransformHtmlToXml(\@tags,\@subfields,\@values,\@indicator,\@ind_tag);
-       my $record=MARC::Record->new_from_xml($xml,'UTF-8');
-       $record->encoding('UTF-8');
-       # adding an empty field
-       my $field = MARC::Field->new("$addedfield",'','','$tagaddfield_subfield' => "");
-       $record->append_fields($field);
-       build_tabs ($template, $record, $dbh,$encoding);
-       build_hidden_data;
-       $template->param(
-               authid => $authid,);
-
+# #------------------------------------------------------------------------------------------------------------------------------
+} elsif ($op eq "addfield") {
+# #------------------------------------------------------------------------------------------------------------------------------
+#      my $addedfield = $input->param('addfield_field');
+#      my $tagaddfield_subfield = $input->param('addfield_subfield');
+#      my @tags = $input->param('tag');
+#      my @subfields = $input->param('subfield');
+#      my @values = $input->param('field_value');
+#      # build indicator hash.
+#      my @ind_tag = $input->param('ind_tag');
+#      my @indicator = $input->param('indicator');
+#      my $xml = TransformHtmlToXml(\@tags,\@subfields,\@values,\@indicator,\@ind_tag);
+#      my $record=MARC::Record->new_from_xml($xml,'UTF-8');
+#      $record->encoding('UTF-8');
+#      # adding an empty field
+#      my $field = MARC::Field->new("$addedfield",'','','$tagaddfield_subfield' => "");
+#      $record->append_fields($field);
+#      build_tabs ($template, $record, $dbh,$encoding,$input);
+#      build_hidden_data;
+#      $template->param(
+#              authid => $authid,);
+# 
 } elsif ($op eq "delete") {
 #------------------------------------------------------------------------------------------------------------------------------
        &AUTHdelauthority($authid);
@@ -445,7 +641,7 @@ if ($op eq "duplicate")
        {
                $authid = "";
        }
-       build_tabs ($template, $record, $dbh,$encoding);
+       build_tabs ($template, $record, $dbh,$encoding,$input);
        build_hidden_data;
        $template->param(oldauthtypetagfield=>$oldauthtypetagfield, oldauthtypetagsubfield=>$oldauthtypetagsubfield,
                oldauthnumtagfield=>$oldauthnumtagfield, oldauthnumtagsubfield=>$oldauthnumtagsubfield,
index 61e9f0d..afbb16b 100755 (executable)
@@ -103,24 +103,8 @@ if ($authid) {
     }
 } else {
     # authid is empty => the user want to empty the entry.
-    my @subfields_data;
-    my %subfield_data;
-    foreach my $subfield ( '0' .. '9' ) { #subfield code should also be number !
-        $subfield_data{marc_value}    = '';
-        $subfield_data{marc_subfield} = $subfield;
-        push( @subfields_data, \%subfield_data );
-    }
-    foreach my $subfield ( 'a' .. 'z' ) {
-        $subfield_data{marc_value}    = '';
-        $subfield_data{marc_subfield} = $subfield;
-        push( @subfields_data, \%subfield_data );
-    }
-    
-    my %tag_data;
-    # $tag_data{tag}=$field->tag().' -'. $tagslib->{$field->tag()}->{lib};
-    $tag_data{subfield} = \@subfields_data;
-    push( @loop_data, \%tag_data );
-    warn Data::Dumper::Dumper(\@loop_data);
+    $template->param( "clear" => 1 );
+#     warn Data::Dumper::Dumper(\@loop_data);
 }
 
 $template->param( "0XX" => \@loop_data );
index aa95e31..592c26b 100755 (executable)
@@ -50,7 +50,386 @@ use C4::Koha;
 # use C4::Biblio;
 # use C4::Catalogue;
 
+our ($tagslib);
+=item find_value
 
+    ($indicators, $value) = find_value($tag, $subfield, $record,$encoding);
+
+Find the given $subfield in the given $tag in the given
+MARC::Record $record.  If the subfield is found, returns
+the (indicators, value) pair; otherwise, (undef, undef) is
+returned.
+
+=cut
+
+sub find_value {
+  my ($tagfield,$insubfield,$record,$encoding) = @_;
+  my @result;
+  my $indicator;
+  if ($tagfield <10) {
+    if ($record->field($tagfield)) {
+      push @result, $record->field($tagfield)->data();
+    } else {
+      push @result,"";
+    }
+  } else {
+    foreach my $field ($record->field($tagfield)) {
+      my @subfields = $field->subfields();
+      foreach my $subfield (@subfields) {
+        if (@$subfield[0] eq $insubfield) {
+        push @result,@$subfield[1];
+              $indicator = $field->indicator(1).$field->indicator(2);
+        }
+      }
+    }
+  }
+  return($indicator,@result);
+}
+
+
+=item build_authorized_values_list
+
+=cut
+
+sub build_authorized_values_list ($$$$$$$) {
+    my ( $tag, $subfield, $value, $dbh, $authorised_values_sth,$index_tag,$index_subfield ) = @_;
+
+    my @authorised_values;
+    my %authorised_lib;
+
+    # builds list, depending on authorised value...
+
+    #---- branch
+    if ( $tagslib->{$tag}->{$subfield}->{'authorised_value'} eq "branches" ) {
+        my $sth =
+          $dbh->prepare(
+            "select branchcode,branchname from branches order by branchname");
+        $sth->execute;
+        push @authorised_values, ""
+          unless ( $tagslib->{$tag}->{$subfield}->{mandatory} );
+
+        while ( my ( $branchcode, $branchname ) = $sth->fetchrow_array ) {
+            push @authorised_values, $branchcode;
+            $authorised_lib{$branchcode} = $branchname;
+        }
+
+        #----- itemtypes
+    }
+    elsif ( $tagslib->{$tag}->{$subfield}->{authorised_value} eq "itemtypes" ) {
+        my $sth =
+          $dbh->prepare(
+            "select itemtype,description from itemtypes order by description");
+        $sth->execute;
+        push @authorised_values, ""
+          unless ( $tagslib->{$tag}->{$subfield}->{mandatory} );
+          
+        my $itemtype;
+        
+        while ( my ( $itemtype, $description ) = $sth->fetchrow_array ) {
+            push @authorised_values, $itemtype;
+            $authorised_lib{$itemtype} = $description;
+        }
+        $value = $itemtype unless ($value);
+
+        #---- "true" authorised value
+    }
+    else {
+        $authorised_values_sth->execute(
+            $tagslib->{$tag}->{$subfield}->{authorised_value} );
+
+        push @authorised_values, ""
+          unless ( $tagslib->{$tag}->{$subfield}->{mandatory} );
+
+        while ( my ( $value, $lib ) = $authorised_values_sth->fetchrow_array ) {
+            push @authorised_values, $value;
+            $authorised_lib{$value} = $lib;
+        }
+    }
+    return CGI::scrolling_list(
+        -name     => "tag_".$tag."_subfield_".$subfield."_".$index_tag."_".$index_subfield,
+        -values   => \@authorised_values,
+        -default  => $value,
+        -labels   => \%authorised_lib,
+        -override => 1,
+        -size     => 1,
+        -multiple => 0,
+        -tabindex => 1,
+        -id       => "tag_".$tag."_subfield_".$subfield."_".$index_tag."_".$index_subfield,
+        -class    => "input_marceditor",
+    );
+}
+
+
+=item create_input
+ builds the <input ...> entry for a subfield.
+=cut
+
+sub create_input {
+    my ( $tag, $subfield, $value, $index_tag, $tabloop, $rec, $authorised_values_sth,$cgi ) = @_;
+    
+    my $index_subfield = CreateKey(); # create a specifique key for each subfield
+
+    $value =~ s/"/&quot;/g;
+
+    # if there is no value provided but a default value in parameters, get it
+    unless ($value) {
+        $value = $tagslib->{$tag}->{$subfield}->{defaultvalue};
+
+        # get today date & replace YYYY, MM, DD if provided in the default value
+        my ( $year, $month, $day ) = Today();
+        $month = sprintf( "%02d", $month );
+        $day   = sprintf( "%02d", $day );
+        $value =~ s/YYYY/$year/g;
+        $value =~ s/MM/$month/g;
+        $value =~ s/DD/$day/g;
+    }
+    my $dbh = C4::Context->dbh;
+    my %subfield_data = (
+        tag        => $tag,
+        subfield   => $subfield,
+        marc_lib   => substr( $tagslib->{$tag}->{$subfield}->{lib}, 0, 22 ),
+        marc_lib_plain => $tagslib->{$tag}->{$subfield}->{lib}, 
+        tag_mandatory  => $tagslib->{$tag}->{mandatory},
+        mandatory      => $tagslib->{$tag}->{$subfield}->{mandatory},
+        repeatable     => $tagslib->{$tag}->{$subfield}->{repeatable},
+        kohafield      => $tagslib->{$tag}->{$subfield}->{kohafield},
+        index          => $index_tag,
+        id             => "tag_".$tag."_subfield_".$subfield."_".$index_tag."_".$index_subfield,
+        value          => $value,
+    );
+    if($subfield eq '@'){
+        $subfield_data{id} = "tag_".$tag."_subfield_00_".$index_tag."_".$index_subfield;
+    } else {
+         $subfield_data{id} = "tag_".$tag."_subfield_".$subfield."_".$index_tag."_".$index_subfield;
+    }
+
+    
+    $subfield_data{visibility} = "display:none;"
+        if (    ($tagslib->{$tag}->{$subfield}->{hidden} % 2 == 1) and $value ne ''
+            or ($value eq '' and !$tagslib->{$tag}->{$subfield}->{mandatory})
+        );
+    
+    # it's an authorised field
+    if ( $tagslib->{$tag}->{$subfield}->{authorised_value} ) {
+        $subfield_data{marc_value} =
+          build_authorized_values_list( $tag, $subfield, $value, $dbh,
+            $authorised_values_sth,$index_tag,$index_subfield );
+
+    # it's a thesaurus / authority field
+    }
+    elsif ( $tagslib->{$tag}->{$subfield}->{authtypecode} ) {
+        $subfield_data{marc_value} =
+    "<input type=\"text\"
+                        id=\"".$subfield_data{id}."\"
+                        name=\"".$subfield_data{id}."\"
+      value=\"$value\"
+      class=\"input_marceditor\"
+                        tabindex=\"1\"                     
+      DISABLE READONLY \/>
+      <span class=\"buttonDot\"
+        onclick=\"Dopop('/cgi-bin/koha/authorities/auth_finder.pl?authtypecode=".$tagslib->{$tag}->{$subfield}->{authtypecode}."&index=$subfield_data{id}','$subfield_data{id}')\">...</span>
+    ";
+    # it's a plugin field
+    }
+    elsif ( $tagslib->{$tag}->{$subfield}->{'value_builder'} ) {
+
+        # opening plugin. Just check wether we are on a developper computer on a production one
+        # (the cgidir differs)
+        my $cgidir = C4::Context->intranetdir . "/cgi-bin/cataloguing/value_builder";
+        unless ( opendir( DIR, "$cgidir" ) ) {
+            $cgidir = C4::Context->intranetdir . "/cataloguing/value_builder";
+        }
+        my $plugin = $cgidir . "/" . $tagslib->{$tag}->{$subfield}->{'value_builder'};
+        do $plugin || die "Plugin Failed: ".$plugin;
+        my $extended_param = plugin_parameters( $dbh, $rec, $tagslib, $subfield_data{id}, $tabloop );
+        my ( $function_name, $javascript ) = plugin_javascript( $dbh, $rec, $tagslib, $subfield_data{id}, $tabloop );
+#         my ( $function_name, $javascript,$extended_param );
+        
+        $subfield_data{marc_value} =
+    "<input tabindex=\"1\"
+                        type=\"text\"
+                        id=".$subfield_data{id}."
+      name=".$subfield_data{id}."
+      value=\"$value\"
+                        class=\"input_marceditor\"
+      onfocus=\"javascript:Focus$function_name($index_tag)\"
+      onblur=\"javascript:Blur$function_name($index_tag); \" \/>
+    <span class=\"buttonDot\"
+      onclick=\"Clic$function_name('$subfield_data{id}')\">...</a>
+    $javascript";
+        # it's an hidden field
+    }
+    elsif ( $tag eq '' ) {
+        $subfield_data{marc_value} =
+            "<input tabindex=\"1\"
+                    type=\"hidden\"
+                    id=".$subfield_data{id}."
+                    name=".$subfield_data{id}."
+                    value=\"$value\" \/>
+            ";
+    }
+    elsif ( $tagslib->{$tag}->{$subfield}->{'hidden'} ) {
+        $subfield_data{marc_value} =
+            "<input type=\"text\"
+                    id=".$subfield_data{id}."
+                    name=".$subfield_data{id}."
+                    class=\"input_marceditor\"
+                    tabindex=\"1\"
+                    value=\"$value\"
+            \/>";
+
+        # it's a standard field
+    }
+    else {
+        if (
+            length($value) > 100
+            or
+            ( C4::Context->preference("marcflavour") eq "UNIMARC" && $tag >= 300
+                and $tag < 400 && $subfield eq 'a' )
+            or (    $tag >= 500
+                and $tag < 600
+                && C4::Context->preference("marcflavour") eq "MARC21" )
+          )
+        {
+            $subfield_data{marc_value} =
+                "<textarea cols=\"70\"
+                           rows=\"4\"
+                           id=".$subfield_data{id}."
+                           name=".$subfield_data{id}."
+                           class=\"input_marceditor\"
+                           tabindex=\"1\"
+                           >$value</textarea>
+                ";
+        }
+        else {
+            $subfield_data{marc_value} =
+                "<input type=\"text\"
+                        id=".$subfield_data{id}."
+                        name=".$subfield_data{id}."
+                        value=\"$value\"
+                        tabindex=\"1\"
+                        class=\"input_marceditor\"
+                \/>
+                ";
+        }
+    }
+    $subfield_data{'index_subfield'} = $index_subfield;
+    return \%subfield_data;
+}
+
+=item CreateKey
+
+    Create a random value to set it into the input name
+
+=cut
+
+sub CreateKey(){
+    return int(rand(1000000));
+}
+
+sub build_tabs ($$$$$) {
+    my ( $template, $record, $dbh, $encoding,$input ) = @_;
+
+    # fill arrays
+    my @loop_data = ();
+    my $tag;
+
+    my $authorised_values_sth = $dbh->prepare(
+        "select authorised_value,lib
+        from authorised_values
+        where category=? order by lib"
+    );
+    
+    # in this array, we will push all the 10 tabs
+    # to avoid having 10 tabs in the template : they will all be in the same BIG_LOOP
+    my @BIG_LOOP;
+    my %seen;
+    my @tab_data; # all tags to display
+    
+    foreach my $used ( keys %$tagslib ){
+        push @tab_data,$used if not $seen{$used};
+        $seen{$used}++;
+    }
+        
+    my $max_num_tab=9;
+    # loop through each tab 0 through 9
+    for ( my $tabloop = 0 ; $tabloop <= $max_num_tab ; $tabloop++ ) {
+        my @loop_data = (); #innerloop in the template.
+        my $i = 0;
+        foreach my $tag (@tab_data) {
+            $i++;
+            next if ! $tag;
+            my $indicator;
+            my $index_tag = CreateKey;
+
+            # if MARC::Record is not empty =>use it as master loop, then add missing subfields that should be in the tab.
+            # if MARC::Record is empty => use tab as master loop.
+            if ( $record ne -1 && ( $record->field($tag) || $tag eq '000' ) ) {
+                my @fields;
+                if ( $tag ne '000' ) {
+                                @fields = $record->field($tag);
+                }
+                else {
+                  push @fields, $record->leader(); # if tag == 000
+                }
+    # loop through each field
+                foreach my $field (@fields) {
+                    
+                    my @subfields_data;
+                    if ($field->tag()<10) {
+                      next if ($tagslib->{$field->tag()}->{'@'}->{hidden});
+                      my %subfield_data;
+                      $subfield_data{marc_lib}=$tagslib->{$field->tag()}->{'@'}->{lib};
+                      $subfield_data{marc_value}=$field->data();
+                      $subfield_data{marc_subfield}='@';
+                      $subfield_data{marc_tag}=$field->tag();
+                      push(@subfields_data, \%subfield_data);
+                    } else {
+                      my @subf=$field->subfields;
+                  # loop through each subfield
+                      for my $i (0..$#subf) {
+                        $subf[$i][0] = "@" unless $subf[$i][0];
+                        next if ($tagslib->{$field->tag()}->{$subf[$i][0]}->{hidden});
+                        my %subfield_data;
+                        $subfield_data{marc_lib}=$tagslib->{$field->tag()}->{$subf[$i][0]}->{lib};
+                        if ($tagslib->{$field->tag()}->{$subf[$i][0]}->{isurl}) {
+                          $subfield_data{marc_value}="<a href=\"$subf[$i][1]\">$subf[$i][1]</a>";
+                        } else {
+                          $subfield_data{marc_value}=$subf[$i][1];
+                        }
+                              $subfield_data{short_desc} = substr(
+                                  $tagslib->{ $field->tag() }->{ $subf[$i][0] }->{lib},
+                                  0, 20
+                              );
+                              $subfield_data{long_desc} =
+                                $tagslib->{ $field->tag() }->{ $subf[$i][0] }->{lib};
+                        $subfield_data{marc_subfield}=$subf[$i][0];
+                        $subfield_data{marc_tag}=$field->tag();
+                        push(@subfields_data, \%subfield_data);
+                      }
+                    }
+                    if ($#subfields_data>=0) {
+                      my %tag_data;
+                      $tag_data{tag}=$field->tag().' -'. $tagslib->{$field->tag()}->{lib};
+                      $tag_data{subfield} = \@subfields_data;
+                      push (@loop_data, \%tag_data);
+                    }
+                  }
+              }
+            }
+            if ( $#loop_data >= 0 ) {
+                push @BIG_LOOP, {
+                    number    => $tabloop,
+                    innerloop => \@loop_data,
+                };
+            }
+        }                    
+        warn Data::Dumper::Dumper(@BIG_LOOP);
+        $template->param( singletab => (scalar(@BIG_LOOP)==1), BIG_LOOP => \@BIG_LOOP );
+}
+
+
+# 
 my $query=new CGI;
 
 my $dbh=C4::Context->dbh;
@@ -70,7 +449,7 @@ my $authid = $query->param('authid');
 
 
 my $authtypecode = &GetAuthTypeCode($authid);
-my $tagslib = &GetTagsLabels(1,$authtypecode);
+$tagslib = &GetTagsLabels(1,$authtypecode);
 
 my $record;
 if (C4::Context->preference("AuthDisplayHierarchy")){
@@ -117,51 +496,7 @@ my $tag;
 # loop through each tab 0 through 9
 # for (my $tabloop = 0; $tabloop<=10;$tabloop++) {
 # loop through each tag
-my @fields = $record->fields();
-my @loop_data =();
-foreach my $field (@fields) {
-               my @subfields_data;
-       # if tag <10, there's no subfield, use the "@" trick
-       if ($field->tag()<10) {
-               next if ($tagslib->{$field->tag()}->{'@'}->{hidden});
-               my %subfield_data;
-               $subfield_data{marc_lib}=$tagslib->{$field->tag()}->{'@'}->{lib};
-               $subfield_data{marc_value}=$field->data();
-               $subfield_data{marc_subfield}='@';
-               $subfield_data{marc_tag}=$field->tag();
-               push(@subfields_data, \%subfield_data);
-       } else {
-               my @subf=$field->subfields;
-# loop through each subfield
-               for my $i (0..$#subf) {
-                       $subf[$i][0] = "@" unless $subf[$i][0];
-                       next if ($tagslib->{$field->tag()}->{$subf[$i][0]}->{hidden});
-                       my %subfield_data;
-                       $subfield_data{marc_lib}=$tagslib->{$field->tag()}->{$subf[$i][0]}->{lib};
-                       if ($tagslib->{$field->tag()}->{$subf[$i][0]}->{isurl}) {
-                               $subfield_data{marc_value}="<a href=\"$subf[$i][1]\">$subf[$i][1]</a>";
-                       } else {
-                               $subfield_data{marc_value}=$subf[$i][1];
-                       }
-            $subfield_data{short_desc} = substr(
-                $tagslib->{ $field->tag() }->{ $subf[$i][0] }->{lib},
-                0, 20
-            );
-            $subfield_data{long_desc} =
-              $tagslib->{ $field->tag() }->{ $subf[$i][0] }->{lib};
-                       $subfield_data{marc_subfield}=$subf[$i][0];
-                       $subfield_data{marc_tag}=$field->tag();
-                       push(@subfields_data, \%subfield_data);
-               }
-       }
-       if ($#subfields_data>=0) {
-               my %tag_data;
-               $tag_data{tag}=$field->tag().' -'. $tagslib->{$field->tag()}->{lib};
-               $tag_data{subfield} = \@subfields_data;
-               push (@loop_data, \%tag_data);
-       }
-}
-$template->param("0XX" =>\@loop_data);
+  build_tabs ($template, $record, $dbh,"",$query);
 
 my $authtypes = getauthtypes;
 my @authtypesloop;
index e648f8f..a0baa66 100644 (file)
@@ -9,77 +9,75 @@
 <div id="breadcrumbs"><a href="/cgi-bin/koha/mainpage.pl">Home</a> &rsaquo; <a href="/cgi-bin/koha/admin/admin-home.pl">Administration</a> &rsaquo; Authority MARC subfield structure</div>
 
 <div id="doc3" class="yui-t2">
-   
-   <div id="bd">
-       <div id="yui-main">
-       <div class="yui-b">
+
+<div id="bd">
+    <div id="yui-main">
+    <div class="yui-b">
 
 <!-- TMPL_IF NAME="add_form" -->
 
-       <h1><!-- TMPL_IF NAME="use-heading-flags-p" -->
-       <!-- TMPL_IF NAME="heading-edit-subfields-p" -->Edit MARC subfields constraints<!-- /TMPL_IF -->
-       <!-- TMPL_ELSE --><!-- TMPL_VAR NAME="action" --><!-- /TMPL_IF --></h1>
-       <form action="<!-- TMPL_VAR NAME="script_name" -->" name="Aform" method="post">
-       <input type="hidden" name="op" value="add_validate" />
-       <input type="hidden" name="authtypecode" value="<!-- TMPL_VAR NAME="authtypecode" -->" />
-       <!-- TMPL_LOOP NAME="loop" -->
-       <div class="data <!-- TMPL_VAR NAME="toggle" -->">
-          <h2>Tag <!-- TMPL_VAR NAME="tagfield" -->, Subfield <!-- TMPL_VAR NAME="tagsubfield" --></h2>
-          <p><label for="repeatable<!-- TMPL_VAR NAME="row" -->">Repeatable:</label><!-- TMPL_VAR NAME="repeatable" -->&nbsp;</p>
-          <p><label for="mandatory<!-- TMPL_VAR NAME="row" -->">Mandatory:</label><!-- TMPL_VAR NAME="mandatory" -->&nbsp;</p>
-          <p><label for="seealso<!-- TMPL_VAR NAME="row" -->">Search also:</label><input type="text" id="seealso<!-- TMPL_VAR NAME="row" -->" name="seealso" value="<!-- TMPL_VAR name="seealso" -->" size="20" /> (example for 200a: '200c','200d','200e'...)</p>
-          <p><label for="liblibrarian<!-- TMPL_VAR NAME="row" -->">Text for librarian:</label><input id="liblibrarian<!-- TMPL_VAR NAME="row" -->" type="text" name="liblibrarian" value="<!-- TMPL_VAR NAME="liblibrarian" -->" size="40" maxlength="80" /></p>
-          <p><label for="libopac<!-- TMPL_VAR NAME="row" -->">Text for OPAC:</label><input type="text" id="libopac<!-- TMPL_VAR NAME="row" -->" name="libopac" value="<!-- TMPL_VAR NAME="libopac" -->" size="40" maxlength="80" /></p>
-          <p><label for="tab<!-- TMPL_VAR NAME="row" -->">Managed in tab</label><!-- TMPL_VAR NAME="tab" --> (ignore means that the subfield is NOT managed by Koha)</p>
-          <p><label for="hidden<!-- TMPL_VAR NAME="row" -->">Hidden</label> Opac:<!-- TMPL_VAR name="ohidden" -->  Intranet:<!-- TMPL_VAR name="ihidden" --> Editor:<!-- TMPL_VAR name="ehidden" --> (see online help)</p>
-          <p><label for="isurl<!-- TMPL_VAR NAME="row" -->">Is a URL </label><!-- TMPL_VAR NAME="isurl" --> (if checked, it means that the subfield is an URL and can be clicked)</p>
-        <p>Help input: </p>    
-        <ul>
-            <li>Authorized Value <!-- TMPL_VAR NAME="authorised_value" --></li>
-            <li>Thesaurus <!-- TMPL_VAR NAME="frameworkcode" --></li>
-            <li>Plugin <!-- TMPL_VAR NAME="value_builder" --></li>
-        </ul> 
-    </div>
-       <!-- /TMPL_LOOP -->
-       <input type="submit" class="submit" value="Save Changes" />
-       <p>Note: in the last column, you can choose:
-       <ul><li>An "authorised value": it refers to a list of authorised values for this subfield. See the corresponding admin table.</li>
-       <li>A "thesaurus category": it refers to a thesaurus category. See the corresponding admin table.</li>
-       <li>A "value builder": values builders are perl programs that help you select the value of the field. They are MARC-flavor dependant and sometimes fill another subfield automatically.</li>
-       </ul>
-       </p>
-       </form>
+    <h1><!-- TMPL_IF NAME="use-heading-flags-p" -->
+    <!-- TMPL_IF NAME="heading-edit-subfields-p" -->Edit MARC subfields constraints<!-- /TMPL_IF -->
+    <!-- TMPL_ELSE --><!-- TMPL_VAR NAME="action" --><!-- /TMPL_IF --></h1>
+    <form action="<!-- TMPL_VAR NAME="script_name" -->" name="Aform" method="post">
+        <input type="hidden" name="op" value="add_validate" />
+        <input type="hidden" name="authtypecode" value="<!-- TMPL_VAR NAME="authtypecode" -->" />
+        <!-- TMPL_LOOP NAME="loop" -->
+        <div class="data <!-- TMPL_VAR NAME="toggle" -->">
+            <h2>Tag <!-- TMPL_VAR NAME="tagfield" -->, Subfield <!-- TMPL_VAR NAME="tagsubfield" --></h2>
+            <p><label for="repeatable<!-- TMPL_VAR NAME="row" -->">Repeatable:</label><!-- TMPL_VAR NAME="repeatable" -->&nbsp;</p>
+            <p><label for="mandatory<!-- TMPL_VAR NAME="row" -->">Mandatory:</label><!-- TMPL_VAR NAME="mandatory" -->&nbsp;</p>
+            <p><label for="liblibrarian<!-- TMPL_VAR NAME="row" -->">Text for librarian:</label><input id="liblibrarian<!-- TMPL_VAR NAME="row" -->" type="text" name="liblibrarian" value="<!-- TMPL_VAR NAME="liblibrarian" -->" size="40" maxlength="80" /></p>
+            <p><label for="libopac<!-- TMPL_VAR NAME="row" -->">Text for OPAC:</label><input type="text" id="libopac<!-- TMPL_VAR NAME="row" -->" name="libopac" value="<!-- TMPL_VAR NAME="libopac" -->" size="40" maxlength="80" /></p>
+            <p><label for="tab<!-- TMPL_VAR NAME="row" -->">Managed in tab</label><!-- TMPL_VAR NAME="tab" --> (ignore means that the subfield is NOT managed by Koha)</p>
+            <p><label for="hidden<!-- TMPL_VAR NAME="row" -->">Hidden</label> Opac:<!-- TMPL_VAR name="ohidden" -->  Intranet:<!-- TMPL_VAR name="ihidden" --> Editor:<!-- TMPL_VAR name="ehidden" --> (see online help)</p>
+            <p><label for="isurl<!-- TMPL_VAR NAME="row" -->">Is a URL </label><!-- TMPL_VAR NAME="isurl" --> (if checked, it means that the subfield is an URL and can be clicked)</p>
+            <p>Help input: </p>        
+            <ul>
+                <li>Authorized Value <!-- TMPL_VAR NAME="authorised_value" --></li>
+                <li>Thesaurus <!-- TMPL_VAR NAME="frameworkcode" --></li>
+                <li>Plugin <!-- TMPL_VAR NAME="value_builder" --></li>
+            </ul> 
+        </div>
+        <!-- /TMPL_LOOP -->
+        <input type="submit" class="submit" value="Save Changes" />
+        <p>Note: in the last column, you can choose:
+            <ul><li>An "authorised value": it refers to a list of authorised values for this subfield. See the corresponding admin table.</li>
+            <li>A "thesaurus category": it refers to a thesaurus category. See the corresponding admin table.</li>
+            <li>A "value builder": values builders are perl programs that help you select the value of the field. They are MARC-flavor dependant and sometimes fill another subfield automatically.</li>
+            </ul>
+        </p>
+    </form>
 <!-- /TMPL_IF -->
 
 <!-- TMPL_IF NAME="delete_confirm" -->
 
-<h3>Confirm Deletion of Subfield <span class="ex"><!-- TMPL_VAR NAME="tagsubfield" -->?</span></h3>
-       <p>Subfield: <!-- TMPL_VAR NAME="tagsubfield" --></p>
-       <p>Description: <!-- TMPL_VAR NAME="liblibrarian" --></p>
-
-               <form action="<!-- TMPL_VAR NAME="delete_link" -->" method="post"><input type="hidden" name="op" value="delete_confirmed" />
-                               <input type="hidden" name="searchfield" value="<!-- TMPL_VAR NAME="searchfield" -->" />
-                               <input type="hidden" name="tagfield" value="<!-- TMPL_VAR NAME="tagfield" -->" />
-                               <input type="hidden" name="tagsubfield" value="<!-- TMPL_VAR NAME="tagsubfield" -->" />
-                               <input type="hidden" name="authtypecode" value="<!-- TMPL_VAR NAME="authtypecode" -->" />
-                               <input type="submit" class="cancel" value="Yes, Delete this Subfield" />
-               </form>
-               <form action="<!-- TMPL_VAR NAME="script_name" -->" method="post">
-                       <input type="hidden" name="searchfield" value="<!-- TMPL_VAR NAME="searchfield" -->" />
-                       <input type="hidden" name="tagfield" value="<!-- TMPL_VAR NAME="tagfield" -->" />
-                       <input type="hidden" name="tagsubfield" value="<!-- TMPL_VAR NAME="tagsubfield" -->" />
-                       <input type="hidden" name="authtypecode" value="<!-- TMPL_VAR NAME="authtypecode" -->" />
-                       <input type="submit" class="submit" value="No, Do Not Delete" />
-               </form>
+    <h3>Confirm Deletion of Subfield <span class="ex"><!-- TMPL_VAR NAME="tagsubfield" -->?</span></h3>
+    <p>Subfield: <!-- TMPL_VAR NAME="tagsubfield" --></p>
+    <p>Description: <!-- TMPL_VAR NAME="liblibrarian" --></p>
+    <form action="<!-- TMPL_VAR NAME="delete_link" -->" method="post"><input type="hidden" name="op" value="delete_confirmed" />
+        <input type="hidden" name="searchfield" value="<!-- TMPL_VAR NAME="searchfield" -->" />
+        <input type="hidden" name="tagfield" value="<!-- TMPL_VAR NAME="tagfield" -->" />
+        <input type="hidden" name="tagsubfield" value="<!-- TMPL_VAR NAME="tagsubfield" -->" />
+        <input type="hidden" name="authtypecode" value="<!-- TMPL_VAR NAME="authtypecode" -->" />
+        <input type="submit" class="cancel" value="Yes, Delete this Subfield" />
+    </form>
+    <form action="<!-- TMPL_VAR NAME="script_name" -->" method="post">
+        <input type="hidden" name="searchfield" value="<!-- TMPL_VAR NAME="searchfield" -->" />
+        <input type="hidden" name="tagfield" value="<!-- TMPL_VAR NAME="tagfield" -->" />
+        <input type="hidden" name="tagsubfield" value="<!-- TMPL_VAR NAME="tagsubfield" -->" />
+        <input type="hidden" name="authtypecode" value="<!-- TMPL_VAR NAME="authtypecode" -->" />
+        <input type="submit" class="submit" value="No, Do Not Delete" />
+    </form>
 <!-- /TMPL_IF -->
 
 <!-- TMPL_IF NAME="delete_confirmed" -->
 
-       <h3>Data deleted</h3>
-       <form action="<!-- TMPL_VAR NAME="script_name" -->" method="post">
-               <input type="hidden" name="tagfield" value="<!-- TMPL_VAR NAME="tagfield" -->" />
-               <input type="submit" class="submit" value="OK" />
-       </form>
+    <h3>Data deleted</h3>
+    <form action="<!-- TMPL_VAR NAME="script_name" -->" method="post">
+        <input type="hidden" name="tagfield" value="<!-- TMPL_VAR NAME="tagfield" -->" />
+        <input type="submit" class="submit" value="OK" />
+    </form>
 <!-- /TMPL_IF -->
 
 
 <p>The column <b>Koha field</b> shows that the subfield is linked with a Koha field. Koha can manage a MARC interface, and a Koha interface. This link ensures that both DB are synchronized</p>
 
 <table>
-<tr>
-       <th>Subfield</th>
-       <th>Text</th>
-       <th>Constraints</th>
-       <th>Delete</th>
-</tr>
-<!-- TMPL_LOOP NAME="loop" -->
-<!-- TMPL_IF NAME="toggle" --><tr class="highlighted"><!-- TMPL_ELSE --><tr><!-- /TMPL_IF -->
-       <td><!-- TMPL_VAR NAME="tagsubfield" --></td>
-       <td>
-               <!-- TMPL_IF NAME="subfield_ignored" -->
-                       <i><!-- TMPL_VAR NAME="liblibrarian" --></i>
-               <!-- TMPL_ELSE -->
-                       <!-- TMPL_VAR NAME="liblibrarian" -->
-               <!-- /TMPL_IF -->
-       </td>
-       <td>
-               <!-- TMPL_IF NAME="subfield_ignored" -->
-                       <i>subfield ignored</i>
-               <!-- TMPL_ELSE -->
-                       <strong>Tab:</strong><!-- TMPL_VAR NAME="tab" -->,
-                       <!-- TMPL_IF NAME="kohafield" --> | <strong>Koha field:</strong> <!-- TMPL_VAR NAME="kohafield" -->, <!--/TMPL_IF -->
-                       <!-- TMPL_IF NAME="repeatable" -->Repeatable, <!-- TMPL_ELSE -->Not repeatable,
-            <!-- /TMPL_IF -->
-                       <!-- TMPL_IF NAME="mandatory" -->Mandatory, <!-- TMPL_ELSE -->Not mandatory,
-            <!-- /TMPL_IF -->
-                       <!-- TMPL_IF NAME="seealso" --> | <strong>See Also:</strong> <!-- TMPL_VAR NAME="seealso" -->,
-            <!-- /TMPL_IF -->
-                       <!-- TMPL_IF NAME="hidden" -->hidden,
+    <tr>
+        <th>Subfield</th>
+        <th>Text</th>
+        <th>Constraints</th>
+        <th>Delete</th>
+    </tr>
+    <!-- TMPL_LOOP NAME="loop" -->
+    <!-- TMPL_IF NAME="toggle" --><tr class="highlighted"><!-- TMPL_ELSE --><tr><!-- /TMPL_IF -->
+        <td><!-- TMPL_VAR NAME="tagsubfield" --></td>
+        <td>
+            <!-- TMPL_IF NAME="subfield_ignored" -->
+                    <i><!-- TMPL_VAR NAME="liblibrarian" --></i>
+            <!-- TMPL_ELSE -->
+                    <!-- TMPL_VAR NAME="liblibrarian" -->
             <!-- /TMPL_IF -->
-                       <!-- TMPL_IF NAME="isurl" -->is an url,
-            <!-- /TMPL_IF -->
-                       <!-- TMPL_IF NAME="authorised_value" --> | <strong>Auth value:</strong><!-- TMPL_VAR NAME="authorised_value" -->,
-            <!-- /TMPL_IF -->
-                       <!-- TMPL_IF NAME="frameworkcode" --> | <strong>Authority:</strong><!-- TMPL_VAR NAME="frameworkcode" -->,
-            <!-- /TMPL_IF -->
-                       <!-- TMPL_IF NAME="value_builder" --> | <strong>Plugin:</strong><!-- TMPL_VAR NAME="value_builder" -->,<!-- /TMPL_IF -->
-          <!--/TMPL_IF-->
-       </td>
-       <td><a href="<!-- TMPL_VAR NAME="delete" -->">Delete</a></td>
-</tr>
-<!-- /TMPL_LOOP -->
+        </td>
+        <td>
+            <!-- TMPL_IF NAME="subfield_ignored" -->
+                    <i>subfield ignored</i>
+            <!-- TMPL_ELSE -->
+                <strong>Tab:</strong><!-- TMPL_VAR NAME="tab" -->,
+                <!-- TMPL_IF NAME="kohafield" --> | <strong>Koha field:</strong> <!-- TMPL_VAR NAME="kohafield" -->, <!--/TMPL_IF -->
+                <!-- TMPL_IF NAME="repeatable" -->Repeatable, <!-- TMPL_ELSE -->Not repeatable,
+                <!-- /TMPL_IF -->
+                        <!-- TMPL_IF NAME="mandatory" -->Mandatory, <!-- TMPL_ELSE -->Not mandatory,
+                <!-- /TMPL_IF -->
+                        <!-- TMPL_IF NAME="hidden" -->hidden,
+                <!-- /TMPL_IF -->
+                        <!-- TMPL_IF NAME="isurl" -->is an url,
+                <!-- /TMPL_IF -->
+                        <!-- TMPL_IF NAME="authorised_value" --> | <strong>Auth value:</strong><!-- TMPL_VAR NAME="authorised_value" -->,
+                <!-- /TMPL_IF -->
+                        <!-- TMPL_IF NAME="frameworkcode" --> | <strong>Authority:</strong><!-- TMPL_VAR NAME="frameworkcode" -->,
+                <!-- /TMPL_IF -->
+                <!-- TMPL_IF NAME="value_builder" --> | <strong>Plugin:</strong><!-- TMPL_VAR NAME="value_builder" -->,<!-- /TMPL_IF -->
+            <!--/TMPL_IF-->
+        </td>
+        <td><a href="<!-- TMPL_VAR NAME="delete" -->">Delete</a></td>
+    </tr>
+    <!-- /TMPL_LOOP -->
 </table>
 <div id="action">
     <a href="<!-- TMPL_VAR NAME="script_name" -->?op=add_form&amp;tagfield=<!-- TMPL_VAR name="edit_tagfield" -->&amp;authtypecode=<!-- TMPL_VAR name="edit_authtypecode" -->">Edit subfields</a>
     <a href="auth_tag_structure.pl?searchfield=<!-- TMPl_VAR name="tagfield" -->&amp;authtypecode=<!-- TMPL_VAR name="authtypecode"-->">Return to Auth Structure</a>
 </div>
     <!-- TMPL_IF NAME="previous" -->
-      <input type="image" src="<!-- TMPL_VAR NAME="interface" -->/<!-- TMPL_VAR NAME="theme" -->/images/1leftarrow.png" title="previous" alt="previous" border="0" >
-      </a>
+    <input type="image" src="<!-- TMPL_VAR NAME="interface" -->/<!-- TMPL_VAR NAME="theme" -->/images/1leftarrow.png" title="previous" alt="previous" border="0" >
+    </a>
     <!-- /TMPL_IF -->
     <!-- TMPL_IF NAME="next" -->
-       <!-- TMPL_VAR NAME="next" -->
-      <input type="image" src="<!-- TMPL_VAR NAME="interface" -->/<!-- TMPL_VAR NAME="theme" -->/images/1rightarrow.png" title="next" alt="next" border="0" />
-      </a>
+        <!-- TMPL_VAR NAME="next" -->
+    <input type="image" src="<!-- TMPL_VAR NAME="interface" -->/<!-- TMPL_VAR NAME="theme" -->/images/1rightarrow.png" title="next" alt="next" border="0" />
+    </a>
     <!-- /TMPL_IF -->
 
 <!-- /TMPL_IF -->
 
-
-
 </div>
 </div>
 <div class="yui-b">
index 6855402..5a35105 100644 (file)
 <!-- TMPL_INCLUDE NAME="doc-head-open.inc" -->
 <Title>Koha -- Authority details</title>
 <!-- TMPL_INCLUDE NAME="doc-head-close.inc" -->
+
 <script type="text/javascript">
-function _(s) { return s } // dummy function for gettext
+//<![CDATA[
+
 function active(numlayer)
 {
-       for (i=0; i < 10 ; i++ ) {
-               ong = i+"XX";
-               link = "link"+i;
-               if (numlayer==i) {
-                       document.getElementById(ong).style.visibility="visible";
-               } else {
-                       document.getElementById(ong).style.visibility="hidden";
-               }
-       }
+    for (i=0; i < 10 ; i++ ) {
+        ong = i+"XX";
+        link = "link"+i;
+        if (numlayer==i) {
+                document.getElementById(ong).style.visibility="visible";
+        } else {
+                document.getElementById(ong).style.visibility="hidden";
+        }
+    }
+}
+/**
+ * check if mandatory subfields are writed
+ */
+function AreMandatoriesNotOk(){
+    var mandatories = new Array();
+    var tab = new Array();
+    var label = new Array();
+    var flag=0;
+    <!-- TMPL_LOOP NAME='BIG_LOOP' --> 
+        <!-- TMPL_LOOP NAME='innerloop' -->
+            <!-- TMPL_LOOP NAME='subfield_loop'-->
+                <!-- TMPL_IF NAME='mandatory'-->
+                    mandatories.push("<!-- TMPL_VAR NAME='id' -->");
+                        tab.push("<!-- TMPL_VAR NAME='number' -->");
+                        label.push("<!-- TMPL_VAR NAME='marc_lib' ESCAPE=JS-->");
+                <!-- /TMPL_IF -->
+            <!-- /TMPL_LOOP -->
+        <!-- /TMPL_LOOP -->
+    <!-- /TMPL_LOOP -->
+    var StrAlert = _("Can't save this record because the following field aren't filled :\n\n");
+    for(var i=0,len=mandatories.length; i<len ; i++){
+        //alert (  mandatories[i]);
+        if( ! document.getElementById(mandatories[i]).value){
+            flag = 1;
+            document.getElementById(mandatories[i]).setAttribute('class','subfield_not_filled');
+            document.getElementById(mandatories[i]).focus();
+            StrAlert += "\t* "+label[i]+_(" in tab ")+tab[i]+"\n";
+        }
+    }
+    if(flag){
+      return StrAlert;
+  } else {
+    return flag;
+  }
 }
-function Check(f) {
-       // Scan for nonempty fields
-       var field_is_nonempty_p = new Array();
-       for (i=0 ; i<f.field_value.length ; i++) {
-           field_is_nonempty_p[f.tag[i].value] = 0;
-       }
-       for (i=0 ; i<f.field_value.length ; i++) {
-           if (f.field_value[i].value.length != 0) {
-               field_is_nonempty_p[f.tag[i].value] += 1;
-           }
-       }
 
-       // Scan for missing mandatory subfields
-       var total_missing_mandatory_subfields = 0;
-       for (i=0 ; i<f.field_value.length-2 ; i++) {
-               if (f.field_value[i].value.length==0 && f.mandatory[i].value==1) {
-                   // We should not flag an error unless the tag is also
-                   // mandatory, or if something else in the tag is entered
+/**
+ * 
+ * 
+ */
+function Check(){
+    var StrAlert = AreMandatoriesNotOk();
+    if( ! StrAlert ){
+        document.f.submit;
+        return true;
+    } else {
+        alert(StrAlert);
+        return false;
+    }
+}
 
-                   if (f.tag_mandatory[i].value == 1 || field_is_nonempty_p[f.tag[i].value]) {
-                       document.getElementById("error"+i).style.backgroundColor="#FF0000";
-                       total_missing_mandatory_subfields++;
-                   }
-               } else {
-                       document.getElementById("error"+i).style.backgroundColor="#FFFFFF";
-               }
-       }
 
-       // Scan for missing mandatory tags
-       var total_missing_mandatory_tags = 0;
-       var seen_mandatory_tag_p = new Array();
-       for (i=0 ; i<f.field_value.length ; i++) {
-           var j = f.tag[i].value;
-           if (!field_is_nonempty_p[j] && f.tag_mandatory[i].value == 1) {
-               if (seen_mandatory_tag_p[j] != 1) {
-                   seen_mandatory_tag_p[j] = 1;
-                   total_missing_mandatory_tags++;
-               }
-               document.getElementById("error"+i).style.backgroundColor="#ffff00";
-           }
-       }
 
-       var total_errors = total_missing_mandatory_tags + total_missing_mandatory_subfields;
-       var alertString2;
-       if (total_errors!=0) {
-               alertString2  = _("Form not submitted because of the following problem(s)");
-               alertString2 += "\n------------------------------------------------------------------------------------\n";
-               alertString2 += "\n- "+ total_missing_mandatory_tags +_(" mandatory tags empty");
-               alertString2 += "\n- "+ total_missing_mandatory_subfields +_(" mandatory fields empty (see bold subfields)");
-               alert(alertString2);
-       } else {
-               document.forms['f'].submit();
-       }
+
+function AddField(field,cntrepeatfield) {
+    document.forms['f'].op.value = "addfield";
+    document.forms['f'].addfield_field.value=field;
+    document.forms['f'].repeat_field.value=cntrepeatfield;
+    document.f.submit();
 }
+
 function Dopop(link,i) {
-       defaultvalue=document.forms['f'].field_value[i].value;
-       newin=window.open(link+"&result="+defaultvalue,"value builder",'width=550,height=550,toolbar=false,scrollbars=yes');
+    defaultvalue = document.getElementById(i).value;
+    window.open(link+"&result="+defaultvalue,"value builder",'width=700,height=550,toolbar=false,scrollbars=yes');
 }
 
-function PopupZ3950() {
-    var strQuery="";
-       for (i=0 ; i<document.forms['f'].field_value.length ; i++) {
-               if (document.forms['f'].kohafield[i].value == "biblioitems.isbn" && document.forms['f'].field_value[i].value.length>0) {
-                   strQuery += "&isbn="+document.forms['f'].field_value[i].value;
-               }
-               if (document.forms['f'].kohafield[i].value == "biblio.title" && document.forms['f'].field_value[i].value.length>0) {
-                   strQuery += "&title="+document.forms['f'].field_value[i].value;
-               }
-               if (document.forms['f'].kohafield[i].value == "biblio.author" &&document.forms['f'].field_value[i].value.length>0) {
-                   strQuery += "&author="+document.forms['f'].field_value[i].value;
-               }
-               if (document.forms['f'].kohafield[i].value == "biblioitems.issn" && document.forms['f'].field_value[i].value.length>0) {
-                   strQuery += "&issn="+document.forms['f'].field_value[i].value;
-               }
-       }
-       newin=window.open("../z3950/search.pl?biblionumber=<!-- TMPL_VAR NAME="biblionumber" -->"+strQuery,"z3950search",'width=500,height=400,toolbar=false,scrollbars=yes');
+function ExpandField(index) {
+    var original = document.getElementById(index); //original <div>
+    var divs = original.getElementsByTagName('div');
+    for(var i=0,divslen = divs.length ; i<divslen ; i++){      // foreach div
+        if(divs[i].getAttribute("name") == 'line'){  // if it s a subfield
+            if (divs[i].style.display == 'block') {
+                divs[i].style.display = 'none';
+            } else {
+                divs[i].style.display = 'block';
+            }
+        }
+    }
 }
 
-function AddField(field,cntrepeatfield) {
-       document.forms['f'].op.value = "addfield";
-       document.forms['f'].addfield_field.value=field;
-       document.forms['f'].repeat_field.value=cntrepeatfield;
-       document.f.submit();
+/**
+ * To clone a field or a subfield by clickink on '+' button
+ */ 
+function CloneField(index) {
+    var original = document.getElementById(index); //original <div>
+    var clone = original.cloneNode(true);
+    var new_key = CreateKey();
+    var new_id  = original.getAttribute('id')+new_key;
+    
+    clone.setAttribute('id',new_id); // setting a new id for the parent div
+    
+    var divs = clone.getElementsByTagName('div');
+    
+    <!-- TMPL_UNLESS NAME='hide_marc'--> // No indicator if hide_marc
+        // setting a new name for the new indicator
+        var indicator = clone.getElementsByTagName('input')[0];
+        indicator.setAttribute('name',indicator.getAttribute('name')+new_key);
+    <!-- /TMPL_UNLESS -->
+        
+    // settings all subfields
+    for(var i=0,divslen = divs.length ; i<divslen ; i++){      // foreach div
+        if(divs[i].getAttribute("name") == 'line'){  // if it s a subfield
+            
+            // set the attribute for the new 'div' subfields
+            divs[i].setAttribute('id',divs[i].getAttribute('id')+new_key);
+            
+            var inputs   = divs[i].getElementsByTagName('input');
+            var id_input = "";
+            
+            inputs[0].setAttribute('id',inputs[0].getAttribute('id')+new_key);
+            inputs[0].setAttribute('name',inputs[0].getAttribute('name')+new_key);
+            var id_input;
+            try {
+              id_input = inputs[1].getAttribute('id')+new_key;
+                inputs[1].setAttribute('id',id_input);
+                inputs[1].setAttribute('name',inputs[1].getAttribute('name')+new_key);
+            } catch(e) {
+              try{ // it s a select if it is not an input
+                    var selects = divs[i].getElementsByTagName('select');
+                    id_input = selects[0].getAttribute('id')+new_key;
+                    selects[0].setAttribute('id',id_input);
+                    selects[0].setAttribute('name',selects[0].getAttribute('name')+new_key);
+                }catch(e2){ // it is a textarea if it s not a select or an input
+                  var textaeras = divs[i].getElementsByTagName('textarea');
+                  id_input = textaeras[0].getAttribute('id')+new_key;
+                  textaeras[0].setAttribute('id',id_input);
+                    textaeras[0].setAttribute('name',textaeras[0].getAttribute('name')+new_key);
+                }
+            }
+            
+            <!-- TMPL_UNLESS NAME='advancedMARCEditor'-->
+            // when cloning a subfield, re set its label too.
+            var labels = divs[i].getElementsByTagName('label');
+            labels[0].setAttribute('for',id_input);
+            <!-- /TMPL_UNLESS -->
+            
+            <!-- TMPL_UNLESS NAME='hide_marc'-->
+                // updating javascript parameters on button up
+                var imgs = divs[i].getElementsByTagName('img');
+                imgs[0].setAttribute('onclick',"upSubfield(\'"+divs[i].getAttribute('id')+"\');");
+            <!-- /TMPL_UNLESS -->
+            
+            // setting its '+' button
+            var CloneButtonPlus=0;
+            try {
+                CloneButtonPlus = divs[i].getElementsByTagName('span')[0];
+                if(CloneButtonPlus.getAttribute('class') == 'buttonPlus'){
+                    CloneButtonPlus.setAttribute('onclick',"CloneSubfield('" + divs[i].getAttribute('id') + "')");
+                } else {
+                    CloneButtonPlus = 0;
+                }
+            }
+            catch(e){
+                // do nothig if ButtonPlus & CloneButtonPlus don t exist.
+            }
+            
+            // button ...
+            var spans=0;
+            try {
+                spans = divs[i].getElementsByTagName('span');
+            } catch(e) {
+                // no spans
+            }
+            if(spans){
+                var buttonDot;
+                if(!CloneButtonPlus){ // it s impossible to have  + ... (buttonDot AND buttonPlus)
+                    buttonDot = spans[0];
+                    if(buttonDot){
+                        // 2 possibilities :
+                        try{
+                            var buttonDotOnClick = buttonDot.getAttribute('onclick');
+                            if(buttonDotOnClick.match('Clictag')){   // -1- It s a plugin
+                                var re = /\('.*'\)/i;
+                                buttonDotOnClick = buttonDotOnClick.replace(re,"('"+inputs[1].getAttribute('id')+"')");
+                                if(buttonDotOnClick){
+                                    buttonDot.setAttribute('onclick',buttonDotOnClick);
+                                }
+                            } else {
+                                if(buttonDotOnClick.match('Dopop')) {  // -2- It's a auth value
+                                    
+                                    var re1 = /&index=.*',/;
+                                    var re2 = /,.*\)/;
+
+                                    buttonDotOnClick = buttonDotOnClick.replace(re1,"&index="+inputs[1].getAttribute('id')+"',");
+                                    buttonDotOnClick = buttonDotOnClick.replace(re2,",'"+inputs[1].getAttribute('id')+"')");
+                                    
+                                    if(buttonDotOnClick){
+                                            buttonDot.setAttribute('onclick',buttonDotOnClick);
+                                    }
+                                }
+                            }
+                            try {
+                              // do not copy the script section.
+                              var script = spans[0].getElementsByTagName('script')[0];
+                              spans[0].removeChild(script);
+                            } catch(e) {
+                              // do nothing if there is no script
+                            }
+                      }catch(e){}
+                  }
+                }
+            }
+            <!-- TMPL_UNLESS NAME='hide_marc'-->
+                var buttonUp = divs[i].getElementsByTagName('img')[0];
+                buttonUp.setAttribute('onclick',"upSubfield('" + divs[i].getAttribute('id') + "')");
+            <!-- /TMPL_UNLESS -->
+            
+        } else { // it's a indicator div
+            if(divs[i].getAttribute('name') == 'div_indicator'){
+                var inputs = divs[i].getElementsByTagName('input');
+                inputs[0].setAttribute('id',inputs[0].getAttribute('id')+new_key);
+                
+                var CloneButtonPlus;
+                try {
+                    CloneButtonPlus = divs[i].getElementsByTagName('span')[1]; // 0 is the title
+                    CloneButtonPlus.setAttribute('onclick',"CloneField('" + divs[i].parentNode.getAttribute('id') + "')");
+                }
+                catch(e){
+                    // do nothig CloneButtonPlus doesn't exist.
+                }
+                
+                // setting its 'Expand' property
+                var ExpandFieldA=0;
+                try {
+                    ExpandFieldA = divs[i].getElementsByTagName('a')[0];
+                    ExpandFieldA.setAttribute('onclick',"ExpandField('" + divs[i].parentNode.getAttribute('id') + "')");
+                }
+                catch(e){
+                    // do nothig if ButtonPlus & CloneButtonPlus don t exist.
+                }
+                
+            }
+        }
+    }
+    
+    // insert this line on the page
+    original.parentNode.insertBefore(clone,original.nextSibling);
 }
 
-function cloneSubfield(index) {
+function CloneSubfield(index){
     var original = document.getElementById(index); //original <div>
     var clone = original.cloneNode(true);
-
+    var new_key = CreateKey();
+    var new_id  = original.getAttribute('id')+new_key;
+    
     // set the attribute for the new 'div' subfields
-    clone.setAttribute('id',index + index);//set another id.
-    var NumTabIndex;
-    NumTabIndex = parseInt(original.getAttribute('tabindex'));
-    if(isNaN(NumTabIndex)) NumTabIndex = 0;
-    clone.setAttribute('tabindex',NumTabIndex+1);
+    var inputs     = clone.getElementsByTagName('input');
+    var selects    = clone.getElementsByTagName('select');
+    var textareas  = clone.getElementsByTagName('textarea');
+        
+    // input
+    var id_input = "";
+    for(var i=0,len=inputs.length; i<len ; i++ ){
+        id_input = inputs[i].getAttribute('id')+new_key;
+        inputs[i].setAttribute('id',id_input);
+        inputs[i].setAttribute('name',inputs[i].getAttribute('name')+new_key);
+    }
+    
+    // select 
+    for(var i=0,len=selects.length; i<len ; i++ ){
+        id_input = selects[i].getAttribute('id')+new_key;
+        selects[i].setAttribute('id',selects[i].getAttribute('id')+new_key);
+        selects[i].setAttribute('name',selects[i].getAttribute('name')+new_key);
+    }
+    
+    // textarea
+    for(var i=0,len=textareas.length; i<len ; i++ ){
+        id_input = textareas[i].getAttribute('id')+new_key;
+        textareas[i].setAttribute('id',textareas[i].getAttribute('id')+new_key);
+        textareas[i].setAttribute('name',textareas[i].getAttribute('name')+new_key);
+    }
+    
+    <!-- TMPL_UNLESS NAME='advancedMARCEditor' -->
+    // when cloning a subfield, reset its label too.
+    var label = clone.getElementsByTagName('label')[0];
+    label.setAttribute('for',id_input);
+    <!-- /TMPL_UNLESS -->
+    
+    // setting a new if for the parent div
+    clone.setAttribute('id',new_id);
     
     var CloneButtonPlus;
-    try{
-        CloneButtonPlus = clone.getElementsByTagName('a')[0];
-        CloneButtonPlus.setAttribute('onclick',"cloneSubfield('" + index + index + "')");
+    try {
+      var spans = clone.getElementsByTagName('span');
+      if(spans.length){
+          for(var i = 0 ,lenspans = spans.length ; i < lenspans ; i++){
+            if(spans[i].getAttribute('class') == 'buttonPlus'){
+                    CloneButtonPlus = spans[i];
+                    CloneButtonPlus.setAttribute('onclick',"CloneSubfield('" + new_id + "')");
+                    var buttonUp = clone.getElementsByTagName('img')[0];
+                    buttonUp.setAttribute('onclick',"upSubfield('" + new_id + "')");
+                }
+            }
+        }
     }
     catch(e){
-        // do nothing if ButtonPlus & CloneButtonPlus don't exist.
+        // do nothig if ButtonPlus & CloneButtonPlus don't exist.
     }
-
     // insert this line on the page
     original.parentNode.insertBefore(clone,original.nextSibling);
 }
 
+/**
+ * This function create a random number
+ */
+function CreateKey(){
+    return parseInt(Math.random() * 100000);
+}
+
+/**
+ * This function allows to move a subfield up by clickink on the 'up' button .
+ */
 function upSubfield(index) {
-       try{
-               var line = document.getElementById(index); // get the line where the user has clicked.
-       } catch(e) {
-               return;
-       }
-       var tag = line.parentNode; // get the dad of this line. (should be "<div tag=XXX>")
-       
-       // getting all subfields for this tag
-       var subfields = tag.getElementsByTagName('div');
-       var subfieldsLength = subfields.length;
-       if(subfieldsLength<=1) return; // nothing to do if there is just one subfield.
-       // among all subfields 
-       for(var i=0;i<subfieldsLength;i++){ 
-               if(subfields[i].getAttribute('id') == index){ //looking for the subfield which is clicked :
-                       if(i==0){ // if the clicked subfield is on the top
-                               tag.appendChild(subfields[0]);
-                               return;
-                       }else{
-                               var lineAbove = subfields[i-1];
-                               tag.insertBefore(line,lineAbove);
-                               return;
-                       }
-               }
-       }
+    try{
+        var line = document.getElementById(index); // get the line where the user has clicked.
+    } catch(e) {
+        return; // this line doesn't exist...
+    }
+    var tag = line.parentNode; // get the dad of this line. (should be "<div id='tag_...'>")
+    
+    // getting all subfields for this tag
+    var subfields = tag.getElementsByTagName('div');
+    var subfieldsLength = subfields.length;
+    
+    if(subfieldsLength<=1) return; // nothing to do if there is just one subfield.
+    
+    // among all subfields 
+    for(var i=0;i<subfieldsLength;i++){ 
+        if(subfields[i].getAttribute('id') == index){ //looking for the subfield which is clicked :
+            if(i==1){ // if the clicked subfield is on the top
+                tag.appendChild(subfields[1]);
+                return;
+            } else {
+                var lineAbove = subfields[i-1];
+                tag.insertBefore(line,lineAbove);
+                return;
+            }
+        }
+    }
 }
 
-function unHideSubfield(index,labelindex) {
-       subfield = document.getElementById(index);
-       subfield.style.display = 'block';
-       label = document.getElementById(labelindex);
-       label.style.display='none';     
+function unHideSubfield(index,labelindex) { // FIXME :: is it used ?
+    subfield = document.getElementById(index);
+    subfield.style.display = 'block';
+    label = document.getElementById(labelindex);
+    label.style.display='none'; 
 }
 
 function addauthority() {
@@ -167,6 +374,7 @@ function searchauthority() {
     Y = document.forms[0].value.value;
     window.location="/cgi-bin/koha/authorities/authorities-home.pl?op=do_search&type=intranet&authtypecode="+X+"&value="+Y+"&marclist=&and_or=and&excluding=&operator=contains";
 }
+//]]>
 </script>
 </head>
 <body>
@@ -175,17 +383,17 @@ function searchauthority() {
 <div id="breadcrumbs"><a href="/cgi-bin/koha/mainpage.pl">Home</a> &rsaquo; <a href="/cgi-bin/koha/authorities/authorities-home.pl">Authorities</a> &rsaquo; <!-- TMPL_IF name="authid" -->Modify authority #<!-- TMPL_VAR NAME="authid" --> (<!-- TMPL_VAR name="authtypetext" -->)<!-- TMPL_ELSE -->Adding authority (<!-- TMPL_VAR name="authtypetext" -->)<!-- /TMPL_IF -->  </div>
 
 <div id="doc" class="yui-t7">
-   
-   <div id="bd">
-       <div id="yui-main">
-       <div class="yui-g">
+
+<div id="bd">
+        <div id="yui-main">
+        <div class="yui-g">
 
 <!-- TMPL_IF name="authid" -->
-  <h1>Modify authority #<!-- TMPL_VAR NAME="authid" --> (<!-- TMPL_VAR name="authtypetext" -->)</h1>
+<h1>Modify authority #<!-- TMPL_VAR NAME="authid" --> (<!-- TMPL_VAR name="authtypetext" -->)</h1>
 <!-- TMPL_ELSE -->
-  <h1>Adding authority (<!-- TMPL_VAR name="authtypetext" -->)</h1>
+<h1>Adding authority (<!-- TMPL_VAR name="authtypetext" -->)</h1>
 <!-- /TMPL_IF -->  
-  <form method="post" name="f">
+<form method="post" name="f">
     <input type="hidden" name="op" value="add" />
     <input type="hidden" name="addfield_field" value="" />
     <input type="hidden" name="repeat_field" value="" />
@@ -194,109 +402,174 @@ function searchauthority() {
 
     <div id="action">
 <!-- TMPL_IF name="authid" -->
-      <input type="button" value="Save" onclick="Check(this.form)" accesskey="w" />
+    <input type="button" value="Save" onclick="Check(this.form)" accesskey="w" />
 <!-- TMPL_ELSE -->
-      <input type="button" value="Add authority" onclick="Check(this.form)" accesskey="w" />
+    <input type="button" value="Add authority" onclick="Check(this.form)" accesskey="w" />
 <!-- /TMPL_IF -->
     </div>
 
 <!-- TMPL_IF name="duplicateauthid" -->
-       <div class="problem">
-               <p>Duplicate suspected with <a href="javascript:openWindow("detail.pl?authid=<!-- TMPL_VAR name="duplicateauthid" -->&amp;popup=1", "Duplicate Authority");" class="button"><!-- TMPL_VAR name="duplicateauthvalue" --></a></p>
-               <p>You must either :</p>
-               <ul>
-                       <p><input type="checkbox" value="1" name="confirm_not_duplicate" />confirm it's not a duplicate (and click on <input type="button" value="Add authority" onclick="Check(this.form)" accesskey="w" class="button" /> again)</p>
-                       <p>Go to <a href="authorities.pl?authid=<!-- TMPL_VAR name="duplicateauthid" -->" >original authority</a></p>
-               </ul>
-       </div>
+        <div class="problem">
+                <p>Duplicate suspected with <a href="javascript:openWindow("detail.pl?authid=<!-- TMPL_VAR name="duplicateauthid" -->&amp;popup=1", "Duplicate Authority");" class="button"><!-- TMPL_VAR name="duplicateauthvalue" --></a></p>
+                <p>You must either :</p>
+                <ul>
+                        <p><input type="checkbox" value="1" name="confirm_not_duplicate" />confirm it's not a duplicate (and click on <input type="button" value="Add authority" onclick="Check(this.form)" accesskey="w" class="button" /> again)</p>
+                        <p>Go to <a href="authorities.pl?authid=<!-- TMPL_VAR name="duplicateauthid" -->" >original authority</a></p>
+                </ul>
+        </div>
 <!-- /TMPL_IF -->
 
-<!-- TMPL_LOOP NAME="0XX" -->
-    <!-- TMPL_IF name="tag" -->
-        <p class="tag">
-            <input type="hidden" name="ind_tag" value="<!-- TMPL_VAR NAME="tag" -->" />
-            <!-- TMPL_UNLESS name="hide_marc" -->
-                <a title="<!-- TMPL_VAR NAME="tag_lib" -->"><!-- TMPL_VAR NAME="tag" --></a>
-                <input tabindex="1" onblur="this.style.backgroundColor='#ffffff';" onfocus="this.style.backgroundColor='#ffffff;'" type="text" <!-- TMPL_IF NAME="fixedfield" --> style="display:none;" <!-- /TMPL_IF --> name="indicator" size="2" maxlength="2" value="<!-- TMPL_VAR NAME="indicator" -->" class="flat" /> -
+<!--TMPL_UNLESS Name="singletab"-->
+<div id="tabs">
+        <!-- TMPL_LOOP name="BIG_LOOP" -->
+            <!-- TMPL_IF name="number" -->
+                <a href="JavaScript:active(<!-- TMPL_VAR name="number"-->)" class="tab_inactive" id="link<!-- TMPL_VAR name="number"-->"><!-- TMPL_VAR name="number"--></a>
             <!-- TMPL_ELSE -->
-                <input tabindex="1" type="hidden" <!-- TMPL_IF NAME="fixedfield" --> style="display:none;" <!-- /TMPL_IF --> name="indicator" value="<!-- TMPL_VAR NAME="indicator" -->" />
-            <!-- /TMPL_UNLESS -->
-            <!-- TMPL_UNLESS NAME="advancedMARCEditor" --><!-- TMPL_VAR NAME="tag_lib" --><!-- /TMPL_UNLESS -->
-            <!-- TMPL_IF name="repeatable" -->
-                <a href="#<!-- TMPL_VAR NAME="tag" -->" onclick="this.nextSibling.type='text';this.nextSibling.focus()">+</a><input type="hidden" value="" size="2" onchange="AddField('<!-- TMPL_VAR NAME="tag" -->',this.value)" />
+                <a href="JavaScript:active(<!-- TMPL_VAR name="number"-->)" class="tab_active" id="link<!-- TMPL_VAR name="number"-->"><!-- TMPL_VAR name="number"--></a>
             <!-- /TMPL_IF -->
-        </p>
+        <!--  /TMPL_LOOP -->
+</div>
+<!--/TMPL_UNLESS-->
+
+<!-- TMPL_LOOP name="BIG_LOOP" -->
+<!-- hide every tab except the 1st -->
+<!--TMPL_UNLESS Name="singletab"-->
+    <!-- TMPL_IF name="number" -->
+        <div id="<!-- TMPL_VAR name="number" -->XX" class="content_hidden">
+    <!-- TMPL_ELSE -->
+        <div id="0XX" class="content_visible">
     <!-- /TMPL_IF -->
+<!-- /TMPL_UNLESS -->
+    
+    <!-- TMPL_LOOP NAME="innerloop" -->
+        <!-- TMPL_IF NAME="tag" -->
+<div class="tag" id="tag_<!-- TMPL_VAR name="tag"-->_<!-- TMPL_VAR NAME='index'--><!-- TMPL_VAR name="random" -->">
+        <div class="tag_title" name="div_indicator">
+            <!-- TMPL_UNLESS name="hide_marc" -->
+                <span title="<!-- TMPL_VAR NAME="tag_lib" -->"><!-- TMPL_VAR NAME="tag" --></span>
+                <!-- TMPL_IF NAME="fixedfield" -->
+                <input tabindex="1"
+                            class="indicator"
+                            type="text"
+                            style="display:none;"
+                            name="tag_<!-- TMPL_VAR NAME="tag" -->_indicator_<!-- TMPL_VAR NAME='index'--><!-- TMPL_VAR name="random" -->"
+                            size="2"
+                            maxlength="2"
+                            value="<!-- TMPL_VAR NAME="indicator" -->"
+                            class="flat" />
+                <!-- TMPL_ELSE -->
+                <input tabindex="1"
+                            class="indicator"
+                            type="text"
+                            name="tag_<!-- TMPL_VAR NAME="tag" -->_indicator_<!-- TMPL_VAR NAME='index'--><!-- TMPL_VAR name="random" -->"
+                            size="2"
+                            maxlength="2"
+                            value="<!-- TMPL_VAR NAME="indicator" -->"
+                            class="flat" />
+                <!-- /TMPL_IF --> -
+            <!-- TMPL_ELSE -->
+                <!-- TMPL_IF NAME="fixedfield" -->
+                    <input tabindex="1"
+                        type="hidden"
+                        name="tag_<!-- TMPL_VAR NAME="tag" -->_indicator_<!-- TMPL_VAR NAME='index'-->"
+                        value="<!-- TMPL_VAR NAME="indicator" --><!-- TMPL_VAR name="random" -->" />
+                <!-- TMPL_ELSE -->
+                    <input tabindex="1"
+                        type="hidden"
+                        name="tag_<!-- TMPL_VAR NAME="tag" -->_indicator_<!-- TMPL_VAR NAME='index'-->"
+                        value="<!-- TMPL_VAR NAME="indicator" --><!-- TMPL_VAR name="random" -->" />
+                <!-- /TMPL_IF -->
+            <!-- /TMPL_UNLESS -->
 
-    <!-- TMPL_LOOP NAME="subfield_loop" -->
-        <p class="subfield">
-        <!-- TMPL_IF NAME="visibility" -->
-            <a tabindex="1" style="color: grey; font-size: 80%; cursor: se-resize;" id="label<!-- TMPL_VAR name="index" -->" onclick="unHideSubfield('subfield<!-- TMPL_VAR NAME="tag" --><!-- TMPL_VAR name="index" -->','label<!-- TMPL_VAR name="index" -->')">
-                <!-- TMPL_VAR NAME="subfield" -->
-            </a>
-        <!-- /TMPL_IF -->
-        <div style="<!-- TMPL_VAR NAME='visibility' -->;" id="subfield<!-- TMPL_VAR NAME='tag' --><!-- TMPL_VAR NAME='index' -->">
-            <p>
             <!-- TMPL_UNLESS NAME="advancedMARCEditor" -->
-                <label <!-- TMPL_IF NAME="fixedfield" --> style="display:none;" <!-- /TMPL_IF --> class="labelsubfield"> 
+            <a onClick="ExpandField('tag_<!-- TMPL_VAR name="tag"-->_<!-- TMPL_VAR NAME='index'--><!-- TMPL_VAR name="random" -->')"><!-- TMPL_VAR NAME="tag_lib" --></a>
             <!-- /TMPL_UNLESS -->
-            <!-- TMPL_UNLESS name="hide_marc" -->
-                    <img <!-- TMPL_IF NAME="fixedfield" --> style="display:none;" <!-- /TMPL_IF --> src="<!-- TMPL_VAR NAME="themelang" -->/../img/up.png" onclick="upSubfield('subfield<!-- TMPL_VAR NAME="tag" --><!-- TMPL_VAR name="index" -->')" />
-                    <input title="<!-- TMPL_VAR NAME="marc_lib_plain" -->" style=" <!-- TMPL_IF NAME="fixedfield" -->display:none; <!-- /TMPL_IF -->border:0;" type="text" name="subfield" value="<!-- TMPL_VAR NAME="subfield" -->" size="1" maxlength="1" class="flat" disabled="disabled" readonly="readonly" tabindex="-1" />
+            <!-- TMPL_IF name="repeatable" -->
+                <span class="buttonPlus" onclick="CloneField('tag_<!-- TMPL_VAR name="tag"-->_<!-- TMPL_VAR NAME='index'--><!-- TMPL_VAR name="random" -->')">+</span>
+            <!-- /TMPL_IF -->
+            
+        </div>
+
+        <!-- TMPL_LOOP NAME="subfield_loop" -->
+            <!--  One line on the marc editor -->
+            <div name="line" class="subfield_line" style="<!-- TMPL_VAR NAME='visibility' -->;" id="subfield<!-- TMPL_VAR NAME='tag' --><!-- TMPL_VAR NAME='subfield' -->">
+            
+                <!--TMPL_UNLESS NAME="advancedMARCEditor" -->
+                <label for="tag_<!-- TMPL_VAR NAME='tag'-->_subfield_<!--  TMPL_VAR NAME='subfield'-->_<!-- TMPL_VAR NAME='index'-->_<!-- TMPL_VAR NAME='index_subfield'-->"
+                        <!-- TMPL_IF NAME="fixedfield" --> style="display:none;" <!-- /TMPL_IF --> class="labelsubfield" >
+                <!-- /TMPL_UNLESS --> 
+                
+                <!-- TMPL_UNLESS name="hide_marc" -->
+                    <img class="buttonUp" <!-- TMPL_IF NAME="fixedfield" --> style="display:none;" <!-- /TMPL_IF --> src="<!-- TMPL_VAR NAME="themelang" -->/../img/up.png" onclick="upSubfield('subfield<!-- TMPL_VAR NAME='tag' --><!-- TMPL_VAR NAME='subfield' -->')"/>
+                        <input title="<!-- TMPL_VAR NAME='marc_lib_plain' -->"
+                            style=" <!-- TMPL_IF NAME="fixedfield" -->display:none; <!-- /TMPL_IF -->border:0;" type="text"
+                            name="tag_<!-- TMPL_VAR NAME='tag'-->_code_<!--  TMPL_VAR NAME='subfield'-->_<!-- TMPL_VAR NAME='index'-->_<!-- TMPL_VAR NAME='index_subfield'-->"
+                            value="<!-- TMPL_VAR NAME="subfield" -->"
+                            size="1"
+                            maxlength="1"
+                            class="flat"
+                            tabindex=-1 />
                 <!-- TMPL_ELSE -->
-                    <input type="hidden" name="subfield" value="<!-- TMPL_VAR NAME="subfield" -->" />
+                    <input type="hidden"
+                        name="tag_<!-- TMPL_VAR NAME='tag'-->_code_<!--  TMPL_VAR NAME='subfield'-->_<!-- TMPL_VAR NAME='index'-->_<!-- TMPL_VAR NAME='index_subfield'-->"
+                        value="<!-- TMPL_VAR NAME="subfield" -->"/>
                 <!-- /TMPL_UNLESS -->
+            
                 <!-- TMPL_UNLESS NAME="advancedMARCEditor" -->
-                    <!-- TMPL_IF name="mandatory" --><b><!-- /TMPL_IF -->
-                    <!-- TMPL_VAR NAME="marc_lib" -->
-                    <!-- TMPL_IF name="mandatory" --> *</b><!-- /TMPL_IF -->
+                    <!-- TMPL_IF name="mandatory" --><span class="subfield_mandatory"><!-- /TMPL_IF -->
+                        <!-- TMPL_VAR NAME="marc_lib" -->
+                    <!-- TMPL_IF name="mandatory" --></span><!-- /TMPL_IF -->
                     </label>
                 <!-- /TMPL_UNLESS -->
-                    <!-- TMPL_VAR NAME="marc_value" -->
-                    <!-- TMPL_IF NAME="repeatable" -->
-                        <a style="cursor: crosshair; color: grey; font-size: 80%;" onclick="cloneSubfield('subfield<!-- TMPL_VAR NAME="tag" --><!-- TMPL_VAR name="index" -->')">+</a>
-                    <!-- /TMPL_IF -->
-                    <input type="hidden" name="tag" value="<!-- TMPL_VAR NAME="tag" -->" />
-                    <input type="hidden" name="subfieldYYY" value="<!-- TMPL_VAR NAME="subfield" -->" size="2" maxlength="1" />
-                    <input type="hidden" name="mandatory" value="<!-- TMPL_VAR NAME="mandatory" -->" />
-                    <input type="hidden" name="kohafield" value="<!-- TMPL_VAR NAME="kohafield" -->" />
-                    <input type="hidden" name="tag_mandatory" value="<!-- TMPL_VAR NAME="tag_mandatory" -->" />
-                </p>
-</div>
+                
+                <!-- TMPL_VAR NAME="marc_value" -->
+                
+                <!-- TMPL_IF NAME="repeatable" -->
+                    <span class="buttonPlus" onclick="CloneSubfield('subfield<!-- TMPL_VAR NAME='tag' --><!-- TMPL_VAR NAME='subfield' -->')">+</span>
+                <!-- /TMPL_IF -->
+                
+            </div>
+            <!-- End of the line -->
+            
+        <!-- /TMPL_LOOP -->
+        </div>
+        <!-- /TMPL_IF --><!-- tag -->
     <!-- /TMPL_LOOP -->
-
+    </div>
 <!-- /TMPL_LOOP -->
+<!--TMPL_UNLESS Name="singletab"-->
+</div> 
+<!--/TMPL_UNLESS-->
 
-               <div name="hidden" id="hidden" class="tab">
-               <!-- TMPL_LOOP NAME="hidden_loop" -->
-                               <input type="hidden" name="tag" value="<!-- TMPL_VAR NAME="tag" -->" />
-                               <input type="hidden" name="subfield" value="<!-- TMPL_VAR NAME="subfield" -->" />
-                               <input type="hidden" name="mandatory" value="<!-- TMPL_VAR NAME="mandatory" -->" />
-                               <input type="hidden" name="kohafield" value="<!-- TMPL_VAR NAME="kohafield" -->" />
-                               <input type="hidden" name="tag_mandatory" value="<!-- TMPL_VAR NAME="tag_mandatory" -->" />
-               <!-- /TMPL_LOOP -->
-               </div>
-               <!-- TMPL_IF name="oldauthnumtagfield" -->
-                       <input type="hidden" name="tag" value="<!-- TMPL_VAR NAME="oldauthnumtagfield" -->" />
-                       <input type="hidden" name="subfield" value="<!-- TMPL_VAR NAME="oldauthnumtagsubfield" -->" />
-                       <input type="hidden" name="field_value" value="<!-- TMPL_VAR NAME="authid" -->" />
-                       <input type="hidden" name="mandatory" value="0" />
-                       <input type="hidden" name="kohafield" value="<!-- TMPL_VAR NAME="kohafield" -->" />
-                       <input type="hidden" name="tag_mandatory" value="<!-- TMPL_VAR NAME="tag_mandatory" -->" />
-                       <input type="hidden" name="tag" value="<!-- TMPL_VAR NAME="oldauthtypetagfield" -->" />
-                       <input type="hidden" name="subfield" value="<!-- TMPL_VAR NAME="oldauthtypetagsubfield" -->" />
-                       <input type="hidden" name="field_value" value="<!-- TMPL_VAR NAME="authtypecode" -->" />
-               <!-- /TMPL_IF -->
-    <div id="action">
-<!-- TMPL_IF name="authid" -->
-      <input type="button" value="Save" onclick="Check(this.form)" accesskey="w" />
-<!-- TMPL_ELSE -->
-      <input type="button" value="Add authority" onclick="Check(this.form)" accesskey="w" />
+<div name="hidden" id="hidden" class="tab">
+<!-- TMPL_LOOP NAME="hidden_loop" -->
+    <input type="hidden" name="tag" value="<!-- TMPL_VAR NAME="tag" -->">
+    <input type="hidden" name="subfield" value="<!-- TMPL_VAR NAME="subfield" -->">
+    <input type="hidden" name="mandatory" value="<!-- TMPL_VAR NAME="mandatory" -->">
+    <input type="hidden" name="kohafield" value="<!-- TMPL_VAR NAME="kohafield" -->">
+    <input type="hidden" name="tag_mandatory" value="<!-- TMPL_VAR NAME="tag_mandatory" -->">
+<!-- /TMPL_LOOP -->
+</div>
+<!-- TMPL_IF name="oldauthnumtagfield" -->
+    <input type="hidden" name="tag" value="<!-- TMPL_VAR NAME="oldauthnumtagfield" -->">
+    <input type="hidden" name="subfield" value="<!-- TMPL_VAR NAME="oldauthnumtagsubfield" -->">
+    <input type="hidden" name="field_value" value="<!-- TMPL_VAR NAME="authid" -->">
+    <input type="hidden" name="mandatory" value="0">
+    <input type="hidden" name="kohafield" value="<!-- TMPL_VAR NAME="kohafield" -->">
+    <input type="hidden" name="tag_mandatory" value="<!-- TMPL_VAR NAME="tag_mandatory" -->">
+    <input type="hidden" name="tag" value="<!-- TMPL_VAR NAME="oldauthtypetagfield" -->">
+    <input type="hidden" name="subfield" value="<!-- TMPL_VAR NAME="oldauthtypetagsubfield" -->">
+    <input type="hidden" name="field_value" value="<!-- TMPL_VAR NAME="authtypecode" -->">
 <!-- /TMPL_IF -->
-    </div>
-       </form>
+<div id="action">
+    <!-- TMPL_IF name="authid" -->
+        <input type="button" value="Save" onClick="Check(this.form)" accesskey="w">
+    <!-- TMPL_ELSE -->
+        <input type="button" value="Add authority" onClick="Check(this.form)" accesskey="w">
+    <!-- /TMPL_IF -->
+</div>
+</form>
 </fieldset>
-
 </div>
 </div>
 
index 6e0b73a..2fc9524 100644 (file)
@@ -20,6 +20,9 @@
             if(subfields[i].getAttribute('name').match(re)){ // it s a subfield
                 var code     = subfields[i];   // code is the first input 
                 var subfield = subfields[i+1]; // subfield the second
+            <!-- TMPL_IF NAME="clear" -->
+                if (subfield){subfield.value="" ;}
+            <!--TMPL_ELSE-->      
                 if(code.value=='9'){
                         subfield.value = "<!-- TMPL_VAR NAME="authid" -->";
                 }
                     }
                 <!-- /TMPL_LOOP -->
             <!-- /TMPL_LOOP -->
+            <!--/TMPL_IF-->
             }
         }
-        
        opener.close();
                window.close();
+            
                return false;
     }
 </script>
index 62308f8..355e8a8 100644 (file)
@@ -108,18 +108,65 @@ function searchauthority() {
 </div>
 
 <div id="authorities_detail_details">
-<!-- TMPL_LOOP NAME="0XX" -->
+
+<!--TMPL_UNLESS Name="singletab"-->
+    <div id="tabs">
+        <!-- TMPL_IF NAME="0XX" -->
+            <a href="javascript:active(0)" class="tab_active" id="link0">0</a>
+        <!-- /TMPL_IF -->
+        <!-- TMPL_IF NAME="1XX" -->
+            <a href="javascript:active(1)" class="tab_inactive" id="link1">1</a>
+        <!-- /TMPL_IF -->
+        <!-- TMPL_IF NAME="2XX" -->
+            <a href="javascript:active(2)" class="tab_inactive" id="link2">2</a>
+        <!-- /TMPL_IF -->
+        <!-- TMPL_IF NAME="3XX" -->
+            <a href="javascript:active(3)" class="tab_inactive" id="link3">3</a>
+        <!-- /TMPL_IF -->
+        <!-- TMPL_IF NAME="4XX" -->
+            <a href="javascript:active(4)" class="tab_inactive" id="link4">4</a>
+        <!-- /TMPL_IF -->
+        <!-- TMPL_IF NAME="5XX" -->
+            <a href="javascript:active(5)" class="tab_inactive" id="link5">5</a>
+        <!-- /TMPL_IF -->
+        <!-- TMPL_IF NAME="6XX" -->
+            <a href="javascript:active(6)" class="tab_inactive" id="link6">6</a>
+        <!-- /TMPL_IF -->
+        <!-- TMPL_IF NAME="7XX" -->
+            <a href="javascript:active(7)" class="tab_inactive" id="link7">7</a>
+        <!-- /TMPL_IF -->
+        <!-- TMPL_IF NAME="8XX" -->
+            <a href="javascript:active(8)" class="tab_inactive" id="link8">8</a>
+        <!-- /TMPL_IF -->
+        <!-- TMPL_IF NAME="9XX" -->
+            <a href="javascript:active(9)" class="tab_inactive" id="link9">9</a>
+        <!-- /TMPL_IF -->
+    </div>
+<!--/TMPL_UNLESS-->
+
+<!-- TMPL_LOOP name="BIG_LOOP" -->
+<!-- hide every tab except the 1st -->
+<!--TMPL_UNLESS Name="singletab"-->
+  <!-- TMPL_IF name="number" -->
+    <div id="<!-- TMPL_VAR name="number" -->XX" class="content_hidden">
+  <!-- TMPL_ELSE -->
+    <div id="0XX" class="content_visible">
+  <!-- /TMPL_IF -->
+<!-- /TMPL_UNLESS -->
+    
+    <!-- TMPL_LOOP NAME="innerloop" -->
                 <!-- TMPL_IF name="tag" -->
-                    <p class="tag">
+                    <div class="tag">
+                    <div class="tag_title">
                         <!-- TMPL_VAR NAME="tag" -->
-                    </p>
+                    </div>
                 <!-- TMPL_ELSE -->
-                    <br />
+                    <div class="tag">
                 <!-- /TMPL_IF -->
             <!-- TMPL_LOOP NAME="subfield" -->
                 <p>
-                    <label>&nbsp;
-                    <!-- TMPL_UNLESS name="hide_marc" --><!-- TMPL_VAR NAME="marc_subfield" --><!-- /TMPL_UNLESS -->
+                    <label class="labelsubfield">&nbsp;
+                    <!-- TMPL_UNLESS name="hide_marc" --><b><!-- TMPL_VAR NAME="marc_subfield" --></b><!-- /TMPL_UNLESS -->
                     <span title="<!-- TMPL_VAR name="long_desc" -->"><!-- TMPL_VAR NAME="short_desc" --></span></label>
                     <!-- TMPL_VAR NAME="marc_value" -->
                     <!-- TMPL_IF name="link" -->
@@ -131,9 +178,13 @@ function searchauthority() {
                         <a href="/cgi-bin/koha/authorities/detail.pl?authid=<!-- TMPL_VAR name="authority" -->" class="button">Auth</a>
                     <!-- /TMPL_IF -->
                 </p>
-             <!-- /TMPL_LOOP -->
-
-<!-- /TMPL_LOOP --> <!-- tag -->
+            <!-- /TMPL_LOOP -->
+            </div>
+  
+    <!-- /TMPL_LOOP -->
+    </div>
+<!-- /TMPL_LOOP -->
+    
 </div>