fixed to work with addbiblio.
authortoins <toins>
Tue, 31 Jul 2007 16:11:48 +0000 (16:11 +0000)
committertoins <toins>
Tue, 31 Jul 2007 16:11:48 +0000 (16:11 +0000)
authorities/blinddetail-biblio-search.pl
koha-tmpl/intranet-tmpl/prog/en/authorities/blinddetail-biblio-search.tmpl

index a5165af..71be1da 100755 (executable)
@@ -19,7 +19,7 @@
 
 =head1 NAME
 
-etail.pl : script to show an authority in MARC format
+blinddetail-biblio-search.pl : script to show an authority in MARC format
 
 =head1 SYNOPSIS
 
@@ -37,7 +37,6 @@ parameters tables.
 
 =cut
 
-
 use strict;
 require Exporter;
 use C4::AuthoritiesMarc;
@@ -48,85 +47,89 @@ use CGI;
 use MARC::Record;
 use C4::Koha;
 
+my $query = new CGI;
 
-my $query=new CGI;
-
-my $dbh=C4::Context->dbh;
+my $dbh = C4::Context->dbh;
 
-my $authid = $query->param('authid');
-my $index = $query->param('index');
-my $tagid = $query->param('tagid');
+my $authid       = $query->param('authid');
+my $index        = $query->param('index');
+my $tagid        = $query->param('tagid');
 my $authtypecode = &GetAuthTypeCode($authid);
-my $tagslib = &GetTagsLabels(1,$authtypecode);
+my $tagslib      = &GetTagsLabels( 1, $authtypecode );
 
 my $auth_type = GetAuthType($authtypecode);
+my $record = GetAuthority($authid) if $authid;
 
-my $record =GetAuthority($authid) if $authid;
 # open template
-my ($template, $loggedinuser, $cookie)
-               = get_template_and_user({template_name => "authorities/blinddetail-biblio-search.tmpl",
-                            query => $query,
-                            type => "intranet",
-                            authnotrequired => 0,
-                            flagsrequired => {editauthorities => 1},
-                            debug => 1,
-                            });
+my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
+    {
+        template_name   => "authorities/blinddetail-biblio-search.tmpl",
+        query           => $query,
+        type            => "intranet",
+        authnotrequired => 0,
+        flagsrequired   => { editauthorities => 1 },
+    }
+);
 
 # fill arrays
-my @loop_data =();
 my $tag;
-my @loop_data =();
+my @loop_data = ();
 if ($authid) {
-  foreach my $field ($record->field($auth_type->{auth_tag_to_report})) {
-    my @subfields_data;
-    my @subf=$field->subfields;
-    # loop through each subfield
-    my %result;
-    for my $i (0..$#subf) {
-      $subf[$i][0] = "@" unless $subf[$i][0];
-      $result{$subf[$i][0]}.=$subf[$i][1]."|";
-    }
-    foreach (keys %result) {
-      my %subfield_data;
-      chop $result{$_};
-      $subfield_data{marc_value}=$result{$_};
-      $subfield_data{marc_subfield}=$_;
-#                      $subfield_data{marc_tag}=$field->tag();
-      push(@subfields_data, \%subfield_data);
+    foreach my $field ( $record->field( $auth_type->{auth_tag_to_report} ) ) {
+        my @subfields_data;
+        my @subf = $field->subfields;
+
+        # loop through each subfield
+        my %result;
+        for my $i ( 0 .. $#subf ) {
+            $subf[$i][0] = "@" unless $subf[$i][0];
+            $result{ $subf[$i][0] } .= $subf[$i][1] . "|";
+        }
+        foreach ( keys %result ) {
+            my %subfield_data;
+            chop $result{$_};
+            $subfield_data{marc_value}    = $result{$_};
+            $subfield_data{marc_subfield} = $_;
+
+            # $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 ($#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);
-    }
-  }
 } else {
-# authid is empty => the user want to empty the entry.
-  my @subfields_data;
-  foreach my $subfield ('a'..'z') {
+    # authid is empty => the user want to empty the entry.
+    my @subfields_data;
     my %subfield_data;
-    $subfield_data{marc_value}='';
-    $subfield_data{marc_subfield}=$subfield;
-    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);
-#      }
+    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("0XX" =>\@loop_data);
+$template->param( "0XX" => \@loop_data );
 
+$template->param(
+    authid => $authid ? $authid : "",
+    index  => $index,
+    tagid  => $tagid,
+);
 
-$template->param(authid => $authid?$authid:"",
-                index => $index,
-                tagid => $tagid,
-                intranetcolorstylesheet => C4::Context->preference("intranetcolorstylesheet"),
-                intranetstylesheet => C4::Context->preference("intranetstylesheet"),
-                IntranetNav => C4::Context->preference("IntranetNav"),
-                );
 output_html_with_http_headers $query, $cookie, $template->output;
 
index afbad4f..a61cdf5 100644 (file)
@@ -3,57 +3,41 @@
 <!-- TMPL_INCLUDE NAME="doc-head-close.inc" -->
 
 <script type="text/javascript">
-
-function go()
-{
-var index_start = <!-- TMPL_VAR NAME="index" -->;
-var whichfield = opener.opener.document.f.tag[index_start].value;
-i=index_start
-// go forward, until reaching the end of the field.
-while (i<opener.opener.document.f.field_value.length) {
-       if (opener.opener.document.f.tag[i].value == whichfield && opener.opener.document.f.subfield[i].value == '9') {
-               opener.opener.document.f.field_value[i].value = "<!-- TMPL_VAR NAME="authid" -->";
-       }
-       <!-- TMPL_LOOP NAME="0XX" -->
-               <!-- TMPL_LOOP NAME="subfield" -->
-                       if (opener.opener.document.f.tag[i].value == whichfield && opener.opener.document.f.subfield[i].value == '<!-- TMPL_VAR NAME="marc_subfield" -->') 
-                       {
-                               opener.opener.document.f.field_value[i].value = "<!-- TMPL_VAR NAME="marc_value" -->";
-                       }
-               <!-- /TMPL_LOOP -->
-       <!-- /TMPL_LOOP -->
-       if (opener.opener.document.f.tag[i].value != whichfield) {
-               i=opener.opener.document.f.field_value.length;
-       }
-       i++;
-}
-// go backward until the beginning of the field
-i=index_start
-while (i>=0) {
-       if (opener.opener.document.f.tag[i].value == whichfield && opener.opener.document.f.subfield[i].value == '9') {
-               opener.opener.document.f.field_value[i].value = "<!-- TMPL_VAR NAME="authid">";
-       }
-       <!-- TMPL_LOOP NAME="0XX" -->
-               <!-- TMPL_LOOP NAME="subfield" -->
-                       if (opener.opener.document.f.tag[i].value == whichfield && opener.opener.document.f.subfield[i].value == '<!-- TMPL_VAR NAME="marc_subfield" -->') 
-                       {
-                               opener.opener.document.f.field_value[i].value = "<!-- TMPL_VAR NAME="marc_value" -->";
-                       }
-               <!-- /TMPL_LOOP -->
-       <!-- /TMPL_LOOP -->
-       if (opener.opener.document.f.tag[i].value != whichfield) {
-               i=0;
-       }
-       i--;
-}
-       opener.close();
-       self.close();
-       return false;
-
-
-}
+    window.onload = go();
+    
+    function go(){
+        var index_start = "<!-- TMPL_VAR NAME='index' -->";
+        var whichfield;
+        try {
+            whichfield = opener.opener.document.getElementById(index_start);
+        } catch(e) {
+            return;
+        }
+        
+        // browse all its subfields
+        var subfields = whichfield.parentNode.parentNode.getElementsByTagName('input');
+        var re = /^tag_\d*_code_/;
+        for(var i=0, len = subfields.length ; i< len ; i++) { // browse all subfields
+            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
+                if(code.value=='9'){
+                        subfield.value = "<!-- TMPL_VAR NAME="authid" -->";
+                }
+            <!-- TMPL_LOOP NAME="0XX" -->
+                <!-- TMPL_LOOP NAME="subfield" -->
+                    if (code.value == "<!-- TMPL_VAR NAME="marc_subfield" -->"){
+                        subfield.value = "<!-- TMPL_VAR NAME="marc_value" -->";
+                    }
+                <!-- /TMPL_LOOP -->
+            <!-- /TMPL_LOOP -->
+            }
+        }
+        
+       opener.close();
+               window.close();
+               return false;
+    }
 </script>
-<script language="javascript" type="text/javascript">
-window.onload = go();
-</script>
-<!-- TMPL_INCLUDE name="intranet-bottom.inc" -->
\ No newline at end of file
+
+<!-- TMPL_INCLUDE name="intranet-bottom.inc" -->