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