<?PHP
//echo mktime(0, 0, 0, date("m"), date("d"), date("Y")); die;
include "../inc/var.php";
include "../inc/connect.php";
include $server_inc."/whm_functions.php";
include $server_inc."/client_functions.php";
include $server_inc."/login_functions.php";

if (isset($del)) { mysql_query("delete from authnet_batch where bid='".addslashes(trim($bid))."'"); }

if (phpversion()<="4.0.6") { $_POST=$HTTP_POST_VARS; }
if (isset($_POST['submit']))
	{
	if (isset($_POST['ccid']))
		{
		while (list($key, $value)=each($ccid)) 
			{ 
			$xc.=$value."|";	
			}
		header("Location: ".$http_admin."/process_batch.php?sid=".$sid."&xc=".base64_encode($xc));
		exit;
		}
	}

include $server_admin_inc."/header.php";

echo("
	<table width='725' cellpadding='0' cellspacing='0' border='0'>
		<tr>
			<td width='1%' align='left' valign='top'><img src='".$http_images."/space.gif' width='15' height='375'></td>
			<td width='99%' align='left' valign='top'>
			<form action='".$PHP_SELF."' method='POST'>
			<input type='hidden' name='sid' value='".$sid."'>
			<input type='hidden' name='c' value='".$c."'>
			<table width='100%' cellpadding='4' cellspacing='1' border='0'>
	");
$data=("
				<tr>
					<td colspan='".(($c==1)?"4":"6")."' align='left' valign='middle'>[&nbsp;<a href='".$http_admin."/manage_batch.php?sid=".$sid."'>Go Back</a>&nbsp;]&nbsp;&nbsp;<b>
		");
	if ($c==0) { $data.="Open Batch Editor";}
	else if ($c==1) { $data.="Completed Batch History";}
	else if ($c==2) { $data.="Declined Batch History";}
	else if ($c==3) { $data.="Error Batch History";}
	$data.=("
			</b></td>
				</tr>
				<tr>
					".(($c!=1)?"<td align='center' valign='middle' bgcolor='#E5E7E9'>&nbsp<b>Include</b></td>":"")."
					<td align='center' valign='middle' bgcolor='#E5E7E9'>&nbsp<b>Edit Batch</b></td>
					".(($c!=1)?"<td align='center' valign='middle' bgcolor='#E5E7E9'>&nbsp<b>Delete Batch</b></td>":"")."
					<td align='left' valign='middle' bgcolor='#E5E7E9'>&nbsp<b>Domain Name</b> [click the domain to view account information]</td>
					<td align='left' valign='middle' bgcolor='#E5E7E9'>&nbsp<b>Batch Created</b></td>
					<td align='left' valign='middle' bgcolor='#E5E7E9'>&nbsp<b>Invoice</b></td>
					<td align='left' valign='middle' bgcolor='#E5E7E9'>&nbsp<b>Amount Due</b></td>
				</tr>
	");
$query="select ";
$query.="hosting_order.domain_name, ";				// 0
# $query.="UNIX_TIMESTAMP(hosting_order.ogcreate), ";	// 1
$query.="hosting_order.ogcreate, ";	// 1
$query.="hosting_order.next_due_date, ";			// 2
$query.="authnet_batch.bid, ";						// 3
$query.="hosting_order.oid, ";						// 4
$query.="hosting_order.status, ";					// 5
$query.="hosting_order.total_due_today, ";			// 6
$query.="hosting_order.total_due_reoccur, ";		// 7
$query.="authnet_batch.ogcreate, ";					// 8
$query.="authnet_batch.ccid, ";						// 9
$query.="authnet_batch.invoice_number ";				// 10
$query.="from ";
$query.="hosting_order, ";
$query.="authnet_batch ";
$query.="where ";
$query.="authnet_batch.batch_status='".addslashes(trim($c))."' ";
$query.="and ";
$query.="authnet_batch.oid=hosting_order.oid ";
$query.="order by authnet_batch.bid asc";

$y=1;
$g=0;
$row=mysql_query($query);
while ($rs=mysql_fetch_row($row))
	{
	if ($y==1) {$bgcolor="#F2F4F6"; $y=0;} else {$bgcolor="#ECEEF0"; $y=1;}

	$domain_name=stripslashes(trim($rs[0]));
	$hogcreate=stripslashes(trim($rs[1]));
	$next_due_date=stripslashes(trim($rs[2]));
	$bid=stripslashes(trim($rs[3]));
	$oid=stripslashes(trim($rs[4]));
	$status=stripslashes(trim($rs[5]));
	$total_due_today=stripslashes(trim($rs[6]));
	$total_due_reoccur=stripslashes(trim($rs[7]));
	$ogcreate=stripslashes(trim($rs[8]));
	$ccid=stripslashes(trim($rs[9]));
	$thisinvoice=stripslashes(trim($rs[10]));
	if ($total_due_today==0&&$total_due_reoccur==0) { $onesub_total=0; }
	else if ($total_due_today==0) { $onesub_total=$total_due_reoccur; }
	else { $onesub_total=$total_due_today; }
		$sub_total=sprintf("%01.2f", ($onesub_total));
	$data.=("
				<tr>
					".(($c!=1)?"<td align='center' valign='middle' bgcolor='".$bgcolor."'><input type='checkbox' name='ccid[]' value='".$ccid."{{}}".$oid."{{}}".$bid."'></td>":"")."

					<td align='center' valign='middle' bgcolor='".$bgcolor."'>&nbsp[<a href='".$http_admin."/master_batch.php?sid=".$sid."&ccid=".$ccid."&bid=".$bid."&c=".$c."'>click</a>]</td>
					
					".(($c!=1)?"<td align='center' valign='middle' bgcolor='".$bgcolor."'>&nbsp[<a href='".$PHP_SELF."?sid=".$sid."&bid=".$bid."&c=".$c."&del=5'>click</a>]</td>":"")."
					
					<td align='left' valign='middle' bgcolor='".$bgcolor."'>&nbsp;<a href='".$http_admin."/client_view.php?sid=".$sid."&oid=".$oid."'>http://".$domain_name."</td>
					<td align='left' valign='middle' bgcolor='".$bgcolor."'>&nbsp".date("m/d/Y", $ogcreate)."</td>
						<td align='left' valign='middle' bgcolor='".$bgcolor."'><center><b>".$thisinvoice."</td>
					<td align='left' valign='middle' bgcolor='".$bgcolor."'>&nbsp".$currency."&nbsp".(($status==0)?"".$sub_total."":"".$sub_total."")."&nbsp".$currency_type."</td>
				</tr>
		");
	
	$g+=1;
	unset($domain_name);
	unset($hogcreate);
	unset($next_due_date);
	unset($bid);
	}
if ($g==0) 
	{ 
	echo("
		<tr>
			<td align='left' valign='middle'>[&nbsp;<a href='".$http_admin."/manage_batch.php?sid=".$sid."'>Go Back</a>&nbsp;]&nbsp;&nbsp;<b>
		");
	if ($c==0) { echo "Open Batch Editor";}
	else if ($c==1) { echo "Completed Batch History";}
	else if ($c==2) { echo "Declined Batch History";}
	else if ($c==3) { echo "Error Batch History";}
	echo ("
			</b></td>
		</tr>
		<tr>
			<td align='left' valign='middle'><hr color='#F0EFED'></td>
		</tr>
		<tr>
			<td>
		");
	if ($c==0) { echo "Found no open batches.";}
	else if ($c==1) { echo "Found no completed batch history.";}
	else if ($c==2) { echo "Found no declined batches.";}
	else if ($c==3) { echo "Found no error batches.";}
	echo("
			</td>
		</tr>
		");
	}
else
	{ 
	echo $data;
	if ($c!=1)
		{
		echo("
				<tr>
					<td colspan='".(($c==1)?"4":"6")."' align='right' valign='middle'><br><input ".$button_style." type='submit' name='submit' value='Run Batch Now'></td>
				</tr>
			");
		}
	}
echo("
			</table>
			</form>
			</td>
		</tr>
	</table>
	");

include $server_admin_inc."/footer.php";
mysql_close($dblink);
?>