#1444: Porting marcEditor to authorities (tab management)
[koha.git] / authorities / authorities.pl
1 #!/usr/bin/perl
2
3 # $Id$
4
5 # Copyright 2000-2002 Katipo Communications
6 #
7 # This file is part of Koha.
8 #
9 # Koha is free software; you can redistribute it and/or modify it under the
10 # terms of the GNU General Public License as published by the Free Software
11 # Foundation; either version 2 of the License, or (at your option) any later
12 # version.
13 #
14 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
15 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
16 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
17 #
18 # You should have received a copy of the GNU General Public License along with
19 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
20 # Suite 330, Boston, MA  02111-1307 USA
21
22 use strict;
23 use CGI;
24 use C4::Auth;
25 use C4::Output;
26 use C4::AuthoritiesMarc;
27 use C4::Context;
28 use C4::Koha; # XXX subfield_is_koha_internal_p
29 use Date::Calc qw(Today);
30 use MARC::File::USMARC;
31 use MARC::File::XML;
32 use C4::Biblio;
33 use vars qw( $tagslib);
34 use vars qw( $authorised_values_sth);
35 use vars qw( $is_a_modif );
36
37 my $itemtype; # created here because it can be used in build_authorized_values_list sub
38 our($authorised_values_sth,$is_a_modif,$usedTagsLib,$mandatory_z3950);
39 =item find_value
40
41     ($indicators, $value) = find_value($tag, $subfield, $record,$encoding);
42
43 Find the given $subfield in the given $tag in the given
44 MARC::Record $record.  If the subfield is found, returns
45 the (indicators, value) pair; otherwise, (undef, undef) is
46 returned.
47
48 =cut
49
50 sub find_value {
51         my ($tagfield,$insubfield,$record,$encoding) = @_;
52         my @result;
53         my $indicator;
54         if ($tagfield <10) {
55                 if ($record->field($tagfield)) {
56                         push @result, $record->field($tagfield)->data();
57                 } else {
58                         push @result,"";
59                 }
60         } else {
61                 foreach my $field ($record->field($tagfield)) {
62                         my @subfields = $field->subfields();
63                         foreach my $subfield (@subfields) {
64                                 if (@$subfield[0] eq $insubfield) {
65                                 push @result,@$subfield[1];
66                                                         $indicator = $field->indicator(1).$field->indicator(2);
67                                 }
68                         }
69                 }
70         }
71         return($indicator,@result);
72 }
73
74
75 =item build_authorized_values_list
76
77 =cut
78
79 sub build_authorized_values_list ($$$$$$$) {
80     my ( $tag, $subfield, $value, $dbh, $authorised_values_sth,$index_tag,$index_subfield ) = @_;
81
82     my @authorised_values;
83     my %authorised_lib;
84
85     # builds list, depending on authorised value...
86
87     #---- branch
88     if ( $tagslib->{$tag}->{$subfield}->{'authorised_value'} eq "branches" ) {
89         my $sth =
90           $dbh->prepare(
91             "select branchcode,branchname from branches order by branchname");
92         $sth->execute;
93         push @authorised_values, ""
94           unless ( $tagslib->{$tag}->{$subfield}->{mandatory} );
95
96         while ( my ( $branchcode, $branchname ) = $sth->fetchrow_array ) {
97             push @authorised_values, $branchcode;
98             $authorised_lib{$branchcode} = $branchname;
99         }
100
101         #----- itemtypes
102     }
103     elsif ( $tagslib->{$tag}->{$subfield}->{authorised_value} eq "itemtypes" ) {
104         my $sth =
105           $dbh->prepare(
106             "select itemtype,description from itemtypes order by description");
107         $sth->execute;
108         push @authorised_values, ""
109           unless ( $tagslib->{$tag}->{$subfield}->{mandatory} );
110           
111         my $itemtype;
112         
113         while ( my ( $itemtype, $description ) = $sth->fetchrow_array ) {
114             push @authorised_values, $itemtype;
115             $authorised_lib{$itemtype} = $description;
116         }
117         $value = $itemtype unless ($value);
118
119         #---- "true" authorised value
120     }
121     else {
122         $authorised_values_sth->execute(
123             $tagslib->{$tag}->{$subfield}->{authorised_value} );
124
125         push @authorised_values, ""
126           unless ( $tagslib->{$tag}->{$subfield}->{mandatory} );
127
128         while ( my ( $value, $lib ) = $authorised_values_sth->fetchrow_array ) {
129             push @authorised_values, $value;
130             $authorised_lib{$value} = $lib;
131         }
132     }
133     return CGI::scrolling_list(
134         -name     => "tag_".$tag."_subfield_".$subfield."_".$index_tag."_".$index_subfield,
135         -values   => \@authorised_values,
136         -default  => $value,
137         -labels   => \%authorised_lib,
138         -override => 1,
139         -size     => 1,
140         -multiple => 0,
141         -tabindex => 1,
142         -id       => "tag_".$tag."_subfield_".$subfield."_".$index_tag."_".$index_subfield,
143         -class    => "input_marceditor",
144     );
145 }
146
147
148 =item create_input
149  builds the <input ...> entry for a subfield.
150 =cut
151
152 sub create_input {
153     my ( $tag, $subfield, $value, $index_tag, $tabloop, $rec, $authorised_values_sth,$cgi ) = @_;
154     
155     my $index_subfield = CreateKey(); # create a specifique key for each subfield
156
157     $value =~ s/"/&quot;/g;
158
159     # if there is no value provided but a default value in parameters, get it
160     unless ($value) {
161         $value = $tagslib->{$tag}->{$subfield}->{defaultvalue};
162
163         # get today date & replace YYYY, MM, DD if provided in the default value
164         my ( $year, $month, $day ) = Today();
165         $month = sprintf( "%02d", $month );
166         $day   = sprintf( "%02d", $day );
167         $value =~ s/YYYY/$year/g;
168         $value =~ s/MM/$month/g;
169         $value =~ s/DD/$day/g;
170     }
171     my $dbh = C4::Context->dbh;
172     my %subfield_data = (
173         tag        => $tag,
174         subfield   => $subfield,
175         marc_lib   => substr( $tagslib->{$tag}->{$subfield}->{lib}, 0, 22 ),
176         marc_lib_plain => $tagslib->{$tag}->{$subfield}->{lib}, 
177         tag_mandatory  => $tagslib->{$tag}->{mandatory},
178         mandatory      => $tagslib->{$tag}->{$subfield}->{mandatory},
179         repeatable     => $tagslib->{$tag}->{$subfield}->{repeatable},
180         kohafield      => $tagslib->{$tag}->{$subfield}->{kohafield},
181         index          => $index_tag,
182         id             => "tag_".$tag."_subfield_".$subfield."_".$index_tag."_".$index_subfield,
183         value          => $value,
184     );
185     if($subfield eq '@'){
186         $subfield_data{id} = "tag_".$tag."_subfield_00_".$index_tag."_".$index_subfield;
187     } else {
188          $subfield_data{id} = "tag_".$tag."_subfield_".$subfield."_".$index_tag."_".$index_subfield;
189     }
190
191     if(exists $mandatory_z3950->{$tag.$subfield}){
192         $subfield_data{z3950_mandatory} = $mandatory_z3950->{$tag.$subfield};
193     }
194     
195     $subfield_data{visibility} = "display:none;"
196         if (    ($tagslib->{$tag}->{$subfield}->{hidden} % 2 == 1) and $value ne ''
197             or ($value eq '' and !$tagslib->{$tag}->{$subfield}->{mandatory})
198         );
199     
200     # it's an authorised field
201     if ( $tagslib->{$tag}->{$subfield}->{authorised_value} ) {
202         $subfield_data{marc_value} =
203           build_authorized_values_list( $tag, $subfield, $value, $dbh,
204             $authorised_values_sth,$index_tag,$index_subfield );
205
206     # it's a thesaurus / authority field
207     }
208     elsif ( $tagslib->{$tag}->{$subfield}->{authtypecode} ) {
209         $subfield_data{marc_value} =
210     "<input type=\"text\"
211                         id=\"".$subfield_data{id}."\"
212                         name=\"".$subfield_data{id}."\"
213       value=\"$value\"
214       class=\"input_marceditor\"
215                         tabindex=\"1\"                     
216       DISABLE READONLY \/>
217       <span class=\"buttonDot\"
218         onclick=\"Dopop('/cgi-bin/koha/authorities/auth_finder.pl?authtypecode=".$tagslib->{$tag}->{$subfield}->{authtypecode}."&index=$subfield_data{id}','$subfield_data{id}')\">...</span>
219     ";
220     # it's a plugin field
221     }
222     elsif ( $tagslib->{$tag}->{$subfield}->{'value_builder'} ) {
223
224         # opening plugin. Just check wether we are on a developper computer on a production one
225         # (the cgidir differs)
226         my $cgidir = C4::Context->intranetdir . "/cgi-bin/cataloguing/value_builder";
227         unless ( opendir( DIR, "$cgidir" ) ) {
228             $cgidir = C4::Context->intranetdir . "/cataloguing/value_builder";
229         }
230         my $plugin = $cgidir . "/" . $tagslib->{$tag}->{$subfield}->{'value_builder'};
231         do $plugin || die "Plugin Failed: ".$plugin;
232         my $extended_param = plugin_parameters( $dbh, $rec, $tagslib, $subfield_data{id}, $tabloop );
233         my ( $function_name, $javascript ) = plugin_javascript( $dbh, $rec, $tagslib, $subfield_data{id}, $tabloop );
234 #         my ( $function_name, $javascript,$extended_param );
235         
236         $subfield_data{marc_value} =
237     "<input tabindex=\"1\"
238                         type=\"text\"
239                         id=".$subfield_data{id}."
240       name=".$subfield_data{id}."
241       value=\"$value\"
242                         class=\"input_marceditor\"
243       onfocus=\"javascript:Focus$function_name($index_tag)\"
244       onblur=\"javascript:Blur$function_name($index_tag); \" \/>
245     <span class=\"buttonDot\"
246       onclick=\"Clic$function_name('$subfield_data{id}')\">...</a>
247     $javascript";
248         # it's an hidden field
249     }
250     elsif ( $tag eq '' ) {
251         $subfield_data{marc_value} =
252             "<input tabindex=\"1\"
253                     type=\"hidden\"
254                     id=".$subfield_data{id}."
255                     name=".$subfield_data{id}."
256                     value=\"$value\" \/>
257             ";
258     }
259     elsif ( $tagslib->{$tag}->{$subfield}->{'hidden'} ) {
260         $subfield_data{marc_value} =
261             "<input type=\"text\"
262                     id=".$subfield_data{id}."
263                     name=".$subfield_data{id}."
264                     class=\"input_marceditor\"
265                     tabindex=\"1\"
266                     value=\"$value\"
267             \/>";
268
269         # it's a standard field
270     }
271     else {
272         if (
273             length($value) > 100
274             or
275             ( C4::Context->preference("marcflavour") eq "UNIMARC" && $tag >= 300
276                 and $tag < 400 && $subfield eq 'a' )
277             or (    $tag >= 500
278                 and $tag < 600
279                 && C4::Context->preference("marcflavour") eq "MARC21" )
280           )
281         {
282             $subfield_data{marc_value} =
283                 "<textarea cols=\"70\"
284                            rows=\"4\"
285                            id=".$subfield_data{id}."
286                            name=".$subfield_data{id}."
287                            class=\"input_marceditor\"
288                            tabindex=\"1\"
289                            >$value</textarea>
290                 ";
291         }
292         else {
293             $subfield_data{marc_value} =
294                 "<input type=\"text\"
295                         id=".$subfield_data{id}."
296                         name=".$subfield_data{id}."
297                         value=\"$value\"
298                         tabindex=\"1\"
299                         class=\"input_marceditor\"
300                 \/>
301                 ";
302         }
303     }
304     $subfield_data{'index_subfield'} = $index_subfield;
305     return \%subfield_data;
306 }
307
308 =item CreateKey
309
310     Create a random value to set it into the input name
311
312 =cut
313
314 sub CreateKey(){
315     return int(rand(1000000));
316 }
317
318 sub build_tabs ($$$$$) {
319     my ( $template, $record, $dbh, $encoding,$input ) = @_;
320
321     # fill arrays
322     my @loop_data = ();
323     my $tag;
324
325     my $authorised_values_sth = $dbh->prepare(
326         "select authorised_value,lib
327         from authorised_values
328         where category=? order by lib"
329     );
330     
331     # in this array, we will push all the 10 tabs
332     # to avoid having 10 tabs in the template : they will all be in the same BIG_LOOP
333     my @BIG_LOOP;
334     my %seen;
335     my @tab_data; # all tags to display
336     
337     foreach my $used ( keys %$tagslib ){
338         push @tab_data,$used if not $seen{$used};
339         $seen{$used}++;
340     }
341         
342     my $max_num_tab=9;
343     # loop through each tab 0 through 9
344     for ( my $tabloop = 0 ; $tabloop <= $max_num_tab ; $tabloop++ ) {
345         my @loop_data = (); #innerloop in the template.
346         my $i = 0;
347         foreach my $tag (@tab_data) {
348             $i++;
349             next if ! $tag;
350             my $indicator;
351             my $index_tag = CreateKey;
352
353             # if MARC::Record is not empty =>use it as master loop, then add missing subfields that should be in the tab.
354             # if MARC::Record is empty => use tab as master loop.
355             if ( $record ne -1 && ( $record->field($tag) || $tag eq '000' ) ) {
356                 my @fields;
357     if ( $tag ne '000' ) {
358                     @fields = $record->field($tag);
359     }
360     else {
361        push @fields, $record->leader(); # if tag == 000
362     }
363     # loop through each field
364                 foreach my $field (@fields) {
365                     
366                     my @subfields_data;
367                     if ( $tag < 10 ) {
368                         my ( $value, $subfield );
369                         if ( $tag ne '000' ) {
370                             $value    = $field->data();
371                             $subfield = "@";
372                         }
373                         else {
374                             $value    = $field;
375                             $subfield = '@';
376                         }
377                         next if ( $tagslib->{$tag}->{$subfield}->{tab} ne $tabloop );
378                         next
379                           if ( $tagslib->{$tag}->{$subfield}->{kohafield} eq
380                             'biblio.biblionumber' );
381                         push(
382                             @subfields_data,
383                             &create_input(
384                                 $tag, $subfield, $value, $index_tag, $tabloop, $record,
385                                 $authorised_values_sth,$input
386                             )
387                         );
388                     }
389                     else {
390                         my @subfields = $field->subfields();
391                         foreach my $subfieldcount ( 0 .. $#subfields ) {
392                             my $subfield = $subfields[$subfieldcount][0];
393                             my $value    = $subfields[$subfieldcount][1];
394                             next if ( length $subfield != 1 );
395                             next if ( $tagslib->{$tag}->{$subfield}->{tab} ne $tabloop );
396                             push(
397                                 @subfields_data,
398                                 &create_input(
399                                     $tag, $subfield, $value, $index_tag, $tabloop,
400                                     $record, $authorised_values_sth,$input
401                                 )
402                             );
403                         }
404                     }
405
406                     # now, loop again to add parameter subfield that are not in the MARC::Record
407                     foreach my $subfield ( sort( keys %{ $tagslib->{$tag} } ) )
408                     {
409                         next if ( length $subfield != 1 );
410                         next if ( $tagslib->{$tag}->{$subfield}->{tab} ne $tabloop );
411                         next if ( $tag < 10 );
412                         next
413                           if ( ( $tagslib->{$tag}->{$subfield}->{hidden} <= -4 )
414                             or ( $tagslib->{$tag}->{$subfield}->{hidden} >= 5 )
415                           );    #check for visibility flag
416                         next if ( defined( $field->subfield($subfield) ) );
417                         push(
418                             @subfields_data,
419                             &create_input(
420                                 $tag, $subfield, '', $index_tag, $tabloop, $record,
421                                 $authorised_values_sth,$input
422                             )
423                         );
424                     }
425                     if ( $#subfields_data >= 0 ) {
426                         # build the tag entry.
427                         # note that the random() field is mandatory. Otherwise, on repeated fields, you'll 
428                         # have twice the same "name" value, and cgi->param() will return only one, making
429                         # all subfields to be merged in a single field.
430                         my %tag_data = (
431                             tag           => $tag,
432                             index         => $index_tag,
433                             tag_lib       => $tagslib->{$tag}->{lib},
434                             repeatable       => $tagslib->{$tag}->{repeatable},
435                             subfield_loop => \@subfields_data,
436                             fixedfield    => ($tag < 10)?(1):(0),
437                             random        => CreateKey,
438                         );
439                         if ($tag >= 010){ # no indicator for theses tag
440                            $tag_data{indicator} = $field->indicator(1).$field->indicator(2);
441                         }
442                         push( @loop_data, \%tag_data );
443                     }
444                  } # foreach $field end
445
446             # if breeding is empty
447             }
448             else {
449                 my @subfields_data;
450                 foreach my $subfield ( sort( keys %{ $tagslib->{$tag} } ) ) {
451                     next if ( length $subfield != 1 );
452                     next
453                       if ( ( $tagslib->{$tag}->{$subfield}->{hidden} <= -5 )
454                         or ( $tagslib->{$tag}->{$subfield}->{hidden} >= 4 ) )
455                       ;    #check for visibility flag
456                     next
457                       if ( $tagslib->{$tag}->{$subfield}->{tab} ne $tabloop );
458                     push(
459                         @subfields_data,
460                         &create_input(
461                             $tag, $subfield, '', $index_tag, $tabloop, $record,
462                             $authorised_values_sth,$input
463                         )
464                     );
465                 }
466                 if ( $#subfields_data >= 0 ) {
467                     my %tag_data = (
468                         tag              => $tag,
469                         index            => $index_tag,
470                         tag_lib          => $tagslib->{$tag}->{lib},
471                         repeatable       => $tagslib->{$tag}->{repeatable},
472                         indicator        => $indicator,
473                         subfield_loop    => \@subfields_data,
474                         tagfirstsubfield => $subfields_data[0],
475                         fixedfield       => ($tag < 10)?(1):(0)
476                     );
477                     
478                     push @loop_data, \%tag_data ;
479                 }
480             }
481         }
482         if ( $#loop_data >= 0 ) {
483             push @BIG_LOOP, {
484                 number    => $tabloop,
485                 innerloop => \@loop_data,
486             };
487         }
488     }
489     $template->param( singletab => (scalar(@BIG_LOOP)==1), BIG_LOOP => \@BIG_LOOP );
490 }
491
492
493 sub build_hidden_data () {
494     # build hidden data =>
495     # we store everything, even if we show only requested subfields.
496
497     my @loop_data =();
498     my $i=0;
499     foreach my $tag (keys %{$tagslib}) {
500         my $previous_tag = '';
501
502         # loop through each subfield
503         foreach my $subfield (keys %{$tagslib->{$tag}}) {
504             next if ($subfield eq 'lib');
505             next if ($subfield eq 'tab');
506             next if ($subfield eq 'mandatory');
507                 next if ($subfield eq 'repeatable');
508             next if ($tagslib->{$tag}->{$subfield}->{'tab'}  ne "-1");
509             my %subfield_data;
510             $subfield_data{marc_lib}=$tagslib->{$tag}->{$subfield}->{lib};
511             $subfield_data{marc_mandatory}=$tagslib->{$tag}->{$subfield}->{mandatory};
512             $subfield_data{marc_repeatable}=$tagslib->{$tag}->{$subfield}->{repeatable};
513             $subfield_data{marc_value}="<input type=\"hidden\" name=\"field_value[]\">";
514             push(@loop_data, \%subfield_data);
515             $i++
516         }
517     }
518 }
519
520 # ======================== 
521 #          MAIN 
522 #=========================
523 my $input = new CGI;
524 my $z3950 = $input->param('z3950');
525 my $error = $input->param('error');
526 my $authid=$input->param('authid'); # if authid exists, it's a modif, not a new authority.
527 my $op = $input->param('op');
528 my $nonav = $input->param('nonav');
529 my $myindex = $input->param('index');
530 my $linkid=$input->param('linkid');
531 my $authtypecode = $input->param('authtypecode');
532
533 my $dbh = C4::Context->dbh;
534 $authtypecode = &GetAuthTypeCode($authid) if !$authtypecode;
535
536 my ($template, $loggedinuser, $cookie)
537     = get_template_and_user({template_name => "authorities/authorities.tmpl",
538                              query => $input,
539                              type => "intranet",
540                              authnotrequired => 0,
541                              flagsrequired => {editauthorities => 1},
542                              debug => 1,
543                              });
544 $template->param(nonav   => $nonav,index=>$myindex,authtypecode=>$authtypecode,);
545 $tagslib = GetTagsLabels(1,$authtypecode);
546 my $record=-1;
547 my $encoding="";
548 $record = GetAuthority($authid) if ($authid);
549 my ($oldauthnumtagfield,$oldauthnumtagsubfield);
550 my ($oldauthtypetagfield,$oldauthtypetagsubfield);
551 $is_a_modif=0;
552 if ($authid) {
553   $is_a_modif=1;
554   ($oldauthnumtagfield,$oldauthnumtagsubfield) = &GetAuthMARCFromKohaField("auth_header.authid",$authtypecode);
555   ($oldauthtypetagfield,$oldauthtypetagsubfield) = &GetAuthMARCFromKohaField("auth_header.authtypecode",$authtypecode);
556 }
557
558 #------------------------------------------------------------------------------------------------------------------------------
559 if ($op eq "add") {
560 #------------------------------------------------------------------------------------------------------------------------------
561         # rebuild
562         my @tags = $input->param('tag');
563         my @subfields = $input->param('subfield');
564         my @values = $input->param('field_value');
565         # build indicator hash.
566         my @ind_tag = $input->param('ind_tag');
567         my @indicator = $input->param('indicator');
568   my @params = $input->param();
569   my $record = TransformHtmlToMarc(\@params,$input);
570   if  (C4::Context->preference("marcflavour") eq "UNIMARC"){
571     unless ($record->field('100')){
572       use POSIX qw(strftime);
573       my $string = strftime( "%Y%m%d", localtime(time) );
574       # set 50 to position 26 is biblios, 13 if authorities
575       my $pos=13;
576       $string = sprintf( "%-*s", 35, $string );
577       substr( $string, $pos , 2, "50" );
578       $record->append_fields(MARC::Field->new('100','','',"a"=>$string));
579     }    
580   }
581     
582 #   warn $record->as_formatted;  
583 #       my $record=MARC::Record->new_from_xml($xml,'UTF-8',(C4::Context->preference("marcflavour") eq "UNIMARC"?"UNIMARCAUTH":C4::Context->preference("marcflavour")));
584 #       $record->encoding('UTF-8');
585         #warn $record->as_formatted;
586         # check for a duplicate
587         my ($duplicateauthid,$duplicateauthvalue) = FindDuplicateAuthority($record,$authtypecode) if ($op eq "add") && (!$is_a_modif);
588         my $confirm_not_duplicate = $input->param('confirm_not_duplicate');
589 # it is not a duplicate (determined either by Koha itself or by user checking it's not a duplicate)
590         if (!$duplicateauthid or $confirm_not_duplicate) {
591 # warn "noduplicate";
592           if ($is_a_modif ) {   
593             ModAuthority($authid,$record,$authtypecode,1);
594           } else {
595             ($authid) = AddAuthority($record,$authid,$authtypecode);
596           }
597           print $input->redirect("detail.pl?authid=$authid");
598           exit;
599         } else {
600         # it may be a duplicate, warn the user and do nothing
601             build_tabs($template, $record, $dbh, $encoding,$input);
602             build_hidden_data;
603             $template->param(authid =>$authid,
604                             duplicateauthid     => $duplicateauthid,
605                             duplicateauthvalue  => $duplicateauthvalue,
606                             );
607         }
608 # #------------------------------------------------------------------------------------------------------------------------------
609 # } elsif ($op eq "addfield") {
610 # #------------------------------------------------------------------------------------------------------------------------------
611 #       my $addedfield = $input->param('addfield_field');
612 #       my $tagaddfield_subfield = $input->param('addfield_subfield');
613 #       my @tags = $input->param('tag');
614 #       my @subfields = $input->param('subfield');
615 #       my @values = $input->param('field_value');
616 #       # build indicator hash.
617 #       my @ind_tag = $input->param('ind_tag');
618 #       my @indicator = $input->param('indicator');
619 #       my $xml = TransformHtmlToXml(\@tags,\@subfields,\@values,\@indicator,\@ind_tag);
620 #       my $record=MARC::Record->new_from_xml($xml,'UTF-8');
621 #       $record->encoding('UTF-8');
622 #       # adding an empty field
623 #       my $field = MARC::Field->new("$addedfield",'','','$tagaddfield_subfield' => "");
624 #       $record->append_fields($field);
625 #       build_tabs ($template, $record, $dbh,$encoding,$input);
626 #       build_hidden_data;
627 #       $template->param(
628 #               authid => $authid,);
629
630 } elsif ($op eq "delete") {
631 #------------------------------------------------------------------------------------------------------------------------------
632         &AUTHdelauthority($authid);
633         if ($nonav){
634         print $input->redirect("auth_finder.pl");
635         }else{
636         print $input->redirect("authorities-home.pl?authid=0");
637         }
638                 exit;
639 } else {
640 if ($op eq "duplicate")
641         {
642                 $authid = "";
643         }
644         build_tabs ($template, $record, $dbh,$encoding,$input);
645         build_hidden_data;
646         $template->param(oldauthtypetagfield=>$oldauthtypetagfield, oldauthtypetagsubfield=>$oldauthtypetagsubfield,
647                 oldauthnumtagfield=>$oldauthnumtagfield, oldauthnumtagsubfield=>$oldauthnumtagsubfield,
648                 authid                      => $authid , authtypecode=>$authtypecode,   );
649 }
650
651 $template->param(
652         authid                       => $authid,
653         authtypecode => $authtypecode,
654         linkid=>$linkid,
655         );
656
657 my $authtypes = getauthtypes;
658 my @authtypesloop;
659 foreach my $thisauthtype (keys %$authtypes) {
660         my $selected = 1 if $thisauthtype eq $authtypecode;
661         my %row =(value => $thisauthtype,
662                                 selected => $selected,
663                                 authtypetext => $authtypes->{$thisauthtype}{'authtypetext'},
664                         );
665         push @authtypesloop, \%row;
666 }
667
668 $template->param(authtypesloop => \@authtypesloop,
669                                 authtypetext => $authtypes->{$authtypecode}{'authtypetext'},
670                                 hide_marc => C4::Context->preference('hide_marc'),
671                                 intranetcolorstylesheet => C4::Context->preference("intranetcolorstylesheet"),
672                 intranetstylesheet => C4::Context->preference("intranetstylesheet"),
673                 IntranetNav => C4::Context->preference("IntranetNav"),
674                                 );
675 output_html_with_http_headers $input, $cookie, $template->output;