<?PHP
require '/usr/local/cpanel/Cpanel/Accounting.php.inc';

$SQL = "SELECT * from SETTINGS";
$result = mysql_query( $SQL ); while( $row = mysql_fetch_array( $result ) ) {
$host = $row["HOST"];
$rak = $row["RAK"];
$user = $row["USER"];}

$accesshash = "$rak";

createacct ($host,$user,$accesshash,$usessl,$domain,$un,$pw,$package);

$viewaccounts = listaccts( $host , $user , $accesshash , 0);
$keys = array_keys( $viewaccounts );

$newUser="$un";

if( array_key_exists($newUser, $viewaccounts) )
{}else{

$to="$from";
$headers.= "MIME-Version: 1.0\r\n";
$headers.= "Content-type: text/html; ";
$headers.= "charset=iso-8859-1\r\n";

$headers.= "From: Auto-Host 2";

$subject = "There was a problem creating an account";
$body = "Account creation failed to setup an account for $payer_email<br><br>$domain<br>$un : $pw <br> $package";

$send_check=mail($to,$subject,$body,$headers);if ($send_check!=true) {die();}

die();
}



//-----------------------------------------
$month=date(m);
$day=date(d);
$year=date(Y);

$today  = strftime ("%B %d, %Y", mktime(0, 0, 0, date("m") , date("d"), date("Y")));
$month  = strftime ("%B %d, %Y", mktime(0, 0, 0, date("m")+1  , date("d"), date("Y")));
$quarter  = strftime ("%B %d, %Y", mktime(0, 0, 0, date("m")+3  , date("d"), date("Y")));
$semi  = strftime ("%B %d, %Y", mktime(0, 0, 0, date("m")+6  , date("d"), date("Y")));
$anually  = strftime ("%B %d, %Y", mktime(0, 0, 0, date("m")  , date("d"), date("Y")+1));
$twoyears  = strftime ("%B %d, %Y", mktime(0, 0, 0, date("m")  , date("d"), date("Y")+2));

if ($period3 == '1 M') {$next = $month;}else{}
if ($period3 == '3 M') {$next = $quarter;}else{}
if ($period3 == '6 M') {$next = $semi;}else{}
if ($period3 == '1 Y') {$next = $anually;}else{}
if ($period3 == '2 Y') {$next = $twoyears;}else{}
//-----------------------------------------
$sql = "INSERT INTO CLIENTS SET
PAYER_EMAIL ='$payer_email' ,
USERNAME ='$un' ,
DOMAIN ='$domain' ,
CPW ='$pw' ,
PACKAGE ='$item_name' ,
SIGNUPDATE = '$today',
IG ='$price' ,
LASTPAYMENT = '$today',
UNI = '$item_number',
STATUS ='Active' ,
NEXTPAYMENT ='$next'";
$query = mysql_query($sql) or die("Cannot query the database.<br>" . mysql_error());

$sql = "INSERT INTO MAILINGLIST SET
PAYER_EMAIL ='$payer_email' ,
PRODUCT ='$item_name'";
$query = mysql_query($sql) or die("Cannot query the database.<br>" . mysql_error());

?>
