global $top_message;
// Anonymous user auth
if (AREA_TYPE == 'C' && $mode == 'add' && $config['General']['anonymous_allowed'] == 'Y' && isset($request_prepared['is_anonymous']) && $request_prepared['is_anonymous'] == 1) {
    $is_anonymous = $request_prepared['is_anonymous'];
    $real_email = $anonymous_email = $update_fields['basic']['email'];
    $anonymous_email = str_replace("@", "-at-", $anonymous_email);
    $pref = constant('ANONYMOUS_USERNAME_PREFIX');
    $re_pref = str_replace('.', '\\.', $pref);
    $next = intval(cw_query_first_cell("\n\t\tselect SUBSTRING_INDEX(SUBSTRING(email from LENGTH('{$pref}-')+1),'-',1) as num\n\t\tfrom {$tables['customers']} where email rlike '{$re_pref}-[0-9]+-mailto-.*-at-.*@' order by customer_id desc limit 1"));
    $host = $app_config_file['web']['http_host'];
    if (!preg_match("'[a-z\\_\\-.]+\\.[a-z]{2,6}'", $host)) {
        $host .= '.local';
    }
    $anonymous_email = $pref . '-' . ++$next . '-mailto-' . $anonymous_email . '@' . $host;
    $update_fields['basic']['email'] = $anonymous_email;
    $update_fields['basic']['password2'] = $update_fields['basic']['password'] = cw_user_generate_password();
    $smarty->assign('is_anonymous', $is_anonymous);
    $smarty->assign('real_email', $real_email);
}
$display_antibot = false;
$search =& cw_session_register('search', array());
$smarty->assign('purchased_products', isset($search['purchased_products']) ? $search['purchased_products'] : array());
/*
 * require $app_main_dir.'/include/users/register.php'; {
 */
$fill_error =& cw_session_register('fill_error', array());
$filled_profile =& cw_session_register('filled_profile', array());
$fields_area = cw_profile_fields_get_area($user, $salesman_membership, $self_modification, AREA_TYPE == 'A' ? $usertype : null);
list($profile_sections, $profile_fields, $additional_fields) = cw_profile_fields_get_sections('U', true, $fields_area);
$userphoto = array();
if ($user) {
function cw_user_create_profile($fields)
{
    global $tables, $customer_id, $current_language;
    cw_load('crypt');
    // Defaults
    // password
    if (empty($fields['password'])) {
        $fields['password'] = cw_user_generate_password();
    }
    // membership
    if (empty($fields['membership_id'])) {
        $fields['membership_id'] = cw_query_first_cell("select membership_id from {$tables['memberships']} where default_membership='Y' and area='{$usertype}' ");
    }
    // usertype
    if (empty($fields['usertype'])) {
        $fields['usertype'] = 'C';
    }
    // status
    if (empty($fields['status'])) {
        $fields['status'] = 'Y';
    }
    // language
    if (empty($fields['language'])) {
        $fields['language'] = $current_language;
    }
    // Create profile
    $profile_create = array('password' => cw_call('cw_user_get_hashed_password', array($fields['password'])), 'email' => $fields['email'], 'membership_id' => $fields['membership_id'], 'status' => $fields['status'], 'usertype' => $fields['usertype']);
    $user = cw_array2insert('customers', $profile_create);
    $customers_customer_info = array('customer_id' => $user, 'web_user' => 1);
    cw_array2insert('customers_customer_info', $customers_customer_info);
    if (empty($customer_id)) {
        $customer_id = $user;
    }
    $customer_system_info = array('customer_id' => $customer_id, 'creation_customer_id' => $user, 'creation_date' => cw_core_get_time());
    cw_array2insert('customers_system_info', $customer_system_info, true);
    cw_array2insert('customers_settings', array('customer_id' => $user), true);
    return $user;
}
            continue;
        }
        $reset_key = $reset_keys[0];
        $smarty->assign('reset_url', $reset_url = cw_call('cw_core_get_html_page_url', array(array('var' => 'help', 'section' => 'reset_password', 'reset_key' => $reset_key, 'email' => urlencode($email), 'delimiter' => '&'))));
        //cw_log_add("password_reset_url", $reset_url);
        cw_call('cw_send_mail', array($config['Company']['support_department'], $email, "mail/password_recover_confirm_subj.tpl", "mail/password_recover_confirm.tpl"));
    }
    $top_message = array('content' => cw_get_langvar_by_name('txt_password_recovery_email_confirmation_sent'), 'type' => 'I');
    cw_header_location(cw_call('cw_core_get_html_page_url', array(array('var' => 'help', 'section' => 'password', 'email' => urlencode($email), 'delimiter' => '&'))));
}
if ($REQUEST_METHOD == "GET" && $section == "reset_password" && !empty($reset_key) && !empty($email)) {
    $reset_key = preg_replace("/[^A-Za-z0-9\\s\\s+]/", '', substr($reset_key, 0, 32));
    $email = urldecode($email);
    $account = cw_query_first("SELECT customer_id, password, usertype, email FROM {$tables['customers']} WHERE email='{$email}' and password like '{$reset_key}:%' AND status='Y'");
    if (!empty($account)) {
        $account['password'] = cw_user_generate_password();
        cw_array2update('customers', array('password' => cw_call('cw_user_get_hashed_password', array($account['password']))), "customer_id = '{$account['customer_id']}'");
        $smarty->assign('accounts', array($account));
        cw_call('cw_send_mail', array($config['Company']['support_department'], $email, "mail/password_recover_subj.tpl", "mail/password_recover.tpl"));
        $top_message = array('content' => cw_get_langvar_by_name('txt_password_recover_message'), 'type' => 'I');
    } else {
        $top_message = array('content' => cw_get_langvar_by_name('txt_password_recover_expired_key'), 'type' => 'E');
    }
    cw_header_location(cw_call('cw_core_get_html_page_url', array(array('var' => 'help', 'section' => 'password', 'email' => urlencode($email), 'delimiter' => '&'))));
}
if ($popup_title) {
    $smarty->assign('popup_title', $popup_title);
}
if (!empty($section) && $section != 'general') {
    $location[] = array(cw_get_langvar_by_name('lbl_help_zone'), 'index.php?target=help');
    $location[] = array(cw_get_langvar_by_name('lbl_help_section_' . $section), '');