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