Bug 12478: starting authority search in staff client
[koha.git] / authorities / authorities.pl
index 16910c8..bc2c8d4 100755 (executable)
@@ -26,11 +26,12 @@ 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 vars qw( $tagslib);
 use vars qw( $authorised_values_sth);
 use vars qw( $is_a_modif );
@@ -83,23 +84,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 = GetItemTypes( style => 'array' );
+        for my $itemtype ( @$itemtypes ) {
+            push @authorised_values, $itemtype->{itemtype};
+            $authorised_lib{$itemtype->{itemtype}} = $itemtype->{translated_description};
         }
         $value = $itemtype unless ($value);
 
@@ -573,7 +568,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)
@@ -617,7 +612,7 @@ if ($op eq "add") {
     # build indicator hash.
     my @ind_tag = $input->param('ind_tag');
     my @indicator = $input->param('indicator');
-    my $record = TransformHtmlToMarc($input);
+    my $record = TransformHtmlToMarc($input, 0);
 
     my ($duplicateauthid,$duplicateauthvalue);
      ($duplicateauthid,$duplicateauthvalue) = FindDuplicateAuthority($record,$authtypecode) if ($op eq "add") && (!$is_a_modif);
@@ -665,23 +660,14 @@ 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'),
-                );
+$template->param(
+    authority_types => $authority_types,
+    authtypecode    => $authtypecode,
+    authid          => $authid,
+    linkid          => $linkid,
+    authtypetext    => $authority_types->find($authtypecode)->authtypetext,
+    hide_marc       => C4::Context->preference('hide_marc'),
+);
 output_html_with_http_headers $input, $cookie, $template->output;