<?php
//=================================================================
// KOOBI R7 - CMS - PORTALSOFTWARE(c) DREAM4(r) 
// HTTP://WWW.DREAM4.DE
//=================================================================
// ACHTUNG!
// DIESER PROGRAMMCODE IST URHERRECHTLICH GESCHUETZT
// DIE URHEBERRECHTE LIEGEN BEI DEN JEWEILIGEN AUTOREN.
// AENDERUNGEN IN DIESER DATEI ERFOLGEN AUF EIGENE GEFAHR!
// ES IST NICHT GESTATTET, DEN COPYRIGHTHINWEIS ZU AENDERN ODER ZU
// ENTFERNEN. NUR WENN SIE EINE COPYRIGHTHINWEIS-ENTFERNUNG BESTELLT
// HABEN, DUERFEN SIE DIESEN ENTFERNEN.
//================================================================
// BEI FRAGEN WENDEN SIE SICH BITTE AN: KONTAKT@DREAM4.DE
//=================================================================
if(!defined('START_PATH')) exit;

$ShopInit = $GLOBALS['db']->RowQuery("SELECT 
	Start_Limit,
	ShopLand,
	RechnungsLogo,
	ShopAdresse,
	Bestand_Zaehlen,
	VersandInfo_Footer,
	Topseller_Limit,
	Angebote_Limit,
	Spalten_Neueste,
	Spalten_Topseller,
	Spalten_Angebote,
	Produkt_Limit_Seite,
	Topseller_Navi_Limit,
	Zubehoer_Limit,
	Lager_Gering,
	Tab_Limit,
	Prodtext_Laenge,
	Versandfreibetrag,
	NettoKlein 
FROM " . PREFIX . "_shop_einstellungen");

$Shop = new Shop;
$Shop->_start_limit        = ($ShopInit->Start_Limit<2) ? 2 : $ShopInit->Start_Limit;
$Shop->_offer_limit        = ($ShopInit->Angebote_Limit<2) ? 2 : $ShopInit->Angebote_Limit;
$Shop->_topseller_limit    = ($ShopInit->Topseller_Limit<2) ? 2 : $ShopInit->Topseller_Limit;
$Shop->_newest_colums      = ($ShopInit->Spalten_Neueste<2) ? 2 : $ShopInit->Spalten_Neueste;
$Shop->_topseller_colums   = ($ShopInit->Spalten_Topseller<2) ? 2 : $ShopInit->Spalten_Topseller;
$Shop->_colums_offers      = ($ShopInit->Spalten_Angebote<2) ? 2 : $ShopInit->Spalten_Angebote;
$Shop->_small_navi_limit   = ($ShopInit->Topseller_Navi_Limit>25) ? 25 : $ShopInit->Topseller_Navi_Limit;     // Limit fuer Topseller- und/oder Schnaeppchen Navigation
$Shop->_limit              = $ShopInit->Produkt_Limit_Seite;                // Limit der Produkte in Shop-Kategorien
$Shop->_similar_limit      = $ShopInit->Zubehoer_Limit;
$Shop->_accessories_limit  = $ShopInit->Zubehoer_Limit;
$Shop->_low_amount         = $ShopInit->Lager_Gering;       // Ab welchem Lagerbestand warnen?
$Shop->_browse_tab_limit   = $ShopInit->Tab_Limit;
$Shop->_maxlength_prodtext = $ShopInit->Prodtext_Laenge;
$Shop->deZip               = 5;
$Shop->chZip               = 4;
$Shop->atZip               = 4;
$Shop->frZip               = 5;
$Shop->itZip               = 5;
$Shop->_colums             = 1;              
$db_c                      = 'WaehrungSymbol_1';

$a = array();
$GLOBALS['tmpl']->assign('navi_current', $Shop->get_starter_shopcateg($_REQUEST['cid'],'',$a));

$categs_shop = array();
$inarray = array();
$shop_categs = $Shop->MyShopNavi(0,$categs_shop,@$_REQUEST['cid'],$inarray);

//=================================================================
// Ist Benutzer FSK18-Benutzer?
//=================================================================
$fsk18 = $GLOBALS['db']->RowQuery("SELECT Fsk18 FROM " . PREFIX . "_benutzer WHERE Id = '".abs((int)$_SESSION['benutzer_id'])."'");
$is_fsk18_user = (is_object($fsk18) && $fsk18->Fsk18==1) ? 1 : 0;
define('FSK_USER', $is_fsk18_user);

$GLOBALS['tmpl']->assign('fsk_user', FSK_USER);
$GLOBALS['tmpl']->assign('MyShopNavi', $shop_categs);
$GLOBALS['tmpl']->assign('MySearchCategs', $shop_categs);
$GLOBALS['tmpl']->assign('ShopInfoPanel', $Shop->getInfoPanel());


//=================================================================
// Generelle Shopeinstellungen
//=================================================================
$sql_payments = $GLOBALS['db']->Query("SELECT Id FROM " . PREFIX . "_shop_zahlungsmethoden WHERE Aktiv = '1'");
while($row_payments = $sql_payments->fetchrow())
{
	$GLOBALS['tmpl']->assign('payment_' . $row_payments->Id, 1);
}

$shop_settings_detail = $GLOBALS['db']->RowQuery("SELECT * FROM " . PREFIX . "_shop_einstellungen");

define('VERSAND_FREIBETRAG', $shop_settings_detail->Versandfreibetrag);
define('BEST_MAX', $shop_settings_detail->BestMax);
define('BEST_MIN', $shop_settings_detail->BestMin);
define('NETTO_SHOP', $shop_settings_detail->NettoPreise);
define('GUEST_ORDER', $shop_settings_detail->Gastbestellung);

$GLOBALS['shopsettings'] = $shop_settings_detail;
$GLOBALS['tmpl']->assign('shopsettings', $shop_settings_detail);
$GLOBALS['tmpl']->assign('versand_freibetrag', $shop_settings_detail->Versandfreibetrag);
$GLOBALS['tmpl']->assign('shop_settings', $shop_settings_detail);
$GLOBALS['tmpl']->assign('best_max', BEST_MAX);
$GLOBALS['tmpl']->assign('best_min', BEST_MIN);
$GLOBALS['tmpl']->assign('shop_land', strtoupper($shop_settings_detail->ShopLand));

if($shop_settings_detail->Gutscheine==1)
{
	$GLOBALS['tmpl']->assign('shop_coupons',1);
	define('SHOP_COUPONS', 1);
} else {
	define('SHOP_COUPONS', 0);
}

//=================================================================
//=================================================================
$GLOBALS['tmpl']->assign('curr_change', ($shop_settings_detail->MultiWaehrung==1) ? 1 : 0);
$GLOBALS['tmpl']->assign('is_shop', 1);

if((isset($_REQUEST['subaction']) && !empty($_REQUEST['subaction'])) || (isset($_REQUEST['action'])))
{
	if(@$_REQUEST['action']=='showbasket' || @$_REQUEST['subaction']=='step2' || @$_REQUEST['subaction']=='step3' || @$_REQUEST['subaction']=='step4') $_SESSION['currency'] = 1;
}


if((isset($_SESSION['currency']) && !empty($_SESSION['currency'])) && !@$_REQUEST['currency'])
{
	#echo $_REQUEST['currency'];
	#exit;
	$currency = ereg_replace('([^0-9])', '', $_SESSION['currency']);
	$row_c = $GLOBALS['db']->ArrQuery("SELECT MultiWaehrung, WaehrungSymbol_$currency, Multiplikator_$currency FROM " . PREFIX . "_shop_einstellungen");
	if(is_array($row_c) && $row_c['MultiWaehrung'] == 1 && $row_c['WaehrungSymbol_' . $currency] != '')
	{
		$db_c = 'WaehrungSymbol_' . $currency;
		$_SESSION['Multiplikator'] = $row_c['Multiplikator_' . $currency];
		$curr = $GLOBALS['db']->ArrQuery("SELECT Waehrung_{$currency} FROM " . PREFIX . "_shop_einstellungen");
		$_SESSION['currency_registered'] = $curr['Waehrung_' . $currency];
	} else {
	
		$db_c = 'WaehrungSymbol_1';
		$_SESSION['Multiplikator'] = '1';
		$curr = $GLOBALS['db']->RowQuery("SELECT Waehrung_1 FROM " . PREFIX . "_shop_einstellungen");
		$_SESSION['currency_registered'] = $curr->Waehrung_1;
	}
	
} else {

	if(isset($_REQUEST['currency']) && !empty($_REQUEST['currency']) && is_numeric($_REQUEST['currency']) && $_REQUEST['currency']>0)
	{
		$currency = ereg_replace('([^0-9])', '', $_REQUEST['currency']);
		$row_c = $GLOBALS['db']->ArrQuery("SELECT MultiWaehrung, WaehrungSymbol_$currency, Multiplikator_$currency FROM " . PREFIX . "_shop_einstellungen");
		if(is_array($row_c) && $row_c['MultiWaehrung'] == 1 && $row_c['WaehrungSymbol_' . $currency] != '')
		{
			$_SESSION['currency'] = $currency;
			$_SESSION['Multiplikator'] = $row_c['Multiplikator_' . $currency];
			$db_c = 'WaehrungSymbol_' . $currency;	
			$curr = $GLOBALS['db']->ArrQuery("SELECT Waehrung_{$currency} FROM " . PREFIX . "_shop_einstellungen");
			$_SESSION['currency_registered'] = $curr['Waehrung_' . $currency];
		} else {
			$db_c = 'WaehrungSymbol_1';
			$_SESSION['Multiplikator'] = '1';
			$curr = $GLOBALS['db']->RowQuery("SELECT Waehrung_1 FROM " . PREFIX . "_shop_einstellungen");
			$_SESSION['currency_registered'] = $curr->Waehrung_1;
			$_SESSION['currency'] = $currency;
		}
		
		if(isset($_REQUEST['redirect']) && !empty($_REQUEST['redirect']))
		{
			$redir = base64_decode($_REQUEST['redirect']);
			$redir = str_replace('&amp;', '&', $redir);
			refer($redir);
			exit;
		}
		
	} else {
	
		$db_c = 'WaehrungSymbol_1';
		$_SESSION['Multiplikator'] = '1';
		$curr = $GLOBALS['db']->RowQuery("SELECT Waehrung_1 FROM " . PREFIX . "_shop_einstellungen");
		$_SESSION['currency_registered'] = $curr->Waehrung_1;
	}
	
}



$categs = array();
$area = AREA;

$Shop->checkDiscount();

$GLOBALS['tmpl']->assign('widerruf_belehrung', str_replace('%%SHOPADRESSE%%', $shop_settings_detail->ShopAdresse, $shop_settings_detail->Widerruf));
//$GLOBALS['tmpl']->assign('widerruf_folgen', $shop_settings_detail->Widerruffolgen);
$GLOBALS['tmpl']->assign('shop_navigation', $GLOBALS['tmpl']->fetch(BASE_DIR . '/theme/' . $config['std_theme'] . '/shop/shopnavi.tpl'));


//=================================================================
// Shopeinstellungen
//=================================================================
$cu_array   = $GLOBALS['db']->ArrQuery("SELECT Waehrung_1,Waehrung_2,Waehrung_3 FROM " . PREFIX . "_shop_einstellungen");
$CurrSymbol = $GLOBALS['shopsettings']->$db_c;
$SiLc       = 'ShopInfo_' . $_SESSION['Langcode'];
define("KOOBI_CURRENCY_SYMBOL", $CurrSymbol);
$GLOBALS['tmpl']->assign('ShopInfo', $GLOBALS['shopsettings']->$SiLc);
$GLOBALS['tmpl']->assign('cu_array', $cu_array);
$GLOBALS['tmpl']->assign('currency_symbol', $CurrSymbol);


$LC = $_SESSION['Langcode'];
$Available = array();
$sql_Available = $GLOBALS['db']->Query("SELECT Id, Titel_{$LC} AS Name FROM " . PREFIX . "_shop_verfuegbarkeit ORDER BY Id ASC");
while($row_Available = $sql_Available ->fetchrow()) 
{
	array_push($Available,$row_Available);
}
$GLOBALS['vailmsg'] = $Available;
$GLOBALS['tmpl']->assign('available_array',$Available);


//=================================================================
// Topseller Navigation
//=================================================================
if(get_active('shop_topseller'))
{
	$GLOBALS['tmpl']->assign('small_topseller_array', $Shop->listProducts(0,0,1,1,$Shop->_small_navi_limit,1));
	$GLOBALS['tmpl']->assign('small_topseller', $GLOBALS['tmpl']->fetch(BASE_DIR . '/theme/' . $config['std_theme'] . '/shop/small_topseller.tpl'));
}

// Gesehene Produkte
if(isset($_SESSION['prod_seen']) && is_array($_SESSION['prod_seen']) && get_active('shop_seenproducts') && $_REQUEST['p'] != 'misc')
{
	$GLOBALS['tmpl']->assign('seen_products_array', $Shop->showProductsVarious());
	$GLOBALS['tmpl']->assign('small_seen_products', $GLOBALS['tmpl']->fetch(BASE_DIR . '/theme/' . $config['std_theme'] . '/shop/small_seen_products.tpl'));
}

//=================================================================
// Waehrungs-Auswahl
//=================================================================
if(get_active('shop_currency'))
{
	$GLOBALS['tmpl']->assign('curreny_selector', $GLOBALS['tmpl']->fetch(BASE_DIR . '/theme/' . $config['std_theme'] . '/shop/curreny_selector.tpl'));
}

$GLOBALS['tmpl']->assign('payment_images', $GLOBALS['tmpl']->fetch(BASE_DIR . '/theme/' . $config['std_theme'] . '/shop/payment_images.tpl'));

//=================================================================
// Warenkorb klein
//=================================================================
$GLOBALS['tmpl']->assign('basket_small', $Shop->initBasket(BASE_DIR . '/theme/' . $config['std_theme'] . '/'));

//
$GLOBALS['tmpl']->assign('shop_manufaturers', $Shop->getManufacturer());

//
$scategs = array();
$GLOBALS['tmpl']->assign('status_legend', $GLOBALS['tmpl']->fetch(BASE_DIR . '/theme/' . $config['std_theme'] . '/shop/products_legend.tpl'));
$GLOBALS['tmpl']->assign('shop_search_small_action', 'index.php?s=1&amp;area=' . AREA . '&amp;lang=' . $_SESSION['lang'] . '&amp;p=shop&amp;action=showproducts');
$GLOBALS['tmpl']->assign('shop_search_small', $Shop->showSearchSmall(BASE_DIR . '/theme/' . $config['std_theme'] . '/'));
?>