work on input routines
This commit is contained in:
parent
864ef633f0
commit
3e764df1fe
4 changed files with 71 additions and 41 deletions
16
C4/Input.pm
16
C4/Input.pm
|
@ -49,7 +49,7 @@ my $priv_func = sub {
|
|||
# make all your functions, whether exported or not;
|
||||
|
||||
sub checkflds {
|
||||
my ($reqflds,$data) = @_;
|
||||
my ($env,$reqflds,$data) = @_;
|
||||
my $numrflds = @$reqflds;
|
||||
my @probarr;
|
||||
my $i = 0;
|
||||
|
@ -57,27 +57,31 @@ sub checkflds {
|
|||
if ($data->{@$reqflds[$i]} eq "") {
|
||||
push(@probarr, @$reqflds[$i]);
|
||||
}
|
||||
$i++
|
||||
}
|
||||
return (\@probarr);
|
||||
}
|
||||
|
||||
sub checkdigit {
|
||||
my ($infl) = @_;
|
||||
my ($env,$infl) = @_;
|
||||
$infl = uc $infl;
|
||||
my @weightings = (9,4,6,3,5,2,1);
|
||||
my @weightings = (8,4,6,3,5,2,1);
|
||||
my $sum;
|
||||
my $i = 1;
|
||||
my $valid = 0;
|
||||
# print $infl."<br>";
|
||||
while ($i <8) {
|
||||
$sum = $sum + $weightings[$i-1] * substr($infl,$i,1);
|
||||
print "$i\t$infl\t$sum\t$weightings[$i-1]\t".substr($infl,$i,1)."\n";
|
||||
my $temp1 = $weightings[$i-1];
|
||||
my $temp2 = substr($infl,$i,1);
|
||||
$sum = $sum + ($temp1*$temp2);
|
||||
# print "$sum $temp1 $temp2<br>";
|
||||
$i++;
|
||||
}
|
||||
my $rem = ($sum%11);
|
||||
print $rem;
|
||||
if ($rem == 10) {
|
||||
$rem = "X";
|
||||
}
|
||||
#print $rem."<br>";
|
||||
if ($rem eq substr($infl,8,1)) {
|
||||
$valid = 1;
|
||||
}
|
||||
|
|
13
C4/Output.pm
13
C4/Output.pm
|
@ -166,9 +166,18 @@ sub mkform2{
|
|||
$text="<input type=radio name=$key value=$data[1]>$data[1]
|
||||
<input type=radio name=$key value=$data[2]>$data[2]";
|
||||
} elsif ($data[0] eq 'text') {
|
||||
$text="<input type=$data[0] name=$key value=\"$data[1]\">";
|
||||
my $size = $data[1];
|
||||
if ($size eq "") {
|
||||
$size=40;
|
||||
}
|
||||
$text="<input type=$data[0] name=$key size=$size value=\"$data[2]\">";
|
||||
} elsif ($data[0] eq 'textarea') {
|
||||
$text="<textarea name=$key wrap=physical cols=40 rows=4>$data[1]</textarea>";
|
||||
my @size=split("x",$data[1]);
|
||||
if ($data[1] eq "") {
|
||||
$size[0] = 40;
|
||||
$size[1] = 4;
|
||||
}
|
||||
$text="<textarea name=$key wrap=physical cols=$size[0] rows=$size[1]>$data[2]</textarea>";
|
||||
} elsif ($data[0] eq 'select') {
|
||||
$text="<select name=$key>";
|
||||
my $sel=$data[1];
|
||||
|
|
|
@ -28,25 +28,25 @@ print startpage();
|
|||
print startmenu();
|
||||
my %inputs;
|
||||
my $catlist=makelist("categories","categorycode","description");
|
||||
$inputs{'cardnumber'} ="1\tR\tCard Number\ttext\t$data->{'cardnumber'}";
|
||||
$inputs{'surname'} ="2\tR\tSurname\ttext\t$data->{'surname'}";
|
||||
$inputs{'firstname'} ="3\tR\tFirst Name\ttext\t$data->{'firstname'}";
|
||||
$inputs{'othernames'} ="4\t\tOther Names\ttext\t$data->{'othernames'}";
|
||||
$inputs{'initials'} ="5\t\tInitials\ttext\t$data->{'initials'}";
|
||||
$inputs{'streetaddress'}="6\tR\tAddress\ttext\t$data->{'streetaddress'}";
|
||||
$inputs{'suburb'} ="7\t\tArea\ttext\t$data->{'suburb'}";
|
||||
$inputs{'city'} ="8\t\tTown\ttext\t$data->{'city'}";
|
||||
$inputs{'phone'} ="9\tR\tTelephone\ttext\t$data->{'phone'}";
|
||||
$inputs{'emailaddress'} ="10\t\tEmail\ttext\t$data->{'emailaddress'}";
|
||||
$inputs{'faxnumber'} ="11\t\tFax Number\ttext\t$data->{'faxnumber'}";
|
||||
$inputs{'altstreetaddress'}="12\tR\tAlt Address\ttext\t$data->{'altstreetaddress'}";
|
||||
$inputs{'altsuburb'} ="13\t\tAlt Area\ttext\t$data->{'altsuburb'}";
|
||||
$inputs{'altcity'} ="14\t\tAlt Town\ttext\t$data->{'altcity'}";
|
||||
$inputs{'altphone'} ="15\tR\tAlt Phone\ttext\t$data->{'altphone'}";
|
||||
$inputs{'cardnumber'} ="1\tR\tCard Number\ttext\t20\t$data->{'cardnumber'}";
|
||||
$inputs{'surname'} ="2\tR\tSurname\ttext\t40\t$data->{'surname'}";
|
||||
$inputs{'firstname'} ="3\tR\tFirst Name\ttext\t40\t$data->{'firstname'}";
|
||||
$inputs{'othernames'} ="4\t\tOther Names\ttext\t40\t$data->{'othernames'}";
|
||||
$inputs{'initials'} ="5\t\tInitials\ttext\t40\t$data->{'initials'}";
|
||||
$inputs{'streetaddress'}="6\tR\tAddress\ttext\t40\t$data->{'streetaddress'}";
|
||||
$inputs{'suburb'} ="7\t\tArea\ttext\t40\t$data->{'suburb'}";
|
||||
$inputs{'city'} ="8\t\tTown\ttext\t40\t$data->{'city'}";
|
||||
$inputs{'phone'} ="9\tR\tTelephone\ttext\t20\t$data->{'phone'}";
|
||||
$inputs{'emailaddress'} ="10\t\tEmail\ttext\t40\t$data->{'emailaddress'}";
|
||||
$inputs{'faxnumber'} ="11\t\tFax Number\ttext\t20\t$data->{'faxnumber'}";
|
||||
$inputs{'altstreetaddress'}="12\tR\tAlt Address\ttext\t40\t$data->{'altstreetaddress'}";
|
||||
$inputs{'altsuburb'} ="13\t\tAlt Area\ttext\t40\t$data->{'altsuburb'}";
|
||||
$inputs{'altcity'} ="14\t\tAlt Town\ttext\t40\t$data->{'altcity'}";
|
||||
$inputs{'altphone'} ="15\tR\tAlt Phone\ttext\t20\t$data->{'altphone'}";
|
||||
$inputs{'categorycode'} ="16\t\tCategory\tselect\t$data->{'categorycode'}".$catlist;
|
||||
$inputs{'dateofbirth'} ="17\t\tDate of Birth\ttext\t$data->{'dateofbirth'}";
|
||||
$inputs{'contactname'} ="18\tR\tContact Name\ttext\t$data->{'contactname'}";
|
||||
$inputs{'borrowernotes'}="19\t\tNotes\ttextarea\t$data->{'borrowernotes'}";
|
||||
$inputs{'dateofbirth'} ="17\t\tDate of Birth\ttext\t20\t$data->{'dateofbirth'}";
|
||||
$inputs{'contactname'} ="18\tR\tContact Name\ttext\t40\t$data->{'contactname'}";
|
||||
$inputs{'borrowernotes'}="19\t\tNotes\ttextarea\t40x4\t$data->{'borrowernotes'}";
|
||||
$inputs{'type'} ="20\t\t\thidden\tborrowers";
|
||||
$inputs{'updtype'} ="I";
|
||||
if ($action eq "M") {
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
|
||||
use CGI;
|
||||
use C4::Database;
|
||||
use C4::Input;
|
||||
use strict;
|
||||
|
||||
my $input= new CGI;
|
||||
|
@ -17,6 +18,7 @@ my @names=$input->param;
|
|||
my %data;
|
||||
my $keyfld;
|
||||
my $problems;
|
||||
my $env;
|
||||
foreach my $key (@names){
|
||||
$data{$key}=$input->param($key);
|
||||
}
|
||||
|
@ -33,22 +35,37 @@ if ($data{'type'} eq 'biblio'){
|
|||
# required fields
|
||||
my @reqflds = ("cardnumber","surname","firstname",
|
||||
"streetaddress","phone","altstreetaddress","altphone","dateofbirth","contactname");
|
||||
# $problems = checkflds(\@reqflds,\%data);
|
||||
if ($updtype eq "M") {
|
||||
$keyfld = "borrowernumber";
|
||||
} else {
|
||||
my $bornum=getmax('borrowers','borrowernumber');
|
||||
my $num=$bornum->{'max'};
|
||||
$num++;
|
||||
$data{'borrowernumber'}=$num;
|
||||
$data{'branchcode'}="L";
|
||||
my $probflds = checkflds($env,\@reqflds,\%data);
|
||||
if ($probflds ne "") {
|
||||
$problems = "The following required fields are missing: <br>";
|
||||
$problems = $problems.join(", ",@$probflds)."<br>";
|
||||
}
|
||||
$data{cardnumber} = uc ($data{cardnumber});
|
||||
my $validcard = checkdigit($env,$data{cardnumber});
|
||||
if ($validcard ne "1") {
|
||||
$problems = $problems."The card number failed the check digit check.<br>";
|
||||
}
|
||||
if ($problems eq "") {
|
||||
if ($updtype eq "M") {
|
||||
$keyfld = "borrowernumber";
|
||||
} else {
|
||||
my $bornum=getmax('borrowers','borrowernumber');
|
||||
my $num=$bornum->{'max'};
|
||||
$num++;
|
||||
$data{'borrowernumber'}=$num;
|
||||
$data{'branchcode'}="L";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if ($updtype eq "M") {
|
||||
&sqlupdate($data{'type'},$keyfld,$data{$keyfld},%data);
|
||||
if ($problems eq "") {
|
||||
if ($updtype eq "M") {
|
||||
&sqlupdate($data{'type'},$keyfld,$data{$keyfld},%data);
|
||||
} else {
|
||||
&sqlinsert($data{'type'},%data);
|
||||
}
|
||||
} else {
|
||||
&sqlinsert($data{'type'},%data);
|
||||
}
|
||||
|
||||
print "<strong>The following problems occured with the data:</strong><br>";
|
||||
print $problems;
|
||||
print "<br><br><strong>Please press the back key to fix this problem.</strong>";
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue