MT2502 : Reports Editor's 200$b to biblio's 210$c within unimarc_field_210c plugin
[koha_fer] / C4 / Biblio.pm
index 7b17981..9669752 100755 (executable)
@@ -13,9 +13,9 @@ package C4::Biblio;
 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
 #
-# You should have received a copy of the GNU General Public License along with
-# Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
-# Suite 330, Boston, MA  02111-1307 USA
+# You should have received a copy of the GNU General Public License along
+# with Koha; if not, write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 
 use strict;
 use warnings;
@@ -1146,6 +1146,11 @@ sub GetCOinSBiblio {
     my $record = GetMarcBiblio($biblionumber);
 
     # get the coin format
+    if ( ! $record ) {
+       # can't get a valid MARC::Record object, bail out at this point
+       warn "We called GetMarcBiblio with a biblionumber that doesn't exist biblionumber=$biblionumber";
+       return;
+    }
     my $pos7 = substr $record->leader(), 7, 1;
     my $pos6 = substr $record->leader(), 6, 1;
     my $mtx;
@@ -2294,14 +2299,15 @@ sub PrepareItemrecordDisplay {
                 $subfield_data{repeatable} = $tagslib->{$tag}->{$subfield}->{repeatable};
                 $subfield_data{hidden}     = "display:none"
                   if $tagslib->{$tag}->{$subfield}->{hidden};
-                my ( $x, $value );
+                my ( $x, $defaultvalue );
                 if ($itemrecord) {
-                    ( $x, $value ) = _find_value( $tag, $subfield, $itemrecord );
+                    ( $x, $defaultvalue ) = _find_value( $tag, $subfield, $itemrecord );
                 }
-                if ( !defined $value ) {
-                    $value = q||;
+                $defaultvalue = $tagslib->{$tag}->{$subfield}->{defaultvalue} unless $defaultvalue;
+                if ( !defined $defaultvalue ) {
+                    $defaultvalue = q||;
                 }
-                $value =~ s/"/"/g;
+                $defaultvalue =~ s/"/"/g;
 
                 # search for itemcallnumber if applicable
                 if ( $tagslib->{$tag}->{$subfield}->{kohafield} eq 'items.itemcallnumber'
@@ -2310,7 +2316,7 @@ sub PrepareItemrecordDisplay {
                     my $CNsubfield = substr( C4::Context->preference('itemcallnumber'), 3, 1 );
                     my $temp = $itemrecord->field($CNtag) if ($itemrecord);
                     if ($temp) {
-                        $value = $temp->subfield($CNsubfield);
+                        $defaultvalue = $temp->subfield($CNsubfield);
                     }
                 }
                 if (   $tagslib->{$tag}->{$subfield}->{kohafield} eq 'items.itemcallnumber'
@@ -2318,7 +2324,7 @@ sub PrepareItemrecordDisplay {
                     && $defaultvalues->{'callnumber'} ) {
                     my $temp = $itemrecord->field($subfield) if ($itemrecord);
                     unless ($temp) {
-                        $value = $defaultvalues->{'callnumber'} if $defaultvalues;
+                        $defaultvalue = $defaultvalues->{'callnumber'} if $defaultvalues;
                     }
                 }
                 if (   ( $tagslib->{$tag}->{$subfield}->{kohafield} eq 'items.holdingbranch' || $tagslib->{$tag}->{$subfield}->{kohafield} eq 'items.homebranch' )
@@ -2326,7 +2332,7 @@ sub PrepareItemrecordDisplay {
                     && $defaultvalues->{'branchcode'} ) {
                     my $temp = $itemrecord->field($subfield) if ($itemrecord);
                     unless ($temp) {
-                        $value = $defaultvalues->{branchcode} if $defaultvalues;
+                        $defaultvalue = $defaultvalues->{branchcode} if $defaultvalues;
                     }
                 }
                 if ( $tagslib->{$tag}->{$subfield}->{authorised_value} ) {
@@ -2381,14 +2387,14 @@ sub PrepareItemrecordDisplay {
                     $subfield_data{marc_value} = CGI::scrolling_list(
                         -name     => 'field_value',
                         -values   => \@authorised_values,
-                        -default  => "$value",
+                        -default  => "$defaultvalue",
                         -labels   => \%authorised_lib,
                         -size     => 1,
                         -tabindex => '',
                         -multiple => 0,
                     );
                 } else {
-                    $subfield_data{marc_value} = "<input type=\"text\" name=\"field_value\" value=\"$value\" size=\"50\" maxlength=\"255\" />";
+                    $subfield_data{marc_value} = "<input type=\"text\" name=\"field_value\" value=\"$defaultvalue\" size=\"50\" maxlength=\"255\" />";
                 }
                 push( @loop_data, \%subfield_data );
             }
@@ -2970,8 +2976,10 @@ sub _koha_add_biblio {
     my $error;
 
     # set the series flag
-    my $serial = 0;
-    if ( $biblio->{'seriestitle'} ) { $serial = 1 }
+    unless (defined $biblio->{'serial'}){
+       $biblio->{'serial'} = 0;
+       if ( $biblio->{'seriestitle'} ) { $biblio->{'serial'} = 1 }
+    }
 
     my $query = "INSERT INTO biblio
         SET frameworkcode = ?,
@@ -2988,7 +2996,7 @@ sub _koha_add_biblio {
     my $sth = $dbh->prepare($query);
     $sth->execute(
         $frameworkcode, $biblio->{'author'},      $biblio->{'title'},         $biblio->{'unititle'}, $biblio->{'notes'},
-        $serial,        $biblio->{'seriestitle'}, $biblio->{'copyrightdate'}, $biblio->{'abstract'}
+        $biblio->{'serial'},        $biblio->{'seriestitle'}, $biblio->{'copyrightdate'}, $biblio->{'abstract'}
     );
 
     my $biblionumber = $dbh->{'mysql_insertid'};