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
26 use vars qw($VERSION @ISA @EXPORT);
28 # set the version for version checking
33 C4::Input - Miscellaneous sanity checks
41 This module provides functions to see whether a given library card
42 number or ISBN is valid.
52 &checkdigit &checkvalidisbn
56 # FIXME - This is never used.
58 # my ($env,$reqflds,$data) = @_;
59 # my $numrflds = @$reqflds;
62 # while ($i < $numrflds) {
63 # if ($data->{@$reqflds[$i]} eq "") {
64 # push(@probarr, @$reqflds[$i]);
73 $valid = &checkdigit($env, $cardnumber $nounique);
75 Takes a card number, computes its check digit, and compares it to the
76 checkdigit at the end of C<$cardnumber>. Returns a true value iff
77 C<$cardnumber> has a valid check digit.
85 my ($env,$infl, $nounique) = @_;
89 #Check to make sure the cardnumber is unique
91 #FIXME: We should make the error for a nonunique cardnumber
92 #different from the one where the checkdigit on the number is
97 my $dbh=C4::Context->dbh;
98 my $query=qq{SELECT * FROM borrowers WHERE cardnumber=?};
99 my $sth=$dbh->prepare($query);
100 $sth->execute($infl);
101 my %results = $sth->fetchrow_hashref();
102 if ( $sth->rows != 0 )
107 if (C4::Context->preference("checkdigit") eq "none") {
111 my @weightings = (8,4,6,3,5,2,1);
117 my $temp1 = $weightings[$i-1];
118 my $temp2 = substr($infl,$i,1);
119 $sum += $temp1 * $temp2;
125 if ($rem eq substr($infl,8,1)) {
133 $valid = &checkvalidisbn($isbn);
135 Returns a true value iff C<$isbn> is a valid ISBN: it must be ten
136 digits long (counting "X" as a digit), and must have a valid check
141 #--------------------------------------
142 # Determine if a number is a valid ISBN number, according to length
143 # of 10 digits and valid checksum
146 my ($q)=@_ ; # Input: ISBN number
148 my $isbngood = 0; # Return: true or false
150 $q=~s/x$/X/g; # upshift lower case X
154 #return 0 if $q is not ten digits long
155 if (length($q)!=10) {
159 #If we get to here, length($q) must be 10
160 my $checksum=substr($q,9,1);
161 my $isbn=substr($q,0,9);
164 for ($i=0; $i<9; $i++) {
165 my $digit=substr($q,$i,1);
169 ($c==10) && ($c='X');
170 $isbngood = $c eq $checksum;
173 } # sub checkvalidisbn
177 $CGIScrollingList = &BuildCGISort($name string, $input_name string);
179 Returns the scrolling list with name $input_name, built on authorised Values named $name.
180 Returns NULL if no authorised values found
184 #--------------------------------------
185 # Determine if a number is a valid ISBN number, according to length
186 # of 10 digits and valid checksum
189 my ($name,$input_name,$data) = @_;
190 my $dbh=C4::Context->dbh;
191 my $query=qq{SELECT * FROM authorised_values WHERE category=?};
192 my $sth=$dbh->prepare($query);
193 $sth->execute($name);
198 for (my $i =0;$i<=$sth->rows;$i++){
199 my $results = $sth->fetchrow_hashref;
200 push @values, $results->{authorised_value};
201 $labels{$results->{authorised_value}}=$results->{lib};
203 $CGISort= CGI::scrolling_list(
204 -name => $input_name,
213 END { } # module clean-up code here (global destructor)
222 Koha Developement team <info@koha.org>