#!c:/perl/bin/perl.exe &parseforms; #&http; #print "
\n";
#foreach $key (keys(%FORM)) {print "$key = $FORM{'key'}\n";}
#exit;
if ($FORM{'ccticket'}) {$email = 1;&connectdatabase;}
if ($FORM{'cccount'} eq "") {$FORM{'cccount'} = 175;}
if ($FORM{'ccticket'} eq "") {$FORM{'ccticket'} = 285.00;}
if ($FORM{'ccpercent'} eq "") {$FORM{'ccpercent'} = 2.975;}
if ($FORM{'ccfee'} eq "") {$FORM{'ccfee'} = 0.35;}
if ($FORM{'pbcfee'} eq "") {$FORM{'pbcfee'} = 1.85;}
if ($FORM{'pbcpercent'} eq "") {$FORM{'pbcpercent'} = 100;}
foreach $key (keys(%FORM)) {
$FORM{$key} =~ s/[^0-9\^.]//g;
}
@results = &math($FORM{'cccount'}, $FORM{'ccticket'}, $FORM{'ccpercent'}, $FORM{'ccfee'}, $FORM{'pbcfee'}, $FORM{'pbcpercent'});
($FORM{'cccount'}, $FORM{'ccticket'}, $FORM{'ccpercent'}, $FORM{'ccfee'}, $FORM{'pbcfee'}, $FORM{'pbcpercent'}, $FORM{'monthly'}, $FORM{'yearly'}) = @results;
$MAIL{'body'} = <Sql($itisql)){
#open(OUTFILE,">>error.log");
#seek(OUTFILE,0,2);
#print OUTFILE "SQL failed.\n";
#print OUTFILE "Error: " . $itidb->Error() . "\n$itisql\n";
#print "Error: " . $itidb->Error() . "\n";
#print OUTFILE "---------------------------------------------------\n";
#close(OUTFILE);
}
}# end if
&display('savings.html');
sub math {
local($cccount) = $_[0];
local($ccticket) = $_[1];
local($ccpercent) = $_[2];
local($ccfee) = $_[3];
local($pbcfee) = $_[4];
local($pbcpercent) = $_[5];
if ($cccount < 0) {$cccount = 0;}
if ($ccticket < 0) {$ccticket = 0;}
if ($ccpercent < 0) {$ccpercent = 0;}
if ($ccfee < 0) {$ccfee = 0;}
if ($pbcfee < 0) {$pbcfee = 0;}
if ($pbcpercent < 0) {$pbcpercent = 0;}
$ccfeeeach = (($ccticket * ($ccpercent / 100)) + $ccfee);
$pbcusers = int($cccount * ($pbcpercent / 100));
$ccusers = ($cccount - $pbcusers);
$ccoldtotal = ($ccfeeeach * $cccount);
$cctotal = ($ccfeeeach * $ccusers);
$pbctotal = ($pbcfee * $pbcusers);
$monthly = ($ccoldtotal - ($cctotal + $pbctotal));
$yearly = ($monthly * 12);
$monthly = &amount($monthly, 1);
$yearly = &amount($yearly, 1);
$ccticket = &amount($ccticket, 1);
$ccfee = &amount($ccfee, 1);
$pbcfee = &amount($pbcfee, 1);
return ($cccount, "\$$ccticket", "$ccpercent\%", "\$$ccfee", "\$$pbcfee", "$pbcpercent\%", "\$$monthly", "\$$yearly");
} # end sub
sub amount {
local($amounttoclean) = $_[0];
$amounttoclean =~ s/\$//g;
$amounttoclean =~ s/\%//g;
$amounttoclean =~ s/,//g;
$amounttoclean = sprintf ("%9.2f",$amounttoclean);$amounttoclean =~ s/ //g;
if ($_[1] > 0) {
if (length($amounttoclean) > 6) {
local($numofcommas) = ((length($amounttoclean) - 6) / 3);
if (int($numofcommas) < $numofcommas) {$numofcommas = (int($numofcommas) + 1);}
$firsttry = 0;
while ($numofcommas >= 0) {
if ($firsttry == 0) {
$tempamount = substr($amounttoclean, 0, (length($amounttoclean) - 6));
$amountarr[$numofcommas] = substr($amounttoclean, (length($amounttoclean) - 6), 6);
$firsttry = 1;
}else{
if (length($tempamount) > 3) {
$amountarr[$numofcommas] = substr($tempamount, (length($tempamount) - 3), 3);
}else{
$amountarr[$numofcommas] = $tempamount;
}
$tempamount = substr($tempamount, 0, (length($tempamount) - 3));
}
$numofcommas -= 1;
}
$amounttoclean = join(',', @amountarr);
}
}
return $amounttoclean;
}
#
# Display
#
sub display {
$pagename = $_[0];
&http;
$template = "$pagename";
if (open(HTXFILE,"$template")) {@htmlfile = ;close(HTXFILE);}
else {print "Can't find template ($template)";}
foreach $key (@htmlfile) {
$html .= $key;
}
if (open(BFILE,"header.html")) {@bfile = ;close(BFILE);}
foreach $key (@bfile) {$bhtml .= $key;}
$include = '';
$html =~ s/$include/$bhtml/g;
foreach $key (keys(%FORM)) {$html =~ s/\[$key\]/$FORM{$key}/g;}
#$html =~ s/\[.*\]//g; #<--------- this line interfered with the java script in the html template.
print $html;
#print "";
} # end sub
#
# Print HTTP Headers
#
sub http {
if($httpdone ne "1"){
foreach $key (keys(%SETCOOKIE)) {
print "Set-Cookie: $key=$SETCOOKIE{$key}; expires=Thu, 15 Apr 2010 20:00:00 GMT; path=/; domain=$cookiedomain\n";
}
print "$HTTP{'header'}";
if ($HTTP{'location'}) {print "Location: $HTTP{'location'}\n\n";}
else {print "Content-type: text/html\n\n";}
$httpdone = 1;
}}
#
# Parse form contents
#
sub parseforms {
if ($ENV{'REQUEST_METHOD'} eq 'GET')
{@pairs = split(/&/, $ENV{'QUERY_STRING'});}
elsif ($ENV{'REQUEST_METHOD'} eq 'POST')
{read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
@pairs = split(/&/, $buffer);}
foreach $pair (@pairs)
{local($name, $value) = split(/=/, $pair);
$name =~ tr/+/ /;
$name =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$value =~ tr/+/ /;$value =~ s///g;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$FORM{$name} = $value;}
foreach (split(/; /,$ENV{'HTTP_COOKIE'})) {
($cookie,$cookievalue) = split(/=/);
$COOKIE{$cookie} = $cookievalue;}
}
#
# Send an email
#
# &sendmail($MAIL{'to'},$MAIL{'from'},$MAIL{'subject'},$MAIL{'body'});
sub sendmail {
use Mail::Sender;
$sender = new Mail::Sender { from => "$_[1]", smtp => '208.49.29.160', boundary => 'This-is-a-mail-boundary-435427'};
$sender->Open({to => "$_[0]", subject => "$_[2]"});
$sender->SendLine("$_[3]");
$sender->Close;
}
#
# Connect to the database
#
sub connectdatabase {
use Win32::ODBC;
########
if (!($itidb = new Win32::ODBC("DSN=iti;UID=sa;PWD=countrbeans6;"))){
#open(OUTFILE,">>error.log");
#seek(OUTFILE,0,2);
#print "Error connecting to the ITI Database\n";
#print "Error: " . Win32::ODBC::Error() . "\n\nTHE EXPORT HAS FAILED!";
#print OUTFILE "Error connecting to the i-Check Database\n";
#print OUTFILE "Error: " . Win32::ODBC::Error() . "\n";
#print OUTFILE "---------------------------------------------------\n";
#close(OUTFILE);
#&sorry;
exit;}
}