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


if (isset($submity))
	{
	if (strlen(trim($domain_name))==0) 
		{
		$err0=true;
		} 
	else 
		{
		$rxx=mysql_fetch_row(mysql_query("select addon_choices from hosting_order where oid='".addslashes(trim($oid))."'"));
		$addon_choices=stripslashes(trim($rxx[0]));

		// parse expire date if any
		$domain_expire=$dexpirem."/";
		$domain_expire.=$dexpired."/";
		$domain_expire.=$dexpirey;
	
		// parse plan
		list($pid, $payment_term)=split("[|]", $pid);
		
		list($total_due_today, $total_reoccur, $payment_term)=split("[|]", calc_totals($payment_term, $domain_registration, $domain_fee, $pid, $addon_choices));

		// UPDATE THE ORDER
		$update="update hosting_order set ";
		$update.="domain_name='".addslashes(trim($domain_name))."', ";
		$update.="domain_expire='".addslashes(trim($domain_expire))."', ";
		$update.="ip='".addslashes(trim($ip))."', ";
		$update.="ns1='".addslashes(trim($ns1))."', ";
		$update.="ns2='".addslashes(trim($ns2))."', ";
		$update.="status='1', ";
		
		if (isset($resell)) { $update.="reseller='1', "; }
		else { $update.="reseller='0', "; }

		$update.="whm_username='".addslashes(trim($whm_username))."', ";
		$update.="whm_password='".addslashes(trim($whm_password))."', ";
		$update.="pid='".addslashes(trim($pid))."', ";
		$update.="total_due_today='".addslashes(trim($total_today))."', ";
		$update.="total_due_reoccur='".addslashes(trim($total_reoccur))."', ";
		$update.="payment_term='".addslashes(trim($payment_term))."', ";
		$update.="whm_id='".addslashes(trim($whm_id))."', ";
		$update.="payment_method='".addslashes(trim($payment_method))."', ";
		if (isset($resolved)) {	$update.="resolved_time='".time()."', "; }
		
		// build date
		list($m, $d, $y)=explode("/", $build_date);
		$build_date=mktime(0, 0, 0, $m, $d, $y);
		if (trim($build_date)=="") { $update.="ogcreate='".time()."', "; }
		else { $update.="ogcreate='".addslashes(trim($build_date))."', "; }
		
		list($m, $d, $y)=explode("/", $next_due_date);
		$next_due_date=mktime(0, 0, 0, $m, $d, $y);
		if (trim($next_due_date)=="") { $update.="next_due_date='".create_next_due(time(), $payment_term)."', "; }
		else { $update.="next_due_date='".addslashes(trim($next_due_date))."', "; }
		

		// is resolved?
		if (isset($resolved))
			{
			$update.="resolved='1', ";
			$update.="resolved_time='".addslashes(trim($build_date))."' ";
			}
		else { $update.="resolved='0' "; }

		$update.="where oid='".addslashes(trim($oid))."'";

		mysql_query($update);
		
		update_invoice_internal($oid);
		
		// DEFINE PATH TO TAKE
		if (trim($addon_choices)!="") { $todo=1; }

		// SEND TO ADDONS OR CREATE THE ACCOUNT
		if (trim($todo)=="1")
			{
			// send to addons
			$link_out="Location: ";
			$link_out.=$http_admin;
			$link_out.="/csv_addon.php?";
			$link_out.="sid=".trim($sid);
			$link_out.="&uid=".trim($uid);
			$link_out.="&oid=".trim($oid);
			$link_out.="&pid=".trim($pid);
			$link_out.="&whm_id=".trim($whm_id);
			
			header($link_out);
			exit;
			}
		else
			{
			// send to complete
			$link_out="Location: ";
			$link_out.=$http_admin;
			$link_out.="/csv_complete.php?";
			$link_out.="sid=".trim($sid);
			$link_out.="&uid=".trim($uid);
			$link_out.="&oid=".trim($oid);
			$link_out.="&whm_id=".trim($whm_id);

			header($link_out);
			exit;
			}
		}
	}

$query="select ";
$query.="whm_username, ";				// 0
$query.="domain_name, ";				// 1
$query.="ip, ";							// 2
$query.="domain_expire, ";				// 3
$query.="resolved, ";					// 4
$query.="ogcreate, ";					// 5
$query.="whm_password, ";				// 6
$query.="next_due_date ";				// 7
$query.="from hosting_order ";
$query.="where oid='".addslashes(trim($oid))."'";

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

$whm_username=stripslashes(trim($rs[0]));
$domain_name=stripslashes(trim($rs[1]));
$ip=stripslashes(trim($rs[2]));

$domain_expire=stripslashes(trim($rs[3]));
list($dexpirem, $dexpired, $dexpirey)=split("[/]", $domain_expire);

$resolved=stripslashes(trim($rs[4]));
$whm_password=stripslashes(trim($rs[6]));
$ogcreate=stripslashes(trim($rs[5]));
$next_due_date=stripslashes(trim($rs[7]));

$build_date=date("m/d/Y", $ogcreate);
$next_due_date=date("m/d/Y", $next_due_date);

// grab whois
# $base=lookup($domain_name);

// grab expire from whois
# $parse_expire=whois_parse($base);
# list($dexpirem, $dexpired, $dexpirey)=split("[|]", $parse_expire);

// grab ns from whois
# $parse_ns=whois_2_ns($base, 0);
# list($ns1, $ns2)=split("[|]", $parse_ns);

// 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]);

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'>
			<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>Add Accounts to Existing Reseller From WHM CSV File</b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href='".$http_admin."/csv.php?sid=".$sid."&whm_id=".trim($whm_id)."'>Import Utility Home</a>&nbsp;&nbsp;&gt&nbsp;&nbsp;<a href='".$http_admin."/csv_add_user_accounts.php?sid=".$sid."&whm_id=".trim($whm_id)."'>Add Account to User</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[<a href='".$http_admin."/csv_whois.php?sid=".trim($sid)."&oid=".trim($oid)."' target='_blank'>View Whois for Domain</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='12'></td>
				</tr>
			</table>
	");
if (isset($err0))
	{
	echo("
			<table width='725' cellpadding='2' cellspacing='0' border='0'>
				<tr>
					<td align='left' valign='top'><img src='".$http_images."/space.gif' width='9' height='9'><img src='".$http_images."/error_arrow.gif'><b>ERROR!</b> You must enter a <b>domain name</b> to continue.</td> 
				</tr>
				<tr>
					<td><img src='".$http_images."/space.gif' width='1' height='2'></td>
				</tr>
			</table>
		");
	}
include $server_admin_tools."/csv_server.php";
echo("
			</td>
		</tr>
	</table>
	");

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