Пример #1
0
function fn_wishlist_user_init(&$auth, &$user_info, &$first_init)
{
    if ($first_init == true) {
        $user_id = $auth['user_id'];
        $user_type = 'R';
        if (empty($user_id) && fn_get_cookie('cu_id')) {
            $user_id = fn_get_cookie('cu_id');
            $user_type = 'U';
        }
        fn_extract_cart_content($_SESSION['wishlist'], $user_id, 'W', $user_type);
        return true;
    }
    return false;
}
Пример #2
0
// Recover password mode
//
if ($mode == 'recover_password') {
    // Cleanup expired keys
    db_query("DELETE FROM ?:ekeys WHERE ttl > 0 AND ttl < ?i", TIME);
    // FIXME: should be moved to another place
    if (!empty($_REQUEST['ekey'])) {
        $u_id = db_get_field("SELECT object_id FROM ?:ekeys WHERE ekey = ?s AND object_type = 'U' AND ttl > ?i", $_REQUEST['ekey'], TIME);
        if (!empty($u_id)) {
            $udata = db_get_row("SELECT user_id, user_type, tax_exempt, last_login, password_change_timestamp FROM ?:users WHERE user_id = ?i AND status = 'A'", $u_id);
            // Delete this key
            db_query("DELETE FROM ?:ekeys WHERE ekey = ?s", $_REQUEST['ekey']);
            if (!empty($udata)) {
                $auth = fn_fill_auth($udata, isset($auth['order_ids']) ? $auth['order_ids'] : array());
                if (AREA == 'C') {
                    if ($cu_id = fn_get_cookie('cu_id')) {
                        fn_clear_cart($cart);
                        fn_save_cart_content($cart, $cu_id, 'C', 'U');
                        fn_delete_cookies('cu_id');
                    }
                    fn_init_user_session_data($_SESSION, $udata['user_id']);
                }
                fn_set_notification('N', fn_get_lang_var('notice'), fn_get_lang_var('text_change_password'));
                return array(CONTROLLER_STATUS_OK, "profiles.update");
            } else {
                fn_set_notification('E', fn_get_lang_var('error'), fn_get_lang_var('error_account_disabled'));
                return array(CONTROLLER_STATUS_OK, $index_script);
            }
        } else {
            fn_set_notification('E', fn_get_lang_var('error'), fn_get_lang_var('text_ekey_not_valid'));
            return array(CONTROLLER_STATUS_OK, "auth.recover_password");
Пример #3
0
/**
 * Init localizations
 *
 * @param array $params request parameters
 * @return boolean true if localizations exists, false otherwise
 */
function fn_init_localization($params)
{
    $locs = db_get_hash_array("SELECT localization_id, custom_weight_settings, weight_symbol, weight_unit FROM ?:localizations WHERE status = 'A'", 'localization_id');
    if (empty($locs)) {
        return false;
    }
    if (!empty($_REQUEST['lc']) && !empty($locs[$_REQUEST['lc']])) {
        $cart_localization = $_REQUEST['lc'];
    } elseif (($l = fn_get_cookie('cart_localization')) && !empty($locs[$l])) {
        $cart_localization = $l;
    } else {
        $_ip = fn_get_ip(true);
        $_country = fn_get_country_by_ip($_ip['host']);
        $_lngs = db_get_hash_single_array("SELECT lang_code, 1 as 'l' FROM ?:languages WHERE status = 'A'", array('lang_code', 'l'));
        $_language = fn_get_browser_language($_lngs);
        $cart_localization = db_get_field("SELECT localization_id, COUNT(localization_id) as c FROM ?:localization_elements WHERE (element = ?s AND element_type = 'C') OR (element = ?s AND element_type = 'L') GROUP BY localization_id ORDER BY c DESC LIMIT 1", $_country, $_language);
        if (empty($cart_localization) || empty($locs[$cart_localization])) {
            $cart_localization = db_get_field("SELECT localization_id FROM ?:localizations WHERE status = 'A' AND is_default = 'Y'");
        }
    }
    if (empty($cart_localization)) {
        reset($locs);
        $cart_localization = key($locs);
    }
    if ($cart_localization != fn_get_cookie('cart_localization')) {
        fn_set_cookie('cart_localization', $cart_localization, COOKIE_ALIVE_TIME);
    }
    if ($locs[$cart_localization]['custom_weight_settings'] == 'Y') {
        Registry::set('config.localization.weight_symbol', $locs[$cart_localization]['weight_symbol']);
        Registry::set('config.localization.weight_unit', $locs[$cart_localization]['weight_unit']);
    }
    fn_define('CART_LOCALIZATION', $cart_localization);
    return true;
}
Пример #4
0
         if (fn_check_amount_in_stock($v['product_id'], $v['amount'], empty($v['product_options']) ? array() : $v['product_options'], $k, $_is_edp, 0, $cart) == false) {
             unset($cart['products'][$k]);
             return array(CONTROLLER_STATUS_REDIRECT, "checkout.cart");
         }
         $exceptions = fn_get_product_exceptions($v['product_id'], true);
         if (!isset($v['options_type']) || !isset($v['exceptions_type'])) {
             $v = array_merge($v, db_get_row('SELECT options_type, exceptions_type FROM ?:products WHERE product_id = ?i', $v['product_id']));
         }
         if (!fn_is_allowed_options_exceptions($exceptions, $v['product_options'], $v['options_type'], $v['exceptions_type'])) {
             fn_set_notification('E', fn_get_lang_var('notice'), str_replace('[product]', $v['product'], fn_get_lang_var('product_options_forbidden_combination')));
             unset($cart['products'][$k]);
             return array(CONTROLLER_STATUS_REDIRECT, "checkout.cart");
         }
     }
 }
 $_last_order_time = fn_get_cookie('last_order_time');
 /*if (!empty($_last_order_time) && ($_last_order_time + ORDERS_TIMEOUT > TIME)) {
             fn_set_notification('E', fn_get_lang_var('error'), str_replace('[minutes]', round(ORDERS_TIMEOUT / 60, 2), fn_get_lang_var('duplicate_order_warning')));
             if (!empty($auth['order_ids'])) {
                 $_o_ids = $auth['order_ids'];
             }
             $last_order_id = empty($auth['user_id']) ? array_pop($_o_ids) : db_get_field("SELECT order_id FROM ?:orders WHERE user_id = ?i ORDER BY order_id DESC", $auth['user_id']);
 
             return array(CONTROLLER_STATUS_REDIRECT, "orders.details?order_id=$last_order_id");
         }*/
 // Time of placing ordes is saved to avoid duplicate  orders.
 fn_set_cookie('last_order_time', TIME);
 list($order_id, $process_payment) = fn_place_order($cart, $auth);
 if (!empty($order_id)) {
     $view->assign('order_action', fn_get_lang_var('placing_order'));
     $view->display('views/orders/components/placing_order.tpl');
Пример #5
0
function fn_set_partner_cookie($partner_id)
{
    if (headers_sent()) {
        return false;
    }
    if (!empty($partner_id) && fn_get_cookie('partner_id') != $partner_id) {
        $plan_data = fn_get_affiliate_plan_data_by_partner_id($partner_id, true);
        if (!empty($plan_data['cookie_expiration'])) {
            $partner_id_alive_time = $plan_data['cookie_expiration'] * 24 * 3600;
            fn_set_cookie('partner_id', $partner_id, $partner_id_alive_time);
            return true;
        }
    }
    return false;
}
Пример #6
0
function fn_save_cart_content(&$cart, $user_id, $type = 'C', $user_type = 'R')
{
    if (empty($user_id)) {
        if (fn_get_cookie('cu_id')) {
            $user_id = fn_get_cookie('cu_id');
        } else {
            $user_id = fn_crc32(uniqid(TIME));
            fn_set_cookie('cu_id', $user_id, COOKIE_ALIVE_TIME);
        }
        $user_type = 'U';
    }
    if (!empty($user_id)) {
        db_query("DELETE FROM ?:user_session_products WHERE user_id = ?i AND type = ?s AND user_type = ?s", $user_id, $type, $user_type);
        if (!empty($cart['products']) && is_array($cart['products'])) {
            $_cart_prods = $cart['products'];
            foreach ($_cart_prods as $_item_id => $_prod) {
                $_cart_prods[$_item_id]['user_id'] = $user_id;
                $_cart_prods[$_item_id]['timestamp'] = TIME;
                $_cart_prods[$_item_id]['type'] = $type;
                $_cart_prods[$_item_id]['user_type'] = $user_type;
                $_cart_prods[$_item_id]['item_id'] = $_item_id;
                $_cart_prods[$_item_id]['item_type'] = 'P';
                $_cart_prods[$_item_id]['extra'] = serialize($_prod);
                $_cart_prods[$_item_id]['amount'] = empty($_cart_prods[$_item_id]['amount']) ? 1 : $_cart_prods[$_item_id]['amount'];
                $_cart_prods[$_item_id]['session_id'] = Session::get_id();
                if (!empty($_cart_prods[$_item_id])) {
                    db_query('REPLACE INTO ?:user_session_products ?e', $_cart_prods[$_item_id]);
                }
            }
        }
        fn_set_hook('save_cart', $cart, $user_id, $type);
    }
    return true;
}
Пример #7
0
function fn_stat_save_session_data(&$stat_data)
{
    $stat_data['user_agent'] = $_SERVER['HTTP_USER_AGENT'];
    $ip = fn_get_ip(true);
    $stat_data['host_ip'] = $ip['host'];
    $stat_data['proxy_ip'] = $ip['proxy'];
    $stat_data['client_language'] = strtoupper(empty($stat_data['client_language']) ? empty($_SERVER['HTTP_ACCEPT_LANGUAGE']) ? '' : $_SERVER['HTTP_ACCEPT_LANGUAGE'] : $stat_data['client_language']);
    $stat_data['session'] = Session::get_id();
    $stat_data['host_ip'] = $ip['host'];
    $stat_data['proxy_ip'] = $ip['proxy'];
    $stat_data['ip_id'] = fn_stat_ip_exist($ip);
    if (!empty($stat_data['browser'])) {
        $browser_id = db_get_field("SELECT browser_id FROM ?:stat_browsers WHERE browser = ?s AND version = ?s", $stat_data['browser'], $stat_data['browser_version']);
        if (empty($browser_id)) {
            $browser_id = db_query('INSERT INTO ?:stat_browsers ?e', array('browser' => $stat_data['browser'], 'version' => $stat_data['browser_version']));
        }
        $stat_data['browser_id'] = $browser_id;
    }
    $parse_url = parse_url(@$stat_data['referrer']);
    $stat_data['referrer_scheme'] = empty($parse_url['scheme']) ? '' : $parse_url['scheme'];
    $stat_data['referrer_host'] = empty($parse_url['host']) ? '' : $parse_url['host'];
    $search_data = fn_get_search_words(@$stat_data['referrer']);
    if (!empty($search_data['engine'])) {
        //$stat_data['engine'] = $search_data['engine'];
        $engine_id = db_get_field("SELECT engine_id FROM ?:stat_search_engines WHERE engine = ?s", $search_data['engine']);
        if (empty($engine_id)) {
            $engine_id = db_query('INSERT INTO ?:stat_search_engines ?e', array('engine' => $search_data['engine']));
        }
        $stat_data['engine_id'] = empty($engine_id) ? 0 : $engine_id;
    }
    if (!empty($search_data['phrase'])) {
        $phrase_id = db_get_field("SELECT phrase_id FROM ?:stat_search_phrases WHERE phrase = ?s", $search_data['phrase']);
        if (empty($phrase_id)) {
            $phrase_id = db_query('INSERT INTO ?:stat_search_phrases ?e', array('phrase' => $search_data['phrase']));
        }
        $stat_data['phrase_id'] = empty($phrase_id) ? 0 : $phrase_id;
    }
    if (!empty($stat_data['client_language'])) {
        $is_lang = db_get_field("SELECT lang_code FROM ?:stat_languages WHERE lang_code = ?s", $stat_data['client_language']);
        // If there is not long language code in DB then save short language code
        if (empty($is_lang)) {
            $stat_data['client_language'] = substr($stat_data['client_language'], 0, 2);
        }
    }
    $stat_data['expiry'] = TIME + SESSION_ALIVE_TIME;
    $session_data = fn_check_table_fields($stat_data, 'stat_sessions');
    $sess_id = db_query('INSERT INTO ?:stat_sessions ?e', $session_data);
    // Set the cookie 'stat_uniq_code' to identify unique clients.
    $stat_uniq_code = fn_get_cookie('stat_uniq_code');
    if (!empty($sess_id) && (empty($stat_uniq_code) || $stat_uniq_code >= $sess_id)) {
        $stat_uniq_code = $sess_id;
    }
    fn_set_cookie('stat_uniq_code', $stat_uniq_code, 365 * 24 * 3600);
    if (!empty($sess_id)) {
        db_query('UPDATE ?:stat_sessions SET ?u WHERE sess_id = ?i', array('uniq_code' => $stat_uniq_code), $sess_id);
    }
    return $sess_id;
}
Пример #8
0
function fn_init_store_params_by_host(&$request, $area = AREA)
{
    if ($area == 'A' && empty($request['allow_initialization'])) {
        return array(INIT_STATUS_OK);
    }
    $host = $_SERVER['HTTP_HOST'];
    $host = preg_replace('#^www.#i', '', $host);
    $field = defined('HTTPS') ? 'secure_storefront' : 'storefront';
    $companies = db_get_array("SELECT company_id, {$field} FROM ?:companies WHERE {$field} LIKE ?l OR {$field} LIKE ?l", $host . '%', 'www.' . $host . '%');
    if (!empty($companies)) {
        if (count($companies) == 1) {
            $request['switch_company_id'] = $companies[0]['company_id'];
        } else {
            $found_companies = array();
            foreach ($companies as $company) {
                $parsed_url = parse_url('http://' . $company[$field]);
                // protocol prefix does not matter
                if (empty($parsed_url['path'])) {
                    $found_companies[0] = $company['company_id'];
                } elseif (!empty($_SERVER['REQUEST_URI']) && preg_match("/^" . preg_quote($parsed_url['path'], '/') . "([\\/\\?].*?)?\$/", $_SERVER['REQUEST_URI'], $m)) {
                    $priority = count(explode('/', $parsed_url['path']));
                    $found_companies[$priority] = $company['company_id'];
                }
            }
            if (!empty($found_companies)) {
                krsort($found_companies);
                $request['switch_company_id'] = reset($found_companies);
            }
        }
    }
    if (!empty($request['switch_company_id']) && $request['switch_company_id'] != 'all' && !isset($request['skip_config_changing'])) {
        // theme for company with id = 0 cannot be loaded.
        $company_data = db_get_row('SELECT company_id, storefront, secure_storefront, redirect_customer FROM ?:companies WHERE company_id = ?i', $request['switch_company_id']);
        if (empty($company_data)) {
            return array(INIT_STATUS_OK);
        }
        if ($company_data['redirect_customer'] == 'Y' && !fn_get_cookie('storefront_redirect_' . $request['switch_company_id'])) {
            $_ip = fn_get_ip(true);
            $_country = fn_get_country_by_ip($_ip['host']);
            if (!empty($_country)) {
                // Check if found country assigned to some companies
                $redirect = db_get_hash_array('SELECT company_id, storefront FROM ?:companies WHERE FIND_IN_SET(?s, countries_list) LIMIT 1', 'company_id', $_country);
                if (!empty($redirect) && !isset($redirect[$request['switch_company_id']])) {
                    if (!defined('CRAWLER')) {
                        $redirect_url = reset($redirect);
                        $redirect_url = 'http://' . $redirect_url['storefront'];
                        fn_set_cookie('storefront_redirect_' . $request['switch_company_id'], true);
                        return array(INIT_STATUS_REDIRECT, $redirect_url);
                    }
                }
            }
        }
        $config = Registry::get('config');
        $url_data = fn_get_storefront_urls(0, $company_data);
        $config = fn_array_merge($config, $url_data);
        $config['images_path'] = $config['current_path'] . '/media/images/';
        $config['origin_http_location'] = $config['http_location'];
        $config['origin_https_location'] = $config['https_location'];
        Registry::set('config', $config);
    } else {
        return array(INIT_STATUS_FAIL, '', 'No storefronts defined for this domain');
    }
    return array(INIT_STATUS_OK);
}
Пример #9
0
     if ($res = fn_update_user(0, $_REQUEST['user_data'], $_auth, !empty($_REQUEST['ship_to_another']), AREA == 'A' ? !empty($_REQUEST['notify_customer']) : true)) {
         $suffix = 'update';
         list($user_id, $profile_id) = $res;
         // Cleanup user info stored in cart
         if (!empty($_SESSION['cart']) && !empty($_SESSION['cart']['user_data']) && AREA != 'A') {
             unset($_SESSION['cart']['user_data']);
         }
         if (Registry::get('settings.General.user_multiple_profiles') == 'Y') {
             $suffix .= "?profile_id={$profile_id}";
         }
         if (AREA == 'A') {
             $suffix .= "?user_id={$user_id}";
         }
         // Delete anonymous authentication
         if (AREA != 'A') {
             if ($cu_id = fn_get_cookie('cu_id') && !empty($auth['user_id'])) {
                 fn_delete_cookies('cu_id');
             }
         }
     } else {
         $suffix = 'add';
     }
     return array(CONTROLLER_STATUS_OK, "profiles." . $suffix);
 }
 //
 // Update user
 //
 if ($mode == 'update') {
     if (fn_is_restricted_admin($_REQUEST) == true) {
         return array(CONTROLLER_STATUS_DENIED);
     }
Пример #10
0
function fn_init_store_params_by_host(&$request, $area = AREA)
{
    if ($area == 'A' && empty($request['allow_initialization'])) {
        return array(INIT_STATUS_OK);
    }
    $host = $_SERVER['HTTP_HOST'];
    $short_host = preg_replace('/^www[0-9]*\\./i', '', $host);
    $field = defined('HTTPS') ? 'secure_storefront' : 'storefront';
    $conditions = db_quote("{$field} RLIKE ?l", '^(www[0-9]*.)?' . $short_host);
    if (fn_allowed_for('ULTIMATE:FREE')) {
        $company_id = db_get_field("SELECT company_id FROM ?:companies LIMIT 1");
        $conditions .= db_quote(" AND company_id = ?i", $company_id);
    }
    $companies = db_get_array("SELECT company_id, {$field} FROM ?:companies WHERE {$conditions}");
    /**
     * Actions before choosing a company by host
     *
     * @param array $request    Request
     * @param string $area       Area
     * @param string $host       Host
     * @param string $short_host Short Host
     * @param string $field      Field name
     * @param array $companies  Companies list
     */
    fn_set_hook('init_store_params_by_host', $request, $area, $host, $short_host, $field, $companies);
    if (!empty($companies)) {
        if (count($companies) == 1) {
            $request['switch_company_id'] = $companies[0]['company_id'];
        } else {
            $found_companies = array();
            foreach ($companies as $company) {
                $parsed_url = parse_url('http://' . $company[$field]);
                // protocol prefix does not matter
                if (empty($parsed_url['path'])) {
                    $found_companies[0] = $company['company_id'];
                } elseif (!empty($_SERVER['REQUEST_URI']) && preg_match("/^" . preg_quote($parsed_url['path'], '/') . "([\\/\\?].*?)?\$/", $_SERVER['REQUEST_URI'], $m)) {
                    $priority = count(explode('/', $parsed_url['path']));
                    $found_companies[$priority] = $company['company_id'];
                }
            }
            if (!empty($found_companies)) {
                krsort($found_companies);
                $request['switch_company_id'] = reset($found_companies);
            }
        }
    }
    if (!empty($request['switch_company_id']) && $request['switch_company_id'] != 'all' && !isset($request['skip_config_changing'])) {
        // theme for company with id = 0 cannot be loaded.
        $company_data = db_get_row('SELECT company_id, storefront, secure_storefront, redirect_customer FROM ?:companies WHERE company_id = ?i', $request['switch_company_id']);
        if (empty($company_data)) {
            return array(INIT_STATUS_OK);
        }
        if ($company_data['redirect_customer'] == 'Y' && !fn_get_cookie('storefront_redirect_' . $request['switch_company_id'])) {
            $_ip = fn_get_ip(true);
            $_country = fn_get_country_by_ip($_ip['host']);
            if (!empty($_country)) {
                // Check if found country assigned to some companies
                $redirect = db_get_hash_array('SELECT company_id, storefront FROM ?:companies WHERE FIND_IN_SET(?s, countries_list) LIMIT 1', 'company_id', $_country);
                if (!empty($redirect) && !isset($redirect[$request['switch_company_id']])) {
                    if (!defined('CRAWLER')) {
                        $redirect_url = reset($redirect);
                        $redirect_url = 'http://' . $redirect_url['storefront'];
                        fn_set_cookie('storefront_redirect_' . $request['switch_company_id'], true);
                        return array(INIT_STATUS_REDIRECT, $redirect_url);
                    }
                }
            }
        }
        $config = Registry::get('config');
        $url_data = fn_get_storefront_urls(0, $company_data);
        $config = fn_array_merge($config, $url_data);
        $config['images_path'] = $config['current_path'] . '/media/images/';
        $config['origin_http_location'] = $config['http_location'];
        $config['origin_https_location'] = $config['https_location'];
        Registry::set('config', $config);
        $status = INIT_STATUS_OK;
        $message = '';
    } else {
        $status = INIT_STATUS_FAIL;
        $message = 'No storefronts defined for this domain';
    }
    /**
     * Actions after choosing a company by host
     *
     * @param array $request Request
     * @param string $area    Area
     * @param array $config  Config
     * @param string $status  Status
     * @param string $message Message text
     */
    fn_set_hook('init_store_params_by_host_post', $request, $area, $config, $status, $message);
    return array($status, '', $message);
}