Added PODs.
[koha.git] / C4 / Input.pm
1 package C4::Input; #assumes C4/Input
2
3
4 # Copyright 2000-2002 Katipo Communications
5 #
6 # This file is part of Koha.
7 #
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
11 # version.
12 #
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.
16 #
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
20
21 use strict;
22 require Exporter;
23
24 use vars qw($VERSION @ISA @EXPORT);
25
26 # set the version for version checking
27 $VERSION = 0.01;
28
29 @ISA = qw(Exporter);
30 @EXPORT = qw(
31         &checkflds &checkdigit &checkvalidisbn
32 );
33  
34 sub checkflds {
35   my ($env,$reqflds,$data) = @_;
36   my $numrflds = @$reqflds;
37   my @probarr;
38   my $i = 0;
39   while ($i < $numrflds) {
40     if ($data->{@$reqflds[$i]} eq "") {
41       push(@probarr, @$reqflds[$i]);
42     }  
43     $i++
44   }
45   return (\@probarr);
46 }
47
48 sub checkdigit {
49   my ($env,$infl) =  @_;
50   $infl = uc $infl;
51   my @weightings = (8,4,6,3,5,2,1);
52   my $sum;
53   my $i = 1;
54   my $valid = 0;
55   #  print $infl."<br>";
56   while ($i <8) {
57     my $temp1 = $weightings[$i-1];
58     my $temp2 = substr($infl,$i,1);
59     $sum = $sum + ($temp1*$temp2);
60 #    print "$sum $temp1 $temp2<br>";
61     $i++;
62   }
63   my $rem = ($sum%11);
64   if ($rem == 10) {
65     $rem = "X";
66   }  
67   #print $rem."<br>";
68   if ($rem eq substr($infl,8,1)) {
69     $valid = 1;
70   }
71   return $valid;
72 } # sub checkdigit
73
74 #--------------------------------------
75 # Determine if a number is a valid ISBN number, according to length
76 #   of 10 digits and valid checksum
77 sub checkvalidisbn {
78         use strict; 
79         my ($q)=@_ ;    # Input: ISBN number
80
81         my $isbngood = 0; # Return: true or false
82
83         $q=~s/x$/X/g;           # upshift lower case X
84         $q=~s/[^X\d]//g;
85         $q=~s/X.//g;
86         if (length($q)==10) {
87             my $checksum=substr($q,9,1);
88             my $isbn=substr($q,0,9);
89             my $i;  
90             my $c=0;
91             for ($i=0; $i<9; $i++) { 
92                 my $digit=substr($q,$i,1);
93                 $c+=$digit*(10-$i);
94             }
95             $c=$c%11;  # % is the modulus function
96             ($c==10) && ($c='X');
97             if ($c eq $checksum) {
98                 $isbngood=1;
99             } else {
100                 $isbngood=0;
101             }
102         } else {
103             $isbngood=0;
104         } # if length good
105
106         return $isbngood;
107
108 } # sub checkvalidisbn
109
110  
111 END { }       # module clean-up code here (global destructor)