<?php
include("postget.php");
include_once("common.php");
$pagetitle = _ADD_A_NEW_CLIENT;
checklevel(3,$_REQUEST['clientid']);


if ($_REQUEST[send]==""._SEND."") {
	$estiloerror = "class='formfielderror'";
	$errors = '';
	if ($_POST['First']=='') {$errors.= "<br>".ucfirst(_FIRST_NAME).": "._NOT_SPECIFIED.""; $estilofirst=$estiloerror;}
	if ($_POST['Last']=='') {$errors.= "<br>".ucfirst(_LAST_NAME).": "._NOT_SPECIFIED.""; $estilolast=$estiloerror;}
	if ($_POST['City']=='') {$errors.= "<br>".ucfirst(_CITY).": "._NOT_SPECIFIED.""; $estilocity=$estiloerror;}
	if ($_POST['Address']=='') {$errors.= "<br>".ucfirst(_ADDRESS).": "._NOT_SPECIFIED.""; $estiloaddress=$estiloerror;}
	if ($_POST['Phone']=='') {$errors.= "<br>".ucfirst(_PHONE).": "._NOT_SPECIFIED.""; $estilophone=$estiloerror;}
	if ($_POST['password']=='') {$errors.= "<br>".ucfirst(_PASSWORD).": "._NOT_SPECIFIED.""; $estilopassword=$estiloerror;}
	if ($_POST['Email']=='') {$errors.= "<br>".ucfirst(_EMAIL).": "._NOT_SPECIFIED.""; $estiloemail=$estiloerror;}

	if ($_POST['Country']=='230'
	AND ($config[45][1]=='Documento' OR $config[45][1]=='Cedula de identidad')
	AND $_POST['Personalized_5']<>'' ) {
		if (!checkciuy($_POST['Personalized_5'])) {$errors.= "<br>El número de Cédula de Identidad es INCORRECTO"; $estilocedula=$estiloerror;}
	}

	if (antispam('Email',$_POST['Email'])) {$errors.= antispam('Email',$_POST['Email']); $estiloemail=$estiloerror;}
}



if($errors=='' AND $_REQUEST[send]==""._SEND."") {

	if($_POST['reseller']=="on"){$reseller=1;}else{$reseller=0;}
	$query="INSERT INTO hd_clients (clientid,first,last,company,address,city,state,zip,country,phone,email,comments,password,start,personalized_1,personalized_2,personalized_3,personalized_4,personalized_5) ";
	$Company=addslashes($_POST['Company']);
	$Address=addslashes($_POST['Address']);
	$City=addslashes($_POST['City']);
	$First=addslashes($_POST['First']); $First = ucwords(strtolower($First));
	$Last=addslashes($_POST['Last']); $Last = ucwords(strtolower($Last));
	$Email=addslashes($_POST['Email']);
	$Comment=nl2br($_POST['Comment']); $Comment=addslashes($Comment);
	$Phone=addslashes($_POST['Phone']);
	$Zip=addslashes($_POST['Zip']);
	$Fax=addslashes($_POST['Fax']);
	$fechahora = time()+$config[31][1]*3600;
	$password = encrypt($password);
	$ClientID = generate_id('hd_clients','clientid',$config[101][1]);
	$query.="VALUES('$ClientID','$First','$Last','$Company','$Address','$City','$State','$Zip','$Country','$Phone','$Email','$Comment','$password','$fechahora','$Personalized_1','$Personalized_2','$Personalized_3','$Personalized_4','$Personalized_5')";

	if(!mysql_query($query,$db_link)) {
		print(""._CLIENT_NOT_ADDED."");
	}else{
		$newclientid = $ClientID;

		logevent(""._CLIENT." $newclientid "._CREATED."",$newclientid,$_SESSION['hd_idc']);
		go2('tickets.php?clientid='.$newclientid);
	}





}else{





	include("head_template.php");


?>
<script language="javascript" type="text/javascript" src="tiny_mce/tiny_mce.js"></script>
<script language="javascript" type="text/javascript">
tinyMCE.init({
	mode : "textareas",
	theme : "simple"
});
</script>
<?php




echo '
<div class="container">
	<div class="row">
';


print errors($errors); $errors = '';

print("<form action='addclient.php' method='POST'>");


print("<table class='table'><tr><td width='50%' valign='top'>");

print("<table cellspacing='4' cellpadding='2' border='0' width='100%'>");

print("<tr>");
print("<td nowrap><b>".ucfirst(_FIRST_NAME).":</b></td>");
print("<td><input $estilofirst type='text' name='First' size='50' value='".$_POST['First']."'></td>");
print("</tr>");
print("<tr>");
print("<td nowrap><b>".ucfirst(_LAST_NAME).":</b></td>");
print("<td><input $estilolast type='text' name='Last' size='50' value='".$_POST['Last']."'></td>");
print("</tr>");
print("<tr>");
print("<td nowrap>".ucfirst(_COMPANY).":</td>");
print("<td><input $estilocompany type='text' name='Company' size='50' value='".$_POST['Company']."'></td>");
print("</tr>");




print("<tr>");
print("<td nowrap><b>".ucfirst(_COUNTRY).":</b></td>");
print("<td>");
print("<select $estilocountry name='Country' onChange='this.form.submit()'>");
$query="SELECT * FROM hd_countries ORDER BY country";
$countries=mysql_query($query,$db_link);
while($row=mysql_fetch_array($countries)) {
	if ($_POST['Country']) {
		print ("<option value='".$row[id]."' ".sele($_POST['Country'],$row[id]).">".$row[country]." (".$row[countrycode].")</option>");
	}else{
		print ("<option value='".$row[id]."' ".sele($config[54][1],$row[id]).">".$row[country]." (".$row[countrycode].")</option>");
	}
};
print("</select> ");
if ($_POST['Country']) {
	bandera2($_POST['Country']);
}else{
	bandera2($config[54][1]);
}
print("</td>");
print("</tr>");




print("<tr>");
print("<td nowrap><b>".ucfirst(_STATE).":</b></td>");
print("<td>");
print("<select $estilostate name='State'>");
if ($_POST['Country']) {
	$query="SELECT * FROM hd_countries_states WHERE country='".$_POST['Country']."' ORDER BY state";
}else{
	$query="SELECT * FROM hd_countries_states WHERE country='".$config[54][1]."' ORDER BY state";
}
$states=mysql_query($query,$db_link);
while($row=mysql_fetch_array($states)) {
	if ($_POST['State']) {
		print ("<option value='".$row[id]."' ".sele($_POST['State'],$row[id]).">".$row[state]."</option>");
	}else{
		print ("<option value='".$row[id]."'>".$row[state]."</option>");
	}
};
print("</select>");

print("</td>");
print("</tr>");



print("<tr>");
print("<td nowrap><b>".ucfirst(_CITY).":</b></td>");
print("<td><input $estilocity type='text' name='City' size='50' value='".$_POST['City']."'></td>");
print("</tr>");
print("<tr> ");
print("<td nowrap><b>".ucfirst(_ADDRESS).":</b></td>");
print("<td><input $estiloaddress type='text' name='Address' size='50' value='".$_POST['Address']."'></td>");
print("</tr>");


print("<tr> ");
print("<td nowrap>".ucfirst(_ZIP_CODE).":</td>");
print("<td><input type='text' name='Zip' size='15' value='".$_POST['Zip']."'></td>");
print("</tr>");

print("</table>");

print("</td><td valign='top'>");

print("<table cellspacing='4' cellpadding='2' border='0' width='100%'>");



print("<tr>");
print("<td nowrap><b>".ucfirst(_PHONE).":</b></td>");
print("<td><input $estilophone type='text' name='Phone' size='50' value='".$_POST['Phone']."'></td>");
print("</tr>");

print("<tr> ");
print("<td nowrap><b>".ucfirst(_EMAIL)."</b>:</td>");
print("<td><input $estiloemail type='text' name='Email' size='50' value='".$_POST['Email']."'></td>");
print("</tr>");


$pass0=generate_password(0);
print("<tr>");
print("<td nowrap><b>".ucfirst(_PASSWORD).":</b></td>");
print("<td><input $estilopassword type='text' name='password' value = '".$pass0."' size='50'></td>");
print("</tr>");


if ($config[41][1]) {
	print("<tr> ");
	print("<td>". $config[41][1].":</td>");
	print("<td><input type='text' name='Personalized_1' size='50' value='".$_POST['Personalized_1']."'></td>");
	print("</tr>");
}
if ($config[42][1]) {
	print("<tr> ");
	print("<td>". $config[42][1].":</td>");
	print("<td><input type='text' name='Personalized_2' size='50' value='".$_POST['Personalized_2']."'></td>");
	print("</tr>");
}
if ($config[43][1]) {
	print("<tr> ");
	print("<td>". $config[43][1].":</td>");
	print("<td><input type='text' name='Personalized_3' size='50' value='".$_POST['Personalized_3']."'></td>");
	print("</tr>");
}
if ($config[44][1]) {
	print("<tr> ");
	print("<td>". $config[44][1].":</td>");
	print("<td><input type='text' name='Personalized_4' size='50' value='".$_POST['Personalized_4']."'></td>");
	print("</tr>");
}
if ($config[45][1]) {
	print("<tr> ");
	print("<td>". $config[45][1].":</td>");
	print("<td><input $estilocedula type='text' name='Personalized_5' size='50' value='".$_POST['Personalized_5']."'>");
	if ($_POST['Country']=='230'
	AND ($config[45][1]=='Documento' OR $config[45][1]=='Cedula de identidad')
	AND $_POST['Personalized_5']<>'' ) {
		if (checkciuy($_POST['Personalized_5'])) {
			echo " <img class='sprites green_status' src='images/transparent.gif'";
		}else{
			echo " <img class='sprites red_status' src='images/transparent.gif'";
		}
	}
	print("</td>");
	print("</tr>");
}

print("<tr> ");
print("<td nowrap>".ucfirst(_INTERNAL_NOTE).":</td>");
print("<td><textarea name='Comment' rows='5' cols='47'>".$_POST['Comment']."</textarea></td>");
print("</tr>");

print("<tr>");
print("<td><input type='submit' name='send' value='"._SEND."'>&nbsp;&nbsp;&nbsp;");
print("<input type='reset' name='Reset' value='"._RESET."' class='btnformyellow'></td>");
print("</tr>");


print("</table>");

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


print("</form>");


echo '
</div>
</div>
';

include("foot_template.php");
}
?>