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