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