Bug #6139 Automatic incrementation of call number does not work if prefix contains '
authorSophie Meynieux <sophie.meynieux@biblibre.com>
Fri, 8 Apr 2011 10:12:09 +0000 (12:12 +0200)
committerChris Cormack <chrisc@catalyst.net.nz>
Sun, 14 Aug 2011 08:27:17 +0000 (20:27 +1200)
This patch also fixes giving the first callnumber with a given prefix.

Signed-off-by: Paul Poulain <paul.poulain@biblibre.com>
Signed-off-by: Chris Cormack <chrisc@catalyst.net.nz>
cataloguing/value_builder/callnumber.pl

index cc37af0..64507f2 100755 (executable)
@@ -95,7 +95,7 @@ sub plugin {
             );
         }
     # If a prefix is submited, we look for the highest itemcallnumber with this prefix, and return it incremented
-    } elsif ( $code =~ m/^[A-Z.\-]+$/ ) {
+    } elsif ( $code =~ m/^[A-Z.\-']+$/ ) {
         my $sth = $dbh->prepare("SELECT MAX(CAST(SUBSTRING_INDEX(itemcallnumber,' ',-1) AS SIGNED)) FROM items WHERE itemcallnumber LIKE ?");
         $sth->execute($code.' %');
         if ( my $max = $sth->fetchrow ) {
@@ -103,10 +103,16 @@ sub plugin {
                 return => $code.' '.($max+1)
             );
         }
+        else {
+            $template->param(
+                return => $code.' 1'
+            );
+        }
+
     # The user entered a custom value, we don't touch it, this could be handled in js
     } else {
         $template->param(
-            return => $code,
+            return => $code
         );
     }
     output_html_with_http_headers $input, $cookie, $template->output;