$data = JRequest::get('post');
$userTable
= JTable::getInstance('User', 'JTable', $config = array());
$CustomerTable
= $this -> getTable();
$userData
= array();
$params
= JComponentHelper::getParams('com_users');
$useractivation
= $params -> get('useractivation');
jimport('joomla.user.helper');
$salt
= JUserHelper::genRandomPassword(32);
$pswrd
= $data['password'];
$cryptpswrd
= JUserHelper::getCryptedPassword($pswrd, $salt);
$dbpassword
= $cryptpswrd . ':' . $salt;
$date
= date('Y-m-d H:i:s');
if
($data['id'] && $data['customer_id']) {
$userData['id']
= $data['customer_id'];
}
$userData['name']
= $data['first_name'] . ' ' . $data['last_name'];
$userData['username']
= $userData['email'] = $data['email_address'];
if
(!empty($data['password'])) {
$userData['password']
= $dbpassword;
}
$userData['block']
= 0;
$userData['registerDate']
= $date;
if
(empty($data['id']) && empty($data['customer_id']))
{
//
Check if the user needs to activate their account.
if
(($useractivation == 1) || ($useractivation == 2)) {
$userData['activation']
= JApplication::getHash(JUserHelper::genRandomPassword());
$userData['block']
= 1;
}
}
//echo
"<pre>"; print_r($data); print_r($userData); exit ;
//
Inserting Data into Users Table
if
(!$userTable -> bind($userData)) {
$this
-> setError($userTable -> getError());
return
false;
}
//
Check the data.
if
(!$userTable -> check()) {
$this
-> setError($userTable -> getError());
return
false;
}
//
Store the data.
if
(!$userTable -> store()) {
$this
-> setError($userTable -> getError());
return
false;
}
if
(empty($data['id']) && empty($data['customer_id']))
{
$userid
= $userTable -> get('id');
}
else {
$userid
= $data['customer_id'];
}
//
Inserting Data into Users Group Table
if
(empty($data['id'])) {
$sql
= "INSERT INTO `#__user_usergroup_map` (`user_id`,
`group_id`) VALUES('" . $userid . "','2')";
$this
-> _db -> setQuery($sql);
if
(!$this -> _db -> query()) {
JError::raiseError(500,
$this -> _db -> getErrorMsg());
}
}