From 35d366f4d5f4c0475c68deb5c33779d1b8678c69 Mon Sep 17 00:00:00 2001 From: amillar Date: Mon, 20 May 2002 04:55:20 +0000 Subject: [PATCH] Some code cleanup. Created subroutines for ISBN checksum, z3950 queue insert, and table-based form option selects for item type and branch code (branch code select no longer hard-coded). --- acqui.simple/marcimport.pl | 225 ++++++++++++++++++++++++++++--------- 1 file changed, 172 insertions(+), 53 deletions(-) diff --git a/acqui.simple/marcimport.pl b/acqui.simple/marcimport.pl index 7919d4e33d..709daa2f59 100755 --- a/acqui.simple/marcimport.pl +++ b/acqui.simple/marcimport.pl @@ -1,19 +1,31 @@ #!/usr/bin/perl +# Script for handling import of MARC data into Koha db +# and Z39.50 lookups -my $lc1='#dddddd'; -my $lc2='#ddaaaa'; +# Koha library project www.koha.org +# Licensed under the GPL -use C4::Database; +#use strict; + +# standard or CPAN modules used use CGI; use DBI; -#use strict; + +# Koha modules used +use C4::Database; use C4::Acquisitions; use C4::Output; -my $dbh=C4Connect; -my $userid=$ENV{'REMOTE_USER'}; -%tagtext = ( + +#------------------ +# Constants + +# 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', @@ -71,35 +83,109 @@ my $userid=$ENV{'REMOTE_USER'}; '856' => 'Electronic location and access', ); +#------------- +# Initialize + +my $userid=$ENV{'REMOTE_USER'}; my $input = new CGI; my $dbh=C4Connect; +#------------- +# Display output print $input->header; print startpage(); print startmenu('acquisitions'); + +#------------- +# Process input parameters my $file=$input->param('file'); if ($input->param('z3950queue')) { my $query=$input->param('query'); - my $type=$input->param('type'); + my @serverlist; - foreach ($input->param) { - if (/S-(.*)/) { - my $server=$1; - if ($server eq 'MAN') { - push @serverlist, "MAN/".$input->param('manualz3950server')."//"; + + my $isbngood=1; + if ($input->param('type') eq 'isbn') { + $isbngood=CheckIsbn($query); + } + if ($isbngood) { + foreach ($input->param) { + if (/S-(.*)/) { + my $server=$1; + if ($server eq 'MAN') { + push @serverlist, "MAN/".$input->param('manualz3950server')."//" +; + } else { + push @serverlist, $server; + } + } + } + + Addz3950queue($input->param('query'), $input->param('type'), + $input->param('rand'), @serverlist); + } else { + print "$query is not a valid ISBN + Number

\n"; + } +} + +sub Addz3950queue { + use strict; + my ( + $query, # value to look up + $type, # type of value ("isbn", "lccn", etc). + $requestid, + @z3950list, # list of z3950 servers to query + )=@_; + + my ( + @serverlist, + $server, + $failed, + ); + + # list of servers: entry can be a fully qualified URL-type entry + # or simply just a server ID number. + + my $sth=$dbh->prepare("select host,port,db,userid,password + from z3950servers + where id=? "); + foreach $server (@z3950list) { + if ($server =~ /:/ ) { + push @serverlist, $server; } else { - my $sth=$dbh->prepare("select host,port,db,userid,password from z3950servers where id=$server"); - $sth->execute; + $sth->execute($server); my ($host, $port, $db, $userid, $password) = $sth->fetchrow; push @serverlist, "$server/$host\:$port/$db/$userid/$password"; } + } + + my $serverlist=''; + foreach (@serverlist) { + $serverlist.="$_ "; } - } - my $isbnfailed=0; - if ($type eq 'isbn') { - my $q=$query; + chop $serverlist; + + # Don't allow reinsertion of the same request number. + my $sth=$dbh->prepare("select identifier from z3950queue + where identifier=?"); + $sth->execute($requestid); + unless ($sth->rows) { + $sth=$dbh->prepare("insert into z3950queue + (term,type,servers, identifier) + values (?, ?, ?, ?)"); + $sth->execute($query, $type, $serverlist, $requestid); + } +} # sub + +#-------------------------------------- +sub CheckIsbn { + my ($q)=@_ ; + + my $isbngood = 0; + $q=~s/[^X\d]//g; $q=~s/X.//g; if (length($q)==10) { @@ -114,35 +200,19 @@ if ($input->param('z3950queue')) { $c=int(11-($c/11-int($c/11))*11+.1); ($c==10) && ($c='X'); if ($c eq $checksum) { + $isbngood=1; } else { - print "$query is not a valid ISBN - Number

\n"; - $isbnfailed=1; + $isbngood=0; } } else { - print "$query is not a valid ISBN - Number

\n"; - $isbnfailed=1; - } - } - unless ($isbnfailed) { - my $q_term=$dbh->quote($query); - my $serverlist=''; - foreach (@serverlist) { - $serverlist.="$_ "; + $isbngood=0; } - chop $serverlist; - my $q_serverlist=$dbh->quote($serverlist); - my $rand=$input->param('rand'); - my $sth=$dbh->prepare("select identifier from z3950queue where - identifier=$rand"); - $sth->execute; - unless ($sth->rows) { - $sth=$dbh->prepare("insert into z3950queue (term,type,servers, identifier) values ($q_term, '$type', $q_serverlist, '$rand')"); - $sth->execute; - } - } -} + + return $isbngood; + +} # sub CheckIsbn + + if (my $data=$input->param('uploadmarc')) { my $name=$input->param('name'); @@ -171,7 +241,7 @@ if ($input->param('insertnewrecord')) { my $q_isbn=$dbh->quote((($isbn) || ('NIL'))); my $q_issn=$dbh->quote((($issn) || ('NIL'))); my $q_lccn=$dbh->quote((($lccn) || ('NIL'))); - $sth=$dbh->prepare("insert into marcrecorddone values ($q_origisbn, $q_origissn, $q_origlccn, $q_origcontrolnumber)"); + my $sth=$dbh->prepare("insert into marcrecorddone values ($q_origisbn, $q_origissn, $q_origlccn, $q_origcontrolnumber)"); $sth->execute; my $sth=$dbh->prepare("select biblionumber,biblioitemnumber from biblioitems where issn=$q_issn or isbn=$q_isbn or lccn=$q_lccn"); $sth->execute; @@ -278,6 +348,8 @@ EOF EOF } my $title=$input->param('title'); + + # Get next barcode, or pick random one if none exist yet $sth=$dbh->prepare("select max(barcode) from items"); $sth->execute; my ($barcode) = $sth->fetchrow; @@ -285,6 +357,10 @@ EOF if ($barcode==1) { $barcode=int(rand()*1000000); } + + my $branchselect=GetKeyTableSelectOptions( + $dbh, 'branches', 'branchcode', 'branchname', 0); + print << "EOF";
@@ -298,7 +374,10 @@ Add a New Item for $title - + + @@ -622,18 +701,19 @@ RECORD: $origlccn=$input->hidden(-name=>'origlccn', -default=>$lccn); $origcontrolnumber=$input->hidden(-name=>'origcontrolnumber', -default=>$controlnumber); - my $itemtypeselect=''; - $sth=$dbh->prepare("select itemtype,description from itemtypes"); - $sth->execute; - while (my ($itemtype, $description) = $sth->fetchrow) { - $itemtypeselect.="
BARCODE Home Branch:
BARCODE + +Home Branch:
Replacement Price:
Notes
\n"; @@ -1174,3 +1254,42 @@ sub parsemarcdata { } return @records; } + +#--------------- +# Create an HTML option list for a