refactored slashifyDate function out of inline code, created C4/Koha.pm
[koha.git] / C4 / Input.pm
1 package C4::Input; #asummes C4/Input
2
3 #package to deal with marking up output
4
5 use strict;
6 require Exporter;
7
8 use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
9
10 # set the version for version checking
11 $VERSION = 0.01;
12
13 @ISA = qw(Exporter);
14 @EXPORT = qw(&checkflds &checkdigit);
15 %EXPORT_TAGS = ( );     # eg: TAG => [ qw!name1 name2! ],
16
17 # your exported package globals go here,
18 # as well as any optionally exported functions
19
20 @EXPORT_OK   = qw($Var1 %Hashit);
21
22
23 # non-exported package globals go here
24 use vars qw(@more $stuff);
25
26 # initalize package globals, first exported ones
27
28 my $Var1   = '';
29 my %Hashit = ();
30
31
32 # then the others (which are still accessible as $Some::Module::stuff)
33 my $stuff  = '';
34 my @more   = ();
35
36 # all file-scoped lexicals must be created before
37 # the functions below that use them.
38
39 # file-private lexicals go here
40 my $priv_var    = '';
41 my %secret_hash = ();
42
43 # here's a file-private function as a closure,
44 # callable as &$priv_func;  it cannot be prototyped.
45 my $priv_func = sub {
46 # stuff goes here.
47   };
48    
49 # make all your functions, whether exported or not;
50  
51 sub checkflds {
52   my ($env,$reqflds,$data) = @_;
53   my $numrflds = @$reqflds;
54   my @probarr;
55   my $i = 0;
56   while ($i < $numrflds) {
57     if ($data->{@$reqflds[$i]} eq "") {
58       push(@probarr, @$reqflds[$i]);
59     }  
60     $i++
61   }
62   return (\@probarr);
63 }
64
65 sub checkdigit {
66   my ($env,$infl) =  @_;
67   $infl = uc $infl;
68   my @weightings = (8,4,6,3,5,2,1);
69   my $sum;
70   my $i = 1;
71   my $valid = 0;
72   #  print $infl."<br>";
73   while ($i <8) {
74     my $temp1 = $weightings[$i-1];
75     my $temp2 = substr($infl,$i,1);
76     $sum = $sum + ($temp1*$temp2);
77 #    print "$sum $temp1 $temp2<br>";
78     $i++;
79   }
80   my $rem = ($sum%11);
81   if ($rem == 10) {
82     $rem = "X";
83   }  
84   #print $rem."<br>";
85   if ($rem eq substr($infl,8,1)) {
86     $valid = 1;
87   }
88   return $valid;
89 }
90  
91 END { }       # module clean-up code here (global destructor)
92