<?php
session_start();
set_time_limit(1000);

if(!is_file(str_replace("\\",'/',dirname(__FILE__)).'/data/config.inc.php'))
{
	echo '<SCRIPT LANGUAGE="JavaScript">
	<!--
		window.location="install/index.php";
	//-->
	</SCRIPT>';
	exit;
}

require('inc/common.inc.php');

require(ROOT_PATH.'/inc/session.class.php');
$session=new session();
if($GLOBALS['setting']['seo_rewrite'])
{
	$var=explode('-',str_replace('/','-',$_REQUEST['repparam']));
	
	foreach($var as $p)
	{
		$param=explode('_',$p);
		$_REQUEST[$param[0]]=$param[1];
		$_GET[$param[0]]=$param[1];
	}
	
}

//³ÇÊÐ

if(isset($_REQUEST['cityid']))
{
	$defaultcity=$_REQUEST['cityid'];
}
else
{
	if(!$GLOBALS['session']->get('cityid'))
	{
		if($GLOBALS['setting']['auto_city'])
		{
			//$defaultcity=ip2city(real_ip(),ROOT_PATH.'/data/ipdata/ipdata.dat',$GLOBALS['city']);		
			$defaultcity=Pinyin(ip2city());		
			if($defaultcity=='quanguo')
			{
				if($GLOBALS['setting']['site_default_city'])
				{
					$defaultcity=$GLOBALS['setting']['site_default_city'];
				}
				else
				{
					$defaultcity='quanguo';
				}
			}
		}
		else
		{
			if($GLOBALS['setting']['site_default_city'])
			{
				$defaultcity=$GLOBALS['setting']['site_default_city'];
			}
			else
			{
				$defaultcity='quanguo';
			}
		} 
	}
	else
	{
		$defaultcity=$GLOBALS['session']->get('cityid')?$GLOBALS['session']->get('cityid'):'quanguo';
	}
}
$nowcityid=strtolower($defaultcity);
$nowcity=$GLOBALS['city'][$nowcityid]['cityname'];

$GLOBALS['session']->set(array('cityid'=>$defaultcity));
//My Info
if($session->get('uid')>0)
{
	$userinfo=$db->fetch_first('select money,score,username,ucid,mobile,usertype,verification,lastip,lastlogin,email,uid from '.tname('user').' where  uid='.$session->get('uid'));
}
if(!empty($_GET['uid']))
{
	$GLOBALS['session']->set(array('friendid'=>intval($_GET['uid'])));
}
$controller=(empty($_REQUEST['con'])?'index':$_REQUEST['con']);
if(!empty($GLOBALS['setting']['adminpath']) && $GLOBALS['setting']['adminpath']!='admin' && $_REQUEST['con']=='admin' && empty($_REQUEST['pluginid']))
{
	$controller='index';
	$action='index';
}

$action=empty($_REQUEST['act'])?'index':$_REQUEST['act'];
if(!empty($_REQUEST['pluginid']))
{
	$pfile=ROOT_PATH.'/plugins/'.$_REQUEST['pluginid'].'/controls/'.$controller.'.class.php';
	
	//Plugins
	if(!is_file($pfile))
	{
		$controller='index';
		$action='index';
		require(ROOT_PATH.'/controls/'.$controller.'.class.php');
	}
	else
	{
		require($pfile);
	}
}
else
{
	//Program
	if(!is_file(ROOT_PATH.'/controls/'.$controller.'.class.php'))
	{
		$controller='index';
		$action='index';
	}
	require(ROOT_PATH.'/controls/'.$controller.'.class.php');
	
}

$conclass=$controller.'_controller';
$actfunc=$action.'_action';
$views=new $conclass;
$views->$actfunc();
