<?php
define('THIS_SCRIPT', 'board');
include_once 'global.php';
$lang = load_lang($lang, THIS_SCRIPT);
checklogin();
include_once 'inc/board_functions.php';
header("content-Type: text/html; charset=".$charset);
if ( strpos($sysinfo['flag'],'9,') === false ){
	head();
	show_msg($lang['readme_tit'],$lang['error.str1'],0,'','','','');
	exit;
}
switch ($_GET['action']) {
	case 'editpermission':
		editpermission();
		break;
	case 'savepermission':
		savepermission();
		break;
	case 'permission':
		head();
		readme($lang['page_title'],$lang['page_readme'],$lang['nav']);
		board_permission();
		footer();
		break;
	case 'add':
		new_board();
		break;
	case 'edit':
		board_edit();
		break;
	case 'saveedit':
		save_edit();
		break;
	case 'savenew':
		save_new();
		break;
	case "deldate":
		head();
		readme($lang['page_title'],$lang['page_readme'],$lang['nav']);
		clear_date();
		table_list();
		include printout('board');
		footer();
		break;
	case 'miniclass':
		head();
		readme($lang['page_title'],$lang['page_readme'],$lang['nav']);
		miniclass();
		footer();
		break;
	case 'saveminiclass':
		saveminiclass();
		break;
	case "check":
		del_date();
		break;
	case "delboard":
		del_board();
		break;
	case 'saveorder':
		save_order();
		break;
		case 'orders':
		head();
		readme($lang['page_orders'],$lang['page_readme'],$lang['nav']);
		board_order();
		footer();
		break;
	default:
		head();
		readme($lang['page_title'],$lang['page_readme'],$lang['nav']);
		board_list();
		footer();
}
function savepermission(){
	global $db,$lang,$dv,$boardid,$groupid,$editgroupid,$isdefault,$sum_CheckGroupSetting,$_POST,$_DCACHE;
	if( $groupid != '' ){
		$SaveGroupid = $editgroupid. ',' .$groupid;
	}else{
		$SaveGroupid = $editgroupid;
	}
	include_once CACHE_PATH.'forum_setting.php';
	require_once ROOT_PATH.'templates/'.$_DCACHE['settings']['styletpl'].'/grouppermission.tpl.php';
	if ( $isdefault == '0' ){
		//接收并整理参数
		$myGroupSetting = getgrouppermission();
		$query=$db->query("select groupid from {$dv}boardpermission where groupid={$editgroupid} and boardid={$boardid}");
		if ($gs = $db->fetch_array($query)){
			$db->query("update {$dv}boardpermission set psetting='{$myGroupSetting}' where groupid={$editgroupid} and boardid={$boardid}");
		}else{
			$db->query("Insert Into {$dv}boardpermission (boardid,groupid,psetting) values ('{$boardid}','{$editgroupid}','{$myGroupSetting}')");
		}

		if( $groupid !='' && $sum_CheckGroupSetting > 0 ){
			$groupidlist = explode(',',$groupid);
			foreach($groupidlist as $groupid){
				$query=$db->query("select psetting from {$dv}boardpermission where groupid={$groupid} and boardid={$boardid}");
				if ($gs = $db->fetch_array($query)){
					$newstr = explode(',',$myGroupSetting);
					$oldstr = explode(',',$gs['psetting']);
					for($k=0; $k<93; $k++){
						if ($_POST["CheckGroupSetting($k)"] == 1){
							$updatestr .= $newstr[$k];
						}else{
							$updatestr .= $oldstr[$k];
						}
						if ($k < 92){
							$updatestr .= ',';
						}
					}
					$db->query("update {$dv}boardpermission set psetting='{$updatestr}' where groupid={$groupid} and boardid={$boardid}");
				}else{
					$query=$db->query("Select groupsetting From {$dv}usergroups Where usergroupid={$groupid}");
					if ($gs = $db->fetch_array($query)){
						$newstr = explode(',',$myGroupSetting);
						$oldstr = explode(',',$gs['groupsetting']);
						for($k=0; $k<93; $k++){
							if ($_POST["CheckGroupSetting($k)"] == 1){
								$updatestr .= $newstr[$k];
							}else{
								$updatestr .= $oldstr[$k];
							}
							if ($k < 92){
								$updatestr .= ',';
							}
						}
						$db->query("Insert Into {$dv}boardpermission (boardid,groupid,psetting)values('{$boardid}','{$groupid}','{$updatestr}')");
					}
				}
			}
		}
	}else{
		//-------------------------2007-8-23 IvanSky BoardGroup del ceche file function----------------
		ActionBoardGroupFileDel($boardid,$SaveGroupid);
		$db->query("delete from {$dv}boardpermission where boardid={$boardid} and groupid in ({$SaveGroupid})");
	}
	
	reload_isgroupsetting($boardid);
	include_once INC_PATH.'BoardCache.class.php';
	$mycache =& new BoardCache($db);
	$mycache->createAll();
	$mycache->createboardgroup();
	unset ($mycache);
	head();
	show_msg($lang['page_permission'],$lang['permission_suc'],1,'','','board.php?action=permission');
	footer();
}
function editpermission(){
	global $db,$lang,$dv,$boardid,$groupid,$_DCACHE;
	include_once CACHE_PATH.'forum_setting.php';
	require_once ROOT_PATH.'templates/'.$_DCACHE['settings']['styletpl'].'/grouppermission.tpl.php';
	$lang = load_lang($lang, 'grouppermission',ROOT_PATH.'templates/lang/'.$_DCACHE['settings']['lang'].'/');
	$query=$db->query('select psetting from '.$dv.'boardpermission where boardid='.intval($boardid).' and groupid='.intval($groupid));
	if ($gs = $db->fetch_array($query)) {
		$isdefault=0;
		$groupsetting = $gs['psetting'];
	}else{
		$query=$db->query('select groupsetting from '.$dv.'usergroups where  usergroupid='.intval($groupid));
		$gs = $db->fetch_array($query);
		$groupsetting = $gs['groupsetting'];
		$isdefault=1;
	}
	$query=$db->query('select boardtype from '.$dv.'board where boardid='.intval($boardid).'');
	if ($bs = $db->fetch_array($query)) {
		$boardtype=$bs['boardtype'];
	}
	$query=$db->query('select usertitle from '.$dv.'usergroups where usergroupid='.intval($groupid).'');
	if ($ts = $db->fetch_array($query)){
		$usertitle=$ts['usertitle'];
	}
	head();
	readme($lang['page_title'],$lang['page_readme'],$lang['nav']);
	require_once printout('boardpermission');
	footer();
}
function board_permission(){
	global $db,$lang,$dv;
	$query_groups=$db->query('select usertitle,usergroupid,parentgid from '.$dv.'usergroups where parentgid > 0 order by parentgid,usergroupid');
	//用户组列表
	while($group = $db->fetch_array($query_groups)) {
		$usergroups[]=$group;
		}
	//版面自定权限列表
	$query_b_p=$db->query('select boardid,groupid from '.$dv.'boardpermission order by pid');
	$permission_list = array();
	while($permission = $db->fetch_array($query_b_p)) {
		$permission_list[]=intval($permission['boardid']).'_'.intval($permission['groupid']);
		}
	//版面列表
	$query=$db->query('select boardid,boardtype,parentid,depth,child,isgroupsetting from '.$dv.'board order by rootid,orders');
	if (!is_array($permission_list)) {
		$permission_list = array();
	}
	require_once printout('board_permission');
}
function save_order(){
	global $db,$lang,$dv;
	$parentid=intval($_GET['parentid']);
	$i=1;
	if ($parentid==0){
	foreach($_POST['order'] as $boardid){
		$db->query('update '.$dv.'board set rootid='.$i.' where boardid='.intval($boardid));
		$i++;
		}
	}else{
	foreach($_POST['order'] as $boardid){
		$db->query('update '.$dv.'board set orders='.$i.' where boardid='.intval($boardid));
		$i++;
		}
	}
	forum_board_init(0);
	include_once INC_PATH.'BoardCache.class.php';
	$mycache =& new BoardCache($db);
	$mycache->createAll();
	unset ($mycache);
	head();
	show_msg($lang['page_orders'],$lang['order_suc'],1,'','','board.php');
	footer();
}
function save_new(){
	global $db,$lang,$dv,$restriction;
	$boardtype=$_POST['boardtype'];
	$boardname=$_POST['boardname'];
	$readme=$_POST['readme'];
	$rules=$_POST['rules'];
	$parentid=intval($_POST['parentid']);
	$cid=$_POST['sid'];
	$setting_id=intval($_POST['setting_id']);
	$ads_id=intval($_POST['ads_id']);
	$audit_settings_id=intval($_POST['audit_settings_id']);
	$allowpost=intval($_POST['allowpost']);
	$ishidden=intval($_POST['ishidden']);
	$ischeckout=intval($_POST['ischeckout']);
	$boarduser=$_POST['boarduser'];
	$boardmaster=$_POST['boardmaster'];
	$indeximg=$_POST['indeximg'];
	$showtype=intval($_POST['showtype']);
	$showboard=intval($_POST['showboard']);
	$showboardmaster=intval($_POST['showboardmaster']);
	$lastpost='$0$'.time().'$$$$';
	if($_GET['editid']) {
		$query=$db->query('select rootid from '.$dv.'board where boardid='.intval($_GET['editid']));
		if ($ts = $db->fetch_array($query)) {
			$rootid=$ts['rootid'];
		}else{
			$parentid=0;
			$rootid=get_newrootid();
		}
	} else {
		if($parentid==0) {
			$rootid=get_newrootid();
		} else {
			$query=$db->query("select rootid from {$dv}board where boardid='$parentid'");
			if($rs = $db->fetch_array($query)) {
				$rootid = $rs['rootid'];
			}
		}
	}
	$boardid=get_newboardid();
	$master=explode('|',$boardmaster);
	$boardmaster='';
	foreach($master as $bmaster){
		if (trim($bmaster)!=''){
			if ($boardmaster ==''){$boardmaster=trim($bmaster);}else{$boardmaster.='|'.trim($bmaster);}
		}
	}
	$master=explode('|',$boardmaster);
	$all_masterlist=get_all_masterlist();
	$db->query("Insert Into {$dv}board (boardid,boardtype,boardname,showtype,readme,rules,parentid,cid,setting_id,ads_id,boardmaster,indeximg,lastpost,rootid,orders,audit_settings_id,allowpost,ishidden,ischeckout,boarduser,showboard,showboardmaster)values('$boardid','$boardtype','$boardname','$showtype','$readme','$rules','$parentid','$cid','$setting_id','$ads_id','$boardmaster','$indeximg','$lastpost','$rootid','999999','$audit_settings_id','$allowpost','$ishidden','$ischeckout','$boarduser','$showboard','$showboardmaster')");
	//检查是否有新版主
	foreach($master as $bmaster){
		if (!in_array($bmaster,$all_masterlist)){
			$new_master[]=$bmaster;
		}
	}
	if (is_array($new_master) ){
		foreach($new_master as $username){
			set_usergroup($username);
		}
	}
	forum_board_init(0);
	include_once INC_PATH.'BoardCache.class.php';
	$mycache =& new BoardCache($db);
	$mycache->createAll();
	unset ($mycache);
	head();
	show_msg($lang['page_title'],$lang['new_suc'],1,'','','board.php');
	footer();
}
function save_edit(){
	global $db,$lang,$dv,$restriction,$editid;
	$boardtype=$_POST['boardtype'];
	$boardname=$_POST['boardname'];
	$readme=$_POST['readme'];
	$rules=$_POST['rules'];
	$parentid=intval($_POST['parentid']);
	$cid=$_POST['sid'];
	$setting_id=intval($_POST['setting_id']);
	$ads_id=intval($_POST['ads_id']);
	$audit_settings_id=intval($_POST['audit_settings_id']);
	$allowpost=intval($_POST['allowpost']);
	$ishidden=intval($_POST['ishidden']);
	$ischeckout=intval($_POST['ischeckout']);
	$boarduser=$_POST['boarduser'];
	$boardmaster=trim($_POST['boardmaster']);
	$indeximg=$_POST['indeximg'];
	$showtype=intval($_POST['showtype']);
	$showboard=intval($_POST['showboard']);
	$showboardmaster=intval($_POST['showboardmaster']);
	$query=$db->query('select parentid from '.$dv.'board where boardid='.intval($_GET['editid']));
	if ($ts = $db->fetch_array($query)) {
	}else{
		head();
		show_msg($lang['page_title'],$lang['edit_err1'],0,'','','board.php');
		footer();
		exit;
	}
	$master=explode('|',$boardmaster);
	$boardmaster='';
	foreach($master as $bmaster){
		if (trim($bmaster)!=''){
			if ($boardmaster ==''){$boardmaster=trim($bmaster);}else{$boardmaster.='|'.trim($bmaster);}
		}
	}
	$master=explode('|',$boardmaster);
	$masterlist=get_masterlist($_GET['editid']);
	$all_masterlist=get_all_masterlist();
	//检查是否有撤职版主
	foreach($masterlist as $oldmaster){
		if (!in_array($oldmaster,$master)){
			$un_master[]=$oldmaster;
		}
	}
	foreach($master as $bmaster){
		if (!in_array($bmaster,$all_masterlist)){
			$new_master[]=$bmaster;
		}
	}
	if (intval($ts['parentid'])!= $parentid){
		$has_update=1;
		//层次变化了，要检查是否是错误的选择了自己或自己的子版面为父级版面
		if($parentid!=0){
			$query=$db->query('select boardid,parentstr from '.$dv.'board where boardid='.$parentid);
			 //父级版面不存在
			 if ($ts = $db->fetch_array($query)) {
			 }else{
				head();
				show_msg($lang['page_title'],$lang['edit_err2'],0,'','','board.php');
				footer();
				exit;
			}
			//父级版面是自己
			if(intval($_GET['editid'])==$ts['boardid']){
				head();
				show_msg($lang['page_title'],$lang['edit_err3'],0,'','','board.php');
				footer();
				exit;
			}
			//父级版面是自己的下属
			if(strpos(','.$ts['parentstr'].',',','.intval($_GET['editid']).',')){
				head();
				show_msg($lang['page_title'],$lang['edit_err4'],0,'','','board.php');
				footer();
				exit;
			}
		}
	}
	$db->query("update {$dv}board set boardname='{$boardname}',boardtype='{$boardtype}',showtype='{$showtype}',readme='{$readme}',rules='{$rules}',parentid='{$parentid}',cid='{$cid}',setting_id='{$setting_id}',ads_id='{$ads_id}',boardmaster='{$boardmaster}',indeximg='{$indeximg}',audit_settings_id='{$audit_settings_id}',allowpost='{$allowpost}',ishidden='{$ishidden}',ischeckout='{$ischeckout}',boarduser='{$boarduser}',showboard='{$showboard}',showboardmaster='{$showboardmaster}' where boardid=$editid");
	if ($has_update==1){
		//层次变化了，并且移动到一级分类，重新取一个rootid
		if($parentid==0){
			$db->query("update ".$dv."board set rootid=".get_newrootid()." where  boardid=".intval($_GET['editid']));
		}
		//层次变化了，更新所有的层次数据.
		forum_board_init(0);
		$lang['edit_suc'].=$lang['edit_description'];
	}
	if (is_array($un_master)){
		$all_masterlist1=get_all_masterlist();
		foreach($un_master as $username){
			if (!in_array($username,$all_masterlist1)){//撤消职务了
				if ($_POST['unset_master']=='0'){
					//转为贵宾
					set_usergroup($username,0);
				}else{
					//自动更新等级
					reset_grade($username);
				}
			}
		}
	}
	if (is_array($new_master) ){
		foreach($new_master as $username){
			set_usergroup($username);
		}
	}
	include_once INC_PATH.'BoardCache.class.php';
	$mycache =& new BoardCache($db);
	$mycache->createAll();
	unset ($mycache);
	head();
	show_msg($lang['page_title'],$lang['edit_suc'],1,'','','board.php');
	footer();
}
function board_order(){
	global $db,$lang,$dv;
	$parentid=intval($_GET['parentid']);
	$query=$db->query('select boardid,boardtype,parentid,depth,child from '.$dv.'board where parentid='.$parentid.' order by rootid,orders');
	require_once printout('board_order');
	}
function board_list(){
	global $db,$lang,$dv;
	$query=$db->query('select boardid,boardtype,parentid,depth,child from '.$dv.'board order by rootid,orders');
	require_once printout('board_list');
	}
function new_board(){
	global $db,$lang,$dv,$restriction,$editid;
	$submit=$lang['submit'];
	$action='?action=savenew&amp;editid='.stripslashes($editid);
	$form_tit1=$lang['new_board_tit'];
	$parentid=intval($editid);
	//$sid=get_min_sid();
	$cid=get_min_cid();
	$setting_id=intval(get_setting_id());
	$ads_id=intval(get_ads_id());
	$audit_settings_id = 0;
	if ( $parentid == 0 ){
		$allowpost = 0;
	}else{
		$allowpost = 1;
	}
	$ishidden = 0;
	$ischeckout = 0;
	$unset_master_type='hidden';
	//require_once 'inc/board.form.php';
	head();
	readme($lang['page_title'],$lang['page_readme'],$lang['nav']);
	//show_form($form);
	$query1=$db->query("select id,type from {$dv}fsettings where s_class=1 order by c_orders");
	$query2=$db->query("select id,type from {$dv}fsettings where s_class=2 order by c_orders");
	$query3=$db->query("Select s1.styleid,s1.name,s1.ename,s1.directory,s2.name as tplname From {$dv}styles s1 inner join {$dv}styles s2 on s1.parentid=s2.styleid where s1.stype='2' order by s1.styleid");
	$query4=$db->query("select id,type from {$dv}fsettings where s_class=3 order by c_orders");
	require_once printout('board');
	footer();
	}
function board_edit(){
	global $db,$lang,$dv,$restriction,$editid;
	$query=$db->query("select boardid,boardtype,boardname,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,showboard,showboardmaster from ".$dv."board where boardid=". intval($editid));
	if ($db->num_rows($query) <= 0) {
		head();
		show_msg($lang['page_title'],$lang['edit_err1'],0,'','','board.php');
		footer();
		exit;
		}
		$forum=$db->fetch_array($query);
		$action='?action=saveedit&amp;editid='.stripslashes($editid);
		$submit=$lang['submit'];
		$form_tit1=$forum['boardtype'].'-'.$lang['edit_tit'];
		$boardtype=htmlspecialchars($forum['boardtype']);
		$boardname=htmlspecialchars($forum['boardname']);
		$readme=htmlspecialchars($forum['readme']);
		$rules=htmlspecialchars($forum['rules']);
		$boarduser=htmlspecialchars($forum['boarduser']);
		$parentid=intval($forum['parentid']);
		$cid=$forum['cid'];
		$setting_id=intval($forum['setting_id']);
		$ads_id=intval($forum['ads_id']);
		$audit_settings_id=$forum['audit_settings_id'];
		$allowpost=$forum['allowpost'];
		$ishidden=$forum['ishidden'];
		$ischeckout=$forum['ischeckout'];
		$boardmaster=htmlspecialchars($forum['boardmaster']);
		$indeximg=htmlspecialchars($forum['indeximg']);
		$showtype=$forum['showtype'];
		$unset_master_type='radio';
		$showboard=$forum['showboard'];
		$showboardmaster=$forum['showboardmaster'];
		head();
		readme($lang['page_title'],$lang['page_readme'],$lang['nav']);
		$query1=$db->query("select id,type from {$dv}fsettings where s_class=1 order by c_orders");
		$query2=$db->query("select id,type from {$dv}fsettings where s_class=2 order by c_orders");
		$query3=$db->query("Select s1.styleid,s1.name,s1.ename,s1.directory,s2.name as tplname From {$dv}styles s1 inner join {$dv}styles s2 on s1.parentid=s2.styleid where s1.stype='2' order by s1.styleid");
		$query4=$db->query("select id,type from {$dv}fsettings where s_class=3 order by c_orders");
		require_once printout('board');
		footer();
	}
function clear_date(){//清理数据;
	global $lang,$dv,$db,$id,$board_type,$str1,$str2,$str3,$str4;
	$id=$_GET['editid'];
	if($id==0){
		head();
		show_msg($lang['page_title'],$lang['b_info1'],0,'','','board.php');
		footer();
		exit;
	}
	else{
		$board_type=$db->scalar("SELECT boardtype FROM ".$dv."board WHERE boardid=". intval($id)."");
		$str1=$db->scalar("select count(1) FROM {$dv}topic WHERE boardid=".intval($id)."");
		$str3=0;
		$str4=0;
		$sql=$db->query("SELECT id,tablename,tabletype FROM {$dv}tablelist");
		while ($t_arr=$db->fetch_array($sql)){
			$num=$db->scalar("SELECT count(1) FROM ".$t_arr['tablename']." WHERE boardid=".intval($id)."");
			$str2.="<li>".$lang['b_info2'].$t_arr['tablename'].$lang['b_info3'].$num.$lang['b_info4']."</li>";
			$str3+=$num;
			$count=$db->scalar("SELECT count(1) FROM ".$t_arr['tablename']." WHERE boardid=".intval($id)." and isbest='1'");
			$str4+=$count;
		}
	}
}
function deft_table(){
	global $dv,$db,$lang,$def_table;
	$d_sql=$db->scalar("select forum_nowusebbs from {$dv}setup");
	return ($d_sql);
}
function del_date(){//清空;
	global $lang,$dv,$db,$id,$tablelist,$date_num;
	$url='board.php';			//解决在清空一个版面后，返回时不能显示最新操作后的结果			
	$id=$_GET['editid'];
	$tablelist=$_POST['tablelist'];
	$date_num=$_POST['date_num'];
	if($id==0){
		head();
		show_msg($lang['page_title'],$lang['b_info1'],0,'','','board.php');
		footer();
		exit;
	}
	else{
		if($tablelist=="all"){
			$sql=$db->query("SELECT id,tablename,tabletype FROM {$dv}tablelist");
			while ($arr=$db->fetch_array($sql)){
				$dellastposttime=dv_gmtimestamp(gmdate('Y-m-d 00:00:00'))-($date_num*24*3600);
				$sqltopic=$db->query("SELECT topicid,isvote,pollid FROM {$dv}topic WHERE boardid=".intval($id)." and isbest='0' and posttable='".$arr['tablename']."' and lastposttime<='".$dellastposttime."'");
				while ($topic_arr=$db->fetch_array($sqltopic)){
					$sql=$db->query("DELETE FROM ".$arr['tablename']." WHERE boardid=".intval($id)." and rootid=".$topic_arr['topicid']."");
					if($topic_arr['isvote']==1 and !is_null($topic_arr['pollid'])){
						$sql=$db->query("DELETE FROM {$dv}vote WHERE voteid=".$topic_arr['pollid']."");
					}
					$topic_num+=1;
				}
				$sqltopic=$db->query("DELETE FROM {$dv}topic WHERE boardid=".intval($id)." and isbest='0' and posttable='".$arr['tablename']."' and lastposttime<='".$dellastposttime."'");
				$lastpoststr='';
				$db->query("update {$dv}board set postnum=postnum-".$topic_num.",topicnum=topicnum-".$topic_num.",todaynum=todaynum-".$topic_num." where boardid=".$id."");				
			}
		}
		else{
			if($tablelist==''){
				$tablelist=deft_table();
				$sqltopic=$db->query("SELECT topicid,isvote,pollid FROM {$dv}topic WHERE boardid=".intval($id)." and isbest='0' and posttable='".$tablelist."'");
				while ($topic_arr=$db->fetch_array($sqltopic)){
					$sql=$db->query("DELETE FROM ".$tablelist." WHERE boardid=".intval($id)." and rootid=".$topic_arr['topicid']."");
					if($topic_arr['isvote']==1 and !is_null($topic_arr['pollid'])){
						$sql=$db->query("DELETE FROM {$dv}vote WHERE voteid=".$topic_arr['pollid']."");
					}
					$topic_num++;
				}
				$sqltopic=$db->query("DELETE FROM {$dv}topic WHERE boardid=".intval($id)." and isbest='0' and posttable='".$tablelist."'");
				$lastpoststr='';
				$db->query("update {$dv}board set postnum=postnum-".$topic_num.",topicnum=topicnum-".$topic_num.",todaynum=todaynum-".$topic_num.",lastpost='".$lastpoststr."' where boardid=".$id."");
			}
			else{
				$dellastposttime=dv_gmtimestamp(gmdate('Y-m-d 00:00:00'))-($date_num*24*3600);
				$sqltopic=$db->query("SELECT topicid,isvote,pollid FROM {$dv}topic WHERE boardid=".intval($id)." and isbest='0' and posttable='".$tablelist."' and lastposttime<='".$dellastposttime."'");
				while ($topic_arr=$db->fetch_array($sqltopic)){
					$sql=$db->query("DELETE FROM ".$tablelist." WHERE boardid=".intval($id)." and rootid=".$topic_arr['topicid']."");
					if($topic_arr['isvote']==1 and !is_null($topic_arr['pollid'])){
						$sql=$db->query("DELETE FROM {$dv}vote WHERE voteid=".$topic_arr['pollid']."");
					}
					$topic_num++;
				}
				$sqltopic=$db->query("DELETE FROM {$dv}topic WHERE boardid=".intval($id)." and isbest='0' and posttable='".$tablelist."' and lastposttime<='".$dellastposttime."'");
				$lastpoststr='';
				$db->query("update {$dv}board set postnum=postnum-".$topic_num.",topicnum=topicnum-".$topic_num.",todaynum=todaynum-".$topic_num." where boardid=".$id."");				
			}
		}
		head();
		show_msg($lang['b_info7'],$lang['b_info8'].$topic_num.$lang['b_info9'],1,'','',$url,$lang['cmdback']);
		footer();
		exit;
	}
}
function table_list(){
	global $dv,$db,$t_list;
	$t_list=array();
	$sql=$db->query("SELECT id,tablename,tabletype FROM {$dv}tablelist");
	while ($arr=$db->fetch_array($sql)){
		$t_list[]=$arr;
	}
}
function del_board(){
	global $lang,$dv,$db,$id;
	$url='board.php';			//解决在删除一个版面，返回时不能显示最新操作后的结果
	$id=$_GET['editid'];
	$sql=$db->query("SELECT rootid FROM {$dv}board WHERE boardid=".intval($id)."");
	$stmt=$db->query("SELECT parentstr,child,depth FROM {$dv}board WHERE boardid=".intval($id)."");
	while ($arr=$db->fetch_array($stmt)){
		if($arr['child']>0){
			head();
			show_msg($lang['b_info7'],$lang['b_info10'],1,'','',$url,$lang['cmdback']);
			footer();
			exit;
		}
		$parentstr=$arr['parentstr'];
		if($arr['depth']>0){
			$parentstr_sql=$db->query("update {$dv}board set child=child-1 where boardid IN ($parentstr)");
		}
		$delsql=$db->query("DELETE FROM {$dv}board WHERE boardid=".$id."");
		$sql=$db->query("SELECT id,tablename,tabletype FROM {$dv}tablelist");
		while ($table_arr=$db->fetch_array($sql)){
			$del_sql=$db->query("DELETE FROM ".$table_arr['tablename']." WHERE boardid=".$id."");
		}
		$Execute=$db->query("DELETE FROM {$dv}topic WHERE boardid=".$id."");
		$Execute=$db->query("DELETE FROM {$dv}besttopic WHERE boardid=".$id."");
		$Execute=$db->query("DELETE FROM {$dv}upfile WHERE f_boardid=".$id."");
		$boardid_idarr=$db->scalar("SELECT boardid FROM {$dv}board");
		if($boardid_idarr) {
			$Execute=$db->query("DELETE FROM {$dv}useraccess WHERE uc_boardid not in (".$boardid_idarr.")");
		}
	}
	include_once INC_PATH.'BoardCache.class.php';
	$mycache =& new BoardCache($db);
	$mycache->createAll();
	unset ($mycache);
	head();
	show_msg($lang['b_info7'],$lang['b_info11'],1,'','',$url,$lang['cmdback']);
	footer();
	exit;
}
function miniclass(){
	global $lang,$dv,$db,$editid,$action;
	if ( $editid == '' || !is_numeric($editid) ){
		head();
		show_msg($lang['page_title'],$lang['b_info1'],0,'','','board.php');
		footer();
		exit;
	}
	$query=$db->query("Select boardid,boardtype,board_setting From {$dv}board Where boardid=$editid");
	if ( $bs=$db->fetch_array($query) ){
		$board_type = $bs['boardtype'];
		if ( $bs['board_setting'] == '' ){
			$ismini = 0;
		}else{
			$ismini = 1;
			$minilist = explode('$$',$bs['board_setting']);
			array_shift($minilist);
		}
	   require_once printout('board');
	}else{
		head();
		show_msg($lang['page_title'],$lang['edit_err1'],0,'','','board.php');
		footer();
		exit;
	}
}
function saveminiclass() {
	global $lang,$dv,$db,$editid,$action,$miniclass,$newminiclass;
	if ( $editid == '' || !is_numeric($editid) ){
		head();
		show_msg($lang['page_title'],$lang['b_info1'],0,'','','board.php');
		footer();
		exit;
	}
	$ministr = '';
	!is_array($miniclass) && $miniclass = array();
	foreach($miniclass as $val) {
		$ministr .= '$$'.$val;
	}
	if($newminiclass != '') {
		$ministr .= '$$'.$newminiclass;
	}
	$db->query("UPDATE {$dv}board SET board_setting='$ministr' WHERE boardid='$editid'");
	head();
	show_msg($lang['page_title'],$lang['b_info22'],1,'','',"board.php?action=miniclass&editid={$editid}",$lang['comback']);
	footer();
	exit;
}
?>