<?php
ini_set('track_errors','1');
ini_set('display_errors', true);
error_reporting(E_ERROR | E_WARNING | E_PARSE);
set_magic_quotes_runtime(0);
define('ISDVBBS', TRUE);
define('DVBBS_SERVER_URL', 'http://server.dvbbs.net/');
define('DVBBS_PAYTO_URL', 'http://pay.dvbbs.net/');
$cercode_len=4; //验证码长度
$cercode_type=9; //如果只允许数字，设为9;允许数字和小写英文字符，设为35;允许数字和大小写英文字符，设为65
$cercode_width=200;//图片长度
$cercode_height=48;//图片高度
$cercode_image="swf";//gif,agif,jpg,png,swf
$cercode_agif_delay=20;//设为gif动画时，背景图延时
$cercode_agif_lastDelay=80;//设为gif动画时，验证码延时

!defined('ROOT_PATH') AND define('ROOT_PATH', "./");	//	如果你的PHP运行在windows上，并且论坛不正常，禁用此行代码
//如果你的 PHP 运行在 windows 上，并且论坛不正常，启用下述代码
	//define('ROOT_PATH', str_replace(array('\\', '//'), '/', realpath(dirname(__FILE__))).'/');

if(PHP_VERSION < '4.1.0') {
	$_GET = &$HTTP_GET_VARS;
	$_POST = &$HTTP_POST_VARS;
	$_COOKIE = &$HTTP_COOKIE_VARS;
	$_SERVER = &$HTTP_SERVER_VARS;
	$_ENV = &$HTTP_ENV_VARS;
	$_FILES = &$HTTP_POST_FILES;
	$_SESSION =& $HTTP_SESSION_VARS;
}
global $groupboardid,$useindexstatic_css,$membername;
$zliboutputenable = @ini_get('zlib.output_compression');
if (!$zliboutputenable AND function_exists('ob_gzhandler')) {
	$db_obstart = 1;
} else {
	$db_obstart = 0;
}
(!$zliboutputenable AND (1 === $db_obstart)) ? ob_start('ob_gzhandler') : ob_start();

define('INC_PATH', ROOT_PATH.'inc/');
!@is_dir(INC_PATH) AND exit('Cannot find inc directory '.INC_PATH);
require ROOT_PATH.'inc/constants_define.php';

require_once INC_PATH.'dv_clsmain.php';

require_once INC_PATH.'general_funcs.php';

define('MAGIC_QUOTES_GPC', get_magic_quotes_gpc());
$magic_quotes_gpc = MAGIC_QUOTES_GPC;
@extract(i_addslashes($_POST), EXTR_OVERWRITE);
@extract(i_addslashes($_GET), EXTR_OVERWRITE);
@extract(i_addslashes($_COOKIE), EXTR_OVERWRITE);
if(!$magic_quotes_gpc) {
	$_FILES = i_addslashes($_FILES);
}
//防止此变量被客户端有意覆盖
$magic_quotes_gpc = MAGIC_QUOTES_GPC;


if ( $_GET['comeurl'] != '' ){
		$comeurl = $_GET['comeurl'];
	}elseif( $_SERVER['HTTP_REFERER'] != '' ){
		$comeurl = $_SERVER['HTTP_REFERER'];
	}else{
		$comeurl = $fsetting['homepage']?$fsetting['homepage']:"index.php";
}

//通行证设置文件
if(isset($passport))unset($passport);
require_once CACHE_PATH.'passport.config.php';

//CC视频设置
if(isset($ccvideo))unset($ccvideo);
require_once CACHE_PATH.'ccvideo.config.php';

//奇虎组图插件配置
unset($qihoo);
if(file_exists(CACHE_PATH.'qihoo.config.php'))require_once CACHE_PATH.'qihoo.config.php';

$time_array = explode(' ', microtime());
$time_start = $time_array[1] + $time_array[0];

require_once CACHE_PATH.'forum_setting.php';
require_once CACHE_PATH.'forum_plus_honor.php';
$fsetting =& $_DCACHE['settings'];
$cercode_image=empty($fsetting['cercode_image'])?'swf':$fsetting['cercode_image'];

//	other
if (defined('UPLOAD_BASEDIR')) {
	$fsetting['forumuploadname'] = UPLOAD_BASEDIR;
}

$ScriptName = getScriptName();

//Start 伪静态支持
	//*
	if ((1 == $fsetting['bogushtml_settings']) AND (!empty($_GET['__is_apache_rewrite']) OR !empty($_GET['__is_iis_rewrite']))) {
	if(THIS_SCRIPT=='index'&&$fsetting['bogushtml_settings_forum']=='domain'){
		$lowfurl=strtolower($fsetting['forumurl']);
		if(false!==$pos=strpos($lowfurl,'/',7))$lowfurl=substr($lowfurl,0,$pos);
		$lowhost=strtolower($_SERVER['HTTP_HOST']);
		$issnamedomain=(strpos($lowfurl,$lowhost)!==false);
		$isreferfromdomain=(false!==strpos(strtolower($_SERVER['HTTP_REFERER']),$lowfurl));
		$isredirecttoindex=false;
		if($_SERVER['SCRIPT_URI']||$_SERVER['SCRIPT_URL']){
			if(false!==strpos(strtolower($_SERVER['SCRIPT_URI']),'index.php')||false!==strpos(strtolower($_SERVER['SCRIPT_URL']),'index.php'))$isredirecttoindex=true;
		}elseif($_SERVER['QUERY_STRING']==''&!$isreferfromdomain){
			$isredirecttoindex=true;
		}
		if(!$issnamedomain&&$isredirecttoindex){
			header("Location:{$fsetting['forumurl']}");
			exit;
		}
		$boardname=(false!==$pos=strpos($_SERVER['HTTP_HOST'],'.'))?substr($_SERVER['HTTP_HOST'],0,$pos):'';
		$boardid=$fsetting['bogushtml_settings_board'][$boardname];
	};


	$qs= str_replace(array('/','\\'),array('',''),$_GET['rewrite_url'])."&";
	
	if(preg_match('/[fbds]((?:\_[\w]*?[\_\.\&])|(?:[\d]+))?(?:t([\d]*))?(?:p([\d]*))?(?:i([\d]*))?(?:ri([\d]*))?(?:s([\d]*))?(?:k([\d]*))?.*(?:\#([^\.]*))?.*/i',$qs,$arr)==1){
		if($boardid){
			$_GET['boardid']=$boardid=intval($boardid);
		}elseif(substr($arr[1],0,1)=='_'){
			$boardname=str_replace(array('_','.','&'),array('','',''),$arr[1]);
			$_GET['boardid']=$boardid=intval($fsetting['bogushtml_settings_board'][$boardname]);
		}else{
			$_GET['boardid']=$boardid=intval($arr[1]);
		}
		
		$_GET['topicmode']=$topicmode=intval($arr[2]);
		$_GET['page']=$page =intval($arr[3]);	
		$_GET['id']=$id =intval($arr[4]);
		$_GET['replyid']=$replyid =intval($arr[5]);
		$_GET['star']=$star =intval($arr[6]);
		$_GET['skin']=$skin=intval($arr[7]);
	}

		if (!empty($_GET['__rewrite_arg']) AND ($_NEW_GET = explode('-', $_GET['__rewrite_arg']))) {
			$ScriptName = trim(str_replace(getDocumentRoot(true), '', getPathTranslated(true)));
		} else {
			parse_str(strtolower($_SERVER['QUERY_STRING']), $_NEW_GET);
		}
		if (!empty($_NEW_GET)) {
			$i= 0;
			if (is_numeric($_NEW_GET[$i])) {
				$_GET['boardid'] = $_NEW_GET[$i];
				$boardid = $_NEW_GET[$i];
				$i++;
			}
			if((count($_NEW_GET) == 3) || (count($_NEW_GET) == 7)){
				if (is_numeric($_NEW_GET[$i])) {
					$_GET['topicmode'] = $_NEW_GET[$i];
					$topicmode = $_NEW_GET[$i];
					$i++;
				}
			}
			if (is_numeric($_NEW_GET[$i])) {
				$_GET['page'] = $_NEW_GET[$i];
				$page = $_NEW_GET[$i];
				$i++;
			}
			if (is_numeric($_NEW_GET[$i])) {
				$_GET['id'] = $_NEW_GET[$i];
				$id = $_NEW_GET[$i];
				$i++;
			}
			if (is_numeric($_NEW_GET[$i])) {
				$_GET['replyid'] = $_NEW_GET[$i];
				$replyid = $_NEW_GET[$i];
				$i++;
			}
			if (is_numeric($_NEW_GET[$i])) {
				$_GET['star'] = $_NEW_GET[$i];
				$star = $_NEW_GET[$i];
				$i++;
			}
			if (is_numeric($_NEW_GET[$i])) {
				$_GET['skin'] = $_NEW_GET[$i];
				$skin = $_NEW_GET[$i];
				$i++;
			}
			unset($_NEW_GET);
		}
		
	}//*/
//End 伪静态支持

function illegaloffset_error_handler($errno, $errstr, $errfile, $errline)
{
	
	if ($errno != E_ERROR AND $errno != E_WARNING AND $errno != E_PARSE) {
		return;
	}
	if (0 == preg_match('/Illegal\s*offset/i', $errstr)) {
		return;
	}
	print ''.$errstr.' in '.basename(dirname($errfile)).'/'.basename($errfile).' on line '.$errline.'<br />';
}//end function illegaloffset_error_handler
set_error_handler('illegaloffset_error_handler');

function_exists('date_default_timezone_set') AND date_default_timezone_set('Asia/Shanghai');
!defined('TIME_NOW') AND define('TIME_NOW', time());

require_once CONFIG_PATH.'config.php';
defined('MAIN_DOMAIN_NAME') AND ($cookiedomain = MAIN_DOMAIN_NAME);
defined('DV_MUF_DB_HOST') AND ($dbhost = DV_MUF_DB_HOST);

header('Content-Type: text/html;charset='.$charset);

$istoptable=1;

require_once INC_PATH.'dv_clssql.php';

$db= new sqldb();
defined('DV_MUF_DB_HOST') AND ($dbhost = DV_MUF_DB_HOST);
$db->connect($dbhost, $dbuser, $dbpw, $dbname , $charset,$pconnect);

if(empty($_DCACHE['settings'])){
	if($_GET['reload'] != 1){
		@unlink(CACHE_PATH.'forum_setting.php');
		include_once INC_PATH.'BoardCache.class.php';
		$mycache =& new BoardCache($db);
		$mycache->createForumSetting();
		echo "<script>document.location.href='index.php?reload=1&ftime=".microtime()."';</script>";
		return;
	}
}

if($attackevasive) {
	include_once INC_PATH.'security.php';
}
$nowtimes = $timestamp = TIME_NOW;

$tempdir= dirname($_SERVER['PHP_SELF']."/");
if($tempdir != '/')
	$tempdir.= '/';
if( $_SERVER['SERVER_PORT'] == 80 ){
	$ForumUrl = "http://{$_SERVER['SERVER_NAME']}".$tempdir;
}else{
	$ForumUrl = "http://{$_SERVER['SERVER_NAME']}:{$_SERVER['SERVER_PORT']}".$tempdir;
}

$ScriptName = strtolower(basename($ScriptName));
$usertrueip = forumusertrueip();
$boardid = ( is_numeric($boardid) ? $boardid : 0 );

$forum_ads = $_DCACHE['forum_ads'];
if ( get_cookie("language") !='' ){
	$_lang = get_cookie("language");
	if (false !== strpos($_lang, '..')) {
		set_cookie("language", '');
	} else {
		$fsetting['lang'] = $_lang;
	}
}
$temp_css= $fsetting['css'];
if ( get_cookie("style_{$boardid}") !='' ){
	$_css = get_cookie("style_{$boardid}");
	if (false !== strpos($_css, '..')) {
		set_cookie("css", '');
	} else {
		$fsetting['css'] = $_css;
	}
}

$cssname = explode('/',$fsetting['css']);
$cssname = str_replace('.css','',$cssname[count($cssname)-1]);
$style_file = CACHE_PATH.'style/'.$cssname.'.php';
if (!is_file($style_file)) {
    exit('Cannot found style file "'.$style_file.'"!');
}
require_once $style_file;

$fsetting['styletpl'] = $_DCACHE['stylecss'][0];
$lang = load_lang($lang, 'global' );

@is_file(ROOT_PATH.'install/index.php') AND exit($lang['global.err.str3']);

if (!isset($fsetting['time_zone_supported']) OR true !== $fsetting['time_zone_supported']) {
	print $lang['global.err.str2'];
	exit;
}
$forumChanSetting = explode(',',$fsetting['chansetting']);
$settplurl = get_cookie("tpl_url");
$setimgurl = get_cookie("tpl_img_url");
$setboardstyle = get_cookie("css_style_url");
if (!empty($setimgurl)) {
	$imgurl = $setimgurl;
}elseif (strpos($_DCACHE['stylecss'][22],'templates')!==false){
	$imgurl = $_DCACHE['stylecss'][22];
}elseif (strpos($_DCACHE['stylecss'][21],'templates')!==false){
	$imgurl = $_DCACHE['stylecss'][21];
}
$styleurl = (!empty($setboardstyle)) ? $setboardstyle : $fsetting['css'];

$userid = intval(get_cookie("userid"));

function_exists('auto_login_by_passport') AND auto_login_by_passport();
($userid <= 0) AND ($userid = 0);

$membername = strip_tags(trim(get_cookie("username")));
$memberword = trim(get_cookie("password"));
$setleftbar = trim(get_cookie("setleftbar"));
if ( $setleftbar != '' && is_numeric($setleftbar) ){
	$fsetting['leftbar'] = $setleftbar;
}

//Start 默认的 COOKIE 超时时间
	$user_selected_cookiedate = get_cookie('selected_cookiedate');
	if (!is_numeric($user_selected_cookiedate)) {
		$user_selected_cookiedate = 24*3600;
		set_cookie('selected_cookiedate', $user_selected_cookiedate, $user_selected_cookiedate);
	} else {
		set_cookie('selected_cookiedate', intval($user_selected_cookiedate), $user_selected_cookiedate);
	}
//End 默认的 COOKIE 超时时间
if ($userid > 0) {
	$_COOKIE_USERID = $userid;
	$_COOKIE_USERNAME = $membername;
	$_COOKIE_USERPASSWD = $memberword;
	$_COOKIE_COME_TIME = get_cookie('cometime');
	$_COOKIE_CBOARDID = get_cookie('cboardid');
	$_COOKIE_SYS_USERNAME = get_cookie('sysusername');
	$_COOKIE_SYS_PASSWD = get_cookie('syspassword');
}

//获取和验证用户信息
$boardmaster = $superboardmaster = $master = $vipuser = $cls_issearch = $founduserper = $vipgroupuser = false;
$statuserid = get_cookie("statuserid");
if($statuserid=='' || !is_numeric($statuserid)){
	$statuserid = str_replace(".","",$usertrueip);
	$statuserid = $statuserid + $timestamp;
	set_cookie("statuserid",$statuserid,7200);
}
		//---------------------2007-8-30 添加字段userupfiledate----------------------------

if (($userid OR $membername) && strlen($memberword)==16){
	$query=$db->query("Select /*!40001 SQL_CACHE */ u.userid,u.username,u.userpassword,u.useremail,u.userpost,u.posttimelimit,u.usertopic,u.usersex,u.userface,u.userwidth,u.userheight,u.joindate,u.lastlogin,u.userlogins,u.lockuser,u.userclass,u.usergroupid,u.usergroup,u.userwealth,u.userep,u.usercp,u.userpower,u.userbirthday,u.userlastip,u.userdel,u.userisbest,u.userhidden,u.usermsg,u.ischallenge,u.usermobile,u.titlepic,u.usertitle,u.truepassword,u.usertoday,u.userupfiledate,u.usermoney,u.userticket,u.followmsgid,u.vip_startime,u.vip_endtime,u.userfav,o.id,o.actforip as getcode,o.boardid,o.ip,o.lastimebk,o.browser,o.usergroupid as nowgroupid From {$dv}user u,{$dv}online o Where u.userid=o.userid And u.userid=$userid");
	$userinfo = $db->fetch_array($query);
	if ($userinfo AND !$userid AND $membername) {
		$userid = $userinfo['userid'];
	}
	if ($memberword != $userinfo['truepassword'] || $userinfo['lockuser']==1 || $userinfo['usergroupid']==5){
		$myuserid = 1;
	}
	if($myuserid == 1){
		$query=$db->query("Select /*!40001 SQL_CACHE */ userid,username,userpassword,useremail,userpost,posttimelimit,usertopic,usersex,userface,userwidth,userheight,joindate,lastlogin,userlogins,lockuser,userclass,usergroupid,usergroup,userwealth,userep,usercp,userpower,userbirthday,userlastip,userdel,userisbest,userhidden,usermsg,ischallenge,usermobile,titlepic,usertitle,truepassword,usertoday,userupfiledate,usermoney,userticket,followmsgid,vip_startime,vip_endtime,userfav From {$dv}user Where userid=$userid");
		$userinfo = $db->fetch_array($query);
		if ($memberword != $userinfo['truepassword'] || $userinfo['lockuser']==1 || $userinfo['usergroupid']==5){
			$userid = 0;
		}else{
			$onlineexists = 1;
		}
	}
	if($userid>0){
		$userid = $userinfo['userid'];
		$usergroupid = $userinfo['usergroupid'];
		if ( $userinfo['nowgroupid'] == '' ){$userinfo['nowgroupid'] = $userinfo['usergroupid'];}
		switch($userinfo['usergroupid']){
			case 8:
				$vipuser = true;
				break;
			case 3:
				$boardmaster = true;
				break;
			case 2:
				$boardmaster = true;
				$superboardmaster = true;
				break;
			case 1:
				$master = true;
				$boardmaster = true;
				break;
		}
		
		//用户信息处理
		if ( $userinfo['usertoday'] == '' ){
			$db->query("Update {$dv}user Set usertoday='0|0|0|0|0' Where userid=$userid");
			$userinfo['usertoday'] = '0|0|0|0|0';
			$UserToday = array(0,0,0,0,0);
		}else{
			//2007-9-29
			$UserToday = explode('|',$userinfo['usertoday']);
			if ( count($UserToday) != 5 ){
				$db->query("Update {$dv}user Set usertoday='0|0|0|0|0' Where userid=$userid");
				$userinfo['usertoday'] = '0|0|0|0|0';
				$UserToday = array(0,0,0,0,0);
			}
		}
		

		if ($userinfo['vip_startime'] > 0){
			if ( dateDiff('d',$nowtimes,$userinfo['vip_startime']) > 0 ){
				$vipgroupuser = true;
			}else{
				if ( $usergroupid > 8 ){
					$userparentid = $db->scalar("SELECT parentgid FROM {$dv}usergroups WHERE usergroupid=$usergroupid");
					if ($userparentid == 5){
						$tquery=$db->query("Select /*!40001 SQL_CACHE */ usertitle,grouppic,usergroupid From {$dv}usergroups Where parentgid=3 And minarticle<={$userinfo[userpost]} Order By minarticle Desc Limit 1");
						if( $trs = $db->fetch_array($tquery) ){
							$db->query("Update {$dv}user Set userclass='{$trs[usertitle]}',titlepic='{$trs[grouppic]}',usergroupid='{$trs[usergroupid]}',vip_startime=null,vip_endtime=null Where userid=$userid");
						}
					}
				}else{
					$db->query("Update {$dv}user Set vip_startime=null,vip_endtime=null Where userid=$userid");
				}
				$userinfo['vip_startime'] = '';
				$userinfo['vip_endtime'] = '';
			}
		}

		if ( get_cookie("lastuserposttime") !='' ){
			$userinfo_Topic['dateandtime'] = get_cookie("lastuserposttime");
		}
		else{
			$query_Topic=$db->query("Select max(dateandtime) as dateandtime From {$dv}topic Where postuserid=$userid limit 1");
			$userinfo_Topic = $db->fetch_array($query_Topic);
			if($userinfo_Topic['dateandtime'] == '')
				$userinfo_Topic['dateandtime']= $nowtimes;
			set_cookie("lastuserposttime", $userinfo_Topic['dateandtime']);
		}

		if( ( dateDiff('d',$nowtimes,$userinfo_Topic['dateandtime']) != 0 ) AND (dateDiff('d',$nowtimes,$userinfo['userupfiledate']) != 0  or trim($userinfo['userupfiledate'])=='' )){
			set_cookie("lastuserposttime", $nowtimes);
			$db->query("Update {$dv}user Set usertoday='0|0|0|0|0',lastlogin='{$nowtimes}' Where userid=$userid");
			$userinfo['lastlogin'] = $nowtimes;
			$userinfo['usertoday'] = '0|0|0|0|0';
			$UserToday = array(0,0,0,0,0);
		}
		if (defined('THIS_SCRIPT') AND THIS_SCRIPT !== 'login') {
			$userhidden = $userinfo['userhidden'];
		}
		//删除不活动用户时间
		if ( $userhidden == 2 && dateDiff('S',$userinfo['lastlogin'],$nowtimes) > $fsetting['onlinetimeout']*60 ){
			$db->query("Update {$dv}user Set userlastip='{$usertrueip}',lastlogin='{$nowtimes}' Where userid=$userid");
			$userinfo['lastlogin'] = $nowtimes;
			require_once INC_PATH.'BoardCache.class.php';
			Create_online_boardmaster();// 生成在线版主、管理员、超版
		}
		$sendmsgnum = $sendmsgid = 0;
		$sendmsguser = '';
		if ( $userinfo['usermsg'] != '' ){
			$usermsg = explode('||',$userinfo['usermsg']);
			if ( count($usermsg) == 3 ){
				$sendmsgnum = intval($usermsg[0]);
				$sendmsgid = $usermsg[1];
				$sendmsguser = $usermsg[2];
			}
		}
		if ( $userinfo['followmsgid'] != '' ){
			$followmsgid = explode(',',$userinfo['followmsgid']);
			foreach( $followmsgid as $val ){
				if ( strlen($val) > 0 && strlen($val) < 50 && $val != '' ){
					$val = addslashes($val);
					eval("\$lang['user.str1']=\"{$lang['user.str1']}\";");
					eval("\$lang['user.str2']=\"{$lang['user.str2']}\";");
					$db->query("Insert into {$dv}message (incept,sender,title,content,sendtime,flag,issend) values ('{$val}','{$fsetting[forumname]}','{$lang[user.str1]}','{$lang[user.str2]}','{$nowtimes}',0,1)");
					$tquery=$db->query("Select /*!40001 SQL_CACHE */ id,sender From {$dv}message Where incept='{$val}' Order By id Desc Limit 1");
					$trs = $db->fetch_array($tquery);
					$tools_inceptid = $trs['id']. '||' .$trs['sender'];
					$tools_newincept=$db->scalar("Select /*!40001 SQL_CACHE */ Count(id) From {$dv}message Where flag=0 and issend=1 and delr=0 And incept='{$val}'");
					if ( !is_numeric($tools_newincept) || $tools_newincept == '' ){$tools_newincept = 0;}
					$tools_msginfo = $tools_newincept. '||' .$tools_inceptid;
					$tools_msginfo = addslashes($tools_msginfo);
					$db->query("Update {$dv}user Set usermsg='{$tools_msginfo}' Where username='{$val}'");
				}
			}
			$db->query("Update {$dv}user Set followmsgid='' Where userid=$userid");
			$userinfo['followmsgid'] = '';
		}
	}else{
		$userid = 0;
		$usergroupid = 7;
		//------------------------------2007-8-30 IvanSky guesttoday----------------------------------
		$Forum_guest_info_File_url = CACHE_PATH.'Forum_guest_info_File.php';
		if (file_exists($Forum_guest_info_File_url))
		{
			include_once $Forum_guest_info_File_url;
			$arrguest_info = $Forum_guest_info['guesttoday'];			
			$userinfo['usertoday'] = $arrguest_info[0];

			if ($arrguest_info[1] != strtotime(date("Y-m-d")))
			{
				require_once INC_PATH.'BoardCache.class.php';
				Create_Forum_guest_info($arrguest_info);
			}	
		}else{
				require_once INC_PATH.'BoardCache.class.php';
				Create_Forum_guest_info($arrguest_info);
		}
		$query=$db->query("Select /*!40001 SQL_CACHE */ id,boardid,ip,actforip as getcode,lastimebk,browser,usergroupid as nowgroupid From {$dv}online Where id = $statuserid");
		$userinfo = $db->fetch_array($query);
	}
}else{
	$userid = 0;
	$usergroupid = 7;
		//------------------------------2007-8-30 IvanSky guesttoday----------------------------------
		$Forum_guest_info_File_url = CACHE_PATH.'Forum_guest_info_File.php';
		if (file_exists($Forum_guest_info_File_url))
		{
			include_once $Forum_guest_info_File_url;
			$arrguest_info = $Forum_guest_info['guesttoday'];			
			$userinfo['usertoday'] = $arrguest_info[0];

			if ($arrguest_info[1] != strtotime(date("Y-m-d")))
			{
				include_once INC_PATH.'BoardCache.class.php';
				Create_Forum_guest_info($arrguest_info);
			}	
		}else{
				include_once INC_PATH.'BoardCache.class.php';
				Create_Forum_guest_info($arrguest_info);		
		}
	$query=$db->query("Select /*!40001 SQL_CACHE */ id,boardid,ip,actforip as getcode,lastimebk,browser,usergroupid as nowgroupid From {$dv}online Where id = $statuserid");
	$userinfo = $db->fetch_array($query);

}
include_once CACHE_PATH.'group/group_'.$usergroupid.'.php';
//多属性用户组处理
$isgroupselected = 0;
if ( $gp_parentgid == 4 && $gp_issetting != '' && $userid > 0 ){
	if ( $usergroupid != $userinfo['nowgroupid'] && strpos('|'.$gp_issetting.'|','|'.$userinfo['nowgroupid'].'|') !== false ){
		$usergroupid = $userinfo['nowgroupid'];
		switch($usergroupid){
			case 8:
				$vipuser = true;
				break;
			case 3:
				$boardmaster = true;
				break;
			case 2:
				$boardmaster = true;
				$superboardmaster = true;
				break;
			case 1:
				$master = true;
				$boardmaster = true;
				break;
		}
		$temp_gp_issetting = $gp_issetting;
		include_once CACHE_PATH.'group/group_'.$usergroupid.'.php';
		$gp_issetting = $temp_gp_issetting;
	}
	include_once CACHE_PATH.'group/group_all.php';
	$isgroupselected = 1;
}
/*
//有安全问题，已禁用
if ( $groupsetting[70] == 1 ){
	$master = true;
}//*/

//检测是否存在用户全局自定义设置
if($userid > 0)
	if( file_exists(CACHE_PATH.'group/user_0_'.$userid.'.php')){
		include_once CACHE_PATH.'group/user_0_'.$userid.'.php';
		$founduserper = true;
	}
if ( $boardid > 0 ){
	$query=$db->query("Select /*!40001 SQL_CACHE */ boardid,boardtype,parentid,parentstr,depth,rootid,child,boardmaster,readme,boarduser,board_setting,board_user,postnum,topicnum,todaynum,lastpost,allowpost,ishidden,ischeckout,isgroupsetting,rules,boardtopstr,audit_settings_id,cid From {$dv}board Where boardid=$boardid");
	if ($boardinfo = $db->fetch_array($query)){
		include_once CACHE_PATH.'board/board_all.php';
		$boardid = $boardinfo['boardid'];
		if(0!=($boardinfo["parentid"])){
			//get parant board info
			$parentboardinfo=$_DCACHE['all_forums'][$boardinfo["parentid"]];
		}
		$board_setid = $_DCACHE['all_forums']["{$boardid}"]['setting_id'];
		$board_settings = $_DCACHE['forum_settings']["{$board_setid}"]['setting'];
		$board_user = explode(',', $boardinfo['board_user']);
		
        $boardsettings46=intval($board_settings[46]);
        
        if($board_settings[46]>1){
        	$board_settings[46]=intval(!(($UserToday[0]&&$UserToday[0]%$board_settings[46]!=0||$userinfo['posttimelimit']+60<time())));
        }
		
			
		//广告数据部分
		$board_adsid = $_DCACHE['all_forums']["{$boardid}"]['ads_id'];
		$forum_ads = $_DCACHE['forum_settings']["{$board_adsid}"]['setting'];
		switch( $forum_ads[15] ){
			case 0:
				if ( $ScriptName == 'index.php' && $forum_ads[14] == 1 ){$forum_ads[14] = 1;}else{$forum_ads[14] = 0;}
				break;
			case 1:
				if ( $ScriptName == 'dispbbs.php' && $forum_ads[14] == 1 ){$forum_ads[14] = 1;}else{$forum_ads[14] = 0;}
				break;
			case 2:
				if ( ($ScriptName == 'dispbbs.php' || $ScriptName == 'index.php') && $forum_ads[14] == 1 ){$forum_ads[14] = 1;}else{$forum_ads[14] = 0;}
				break;
			case 3:
				$forum_ads[14] = 0;
				break;
		}
		if ($ScriptName != 'dispbbs.php' && $ScriptName != 'index.php'){$forum_ads[14] = 0;}
		//版面或用户版面自定义权限
		if ($boardinfo['isgroupsetting'] != '0' && $boardinfo['isgroupsetting'] != ''){
			$boardinfo['isgroupsetting'] = ','.$boardinfo['isgroupsetting'].',';
			if(strpos($boardinfo['isgroupsetting'],",".$usergroupid.",")!==false){
				include_once CACHE_PATH.'group/board_'.$usergroupid.'_'.$boardid.'.php';
			}
			if($userid !=0 && strpos($boardinfo['isgroupsetting'],",0_".$userid.",")!==false){
				include_once CACHE_PATH.'group/user_'.$boardid.'_'.$userid.'.php';
				$userpermission = $groupsetting;
				$founduserper = true;
			}
		}
		if ( $fsetting['css'] != $boardinfo['cid'] && $boardinfo['cid'] != '' ){
			$fsetting['css'] = $boardinfo['cid'];
			$cssnameARR = explode('/',$fsetting['css']);
			$cssname = str_replace('.css','',$cssnameARR[count($cssnameARR)-1]);
			require_once CACHE_PATH.'style/'.$cssname.'.php';
			if (!empty($setimgurl)) {
				$imgurl = $setimgurl;
			}elseif (strpos($_DCACHE['stylecss'][22],'templates')!==false){
				$imgurl = $_DCACHE['stylecss'][22];
			}elseif (strpos($_DCACHE['stylecss'][21],'templates')!==false){
				$imgurl = $_DCACHE['stylecss'][21];
			}

			$styleurl = (!empty($setboardstyle)) ? $setboardstyle : $fsetting['css'];

			$fsetting['styletpl'] = $_DCACHE['stylecss'][0];
		}

		if(intval($board_settings[2])==1){
			$tempboardid= $boardinfo["parentstr"];
			if($tempboardid != '0' && $tempboardid != ''){
				$tempquery=$db->query("Select /*!40001 SQL_CACHE */ boardid,parentid,boardmaster From {$dv}board Where boardid in($tempboardid)");
				while($tempboardinfo = $db->fetch_array($tempquery)){
					if(false !== strpos('|'.$tempboardinfo['boardmaster'].'|', '|'.$membername.'|')){
						$founduserper=true;
						break;							
					}
				}
			}
        }

        $parentboardmaster=empty($parentboardinfo)?"":$parentboardinfo["boardmaster"]."|";
		if($boardmaster!==true){
			chkboardlogin();
			if ('' !== $membername) {	//	判断版主权限
				(false !== strpos('|'.$boardinfo['boardmaster'].'|'.$parentboardmaster, '|'.$membername.'|')) AND ($boardmaster = true);
			}
		} else {	//	修正版主可以跨版面管理的问题
			(false === $master AND false === $superboardmaster) AND (false === strpos('|'.$boardinfo['boardmaster'].'|'.$parentboardmaster, '|'.$membername.'|')) AND ($boardmaster = false);
		}
		(false === $boardmaster)  AND chkboardlogin();
	}else{
		exit('Access denied.Sorry, can not found this board info.');
	}
	
} else {
	$board_user = explode(',',$fsetting['userpoint']);
}
$groupid= intval($groupid);
if ( $groupid > 0 ){
	include_once CACHE_PATH.'board/board_all.php';
	$board_settings = $_DCACHE['forum_settings'][$fsetting['indivgroup_set']]['setting'];
}
//每日数据更新
$gTimezoneSecondOffset = $fsetting['timeoffset'] * 3600;
if (intval(dateDiff('d', $fsetting['forum_uptime'], $nowtimes))==1) {
	//生日会员
	if(1 == $fsetting['showbirthuser']) {
		$userbirthday_m_d = gmdate('m-d', $nowtimes + getUserTimeZoneOffset());
		$query=$db->query("Select /*!40001 SQL_CACHE */ userid,username,year(now())-year(DATE_FORMAT(FROM_UNIXTIME(userbirthday), '%Y-%m-%d')) as userbirthday,DATE_FORMAT(FROM_UNIXTIME(userbirthday), '%m') as userbirthmonth From {$dv}user Where userbirthday IS NOT NULl AND userbirthday>28800 AND DATE_FORMAT(FROM_UNIXTIME(userbirthday), '%m-%d')='{$userbirthday_m_d}' Order By userid");
		$num_rows = $db->num_rows($query);
		$bir = 0;

		while($birthuser = $db->fetch_array($query)){
			$Setuserbirthmonth = '';
			$Setuserbirthmonth =  (!empty($birthuser['userbirthmonth']) ) ? $Setuserbirthmonth = $birthuser['userbirthmonth']: '1';
			$Setuserbirthmonth = (($Setuserbirthmonth < 10) and (strlen($Setuserbirthmonth) == 2) )?substr($Setuserbirthmonth, -1, 1) : $Setuserbirthmonth;
			$bir++;
			$birthusers .= ' <li><img src="images/birth/z'.$Setuserbirthmonth.'.gif" align=absmiddle border=0 ><a href=dispuser.php?id='.$birthuser['userid'].' title="{tpl.str101}'.$birthuser['userbirthday'].'{tpl.str102}" target="_blank">〖{tpl.str101} '.htmlspecialchars($birthuser['username']).' {tpl.str102}〗</a></li>';
		}

		
		if (!empty($birthusers))
		{
			$Settodaybirths = '
			<div class="bbs_column birthdaylist">
			<h2>{tpl.str74}（{tpl.str103} '.$num_rows.' {tpl.str104}）</h2>
			<ul>
			   '.$birthusers.'
			</ul>
			</div>

		   ';
		}
		$fsetting['birthuser'] = $Settodaybirths;
		$db->query("UPDATE {$dv}setup SET forum_birthuser='".$db->escape_string($Settodaybirths)."'");
	}

	$fsetting['yestodaynum'] = allyesterdays_index();
	if ( intval($fsetting['yestodaynum']) > intval($fsetting['maxpost']) ){
		$smst = ",forum_maxpostnum='{$fsetting[yestodaynum]}',forum_maxpostdate='{$fsetting[forum_uptime]}'";
		$fsetting['maxpost'] = $fsetting['yestodaynum'];
		$fsetting['maxpostdate'] = $fsetting['forum_uptime'];
	}
	$db->query("Update {$dv}setup Set forum_yesterdaynum='{$fsetting[yestodaynum]}'".$smst);//edit 2007-04-26
	$db->query("Update {$dv}board Set todaynum=0");
	if ( $boardid > 0 ){
		$boardinfo['todaynum'] = 0;
	}
	$db->query("Update {$dv}savvy_topic set solve=2 Where dateandtime<'".dateAdd('d',-15,gmdate('Y-m-d 23:59:59'), '')."' and boardid NOT IN (777,444)");//论坛知道过期问题
	include_once INC_PATH.'BoardCache.class.php';
	$mycache =& new BoardCache($db);
	$mycache->createForumSetting();
	Create_index_forumnum();
	Create_index_forumnum_group();
	update_group_all();
	Create_Forum_Group_top(5);
	Create_Forum_Topic_List(2,'');//创建首页右边贴子列表
	del_static_cache();				//清除缓存文件
}
function allyesterdays_index(){//昨天帖子数;
	global $lang,$dv,$db;
	$t_sql=$db->query("select tablename from {$dv}tablelist");
	while($t_arr=$db->fetch_array($t_sql)){
		$time1 = strtotime(date('Y-m-d 00:00:00'));
		$time2 = $time1 - 1;
		$time1 = $time1 - (24 * 3600);
		$yesday_num=$db->scalar("SELECT count(1) FROM ".$t_arr['tablename']." WHERE boardid!=444 and boardid!=777 AND (dateandtime between ".$time1." and ".$time2.")");
		$yes_count+=$yesday_num;
	}
	return ($yes_count);
}

unset($_DCACHE['settings']);
function _timeout($var=0){
	global $lang;
	$timestamp = time();
	$timeoffset = 8;
	$timenow = array('time' => gmdate("Y-n-j H:i", $timestamp + 3600 * $timeoffset),'offset' => ($timeoffset >= 0 ? ($timeoffset == 0 ? '' : '+'.$timeoffset) : $timeoffset));
	$thetimenow = '(GMT '.($timeoffset > 0 ? '+' : '').$timeoffset.') '.gmdate("Y-n-j H:i", $timestamp + $timeoffset * 3600);
	$_msg = str_replace("thetimenow",$thetimenow,$lang['login_timeoffset']);
	$_msg = str_replace("n",'\n',$_msg);
	$_msg = '<script type="text/javascript">
		function dvbbsf(){
		var mydate = new Date();
		var mytimestamp = parseInt(mydate.valueOf() / 1000);
		if(Math.abs(mytimestamp - '.$timestamp.') > 86400) {
			window.alert("'.$_msg.'");
		}
		}
		'.($var==1?'dvbbsf();':'').'
		</script>';
	echo $_msg;
}

if($temp_css == $styleurl)
	$useindexstatic_css= true;
else
	$useindexstatic_css= false;
?>