<?PHP
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($search_db))
	{
	// grab the counts
	if (isset($search_last_name))
		{
		if (strlen(trim($search_last_name))!=0)
			{
			$ct=mysql_fetch_row(mysql_query("select count(*) from user where last_name like '%".addslashes(trim($search_last_name))."%'"));
			if ($ct[0]<1)
				{
				// return nothing
				header("Location: ".$http_admin."/client_view_edit.php?sid=".trim($sid));
				exit;
				}
			else if ($ct[0]==1)
				{
				$rs=mysql_fetch_row(mysql_query("select hosting_order.oid from hosting_order, user where user.last_name like '%".addslashes(trim($search_last_name))."%' and hosting_order.uid=user.uid order by hosting_order.uid asc limit 0, 1"));
				// redirect to record
				header("Location: ".$http_admin."/client_view.php?sid=".trim($sid)."&oid=".trim($rs[0])."&status=99");
				exit;
				}
			else if ($ct[0]>=2)
				{
				$row=mysql_query("select hosting_order.oid from hosting_order, user where user.last_name like '%".addslashes(trim($search_last_name))."%' and user.uid=hosting_order.uid order by hosting_order.oid asc");
				while ($rs=mysql_fetch_row($row))
					{
					if ($gg==1)
						{
						$list_all=$rs[0]."|";
						$gg++;
						}
					else
						{
						$list_all.=$rs[0]."|";
						}
					}

				// redirect back into form
				header("Location: ".$http_admin."/client_view_edit.php?sid=".trim($sid)."&list_all=".trim($list_all));
				exit;
				}
			}
		else
			{
			// return nothing
			header("Location: ".$http_admin."/client_view_edit.php?sid=".trim($sid));
			exit;
			}
		}
	else if(isset($search_domain))
		{
		if (strlen(trim($search_domain))!=0)
			{
			$search_domain=str_replace("http://", "", $search_domain);
			$search_domain=str_replace("www.", "", $search_domain);

			$ct=mysql_fetch_row(mysql_query("select count(*) from hosting_order where domain_name like '%".addslashes(trim($search_domain))."%'"));
			if ($ct[0]<1)
				{
				// return nothing
				header("Location: ".$http_admin."/client_view_edit.php?sid=".trim($sid));
				exit;
				}
			else if ($ct[0]==1)
				{
				$rs=mysql_fetch_row(mysql_query("select oid from hosting_order where domain_name like '%".addslashes(trim($search_domain))."%' limit 0, 1"));

				// redirect to record
				header("Location: ".$http_admin."/client_view.php?sid=".trim($sid)."&oid=".trim($rs[0])."&status=99");
				exit;
				}
			else if ($ct[0]>=2)
				{
				$row=mysql_query("select oid from hosting_order where domain_name like '%".addslashes(trim($search_domain))."%' order by oid asc");
				while ($rs=mysql_fetch_row($row))
					{
					if ($gg==1)
						{
						$list_all=$rs[0]."|";
						$gg++;
						}
					else
						{
						$list_all.=$rs[0]."|";
						}
					}

				// redirect back into form
				header("Location: ".$http_admin."/client_view_edit.php?sid=".trim($sid)."&list_all=".trim($list_all));
				exit;
				}
			}
		else
			{
			// return nothing
			header("Location: ".$http_admin."/client_view_edit.php?sid=".trim($sid));
			exit;
			}
		}
	else
		{
		// return nothing
		header("Location: ".$http_admin."/client_view_edit.php?sid=".trim($sid));
		exit;
		}
	}

if (isset($route_to_record))
	{
	// redirect to record
	header("Location: ".$http_admin."/client_view.php?sid=".trim($sid)."&oid=".trim($oid)."&status=99");
	exit;
	}

include $server_admin_inc."/header.php";

if (isset($delete))
	{
	mysql_query("delete from plan_specs where pid='".addslashes(trim($delete))."'");
	}

// End Form Handler

// define status on entry
if (!isset($status)) 
	{ 
	$query=""; 
	$stats=0;
	$status=99;
	}
else if (trim($status)=="99")
	{
	$query=""; 
	$stats=0;
	}
else if (trim($status)=="0")
	{
	$query="and hosting_order.status='0'"; 
	$stats=1;
	}
else if (trim($status)=="1")
	{
	$query="and hosting_order.status='1'"; 
	$stats=2;
	}
else if (trim($status)=="2")
	{
	// changed to 2 12/19/2002 2:16 AM
	$query="and hosting_order.status='2'"; 
	$stats=3;
	}
else if (trim($status)=="4")
	{
	// changed to 2 12/19/2002 2:16 AM
	$query="and hosting_order.status='4'"; 
	$stats=4;
	}
else if (trim($status)=="5")
	{
	// changed to 2 12/19/2002 2:16 AM
	$query="and hosting_order.status='5'"; 
	$stats=5;
	}

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'>


<table width='100%' border='0' cellspacing='1' cellpadding='2'>
	<form action='".$PHP_SELF."' method='POST'>
	".((isset($pid))?"<input type='hidden' name='pid' value='".trim($pid)."'>":"")."
	<input type='hidden' name='sid' value='".trim($sid)."'>
	<input type='hidden' name='order' value='".trim($order)."'>
	<input type='hidden' name='sort' value='".trim($sort)."'>
	<input type='hidden' name='status' value='".trim($status)."'>
	<tr>
		<td width='20%' align='left' valign='top'>Search by Last Name:</td>
		<td width='80%' align='left' valign='top'><input ".$input_style." type='text' name='search_last_name' size='40' maxlength='255'> <input ".$button_style." type='submit' name='search_db' value='Lookup User'></td>
	</tr>
	</form>
	<tr>
		<td colspan='2' align='left' valign='top'><hr color='#F0EFED'></td>
	</tr>
	<form action='".$PHP_SELF."' method='POST'>
	".((isset($pid))?"<input type='hidden' name='pid' value='".trim($pid)."'>":"")."
	<input type='hidden' name='sid' value='".trim($sid)."'>
	<input type='hidden' name='order' value='".trim($order)."'>
	<input type='hidden' name='sort' value='".trim($sort)."'>
	<input type='hidden' name='status' value='".trim($status)."'>
	<tr>
		<td width='20%' align='left' valign='top'>Search by Domain:</td>
		<td width='80%' align='left' valign='top'><input ".$input_style." type='text' name='search_domain' size='40' maxlength='255'> <input ".$button_style." type='submit' name='search_db' value='Lookup Domain'></td>
	</tr>
	</form>
	");
if (isset($list_all))
	{
	$x=1;
	$tok = strtok($list_all, "|");
	while ($tok) 
		{
		$rsdomain=mysql_fetch_row(mysql_query("select uid, domain_name from hosting_order where oid='".addslashes(trim($tok))."'"));
		$rsuser=mysql_fetch_row(mysql_query("select first_name, last_name, status from user where uid='".addslashes(trim($rsdomain[0]))."'"));
		if ($rsuser[2]!=69)
			{
			if ($x==1)
				{
				$data="<option value='".$tok."'>".$rsuser[0]." ".$rsuser[1]." - ".$rsdomain[1]."</option>\n";
				$x=2;
				}
			else
				{
				$data.="<option value='".$tok."'>".$rsuser[0]." ".$rsuser[1]." - ".$rsdomain[1]."</option>\n";
				$x++;
				}
			}

		$tok = strtok("|");
		}
	if (strlen(trim($data))!=0)
		{
		echo("
			<tr>
				<td colspan='2' align='left' valign='top'><hr color='#F0EFED'></td>
			</tr>
			<form action='".$PHP_SELF."' method='POST'>
			".((isset($pid))?"<input type='hidden' name='pid' value='".trim($pid)."'>":"")."
			<input type='hidden' name='sid' value='".trim($sid)."'>
			<input type='hidden' name='order' value='".trim($order)."'>
			<input type='hidden' name='sort' value='".trim($sort)."'>
			<input type='hidden' name='status' value='".trim($status)."'>
			<tr>
				<td width='20%' align='left' valign='top'>Specify Record:</td>
				<td width='80%' align='left' valign='top'><select name='oid' ".$input_style.">
			");
		echo $data;
		echo("
				</select> <input ".$button_style." type='submit' name='route_to_record' value='View Record'></td>
			</tr>
			</form>
			");
		}
	}
echo("
</table>
	<form action='".$PHP_SELF."' method='POST'>
	".((isset($pid))?"<input type='hidden' name='pid' value='".trim($pid)."'>":"")."
	<input type='hidden' name='sid' value='".trim($sid)."'>

<table width='100%' cellpadding='4' cellspacing='0' border='1' bordercolor='#F0EFED'>
	<tr>
		<td align='center' valign='middle'>
		<table width='100%' cellpadding='0' cellspacing='0' border='0'>
			<tr>
				<td width='1%' align='left' valign='middle'><img src='".$http_images."/view_invoice.gif' alt='View Invoice'>&nbsp;&nbsp;</td>
				<td width='40%' align='left' valign='middle'>Invoice History</td>
			</tr>
		</table>
		</td>
		<td align='center' valign='middle'>
		<table width='100%' cellpadding='0' cellspacing='0' border='0'>
			<tr>
				<td width='1%' align='left' valign='middle'><img src='".$http_images."/icon_view.gif' alt='Order Details'>&nbsp;&nbsp;</td>
				<td width='99%' align='left' valign='middle'>Order Details</td>
			</tr>
		</table>
		</td>
		<td align='center' valign='middle'>
		<table width='100%' cellpadding='0' cellspacing='0' border='0'>
			<tr>
				<td width='1%' align='left' valign='middle'><img src='".$http_images."/icon_cp.gif' alt='Access Client Area'>&nbsp;&nbsp;</td>
				<td width='99%' align='left' valign='middle'>Access Client Area</td>
			</tr>
		</table>
		</td>
		<td align='center' valign='middle'>
		<table width='100%' cellpadding='0' cellspacing='0' border='0'>
			<tr>
				<td width='1%' align='left' valign='middle'><img src='".$http_images."/dedicated.gif' alt='Dedicated Server'>&nbsp;&nbsp;</td>
				<td width='99%' align='left' valign='middle'>Dedicated Server</td>
			</tr>
		</table>
		</td>
		<td align='center' valign='middle'>
		<table width='100%' cellpadding='0' cellspacing='0' border='0'>
			<tr>
				<td width='1%' align='left' valign='middle'><img src='".$http_images."/mailinpayment.gif' alt='Mail in Payment'>&nbsp;&nbsp;</td>
				<td width='99%' align='left' valign='middle'>Mail in Payment</td>
			</tr>
		</table>
		</td>
		<td align='center' valign='middle'>
		<table width='100%' cellpadding='0' cellspacing='0' border='0'>
			<tr>
				<td width='1%' align='left' valign='middle'><img src='".$http_images."/reseller.gif' alt='Reseller'>&nbsp;&nbsp;</td>
				<td width='99%' align='left' valign='middle'>Reseller</td>
			</tr>
		</table>
		</td>
	</tr>
</table>
<table width='725' border='0' cellspacing='1' cellpadding='2'>
		<tr>
			<td align='center' valign='top' bgcolor='#E5E7E9'><b>#</b></td>
			<td align='left' valign='top' bgcolor='#E5E7E9'>&nbsp;&nbsp;<a href='".$http_admin."/client_view_edit.php?sid=".trim($sid)."&order=0&sort=".((isset($sort))?"".((trim($sort)=="0")?"1":"0")."":"0")."&status=".trim($status)."'><b>Client Name</b></a></td>
			<td align='left' valign='top' bgcolor='#E5E7E9'>&nbsp;&nbsp;<a href='".$http_admin."/client_view_edit.php?sid=".trim($sid)."&order=1&sort=".((isset($sort))?"".((trim($sort)=="0")?"1":"0")."":"0")."&status=".trim($status)."'><b>Domain Name</b></a><img src='".$http_images."/space.gif' width='20' height='1'>[<a href='".$http_admin."/client_view_edit.php?sid=".trim($sid)."&status=99'>".((trim($status)=="99")?"<font color='#990000'>Show All</font>":"Show All")."</a>] [<a href='".$http_admin."/client_view_edit.php?sid=".trim($sid)."&status=0'>".((trim($status)=="0")?"<font color='#990000'>Pending</font>":"Pending")."</a>] [<a href='".$http_admin."/client_view_edit.php?sid=".trim($sid)."&status=1'>".((trim($status)=="1")?"<font color='#990000'>Active</font>":"Active")."</a>] [<a href='".$http_admin."/client_view_edit.php?sid=".trim($sid)."&status=2'>".((trim($status)=="2")?"<font color='#990000'>Suspended</font>":"Suspended")."</a>] [<a href='".$http_admin."/client_view_edit.php?sid=".trim($sid)."&status=4'>".((trim($status)=="4")?"<font color='#990000'>Pending Cancel</font>":"Pending Cancel")."</a>] [<a href='".$http_admin."/client_view_edit.php?sid=".trim($sid)."&status=5'>".((trim($status)=="5")?"<font color='#990000'>Cancelled</font>":"Cancelled")."</a>]</td>
			<td align='left' valign='top' bgcolor='#E5E7E9'>&nbsp;&nbsp;<a href='".$http_admin."/client_view_edit.php?sid=".trim($sid)."&order=2&sort=".((isset($sort))?"".((trim($sort)=="0")?"1":"0")."":"0")."&status=".trim($status)."'><b>Created on</b></a></td>
		</tr>
	");

// define order by
if (!isset($order)) 
	{ 
	$order_by="order by user.first_name"; 
	}
else if (trim($order)=="0")
	{
	$order_by="order by user.first_name";
	}
else if (trim($order)=="1")
	{
	$order_by="order by hosting_order.domain_name";
	}
else if (trim($order)=="2")
	{
	$order_by="order by hosting_order.ogcreate";
	}

// define sort on
if (!isset($sort)) 
	{ 
	$sort_by="asc"; 
	}
else if (trim($sort)=="0")
	{
	$sort_by="asc";
	}
else if (trim($sort)=="1")
	{
	$sort_by="desc";
	}
$x=1;
$y=1;
$query0="select ";
$query0.="user.first_name, ";							// 0
$query0.="user.last_name, ";								// 1
$query0.="user.email, ";									// 2
$query0.="user.sid, ";									// 3
$query0.="hosting_order.domain_name, ";					// 4
# $query0.="UNIX_TIMESTAMP(hosting_order.ogcreate), ";		// 5
$query0.="hosting_order.ogcreate, ";		// 5
$query0.="hosting_order.status, ";						// 6
$query0.="hosting_order.oid, ";							// 7
$query0.="hosting_order.pid, ";							// 8
$query0.="plan_specs.dedicated, ";						// 9
$query0.="hosting_order.payment_method, ";				// 10
$query0.="hosting_order.reseller, ";						// 11
$query0.="hosting_order.server_hostname, ";						// 12
$query0.="hosting_order.uid ";						// 13
$query0.="from ";
$query0.="user, ";
$query0.="hosting_order, ";
$query0.="plan_specs ";
$query0.="where ";
$query0.="user.uid=hosting_order.uid ";
$query0.="and ";
$query0.="hosting_order.pid=plan_specs.pid ";
$query0.=$query." ";
$query0.=addslashes(trim($order_by))." ";
$query0.=addslashes(trim($sort_by));

$row=mysql_query($query0);
while ($rs=mysql_fetch_row($row))
	{
	if ($y==1) {$bgcolor="#F2F4F6"; $y=0;} else {$bgcolor="#ECEEF0"; $y=1;}
	$rsf=mysql_fetch_row(mysql_query("select gid from plan_specs where pid='".addslashes(trim($rs[8]))."'"));
	$c=base64_encode($rsf[0]."|".$rs[7]);
	$uid=base64_encode($rs[13]);
	echo("
		<tr>
			<td align='center' valign='top' bgcolor='".$bgcolor."'>".$x.").</td>
			<td align='left' valign='top' bgcolor='".$bgcolor."'>
			<table width='100%' cellpadding='0' cellspacing='0' border='0'>
				<tr>
					<td width='10%' align='left' valign='middle'>&nbsp;&nbsp;<a href='".$http_admin."/invoice_hosting_history.php?sid=".$sid."&uid=".$uid."&oid=".base64_encode($rs[7])."'><img border='0' src='".$http_images."/view_invoice.gif' alt='Click to view invoice history for this domain and billable services for the client.'></a>&nbsp;&nbsp;<a href='".$http_admin."/client_view.php?sid=".trim($sid)."&oid=".trim($rs[7])."&status=".trim($status)."'><img border='0' src='".$http_images."/icon_view.gif' alt='Click to view order details.'></a>&nbsp;&nbsp;<a href='".$http_web."/client_area.php?sid=".trim($rs[3])."' target='_blank'><img border='0' src='".$http_images."/icon_cp.gif' alt='Click to view the client area.'></a></td>
					<td width='90%' align='left' valign='middle'>&nbsp;&nbsp;<a href='mailto:".$rs[2]."'>".(($rs[8]==999)?"<font color='#990000'>":"")."".stripslashes($rs[0])." ".stripslashes($rs[1])."".(($rs[8]==999)?"</font>":"")."</a></td>
				</tr>
			</table>
		</td>
			<td align='left' valign='top' bgcolor='".$bgcolor."'>
			<table width='100%' cellpadding='0' cellspacing='0' border='0'>
				<tr>
					<td width='80%' align='left' valign='top'>&nbsp;&nbsp;");
	if ($rs[9]==1) { echo "<img src='".$http_images."/dedicated.gif' alt='Dedicated Server'>&nbsp;"; }
	if ($rs[10]==6) { echo "<img src='".$http_images."/mailinpayment.gif' alt='Mail in Payment'>&nbsp;"; }
	if ($rs[10]==1) { echo "<img src='".$http_images."/paypal_gif.gif' alt='PayPal'>&nbsp;"; }
	if ($rs[10]==3) { echo "<img src='".$http_images."/paysystems_gif.gif' alt='PaySystems'>&nbsp;"; }
	if ($rs[10]==8) { echo "<img src='".$http_images."/auth_gif.gif' alt='Authorize.net'>&nbsp;"; }
	if ($rs[10]==2) { echo "<img src='".$http_images."/wp_gif.gif' alt='WorldPay'>&nbsp;"; }
	if ($rs[10]==4) { echo "<img src='".$http_images."/2co_gif.gif' alt='2Checkout.com'>&nbsp;"; }
	if ($rs[11]==1) { echo "<img src='".$http_images."/reseller.gif' alt='Reseller'>&nbsp;"; }
	unset($bit);
	echo("<a href='http://".(($rs[9]==1)?"".$rs[12].".":"")."".$rs[4]."' target='_blank'>http://".(($rs[9]==1)?"".$rs[12].".":"")."".stripslashes($rs[4])."</a></td>
					<td width='20%' align='center' valign='top'>
		");
	if ($rs[6]==0) { echo "Pending"; }
	else if ($rs[6]==1) { echo "Active"; }
	else if ($rs[6]==2) { echo "Suspended"; }
	else if ($rs[6]==4) { echo "Pending Cancel"; }
	else if ($rs[6]==5) { echo "Cancelled"; }

	echo("
					</td>
				</tr>
			</table>
			</td>
			<td align='left' valign='top' bgcolor='".$bgcolor."'>&nbsp;&nbsp;".date("m/d/Y", $rs[5])."</td>
		</tr>
		");
	$x++;
	}
if ($x==1&&$stats==0)
	{
	echo("
		<tr>
			<td colspan='5'><br><img src='".$http_images."/error_arrow.gif'>No orders found in the database.</td>
		</tr>
		");
	}
else if ($x==1&&$stats==1)
	{
	echo("
		<tr>
			<td colspan='5'><br><img src='".$http_images."/error_arrow.gif'>No pending orders found in the database.</td>
		</tr>
		");
	}
else if ($x==1&&$stats==2)
	{
	echo("
		<tr>
			<td colspan='5'><br><img src='".$http_images."/error_arrow.gif'>No active orders found in the database.</td>
		</tr>
		");
	}
else if ($x==1&&$stats==3)
	{
	echo("
		<tr>
			<td colspan='5'><br><img src='".$http_images."/error_arrow.gif'>No suspended orders found in the database.</td>
		</tr>
		");
	}
else if ($x==1&&$stats==4)
	{
	echo("
		<tr>
			<td colspan='5'><br><img src='".$http_images."/error_arrow.gif'>No pending cancel orders found in the database.</td>
		</tr>
		");
	}
else if ($x==1&&$stats==5)
	{
	echo("
		<tr>
			<td colspan='5'><br><img src='".$http_images."/error_arrow.gif'>No cancelled orders found in the database.</td>
		</tr>
		");
	}
echo("
</table>
</form>
			</td>
		</tr>
	</table>
	<table width='100%' cellpadding='0' cellspacing='0'>
		<tr>
			<td><img src='".$http_images."/space.gif' width='1' height='6'></td>
		</tr>
	</table>
	");
// End Main Process
mysql_close($dblink);
include $server_admin_inc."/footer.php";
?>