koha-cvs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Koha-cvs] koha/authorities auth_finder.pl auth_linker.pl ...


From: paul poulain
Subject: [Koha-cvs] koha/authorities auth_finder.pl auth_linker.pl ...
Date: Fri, 09 Mar 2007 14:31:17 +0000

CVSROOT:        /sources/koha
Module name:    koha
Changes by:     paul poulain <tipaul>   07/03/09 14:31:17

Modified files:
        authorities    : auth_finder.pl auth_linker.pl 
                         authorities-home.pl authorities.pl 
                         blinddetail-biblio-search.pl 
                         blinddetail-linker.pl detail-biblio-search.pl 
                         detail.pl 

Log message:
        rel_3_0 moved to HEAD

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/koha/authorities/auth_finder.pl?cvsroot=koha&r1=1.12&r2=1.13
http://cvs.savannah.gnu.org/viewcvs/koha/authorities/auth_linker.pl?cvsroot=koha&r1=1.2&r2=1.3
http://cvs.savannah.gnu.org/viewcvs/koha/authorities/authorities-home.pl?cvsroot=koha&r1=1.15&r2=1.16
http://cvs.savannah.gnu.org/viewcvs/koha/authorities/authorities.pl?cvsroot=koha&r1=1.18&r2=1.19
http://cvs.savannah.gnu.org/viewcvs/koha/authorities/blinddetail-biblio-search.pl?cvsroot=koha&r1=1.8&r2=1.9
http://cvs.savannah.gnu.org/viewcvs/koha/authorities/blinddetail-linker.pl?cvsroot=koha&r1=1.3&r2=1.4
http://cvs.savannah.gnu.org/viewcvs/koha/authorities/detail-biblio-search.pl?cvsroot=koha&r1=1.3&r2=1.4
http://cvs.savannah.gnu.org/viewcvs/koha/authorities/detail.pl?cvsroot=koha&r1=1.5&r2=1.6

Patches:
Index: auth_finder.pl
===================================================================
RCS file: /sources/koha/koha/authorities/auth_finder.pl,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -b -r1.12 -r1.13
--- auth_finder.pl      6 Sep 2006 16:21:04 -0000       1.12
+++ auth_finder.pl      9 Mar 2007 14:31:17 -0000       1.13
@@ -19,19 +19,21 @@
 # Suite 330, Boston, MA  02111-1307 USA
 
 use strict;
-
+require Exporter;
 use CGI;
+use C4::Interface::CGI::Output;
 use C4::Auth;
+
 use C4::Context;
-use C4::Search;
-use C4::Interface::CGI::Output;
 use C4::AuthoritiesMarc;
+use C4::Acquisition;
 use C4::Koha; # XXX subfield_is_koha_internal_p
 
 my $query=new CGI;
 my $op = $query->param('op');
 my $authtypecode = $query->param('authtypecode');
 my $index = $query->param('index');
+my $tagid=$query->param('tagid');
 my $resultstring = $query->param('result');
 my $dbh = C4::Context->dbh;
 
@@ -54,24 +56,17 @@
 
 if ($op eq "do_search") {
        my @marclist = $query->param('marclist');
-       
+    my @and_or = $query->param('and_or');
+    my @excluding = $query->param('excluding');
        my @operator = $query->param('operator');
        my @value = $query->param('value');
 
        $resultsperpage= $query->param('resultsperpage');
-       $resultsperpage = 10 ;
-
-       my ($results,$total) = authoritysearch($dbh, address@hidden, 
address@hidden, address@hidden,$startfrom*$resultsperpage, 
$resultsperpage,$authtypecode);# $orderby);
+    $resultsperpage = 19 if(!defined $resultsperpage);
 
-       ($template, $loggedinuser, $cookie)
-               = get_template_and_user({template_name => 
"authorities/searchresultlist-auth.tmpl",
-                               query => $query,
-                               type => 'intranet',
-                               authnotrequired => 0,
-                               flagsrequired => {borrowers => 1},
-                               flagsrequired => {catalogue => 1},
-                               debug => 1,
-                               });
+    my ($results,$total) = authoritysearch(address@hidden,address@hidden,
+                                        address@hidden, address@hidden, 
address@hidden,
+                                        $startfrom*$resultsperpage, 
$resultsperpage,$authtypecode);# $orderby);
 
        # multi page display gestion
        my $displaynext=0;
@@ -86,6 +81,8 @@
        my @marclist_ini = $query->param('marclist'); # get marclist again, as 
the previous one has been modified by catalogsearch (mainentry replaced by 
field name
        for(my $i = 0 ; $i <= $#marclist ; $i++) {
                push @field_data, { term => "marclist", val=>$marclist_ini[$i] 
};
+               push @field_data, { term => "and_or", val=>$and_or[$i] };
+               push @field_data, { term => "excluding", val=>$excluding[$i] };
                push @field_data, { term => "operator", val=>$operator[$i] };
                push @field_data, { term => "value", val=>$value[$i] };
        }
@@ -113,6 +110,15 @@
        } else {
                $to = (($startfrom+1)*$resultsperpage);
        }
+   ($template, $loggedinuser, $cookie)
+        = get_template_and_user({template_name => 
"authorities/searchresultlist-auth.tmpl",
+                query => $query,
+                type => 'intranet',
+                authnotrequired => 0,
+                flagsrequired => {catalogue => 1},
+                debug => 1,
+                });
+
        $template->param(result => $results) if $results;
        $template->param(index => $query->param('index')."");
        $template->param(startfrom=> $startfrom,
@@ -122,13 +128,16 @@
                                                        startfromnext => 
$startfrom+1,
                                                        startfromprev => 
$startfrom-1,
                                                          index => $index,
+                            tagid => $tagid,
                                                        
searchdata=>address@hidden,
                                                        total=>$total,
                                                        from=>$from,
                                                        to=>$to,
                                                        numbers=>address@hidden,
                                                        authtypecode 
=>$authtypecode,
-                                                       resultstring 
=>$value[0],
+                            mainmainstring =>$value[0],
+                            mainstring =>$value[1],
+                            anystring =>$value[2],
                                                        );
 } else {
        ($template, $loggedinuser, $cookie)
@@ -141,13 +150,17 @@
                                });
 
        $template->param(index=>$query->param('index')."",
+                    tagid => $tagid,
                                        resultstring => $resultstring,
                                        );
 }
 
 $template->param(authtypesloop => address@hidden,
                                authtypecode => $authtypecode,
-                               nonav=>"1",);
+        intranetcolorstylesheet => 
C4::Context->preference("intranetcolorstylesheet"),
+        intranetstylesheet => C4::Context->preference("intranetstylesheet"),
+        IntranetNav => C4::Context->preference("IntranetNav"),
+        );
 
 # Print the page
 output_html_with_http_headers $query, $cookie, $template->output;

Index: auth_linker.pl
===================================================================
RCS file: /sources/koha/koha/authorities/auth_linker.pl,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -b -r1.2 -r1.3
--- auth_linker.pl      6 Sep 2006 16:21:04 -0000       1.2
+++ auth_linker.pl      9 Mar 2007 14:31:17 -0000       1.3
@@ -19,14 +19,17 @@
 # Suite 330, Boston, MA  02111-1307 USA
 
 use strict;
-
+require Exporter;
 use CGI;
 use C4::Auth;
-use C4::Context;
-use C4::Search;
 
+use C4::Context;
+use C4::Auth;
+use C4::Output;
 use C4::Interface::CGI::Output;
 use C4::AuthoritiesMarc;
+#use C4::Biblio;
+use C4::Acquisition;
 use C4::Koha; # XXX subfield_is_koha_internal_p
 
 my $query=new CGI;
@@ -56,22 +59,23 @@
 
 if ($op eq "do_search") {
        my @marclist = $query->param('marclist');
-       
+    my @and_or = $query->param('and_or');
+    my @excluding = $query->param('excluding');
        my @operator = $query->param('operator');
        my @value = $query->param('value');
 
        $resultsperpage= $query->param('resultsperpage');
-       $resultsperpage = 10 if(!defined $resultsperpage);
-
-       my ($results,$total) = authoritysearch($dbh, address@hidden, 
address@hidden, address@hidden,$startfrom*$resultsperpage, 
$resultsperpage,$authtypecode) ;
+    $resultsperpage = 19 if(!defined $resultsperpage);
 
+    my ($results,$total) = authoritysearch($dbh, address@hidden,address@hidden,
+                                        address@hidden, address@hidden, 
address@hidden,
+                                        $startfrom*$resultsperpage, 
$resultsperpage,$authtypecode);# $orderby);
 
        ($template, $loggedinuser, $cookie)
                = get_template_and_user({template_name => 
"authorities/linkresultlist-auth.tmpl",
                                query => $query,
                                type => 'intranet',
                                authnotrequired => 0,
-                               flagsrequired => {borrowers => 1},
                                flagsrequired => {catalogue => 1},
                                debug => 1,
                                });
@@ -85,10 +89,12 @@
 
        my @field_data = ();
 
-
-       my @marclist_ini = $query->param('marclist'); # get marclist again, as 
the previous one has been modified by authoritysearch (mainentry replaced by 
field name
+    # get marclist again, as the previous one has been modified by 
catalogsearch
+    my @marclist_ini = $query->param('marclist');
        for(my $i = 0 ; $i <= $#marclist ; $i++) {
                push @field_data, { term => "marclist", val=>$marclist_ini[$i] 
};
+        push @field_data, { term => "and_or", val=>$and_or[$i] };
+        push @field_data, { term => "excluding", val=>$excluding[$i] };
                push @field_data, { term => "operator", val=>$operator[$i] };
                push @field_data, { term => "value", val=>$value[$i] };
        }

Index: authorities-home.pl
===================================================================
RCS file: /sources/koha/koha/authorities/authorities-home.pl,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -b -r1.15 -r1.16
--- authorities-home.pl 6 Sep 2006 16:21:04 -0000       1.15
+++ authorities-home.pl 9 Mar 2007 14:31:17 -0000       1.16
@@ -19,26 +19,26 @@
 # Suite 330, Boston, MA  02111-1307 USA
 
 use strict;
+require Exporter;
 use CGI;
 use C4::Auth;
+
 use C4::Context;
+use C4::Auth;
+use C4::Output;
 use C4::Interface::CGI::Output;
 use C4::AuthoritiesMarc;
+use C4::Acquisition;
 use C4::Koha; # XXX subfield_is_koha_internal_p
 use C4::Biblio;
 
-
 my $query=new CGI;
 my $op = $query->param('op');
 my $authtypecode = $query->param('authtypecode');
 my $dbh = C4::Context->dbh;
-my $mergefrom=$query->param('mergefrom');
-my $mergeto=$query->param('mergeto');
-my $startfrom=$query->param('startfrom');
+
 my $authid=$query->param('authid');
-$startfrom=0 if(!defined $startfrom);
 my ($template, $loggedinuser, $cookie);
-my $resultsperpage;
 
 my $authtypes = getauthtypes;
 my @authtypesloop;
@@ -51,92 +51,102 @@
        push @authtypesloop, \%row;
 }
 
-
 if ($op eq "do_search") {
        my @marclist = $query->param('marclist');
-       
+       my @and_or = $query->param('and_or');
+       my @excluding = $query->param('excluding');
        my @operator = $query->param('operator');
+       my $orderby = $query->param('orderby');
        my @value = $query->param('value');
 
-       $resultsperpage= $query->param('resultsperpage');
-       $resultsperpage = 10 unless $resultsperpage;
-       my @tags;
-       my ($results,$total) = authoritysearch($dbh, address@hidden, 
address@hidden, address@hidden,$startfrom*$resultsperpage, 
$resultsperpage,$authtypecode) ;
+    my $startfrom = $query->param('startfrom') || 1;
+    my $resultsperpage = $query->param('resultsperpage') || 19;
+
+       my ($results,$total) = authoritysearch(
+        address@hidden,
+        address@hidden,
+        address@hidden,
+        address@hidden,
+        address@hidden,
+        ($startfrom - 1)*$resultsperpage,
+        $resultsperpage,
+        $authtypecode,
+        $orderby
+    );
+
        ($template, $loggedinuser, $cookie)
-               = get_template_and_user({template_name => 
"authorities/searchresultlist.tmpl",
+               = get_template_and_user({
+            template_name => "authorities/searchresultlist.tmpl",
                                query => $query,
                                type => 'intranet',
                                authnotrequired => 0,
-                               authtypecode=> $authtypecode,
-                               flagsrequired => {borrowers => 1},
                                flagsrequired => {catalogue => 1},
                                debug => 1,
                                });
 
-       # multi page display gestion
-       my $displaynext=0;
-       my $displayprev=$startfrom;
-       if(($total - (($startfrom+1)*($resultsperpage))) > 0 ){
-               $displaynext = 1;
-       }
-
        my @field_data = ();
 
-       # we must get parameters once again. Because if there is a mainentry, 
it has been replaced by something else during the search, thus the links 
next/previous would not work anymore 
+       # we must get parameters once again. Because if there is a mainentry, it
+       # has been replaced by something else during the search, thus the links
+       # next/previous would not work anymore
        my @marclist_ini = $query->param('marclist');
        for(my $i = 0 ; $i <= $#marclist ; $i++)
        {
-               push @field_data, { term => "marclist", val=>$marclist_ini[$i] 
};
-               push @field_data, { term => "operator", val=>$operator[$i] };
-               push @field_data, { term => "value", val=>$value[$i] };
-       }
-
-       my @numbers = ();
-
-       if ($total>$resultsperpage)
-       {
-               for (my $i=1; $i<$total/$resultsperpage+1; $i++)
-               {
-                       if ($i<31)
-                       {
-                       my $highlight=0;
-                       ($startfrom==($i-1)) && ($highlight=1);
-                       push @numbers, { number => $i,
-                                       highlight => $highlight ,
-                                       searchdata=> address@hidden,
-                                       startfrom => ($i-1)};
-                       }
-       }
-       }
+               push @field_data, { term => "marclist"  , 
val=>$marclist_ini[$i] };
+               push @field_data, { term => "and_or"    , val=>$and_or[$i] };
+               push @field_data, { term => "excluding" , val=>$excluding[$i] };
+               push @field_data, { term => "operator"  , val=>$operator[$i] };
+               push @field_data, { term => "value"     , val=>$value[$i] };
+       }
+
+    # construction of the url of each page
+    my $base_url =
+        'authorities-home.pl?'
+        .join(
+            '&amp;',
+            map { $_->{term}.'='.$_->{val} } @field_data
+        )
+        .'&amp;'
+        .join(
+            '&amp;',
+            map { $_->{term}.'='.$_->{val} } (
+                {term => 'resultsperpage', val => $resultsperpage},
+                {term => 'type'          , val => 'intranet'},
+                {term => 'op'            , val => 'do_search'},
+                {term => 'authtypecode'  , val => $authtypecode},
+                {term => 'orderby'       , val => $orderby},
+            )
+        )
+        ;
 
-       my $from = $startfrom*$resultsperpage+1;
+       my $from = ($startfrom - 1) * $resultsperpage + 1;
        my $to;
 
-       if($total < (($startfrom+1)*$resultsperpage))
-       {
+       if ($total < $startfrom * $resultsperpage) {
                $to = $total;
-       } else {
-               $to = (($startfrom+1)*$resultsperpage);
        }
+    else {
+               $to = $startfrom * $resultsperpage;
+       }
+
        $template->param(result => $results) if $results;
+
        $template->param(
-                                                       startfrom=> $startfrom,
-                                                       displaynext=> 
$displaynext,
-                                                       displayprev=> 
$displayprev,
-                                                       resultsperpage => 
$resultsperpage,
-                                                       startfromnext => 
$startfrom+1,
-                                                       startfromprev => 
$startfrom-1,
-                                                       
searchdata=>address@hidden,
+        pagination_bar => pagination_bar(
+            $base_url,
+            int($total/$resultsperpage)+1,
+            $startfrom,
+            'startfrom'
+            ),
                                                        total=>$total,
                                                        from=>$from,
                                                        to=>$to,
-                                                       numbers=>address@hidden,
-                                                       
authtypecode=>$authtypecode,
+        isEDITORS => $authtypecode eq 'EDITORS',
                                                        );
 
 } elsif ($op eq "delete") {
 
-       &AUTHdelauthority($dbh,$authid);
+       &AUTHdelauthority($dbh,$authid, 1);
 
        ($template, $loggedinuser, $cookie)
                = get_template_and_user({template_name => 
"authorities/authorities-home.tmpl",
@@ -146,14 +156,11 @@
                                flagsrequired => {catalogue => 1},
                                debug => 1,
                                });
+#      $template->param("statements" => address@hidden,
+#                                              "nbstatements" => 
$nbstatements);
+}
+elsif ($op eq "AddStatement") {
 
-
-}elsif ($op eq "merge") {
-
-
-       my $MARCfrom = XMLgetauthorityhash($dbh,$mergefrom);
-       my $MARCto = XMLgetauthorityhash($dbh,$mergeto);
-       merge($dbh,$mergefrom,$MARCfrom,$mergeto,$MARCto);
        ($template, $loggedinuser, $cookie)
                = get_template_and_user({template_name => 
"authorities/authorities-home.tmpl",
                                query => $query,
@@ -162,7 +169,73 @@
                                flagsrequired => {catalogue => 1},
                                debug => 1,
                                });
-}else {
+
+       # Gets the entered information
+       my @marcfields = $query->param('marclist');
+       my @and_or = $query->param('and_or');
+       my @excluding = $query->param('excluding');
+       my @operator = $query->param('operator');
+       my @value = $query->param('value');
+
+       my @statements = ();
+
+       # List of the marc tags to display
+       my $marcarray = create_marclist();
+
+       my $nbstatements = $query->param('nbstatements');
+       $nbstatements = 1 if(!defined $nbstatements);
+
+       for(my $i = 0 ; $i < $nbstatements ; $i++)
+       {
+               my %fields = ();
+
+               # Recreates the old scrolling lists with the previously 
selected values
+               my $marclist = create_scrolling_list({name=>"marclist",
+                                       values=> $marcarray,
+                                       size=> 1,
+                                       -tabindex=>'',
+                                       default=>$marcfields[$i],
+                                       onChange => "sql_update()"}
+                                       );
+
+               $fields{'marclist'} = $marclist;
+               $fields{'first'} = 1 if($i == 0);
+
+               # Restores the and/or parameters (no need to test the 'and' for 
activation because it's the default value)
+               $fields{'or'} = 1 if($and_or[$i] eq "or");
+
+               #Restores the "not" parameters
+               $fields{'not'} = 1 if($excluding[$i]);
+
+               #Restores the operators (most common operators first);
+               if($operator[$i] eq "=") { $fields{'eq'} = 1; }
+               elsif($operator[$i] eq "contains") { $fields{'contains'} = 1; }
+               elsif($operator[$i] eq "start") { $fields{'start'} = 1; }
+               elsif($operator[$i] eq ">") { $fields{'gt'} = 1; }      
#greater than
+               elsif($operator[$i] eq ">=") { $fields{'ge'} = 1; } #greater or 
equal
+               elsif($operator[$i] eq "<") { $fields{'lt'} = 1; } #lower than
+               elsif($operator[$i] eq "<=") { $fields{'le'} = 1; } #lower or 
equal
+
+               #Restores the value
+               $fields{'value'} = $value[$i];
+
+               push @statements, \%fields;
+       }
+       $nbstatements++;
+
+       # The new scrolling list
+       my $marclist = create_scrolling_list({name=>"marclist",
+                               values=> $marcarray,
+                               size=>1,
+                               -tabindex=>'',
+                               onChange => "sql_update()"});
+       push @statements, {"marclist" => $marclist };
+
+       $template->param("statements" => address@hidden,
+                                               "nbstatements" => 
$nbstatements);
+
+}
+else {
        ($template, $loggedinuser, $cookie)
                = get_template_and_user({template_name => 
"authorities/authorities-home.tmpl",
                                query => $query,
@@ -174,9 +247,11 @@
 
 }
 
-
-
-$template->param(authtypesloop => address@hidden);
+$template->param(authtypesloop => address@hidden,
+               intranetcolorstylesheet => 
C4::Context->preference("intranetcolorstylesheet"),
+               intranetstylesheet => 
C4::Context->preference("intranetstylesheet"),
+               IntranetNav => C4::Context->preference("IntranetNav"),
+               );
 
 # Print the page
 output_html_with_http_headers $query, $cookie, $template->output;

Index: authorities.pl
===================================================================
RCS file: /sources/koha/koha/authorities/authorities.pl,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -b -r1.18 -r1.19
--- authorities.pl      27 Sep 2006 21:19:21 -0000      1.18
+++ authorities.pl      9 Mar 2007 14:31:17 -0000       1.19
@@ -1,6 +1,6 @@
 #!/usr/bin/perl
 
-# $Id: authorities.pl,v 1.18 2006/09/27 21:19:21 tgarip1957 Exp $
+# $Id: authorities.pl,v 1.19 2007/03/09 14:31:17 tipaul Exp $
 
 # Copyright 2000-2002 Katipo Communications
 #
@@ -25,22 +25,52 @@
 use C4::Output;
 use C4::Interface::CGI::Output;
 use C4::AuthoritiesMarc;
-use C4::Biblio;
 use C4::Context;
 use C4::Koha; # XXX subfield_is_koha_internal_p
-use Encode;
 
+use MARC::File::USMARC;
+use MARC::File::XML;
+use C4::Biblio;
 use vars qw( $tagslib);
 use vars qw( $authorised_values_sth);
 use vars qw( $is_a_modif );
-my $input = new CGI;
-my $z3950 = $input->param('z3950');
-my $logstatus=C4::Context->preference('Activate_log');
-my $xml;
+
 my $itemtype; # created here because it can be used in 
build_authorized_values_list sub
 
+=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
@@ -96,6 +126,7 @@
                                -labels   => \%authorised_lib,
                                -override => 1,
                                -size     => 1,
+                               -tabindex=>'',
                                -multiple => 0 );
 }
 
@@ -104,11 +135,11 @@
  builds the <input ...> entry for a subfield.
 =cut
 sub create_input () {
-       my ($tag,$subfield,$value,$i,$tabloop,$rec,$authorised_values_sth,$id) 
= @_;    
+       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{id}=$id;
        $subfield_data{tag}=$tag;
        $subfield_data{subfield}=$subfield;
        $subfield_data{marc_lib}="<span 
id=\"error$i\">".$tagslib->{$tag}->{$subfield}->{lib}."</span>";
@@ -116,66 +147,58 @@
        $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 linking authority field to another authority
+       # 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\" id=\"field_value$id\" value=\"$value\" size=\"40\" 
maxlength=\"255\" DISABLE READONLY> <a  style=\"cursor: help;\" 
href=\"javascript:Dopop('../authorities/auth_linker.pl?index=$id',$id);\">...</a>";
+               $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/value_builder";
+               my $cgidir = C4::Context->intranetdir 
."/cgi-bin/cataloguing/value_builder";
                unless (opendir(DIR, "$cgidir")) {
-                       $cgidir = C4::Context->intranetdir."/value_builder";
+                       $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\" id=\"field_value$id\"  value=\"$value\" size=\"40\" 
maxlength=\"255\" DISABLE READONLY 
OnFocus=\"javascript:Focus$function_name($i)\" 
OnBlur=\"javascript:Blur$function_name($i); \"> <a  style=\"cursor: help;\" 
href=\"javascript:Clic$function_name($i)\">...</a> $javascript";
+               $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\" id=\"field_value$id\"  value=\"$value\">";
+               $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\" id=\"field_value$id\"   value=\"$value\" size=\"40\" 
maxlength=\"255\" >";
+               $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\" id=\"field_value$id\"  cols=\"40\" rows=\"5\" 
>$value</textarea>";
+                       $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\" id=\"field_value$id\"  value=\"$value\" size=\"50\">"; #"
+                       $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 build_tabs  ($$$;$){
-    my($template, $xmlhash, $dbh,$addedfield) = @_;
+sub build_tabs ($$$$) {
+    my($template, $record, $dbh,$encoding) = @_;
     # fill arrays
     my @loop_data =();
     my $tag;
     my $i=0;
-my $id=100;
-my 
($authidtagfield,$authidtagsubfield)=MARCfind_marc_from_kohafield("authid","authorities");
        my $authorised_values_sth = $dbh->prepare("select authorised_value,lib
                from authorised_values
                where category=? order by lib");
-my $author;
-my $controlfields;
-my $leader;
-if ($xmlhash){
- $author=$xmlhash->{'datafield'};
- $controlfields=$xmlhash->{'controlfield'};
- $leader=$xmlhash->{'leader'};
-}
-    my @BIG_LOOP;
-my %built;
+
 # loop through each tab 0 through 9
        for (my $tabloop = 0; $tabloop <= 9; $tabloop++) {
                my @loop_data = ();
@@ -183,141 +206,47 @@
                        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 ($xmlhash) {
-                       ####
-               
-                       my %tagdefined;
-                       my %definedsubfields;
-                       my $hiddenrequired;
-                       my ($ind1,$ind2);
-                       
-                if ($tag>9){
-                       next if ($tag eq $authidtagfield); #we do not want 
authid to duplicate
-
-                       foreach my $data (@$author){                            
                        
-                                       $hiddenrequired=0;
-                                       my @subfields_data;
-                                       undef %definedsubfields;
-                                if ($data->{'tag'} eq $tag){
-                                       $tagdefined{$tag}=1 ;
-                                          if ($built{$tag}==1){
-                                               $hiddenrequired=1;
-                                           }
-                                           $ind1="  ";
-                                             $ind2="  ";               
-                                             foreach my $subfieldcode ( 
$data->{'subfield'}){
-                                                foreach my $code ( 
@$subfieldcode){    
-                                                       next if 
($tagslib->{$tag}->{$code->{'code'}}->{tab} ne $tabloop);                       
                        
-                                                       my 
$subfield=$code->{'code'}  ;
-                                                       my 
$value=$code->{'content'};
-                                                       
$definedsubfields{$tag.$subfield}=1 ;
-                                                        $built{$tag}=1;
-                                                       push(@subfields_data, 
&create_input($tag,$subfield,$value,$i,$tabloop,$xmlhash,$authorised_values_sth,$id))
 ;
-                                                       $i++ ;
-                                               }
-                                             } ##each subfield
-                                           $ind1=$data->{'ind1'};
-                                           $ind2=      $data->{'ind2'};
-                                         
-                                       if ($hiddenrequired && $#loop_data >=0 
&& $loop_data[$#loop_data]->{'tag'} eq $tag) {
-                                               my @hiddensubfields_data;
-                                               my %tag_data;
-                                               push(@hiddensubfields_data, 
&create_input('','','',$i,$tabloop,$xmlhash,$authorised_values_sth,$id));
-                                               $tag_data{tag} = '';
-                                               $tag_data{tag_lib} = '';
-                                               $tag_data{indicator} = '';
-                                               $tag_data{subfield_loop} = 
address@hidden;
-                                               push (@loop_data, \%tag_data);
-                                               $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 
((substr($tagslib->{$tag}->{$subfield}->{hidden},2,1) >1)  ); #check for 
visibility flag
-                                               next if 
($definedsubfields{$tag.$subfield} );
-                                               push(@subfields_data, 
&create_input($tag,$subfield,'',$i,$tabloop,$xmlhash,$authorised_values_sth,$id));
-                                               
$definedsubfields{$tag.$subfield}=1;
-                                               $i++;
+                       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 ($#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} = 
$ind1.$ind2 if ($tag>=10);
-                                               $tag_data{subfield_loop} = 
address@hidden;
-                                               push (@loop_data, \%tag_data);
-                                               
+                               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='@';
                                        }
-                                       $id++;
-                                    }## if tag matches
-                       
-                       }#eachdata
-               }else{ ## tag <10
-                       next if ($tag eq $authidtagfield); #we do not want 
authid to duplicate
-
-                               if ($tag eq "000" || $tag eq "LDR"){
-                                       my $subfield="@";
                                        next if 
($tagslib->{$tag}->{$subfield}->{tab} ne $tabloop);
-                                       my @subfields_data;
-                                       my $value=$leader->[0] if $leader->[0];
-                                       $tagdefined{$tag}=1 ;
-                                       push(@subfields_data, 
&create_input($tag,$subfield,$value,$i,$tabloop,$xmlhash,$authorised_values_sth,$id));
                                    
+                                       #       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++;
-                                       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{subfield_loop} = 
address@hidden;
-                                                                       
$tag_data{fixedfield} = 1;
-                                               push (@loop_data, \%tag_data);
-                                       }
-                                }else{
-                                foreach my $control (@$controlfields){
-                                       my $subfield="@";
+                                       } 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);
-                                       next if ($tagslib->{$tag} eq 
$authidtagfield);
-                                       my @subfields_data;
-                                       if ($control->{'tag'} eq $tag){
-                                               $hiddenrequired=0;
-                                               $tagdefined{$tag}=1;
-                                                if 
($built{$tag}==1){$hiddenrequired=1;}
-                                               my $value=$control->{'content'} 
;
-                                               $definedsubfields{$tag.'@'}=1;
-                                               push(@subfields_data, 
&create_input($tag,$subfield,$value,$i,$tabloop,$xmlhash,$authorised_values_sth,$id));
                                    
+                                                       push(@subfields_data, 
&create_input($tag,$subfield,$value,$i,$tabloop,$record,$authorised_values_sth));
                                                $i++;
-                                       
-                                               $built{$tag}=1;
-                                       ###hiddenrequired
-                                       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{subfield_loop} = 
address@hidden;
-                                               $tag_data{fixedfield} = 1;
-                                               push (@loop_data, \%tag_data);
                                        }
-                                       $id++;
-                                       }## tag matches
-                                }# each control
                               }
-                       }##tag >9
-
-
-                       ##### Any remaining tag
-                               my @subfields_data;
-                               # now, loop again to add parameter subfield 
that are not in the MARC::Record
+# now, loop again to add parameter subfield that are not in the MARC::Record
                                        foreach my $subfield (sort( keys 
%{$tagslib->{$tag}})) {
-                                               next if ($tagdefined{$tag} );
                                                next if (length $subfield !=1);
                                                next if 
($tagslib->{$tag}->{$subfield}->{tab} ne $tabloop);
-                                               next if 
((substr($tagslib->{$tag}->{$subfield}->{hidden},2,1) > 1) ); #check for 
visibility flag
-                                               push(@subfields_data, 
&create_input($tag,$subfield,'',$i,$tabloop,$xmlhash,$authorised_values_sth,$id));
-                                               $tagdefined{$tag.$subfield}=1;
+                                               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) {
@@ -325,7 +254,7 @@
                                                $tag_data{tag} = $tag;
                                                $tag_data{tag_lib} = 
$tagslib->{$tag}->{lib};
                                                $tag_data{repeatable} = 
$tagslib->{$tag}->{repeatable};
-                                               $tag_data{indicator} = 
$ind1.$ind2 if ($tag>=10);
+                                               $tag_data{indicator} = 
$record->field($tag)->indicator(1). $record->field($tag)->indicator(2) if 
($tag>=10);
                                                $tag_data{subfield_loop} = 
address@hidden;
                                                if ($tag<10) {
                                                                        
$tag_data{fixedfield} = 1;
@@ -333,44 +262,30 @@
 
                                                push (@loop_data, \%tag_data);
                                        }
-
-                                       
-                                       if ($addedfield eq $tag) {
-                                               my %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;
-                                               $id++;
-                                               $tagdefined{$tag}=1 ;
-                                               foreach my $subfield (sort( 
keys %{$tagslib->{$tag}})) {
-                                               next if (length $subfield !=1);
-                                               next if 
($tagslib->{$tag}->{$subfield}->{tab} ne $tabloop);
-                                               next if 
((substr($tagslib->{$tag}->{$subfield}->{hidden},2,1) >1)  ); #check for 
visibility flag
-                                               $addedfield=""; 
-                                               push(@subfields_data, 
&create_input($tag,$subfield,'',$i,$tabloop,$xmlhash,$authorised_values_sth,$id));
-                                               $i++;
-                                                       }
-                                               if ($#subfields_data >= 0) {
-                                               $tag_data{tag} = $tag;
-                                               $tag_data{tag_lib} = 
$tagslib->{$tag}->{lib};
-                                               $tag_data{repeatable} = 
$tagslib->{$tag}->{repeatable};
-                                               $tag_data{indicator} = ' ' if 
($tag>=10);
+                                               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} = 
address@hidden;
                                                        if ($tag<10) {
                                                                                
$tag_data{fixedfield} = 1;
                                                                                
}
                                                push (@loop_data, \%tag_data);
-                                                                               
        
+                                               $i++;
                                                }
-                               
                                        }
                                
-       # if breeding is empty
                        } 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) >1)  ); #check for 
visibility flag
+                                       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,$xmlhash,$authorised_values_sth,$id));
+                                       push(@subfields_data, 
&create_input($tag,$subfield,'',$i,$tabloop,$record,$authorised_values_sth));
                                        $i++;
                                }
                                if ($#subfields_data >= 0) {
@@ -387,17 +302,9 @@
                                        push (@loop_data, \%tag_data);
                                }
                        }
-               $id++;
        }
-       if ($#loop_data >=0) {
-            my %big_loop_line;
-            $big_loop_line{number}=$tabloop;
-            address@hidden;
-            push @BIG_LOOP,\%big_loop_line;
-            }  
-#              $template->param($tabloop."XX" =>address@hidden);
-               $template->param(BIG_LOOP => address@hidden);
-}## tab loop
+               $template->param($tabloop."XX" =>address@hidden);
+       }
 }
 
 
@@ -432,9 +339,9 @@
 #          MAIN 
 #=========================
 my $input = new CGI;
+my $z3950 = $input->param('z3950');
 my $error = $input->param('error');
 my $authid=$input->param('authid'); # if authid exists, it's a modif, not a 
new authority.
-my $z3950 = $input->param('z3950');
 my $op = $input->param('op');
 my $nonav = $input->param('nonav');
 my $myindex = $input->param('index');
@@ -450,24 +357,21 @@
                             query => $input,
                             type => "intranet",
                             authnotrequired => 0,
-                            flagsrequired => {editcatalogue => 1},
+                            flagsrequired => {editauthorities => 1},
                             debug => 1,
                             });
 $template->param(nonav   => 
$nonav,index=>$myindex,authtypecode=>$authtypecode,);
 $tagslib = AUTHgettagslib($dbh,1,$authtypecode);
-
-my $xmlhash;
-my $xml;
-$xmlhash = XMLgetauthorityhash($dbh,$authid) if ($authid);
-
-
+my $record=-1;
+my $encoding="";
+$record = AUTHgetauthority($dbh,$authid) if ($authid);
 my ($oldauthnumtagfield,$oldauthnumtagsubfield);
 my ($oldauthtypetagfield,$oldauthtypetagsubfield);
 $is_a_modif=0;
 if ($authid) {
        $is_a_modif=1;
-       ($oldauthnumtagfield,$oldauthnumtagsubfield) = 
MARCfind_marc_from_kohafield("authid","authorities");
-       ($oldauthtypetagfield,$oldauthtypetagsubfield) = 
MARCfind_marc_from_kohafield("authtypecode","authorities");
+       ($oldauthnumtagfield,$oldauthnumtagsubfield) = 
&AUTHfind_marc_from_kohafield($dbh,"auth_header.authid",$authtypecode);
+       ($oldauthtypetagfield,$oldauthtypetagsubfield) = 
&AUTHfind_marc_from_kohafield($dbh,"auth_header.authtypecode",$authtypecode);
 }
 
 
#------------------------------------------------------------------------------------------------------------------------------
@@ -481,46 +385,36 @@
        # build indicator hash.
        my @ind_tag = $input->param('ind_tag');
        my @indicator = $input->param('indicator');
-## check for malformed xml -- non UTF-8 like (MARC8) will break xml without 
warning
-### This usually happens with data coming from other Z3950 servers
-## Slows the saving process so comment out at your own risk
-eval{
- $xml = 
MARChtml2xml(address@hidden,address@hidden,address@hidden,address@hidden,address@hidden);
      
-};
-
- if ($@){
-warn $@;
- $template->param(error             =>1,xmlerror=>1,);
-goto FINAL;
-  };   # check for a duplicate
-###Authorities need the XML header unlike biblios
-$xml='<?xml version="1.0" encoding="UTF-8"?>'.$xml;
-  my $xmlhash=XML_xml2hash_onerecord($xml);
-       my ($duplicateauthid,$duplicateauthvalue) = 
C4::AuthoritiesMarc::FindDuplicateauth($xmlhash,$authtypecode) if ($op eq 
"add") && (!$is_a_modif);
-#warn "duplicate:$duplicateauthid,$duplicateauthvalue";        
+       my $xml = 
MARChtml2xml(address@hidden,address@hidden,address@hidden,address@hidden,address@hidden);
+#     warn $record->as_formatted;
+       warn $xml;
+       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) = 
C4::AuthoritiesMarc::FindDuplicate($record,$authtypecode) if ($op eq "add") && 
(!$is_a_modif);
+warn "duplicate:$duplicateauthid,$duplicateauthvalue"; 
        my $confirm_not_duplicate = $input->param('confirm_not_duplicate');
-       # it is not a duplicate (determined either by Koha itself or by user 
checking it's not a duplicate)
+# it is not a duplicate (determined either by Koha itself or by user checking 
it's not a duplicate)
        if (!$duplicateauthid or $confirm_not_duplicate) {
 # warn "noduplicate";
                if ($is_a_modif ) {     
-                       
$authid=AUTHmodauthority($dbh,$authid,$xmlhash,$authtypecode);
+                       
$authid=AUTHmodauthority($dbh,$authid,$record,$authtypecode,1);         
                } else {
-               $authid = AUTHaddauthority($dbh,$xmlhash,'',$authtypecode);
+               ($authid) = 
AUTHaddauthority($dbh,$record,$authid,$authtypecode);
 
                }
        # now, redirect to detail page
-               if ($nonav){
+#              if ($nonav){
 #warn ($myindex,$nonav);
-               print 
$input->redirect("auth_finder.pl?index=$myindex&nonav=$nonav&authtypecode=$authtypecode");
-               }else{
-               print $input->redirect("detail.pl?nonav=$nonav&authid=$authid");
-               }
+#              print 
$input->redirect("auth_finder.pl?index=$myindex&nonav=$nonav&authtypecode=$authtypecode");
+#              }else{
+               print $input->redirect("detail.pl?authid=$authid");
+#              }
                exit;
        } else {
-FINAL:
-#warn "duplicate";
        # it may be a duplicate, warn the user and do nothing
-               build_tabs ($template, $xmlhash, $dbh);
+               build_tabs ($template, $record, $dbh,$encoding);
                build_hidden_data;
                $template->param(authid =>$authid,
                        duplicateauthid                         => 
$duplicateauthid,
@@ -531,6 +425,7 @@
 } 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');
@@ -538,10 +433,12 @@
        my @ind_tag = $input->param('ind_tag');
        my @indicator = $input->param('indicator');
        my $xml = 
MARChtml2xml(address@hidden,address@hidden,address@hidden,address@hidden,address@hidden);
-       $xml='<?xml version="1.0" encoding="UTF-8"?>'.$xml;
-       my $xmlhash=XML_xml2hash_onerecord($xml);
+       my $record=MARC::Record->new_from_xml($xml,'UTF-8');
+       $record->encoding('UTF-8');
        # adding an empty field
-       build_tabs ($template, $xmlhash, $dbh,$addedfield);
+       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,);
@@ -560,21 +457,22 @@
        {
                $authid = "";
        }
-       build_tabs ($template, $xmlhash, $dbh);
+       build_tabs ($template, $record, $dbh,$encoding);
        build_hidden_data;
        $template->param(oldauthtypetagfield=>$oldauthtypetagfield, 
oldauthtypetagsubfield=>$oldauthtypetagsubfield,
                oldauthnumtagfield=>$oldauthnumtagfield, 
oldauthnumtagsubfield=>$oldauthnumtagsubfield,
                authid                      => $authid , 
authtypecode=>$authtypecode,   );
 }
 
+#unless ($op) {
+#      warn "BUILDING";
+#      build_tabs ($template, $record, $dbh,$encoding);
+#      build_hidden_data;
+#}
 $template->param(
        authid                       => $authid,
        authtypecode => $authtypecode,
        linkid=>$linkid,
-                       intranetcolorstylesheet => 
C4::Context->preference("intranetcolorstylesheet"),
-               intranetstylesheet => 
C4::Context->preference("intranetstylesheet"),
-               IntranetNav => C4::Context->preference("IntranetNav"),
-               advancedMARCEditor => 
C4::Context->preference("advancedMARCEditor"),
                );
 
 my $authtypes = getauthtypes;
@@ -590,5 +488,9 @@
 
 $template->param(authtypesloop => address@hidden,
                                authtypetext => 
$authtypes->{$authtypecode}{'authtypetext'},
-                               nonav=>$nonav,);
+                               hide_marc => 
C4::Context->preference('hide_marc'),
+                               intranetcolorstylesheet => 
C4::Context->preference("intranetcolorstylesheet"),
+               intranetstylesheet => 
C4::Context->preference("intranetstylesheet"),
+               IntranetNav => C4::Context->preference("IntranetNav"),
+                               );
 output_html_with_http_headers $input, $cookie, $template->output;

Index: blinddetail-biblio-search.pl
===================================================================
RCS file: /sources/koha/koha/authorities/blinddetail-biblio-search.pl,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -b -r1.8 -r1.9
--- blinddetail-biblio-search.pl        6 Sep 2006 16:21:04 -0000       1.8
+++ blinddetail-biblio-search.pl        9 Mar 2007 14:31:17 -0000       1.9
@@ -19,6 +19,7 @@
 
 =head1 NAME
 
+etail.pl : script to show an authority in MARC format
 
 =head1 SYNOPSIS
 
@@ -27,7 +28,8 @@
 
 This script needs an authid
 
-
+It shows the authority in a (nice) MARC format depending on authority MARC
+parameters tables.
 
 =head1 FUNCTIONS
 
@@ -37,34 +39,39 @@
 
 
 use strict;
+require Exporter;
 use C4::AuthoritiesMarc;
 use C4::Auth;
 use C4::Context;
+use C4::Output;
 use C4::Interface::CGI::Output;
 use CGI;
-use C4::Search;
+use MARC::Record;
 use C4::Koha;
-use C4::Biblio;
+
+
 my $query=new CGI;
 
 my $dbh=C4::Context->dbh;
 
 my $authid = $query->param('authid');
-my $index=$query->param('index');
+my $index = $query->param('index');
+my $tagid = $query->param('tagid');
 my $authtypecode = &AUTHfind_authtypecode($dbh,$authid);
 my $tagslib = &AUTHgettagslib($dbh,1,$authtypecode);
-my 
($dummyfield,$linkidsubfield)=MARCfind_marc_from_kohafield("auth_biblio_link_subf","biblios");
+
 my $auth_type = AUTHgetauth_type($authtypecode);
-#warn "$authid =$authtypecode ".$auth_type->{auth_tag_to_report};
+ warn "XX = ".$auth_type->{auth_tag_to_report};
 
-my $record =XMLgetauthorityhash($dbh,$authid) if $authid;
+my $record =AUTHgetauthority($dbh,$authid);
+  warn "record auth :".$record->as_formatted;
 # open template
 my ($template, $loggedinuser, $cookie)
                = get_template_and_user({template_name => 
"authorities/blinddetail-biblio-search.tmpl",
                             query => $query,
                             type => "intranet",
                             authnotrequired => 0,
-                            flagsrequired => {catalogue => 1},
+                            flagsrequired => {editauthorities => 1},
                             debug => 1,
                             });
 
@@ -73,29 +80,30 @@
 my $tag;
 my @loop_data =();
 if ($authid) {
-       my 
@record_subs=XML_readline_withtags($record,"","",$auth_type->{auth_tag_to_report});
-       ##Put the result in a hash
-       my %filled_subfield;
-       foreach my $subfield (@record_subs) {
-       $filled_subfield{$subfield->[0]}=$subfield->[1];
-       }
+       foreach my $field ($record->field($auth_type->{auth_tag_to_report})) {
                        my @subfields_data;
-                       
+               my @subf=$field->subfields;
                # loop through each subfield
-               foreach my $subfield ('a'..'z') {                       
+               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;
-                       $subfield_data{marc_value}=$filled_subfield{$subfield} ;
-                       $subfield_data{marc_subfield}=$subfield;
-                       
$subfield_data{marc_tag}=$auth_type->{auth_tag_to_report};
+                       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}=$auth_type->{auth_tag_to_report}.' -'. 
$tagslib->{$auth_type->{auth_tag_to_report}}->{lib};
+                       $tag_data{tag}=$field->tag().' -'. 
$tagslib->{$field->tag()}->{lib};
                        $tag_data{subfield} = address@hidden;
                        push (@loop_data, \%tag_data);
                }
-       
+       }
 } else {
 # authid is empty => the user want to empty the entry.
        my @subfields_data;
@@ -105,21 +113,34 @@
                        $subfield_data{marc_subfield}=$subfield;
                        push(@subfields_data, \%subfield_data);
                }
-       foreach my $subfield ('0'..'9') {
-                       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} = address@hidden;
                push (@loop_data, \%tag_data);
+#      }
 }
 
 $template->param("0XX" =>address@hidden);
 
-
-
-$template->param(authid => $authid?$authid:"", 
linkidsubfield=>$linkidsubfield,index=>$index,);
+# my $authtypes = getauthtypes;
+# my @authtypesloop;
+# foreach my $thisauthtype (keys %$authtypes) {
+#      my $selected = 1 if $thisauthtype eq $authtypecode;
+#      my %row =(value => $thisauthtype,
+#                              selected => $selected,
+#                              authtypetext => 
$authtypes->{$thisauthtype}{'authtypetext'},
+#                      );
+#      push @authtypesloop, \%row;
+# }
+
+$template->param(authid => $authid?$authid:"",
+#                              authtypesloop => address@hidden,
+                               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: blinddetail-linker.pl
===================================================================
RCS file: /sources/koha/koha/authorities/blinddetail-linker.pl,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -b -r1.3 -r1.4
--- blinddetail-linker.pl       27 Sep 2006 21:19:21 -0000      1.3
+++ blinddetail-linker.pl       9 Mar 2007 14:31:17 -0000       1.4
@@ -28,6 +28,8 @@
 
 This script needs an authid
 
+It shows the authority in a (nice) MARC format depending on authority MARC
+parameters tables.
 
 =head1 FUNCTIONS
 
@@ -37,14 +39,17 @@
 
 
 use strict;
+require Exporter;
 use C4::AuthoritiesMarc;
 use C4::Auth;
 use C4::Context;
+use C4::Output;
 use C4::Interface::CGI::Output;
 use CGI;
-use C4::Search;
+use MARC::Record;
 use C4::Koha;
-use C4::Biblio;
+
+
 my $query=new CGI;
 
 my $dbh=C4::Context->dbh;
@@ -54,17 +59,17 @@
 my $authtypecode=$query->param('authtypecode');
  $authtypecode = &AUTHfind_authtypecode($dbh,$authid) if !$authtypecode;
 my $tagslib = &AUTHgettagslib($dbh,1,$authtypecode);
-my 
($linkidfield,$linkidsubfield)=MARCfind_marc_from_kohafield("linkid","authorities");
+my 
($linkidfield,$linkidsubfield)=AUTHfind_marc_from_kohafield($dbh,"auth_header.linkid",$authtypecode);
 my $auth_type = AUTHgetauth_type($authtypecode);
 
-my $record =XMLgetauthorityhash($dbh,$authid);
+my $record =AUTHgetauthority($dbh,$authid);
 # open template
 my ($template, $loggedinuser, $cookie)
                = get_template_and_user({template_name => 
"authorities/blinddetail-linker.tmpl",
                             query => $query,
                             type => "intranet",
                             authnotrequired => 0,
-                            flagsrequired => {catalogue => 1},
+                            flagsrequired => {editauthorities => 1},
                             debug => 1,
                             });
 
@@ -74,46 +79,42 @@
 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
-#              for my $i (0..$#subf) {
-#                      $subf[$i][0] = "@" unless $subf[$i][0];
-#                      my %subfield_data;
-#                      $subfield_data{marc_value}=$subf[$i][1];
-#                      $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} = address@hidden;
-#                      push (@loop_data, \%tag_data);
-#              }
-#      }
-} else {
-# authid is empty => the user want to empty the entry.
+       foreach my $field ($record->field($auth_type->{auth_tag_to_report})) {
        my @subfields_data;
-       foreach my $subfield ('0'..'9') {
+                       my @subf=$field->subfields;
+               # loop through each subfield
+               for my $i (0..$#subf) {
+                       $subf[$i][0] = "@" unless $subf[$i][0];
                        my %subfield_data;
-                       $subfield_data{marc_value}='';
-                       $subfield_data{marc_subfield}=$subfield;
+                       $subfield_data{marc_value}=$subf[$i][1];
+                       $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} = address@hidden;
+                       push (@loop_data, \%tag_data);
+               }
+       }
+} else {
+# authid is empty => the user want to empty the entry.
+       my @subfields_data;
        foreach my $subfield ('a'..'z') {
                        my %subfield_data;
                        $subfield_data{marc_value}='';
                        $subfield_data{marc_subfield}=$subfield;
                        push(@subfields_data, \%subfield_data);
+               
                }
        
-       if ($#subfields_data>=0) {
+#      if ($#subfields_data>=0) {
                my %tag_data;
+#                      $tag_data{tag}=$field->tag().' -'. 
$tagslib->{$field->tag()}->{lib};
                $tag_data{subfield} = address@hidden;
                push (@loop_data, \%tag_data);
-       }
+#      }
 }
 
 $template->param("0XX" =>address@hidden);

Index: detail-biblio-search.pl
===================================================================
RCS file: /sources/koha/koha/authorities/detail-biblio-search.pl,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -b -r1.3 -r1.4
--- detail-biblio-search.pl     6 Sep 2006 16:21:04 -0000       1.3
+++ detail-biblio-search.pl     9 Mar 2007 14:31:17 -0000       1.4
@@ -39,13 +39,18 @@
 
 
 use strict;
+require Exporter;
 use C4::AuthoritiesMarc;
 use C4::Auth;
 use C4::Context;
+use C4::Output;
 use C4::Interface::CGI::Output;
 use CGI;
-use C4::Search;
+use MARC::Record;
 use C4::Koha;
+# use C4::Biblio;
+# use C4::Catalogue;
+
 
 my $query=new CGI;
 
@@ -56,7 +61,7 @@
 my $authtypecode = &AUTHfind_authtypecode($dbh,$authid);
 my $tagslib = &AUTHgettagslib($dbh,1,$authtypecode);
 
-my $record =XMLgetauthorityhash($dbh,$authid);
+my $record =AUTHgetauthority($dbh,$authid);
 # open template
 my ($template, $loggedinuser, $cookie)
                = get_template_and_user({template_name => 
"authorities/detail-biblio-search.tmpl",
@@ -70,93 +75,96 @@
 # fill arrays
 my @loop_data =();
 my $tag;
-if ($xmlhash){
 # loop through each tab 0 through 9
-my $author=$xmlhash->{'datafield'};
-my $controlfields=$xmlhash->{'controlfield'};
-my $leader=$xmlhash->{'leader'};
-for (my $tabloop = 0; $tabloop<10;$tabloop++) {
+# 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;
-
-       # deal with leader 
-       unless (($tagslib->{'000'}->{'@'}->{tab}  ne $tabloop)  || 
(substr($tagslib->{'000'}->{'@'}->{hidden},1,1)>0)) {
-               
-               my %subfield_data;
-               $subfield_data{marc_value}=$leader->[0] ;
-               push(@subfields_data, \%subfield_data);
-               my %tag_data;
-               $tag_data{tag}='000 -'. $tagslib->{'000'}->{lib};
-               my @tmp = @subfields_data;
-               $tag_data{subfield} = address@hidden;
-               push (@loop_data, \%tag_data);
-               undef @subfields_data;
-       }
-       ##Controlfields
-               
-                foreach my $control (@$controlfields){
+               # if tag <10, there's no subfield, use the "@" trick
+               if ($field->tag()<10) {
+#                      next if ($tagslib->{$field->tag()}->{'@'}->{tab}  ne 
$tabloop);
+                       next if ($tagslib->{$field->tag()}->{'@'}->{hidden});
                        my %subfield_data;
-                       my %tag_data;
-                       next if ($tagslib->{$control->{'tag'}}->{'@'}->{tab}  
ne $tabloop);
-                       next if 
(substr($tagslib->{$control->{'tag'}}->{'@'}->{hidden},1,1)>0);                 
-                       $subfield_data{marc_value}=$control->{'content'} ;
+                       
$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);
-                               if (C4::Context->preference('hide_marc')) {
-                                       
$tag_data{tag}=$tagslib->{$control->{'tag'}}->{lib};
                                } else {
-                                       $tag_data{tag}=$control->{'tag'}.' -'. 
$tagslib->{$control->{'tag'}}->{lib};
-                               }                       
-                       my @tmp = @subfields_data;
-                       $tag_data{subfield} = address@hidden;
-                       push (@loop_data, \%tag_data);
-                       undef @subfields_data;
-               }
-       my $previoustag;
-       my %datatags;
-       my $i=0;
-       foreach my $data (@$author){
-               $datatags{$i++}=$data->{'tag'};
-                foreach my $subfield ( $data->{'subfield'}){
-                    foreach my $code ( @$subfield){
-                       next if 
($tagslib->{$data->{'tag'}}->{$code->{'code'}}->{tab}  ne $tabloop);
-                       next if 
(substr($tagslib->{$data->{'tag'}}->{$code->{'code'}}->{hidden},1,1)>0);
+                       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]}->{tab}  ne $tabloop);
+                               next if 
($tagslib->{$field->tag()}->{$subf[$i][0]}->{hidden});
                        my %subfield_data;
-                       my $value=$code->{'content'};
-                       
$subfield_data{marc_lib}=$tagslib->{$data->{'tag'}}->{$code->{'code'}}->{lib};
-                       
$subfield_data{link}=$tagslib->{$data->{'tag'}}->{$code->{'code'}}->{link};
-                       if 
($tagslib->{$data->{'tag'}}->{$code->{'code'}}->{isurl}) {
-                               $subfield_data{marc_value}="<a 
href=\"$value]\">$value</a>";
+                               
$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}=get_authorised_value_desc($data->{'tag'}, 
$code->{'code'}, $value, '', $dbh);
+                                       $subfield_data{marc_value}=$subf[$i][1];
                        }
-                       $subfield_data{marc_subfield}=$code->{'code'};
-                       $subfield_data{marc_tag}=$data->{'tag'};
+                               $subfield_data{marc_subfield}=$subf[$i][0];
+                               $subfield_data{marc_tag}=$field->tag();
                        push(@subfields_data, \%subfield_data);
-                    }### $code
-               
-               
-               if ($#subfields_data>=0) {
-                       my %tag_data;
-                       if (($datatags{$i} eq $datatags{$i-1}) && 
(C4::Context->preference('LabelMARCView') eq 'economical')) {
-                               $tag_data{tag}="";
-                       } else {
-                               if (C4::Context->preference('hide_marc')) {
-                                       
$tag_data{tag}=$tagslib->{$data->{'tag'}}->{lib};
-                               } else {
-                                       $tag_data{tag}=$data->{'tag'}.' -'. 
$tagslib->{$data->{'tag'}}->{lib};
                                }
                        }
-                       my @tmp = @subfields_data;
-                       $tag_data{subfield} = address@hidden;
+               if ($#subfields_data>=0) {
+                       my %tag_data;
+                       $tag_data{tag}=$field->tag().' -'. 
$tagslib->{$field->tag()}->{lib};
+                       $tag_data{subfield} = address@hidden;
                        push (@loop_data, \%tag_data);
-                       undef @subfields_data;
                }
-             }### each $subfield
        }
-
-       $template->param($tabloop."XX" =>address@hidden);
-}
+       $template->param("0XX" =>address@hidden);
+# }
+# now, build item tab !
+# the main difference is that datas are in lines and not in columns : thus, we 
build the <th> first, then the values...
+# loop through each tag
+# warning : we may have differents number of columns in each row. Thus, we 
first build a hash, complete it if necessary
+# then construct template.
+# my @fields = $record->fields();
+# my %witness; #---- stores the list of subfields used at least once, with the 
"meaning" of the code
+# my @big_array;
+# foreach my $field (@fields) {
+#      next if ($field->tag()<10);
+#      my @subf=$field->subfields;
+#      my %this_row;
+# # loop through each subfield
+#      for my $i (0..$#subf) {
+#              next if ($tagslib->{$field->tag()}->{$subf[$i][0]}->{tab}  ne 
10);
+#              $witness{$subf[$i][0]} = 
$tagslib->{$field->tag()}->{$subf[$i][0]}->{lib};
+#              $this_row{$subf[$i][0]} =$subf[$i][1];
+#      }
+#      if (%this_row) {
+#              push(@big_array, \%this_row);
+#      }
+# }
+# #fill big_row with missing datas
+# foreach my $subfield_code  (keys(%witness)) {
+#      for (my $i=0;$i<=$#big_array;$i++) {
+#              $big_array[$i]{$subfield_code}="&nbsp;" unless 
($big_array[$i]{$subfield_code});
+#      }
+# }
+# # now, construct template !
+# my @item_value_loop;
+# my @header_value_loop;
+# for (my $i=0;$i<=$#big_array; $i++) {
+#      my $items_data;
+#      foreach my $subfield_code (keys(%witness)) {
+#              $items_data .="<td>".$big_array[$i]{$subfield_code}."</td>";
+#      }
+#      my %row_data;
+#      $row_data{item_value} = $items_data;
+#      push(@item_value_loop,\%row_data);
+# }
+# foreach my $subfield_code (keys(%witness)) {
+#      my %header_value;
+#      $header_value{header_value} = $witness{$subfield_code};
+#      push(@header_value_loop, \%header_value);
+# }
 
 my $authtypes = getauthtypes;
 my @authtypesloop;
@@ -170,32 +178,10 @@
 }
 
 $template->param(authid => $authid,
-                               authtypesloop => address@hidden, index => 
$index);
-}
+               authtypesloop => address@hidden, index => $index,
+               intranetcolorstylesheet => 
C4::Context->preference("intranetcolorstylesheet"),
+               intranetstylesheet => 
C4::Context->preference("intranetstylesheet"),
+               IntranetNav => C4::Context->preference("IntranetNav"),
+               );
 output_html_with_http_headers $query, $cookie, $template->output;
 
-sub get_authorised_value_desc ($$$$$) {
-   my($tag, $subfield, $value, $framework, $dbh) = @_;
-
-   #---- branch
-    if ($tagslib->{$tag}->{$subfield}->{'authorised_value'} eq "branches" ) {
-       return getbranchname($value);
-    }
-
-   #---- itemtypes
-   if ($tagslib->{$tag}->{$subfield}->{'authorised_value'} eq "itemtypes" ) {
-       return ItemType($value);
-    }
-
-   #---- "true" authorized value
-   my $category = $tagslib->{$tag}->{$subfield}->{'authorised_value'};
-
-   if ($category ne "") {
-       my $sth = $dbh->prepare("select lib from authorised_values where 
category = ? and authorised_value = ?");
-       $sth->execute($category, $value);
-       my $data = $sth->fetchrow_hashref;
-       return $data->{'lib'};
-   } else {
-       return $value; # if nothing is found return the original value
-   }
-}

Index: detail.pl
===================================================================
RCS file: /sources/koha/koha/authorities/detail.pl,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -b -r1.5 -r1.6
--- detail.pl   6 Sep 2006 16:21:04 -0000       1.5
+++ detail.pl   9 Mar 2007 14:31:17 -0000       1.6
@@ -39,28 +39,22 @@
 
 
 use strict;
+require Exporter;
 use C4::AuthoritiesMarc;
 use C4::Auth;
 use C4::Context;
+use C4::Output;
 use C4::Interface::CGI::Output;
 use CGI;
-use C4::Search;
+use MARC::Record;
 use C4::Koha;
+# use C4::Biblio;
+# use C4::Catalogue;
 
 
 my $query=new CGI;
 
 my $dbh=C4::Context->dbh;
-my $nonav = $query->param('nonav');
-my $authid = $query->param('authid');
-my $authtypecode = &AUTHfind_authtypecode($dbh,$authid);
-my $tagslib = &AUTHgettagslib($dbh,1,$authtypecode);
-
-my $xmlhash =XMLgetauthorityhash($dbh,$authid);
-
-my ($count) = AUTHcount_usage($authid);
-
-#chop;
 
 # open template
 my ($template, $loggedinuser, $cookie)
@@ -72,97 +66,104 @@
                             debug => 1,
                             });
 
+my $authid = $query->param('authid');
+
+
+
+my $authtypecode = &AUTHfind_authtypecode($dbh,$authid);
+my $tagslib = &AUTHgettagslib($dbh,1,$authtypecode);
+
+my $record;
+if (C4::Context->preference("AuthDisplayHierarchy")){
+  my $trees=BuildUnimarcHierarchies($authid);
+  my @trees = split /;/,$trees ;
+  push @trees,$trees unless (@trees);
+  my @loophierarchies;
+  foreach my $tree (@trees){
+    my @tree=split /,/,$tree;
+    push @tree,$tree unless (@tree);
+    my $cnt=0;
+    my @loophierarchy;
+    foreach my $element (@tree){
+      my %cell;
+      my $elementdata = AUTHgetauthority($dbh,$element);
+      $record= $elementdata if ($authid==$element);
+      push @loophierarchy, BuildUnimarcHierarchy($elementdata,"child".$cnt, 
$authid);
+      $cnt++;
+    }
+    push @loophierarchies, { 'loopelement' =>address@hidden;
+  }
+  $template->param(
+    'displayhierarchy' =>C4::Context->preference("AuthDisplayHierarchy"),
+    'loophierarchies' =>address@hidden,
+  );
+} else {
+  $record=AUTHgetauthority($dbh,$authid);
+}
+my $count = AUTHcount_usage($authid);
+
+# find the marc field/subfield used in biblio by this authority
+my $sth = $dbh->prepare("select distinct tagfield from marc_subfield_structure 
where authtypecode=?");
+$sth->execute($authtypecode);
+my $biblio_fields;
+while (my ($tagfield) = $sth->fetchrow) {
+       $biblio_fields.= $tagfield."9,";
+}
+chop $biblio_fields;
+
 
 # fill arrays
 my @loop_data =();
 my $tag;
-if ($xmlhash){
 # loop through each tab 0 through 9
-my $author=$xmlhash->{'datafield'};
-my $controlfields=$xmlhash->{'controlfield'};
-my $leader=$xmlhash->{'leader'};
-for (my $tabloop = 0; $tabloop<10;$tabloop++) {
+# for (my $tabloop = 0; $tabloop<=10;$tabloop++) {
 # loop through each tag
-       my @loop_data =();
+my @fields = $record->fields();
+my @loop_data =();
+foreach my $field (@fields) {
        my @subfields_data;
-
-       # deal with leader 
-       unless (($tagslib->{'000'}->{'@'}->{tab}  ne $tabloop)  || 
(substr($tagslib->{'000'}->{'@'}->{hidden},1,1)>0)) {
-               
+       # 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_value}=$leader->[0] ;
+               
$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);
-               my %tag_data;
-               $tag_data{tag}='000 -'. $tagslib->{'000'}->{lib};
-               my @tmp = @subfields_data;
-               $tag_data{subfield} = address@hidden;
-               push (@loop_data, \%tag_data);
-               undef @subfields_data;
-       }
-       ##Controlfields
-               
-                foreach my $control (@$controlfields){
-                       my %subfield_data;
-                       my %tag_data;
-                       next if ($tagslib->{$control->{'tag'}}->{'@'}->{tab}  
ne $tabloop);
-                       next if 
(substr($tagslib->{$control->{'tag'}}->{'@'}->{hidden},1,1)>0);                 
-                       $subfield_data{marc_value}=$control->{'content'} ;
-                       push(@subfields_data, \%subfield_data);
-                               if (C4::Context->preference('hide_marc')) {
-                                       
$tag_data{tag}=$tagslib->{$control->{'tag'}}->{lib};
                                } else {
-                                       $tag_data{tag}=$control->{'tag'}.' -'. 
$tagslib->{$control->{'tag'}}->{lib};
-                               }                       
-                       my @tmp = @subfields_data;
-                       $tag_data{subfield} = address@hidden;
-                       push (@loop_data, \%tag_data);
-                       undef @subfields_data;
-               }
-       my $previoustag;
-       my %datatags;
-       my $i=0;
-       foreach my $data (@$author){
-               $datatags{$i++}=$data->{'tag'};
-                foreach my $subfield ( $data->{'subfield'}){
-                    foreach my $code ( @$subfield){
-                       next if 
($tagslib->{$data->{'tag'}}->{$code->{'code'}}->{tab}  ne $tabloop);
-                       next if 
(substr($tagslib->{$data->{'tag'}}->{$code->{'code'}}->{hidden},1,1)>0);
+               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;
-                       my $value=$code->{'content'};
-                       
$subfield_data{marc_lib}=$tagslib->{$data->{'tag'}}->{$code->{'code'}}->{lib};
-                       
$subfield_data{link}=$tagslib->{$data->{'tag'}}->{$code->{'code'}}->{link};
-                       if 
($tagslib->{$data->{'tag'}}->{$code->{'code'}}->{isurl}) {
-                               $subfield_data{marc_value}="<a 
href=\"$value]\">$value</a>";
+                       
$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}=get_authorised_value_desc($data->{'tag'}, 
$code->{'code'}, $value, '', $dbh);
+                               $subfield_data{marc_value}=$subf[$i][1];
                        }
-                       $subfield_data{marc_subfield}=$code->{'code'};
-                       $subfield_data{marc_tag}=$data->{'tag'};
+            $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);
-                    }### $code
-               
-               
-               if ($#subfields_data>=0) {
-                       my %tag_data;
-                       if (($datatags{$i} eq $datatags{$i-1}) && 
(C4::Context->preference('LabelMARCView') eq 'economical')) {
-                               $tag_data{tag}="";
-                       } else {
-                               if (C4::Context->preference('hide_marc')) {
-                                       
$tag_data{tag}=$tagslib->{$data->{'tag'}}->{lib};
-                               } else {
-                                       $tag_data{tag}=$data->{'tag'}.' -'. 
$tagslib->{$data->{'tag'}}->{lib};
                                }
                        }
-                       my @tmp = @subfields_data;
-                       $tag_data{subfield} = address@hidden;
+       if ($#subfields_data>=0) {
+               my %tag_data;
+               $tag_data{tag}=$field->tag().' -'. 
$tagslib->{$field->tag()}->{lib};
+               $tag_data{subfield} = address@hidden;
                        push (@loop_data, \%tag_data);
-                       undef @subfields_data;
                }
-             }### each $subfield
-       }
-
-       $template->param($tabloop."XX" =>address@hidden);
 }
+$template->param("0XX" =>address@hidden);
+
 my $authtypes = getauthtypes;
 my @authtypesloop;
 foreach my $thisauthtype (keys %$authtypes) {
@@ -176,35 +177,12 @@
 
 $template->param(authid => $authid,
                                count => $count,
+               biblio_fields => $biblio_fields,
                                authtypetext => 
$authtypes->{$authtypecode}{'authtypetext'},
-                               authtypecode => 
$authtypes->{$authtypecode}{'authtypecode'},
-                               authtypesloop => address@hidden);
-$template->param(nonav =>$nonav);
-}### if $xmlash exist
+               authtypesloop => address@hidden,
+               intranetcolorstylesheet => 
C4::Context->preference("intranetcolorstylesheet"),
+               intranetstylesheet => 
C4::Context->preference("intranetstylesheet"),
+               IntranetNav => C4::Context->preference("IntranetNav"),
+               );
 output_html_with_http_headers $query, $cookie, $template->output;
 
-sub get_authorised_value_desc ($$$$$) {
-   my($tag, $subfield, $value, $framework, $dbh) = @_;
-
-   #---- branch
-    if ($tagslib->{$tag}->{$subfield}->{'authorised_value'} eq "branches" ) {
-       return getbranchname($value);
-    }
-
-   #---- itemtypes
-   if ($tagslib->{$tag}->{$subfield}->{'authorised_value'} eq "itemtypes" ) {
-       return ItemType($value);
-    }
-
-   #---- "true" authorized value
-   my $category = $tagslib->{$tag}->{$subfield}->{'authorised_value'};
-
-   if ($category ne "") {
-       my $sth = $dbh->prepare("select lib from authorised_values where 
category = ? and authorised_value = ?");
-       $sth->execute($category, $value);
-       my $data = $sth->fetchrow_hashref;
-       return $data->{'lib'};
-   } else {
-       return $value; # if nothing is found return the original value
-   }
-}
\ No newline at end of file




reply via email to

[Prev in Thread] Current Thread [Next in Thread]