upgrading import in breeding farm (you can now search on ISBN or on title) AND character encoding.

This commit is contained in:
tipaul 2003-01-23 12:26:41 +00:00
parent 8392f92ec0
commit a9b32d47f4
5 changed files with 135 additions and 185 deletions

View File

@ -46,11 +46,10 @@ sub find_value {
}
sub MARCfindbreeding {
my ($dbh,$isbn) = @_;
my $sth = $dbh->prepare("select file,marc from marc_breeding where isbn=?");
$sth->execute($isbn);
my ($dbh,$id) = @_;
my $sth = $dbh->prepare("select file,marc from marc_breeding where id=?");
$sth->execute($id);
my ($file,$marc) = $sth->fetchrow;
# $marc = char_decode($marc);
if ($marc) {
my $record = MARC::File::USMARC::decode($marc);
if (ref($record) eq undef) {
@ -62,101 +61,11 @@ sub MARCfindbreeding {
return -1;
}
# some special chars in ISO 2709 (ISO 6630 and ISO 646 set)
my $IS3 = '\x1d' ; # IS3 : record end
my $IS2 = '\x1e' ; # IS2 : field end
my $IS1 = '\x1f' ; # IS1 : begin subfield
my $NSB = '\x88' ; # NSB : begin Non Sorting Block
my $NSE = '\x89' ; # NSE : Non Sorting Block end
sub char_decode {
# converts ISO 5426 coded string to ISO 8859-1
# sloppy code : should be improved in next issue
my ($string) = @_ ;
$_ = $string ;
if(/[\xc1-\xff]/) {
s/\xe1/Æ/gm ;
s/\xe2/Ð/gm ;
s/\xe9/Ø/gm ;
s/\xec/þ/gm ;
s/\xf1/æ/gm ;
s/\xf3/ð/gm ;
s/\xf9/ø/gm ;
s/\xfb/ß/gm ;
s/\xc1\x61/à/gm ;
s/\xc1\x65/è/gm ;
s/\xc1\x69/ì/gm ;
s/\xc1\x6f/ò/gm ;
s/\xc1\x75/ù/gm ;
s/\xc1\x41/À/gm ;
s/\xc1\x45/È/gm ;
s/\xc1\x49/Ì/gm ;
s/\xc1\x4f/Ò/gm ;
s/\xc1\x55/Ù/gm ;
s/\xc2\x41/Á/gm ;
s/\xc2\x45/É/gm ;
s/\xc2\x49/Í/gm ;
s/\xc2\x4f/Ó/gm ;
s/\xc2\x55/Ú/gm ;
s/\xc2\x59/Ý/gm ;
s/\xc2\x61/á/gm ;
s/\xc2\x65/é/gm ;
s/\xc2\x69/í/gm ;
s/\xc2\x6f/ó/gm ;
s/\xc2\x75/ú/gm ;
s/\xc2\x79/ý/gm ;
s/\xc3\x41/Â/gm ;
s/\xc3\x45/Ê/gm ;
s/\xc3\x49/Î/gm ;
s/\xc3\x4f/Ô/gm ;
s/\xc3\x55/Û/gm ;
s/\xc3\x61/â/gm ;
s/\xc3\x65/ê/gm ;
s/\xc3\x69/î/gm ;
s/\xc3\x6f/ô/gm ;
s/\xc3\x75/û/gm ;
s/\xc4\x41/Ã/gm ;
s/\xc4\x4e/Ñ/gm ;
s/\xc4\x4f/Õ/gm ;
s/\xc4\x61/ã/gm ;
s/\xc4\x6e/ñ/gm ;
s/\xc4\x6f/õ/gm ;
s/\xc8\x45/Ë/gm ;
s/\xc8\x49/Ï/gm ;
s/\xc8\x65/ë/gm ;
s/\xc8\x69/ï/gm ;
s/\xc8\x76/ÿ/gm ;
s/\xc9\x41/Ä/gm ;
s/\xc9\x4f/Ö/gm ;
s/\xc9\x55/Ü/gm ;
s/\xc9\x61/ä/gm ;
s/\xc9\x6f/ö/gm ;
s/\xc9\x75/ü/gm ;
s/\xca\x41/Å/gm ;
s/\xca\x61/å/gm ;
s/\xd0\x43/Ç/gm ;
s/\xd0\x63/ç/gm ;
}
# this handles non-sorting blocks (if implementation requires this)
$string = nsb_clean($_) ;
return($string) ;
}
sub nsb_clean {
# handles non sorting blocks
my ($string) = @_ ;
$_ = $string ;
s/$NSB/(/gm ;
s/[ ]{0,1}$NSE/) /gm ;
$string = $_ ;
return($string) ;
}
my $input = new CGI;
my $error = $input->param('error');
my $oldbiblionumber=$input->param('oldbiblionumber'); # if bib exists, it's a modif, not a new biblio.
my $isbn = $input->param('isbn');
my $breedingid = $input->param('breedingid');
my $op = $input->param('op');
my $dbh = C4::Context->dbh;
my $bibid;
@ -178,7 +87,7 @@ my $tagslib = &MARCgettagslib($dbh,1);
my $record=-1;
$record = MARCgetbiblio($dbh,$bibid) if ($bibid);
#warn "1= ".$record->as_formatted;
$record = MARCfindbreeding($dbh,$isbn) if ($isbn);
$record = MARCfindbreeding($dbh,$breedingid) if ($breedingid);
my $is_a_modif=0;
my ($oldbiblionumtagfield,$oldbiblionumtagsubfield);
my ($oldbiblioitemnumtagfield,$oldbiblioitemnumtagsubfield,$bibitem,$oldbiblioitemnumber);
@ -248,7 +157,7 @@ if ($op eq "addbiblio") {
# if breeding is not empty
if ($record ne -1) {
my ($x,$value) = find_value($tag,$subfield,$record);
$value=char_decode($value);
$value=char_decode($value) unless ($is_a_modif);
$indicator = $x if $x;
if ($tagslib->{$tag}->{$subfield}->{authorised_value}) {
my @authorised_values;
@ -303,7 +212,7 @@ if ($op eq "addbiblio") {
} else {
my ($x,$value);
($x,$value) = find_value($tag,$subfield,$record) if ($record ne -1);
$value=char_decode($value);
$value=char_decode($value) unless ($is_a_modif);
if ($tagslib->{$tag}->{$subfield}->{authorised_value}) {
my @authorised_values;
my %authorised_lib;

View File

@ -30,6 +30,7 @@ use HTML::Template;
my $input = new CGI;
my $isbn = $input->param('isbn');
my $title = $input->param('title');
my $offset = $input->param('offset');
my $num = $input->param('num');
my $showoffset = $offset + 1;
@ -44,9 +45,10 @@ my ($template, $loggedinuser, $cookie)
flagsrequired => {catalogue => 1},
debug => 1,
});
if (! $isbn) {
if (! $isbn && !$title) {
print $input->redirect('addbooks.pl');
} else {
# fill with books in ACTIVE DB (biblio)
if (! $offset) {
$offset = 0;
$showoffset = 1;
@ -84,11 +86,24 @@ if (! $isbn) {
$row_data{num} = $num;
push (@loop_links,\%row_data);
} # for
# fill with books in breeding farm
($count, @results) = breedingsearch($title,$isbn);
my @breeding_loop = ();
for (my $i=0; $i <= $#results; $i++) {
my %row_data;
$row_data{id} = $results[$i]->{'id'};
$row_data{isbn} = $results[$i]->{'isbn'};
$row_data{file} = $results[$i]->{'file'};
$row_data{title} = $results[$i]->{'title'};
$row_data{author} = $results[$i]->{'author'};
push (@breeding_loop, \%row_data);
}
$template->param(isbn => $isbn,
showoffset => $showoffset,
total => $total,
offset => $offset,
loop => \@loop_data,
breeding_loop => \@breeding_loop,
loop_links => \@loop_links);
print $input->header(

View File

@ -86,8 +86,9 @@ if ($uploadmarc && length($uploadmarc)>0) {
my $dbh = C4::Context->dbh;
my $searchisbn = $dbh->prepare("select biblioitemnumber from biblioitems where isbn=?");
my $searchissn = $dbh->prepare("select biblioitemnumber from biblioitems where issn=?");
my $searchbreeding = $dbh->prepare("select isbn from marc_breeding where isbn=?");
my $insertsql = $dbh->prepare("replace into marc_breeding (file,isbn,title,marc) values(?,?,?,?)");
my $searchbreeding = $dbh->prepare("select id from marc_breeding where isbn=?");
my $insertsql = $dbh->prepare("insert into marc_breeding (file,isbn,title,author,marc) values(?,?,?,?,?)");
my $replacesql = $dbh->prepare("update marc_breeding set file=?,isbn=?,title=?,author=?,marc=? where id=?");
# fields used for import results
my $imported=0;
my $alreadyindb = 0;
@ -99,42 +100,44 @@ if ($uploadmarc && length($uploadmarc)>0) {
$notmarcrecord++;
} else {
my $oldbiblio = MARCmarc2koha($dbh,$marcrecord);
$oldbiblio->{title} = char_decode($oldbiblio->{title});
$oldbiblio->{author} = char_decode($oldbiblio->{author});
# if isbn found and biblio does not exist, add it. If isbn found and biblio exists, overwrite or ignore depending on user choice
if ($oldbiblio->{isbn} || $oldbiblio->{issn}) {
# drop every "special" char : spaces, - ...
$oldbiblio->{isbn} =~ s/ |-|\.//g,
# search if biblio exists
my $biblioitemnumber;
if ($oldbiblio->{isbn}) {
$searchisbn->execute($oldbiblio->{isbn});
($biblioitemnumber) = $searchisbn->fetchrow;
} else {
$searchissn->execute($oldbiblio->{issn});
($biblioitemnumber) = $searchissn->fetchrow;
}
if ($biblioitemnumber) {
$alreadyindb++;
} else {
# search in breeding farm
my $breedingresult;
if ($oldbiblio->{isbn}) {
$searchbreeding->execute($oldbiblio->{isbn});
($breedingresult) = $searchbreeding->fetchrow;
} else {
$searchbreeding->execute($oldbiblio->{issn});
($breedingresult) = $searchbreeding->fetchrow;
}
if (!$breedingresult || $overwrite_biblio) {
my $recoded;
$recoded = $marcrecord->as_usmarc();
$insertsql ->execute($filename,$oldbiblio->{isbn}.$oldbiblio->{issn},$oldbiblio->{title},$recoded);
$imported++;
} else {
$alreadyinfarm++;
}
}
# drop every "special" char : spaces, - ...
$oldbiblio->{isbn} =~ s/ |-|\.//g,
# search if biblio exists
my $biblioitemnumber;
if ($oldbiblio->{isbn}) {
$searchisbn->execute($oldbiblio->{isbn});
($biblioitemnumber) = $searchisbn->fetchrow;
} else {
$notmarcrecord++;
$searchissn->execute($oldbiblio->{issn});
($biblioitemnumber) = $searchissn->fetchrow;
}
if ($biblioitemnumber) {
$alreadyindb++;
} else {
# search in breeding farm
my $breedingid;
if ($oldbiblio->{isbn}) {
$searchbreeding->execute($oldbiblio->{isbn});
($breedingid) = $searchbreeding->fetchrow;
} else {
$searchbreeding->execute($oldbiblio->{issn});
($breedingid) = $searchbreeding->fetchrow;
}
if (!$breedingid || $overwrite_biblio) {
my $recoded;
$recoded = $marcrecord->as_usmarc();
if ($breedingid) {
$replacesql ->execute($filename,$oldbiblio->{isbn}.$oldbiblio->{issn},$oldbiblio->{title},$oldbiblio->{author},$recoded,$breedingid);
} else {
$insertsql ->execute($filename,$oldbiblio->{isbn}.$oldbiblio->{issn},$oldbiblio->{title},$oldbiblio->{author},$recoded);
}
$imported++;
} else {
$alreadyinfarm++;
}
}
}
}
@ -803,6 +806,9 @@ sub FormatMarcText {
#---------------
# log cleared, as marcimport is (almost) rewritten from scratch.
# $Log$
# Revision 1.26 2003/01/23 12:26:41 tipaul
# upgrading import in breeding farm (you can now search on ISBN or on title) AND character encoding.
#
# Revision 1.25 2003/01/21 08:13:50 tipaul
# character encoding ISO646 => 8859-1, first draft
#

View File

@ -22,20 +22,23 @@
<td><font size="4">To add a new biblio/item, scan or type the ISBN/ISSN number:</font></td>
</tr>
</table>
<table cellpadding="3" border=0 width="100%">
<tr valign="top">
<form action="isbnsearch.pl">
<td width="5%">ISBN:</td>
<td width="20%"><input type="text" name="isbn" /></td>
<td width="10%"><input type="submit" value="Go" /></td>
<td>If the ISBN is found into the biblio table, it will be retrieved and can be modified.<br/>
If the ISBN is found into the breeding farm, it will be retrieved. and a biblio added.<br/>
Otherwise, a biblio can be added from scratch.</td>
</form>
</tr>
<tr><td>&nbsp;</td>
<td colspan=2><a href=addbiblio.pl>Add biblio without ISBN/ISSN</a></td></tr>
</table>
<form action="isbnsearch.pl">
<table cellpadding="3" border=0 width="100%">
<tr valign="top">
<td width="5%">ISBN:</td>
<td width="20%"><input type="text" name="isbn" /></td>
<td width="10%" rowspan=2 valign="middle"><input type="submit" value="Go" /></td>
<td rowspan=2>If the ISBN is found into the biblio table, it will be retrieved and can be modified.<br/>
If the ISBN is found into the breeding farm, it will be retrieved. and a biblio added.<br/>
Otherwise, a biblio can be added from scratch.</td>
</tr>
<td width="5%">Title</td>
<td width="20%"><input type="text" name="title" /></td>
</tr>
<tr><td>&nbsp;</td>
<td colspan=2><a href=addbiblio.pl>Add biblio without ISBN/ISSN</a></td></tr>
</table>
</form>
<p />
<p />
@ -83,22 +86,5 @@
</tr>
</table>
</FORM>
<p />
<table bgcolor="#ffcc00" width="80%" cellpadding="3">
<tr valign="center">
<td><FONT SIZE=4>Help</font></td>
</tr>
</table>
<FONT SIZE=5>Koha stores data in three sections</font>
<p />
<h2>Biblio</h2>
The first section records bibliographic data such as title, author and copyright for a particular work.
<p />
<h2>Group</h2>
The second records bibliographic data for a particular publication of that work, such as ISBN number, physical description, publisher information, etc
<p />
<h2>Item</h2>
The third section holds specific item information, such as the bar code number
<p />
<TMPL_INCLUDE NAME="acquisitions-bottom.inc">

View File

@ -2,30 +2,64 @@
<font size="6"><em>Biblio Search Results</em></font><br />
<CENTER>
You searched on <b>ISBN <TMPL_VAR name="isbn">,</b> <TMPL_VAR name="count"> results found <br />
You searched on <b><TMPL_IF name="isbn">ISBN <TMPL_VAR name="isbn"></TMPL_IF><TMPL_IF name="title">title <TMPL_VAR name="title"></TMPL_IF></b><br />
<TMPL_VAR name="count"> results found <br />
Results <TMPL_VAR name="showoffset"> to <TMPL_VAR name="total"> displayed
<div align="right">
<h2><a href="addbiblio.pl?isbn=<TMPL_VAR name="isbn">">Add New Biblio</a></h2>
</div>
<p />
<table border="0" cellspacing="0" cellpadding="5">
<tr valign=top bgcolor=#ffcc00>
<td><b>TITLE</b></td>
<td><b>AUTHOR</b></td>
<td><b>&copy;</b></td>
<td><b>Items</b></td>
</tr>
<TMPL_LOOP name="loop">
<tr valign="top" bgcolor="<TMPL_VAR name="toggle">">
<td><TMPL_VAR name="title"></a>
<td><TMPL_VAR name="author"></td>
<td><TMPL_VAR name="copyrightdate"></td>
<td><a href="addbiblio.pl?oldbiblionumber=<TMPL_VAR name="biblionumber">">Edit...</a></td>
<table width="80%" cellpadding="3">
<tr valign="center">
<td><font size="4">Biblios in koha</font></td>
</tr>
</TMPL_LOOP>
</table>
<table border="0" cellspacing="0" cellpadding="5" width="80%">
<tr valign=top bgcolor=#ffcc00>
<td><b>Title</b></td>
<td><b>Author</b></td>
<td><b>&copy;</b></td>
<td>&nbsp;</td>
</tr>
<TMPL_LOOP name="loop">
<tr valign="top" bgcolor="<TMPL_VAR name="toggle">">
<td><TMPL_VAR name="title"></a>
<td><TMPL_VAR name="author"></td>
<td><TMPL_VAR name="copyrightdate"></td>
<td><a href="addbiblio.pl?oldbiblionumber=<TMPL_VAR name="biblionumber">">Edit...</a></td>
</tr>
</TMPL_LOOP>
</table>
<br />
<table width="80%" cellpadding="3">
<tr valign="center">
<td><font size="4">Biblios in breeding farm</font></td>
</tr>
</table>
<table border="0" cellspacing="0" cellpadding="5" width="80%">
<tr valign=top bgcolor=#ffcc00>
<td><b>Title</b></td>
<td><b>Author</b></td>
<td><b>ISBN</b></td>
<td><b>coming from</b></td>
<td><b>&nbsp;</b></td>
<td>&nbsp;</td>
</tr>
<TMPL_LOOP name="breeding_loop">
<tr valign="top" bgcolor="<TMPL_VAR name="toggle">">
<td><TMPL_VAR name="title"></a>
<td><TMPL_VAR name="author"></td>
<td><TMPL_VAR name="isbn"></td>
<td><TMPL_VAR name="file"></td>
<td><a href="addbiblio.pl?breedingid=<TMPL_VAR name="id">">Add biblio</a></td>
</tr>
</TMPL_LOOP>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td><a href="addbiblio.pl?isbn=<TMPL_VAR name="isbn">">Add New Biblio</a></td>
</tr>
</table>
<br />
<TMPL_LOOP name="loop_links">
<a href="isbnsearch.pl?isbn=<TMPL_VAR name="isbn">&offset=<TMPL_VAR name="newoffset">&num=<TMPL_VAR name="num">"><TMPL_VAR name="shownumber"></a>