20) /* to limit the damage - LoL */
{
$rate = 20;
}
if($rate > 1)
{
$rate = abs($rate / 100.);
}
else
{
$rate = 3.5 / 100.;
}
if (isset($_GET['term']))
{
$term = floatval(trim($_GET['term']));
}
if ($term == '' || $term < 1 || $term == ' ')
{
$term = 1;
}
elseif ($term > 800) /* to limit the damage - LoL */
{
$term = 800;
}
else
{
$term = round(abs($term));
}
$name = addslashes($name);
$year = 1;
$lastpayment = 1;
/* all literal strings provided by a client must be escaped this way
* if you inject them into an HTML page
*/
htmlspecialchars($name);
/* calculate the montly payment amount */
$payment = $amount*$rate/12*pow(1+$rate/12,$term*12)/(pow(1+$rate/12,$term*12)-1);
/* build the top of our HTML page */
$cost = ($term*12*$payment)-$amount;
$result = "";
$result .= sprintf("" .
"" .
"" .
"Loan calculator " .
" " .
"" .
"" .
"Dear $name, your loan goes as follows: ");
$result .= sprintf(" " .
"" .
"" .
"" .
"" .
"" .
"loan details Amount %s Rate %.2f%% Term %u %s(s) Cost %s (%.2f%%)

", number_format($amount, 2), $rate*100,
$term,($term>0)?"year":"month",
number_format($cost,2), 100/($amount/$cost));
$result .= sprintf(" " .
"" .
"" .
"" .
"", $year);
for($month = 1; $month <= 12; $month++) // ouput monthly payments
{
$interest = ($amount*$rate)/12;
if($amount > $payment)
{
$amount = ($amount-$payment) + $interest;
$principal = $payment - $interest;
}
else // calculate last payment
{
if($lastpayment > 0)
{
$lastpayment = 0;
$payment = $amount;
$principal = $amount - $interest;
$amount = 0;
}
else // all payments are done, just pad the table
{
$amount = 0;
$payment = 0;
$interest = 0;
$principal = 0;
}
}
$result .= sprintf("",
$month%2, $monthList[$month-1],
number_format($payment, 2),
number_format($interest, 2),
number_format($principal, 2),
number_format($amount, 2));
if($month == 12)
{
if($amount)
{
$month = 0;
$year++;
$result .= sprintf("month payment interest principal balance %s %s " .
"%s %s %s

" .
"" .
"",
$year);
}
}
}
/* time the process, print the HTML page and close the program with a "200" return code */
$result .= sprintf("month payment interest principal balance

This page was generated in %.2F ms. (on a 3GHz CPU 1 ms = 3,000,000 cycles)".
" ",number_format(((microtime(true)-$time_start)*1000),2));
echo $result;
exit(200);
}
?>