fix for bug 1499 - normalize ISBN before dupe check
[koha.git] / C4 / Biblio.pm
index 38b5a39..11df070 100644 (file)
@@ -65,9 +65,11 @@ push @EXPORT, qw(
   &GetMarcBiblio
   &GetMarcAuthors
   &GetMarcSeries
+  GetMarcUrls
   &GetUsedMarcStructure
 
   &GetItemsInfo
+  &GetItemsByBiblioitemnumber
   &GetItemnumberFromBarcode
   &get_itemnumbers_of
   &GetXmlBiblio
@@ -393,10 +395,10 @@ sub ModBiblio {
     # adding biblionumber
     my ($tag_biblionumber, $subfield_biblionumber) = GetMarcFromKohaField('biblio.biblionumber',$frameworkcode);
     $record->append_fields(
-       MARC::Field->new(
-               $tag_biblionumber,'','',$subfield_biblionumber => $biblionumber
-       )
-    );
+           MARC::Field->new(
+                   $tag_biblionumber,'','',$subfield_biblionumber => $biblionumber
+           )
+    ) unless ($record->subfield($tag_biblionumber,$subfield_biblionumber));
     
     # update the MARC record (that now contains biblio and items) with the new record data
     &ModBiblioMarc( $record, $biblionumber, $frameworkcode );
@@ -593,26 +595,15 @@ sub DelBiblio {
     my ( $biblionumber ) = @_;
     my $dbh = C4::Context->dbh;
     my $error;    # for error handling
+       
+       # First make sure this biblio has no items attached
+       my $sth = $dbh->prepare("SELECT itemnumber FROM items WHERE biblionumber=?");
+       $sth->execute($biblionumber);
+       if (my $itemnumber = $sth->fetchrow){
+               # Fix this to use a status the template can understand
+               $error .= "This Biblio has items attached, please delete them first before deleting this biblio ";
+       }
 
-    # First make sure there are no items with issues are still attached
-    my $sth =
-      $dbh->prepare(
-        "SELECT itemnumber FROM items WHERE biblionumber=?");
-    $sth->execute($biblionumber);
-    while ( my $itemnumber = $sth->fetchrow ) {
-        my $issues = GetItemIssues($itemnumber);
-        foreach my $issue (@$issues) {
-            if (   ( $issue->{date_due} )
-                && ( $issue->{date_due} ne "Available" ) )
-            {
-
-#FIXME: we need a status system in Biblio like in Circ to return standard codes and messages
-# instead of hard-coded strings
-                $error .=
-"Item is checked out to a patron -- you must return it before deleting the Biblio";
-            }
-        }
-    }
     return $error if $error;
 
     # Delete in Zebra. Be careful NOT to move this line after _koha_delete_biblio
@@ -635,16 +626,6 @@ sub DelBiblio {
         # delete this biblioitem
         $error = &_koha_delete_biblioitems( $dbh, $biblioitemnumber );
         return $error if $error;
-
-        # delete items
-        my $items_sth =
-          $dbh->prepare(
-            "SELECT itemnumber FROM items WHERE biblioitemnumber=?");
-        $items_sth->execute($biblioitemnumber);
-        while ( my $itemnumber = $items_sth->fetchrow ) {
-            $error = &_koha_delete_item( $dbh, $itemnumber );
-            return $error if $error;
-        }
     }
     &logaction(C4::Context->userenv->{'number'},"CATALOGUING","DELETE",$biblionumber,"") 
         if C4::Context->preference("CataloguingLog");
@@ -665,6 +646,10 @@ Exported function (core API) for deleting an item record in Koha.
 sub DelItem {
     my ( $biblionumber, $itemnumber ) = @_;
     my $dbh = C4::Context->dbh;
+       
+       # check the item has no current issues
+       
+       
     &_koha_delete_item( $dbh, $itemnumber );
     # get the MARC record
     my $record = GetMarcBiblio($biblionumber);
@@ -712,7 +697,7 @@ sub GetBiblioData {
     my $dbh = C4::Context->dbh;
 
     my $query = "
-        SELECT * , biblioitems.notes AS bnotes, biblio.notes
+        SELECT * , biblioitems.notes AS bnotes, itemtypes.notforloan as bi_notforloan, biblio.notes
         FROM biblio
             LEFT JOIN biblioitems ON biblio.biblionumber = biblioitems.biblionumber
             LEFT JOIN itemtypes ON biblioitems.itemtype = itemtypes.itemtype
@@ -783,11 +768,11 @@ sub GetItemsInfo {
     my ( $biblionumber, $type ) = @_;
     my $dbh   = C4::Context->dbh;
     my $query = "SELECT *,items.notforloan as itemnotforloan
-                 FROM items, biblio, biblioitems
+                 FROM items 
+                 LEFT JOIN biblio ON biblio.biblionumber = items.biblionumber
+                 LEFT JOIN biblioitems ON biblioitems.biblioitemnumber = items.biblioitemnumber
                  LEFT JOIN itemtypes on biblioitems.itemtype = itemtypes.itemtype
                 WHERE items.biblionumber = ?
-                    AND biblioitems.biblioitemnumber = items.biblioitemnumber
-                    AND biblio.biblionumber = items.biblionumber
                 ORDER BY items.dateaccessioned desc
                  ";
     my $sth = $dbh->prepare($query);
@@ -800,10 +785,9 @@ sub GetItemsInfo {
         my $datedue = '';
         my $isth    = $dbh->prepare(
             "SELECT issues.*,borrowers.cardnumber,borrowers.surname,borrowers.firstname
-            FROM   issues, borrowers
+            FROM   issues LEFT JOIN borrowers ON issues.borrowernumber=borrowers.borrowernumber
             WHERE  itemnumber = ?
-                AND returndate IS NULL
-                AND issues.borrowernumber=borrowers.borrowernumber"
+                AND returndate IS NULL"
         );
         $isth->execute( $data->{'itemnumber'} );
         if ( my $idata = $isth->fetchrow_hashref ) {
@@ -1177,18 +1161,18 @@ that C<biblioitems.notes> is given as C<$itemdata-E<gt>{bnotes}>.
 
 #'
 sub GetBiblioItemData {
-    my ($bibitem) = @_;
+    my ($biblioitemnumber) = @_;
     my $dbh       = C4::Context->dbh;
     my $sth       =
       $dbh->prepare(
-"Select *,biblioitems.notes as bnotes from biblioitems, biblio,itemtypes where biblio.biblionumber = biblioitems.biblionumber and biblioitemnumber = ? and biblioitems.itemtype = itemtypes.itemtype"
+       "SELECT *,biblioitems.notes AS bnotes
+               FROM biblioitems,biblio,itemtypes 
+       WHERE biblio.biblionumber = biblioitems.biblionumber 
+               AND biblioitemnumber = ? "
       );
     my $data;
-
-    $sth->execute($bibitem);
-
+    $sth->execute($biblioitemnumber);
     $data = $sth->fetchrow_hashref;
-
     $sth->finish;
     return ($data);
 }    # sub &GetBiblioItemData
@@ -1262,10 +1246,10 @@ sub GetBiblioFromItemNumber {
     my ( $itemnumber ) = @_;
     my $dbh = C4::Context->dbh;
     my $sth = $dbh->prepare(
-        "SELECT * FROM biblio,items,biblioitems
-         WHERE items.itemnumber = ?
-           AND biblio.biblionumber = items.biblionumber
-           AND biblioitems.biblioitemnumber = items.biblioitemnumber"
+        "SELECT * FROM items 
+        LEFT JOIN biblio ON biblio.biblionumber = items.biblionumber
+        LEFT JOIN biblioitems ON biblioitems.biblioitemnumber = items.biblioitemnumber
+         WHERE items.itemnumber = ?"
     );
 
     $sth->execute($itemnumber);
@@ -1392,6 +1376,68 @@ sub GetItemInfosOf {
     return get_infos_of( $query, 'itemnumber' );
 }
 
+=head2 GetItemsByBiblioitemnumber
+
+=over 4
+
+GetItemsByBiblioitemnumber($biblioitemnumber);
+
+Returns an arrayref of hashrefs suitable for use in a TMPL_LOOP
+Called by moredetail.pl
+
+=back
+
+=cut
+
+sub GetItemsByBiblioitemnumber {
+       my ( $bibitem ) = @_;
+       my $dbh = C4::Context->dbh;
+       my $sth = $dbh->prepare("SELECT * FROM items WHERE items.biblioitemnumber = ?") || die $dbh->errstr;
+       # Get all items attached to a biblioitem
+    my $i = 0;
+    my @results; 
+    $sth->execute($bibitem) || die $sth->errstr;
+    while ( my $data = $sth->fetchrow_hashref ) {  
+               # Foreach item, get circulation information
+               my $sth2 = $dbh->prepare( "SELECT * FROM issues,borrowers
+                                   WHERE itemnumber = ?
+                                   AND returndate is NULL
+                                   AND issues.borrowernumber = borrowers.borrowernumber"
+        );
+        $sth2->execute( $data->{'itemnumber'} );
+        if ( my $data2 = $sth2->fetchrow_hashref ) {
+                       # if item is out, set the due date and who it is out too
+                       $data->{'date_due'}   = $data2->{'date_due'};
+                       $data->{'cardnumber'} = $data2->{'cardnumber'};
+                       $data->{'borrowernumber'}   = $data2->{'borrowernumber'};
+               }
+        else {
+                       # set date_due to blank, so in the template we check itemlost, and wthdrawn 
+                       $data->{'date_due'} = '';                                                                                                         
+               }    # else         
+        $sth2->finish;
+        # Find the last 3 people who borrowed this item.                  
+        my $query2 = "SELECT * FROM issues, borrowers WHERE itemnumber = ?
+                      AND issues.borrowernumber = borrowers.borrowernumber
+                      AND returndate is not NULL
+                      ORDER BY returndate desc,timestamp desc LIMIT 3";
+        $sth2 = $dbh->prepare($query2) || die $dbh->errstr;
+        $sth2->execute( $data->{'itemnumber'} ) || die $sth2->errstr;
+        my $i2 = 0;
+        while ( my $data2 = $sth2->fetchrow_hashref ) {
+                       $data->{"timestamp$i2"} = $data2->{'timestamp'};
+                       $data->{"card$i2"}      = $data2->{'cardnumber'};
+                       $data->{"borrower$i2"}  = $data2->{'borrowernumber'};
+                       $i2++;
+               }
+        $sth2->finish;
+        push(@results,$data);
+    } 
+    $sth->finish;
+    return (\@results); 
+}
+
+
 =head2 GetBiblioItemInfosOf
 
 =over 4
@@ -1589,10 +1635,12 @@ sub GetMarcBiblio {
      $marcxml =~ s/\x1f//g;
      $marcxml =~ s/\x1d//g;
      $marcxml =~ s/\x0f//g;
-     $marcxml =~ s/\x0c//g;
+     $marcxml =~ s/\x0c//g;  
 #   warn $marcxml;
     my $record = MARC::Record->new();
-     $record = MARC::Record::new_from_xml( $marcxml, "utf8",C4::Context->preference('marcflavour')) if $marcxml;
+     
+      $record = eval {MARC::Record::new_from_xml( $marcxml, "utf8",C4::Context->preference('marcflavour'))} if ($marcxml);
+     if ($@) {warn $@;}
 #      $record = MARC::Record::new_from_usmarc( $marc) if $marc;
     return $record;
 }
@@ -1820,6 +1868,8 @@ The authors are stored in differents places depending on MARC flavour
 sub GetMarcAuthors {
     my ( $record, $marcflavour ) = @_;
     my ( $mintag, $maxtag );
+    # tagslib useful for UNIMARC author reponsabilities
+    my $tagslib = &GetMarcStructure( 1, '' ); # FIXME : we don't have the framework available, we take the default framework. May be bugguy on some setups, will be usually correct.
     if ( $marcflavour eq "MARC21" ) {
         $mintag = "100";
         $maxtag = "111"; 
@@ -1842,7 +1892,6 @@ sub GetMarcAuthors {
                 $marcflavour ne 'MARC21'
                 and (
                     ($authors_subfield->[0] eq '3') or
-                    ($authors_subfield->[0] eq '4') or
                     ($authors_subfield->[0] eq '5')
                 )
             )
@@ -1854,7 +1903,17 @@ sub GetMarcAuthors {
             }
             $count_auth++;
             my $subfieldcode = $authors_subfield->[0];
-            my $value        = $authors_subfield->[1];
+            my $value;
+            # deal with UNIMARC author responsibility
+            if (
+                $marcflavour ne 'MARC21'
+                and ($authors_subfield->[0] eq '4')
+            )
+            {
+                $value = "(".GetAuthorisedValueDesc( $field->tag(), $authors_subfield->[0], $authors_subfield->[1], '', $tagslib ).")";
+            } else {
+                $value        = $authors_subfield->[1];
+            }
             $hash{tag}       = $field->tag;
             $hash{value}    .= $value . " " if ($subfieldcode != 9) ;
             $hash{link}     .= $value if ($subfieldcode eq 9);
@@ -1864,11 +1923,50 @@ sub GetMarcAuthors {
     return \@marcauthors;
 }
 
+=head2 GetMarcUrls
+
+=over 4
+
+$marcurls = GetMarcUrls($record,$marcflavour);
+Returns arrayref of URLs from MARC data, suitable to pass to tmpl loop.
+Assumes web resources (not uncommon in MARC21 to omit resource type ind) 
+
+=back
+
+=cut
+
+sub GetMarcUrls {
+    my ($record, $marcflavour) = @_;
+    my @marcurls;
+    my $marcurl;
+    for my $field ($record->field('856')) {
+        my $url = $field->subfield('u');
+        my @notes;
+        for my $note ( $field->subfield('z')) {
+            push @notes , {note => $note};
+        }        
+        $marcurl = {  MARCURL => $url,
+                      notes => \@notes,
+                                       };
+               if($marcflavour eq 'MARC21') {
+               my $s3 = $field->subfield('3');
+                       my $link = $field->subfield('y');
+            $marcurl->{'linktext'} = $link || $s3 || $url ;;
+            $marcurl->{'part'} = $s3 if($link);
+            $marcurl->{'toc'} = 1 if($s3 =~ /^[Tt]able/) ;
+               } else {
+                       $marcurl->{'linktext'} = $url;
+               }
+        push @marcurls, $marcurl;    
+       }
+    return \@marcurls;
+}  #end GetMarcUrls
+
 =head2 GetMarcSeries
 
 =over 4
 
-$marcseriessarray = GetMarcSeries($record,$marcflavour);
+$marcseriesarray = GetMarcSeries($record,$marcflavour);
 Get all series from the MARC record and returns them in an array.
 The series are stored in differents places depending on MARC flavour
 
@@ -2214,17 +2312,34 @@ sub TransformHtmlToMarc {
     my $record  = MARC::Record->new();
     my $i=0;
     my @fields;
-    
     while ($params->[$i]){ # browse all CGI params
         my $param = $params->[$i];
-        
-        if($param =~ /^tag_(\d*)_indicator_/){ # new field start when having 'input name="..._indicator_..."
+        my $newfield=0;
+        # if we are on biblionumber, store it in the MARC::Record (it may not be in the edited fields)
+        if ($param eq 'biblionumber') {
+            my ( $biblionumbertagfield, $biblionumbertagsubfield ) =
+                &GetMarcFromKohaField( "biblio.biblionumber", '' );
+            if ($biblionumbertagfield < 10) {
+                $newfield = MARC::Field->new(
+                    $biblionumbertagfield,
+                    $cgi->param($param),
+                );
+            } else {
+                $newfield = MARC::Field->new(
+                    $biblionumbertagfield,
+                    '',
+                    '',
+                    "$biblionumbertagsubfield" => $cgi->param($param),
+                );
+            }
+            push @fields,$newfield if($newfield);
+        } 
+        elsif ($param =~ /^tag_(\d*)_indicator_/){ # new field start when having 'input name="..._indicator_..."
             my $tag  = $1;
             
             my $ind1 = substr($cgi->param($param),0,1);
             my $ind2 = substr($cgi->param($param),1,1);
-            
-            my $newfield=0;
+            $newfield=0;
             my $j=$i+1;
             
             if($tag < 10){ # no code for theses fields
@@ -3061,25 +3176,25 @@ sub _AddBiblioNoZebra {
                         next unless $_; # skip  empty values (multiple spaces)
                         # if the entry is already here, improve weight
 #                         warn "managing $_";
-                        if ($result{$key}->{$_} =~ /$biblionumber,$title\-(\d);/) {
+                        if ($result{$key}->{"$_"} =~ /$biblionumber,$title\-(\d);/) {
                             my $weight=$1+1;
-                            $result{$key}->{$_} =~ s/$biblionumber,$title\-(\d);//;
-                            $result{$key}->{$_} .= "$biblionumber,$title-$weight;";
+                            $result{$key}->{"$_"} =~ s/$biblionumber,$title\-(\d);//;
+                            $result{$key}->{"$_"} .= "$biblionumber,$title-$weight;";
                         } else {
                             # get the value if it exist in the nozebra table, otherwise, create it
                             $sth2->execute($server,$key,$_);
                             my $existing_biblionumbers = $sth2->fetchrow;
                             # it exists
                             if ($existing_biblionumbers) {
-                                $result{$key}->{$_} =$existing_biblionumbers;
+                                $result{$key}->{"$_"} =$existing_biblionumbers;
                                 my $weight=$1+1;
-                                $result{$key}->{$_} =~ s/$biblionumber,$title\-(\d);//;
-                                $result{$key}->{$_} .= "$biblionumber,$title-$weight;";
+                                $result{$key}->{"$_"} =~ s/$biblionumber,$title\-(\d);//;
+                                $result{$key}->{"$_"} .= "$biblionumber,$title-$weight;";
                             # create a new ligne for this entry
                             } else {
 #                             warn "INSERT : $server / $key / $_";
                                 $dbh->do('INSERT INTO nozebra SET server='.$dbh->quote($server).', indexname='.$dbh->quote($key).',value='.$dbh->quote($_));
-                                $result{$key}->{$_}.="$biblionumber,$title-1;";
+                                $result{$key}->{"$_"}.="$biblionumber,$title-1;";
                             }
                         }
                     }
@@ -3093,24 +3208,24 @@ sub _AddBiblioNoZebra {
                 foreach (split / /,$line) {
                     next unless $_; # skip  empty values (multiple spaces)
                     # if the entry is already here, improve weight
-                    if ($result{'__RAW__'}->{$_} =~ /$biblionumber,$title\-(\d);/) {
+                    if ($result{'__RAW__'}->{"$_"} =~ /$biblionumber,$title\-(\d);/) {
                         my $weight=$1+1;
-                        $result{'__RAW__'}->{$_} =~ s/$biblionumber,$title\-(\d);//;
-                        $result{'__RAW__'}->{$_} .= "$biblionumber,$title-$weight;";
+                        $result{'__RAW__'}->{"$_"} =~ s/$biblionumber,$title\-(\d);//;
+                        $result{'__RAW__'}->{"$_"} .= "$biblionumber,$title-$weight;";
                     } else {
                         # get the value if it exist in the nozebra table, otherwise, create it
                         $sth2->execute($server,'__RAW__',$_);
                         my $existing_biblionumbers = $sth2->fetchrow;
                         # it exists
                         if ($existing_biblionumbers) {
-                            $result{'__RAW__'}->{$_} =$existing_biblionumbers;
+                            $result{'__RAW__'}->{"$_"} =$existing_biblionumbers;
                             my $weight=$1+1;
-                            $result{'__RAW__'}->{$_} =~ s/$biblionumber,$title\-(\d);//;
-                            $result{'__RAW__'}->{$_} .= "$biblionumber,$title-$weight;";
+                            $result{'__RAW__'}->{"$_"} =~ s/$biblionumber,$title\-(\d);//;
+                            $result{'__RAW__'}->{"$_"} .= "$biblionumber,$title-$weight;";
                         # create a new ligne for this entry
                         } else {
                             $dbh->do('INSERT INTO nozebra SET server='.$dbh->quote($server).',  indexname="__RAW__",value='.$dbh->quote($_));
-                            $result{'__RAW__'}->{$_}.="$biblionumber,$title-1;";
+                            $result{'__RAW__'}->{"$_"}.="$biblionumber,$title-1;";
                         }
                     }
                 }
@@ -3176,7 +3291,7 @@ sub _koha_add_biblio {
     $sth->finish;
     $sth = $dbh->prepare(
         "INSERT INTO biblio
-    SET biblionumber  = ?, title = ?, author = ?, copyrightdate = ?, serial = ?, seriestitle = ?, notes = ?, abstract = ?, unititle = ?, frameworkcode = ? "
+    SET datecreated=NOW(), biblionumber  = ?, title = ?, author = ?, copyrightdate = ?, serial = ?, seriestitle = ?, notes = ?, abstract = ?, unititle = ?, frameworkcode = ? "
     );
     $sth->execute(
         $biblionumber,         $biblio->{'title'},
@@ -3314,11 +3429,16 @@ sub _koha_modify_biblioitem {
     $biblioitem->{'bnotes'}       = $dbh->quote( $biblioitem->{'bnotes'} );
     $biblioitem->{'size'}         = $dbh->quote( $biblioitem->{'size'} );
     $biblioitem->{'place'}        = $dbh->quote( $biblioitem->{'place'} );
+    $biblioitem->{'collectiontitle'}        = $dbh->quote( $biblioitem->{'collectiontitle'} );
+    $biblioitem->{'collectionissn'}         = $dbh->quote( $biblioitem->{'collectionissn'} );
+    $biblioitem->{'collectionvolume'}       = $dbh->quote( $biblioitem->{'collectionvolume'} );
+    $biblioitem->{'editionstatement'}       = $dbh->quote( $biblioitem->{'editionstatement'} );
+    $biblioitem->{'editionresponsibility'}  = $dbh->quote( $biblioitem->{'editionresponsibility'} );
     $biblioitem->{'ccode'}        = $dbh->quote( $biblioitem->{'ccode'} );
     $biblioitem->{'biblionumber'} =
       $dbh->quote( $biblioitem->{'biblionumber'} );
 
-    $query = "Update biblioitems set
+    $query = "UPDATE biblioitems SET
         itemtype        = $biblioitem->{'itemtype'},
         url             = $biblioitem->{'url'},
         isbn            = $biblioitem->{'isbn'},
@@ -3334,6 +3454,11 @@ sub _koha_modify_biblioitem {
         notes           = $biblioitem->{'bnotes'},
         size            = $biblioitem->{'size'},
         place           = $biblioitem->{'place'},
+        collectiontitle = $biblioitem->{'collectiontitle'},
+        collectionissn  = $biblioitem->{'collectionissn'},
+        collectionvolume= $biblioitem->{'collectionvolume'},
+        editionstatement= $biblioitem->{'editionstatement'},
+        editionresponsibility= $biblioitem->{'editionresponsibility'},
         ccode           = $biblioitem->{'ccode'}
         where biblionumber = $biblioitem->{'biblionumber'}";
 
@@ -3381,8 +3506,11 @@ sub _koha_add_biblioitem {
             volumeddesc      = ?, illus           = ?,
             pages            = ?, notes           = ?,
             size             = ?, lccn            = ?,
-            marc             = ?, lcsort          =?,
-            place            = ?, ccode           = ?
+            marc             = ?, lcsort          = ?,
+            place            = ?, ccode           = ?,
+            collectiontitle  = ?, collectionissn  = ?,
+            collectionvolume = ?, editionstatement= ?,
+            editionresponsibility= ?
           "
     );
     my ($lcsort) =
@@ -3400,7 +3528,10 @@ sub _koha_add_biblioitem {
         $biblioitem->{'pages'},          $biblioitem->{'bnotes'},
         $biblioitem->{'size'},           $biblioitem->{'lccn'},
         $biblioitem->{'marc'},           $biblioitem->{'place'},
-        $lcsort,                         $biblioitem->{'ccode'}
+        $lcsort,                         $biblioitem->{'ccode'},
+        $biblioitem->{'collectiontitle'},$biblioitem->{'collectionissn'},
+        $biblioitem->{'collectionvolume'},$biblioitem->{'editionstatement'},
+        $biblioitem->{'editionresponsibility'}
     );
     $sth->finish;
     return ($bibitemnum);
@@ -3447,13 +3578,12 @@ sub _koha_new_items {
         $sth = $dbh->prepare(
             "Insert into items set
             itemnumber           = ?,     biblionumber     = ?,
-            multivolumepart      = ?,
             biblioitemnumber     = ?,     barcode          = ?,
             booksellerid         = ?,     dateaccessioned  = NOW(),
             homebranch           = ?,     holdingbranch    = ?,
             price                = ?,     replacementprice = ?,
             replacementpricedate = NOW(), datelastseen     = NOW(),
-            multivolume          = ?,     stack            = ?,
+                       stack            = ?,
             itemlost             = ?,     wthdrawn         = ?,
             paidfor              = ?,     itemnotes        = ?,
             itemcallnumber       =?,      notforloan       = ?,
@@ -3462,11 +3592,11 @@ sub _koha_new_items {
         );
         $sth->execute(
             $itemnumber,                $item->{'biblionumber'},
-            $item->{'multivolumepart'}, $item->{'biblioitemnumber'},
+                       $item->{'biblioitemnumber'},
             $barcode,                   $item->{'booksellerid'},
             $item->{'homebranch'},      $item->{'holdingbranch'},
             $item->{'price'},           $item->{'replacementprice'},
-            $item->{multivolume},       $item->{stack},
+                       $item->{stack},
             $item->{itemlost},          $item->{wthdrawn},
             $item->{paidfor},           $item->{'itemnotes'},
             $item->{'itemcallnumber'},  $item->{'notforloan'},
@@ -3477,13 +3607,12 @@ sub _koha_new_items {
         $sth = $dbh->prepare(
             "INSERT INTO items SET
             itemnumber           = ?,     biblionumber     = ?,
-            multivolumepart      = ?,
             biblioitemnumber     = ?,     barcode          = ?,
             booksellerid         = ?,     dateaccessioned  = ?,
             homebranch           = ?,     holdingbranch    = ?,
             price                = ?,     replacementprice = ?,
             replacementpricedate = NOW(), datelastseen     = NOW(),
-            multivolume          = ?,     stack            = ?,
+                       stack            = ?,
             itemlost             = ?,     wthdrawn         = ?,
             paidfor              = ?,     itemnotes        = ?,
             itemcallnumber       = ?,     notforloan       = ?,
@@ -3493,11 +3622,11 @@ sub _koha_new_items {
         );
         $sth->execute(
             $itemnumber,                 $item->{'biblionumber'},
-            $item->{'multivolumepart'},  $item->{'biblioitemnumber'},
+                       $item->{'biblioitemnumber'},
             $barcode,                    $item->{'booksellerid'},
             $item->{'dateaccessioned'},  $item->{'homebranch'},
             $item->{'holdingbranch'},    $item->{'price'},
-            $item->{'replacementprice'}, $item->{multivolume},
+            $item->{'replacementprice'},
             $item->{stack},              $item->{itemlost},
             $item->{wthdrawn},           $item->{paidfor},
             $item->{'itemnotes'},        $item->{'itemcallnumber'},
@@ -3528,10 +3657,10 @@ sub _koha_modify_item {
     # if all we're doing is setting statuses, just update those and get out
     if ( $op eq "setstatus" ) {
         my $query =
-          "UPDATE items SET itemlost=?,wthdrawn=?,binding=? WHERE itemnumber=?";
+          "UPDATE items SET itemlost=?,wthdrawn=? WHERE itemnumber=?";
         my @bind = (
             $item->{'itemlost'}, $item->{'wthdrawn'},
-            $item->{'binding'},  $item->{'itemnumber'}
+                       $item->{'itemnumber'}
         );
         my $sth = $dbh->prepare($query);
         $sth->execute(@bind);
@@ -3543,32 +3672,29 @@ sub _koha_modify_item {
       itemcalculator( $dbh, $item->{'bibitemnum'}, $item->{'itemcallnumber'} );
 
     my $query = "UPDATE items SET
-barcode=?,itemnotes=?,itemcallnumber=?,notforloan=?,location=?,multivolumepart=?,multivolume=?,stack=?,wthdrawn=?,holdingbranch=?,homebranch=?,cutterextra=?, onloan=?, binding=?";
+barcode=?,itemnotes=?,itemcallnumber=?,notforloan=?,location=?,stack=?,wthdrawn=?,holdingbranch=?,homebranch=?,cutterextra=?, onloan=?";
 
     my @bind = (
         $item->{'barcode'},        $item->{'notes'},
         $item->{'itemcallnumber'}, $item->{'notforloan'},
-        $item->{'location'},       $item->{multivolumepart},
-        $item->{multivolume},      $item->{stack},
+        $item->{'location'},       $item->{stack},
         $item->{wthdrawn},         $item->{holdingbranch},
         $item->{homebranch},       $cutterextra,
-        $item->{onloan},           $item->{binding}
+        $item->{onloan},           
     );
     if ( $item->{'lost'} ne '' ) {
         $query =
 "update items set biblioitemnumber=?,barcode=?,itemnotes=?,homebranch=?,
                             itemlost=?,wthdrawn=?,itemcallnumber=?,notforloan=?,
-                             location=?,multivolumepart=?,multivolume=?,stack=?,wthdrawn=?,holdingbranch=?,cutterextra=?,onloan=?, binding=?";
+                             location=?,stack=?,wthdrawn=?,holdingbranch=?,cutterextra=?,onloan=?";
         @bind = (
             $item->{'bibitemnum'},     $item->{'barcode'},
             $item->{'notes'},          $item->{'homebranch'},
             $item->{'lost'},           $item->{'wthdrawn'},
             $item->{'itemcallnumber'}, $item->{'notforloan'},
-            $item->{'location'},       $item->{multivolumepart},
-            $item->{multivolume},      $item->{stack},
+            $item->{'location'},       $item->{stack},
             $item->{wthdrawn},         $item->{holdingbranch},
-            $cutterextra,              $item->{onloan},
-            $item->{binding}
+            $cutterextra,              $item->{onloan}
         );
         if ( $item->{homebranch} ) {
             $query .= ",homebranch=?";
@@ -3863,7 +3989,7 @@ sub ModBiblioMarc {
     $sth =
       $dbh->prepare(
         "update biblioitems set marc=?,marcxml=?  where biblionumber=?");
-    $sth->execute( $record->as_usmarc(), $record->as_xml_record(),
+    $sth->execute( $record->as_usmarc(), $record->as_xml_record($encoding),
         $biblionumber );
     $sth->finish;
     return $biblionumber;