Location: PHPKode > projects > Total ISP > total-isp/addtime.php
<?
if (!$CustomerID){
	print "Please Select a <A HREF=\"frmain.php\">user</A>.";
	exit;
}
?><HTML>
<HEAD>
<TITLE>Payment</TITLE>
</HEAD>
<BODY>
<script>

rate="1.00";
c="3";

//these are the minimums
x=new Array(c);
x[0]="0";
x[1]="50";
x[2]="100";

//these are the dollar rates matching the minimums
d=new Array(c);
d[0]="1.50";
d[1]="1.00";
d[2]="0.90";

function dp(price) 
{
   string = "" + price;
   number = string.length - string.indexOf('.');
   if (string.indexOf('.') == -1)
      return string + '.00';
   if (number == 1)
      return string + '00';
   if (number == 2)
      return string + '0';
   if (number > 3)
      return string.substring(0,string.length-number+3);
return string;
}

function getrate(numhours)
{
	for (i=0;i<c;i++){
		if (numhours >= x[i]){
			rate=d[i];
		}
	}
}

function getrate2(numdollars){
	for (i=0;i<c;i++){
		//get the best rate
		numhours=numdollars/d[i];
		if (numhours>=x[i]){
			rate=d[i];
		}
	}
}

function selectplan(){
	document.paycalc.PaymentObject[0].checked=1;
}

function selectalt(){
        document.paycalc.PaymentObject[1].checked=1;
}


function selectadd(){
	document.paycalc.PaymentObject[2].checked=1;
}

function selectmisc(){
	document.paycalc.PaymentObject[3].checked=1;
}

function calch()
{
	getrate(eval(document.paycalc.hours.value));

document.paycalc.dollars.value=eval(document.paycalc.hours.value)*rate;
	document.paycalc.Rate.value=rate;
}

function calcd(){
	getrate2(eval(document.paycalc.dollars.value));

document.paycalc.hours.value=dp(eval(document.paycalc.dollars.value)/rate);
	document.paycalc.Rate.value=rate;
}
</script>

<?
$sql="SELECT FirstName, LastName, ExpireDate, Reseller, CreditCardNumbor,MONTH(CreditCardExp) as mcx, YEAR(CreditCardExp) as ycx 
	FROM MasterAccounts 
	WHERE CustomerID=$CustomerID";

include "mysql.inc.php";

#echo $sql;

$result=mysql_query($sql);
#print mysql_error();
$row=mysql_fetch_array($result);

#get the dealer.
if ($row[3]){
	$dsql="SELECT DealerName FROM Dealer WHERE DealerID=$row[3]";
	$dres=mysql_query($dsql);
	$drow=mysql_fetch_row($dres);
}

$ssql="SELECT Login, AccountType FROM SubAccounts WHERE CustomerID=$CustomerID";
$sres=mysql_query($ssql);
$srow=mysql_fetch_array($sres);

$crsql="SELECT CustomerID FROM Payments WHERE CustomerID=$CustomerID AND Credit > 0";
$crres=mysql_query($crsql);
$apsql="SELECT CustomerID, PaymentDate FROM Payments WHERE CustomerID=$CustomerID AND (TO_DAYS(now())-TO_DAYS(PaymentDate)<7)";
$apres=mysql_query($apsql);
#print $apsql;
if ($apres){
	if (!mysql_fetch_row($apres))
		$apres=0;
}
if ($message)
	print "<B>$message</B>";
?>
Add some time on or service for <H1><? print "$row[FirstName] $row[LastName]"?></H1>
Primary Account Type: <? echo $srow[AccountType] ?><BR>
<? 
if ($ccres) print "<H2><FONT COLOR=RED>Warning!</FONT> User may have outstanding Credit owing</H2><BR>";
if ($apres) print "<H2><FONT COLOR=RED>Warning!</FONT> User has had a payment added within the last week!</H2>";
if ($drow[0]) print "Dealer: $drow[0]<BR>"; 
?>

<P>
<FORM action="addpay.php" method=post name="paycalc">
Payment Type: <SELECT NAME="PaymentType">
<?
$ptsql="SELECT * from PaymentTypes ORDER BY PaymentTypeName";
$ptres=mysql_query($ptsql);
while ($ptrow=mysql_fetch_array($ptres)){
	print "<option";
	if (ereg('Card Pend',$ptrow[PaymentTypeName]))
		print " selected";
	print ">$ptrow[PaymentTypeName]</option>\n";
}
?>
</select> 
<P>Name: <INPUT TYPE=TEXT NAME="RecallName" VALUE="<? echo $row[FirstName]?>">
<P>Contact Detail: <INPUT TYPE=TEXT NAME="RecallPhone">

<? if ( $row[CreditCardNumbor] ){ 
	print "<P>Existing Credit Card Number ends in: ";
	print substr( 
		$row[CreditCardNumbor] , 
		strlen($row[CreditCardNumbor]) -4 
	);
	print " (no need to enter number if correct)";
} 
?>

<P>Credit Card Number: <INPUT TYPE=TEXT SIZE=20 NAME=ccnum>

Credit Card Expires

<SELECT Name="ExpiryDateMonth"><?
for ($i=1;$i<13;$i++){
        print "<OPTION";
        if ($row[mcx]==$i) print " selected";
        if (!$row[mcx]){
                if ($i==date("m")) print " selected";
        }
        print "> ";
        if ($i<10) print "0";
        print "$i </OPTION>\n";
}
?>
</SELECT> / <SELECT Name="ExpiryDateYear">
<?
$ynow=date("Y");
for ($i=0;$i<6;$i++){
        $year=$ynow+$i;
        print "<OPTION";
        if ($year==$row[ycx]) print " selected";
        print "> $year </OPTION>";

}
?></SELECT>


<? if (!$purchase) { ?>
<P><INPUT TYPE="RADIO" NAME="PaymentObject" value="Plan"><B><? echo $srow[AccountType] ?> Plans</B>
<?
if ($srow[AccountType] <> 'dealerspecial') 
	$psql="SELECT * FROM PlanTypes WHERE AccountType='$srow[AccountType]' ORDER BY Cost"; 
#elseif($security > 90)
#	$psql = "SELECT * FROM PlanTypes";
else
	$psql = "SELECT * FROM PlanTypes WHERE AccessFlags LIKE '%S%' AND AccessFlags LIKE '%P%'";


$pres=mysql_query($psql);
while ($prow=mysql_fetch_array($pres)){
?>
<ul><INPUT TYPE="RADIO" NAME="PlanType" value="<? print $prow[PlanID]
?>" onClick="selectplan()"><? print $prow[PlanName] ?> $<? print
$prow[Cost];?></ul>
<?
}
?>

<P><INPUT TYPE="RADIO" NAME="PaymentObject" value="Plan"><B>Alternative Plans</B>
<? 
if($security > 90)
        $psql = "SELECT * FROM PlanTypes WHERE AccountType != '$srow[AccountType]'";
else
        $psql = "SELECT * FROM PlanTypes WHERE (AccessFlags LIKE '%S%' OR AccessFlags LIKE '%P%') AND AccountType
!='$srow[AccountType]'";

$pres=mysql_query($psql);
while ($prow=mysql_fetch_array($pres)){
?>
<ul><INPUT TYPE="RADIO" NAME="PlanType" value="<? print $prow[PlanID]
?>" onClick="selectalt()"><? print $prow[PlanName] ?> $<? print
$prow[Cost];?></ul>
<?
}


?>
<P><INPUT TYPE="RADIO" NAME="PaymentObject" value="Casual">
<B>Add or Subtract Extra Time.</B>
<UL>Hours:
<INPUT TYPE=TEXT size=4 NAME="hours" onClick="selectadd()"></UL>
<UL>Cost: $<input type=text name="dollars"  onClick="selectadd()"> (See
Rate
Sheet)</UL>

<? } #purchase ?>

<P>
<INPUT TYPE="RADIO" NAME="PaymentObject" value="Misc" 
<? if ($purchase) print "checked"; ?>
><B> Miscellaneous Payment</B> 
<UL>Amount: $<INPUT NAME="Misc" TYPE=TEXT onClick="selectmisc()" VALUE="<? echo $cost ?>"></UL>
<UL>Description: <INPUT NAME="MiscDesc" TYPE=TEXT WIDTH=30 VALUE="<? echo $purchase; ?>"></UL>
<P>If you are adding this payment on behalf of a reseller, which one is it? <SELECT NAME="ResellerPay"><OPTION
value="0" SELECTED>(None)</OPTION>
<?
$rsql="SELECT DealerID, DealerName FROM Dealer ORDER BY DealerName";
$rres=mysql_query($rsql);
if ($rres)
	while ($row=mysql_fetch_row($rres))
		echo "<OPTION VALUE=\"$row[0]\">$row[1]</option>";

?></SELECT>
<P>
<P>
<INPUT TYPE=HIDDEN NAME="accounttype" VALUE="<? echo $srow[AccountType] ?>">
<INPUT TYPE=HIDDEN NAME="ID" VALUE="<? echo $CustomerID ?>">
<INPUT TYPE=SUBMIT VALUE="It's all correct, add the payment"> 
</FORM>
</BODY>
</HTML>
Return current item: Total ISP