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

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

if (isset($submitz))
	{
	$r=mysql_fetch_row(mysql_query("select payment_term, pid, domain_registration, ip from hosting_order where oid='".addslashes(trim($oid))."'"));

	$payment_term=addslashes(trim($r[0]));
	$pid=addslashes(trim($r[1]));

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

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

	$reseller=$rsip[2];

	//-------------------------------------------------------------

	$aid=array();
	$count=count($_POST);
	for ($i=0; $i<$count; $i++) 
		{  
		$name="aid".$i;
		$aid[]=${$name}; 

		if (trim($aid[$i])!="") { @$addon_choices.=$aid[$i]."|"; }
		}

	if ($reseller==0) 
		{ 
		$unique_ip_ordered=unique_ip_ordered($addon_choices);
		if ($unique_ip_ordered==1) 
			{ 
			if (strcmp($r[3],default_install_ip($rsip[0], $xwhm_username, $xwhm_password))==0)
				{
				$default_ip=get_free_ips($rsip[0], $xwhm_username, $xwhm_password); 
				}
			else
				{
				$default_ip=$r[3]; 
				}
			}
		else { $default_ip=$rsip[0]; }
		}
	else { $default_ip=$rsip[0]; }

	if (isset($r[2])) { $r[2]=1; } else { $r[2]=0; }
	$data_calc=calc_totals($payment_term, $r[2], $domain_fee, $pid, $addon_choices);
	list($total_due_today, $total_reoccur, $payment_term)=split("[|]", $data_calc);

	$update="update hosting_order set ";
	$update.="total_due_today='".addslashes(trim($total_due_today))."', ";
	$update.="total_due_reoccur='".addslashes(trim($total_reoccur))."', ";
	$update.="ip='".addslashes(trim($default_ip))."', ";
	$update.="addon_choices='".stripslashes(trim($addon_choices))."' ";
	$update.="where oid='".addslashes(trim($oid))."'";

	mysql_query($update);

	//-------------------------------------------------------------

	// 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;
	}

include $server_admin_inc."/header.php";

$r=mysql_fetch_row(mysql_query("select reseller from hosting_order where oid='".addslashes(trim($oid))."'"));
if ($r[0]==1)
	{
	$resold=true;
	}

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 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;<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."/".((isset($resold))?"csv_add_reseller_accounts.php":"csv_add_user_accounts.php")."?sid=".$sid."&whm_id=".trim($whm_id)."'>Add Account to User</a>&nbsp;&nbsp;&gt&nbsp;&nbsp;<a href='".$http_admin."/csv_server.php?sid=".$sid."&oid=".trim($oid)."&whm_id=".trim($whm_id)."'>Edit User Account Information</a></td>
				</tr>
				<tr>
					<td align='left' valign='top'><img src='".$http_images."/space.gif' width='1' height='2'></td>
				</tr>
				<tr>
					<td 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 align='left' valign='top'><img src='".$http_images."/space.gif' width='1' height='12'></td>
				</tr>
			</table>
	");
include $server_admin_tools."/csv_addon.php";
echo("
			</td>
		</tr>
	</table>
	");

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