<?PHP
echo("
<table width='725' cellpadding='2' cellspacing='0' border='0'>
	<tr>
		<td align='left' valign='top'><img src='".$http_images."/error_arrow.gif'>This account record was updated <b>successfully</b> in the AutoPilot system!</td> 
	</tr>
	<tr>
		<td><img src='".$http_images."/space.gif' width='1' height='2'></td>
	</tr>
	<tr>
		<td><img src='".$http_images."/space.gif' width='15' height='9'><img src='".$http_images."/drop_arrow.gif'><a href='".$http_admin."/csv.php?sid=".trim($sid)."&whm_id=".trim($whm_id)."'>Import Utility Home</a></td>
	</tr>
	<tr>
		<td><img src='".$http_images."/space.gif' width='1' height='2'></td>
	</tr>
	<tr>
		<td><img src='".$http_images."/space.gif' width='15' height='9'><img src='".$http_images."/drop_arrow.gif'><a href='".$http_admin."/csv_add_user_accounts.php?sid=".trim($sid)."&whm_id=".trim($whm_id)."'>Add Account to User</a></td>
	</tr>
	");
$q="select ";
$q.="payment_process.name, ";			// 0
$q.="hosting_order.uid, ";				// 1
$q.="hosting_order.payment_term, ";		// 2
$q.="hosting_order.ogcreate, ";			// 3
$q.="hosting_order.resolved_time, ";	// 4
$q.="hosting_order.ur_date, ";			// 5
$q.="hosting_order.cancel_date, ";		// 6
$q.="hosting_order.domain_name, ";		// 7
$q.="hosting_order.pid ";				// 8
$q.="from ";
$q.="hosting_order, ";
$q.="payment_process ";
$q.="where ";
$q.="oid='".addslashes(trim($oid))."' ";
$q.="and ";
$q.="hosting_order.payment_method=payment_process.pid ";
$q.="limit 0, 1";

$rs=mysql_fetch_row(mysql_query($q));
if (ereg("authorize", strtolower($rs[0]))==true)
	{
	$payment_name=stripslashes(trim($rs[0]));
	$uid=stripslashes(trim($rs[1]));
	$payment_term=stripslashes(trim($rs[2]));
	$ogcreate=stripslashes(trim($rs[3]));
	$resolved_time=stripslashes(trim($rs[4]));
	$ur_date=stripslashes(trim($rs[5]));
	$cancel_date=stripslashes(trim($rs[6]));
	$domain_name=stripslashes(trim($rs[7]));
	$pid=stripslashes(trim($rs[8]));

	# calc next due date
	# -------------------------------------------------------------------------------------------------------
	# which == 0 == return timestamp from todays date
	# which == 1 == use hosting order ogcreate to build next due date
	$next_due_date=find_next_due($payment_term, $oid, 1);
	list($proc_bit, $other)=explode("|", $next_due_date);
	if ($proc_bit==0) 
		{ 
		$subject="[AutoPilot System] Possible Invalid Start Date";
		$message="Please check that the start date for ".$other." is correct. We could not create a next due date for this order.";
		mail($email_admin, $subject, $message, "From: ".$email_admin."\nReply-To: ".$email_admin."\nX-Mailer: PHP/".phpversion());
		$next_due_date="";  
		}
	else { $next_due_date=$other; }
	# -------------------------------------------------------------------------------------------------------
	# END calc next due date
	
	if (trim($next_due_date)!="") 
		{
		$query5="update ";
		$query5.="hosting_order ";
		$query5.="set ";
		$query5.="next_due_date='".addslashes(trim($next_due_date))."', ";
		$query5.="ogcreate='".addslashes(trim($ogcreate))."', ";
		$query5.="resolved_time='".addslashes(trim($resolved_time))."', ";
		$query5.="ur_date='".addslashes(trim($ur_date))."', ";
		$query5.="cancel_date='".addslashes(trim($cancel_date))."' ";
		$query5.="where ";
		$query5.="oid='".addslashes(trim($oid))."'";

		mysql_query($query5);
		}
	
	$r=mysql_fetch_row(mysql_query("select package_name from plan_specs where pid='".addslashes(trim($pid))."'"));

	$query="insert into ";
	$query.="authnet_batch ";
	$query.="set ";
	$query.="description='".$r[0]." [".$domain_name."]', ";
	$query.="uid='".addslashes(trim($uid))."', ";
	$query.="oid='".addslashes(trim($oid))."', ";
	$query.="master_batch='1', ";
	$query.="ogcreate='".time()."'";

	mysql_query($query);

	$bid=mysql_insert_id();

	echo("
		<tr>
			<td><img src='".$http_images."/space.gif' width='1' height='2'></td>
		</tr>
		<tr>
			<td><img src='".$http_images."/space.gif' width='15' height='9'><img src='".$http_images."/drop_arrow.gif'><a href='".$http_admin."/master_batch.php?sid=".$sid."&bid=".$bid."'>Enter Credit Card information for this client.</a></td>
		</tr>
		");
	}
echo("
	<tr>
		<td><img src='".$http_images."/space.gif' width='1' height='8'></td>
	</tr>
</table>
	");
?>