<?php
unset( $config, $aMenuTypes, $aPhotoTypes, $lang, $aBanners, $aBoxes, $aUser );
require_once __DIR__.'/../libraries/utils.php';
define( 'SUBIEKT_GT', is_dir( 'subiektgt' ) );
$config['subiektgt'] = SUBIEKT_GT;
// Strip magic quotes from request data.
//if( function_exists( 'get_magic_quotes_gpc' ) && get_magic_quotes_gpc( ) ){
//	// Create lamba style unescaping function (for portability)
//	$quotes_sybase = strtolower( ini_get( 'magic_quotes_sybase' ) );
//	$unescape_function = ( empty( $quotes_sybase ) || $quotes_sybase === 'off' ) ? 'stripslashes($value)' : 'str_replace("\'\'","\'",$value)';
//	$stripslashes_deep = create_function( '&$value, $fn', '
//        if (is_string($value)) {
//            $value = ' . $unescape_function . ';
//        } else if (is_array($value)) {
//            foreach ($value as &$v) $fn($v, $fn);
//        }
//    ' );
//	// Unescape data
//	$stripslashes_deep( $_POST, $stripslashes_deep );
//	$stripslashes_deep( $_GET, $stripslashes_deep );
//	$stripslashes_deep( $_COOKIE, $stripslashes_deep );
//	$stripslashes_deep( $_REQUEST, $stripslashes_deep );
//}
//@set_magic_quotes_runtime( false );
extract( $_GET );
require __DIR__.'/database.php';
require __DIR__.'/general.php';
$config['SESSION_NAME_SELLSMART'] = 'sellsmart' . intval( VERSION ) . '_' . md5( strtolower( dirname( $_SERVER['PHP_SELF'] ) ) );
define( 'SESSION_NAME_SELLSMART', $config['SESSION_NAME_SELLSMART'] );
session_name( SESSION_NAME_SELLSMART );
session_start( );
require __DIR__.'/../'.DB_CONFIG_LANG;
require_once __DIR__.'/../'.DIR_LANG . LANGUAGE . '.php';
if( !defined( 'CUSTOMER_PAGE' ) ){
	$lang_client = $lang;
	$lang = Array();
	require_once __DIR__.'/../'.DIR_LANG . 'admin.php';
	require_once __DIR__.'/../'.DIR_LANG . 'admin_help.php';
}
require __DIR__.'/../'.DB_CONFIG_CARRIERS;
require __DIR__.'/template.php';
if( !defined( 'CUSTOMER_PAGE' ) ){
	require __DIR__.'/admins.php';
}
$config['foot_info'] = str_replace( '&quot;', '"', $config['foot_info'] );

// AUTOLOAD
if (strpos($_SERVER['SCRIPT_NAME'],'/api/')) chdir('..');
//require_once DIR_LIBRARIES . 'FileJobs.php';//require_once DIR_LIBRARIES . 'SMS.php';//require_once DIR_LIBRARIES . 'DataBase.php';//require_once DIR_LIBRARIES . 'http.php';//require_once DIR_ENGINE . 'pages.php';//require_once DIR_ENGINE . 'admins.php';//require_once DIR_ENGINE . 'attributes.php';//require_once DIR_ENGINE . 'vat.php';//require_once DIR_ENGINE . 'products.php';//require_once  __DIR__.'/../'.DIR_LIBRARIES . 'DataBase.php';//require_once  __DIR__.'/../'.DIR_LIBRARIES . 'TplParser.php';
require_once  __DIR__.'/../'.DIR_LIBRARIES . 'salesManago.php';
require_once  __DIR__.'/../'.DIR_LIBRARIES . 'bluemedia.php';
require_once  __DIR__.'/../'.DIR_LIBRARIES . 'firstData.php';
require_once  __DIR__.'/../'.DIR_ENGINE . 'common.php';
require_once  __DIR__.'/../'.DIR_ENGINE . 'producers.php';
require_once  __DIR__.'/../'.DIR_ENGINE . 'comments.php';
require_once  __DIR__.'/../'.DIR_ENGINE . 'files.php';
require_once __DIR__.'/../'.DIR_ENGINE . 'users.php';
require_once  __DIR__.'/../'.DIR_ENGINE . 'banners.php';
require_once  __DIR__.'/../'.DIR_ENGINE . 'boxes.php';
require_once  __DIR__.'/../'.DIR_ENGINE . 'polls.php';
require_once  __DIR__.'/../'.DIR_ENGINE . 'stats.php';
require_once  __DIR__.'/../'.DIR_LIBRARIES . 'FileJobs.php';
require_once __DIR__.'/../'.DIR_ENGINE . 'vat.php';
require_once __DIR__.'/../'.DIR_ENGINE . 'attributes.php';
require_once __DIR__.'/../'.DIR_ENGINE . 'comments.php';
require_once __DIR__.'/../'.DIR_ENGINE . 'users.php';
require_once __DIR__.'/../'.DIR_ENGINE . 'admins.php';
require_once __DIR__.'/../'.DIR_LIBRARIES . 'SMS.php';
require_once __DIR__.'/../'.DIR_LIBRARIES . 'http.php';
//require_once DIR_LIBRARIES . 'TplParser.php';//require_once DIR_LIBRARIES . 'FileJobs.php';//require_once DIR_LIBRARIES . 'DataBase.php';//require_once DIR_LIBRARIES . 'FotoJobs.php';//require_once DIR_ENGINE . 'pages.php';//require_once DIR_ENGINE . 'products.php';//require_once DIR_ENGINE . 'products-admin.php';//require_once DIR_ENGINE . 'orders.php';//require_once DIR_ENGINE . 'orders-admin.php';
if( $config['facebook_login'] ){
	require_once __DIR__.'/../'.DIR_PLUGINS . 'facebook/facebook.php';
	$fbconfig = array(
		'appId' => $config['facebook_login_appId'],
		'secret' => $config['facebook_login_secret'],
		'fileUpload' => false, // optional
		'allowSignedRequest' => false, // optional, but should be set to false for non-canvas apps
	);
}

spl_autoload_register(function ($class) {
	if ((!strpos($_SERVER['SCRIPT_NAME'],'/api/')||(isset($_SESSION['bSellSmartUser']) && $_SESSION['bSellSmartUser'] == true) && strpos($class,'Admin')) ) 
	$class=str_replace('Admin','-admin',$class);
	if (file_exists(DIR_ENGINE.strtolower($class).'.php')) require_once(DIR_ENGINE.strtolower($class).'.php');
	if (file_exists(DIR_LIBRARIES.$class.'.php')) require_once(DIR_LIBRARIES.$class.'.php');
	
});

if (strpos($_SERVER['SCRIPT_NAME'],'admin.php')||strpos($_SERVER['SCRIPT_NAME'],'/api/') ){
	require_once  __DIR__.'/../'.DIR_ENGINE . 'files-admin.php';
	require_once  __DIR__.'/../'.DIR_ENGINE . 'common-admin.php';
	require_once  __DIR__.'/../'.DIR_ENGINE . 'admins-admin.php';
	require_once  __DIR__.'/../'.DIR_ENGINE . 'lang-admin.php';
	require_once  __DIR__.'/../'.DIR_ENGINE . 'polls-admin.php';
	require_once  __DIR__.'/../'.DIR_LIBRARIES . 'FotoJobs.php';
	require_once __DIR__.'/../'.DIR_ENGINE . 'vat-admin.php';	
	require_once __DIR__.'/../'.DIR_ENGINE . 'producers-admin.php';
	require_once __DIR__.'/../'.DIR_ENGINE . 'attributes-admin.php';
	require_once __DIR__.'/../'.DIR_ENGINE . 'comments-admin.php';
	require_once __DIR__.'/../'.DIR_ENGINE . 'users-admin.php';
	require_once __DIR__.'/../'.DIR_ENGINE . 'admins-admin.php';
	require_once __DIR__.'/../'.DIR_ENGINE . 'stores-admin.php';
}
