authorities: make tag editor links consistent with bib
[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 (-r $cgidir and -d $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                     <a href=\"#\" class=\"buttonDot\" onclick=\"Clic$function_name('$subfield_data{id}'); return false;\" title=\"Tag Editor\">...</a>
248                     $javascript";
249         # it's an hidden field
250     }
251     elsif ( $tag eq '' ) {
252         $subfield_data{marc_value} =
253             "<input tabindex=\"1\"
254                     type=\"hidden\"
255                     id=\"".$subfield_data{id}."\"
256                     name=\"".$subfield_data{id}."\"
257                     size=\"67\"
258                     maxlength=\"255\" 
259                     value=\"$value\" \/>
260             ";
261     }
262     elsif ( $tagslib->{$tag}->{$subfield}->{'hidden'} ) {
263         $subfield_data{marc_value} =
264             "<input type=\"text\"
265                     id=\"".$subfield_data{id}."\"
266                     name=\"".$subfield_data{id}."\"
267                     class=\"input_marceditor\"
268                     tabindex=\"1\"
269                     size=\"67\"
270                     maxlength=\"255\" 
271                     value=\"$value\"
272             \/>";
273
274         # it's a standard field
275     }
276     else {
277         if (
278             length($value) > 100
279             or
280             ( C4::Context->preference("marcflavour") eq "UNIMARC" && $tag >= 300
281                 and $tag < 400 && $subfield eq 'a' )
282             or (    $tag >= 500
283                 and $tag < 600
284                 && C4::Context->preference("marcflavour") eq "MARC21" )
285         )
286         {
287             $subfield_data{marc_value} =
288                 "<textarea cols=\"70\"
289                         rows=\"4\"
290                         id=\"".$subfield_data{id}."\"
291                         name=\"".$subfield_data{id}."\"
292                         class=\"input_marceditor\"
293                         tabindex=\"1\"
294                         size=\"67\"
295                         maxlength=\"255\" 
296                         >$value</textarea>
297                 ";
298         }
299         else {
300             $subfield_data{marc_value} =
301                 "<input type=\"text\"
302                         id=\"".$subfield_data{id}."\"
303                         name=\"".$subfield_data{id}."\"
304                         value=\"$value\"
305                         tabindex=\"1\"
306                         size=\"67\"
307                         maxlength=\"255\" 
308                         class=\"input_marceditor\"
309                 \/>
310                 ";
311         }
312     }
313     $subfield_data{'index_subfield'} = $index_subfield;
314     return \%subfield_data;
315 }
316
317 =item CreateKey
318
319     Create a random value to set it into the input name
320
321 =cut
322
323 sub CreateKey(){
324     return int(rand(1000000));
325 }
326
327 sub build_tabs ($$$$$) {
328     my ( $template, $record, $dbh, $encoding,$input ) = @_;
329
330     # fill arrays
331     my @loop_data = ();
332     my $tag;
333
334     my $authorised_values_sth = $dbh->prepare(
335         "SELECT authorised_value,lib
336         FROM authorised_values
337         WHERE category=? ORDER BY lib"
338     );
339     
340     # in this array, we will push all the 10 tabs
341     # to avoid having 10 tabs in the template : they will all be in the same BIG_LOOP
342     my @BIG_LOOP;
343     my %seen;
344     my @tab_data; # all tags to display
345     
346     foreach my $used ( keys %$tagslib ){
347         push @tab_data,$used if not $seen{$used};
348         $seen{$used}++;
349     }
350         
351     my $max_num_tab=9;
352     # loop through each tab 0 through 9
353     for ( my $tabloop = 0 ; $tabloop <= $max_num_tab ; $tabloop++ ) {
354         my @loop_data = (); #innerloop in the template.
355         my $i = 0;
356         foreach my $tag (sort @tab_data) {
357             $i++;
358             next if ! $tag;
359             my $indicator;
360             my $index_tag = CreateKey;
361
362             # if MARC::Record is not empty =>use it as master loop, then add missing subfields that should be in the tab.
363             # if MARC::Record is empty => use tab as master loop.
364             if ( $record ne -1 && ( $record->field($tag) || $tag eq '000' ) ) {
365                 my @fields;
366                 if ( $tag ne '000' ) {
367                                 @fields = $record->field($tag);
368                 }
369                 else {
370                 push @fields, $record->leader(); # if tag == 000
371                 }
372                 # loop through each field
373                 foreach my $field (@fields) {
374                     
375                     my @subfields_data;
376                     if ( $tag < 10 ) {
377                         my ( $value, $subfield );
378                         if ( $tag ne '000' ) {
379                             $value    = $field->data();
380                             $subfield = "@";
381                         }
382                         else {
383                             $value    = $field;
384                             $subfield = '@';
385                         }
386                         next if ( $tagslib->{$tag}->{$subfield}->{tab} ne $tabloop );
387                         push(
388                             @subfields_data,
389                             &create_input(
390                                 $tag, $subfield, $value, $index_tag, $tabloop, $record,
391                                 $authorised_values_sth,$input
392                             )
393                         );
394                     }
395                     else {
396                         my @subfields = $field->subfields();
397                         foreach my $subfieldcount ( 0 .. $#subfields ) {
398                             my $subfield = $subfields[$subfieldcount][0];
399                             my $value    = $subfields[$subfieldcount][1];
400                             next if ( length $subfield != 1 );
401                             next if ( $tagslib->{$tag}->{$subfield}->{tab} ne $tabloop );
402                             push(
403                                 @subfields_data,
404                                 &create_input(
405                                     $tag, $subfield, $value, $index_tag, $tabloop,
406                                     $record, $authorised_values_sth,$input
407                                 )
408                             );
409                         }
410                     }
411
412                     # now, loop again to add parameter subfield that are not in the MARC::Record
413                     foreach my $subfield ( sort( keys %{ $tagslib->{$tag} } ) )
414                     {
415                         next if ( length $subfield != 1 );
416                         next if ( $tagslib->{$tag}->{$subfield}->{tab} ne $tabloop );
417                         next if ( $tag < 10 );
418                         next
419                         if ( ( $tagslib->{$tag}->{$subfield}->{hidden} <= -4 )
420                             or ( $tagslib->{$tag}->{$subfield}->{hidden} >= 5 )
421                         );    #check for visibility flag
422                         next if ( defined( $field->subfield($subfield) ) );
423                         push(
424                             @subfields_data,
425                             &create_input(
426                                 $tag, $subfield, '', $index_tag, $tabloop, $record,
427                                 $authorised_values_sth,$input
428                             )
429                         );
430                     }
431                     if ( $#subfields_data >= 0 ) {
432                         # build the tag entry.
433                         # note that the random() field is mandatory. Otherwise, on repeated fields, you'll 
434                         # have twice the same "name" value, and cgi->param() will return only one, making
435                         # all subfields to be merged in a single field.
436                         my %tag_data = (
437                             tag           => $tag,
438                             index         => $index_tag,
439                             tag_lib       => $tagslib->{$tag}->{lib},
440                             repeatable       => $tagslib->{$tag}->{repeatable},
441                             subfield_loop => \@subfields_data,
442                             fixedfield    => ($tag < 10)?(1):(0),
443                             random        => CreateKey,
444                         );
445                         if ($tag >= 010){ # no indicator for theses tag
446                         $tag_data{indicator} = $field->indicator(1).$field->indicator(2);
447                         }
448                         push( @loop_data, \%tag_data );
449                     }
450                 } # foreach $field end
451
452             # if breeding is empty
453             }
454             else {
455                 my @subfields_data;
456                 foreach my $subfield ( sort( keys %{ $tagslib->{$tag} } ) ) {
457                     next if ( length $subfield != 1 );
458                     next if ( ( $tagslib->{$tag}->{$subfield}->{hidden} <= -5 )
459                                 or ( $tagslib->{$tag}->{$subfield}->{hidden} >= 4 ) )
460                             ;    #check for visibility flag
461                     next if ( $tagslib->{$tag}->{$subfield}->{tab} ne $tabloop );
462                     push(
463                         @subfields_data,
464                         &create_input(
465                             $tag, $subfield, '', $index_tag, $tabloop, $record,
466                             $authorised_values_sth,$input
467                         )
468                     );
469                 }
470                 if ( $#subfields_data >= 0 ) {
471                     my %tag_data = (
472                         tag              => $tag,
473                         index            => $index_tag,
474                         tag_lib          => $tagslib->{$tag}->{lib},
475                         repeatable       => $tagslib->{$tag}->{repeatable},
476                         indicator        => $indicator,
477                         subfield_loop    => \@subfields_data,
478                         tagfirstsubfield => $subfields_data[0],
479                         fixedfield       => ($tag < 10)?(1):(0)
480                     );
481                     
482                     push @loop_data, \%tag_data ;
483                 }
484             }
485         }
486         if ( $#loop_data >= 0 ) {
487             push @BIG_LOOP, {
488                 number    => $tabloop,
489                 innerloop => \@loop_data,
490             };
491         }
492     }
493     $template->param( BIG_LOOP => \@BIG_LOOP );
494 }
495
496
497 sub build_hidden_data () {
498     # build hidden data =>
499     # we store everything, even if we show only requested subfields.
500
501     my @loop_data =();
502     my $i=0;
503     foreach my $tag (keys %{$tagslib}) {
504         my $previous_tag = '';
505
506         # loop through each subfield
507         foreach my $subfield (keys %{$tagslib->{$tag}}) {
508             next if ($subfield eq 'lib');
509             next if ($subfield eq 'tab');
510             next if ($subfield eq 'mandatory');
511                 next if ($subfield eq 'repeatable');
512             next if ($tagslib->{$tag}->{$subfield}->{'tab'}  ne "-1");
513             my %subfield_data;
514             $subfield_data{marc_lib}=$tagslib->{$tag}->{$subfield}->{lib};
515             $subfield_data{marc_mandatory}=$tagslib->{$tag}->{$subfield}->{mandatory};
516             $subfield_data{marc_repeatable}=$tagslib->{$tag}->{$subfield}->{repeatable};
517             $subfield_data{marc_value}="<input type=\"hidden\" name=\"field_value[]\">";
518             push(@loop_data, \%subfield_data);
519             $i++
520         }
521     }
522 }
523
524 # ======================== 
525 #          MAIN 
526 #=========================
527 my $input = new CGI;
528 my $z3950 = $input->param('z3950');
529 my $error = $input->param('error');
530 my $authid=$input->param('authid'); # if authid exists, it's a modif, not a new authority.
531 my $op = $input->param('op');
532 my $nonav = $input->param('nonav');
533 my $myindex = $input->param('index');
534 my $linkid=$input->param('linkid');
535 my $authtypecode = $input->param('authtypecode');
536
537 my $dbh = C4::Context->dbh;
538 $authtypecode = &GetAuthTypeCode($authid) if !$authtypecode;
539
540 my ($template, $loggedinuser, $cookie)
541     = get_template_and_user({template_name => "authorities/authorities.tmpl",
542                             query => $input,
543                             type => "intranet",
544                             authnotrequired => 0,
545                             flagsrequired => {editauthorities => 1},
546                             debug => 1,
547                             });
548 $template->param(nonav   => $nonav,index=>$myindex,authtypecode=>$authtypecode,);
549 $tagslib = GetTagsLabels(1,$authtypecode);
550 my $record=-1;
551 my $encoding="";
552 $record = GetAuthority($authid) if ($authid);
553 my ($oldauthnumtagfield,$oldauthnumtagsubfield);
554 my ($oldauthtypetagfield,$oldauthtypetagsubfield);
555 $is_a_modif=0;
556 if ($authid) {
557     $is_a_modif=1;
558     ($oldauthnumtagfield,$oldauthnumtagsubfield) = &GetAuthMARCFromKohaField("auth_header.authid",$authtypecode);
559     ($oldauthtypetagfield,$oldauthtypetagsubfield) = &GetAuthMARCFromKohaField("auth_header.authtypecode",$authtypecode);
560 }
561
562 #------------------------------------------------------------------------------------------------------------------------------
563 if ($op eq "add") {
564 #------------------------------------------------------------------------------------------------------------------------------
565     # rebuild
566     my @tags = $input->param('tag');
567     my @subfields = $input->param('subfield');
568     my @values = $input->param('field_value');
569     # build indicator hash.
570     my @ind_tag = $input->param('ind_tag');
571     my @indicator = $input->param('indicator');
572     my @params = $input->param();
573     my $record = TransformHtmlToMarc(\@params,$input);
574     if  (C4::Context->preference("marcflavour") eq "UNIMARC"){
575         unless ($record->field('100')){
576         use POSIX qw(strftime);
577         my $string = strftime( "%Y%m%d", localtime(time) );
578         # set 50 to position 26 is biblios, 13 if authorities
579         my $pos=13;
580         $string = sprintf( "%-*s", 35, $string );
581         substr( $string, $pos , 2, "50" );
582         $record->append_fields(MARC::Field->new('100','','',"a"=>$string));
583         }    
584     }
585
586     my ($duplicateauthid,$duplicateauthvalue) = FindDuplicateAuthority($record,$authtypecode) if ($op eq "add") && (!$is_a_modif);
587     my $confirm_not_duplicate = $input->param('confirm_not_duplicate');
588     # it is not a duplicate (determined either by Koha itself or by user checking it's not a duplicate)
589     if (!$duplicateauthid or $confirm_not_duplicate) {
590         if ($is_a_modif ) {     
591             ModAuthority($authid,$record,$authtypecode,1);
592         } else {
593             ($authid) = AddAuthority($record,$authid,$authtypecode);
594         }
595         print $input->redirect("detail.pl?authid=$authid");
596         exit;
597     } else {
598     # it may be a duplicate, warn the user and do nothing
599         build_tabs($template, $record, $dbh, $encoding,$input);
600         build_hidden_data;
601         $template->param(authid =>$authid,
602                         duplicateauthid     => $duplicateauthid,
603                         duplicateauthvalue  => $duplicateauthvalue,
604                         );
605     }
606 } elsif ($op eq "delete") {
607 #------------------------------------------------------------------------------------------------------------------------------
608         &AUTHdelauthority($authid);
609         if ($nonav){
610             print $input->redirect("auth_finder.pl");
611         }else{
612             print $input->redirect("authorities-home.pl?authid=0");
613         }
614                 exit;
615 } else {
616 if ($op eq "duplicate")
617         {
618                 $authid = "";
619         }
620         build_tabs ($template, $record, $dbh,$encoding,$input);
621         build_hidden_data;
622         $template->param(oldauthtypetagfield=>$oldauthtypetagfield, oldauthtypetagsubfield=>$oldauthtypetagsubfield,
623                         oldauthnumtagfield=>$oldauthnumtagfield, oldauthnumtagsubfield=>$oldauthnumtagsubfield,
624                         authid                      => $authid , authtypecode=>$authtypecode,   );
625 }
626
627 $template->param(authid                       => $authid,
628                  authtypecode => $authtypecode,
629                  linkid=>$linkid,
630 );
631
632 my $authtypes = getauthtypes;
633 my @authtypesloop;
634 foreach my $thisauthtype (keys %$authtypes) {
635     my $selected = 1 if $thisauthtype eq $authtypecode;
636     my %row =(value => $thisauthtype,
637                 selected => $selected,
638                 authtypetext => $authtypes->{$thisauthtype}{'authtypetext'},
639             );
640     push @authtypesloop, \%row;
641 }
642
643 $template->param(authtypesloop => \@authtypesloop,
644                 authtypetext => $authtypes->{$authtypecode}{'authtypetext'},
645                 hide_marc => C4::Context->preference('hide_marc'),
646                 );
647 output_html_with_http_headers $input, $cookie, $template->output;