From 64dae2746d16af60e7080f228fcde51798a8c938 Mon Sep 17 00:00:00 2001 From: tipaul Date: Wed, 24 Jul 2002 16:24:20 +0000 Subject: [PATCH] Now, the acqui.simple system... marcimport.pl has been almost completly rewritten, so LOT OF BUGS TO COME !!! You've been warned. It seems to work, but... As with my former messages, nothing seems to have been changed... but ... * marcimport now uses HTML::Template. * marcimport now uses MARC::Record. that means that when you import a record, the old-DB is populated with the data as in version 1.2, but the MARC-DB part is filled with full MARC::Record. to get correct response times, you MUST add an index on isbn, issn and lccn rows in biblioitem table. Note this should be done in 1.2 too... acqui.simple manage biblio, biblioitems and items tables quite properly. Normal acquisition system manages biblio, biblioitems BUT NOT items. That will be done in the near future... what's next now ? * bug tracking, of course... Surely a dozen of dozens... * LOT of developpments, i'll surely write a mail to koha-devel tomorrow (as it's time for dinner in France, and i plan to play NeverwinterNights after dinner ;-) ... --- acqui.simple/addbooks.pl | 11 + acqui.simple/addbookslccn.pl | 2 +- acqui.simple/additem.pl | 3 +- acqui.simple/bulkmarcimport.pl | 2 +- acqui.simple/isbnsearch.pl | 3 +- acqui.simple/keywordsearch.pl | 3 +- acqui.simple/marcimport.pl | 1551 ++++++++++++---------------------------- acqui.simple/savebiblio.pl | 3 +- acqui.simple/saveitem.pl | 3 +- acqui.simple/viewmarc.pl | 2 +- acqui.simple/websitesearch.pl | 3 +- 11 files changed, 466 insertions(+), 1120 deletions(-) diff --git a/acqui.simple/addbooks.pl b/acqui.simple/addbooks.pl index 958cbd477c..a8924376fe 100755 --- a/acqui.simple/addbooks.pl +++ b/acqui.simple/addbooks.pl @@ -1,14 +1,25 @@ #!/usr/bin/perl # +# Modified saas@users.sf.net 12:00 01 April 2001 +# The biblioitemnumber was not correctly initialised +# The max(barcode) value was broken - koha 'barcode' is a string value! +# - If left blank, barcode value now defaults to max(biblionumber) + +# # TODO # # Add info on biblioitems and items already entered as you enter new ones # +# Add info on biblioitems and items already entered as you enter new ones +use C4::Database; use CGI; use strict; +use C4::Catalogue; +use C4::Biblio; use C4::Output; +use C4::Circulation::Circ2; my $input = new CGI; my $error = $input->param('error'); diff --git a/acqui.simple/addbookslccn.pl b/acqui.simple/addbookslccn.pl index 04acec2e99..0f921af4cf 100755 --- a/acqui.simple/addbookslccn.pl +++ b/acqui.simple/addbookslccn.pl @@ -16,7 +16,7 @@ use C4::Database; use CGI; use strict; -use C4::Acquisitions; +use C4::Catalogue; use C4::Biblio; use C4::Output; use C4::Circulation::Circ2; diff --git a/acqui.simple/additem.pl b/acqui.simple/additem.pl index ab064b0ca1..0bf647edec 100755 --- a/acqui.simple/additem.pl +++ b/acqui.simple/additem.pl @@ -2,7 +2,8 @@ use CGI; use strict; -use C4::Acquisitions; +use C4::Catalogue; +use C4::Biblio; use C4::Output; my $input = new CGI; diff --git a/acqui.simple/bulkmarcimport.pl b/acqui.simple/bulkmarcimport.pl index e54d224f17..59120b227d 100755 --- a/acqui.simple/bulkmarcimport.pl +++ b/acqui.simple/bulkmarcimport.pl @@ -31,7 +31,7 @@ use C4::Database; use CGI; use DBI; #use strict; -use C4::Acquisitions; +use C4::Catalogue; use C4::Biblio; use C4::Output; my $dbh=C4Connect; diff --git a/acqui.simple/isbnsearch.pl b/acqui.simple/isbnsearch.pl index 55adb6db0f..ab111f44e2 100755 --- a/acqui.simple/isbnsearch.pl +++ b/acqui.simple/isbnsearch.pl @@ -2,7 +2,8 @@ use CGI; use strict; -use C4::Acquisitions; +use C4::Catalogue; +use C4::Biblio; use C4::Search; use C4::Output; diff --git a/acqui.simple/keywordsearch.pl b/acqui.simple/keywordsearch.pl index fef1a13cab..07a88da627 100755 --- a/acqui.simple/keywordsearch.pl +++ b/acqui.simple/keywordsearch.pl @@ -2,7 +2,8 @@ use CGI; use strict; -use C4::Acquisitions; +use C4::Catalogue; +use C4::Biblio; use C4::Search; use C4::Output; diff --git a/acqui.simple/marcimport.pl b/acqui.simple/marcimport.pl index f94397505c..874f8fff9b 100755 --- a/acqui.simple/marcimport.pl +++ b/acqui.simple/marcimport.pl @@ -1,13 +1,15 @@ #!/usr/bin/perl +# $Id$ + # Script for handling import of MARC data into Koha db # and Z39.50 lookups # Koha library project www.koha.org # Licensed under the GPL + use strict; -#use strict; # standard or CPAN modules used use CGI; @@ -17,100 +19,39 @@ use DBI; use C4::Database; use C4::Acquisitions; use C4::Output; - use C4::Input; use C4::Biblio; +use C4::SimpleMarc; +use C4::Z3950; +use MARC::File::USMARC; +use HTML::Template; #------------------ # Constants +my %configfile; +open (KC, "/etc/koha.conf"); +while () { + chomp; + (next) if (/^\s*#/); + if (/(.*)\s*=\s*(.*)/) { + my $variable=$1; + my $value=$2; + # Clean up white space at beginning and end + $variable=~s/^\s*//g; + $variable=~s/\s*$//g; + $value=~s/^\s*//g; + $value=~s/\s*$//g; + $configfile{$variable}=$value; + } +} +my $includes=$configfile{'includes'}; +($includes) || ($includes="/usr/local/www/hdl/htdocs/includes"); + # HTML colors for alternating lines my $lc1='#dddddd'; my $lc2='#ddaaaa'; -my %tagtext = ( - '001' => 'Control number', - '003' => 'Control number identifier', - '005' => 'Date and time of latest transaction', - '006' => 'Fixed-length data elements -- additional material characteristics', - '007' => 'Physical description fixed field', - '008' => 'Fixed length data elements', - '010' => 'LCCN', - '015' => 'LCCN Cdn', - '020' => 'ISBN', - '022' => 'ISSN', - '037' => 'Source of acquisition', - '040' => 'Cataloging source', - '041' => 'Language code', - '043' => 'Geographic area code', - '050' => 'Library of Congress call number', - '060' => 'National Library of Medicine call number', - '082' => 'Dewey decimal call number', - '100' => 'Main entry -- Personal name', - '110' => 'Main entry -- Corporate name', - '130' => 'Main entry -- Uniform title', - '240' => 'Uniform title', - '245' => 'Title statement', - '246' => 'Varying form of title', - '250' => 'Edition statement', - '256' => 'Computer file characteristics', - '260' => 'Publication, distribution, etc.', - '263' => 'Projected publication date', - '300' => 'Physical description', - '306' => 'Playing time', - '440' => 'Series statement / Added entry -- Title', - '490' => 'Series statement', - '500' => 'General note', - '504' => 'Bibliography, etc. note', - '505' => 'Formatted contents note', - '508' => 'Creation/production credits note', - '510' => 'Citation/references note', - '511' => 'Participant or performer note', - '520' => 'Summary, etc. note', - '521' => 'Target audience note (ie age)', - '530' => 'Additional physical form available note', - '538' => 'System details note', - '586' => 'Awards note', - '600' => 'Subject added entry -- Personal name', - '610' => 'Subject added entry -- Corporate name', - '650' => 'Subject added entry -- Topical term', - '651' => 'Subject added entry -- Geographic name', - '656' => 'Index term -- Occupation', - '700' => 'Added entry -- Personal name', - '710' => 'Added entry -- Corporate name', - '730' => 'Added entry -- Uniform title', - '740' => 'Added entry -- Uncontrolled related/analytical title', - '800' => 'Series added entry -- Personal name', - '830' => 'Series added entry -- Uniform title', - '852' => 'Location', - '856' => 'Electronic location and access', -); - -# tag, subfield, field name, repeats, striptrailingchars -my %tagmap=( - '010'=>{'a'=>{name=> 'lccn', rpt=>0 }}, - '015'=>{'a'=>{name=> 'lccn', rpt=>0 }}, - '020'=>{'a'=>{name=> 'isbn', rpt=>0 }}, - '022'=>{'a'=>{name=> 'issn', rpt=>0 }}, - '082'=>{'a'=>{name=> 'dewey', rpt=>0 }}, - '100'=>{'a'=>{name=> 'author', rpt=>0, striptrail=>',:;/-' }}, - '245'=>{'a'=>{name=> 'title', rpt=>0, striptrail=>',:;/' }, - 'b'=>{name=> 'subtitle', rpt=>0, striptrail=>',:;/' }}, - '260'=>{'a'=>{name=> 'place', rpt=>0, striptrail=>',:;/-' }, - 'b'=>{name=> 'publisher', rpt=>0, striptrail=>',:;/-' }, - 'c'=>{name=> 'year' , rpt=>0, striptrail=>'.,:;/-' }}, - '300'=>{'a'=>{name=> 'pages', rpt=>0, striptrail=>',:;/-' }, - 'c'=>{name=> 'size', rpt=>0, striptrail=>',:;/-' }}, - '362'=>{'a'=>{name=> 'volume-number', rpt=>0 }}, - '440'=>{'a'=>{name=> 'seriestitle', rpt=>0, striptrail=>',:;/' }, - 'v'=>{name=> 'volume-number',rpt=>0 }}, - '490'=>{'a'=>{name=> 'seriestitle', rpt=>0, striptrail=>',:;/' }, - 'v'=>{name=> 'volume-number',rpt=>0 }}, - '700'=>{'a'=>{name=> 'addtional-author-illus',rpt=>1, striptrail=>',:;/' }}, - '5xx'=>{'a'=>{name=> 'notes', rpt=>1 }}, - '65x'=>{'a'=>{name=> 'subject', rpt=>1, striptrail=>'.,:;/-' }}, -); - #------------- #------------- # Initialize @@ -122,14 +63,22 @@ my $dbh=C4Connect; #------------- # Display output -print $input->header; -print startpage(); -print startmenu('acquisitions'); +#print $input->header; +#print startpage(); +#print startmenu('acquisitions'); + #------------- # Process input parameters + my $file=$input->param('file'); my $menu = $input->param('menu'); +# +# +# TODO : parameter decoding and function call is quite dirty. +# should be rewritten... +# +# if ($input->param('z3950queue')) { AcceptZ3950Queue($dbh,$input); } @@ -141,38 +90,35 @@ if ($input->param('uploadmarc')) { if ($input->param('insertnewrecord')) { # Add biblio item, and set up menu for adding item copies my ($biblionumber,$biblioitemnumber)=AcceptBiblioitem($dbh,$input); - ItemCopyForm($dbh,$input,$biblionumber,$biblioitemnumber); - print endmenu(); - print endpage(); exit; } - if ($input->param('newitem')) { # Add item copy &AcceptItemCopy($dbh,$input); + exit; } # if newitem + if ($file) { ProcessFile($dbh,$input); } else { -SWITCH: + SWITCH: { if ($menu eq 'z3950') { z3950menu($dbh,$input); last SWITCH; } - if ($menu eq 'uploadmarc') { uploadmarc(); last SWITCH; } + if ($menu eq 'uploadmarc') { uploadmarc($dbh); last SWITCH; } if ($menu eq 'manual') { manual(); last SWITCH; } mainmenu(); } - } -print endmenu(); -print endpage(); +#print endmenu(); +#print endpage(); +# Process a MARC file : show list of records, of 1 record detail, if numrecord exists sub ProcessFile { # A MARC file has been specified; process it for review form use strict; - # Input params my ( $dbh, @@ -186,209 +132,91 @@ sub ProcessFile { ); my $debug=0; - my $splitchar=chr(29); requireDBI($dbh,"ProcessFile"); - print "Main Menu
\n"; - my $qisbn=$input->param('isbn'); - my $qissn=$input->param('issn'); - my $qlccn=$input->param('lccn'); - my $qcontrolnumber=$input->param('controlnumber'); - # See if a particular result item was specified - if ($qisbn || $qissn || $qlccn || $qcontrolnumber) { - print "New File
\n"; - #open (F, "$file"); - #my $data=; - my $data; - - if ($file=~/Z-(\d+)/) { - my $id=$1; - my $resultsid=$input->param('resultsid'); - my $sth=$dbh->prepare("select results from z3950results where id=$resultsid"); - $sth->execute; - ($data) = $sth->fetchrow; - } else { - my $sth=$dbh->prepare("select marc from uploadedmarc where id=$file"); - $sth->execute; - ($data) = $sth->fetchrow; - } - - my @records; - -RECORD: - foreach $record (split(/$splitchar/, $data)) { - - my ( - $bib, # hash ref to named fields - $fieldlist, # list ref - $lccn, $isbn, $issn, $dewey, - $publisher, $publicationyear, $volume, - $number, @subjects, $notes, $additionalauthors, - $copyrightdate, $seriestitle, - $origisbn, $origissn, $origlccn, $origcontrolnumber, - $subtitle, - $controlnumber, - $cleanauthor, - $subject, - $volumedate, - $volumeddesc, - $itemtypeselect, - ); - my ($lccninput, $isbninput, $issninput, $deweyinput, $authorinput, $titleinput, - $placeinput, $publisherinput, $publicationyearinput, $volumeinput, - $numberinput, $notesinput, $additionalauthorsinput, - $illustratorinput, $copyrightdateinput, $seriestitleinput, - $subtitleinput, - $copyrightinput, - $volumedateinput, - $volumeddescinput, - $subjectinput, - $noteinput, - $subclassinput, - $pubyearinput, - $pagesinput, - $sizeinput, - $marcinput, - $fileinput, - ); - - - my $marctext; - - my $marc=$record; - - ($fieldlist)=parsemarcfileformat($record ); - - $bib=extractmarcfields($fieldlist ); - - print "Title=$bib->{title}\n" if $debug; - - $marctext=FormatMarcText($fieldlist); - - $controlnumber =$bib->{controlnumber}; - $lccn =$bib->{lccn}; - $isbn =$bib->{isbn}; - $issn =$bib->{issn}; - $publisher =$bib->{publisher}; - $publicationyear =$bib->{publicationyear}; - $copyrightdate =$bib->{copyrightdate}; - - $volume =$bib->{volume}; - $number =$bib->{number}; - $seriestitle =$bib->{seriestitle}; - $additionalauthors =$bib->{additionalauthors}; - $notes =$bib->{notes}; - - $titleinput=$input->textfield(-name=>'title', -default=>$bib->{title}, -size=>40); - $marcinput=$input->hidden(-name=>'marc', -default=>$marc); - $subtitleinput=$input->textfield(-name=>'subtitle', -default=>$bib->{subtitle}, -size=>40); - $authorinput=$input->textfield(-name=>'author', -default=>$bib->{author}); - $illustratorinput=$input->textfield(-name=>'illustrator', - -default=>$bib->{illustrator}); - $additionalauthorsinput=$input->textarea(-name=>'additionalauthors', -default=>$additionalauthors, -rows=>4, -cols=>20); - - my $subject=''; - foreach ( @{$bib->{subject} } ) { - $subject.="$_\n"; - print "
form subject=$subject
\n" if $debug; - } - $subjectinput=$input->textarea(-name=>'subject', - -default=>$subject, -rows=>4, -cols=>40); - - $noteinput=$input->textarea(-name=>'notes', - -default=>$notes, -rows=>4, -cols=>40, -wrap=>'physical'); - $copyrightinput=$input->textfield(-name=>'copyrightdate', -default=>$copyrightdate); - $seriestitleinput=$input->textfield(-name=>'seriestitle', -default=>$seriestitle); - $volumeinput=$input->textfield(-name=>'volume', -default=>$volume); - $volumedateinput=$input->textfield(-name=>'volumedate', -default=>$volumedate); - $volumeddescinput=$input->textfield(-name=>'volumeddesc', -default=>$volumeddesc); - $numberinput=$input->textfield(-name=>'number', -default=>$number); - $isbninput=$input->textfield(-name=>'isbn', -default=>$isbn); - $issninput=$input->textfield(-name=>'issn', -default=>$issn); - $lccninput=$input->textfield(-name=>'lccn', -default=>$lccn); - $isbninput=$input->textfield(-name=>'isbn', -default=>$isbn); - $deweyinput=$input->textfield(-name=>'dewey', -default=>$bib->{dewey}); - $cleanauthor=$bib->{author}; - $cleanauthor=~s/[^A-Za-z]//g; - $subclassinput=$input->textfield(-name=>'subclass', -default=>uc(substr($cleanauthor,0,3))); - $publisherinput=$input->textfield(-name=>'publishercode', -default=>$publisher); - $pubyearinput=$input->textfield(-name=>'publicationyear', -default=>$publicationyear); - $placeinput=$input->textfield(-name=>'place', -default=>$bib->{place}); - $pagesinput=$input->textfield(-name=>'pages', -default=>$bib->{pages}); - $sizeinput=$input->textfield(-name=>'size', -default=>$bib->{size}); - $fileinput=$input->hidden(-name=>'file', -default=>$file); - $origisbn=$input->hidden(-name=>'origisbn', -default=>$isbn); - $origissn=$input->hidden(-name=>'origissn', -default=>$issn); - $origlccn=$input->hidden(-name=>'origlccn', -default=>$lccn); - $origcontrolnumber=$input->hidden(-name=>'origcontrolnumber', -default=>$controlnumber); - - #print "
getting itemtypeselect
\n"; - $itemtypeselect=&getkeytableselectoptions( - $dbh, 'itemtypes', 'itemtype', 'description', 1); - #print "
it=$itemtypeselect
\n"; - - ($qissn) || ($qissn='NIL'); - ($qlccn) || ($qlccn='NIL'); - ($qisbn) || ($qisbn='NIL'); - ($qcontrolnumber) || ($qcontrolnumber='NIL'); - $controlnumber=~s/\s+//g; - - unless (($isbn eq $qisbn) || ($issn eq $qissn) || ($lccn eq $qlccn) || ($controlnumber eq $qcontrolnumber)) { - #print "
Skip record $isbn $issn $lccn 
\n"; - next RECORD; - } - - print << "EOF"; -
-

New Record

- Full MARC Record available at bottom -
- - - - - - - - - - - - - - - - - - - - - - - - - -
Title$titleinput
Subtitle$subtitleinput
Author$authorinput
Additional Authors$additionalauthorsinput
Illustrator$illustratorinput
Copyright$copyrightinput
Series Title$seriestitleinput
Volume$volumeinput
Number$numberinput
Volume Date$volumedateinput
Volume Description$volumeddescinput
Subject$subjectinput
Notes$noteinput
Item Type
ISBN$isbninput
ISSN$issninput
LCCN$lccninput
Dewey$deweyinput
Subclass$subclassinput
Publication Year$pubyearinput
Publisher$publisherinput
Place$placeinput
Pages$pagesinput
Size$sizeinput
- - - $fileinput - $marcinput - $origisbn - $origissn - $origlccn - $origcontrolnumber -
- $marctext -EOF - } # foreach record + my $numrecord = $input->param('numrecord'); + if ($numrecord) { + ProcessRecord($dbh,$input,$numrecord); } else { - # No result item specified, list results + # No result item specified, list results ListFileRecords($dbh,$input); } # if } # sub ProcessFile +# show 1 record from the MARC file +sub ProcessRecord { + my ($dbh, $input,$numrecord) = @_; + # local vars + my ( + $sth, + $record, + $data, + ); + + if ($file=~/Z-(\d+)/) { + my $id=$1; + my $resultsid=$input->param('resultsid'); + my $sth=$dbh->prepare("select results from z3950results where id=$resultsid"); + $sth->execute; + ($data) = $sth->fetchrow; + } else { + my $sth=$dbh->prepare("select marc from uploadedmarc where id=$file"); + $sth->execute; + ($data) = $sth->fetchrow; + } + + my $file=MARC::File::USMARC->indata ($data); + my $oldkoha; + for (my $i==1;$i<$numrecord;$i++) { + $record = $file->next; + } + if ($record) { + $oldkoha=MARCmarc2koha($dbh,$record); + } + my $templatebase="marcimport/marcimportdetail.tmpl"; + my $theme=picktemplate($includes, $templatebase); + my $template = HTML::Template->new(filename => "$includes/templates/$theme/$templatebase", die_on_bad_params => 0, path => [$includes]); + $oldkoha->{additionalauthors} =~ s/ \| /\n/g; + $oldkoha =~ s/\|/\n/g; + $template->param($oldkoha); +#---- build MARC array for template + my @loop = (); + my $tagmeaning = &MARCgettagslib($dbh,1); + my @fields = $record->fields(); + my $color=0; + my $lasttag=""; + foreach my $field (@fields) { + my @subfields=$field->subfields(); + foreach my $subfieldcount (0..$#subfields) { + my %row_data; + if ($lasttag== $field->tag()) { + $row_data{tagid} = ""; + } else { + $row_data{tagid} = $field->tag(); + } + $row_data{subfield} = $subfields[$subfieldcount][0]; + $row_data{tagmean} = $tagmeaning->{$field->tag()}->{$subfields[$subfieldcount][0]}; + $row_data{tagvalue}= $subfields[$subfieldcount][1]; + if ($color ==0) { + $color=1; + $row_data{color} = $lc1; + } else { + $color=0; + $row_data{color} = $lc2; + } + push(@loop,\%row_data); + $lasttag=$field->tag(); + } + } + $template->param(MARC => \@loop); + $template->param(numrecord => $numrecord); + $template->param(file => $data); + print "Content-Type: text/html\n\n", $template->output; +} + +# lists all records from the MARC file sub ListFileRecords { use strict; @@ -408,47 +236,37 @@ sub ListFileRecords { $serverdb, ); - my $z3950=0; - my $recordsource; - my $record; - my ($numrecords,$resultsid,$data,$startdate,$enddate); - + my $z3950=0; + my $recordsource; + my $record; + my ($numrecords,$resultsid,$data,$startdate,$enddate); + requireDBI($dbh,"ListFileRecords"); - # File can be z3950 search query or uploaded MARC data - - # if z3950 results - if ($file=~/Z-(\d+)/) { - # This is a z3950 search - $recordsource=''; - } else { - # This is a Marc upload - $sth=$dbh->prepare("select marc,name from uploadedmarc where id=$file"); - $sth->execute; - ($data, $name) = $sth->fetchrow; - $recordsource="from $name"; - } - - print << "EOF"; -
-

- Select a New File -

- - -
- Select a Record to Import $recordsource -
-EOF - - if ($file=~/Z-(\d+)/) { - # This is a z3950 search + my $templatebase="marcimport/ListFileRecords.tmpl"; + my $theme=picktemplate($includes, $templatebase); + my $template = HTML::Template->new(filename => "$includes/templates/$theme/$templatebase", die_on_bad_params => 0, path => [$includes]); - my $id=$1; # search query id number - my $serverstring; - my $starttimer=time(); + # File can be z3950 search query or uploaded MARC data + + # if z3950 results + if (not $file=~/Z-(\d+)/) { + # This is a Marc upload + $sth=$dbh->prepare("select marc,name from uploadedmarc where id=$file"); + $sth->execute; + ($data, $name) = $sth->fetchrow; + $template->param(IS_MARC => 1); + $template->param(recordsource => $name); + } - $sth=$dbh->prepare(" + if ($file=~/Z-(\d+)/) { + # This is a z3950 search + $template->param(IS_Z3950 =>1); + my $id=$1; # search query id number + my $serverstring; + my $starttimer=time(); + + $sth=$dbh->prepare(" select z3950results.numrecords,z3950results.id,z3950results.results, z3950results.startdate,z3950results.enddate,server from z3950queue left outer join z3950results @@ -456,16 +274,16 @@ EOF where z3950queue.id=? order by server "); - $sth->execute($id); - if ( $sth->rows ) { - # loop through all servers in search results - while ( ($numrecords,$resultsid,$data, - $startdate,$enddate,$serverstring) = $sth->fetchrow ) { + $sth->execute($id); + if ( $sth->rows ) { + # loop through all servers in search results + while ( ($numrecords,$resultsid,$data, + $startdate,$enddate,$serverstring) = $sth->fetchrow ) { my ($srvid, $server, $database, $auth) = split(/\//, $serverstring, 4); - #print "server=$serverstring\n"; if ( $server ) { - print " " . - &z3950servername($dbh,$srvid,"$server/$database") . "\n"; + my $srvname=&z3950servername($dbh,$srvid,"$server/$database"); + $template->parram(srvid => $srvid); + $template->param(srvname => $srvname); } # if $server my $startrecord=$input->param("ST-$srvid"); ($startrecord) || ($startrecord='0'); @@ -478,6 +296,7 @@ EOF $serverplaceholder.="\&ST-$serverid=$place"; } if ($numrecords) { + $template->param(HAS_NUMRECORDS => 1); my $previous=''; my $next=''; if ($startrecord>0) { @@ -489,17 +308,18 @@ EOF if ($numrecords>$startrecord+10) { $next="Next"; } - print "[Viewing ".($startrecord+1)." to ".$highest." of $numrecords records] $previous | $next
\n"; + $template->param(startrecord => $startrecord+1); + $template->param(highest => $highest); + $template->param(numrecords => $numrecords); + $template->param(previous => $previous); + $template->param(next => $next); my $stj=$dbh->prepare("update z3950results set highestseen=? where id=?"); $stj->execute($startrecord+10,$resultsid); - } else { - print "
\n"; } - print "
    \n"; if (! $server ) { - print "Search still pending..."; + $template->param(PENDING => 1); } elsif ($enddate == 0) { my $now=time(); my $elapsed=$now-$startdate; @@ -509,343 +329,96 @@ EOF } else { $elapsedtime=sprintf "%d seconds",$elapsed; } - print "processing... ($elapsedtime)"; + $template->param(elapsedtime => $elapsedtime); } elsif ($numrecords) { - my @records=parsemarcfileformat($data); - my $i; - for ($i=$startrecord; $i<$startrecord+10; $i++) { - $data.=$records[$i].$splitchar; - } - @records=parsemarcdata($data); - my $counter=0; - foreach $record (@records) { - $counter++; - #(next) unless ($counter>=$startrecord && $counter<=$startrecord+10); - my ($lccn, $isbn, $issn, $dewey, $author, $title, $place, $publisher, $publicationyear, $volume, $number, @subjects, $notes, $controlnumber); - foreach $field (@$record) { - if ($field->{'tag'} eq '001') { - $controlnumber=$field->{'indicator'}; - } - if ($field->{'tag'} eq '010') { - $lccn=$field->{'subfields'}->{'a'}; - $lccn=~s/^\s*//; - ($lccn) = (split(/\s+/, $lccn))[0]; - } - if ($field->{'tag'} eq '015') { - $lccn=$field->{'subfields'}->{'a'}; - $lccn=~s/^\s*//; - $lccn=~s/^C//; - ($lccn) = (split(/\s+/, $lccn))[0]; - } - if ($field->{'tag'} eq '020') { - $isbn=$field->{'subfields'}->{'a'}; - ($isbn=~/ARRAY/) && ($isbn=$$isbn[0]); - $isbn=~s/[^\d]*//g; - } - if ($field->{'tag'} eq '022') { - $issn=$field->{'subfields'}->{'a'}; - $issn=~s/^\s*//; - ($issn) = (split(/\s+/, $issn))[0]; - } - if ($field->{'tag'} eq '100') { - $author=$field->{'subfields'}->{'a'}; - } - if ($field->{'tag'} eq '245') { - $title=$field->{'subfields'}->{'a'}; - $title=~s/ \/$//; - $subtitle=$field->{'subfields'}->{'b'}; - $subtitle=~s/ \/$//; - } - } - my $q_isbn=$dbh->quote((($isbn) || ('NIL'))); - my $q_issn=$dbh->quote((($issn) || ('NIL'))); - my $q_lccn=$dbh->quote((($lccn) || ('NIL'))); - my $q_controlnumber=$dbh->quote((($controlnumber) || ('NIL'))); - my $sth=$dbh->prepare("select * from marcrecorddone where isbn=$q_isbn or issn=$q_issn or lccn=$q_lccn or controlnumber=$q_controlnumber"); - $sth->execute; - my $donetext=''; - if ($sth->rows) { - $donetext="DONE"; - } - $sth=$dbh->prepare("select * from biblioitems where isbn=$q_isbn or issn=$q_issn or lccn=$q_lccn"); - $sth->execute; - if ($sth->rows) { - $donetext="DONE"; - } - ($author) && ($author="by $author"); - if ($isbn) { - print "
  • $title $subtitle $author $donetext
    \n"; - } elsif ($lccn) { - print "
  • $title $subtitle $author $donetext
    \n"; - } elsif ($issn) { - print "
  • $title $subtitle $author
    $donetext\n"; - } elsif ($controlnumber) { - print "
  • $title $subtitle $author
    $donetext\n"; - } else { - print "Error: Contact steve regarding $title by $author
    \n"; - } + my @loop = (); + my $z3950file=MARC::File::USMARC->indata ($data); + while (my $record=$z3950file->next) { + my $oldkoha = MARCmarc2koha($dbh,$record); + my %row = ResultRecordLink($dbh,$oldkoha,$resultsid); + push(@loop,\%row); } - print "

    \n"; - } else { - if ( $records[$i] ) { - &PrintResultRecordLink($dbh,$records[$i],$resultsid); - } # if record - } # for records - print "

    \n"; + $template->param(LINES => \@loop); } else { - print "No records returned.

    \n"; } - print "

\n"; +# print "\n"; } # foreach server my $elapsed=time()-$starttimer; - print "
It took $elapsed seconds to process this page.\n"; +# print "
It took $elapsed seconds to process this page.\n"; } else { - print "No results found for query $id\n"; + $template->param(NO_RECORDS =>1); + $template->param(id => $id); } # if rows - } else { - # This is an uploaded Marc record - my @records=parsemarcfileformat($data); - foreach $record (@records) { - &PrintResultRecordLink($dbh,$record,''); - } # foreach record + } else { +# +# This is an uploaded Marc record +# + my @loop = (); + my $MARCfile = MARC::File::USMARC->indata($data); + my $num = 0; + while (my $record=$MARCfile->next) { + $num++; + my $oldkoha = MARCmarc2koha($dbh,$record); + my %row = ResultRecordLink($dbh,$oldkoha,'',$num); + push(@loop,\%row); + } + $template->param(LINES => \@loop); } # if z3950 or marc upload - print "
\n"; + print "Content-Type: text/html\n\n", $template->output; } # sub ListFileRecords #-------------- -sub z3950servername { - # inputs - my ( - $dbh, - $srvid, # server id number - $default, - )=@_; - # return - my $longname; - #---- - - requireDBI($dbh,"z3950servername"); - - my $sti=$dbh->prepare("select name - from z3950servers - where id=?"); - $sti->execute($srvid); - if ( ! $sti->err ) { - ($longname)=$sti->fetchrow; - } - if (! $longname) { - $longname="$default"; - } - return $longname; -} # sub z3950servername -sub PrintResultRecordLink { +sub ResultRecordLink { use strict; - my ($dbh,$record,$resultsid)=@_; # input - + my ($dbh,$oldkoha,$resultsid, $num)=@_; # input my ( $sth, $bib, # hash ref to named fields $searchfield, $searchvalue, $donetext, $fieldname, - ); - + ); + my %row = (); requireDBI($dbh,"PrintResultRecordLink"); - $bib=extractmarcfields($record); +# $bib=extractmarcfields($record); - $sth=$dbh->prepare("select * + $sth=$dbh->prepare("select * from biblioitems - where isbn=? or issn=? or lccn=? "); - $sth->execute($bib->{isbn},$bib->{issn},$bib->{lccn}); - if ($sth->rows) { - $donetext="DONE"; - } else { - $donetext=""; - } - ($bib->{author}) && ($bib->{author}="by $bib->{author}"); - - $searchfield=""; - foreach $fieldname ( "controlnumber", "lccn", "issn", "isbn") { - if ( defined $bib->{$fieldname} ) { - $searchfield=$fieldname; - $searchvalue=$bib->{$fieldname}; - } # if defined fieldname - } # foreach - - if ( $searchfield ) { - print "$bib->{title} $bib->{author}" . - " $donetext
\n"; - } else { - print "Error: Problem with $bib->{title} $bib->{author}
\n"; - } # if searchfield -} # sub PrintResultRecordLink - -#------------------ -sub extractmarcfields { - use strict; - # input - my ( - $record, # pointer to list of MARC field hashes. - # Example: $record->[0]->{'tag'} = '100' # Author - # $record->[0]->{'subfields'}->{'a'} = subfieldvalue - )=@_; - - # return - my $bib; # pointer to hash of named output fields - # Example: $bib->{'author'} = "Twain, Mark"; - - my $debug=0; - - my ( - $field, # hash ref - $value, - $subfield, # Marc subfield [a-z] - $fieldname, # name of field "author", "title", etc. - $strip, # chars to remove from end of field - $stripregex, # reg exp pattern - ); - my ($lccn, $isbn, $issn, - $publicationyear, @subjects, $subject, - $controlnumber, - $notes, $additionalauthors, $illustrator, $copyrightdate, - $s, $subdivision, $subjectsubfield, - ); - - print "

\n" if $debug;
-
-    if ( ref($record) eq "ARRAY" ) {
-        foreach $field (@$record) {
-
-	    # Check each subfield in field
-	    foreach $subfield ( keys %{$field->{subfields}} ) {
-		# see if it is defined in our Marc to koha mapping table
-	    	if ( $fieldname=$tagmap{ $field->{'tag'} }->{$subfield}->{name} ) {
-		    # Yes, so keep the value
-		    if ( ref($field->{'subfields'}->{$subfield} ) eq 'ARRAY' ) {
-		        # if it was an array, just keep first element.
-		        $bib->{$fieldname}=$field->{'subfields'}->{$subfield}[0];
-		    } else {
-		        $bib->{$fieldname}=$field->{'subfields'}->{$subfield};
-		    } # if array
-		    print "$field->{'tag'} $subfield $fieldname=$bib->{$fieldname}\n" if $debug;
-		    # see if this field should have trailing chars dropped
-	    	    if ($strip=$tagmap{ $field->{'tag'} }->{$subfield}->{striptrail} ) {
-			$strip=~s//\\/; # backquote each char
-			$stripregex='[ ' . $strip . ']+$';  # remove trailing spaces also
-			$bib->{$fieldname}=~s/$stripregex//;
-		    } # if strip
-		    print "Found subfield $field->{'tag'} $subfield " .
-			"$fieldname = $bib->{$fieldname}\n" if $debug;
-		} # if tagmap exists
-
-	    } # foreach subfield
-
-
-	    if ($field->{'tag'} eq '001') {
-		$bib->{controlnumber}=$field->{'indicator'};
-	    }
-	    if ($field->{'tag'} eq '015') {
-		$bib->{lccn}=$field->{'subfields'}->{'a'};
-		$bib->{lccn}=~s/^\s*//;
-		$bib->{lccn}=~s/^C//;
-		($bib->{lccn}) = (split(/\s+/, $bib->{lccn}))[0];
-	    }
-
-
-		if ($field->{'tag'} eq '260') {
-
-		    $publicationyear=$field->{'subfields'}->{'c'};
-		    if ($publicationyear=~/c(\d\d\d\d)/) {
-			$copyrightdate=$1;
-		    }
-		    if ($publicationyear=~/[^c](\d\d\d\d)/) {
-			$publicationyear=$1;
-		    } elsif ($copyrightdate) {
-			$publicationyear=$copyrightdate;
-		    } else {
-			$publicationyear=~/(\d\d\d\d)/;
-			$publicationyear=$1;
-		    }
-		}
-		if ($field->{'tag'} eq '700') {
-		    my $name=$field->{'subfields'}->{'a'};
-		    if ($field->{'subfields'}->{'e'}!~/ill/) {
-			$additionalauthors.="$name\n";
-		    } else {
-			$illustrator=$name;
-		    }
-		}
-		if ($field->{'tag'} =~/^5/) {
-		    $notes.="$field->{'subfields'}->{'a'}\n";
-		}
-		if ($field->{'tag'} =~/65\d/) {
-		    my $sub;
-		    my $subject=$field->{'subfields'}->{'a'};
-		    $subject=~s/\.$//;
-		    print "Subject=$subject\n" if $debug;
-		    foreach $subjectsubfield ( 'x','y','z' ) {
-		      if ($subdivision=$field->{'subfields'}->{$subjectsubfield}) {
-			if ( ref($subdivision) eq 'ARRAY' ) {
-			    foreach $s (@$subdivision) {
-				$s=~s/\.$//;
-				$subject.=" -- $s";
-			    } # foreach subdivision
-			} else {
-			    $subdivision=~s/\.$//;
-			    $subject.=" -- $subdivision";
-			} # if array
-		      } # if subfield exists
-		    } # foreach subfield
-		    print "Subject=$subject\n" if $debug;
-		    push @subjects, $subject;
-		} # if tag 65x
-
-
-        } # foreach field
-	($publicationyear	) && ($bib->{publicationyear}=$publicationyear  );
-	($copyrightdate		) && ($bib->{copyrightdate}=$copyrightdate  );
-	($additionalauthors	) && ($bib->{additionalauthors}=$additionalauthors  );
-	($illustrator		) && ($bib->{illustrator}=$illustrator  );
-	($notes			) && ($bib->{notes}=$notes  );
-	($#subjects		) && ($bib->{subject}=\@subjects  );
-
-	# Misc cleanup
-	$bib->{dewey}=~s/\///g;	# drop any slashes
-
-	($bib->{lccn}) = (split(/\s+/, $bib->{lccn}))[0]; # only keep first word
-
-	$bib->{isbn}=~s/[^\d]*//g;	# drop non-digits
-
-	$bib->{issn}=~s/^\s*//;
-	($bib->{issn}) = (split(/\s+/, $bib->{issn}))[0];
-
-	if ( $bib->{'volume-number'} ) {
-	    if ($bib->{'volume-number'}=~/(\d+).*(\d+)/ ) {
-		$bib->{'volume'}=$1;
-		$bib->{'number'}=$2;
-	    } else {
-		$bib->{volume}=$bib->{'volume-number'};
-	    }
-	    delete $bib->{'volume-number'};
-	} # if volume-number
-
+	  where (isbn=? and isbn!='')  or (issn=? and issn!='')  or (lccn=? and lccn!='') ");
+    $sth->execute($oldkoha->{isbn},$oldkoha->{issn},$oldkoha->{lccn});
+    if ($sth->rows) {
+	$donetext="DONE";
     } else {
-	print "Error: extractmarcfields: input ref $record is " .
-		ref($record) . " not ARRAY. Contact sysadmin.\n";
+	$donetext="";
     }
-    print "
\n" if $debug; - - return $bib; + ($oldkoha->{author}) && ($oldkoha->{author}="by $oldkoha->{author}"); + + $searchfield=""; + foreach $fieldname ( "controlnumber", "lccn", "issn", "isbn") { + if ( defined $oldkoha->{$fieldname} && $oldkoha->{$fieldname} ) { + $searchfield=$fieldname; + $searchvalue=$oldkoha->{$fieldname}; + } # if defined fieldname + } # foreach + if ( $searchfield ) { + $row{SCRIPT_NAME} = $ENV{'SCRIPT_NAME'}; + $row{donetext} = $donetext; + $row{file} = $file; +# $row{resultsid} = $resultsid; +# $row{searchfield} = $searchfield; +# $row{searchvalue} = $searchvalue; + $row{numrecord} = $num; + $row{title} = $oldkoha->{title}; + $row{author} = $oldkoha->{author}; + } else { + $row{title} = "Error: Problem with
$bib->{title} $bib->{author}
"; + } # if searchfield + return %row; +} # sub PrintResultRecordLink -} # sub extractmarcfields #--------------------------------- sub z3950menu { @@ -1000,32 +573,25 @@ sub uploadmarc { requireDBI($dbh,"uploadmarc"); - print "Main Menu
\n"; + my $templatebase="marcimport/uploadmarc.tmpl"; + my $theme=picktemplate($includes, $templatebase); + my $template = HTML::Template->new(filename => "$includes/templates/$theme/$templatebase", die_on_bad_params => 0, path => [$includes]); + $template->param(SCRIPT_NAME => $ENV{'SCRIPT_NAME'}); +# print "Main Menu
\n"; my $sth=$dbh->prepare("select id,name from uploadedmarc"); $sth->execute; - print "

Select a set of MARC records

\n
    "; +# print "

    Select a set of MARC records

    \n
      "; + my @marc_loop = (); while (my ($id, $name) = $sth->fetchrow) { - print "
    • $name
      \n"; + my %row; + $row{id} = $id; + $row{name} = $name; + push(@marc_loop, \%row); +# print "
    • $name
      \n"; } - print "
    \n"; - print "

    \n"; - print "\n"; - print " - - -
    Upload a set of MARC records
    Upload a set of MARC records:"; - print $input->start_multipart_form(); - print $input->filefield('uploadmarc'); - print << "EOF"; -
    - - Name this set of MARC records:
    - -
    - -EOF + $template->param(marc => \@marc_loop); + print "Content-Type: text/html\n\n", $template->output; + } sub manual { @@ -1033,114 +599,13 @@ sub manual { sub mainmenu { - print << "EOF"; -

    Main Menu

    - -EOF + my $templatebase="marcimport/mainmenu.tmpl"; + my $theme=picktemplate($includes, $templatebase); + my $template = HTML::Template->new(filename => "$includes/templates/$theme/$templatebase", die_on_bad_params => 0, path => [$includes]); + $template->param(SCRIPT_NAME => $ENV{'SCRIPT_NAME'}); + print "Content-Type: text/html\n\n", $template->output; } # sub mainmenu - -#-------------------------- -# Parse MARC data in file format with control-character separators -# May be multiple records. -sub parsemarcfileformat { - use strict; - # Input is one big text string - my $data=shift; - # Output is list of records. Each record is list of field hashes - my @records; - - my $splitchar=chr(29); - my $splitchar2=chr(30); - my $splitchar3=chr(31); - my $debug=0; - my $record; - foreach $record (split(/$splitchar/, $data)) { - my @record; - my $directory=0; - my $tagcounter=0; - my %tag; - my $field; - - my $leader=substr($record,0,24); - print "Leader:$leader\n" if $debug; - push (@record, { - 'tag' => 'Leader', - 'indicator' => $leader , - } ); - - $record=substr($record,24); - foreach $field (split(/$splitchar2/, $record)) { - my %field; - my $tag; - my $indicator; - unless ($directory) { - $directory=$field; - my $itemcounter=1; - my $counter2=0; - my $item; - my $length; - my $start; - while ($item=substr($directory,0,12)) { - $tag=substr($directory,0,3); - $length=substr($directory,3,4); - $start=substr($directory,7,6); - $directory=substr($directory,12); - $tag{$counter2}=$tag; - $counter2++; - } - $directory=1; - next; - } - $tag=$tag{$tagcounter}; - $tagcounter++; - $field{'tag'}=$tag; - my @subfields=split(/$splitchar3/, $field); - $indicator=$subfields[0]; - $field{'indicator'}=$indicator; - my $firstline=1; - unless ($#subfields==0) { - my %subfields; - my @subfieldlist; - my $i; - for ($i=1; $i<=$#subfields; $i++) { - my $text=$subfields[$i]; - my $subfieldcode=substr($text,0,1); - my $subfield=substr($text,1); - # if this subfield already exists, do array - if ($subfields{$subfieldcode}) { - my $subfieldlist=$subfields{$subfieldcode}; - if ( ref($subfieldlist) eq 'ARRAY' ) { - # Already an array, add on to it - print "$tag Adding to array $subfieldcode -- $subfield
    \n" if $debug; - @subfieldlist=@$subfieldlist; - push (@subfieldlist, $subfield); - } else { - # Change simple value to array - print "$tag Arraying $subfieldcode -- $subfield
    \n" if $debug; - @subfieldlist=($subfields{$subfieldcode}, $subfield); - } - # keep new array - $subfields{$subfieldcode}=\@subfieldlist; - } else { - # subfield doesn't exist yet, keep simple value - $subfields{$subfieldcode}=$subfield; - } - } - $field{'subfields'}=\%subfields; - } - push (@record, \%field); - } # foreach field in record - push (@records, \@record); - # $counter++; - } - print "" if $debug; - return @records; -} # sub parsemarcfileformat - #---------------------------- # Accept form results to add query to z3950 queue sub AcceptZ3950Queue { @@ -1153,6 +618,7 @@ sub AcceptZ3950Queue { )=@_; my @serverlist; + my $error; requireDBI($dbh,"AcceptZ3950Queue"); @@ -1175,8 +641,33 @@ sub AcceptZ3950Queue { } } - addz3950queue($dbh,$input->param('query'), $input->param('type'), + $error=addz3950queue($dbh,$input->param('query'), $input->param('type'), $input->param('rand'), @serverlist); + if ( $error ) { + print qq| + + + +
    Error
    +$error

    +|; + if ( $error =~ /daemon/i ) { + print qq| +There is a launcher for the Z39.50 client daemon in your intranet installation
    +directory under ./scripts/z3950daemon/z3950-daemon-launch.sh. This
    +script should be run as root, and it will start up the program running with the
    +privileges of your apache user. Ideally, this script should be started from a
    +system init directory so that is running after the machine starts up. +|; + + } # if daemon + print qq| +

    + +$query is not a valid ISBN Number

    \n"; @@ -1222,48 +713,52 @@ sub AcceptBiblioitem { my $biblionumber=0; my $biblioitemnumber=0; my $sth; + my $record; requireDBI($dbh,"AcceptBiblioitem"); - my $isbn=$input->param('isbn'); - my $issn=$input->param('issn'); - my $lccn=$input->param('lccn'); - my $q_origisbn=$dbh->quote($input->param('origisbn')); - my $q_origissn=$dbh->quote($input->param('origissn')); - my $q_origlccn=$dbh->quote($input->param('origlccn')); - my $q_origcontrolnumber=$dbh->quote($input->param('origcontrolnumber')); - my $q_isbn=$dbh->quote((($isbn) || ('NIL'))); - my $q_issn=$dbh->quote((($issn) || ('NIL'))); - my $q_lccn=$dbh->quote((($lccn) || ('NIL'))); - my $file=$input->param('file'); - - #my $sth=$dbh->prepare("insert into marcrecorddone values ($q_origisbn, $q_origissn, $q_origlccn, $q_origcontrolnumber)"); - #$sth->execute; +# my $isbn=$input->param('isbn'); +# my $issn=$input->param('issn'); +# my $lccn=$input->param('lccn'); +# my $q_origisbn=$dbh->quote($input->param('origisbn')); +# my $q_origissn=$dbh->quote($input->param('origissn')); +# my $q_origlccn=$dbh->quote($input->param('origlccn')); +# my $q_origcontrolnumber=$dbh->quote($input->param('origcontrolnumber')); + my $title=$input->param('title'); - print "

    \n"; - print "New Record | New File
    \n"; +# my $q_isbn=$dbh->quote((($isbn) || ('NIL'))); +# my $q_issn=$dbh->quote((($issn) || ('NIL'))); +# my $q_lccn=$dbh->quote((($lccn) || ('NIL'))); + my $file= MARC::File::USMARC->indata($input->param('file')); + my $numrecord = $input->param('numrecord'); + if ($numrecord) { + for (my $i==1;$i<$numrecord;$i++) { + $record=$file->next; + } + } else { + print STDERR "Error in marcimport.pl/Acceptbiblioitem : numrecord not defined\n"; + print "Error in marcimport.pl/Acceptbiblioitem : numrecord not defined : contact administrator\n"; + } + my $templatebase="marcimport/AcceptBiblioitem.tmpl"; + my $theme=picktemplate($includes, $templatebase); + my $template = HTML::Template->new(filename => "$includes/templates/$theme/$templatebase", die_on_bad_params => 0, path => [$includes]); + my $oldkoha = MARCmarc2koha($dbh,$record); # See if it already exists my $sth=$dbh->prepare("select biblionumber,biblioitemnumber from biblioitems - where issn=$q_issn or isbn=$q_isbn or lccn=$q_lccn"); - $sth->execute; + where isbn=? or issn=? or lccn=?"); + $sth->execute($oldkoha->{isbn},$oldkoha->{issn},$oldkoha->{lccn}); if ($sth->rows) { # Already exists + ($biblionumber, $biblioitemnumber) = $sth->fetchrow; - my $title=$input->param('title'); - print << "EOF"; -
    - - -
    Record already in database -
    $title is already in the database with - biblionumber $biblionumber and biblioitemnumber $biblioitemnumber -
    -

    -EOF - } else { + $template->param(title => $title); + $template->param(biblionumber => $biblionumber); + $template->param(biblioitemnumber => $biblioitemnumber); + $template->param(BIBLIO_EXISTS => 1); + } else { # It doesn't exist; add it. my $error; @@ -1275,7 +770,7 @@ EOF my @subjectheadings=split(/[\r\n]+/,$subjectheadings); my $additionalauthors=$input->param('additionalauthors'); - my @additionalauthors=split(/[\r\n]+/,uc($additionalauthors)); + my @additionalauthors=split(/[\r\n]+|\|/,uc($additionalauthors)); # Use individual assignments to hash buckets, in case # any of the input parameters are empty or don't exist @@ -1305,51 +800,28 @@ EOF $biblioitem{place} =$input->param('place'); $biblioitem{lccn} =$input->param('lccn'); $biblioitem{marc} =$input->param('marc'); - - #print "

    subjects=@subjectheadings
    \n"; - #print "
    auth=@additionalauthors
    \n"; - +# print STDERR $record->as_formatted(); +# die; ($biblionumber, $biblioitemnumber, $error)= - newcompletebiblioitem($dbh, - \%biblio, - \%biblioitem, - \@subjectheadings, - \@additionalauthors - ); + ALLnewbiblio($dbh,$record,\%biblio,\%biblioitem); +# (1,2,0); +# newcompletebiblioitem($dbh, +# \%biblio, +# \%biblioitem, +# \@subjectheadings, +# \@additionalauthors +# ); if ( $error ) { print "

    Error adding biblio item

    $error\n"; } else { - - my $title=$input->param('title'); - print << "EOF"; - - - -
    Record entered into database
    $title has been entered into the database with biblionumber - $biblionumber and biblioitemnumber $biblioitemnumber
    -EOF + $template->param(title => $title); + $template->param(biblionumber => $biblionumber); + $template->param(biblioitemnumber => $biblioitemnumber); + $template->param(BIBLIO_CREATE => 1); } # if error } # if new record - - return $biblionumber,$biblioitemnumber; -} # sub AcceptBiblioitem - -sub ItemCopyForm { - use strict; - my ( - $dbh, - $input, # CGI input object - $biblionumber, - $biblioitemnumber, - )=@_; - - my $sth; my $barcode; - requireDBI($dbh,"ItemCopyForm"); - - my $title=$input->param('title'); - my $file=$input->param('file'); # Get next barcode, or pick random one if none exist yet $sth=$dbh->prepare("select max(barcode) from items"); @@ -1359,37 +831,11 @@ sub ItemCopyForm { if ($barcode==1) { $barcode=int(rand()*1000000); } - my $branchselect=getkeytableselectoptions( $dbh, 'branches', 'branchcode', 'branchname', 0); - - print << "EOF"; - - - -
    - Add a New Item for $title -
    -
    - - - - - - - - - - -
    BARCODE - Home Branch: -
    Replacement Price:
    Notes -
    -

    - -

    -
    -EOF + $template->param(barcode => $barcode); + $template->param(branchselect => $branchselect); + print "Content-Type: text/html\n\n", $template->output; } # sub ItemCopyForm @@ -1399,6 +845,10 @@ sub AcceptItemCopy { use strict; my ( $dbh, $input )=@_; + my $templatebase="marcimport/AcceptItemCopy.tmpl"; + my $theme=picktemplate($includes, $templatebase); + my $template = HTML::Template->new(filename => "$includes/templates/$theme/$templatebase", die_on_bad_params => 0, path => [$includes]); + my $error; requireDBI($dbh,"AcceptItemCopy"); @@ -1411,235 +861,31 @@ sub AcceptItemCopy { where barcode=?"); $sth->execute($barcode); if ($sth->rows) { - print "Barcode '$barcode' has already been assigned.

    \n"; + $template->param(BARCODE_EXISTS => 1); + $template->param(barcode => $barcode); } else { # Insert new item into database - $error=&newitems( - { biblionumber=> $input->param('biblionumber'), - biblioitemnumber=> $input->param('biblioitemnumber'), - itemnotes=> $input->param('notes'), - homebranch=> $input->param('homebranch'), - replacementprice=> $replacementprice, - }, - $barcode - ); + $error=&ALLnewitem($dbh, + { biblionumber=> $input->param('biblionumber'), + biblioitemnumber=> $input->param('biblioitemnumber'), + itemnotes=> $input->param('notes'), + homebranch=> $input->param('homebranch'), + replacementprice=> $replacementprice, + barcode => $barcode + } + ); if ( $error ) { - print "Error: $error

    \n"; + $template->param(ITEM_ERROR => 1); + $template->param(error => $error); } else { - - print " -
    - Item added with barcode $barcode -
    \n"; + $template->param(ITEM_CREATED => 1); + $template->param(barcode => $barcode); } # if error } # if barcode exists + print "Content-Type: text/html\n\n", $template->output; } # sub AcceptItemCopy -#--------------- -# Create an HTML option list for a