1 package C4::Input; #assumes C4/Input
4 # Copyright 2000-2002 Katipo Communications
6 # This file is part of Koha.
8 # Koha is free software; you can redistribute it and/or modify it under the
9 # terms of the GNU General Public License as published by the Free Software
10 # Foundation; either version 2 of the License, or (at your option) any later
13 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
14 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
15 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License along with
18 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
19 # Suite 330, Boston, MA 02111-1307 USA
24 use vars qw($VERSION @ISA @EXPORT);
26 # set the version for version checking
31 C4::Input - Miscellaneous sanity checks
39 This module provides functions to see whether a given library card
40 number or ISBN is valid.
50 &checkflds &checkdigit &checkvalidisbn
53 # FIXME - This is never used.
55 my ($env,$reqflds,$data) = @_;
56 my $numrflds = @$reqflds;
59 while ($i < $numrflds) {
60 if ($data->{@$reqflds[$i]} eq "") {
61 push(@probarr, @$reqflds[$i]);
70 $valid = &checkdigit($env, $cardnumber);
72 Takes a card number, computes its check digit, and compares it to the
73 checkdigit at the end of C<$cardnumber>. Returns a true value iff
74 C<$cardnumber> has a valid check digit.
83 my @weightings = (8,4,6,3,5,2,1);
88 # FIXME - for ($i = 1; $i < 8; $i++)
89 # or foreach $i (1..7)
91 my $temp1 = $weightings[$i-1];
92 my $temp2 = substr($infl,$i,1);
93 $sum += $temp1 * $temp2;
94 # print "$sum $temp1 $temp2<br>";
102 if ($rem eq substr($infl,8,1)) {
110 $valid = &checkvalidisbn($isbn);
112 Returns a true value iff C<$isbn> is a valid ISBN: it must be ten
113 digits long (counting "X" as a digit), and must have a valid check
118 #--------------------------------------
119 # Determine if a number is a valid ISBN number, according to length
120 # of 10 digits and valid checksum
123 my ($q)=@_ ; # Input: ISBN number
125 my $isbngood = 0; # Return: true or false
127 $q=~s/x$/X/g; # upshift lower case X
130 if (length($q)==10) {
131 my $checksum=substr($q,9,1);
132 my $isbn=substr($q,0,9);
135 for ($i=0; $i<9; $i++) {
136 my $digit=substr($q,$i,1);
139 $c=$c%11; # % is the modulus function
140 ($c==10) && ($c='X');
141 # FIXME - $isbngood = $c eq $checksum;
142 if ($c eq $checksum) {
148 # FIXME - Put "return 0 if $length($q) != 10" near the
149 # top, so we don't have to indent the rest of the function
156 } # sub checkvalidisbn
158 END { } # module clean-up code here (global destructor)
167 Koha Developement team <info@koha.org>