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

# --------------------------------------------------------------------------------------------------------------------
# start client entry
if (isset($submit))
	{
	if (strlen(trim($first_name))==0) {$err0=true;} else {$n0=true;}
	if (strlen(trim($last_name))==0) {$err1=true;} else {$n1=true;}
	if (strlen(trim($street_address_1))==0) {$err2=true;} else {$n2=true;}
	if (strlen(trim($city))==0) {$err3=true;} else {$n3=true;}
	if (strlen(trim($state))==0) {$err4=true;} else {$n4=true;}
	if (strlen(trim($zip_code))==0) {$err5=true;} else {$n5=true;}
	if (strlen(trim($country))==0) {$err6=true;} else {$n6=true;}
	if (strlen(trim($phone))==0) {$err7=true;} else {$n7=true;}

	if (isset($uid)&&trim($password)==""&&trim($password2)=="") { $n10=true; }
	else { if (strcmp($password, $password2)!=0||strlen(trim($password))==0) {$err10=true;} else {$n10=true;} }

	if (!isset($uid))
		{
		if (strlen(trim($email))==0) {$err8=true;} else {$n8=true;}
		if (strlen(trim($username))==0) {$err9=true;} else {$n9=true;}
		if (check_user($username)==1) {$err14=true;} else {$n14=true;}
		if (check_email($email)==1) {$err15=true;} else {$n15=true;}
		}
	else { $n8=true; $n9=true; $n14=true; $n15=true; }

	if (isset($n0)&&isset($n1)&&isset($n2)&&isset($n3)
		&&isset($n4)&&isset($n5)&&isset($n6)&&isset($n7)
		&&isset($n8)&&isset($n9)&&isset($n10)&&isset($n14)
		&&isset($n15))
		{
		// put order in system
		// insert user
		$update="update user set ";
		$update.="first_name='".addslashes(trim($first_name))."', ";
		$update.="last_name='".addslashes(trim($last_name))."', ";
		if (strlen(trim($organization_name))!=0) { $update.="organization_name='".addslashes(trim($organization_name))."', "; }
		$update.="street_address_1='".addslashes(trim($street_address_1))."', ";
		if (strlen(trim($street_address_2))!=0) { $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.="username='".addslashes(trim($username))."', ";
		$update.="password='".md5(strtolower(trim($password)))."', ";
		$update.="advert='OTHER', ";
		$update.="advert_other='Manually Created', ";
		$update.="tos='1',";
		$update.="sid='".create_sid()."' ";
		$update.="where uid='".addslashes(trim($uid))."'";

		mysql_query($update);
		
		$done=true;
		}
	}
# end client entry

# general variables
if (isset($uid))
	{
	$qrs4="select ";
	$qrs4.="first_name, ";			// 0
	$qrs4.="last_name, ";			// 1
	$qrs4.="organization_name, ";	// 2
	$qrs4.="street_address_1, ";	// 3
	$qrs4.="street_address_2, ";	// 4
	$qrs4.="city, ";				// 5
	$qrs4.="state, ";				// 6
	$qrs4.="zip_code, ";			// 7
	$qrs4.="country, ";				// 8
	$qrs4.="phone, ";				// 9
	$qrs4.="fax, ";					// 10
	$qrs4.="email, ";				// 11
	$qrs4.="username ";				// 12
	$qrs4.="from ";		
	$qrs4.="user ";
	$qrs4.="where ";
	$qrs4.="uid='".addslashes(trim($uid))."'";
	
	$rs=mysql_fetch_row(mysql_query($qrs4));

	$first_name=stripslashes(trim($rs[0]));
	$last_name=stripslashes(trim($rs[1]));
	$organization_name=stripslashes(trim($rs[2]));
	$street_address_1=stripslashes(trim($rs[3]));
	$street_address_2=stripslashes(trim($rs[4]));
	$city=stripslashes(trim($rs[5]));
	$state=stripslashes(trim($rs[6]));
	$zip_code=stripslashes(trim($rs[7]));
	$country=stripslashes(trim($rs[8]));
	$phone=stripslashes(trim($rs[9]));
	$fax=stripslashes(trim($rs[10]));
	$email=stripslashes(trim($rs[11]));
	$username=stripslashes(trim($rs[12]));
	}
# end general variables

# start GUI
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='725' cellpadding='2' cellspacing='0' border='0'>
				<tr>
					<td colspan='2' align='left' valign='top'><img src='".$http_images."/menu_arrow.gif'> <a href='".$http_admin."/invoice.php?sid=".$sid."'>Invoice Home</a> &gt; <a href='".$http_admin."/invoice_non_hosting_clients.php?sid=".$sid."'><font color='#990000'>Non Hosting Clients View</font></a></td>
				</tr>
				<tr>
					<td colspan='2' align='left' valign='top'><hr color='#F0EFED'></td>
				</tr>
			</table>
	");

if (isset($done))
	{
	echo("
		<table width='725' cellpadding='2' cellspacing='0' border='0'>
			<tr>
				<td align='left' valign='top'><font color='#990000'>The client information was edited successfully!</font></td>
			</tr>
			<tr>
				<td align='left' valign='top'><img src='".$http_images."/error_arrow.gif'><a href='".$http_admin."/invoice_non_hosting_clients.php?sid=".$sid."'>Go back to the non hosting clients view</a></td>
			</tr>
			<tr>
				<td align='left' valign='top'><img src='".$http_images."/error_arrow.gif'><a href='".$http_admin."/invoice.php?sid=".$sid."'>Go back to the main invoice view</a>.</td>
			</tr>
			<tr>
				<td align='left' valign='top'><img src='".$http_images."/error_arrow.gif'>Make edits to <b>this invoice</b> below:</td>
			</tr>
			<tr>
				<td align='left' valign='top'><hr align='left' valign='top' color='#F0EFED' width='725'></td>
			</tr>
		</table>
		");
	}

// Error Handling
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 your <b>first name</b> to continue.</td> 
	</tr>
	<tr>
		<td><img src='".$http_images."/space.gif' width='1' height='2'></td>
	</tr>
</table>
		");
	}
if (isset($err1))
	{
	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 your <b>last name</b> to continue.</td> 
	</tr>
	<tr>
		<td><img src='".$http_images."/space.gif' width='1' height='2'></td>
	</tr>
</table>
		");
	}
if (isset($err2))
	{
	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 your <b>street address</b> to continue.</td> 
	</tr>
	<tr>
		<td><img src='".$http_images."/space.gif' width='1' height='2'></td>
	</tr>
</table>
		");
	}
if (isset($err3))
	{
	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 your <b>city</b> to continue.</td> 
	</tr>
	<tr>
		<td><img src='".$http_images."/space.gif' width='1' height='2'></td>
	</tr>
</table>
		");
	}
if (isset($err4))
	{
	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 your <b>state</b> to continue.</td> 
	</tr>
	<tr>
		<td><img src='".$http_images."/space.gif' width='1' height='2'></td>
	</tr>
</table>
		");
	}
if (isset($err5))
	{
	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 your <b>postal code</b> to continue.</td> 
	</tr>
	<tr>
		<td><img src='".$http_images."/space.gif' width='1' height='2'></td>
	</tr>
</table>
		");
	}
if (isset($err7))
	{
	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 your <b>phone number</b> to continue.</td> 
	</tr>
	<tr>
		<td><img src='".$http_images."/space.gif' width='1' height='2'></td>
	</tr>
</table>
		");
	}
if (isset($err8))
	{
	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 your <b>eMail address</b> to continue.</td> 
	</tr>
	<tr>
		<td><img src='".$http_images."/space.gif' width='1' height='2'></td>
	</tr>
</table>
		");
	}
if (isset($err9))
	{
	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 choose a <b>username</b> to continue.</td> 
	</tr>
	<tr>
		<td><img src='".$http_images."/space.gif' width='1' height='2'></td>
	</tr>
</table>
		");
	}
if (isset($err10))
	{
	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> Your <b>passwords</b> were left blank or do not match.</td> 
	</tr>
	<tr>
		<td><img src='".$http_images."/space.gif' width='1' height='2'></td>
	</tr>
</table>
		");
	}
if (isset($err11))
	{
	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> Please specify the way that <b>you found us</b> in order to continue.</td> 
	</tr>
	<tr>
		<td><img src='".$http_images."/space.gif' width='1' height='2'></td>
	</tr>
</table>
		");
	}
if (isset($err12))
	{
	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 choose other as how you found us, <b>please specify</b> in order to continue.</td> 
	</tr>
	<tr>
		<td><img src='".$http_images."/space.gif' width='1' height='2'></td>
	</tr>
</table>
		");
	}
if (isset($err13))
	{
	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 agree to our <b>terms of service</b> to continue.</td> 
	</tr>
</table>
		");
	}
if (isset($err14))
	{
	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> The username <b>".$username."</b> already in use.</td> 
	</tr>
</table>
		");
	}
if (isset($err15))
	{
	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> The eMail address <b>".$email."</b> already in use.</td> 
	</tr>
</table>
		");
	}
if (isset($err0)||isset($err1)||isset($err2)||isset($err3)||isset($err4)||isset($err5)||isset($err6)||isset($err7)||isset($err8)||isset($err9)||isset($err10)||isset($err11)||isset($err12)||isset($err13)||isset($err14)||isset($err15))
	{
	echo("
<table width='725' cellpadding='2' cellspacing='0' border='0'>
	<tr>
		<td><img src='".$http_images."/space.gif' width='1' height='10'></td>
	</tr>
</table>
		");
	}
// end error handling





echo("
<form action='".$PHP_SELF."' method='POST'> 
<input type='hidden' name='sid' value='".$sid."'>
<input type='hidden' name='uid' value='".$uid."'>
<table width='725' cellpadding='2' cellspacing='0' border='0'>
	<tr>
		<td width='30%' align='left' valign='top'><img src='".$http_images."/".((isset($err0))?"error_arrow.gif":"space.gif")."' width='15' height='9'>First Name:</td>
		<td width='70%' align='left' valign='top'><input ".$input_style." size='30' maxlength='255' type='text' name='first_name' value=\"".((isset($first_name))?"".trim(stripslashes($first_name))."":"")."\"> [Required]</td>
	</tr>
	<tr>
		<td width='30%' align='left' valign='top'><img src='".$http_images."/".((isset($err1))?"error_arrow.gif":"space.gif")."' width='15' height='9'>Last Name:</td>
		<td width='70%' align='left' valign='top'><input ".$input_style." size='30' maxlength='255' type='text' name='last_name' value=\"".((isset($last_name))?"".$last_name."":"")."\"> [Required]</td>
	</tr>
	<tr>
		<td width='30%' align='left' valign='top'><img src='".$http_images."/space.gif' width='15' height='9'>Organization Name:</td>
		<td width='70%' align='left' valign='top'><input ".$input_style." size='30' maxlength='255' type='text' name='organization_name' value=\"".((isset($organization_name))?"".$organization_name."":"")."\"> [<font color='#990000'><i>Optional</i></font>]</td>
	</tr>
	<tr>
		<td width='30%' align='left' valign='top'><img src='".$http_images."/".((isset($err2))?"error_arrow.gif":"space.gif")."' width='15' height='9'>Street Address:</td>
		<td width='70%' align='left' valign='top'><input ".$input_style." size='30' maxlength='255' type='text' name='street_address_1' value=\"".((isset($street_address_1))?"".$street_address_1."":"")."\"> [Required]</td>
	</tr>
	<tr>
		<td width='30%' align='left' valign='top'></td>
		<td width='70%' align='left' valign='top'><input ".$input_style." size='30' maxlength='255' type='text' name='street_address_2' value=\"".((isset($street_address_2))?"".$street_address_2."":"")."\"> [<font color='#990000'><i>Optional</i></font>]</td>
	</tr>
	<tr>
		<td width='30%' align='left' valign='top'><img src='".$http_images."/".((isset($err3))?"error_arrow.gif":"space.gif")."' width='15' height='9'>City:</td>
		<td width='70%' align='left' valign='top'><input ".$input_style." size='30' maxlength='255' type='text' name='city' value=\"".((isset($city))?"".$city."":"")."\"> [Required]</td>
	</tr>
	<tr>
		<td width='30%' align='left' valign='top'><img src='".$http_images."/".((isset($err4))?"error_arrow.gif":"space.gif")."' width='15' height='9'>State/Province:</td>
		<td width='70%' align='left' valign='top'><input ".$input_style." size='30' maxlength='255' type='text' name='state' value=\"".((isset($state))?"".$state."":"")."\"> [Required]</td>
	</tr>
	<tr>
		<td width='30%' align='left' valign='top'><img src='".$http_images."/".((isset($err5))?"error_arrow.gif":"space.gif")."' width='15' height='9'>Postal Code:</td>
		<td width='70%' align='left' valign='top'><input ".$input_style." size='30' maxlength='255' type='text' name='zip_code' value=\"".((isset($zip_code))?"".$zip_code."":"")."\"> [Required]</td>
	</tr>
	<tr>
		<td width='30%' align='left' valign='top'><img src='".$http_images."/".((isset($err6))?"error_arrow.gif":"space.gif")."' width='15' height='9'>Country:</td>
		<td width='70%' align='left' valign='top'>
	");
@country($country,$input_style);
echo("
		<img src='".$http_images."/space.gif' width='5' height='9'>[Required]</td>
	</tr>
	<tr>
		<td width='30%' align='left' valign='top'><img src='".$http_images."/".((isset($err7))?"error_arrow.gif":"space.gif")."' width='15' height='9'>Phone Number:</td>
		<td width='70%' align='left' valign='top'><input ".$input_style." size='30' maxlength='255' type='text' name='phone' value=\"".((isset($phone))?"".$phone."":"")."\"> [Required]</td>
	</tr>
	<tr>
		<td width='30%' align='left' valign='top'><img src='".$http_images."/space.gif' width='15' height='9'>Fax Number:</td>
		<td width='70%' align='left' valign='top'><input ".$input_style." size='30' maxlength='255' type='text' name='fax' value=\"".((isset($fax))?"".$fax."":"")."\"> [<font color='#990000'><i>Optional</i></font>]</td>
	</tr>
	");
if (!isset($uid))
	{
	echo("
	<tr>
		<td width='30%' align='left' valign='top'><img src='".$http_images."/".((isset($err8))?"error_arrow.gif":"space.gif")."' width='15' height='9'>eMail Address:</td>
		<td width='70%' align='left' valign='top'><input ".$input_style." size='30' maxlength='255' type='text' name='email' value=\"".((isset($email))?"".$email."":"")."\"> [Required]</td>
	</tr>
		");
	}
else
	{
	echo("
	<tr>
		<td width='30%' align='left' valign='top'><img src='".$http_images."/".((isset($err8))?"error_arrow.gif":"space.gif")."' width='15' height='9'>eMail Address:</td>
		<td width='70%' align='left' valign='top'><input type='hidden' name='email' value='".$email."'><a href='mailto:".$email."'>".$email."</a></td>
	</tr>
		");
	}
if (!isset($uid))
	{
	echo("
	<tr>
		<td width='30%' align='left' valign='top'><img src='".$http_images."/".((isset($err9))?"error_arrow.gif":"space.gif")."' width='15' height='9'>Client Area Username:</td>
		<td width='70%' align='left' valign='top'><input ".$input_style." size='30' maxlength='255' type='text' name='username' value=\"".((isset($username))?"".$username."":"")."\"> [Required]</td>
	</tr>
		");
	}
else
	{
	echo("
	<tr>
		<td width='30%' align='left' valign='top'><img src='".$http_images."/".((isset($err9))?"error_arrow.gif":"space.gif")."' width='15' height='9'>Client Area Username:</td>
		<td width='70%' align='left' valign='top'><input type='hidden' name='username' value=\"".$username."\">".$username."</td>
	</tr>
		");
	}
echo("
	<tr>
		<td width='30%' align='left' valign='top'><img src='".$http_images."/".((isset($err10))?"error_arrow.gif":"space.gif")."' width='15' height='9'>".((isset($uid))?"Change":"Choose")." Password:</td>
		<td width='70%' align='left' valign='top'><input ".$input_style." size='30' maxlength='255' type='text' name='password' value=''> [Required]</td>
	</tr>
	<tr>
		<td width='30%' align='left' valign='top'><img src='".$http_images."/".((isset($err10))?"error_arrow.gif":"space.gif")."' width='15' height='9'>Verify Password:</td>
		<td width='70%' align='left' valign='top'><input ".$input_style." size='30' maxlength='255' type='text' name='password2' value=''> [Required]</td>
	</tr>
	<tr>
		<td colspan='2'><img src='".$http_images."/space.gif' width='1' height='10'></td>
	</tr>
	<tr>
		<td width='30%' align='left' valign='top'></td>
		<td width='70%' align='left' valign='top'><input ".$button_style." type='submit' name='submit' value='Save Changes Now'></td>
	</tr>
</table>
</form>
	");






echo("
			</td>
		</tr>
		<tr>
			<td colspan='2'><img src='".$http_images."/space.gif' width='1' height='6'></td>
		</tr>
	</table>
	");

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