function addNewUser($arrUserData = array(), $arrGroupIDs = array(), $bForceCreation = false)
{
    global $g_db, $srv_settings;
    if (!isset($arrUserData['user_password'])) {
        $arrUserData['user_password'] = '';
    }
    if (!isset($arrUserData['user_passhash'])) {
        $arrUserData['user_passhash'] = md5($arrUserData['user_password']);
    }
    unset($arrUserData['user_password']);
    if (!isset($arrUserData['user_checkword'])) {
        $arrUserData['user_checkword'] = getAutoPassword(IGT_CHECKWORD_LENGTH);
    }
    if (!isset($arrUserData['user_joindate'])) {
        $arrUserData['user_joindate'] = time();
    }
    if (!isset($arrUserData['user_logindate'])) {
        $arrUserData['user_logindate'] = 0;
    }
    if (!isset($arrUserData['user_address'])) {
        $arrUserData['user_address'] = '';
    }
    if (!isset($arrUserData['user_caddress'])) {
        $arrUserData['user_caddress'] = '';
    }
    if (!isset($arrUserData['user_ufield1'])) {
        $arrUserData['user_ufield1'] = '';
    }
    if (!isset($arrUserData['user_ufield2'])) {
        $arrUserData['user_ufield2'] = '';
    }
    if (!isset($arrUserData['user_ufield3'])) {
        $arrUserData['user_ufield3'] = '';
    }
    if (!isset($arrUserData['user_ufield4'])) {
        $arrUserData['user_ufield4'] = '';
    }
    if (!isset($arrUserData['user_ufield5'])) {
        $arrUserData['user_ufield5'] = '';
    }
    if (!isset($arrUserData['user_ufield6'])) {
        $arrUserData['user_ufield6'] = '';
    }
    if (!isset($arrUserData['user_ufield7'])) {
        $arrUserData['user_ufield7'] = '';
    }
    if (!isset($arrUserData['user_ufield8'])) {
        $arrUserData['user_ufield8'] = '';
    }
    if (!isset($arrUserData['user_ufield9'])) {
        $arrUserData['user_ufield9'] = '';
    }
    if (!isset($arrUserData['user_ufield10'])) {
        $arrUserData['user_ufield10'] = '';
    }
    if (!isset($arrUserData['user_notes'])) {
        $arrUserData['user_notes'] = '';
    }
    $i_names = '';
    $i_values = '';
    foreach ($arrUserData as $name => $value) {
        if (strlen($i_names) > 0) {
            $i_names .= ',';
            $i_values .= ',';
        }
        $i_names .= $name;
        $i_values .= $g_db->qstr($value, get_magic_quotes_gpc());
    }
    if (!$bForceCreation && getConfigItem(CONFIG_reg_username) == CONFIG_CONST_show_require) {
        $i_duplicates = getRecordCount($srv_settings['table_prefix'] . 'users', "username=" . $g_db->qstr($arrUserData['username'], get_magic_quotes_gpc()));
    } else {
        $i_duplicates = 0;
    }
    if ($i_duplicates <= 0) {
        $qry_str = 'INSERT INTO ' . $srv_settings['table_prefix'] . 'users (' . $i_names . ') VALUES (' . $i_values . ')';
        if ($g_db->Execute($qry_str) === false) {
            showDBError('addNewUser', 1);
        }
        $i_id = (int) $g_db->Insert_ID($srv_settings['table_prefix'] . 'users', 'id');
        manageUserGroups(array($i_id), $arrGroupIDs, true);
        return $i_id;
    } else {
        return false;
    }
}
$i_userlastname = '';
$i_userfirstname = '';
$i_isok = false;
$i_rSet1 = $g_db->SelectLimit("SELECT * FROM " . $srv_settings['table_prefix'] . "users WHERE username="******" AND user_enabled=1", 1);
if (!$i_rSet1) {
    showDBError(__FILE__, 1);
} else {
    if (!$i_rSet1->EOF) {
        $i_isok = true;
        $i_useremail = $i_rSet1->fields['email'];
        $i_userfirstname = $i_rSet1->fields['user_firstname'];
        $i_userlastname = $i_rSet1->fields['user_lastname'];
    }
}
if ($i_isok) {
    $i_password = getAutoPassword(IGT_PASSWORD_LENGTH);
    $i_password_hash = md5($i_password);
    $i_password_hash = $g_db->qstr($i_password_hash, 0);
    if ($g_db->Execute("UPDATE " . $srv_settings['table_prefix'] . "users SET user_passhash=" . $i_password_hash . " WHERE username={$f_username} AND user_enabled=1") === false) {
        showDBError(__FILE__, 2);
    }
    $i_isok = $i_isok && ($i_rSet3 = $g_db->SelectLimit("SELECT etemplate_from, etemplate_subject, etemplate_body FROM " . $srv_settings['table_prefix'] . "etemplates WHERE etemplateid=" . SYSTEM_ETEMPLATES_LOSTPASSWORD_INDEX, 1));
    if ($i_isok) {
        $i_isok = $i_isok && !$i_rSet3->EOF;
    }
    if ($i_isok) {
        $i_email_subject = $i_rSet3->fields['etemplate_subject'];
        $i_email_body = $i_rSet3->fields['etemplate_body'];
        if ($i_email_body) {
            $i_email_body = str_replace(ETEMPLATE_TAG_USERNAME, $i_rSet1->fields['username'], $i_email_body);
            $i_email_body = str_replace(ETEMPLATE_TAG_USER_PASSWORD, $i_password, $i_email_body);
$f_testid = (int) readPostVar('testid');
$i_CONFIG_reg_username = getConfigItem(CONFIG_reg_username);
if ($i_CONFIG_reg_username == CONFIG_CONST_show_require) {
    if (!$f_username || strlen($f_username) > 255) {
        $g_vars['page']['errors'] .= $lngstr['page_register']['no_username'];
    }
}
if (getConfigItem(CONFIG_reg_password) == CONFIG_CONST_show_require) {
    if ($f_password != $f_confirmpassword) {
        $g_vars['page']['errors'] .= $lngstr['page_register']['no_password'];
    }
}
if (getConfigItem(CONFIG_reg_password) == CONFIG_CONST_donotshow_autogenerate) {
    $f_password = getAutoPassword(IGT_PASSWORD_LENGTH);
}
$i_checkword = getAutoPassword(IGT_CHECKWORD_LENGTH);
if (getConfigItem(CONFIG_reg_email) == CONFIG_CONST_show_require) {
    if (!$f_email || !strpos($f_email, "@") || !strpos($f_email, ".")) {
        $g_vars['page']['errors'] .= $lngstr['page_register']['no_email'];
    }
}
checkInputField('title', $f_title, getConfigItem(CONFIG_reg_title) == CONFIG_CONST_show_require);
checkInputField('firstname', $f_firstname, getConfigItem(CONFIG_reg_firstname) == CONFIG_CONST_show_require);
checkInputField('lastname', $f_lastname, getConfigItem(CONFIG_reg_lastname) == CONFIG_CONST_show_require);
checkInputField('middlename', $f_middlename, getConfigItem(CONFIG_reg_middlename) == CONFIG_CONST_show_require);
checkInputField('address', $f_address, getConfigItem(CONFIG_reg_address) == CONFIG_CONST_show_require);
checkInputField('city', $f_city, getConfigItem(CONFIG_reg_city) == CONFIG_CONST_show_require);
checkInputField('state', $f_state, getConfigItem(CONFIG_reg_state) == CONFIG_CONST_show_require);
checkInputField('zip', $f_zip, getConfigItem(CONFIG_reg_zip) == CONFIG_CONST_show_require);
checkInputField('country', $f_country, getConfigItem(CONFIG_reg_country) == CONFIG_CONST_show_require);
checkInputField('phone', $f_phone, getConfigItem(CONFIG_reg_phone) == CONFIG_CONST_show_require);