<?php

if(!defined('IN_WEENCOMPANY'))
  die('·Ç·¨½øÈë!');



$time_start = microtime(true);

error_reporting(E_ALL & ~E_NOTICE);


define('TIMENOW', time());
define('EMAIL_CRLF', "\r\n");	


if(is_file($rootpath . 'includes/config.php'))
{
  include($rootpath . 'includes/config.php');
}


if(!defined('CWSINSTALLED'))
{
  header('Location: '.$rootpath . 'install/index.php');
  exit;
}

include($rootpath . 'includes/db/' . $dbtype . '.php');

$DB = new DB;

$DB->database = $dbname;
$DB->server   = $servername;
$DB->user     = $dbusername;
$DB->password = $dbpassword;

$DB->connect();

$dbpassword   = '';
$DB->password = '';

if(defined('IN_ADMIN'))
{
	if(isset($_COOKIE['weenCompany_mplang'])){
		if($_COOKIE['weenCompany_mplang'] == 'en')
		{
			define('TABLE_PREFIX', TABLE_PREFIX_ALL . 'en_');
			define('OLDTABLE_PREFIX', TABLE_PREFIX_ALL . '_');
			$sitedefaultlang    = 'en';
		}
		else if($_COOKIE['weenCompany_mplang'] == 'cn')
		{
			define('TABLE_PREFIX', TABLE_PREFIX_ALL . '_');
			define('OLDTABLE_PREFIX', TABLE_PREFIX_ALL . 'en_');
			$sitedefaultlang    = 'cn';
		}
	}
	else
	{
		$getsitedefaultlang = $DB->query_first("SELECT value FROM " . TABLE_PREFIX_ALL . "_mainsettings WHERE varname = 'sitedefaultlang'");
		$sitedefaultlang    = $getsitedefaultlang['value'];

		if($sitedefaultlang == 'auto'){
			if (strstr(strtolower($_SERVER['HTTP_ACCEPT_LANGUAGE']), 'zh-cn') OR strstr(strtolower($_SERVER['HTTP_ACCEPT_LANGUAGE']), 'zh-tw'))
			{
				define('TABLE_PREFIX', TABLE_PREFIX_ALL . '_');
				define('OLDTABLE_PREFIX', TABLE_PREFIX_ALL . 'en_');
				$sitedefaultlang    = 'cn';
			}
			else
			{
				define('TABLE_PREFIX', TABLE_PREFIX_ALL . 'en_');
				define('OLDTABLE_PREFIX', TABLE_PREFIX_ALL . '_');
				$sitedefaultlang    = 'en';
			}
		}
		else if($sitedefaultlang == 'en')
		{
			define('TABLE_PREFIX', TABLE_PREFIX_ALL . 'en_');
			define('OLDTABLE_PREFIX', TABLE_PREFIX_ALL . '_');
		}
		else
		{
			define('TABLE_PREFIX', TABLE_PREFIX_ALL . '_');
			define('OLDTABLE_PREFIX', TABLE_PREFIX_ALL . 'en_');
		}
	
	}

}
else
{
	if(isset($_COOKIE['weenCompany_forelang'])){
		if($_COOKIE['weenCompany_forelang'] == 'en')
		{
			define('TABLE_PREFIX', TABLE_PREFIX_ALL . 'en_');
			$sitedefaultlang    = 'en';
		}
		else if($_COOKIE['weenCompany_forelang'] == 'cn')
		{
			define('TABLE_PREFIX', TABLE_PREFIX_ALL . '_');
			$sitedefaultlang    = 'cn';
		}
	}
	else
	{
		$getsitedefaultlang = $DB->query_first("SELECT value FROM " . TABLE_PREFIX_ALL . "_mainsettings WHERE varname = 'sitedefaultlang'");
		$sitedefaultlang    = $getsitedefaultlang['value'];
		if($sitedefaultlang == 'auto'){
			if (strstr(strtolower($_SERVER['HTTP_ACCEPT_LANGUAGE']), 'zh-cn') OR strstr(strtolower($_SERVER['HTTP_ACCEPT_LANGUAGE']), 'zh-tw'))
			{
				define('TABLE_PREFIX', TABLE_PREFIX_ALL . '_');
				$sitedefaultlang    = 'cn';
			}
			else
			{
				define('TABLE_PREFIX', TABLE_PREFIX_ALL . 'en_');
				$sitedefaultlang    = 'en';
			}
		}
		else if($sitedefaultlang == 'en')
		{
			define('TABLE_PREFIX', TABLE_PREFIX_ALL . 'en_');
		}
		else
		{
			define('TABLE_PREFIX', TABLE_PREFIX_ALL . '_');
		}
	}

}


if(!defined('TABLE_PREFIX'))
{
  define('TABLE_PREFIX', "");
}


$gettechnicalemail = $DB->query_first("SELECT value FROM " . TABLE_PREFIX . "mainsettings WHERE varname = 'technicalemail'");
$technicalemail    = $gettechnicalemail['value'];

$getversion = $DB->query_first("SELECT value FROM " . TABLE_PREFIX . "mainsettings WHERE  varname = 'sdversion'");
$cwsversion    = $getversion['value']; 


$getadmindir = $DB->query_first("SELECT value FROM " . TABLE_PREFIX . "mainsettings WHERE  varname = 'admin_dir'");

define('ADMIN_DIR', $getadmindir['value']);




if(defined('IN_ADMIN'))
{
  include($rootpath . ADMIN_DIR.'/adminfunctions.php');
}
else
{
  include_once($rootpath . 'includes/functions.php');
}

ini_set("magic_quotes_runtime", 0);




if(get_magic_quotes_gpc())
{
  if($_POST)   $_POST   = StripSlashesArray($_POST);
  if($_GET)    $_GET    = StripSlashesArray($_GET);
  if($_COOKIE) $_COOKIE = StripSlashesArray($_COOKIE);
}



if(defined('IN_ADMIN'))
{
  if($_POST)   $_POST   = AddSlashesArray($_POST);
  if($_GET)    $_GET    = AddSlashesArray($_GET);
  if($_COOKIE) $_COOKIE = AddSlashesArray($_COOKIE);
}



if(!defined('IN_ADMIN'))
{
  if($_POST)   $_POST   = PreClean($_POST);
  if($_GET)    $_GET    = PreClean($_GET);
  if($_COOKIE) $_COOKIE = PreClean($_COOKIE);
}




if(!$globalsoption = ini_get('register_globals'))
{
  @extract($_POST,    EXTR_SKIP);
  @extract($_GET,     EXTR_SKIP);
  @extract($_SERVER,  EXTR_SKIP);
  @extract($_FILES,   EXTR_SKIP);
  @extract($_ENV,     EXTR_SKIP);
  @extract($_COOKIE,  EXTR_SKIP);
}




$sdlanguage = GetLanguage(1);

$thisfiledirname = strtolower(substr(str_replace(dirname(dirname(dirname(__FILE__))), '', dirname(dirname(__FILE__))), 1));
$script_name = strtolower($_SERVER['SCRIPT_NAME']);

if (strstr($script_name, $thisfiledirname.'/')){
	$thiswebsitedir = str_replace(strstr($script_name, $thisfiledirname.'/'), '', $script_name);
	$weenurl = "http://". $_SERVER['HTTP_HOST'] . $thiswebsitedir . $thisfiledirname . '/';
}else{
	$weenurl = "http://". $_SERVER['HTTP_HOST'] . '/';
}




$usersystem = $DB->query_first("SELECT * FROM " . TABLE_PREFIX . "usersystems WHERE activated='1'");




if(defined('IN_ADMIN'))
{
  $getadmincookietime = $DB->query_first("SELECT value FROM " . TABLE_PREFIX . "mainsettings WHERE varname = 'admincookietimeout'");
  $mainsettings['admincookietimeout'] = $getadmincookietime['value'];
  include($rootpath . ADMIN_DIR.'/authenticate.php');
}



$smilieimagetexts = array();
$smilieimagepaths = array();

LoadSmilies($usersystem);

?>