<?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";
include $server_inc."/enom_functions.php";

if (isset($submit))
	{
	if (trim($password)==""&&!isset($deleteme)) { $e0=true;}
	else 
		{
		if (isset($deleteme))
			{
			$query="delete from ";
			$query.="domains ";
			$query.="where ";
			$query.="dom_id='".addslashes(trim($dom_id))."'";

			mysql_query($query);
			}
		else
			{
			$query="select ";
			$query.="hosting_order.domain_name, ";	// 0
			$query.="tld_chart.cost, ";				// 1
			$query.="tld_chart.reg_period ";		// 2
			$query.="from ";
			$query.="hosting_order, tld_chart ";
			$query.="where ";
			$query.="hosting_order.oid='".addslashes(trim($oid))."' ";
			$query.="and ";
			$query.="hosting_order.tld_id=tld_chart.tld_id ";
			$query.="order by hosting_order.oid asc ";
			$query.="limit 0, 1";

			$rs=mysql_fetch_row(mysql_query($query));

			$domain_name=stripslashes(trim($rs[0]));
			$cost=stripslashes(trim($rs[1]));
			$reg_period=stripslashes(trim($rs[2]));

			$query="update ";
			$query.="domains ";
			$query.="set ";
			$query.="oid='".addslashes(trim($oid))."', ";
			$query.="uid='".addslashes(trim($uid))."', ";
			$query.="tld_cost='".addslashes(trim($cost))."', ";
			$query.="domain_name='".addslashes(trim($domain_name))."', ";
			$query.="purchase_rc='Manually Created', ";
			$query.="purchase_text='Manually Created', ";
			$query.="modifyns_rc='Manually Created', ";
			$query.="modifyns_text='Manually Created', ";
			$query.="created='".time()."', ";
			$query.="expires='".mktime(0, 0, 0, date("m"), (date("d")+(365*$reg_period)), date("Y"))."', ";
			$query.="order_id='Manually Created', ";
			$query.="password='".addslashes(trim($password))."', ";
			$query.="status='1' ";
			$query.="where ";
			$query.="dom_id='".addslashes(trim($dom_id))."'";

			mysql_query($query);

			enom_reg_email($oid, $uid, $email_admin);
			}

		$done=true;
		}
	}

include $server_admin_inc."/header.php";

if (isset($done))
	{
	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%' cellpadding='4' cellspacing='1' border='0'>
					<tr>
						<td align='left' valign='top'><img src='".$http_images."/menu_arrow.gif'><b>Manage Incomplete Enom Orders</b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[<a href='".$http_admin."/enom_incomplete.php?sid=".trim($sid)."'>go back</a>]</td>
					</tr>
					<tr>
						<td align='left' valign='top'>".((isset($deleteme))?"The domain was removed from the queue.":"The domain is now active.")."</td>
					</tr>
					<tr>
						<td align='left' valign='top'><img src='".$http_images."/space.gif' width='10' height='10'></td>
					</tr>
					<tr>
						<td align='left' valign='top'><a href='".$http_admin."/enom_incomplete.php?sid=".$sid."'>Click here</a> to continue.</td>
					</tr>
					<tr>
						<td align='left' valign='top'><a href='".$http_admin."/index2.php?sid=".$sid."'>Click here</a> to return to the index page.</td>
					</tr>
				</table>
				</td>
			</tr>
		</table>
		");
	include $server_admin_inc."/footer.php";
	mysql_close($dblink);
	die();
	}

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%' cellpadding='4' cellspacing='1' border='0'>
				<tr>
					<td colspan='4' align='left' valign='top'><img src='".$http_images."/menu_arrow.gif'><b>Manage Incomplete Enom Orders</b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[<a href='".$http_admin."/index2.php?sid=".trim($sid)."'>go back</a>]</td>
				</tr>
				<tr>
					<td colspan='4' align='left' valign='top'><img src='".$http_images."/space.gif' width='10' height='1'></td>
				</tr>
		");

if (isset($e0))
	{
	echo("
				<tr>
					<td colspan='4' align='left' valign='top'><b>ERROR!</b> Please enter a password for this domain to continue.</td>
				</tr>
		");
	}
echo("
				<tr>
					<td colspan='4' align='left' valign='top'><img src='".$http_images."/space.gif' width='10' height='1'></td>
				</tr>
				<tr>
					<td align='left' valign='middle' bgcolor='#E5E7E9'>&nbsp;<b>#</b></td>
					<td align='left' valign='middle' bgcolor='#E5E7E9'>&nbsp;<b>Domain Name</b></td>
					<td align='left' valign='middle' bgcolor='#E5E7E9'>&nbsp;<b>Assign Password</b></td>
					<td align='center' valign='middle' bgcolor='#E5E7E9'><img src='".$http_images."/down_arrow.gif'></td>
				</tr>
		");

$y=1;
$query="select ";
$query.="dom_id, ";			// 0
$query.="domain_name, ";	// 1
$query.="uid, ";			// 2
$query.="oid ";				// 3
$query.="from ";
$query.="domains ";
$query.="where ";
$query.="status='0' ";
$query.="order by dom_id desc";

$row=mysql_query($query);

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

	echo("
		<form action='".$PHP_SELF."' method='POST'>
		<input type='hidden' name='sid' value='".trim($sid)."'>
		<input type='hidden' name='dom_id' value='".$rs[0]."'>
		<input type='hidden' name='uid' value='".$rs[2]."'>
		<input type='hidden' name='oid' value='".$rs[3]."'>
			<tr>
				<td align='left' valign='middle' bgcolor='".$bgcolor."'>&nbsp;<b>".($g+=1)."</b></td>
				<td align='left' valign='middle' bgcolor='".$bgcolor."'>&nbsp;".stripslashes(trim($rs[1]))."</td>
				<td align='left' valign='middle' bgcolor='".$bgcolor."'>&nbsp;<input type='text' name='password' size='20' maxlength='16' ".$input_style."></td>
				<td align='center' valign='middle' bgcolor='".$bgcolor."'><input type='checkbox' name='deleteme' value='1' id='dom_id".$rs[0]."'> <label for='dom_id".$rs[0]."'>Check to delete.</label>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input ".$button_style." type='submit' name='submit' value='Continue'></td>
			</tr>
		</form>
		");
	$x++;
	}

if (!isset($g))
	{
	echo("
				<tr>
					<td colspan='4' align='left' valign='top'><img src='".$http_images."/error_arrow.gif'> No incomplete Enom orders found in the database.</td>
				</tr>
		");
	}

echo("
			</table>
			</td>
		</tr>
	</table>
	");

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