function cw_user_get_info($customer_id, $info_type = 0)
{
    global $tables, $current_language, $default_user_profile_fields, $config;
    global $addons;
    $userinfo = \Customer\get($customer_id);
    if (empty($userinfo)) {
        return null;
    }
    $userinfo = array_merge($userinfo, (array) cw_query_first("SELECT membership, flag FROM {$tables['memberships']} WHERE membership_id = '{$userinfo['membership_id']}'"));
    # kornev, TOFIX
    if ($userinfo['usertype'] == 'B') {
        $userinfo['plan_id'] = cw_query_first_cell("SELECT plan_id FROM {$tables['salesman_commissions']} WHERE salesman_customer_id='{$userinfo['customer_id']}'");
    }
    if ($info_type & 1) {
        $userinfo['addresses'] = cw_user_get_addresses($customer_id);
        $userinfo['main_address'] = cw_user_get_address($customer_id, 'main');
        $userinfo['current_address'] = cw_user_get_address($customer_id, 'current');
        $address = empty($userinfo['main_address']) ? $userinfo['current_address'] : $userinfo['main_address'];
        $userinfo['firstname'] = $address['firstname'];
        $userinfo['lastname'] = $address['lastname'];
        $userinfo['fullname'] = trim($address['firstname'] . ' ' . $address['lastname']);
        unset($address);
    }
    if ($info_type & 2) {
        cw_load('crypt');
        // For security reason password must be left encrypted in userinfo data
        /*
        	$userinfo['password'] = text_decrypt($userinfo['password']);
        	if (is_null($userinfo['password']))
        	    cw_log_flag("log_decrypt_errors", "DECRYPT", "Could not decrypt password for the user ".$userinfo['customer_id'], true);
        	elseif ($userinfo['password'] !== false)
        	    $userinfo['password'] = stripslashes($userinfo['password']);
        */
    }
    if ($info_type & 4) {
        $userinfo['cc_info'] = cw_user_get_current_ccinfo($customer_id);
    }
    if ($info_type & 8) {
        cw_load('profile_fields');
        $userinfo['additional_fields'] = cw_profile_fields_get_additional($customer_id);
    }
    if ($info_type & 16) {
        if ($userinfo['usertype'] == 'B') {
            $userinfo['salesman_info'] = cw_get_salesman_info($customer_id);
        }
    }
    if ($info_type & 32) {
        $userinfo['system_info'] = cw_user_get_system_info($customer_id);
    }
    if ($info_type & 64) {
        $userinfo['additional_info'] = cw_user_get_addition_info($customer_id, $userinfo['usertype']);
        $userinfo['relations'] = cw_user_get_relations($customer_id);
    }
    if ($info_type & 256) {
        $userinfo['addresses'] = cw_user_get_addresses($customer_id);
    }
    if ($info_type & 1024) {
        $userinfo['custom_fields'] = cw_user_get_custom_fields($customer_id);
    }
    return $userinfo;
}
        $address = cw_user_get_address($user, $address_id);
    }
    $smarty->assign('address', $address);
    $smarty->assign('address_id', $address_id);
    //    $smarty->assign('is_main', $is_main);
    $smarty->assign('name_prefix', 'update_fields[address][' . (in_array($address_type, array('main', 'current'), true) ? $address_type : $address_id) . ']');
    cw_add_ajax_block(array('id' => in_array($address_type, array('main', 'current'), true) ? $address_type . '_address' : 'address', 'action' => 'update', 'template' => 'main/users/sections/address_modify.tpl'), $address_type . '_address');
}
if ($action == 'set_main' || $action == 'set_current') {
    $field = $action == 'set_main' ? 'main' : 'current';
    Customer\Address\setAddressType($user, $field, $address_id);
    cw_user_check_addresses($user);
    // For correct shipping cost calculate after address changing
    cw_load('user');
    $user_address =& cw_session_register('user_address');
    $user_address = array();
    global $userinfo;
    $userinfo['current_address'] = cw_user_get_address_by_type('current');
    cw_add_top_message('Address has been updated');
}
$smarty->assign('address_type', $address_type);
$smarty->assign('user', $user);
if (defined('IS_AJAX')) {
    if ($user) {
        $addresses = cw_user_get_addresses(intval($user));
    }
    $smarty->assign('addresses', $addresses);
    cw_add_ajax_block(array('id' => 'address_book', 'action' => 'replace', 'template' => 'main/users/address_book.tpl'), 'address_book');
} else {
    cw_header_location("index.php?target={$target}&user={$user}");
}