<?php
include_once ("../include/auth.inc.php");
include_once ("../include/global.inc.php");


getSecHttpVars("1", array("usrType", "usrFirstname", "usrName", "usrAccount", "usrPassword", "usrEmail"));
// echo "alert(\"" . str_replace('"', "'", $ret_value) . "\");";

$ret_value = "fail";

$usrType = trim($usrType);
$usrFirstname = trim($usrFirstname);
$usrName = trim($usrName);
$usrEmail = trim($usrEmail);
$usrAccount = trim($usrAccount);
$usrPassword = trim($usrPassword);

if ($usrType != "" && is_numeric($usrType) && $usrFirstname != "" && $usrName != "" && $usrEmail != "" && $usrAccount != "" && $usrPassword != "") :	 
$ret_value = "X1";
	 // Check existence of account
	 if (getFieldValueFromId("user","usr_account", $usrAccount,"usr_id") == "") :
$ret_value = "X2";
      // Insert user
      $sqlStmtPwd = "INSERT INTO user (hq_id,usr_type,usr_name,usr_firstname,usr_email,usr_inv_email,usr_phone,usr_phone2,usr_fax,usr_account,usr_password,usr_birthdate)" .
                        " VALUES ('$hq_id','$usrType','$usrName','$usrFirstname','$usrEmail,'','$usrPhone','$usrPhone2','$usrFax','$usrAccount',PASSWORD('$usrPassword'),'$usrBirthdate')";
      // writeDbLog($sqlStmtPwd);
      $res = $db->query($sqlStmtPwd);
      if (DB::isError($res)) : die ("$PHP_SELF: " . $res->getMessage()); endif;                                     
      $usr_id_new = getLastInsertID(); 
	    if ($usr_id_new != "" && is_numeric($usr_id_new)) :
	       $ret_value = "ok";
	    endif;
	 endif;

  echo "retValue = '" . $ret_value . "';\n";
endif;


?>
