/** * create() - Create a new user. * * @param string The unix username. * @param string The real firstname. * @param string The real lastname. * @param string The first password. * @param string The confirmation password. * @param string The users email address. * @param string The users preferred default language. * @param string The users preferred default timezone. * @param string The users preference for receiving site updates by email. * @param string The users preference for receiving community updates by email. * @param int The ID of the language preference. * @param string The users preferred timezone. * @param string The users Jabber address. * @param int The users Jabber preference. * @param int The users theme_id. * @param string The users unix_box. * @param string The users address. * @param string The users address part 2. * @param string The users phone. * @param string The users fax. * @param string The users title. * @param char(2) The users ISO country_code. * @param bool Whether to send an email or not * @returns The newly created user ID * */ function create($unix_name, $firstname, $lastname, $password1, $password2, $email, $mail_site, $mail_va, $language_id, $timezone, $jabber_address, $jabber_only, $theme_id, $unix_box = 'shell', $address = '', $address2 = '', $phone = '', $fax = '', $title = '', $ccode = 'US', $send_mail = true) { if (!$theme_id) { $this->setError(_('You must supply a theme')); return false; } if (!$unix_name) { $this->setError(_('You must supply a username')); return false; } if (!$firstname) { $this->setError(_('You must supply a first name')); return false; } if (!$lastname) { $this->setError(_('You must supply a last name')); return false; } if (!$password1) { $this->setError(_('You must supply a password')); return false; } if ($password1 != $password2) { $this->setError(_('Passwords do not match')); return false; } if (!account_pwvalid($password1)) { $this->setError(_('Invalid Password:'******'Invalid Unix Name.')); return false; } if (!validate_email($email)) { $this->setError(_('Invalid Email Address')); return false; } if ($jabber_address && !validate_email($jabber_address)) { $this->setError(_('Invalid Jabber Address')); return false; } if (!$jabber_only) { $jabber_only = 0; } else { $jabber_only = 1; } if (db_numrows(db_query("SELECT user_id FROM users WHERE user_name LIKE '{$unix_name}'")) > 0) { $this->setError(_('That username already exists.')); return false; } if ($GLOBALS['sys_require_unique_email']) { if (db_numrows(db_query("SELECT user_id FROM users WHERE email='{$email}'")) > 0) { $this->setError(_('User with this email already exists - use people search to recover your login.')); return false; } } // if we got this far, it must be good $confirm_hash = substr(md5($password1 . rand() . microtime()), 0, 16); db_begin(); $sql = "INSERT INTO users (user_name,user_pw,unix_pw,realname,firstname,lastname,email,add_date,\n\t\t\tstatus,confirm_hash,mail_siteupdates,mail_va,language,timezone,jabber_address,jabber_only,\n\t\t\tunix_box,address,address2,phone,fax,title,ccode,theme_id) \n\t\t\tVALUES ('{$unix_name}',\n\t\t\t'" . md5($password1) . "',\n\t\t\t'" . account_genunixpw($password1) . "',\n\t\t\t'" . htmlspecialchars($firstname . ' ' . $lastname) . "',\n\t\t\t'" . htmlspecialchars($firstname) . "',\n\t\t\t'" . htmlspecialchars($lastname) . "',\n\t\t\t'{$email}',\n\t\t\t'" . time() . "',\n\t\t\t'P',\n\t\t\t'{$confirm_hash}',\n\t\t\t'" . ($mail_site ? "1" : "0") . "',\n\t\t\t'" . ($mail_va ? "1" : "0") . "',\n\t\t\t'{$language_id}',\n\t\t\t'{$timezone}',\n\t\t\t'{$jabber_address}',\n\t\t\t'{$jabber_only}',\n\t\t\t'{$unix_box}',\n\t\t\t'" . htmlspecialchars($address) . "',\n\t\t\t'" . htmlspecialchars($address2) . "',\n\t\t\t'" . htmlspecialchars($phone) . "',\n\t\t\t'" . htmlspecialchars($fax) . "',\n\t\t\t'" . htmlspecialchars($title) . "',\n\t\t\t'{$ccode}',\n\t\t\t'{$theme_id}')"; $result = db_query($sql); if (!$result) { $this->setError(_('Insert Failed') . db_error() . $sql); db_rollback(); return false; } else { $id = db_insertid($result, 'users', 'user_id'); if (!$id) { $this->setError('Could Not Get USERID: ' . db_error()); db_rollback(); return false; } // send mail if (!$this->fetchData($id)) { db_rollback(); return false; } $hook_params = array(); $hook_params['user'] = $this; $hook_params['user_id'] = $this->getID(); $hook_params['user_name'] = $unix_name; $hook_params['user_password'] = $password1; plugin_hook("user_create", $hook_params); if ($send_mail) { setup_gettext_from_lang_id($language_id); $this->sendRegistrationEmail(); setup_gettext_from_browser(); } db_commit(); return $id; } }
function setup_gettext_for_user($user) { setup_gettext_from_lang_id($user->getLanguage()); }