To Test:
Performa a catalogue search then hit the Z39.50 search button and your search 
term should populate the Title field in the pop up window. Now perform a search 
on a valid ISBN (10 or 13) number and the term you searched for should populate 
the ISBN field on the popup window.
---
 C4/Search.pm |   73 ++++++++++++++++++++++++++++++++++++++++++++++++---------
 1 files changed, 61 insertions(+), 12 deletions(-)

diff --git a/C4/Search.pm b/C4/Search.pm
index c3cff65..be96946 100644
--- a/C4/Search.pm
+++ b/C4/Search.pm
@@ -33,6 +33,7 @@ use C4::Debug;
 use C4::Items;
 use YAML;
 use URI::Escape;
+use POSIX;
 
 use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS $DEBUG);
 
@@ -1423,7 +1424,7 @@ sub searchResults {
     #find branchname
     #get branch information.....
     my %branches;
-    my $bsth =$dbh->prepare("SELECT branchcode,branchname FROM branches"); # 
FIXME : use C4::Branch::GetBranches
+    my $bsth =$dbh->prepare("SELECT branchcode,branchname FROM branches ");    
            
     $bsth->execute();
     while ( my $bdata = $bsth->fetchrow_hashref ) {
         $branches{ $bdata->{'branchcode'} } = $bdata->{'branchname'};
@@ -1671,7 +1672,7 @@ sub searchResults {
                    ($reservestatus, $reserveitem) = 
C4::Reserves::CheckReserves($item->{itemnumber});
                 }
 
-                # item is withdrawn, lost, damaged, not for loan, reserved or 
in transit
+                # item is withdrawn, lost or damaged
                 if (   $item->{wthdrawn}
                     || $item->{itemlost}
                     || $item->{damaged}
@@ -1686,15 +1687,6 @@ sub searchResults {
                     $item_in_transit_count++ if $transfertwhen ne '';
                    $item_onhold_count++     if $reservestatus eq 'Waiting';
                     $item->{status} = $item->{wthdrawn} . "-" . 
$item->{itemlost} . "-" . $item->{damaged} . "-" . $item->{notforloan};
-                    
-                    # can place hold on item ?
-                    if ((!$item->{damaged} || 
C4::Context->preference('AllowHoldsOnDamagedItems'))
-                      && !$item->{itemlost}
-                      && !$item->{withdrawn}
-                    ) {
-                        $can_place_holds = 1;
-                    }
-                    
                     $other_count++;
 
                     my $key = $prefix . $item->{status};
@@ -2599,9 +2591,20 @@ $template->param ( MYLOOP => 
C4::Search::z3950_search_args($searchscalar) )
 
 =cut
 
+
+
+
 sub z3950_search_args {
     my $bibrec = shift;
-    $bibrec = { title => $bibrec } if !ref $bibrec;
+  
+ 
+    if (validate_isbn($bibrec) == 1)
+    {
+    $bibrec = { isbn => $bibrec } if !ref $bibrec;
+}
+else {
+     $bibrec = { title => $bibrec } if !ref $bibrec;
+}
     my $array = [];
     for my $field (qw/ lccn isbn issn title author dewey subject /)
     {
@@ -2641,6 +2644,52 @@ OR adds a new authority record
 =cut
 
 
+=head
+BOOL validate_isbn($isbn_number)
+
+This function validates an isbn number by:
+
+1. Checking it is 10 or 13 characters long
+2. If it is 10 characters long, checks the lasd character is an 'X' and all 
other characters are digits
+3. If it is 13 characters long, checks it begins with '97' and all other 
characters are digits
+
+=cut
+sub validate_isbn { 
+  my $isbn = shift; 
+    
+    # Handle ISBNs with spaces or hyphens in them 
+    $isbn =~ s/\s+//g;
+    $isbn =~ s/\-//g;
+    
+    # Is it the correct length ?
+         if (length($isbn) != 10 && length($isbn) != 13)
+         { return 0; } 
+                     else {   
+                         
+                         # Is the last char 'x' for ISBN10 ?  
+                            my @chars = split('', $isbn); 
+                              if (length($isbn) == 10 && uc($chars[9]) eq 'X')
+                               {
+                                    # Are all but the last characters digits ? 
+                                    if 
(isdigit(substr($isbn,0,length($isbn)-1)) )
+                                     { return 1;}
+                               }
+  
+                    # Is it 13 chars long and begin with '97' ?
+                   if ( ($chars[0] eq '9' && $chars[1] eq '7') && 
length($isbn) == 13)
+                   {
+                       # is it made up of digits? 
+                    if (isdigit($isbn))  
+                     { return 1;}
+         
+      
+                    }
+      
+                 } 
+     # If this function has not yet successfully returned the return failure
+     return 0;
+}
+
 sub BiblioAddAuthorities{
   my ( $record, $frameworkcode ) = @_;
   my $dbh=C4::Context->dbh;
-- 
1.7.4.1

_______________________________________________
Koha-patches mailing list
[email protected]
http://lists.koha-community.org/cgi-bin/mailman/listinfo/koha-patches
website : http://www.koha-community.org/
git : http://git.koha-community.org/
bugs : http://bugs.koha-community.org/

Reply via email to