3 # Copyright 2000-2002 Katipo Communications
5 # This file is part of Koha.
7 # Koha is free software; you can redistribute it and/or modify it under the
8 # terms of the GNU General Public License as published by the Free Software
9 # Foundation; either version 2 of the License, or (at your option) any later
12 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License along with
17 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
18 # Suite 330, Boston, MA 02111-1307 USA
22 use MARC::File::USMARC;
25 use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
27 # set the version for version checking
32 C4::Breeding : script to add a biblio in marc_breeding table.
37 &ImportBreeding($marcrecords,$);
41 This module doesn't do anything.
46 @EXPORT = qw(&ImportBreeding);
49 my ($marcrecords,$overwrite_biblio,$filename) = @_;
50 my @marcarray = split /\x1D/, $marcrecords;
51 my $dbh = C4::Context->dbh;
52 my $searchisbn = $dbh->prepare("select biblioitemnumber from biblioitems where isbn=?");
53 my $searchissn = $dbh->prepare("select biblioitemnumber from biblioitems where issn=?");
54 my $searchbreeding = $dbh->prepare("select id from marc_breeding where isbn=?");
55 my $insertsql = $dbh->prepare("insert into marc_breeding (file,isbn,title,author,marc) values(?,?,?,?,?)");
56 my $replacesql = $dbh->prepare("update marc_breeding set file=?,isbn=?,title=?,author=?,marc=? where id=?");
57 # fields used for import results
60 my $alreadyinfarm = 0;
61 my $notmarcrecord = 0;
62 for (my $i=0;$i<=$#marcarray;$i++) {
63 my $marcrecord = MARC::File::USMARC::decode($marcarray[$i]."\x1D");
64 if (ref($marcrecord) eq undef) {
67 my $oldbiblio = MARCmarc2koha($dbh,$marcrecord);
68 $oldbiblio->{title} = char_decode($oldbiblio->{title});
69 $oldbiblio->{author} = char_decode($oldbiblio->{author});
70 # if isbn found and biblio does not exist, add it. If isbn found and biblio exists, overwrite or ignore depending on user choice
71 # drop every "special" char : spaces, - ...
72 $oldbiblio->{isbn} =~ s/ |-|\.//g,
73 # search if biblio exists
75 if ($oldbiblio->{isbn}) {
76 $searchisbn->execute($oldbiblio->{isbn});
77 ($biblioitemnumber) = $searchisbn->fetchrow;
79 $searchissn->execute($oldbiblio->{issn});
80 ($biblioitemnumber) = $searchissn->fetchrow;
82 if ($biblioitemnumber) {
85 # search in breeding farm
87 if ($oldbiblio->{isbn}) {
88 $searchbreeding->execute($oldbiblio->{isbn});
89 ($breedingid) = $searchbreeding->fetchrow;
91 $searchbreeding->execute($oldbiblio->{issn});
92 ($breedingid) = $searchbreeding->fetchrow;
94 if (!$breedingid || $overwrite_biblio) {
96 $recoded = $marcrecord->as_usmarc();
98 $replacesql ->execute($filename,substr($oldbiblio->{isbn}.$oldbiblio->{issn},0,10),$oldbiblio->{title},$oldbiblio->{author},$recoded,$breedingid);
100 $insertsql ->execute($filename,substr($oldbiblio->{isbn}.$oldbiblio->{issn},0,10),$oldbiblio->{title},$oldbiblio->{author},$recoded);
109 return ($notmarcrecord,$alreadyindb,$alreadyinfarm,$imported);
112 END { } # module clean-up code here (global destructor)