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