<?
require_once("const.php");
// modify $form["fields"] => optional/reqired fields, added by niotech
if($USER_PROFILE_FIELDS["company"]==1){ $form["fields"]["company"]=array("type"=>"text","description"=>"Company Name","error"=>"Enter Company Name"); }
if($USER_PROFILE_FIELDS["address1"]==1){ $form["fields"]["address1"]=array("type"=>"text","description"=>"Address 1","error"=>"Enter Address 1"); }
if($USER_PROFILE_FIELDS["address2"]==1){ $form["fields"]["address2"]=array("type"=>"text","description"=>"Address 2","error"=>"Enter Address 2"); }
if($USER_PROFILE_FIELDS["city"]==1){ $form["fields"]["city"]=array("type"=>"text","description"=>"City","error"=>"Enter City"); }
if($USER_PROFILE_FIELDS["state"]==1){ $form["fields"]["state"]=array("type"=>"text","description"=>"State","error"=>"Enter State"); }
if($USER_PROFILE_FIELDS["postcode"]==1){ $form["fields"]["postcode"]=array("type"=>"text","description"=>"Postcode","error"=>"Enter Postcode"); }
if($USER_PROFILE_FIELDS["country"]==1){ $form["fields"]["country"]=array("type"=>"text","description"=>"Country","error"=>"Enter Country"); }
if($USER_PROFILE_FIELDS["telephone"]==1){ $form["fields"]["telephone"]=array("type"=>"text","description"=>"Phone","error"=>"Enter Phone Number"); }
$smarty->assign("action", $lang['add_user']);
$form["submit"]=$lang['add'];
if($_SERVER["REQUEST_METHOD"]==$form["method"])
{
$userform->load($form["fields"], $_POST);
$form["errorcount"]=$userform->check($form["fields"]);
if($form["errorcount"]==0)
{
$SQL="SELECT COUNT(*) AS `cnt` FROM `".DB_PREFIX."users`";
$SQL.=" WHERE `login`='".AddSlashes(trim($form["fields"]["login"]["value"]))."'";
if(!$mysql->query($SQL) || $mysql->num<=0)
{
exit($mysql->error);
}
if(intval($mysql->field("cnt"))>0)
{
$form["errorcount"]=1;
$form["message"]=$lang['login_exist'];
}else
{
$SQL="INSERT INTO `".DB_PREFIX."users` SET ".$userform->sql($form["fields"]);
if(!$mysql->query($SQL))
{
exit($mysql->error);
}
Header("Location:index.php");
exit();
}
}
}
$smarty->assign("form", $form);
$smarty->display("control/form.tpl");
?>