<?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";

// START CONNECTION STRING ----------------------

// get the server IP
$rsip=mysql_fetch_row(mysql_query("select server_ip, server_name from server_config where whm_id='".addslashes(trim($whm_id))."'"));
$server_ip=trim($rsip[0]);
$server_name=trim($rsip[1]);

// read in logins
$temp=@read_log($whm_id, $below_public);
list($xwhm_username, $xwhm_password)=split("[|]", $temp);

// END CONNECTION STRING ------------------------

if (isset($submit))
	{
	$r=mysql_fetch_row(mysql_query("select whm_username from hosting_order where oid='".addslashes(trim($oid))."'"));
	$username=stripslashes(trim($r[0]));

	$s=mysql_fetch_row(mysql_query("select reseller_primary_domain from user where uid='".addslashes(trim($uid))."'"));
	$new_owner_oid=stripslashes(trim($s[0]));
	if ($new_owner_oid==0)
		{
		$err=true;
		}
	else
		{
		$t=mysql_fetch_row(mysql_query("select whm_username from hosting_order where oid='".addslashes(trim($new_owner_oid))."'"));
		$new_owner=stripslashes(trim($t[0]));

		change_ownership($server_ip, $xwhm_username, $xwhm_password, $username, $new_owner);

		mysql_query("update hosting_order set hosting_order.reseller='1', hosting_order.ogcreate='hosting_order.ogcreate', hosting_order.ur_date='hosting_order.ur_date', hosting_order.resolved_time='hosting_order.resolved_time', hosting_order.uid='".addslashes(trim($uid))."' where oid='".addslashes(trim($oid))."'");
		}
	}

include $server_admin_inc."/header.php";

echo("
	<form action='".$PHP_SELF."' method='POST'>
	<input type='hidden' name='sid' value='".trim($sid)."'>
	<input type='hidden' name='whm_id' value='".trim($whm_id)."'>
	<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%' cellpadding='2' cellspacing='0' border='0'>
				<tr>
					<td colspan='2' align='left' valign='top'><img src='".$http_images."/menu_arrow.gif'><b>Change Ownership of an Account</b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[<a href='".$http_admin."/csv.php?sid=".$sid."&whm_id=".trim($whm_id)."'>Go Back</a>]</td>
				</tr>
				<tr>
					<td colspan='2' align='left' valign='top'><img src='".$http_images."/space.gif' width='1' height='2'></td>
				</tr>
				<tr>
					<td colspan='2' align='left' valign='top'><img src='".$http_images."/space.gif' width='15' height='9'><img src='".$http_images."/drop_arrow.gif'> You are currently working with the server: <b>".$server_name."</b></td>
				</tr>
				<tr>
					<td colspan='2' align='left' valign='top'><img src='".$http_images."/space.gif' width='1' height='8'></td>
				</tr>
	");
$ct=mysql_fetch_row(mysql_query("select count(*) from hosting_order"));
if ($ct[0]<=0)
	{
	echo("
				<tr>
					<td colspan='2' align='left' valign='top'><img src='".$http_images."/space.gif' width='15' height='9'><img src='".$http_images."/error_arrow.gif'><font color='#990000'>You have no orders in the database to work with.</font></td>
				</tr>
				<tr>
					<td width='25%' align='left' valign='top'></td>
					<td width='75%' align='left' valign='top'></td>
				</tr>
			</table>
			</td>
		</tr>
	</table>
	</form>
	");

	include $server_admin_inc."/footer.php";
	mysql_close($dblink);
	die();
	}
else
	{
	echo("
				<tr>
					<td width='25%' align='left' valign='top'><img src='".$http_images."/space.gif' width='15' height='9'>Choose Domain:</td>
					<td width='75%' align='left' valign='top'>
					<select name='oid' ".$input_style.">
		");

	$row1=mysql_query("select oid, domain_name, reseller, uid from hosting_order order by reseller asc, domain_name asc");
	while ($rs1=mysql_fetch_row($row1))
		{
		if ($rs1[2]==1)
			{
			$rs2=mysql_fetch_row(mysql_query("select reseller_primary_domain from user where uid='".addslashes(trim($rs1[3]))."'"));
			$rs3=mysql_fetch_row(mysql_query("select whm_username from hosting_order where oid='".addslashes(trim($rs2[0]))."'"));
			$current_owner=stripslashes(trim($rs3[0]));
			}

		echo "<option value='".$rs1[0]."'".((isset($oid))?"".(($oid==$rs1[0])?" selected":"")."":"").">[".(($rs1[2]==0)?"standard":"resold")."] [".(($rs1[2]==0)?"".$xwhm_username."":"".stripslashes(trim($current_owner))."")."] http://".stripslashes(trim($rs1[1]))."</option>\n";
		}

	echo("
						</select><br><img src='".$http_images."/space.gif' width='2' height='16'><img src='".$http_images."/drop_arrow.gif'>ex. [domain status] [owner] domain name</td>
					</tr>
		");
	}
echo("
				<tr>
					<td colspan='2' align='left' valign='top'><img src='".$http_images."/space.gif' width='1' height='12'></td>
				</tr>
				<tr>
					<td width='25%' align='left' valign='top'><img src='".$http_images."/space.gif' width='15' height='9'>Choose User:</td>
					<td width='75%' align='left' valign='top'>
					<select name='uid' ".$input_style.">
	");
$row=mysql_query("select uid, first_name, last_name, zip_code, status, username, reseller, reseller_primary_domain from user where reseller='1' order by first_name asc, last_name asc");
while ($rs=mysql_fetch_row($row))
	{
	if ($rs[4]!=69)
		{
		if ($rs[7]!=0)
			{
			$rs0=mysql_fetch_row(mysql_query("select domain_name from hosting_order where oid='".addslashes(trim($rs[7]))."'"));
			$pri_dom="http://".stripslashes(trim($rs0[0]));
			}
		else
			{
			$pri_dom="Undefined";
			}
		echo "<option value='".$rs[0]."'".((isset($uid))?"".(($uid==$rs[0])?" selected":"")."":"").">[".$pri_dom."] ".stripslashes(trim($rs[1]))." ".stripslashes(trim($rs[2]))."</option>\n";
		}
	}
echo("
					</select><br><img src='".$http_images."/space.gif' width='2' height='16'><img src='".$http_images."/drop_arrow.gif'>ex. [primary domain] reseller</td>
				</tr>
				<tr>
					<td colspan='2' align='left' valign='top'><img src='".$http_images."/space.gif' width='1' height='18'></td>
				</tr>
				<tr>
					<td width='25%' align='left' valign='top'></td>
					<td width='75%' align='left' valign='top'><input ".$button_style." type='submit' name='submit' value='Change Ownership'></td>
				</tr>
				<tr>
					<td colspan='2' align='left' valign='top'><img src='".$http_images."/space.gif' width='1' height='6'></td>
				</tr>
				<tr>
					<td width='25%' align='left' valign='top'></td>
					<td width='75%' align='left' valign='top'><font color='#990000'>* You cannot add domains to a reseller until the reseller<br>has a primary domain defined.</font></td>
				</tr>
			</table>
			</td>
		</tr>
	</table>
	</form>
	");

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