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

if (!isset($oid)) { header("Location: ".$http_admin."/client_view_edit.php?sid=".$sid); exit; }

if (isset($edit_dedicated))
	{
	if ($activate==5) 
		{ 
		mysql_query("delete from hosting_order where oid='".addslashes(trim($oid))."'");
		header("Location: ".$http_admin."/client_view_edit.php?sid=".$sid); 
		exit;
		}
	else
		{
		if (trim($ip)=="") { $e0=true; }
		if (trim($server_specs)=="") { $e1=true; }

		if (!isset($e0)&&!isset($e1))
			{				
			list($pid, $payment_term)=split("[|]", $xpid);
			
			$addon_choices="";
			if(phpversion() <= "4.0.6") { $_POST=$HTTP_POST_VARS; }
			while (list ($key, $value) = each ($HTTP_POST_VARS)) 
				{ 
				if (ereg("aid", $key)==true) 
					{ 
					# -----------------------------------------------------------------------------------------------------------------
					$rs_c=mysql_fetch_row(mysql_query("select coupon from addon_specs where aid='".addslashes(trim($value))."'"));
					if ($rs_c[0]==1) { $coupon_bit=$value; }
					# -----------------------------------------------------------------------------------------------------------------
					$addon_choices.=$value."|"; 
					} 
				}
			
			$data_calc=calc_totals($payment_term, 0, $domain_fee, $pid, $addon_choices);
			list($total_due_today, $total_reoccur, $xpayment_term)=split("[|]", $data_calc);

			# -----------------------------------------------------------------------------------------------------------------
			if (isset($coupon_bit))
				{
				$query_c="select ";
				$query_c.="coupon_terms, ";				// 0
				$query_c.="coupon_discount_type, ";		// 1
				$query_c.="coupon_discount_percent, ";	// 2
				$query_c.="coupon_discount_whole ";		// 3
				$query_c.="from ";
				$query_c.="addon_specs ";
				$query_c.="where ";
				$query_c.="aid='".addslashes(trim($coupon_bit))."'";

				$rs_c=mysql_fetch_row(mysql_query($query_c));

				$coupon_terms=stripslashes(trim($rs_c[0])); # 1 == one time; 2 == monthly;
				$coupon_discount_type=stripslashes(trim($rs_c[1])); # 1 == %; 2 == whole dollar amount;
				$coupon_discount_percent=stripslashes(trim($rs_c[2]));
				$coupon_discount_whole=stripslashes(trim($rs_c[3]));

				# 1. figure out one time or monthly
				if ($coupon_terms==1) # one time
					{
					if ($coupon_discount_type==1) # %
						{
						# - %
						$sub_total_due_today=($total_due_today-$total_reoccur);
						$convert_to_percent=($coupon_discount_percent/100);
						$discounted_total_due_today=$total_reoccur-($total_reoccur*$convert_to_percent);
						$new_total_due_today=$sub_total_due_today+$discounted_total_due_today;
						if ($discounted_total_due_today+$setup_cost>=1) { $total_due_today=$new_total_due_today; }
						}
					else if ($coupon_discount_type==2) # whole dollar amount
						{
						# - WHOLE DOLLAR
						$sub_total_due_today=($total_due_today-$total_reoccur);
						$discounted_total_due_today=$total_reoccur-$coupon_discount_whole;
						$new_total_due_today=$sub_total_due_today+$discounted_total_due_today;
						if ($discounted_total_due_today+$setup_cost>=1) { $total_due_today=$new_total_due_today; }
						}
					}
				else if ($coupon_terms==2) # monthly
					{
					if ($coupon_discount_type==1) # %
						{
						# - %
						# do today's totals
						$sub_total_due_today=($total_due_today-$total_reoccur);
						$convert_to_percent=($coupon_discount_percent/100);
						$discounted_total_due_today=$total_reoccur-($total_reoccur*$convert_to_percent);
						$new_total_due_today=$sub_total_due_today+$discounted_total_due_today;
						if ($discounted_total_due_today+$setup_cost>=1) 
							{ 
							$total_due_today=$new_total_due_today; 
							$total_reoccur=$discounted_total_due_today;
							}
						}
					else if ($coupon_discount_type==2) # whole dollar amount
						{ 
						# - WHOLE DOLLAR 
						$sub_total_due_today=($total_due_today-$total_reoccur);
						$discounted_total_due_today=$total_reoccur-$coupon_discount_whole;
						$new_total_due_today=$sub_total_due_today+$discounted_total_due_today;
						if ($discounted_total_due_today+$setup_cost>=1)  
							{ 
							$total_due_today=$new_total_due_today; 
							$total_reoccur=$discounted_total_due_today;
							}
						}
					}
				}
			# -----------------------------------------------------------------------------------------------------------------
			
			list($m, $d, $y)=explode("/", $next_due_date);
			$next_due_date=mktime(0, 0, 0, $m, $d, $y);
			
			list($hm, $hd, $hy)=explode("/", $ogcreate_hosting);
			$ogcreate_hosting=mktime(0, 0, 0, $hm, $hd, $hy);

			$update="update hosting_order set ";
			$update.="next_due_date='".addslashes(trim($next_due_date))."', ";
			$update.="ogcreate='".addslashes(trim($ogcreate_hosting))."', ";
			
			# 7/22/2003 - downgrade resellers
			# ------------------------------------------------------------------------------
			$qr="select ";
			$qr.="rid ";
			$qr.="from ";
			$qr.="plan_specs ";
			$qr.="where ";
			$qr.="pid='".addslashes(trim($pid))."'";
			$qrs=mysql_fetch_row(mysql_query($qr));
			if ($qrs[0]==0)
				{
				$update.="pid='".addslashes(trim($pid))."', ";
				$update.="reseller='0', ";
				}
			else
				{
				$update.="pid='".addslashes(trim($pid))."', ";
				$update.="reseller='1', ";
				}
			# ------------------------------------------------------------------------------
			# 7/22/2003 - downgrade resellers

			$update.="root_pw='".addslashes(trim($root_pw))."', ";
			$update.="server_hostname='".addslashes(trim($server_hostname))."', ";
			$update.="domain_name='".addslashes(trim($domain_name))."', ";
			$update.="pns1='".addslashes(trim($pns1))."', ";
			$update.="pns2='".addslashes(trim($pns2))."', ";
			$update.="ip='".addslashes(trim($ip))."', ";
			$update.="ipblock='".addslashes(trim($ipblock))."', ";
			$update.="rack='".addslashes(trim($rack))."', ";
			$update.="server_specs='".addslashes(trim($server_specs))."', ";
			$update.="admin_notes='".addslashes(trim($admin_notes))."', ";
			$update.="client_notes='".addslashes(trim($client_notes))."', ";
			$update.="payment_method='".addslashes(trim($payment_method))."', ";
			$update.="payment_term='".addslashes(trim($payment_term))."', ";

			if ($domain_registration>0) 
				{ 
				$query="select ";
				$query.="reg_period, ";
				$query.="tld,";
				$query.="tld_id, ";
				$query.="cost ";
				$query.="from ";
				$query.="tld_chart ";
				$query.="where ";
				$query.="tld_id='".addslashes(trim($domain_registration))."'";
				
				$rs=mysql_fetch_row(mysql_query($query));
				
				$reg_period=$rs[0];
				$tld=$rs[1];
				$xtld_id=$rs[2];
				$cost=sprintf("%01.2f", $rs[3]);

				if ($reg_period==1) { $reg_period="Domain registration for 1 year. [.".$tld."] [".$cost."] \n";	}
				else if ($reg_period==2) { $reg_period="Domain registration for 2 years. [.".$tld."] [".$cost."]\n";	}
				else if ($reg_period==3) { $reg_period="Domain registration for 5 years. [.".$tld."] [".$cost."]\n";	}
				else if ($reg_period==4) { $reg_period="Domain registration for 10 years. [.".$tld."] [".$cost."]\n";	}

				$update.="domain_registration='1', ";
				$total_due_today+=$cost;
				}
			else { $update.="domain_registration='0', "; }

			$update.="tld_id='".addslashes(trim($domain_registration))."', ";
			$update.="total_due_today='".addslashes(trim($total_due_today))."', ";
			$update.="total_due_reoccur='".addslashes(trim($total_reoccur))."', "; 
			$update.="cont_resolve='0', ";

			if ($activate==0) { $update.="status='1', "; }
			else if ($activate==1) { $update.="status='1', "; }
			else if ($activate==2) { $update.="status='2', "; }

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

			update_invoice_internal($oid);

			// update user
			$uupdate="update user set ";
			if (strlen(trim($client_password))!=0) { $uupdate.="password='".md5(strtolower(trim($client_password)))."', "; }
			$uupdate.="username='".addslashes(trim($client_username))."' ";
			$uupdate.="where uid='".addslashes(trim($uid))."'";
			mysql_query($uupdate);

			// do affiliate stuff
			$rsact=mysql_fetch_row(mysql_query("select count(*) from affiliate_details where oid='".addslashes(trim($oid))."'"));
			if ($rsact[0]>=1) { update_referred_client($pid, $afuid, $oid, $afdid);	}
			else { if (strlen(trim($afuid))!=0) { add_new_referred_client($pid, $afuid, $uid, $oid); } }

			# if (isset($resend_welcome)) { send_dedicated_activation(36, $oid, 1); }
			if ($activate==3) { send_dedicated_activation(36, $oid, 1); }
			else if ($activate==0) { send_dedicated_activation(36, $oid, 1); }

			$header="Location: ";
			$header.=$http_admin;
			$header.="/client_view.php?";
			$header.="sid=".$sid;
			$header.="&oid=".$oid;
			$header.="&status=".$status;
			$header.="&create_account=1000";
			if (isset($in)) { $header.="&in=5"; }
			else if (isset($ix)) { $header.="&ix=5"; }
			if (isset($p)) { $header.="&p=".$p; }
			if (isset($pg)) { $header.="&pg=".$pg; }
			header($header);
			exit;
			}
		}
	}

if (isset($edit_user))
	{
	if ($change_ownership=="x")
		{
		list($m, $d, $y)=explode("/", $user_ogcreate);
		$user_ogcreate=mktime(0, 0, 0, $m, $d, $y);

		$update="update user set ";
		$update.="first_name='".addslashes(trim($first_name))."', ";
		$update.="last_name='".addslashes(trim($last_name))."', ";
		$update.="organization_name='".addslashes(trim($organization_name))."', ";
		$update.="street_address_1='".addslashes(trim($street_address_1))."', ";
		$update.="street_address_2='".addslashes(trim($street_address_2))."', ";
		$update.="city='".addslashes(trim($city))."', ";
		$update.="state='".addslashes(trim($state))."', ";
		$update.="zip_code='".addslashes(trim($zip_code))."', ";
		$update.="country='".addslashes(trim($country))."', ";
		$update.="phone='".addslashes(trim($phone))."', ";
		$update.="fax='".addslashes(trim($fax))."', ";
		$update.="email='".addslashes(trim($email))."', ";
		$update.="ogcreate='".addslashes(trim($user_ogcreate))."' ";
		$update.="where uid='".addslashes(trim($uid))."'";

		// execute query
		mysql_query($update);
		}
	else
		{
		$update="update hosting_order set ";
		$update.="uid='".addslashes(trim($change_ownership))."' ";
		$update.="where ";
		$update.="oid='".addslashes(trim($oid))."'";

		mysql_query($update);
		}
	}

if (isset($edit_domain))
	{
	$update="update hosting_order set ";
	$update.="domain_expire='".addslashes(trim($domain_expire))."', ";

	if (trim($resolved)==1) 
		{ 
		$update.="resolved_time='".time()."', ";
		$update.="resolved='1', "; 
		}
	else
		{
		$update.="resolved_time='', ";
		$update.="resolved='0', "; 
		}

	if (isset($cont_resolve)) { $update.="cont_resolve='1', "; }
	else { $update.="cont_resolve='0', "; }

	$update.="domain_name='".addslashes(trim($domain_name))."' ";

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

	mysql_query($update);
	}
	
if (isset($edit_account))
	{
	// ----------------------------------------------------------------------------

	/* manage account defined
	
	$manange_account==0	[xstatus==0]	Activate Account - Do Not Install
	$manange_account==1	[xstatus==0]	Activate Account - Install Now

	$manange_account==2	[All]			Suspend Account

	$manange_account==3	[All]			Delete Account

	$manange_account==4	[All]			Delete Account in MIB only

	$manange_account==5	[xstatus==2]	Unsuspend Account
	$manange_account==5	[xstatus==5]	Reactivate Account

	$manange_account==6	[xstatus==5]	Keep Account Cancelled

	$manange_account==7	[xstatus==4]	Activate Account - Keep Account Active
	*/

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

	# 7/16/2003 Resend options
	# -----------------------------------------------------------------------------------------
	function resend_logins_admin_area($resend_welcome, $resend_dns)
		{
		GLOBAL $oid;
		GLOBAL $email_admin;
		GLOBAL $unique_ip_ordered;

		if ($resend_welcome==1) 
			{
			$qr="select ";
			$qr.="hosting_order.resolved, ";	// 0
			$qr.="plan_specs.rid ";				// 1
			$qr.="from ";
			$qr.="hosting_order, plan_specs ";
			$qr.="where ";
			$qr.="hosting_order.oid='".addslashes(trim($oid))."' ";
			$qr.="and ";
			$qr.="hosting_order.pid=plan_specs.pid ";
			$qr.="order by hosting_order.oid asc ";
			$qr.="limit 0, 1";
			$rr=mysql_fetch_row(mysql_query($qr));

			if ($rr[0]==1) 
				{ 
				if ($rr[1]!=0) { send_reseller_welcome_email(34, $oid, 1); }
				else { send_successfully_resolved_email($oid, $email_admin); }
				}
			else 
				{ 
				if ($rr[1]!=0) { send_reseller_welcome_email(34, $oid, 1); }
				else { send_welcome_email_ip($email_admin, $oid, $unique_ip_ordered); }
				}			 
			}

		if ($resend_dns==1) { send_dns_config($email_admin, $oid); }

		return 0;
		}
	# -----------------------------------------------------------------------------------------
	# 7/16/2003 Resend options

	$ndd_buffer=explode("/", $next_due_date);
	$next_due_date=mktime(0, 0, 0, $ndd_buffer[0], $ndd_buffer[1], $ndd_buffer[2]);

	$ogcreate_buffer=explode("/", $ogcreate_hosting);
	$ogcreate_hosting=mktime(0, 0, 0, $ogcreate_buffer[0], $ogcreate_buffer[1], $ogcreate_buffer[2]);
	
	if (trim($manage_account)=="0")
		{		
		// split the pid/payment term
		list($pid, $payment_term)=split("[|]", $xpid);

		// build the addon_choices delimit from checkboxes
		$addon_choices="";
		if(phpversion() <= "4.0.6") { $_POST=$HTTP_POST_VARS; }
		while (list ($key, $value) = each ($HTTP_POST_VARS)) 
			{ 
			if (ereg("aid", $key)==true) 
				{
				# -----------------------------------------------------------------------------------------------------------------
				$rs_c=mysql_fetch_row(mysql_query("select coupon from addon_specs where aid='".addslashes(trim($value))."'"));
				if ($rs_c[0]==1) { $coupon_bit=$value; }
				# -----------------------------------------------------------------------------------------------------------------
				$addon_choices.=$value."|"; 
				} 
			}

		$queryy="select ";
		$queryy.="tld_id ";
		$queryy.="from ";
		$queryy.="hosting_order ";
		$queryy.="where ";
		$queryy.="oid='".addslashes(trim($oid))."'";

		$rss=mysql_fetch_row(mysql_query($queryy));

		$tld_id=$rss[0];

		$data_calc=calc_totals($payment_term, 0, $domain_fee, $pid, $addon_choices);
		list($total_due_today, $total_reoccur, $xpayment_term)=split("[|]", $data_calc);
		
		# -----------------------------------------------------------------------------------------------------------------
		if (isset($coupon_bit))
			{
			$query_c="select ";
			$query_c.="coupon_terms, ";				// 0
			$query_c.="coupon_discount_type, ";		// 1
			$query_c.="coupon_discount_percent, ";	// 2
			$query_c.="coupon_discount_whole ";		// 3
			$query_c.="from ";
			$query_c.="addon_specs ";
			$query_c.="where ";
			$query_c.="aid='".addslashes(trim($coupon_bit))."'";

			$rs_c=mysql_fetch_row(mysql_query($query_c));

			$coupon_terms=stripslashes(trim($rs_c[0])); # 1 == one time; 2 == monthly;
			$coupon_discount_type=stripslashes(trim($rs_c[1])); # 1 == %; 2 == whole dollar amount;
			$coupon_discount_percent=stripslashes(trim($rs_c[2]));
			$coupon_discount_whole=stripslashes(trim($rs_c[3]));
			
			# 1. figure out one time or monthly
			if ($coupon_terms==1) # one time
				{
				if ($coupon_discount_type==1) # %
					{
					# - %
					$convert_to_percent=($coupon_discount_percent/100);
					$discounted_total_due_today=$total_reoccur-($total_reoccur*$convert_to_percent);
					$new_total_due_today=$sub_total_due_today+$discounted_total_due_today;
					if ($discounted_total_due_today+$setup_cost>=1) { $total_due_today=$new_total_due_today; }
					}
				else if ($coupon_discount_type==2) # whole dollar amount
					{
					# - WHOLE DOLLAR
					$sub_total_due_today=($total_due_today-$total_reoccur);
					$discounted_total_due_today=$total_reoccur-$coupon_discount_whole;
					$new_total_due_today=$sub_total_due_today+$discounted_total_due_today;
					if ($discounted_total_due_today+$setup_cost>=1) { $total_due_today=$new_total_due_today; }
					}
				}
			else if ($coupon_terms==2) # monthly
				{
				if ($coupon_discount_type==1) # %
					{
					# - %
					# do today's totals
					$sub_total_due_today=($total_due_today-$total_reoccur);
					$convert_to_percent=($coupon_discount_percent/100);
					$discounted_total_due_today=$total_reoccur-($total_reoccur*$convert_to_percent);
					$new_total_due_today=$sub_total_due_today+$discounted_total_due_today;
					if ($discounted_total_due_today+$setup_cost>=1) 
						{ 
						$total_due_today=$new_total_due_today; 
						$total_reoccur=$discounted_total_due_today;
						}
					}
				else if ($coupon_discount_type==2) # whole dollar amount
					{ 
					# - WHOLE DOLLAR 
					$sub_total_due_today=($total_due_today-$total_reoccur);
					$discounted_total_due_today=$total_reoccur-$coupon_discount_whole;
					$new_total_due_today=$sub_total_due_today+$discounted_total_due_today;
					if ($discounted_total_due_today+$setup_cost>=1)  
						{ 
						$total_due_today=$new_total_due_today; 
						$total_reoccur=$discounted_total_due_today;
						}
					}
				}
			}
		# -----------------------------------------------------------------------------------------------------------------


		$update="update hosting_order set ";
		$update.="ogcreate='".addslashes(trim($ogcreate_hosting))."', ";
		$update.="next_due_date='".addslashes(trim($next_due_date))."', ";

		if ($domain_registration>0) 
			{ 
			$query="select ";
			$query.="reg_period, ";
			$query.="tld,";
			$query.="tld_id, ";
			$query.="cost ";
			$query.="from ";
			$query.="tld_chart ";
			$query.="where ";
			$query.="tld_id='".addslashes(trim($domain_registration))."'";
			
			$rs=mysql_fetch_row(mysql_query($query));
			
			$reg_period=$rs[0];
			$tld=$rs[1];
			$xtld_id=$rs[2];
			$cost=sprintf("%01.2f", $rs[3]);

			if ($reg_period==1) { $reg_period="Domain registration for 1 year. [.".$tld."] [".$cost."] \n";	}
			else if ($reg_period==2) { $reg_period="Domain registration for 2 years. [.".$tld."] [".$cost."]\n";	}
			else if ($reg_period==3) { $reg_period="Domain registration for 5 years. [.".$tld."] [".$cost."]\n";	}
			else if ($reg_period==4) { $reg_period="Domain registration for 10 years. [.".$tld."] [".$cost."]\n";	}

			$update.="domain_registration='1', ";
			$total_due_today+=$cost;
			}
		else { $update.="domain_registration='0', "; }

		$update.="tld_id='".addslashes(trim($domain_registration))."', ";
		
		$update.="total_due_today='".addslashes(trim($total_due_today))."', ";
		$update.="total_due_reoccur='".addslashes(trim($total_reoccur))."', "; 
			
		# 7/22/2003 - downgrade resellers
		# ------------------------------------------------------------------------------
		$qr="select ";
		$qr.="rid ";
		$qr.="from ";
		$qr.="plan_specs ";
		$qr.="where ";
		$qr.="pid='".addslashes(trim($pid))."'";
		$qrs=mysql_fetch_row(mysql_query($qr));
		if ($qrs[0]==0)
			{
			$update.="pid='".addslashes(trim($pid))."', ";
			$update.="reseller='0', ";
			}
		else
			{
			$update.="pid='".addslashes(trim($pid))."', ";
			$update.="reseller='1', ";
			}
		# ------------------------------------------------------------------------------
		# 7/22/2003 - downgrade resellers

		$update.="pns1='".addslashes(trim($pns1))."', ";
		$update.="pns2='".addslashes(trim($pns2))."', ";
		$update.="payment_term='".addslashes(trim($payment_term))."', ";
		$update.="addon_choices='".addslashes(trim($addon_choices))."', ";
		$update.="payment_method='".addslashes(trim($payment_method))."', ";
		$update.="whm_username='".addslashes(trim($whm_username))."', ";
		$update.="whm_password='".addslashes(trim($whm_password))."', ";
		$update.="admin_notes='".addslashes(trim($admin_notes))."', ";
		$update.="client_notes='".addslashes(trim($client_notes))."', ";
		$update.="ip='".addslashes(trim($ip))."', ";
		$update.="whm_id='".addslashes(trim($whm_id))."', ";
		$update.="ns1='".addslashes(trim($ns1))."', ";
		$update.="ns2='".addslashes(trim($ns2))."', ";
		$update.="status='1' ";
		$update.="where oid='".addslashes(trim($oid))."'";
		
		mysql_query($update);

		update_invoice_internal($oid);

		// do affiliate stuff
		$rsact=mysql_fetch_row(mysql_query("select count(*) from affiliate_details where oid='".addslashes(trim($oid))."'"));
		if ($rsact[0]>=1) { update_referred_client($pid, $afuid, $oid, $afdid);	}
		else { if (strlen(trim($afuid))!=0) { add_new_referred_client($pid, $afuid, $uid, $oid); } }

		// build query
		$uupdate="update user set ";
		if (strlen(trim($client_password))!=0) { $uupdate.="password='".md5(strtolower(trim($client_password)))."', "; }
		$uupdate.="username='".addslashes(trim($client_username))."' ";
		# $uupdate.="ogcreate='".addslashes(trim($ogcreate))."' ";
		$uupdate.="where uid='".addslashes(trim($uid))."'";
		mysql_query($uupdate);

		# resend_logins_admin_area($resend_welcome, $resend_dns);
		
		$header="Location: ";
		$header.=$http_admin;
		$header.="/client_view.php?";
		$header.="sid=".$sid;
		$header.="&oid=".$oid;
		$header.="&status=".$status;
		$header.="&create_account=1000";
		if (isset($in)) { $header.="&in=5"; }
		else if (isset($ix)) { $header.="&ix=5"; }
		if (isset($p)) { $header.="&p=".$p; }
		if (isset($pg)) { $header.="&pg=".$pg; }
		header($header);
		exit;
		}
	else if (trim($manage_account)=="1")
		{
		$query1="select ";
		$query1.="server_ip, ";		// 0
		$query1.="whm_id, ";		// 1
		$query1.="reseller, ";		// 2
		$query1.="primary_ns, ";	// 3
		$query1.="secondary_ns ";	// 4 
		$query1.="from server_config ";
		$query1.="where whm_id='".addslashes(trim($whm_id))."'";

		$rs1=mysql_fetch_row(mysql_query($query1));

		$server_ip=stripslashes(trim($rs1[0]));
		$whm_id=stripslashes(trim($rs1[1]));
		$reseller=stripslashes(trim($rs1[2]));
		$primary_ns=stripslashes(trim($rs1[3]));
		$secondary_ns=stripslashes(trim($rs1[4]));

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

		// --------------------------------------------------------------
		
		// split the pid/payment term
		list($pid, $payment_term)=split("[|]", $xpid);
		
		// build the addon_choices delimit from checkboxes
		$addon_choices="";
		if(phpversion() <= "4.0.6") { $_POST=$HTTP_POST_VARS; }
		while (list ($key, $value) = each ($HTTP_POST_VARS)) 
			{ 
			if (ereg("aid", $key)==true) 
				{ 
				# -----------------------------------------------------------------------------------------------------------------
				$rs_c=mysql_fetch_row(mysql_query("select coupon from addon_specs where aid='".addslashes(trim($value))."'"));
				if ($rs_c[0]==1) { $coupon_bit=$value; }
				# -----------------------------------------------------------------------------------------------------------------
				$addon_choices.=$value."|"; 
				} 
			}
		
		$data_calc=calc_totals($payment_term, $domain_registration, $domain_fee, $pid, $addon_choices);
		list($total_due_today, $total_reoccur, $payment_term)=split("[|]", $data_calc);

		# -----------------------------------------------------------------------------------------------------------------
		if (isset($coupon_bit))
			{
			$query_c="select ";
			$query_c.="coupon_terms, ";				// 0
			$query_c.="coupon_discount_type, ";		// 1
			$query_c.="coupon_discount_percent, ";	// 2
			$query_c.="coupon_discount_whole ";		// 3
			$query_c.="from ";
			$query_c.="addon_specs ";
			$query_c.="where ";
			$query_c.="aid='".addslashes(trim($coupon_bit))."'";

			$rs_c=mysql_fetch_row(mysql_query($query_c));

			$coupon_terms=stripslashes(trim($rs_c[0])); # 1 == one time; 2 == monthly;
			$coupon_discount_type=stripslashes(trim($rs_c[1])); # 1 == %; 2 == whole dollar amount;
			$coupon_discount_percent=stripslashes(trim($rs_c[2]));
			$coupon_discount_whole=stripslashes(trim($rs_c[3]));

			# 1. figure out one time or monthly
			if ($coupon_terms==1) # one time
				{
				if ($coupon_discount_type==1) # %
					{
					# - %
					$sub_total_due_today=($total_due_today-$total_reoccur);
					$convert_to_percent=($coupon_discount_percent/100);
					$discounted_total_due_today=$total_reoccur-($total_reoccur*$convert_to_percent);
					$new_total_due_today=$sub_total_due_today+$discounted_total_due_today;
					if ($discounted_total_due_today+$setup_cost>=1) { $total_due_today=$new_total_due_today; }
					}
				else if ($coupon_discount_type==2) # whole dollar amount
					{
					# - WHOLE DOLLAR
					$sub_total_due_today=($total_due_today-$total_reoccur);
					$discounted_total_due_today=$total_reoccur-$coupon_discount_whole;
					$new_total_due_today=$sub_total_due_today+$discounted_total_due_today;
					if ($discounted_total_due_today+$setup_cost>=1) { $total_due_today=$new_total_due_today; }
					}
				}
			else if ($coupon_terms==2) # monthly
				{
				if ($coupon_discount_type==1) # %
					{
					# - %
					# do today's totals
					$sub_total_due_today=($total_due_today-$total_reoccur);
					$convert_to_percent=($coupon_discount_percent/100);
					$discounted_total_due_today=$total_reoccur-($total_reoccur*$convert_to_percent);
					$new_total_due_today=$sub_total_due_today+$discounted_total_due_today;
					if ($discounted_total_due_today+$setup_cost>=1) 
						{ 
						$total_due_today=$new_total_due_today; 
						$total_reoccur=$discounted_total_due_today;
						}
					}
				else if ($coupon_discount_type==2) # whole dollar amount
					{ 
					# - WHOLE DOLLAR 
					$sub_total_due_today=($total_due_today-$total_reoccur);
					$discounted_total_due_today=$total_reoccur-$coupon_discount_whole;
					$new_total_due_today=$sub_total_due_today+$discounted_total_due_today;
					if ($discounted_total_due_today+$setup_cost>=1)  
						{ 
						$total_due_today=$new_total_due_today; 
						$total_reoccur=$discounted_total_due_today;
						}
					}
				}
			}
		# -----------------------------------------------------------------------------------------------------------------

		// reseller or not?
		if ($reseller==0) 
			{ 
			// order unique?
			$unique_ip_ordered=unique_ip_ordered($addon_choices);
			
			// get the IP for the account or use the shared
			$unique_ip_ordered=unique_ip_ordered($addon_choices);
			if ($unique_ip_ordered==1) 
				{ 
				$xdefault_ip=get_free_ips($server_ip, $xwhm_username, $xwhm_password); 
				if (trim($xdefault_ip)=="") { $default_ip=$server_ip; }
				else { $default_ip=$xdefault_ip; } 
				}
			else if (isset($ip)) { $default_ip=$ip; }
			else { $default_ip=$server_ip; }

			// extra space ordered?
			$extra_space=extra_webspace_ordered($addon_choices);
			}
		else 
			{ 
			$default_ip=$ip; 
			$extra_space=0;
			}
		
		// --------------------------------------------------------------

		$query2="select ";
		$query2.="cgi_access, ";		// 0
		$query2.="web_space, ";			// 1
		$query2.="frontpage, ";			// 2
		$query2.="cpanel_theme, ";		// 3
		$query2.="ftp, ";				// 4
		$query2.="sql, ";				// 5 
		$query2.="email, ";				// 6
		$query2.="email_list, ";		// 7
		$query2.="sub_domain, ";		// 8
		$query2.="bandwidth, ";			// 9
		$query2.="shell_access, ";		// 10
		$query2.="parked_domain, ";		// 11
		$query2.="addon_domain, ";		// 12
		$query2.="gid, ";				// 13
		$query2.="whm_package_name, ";	// 14
		$query2.="rid ";				// 15
		$query2.="from plan_specs ";		
		$query2.="where pid='".addslashes(trim($pid))."'";
		
		$rs2=mysql_fetch_row(mysql_query($query2));

		$cgi=stripslashes($rs2[0]);
		if (trim($extra_space)=="0") { $quota=stripslashes($rs2[1]); }
		else { $quota=stripslashes($rs2[1]+$extra_space); }
		$frontpage=stripslashes($rs2[2]);
		$cpmod=stripslashes($rs2[3]);
		$maxftp=stripslashes($rs2[4]);
		$maxsql=stripslashes($rs2[5]);
		$maxpop=stripslashes($rs2[6]);
		$maxlst=stripslashes($rs2[7]);
		$maxsub=stripslashes($rs2[8]);
		$bwlimit=stripslashes($rs2[9]);
		$hasshell=stripslashes($rs2[10]);
		$maxpark=stripslashes($rs2[11]);
		$maxaddon=stripslashes($rs2[12]);
		$gid=stripslashes($rs2[13]);
		$whm_package_name=stripslashes($rs2[14]);
		$rid=stripslashes($rs2[15]);
		
		if ($reseller==0)
			{
			$account_creation_status=create_account($server_ip, $xwhm_username, $xwhm_password, $domain_name, $whm_username, $whm_password, $unique_ip_ordered, $cgi, $quota, $frontpage, $cpmod, $maxftp, $maxsql, $maxpop, $maxlst, $maxsub, $bwlimit, $hasshell, $maxpark, $maxaddon, $whm_package_name, $default_ip);
			}
		else
			{
			$account_creation_status=create_account($server_ip, $xwhm_username, $xwhm_password, $domain_name, $whm_username, $whm_password, 0, $cgi, $quota, $frontpage, $cpmod, $maxftp, $maxsql, $maxpop, $maxlst, $maxsub, $bwlimit, $hasshell, $maxpark, $maxaddon, $whm_package_name, $default_ip);
			}

		// account installed successful
		if ($account_creation_status==99)
			{
			// --------------------------------------------------------------
			$update="update hosting_order set ";
			$update.="next_due_date='".addslashes(trim($next_due_date))."', ";
			$update.="ogcreate='".addslashes(trim($ogcreate_hosting))."', ";
			
			# 7/22/2003 - downgrade resellers
			# ------------------------------------------------------------------------------
			$qr="select ";
			$qr.="rid ";
			$qr.="from ";
			$qr.="plan_specs ";
			$qr.="where ";
			$qr.="pid='".addslashes(trim($pid))."'";
			$qrs=mysql_fetch_row(mysql_query($qr));
			if ($qrs[0]==0)
				{
				$update.="pid='".addslashes(trim($pid))."', ";
				$update.="reseller='0', ";
				}
			else
				{
				$update.="pid='".addslashes(trim($pid))."', ";
				$update.="reseller='1', ";
				}
			# ------------------------------------------------------------------------------
			# 7/22/2003 - downgrade resellers

			$update.="pns1='".addslashes(trim($pns1))."', ";
			$update.="pns2='".addslashes(trim($pns2))."', ";
			$update.="payment_term='".addslashes(trim($payment_term))."', ";
			$update.="addon_choices='".addslashes(trim($addon_choices))."', ";
			$update.="payment_method='".addslashes(trim($payment_method))."', ";
			$update.="total_due_today='".addslashes(trim($total_due_today))."', ";
			$update.="total_due_reoccur='".addslashes(trim($total_reoccur))."', ";
			$update.="whm_username='".addslashes(trim($whm_username))."', ";
			$update.="whm_password='".addslashes(trim($whm_password))."', ";
			$update.="ip='".addslashes(trim($default_ip))."', ";
			$update.="admin_notes='".addslashes(trim($admin_notes))."', ";
			$update.="client_notes='".addslashes(trim($client_notes))."', ";
			$update.="whm_id='".addslashes(trim($whm_id))."', ";
			$update.="status='1', ";
			if (trim($ns1)!=""||trim($ns2)!="")
				{
				$update.="ns1='".addslashes(trim($ns1))."', ";
				$update.="ns2='".addslashes(trim($ns2))."' ";
				}
			else
				{
				$update.="ns1='".addslashes(trim($primary_ns))."', ";
				$update.="ns2='".addslashes(trim($secondary_ns))."' ";
				}

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

			mysql_query($update);

			update_invoice_internal($oid);

			// --------------------------------------------------------------
			// do affiliate stuff
			$rsact=mysql_fetch_row(mysql_query("select count(*) from affiliate_details where oid='".addslashes(trim($oid))."'"));
			if ($rsact[0]>=1) { update_referred_client($pid, $afuid, $oid, $afdid);	}
			else { if (strlen(trim($afuid))!=0) { add_new_referred_client($pid, $afuid, $uid, $oid); } }
		
			# START EDITED FOR RESELLER 7/2/2003
			# -----------------------------------------------------------------------------------------
			if ($rid!=0&&trim($rid)!="")
				{
				# 1a. set resellers primary domain to the order id
				$rq0="select ";
				$rq0.="reseller_primary_domain, ";
				$rq0.="ogcreate ";
				$rq0.="from ";
				$rq0.="user ";
				$rq0.="where ";
				$rq0.="uid='".addslashes(trim($uid))."'";
				$mrd=mysql_fetch_row(mysql_query($rq0));

				if ($mrd[0]==0)
					{
					$rq1="update ";
					$rq1.="user ";
					$rq1.="set ";
					$rq1.="reseller_primary_domain='".addslashes(trim($oid))."' ";
					$rq1.="where ";
					$rq1.="uid='".addslashes(trim($uid))."'";
					mysql_query($rq1);
					}
				
				create_reseller($server_ip, $xwhm_username, $xwhm_password, $whm_username, $rid);			
				}

			// check server status
			auto_switch_server($below_public, $email_admin);

			$uupdate="update user set ";
			if (strlen(trim($client_password))!=0) { $uupdate.="password='".md5(strtolower(trim($client_password)))."', "; }
			$uupdate.="username='".addslashes(trim($client_username))."' ";
			$uupdate.="where uid='".addslashes(trim($uid))."'";
			mysql_query($uupdate);
			}
			
		resend_logins_admin_area($resend_welcome, $resend_dns);
		
		$header="Location: ";
		$header.=$http_admin;
		$header.="/client_view.php?";
		$header.="sid=".$sid;
		$header.="&oid=".$oid;
		$header.="&status=".$status;
		$header.="&create_account=".$account_creation_status;
		if (isset($in)) { $header.="&in=5"; }
		else if (isset($ix)) { $header.="&ix=5"; }
		if (isset($p)) { $header.="&p=".$p; }
		if (isset($pg)) { $header.="&pg=".$pg; }
		header($header);
		exit;
		}
	else if (trim($manage_account)=="2")
		{
		$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 from server_config where whm_id='".addslashes(trim($whm_id))."'"));

		suspend_account($rsip[0], $xwhm_username, $xwhm_password, $whm_username);
		
		// suspend the order in the db
		mysql_query("update hosting_order set status='2', client_notes='".addslashes(trim($client_notes))."', admin_notes='".addslashes(trim($admin_notes))."' where oid='".addslashes(trim($oid))."'");
		
		resend_logins_admin_area($resend_welcome, $resend_dns);

		$header="Location: ";
		$header.=$http_admin;
		$header.="/client_view.php?";
		$header.="sid=".$sid;
		$header.="&oid=".$oid;
		$header.="&status=".$status;
		$header.="&create_account=1002";
		if (isset($in)) { $header.="&in=5"; }
		else if (isset($ix)) { $header.="&ix=5"; }
		if (isset($p)) { $header.="&p=".$p; }
		if (isset($pg)) { $header.="&pg=".$pg; }
		header($header);
		exit;
		}
	else if (trim($manage_account)=="3")
		{
		$temp=@read_log($whm_id, $below_public);
		list($xwhm_username, $xwhm_password)=split("[|]", $temp);

		$rs=mysql_fetch_row(mysql_query("select server_ip from server_config where whm_id='".addslashes(trim($whm_id))."'"));
		$rs0=mysql_fetch_row(mysql_query("select whm_username, uid from hosting_order where oid='".addslashes(trim($oid))."'"));
		
		$server_ip=$rs[0];
		$whm_username=$rs0[0];
		$uid=$rs0[1];

		terminate_account($server_ip, $xwhm_username, $xwhm_password, $whm_username);

		mysql_query("delete from hosting_order where oid='".addslashes(trim($oid))."'");
		mysql_query("delete from invoice where oid='".addslashes(trim($oid))."'");
		mysql_query("delete from affiliate_details where oid='".addslashes(trim($oid))."'");
		header("Location: ".$http_admin."/index2.php?sid=".trim($sid));
		exit;
		}
	else if (trim($manage_account)=="4")
		{
		$rs0=mysql_fetch_row(mysql_query("select uid from hosting_order where oid='".addslashes(trim($oid))."'"));
		
		mysql_query("delete from hosting_order where oid='".addslashes(trim($oid))."'");
		mysql_query("delete from invoice where oid='".addslashes(trim($oid))."'");
		mysql_query("delete from affiliate_details where oid='".addslashes(trim($oid))."'");
		header("Location: ".$http_admin."/index2.php?sid=".trim($sid)."");
		exit;
		}
	else if (trim($manage_account)=="5")
		{
		$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 from server_config where whm_id='".addslashes(trim($whm_id))."'"));

		unsuspend_account($rsip[0], $xwhm_username, $xwhm_password, $whm_username);
			
		// update db
		mysql_query("update hosting_order set status='1', client_notes='".addslashes(trim($client_notes))."', admin_notes='".addslashes(trim($admin_notes))."' where oid='".addslashes(trim($oid))."'");

		resend_logins_admin_area($resend_welcome, $resend_dns);
		
		$header="Location: ";
		$header.=$http_admin;
		$header.="/client_view.php?";
		$header.="sid=".$sid;
		$header.="&oid=".$oid;
		$header.="&status=".$status;
		$header.="&create_account=1003";
		if (isset($in)) { $header.="&in=5"; }
		else if (isset($ix)) { $header.="&ix=5"; }
		if (isset($p)) { $header.="&p=".$p; }
		if (isset($pg)) { $header.="&pg=".$pg; }
		header($header);
		exit;
		}
	else if (trim($manage_account)=="6")
		{
		$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 from server_config where whm_id='".addslashes(trim($whm_id))."'"));

		suspend_account($rsip[0], $xwhm_username, $xwhm_password, $whm_username);
		
		// suspend the order in the db
		mysql_query("update hosting_order set status='5', client_notes='".addslashes(trim($client_notes))."', admin_notes='".addslashes(trim($admin_notes))."' where oid='".addslashes(trim($oid))."'");

		resend_logins_admin_area($resend_welcome, $resend_dns);
		
		$header="Location: ";
		$header.=$http_admin;
		$header.="/client_view.php?";
		$header.="sid=".$sid;
		$header.="&oid=".$oid;
		$header.="&status=".$status;
		$header.="&create_account=1004";
		if (isset($in)) { $header.="&in=5"; }
		else if (isset($ix)) { $header.="&ix=5"; }
		if (isset($p)) { $header.="&p=".$p; }
		if (isset($pg)) { $header.="&pg=".$pg; }
		header($header);
		exit;	
		}
	else if (trim($manage_account)=="7")
		{
		// split the pid/payment term
		list($pid, $payment_term)=split("[|]", $xpid);
		
		// build the addon_choices delimit from checkboxes
		$addon_choices="";
		if(phpversion() <= "4.0.6") { $_POST=$HTTP_POST_VARS; }
		while (list ($key, $value) = each ($HTTP_POST_VARS)) 
			{ 
			if (ereg("aid", $key)==true) 
				{
				# -----------------------------------------------------------------------------------------------------------------
				$rs_c=mysql_fetch_row(mysql_query("select coupon from addon_specs where aid='".addslashes(trim($value))."'"));
				if ($rs_c[0]==1) { $coupon_bit=$value; }
				# -----------------------------------------------------------------------------------------------------------------
				$addon_choices.=$value."|"; 
				} 
			}

		// reseller or not?
		if ($reseller==0) 
			{ 
			$temp=@read_log($whm_id, $below_public);
			list($xwhm_username, $xwhm_password)=split("[|]", $temp);

			$rs_oldip=mysql_fetch_row(mysql_query("select ip, addon_choices, whm_id from hosting_order where oid='".addslashes(trim($oid))."'"));

			// will not try to change ip if we are in the process of a server move
			$server_state=strcmp($whm_id, $rs_oldip[2]);
			
			$rs_ip=mysql_fetch_row(mysql_query("select server_ip from server_config where whm_id='".addslashes(trim($whm_id))."'"));

			$already_installed_extra_space=extra_webspace_ordered($rs_oldip[1]);
			$default_ip=$ip;

			// WEB SPACE ADDONS
			$extra_space=extra_webspace_ordered($addon_choices);
			if ($extra_space!=0&&$already_installed_extra_space==0&&$server_state==0) 
				{ 
				$rs_pq=mysql_fetch_row(mysql_query("select web_space from plan_specs where pid='".addslashes(trim($pid))."'"));
				$quota=$extra_space+$rs_pq[0];
				change_sites_quota($rs_ip[0], $xwhm_username, $xwhm_password, $whm_username, $quota); 
				}
			}

		$default_ip=$ip;

		$data_calc=calc_totals($payment_term, $domain_registration, $domain_fee, $pid, $addon_choices);
		list($total_due_today, $total_reoccur, $payment_term)=split("[|]", $data_calc);

		# -----------------------------------------------------------------------------------------------------------------
		if (isset($coupon_bit))
			{
			$query_c="select ";
			$query_c.="coupon_terms, ";				// 0
			$query_c.="coupon_discount_type, ";		// 1
			$query_c.="coupon_discount_percent, ";	// 2
			$query_c.="coupon_discount_whole ";		// 3
			$query_c.="from ";
			$query_c.="addon_specs ";
			$query_c.="where ";
			$query_c.="aid='".addslashes(trim($coupon_bit))."'";

			$rs_c=mysql_fetch_row(mysql_query($query_c));

			$coupon_terms=stripslashes(trim($rs_c[0])); # 1 == one time; 2 == monthly;
			$coupon_discount_type=stripslashes(trim($rs_c[1])); # 1 == %; 2 == whole dollar amount;
			$coupon_discount_percent=stripslashes(trim($rs_c[2]));
			$coupon_discount_whole=stripslashes(trim($rs_c[3]));

			# 1. figure out one time or monthly
			if ($coupon_terms==1) # one time
				{
				if ($coupon_discount_type==1) # %
					{
					# - %
					$sub_total_due_today=($total_due_today-$total_reoccur);
					$convert_to_percent=($coupon_discount_percent/100);
					$discounted_total_due_today=$total_reoccur-($total_reoccur*$convert_to_percent);
					$new_total_due_today=$sub_total_due_today+$discounted_total_due_today;
					if ($discounted_total_due_today+$setup_cost>=1) { $total_due_today=$new_total_due_today; }
					}
				else if ($coupon_discount_type==2) # whole dollar amount
					{
					# - WHOLE DOLLAR
					$sub_total_due_today=($total_due_today-$total_reoccur);
					$discounted_total_due_today=$total_reoccur-$coupon_discount_whole;
					$new_total_due_today=$sub_total_due_today+$discounted_total_due_today;
					if ($discounted_total_due_today+$setup_cost>=1) { $total_due_today=$new_total_due_today; }
					}
				}
			else if ($coupon_terms==2) # monthly
				{
				if ($coupon_discount_type==1) # %
					{
					# - %
					# do today's totals
					$sub_total_due_today=($total_due_today-$total_reoccur);
					$convert_to_percent=($coupon_discount_percent/100);
					$discounted_total_due_today=$total_reoccur-($total_reoccur*$convert_to_percent);
					$new_total_due_today=$sub_total_due_today+$discounted_total_due_today;
					if ($discounted_total_due_today+$setup_cost>=1) 
						{ 
						$total_due_today=$new_total_due_today; 
						$total_reoccur=$discounted_total_due_today;
						}
					}
				else if ($coupon_discount_type==2) # whole dollar amount
					{ 
					# - WHOLE DOLLAR 
					$sub_total_due_today=($total_due_today-$total_reoccur);
					$discounted_total_due_today=$total_reoccur-$coupon_discount_whole;
					$new_total_due_today=$sub_total_due_today+$discounted_total_due_today;
					if ($discounted_total_due_today+$setup_cost>=1)  
						{ 
						$total_due_today=$new_total_due_today; 
						$total_reoccur=$discounted_total_due_today;
						}
					}
				}
			}
		# -----------------------------------------------------------------------------------------------------------------

		$update="update hosting_order set ";
		$update.="next_due_date='".addslashes(trim($next_due_date))."', ";
		$update.="ogcreate='".addslashes(trim($ogcreate_hosting))."', ";
			
		# 7/22/2003 - downgrade resellers
		# ------------------------------------------------------------------------------
		$qr="select ";
		$qr.="rid ";
		$qr.="from ";
		$qr.="plan_specs ";
		$qr.="where ";
		$qr.="pid='".addslashes(trim($pid))."'";
		$qrs=mysql_fetch_row(mysql_query($qr));
		if ($qrs[0]==0)
			{
			$update.="pid='".addslashes(trim($pid))."', ";
			$update.="reseller='0', ";
			}
		else
			{
			$update.="pid='".addslashes(trim($pid))."', ";
			$update.="reseller='1', ";
			}
		# ------------------------------------------------------------------------------
		# 7/22/2003 - downgrade resellers

		
		$update.="pns1='".addslashes(trim($pns1))."', ";
		$update.="pns2='".addslashes(trim($pns2))."', ";
		$update.="payment_term='".addslashes(trim($payment_term))."', ";
		$update.="addon_choices='".addslashes(trim($addon_choices))."', ";
		$update.="payment_method='".addslashes(trim($payment_method))."', ";

		if ($domain_registration>0) 
			{ 
			$query="select ";
			$query.="reg_period, ";
			$query.="tld,";
			$query.="tld_id, ";
			$query.="cost ";
			$query.="from ";
			$query.="tld_chart ";
			$query.="where ";
			$query.="tld_id='".addslashes(trim($domain_registration))."'";
			
			$rs=mysql_fetch_row(mysql_query($query));
			
			$reg_period=$rs[0];
			$tld=$rs[1];
			$xtld_id=$rs[2];
			$cost=sprintf("%01.2f", $rs[3]);

			if ($reg_period==1) { $reg_period="Domain registration for 1 year. [.".$tld."] [".$cost."] \n";	}
			else if ($reg_period==2) { $reg_period="Domain registration for 2 years. [.".$tld."] [".$cost."]\n";	}
			else if ($reg_period==3) { $reg_period="Domain registration for 5 years. [.".$tld."] [".$cost."]\n";	}
			else if ($reg_period==4) { $reg_period="Domain registration for 10 years. [.".$tld."] [".$cost."]\n";	}

			$update.="domain_registration='1', ";
			$total_due_today+=$cost;
			}
		else { $update.="domain_registration='0', "; }

		$update.="tld_id='".addslashes(trim($domain_registration))."', ";
			
		$update.="total_due_today='".addslashes(trim($total_due_today))."', ";
		$update.="total_due_reoccur='".addslashes(trim($total_reoccur))."', ";
		$update.="whm_username='".addslashes(trim($whm_username))."', ";
		$update.="whm_password='".addslashes(trim($whm_password))."', ";
		$update.="admin_notes='".addslashes(trim($admin_notes))."', ";
		$update.="client_notes='".addslashes(trim($client_notes))."', ";
		$update.="ip='".addslashes(trim($default_ip))."', ";
		$update.="whm_id='".addslashes(trim($whm_id))."', ";
		if (trim($ns1)!=""||trim($ns2)!="")
			{
			$update.="ns1='".addslashes(trim($ns1))."', ";
			$update.="ns2='".addslashes(trim($ns2))."' ";
			}
		else
			{
			$update.="ns1='".addslashes(trim($primary_ns))."', ";
			$update.="ns2='".addslashes(trim($secondary_ns))."' ";
			}

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

		mysql_query($update);

		update_invoice_internal($oid);

		// build query
		$uupdate="update user set ";
		if (strlen(trim($client_password))!=0) { $uupdate.="password='".md5(strtolower(trim($client_password)))."', "; }
		$uupdate.="username='".addslashes(trim($client_username))."' ";
		$uupdate.="where uid='".addslashes(trim($uid))."'";
		mysql_query($uupdate);

		resend_logins_admin_area($resend_welcome, $resend_dns);
		
		$header="Location: ";
		$header.=$http_admin;
		$header.="/client_view.php?";
		$header.="sid=".$sid;
		$header.="&oid=".$oid;
		$header.="&status=".$status;
		$header.="&create_account=1001";
		if (isset($in)) { $header.="&in=5"; }
		else if (isset($ix)) { $header.="&ix=5"; }
		if (isset($p)) { $header.="&p=".$p; }
		if (isset($pg)) { $header.="&pg=".$pg; }
		header($header);
		exit;	
		}
	}


$query="select ";
$query.="user.first_name, ";				// 0
$query.="user.last_name, ";					// 1
$query.="user.organization_name, ";			// 2
$query.="user.street_address_1, ";			// 3
$query.="user.street_address_2, ";			// 4
$query.="user.city, ";						// 5
$query.="user.state, ";						// 6
$query.="user.zip_code, ";					// 7
$query.="user.country, ";					// 8
$query.="user.phone, ";						// 9
$query.="user.fax, ";						// 10
$query.="user.email, ";						// 11
# $query.="UNIX_TIMESTAMP(user.ogcreate), ";	// 12
$query.="user.ogcreate, ";	// 12
$query.="hosting_order.domain_name, ";		// 13
$query.="hosting_order.resolved, ";			// 14
$query.="hosting_order.ip, ";								// 15
# $query.="UNIX_TIMESTAMP(hosting_order.resolved_time), ";	// 16
# $query.="UNIX_TIMESTAMP(hosting_order.ur_date), ";			// 17
$query.="hosting_order.resolved_time, ";	// 16
$query.="hosting_order.ur_date, ";			// 17
$query.="hosting_order.domain_expire, ";					// 18
$query.="hosting_order.whm_username, ";						// 19
$query.="hosting_order.whm_password, ";						// 20
$query.="user.username, ";					// 21
$query.="user.temp_pw, ";					// 22
$query.="user.sid, ";						// 23
$query.="hosting_order.ip, ";				// 24
$query.="hosting_order.ns1, ";				// 25
$query.="hosting_order.ns2, ";				// 26
# $query.="UNIX_TIMESTAMP(hosting_order.ogcreate), ";			// 27
$query.="hosting_order.ogcreate, ";			// 27
$query.="hosting_order.pid, ";				// 28
$query.="hosting_order.payment_term, ";		// 29
$query.="hosting_order.total_due_today, ";	// 30
$query.="hosting_order.total_due_reoccur, ";// 31
$query.="hosting_order.status, ";			// 32
$query.="hosting_order.whm_id, ";			// 33
$query.="hosting_order.payment_method, ";	// 34
$query.="user.uid, ";						// 35
$query.="hosting_order.status, ";			// 36
$query.="hosting_order.addon_choices, ";	// 37
$query.="hosting_order.ogcreate, ";			// 38
$query.="user.ogcreate, ";					// 39
$query.="user.advert, ";					// 40
$query.="user.advert_other, ";				// 41
$query.="hosting_order.referrer_id, ";		// 42
$query.="hosting_order.domain_registration, ";// 43
$query.="hosting_order.next_due_date, ";	// 44
$query.="hosting_order.cont_resolve, ";		// 45
$query.="hosting_order.client_notes, ";		// 46
$query.="hosting_order.admin_notes, ";		// 47
$query.="hosting_order.pns1, ";				// 48
$query.="hosting_order.pns2, ";				// 49
$query.="hosting_order.server_hostname, ";	// 50
$query.="hosting_order.root_pw, ";			// 51
$query.="hosting_order.server_specs, ";		// 52
$query.="hosting_order.ipblock, ";			// 53
$query.="hosting_order.rack, ";				// 54
$query.="plan_specs.dedicated, ";			// 55
# added client IP on 11-21-2003 by brandee
$query.="hosting_order.client_ip, ";		// 56
$query.="hosting_order.client_host, ";		// 57
$query.="hosting_order.tld_id ";			// 58
$query.="from user, hosting_order, plan_specs ";
$query.="where user.uid=hosting_order.uid ";
$query.="and hosting_order.oid='".addslashes(trim($oid))."' ";
$query.="and hosting_order.pid=plan_specs.pid ";
$query.="order by user.uid asc";

// execute the query
$rs=mysql_fetch_row(mysql_query($query));

// define variables
$first_name=stripslashes($rs[0]);
$last_name=stripslashes($rs[1]);
$organization_name=stripslashes($rs[2]);
$street_address_1=stripslashes($rs[3]);
$street_address_2=stripslashes($rs[4]);
$city=stripslashes($rs[5]);
$state=stripslashes($rs[6]);
$zip_code=stripslashes($rs[7]);
$country=stripslashes($rs[8]);
$phone=stripslashes($rs[9]);
$fax=stripslashes($rs[10]);
$email=stripslashes($rs[11]);
$domain_name=stripslashes($rs[13]);
$resolved=stripslashes($rs[14]);
$ip=stripslashes($rs[15]);
$domain_expire=stripslashes($rs[18]);
$whm_username=stripslashes($rs[19]);
$whm_password=stripslashes($rs[20]);
$client_username=stripslashes($rs[21]);
$client_password=stripslashes($rs[22]);
$client_sid=stripslashes($rs[23]);
$ip=stripslashes($rs[24]);
$ns1=stripslashes($rs[25]);
$ns2=stripslashes($rs[26]);
$pid=stripslashes($rs[28]);
$payment_term=stripslashes($rs[29]);
$total_due_today=stripslashes($rs[30]);
$total_due_reoccur=stripslashes($rs[31]);
$order_status=stripslashes($rs[32]);
$whm_id=stripslashes($rs[33]);
$payment_method=stripslashes($rs[34]);
$uid=stripslashes($rs[35]);
$xstatus=stripslashes($rs[36]);
$addon_choices=stripslashes($rs[37]);
$advert=stripslashes($rs[40]);
$advert_other=stripslashes($rs[41]);
$referrer_id=stripslashes($rs[42]);
$domain_registration=stripslashes(trim($rs[43]));
$cont_resolve=stripslashes(trim($rs[45]));
$client_notes=stripslashes(trim($rs[46]));
$admin_notes=stripslashes(trim($rs[47]));
$pns1=stripslashes(trim($rs[48]));
$pns2=stripslashes(trim($rs[49]));
$server_hostname=stripslashes(trim($rs[50]));
$root_pw=stripslashes(trim($rs[51]));
$server_specs=stripslashes(trim($rs[52]));
$ipblock=stripslashes(trim($rs[53]));
$rack=stripslashes(trim($rs[54]));
$dedicated=stripslashes(trim($rs[55]));
#added by brandee on 11-21-2003
$client_ip=stripslashes(trim($rs[56]));
$client_host=stripslashes(trim($rs[57]));
$tld_id=stripslashes(trim($rs[58]));


$ogcreate=stripslashes($rs[12]);
$resolved_date=stripslashes($rs[16]);
$ur_date=stripslashes($rs[17]);
$ogcreate_hosting=stripslashes($rs[27]);

$next_due_date=stripslashes(trim($rs[44]));
# PHASE OUT -> $xogcreate=stripslashes($rs[38]);
# PHASE OUT -> $xhogcreate=stripslashes($rs[39]);

$rsaffct=mysql_fetch_row(mysql_query("select count(*) from affiliate_details where oid='".addslashes(trim($oid))."'"));
if ($rsaffct[0]>=1)
	{
	$rsaff=mysql_fetch_row(mysql_query("select afdid, afuid from affiliate_details where oid='".addslashes(trim($oid))."'"));
	$afdid=$rsaff[0];
	$afuid=$rsaff[1];
	}
else
	{
	$afuid="";
	$afdid="";
	}

$xquery="select ";
$xquery.="package_name, ";
$xquery.="addon_gid ";
$xquery.="from plan_specs ";
$xquery.="where pid='".addslashes(trim($pid))."'";
$rs0=mysql_fetch_row(mysql_query($xquery));
$package_name=stripslashes(trim($rs0[0]));
$addon_gid=stripslashes(trim($rs0[1]));

include $server_admin_inc."/header.php";

// display the end game
if (isset($create_account)) { include $server_admin_tools."/client_view_complete_inc.php"; die(); }

// work the show hide menus
if (!isset($show_client)) { $show_client=1; }
if (!isset($show_domain)) { $show_domain=1; }
if (!isset($show_account)) { $show_account=1; }

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='0' border='0'>
				<tr>
					<td><img src='".$http_images."/menu_arrow.gif'><b>Client Management</b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[<a href='".$http_admin."/
	");

if (isset($in)) { echo "invoice_hosting_history.php?sid=".$sid."".((isset($pg))?"&pg=".$pg."":"")."&oid=".base64_encode($oid); }
else if (isset($ix))
	{
	if ($p==0) { echo "invoice_hosting_unpaid.php?sid=".$sid."".((isset($pg))?"&pg=".$pg."":"")."&oid=".base64_encode($oid); }
	else if ($p==1) { echo "invoice_hosting_paid.php?sid=".$sid."".((isset($pg))?"&pg=".$pg."":"")."&oid=".base64_encode($oid); }
	else if ($p==2) { echo "invoice_hosting_past_due.php?sid=".$sid."".((isset($pg))?"&pg=".$pg."":"")."&oid=".base64_encode($oid); }
	}
else { echo "client_view_edit.php?sid=".$sid; }
echo("
					'>go back</a>]</td>
				</tr>
				<tr>
					<td><hr color='#F0EFED'></td>
				</tr>
			</table>
	");
include $server_admin_tools."/client_view_info.php";
if ($dedicated==0) 
	{ 
	include $server_admin_tools."/client_view_domain_info.php";
	include $server_admin_tools."/client_view_account_info.php";
	}
else { include $server_admin_tools."/client_view_dedicated_account_info.php"; }
echo("
			</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>
	");

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