<?php
if( isset( $aActions['a'] ) && is_numeric( $aActions['a'] ) ){
	$iProduct = $aActions['a'];
	$aData = $oProduct->throwProduct( $iProduct );
	if( !empty( $config['recaptcha_private'] ) && !empty( $config['recaptcha_public'] ) ) $oReCaptcha = new recaptchalib($config['recaptcha_private']);
	if( isset( $_GET['mes'] ) && ( $_GET['mes'] == 'message_send' ) ){
		$aMessage = Array( 'header' => $lang['Send_ok'], 'content' => '<p>' . $lang['Message_send'] . '</p>' );
		//var_dump($aMessage);
		
	}
	if( isset( $_GET['mes'] ) && ( $_GET['mes'] == 'comment_add' ) ){
		$aMessage = Array( 'header' => $lang['Send_ok'], 'content' => '<p>' . $lang['Comment_add'] . '</p>' );
	}
	if( isset( $_GET['mes'] ) && ( $_GET['mes'] == 'message_error' ) ){
		$aMessage = Array( 'header' => $lang['Send_error'], 'content' => '<p>' . $lang['Message_send_error'] . '</p>' );
	}
	if( $oSalesManago->checkSettings() === true && isset( $_SESSION['sUserEmail'] ) && $_SESSION['sUserEmail'] != "" ) $oSalesManago->addEventContact( 'VISIT', $aData, $_SESSION ); // nie dalej bo wysyła dwa razy!!!
	if( isset( $aData ) ){
		saveUserAction( Array( 'iProduct' => $iProduct, 'iType' => 1 /* 1 - otworzenie, 2 - porównanie, 3 - dodanie do schowka, 4 - dodanie do koszyka */, 'fPrice' => $aData['bTimePromotionActive'] ? $aData['fTimePrice'] : $aData['fCatalogPrice'], 'iAvailable' => $aData['TiAvailable'] ) );
		$aData['aProducer'] = throwProducer( $aData['iProducer'] );
		$aData['sProducer'] = $aData['aProducer']['sName'];
		$aData['aPagesTree'] = $oProduct->getPagesTree( $iProduct, $aData['sName'] );
		$sMetaPageTree = '';
		if( is_array( $aData['aPagesTree']['aPath'] ) ) foreach( $aData['aPagesTree']['aPath'] as $aPage ) $sMetaPageTree.= ', ' . $aPage['sName'];
		if( !empty( $aData['sNameTitle'] ) ) $sTitle = strip_tags( $aData['sNameTitle'] );
		else $sTitle = strip_tags( $aData['sName'] . ' - ' . $aData['sProducer'] . ' -' . str_replace( ',', '', $sMetaPageTree ) . ( !empty( $config['title_4_products'] ) ? ' - ' . $config['title_4_products'] : null ) );
		if( !empty( $aData['aAttributes'] ) ){
			foreach( $aData['aAttributes'] as $aAttribute ){
				$aMetaAttributes[] = $aAttribute['sName'] . ' ' . implode( ', ', $aAttribute['aValues'] );
			}
			$sMetaAttributes = ', ' . implode( ', ', $aMetaAttributes );
		} else{
			$sMetaAttributes = null;
		}
		if( !empty( $aData['sMetaKeywords'] ) ) $sKeywords = $aData['sMetaKeywords'];
		else $sKeywords = $aData['sName'] . ( !empty( $aData['sProducer'] ) ? ', ' . $aData['sProducer'] : null ) . $sMetaPageTree . $sMetaAttributes . ( !empty( $sKeywords ) ? ', ' . $sKeywords : null );
		if( !empty( $aData['sMetaAbstract'] ) ) $sMetaAbstract = $aData['sMetaAbstract'];
		if( !empty( $aData['sMetaPageTopic'] ) ) $sMetaPageTopic = $aData['sMetaPageTopic'];
		$aData['sDescriptionFull'] = str_replace( Array( '%sName%', '%sProducer%', '%sPrice%' ), Array( $aData['sName'], $aData['sProducer'], $aData['sPrice'] ), $aData['sDescriptionFull'] );
		if( empty( $aData['sDescriptionFull'] ) ) $aData['sDescriptionFull'] = $aData['sDescriptionShort'];
		if( !empty( $aData['sMetaDescription'] ) ) $sDescription = $aData['sMetaDescription'];
		else{
			$sMetaDescPart = $aData['sName'] . ', ' . $aData['sProducer'] . '. ' . $aData['sDescriptionShort'];
			if( empty( $sMetaDescPart ) ) $sMetaDescPart = $aData['sDescriptionFull'];
			$sMetaDescPart = str_replace( '|n|', ' ', strip_tags( $sMetaDescPart ) );
			$sMetaDescPart = preg_replace( '/\\s+/', ' ', $sMetaDescPart );
			$sMetaDescPart = htmlspecialchars( $sMetaDescPart );
			if( strlen( $sMetaDescPart ) > 200 ){
				$sMetaDescPart = substr( $sMetaDescPart, 0, 200 );
				$sMetaDescPart = preg_replace( '/\\s\\S+$/', '', preg_replace( '/&[^;]+$/', '', $sMetaDescPart ) ) . '...';
			}
			$sDescription = $aData['sName'] . ( !empty( $aData['sProducer'] ) ? ' - ' . $aData['sProducer'] : null ) . ', ' . $lang['Price'] . ': ' . $aData['sPrice'] . ' ' . $config['currency_symbol'] . '. ' . $sMetaDescPart;
		}
		$sProductName = $aData['sName'];
		$aData['aAdditionalInfo'] = $aData['aTabs'];
		$aData['aTabs'] = Array( );
		if( $config['show_attributes_table'] && ( count( $aData['aAttributes'] ) > 0 || count( $aData['aProducer']['aGuarantee'] ) > 0 ) ){
			$oTpl->assign( 'aProduct', $aData );
			$sTableContent = $oTpl->parse( 'product_attributes_table.tpl' );
		} else{
			$sTableContent = '';
		}
		if( $config['show_advsearcher_table'] ){
			$aData['aAdvsearcherValues'] = $oDB->executeSQL( 'SELECT `iValue` FROM `' . $oDB->throwTableName( DB_ADVSEARCHER_PRODUCTS ) . '` WHERE `iProduct` = ' . $aData['iProduct'], true, DataBase::ASSOCIATIVE, 'iValue' );
			foreach( $aData['aAdvsearcherValues'] as &$mValue ){
				$sText = '';
				$iParentValue = $mValue['iValue'];
				while( !empty( $iParentValue ) ){
					list( $iParentValue, $sTextAdd ) = $oDB->executeSQL( 'SELECT `iParentValue`, `sValue` FROM `' . $oDB->throwTableName( DB_ADVSEARCHER_VALUES ) . '` WHERE `iValue` = ' . intval( $iParentValue ), true, DataBase::SINGLE_RECORD | MYSQLI_NUM );
					$sText = $sTextAdd . ( !empty( $sText ) ? ' &raquo; ' . $sText : null );
				}
				$mValue = $sText;
			}
			$aData['sAdvsearcherValues'] = implode( '</li><li>', $aData['aAdvsearcherValues'] );
			if( !empty( $aData['sAdvsearcherValues'] ) ) $aData['sAdvsearcherValues'] = '<h2>' . str_replace( '%sProduct%', $aData['sName'], $lang['advsearcher_table'] ) . '</h2><ul id="advsearcher-table"><li>' . $aData['sAdvsearcherValues'] . '</li></ul>';
		}
		if( !empty( $aData['aProducer']['sDescription'] ) && empty( $aData['sDescriptionFull'] ) ){
			$aData['sDescriptionFull'] = $aData['aProducer']['sDescription'];
			$aData['aProducer']['sDescription'] = null;
		}
		$aData['aTabs'][0] = Array( 'sContent' => changeTxt( $aData['sDescriptionFull'], 'nlNds' ) . $sTableContent . $aData['sAdvsearcherValues'], 'sTitle' => $lang['Product_description'], 'sTitleLong' => str_replace( '%sProduct%', $aData['sName'], $lang['Product_description_long'] ) );
		//		ksort( $aData['aTabs'] );
		if( is_array( $aData['aAdditionalInfo'] ) ) foreach( $aData['aAdditionalInfo'] as $iTab => &$mTab ){
			if( !empty( $mTab ) ){
				$aData['aTabs'][1]['sTitle'] = $lang['Additional_info'];
				$aData['aTabs'][1]['sContent'].= ( !empty( $aData['aTabs'][1]['sContent'] ) ? '<hr/>' : '' ) . '<h4>' . $config['tab' . $iTab . '_name'] . '</h4>' . changeTxt( $mTab, 'nlNds' );
				//$mTab = Array( 'sContent' => changeTxt( $mTab, 'nlNds' ), 'sTitle' => $config['tab' . $iTab . '_name'] );
				
			} else{
				unset( $aData['aAdditionalInfo'][$iTab] );
			}
		}
		if( isset( $config['ask_about_product_form'] ) && ($config['ask_about_product_form']) ){
			// generowane też poza zakładkami
			if( isset( $_POST['sOption'] ) && $_POST['sOption'] == 'sendProductQuestion' ){
					if (!$oReCaptcha->verify($_POST['g-recaptcha-response'],$_SERVER['REMOTE_ADDR'])){
						header( 'Location: ' . $sUserPage . ( strpos( $sUserPage, '?' ) !== false ? '&' : '?' ) . 'mes=message_error' );
						exit;
					}
				$_POST['sTopic'] = $lang['Question_from_website'] . ': ' . $sProductName . ' (id ' . $aData['iProduct'] . ')';;
				$_POST['sMailContent'] = '<table class="details"><tbody><tr><th colspan="2">' . $lang['Question_from_website'] . ': ' . $sProductName . ' (id ' . $aData['iProduct'] . ')</th></tr>
				<tr><td>' . $lang['Name_and_surname'] . '</td><td>' . $_POST['sName'] . '</td></tr>
				<tr><td>' . $lang['Email'] . '</td><td>' . $_POST['sSender'] . '</td></tr>
				<tr><td>' . $lang['Phone'] . '</td><td>' . $_POST['sPhone'] . '</td></tr>
				</table><table class="details">
				<tr><th colspan="2">' . $lang['Your_question'] . '</th></tr>
				<tr><td colspan="2">' . $_POST['sMailContent'] . '</td></tr></table>';
				sendEmail( $_POST );
				if( $config['sms_send_new_product_ask_to_admin'] == 1 && !empty( $config['sms_admin_phone'] ) ){
					$aLangOld = $lang;
					include( DIR_LANG . 'admin.php' );
					$sText = str_replace( Array( '%sShopName%', '|n|' ), Array( $GLOBALS['config']['website_name'], "\n" ), $lang['sms_send_new_product_ask_to_admin'] );
					$oSMS = new SMS( $GLOBALS['config']['serwersms_login'], $GLOBALS['config']['serwersms_password'] );
					$oSMS->sendSMS_delay( $GLOBALS['config']['sms_admin_phone'], $sText );
					$lang = $aLangOld;
				}
				//$pageURL = $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
				header( 'Location: ' . ( strpos( $pageURL, '?' ) !== false ? '&' : '?' ) . 'mes=message_send' );
			}
			$aData['aTabs']['ask'] = Array( 'sContent' => null, 'sTitle' => $lang['Ask_about_product'] );
		}
		if( isset( $_POST['sOption'] ) && $_POST['sOption'] == 'sendProductAvailNewsletter' ){
			$oDB->save( DB_PRODUCTS_AVAIL_NEWSLETTER, Array( 'iProduct' => $_POST['iProduct'], 'iProductVariant' => $_POST['iProductVariant'], 'sEmail' => $_POST['sEmail'], 'sPhone' => $_POST['sPhone'], 'iTime' => time() ) );
			$aMessage = Array( 'header' => $lang['avail_newsletter_ok_header'], 'content' => '<p>' . $lang['avail_newsletter_ok_content'] . '</p>' );
		}
		if( empty( $config[base64_decode( 'Zm9vdF9pbmZv' ) ] ) ){
			$aFI = Array( 
				'Q29weXJpZ2h0ICYjMTY5OyAyMDE0PGJyLz5Ta2xlcCBpbnRlcm5ldG93eSA8YSBocmVmPSJodHRwOi8vd3d3LnNlbGxzbWFydC5wbC8iPnNlbGw8c3Ryb25nPnNtYXJ0PC9zdHJvbmc+LnBsPC9hPjxici8+UHJvamVrdCBpIHd5a29uYW5pZSA8YSBocmVmPSJodHRwOi8vd3d3LmxhYnNxbC5wbC8iPkxhYjxzdHJvbmc+U1FMPC9zdHJvbmc+LnBsPC9hPg==',
				'Q29weXJpZ2h0ICYjMTY5OyAyMDE0PGJyLz5Ta2xlcHkgaW50ZXJuZXRvd2UgPGEgaHJlZj0iaHR0cDovL3d3dy5zZWxsc21hcnQucGwvIj5zZWxsPHN0cm9uZz5zbWFydDwvc3Ryb25nPi5wbDwvYT48YnIvPlByb2pla3QgaSB3eWtvbmFuaWUgPGEgaHJlZj0iaHR0cDovL3d3dy5sYWJzcWwucGwvIj5MYWI8c3Ryb25nPlNRTDwvc3Ryb25nPi5wbDwvYT4=',
				'Q29weXJpZ2h0ICYjMTY5OyAyMDE0PGJyLz5Qcm9ncmFtIHNrbGVwdSBXV1cgPGEgaHJlZj0iaHR0cDovL3d3dy5zZWxsc21hcnQucGwvIj5zZWxsPHN0cm9uZz5zbWFydDwvc3Ryb25nPi5wbDwvYT48YnIvPlByb2pla3QgaSB3eWtvbmFuaWUgPGEgaHJlZj0iaHR0cDovL3d3dy5sYWJzcWwucGwvIj5MYWI8c3Ryb25nPlNRTDwvc3Ryb25nPi5wbDwvYT4=',
				'Q29weXJpZ2h0ICYjMTY5OyAyMDE0PGJyLz5PcHJvZ3JhbW93YW5pZSBza2xlcHUgPGEgaHJlZj0iaHR0cDovL3d3dy5zZWxsc21hcnQucGwvIj5zZWxsPHN0cm9uZz5zbWFydDwvc3Ryb25nPjwvYT48YnIvPlByb2pla3QgaSB3eWtvbmFuaWUgPGEgaHJlZj0iaHR0cDovL3d3dy5sYWJzcWwucGwvIj5MYWI8c3Ryb25nPlNRTDwvc3Ryb25nPi5wbDwvYT4=',
				'Q29weXJpZ2h0ICYjMTY5OyAyMDE0PGJyLz5FLXNrbGVwIFdXVyA8YSBocmVmPSJodHRwOi8vd3d3LnNlbGxzbWFydC5wbC8iPnNlbGw8c3Ryb25nPnNtYXJ0PC9zdHJvbmc+LnBsPC9hPjxici8+UHJvamVrdCBpIHd5a29uYW5pZSA8YSBocmVmPSJodHRwOi8vd3d3LmxhYnNxbC5wbC8iPkxhYjxzdHJvbmc+U1FMPC9zdHJvbmc+LnBsPC9hPg==',
				'Q29weXJpZ2h0ICYjMTY5OyAyMDE0PGJyLz5Qcm9ncmFtIGUtc2tsZXB1IDxhIGhyZWY9Imh0dHA6Ly93d3cuc2VsbHNtYXJ0LnBsLyI+c2VsbDxzdHJvbmc+c21hcnQ8L3N0cm9uZz4ucGw8L2E+PGJyLz5Qcm9qZWt0IGkgd3lrb25hbmllIDxhIGhyZWY9Imh0dHA6Ly93d3cubGFic3FsLnBsLyI+TGFiPHN0cm9uZz5TUUw8L3N0cm9uZz4ucGw8L2E+',
			);
			$config[base64_decode( 'Zm9vdF9pbmZv' ) ] = base64_decode( $aFI[$iProduct % 6] );
			$oTpl->assign( 'config', $config );
		}
		if( !empty( $aData['iComments'] ) && $aData['iComments'] == 1 ){
			if(isset( $_POST['sOption'] ) && $_POST['sOption'] == 'saveComment' && !empty( $_POST['sContent'] ) && !empty($_POST['sName']) ){
				if (!$oReCaptcha->verify($_POST['g-recaptcha-response'],$_SERVER['REMOTE_ADDR'])){
					header( 'Location: ' . $sUserPage . ( strpos( $sUserPage, '?' ) !== false ? '&' : '?' ) . 'mes=message_error' );
					exit;
				}
					addComment( $_POST, $iProduct, DB_PRODUCTS_COMMENTS );
					if( $config['sms_send_new_comment_to_admin'] == 1 && !empty( $config['sms_admin_phone'] ) ){
						$aLangOld = $lang;
						include( DIR_LANG . 'admin.php' );
						$sText = str_replace( Array( '%sShopName%', '|n|' ), Array( $GLOBALS['config']['website_name'], "\n" ), $lang['sms_send_new_comment_to_admin'] );
						$oSMS = new SMS( $GLOBALS['config']['serwersms_login'], $GLOBALS['config']['serwersms_password'] );
						$oSMS->sendSMS_delay( $GLOBALS['config']['sms_admin_phone'], $sText );
						$lang = $aLangOld;
					}
					$sIndex = ( !isset( $config['index'] ) || ( isset( $config['index'] ) && $config['index'] == '?' ) ) ? $_SERVER['PHP_SELF'] : null;
					//header( 'Location: ' . $sIndex . $aData['sLinkName'] );
					header( 'Location: ' . $sIndex . $aData['sLinkName'] . ( strpos( $pageURL, '?' ) !== false ? '&' : '?' ) . 'mes=comment_add' );
					exit;
				

			}
			$aData['aTabs']['comments'] = Array( 'sContent' => null, 'sTitle' => $lang['Products_comment'] . ( $iComments > 0 ? ( ' (' . $iComments . ')' ) : null ) );
			$aData['aComments']['aList'] = throwComments( $iProduct, DB_PRODUCTS_COMMENTS, $aData['aComments']['fRating'], true, true, $aData['aComments']['iComments'] );
		}{
			if( isset( $_POST['sOption'] ) && $_POST['sOption'] == 'sendRecommendation' && !empty( $_POST['sContent'] ) && !preg_match( "/(\[url)|(<a href=)/i", $_POST['sContent'] ) && !empty( $_POST['sName'] ) && !empty( $_POST['sEmail'] ) ){
				if (!$oReCaptcha->verify($_POST['g-recaptcha-response'],$_SERVER['REMOTE_ADDR'])) {
						header( 'Location: ' . $sUserPage . ( strpos( $sUserPage, '?' ) !== false ? '&' : '?' ) . 'mes=message_error' );
						exit;
				}
				$sIndex = ( !isset( $config['index'] ) || ( isset( $config['index'] ) && ( $config['index'] == '?' || $config['index'] == 'index.html' ) ) ) ? $_SERVER['PHP_SELF'] : $config['index'];
				$sIndex = ( dirname( $sIndex ) == '.' ) ? '/' : dirname( $sIndex ) . '/';
				sendRecommendation( array_merge( $_POST, Array( 'sProductName' => $aData['sName'], 'sProductLink' => 'http' . ( $_SERVER['HTTPS'] ? 's' : '' ) . '://' . $_SERVER['SERVER_NAME'] . $sIndex . $aData['sLinkName'], 'sShopName' => $config['title'], 'sShopLink' => 'http' . ( $_SERVER['HTTPS'] ? 's' : '' ) . '://' . $_SERVER['SERVER_NAME'] . $sIndex ) ), $iProduct );
				header( 'Location: ' . $aData['sLinkName'] . ( strpos( $pageURL, '?' ) !== false ? '&' : '?' ) . 'mes=message_send' );
				exit;
			}
			$aData['aTabs']['recommend'] = Array( 'sContent' => null, 'sTitle' => $lang['Products_recommend'] );
		}
		if( isset( $config['submit_error_product_form'] ) && $config['submit_error_product_form'] ){
			if( isset( $_POST['sOption'] ) && $_POST['sOption'] == 'sendProductError' ){
				if (!$oReCaptcha->verify($_POST['g-recaptcha-response'],$_SERVER['REMOTE_ADDR'])) {
					header( 'Location: ' . $sUserPage . ( strpos( $sUserPage, '?' ) !== false ? '&' : '?' ) . 'mes=message_error' );
					exit;

				}

				$_POST['sTopic'] = $lang['Information_about_error'] . ': ' . $sProductName . ' (id ' . $aData['iProduct'] . ')';
				$_POST['sMailContent'] = '<table class="details"><tbody><tr><th colspan="2">' . $lang['Information_about_error'] . ': ' . $sProductName . ' (id ' . $aData['iProduct'] . ')</th></tr>
				<tr><td>' . $lang['Name_and_surname'] . '</td><td>' . $_POST['sName'] . '</td></tr>
				<tr><td>' . $lang['Email'] . '</td><td>' . $_POST['sSender'] . '</td></tr>
				</table><table class="details">
				<tr><th colspan="2">' . $lang['Error_description'] . '</th></tr>
				<tr><td colspan="2">' . $_POST['sMailContent'] . '</td></tr></table>';
				
				sendEmail( $_POST );
				header( 'Location: ' . $sIndex . $aData['sLinkName'] . ( strpos( $pageURL, '?' ) !== false ? '&' : '?' ) . 'mes=message_send' );
			}
			$aData['aTabs']['error'] = Array( 'sContent' => null, 'sTitle' => $lang['Inform_about_error_in_description'] );
		}
		if( isset( $config['negotiate_price_form'] ) && $config['negotiate_price_form'] ){
			$sProductName = $aData['sName'];
			if( isset( $_POST['sOption'] ) && $_POST['sOption'] == 'sendPriceNegotiate' ){
				if (!$oReCaptcha->verify($_POST['g-recaptcha-response'],$_SERVER['REMOTE_ADDR'])){
					header( 'Location: ' . $sUserPage . ( strpos( $sUserPage, '?' ) !== false ? '&' : '?' ) . 'mes=message_error' );
					exit;
				}
				$_POST['sTopic'] = $lang['Product_price_negotiate_request'] . ': ' . $sProductName . ' (id ' . $aData['iProduct'] . ')';
				$oDB->executeSQL( 'UPDATE `' . $oDB->throwTableName( DB_USER_ACTIONS ) . '` SET `sEmail` = \'' . $oDB->escape( $_POST['sSender'] ) . '\' WHERE `sEmail` IS NULL AND `iCustomer` = ' . $_SESSION['iCustomer' . LANGUAGE] );
				$_POST['sMailContent'] = '<table class="details"><tbody><tr><th colspan="2">' . $lang['Product_price_negotiate_request'] . ': ' . $sProductName . ' (id ' . $aData['iProduct'] . ')</th></tr>
				<tr><td>' . $lang['Name_and_surname'] . '</td><td>' . $_POST['sName'] . '</td></tr>
				<tr><td>' . $lang['Email'] . '</td><td>' . $_POST['sSender'] . '</td></tr>
				<tr><td>' . $lang['Phone'] . '</td><td>' . $_POST['sPhone'] . '</td></tr>
				</table><table class="details">
				<tr><th colspan="2">' . $lang['Product_price_negotiate_reason'] . '</th></tr>
				<tr><td colspan="2">' . $_POST['sMailContent'] . '</td></tr></table>';
				sendEmail( $_POST );
				if( $config['sms_send_new_price_negotiate_to_admin'] == 1 && !empty( $config['sms_admin_phone'] ) ){
					$aLangOld = $lang;
					include( DIR_LANG . 'admin.php' );
					$sText = str_replace( Array( '%sShopName%', '|n|' ), Array( $GLOBALS['config']['website_name'], "\n" ), $lang['sms_send_new_price_negotiate_to_admin'] );
					$oSMS = new SMS( $GLOBALS['config']['serwersms_login'], $GLOBALS['config']['serwersms_password'] );
					$oSMS->sendSMS_delay( $GLOBALS['config']['sms_admin_phone'], $sText );
					$lang = $aLangOld;
				}
				header( 'Location: ' . $sIndex . $aData['sLinkName'] . ( strpos( $pageURL, '?' ) !== false ? '&' : '?' ) . 'mes=message_send' );
			}
		}
		$aData['sPriceOld'] = ( !empty( $aData['sPriceOld'] ) && ( $aData['fPriceOld'] > $aData['fCatalogPrice'] ) ) ? $aData['sPriceOld'] : null;
		$aData['sCatalogPrice'] = ( $aData['fPrice'] < $aData['fCatalogPrice'] ) ? displayPrice( normalizePrice( $aData['fCatalogPrice'] ) ) : null;
		$aUrl = parse_url( 'http' . ( $_SERVER['HTTPS'] ? 's' : '' ) . '://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] );
		if( !empty( $aUrl['path'] ) && !preg_match( '|/$|', $aUrl['path'] ) ) $aUrl['path'] = dirname( $aUrl['path'] ) . '/';
		if( $config['social_facebook_products'] || $config['social_nk_products'] || $config['social_twitter_products'] || $config['social_gg_products'] || $config['social_google_products'] ){
			if( !empty( $aData['sDescriptionShort'] ) ) $aData['sFBDescription'] = trim_text( strip_tags( changeTxt( $aData['sDescriptionShort'], 'nlNds' ) ), 250 );
			else $aData['sFBDescription'] = trim_text( strip_tags( changeTxt( $aData['sDescriptionFull'], 'nlNds' ) ), 250 );
			$aData['sFBDescriptionEncode'] = rawurlencode( $aData['sFBDescription'] );
			$aData['sFBTitle'] = $aData['sName'];
			$aData['sFBTitleEncode'] = rawurlencode( htmlspecialchars_decode( $aData['sName'] ) );
			$aData['sFBUrl'] = $aUrl['scheme'] . '://' . $aUrl['host'] . $aUrl['path'] . $aData['sLinkName'];
			$aData['sFBUrlEncode'] = rawurlencode( $aData['sFBUrl'] );
			$aData['sFBWebsite'] = $config['website_name'];
			$aData['sFBWebsiteEncode'] = rawurlencode( $aData['sFBWebsite'] );
			$aData['sFBImage'] = $oFile->aImagesDefault[2][$aData['iProduct']];
			if( isset( $aData['sFBImage'] ) && $aData['sFBImage'] != '' ){
				$aData['sFBImage'] = $aUrl['scheme'] . '://' . $aUrl['host'] . $aUrl['path'] . $config['dir_files'] . $aData['sFBImage']['iSize'] . '/' . $aData['sFBImage']['sFileName'];
			}
		}
		$aFiles = $oFile->listFilesByTypes( $iProduct, 2 );
		$sBasketPage = ( isset( $config['basket_page'] ) && isset( $oPage->aPages[$config['basket_page']] ) && ( $aData['iNotForSale'] == 0 ) && ( $aData['iCanBuy'] > 0 ) ) ? $oPage->aPages[$config['basket_page']]['sLinkName'] : null;
		$oTpl->assign( 'sBasketPage', $sBasketPage );
		if( isset( $config['storage_page'] ) && isset( $oPage->aPages[$config['storage_page']] ) ){
			if( isset( $_GET['iProductStorageAdd'] ) && is_numeric( $_GET['iProductStorageAdd'] ) ){
				$oProduct->addToStorage( $_GET['iProductStorageAdd'] );
				saveUserAction( Array( 'iProduct' => $_GET['iProductStorageAdd'], 'iType' => 3 /* 1 - otworzenie, 2 - porównanie, 3 - dodanie do schowka, 4 - dodanie do koszyka */, 'fPrice' => $aData['bTimePromotionActive'] ? $aData['fTimePrice'] : $aData['fCatalogPrice'], 'iAvailable' => $aData['TiAvailable'] ) );
			}
			if( isset( $_GET['iProductStorageRemove'] ) && is_numeric( $_GET['iProductStorageRemove'] ) ) $oProduct->removeFromStorage( $_GET['iProductStorageRemove'] );
			$aStorageProducts = $oProduct->throwProductsStorage( );
			$aData['sStorageLinkName'] = $aData['sLinkName'] . '?';
			$aData['bInStorage'] = in_array( $aData['iProduct'], $aStorageProducts );
		}
		foreach( $aRelatedProducts as $iBox => $aRelatedBox ){
			if( is_numeric( $aRelatedBox['block'] ) ) $aHlProducts = $oProduct->listProductsRelatedByBox( $iProduct, $aRelatedBox['count'], $aRelatedBox['block'] );
			elseif( $aRelatedBox['block'] == 'cross-sell' ) $aHlProducts = $oProduct->listProductsCrossSell( $iProduct, $aRelatedBox['count'] );
			$aHlProducts['sTitle'] = str_replace( '%sProduct%', $aData['sName'], $aRelatedBox['name'] );
			$aHlProducts['sProductsShow'] = $aRelatedBox['show'];
			$aHlProducts['iWidthType'] = $aRelatedBox['width'];
			$aData['aRelated'][] = $aHlProducts;
		}
		//var_dump($aData['aAttributes']);
		//		$aData['aTabs']['Description_full'] = Array( 'sContent' =>changeTxt( $aData['sDescriptionFull'], 'nlNds' ) . $sTableContent, 'sTitle'=>$lang['Product_description']);
		$oTpl->assign( 'aPage', $aData['aMainCategory'] );
		$oTpl->assign( 'aProduct', $aData );
		$oTpl->assign( 'aFiles', $aFiles );
		$oTpl->assign( 'aMessage', $aMessage );
		$content.= $oTpl->parse( 'products_default.tpl' );
		saveProductStat( $iProduct );
	} else{
		$oTpl->assign( 'aMessage', Array( 'message' => $lang['Data_not_found'], 'bError' => true ) );
		$content.= $oTpl->parse( 'message.tpl' );
	}
	$iContent = $aData['iMainCategory'];
} elseif( isset( $aActions['a'] ) && ( $aActions['a'] == 'compare' ) ){
	$aProducts = json_decode( $_COOKIE[SESSION_NAME_SELLSMART . '_compare'] );
	foreach( $aProducts as $iProduct ){
		$aProduct = $oProduct->throwProduct( $iProduct );
		saveUserAction( Array( 'iProduct' => $iProduct, 'iType' => 2 /* 1 - otworzenie, 2 - porównanie, 3 - dodanie do schowka, 4 - dodanie do koszyka */, 'fPrice' => $aData['bTimePromotionActive'] ? $aData['fTimePrice'] : $aData['fCatalogPrice'], 'iAvailable' => $aProduct['TiAvailable'] ) );
	}
	$sBasketLink = $oPage->getLinkName( $config['basket_page'] );
	$sBasketPage = !empty( $sBasketLink ) ? ( $sBasketLink . '?' ) : null;
	$oTpl->assign( 'sBasketPage', $sBasketPage );
	echo $oProduct->listProductsCompare( 'products_compare.tpl', $aProducts );
	exit;
}
$sCookieLink = $oPage->aPages[$config['cookie_page']]['sLinkName'];
$oTpl->assign( 'sCookieLink', $sCookieLink );
?>