<?php
define('THIS_SCRIPT', 'dv_news');
include_once 'global.php';
include_once CACHE_PATH.'board/board_all.php';
include_once INC_PATH.'BoardCache.class.php';
include_once CACHE_PATH.'forum_pic.php';

$lang = load_lang($lang, 'dv_news' );
global $lang,$lockurl;
PageLoad();
function PageLoad(){
	global $lang,$dv,$db,$lockurl,$get_name,$forum_setting,$_DCACHE;
/*@ 说明：只允许调用网址,要以"HTTP://"开头,为空则不限制所有外部调用.(可允许多网址限制，要以","分隔。)
  @ 使用：例如只允许此两个网址调用: lockurl="http://www.artistsky.net/,http://www.artbbs.net/"
*/
	$lockurl="";
	if(check_server($lockurl)==false){
		show_data(fixjs($lang['sys.info1']));
	exit;
	}
	load_main();
}
function load_main(){ 
	global $lang,$get_name;
	$get_name=$_GET['get_name'];
	if(count($get_name)<=0 or count($get_name)==""){
		show_data(fixjs($lang['sys.info2']));
	exit;
	}
	$file_info=Load_File();
	$row_num=count($file_info);
	for($i=0;$i<$row_num;$i++){
		$row_info=explode($lang['exp.col'],$file_info[$i]);
		$col_num=count($row_info);
		for($j=0;$j<$col_num;$j++){				
			if($get_name[$j]==$row_info[0]){
				if(intval($row_info[3])>0){
					stan_type($row_info[3],htmlspecialchars($file_info[$i]));//调用的类型;
				}
			}
		}
	}
}
function Load_File(){//打开文件，读出信息;
	global $lang,$record_row;
	$record_row=array();
	if($fp=@fopen($lang['tran_dir'],'r')){
		if(filesize($lang['tran_dir'])===0){
			show_data(fixjs($lang['sys.info1']));
		exit;
		}
		else{
			$recordset=fread($fp,filesize($lang['tran_dir']));
			$record_row=explode($lang['exp.row'],$recordset);
			@fclose($fp);
		}
	}
	return $record_row;
}
function show_data($info_str){	
	echo "document.write(\"";
	echo $info_str;
	echo "\");";
	echo "\r\n";
}

function get_AD_boardid($getFirst,$boardid,$boarder_limit=0) 
{
	global $dv, $db ;	
	if (  !empty ( $boardid )  )
	{
		$stmt=$db->query("select boardid,parentid,parentstr,ishidden from {$dv}board where parentid={$boardid} ");
		$getBoardid = array();		
		while ($arr=$db->fetch_array($stmt))
		{
			
			if ($boarder_limit==1)
			{
				if (!empty($arr[boardid]) and trim($arr[ishidden])==0)
				{
					$getBoardid[] = $arr[boardid];
					$getBoardid = array_merge((array)get_AD_boardid(2,$arr['boardid']), (array)$getBoardid);				
				}

			}else {
				if (!empty($arr[boardid]))
				{
					$getBoardid[] = $arr[boardid];
					$getBoardid = array_merge((array)get_AD_boardid(2,$arr['boardid']), (array)$getBoardid);
				}
			}
		}
	}
   if ($getFirst==1)return $getBoardid = array_merge((array)$boardid, (array)$getBoardid);
   else if (count($getBoardid)>0)return $getBoardid;
}


function stan_type($type,$tran_info){	
	global $lang;
	switch(intval($type)){
		case 1:
			forum_stan($tran_info);//帖子调用
		break;
		case 2:
			info_stan($tran_info);//信息调用
		break;
		case 3:
			space_stan($tran_info);//版块调用
		break;
		case 4:
			member_stan($tran_info);//会员调用
		break;
		case 5:
			ad_stan($tran_info);//公告调用
		break;
		case 6:
			setout_stan($tran_info);//展区调用
		break;
		default:
			show_data(fixjs($lang['sys.info2']));
	}
}
function forum_stan($info){
	global $lang,$dv,$db,$_DCACHE;
	$info_list=explode($lang['exp.col'],$info);
	if($info_list[7]==""){
		show_data(fixjs($lang['sys.info3']));
	exit;
	}
	if($info_list[12]=="" or !is_numeric($info_list[12])){
		$topic_total=10;//显示记录数;
	}
	else{
		$topic_total=intval($info_list[12]);
	}
	if($info_list[13]=="" or !is_numeric($info_list[13])){
		$topic_len=10;//显示标题长度;
	}
	else{
		$topic_len=intval($info_list[13]);
	}

	//----------------------------2007-8-19 ivan  版面的限制-------------------------------------
	$boarder_limit = $info_list[19];

	if($boarder_limit==1)
	{
		$view_ishidden=" ishidden=0 ";//显示所有数据=0 不显示特殊版面数据=1
	}
	else{
		$view_ishidden='';
	}
	
	$board_start=$info_list[6];
	$board_end=$info_list[8];
	$forum_order=intval($info_list[14]);//帖子排序
	switch(intval($forum_order)){
		case 0:
			$order="dateandtime";
		break;
		case 1:
			$order="lastsmstime"; 
		break;
		case 2:
			$order="lastposttime";
		break;
		case 3:
			$order="hits";
		break;
		default:
			$order="dateandtime";
		break;
	}
	//----------------------------2007-8-17 ivan-------------------------------------
	$limit_day=!empty($info_list[15])?$info_list[15]:NULL;//天数的限制
	if (!empty($limit_day) and !empty($order) )
	{
		settype($limit_day, "integer"); 
		$limit_day_start=time();
		$limit_day_end=mktime(0,0,0,date('m'),date('d')-intval($limit_day),date('Y'))+24*3600;
		//if ( $limit_day < 0 ) {$strsign_s=">=";$strsign_e="<=";}else{$strsign_s="<=";$strsign_e=">=";}
		$limit_day_sql=" (dateandtime <= ".$limit_day_start." and dateandtime >= ".$limit_day_end.") and ";
	} 
	else $limit_day_sql="";

	//----------------------------2007-8-18 ivan  显示的类型------------------------------------
	$view_type=$info_list[16];
	switch(intval($view_type)){
		case 0:
			$v_type=" isbest='0' and ";
		break;
		case 1:
			$v_type=" isbest='1' and "; 
		break;
		case 2:
			$v_type="2";
		break;
	}
	//----------------------------2007-8-16 ivan  版面 设置------------------------------------
	$boarder_setup=$info_list[18];

	//----------------------------2007-8-16 ivan  调用的版面------------------------------------
	$stan_boarder=$info_list[17];//调用的版面：	
	switch( intval( $boarder_setup ) )
	{
		case 0:
			if (!empty($stan_boarder))
				$boardidstr= " boardid in (".intval( $stan_boarder ).") and ";		
		break;
		case 1:
			$adboardid=get_AD_boardid(2,$stan_boarder,$boarder_limit); //不获取本版面ID
			sort($adboardid);
			$adboardid = $db->escape_string(implode(',',$adboardid));
			if (!empty($adboardid))
				$boardidstr= " boardid in (".$adboardid.") and ";		
		break;
		case 2:
			$adboardid=get_AD_boardid(1,$stan_boarder,$boarder_limit); //获取本版面ID和全部
			sort($adboardid);
			$adboardid = $db->escape_string(implode(',',$adboardid));
			if (!empty($adboardid))
				$boardidstr= " boardid in (".$adboardid.") and ";		
		break;
	}
	
	//----------------------------2007-8-17 ivan-------------------------------------
	$solitude_userid=!empty($info_list[20])?$info_list[20]:NULL;//单独用户ID
	if (!empty($solitude_userid) )
	{
		$solitude_userid = strtolower($solitude_userid);
		$solitude_userid = str_replace("，",",",$solitude_userid);
		$solitude_userid_arr = explode(",",$solitude_userid);
		if (count($solitude_userid_arr)>=0)
		{
			foreach($solitude_userid_arr as $struserid){				
				if (!empty($struserid))
				$user_topic.="postusername='".$struserid."' or ";
			}
			if (!empty($user_topic))$user_topic="(".substr($user_topic,0,-4).") and ";					
		}
	}

	$dispaceurl=$info_list[7];
	if ( (is_numeric($v_type) and $v_type==2))
	{
		$user_topic = str_replace("postusername","B.postusername",$user_topic);		
		$boardidstr = str_replace("boardid","B.boardid",$boardidstr);		
		$limit_day_sql = str_replace("dateandtime","B.dateandtime",$limit_day_sql);		
		IF($order=="dateandtime") $order = str_replace("dateandtime","A.dateandtime",$order);		
		IF($order=="lastsmstime") $order = str_replace("lastsmstime","B.lastsmstime",$order);		
		IF($order=="lastposttime") $order = str_replace("dateandtime","B.lastposttime",$order);		
		IF($order=="hits") $order = str_replace("dateandtime","B.hits",$order);		
		
		$sql_s="SELECT B.postusername,A.topic,B.title,B.topicid,B.boardid,B.dateandtime,B.topicid,B.hits,B.expression,B.lastpost  FROM {$fsetting['nowtablename']} A, {$dv}topic B /*!32312 USE INDEX(PRIMARY)*/ WHERE ".$user_topic.$boardidstr.$limit_day_sql." A.rootid=B.topicid and B.boardid<>444 and B.boardid<>777   order by ".$order." desc";
	}else{
		$sql_s="SELECT postusername,title,topicid,boardid,dateandtime,topicid,hits,expression,lastpost FROM {$dv}topic /*!32312 USE INDEX(PRIMARY)*/ WHERE ".$user_topic.$boardidstr.$v_type.$limit_day_sql." boardid<>444 and boardid<>777 order by ".$order." desc";	
	}
	
	
	$sql=$db->query($sql_s,array('pageSize'=>$topic_total));
	while ($arr=$db->fetch_array($sql)){
		$show_info=str_replace('{$id}',$arr['topicid'],$dispaceurl);
		$show_info=str_replace('{$replyid}',$arr['topicid'],$show_info);
		$show_info=str_replace('{$boardid}',$arr['boardid'],$show_info);
		$show_info=str_replace('{$id}',$arr['topicid'],$show_info);
		$expression = $arr['expression'];
		If(strpos($expression,"|")!==false){
			$expression=explode("|",$arr['expression']);
			$expression="<img border=0 src=/{$_DCACHE[forum_postface][0]}{$expression[1]}  alt={$lang['tpl.str86']}>";
		}
		//----------------2007-8-18 ivan---------------------------------------
		if ( is_numeric($v_type) and $v_type=2 )
			$strtitle=!empty($arr['topic'])?$arr['topic']:$arr['title'];
		else
			$strtitle=$arr['title'];
		
		if(strlen($strtitle)>$topic_len)
			$title_len=more_substr(htmlspecialchars($strtitle),0,$topic_len)."...";
		else
			$title_len=$strtitle;

		if(!empty($arr['lastpost'])){
			$last_post=explode("$",$arr['lastpost']);
			$lastpost_name=$last_post[0];
			$lastpost_time=$last_post[2];
		}

		switch (intval($info_list[4])){
			case 0:
				$time_format=gmdate('Y-m-d H:i:s', $arr['dateandtime']+getUserTimeZoneOffset());
			break;
			case 1:
				$time_format=gmdate($lang['tpl.str1'], $arr['dateandtime']+getUserTimeZoneOffset());
			break;
			case 2:
				$time_format=gmdate('Y-n-j', $arr['dateandtime']+getUserTimeZoneOffset());
			break;
			case 3:
				$time_format=gmdate('H-M-S', $arr['dateandtime']+getUserTimeZoneOffset());
			break;
			case 4:
				$time_format=gmdate('h:m', $arr['dateandtime']+getUserTimeZoneOffset());
			break;
		}
		if($stan_boarder==0){//所有版面
			$board_info=$_DCACHE['all_forums'][$arr['boardid']];
			$end_boardid='';
			$wh='';
		}
		else{
			$board_info=&$_DCACHE['all_forums'][$stan_boarder];
			$wh=" where boardid=";
			$end_boardid=$board_info['boardid'];
		}
		if($wh==''){
			if($view_ishidden==''){
				$sql_readme=$db->scalar("select readme from {$dv}board");
			}
			else{				
				$sql_readme=$db->scalar("select readme from {$dv}board where".$view_ishidden.""); 
			}
		}
		else{
			if($view_ishidden==''){
				$sql_readme=$db->scalar("select readme from {$dv}board".$wh.$end_boardid."");
			}
			else{
				$sql_readme=$db->scalar("select readme from {$dv}board".$wh.$end_boardid." and ".$view_ishidden.""); 	
			}
		}
		$show_info=str_replace('{$boardname}',$board_info['boardtype'],$show_info);
		$show_info=str_replace('{$boardinfo}',$sql_readme['readme'],$show_info);
		$show_info=str_replace('{$topic}',$title_len,$show_info);
		$show_info=str_replace('{$face}',$expression,$show_info);
		$show_info=str_replace('{$replyname}',$lastpost_name,$show_info);
		$show_info=str_replace('{$replytime}',gmdate('Y-m-d H:i:s', $lastpost_time+getUserTimeZoneOffset()),$show_info);
		$show_info=str_replace('{$username}',$arr['postusername'],$show_info);
		$show_info=str_replace('{$posttime}',$time_format,$show_info);
		$mem_str.=$show_info;
	}
	$mem_str=$board_start.$mem_str.$board_end;
	show_data(fixjs($mem_str));
}
function info_stan($info){
	global $lang,$dv,$db,$forum_setting,$fsetting;
	$info_list=explode($lang['exp.col'],$info);
	$board_start=$info_list[6];
	$board_end=$info_list[8];
	$t_sql=$db->query("select tablename from {$dv}tablelist");
	while($t_arr=$db->fetch_array($t_sql)){
		$time1 = dv_gmtimestamp(gmdate('Y-m-d 00:00:00'));
		$time2 = $time1 + (24 * 3600 - 1);
		$today_num=$db->scalar("SELECT count(1) FROM ".$t_arr['tablename']." WHERE boardid!=444 and boardid!=777 AND (dateandtime between ".$time1." and ".$time2.")");
		$to_count+=$today_num;//今日贴子数;
	}	
	$sql=$db->query("SELECT id,forum_setting,forum_ads,forum_badwords,forum_rbadword,forum_maxonline,forum_maxonlinedate,forum_topicnum,forum_postnum,forum_todaynum,forum_usernum,forum_yesterdaynum,forum_maxpostnum,forum_maxpostdate,forum_lastuser,forum_lastpost,forum_birthuser,forum_sid,forum_version,forum_nowusebbs,forum_isinstall,forum_challengepassword,forum_channame,forum_chansetting,forum_lockip,forum_cookiespath,forum_boards,forum_alltopnum,forum_pack,forum_cid,forum_avasiteid,forum_avasign,forum_adminfolder,forum_boardxml,forum_css,forum_face,forum_tpl FROM {$dv}setup");
	$arr=$db->fetch_array($sql);
	$online=$db->scalar("SELECT count(1) FROM {$dv}online WHERE userid>0");
	//$dispaceurl=main_cycdeal($info_list[7]);
	$dispaceurl=$info_list[7];
	$show_info=str_replace('{$topicnum}',$arr['forum_topicnum'],$dispaceurl);
	$show_info=str_replace('{$postnum}',$arr['forum_postnum'],$show_info);
	$show_info=str_replace('{$joinmembers}',$arr['forum_usernum'],$show_info);
	$show_info=str_replace('{$allonline}',$online,$show_info);
	$show_info=str_replace('{$lastuser}',$arr['forum_lastuser'],$show_info);
	$show_info=str_replace('{$todaypostnum}',$to_count,$show_info);
	$show_info=str_replace('{$yesterdaypostnum}',$arr['forum_yesterdaynum'],$show_info);
	$show_info=str_replace('{$toppostnum}',$arr['forum_maxpostnum'],$show_info);
	$show_info=str_replace('{$toponline}',$arr['forum_maxonline'],$show_info);
	$show_info=str_replace('{$buildday}',$fsetting[forumstarttime],$show_info);
	$bodyinfo=$board_start.$show_info.$board_end;
	show_data(fixjs($bodyinfo));
}
function space_stan($info){
	global $lang,$dv,$db,$_DCACHE;
	$info_list=explode($lang['exp.col'],$info);
	if($info_list[7]==""){
		show_data(fixjs($lang['sys.info4']));
	exit;
	}
	$dvboard_fielt="boardid,boardtype,showtype,parentid,parentstr,depth,rootid,child,readme,boardmaster,postnum,topicnum,indeximg,todaynum,boarduser,lastpost,orders,board_setting,board_user,isgroupsetting,boardtopstr,cid,rules,allowpost,ishidden,ischeckout,ads_id,setting_id,audit_settings_id";
	$depth=$info_list[14];
	$orders=$info_list[12];
	$boardtab=$info_list[13];
	if($depth==""){
		$depth=20;
	}
	if($orders==1 and $depth>1){
		$depth=1;
		if($boardtab==""){
			$boardtab=5;
		}
	}
	$board_start=$info_list[6];
	$board_end=$info_list[8];
	$parentid=0;
	$d_sign=",";
	$i=0;
	$board_id=$info_list[15];
	$board_body=$info_list[7];
	$section_sign=$info_list[17];//区版块前标识符
	$child_sign=$info_list[18];//子版块前标识符：
	$fluctuate_sign=$info_list[19];//上下级版块间隔
	$homopolarity_sign=$info_list[20];//同级版块间隔
	if(intval($info_list[12])==1){//树型;
		$first_sql=$db->query("SELECT ".$dvboard_fielt." FROM {$dv}board WHERE boardid=".$board_id."");
		while ($first_board=$db->fetch_array($first_sql)) {
			$first_info=str_replace('{$boardid}',$first_board['boardid'],$board_body);
			$first_info=str_replace('{$boardname}',$first_board['boardtype'],$first_info);
			$first_info=str_replace('{$boardinfo}',$first_board['readme'],$first_info);
			$first_info=str_replace('{$boardchild}',$first_board['child'],$first_info);
			$first_info=str_replace('{$postnum}',$first_board['postnum'],$first_info);
			$first_info=str_replace('{$topicnum}',$first_board['topicnum'],$first_info);
			$first_info=str_replace('{$todaynum}',$first_board['todaynum'],$first_info);
			$first_info=str_replace('{$rules}',$first_board['rules'],$first_info);
			$first_infoset.=$first_info.$lang['dvnews.info3'];
		}
		$second_sql=$db->query("select ".$dvboard_fielt." from {$dv}board where parentid=".$board_id." order by orders");
		while ($second_board=$db->fetch_array($second_sql)) {
			$sql=$db->query("SELECT ".$dvboard_fielt." FROM {$dv}board WHERE parentstr like '%".$board_id.$d_sign.$second_board['boardid']."%' order by boardid");
			while ($three_board=$db->fetch_array($sql)) {
				$three_info=str_replace('{$boardid}',$three_board['boardid'],$board_body);
				$three_info=str_replace('{$boardname}',$three_board['boardtype'],$three_info);
				$three_info=str_replace('{$boardinfo}',$three_board['readme'],$three_info);
				$three_info=str_replace('{$boardchild}',$three_board['child'],$three_info);
				$three_info=str_replace('{$postnum}',$three_board['postnum'],$three_info);
				$three_info=str_replace('{$topicnum}',$three_board['topicnum'],$three_info);
				$three_info=str_replace('{$todaynum}',$three_board['todaynum'],$three_info);
				$three_info=str_replace('{$rules}',$three_board['rules'],$three_info);
				$three_infoset.=$lang['dvnews.info1'].$fluctuate_sign.$child_sign.$three_info."<br>";
				$i+=1;
			}
			$second_info=str_replace('{$boardid}',$second_board['boardid'],$board_body);
			$second_info=str_replace('{$boardname}',$second_board['boardtype'],$second_info);
			$second_info=str_replace('{$boardinfo}',$second_board['readme'],$second_info);
			$second_info=str_replace('{$boardchild}',$second_board['child'],$second_info);
			$second_info=str_replace('{$postnum}',$second_board['postnum'],$second_info);
			$second_info=str_replace('{$topicnum}',$second_board['topicnum'],$second_info);
			$second_info=str_replace('{$todaynum}',$second_board['todaynum'],$second_info);
			$second_info=str_replace('{$rules}',$second_board['rules'],$second_info);
			if($i>0){
				$second_infolist.=$lang['dvnews.info2'].$child_sign.$second_info."<br>".$three_infoset;
				$i=0;
			}
			else{
				$second_infolist.=$lang['dvnews.info2'].$child_sign.$second_info."<br>";
			}
		}
		$allshow_info=$section_sign.$first_infoset."<br>".$second_infolist;
	}
	else{//平板
		$first_sql=$db->query("SELECT ".$dvboard_fielt." FROM {$dv}board WHERE boardid=".$board_id."");
		while ($first_board=$db->fetch_array($first_sql)) {
			$first_info=str_replace('{$boardid}',$first_board['boardid'],$board_body);
			$first_info=str_replace('{$boardname}',$first_board['boardtype'],$first_info);
			$first_info=str_replace('{$boardinfo}',$first_board['readme'],$first_info);
			$first_info=str_replace('{$boardchild}',$first_board['child'],$first_info);
			$first_info=str_replace('{$postnum}',$first_board['postnum'],$first_info);
			$first_info=str_replace('{$topicnum}',$first_board['topicnum'],$first_info);
			$first_info=str_replace('{$todaynum}',$first_board['todaynum'],$first_info);
			$first_info=str_replace('{$rules}',$first_board['rules'],$first_info);
			$first_infoset.=$first_info.$lang['dvnews.info3'];
		}
		$second_sql=$db->query("select ".$dvboard_fielt." from {$dv}board where parentid=".$board_id." order by orders");
		while ($second_board=$db->fetch_array($second_sql)) {
			$sql=$db->query("SELECT ".$dvboard_fielt." FROM {$dv}board WHERE parentstr like '%".$board_id.$d_sign.$second_board['boardid']."%' order by boardid");
			while ($three_board=$db->fetch_array($sql)) {
				$three_info=str_replace('{$boardid}',$three_board['boardid'],$board_body);
				$three_info=str_replace('{$boardname}',$three_board['boardtype'],$three_info);
				$three_info=str_replace('{$boardinfo}',$three_board['readme'],$three_info);
				$three_info=str_replace('{$boardchild}',$three_board['child'],$three_info);
				$three_info=str_replace('{$postnum}',$three_board['postnum'],$three_info);
				$three_info=str_replace('{$topicnum}',$three_board['topicnum'],$three_info);
				$three_info=str_replace('{$todaynum}',$three_board['todaynum'],$three_info);
				$three_info=str_replace('{$rules}',$three_board['rules'],$three_info);
				$three_infoset.=$lang['dvnews.info3'].$fluctuate_sign.$child_sign.$three_info.$lang['dvnews.info3'];
				$i+=1;
			}
			$second_info=str_replace('{$boardid}',$second_board['boardid'],$board_body);
			$second_info=str_replace('{$boardname}',$second_board['boardtype'],$second_info);
			$second_info=str_replace('{$boardinfo}',$second_board['readme'],$second_info);
			$second_info=str_replace('{$boardchild}',$second_board['child'],$second_info);
			$second_info=str_replace('{$postnum}',$second_board['postnum'],$second_info);
			$second_info=str_replace('{$topicnum}',$second_board['topicnum'],$second_info);
			$second_info=str_replace('{$todaynum}',$second_board['todaynum'],$second_info);
			$second_info=str_replace('{$rules}',$second_board['rules'],$second_info);
			if($i>0){
				$second_infolist.=$section_sign.$first_infoset.$lang['dvnews.info3'].$child_sign.$second_info.$lang['dvnews.info3'].$three_infoset."<br>";
				$i=0;
			}
			else{
				$second_infolist.=$section_sign.$first_infoset.$lang['dvnews.info3'].$child_sign.$second_info."<br>";
			}
		}
		$allshow_info=$second_infolist;		
	}
	$boardindo=$board_start.$allshow_info.$board_end;
	show_data(fixjs($boardindo));
}
function member_stan($info){
	global $lang,$dv,$db;
	$info_list=explode($lang['exp.col'],$info);
	if($info_list[7]==""){
		show_data(fixjs($lang['sys.info5']));
		exit;
	}
	$board_start=$info_list[6];
	$board_end=$info_list[8];
	if($info_list[12]=="" or !is_numeric($info_list[12])){
		$topic_total=10;//显示记录数;
	}
	else{
		$topic_total=intval($info_list[12]);
	}
	switch (intval($info_list[13])){
		case 0:
			$order="joindate";
		break;
		case 1:
			$order="userpost";
		break;
		case 2:
			$order="usertopic";
		break;
		case 3:
			$order="userisbest";
		break;
		case 4:
			$order="userwealth";
		break;
		case 5:
			$order="userep";
		break;
		case 6:
			$order="usercp";
		break;
		case 7:
			$order="userdel";
		break;
		case 8:
			$order="userlogins";
		break;
	}
	$sql=$db->query("SELECT userid,username,usertopic,userpost,userisbest,userwealth,usercp,userep,userdel,usersex,joindate,userlogins FROM {$dv}user order by ".$order." desc",array('pageSize'=>$topic_total));
	$dispaceurl=$info_list[7];
	while ($arr=$db->fetch_array($sql)){
		$show_info=str_replace('{$userid}',$arr['userid'],$dispaceurl);
		$show_info=str_replace('{$username}',$arr['username'],$show_info);
		$show_info=str_replace('{$usertopic}',$arr['usertopic'],$show_info);
		$show_info=str_replace('{$userpost}',$arr['userpost'],$show_info);
		$show_info=str_replace('{$userbest}',$arr['userisbest'],$show_info);
		$show_info=str_replace('{$userwealth}',$arr['userwealth'],$show_info);
		$show_info=str_replace('{$usercp}',$arr['usercp'],$show_info);
		$show_info=str_replace('{$userep}',$arr['userep'],$show_info);
		$show_info=str_replace('{$userdel}',$arr['userdel'],$show_info);
		$show_info=str_replace('{$usersex}',user_sex($arr['usersex']),$show_info);
		$show_info=str_replace('{$joindate}',gmdate('Y-m-d H:i:s', $arr['joindate']+getUserTimeZoneOffset()),$show_info);
		$show_info=str_replace('{$userlogins}',$arr['userlogins'],$show_info);
		$mem_str.=$show_info;
	}
	$memberinfo=$board_start.$mem_str.$board_end;
	show_data(fixjs($memberinfo));
}
function ad_stan($info){
	global $lang,$dv,$db,$_DCACHE;
	$info_list=explode($lang['exp.col'],$info);
	if($info_list[7]==""){
		show_data(fixjs($lang['sys.info6']));
	exit;
	}
	$board_start=$info_list[6];
	$board_end=$info_list[8];
	if($info_list[12]=="" or !is_numeric($info_list[12])){
		$topic_total=10;//显示记录数;
	}
	else{
		$topic_total=intval($info_list[12]);
	}
	if($info_list[13]=="" or !is_numeric($info_list[13])){
		$topic_len=10;//显示标题长度;
	}
	else{
		$topic_len=intval($info_list[13]);
	}
	//------------------2007-8-16------------------------------------------------------------------------
	$board_id=$info_list[14];
	$adboardid=get_AD_boardid(1,$board_id);
	sort($adboardid);
	$adboardid = $db->escape_string(implode(',',$adboardid));
	if (!empty($adboardid)){
		$ad_sql= " WHERE boardid in (".$adboardid.")";
	}

	$bid=&$_DCACHE['all_forums'][$info_list[14]];
	$sql=$db->query("SELECT id,boardid,title,username,addtime FROM {$dv}bbsnews ".$ad_sql." order by id desc",array('pageSize'=>$topic_total));
	while ($arr=$db->fetch_array($sql)){
		$show_info=str_replace('{$boardname}',$bid['boardtype'],$info_list[7]);
		$show_info=str_replace('{$id}',$arr['id'],$show_info);
		$show_info=str_replace('{$boardid}',$arr['boardid'],$show_info);
		if(strlen($arr['title'])>$topic_len){
			$title_len=more_substr($arr['title'],0,$topic_len)."...";
		}
		else{
			$title_len=$arr['title'];
		}
		$show_info=str_replace('{$topic}',$title_len,$show_info);
		$show_info=str_replace('{$username}',$arr['username'],$show_info);
		$show_info=str_replace('{$posttime}',gmdate('Y-m-d H:i:s', $arr['addtime']+getUserTimeZoneOffset()),$show_info);
		$mem_str.=$show_info;
	}
	$adinfo=$board_start.$mem_str.$board_end;
	show_data(fixjs($adinfo));
}
function setout_stan($info){
	global $lang,$dv,$db,$forum_setting,$fsetting,$_DCACHE;
	$info_list=explode($lang['exp.col'],$info);
	if($info_list[7]==""){
		show_data(fixjs($lang['sys.info7']));
	exit;
	}
	$board_start=$info_list[6];
	$board_end=$info_list[8];
	if($info_list[12]=="" or !is_numeric($info_list[12])){
		$record_total=12;//显示记录数;
	}
	else{
		$record_total=intval($info_list[12]);
	}
	if($info_list[14]=="" or !is_numeric($info_list[14])){
		$topic_len=10;//显示标题长度;
	}
	else{
		$topic_len=intval($info_list[14]);
	}
	$linenum=$info_list[13];//每行显示多少条信息
	$File_Array = $lang['sys.info8'];
	$File_Array = explode("||",$File_Array);
	$picheight =$info_list[20];
	$picwidth  =$info_list[21];
	$TColor1 = $info_list[22];
	$TColor2 = $info_list[23];
	$tab =$info_list[24];//换行标志
	$t=0;
	$b_id=$info_list[15];
	//------------------2007-8-16------------------------------------------------------------------------
	$adboardid=get_AD_boardid(1,$b_id);
	sort($adboardid);
	$adboardid = $db->escape_string(implode(',',$adboardid));
	if (!empty($adboardid)){
		$sql_id= " and f_boardid in (".$adboardid.")";
	}

	$tran_type=$info_list[18];
	if($tran_type=="all"){
		$t_type="";
	}
	else{
		$t_type=" and f_type=".intval($info_list[18])."";
	}
	$order=$info_list[19];
	switch (intval($order)){
		case 0:
			$order="f_id";
		break;
		case 1:
			$order="f_viewnum";
		break;
		case 2:
			$order="f_downnum";
		break;
		case 3:
			$order="f_filesize";
		break;
		default:
			$order="f_id";
		break;
	}
	$dispaceurl=main_cycdeal($info_list[7]);
	$dispaceurl=$info_list[7];
	$stmt=$db->query("SELECT boardid,boardtype,parentid,depth,rootid,child,indeximg,parentstr,cid as checkout,cid as hidden,cid as nopost,cid as checklock,cid as mode,cid as simplenesscount,readme FROM {$dv}board WHERE boardid=".$info_list[15]." order by rootid");
	$sql=$db->query("SELECT f_id,f_announceid,f_boardid,f_username,f_filename,f_readme,f_type,f_filetype,f_addtime,f_viewname,f_viewnum,f_downnum,f_filesize FROM {$dv}upfile WHERE  f_id<>0 ".$sql_id.$t_type." order by ".$order." desc",array('pageSize'=>$record_total));
	while ($arr=$db->fetch_array($sql)){
		$topic = $arr['f_readme'];
		if(strlen($topic)>$topic_len){
			$topic=more_substr($topic,0,$topic_len)."...";
		}
		else{
			$topic=$arr['f_readme'];
		}
		if($Tcolor1==$Tcolor2){
			$Tcolor=$Tcolor1;
		}
		else{
			$Tcolor=$Tcolor2;
		}
		$show_info=str_replace('{$id}',$arr['f_id'],$dispaceurl);
		$show_info=str_replace('{$boardid}',$arr['f_boardid'],$show_info);
		$show_info=str_replace('{$username}',$arr['f_username'],$show_info);
		$show_info=str_replace('{$readme}',$topic,$show_info);
		$show_info=str_replace('{$addtime}',gmdate('Y-m-d H:i:s', $arr['f_addtime']+getUserTimeZoneOffset()),$show_info);
		$show_info=str_replace('{$viewfilename}',$arr['f_viewname'],$show_info);
		$show_info=str_replace('{$viewnum}',$arr['f_viewnum'],$show_info);
		$show_info=str_replace('{$downnum}',$arr['f_downnum'],$show_info);
		$show_info=str_replace('{$filesize}',$arr['f_filesize'],$show_info);
		$show_info=str_replace('{$filetype}',$File_Array[$arr['f_type']],$show_info);
		$show_info=str_replace('{$tcolor}',$Tcolor,$show_info);
		$board_info =&$_DCACHE['all_forums'][$info_list[15]];
		if(strpos($arr['f_announceid'],"|")!==false){
			$f_announceid=explode("|",$arr['f_announceid']);
			$rootid=$f_announceid[0];
			$replyid=$f_announceid[1];
		}
		else{
			$rootid="";
			$replyid="";
		}
		$show_info=str_replace('{$replyid}',$replyid,$show_info);
		$show_info=str_replace('{$rootid}',$rootid,$show_info);
		if(strpos($show_info,'{$boardname}')!==false){
			if(strval($arr['f_announceid'])>'0'){
				while($set=$db->fetch_aray($stmt)){
					if($set['boardid']==strval($arr['f_boardid'])){
						$show_info=str_replace('{$boardname}',$board_info['boardtype'],$show_info);
					}
				}
			}
			else{
				$show_info=str_replace('{$boardname}',"",$show_info);
			}
		}
		$filename=$arr['f_filename'];
		if(strpos($filename,":")!==false or strpos($filename,"//")!==false){
			$filename=getRawUrl().$forum_setting[76].$filename;
		}
		if($arr['f_type']==1){
			$picurl = (substr($fsetting[forumurl], -1, 1) === '/'  ) ? $fsetting[forumurl] : $fsetting[forumurl].'/';
			$filename='<img src='.$picurl.$fsetting[forumuploadname].$filename.' border=1 width='.$picwidth.' height='.$picheight.'>';
		}
		else{
			$filename="".$lang['sys.info12'].$arr['f_filetype'].$lang['sys.info9'];
		}
		$show_info=str_replace('{$filename}',$filename,$show_info);
		++$j;//换行记数
		if(intval($linenum)>0){
			if($j==$linenum){
				$NewsMainStr.='<td>'.$show_info.'</td>'.$lang['swap_row'];
				$j=0;				
			}
			else{
				$NewsMainStr.='<td>'.$show_info.'</td>';				
			}
		}
	}
	show_data(fixjs($board_start.$lang['out_table'].$NewsMainStr.$lang['over_table'].$board_end));
}
function check_server($str){
	global $lang;
	if($str==""){
		return true;
	exit;
	}
	else{
		return false;
	}
	$str_arr=explode(",",strval($str));
	$server_link=$_SERVER['HTTP_REFERER'];
	$count=count($str);
	for($i=0;$i<$count;$i++){
		if(substr($str_arr[$i],-1)=="/"){
			$str_arr[$i]=substr(trim($str_arr[$i]),0,strlen($str_arr)-1);
			if(strtolower(substr($server_link,0,strlen($str_arr[$i])))==strtolower($str_arr[$i])){
				return true;
			exit;
			}
			else{
				return false;
			}
		}
	}
}
function getboardid($boardid) {
	global $dv,$db;	
	$bechildzero=$db->scalar("select child from {$dv}board where boardid={$boardid}");
	if($bechildzero==0){
		return $boardid;
		exit;
	}
	else{
		$stmt=$db->query("select boardid,parentid,parentstr from {$dv}board where parentstr like '%".$boardid."%' order by depth desc",array('pageSize'=>1));
		while ($arr=$db->fetch_array($stmt)) {
			if(strpos($arr['parentstr'],',')!==false){
				$p_arr=explode(',',$arr['parentstr']);
				foreach($p_arr as $pid){
					if($pid!=$boardid){
						continue;
					}
					$sql=$db->query("select boardid,parentid from {$dv}board where parentid=".$pid."");
					while ($parr=$db->fetch_array($sql)) {
						$boardidstr.=$parr['boardid'].',';
					}
				}
				$boardidstr=substr($boardidstr,0,-1);
				$s_arr=explode(',',$boardidstr);
				foreach ($s_arr as $a_id){ 
					$endbidnum=$db->scalar("select count(1) from {$dv}board where parentid=".$a_id."");
					if($endbidnum<=1){
						$endbid.=$a_id.',';
					}
					else{
						$query=$db->query("select boardid from {$dv}board where parentid=".$a_id."");
						while ($agin=$db->fetch_array($query)) {
							$se_boardidstr.=$agin['boardid'].',';
						}
					}
				}
				$boardidstr=$endbid.$se_boardidstr;
			}
			else{
				$boardidstr.=$arr['boardid'].',';
			}
			$pj++;
			$boardidstr=substr($boardidstr,0,-1);
		}
		if($pj<=0){
			$boardidstr=$boardid;//调用的版面：		
		}
		return $boardidstr;
	}
}
function main_cycdeal($str) {
	if(strpos($str,'/a')!==false){
		$bodyinfo=explode('</a>',$str);
		$dispaceurl=str_replace(' ','',$bodyinfo[0]);
		$dispaceurl.=$bodyinfo[1];
		$dispaceurl=str_replace('ahref','a href',$dispaceurl);
		if(strpos($dispaceurl,'target')!==false){
			$dispaceurl=str_replace('target=_blank',' target=_blank',$dispaceurl);			
		}
	}
	else{
		$dispaceurl=$str;
	}
	return $dispaceurl;
}
function user_sex($var){
	global $lang;
	if(intval($var)==1){
		$usex=$lang['sys.info10'];
	}
	else{
		$usex=$lang['sys.info11'];
	}
	return $usex;
}
function fixjs($strings){
	return str_replace(array('&gt;', '&lt;', '&quot;','&amp;','\\','"', "\r", "\n"), array('>', '<','"','&','\\\\', '\\"', '\r', '\n'), $strings);
}
function more_substr($str,$start,$len=-1) {
	preg_match_all("/[\x80-\xff]?./",$str,$arr);
	if($len==-1){
		$len=count($arr[0])-$start;
	}
	return @implode(array_slice($arr[0],$start,$len),"");
}
?>