From 689fee1dd664bd8fa2c1c089b2f49bd7b8c5ef50 Mon Sep 17 00:00:00 2001 From: amillar Date: Tue, 28 May 2002 14:45:20 +0000 Subject: [PATCH] Add biblio using C4::Acquisitions newbiblio --- acqui.simple/marcimport.pl | 72 ++++++++++++++++++++++++++++---------- 1 file changed, 54 insertions(+), 18 deletions(-) diff --git a/acqui.simple/marcimport.pl b/acqui.simple/marcimport.pl index e71151aa33..076cb0c915 100755 --- a/acqui.simple/marcimport.pl +++ b/acqui.simple/marcimport.pl @@ -260,25 +260,21 @@ if ($input->param('insertnewrecord')) {

EOF } else { - my $q_title=$dbh->quote($input->param('title')); - my $q_subtitle=$dbh->quote($input->param('subtitle')); - my $q_author=$dbh->quote($input->param('author')); - my $q_copyrightdate=$dbh->quote($input->param('copyrightdate')); - my $q_seriestitle=$dbh->quote($input->param('seriestitle')); - $sth=$dbh->prepare("select biblionumber from biblio where title=$q_title and author=$q_author and copyrightdate=$q_copyrightdate and seriestitle=$q_seriestitle"); - $sth->execute; - if ($sth->rows) { - ($biblionumber) = $sth->fetchrow; - } else { - $sth=$dbh->prepare("select max(biblionumber) from biblio"); - $sth->execute; - ($biblionumber) = $sth->fetchrow; - $biblionumber++; - $sth=$dbh->prepare("insert into biblio (biblionumber, title, author, copyrightdate, seriestitle) values ($biblionumber, $q_title, $q_author, $q_copyrightdate, $q_seriestitle)"); - $sth->execute; - $sth=$dbh->prepare("insert into bibliosubtitle (biblionumber,subtitle) values ($biblionumber, $q_subtitle)"); - $sth->execute; + use strict; + + # It doesn't exist; add it. + + $biblionumber=GetOrAddBiblio($dbh, + { title =>$input->param('title'), + author =>$input->param('author'), + copyright =>$input->param('copyrightdate'), + seriestitle =>$input->param('seriestitle'), + notes =>$input->param('notes'), + abstract =>$input->param('abstract'), + subtitle =>$input->param('subtitle'), } + ); + $sth=$dbh->prepare("select max(biblioitemnumber) from biblioitems"); $sth->execute; ($biblioitemnumber) = $sth->fetchrow; @@ -394,6 +390,42 @@ print endpage(); exit; } +#--------------------------------------- +# Find a biblio entry, or create a new one if it doesn't exist. +sub GetOrAddBiblio { + use strict; # in here until rest cleaned up + # input params + my ( + $dbh, # db handle + $biblio, # hash ref to fields + )=@_; + + # return + my $biblionumber; + + my $sth; + + #----- + $sth=$dbh->prepare("select biblionumber + from biblio + where title=? and author=? + and copyrightdate=? and seriestitle=?"); + $sth->execute( + $biblio->{title}, $biblio->{author}, + $biblio->{copyright}, $biblio->{seriestitle} ); + if ($sth->rows) { + ($biblionumber) = $sth->fetchrow; + } else { + # Doesn't exist. Add new one. + $biblionumber=&newbiblio($biblio); + &newsubtitle($biblionumber,$biblio->{subtitle} ); + } + + return $biblionumber; + +} # sub GetOrAddBiblio +#--------------------------------------- + if ($input->param('newitem')) { use strict; my $error; @@ -419,6 +451,10 @@ if ($input->param('newitem')) { ); if ( $error ) { print "Error: $error

\n"; + } else { + + print "Item added with barcode $barcode +

\n"; } # if error } # if barcode exists } -- 2.39.5