mb_internal_encoding('utf-8');
if($_GET['route'])
die;
$_SERVER['REQUEST_URI'] = str_replace("%AC_full_page=1", "¬_full_page=1", $_SERVER['REQUEST_URI']);
$_GET['ver'] = str_replace("/", "", $_GET['ver']);
if($_GET['dop_brand'] && !$_GET['brand'] && !$_GET['brand_param']) {
$dpb = explode(",", $_GET['dop_brand']);
$_GET['brand_param'] = $dpb[0];
unset($dpb[0]);
$_GET['dop_brand'] = implode(",", $dpb);
}
if($_GET['brand_param'])
$_GET['brand'] = $_GET['brand_param'];
if($_SERVER["HTTP_REAL_IP"])
$_SERVER["REMOTE_ADDR"] = $_SERVER["HTTP_REAL_IP"];
if(!$_GET['page_not_found'])
session_start();
if($_GET['metka']=="yes" || $_GET['list_type']=="neotren"){
$_SESSION['metka_new']=1;
}
if($_GET['gone']==410){
header("HTTP/1.1 410 Gone");
exit();
}
if ($_SERVER["PHP_SELF"]=="/admin.php") {
$G_is_admin = 1;
}
$G_is_stat_sale = 0;
if($_SERVER["REMOTE_ADDR"] == '93.89.208.158'){
//unset($_GET, $_POST);
}
$DebugMode = false;
DEFINE('ROOT_PATH', str_replace('/functions/tools',"", dirname(__FILE__)));
require_once ROOT_PATH.'/vendor/autoload.php';
include(ROOT_PATH."/functions/functions.php");
include(ROOT_PATH."/functions/tools/check_in_stream.php");
// include core files
include(ROOT_PATH."/conf/connect.inc.php");
include(ROOT_PATH."/conf/language_list.php");
include(ROOT_PATH."/functions/cart_functions.php");
include(ROOT_PATH."/functions/category_functions.php");
include(ROOT_PATH."/functions/configurator_functions.php");
include(ROOT_PATH."/functions/country_functions.php");
include(ROOT_PATH."/functions/crypto_functions.php");
include(ROOT_PATH."/functions/currency_functions.php");
include(ROOT_PATH."/functions/custgroup_functions.php");
include(ROOT_PATH."/functions/datetime_functions.php");
include(ROOT_PATH."/functions/discount_functions.php");
include(ROOT_PATH."/functions/discussion_functions.php");
include(ROOT_PATH."/functions/news_functions.php");
include(ROOT_PATH."/functions/option_functions.php");
include(ROOT_PATH."/functions/order_functions.php");
include(ROOT_PATH."/functions/order_status_functions.php");
include(ROOT_PATH."/functions/pages/database/".DBMS.".php");
include(ROOT_PATH."/functions/payment_functions.php");
include(ROOT_PATH."/functions/picture_functions.php");
include(ROOT_PATH."/functions/product_functions.php");
include(ROOT_PATH."/functions/registration_functions.php");
include(ROOT_PATH."/functions/reg_fields_functions.php");
include(ROOT_PATH."/functions/search_function.php");
include(ROOT_PATH."/functions/setting_functions.php");
include(ROOT_PATH."/functions/shipping_functions.php");
include(ROOT_PATH.'/functions/gallery.php');
include(ROOT_PATH."/functions/static_functions.php");
include(ROOT_PATH."/functions/statistic_functions.php");
include(ROOT_PATH."/functions/subscribers_functions.php");
include(ROOT_PATH.'/functions/manager.php');
include(ROOT_PATH.'/functions/voting.php');
include(ROOT_PATH.'/functions/geo_functions.php');
include(ROOT_PATH.'/functions/promotion_functions.php');
include(ROOT_PATH.'/functions/banner_functions.php');
include(ROOT_PATH.'/functions/subdomain_functions.php');
include(ROOT_PATH.'/functions/comparison_functions.php');
include(ROOT_PATH.'/functions/av_functions.php');
include(ROOT_PATH.'/functions/lang_functions.php');
if(mb_substr_count(urldecode($_SERVER['REQUEST_URI']),"°") ||
mb_substr_count(urldecode($_SERVER['REQUEST_URI']),"Ў") ||
mb_substr_count(urldecode($_SERVER['REQUEST_URI']),"Ѓ")
){
go404();
exit();
}
if(!count($_COOKIE) && !$_SERVER['HTTP_REFERER'] && !$_GET['roistat']){
if(!isBot()){
$metrik_off = 1;
}
}
db_connect(DB_HOST,DB_USER,DB_PASS,DB_NAME) or die (db_error());
//db_select_db(DB_NAME) or die (db_error());
if(Env::get("dev_mode") && $_GET['dev_init'] == 1){
DevFill::checkAndFill();
}
if($_GET['pdf']){
if(! $prd = GetSimpleProductFromUrl($_GET['pdf'])) {
go404();
}
$q = db_query("SELECT * FROM ".PRODUCT_FILES." WHERE productID='{$prd['productID']}' LIMIT 1");
if(!$manual = db_fetch_row($q)) {
go404();
}
$path = "./i/product_f/".$manual['filename'];
// Локально файла может не быть — отдаём через /i/product_f/ (прокси на прод)
if (!file_exists($path) || !is_readable($path)) {
header("Location: /i/product_f/".$manual['filename']);
exit();
}
header('Content-Type: application/pdf');
header("Content-Disposition: inline; filename=\"Инструкция {$prd['url']}.pdf\"");
header('Content-Length: ' . filesize($path));
readfile($path);
exit();
}
if($_GET['short']){
$id_s = db_mysql_real_escape_string(trim("Q".$_GET['short']));
if($ln = GetLinkIzShort($id_s)){
Header("HTTP/1.1 301 Moved Permanently");
Header("Location: $ln");
die;
}
}
checkRewriteModule();
// load all categories to arrays to avoid multiple DB queries
$q = db_query("SELECT * FROM " .
CATEGORIES_TABLE . " ORDER BY sort_order, name") or die (db_error());
$cats_key = $cats = $cur_cats = $cat_urls = $catlist = $parent0 = $parents = array();
while ($row = db_fetch_rowo($q)) {
$parent0[$row[categoryID]] = $row[parent];
$cats[$i++] = $row;
$cats_key[$row['categoryID']] = $row;
$cats_urls[$row['cat_url']] = $row;
$catlist[$row['categoryID']] = $row['name_add'];
$cat_urls[$row['categoryID']] = $row['cat_url'];
}
if($_GET['searchstring'] && mb_substr_count($_GET['searchstring'] ,"?")){
$gt = explode("?", $_GET['searchstring']);
$_GET['searchstring'] = $gt[0];
}
if(mb_substr_count($_SERVER['REQUEST_URI'], "?main_url=")){
$ne = explode("?", $_SERVER['REQUEST_URI']);
$ne = $ne[0];
Header("HTTP/1.1 301 Moved Permanently");
Header("Location: $ne");
die;
}
$zzz = db_mysql_real_escape_string($_SERVER['REDIRECT_URL']);
if($r = db_fetch_row(db_query("SELECT * FROM A_redi WHERE old= '$zzz'"))){
$new_url = str_replace($r['old'], $r['new'], $_SERVER['REQUEST_URI']);
if($new_url){
if($_GET['roistat']){
$new_url .= "?roistat=".$_GET['roistat']."&roistat_pos=".$_GET['roistat_pos']."&roistat_referrer=".$_GET['roistat_referrer'];
}
Header("HTTP/1.1 301 Moved Permanently");
Header("Location: $new_url");
die;
}
}
$G_is_search_stat = 0;
CheckSearchStatPage();
RazborURL();
fillDomainInfo();
if(count($subdomain_info) && (defined('IS_ALLOCATED_DOMAIN') && !IS_ALLOCATED_DOMAIN))
ini_set("session.cookie_domain", ".".MAIN_DOMAIN);
/*if($_SERVER["REMOTE_ADDR"] == "83.102.219.80"){
header("HTTP/1.1 503 Service Unavailable");
header("Status: 503 Service Unavailable");
header("Retry-After: 6200");
die;
}*/
//if($_SESSION['manager']['login'] != 'nickki')
// $_SERVER["REMOTE_ADDR"] = '62.105.128.11';
if(isset($_GET['logout']))
{
if ($_SERVER["PHP_SELF"]=="/admin.php")
{
unset($_SESSION["manager"]);
Redirect('/admin.php');
}
else
{
unset($_SESSION["manager"]);
unset($_SESSION["user"]);
Redirect('/');
}
}
MagicQuotesRuntimeSetting();
// init core
define('SMARTY_RESOURCE_CHAR_SET', 'UTF-8');
require ROOT_PATH."/smarty/SmartyBC.class.php";
$smarty = new SmartyBC; //core smarty object
$smarty_mail = new Smarty; //for e-mails
global $smarty_mail;
$_SESSION["user"]["current_language"] = 0; //set default language
include(ROOT_PATH."/functions/languages/".$lang_list[$_SESSION["user"]["current_language"]]->filename);
$G_cur_ver = "EN";
$G_cur_ver_path = "";
if($_GET['ver']=='de'){
$G_cur_ver = "DE";
$G_cur_ver_path = "/de";
}elseif($_GET['ver']=='ru'){
$G_cur_ver = "RU";
$G_cur_ver_path = "/ru";
$smarty->assign("ru", 1);
}
$smarty->assign("ver", $G_cur_ver_path);
$smarty->assign("cu_ver", $G_cur_ver);
$smarty->register_modifier("l","modiferLang");
//isolated domain
checkAndInitAllocatedDomain();
assignVariableDomain();
$common_docher_cats = array();
$common_clear_parents_array = getAllParentCategories(1); //Все дочерние категории, с учетом любого уровня вложенности, БЕЗ дополнительных родительских категорий
include(ROOT_PATH."/functions/tools/exclusive_prolog.php");
settingDefineConstants();
if(!CONF_SHOU){
unset($magaz_geo['spb'][1]);
}
$G_poddomen = GetAllDomains(1);// Собираем все поддомены
checkGeoRedirect();
$url_for_cookie=str_replace('www.', '', $_SERVER['HTTP_HOST']);
$main_domain_level = mb_substr_count(CONF_SHOP_URL, '.');
if(mb_substr_count($url_for_cookie, '.')>$main_domain_level){ // если пользователь зашел на поддомен, куки ему надо назначить на родительский домен
$s = mb_substr_count($url_for_cookie, '.') - $main_domain_level;
for($i=0;$i<$s;$i++){
$url_for_cookie = mb_substr($url_for_cookie, mb_strpos($url_for_cookie, '.')+1, mb_strlen($url_for_cookie));
}
}
define('URL_FOR_COOKIE', $url_for_cookie);
if(function_exists('exclusiveProcessRedirectMobileSites')){
exclusiveProcessRedirectMobileSites();
}
checkRedirectDelStr();
/*--------------------------------------------------------------------------*/
$categoryID = (int)$_GET[categoryID]?(int)$_GET[categoryID]:getCategoryByURL($_GET["CategoryURL"]);
if(isset($_GET['brand'])){
$cur_brand = BrandDecode($_GET['brand']);
$cur_brand_url = BrandEncode($cur_brand);
}
if (isset($_GET["product_url"])){
$pr = prdProductExists($_GET["product_url"], true);
$productID = $pr[0];
$categoryID = $pr[1];
}
if($productID){
$r = db_fetch_row(db_query("SELECT brand FROM ".PRODUCTS_TABLE." WHERE productID=$productID"));
$cur_brand = $r['brand'];
$cur_brand_url = BrandEncode($r['brand']);
}
checkSourceOfOrders();
if ($_SERVER['PHP_SELF']=="/index.php")
{
if (mb_substr_count($_SERVER["REQUEST_URI"], "/?&offset")){
$_SERVER["REQUEST_URI"] = str_replace("/?&offset", "/?offset", $_SERVER["REQUEST_URI"]);
Header("HTTP/1.1 301 Moved Permanently");
Header("Location: {$_SERVER["REQUEST_URI"]}");
}
if ($_SERVER["REQUEST_URI"]=="/index.php" && !count($_POST))
{
Header("HTTP/1.1 301 Moved Permanently");
Header("Location: /");
die;
}
if (isset($_SESSION["user"]["log"])){
$smarty->assign("log", $_SESSION["user"]["log"]);
$ttmp_email = GetEmailSubscriberByID($_SESSION["user"]["customerID"]);
$smarty->assign("log_email", $ttmp_email);
$smarty->assign("email_cri", $ttmp_email);
}
if (isset($_SESSION["manager"]))
$smarty->assign("admin_link", "Администрирование");
$smarty->template_dir = ROOT_PATH."/templates/frontend/".$lang_list[$_SESSION["user"]["current_language"]]->template_path;
if(Env::get("dir_templates")){
$smarty->template_dir = ROOT_PATH.Env::get("dir_templates");
}
$smarty_mail->template_dir = ROOT_PATH."/templates/email";
$request_params = mb_substr($_SERVER['REQUEST_URI'], mb_strpos($_SERVER['REQUEST_URI'], '?'), mb_strlen($_SERVER['REQUEST_URI']));
if ($_SERVER["REQUEST_URI"]=="/" || mb_substr($_SERVER["REQUEST_URI"],0,12)=="/?_openstat=" || $_SERVER["REQUEST_URI"]=="/?not_full_page=1" ||
(!$categoryID && !$productID && str_replace($request_params, '', $_SERVER["REQUEST_URI"])=='/'))
{
$smarty->assign("title", CONF_DEFAULT_TITLE);
$smarty->assign("main_page", '1');
$smarty->assign("main_content_template", "home.tpl.html");
}
if ((int)CONF_SMARTY_FORCE_COMPILE || $_SESSION['manager']['login'] == 'nickki')
{
$smarty->compile_check = true;
}
elseif ((int)CONF_SMARTY_COMPILE_CHECK)
$smarty->compile_check = true;
if ($_SESSION['manager']['login'] == 'nickki'){
$smarty->force_compile = true;
}
}
else
{
//validate data to avoid SQL injections
if (isset($_GET["customerID"])) $_GET["customerID"] = (int)$_GET["customerID"];
if (isset($_GET["settings_groupID"])) $_GET["settings_groupID"] = (int)$_GET["settings_groupID"];
if (isset($_GET["orderID"])) $_GET["orderID"] = (int)$_GET["orderID"];
if (isset($_GET["answer"])) $_GET["answer"] = (int)$_GET["answer"];
if (isset($_GET["productID"])) $_GET["productID"] = (int)$_GET["productID"];
if (isset($_GET["categoryID"])) $_GET["categoryID"] = (int)$_GET["categoryID"];
if (isset($_GET["countryID"])) $_GET["countryID"] = (int)$_GET["countryID"];
if (isset($_GET["delete"])) $_GET["delete"] = (int)$_GET["delete"];
if (isset($_GET["setting_up"])) $_GET["setting_up"] = (int)$_GET["setting_up"];
if (isset($_GET["safemode"])) //show safe mode warning
$smarty->assign("safemode", ADMIN_SAFEMODE_WARNING);
$smarty->assign("admin_main_content_template", "default.tpl.html");
if($_SESSION['manager']['vodit']){
$is_vodit = 1;
$smarty->assign("is_vodit", $is_vodit);
}
$dpt = $_GET["dpt"];
$sub = $_GET["sub"];
$smarty->assign("current_dpt", $dpt);
$smarty->assign("current_sub_dpt", $sub);
$smarty->template_dir = "./templates";
$smarty->force_compile = true;
$smarty_mail->force_compile = true;
}
if($_GET['subdomain'] && $_GET['subdomain']!="m"){
if($G_poddomen[$_GET['subdomain']]){
$smarty->assign("is_poddomen", 1);
$C_pod = $G_poddomen[$_GET['subdomain']];
$kord = explode(",", $C_pod['xy']);
$C_pod['kord_1'] = $kord[0];
$C_pod['kord_2'] = $kord[1];
if($C_pod['page_sbor'] && $C_pod['page_sbor']>0){
$ttt = db_fetch_row(db_query("SELECT aux_page_url FROM A_aux_pages WHERE aux_page_ID='{$C_pod['page_sbor']}'"));
$C_pod['page_sbor_url'] = $ttt[0];
}
if($C_pod['page_garant'] && $C_pod['page_garant']>0){
$ttt = db_fetch_row(db_query("SELECT aux_page_url FROM A_aux_pages WHERE aux_page_ID='{$C_pod['page_garant']}'"));
$C_pod['page_garant_url'] = $ttt[0];
}
if($C_pod['page_dostavka'] && $C_pod['page_dostavka']>0){
$ttt = db_fetch_row(db_query("SELECT aux_page_url FROM A_aux_pages WHERE aux_page_ID='{$C_pod['page_dostavka']}'"));
$C_pod['page_dostavka_url'] = $ttt[0];
}
$smarty->assign("pod_info", $C_pod);
$seo_city[city] = $C_pod[city];
$seo_city[city_po] = $C_pod[cityto];
$seo_city[city_v] = $C_pod[cityv];
$seo_city[city_v2] = $C_pod[cityv];
}
else{
go404();
exit();
}
}else{
$seo_city[city] = "Санкт-Петербург";
$seo_city[city_po] = "Санкт-Петербургу";
$seo_city[city_v] = "Санкт-Петербурге";
$seo_city[city_v2] = "СПб";
}
$smarty->assign("seo_city", $seo_city);
if($_GET['get_super_menu']){
$smarty->assign("su_prds", SuperMenu::getProductsForMenu());
$resp = $smarty->fetch("super_menu.tpl.html");
echo $resp;die;
}
if(intval($_GET['page'])){
$_GET['offset'] = intval($_GET['page']) * CONF_PRODUCTS_PER_PAGE - CONF_PRODUCTS_PER_PAGE;
}
$offset = isset($_GET["offset"]) ? $_GET["offset"] : 0;
if ($offset<0 || $offset % CONF_PRODUCTS_PER_PAGE) $offset = 0;
if($_GET['searchstring'] || $_POST['ajax_search']){
if($_GET['searchstring'])
$_GET['searchstring'] = strip_tags($_GET['searchstring']);
$_GET['searchstring'] = str_replace("'", "", $_GET['searchstring']);
$rep = preg_replace('/[^ a-zа-я0-9ё\-.,\d]/ui', '',$_GET['searchstring'] );
if($rep){
$_GET['searchstring'] = $rep;
}else{
$_GET['searchstring'] = clearstr($_GET['searchstring']);
}
$_GET['searchstring'] = str_replace('"', '', $_GET['searchstring']);
$_POST['ajax_search'] = str_replace("'", "", $_POST['ajax_search']);
$_POST['ajax_search'] = str_replace('"', '', $_POST['ajax_search']);
if($_POST['ajax_search'])
$_POST['ajax_search'] = strip_tags($_POST['ajax_search']);
require_once(ROOT_PATH.'/smarty/phpmorphy/src/common.php');
$dir = 'smarty/phpmorphy/dicts';
$lang = 'ru_RU';
$opts = array('storage' => PHPMORPHY_STORAGE_FILE,);
$morphy = new phpMorphy($dir, $lang, $opts);
}
if($_POST['ajax_search']){
$query = "select * from " . CATEGORIES_TABLE . " WHERE categoryID <> 1 ";
$query .= " order by parent asc, sort_order asc, name asc";
$result = db_query($query);
$C_pod_not_pdd = array();
while ($row = db_fetch_row($result)){
if(($C_pod && $row['not_pdd']) || $row['off']){
$C_pod_not_pdd[] = $row['categoryID'];
foreach($common_clear_parents_array[$row['categoryID']] as $cccid){
$C_pod_not_pdd[] = $cccid;
}
continue;
}
}
ajax_search(trim($_POST['ajax_search']));
}
//$region=get_region();
//$smarty->assign("region", $region);
$global_compare_product = array();
getCookieCompareProducts();
$smarty->assign("request_uri_for_smarty", mb_substr_count($_SERVER['REQUEST_URI'],".html") ? mb_substr($_SERVER['REQUEST_URI'],0,mb_strpos($_SERVER['REQUEST_URI'],".html")+5) : $_SERVER['REQUEST_URI'] );
$smarty->assign("cur_url", $_SERVER['REQUEST_URI']);
if($C_pod && $C_pod['name'] != 'volgograd' && $C_pod['name'] != 'msk' && $_GET['subdomain']!='msk' && $_GET['subdomain']){
$smarty->assign("GGLNOINDEX", 1);
}
$pids_for_human = $pids_brand_for_human = array(); //глобальная переменная для всех продуктов в с текущим выбранным тегом
if(mb_substr_count($_SERVER['HTTP_ACCEPT'], "image/webp")){
$Gwebp = 1;
$smarty->assign("Gwebp", 1);
}
if(mb_substr_count($_SERVER['REQUEST_URI'], "?")){
$tfp = explode("?", $_SERVER['REQUEST_URI']);
if(trim($tfp[1]) !='not_full_page=1')
$smarty->assign("get_check", 1);
}
if($_SESSION["manager"]["login"] || $_COOKIE['is_a_manager']){
ManagerLogGo();
}
$smarty->assign("manager_check", ManagerCheck());
$smarty->assign("metrik_off", $metrik_off);
if($_POST['promo_valid'] && $_POST['promo']){
$promo = trim(mb_strtolower($_POST['promo']));
if($G_promo[$promo]){
echo json_encode(['status' => 'valid', "sale" => $G_promo[$promo]]);die;
}
echo json_encode(['status' => 'not_found']);die;
}
$current_url = htmlspecialchars(strtok("{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}", '?'));
$smarty->assign("current_url", $current_url);
$categoryID = (int)$_GET[categoryID] ? (int)$_GET[categoryID] : getCategoryByURL($_GET["CategoryURL"]);
$i = 0;
if ($categoryID) $cur_cats[] = $categoryID;
$cur_cats = $common_clear_parents_array[$categoryID];
$cur_cats[] = $categoryID;
foreach ($cats_key as $vl) {
if (($C_pod && $vl['not_pdd']) || $vl['off']) {
$C_temp_not_pdd[] = $vl['categoryID'];
foreach ($common_clear_parents_array[$vl['categoryID']] as $cccid) {
$C_temp_not_pdd[] = $cccid;
}
}
}
foreach ($cur_cats as &$cv){
if(in_array($cv, $C_temp_not_pdd))
$cv = 0;
}
$parents = $common_clear_parents_array;
// Заполнение массивов раздачи веса
if($categoryID && $categoryID!=1){
if($matrix = db_fetch_rowo(db_query("SELECT * FROM A_ves WHERE categoryID='$categoryID' AND `type` != 'main' LIMIT 1 "))){
//Получаем все бренды и их настройки
$q = db_query("SELECT * FROM A_ves WHERE matrixID = '{$matrix['matrixID']}' AND categoryID='$categoryID' AND `type` = 'brand' ");
while ($r = db_fetch_row($q)) {
$vesb[$r['name']] = $r;
}
if(count($vesb))
$smarty->assign("vesb", $vesb);
//Получаем все теги и их настройки
$q = db_query("SELECT * FROM A_ves WHERE matrixID = '{$matrix['matrixID']}' AND categoryID='$categoryID' AND `type` = 'tag' ");
while ($r = db_fetch_row($q)) {
$url = db_fetch_rowo(db_query("SELECT url FROM A_products_opt_val_variants WHERE variantID = '{$r['name']}' LIMIT 1"));
$vest[$url['url']] = $r;
}
if(count($vest))
$smarty->assign("vest", $vest);
}
if($G_is_stat_sale && !$cats_key[$categoryID]['stat_sale']){
$new_url = '/'.$cats_key[$categoryID]['cat_url'].'/';
Header("HTTP/1.1 301 Moved Permanently");
Header("Location: {$new_url}?is_spec_cat=1&s_cat=2");
die;
}
}
global $cat_urls;
$smarty->assign("cats", $cats);
$smarty->assign("catlist", $catlist);
$smarty->assign("cat_urls", $cat_urls);
// loading brands
if ($categoryID || $_GET["brand"]) {
$i = 0;
$brands = array();
$cur_cats_list = implode(",", $cur_cats);
if ($cur_cats_list){
$b_cur_cats_list = " OR b.categoryID IN($cur_cats_list)";
$cur_cats_list = " a.categoryID IN($cur_cats_list)";
}
else{
$cur_cats_list = 1;
$b_cur_cats_list = " OR 1";
}
if($categoryID == 260 || $_GET['is_spec_cat']){
$is_spec_cat = 1;
if($categoryID == 260){
$query = "SELECT COUNT(DISTINCT a.productID) as cnt, a.brand, SUM(a.items_sold) as sold FROM " . PRODUCTS_TABLE . " a
WHERE a.enabled='1' AND a.in_stock>0 AND a.in_stock <= 99 AND a.brand!='' AND a.categoryID!=1 AND ( (a.list_price>0 AND a.list_price>Price) OR a.ucenka_price ) GROUP BY a.brand ";
}
else{
$query = "SELECT COUNT(DISTINCT a.productID) as cnt, a.brand, SUM(a.items_sold) as sold FROM " . PRODUCTS_TABLE . " a LEFT JOIN ".CATEGORIY_PRODUCT_TABLE." b ON a.productID = b.productID
WHERE a.enabled='1' AND a.in_stock>0 AND a.in_stock <= 99 AND a.brand!='' AND ( (a.list_price>0 AND a.list_price>Price) OR a.ucenka_price ) AND a.categoryID!=1 AND ({$cur_cats_list} {$b_cur_cats_list}) GROUP BY a.brand ";
}
$q = db_query($query);
while ($row = db_fetch_rowo($q)) {
$br_rows[] = $row;
}
}
else{
$br_rows = GetZapBrandCatlist($categoryID, $cur_cats_list, $b_cur_cats_list);
}
foreach($br_rows as $row) {
$row['brand_url'] = BrandEncode($row['brand']);
if ($_GET[brand] == $row[brand_url] || $_GET["brand"] == $row[brand_url]) {
$row[sel] = 1;
}
if (!mb_substr_count($_SERVER["REQUEST_URI"], "admin.php")) {
$row['full_url'] = '';
//if ($row['absolute_url'] = checkAllocatedContent(0, $row['brand']))
// $row['full_url'] = $row['absolute_url'];
if ($categoryID > 1) {
$cat_substr = '/';
$cat_substr .= $_GET["CategoryURL"] ? $_GET["CategoryURL"] : CONF_CAT_PATH_URL . '/' . $categoryID;
/*if ($_GET['human_param'] && $vest[$_GET['human_param']]['ves']!='get') {
$cat_substr .= HUMAN_PARAM_SEPARATE . $_GET['human_param'];
}*/
$cat_substr .= '/';
$row['full_url'] .= $cat_substr;
} elseif (!$categoryID && !$allocated_brand[$row['brand_url']])
$row['full_url'] .= '/brand/';
if (!$allocated_brand[$row['brand_url']])
$row['full_url'] .= $row['brand_url'] . '/';
}
$brands[$i++] = $row;
}
$brands_lu = $brands;
uasort($brands_lu, "brandlc_sort");
if(count($brands)>9)
foreach($brands as &$_br){
$i=0;
foreach($brands_lu as $v2){
$i++;
if($i>9) break;
if($_br['brand'] == $v2['brand'])
$_br['show_me'] = 1;
}
}
$smarty->assign("brands", $brands);
}
//Дополнение по раздаче веса, настройки в самой категории, работает только если каты нет в одной из матриц
if(!count($vesb)){
if($cats_key[$categoryID]['ves_type']=='get' ){
foreach ($brands as $vb){
$temp = array('val'=>$cats_key[$categoryID]['ves_type'] , 'ves'=>$cats_key[$categoryID]['ves_to'], 'categoryID' => $categoryID,
'name' => $vb['brand']);
$vesb[$vb['brand']] = $temp;
}
}
if(count($vesb))
$smarty->assign("vesb", $vesb);
//Каноникал на таких страницах ипользуется стандартный
$smarty->assign("not_canonikal_ves", 1);
}
function brandlc_sort($a, $b){
if($a['brand'] == 'Orlauf'){
return -1;
}
if($b['brand'] == 'Orlauf'){
return 1;
}
if($b['brand'] == 'Eisberg Fitness'){
return -1;
}
if($a['brand'] == 'Eisberg Fitness'){
return 1;
}
if ($a['sold'] == $b['sold']) {
return 0;
}
return ($a['sold'] > $b['sold']) ? -1 : 1;
}
if($_SERVER[REQUEST_URI][mb_strlen($_SERVER[REQUEST_URI])-1] == '?'){
$_SERVER[REQUEST_URI] = str_replace('?', '', $_SERVER[REQUEST_URI]);
Header("HTTP/1.1 301 Moved Permanently");
Header("Location: https://{$_SERVER[SERVER_NAME]}{$_SERVER[REQUEST_URI]}");
die;
}
if(mb_substr_count($_SERVER['REQUEST_URI'], "//")){
$sri = $_SERVER['REQUEST_URI'];
while(mb_substr_count($sri, "//")){
$sri = str_replace("//", "/", $sri);
}
Header("HTTP/1.1 301 Moved Permanently");
Header("Location: https://{$_SERVER[SERVER_NAME]}{$sri}");
die;
}
if(mb_substr_count($_SERVER['REQUEST_URI'], ".html/")){
$sri = $_SERVER['REQUEST_URI'];
$sri = str_replace(".html/", ".html", $sri);
Header("HTTP/1.1 301 Moved Permanently");
Header("Location: https://{$_SERVER[SERVER_NAME]}{$sri}");
die;
}
if ($_GET[brand])
$brand_c = mb_strtolower(BrandDecode($_GET[brand]));
else
$brand_c = '';
if (!mb_substr_count($_SERVER["REQUEST_URI"], "admin.php") && $_GET[brand] && !$brand_c) {
go404();
$_GET['page_not_found'] = 1;
}
//if (mb_substr_count($brand_c, "children")) $brand_c = "children's place";
$smarty->assign("brand_c", $_GET[brand] ? BrandDecode($_GET[brand]) : '');
if ($brand_c) {
// $tmp=str_replace("_"," ",iconv("UTF-8","CP1251",urldecode($_GET[brand])));
$tmp = BrandDecode($_GET[brand]);
$q = db_query("SELECT brand FROM " . PRODUCTS_TABLE . " WHERE brand='{$tmp}' ORDER BY BINARY brand DESC LIMIT 1");
$row = db_fetch_row($q);
if (!mb_substr_count($_SERVER["REQUEST_URI"], "admin.php") && $row[brand] && !$allocated_brand[str_replace(" ", "_", urldecode(BrandEncode($row[brand])))] && urldecode(BrandEncode($row[brand])) != str_replace(" ", "+", $_GET[brand])) {
if (mb_substr_count($_SERVER["REQUEST_URI"], urlencode(urldecode($_GET[brand]))))
$temp_get_brand = urlencode(urldecode($_GET[brand]));
elseif (mb_substr_count($_SERVER["REQUEST_URI"], rawurlencode(urldecode($_GET[brand]))))
$temp_get_brand = rawurlencode(urldecode($_GET[brand]));
if(str_replace($temp_get_brand, BrandEncode($row[brand]), $_SERVER["REQUEST_URI"]) != $_SERVER["REQUEST_URI"]) {
Header("HTTP/1.1 301 Moved Permanently");
Header("Location: " . str_replace($temp_get_brand, BrandEncode($row[brand]), $_SERVER["REQUEST_URI"]));
die;
}
}
}
if ($_GET[brand]) {
$smarty->assign("brand", BrandDecode($_GET[brand]));
$b_u = $_GET[brand];
$smarty->assign("brand_url", BrandEncode($b_u));
// echo BrandEncode($_GET[brand])."-".$_GET[brand]; die;
// $smarty->xassign("searchstring", $_GET["brand"]);
$smarty->assign("main_content_template", "category.tpl.html");
}
/*if($categoryID==281 && $brand_c && $_GET[brand]){
Header("HTTP/1.1 301 Moved Permanently");
Header("Location: /massaj/massajnye-kresla/{$_GET[brand]}/");
}*/
// checking and setting correct urls
if (isset($_GET["product_url"])) {
$pr = prdProductExists($_GET["product_url"], true);
$productID = $pr[0];
$categoryID = $pr[1];
if (!$productID) {
go404();
$_GET['page_not_found'] = 1;
}/* elseif ($cat_urls[$categoryID] && ($cat_urls[$categoryID] != $_GET['product_category'] ) && !NO_LOCATION_IN_CATLIST) {
//echo "Location: /{$cat_urls[$categoryID]}/" . BrandEncode($pr["brand"]) . "/{$_GET[product_url]}.html";die;
Header("HTTP/1.1 301 Moved Permanently");
Header("Location: {$G_cur_ver_path}/{$cat_urls[$categoryID]}/{$_GET[product_url]}.html");
}*/
} elseif (isset($_GET["CategoryURL"])) {
$categoryID = getCategoryByURL($_GET["CategoryURL"]);
if (!$categoryID) {
go404();
$_GET['page_not_found'] = 1;
/*Header("HTTP/1.1 301 Moved Permanently");
Header("Location: /");
die;*/
}
}
if($_GET['human_param'] && $categoryID && !db_query("SELECT * FROM A_product_options WHERE for_cat='$categoryID'")){
go404();
$_GET['page_not_found'] = 1;
}
elseif($_GET['human_param'] && $categoryID && $brand_c){
$id_tag = TransformStringToDataBase($_GET['human_param']);
if( $r = db_fetch_row(db_query("SELECT * FROM A_del_str WHERE id_str = '{$id_tag}' "))){
$new_url = str_replace($r['url_old'], $r['redirect'], $_SERVER['REQUEST_URI']);
if($new_url){
Header("HTTP/1.1 301 Moved Permanently");
Header("Location: $new_url");
die;
}
}
}
/*Баннеры------------------------------------------------------------------*/
if(defined('BANNER_GROUP_TABLE') && defined('BANNER_PIC_TABLE')){
$banners = getBannersForTemplate();
foreach($banners as $key => $val){
$smarty->assign("banner_group_$key", $val);
}
}
if (mb_substr_count($_SERVER["REQUEST_URI"], "/?offset")){
if (!mb_substr_count($_SERVER["REQUEST_URI"], "&")){
$canonical = mb_substr($_SERVER["REQUEST_URI"], 0, mb_strpos($_SERVER["REQUEST_URI"], "?offset"));
$smarty->assign('canonical', $canonical);
}
}
if (($categoryID || $productID) ){
if(mb_substr_count($_SERVER["REQUEST_URI"], "?")){
$canonical = mb_substr($_SERVER["REQUEST_URI"], 0, mb_strpos($_SERVER["REQUEST_URI"], "?"));
$smarty->assign("yes_get_param", 1);
}
else
$canonical = $_SERVER["REQUEST_URI"];
$smarty->assign('canonical', $canonical);
}
$favor = GetFavor();
$smarty->assign('favor', $favor);
if($C_pod){
uksort($magaz_geo, 'city_sort');
$cur_center = $C_pod['xy'];
}
else{
$cur_center = '59.939099, 30.315877';
}
$smarty->assign("G_poddomen", $G_poddomen);
$temp = $G_poddomen;
$temp = array_sort($temp, 'city', SORT_ASC);
$G_poddomen_alfa['msk'] = $G_poddomen['msk'];
foreach ($temp as $key => $vl){
$G_poddomen_alfa[$key] = $vl;
}
$smarty->assign("G_poddomen_for_cc", $G_poddomen_alfa);
$smarty->assign("cur_center", $cur_center);
$smarty->assign("magaz_geo", $magaz_geo);
$smarty->assign("sity_geo", $sity_geo);
function city_sort($a, $b){
global $C_pod;
$ac = $bc = 0;
if(strcmp($a, $b)<0){
$ac = 1;
}
else{
$bc = 1;
}
if($a == $C_pod['name'])
$ac = 3;
if($b == $C_pod['name'])
$bc = 3;
if ($ac == $bc) {
return 0;
}
return ($ac > $bc) ? -1 : 1;
}
if($_GET['promo']=='korzina'){
setcookie ("promo_korzina", 1, time() + 60*60*24*1000, "/", '.fitnesslook.ru');
$_COOKIE['promo_korzina'] = 1;
}
if(time()>1546030800 && time()<1546894800 && 0){
$smarty->assign("NG_prd", 1);
}
if(time() < 1673185662 && 0){
$smarty->assign("NG_3", 1);
}
//Оценка качества услуг
$nas_uri = $_SERVER['REQUEST_URI'];
if(mb_substr_count($nas_uri, "?")){
$ttp = explode("?", $nas_uri);
$nas_uri = $ttp[0];
}
$nas_uri = $C_pod['name'].TransformStringToDataBase($nas_uri);
if($_GET['add_rate'] && $_GET['ocenka'] ){
if(!$_GET['mng'])
$_GET['ocenka'] = intval($_GET['ocenka']);
else
$_GET['ocenka'] = round($_GET['ocenka'], 1);
if($_GET['ocenka']>5)
$_GET['ocenka'] = 5;
if(!$_SESSION['rate'][$nas_uri] || $_GET['mng']){
$_SESSION['rate'][$nas_uri] = $_GET['ocenka'];
if($cz = db_fetch_row(db_query("SELECT * FROM A_rate WHERE url='{$nas_uri}'"))){
$nr = $cz['rate'] * $cz['count'];
$nr += $_GET['ocenka'];
$nc = $cz['count']+1;
$nr = round($nr/$nc, 1);
if($_GET['mng'] && $_SESSION['manager']['login'] && $_GET['cnt']){
$nr = round($_GET['ocenka'], 1);
$nc = intval($_GET['cnt']);
$set_hand = ", hand=1 ";
}
db_query("UPDATE A_rate SET rate='$nr', `count` = '$nc' $set_hand WHERE id = '{$cz['id']}'");
//echo "UPDATE A_rate SET rate='$nr', `count` = '$nc' WHERE id = '{$cz['id']}'
";
}
else{
$nr = $_GET['ocenka'];
$nc = 1;
if($_GET['mng'] && $_SESSION['manager']['login'] && $_GET['cnt']){
$nr = round($_GET['ocenka'], 1);
$nc = intval($_GET['cnt']);
$set_hand = ", hand=1 ";
}
//echo "INSERT INTO A_rate SET rate='$nr', `count` = '$nc', url='{$nas_uri}'
";
db_query("INSERT INTO A_rate SET rate='$nr', `count` = '$nc', url='{$nas_uri}' $set_hand ");
}
}
}
if($zap = db_fetch_row(db_query("SELECT * FROM A_rate WHERE url='{$nas_uri}'"))){
}
if($categoryID && !$productID){
if($brand_c){
if(!$C_pod){
if(mb_strlen($nas_uri)<22){
$pl_count = mb_strlen($nas_uri);
}else{
$pl_count = mb_strlen($nas_uri) % 23;
}
if($pl_count<4)
$pl_count = 4;
}else{
if(mb_strlen($nas_uri)<10){
$pl_count = mb_strlen($nas_uri);
}else{
$pl_count = mb_strlen($nas_uri) % 11;
}
if($pl_count<2)
$pl_count = 2;
}
}else{
if(!$C_pod){
if(mb_strlen($nas_uri)<31){
$pl_count = mb_strlen($nas_uri);
}else{
$pl_count = mb_strlen($nas_uri) % 32;
}
if($pl_count<6)
$pl_count = 6;
}else{
if(mb_strlen($nas_uri)<20){
$pl_count = mb_strlen($nas_uri);
}else{
$pl_count = mb_strlen($nas_uri) % 21;
}
if($pl_count<3)
$pl_count = 3;
}
}
}else{
if(!$C_pod){
if(mb_strlen($nas_uri)<20){
$pl_count = mb_strlen($nas_uri);
}else{
$pl_count = mb_strlen($nas_uri) % 21;
}
if($pl_count<3)
$pl_count = 3;
}else{
if(mb_strlen($nas_uri)<12){
$pl_count = mb_strlen($nas_uri);
}else{
$pl_count = mb_strlen($nas_uri) % 13;
}
if($pl_count<1)
$pl_count = 1;
}
}
$pl_rate = intval(hexdec(mb_substr(md5($nas_uri),0,10))) % 6;
$pl_rate = 4.5 + $pl_rate/10;
if(!$zap){
$zap['rate'] = $pl_rate;
$zap['count'] = $pl_count;
}else{
if(!$zap['hand']){
$zap['rate'] = round(($zap['count'] * $zap['rate'] + ($pl_rate*$pl_count)) / ($zap['count'] + $pl_count), 1);
$zap['count'] += $pl_count;
}
if($_SESSION['rate'][$nas_uri]) {
$zap['cur_ocenka'] = $_SESSION['rate'][$nas_uri];
}
}
if($_GET['add_rate'] && $_GET['ocenka'] ){
if($productID){
$q = db_query(
"select Author, Body, add_time, DID, Topic, rate FROM ".DISCUSSIONS_TABLE.
" WHERE is_public <> 0 AND productID='$productID' ORDER BY add_time DESC") or die (db_error());
$result = array();
$rate = 0;
while ($row = db_fetch_row($q))
{
$row["rate"] = TransformDataBaseStringToText( str_replace('"', '', $row["rate"]) );
$result[] = $row;
$rate += $row["rate"];
}
if(count($result)){
$zap['rate'] = round(($rate/count($result) + $zap['rate']) / 2, 1);
$zap['count'] += count($result);
}
}
if($zap['rate']<4.4){
$zap['rate'] = 4.4;
}
echo json_encode($zap);die;
}
if($zap['rate']<4.4){
$zap['rate'] = 4.4;
}
$smarty->assign("rate_new", $zap);
$q = db_query("SELECT COUNT(*) as cnt FROM A_products WHERE 1");
$r = db_fetch_rowo($q);
$r['cnt'] = plural($r['cnt'], ' товару', ' товарам', ' товарам');
$smarty->assign("count_all_prd", $r['cnt']);
//$smarty->assign("po_zaprosu", array('Spirit Fitness'));
if($_SESSION['manager']['login'] || $_SESSION['active_yandex_pay'] || $_GET['active_yandex_pay']){
$_SESSION['active_yandex_pay'] = 1;
$active_yandex_pay = 1;
}
$rMonths_for_menu = array(
1=>'январе', 2=>'феврале', 3=>'марте', 4=>'апреле', 5=>'мае', 6=>'июне', 7=>'июле', 8=>'августе', 9=>'сентябре', 10=>'октябре', 11=>'ноябре', 12=>'декабре'
);
$smarty->assign("cur_mounth_e", $rMonths_for_menu[date("n")]);
?>