Bug 19537: (QA follow-up) Consistent structures
[koha.git] / authorities / authorities.pl
index 8357e2d..84fba09 100755 (executable)
@@ -26,11 +26,13 @@ use C4::Output;
 use C4::AuthoritiesMarc;
 use C4::ImportBatch; #GetImportRecordMarc
 use C4::Context;
-use C4::Koha; # XXX subfield_is_koha_internal_p
+use C4::Koha;
 use Date::Calc qw(Today);
 use MARC::File::USMARC;
 use MARC::File::XML;
 use C4::Biblio;
+use Koha::Authority::Types;
+use Koha::ItemTypes;
 use vars qw( $tagslib);
 use vars qw( $authorised_values_sth);
 use vars qw( $is_a_modif );
@@ -83,23 +85,17 @@ sub build_authorized_values_list {
             push @authorised_values, $branchcode;
             $authorised_lib{$branchcode} = $branchname;
         }
-
-        #----- itemtypes
     }
     elsif ( $tagslib->{$tag}->{$subfield}->{authorised_value} eq "itemtypes" ) {
-        my $sth =
-        $dbh->prepare(
-            "select itemtype,description from itemtypes order by description");
-        $sth->execute;
         push @authorised_values, ""
           unless ( $tagslib->{$tag}->{$subfield}->{mandatory}
             && ( $value || $tagslib->{$tag}->{$subfield}->{defaultvalue} ) );
-        
+
         my $itemtype;
-        
-        while ( my ( $itemtype, $description ) = $sth->fetchrow_array ) {
-            push @authorised_values, $itemtype;
-            $authorised_lib{$itemtype} = $description;
+        my $itemtypes = Koha::ItemTypes->search_with_localization;
+        while ( $itemtype = $itemtypes->next ) {
+            push @authorised_values, $itemtype->itemtype;
+            $authorised_lib{$itemtype->itemtype} = $itemtype->translated_description;
         }
         $value = $itemtype unless ($value);
 
@@ -175,8 +171,7 @@ sub create_input {
     my %subfield_data = (
         tag        => $tag,
         subfield   => $id_subfield,
-        marc_lib   => substr( $tagslib->{$tag}->{$subfield}->{lib}, 0, 22 ),
-        marc_lib_plain => $tagslib->{$tag}->{$subfield}->{lib}, 
+        marc_lib       => $tagslib->{$tag}->{$subfield}->{lib},
         tag_mandatory  => $tagslib->{$tag}->{mandatory},
         mandatory      => $tagslib->{$tag}->{$subfield}->{mandatory},
         repeatable     => $tagslib->{$tag}->{$subfield}->{repeatable},
@@ -325,7 +320,7 @@ sub CreateKey {
 
 =item GetMandatoryFieldZ3950
 
-    This function return an hashref which containts all mandatory field
+    This function returns a hashref which contains all mandatory field
     to search with z3950 server.
 
 =cut
@@ -409,6 +404,7 @@ sub build_tabs {
                             $subfield = '@';
                         }
                         next if ( $tagslib->{$tag}->{$subfield}->{tab} ne $tabloop );
+                        next if $tagslib->{$tag}->{$subfield}->{hidden};
                         push(
                             @subfields_data,
                             &create_input(
@@ -424,6 +420,7 @@ sub build_tabs {
                             my $value    = $subfields[$subfieldcount][1];
                             next if ( length $subfield != 1 );
                             next if ( $tagslib->{$tag}->{$subfield}->{tab} ne $tabloop );
+                            next if $tagslib->{$tag}->{$subfield}->{hidden};
                             push(
                                 @subfields_data,
                                 &create_input(
@@ -440,10 +437,7 @@ sub build_tabs {
                         next if ( length $subfield != 1 );
                         next if ( $tagslib->{$tag}->{$subfield}->{tab} ne $tabloop );
                         next if ( $tag < 10 );
-                        next
-                        if ( ( $tagslib->{$tag}->{$subfield}->{hidden} <= -4 )
-                            or ( $tagslib->{$tag}->{$subfield}->{hidden} >= 5 )
-                        );    #check for visibility flag
+                        next if $tagslib->{$tag}->{$subfield}->{hidden};
                         next if ( defined( $field->subfield($subfield) ) );
                         push(
                             @subfields_data,
@@ -482,9 +476,7 @@ sub build_tabs {
                 my @subfields_data;
                 foreach my $subfield ( sort( keys %{ $tagslib->{$tag} } ) ) {
                     next if ( length $subfield != 1 );
-                    next if ( ( $tagslib->{$tag}->{$subfield}->{hidden} <= -5 )
-                                or ( $tagslib->{$tag}->{$subfield}->{hidden} >= 4 ) )
-                            ;    #check for visibility flag
+                    next if $tagslib->{$tag}->{$subfield}->{hidden};
                     next if ( $tagslib->{$tag}->{$subfield}->{tab} ne $tabloop );
                     push(
                         @subfields_data,
@@ -574,7 +566,7 @@ my $breedingid    = $input->param('breedingid');
 
 my $dbh = C4::Context->dbh;
 if(!$authtypecode) {
-  $authtypecode = $authid? &GetAuthTypeCode($authid): '';
+    $authtypecode = $authid ? Koha::Authorities->find($authid)->authtypecode : '';
 }
 
 my ($template, $loggedinuser, $cookie)
@@ -612,13 +604,13 @@ $op ||= q{};
 if ($op eq "add") {
 #------------------------------------------------------------------------------------------------------------------------------
     # rebuild
-    my @tags = $input->param('tag');
-    my @subfields = $input->param('subfield');
-    my @values = $input->param('field_value');
+    my @tags = $input->multi_param('tag');
+    my @subfields = $input->multi_param('subfield');
+    my @values = $input->multi_param('field_value');
     # build indicator hash.
-    my @ind_tag = $input->param('ind_tag');
-    my @indicator = $input->param('indicator');
-    my $record = TransformHtmlToMarc($input);
+    my @ind_tag = $input->multi_param('ind_tag');
+    my @indicator = $input->multi_param('indicator');
+    my $record = TransformHtmlToMarc($input, 0);
 
     my ($duplicateauthid,$duplicateauthvalue);
      ($duplicateauthid,$duplicateauthvalue) = FindDuplicateAuthority($record,$authtypecode) if ($op eq "add") && (!$is_a_modif);
@@ -647,7 +639,7 @@ if ($op eq "add") {
     }
 } elsif ($op eq "delete") {
 #------------------------------------------------------------------------------------------------------------------------------
-        &DelAuthority($authid);
+        DelAuthority({ authid => $authid });
         if ($nonav){
             print $input->redirect("auth_finder.pl");
         }else{
@@ -666,23 +658,15 @@ if ($op eq "duplicate")
                         authid                      => $authid , authtypecode=>$authtypecode,  );
 }
 
-$template->param(authid                       => $authid,
-                 authtypecode => $authtypecode,
-                 linkid=>$linkid,
-);
+my $authority_types = Koha::Authority::Types->search( {}, { order_by => ['authtypetext'] } );
 
-my $authtypes = getauthtypes;
-my @authtypesloop;
-foreach my $thisauthtype (keys %$authtypes) {
-    my %row =(value => $thisauthtype,
-                selected => $thisauthtype eq $authtypecode,
-                authtypetext => $authtypes->{$thisauthtype}{'authtypetext'},
-            );
-    push @authtypesloop, \%row;
-}
-
-$template->param(authtypesloop => \@authtypesloop,
-                authtypetext => $authtypes->{$authtypecode}{'authtypetext'},
-                hide_marc => C4::Context->preference('hide_marc'),
-                );
+my $type = $authority_types->find($authtypecode);
+$template->param(
+    authority_types => $authority_types,
+    authtypecode    => $authtypecode,
+    authid          => $authid,
+    linkid          => $linkid,
+    authtypetext    => $type ? $type->authtypetext : "",
+    hide_marc       => C4::Context->preference('hide_marc'),
+);
 output_html_with_http_headers $input, $cookie, $template->output;