Bug 17124: Fix tests in DecreaseLoanHighHolds.t
[koha.git] / cataloguing / addbiblio.pl
index 890db0f..1e7cb61 100755 (executable)
@@ -30,11 +30,12 @@ use C4::AuthoritiesMarc;
 use C4::Context;
 use MARC::Record;
 use C4::Log;
-use C4::Koha;    # XXX subfield_is_koha_internal_p
-use C4::Branch;    # XXX subfield_is_koha_internal_p
+use C4::Koha;
+use C4::Branch;
 use C4::ClassSource;
 use C4::ImportBatch;
 use C4::Charset;
+use Koha::BiblioFrameworks;
 
 use Date::Calc qw(Today);
 use MARC::File::USMARC;
@@ -178,32 +179,24 @@ sub build_authorized_values_list {
           && !C4::Context->IsSuperLibrarian()
           && C4::Context->userenv->{branch};
         my $branches = GetBranches($onlymine);
-        my @branchloop;
         foreach my $thisbranch ( sort keys %$branches ) {
             push @authorised_values, $thisbranch;
             $authorised_lib{$thisbranch} = $branches->{$thisbranch}->{'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);
-
-          #---- class_sources
     }
     elsif ( $tagslib->{$tag}->{$subfield}->{authorised_value} eq "cn_source" ) {
         push @authorised_values, ""
@@ -746,23 +739,15 @@ if ($frameworkcode eq 'FA'){
         'stickyduedate'      => $fa_stickyduedate,
         'duedatespec'        => $fa_duedatespec,
     );
+} elsif ( C4::Context->preference('EnableAdvancedCatalogingEditor') && $input->cookie( 'catalogue_editor_' . $loggedinuser ) eq 'advanced' && !$breedingid ) {
+    # Only use the advanced editor for non-fast-cataloging.
+    # breedingid is not handled because those would only come off a Z39.50
+    # search initiated by the basic editor.
+    print $input->redirect( '/cgi-bin/koha/cataloguing/editor.pl' . ( $biblionumber ? ( '#catalog/' . $biblionumber ) : '' ) );
 }
 
-# Getting the list of all frameworks
-# get framework list
-my $frameworks = getframeworks;
-my @frameworkcodeloop;
-foreach my $thisframeworkcode ( keys %$frameworks ) {
-       my %row = (
-               value         => $thisframeworkcode,
-               frameworktext => $frameworks->{$thisframeworkcode}->{'frameworktext'},
-       );
-       if ($frameworkcode eq $thisframeworkcode){
-               $row{'selected'} = 1;
-               }
-       push @frameworkcodeloop, \%row;
-} 
-$template->param( frameworkcodeloop => \@frameworkcodeloop,
+my $frameworkcodeloop = Koha::BiblioFrameworks->search({}, { order_by => ['frameworktext'] });
+$template->param( frameworkcodeloop => $frameworkcodeloop ,
        breedingid => $breedingid );
 
 # ++ Global
@@ -778,7 +763,6 @@ my (
        $biblionumbertagsubfield,
        $biblioitemnumtagfield,
        $biblioitemnumtagsubfield,
-       $bibitem,
        $biblioitemnumber
 );
 
@@ -836,8 +820,8 @@ if ( $op eq "addbiblio" ) {
         biblionumberdata => $biblionumber,
     );
     # getting html input
-    my @params = $input->param();
-    $record = TransformHtmlToMarc( $input );
+    my @params = $input->multi_param();
+    $record = TransformHtmlToMarc( $input, 1 );
     # check for a duplicate
     my ( $duplicatebiblionumber, $duplicatetitle );
     if ( !$is_a_modif ) {
@@ -846,7 +830,6 @@ if ( $op eq "addbiblio" ) {
     my $confirm_not_duplicate = $input->param('confirm_not_duplicate');
     # it is not a duplicate (determined either by Koha itself or by user checking it's not a duplicate)
     if ( !$duplicatebiblionumber or $confirm_not_duplicate ) {
-        my $oldbibnum;
         my $oldbibitemnum;
         if (C4::Context->preference("BiblioAddsAuthorities")){
             BiblioAutoLink( $record, $frameworkcode );
@@ -952,7 +935,7 @@ elsif ( $op eq "delete" ) {
     }
 
     if($changed_framework eq "changed"){
-        $record = TransformHtmlToMarc( $input );
+        $record = TransformHtmlToMarc( $input, 1 );
     }
     elsif( $record ne -1 ) {
 #FIXME: it's kind of silly to go from MARC::Record to MARC::File::XML and then back again just to fix the encoding
@@ -986,7 +969,7 @@ $template->param(
     frameworkcode => $frameworkcode,
     itemtype => $frameworkcode,
     borrowernumber => $loggedinuser,
-    tab => $input->param('tab')
+    tab => scalar $input->param('tab')
 );
 $template->{'VARS'}->{'searchid'} = $searchid;