From 32ff18380bac0db4e9ed706a98b3b3f54702e5b5 Mon Sep 17 00:00:00 2001 From: Nahuel ANGELINETTI Date: Wed, 19 Aug 2009 15:22:24 +0200 Subject: [PATCH] (bug #2829) fix some mistakes extracting editor segment This patch fix how to extract the editor segment, and improve ISBN10/13 support. Signed-off-by: Galen Charlton Signed-off-by: Chris Cormack --- .../value_builder/unimarc_field_010.pl | 69 ++++++++++++++----- 1 file changed, 52 insertions(+), 17 deletions(-) mode change 100644 => 100755 cataloguing/value_builder/unimarc_field_010.pl diff --git a/cataloguing/value_builder/unimarc_field_010.pl b/cataloguing/value_builder/unimarc_field_010.pl old mode 100644 new mode 100755 index 54d887f83d..8b60026bf6 --- a/cataloguing/value_builder/unimarc_field_010.pl +++ b/cataloguing/value_builder/unimarc_field_010.pl @@ -88,26 +88,61 @@ sub plugin { my $dbh = C4::Context->dbh; - my $seg1; - - if (length ($isbn)<13){ - if ( substr( $isbn, 0, 1 ) <= 7 ) { - $seg1 = substr( $isbn, 0, 1 ); - }elsif ( substr( $isbn, 0, 2 ) <= 94 ) { - $seg1 = substr( $isbn, 0, 2 ); - }elsif ( substr( $isbn, 0, 3 ) <= 995 ) { - $seg1 = substr( $isbn, 0, 3 ); - }elsif ( substr( $isbn, 0, 4 ) <= 9989 ) { - $seg1 = substr( $isbn, 0, 4 ); - }else { - $seg1 = substr( $isbn, 0, 5 ); - } + my $len = 0; + my $sth = $dbh->prepare('SELECT publishercode FROM biblioitems WHERE isbn LIKE ? OR isbn LIKE ? LIMIT 1'); + + if (length ($isbn) == 13){ + $isbn = substr($isbn, 3, length($isbn)-3); } + + if(length($isbn) <= 10){ + + $len = 5; + if ( substr( $isbn, 0, 1 ) <= 7 ){ + $len = 1; + }elsif ( substr( $isbn, 0, 2 ) <= 94 ){ + $len = 2; + }elsif ( substr( $isbn, 0, 3 ) <= 995 ){ + $len = 3; + }elsif ( substr( $isbn, 0, 4 ) <= 9989 ){ + $len = 4 ; + } + + my $x = substr( $isbn, $len ); + my $seg2 = ""; + + if ( substr( $x, 0, 2 ) <= 19 ) { + $seg2 = substr( $x, 0, 2 ); + } + elsif ( substr( $x, 0, 3 ) <= 699 ) { + $seg2 = substr( $x, 0, 3 ); + } + elsif ( substr( $x, 0, 4 ) <= 8399 ) { + $seg2 = substr( $x, 0, 4 ); + } + elsif ( substr( $x, 0, 5 ) <= 89999 ) { + $seg2 = substr( $x, 0, 5 ); + } + elsif ( substr( $x, 0, 6 ) <= 9499999 ) { + $seg2 = substr( $x, 0, 6 ); + } + else { + $seg2 = substr( $x, 0, 7 ); + } - $seg1 .= "%"; - my $sth = $dbh->prepare('SELECT publishercode FROM biblioitems WHERE isbn LIKE ? LIMIT 1'); - $sth->execute($seg1); + while($len--){ + $seg2 = "_".$seg2; + } + + $len = 10 -length($seg2); + + while($len--){ + $seg2 .= "_"; + } + $sth->execute($seg2, "978$seg2"); + } + if( (my $publishercode) = $sth->fetchrow ) { $template->param(return => $publishercode); -- 2.39.5