<?PHP
$query_ct0="select ";
$query_ct0.="ccid, ";
$query_ct0.="count(*) ";
$query_ct0.="from ";
$query_ct0.="authnet_master_cc ";
$query_ct0.="where ";
$query_ct0.="uid='".addslashes(trim($uid))."' ";
$query_ct0.="and ";
$query_ct0.="master_cc='1' ";
$query_ct0.="group by ccid";

$rs_ct0=mysql_fetch_row(mysql_query($query_ct0));

$ccid=stripslashes(trim($rs_ct0[0]));
$countMCC=stripslashes(trim($rs_ct0[1]));

if ($countMCC<1)
	{
	$query_ct0="select ";
	$query_ct0.="ccid, ";
	$query_ct0.="count(*) ";
	$query_ct0.="from ";
	$query_ct0.="authnet_master_cc ";
	$query_ct0.="where ";
	$query_ct0.="uid='".addslashes(trim($uid))."' ";
	$query_ct0.="group by ccid";
	$query_ct0.="order by ccid desc limit 0, 1";

	$rs_ct0=mysql_fetch_row(mysql_query($query_ct0));

	$ccid=stripslashes(trim($rs_ct0[0]));
	$countMCC=stripslashes(trim($rs_ct0[1]));
	}

# grab the package name
$query1="select ";
$query1.="package_name ";	// 0
$query1.="from ";
$query1.="plan_specs ";
$query1.="where ";
$query1.="pid='".addslashes(trim($processor_id))."'";

$rs1=mysql_fetch_row(mysql_query($query1));

$package_name=stripslashes(trim($rs1[0]));

# ----------------------------------------------------

$query2="update ";
$query2.="authnet_batch ";
$query2.="set ";
$query2.="master_batch='0' ";
$query2.="where ";
$query2.="oid='".addslashes(trim($oid))."' ";

mysql_query($query2);

# ----------------------------------------------------

# insert a complete promoted master batch 
$query0="insert ";
$query0.="into ";
$query0.="authnet_batch ";
$query0.="set ";
$query0.="description='".addslashes(trim($package_name))."', ";
$query0.="ccid='".addslashes(trim($ccid))."', ";
$query0.="oid='".addslashes(trim($oid))."', ";
$query0.="uid='".addslashes(trim($uid))."', ";
$query0.="ogcreate='".addslashes(trim($authnet_due_date))."', ";
$query0.="invoice_number='".addslashes(trim($invoice_number))."', ";
$query0.="master_batch='1'";

mysql_query($query0);

/*
# ----------------------------------------------------
# have any previous master cc on file?
$query_ct="select ";
$query_ct.="count(*) ";
$query_ct.="from ";
$query_ct.="authnet_master_cc ";
$query_ct.="where ";
$query_ct.="master_cc='1' ";
$query_ct.="and ";
$query_ct.="uid='".addslashes(trim($uid))."'";

$ct=mysql_fetch_row(mysql_query($query_ct));

$countCC=$ct[0];

if ($countCC<=0)
	{
	# have any previous master cc on file?
	$query_ct="select ";
	$query_ct.="count(*) ";
	$query_ct.="from ";
	$query_ct.="authnet_master_cc ";
	$query_ct.="where ";
	$query_ct.="master_cc='1' ";
	$query_ct.="and ";
	$query_ct.="uid='".addslashes(trim($uid))."'";

	$ct=mysql_fetch_row(mysql_query($query_ct));

	$countCC=$ct[0];
	}

# ----------------------------------------------------

# grab the package name
$query1="select ";
$query1.="package_name ";	// 0
$query1.="from ";
$query1.="plan_specs ";
$query1.="where ";
$query1.="pid='".addslashes(trim($processor_id))."'";

$rs1=mysql_fetch_row(mysql_query($query1));

$package_name=stripslashes(trim($rs1[0]));

# ----------------------------------------------------

# grab data for the clone
$query1="select ";
$query1.="customer_ip_address, ";	// 0
$query1.="description, ";			// 1
$query1.="currency_code, ";			// 2
$query1.="customer_first_name, ";	// 3
$query1.="customer_last_name, ";	// 4
$query1.="customer_address, ";		// 5
$query1.="customer_city, ";			// 6
$query1.="customer_state, ";		// 7
$query1.="customer_zip, ";			// 8
$query1.="customer_country, ";		// 9
$query1.="customer_phone, ";		// 10
$query1.="customer_fax, ";			// 11
$query1.="customer_email, ";		// 12
$query1.="card_info, ";				// 13
$query1.="transaction_type ";		// 14
$query1.="from ";
$query1.="authnet_batch ";
$query1.="where ";
$query1.="oid='".addslashes(trim($oid))."' ";
if ($count>0)
	{
	$query1.="and ";
	$query1.="master_batch='1' ";
	}
$query1.="limit 0, 1 ";
$query1.="order by bid desc";

$rs1=mysql_fetch_row(mysql_query($query1));

$customer_ip_address=stripslashes(trim($rs1[0]));
$description=stripslashes(trim($rs1[1]));
$currency_code=stripslashes(trim($rs1[2]));
$customer_first_name=stripslashes(trim($rs1[3]));
$customer_last_name=stripslashes(trim($rs1[4]));
$customer_address=stripslashes(trim($rs1[5]));
$customer_city=stripslashes(trim($rs1[6]));
$customer_state=stripslashes(trim($rs1[7]));
$customer_zip=stripslashes(trim($rs1[8]));
$customer_country=stripslashes(trim($rs1[9]));
$customer_phone=stripslashes(trim($rs1[10]));
$customer_fax=stripslashes(trim($rs1[11]));
$customer_email=stripslashes(trim($rs1[12]));
$card_info=stripslashes(trim($rs1[13]));
$transaction_type=stripslashes(trim($rs1[14]));

# ----------------------------------------------------

# no previous master batch found
if ($count>0) 
	{ 	
	$query2="update ";
	$query2.="authnet_batch ";
	$query2.="set ";
	$query2.="master_batch='0' ";
	$query2.="where ";
	$query2.="oid='".addslashes(trim($oid))."' ";
	$query2.="and ";
	$query2.="master_batch='1'";

	mysql_query($query2);
	}

# ----------------------------------------------------

$query2="update ";
$query2.="authnet_batch ";
$query2.="set ";
$query2.="master_batch='0' ";
$query2.="where ";
$query2.="oid='".addslashes(trim($oid))."' ";
$query2.="and ";
$query2.="master_batch='1'";

mysql_query($query2);

# insert a complete promoted master batch 
$query0="insert ";
$query0.="into ";
$query0.="authnet_batch ";
$query0.="set ";
$query0.="customer_ip_address='".addslashes(trim($customer_ip_address))."', ";
$query0.="description='".addslashes(trim($description))."', ";
$query0.="currency_code='".addslashes(trim($currency_code))."', ";
$query0.="customer_first_name='".addslashes(trim($customer_first_name))."', ";
$query0.="customer_last_name='".addslashes(trim($customer_last_name))."', ";
$query0.="customer_address='".addslashes(trim($customer_address))."', ";
$query0.="customer_city='".addslashes(trim($customer_city))."', ";
$query0.="customer_state='".addslashes(trim($customer_state))."', ";
$query0.="customer_zip='".addslashes(trim($customer_zip))."', ";
$query0.="customer_country='".addslashes(trim($customer_country))."', ";
$query0.="customer_phone='".addslashes(trim($customer_phone))."', ";
$query0.="customer_fax='".addslashes(trim($customer_fax))."', ";
$query0.="customer_email='".addslashes(trim($customer_email))."', ";
$query0.="card_info='".addslashes(trim($card_info))."', ";
$query0.="transaction_type='".addslashes(trim($transaction_type))."', ";
$query0.="batch_status='0', ";
$query0.="oid='".addslashes(trim($oid))."', ";
$query0.="uid='".addslashes(trim($uid))."', ";
$query0.="ogcreate='".addslashes(trim($authnet_due_date))."', ";
$query0.="master_batch='1'";

mysql_query($query0);
*/
?>