Add start of 2.3 installer. Remove obsolete? files conflicting with 2.3 installer
[koha.git] / C4 / Biblio.pm
index 90ad133..8f75db9 100644 (file)
@@ -58,6 +58,7 @@ $VERSION = 0.01;
   &NEWnewbiblio &NEWnewitem
   &NEWmodbiblio &NEWmoditem
   &NEWdelbiblio &NEWdelitem
+  &NEWmodbiblioframework
 
   &MARCaddbiblio &MARCadditem
   &MARCmodsubfield &MARCaddsubfield
@@ -66,7 +67,11 @@ $VERSION = 0.01;
   &MARCkoha2marcItem &MARChtml2marc
   &MARCgetbiblio &MARCgetitem
   &MARCaddword &MARCdelword
+  &MARCdelsubfield
   &char_decode
+  
+  &FindDuplicate
+  &DisplayISBN
 );
 
 #
@@ -199,6 +204,7 @@ MARCfindsubfieldid find a subfieldid for a bibid/tag/tagorder/subfield/subfieldo
 =item &MARCdelsubfield($dbh,$bibid,$tag,$tagorder,$subfield,$subfieldorder);
 
 MARCdelsubfield delete a subfield for a bibid/tag/tagorder/subfield/subfieldorder
+If $subfieldorder is not set, delete all the $tag$subfield subfields 
 
 =item &MARCdelbiblio($dbh,$bibid);
 
@@ -237,13 +243,13 @@ sub MARCgettagslib {
     $frameworkcode = "" unless ( $total > 0 );
     $sth =
       $dbh->prepare(
-"select tagfield,$libfield as lib,mandatory,repeatable from marc_tag_structure where frameworkcode=? order by tagfield"
+"select tagfield,liblibrarian,libopac,mandatory,repeatable from marc_tag_structure where frameworkcode=? order by tagfield"
     );
     $sth->execute($frameworkcode);
-    my ( $lib, $tag, $res, $tab, $mandatory, $repeatable );
+    my ( $liblibrarian, $libopac, $tag, $res, $tab, $mandatory, $repeatable );
 
-    while ( ( $tag, $lib, $mandatory, $repeatable ) = $sth->fetchrow ) {
-        $res->{$tag}->{lib}        = $lib;
+    while ( ( $tag, $liblibrarian, $libopac, $mandatory, $repeatable ) = $sth->fetchrow ) {
+        $res->{$tag}->{lib}        = ($forlibrarian or !$libopac)?$liblibrarian:$libopac;
         $res->{$tab}->{tab}        = "";            # XXX
         $res->{$tag}->{mandatory}  = $mandatory;
         $res->{$tag}->{repeatable} = $repeatable;
@@ -251,7 +257,7 @@ sub MARCgettagslib {
 
     $sth =
       $dbh->prepare(
-"select tagfield,tagsubfield,$libfield as lib,tab, mandatory, repeatable,authorised_value,authtypecode,value_builder,kohafield,seealso,hidden,isurl from marc_subfield_structure where frameworkcode=? order by tagfield,tagsubfield"
+"select tagfield,tagsubfield,liblibrarian,libopac,tab, mandatory, repeatable,authorised_value,authtypecode,value_builder,kohafield,seealso,hidden,isurl,link from marc_subfield_structure where frameworkcode=? order by tagfield,tagsubfield"
     );
     $sth->execute($frameworkcode);
 
@@ -263,16 +269,17 @@ sub MARCgettagslib {
     my $seealso;
     my $hidden;
     my $isurl;
+       my $link;
 
     while (
-        ( $tag,         $subfield,   $lib,              $tab,
+        ( $tag,         $subfield,   $liblibrarian,   , $libopac,      $tab,
         $mandatory,     $repeatable, $authorised_value, $authtypecode,
         $value_builder, $kohafield,  $seealso,          $hidden,
-        $isurl )
+        $isurl,                        $link )
         = $sth->fetchrow
       )
     {
-        $res->{$tag}->{$subfield}->{lib}              = $lib;
+        $res->{$tag}->{$subfield}->{lib}              = ($forlibrarian or !$libopac)?$liblibrarian:$libopac;
         $res->{$tag}->{$subfield}->{tab}              = $tab;
         $res->{$tag}->{$subfield}->{mandatory}        = $mandatory;
         $res->{$tag}->{$subfield}->{repeatable}       = $repeatable;
@@ -283,6 +290,7 @@ sub MARCgettagslib {
         $res->{$tag}->{$subfield}->{seealso}          = $seealso;
         $res->{$tag}->{$subfield}->{hidden}           = $hidden;
         $res->{$tag}->{$subfield}->{isurl}            = $isurl;
+        $res->{$tag}->{$subfield}->{link}            = $link;
     }
     return $res;
 }
@@ -290,13 +298,8 @@ sub MARCgettagslib {
 sub MARCfind_marc_from_kohafield {
     my ( $dbh, $kohafield,$frameworkcode ) = @_;
     return 0, 0 unless $kohafield;
-    my $sth =
-      $dbh->prepare(
-"select tagfield,tagsubfield from marc_subfield_structure where frameworkcode=? and kohafield=?"
-    );
-    $sth->execute($frameworkcode,$kohafield);
-    my ( $tagfield, $tagsubfield ) = $sth->fetchrow;
-    return ( $tagfield, $tagsubfield );
+       my $relations = C4::Context->marcfromkohafield;
+       return ($relations->{$frameworkcode}->{$kohafield}->[0],$relations->{$frameworkcode}->{$kohafield}->[1]);
 }
 
 sub MARCfind_oldbiblionumber_from_MARCbibid {
@@ -410,6 +413,7 @@ sub MARCaddsubfield {
         $tagorder, $subfieldcode, $subfieldorder, $subfieldvalues
       )
       = @_;
+         return unless $subfieldvalues;
 # warn "$tagid / $subfieldcode / $subfieldvalues";
     # if not value, end of job, we do nothing
 #     if ( length($subfieldvalues) == 0 ) {
@@ -473,6 +477,7 @@ sub MARCgetbiblio {
     # Returns MARC::Record of the biblio passed in parameter.
     my ( $dbh, $bibid ) = @_;
     my $record = MARC::Record->new();
+#      warn "". $bidid;
 
     #---- TODO : the leader is missing
     $record->leader('                        ');
@@ -702,37 +707,9 @@ sub MARCdelitem {
 
 sub MARCmoditem {
        my ($dbh,$record,$bibid,$itemnumber,$delete)=@_;
-
-       my $oldrecord=&MARCgetitem($dbh,$bibid,$itemnumber);
-       # if nothing to change, don't waste time...
-       if ($oldrecord eq $record) {
-               return;
-       }
-       # otherwise, skip through each subfield...
-       my @fields = $record->fields();
-       # search old MARC item
-       my $sth2 = $dbh->prepare("select tagorder from marc_subfield_table,marc_subfield_structure where marc_subfield_table.tag=marc_subfield_structure.tagfield and marc_subfield_table.subfieldcode=marc_subfield_structure.tagsubfield and bibid=? and kohafield='items.itemnumber' and subfieldvalue=?");
-       $sth2->execute($bibid,$itemnumber);
-       my ($tagorder) = $sth2->fetchrow_array();
-       foreach my $field (@fields) {
-               my $oldfield = $oldrecord->field($field->tag());
-               my @subfields=$field->subfields();
-               my $subfieldorder=0;
-               foreach my $subfield (@subfields) {
-                       $subfieldorder++;
-                       if ($oldfield eq 0 or (length($oldfield->subfield(@$subfield[0])) ==0) ) {
-               # just adding datas...
-                               &MARCaddsubfield($dbh,$bibid,$field->tag(),$field->indicator(1).$field->indicator(2),
-                                               $tagorder,@$subfield[0],$subfieldorder,@$subfield[1]);
-                       } else {
-               # modify he subfield if it's a different string
-                               if ($oldfield->subfield(@$subfield[0]) ne @$subfield[1] ) {
-                                       my $subfieldid=&MARCfindsubfieldid($dbh,$bibid,$field->tag(),$tagorder,@$subfield[0],$subfieldorder);
-                                       &MARCmodsubfield($dbh,$subfieldid,@$subfield[1]);
-                               }
-                       }
-               }
-       }
+       my $biblionumber = MARCfind_oldbiblionumber_from_MARCbibid($dbh,$bibid);
+       &MARCdelitem($dbh,$bibid,$itemnumber);
+       &MARCadditem($dbh,$record,$biblionumber);
 }
 
 sub MARCmodsubfield {
@@ -872,11 +849,26 @@ sub MARCdelsubfield {
 
     # delete a subfield for $bibid / tag / tagorder / subfield / subfieldorder
     my ( $dbh, $bibid, $tag, $tagorder, $subfield, $subfieldorder ) = @_;
-    $dbh->do( "delete from marc_subfield_table where bibid='$bibid' and
-                       tag='$tag' and tagorder='$tagorder'
-                       and subfieldcode='$subfield' and subfieldorder='$subfieldorder'
-                       "
-    );
+       if ($subfieldorder) {
+               $dbh->do( "delete from marc_subfield_table where bibid='$bibid' and
+                               tag='$tag' and tagorder='$tagorder'
+                               and subfieldcode='$subfield' and subfieldorder='$subfieldorder'
+                               "
+               );
+               $dbh->do( "delete from marc_word where bibid='$bibid' and
+                               tagsubfield='$tag$subfield' and tagorder='$tagorder'
+                               and subfieldorder='$subfieldorder'
+                               "
+               );
+       } else {
+               $dbh->do( "delete from marc_subfield_table where bibid='$bibid' and
+                               tag='$tag' and tagorder='$tagorder'
+                               and subfieldcode='$subfield'"
+               );
+               $dbh->do( "delete from marc_word where bibid='$bibid' and
+                               tagsubfield='$tag$subfield' and tagorder='$tagorder'"
+               );
+       }
 }
 
 sub MARCkoha2marcBiblio {
@@ -938,19 +930,19 @@ sub MARCkoha2marcBiblio {
         &MARCkoha2marcOnefield( $sth, $record, "additionalauthors.author",
             $row->{'author'},'' );
     }
-    my $sth2 =
+    $sth2 =
       $dbh->prepare(" SELECT subject FROM bibliosubject WHERE biblionumber=?");
     $sth2->execute($biblionumber);
     while ( my $row = $sth2->fetchrow_hashref ) {
         &MARCkoha2marcOnefield( $sth, $record, "bibliosubject.subject",
             $row->{'subject'},'' );
     }
-    my $sth2 =
+    $sth2 =
       $dbh->prepare(
         " SELECT subtitle FROM bibliosubtitle WHERE biblionumber=?");
     $sth2->execute($biblionumber);
     while ( my $row = $sth2->fetchrow_hashref ) {
-        &MARCkoha2marcOnefield( $sth, $record, "bibliosubtitle.title",
+        &MARCkoha2marcOnefield( $sth, $record, "bibliosubtitle.subtitle",
             $row->{'subtitle'},'' );
     }
     return $record;
@@ -1052,7 +1044,9 @@ sub MARChtml2marc {
                        $indicators{@$rtags[$i]}.='  ';
                        if (@$rtags[$i] <10) {
                                $prevvalue= @$rvalues[$i];
+                               undef $field;
                        } else {
+                               undef $prevvalue;
                                $field = MARC::Field->new( (sprintf "%03s",@$rtags[$i]), substr($indicators{@$rtags[$i]},0,1),substr($indicators{@$rtags[$i]},1,1), @$rsubfields[$i] => @$rvalues[$i]);
 #                      warn "1=>".@$rtags[$i].@$rsubfields[$i]." = ".@$rvalues[$i].": ".$field->as_formatted;
                        }
@@ -1070,7 +1064,7 @@ sub MARChtml2marc {
                }
        }
        # the last has not been included inside the loop... do it now !
-       $record->add_fields($field);
+       $record->add_fields($field) if $field;
 #      warn "HTML2MARC=".$record->as_formatted;
        return $record;
 }
@@ -1094,7 +1088,6 @@ sub MARCmarc2koha {
        $sth2=$dbh->prepare("SHOW COLUMNS from items");
        $sth2->execute;
        while (($field)=$sth2->fetchrow) {
-#      warn "X";
                $result=&MARCmarc2kohaOneField($sth,"items",$field,$record,$result,$frameworkcode);
        }
        # additional authors : specific
@@ -1110,7 +1103,7 @@ sub MARCmarc2koha {
                $result->{'copyrightdate'} = $1;
        }
 # modify publicationyear to keep only the 1st year found
-       my $temp = $result->{'publicationyear'};
+       $temp = $result->{'publicationyear'};
        $temp =~ m/c(\d\d\d\d)/; # search cYYYY first
        if ($1>0) {
                $result->{'publicationyear'} = $1;
@@ -1129,16 +1122,20 @@ sub MARCmarc2kohaOneField {
     my $res = "";
     my $tagfield;
     my $subfield;
-    $sth->execute($frameworkcode, $kohatable . "." . $kohafield );
-    ( $tagfield, $subfield ) = $sth->fetchrow;
+    ( $tagfield, $subfield ) = MARCfind_marc_from_kohafield("",$kohatable.".".$kohafield,$frameworkcode);
     foreach my $field ( $record->field($tagfield) ) {
-        if ( $field->subfield($subfield) ) {
-            if ( $result->{$kohafield} ) {
-                $result->{$kohafield} .= " | " . $field->subfield($subfield);
-            }
-            else {
-                $result->{$kohafield} = $field->subfield($subfield);
-            }
+        if ( $field->subfields ) {
+            my @subfields = $field->subfields();
+            foreach my $subfieldcount ( 0 .. $#subfields ) {
+                               if ($subfields[$subfieldcount][0] eq $subfield) {
+                                       if ( $result->{$kohafield} ) {
+                                               $result->{$kohafield} .= " | " . $subfields[$subfieldcount][1];
+                                       }
+                                       else {
+                                               $result->{$kohafield} = $subfields[$subfieldcount][1];
+                                       }
+                               }
+                       }
         }
     }
 #      warn "OneField for $kohatable.$kohafield and $frameworkcode=> $tagfield, $subfield";
@@ -1154,7 +1151,7 @@ sub MARCaddword {
         $subfieldid, $subfieldorder, $sentence
       )
       = @_;
-    $sentence =~ s/(\.|\?|\:|\!|\'|,|\-|\"|\(|\)|\[|\]|\{|\})/ /g;
+    $sentence =~ s/(\.|\?|\:|\!|\'|,|\-|\"|\(|\)|\[|\]|\{|\}|\/)/ /g;
     my @words = split / /, $sentence;
     my $stopwords = C4::Context->stopwords;
     my $sth       =
@@ -1225,7 +1222,7 @@ sub NEWnewbiblio {
         }
     }
     ( $tagfield, $tagsubfield ) =
-      MARCfind_marc_from_kohafield( $dbh, "bibliosubtitle.title",$frameworkcode );
+      MARCfind_marc_from_kohafield( $dbh, "bibliosubtitle.subtitle",$frameworkcode );
     my @subtitlefields = $record->field($tagfield);
     foreach my $subtitlefield (@subtitlefields) {
         my @subtitlesubfields = $subtitlefield->subfield($tagsubfield);
@@ -1280,6 +1277,12 @@ sub NEWnewbiblio {
     return ( $bibid, $oldbibnum, $oldbibitemnum );
 }
 
+sub NEWmodbiblioframework {
+       my ($dbh,$bibid,$frameworkcode) =@_;
+       my $sth = $dbh->prepare("Update marc_biblio SET frameworkcode=? WHERE bibid=$bibid");
+       $sth->execute($frameworkcode);
+       return 1;
+}
 sub NEWmodbiblio {
        my ($dbh,$record,$bibid,$frameworkcode) =@_;
        $frameworkcode="" unless $frameworkcode;
@@ -1300,8 +1303,13 @@ sub NEWmodbiblio {
        my @subtitlefields = $record->field($tagfield);
        foreach my $subtitlefield (@subtitlefields) {
                my @subtitlesubfields = $subtitlefield->subfield($tagsubfield);
+               # delete & create subtitle again because OLDmodsubtitle can't handle new subtitles
+               # between 2 modifs
+               $dbh->do("delete from bibliosubtitle where biblionumber=$oldbiblionumber");
                foreach my $subfieldcount (0..$#subtitlesubfields) {
-                       OLDmodsubtitle($dbh,$oldbiblionumber,$subtitlesubfields[$subfieldcount]);
+                       foreach my $subtit(split /\||#/,$subtitlesubfields[$subfieldcount]) {
+                               OLDnewsubtitle($dbh,$oldbiblionumber,$subtit);
+                       }
                }
        }
        ($tagfield,$tagsubfield) = MARCfind_marc_from_kohafield($dbh,"bibliosubject.subject",$frameworkcode);
@@ -1348,7 +1356,7 @@ sub NEWnewitem {
     my ( $itemnumber, $error ) = &OLDnewitems( $dbh, $item, $item->{barcode} );
 
     # add itemnumber to MARC::Record before adding the item.
-    my $sth =
+    $sth =
       $dbh->prepare(
 "select tagfield,tagsubfield from marc_subfield_structure where frameworkcode=? and kohafield=?"
     );
@@ -1458,13 +1466,14 @@ sub OLDnewbiblio {
     $sth->finish;
     $sth =
       $dbh->prepare(
-"insert into biblio set biblionumber  = ?, title = ?, author = ?, copyrightdate = ?, serial = ?, seriestitle = ?, notes = ?, abstract = ?"
+"insert into biblio set biblionumber  = ?, title = ?, author = ?, copyrightdate = ?, serial = ?, seriestitle = ?, notes = ?, abstract = ?, unititle = ?"
     );
     $sth->execute(
         $bibnum,             $biblio->{'title'},
         $biblio->{'author'}, $biblio->{'copyrightdate'},
         $biblio->{'serial'},             $biblio->{'seriestitle'},
-        $biblio->{'notes'},  $biblio->{'abstract'}
+        $biblio->{'notes'},  $biblio->{'abstract'},
+               $biblio->{'unititle'},
     );
 
     $sth->finish;
@@ -1597,13 +1606,12 @@ sub OLDmodsubject {
 
 sub OLDmodbibitem {
     my ( $dbh, $biblioitem ) = @_;
-
-    #    my $dbh   = C4Connect;
     my $query;
 
     $biblioitem->{'itemtype'}      = $dbh->quote( $biblioitem->{'itemtype'} );
     $biblioitem->{'url'}           = $dbh->quote( $biblioitem->{'url'} );
     $biblioitem->{'isbn'}          = $dbh->quote( $biblioitem->{'isbn'} );
+    $biblioitem->{'issn'}          = $dbh->quote( $biblioitem->{'issn'} );
     $biblioitem->{'publishercode'} =
       $dbh->quote( $biblioitem->{'publishercode'} );
     $biblioitem->{'publicationyear'} =
@@ -1623,6 +1631,7 @@ sub OLDmodbibitem {
 itemtype        = $biblioitem->{'itemtype'},
 url             = $biblioitem->{'url'},
 isbn            = $biblioitem->{'isbn'},
+issn            = $biblioitem->{'issn'},
 publishercode   = $biblioitem->{'publishercode'},
 publicationyear = $biblioitem->{'publicationyear'},
 classification  = $biblioitem->{'classification'},
@@ -1640,8 +1649,6 @@ where biblioitemnumber = $biblioitem->{'biblioitemnumber'}";
     if ( $dbh->errstr ) {
         warn "$query";
     }
-
-    #    $dbh->disconnect;
 }    # sub modbibitem
 
 sub OLDmodnote {
@@ -1716,7 +1723,7 @@ sub OLDnewsubtitle {
     my $sth =
       $dbh->prepare(
         "insert into bibliosubtitle set biblionumber = ?, subtitle = ?");
-    $sth->execute( $bibnum, $subtitle );
+    $sth->execute( $bibnum, $subtitle ) if $subtitle;
     $sth->finish;
 }
 
@@ -1797,17 +1804,12 @@ sub OLDmoditem {
 #  my ($dbh,$loan,$itemnum,$bibitemnum,$barcode,$notes,$homebranch,$lost,$wthdrawn,$replacement)=@_;
     #  my $dbh=C4Connect;
     $item->{'itemnum'} = $item->{'itemnumber'} unless $item->{'itemnum'};
-    my $query = "update items set  barcode=?,itemnotes=?,itemcallnumber=?,notforloan=? where itemnumber=?";
+    my $query = "update items set  barcode=?,itemnotes=?,itemcallnumber=?,notforloan=?,location=? where itemnumber=?";
     my @bind = (
         $item->{'barcode'},        $item->{'notes'},
         $item->{'itemcallnumber'}, $item->{'notforloan'},
-        $item->{'itemnum'}
+        $item->{'location'},      $item->{'itemnum'}
     );
-    if ( $item->{'barcode'} eq '' ) {
-        $item->{'notforloan'} = 0 unless $item->{'notforloan'};
-        $query = "update items set notforloan=? where itemnumber=?";
-        @bind = ( $item->{'notforloan'}, $item->{'itemnum'} );
-    }
     if ( $item->{'lost'} ne '' ) {
         $query = "update items set biblioitemnumber=?,
                              barcode=?,
@@ -1982,7 +1984,6 @@ sub newbiblio {
     my ($biblio) = @_;
     my $dbh    = C4::Context->dbh;
     my $bibnum = OLDnewbiblio( $dbh, $biblio );
-
     # finds new (MARC bibid
     #  my $bibid = &MARCfind_MARCbibid_from_oldbiblionumber($dbh,$bibnum);
     my $record = &MARCkoha2marcBiblio( $dbh, $bibnum );
@@ -2067,6 +2068,18 @@ sub modsubject {
     my ( $bibnum, $force, @subject ) = @_;
     my $dbh = C4::Context->dbh;
     my $error = &OLDmodsubject( $dbh, $bibnum, $force, @subject );
+        if ($error eq ''){
+    # When MARC is off, ensures that the MARC biblio table gets updated with new
+    # subjects, of course, it deletes the biblio in marc, and then recreates.
+    # This check is to ensure that no MARC data exists to lose.
+
+        if (C4::Context->preference("MARC") eq '0'){
+            my $MARCRecord = &MARCkoha2marcBiblio($dbh,$bibnum);
+            my $bibid = &MARCfind_MARCbibid_from_oldbiblionumber($dbh,$bibnum);
+            &MARCmodbiblio($dbh,$bibid, $MARCRecord);
+        }
+
+    }
     return ($error);
 }    # sub modsubject
 
@@ -2087,19 +2100,13 @@ sub newbiblioitem {
     my $dbh        = C4::Context->dbh;
     my $bibitemnum = &OLDnewbiblioitem( $dbh, $biblioitem );
 
-    ################################################################
-    ## Fix template and shift this to newbiblio
-    my @subjects = split ( /\n/, $biblioitem->{'subjectheadings'} );
-    modsubject( $biblioitem->{'biblionumber'}, 1, @subjects );
-
-    ################################################################
     my $MARCbiblio =
       MARCkoha2marcBiblio( $dbh, 0, $bibitemnum )
       ; # the 0 means "do NOT retrieve biblio, only biblioitem, in the MARC record
     my $bibid =
       &MARCfind_MARCbibid_from_oldbiblionumber( $dbh,
         $biblioitem->{biblionumber} );
-    &MARCaddbiblio( $dbh, $MARCbiblio, $biblioitem->{biblionumber}, $bibid );
+    &MARCaddbiblio( $dbh, $MARCbiblio, $biblioitem->{biblionumber}, '',$bibid );
     return ($bibitemnum);
 }
 
@@ -2528,6 +2535,138 @@ sub nsb_clean {
     return ($string);
 }
 
+sub FindDuplicate {
+       my ($record)=@_;
+       my $dbh = C4::Context->dbh;
+       my $result = MARCmarc2koha($dbh,$record,'');
+       my $sth;
+       my ($biblionumber,$bibid,$title);
+       # search duplicate on ISBN, easy and fast...
+       if ($result->{isbn}) {
+               $sth = $dbh->prepare("select biblio.biblionumber,bibid,title from biblio,biblioitems,marc_biblio where biblio.biblionumber=biblioitems.biblionumber and marc_biblio.biblionumber=biblioitems.biblionumber and isbn=?");
+               $sth->execute($result->{'isbn'});
+               ($biblionumber,$bibid,$title) = $sth->fetchrow;
+               return $biblionumber,$bibid,$title if ($biblionumber);
+       }
+       # a more complex search : build a request for SearchMarc::catalogsearch()
+       my (@tags, @and_or, @excluding, @operator, @value, $offset,$length);
+       # search on biblio.title
+       my ($tag,$subfield) = MARCfind_marc_from_kohafield($dbh,"biblio.title","");
+       if ($record->field($tag)) {
+               if ($record->field($tag)->subfields($subfield)) {
+                       push @tags, "'".$tag.$subfield."'";
+                       push @and_or, "and";
+                       push @excluding, "";
+                       push @operator, "contains";
+                       push @value, $record->field($tag)->subfield($subfield);
+#                      warn "for title, I add $tag / $subfield".$record->field($tag)->subfield($subfield);
+               }
+       }
+       # ... and on biblio.author
+       ($tag,$subfield) = MARCfind_marc_from_kohafield($dbh,"biblio.author","");
+       if ($record->field($tag)) {
+               if ($record->field($tag)->subfields($subfield)) {
+                       push @tags, "'".$tag.$subfield."'";
+                       push @and_or, "and";
+                       push @excluding, "";
+                       push @operator, "contains";
+                       push @value, $record->field($tag)->subfield($subfield);
+#                      warn "for author, I add $tag / $subfield".$record->field($tag)->subfield($subfield);
+               }
+       }
+       # ... and on publicationyear.
+       ($tag,$subfield) = MARCfind_marc_from_kohafield($dbh,"biblioitems.publicationyear","");
+       if ($record->field($tag)) {
+               if ($record->field($tag)->subfields($subfield)) {
+                       push @tags, "'".$tag.$subfield."'";
+                       push @and_or, "and";
+                       push @excluding, "";
+                       push @operator, "=";
+                       push @value, $record->field($tag)->subfield($subfield);
+#                      warn "for publicationyear, I add $tag / $subfield".$record->field($tag)->subfield($subfield);
+               }
+       }
+       # ... and on size.
+       ($tag,$subfield) = MARCfind_marc_from_kohafield($dbh,"biblioitems.size","");
+       if ($record->field($tag)) {
+               if ($record->field($tag)->subfields($subfield)) {
+                       push @tags, "'".$tag.$subfield."'";
+                       push @and_or, "and";
+                       push @excluding, "";
+                       push @operator, "=";
+                       push @value, $record->field($tag)->subfield($subfield);
+#                      warn "for size, I add $tag / $subfield".$record->field($tag)->subfield($subfield);
+               }
+       }
+       # ... and on publisher.
+       ($tag,$subfield) = MARCfind_marc_from_kohafield($dbh,"biblioitems.publishercode","");
+       if ($record->field($tag)) {
+               if ($record->field($tag)->subfields($subfield)) {
+                       push @tags, "'".$tag.$subfield."'";
+                       push @and_or, "and";
+                       push @excluding, "";
+                       push @operator, "=";
+                       push @value, $record->field($tag)->subfield($subfield);
+#                      warn "for publishercode, I add $tag / $subfield".$record->field($tag)->subfield($subfield);
+               }
+       }
+       # ... and on volume.
+       ($tag,$subfield) = MARCfind_marc_from_kohafield($dbh,"biblioitems.volume","");
+       if ($record->field($tag)) {
+               if ($record->field($tag)->subfields($subfield)) {
+                       push @tags, "'".$tag.$subfield."'";
+                       push @and_or, "and";
+                       push @excluding, "";
+                       push @operator, "=";
+                       push @value, $record->field($tag)->subfield($subfield);
+#                      warn "for volume, I add $tag / $subfield".$record->field($tag)->subfield($subfield);
+               }
+       }
+
+       my ($finalresult,$nbresult) = C4::SearchMarc::catalogsearch($dbh,\@tags,\@and_or,\@excluding,\@operator,\@value,0,10);
+       # there is at least 1 result => return the 1st one
+       if ($nbresult) {
+#              warn "$nbresult => ".@$finalresult[0]->{biblionumber},@$finalresult[0]->{bibid},@$finalresult[0]->{title};
+               return @$finalresult[0]->{biblionumber},@$finalresult[0]->{bibid},@$finalresult[0]->{title};
+       }
+       # no result, returns nothing
+       return;
+}
+sub DisplayISBN {
+       my ($isbn)=@_;
+       my $seg1;
+       if(substr($isbn, 0, 1) <=7) {
+               $seg1 = substr($isbn, 0, 1);
+       } elsif(substr($isbn, 0, 2) <= 94) {
+               $seg1 = substr($isbn, 0, 2);
+       } elsif(substr($isbn, 0, 3) <= 995) {
+               $seg1 = substr($isbn, 0, 3);
+       } elsif(substr($isbn, 0, 4) <= 9989) {
+               $seg1 = substr($isbn, 0, 4);
+       } else {
+               $seg1 = substr($isbn, 0, 5);
+       }
+       my $x = substr($isbn, length($seg1));
+       my $seg2;
+       if(substr($x, 0, 2) <= 19) {
+#              if(sTmp2 < 10) sTmp2 = "0" sTmp2;
+               $seg2 = substr($x, 0, 2);
+       } elsif(substr($x, 0, 3) <= 699) {
+               $seg2 = substr($x, 0, 3);
+       } elsif(substr($x, 0, 4) <= 8399) {
+               $seg2 = substr($x, 0, 4);
+       } elsif(substr($x, 0, 5) <= 89999) {
+               $seg2 = substr($x, 0, 5);
+       } elsif(substr($x, 0, 6) <= 9499999) {
+               $seg2 = substr($x, 0, 6);
+       } else {
+               $seg2 = substr($x, 0, 7);
+       }
+       my $seg3=substr($x,length($seg2));
+       $seg3=substr($seg3,0,length($seg3)-1) ;
+       my $seg4 = substr($x, -1, 1);
+       return "$seg1-$seg2-$seg3-$seg4";
+}
 END { }    # module clean-up code here (global destructor)
 
 =back
@@ -2542,6 +2681,95 @@ Paul POULAIN paul.poulain@free.fr
 
 # $Id$
 # $Log$
+# Revision 1.121  2005/06/20 14:10:00  tipaul
+# synch'ing 2.2 and head
+#
+# Revision 1.120  2005/06/15 16:09:43  hdl
+# Displaying dashed isbn.
+#
+# Revision 1.119  2005/06/01 20:43:58  genjimoto
+# patch from Genji (Waylon R.) to update subjects in MARC tables when systempref has MARC=OFF
+#
+# Revision 1.118  2005/05/04 15:40:01  tipaul
+# synch'ing 2.2 and head
+#
+# Revision 1.115.2.9  2005/04/07 10:05:25  tipaul
+# adding / to the list of symbols that are replace by spaces for searches
+#
+# Revision 1.115.2.8  2005/03/25 16:23:49  tipaul
+# some improvements :
+# * return immediatly when a subfield is empty
+# * search duplicate on isbn must be done only when there is an isbn ;-)
+#
+# Revision 1.115.2.7  2005/03/10 15:52:28  tipaul
+# * adding glass to opac marc detail.
+# * changing glasses behaviour : It now appears only on subfields that have a "link" value. Avoid useless glasses and removes nothing. **** WARNING **** : if you don't change you MARC parameters, glasses DISAPPEAR, because no subfields have a link value. So you MUST "reactivate" them manually. If you want to enable the search glass on field 225$a (collection in UNIMARC), just put 225a to "link" field (Koha >> parameters >> framework >> 225 field >> subfield >> modify $a >> enter 225a in link input field (without quotes or anything else)
+# * fixing bug with libopac
+#
+# Revision 1.115.2.6  2005/03/09 15:56:01  tipaul
+# Changing MARCmoditem to be like MARCmodbiblio : a modif is a delete & create.
+# Longer, but solves problems with repeated subfields.
+#
+# The previous version was not buggy except under certain circumstances (a repeated subfield, that does not exist usually in items)
+#
+# Revision 1.115.2.5  2005/02/24 13:54:04  tipaul
+# exporting MARCdelsubfield sub. It's used in authority merging.
+# Modifying it too to enable deletion of all subfields from a given tag/subfield or just one.
+#
+# Revision 1.115.2.4  2005/02/17 12:44:25  tipaul
+# bug in acquisition : the title was also stored as subtitle.
+#
+# Revision 1.115.2.3  2005/02/10 13:14:36  tipaul
+# * multiple main authors are now correctly handled in simple (non-MARC) view
+#
+# Revision 1.115.2.2  2005/01/11 16:02:35  tipaul
+# in catalogue, modifs were not stored properly the non-MARC item DB. Affect only libraries without barcodes.
+#
+# Revision 1.115.2.1  2005/01/11 14:45:37  tipaul
+# bugfix : issn were not stored correctly in non-MARC DB on biblio modification
+#
+# Revision 1.115  2005/01/06 14:32:17  tipaul
+# improvement of speed for bulkmarcimport.
+# A sub had been forgotten to use the C4::Context->marcfromkohafield array, that caches DB datas.
+# this is only a little improvement for normal DB modif, but almost x2 the speed of bulkmarcimport... from 6records/seconds to more than 10.
+#
+# Revision 1.114  2005/01/03 10:48:33  tipaul
+# * bugfix for the search on a MARC detail, when you clic on the magnifying glass (caused an internal server error)
+# * partial support of the "linkage" MARC feature : if you enter a "link" on a MARC subfield, the magnifying glass won't search on the field, but on the linked field. I agree it's a partial support. Will be improved, but I need to investigate MARC21 & UNIMARC diffs on this topic.
+#
+# Revision 1.113  2004/12/10 16:27:53  tipaul
+# limiting the number of search term to 8. There was no limit before, but 8 words seems to be the upper limit mySQL can deal with (in less than a second. tested on a DB with 13 000 items)
+# In 2.4, a new DB structure will highly speed things and this limit will be removed.
+# FindDuplicate is activated again, the perf problems were due to this problem.
+#
+# Revision 1.112  2004/12/08 10:14:42  tipaul
+# * desactivate FindDuplicate
+# * fix from Genji
+#
+# Revision 1.111  2004/11/25 17:39:44  tipaul
+# removing useless &branches in package declaration
+#
+# Revision 1.110  2004/11/24 16:00:01  tipaul
+# removing sub branches (commited by chris for MARC=OFF bugfix, but sub branches is already in Acquisition.pm)
+#
+# Revision 1.109  2004/11/24 15:58:31  tipaul
+# * critical fix for acquisition (see RC3 release notes)
+# * critical fix for duplicate finder
+#
+# Revision 1.108  2004/11/19 19:41:22  rangi
+# Shifting branches() from deprecated C4::Catalogue to C4::Biblio
+# Allowing the non marc interface acquisitions to work.
+#
+# Revision 1.107  2004/11/05 10:15:27  tipaul
+# Improving FindDuplicate to find duplicate records on adding biblio
+#
+# Revision 1.106  2004/11/02 16:44:45  tipaul
+# new feature : checking for duplicate biblio.
+#
+# For instance, it's only done on ISBN only. Will be improved soon.
+#
+# When a duplicate is detected, the biblio is not saved, but the user is asked for a confirmations.
+#
 # Revision 1.105  2004/09/23 16:15:37  tipaul
 # indenting diff
 #