#! /usr/bin/perl
require "cgi-lib.pl";
require "cl-lib.pl";
sub doform {
if ($forms) {
open(INPUTFORM,"payment/pcinpre.html") || die "Can't open your input form-post. $!\n";
while() {
print $_;
}
close INPUTFORM;
}
print qq!
!;
if ($forms) {
open(INPUTFORM,"payment/pcinpost.html") || die "Can't open your input
form-post. $!\n";
while() {
print $_;
}
close INPUTFORM;
}
print qq!
Return to Home Page
! if ($input{c});
}
sub Results {
if ($forms) {
open(INPUTFORM,"payment/pcoutpre.html") || die "Can't open your input form-post. $!\n";
while() {
print $_;
}
close INPUTFORM;
}
print "";
printf ("| \$%-9.0d |
", $loanamount);
printf ("| %3.3f\% |
", ($rate * 100));
printf ("| %2.0f years. |
", $term);
printf ("| \$%-9.2f per month. |
", $payment);
print "
";
print qq!!;
if ($forms) {
open(INPUTFORM,"payment/pcoutpost.html") || die "Can't open your input form-post. $!\n";
while() {
print $_;
}
close INPUTFORM;
}
print qq!
Return to Home Page
! if ($input{c});
}
sub Process {
$numerator = ( $loanamount * ($rate/12));
$denominator = (1 - (1 / (1 + ($rate/12))) ** ($term * 12));
$payment = $numerator / $denominator;
}
MAIN:
{
$forms=true;
print &PrintHeader;
if (&MethGet) {
&ReadParse ( *input);
&doform;
} else {
if (! &ReadParse ( *input)) {
$in = "";
$in .= "&banana=spiders";
$in .= "&c=abcmortgage";
$in .= "&loanamount_=100000";
$in .= "&term=30";
$in .= "&rate%=8";
@input = split(/&/,$in);
foreach $i (1 .. $#input) {
($key, $val) = split(/=/,$input[$i],2);
if (index($key,"\%") > $[) {
$val = $val * 0.01;
$key =~ s/\%//;
}
if (index($key,"_") > $[) {
$val =~ s/\,//;
$key =~ s/_//;
}
$input{$key} .= $val;
}
}
$loanamount = $input {loanamount};
$term = int ($input {term});
$rate = $input {rate};
&Process;
&Results;
}
}