<?PHP
include "../inc/var.php";
include "../inc/connect.php";
include $server_inc."/client_functions.php";
include $server_inc."/affiliate_functions.php";
include $server_inc."/login_functions.php";

if (isset($request))
	{
	$rsx=mysql_fetch_row(mysql_query("select uid from user where sid='".addslashes(trim($sid))."'"));
	$uid=$rsx[0];

	mysql_query("insert into affiliate_user set uid='".addslashes(trim($uid))."', ogcreate='".time()."', status='2'");

	$done=true;
	}

include $server_admin_inc."/header.php";

// grab the user and email based on sid
$rs0=mysql_fetch_row(mysql_query("select email, uid from user where sid='".addslashes(trim($sid))."'"));
echo("
	<table width='725' cellpadding='2' cellspacing='0' border='0'>
		<tr>
			<td align='left' valign='top'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<img src='".$http_images."/menu_arrow_back.gif'><a href='".$http_admin."/affiliate_details.php?sid=".trim($sid)."'>Go Back</a></td>
			<td align='right' valign='top'><img src='".$http_images."/the_space.gif' width='15' height='9'>Below are the affiliates that this client has refered as of: ".date("m/d/y h:i:s a")."</td>
		</tr>
		<tr>
			<td colspan='2'><img src='".$http_images."/the_space.gif' width='1' height='1'></td>
		</tr>
	</table>
	<table width='725' cellpadding='2' cellspacing='0' border='0'>
		<tr>
			<td width='1%' align='left' valign='center'><img src='".$http_images."/the_space.gif' width='8' height='9'></td>
			<td width='99%' align='left' valign='center'>
			<table width='100%' cellpadding='2' cellspacing='1' border='0'>
				<tr>
					<td align='center' valign='center' bgcolor='#E5E7E9'><b>#</b></td>
					<td align='left' valign='center' bgcolor='#E5E7E9'>&nbsp;&nbsp;<b>Domain</b></td>
					<td align='left' valign='center' bgcolor='#E5E7E9'>&nbsp;&nbsp;<b>Client</b></td>
					<td align='left' valign='center' bgcolor='#E5E7E9'>&nbsp;&nbsp;<b>Payout</b></td>
					<td align='left' valign='center' bgcolor='#E5E7E9'>&nbsp;&nbsp;<b>Created</b></td>
				</tr>
		");
$i=1;
$y=1;
# $row1=mysql_query("select refered_uid, oid, record_payout_type, package_name, total_amount_package, total_due_to_client, UNIX_TIMESTAMP(ogcreate), status from affiliate_details where afuid='".addslashes(trim($afuid))."' and status='1' order by ogcreate, record_payout_type asc");
$row1=mysql_query("select refered_uid, oid, record_payout_type, package_name, total_amount_package, total_due_to_client, ogcreate, status from affiliate_details where afuid='".addslashes(trim($afuid))."' and status='1' order by ogcreate, record_payout_type asc");
while ($rs1=mysql_fetch_row($row1))
	{
	$rs2=mysql_fetch_row(mysql_query("select user.first_name, user.last_name, user.email, hosting_order.domain_name from user, hosting_order where hosting_order.oid='".addslashes(trim($rs1[1]))."' and hosting_order.uid=user.uid order by hosting_order.oid asc limit 0, 1"));
	
	if ($y==1) {$bgcolor="#F2F4F6"; $y=0;} else {$bgcolor="#ECEEF0"; $y=1;}
	echo("
				<tr>
					<td align='center' valign='center' bgcolor='".$bgcolor."'>".$i.").</td>
					<td align='left' valign='center' bgcolor='".$bgcolor."'>&nbsp;&nbsp;<a href='http://".$rs2[3]."'>http://".$rs2[3]."</a></td>
					<td align='left' valign='center' bgcolor='".$bgcolor."'>&nbsp;&nbsp;<a href='mailto:".$rs2[2]."'>".$rs2[0]." ".$rs2[1]."</a></td>
					<td align='left' valign='center' bgcolor='".$bgcolor."'>
					<table width='100%' cellpadding='0' cellspacing='0' border='0'>
						<tr>
							<td align='left' valign='top'>&nbsp;&nbsp;".$currency."".$rs1[5]."".$currency_type."</td>
							<td align='right' valign='top'>[".(($rs1[2]==1)?"One Time":"Monthly")."]&nbsp;&nbsp;</td>
						</tr>
					</table>
					</td>
					<td align='left' valign='center' bgcolor='".$bgcolor."'>&nbsp;&nbsp;".date("m/d/Y h:i:s a", $rs1[6])."</td>
				</tr>
		");
	$i++;
	}
if ($i==1)
	{
	echo("
				<tr>
					<td colspan='4'><img src='".$http_images."/error_arrow.gif'> No records found.</td>
				</tr>
		");
	}
echo("
				<tr>
					<td colspan='4'><img src='".$http_images."/space.gif' width='1' height='10'></td>
				</tr>
			</table>
			</td>
		</tr>
	</table>
	");
include $server_admin_inc."/footer.php";
?>