From 18359015f36a00ec301bfcfbce20c5cb1e64e81e Mon Sep 17 00:00:00 2001 From: amillar Date: Wed, 22 May 2002 06:45:30 +0000 Subject: [PATCH] Add biblio using C4::Acquisitions newbiblio --- acqui.simple/marcimport.pl | 74 ++++++++++++++++++++++++++++++++++------------ 1 file changed, 55 insertions(+), 19 deletions(-) diff --git a/acqui.simple/marcimport.pl b/acqui.simple/marcimport.pl index 5df3765e6b..e39c493fa4 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.11.0