<?php
define('THIS_SCRIPT', 'spaceadmin');
include_once 'global.php';
defined('MAIN_DOMAIN_NAME') AND exit('Access denied');
require_once INC_PATH.'space.functions.php';
include_once CACHE_PATH.'board/board_all.php';
include_once CACHE_PATH.'forum_setting.php';
$lang = load_lang($lang, 'spaceadmin' );
checklogin();
header("content-Type: text/html; charset=".$charset);
head();
if ( strpos($sysinfo['flag'],'29,') === false ){
	show_msg($lang['readme_tit'],$lang['error.str1'],0,'','','','');
	exit;
}
PageLoad();
footer();
function Pageload(){
	global $dv,$db,$lang,$action,$forum_adminfolder,$top_arr,$id,$list_info,$t,$lanmu_edit_list,$systemUpSetting,$pageSize;
	global $page_size,$page,$total,$page_count,$offset,$p,$userinfo_list,$user_info,$ad_type,$ad_info,$file_list,$doaction;
	global $spaceConfig_Syscat,$spaceConfig_Syschatcat,$spaceConfig_UserCat,$space_setting,$tmp_list,$page_size,$page,$total,$page_count,$offset,$p,$tmp_edit_list,$_DCACHE,$uploaddir;
	$uploaddir=basename($_DCACHE['settings']['forumuploadname']);
	$doaction=$_POST['doaction'];
	$action=$_GET['action'];
	$ad_type=intval($_GET['ad_type']);
	switch ($doaction){
		case "user_count":
			space_user_count();
		break;
		case "index_data":
			space_index_data();
		break;
		case "topic_data":
			space_topic_data();
		break;
		case "total_data":
			space_total_data();
		break;
		case "total_updata":
			space_total_updata();
		break;
		case "do_today_recommend":
			do_today_recommend();
		break;
	}
	action_load($action);
	include printout('spaceadmin');
}
function today_star()
{
	global $dv, $db, $todaystarinfo, $page;
	if ($page < 1) {
		$page = 1;
	}
	$dbcount = $db->scalar("SELECT COUNT(*) FROM {$dv}space_apply_today_star");
	$todaystarinfo = array('AbsolutePage'=>$page, 'PageSize'=>20, 'RecordCount'=>$dbcount, 'PageCount'=>0, 'ResultSet'=>false);
	if ($dbcount > 0) {
		$topcount = 0;
		if ($query = $db->query("SELECT userid, apply_timestamp, username, nickname, user_photo, user_preview_photo, status, apply_desc FROM {$dv}space_apply_today_star WHERE status<>'0' ORDER BY status DESC,apply_timestamp DESC, userid DESC", array('pageSize'=>2))) {
			while ($dbinfo =& $db->fetch_array($query)) {
				$todaystarinfo['ResultSet'][] =& $dbinfo;
				$topcount++;
			}//end while
		}
		$todaystarinfo['RecordCount'] -= $topcount;
		$todaystarinfo['PageCount'] = ceil($todaystarinfo['RecordCount'] / $todaystarinfo['PageSize']);
		if ($query = $db->query("SELECT userid, apply_timestamp, username, nickname, user_photo, user_preview_photo, status, apply_desc FROM {$dv}space_apply_today_star WHERE status='0' ORDER BY status DESC,apply_timestamp DESC, userid DESC", array('absolutePage'=>$todaystarinfo['AbsolutePage'], 'pageSize'=>$todaystarinfo['PageSize']))) {
			while ($dbinfo =& $db->fetch_array($query)) {
				$todaystarinfo['ResultSet'][] =& $dbinfo;
			}//end while
		}
	}
}//end function today_star
function do_today_star()
{
	global $lang, $dv, $db, $_POST, $today_star_del_userid, $today_star_audit_userid;
	$today_star_cache = false;
	if ('submitaudit' === $_POST['doaction']) {	//	提交审核操作
		if (!empty($today_star_audit_userid) AND is_array($today_star_audit_userid)) {
			if (count($today_star_audit_userid) > 2) {
				show_msg($lang['sys.info'],$lang['space.info277'],0,'','',$lang['url'],$lang['cmdback']);
				exit;
			}
			$useridlist = implode(',', $today_star_audit_userid);
			if (0 ==  preg_match('/^(?:[0-9]+,)+$/i',"{$useridlist},")) {
				show_msg($lang['sys.info'],$lang['space.info276'],0,'','',$lang['url'],$lang['cmdback']);
				exit;
			}
			$db->query("UPDATE {$dv}space_apply_today_star SET status='0' WHERE status='1'");
			$db->query("UPDATE {$dv}space_apply_today_star SET status='1' WHERE userid IN ({$useridlist})");
		} else {
			$db->query("UPDATE {$dv}space_apply_today_star SET status='0' WHERE status<>'0'");
		}
	} elseif ('delselected' === $_POST['doaction']) {	//	删除所选（包括取消审核）
		if (!empty($today_star_del_userid) AND is_array($today_star_del_userid)) {
			$useridlist = implode(',', $today_star_del_userid);
			if (0 ==  preg_match('/^(?:[0-9]+,)+$/i',"{$useridlist},")) {
				show_msg($lang['sys.info'],$lang['space.info276'],0,'','',$lang['url'],$lang['cmdback']);
				exit;
			}
			$db->query("DELETE FROM {$dv}space_apply_today_star WHERE userid IN({$useridlist})");
		} else {	//	请选择要操作的目标！
			show_msg($lang['sys.info'],$lang['space.info275'],0,'','',$lang['url'],$lang['cmdback']);
			exit;
		}
	} elseif ('delbyday' === $_POST['doaction']) {	//	删除 N 天以前的数据
		$del_day = trim($_POST['del_day']);
		if (!is_numeric($del_day) OR $del_day < 0) {
			show_msg($lang['sys.info'],$lang['space.info280'],0,'','',$lang['url'],$lang['cmdback']);
			exit;
		}
		if (0 == $del_day) {
			$db->query("TRUNCATE TABLE {$dv}space_apply_today_star");
		} else {
			$unixtimestamp =time()+date('Z')-getUserTimeZoneOffset()-($del_day*24*3600);
			$db->query("DELETE FROM {$dv}space_apply_today_star WHERE apply_timestamp<='{$unixtimestamp}'");
		}
	} else {	//	参数错误
		show_msg($lang['sys.info'],$lang['space.info276'],0,'','',$lang['url'],$lang['cmdback']);
		exit;
	}
	$today_star_cache =& $db->getResultSet("SELECT userid, username, nickname, user_photo, (CASE WHEN user_preview_photo<>'' THEN user_preview_photo ELSE user_photo END) AS user_preview_photo FROM {$dv}space_apply_today_star WHERE status<>'0'", array('pageSize'=>2));
	if ($today_star_cache !== false) {
		$db->query("UPDATE {$dv}space_system SET today_star='".base64_encode(serialize($today_star_cache))."'");
	} else {
		$db->query("UPDATE {$dv}space_system SET today_star=''");
	}
	include_once INC_PATH.'BoardCache.class.php';
	$objcache =& new BoardCache($db);
	if ($objcache->createSpaceConfig()) {
		unset($objcache, $today_star_cache);
		show_msg($lang['sys.info'],$lang['space.info278'],1,'','',$lang['url'],$lang['cmdback']);
		exit;
	} else {
		unset($objcache, $today_star_cache);
		show_msg($lang['sys.info'],$lang['space.info279'],0,'','',$lang['url'],$lang['cmdback']);
		exit;
	}
}//end function do_today_star
function today_recommend()
{
	global $dv,$db,$db_today_recommend;
	$db_today_recommend = array(0=>array('', ''), 1=>array('', ''), 2=>array('', ''), 3=>array('', ''), 4=>array('', ''));
	if ($today_recommend = $db->scalar("SELECT today_recommend FROM {$dv}space_system")) {
		if ($unserialize = unserialize(base64_decode($today_recommend))) {
			$db_today_recommend = $unserialize;
		}
	}
}//end function today_recommend
function do_today_recommend()
{
	global $lang,$dv,$db;
	if (empty($_POST['arr_today_recommend'])) {
		$arr_today_recommend = array(0=>array('', ''), 1=>array('', ''), 2=>array('', ''), 3=>array('', ''), 4=>array('', ''));
	} else {
		$arr_today_recommend = $_POST['arr_today_recommend'];
	}
	if ($db->query("update {$dv}space_system set today_recommend='".$db->escape_string(base64_encode(serialize($arr_today_recommend)))."'")) {
		include_once INC_PATH.'BoardCache.class.php';
		$mycache =& new BoardCache($db);
		$mycache->createSpaceConfig();
		unset ($mycache);
		show_msg($lang['sys.info'],$lang['space.info242'],1,'','',$lang['url'],$lang['cmdback']);
		exit;
	} else {
		;
	}

}//end function do_today_recommend
function top1_spaceinfo(){
	global $lang,$dv,$db,$top_arr;
	$top_arr=array();
	$sql=$db->query("SELECT s_id,s_name,s_note,s_lastposttime,s_topicnum,s_photonum,s_favnum,s_usernum,s_todaynum,s_postnum,s_setting,s_url,s_sdomain,skinid FROM {$dv}space_system order by s_id",array('pageSize'=>1));
	while ($arr=$db->fetch_array($sql)){
		$top_arr[]=$arr;
	}
}
function space_info_setting(){
	global $lang,$dv,$db;
	$spaceName=$_POST['spacename'];
	$spaceUrl=$_POST['spaceurl'];
	$spaceDomain=$_POST['spacedomain'];
	$tmpstr="";
	$str_setting=$db->scalar("SELECT s_setting FROM {$dv}space_system");
	$str_setting=explode(",",$str_setting);
	for($i=0;$i<=20;$i++){		
		if($i==2){
			$tmpstr.="999"."|";
		}
		elseif($i==3){
			$tmpstr.="999"."|";
		}
		else{
			$tmp=$_POST['upload_setting'.$i];
			$tmpstr.=str_replace(",","",str_replace("|","",$tmp))."|";
		}
	}
	$upload_str=substr($tmpstr,0,-1);
	for($j=0;$j<100;$j++){
		$bktmp=$_POST['space_setting'.$j];
		if($bktmp==""){
			$tmp_str.="1";
		}
		if($j==12){
			$tmp_str=substr($tmp_str,0,-1);
			$tmp_str.=$upload_str.",";
			$tmp_str=substr($tmp_str,0,-1);
		}
		$tmp_str.=str_replace(" ","",str_replace(",","",$bktmp)).",";
	}
	$space_setting_str=substr($tmp_str,0,-1);
	$sql=$db->query("UPDATE {$dv}space_system SET s_name='".$spaceName."',s_url='".$spaceUrl."',s_sdomain='".$spaceDomain."',s_setting='".$space_setting_str."'");
	include_once INC_PATH.'BoardCache.class.php';
	$mycache =& new BoardCache($db);
	$mycache->createspaceConfig();
	unset ($mycache);
	if($sql){
		$tempsize= (float)($_POST['space_setting15']-$str_setting[15]);
		$db->query("UPDATE {$dv}space_user set spacesize=(spacesize+$tempsize)");
		show_msg($lang['sys.info'],$lang['space.info79'],1,'','',$lang['url'],$lang['cmdback']);
	exit;
	}
	else{
		show_msg($lang['sys.info'],$lang['space.info80'],0,'','',$lang['url'],$lang['cmdback']);
	exit;
	}
}
function lanmu_edit(){
	global $lang,$dv,$db,$id;
	$id=$_GET['id'];
	$title=str_replace(" ","",$_POST['title']);
	$note=htmlspecialchars($_POST['note']);
	if($id=="" or $id==0 or !is_numeric($id)){
		show_msg($lang['sys.info'],$lang['space.info95'],0,'','',$lang['url'],$lang['cmdback']);
	exit;
	}
	if($title=="" or $note==""){
		show_msg($lang['sys.info'],$lang['space.info96'],0,'','',$lang['url'],$lang['cmdback']);
	exit;
	}
	$sql=$db->query("UPDATE {$dv}space_syscat SET scattitle='".$title."',scatnote='".$note."' WHERE scatid=".intval($id)."");
	if($sql){
		show_msg($lang['sys.info'],$lang['space.info97'],1,'','',$lang['url'],$lang['cmdback']);
	exit;
	}
	else{
		show_msg($lang['sys.info'],$lang['space.info98'],0,'','',$lang['url'],$lang['cmdback']);
	exit;
	}
}
function lanmu_del(){
	global $lang,$dv,$db,$id;
	$id=$_GET['id'];
	if($id=="" or $id==0 or !is_numeric($id)){
		show_msg($lang['sys.info'],$lang['space.info95'],0,'','',$lang['url'],$lang['cmdback']);
	exit;
	}
	else{
		$sql=$db->query("DELETE FROM {$dv}space_syscat WHERE scatid=".intval($id)."");
		if($sql){
			show_msg($lang['sys.info'],$lang['space.info99'],1,'','',$lang['url'],$lang['cmdback']);
		exit;
		}
		else{
			show_msg($lang['sys.info'],$lang['space.info100'],0,'','',$lang['url'],$lang['cmdback']);
		exit;
		}
	}
}
function lanmu_list(){
	global $lang,$dv,$db,$list_info;
	$list_info=array();
	$t=intval($_GET['t']);
	if($t=="" or !is_numeric($t) or $t>2){
		show_msg($lang['sys.info'],$lang['space.info95'],0,'','',$lang['url'],$lang['cmdback']);
	exit;
	}
	$sql=$db->query("SELECT scatid,scattitle,scatnote,ucatnum,topicnum,postnum,todaynum,stype,lastuptime FROM {$dv}space_syscat WHERE stype=".($t-1)." order by scatid");
	while($arr=$db->fetch_array($sql)){
		$list_info[]=$arr;
	}
}
function lanum_editlist(){
	global $lang,$db,$dv,$id,$lanmu_edit_list;
	$lanmu_edit_list=array();
	$id=$_GET['id'];
	if(!is_numeric($id) or $id==0 or $id==""){
		show_msg($lang['sys.info'],$lang['space.info95'],0,'','',$lang['url'],$lang['cmdback']);
	exit;
	}
	$sql=$db->query("SELECT scatid,scattitle,scatnote FROM {$dv}space_syscat WHERE scatid=".intval($id)."");
	while ($arr=$db->fetch_array($sql)){
		$lanmu_edit_list[]=$arr;
	}
}
function lanmu_add(){
	global $lang,$dv,$db;
	$t=intval($_GET['t']);
	$title=str_replace(" ","",$_POST['title']);
	$note=str_replace(" ","",$_POST['note']);
	if($t=="" or $t==0){
		show_msg($lang['sys.info'],$lang['space.info96'],0,'','',$lang['url'],$lang['cmdback']);
	exit;
	}
	if($title=="" or $note==""){
		show_msg($lang['sys.info'],$lang['space.info96'],0,'','',$lang['url'],$lang['cmdback']);
	exit;
	}
	$sql=$db->query("INSERT INTO {$dv}space_syscat (scattitle,scatnote,stype) VALUES ('".$title."','".$note."','".($t-1)."')");
	if($sql){
		show_msg($lang['sys.info'],$lang['space.info112'],1,'','',$lang['url'],$lang['cmdback']);
	exit;
	}
	else{
		show_msg($lang['sys.info'],$lang['space.info113'],1,'','',$lang['url'],$lang['cmdback']);
	exit;
	}	
}
function user_manager(){
	global $lang,$dv,$db,$keyword,$page_size,$page,$total,$page_count,$offset,$p,$userinfo_list;
	$userinfo_list=array();
	$keyword=str_replace(" ","",$keyword);	$space_user_fielt="u.userid,u.username,u.nickname,u.spacename,u.password,u.spacetitle,u.spacechildtitle,u.spacenote,u.joinspacetime,u.pageview,u.topicnum,u.favnum,u.photonum,u.postnum,u.todaynum,u.trackbacks,u.spacesize,u.xmldata,u.syscatid,u.spacesetting,u.lastuptime,u.skinid,u.stats";
	if($keyword<>""){
		$total=$db->scalar("SELECT count(1) FROM {$dv}space_user u inner join {$dv}space_syscat c on u.syscatid=c.scatid WHERE u.username LIKE '%".$keyword."%' OR u.spacename LIKE '%".$keyword."%' OR u.spacetitle LIKE '%".$keyword."%' OR u.spacechildtitle LIKE '%".$keyword."%'");
		page_info(20);
		$sql=$db->query("SELECT ".$space_user_fielt.",c.scattitle FROM {$dv}space_user u inner join {$dv}space_syscat c on u.syscatid=c.scatid WHERE u.username LIKE '%".$keyword."%' OR u.spacename LIKE '%".$keyword."%' OR u.spacetitle LIKE '%".$keyword."%' OR u.spacechildtitle LIKE '%".$keyword."%' ORDER BY u.joinspacetime DESC",array('absolutePage'=>$offset,'pageSize'=>$page_size));
	}
	else{
		$total=$db->scalar("SELECT count(1) FROM {$dv}space_user u inner join {$dv}space_syscat c on u.syscatid=c.scatid");
		page_info(20);
		$sql=$db->query("SELECT ".$space_user_fielt.",c.scattitle FROM {$dv}space_user u inner join {$dv}space_syscat c on u.syscatid=c.scatid ORDER BY u.joinspacetime DESC",array('absolutePage'=>$offset,'pageSize'=>$page_size));
	}
	while ($arr=$db->fetch_array($sql)){
		$userinfo_list[]=$arr;
	}
}
function user_editinfo(){
	global $lang,$dv,$db,$id,$user_info;
	$user_info=array();
	$id=$_GET['id'];
	if(intval($id)==0 or $id=="" or !is_numeric($id)){
		show_msg($lang['sys.info'],$lang['space.info95'],0,'','',$lang['url'],$lang['cmdback']);
	exit;
	}
	$sql=$db->query("SELECT userid,username,nickname,spacename,password,spacetitle,spacechildtitle,spacenote,joinspacetime,pageview,topicnum,favnum,photonum,postnum,todaynum,trackbacks,spacesize,xmldata,syscatid,spacesetting,lastuptime,skinid,stats FROM {$dv}space_user WHERE userid=".intval($id)."");
	while($arr=$db->fetch_array($sql)){
		$user_info[]=$arr;
	}
}
function user_infoedit(){
	global $lang,$dv,$db,$id,$syscatid,$skinid,$spacename,$nickname,$password,$spacetitle,$spacechildtitle,$spacenote,$joinspacetime;
	global $todaynum,$topicnum,$postnum,$favnum,$photonum,$trackbacks,$pageview,$spacesize;
	$id=$_GET['id'];
	$syscatid=$_POST['syscatid'];
	$skinid=$_POST['skinid'];
	$spacename=str_replace(" ","",$_POST['spacename']);
	$nickname=str_replace(" ","",$_POST['nickname']);
	$password=$_POST['password'];
	$spacetitle=str_replace(" ","",$_POST['spacetitle']);
	$spacechildtitle=str_replace(" ","",$_POST['spacechildtitle']);
	$spacenote=$_POST['spacenote'];
	$joinspacetime=$_POST['joinspacetime'];
	$todaynum=$_POST['todaynum'];
	$topicnum=$_POST['topicnum'];
	$postnum=$_POST['postnum'];
	$favnum=$_POST['favnum'];
	$photonum=$_POST['photonum'];
	$trackbacks=$_POST['trackbacks'];
	$pageview=$_POST['pageview'];
	$spacesize=$_POST['spacesize'];
	if(intval($id)==0 or $id=="" or !is_numeric($id)){
		show_msg($lang['sys.info'],$lang['space.info95'],0,'','',$lang['url'],$lang['cmdback']);
	exit;
	}
	if($password<>""){
		$newpassword=dv_md5($password);
	}
	if($syscatid=="" or $skinid=="" or $spacename=="" or $nickname=="" or $spacetitle=="" or $spacechildtitle=="" or $spacenote=="" or $joinspacetime=="" or !is_numeric($todaynum) or !is_numeric($topicnum) or !is_numeric($postnum) or !is_numeric($favnum) or !is_numeric($photonum) or !is_numeric($trackbacks) or !is_numeric($pageview) or !is_numeric($spacesize)){
		show_msg($lang['sys.info'],$lang['space.info158'],0,'','',$lang['url'],$lang['cmdback']);
	exit;
	}
	else{
		if($newpassword<>""){
			$sql=$db->query("UPDATE {$dv}space_user SET spacename='".$spacename."',nickname='".$nickname."',spacetitle='".$spacetitle."',spacechildtitle='".$spacechildtitle."',spacenote='".$spacenote."',password='".$newpassword."',syscatid=".intval($syscatid).",skinid=".intval($skinid).",joinspacetime='".$joinspacetime."',todaynum=".intval($todaynum).",topicnum=".intval($topicnum).",postnum=".intval($postnum).",favnum=".intval($favnum).",photonum=".intval($photonum).",trackbacks=".intval($trackbacks).",pageview=".intval($pageview).",spacesize=".intval($spacesize)." WHERE userid=".intval($id)."");
		}
		else{
			$sql=$db->query("UPDATE {$dv}space_user SET spacename='".$spacename."',nickname='".$nickname."',spacetitle='".$spacetitle."',spacechildtitle='".$spacechildtitle."',spacenote='".$spacenote."',syscatid=".intval($syscatid).",skinid=".intval($skinid).",joinspacetime='".$joinspacetime."',todaynum=".intval($todaynum).",topicnum=".intval($topicnum).",postnum=".intval($postnum).",favnum=".intval($favnum).",photonum=".intval($photonum).",trackbacks=".intval($trackbacks).",pageview=".intval($pageview).",spacesize=".intval($spacesize)." WHERE userid=".intval($id)."");
		}
		if($sql){
			show_msg($lang['sys.info'],$lang['space.info97'],1,'','',$lang['url'],$lang['cmdback']);
		exit;
		}
		else{
			show_msg($lang['sys.info'],$lang['space.info98'],0,'','',$lang['url'],$lang['cmdback']);
		exit;
		}
	}
}
function user_infodel(){
	global $lang,$dv,$db,$id;
	$id=$_GET['id'];
	if(intval($id)==0 or $id=="" or !is_numeric($id)){
		show_msg($lang['sys.info'],$lang['space.info95'],0,'','',$lang['url'],$lang['cmdback']);
	exit;
	}
	$sql=$db->query("SELECT userid,username,nickname,spacename,password,spacetitle,spacechildtitle,spacenote,joinspacetime,pageview,topicnum,favnum,photonum,postnum,todaynum,trackbacks,spacesize,xmldata,syscatid,spacesetting,lastuptime,skinid,stats FROM {$dv}space_user WHERE userid=".intval($id)."");
	while ($arr=$db->fetch_array($sql)){
		$stmt_1=$db->query("UPDATE {$dv}space_syscat SET ucatnum=ucatnum-1,topicnum=topicnum-".$arr['topicnum'].",postnum=postnum-".$arr['postnum']." WHERE scatid=".$arr['syscatid']."");
		$stmt_2=$db->query("UPDATE {$dv}space_system SET s_usernum=s_usernum-1,s_topicnum=s_topicnum-".$arr['topicnum'].",s_postnum=s_postnum-".$arr['postnum'].",s_photonum=s_photonum-".$arr['photonum'].",s_favnum=s_favnum-".$arr['favnum']."");
	}
	include_once INC_PATH.'BoardCache.class.php';
	$mycache =& new BoardCache($db);
	$mycache->createspaceConfig();
	unset ($mycache);
	//删除用户文章;
	$sql1=$db->query("DELETE FROM {$dv}space_topic WHERE userid=".intval($id)."");
	$sql2=$db->query("DELETE FROM {$dv}space_post WHERE spaceuserid=".intval($id)."");
	$sql3=$db->query("DELETE FROM {$dv}space_upfile WHERE spaceuserid=".intval($id)."");
	$sql4=$db->query("DELETE FROM {$dv}space_keyword WHERE userid=".intval($id)."");
	$sql5=$db->query("DELETE FROM {$dv}space_usercat WHERE userid=".intval($id)."");
	$sql6=$db->query("DELETE FROM {$dv}space_usersave WHERE userid=".intval($id)."");
	$sql7=$db->query("DELETE FROM {$dv}space_user WHERE userid=".intval($id)."");
	if($sql1 or $sql2 or $sql3 or $sql4 or $sql5 or $sql6 or $sql7){
		show_msg($lang['sys.info'],$lang['space.info162'],1,'','',$lang['url'],$lang['cmdback']);
	exit;
	}
	else{
		show_msg($lang['sys.info'],$lang['space.info163'],0,'','',$lang['url'],$lang['cmdback']);
	exit;
	}
}
function user_item_list(){
	global $lang,$dv,$db,$keyword,$page_size,$page,$total,$page_count,$offset,$p,$userinfo_list;
	$userinfo_list=array();
	$keyword=str_replace(" ","",$_POST['keyword']);	$space_user_fielt="c.ucatid,c.userid,c.ucattitle,c.ucatnote,c.opentime,c.utype,c.topicnum,c.postnum,c.todaynum,c.isview,c.lastuptime";
	if($keyword<>""){
		$total=$db->scalar("SELECT count(1) FROM {$dv}space_usercat c inner join {$dv}space_user u on c.userid=u.userid WHERE u.username LIKE '%".$keyword."%' OR u.spacename LIKE '%".$keyword."%' OR c.ucattitle LIKE '%".$keyword."%' OR c.ucatnote LIKE '%".$keyword."%'");
		page_info(20);
		$sql=$db->query("SELECT ".$space_user_fielt.",u.username,u.spacename FROM {$dv}space_usercat c inner join {$dv}space_user u on c.userid=u.userid WHERE u.username LIKE '%".$keyword."%' OR u.spacename LIKE '%".$keyword."%' OR c.ucattitle LIKE '%".$keyword."%' OR c.ucatnote LIKE '%".$keyword."%' order by ucatid Desc",array('absolutePage'=>$offset,'pageSize'=>$page_size));
	}
	else{
		$total=$db->scalar("SELECT count(1) FROM {$dv}space_usercat c inner join {$dv}space_user u on c.userid=u.userid");
		page_info(20);
		$sql=$db->query("SELECT ".$space_user_fielt.",u.username,u.spacename FROM {$dv}space_usercat c inner join {$dv}space_user u on c.userid=u.userid order by ucatid desc",array('absolutePage'=>$offset,'pageSize'=>$page_size));
	}
	while ($arr=$db->fetch_array($sql)){
		$userinfo_list[]=$arr;
	}
}
function item_editlist(){
	global $lang,$db,$dv,$id,$lanmu_edit_list;
	$lanmu_edit_list=array();
	$id=$_GET['id'];
	if(!is_numeric($id) or $id=="" or $id==0){
		show_msg($lang['sys.info'],$lang['space.info95'],0,'','',$lang['url'],$lang['cmdback']);
	exit;
	}
	$sql=$db->query("SELECT ucatid,userid,ucattitle,ucatnote,opentime,utype,topicnum,postnum,todaynum,isview,lastuptime FROM {$dv}space_usercat WHERE ucatid=".intval($id)."");
	while ($arr=$db->fetch_array($sql)){
		$lanmu_edit_list[]=$arr;
	}
}
function item_edit(){
	global $lang,$dv,$db,$id;
	$id=$_GET['id'];
	$title=str_replace(" ","",$_POST['title']);
	$note=htmlspecialchars($_POST['note']);
	if($id=="" or $id==0 or !is_numeric($id)){
		show_msg($lang['sys.info'],$lang['space.info95'],0,'','',$lang['url'],$lang['cmdback']);
	exit;
	}
	if($title=="" or $note==""){
		show_msg($lang['sys.info'],$lang['space.info96'],0,'','',$lang['url'],$lang['cmdback']);
	exit;
	}
	$sql=$db->query("UPDATE {$dv}space_usercat SET ucattitle='".$title."',ucatnote='".str_replace("'","''",$note)."' WHERE ucatid=".intval($id)."");
	if($sql){
		show_msg($lang['sys.info'],$lang['space.info97'],1,'','',$lang['url'],$lang['cmdback']);
	exit;
	}
	else{
		show_msg($lang['sys.info'],$lang['space.info98'],0,'','',$lang['url'],$lang['cmdback']);
	exit;
	}
}
function item_del(){
	global $lang,$dv,$db,$id;
	$id=$_GET['id'];
	if($id=="" or $id==0 or !is_numeric($id)){
		show_msg($lang['sys.info'],$lang['space.info95'],0,'','',$lang['url'],$lang['cmdback']);
	exit;
	}
	else{
		$sql=$db->query("DELETE FROM {$dv}space_usercat WHERE ucatid=".intval($id)."");
		if($sql){
			show_msg($lang['sys.info'],$lang['space.info99'],1,'','',$lang['url'],$lang['cmdback']);
		exit;
		}
		else{
			show_msg($lang['sys.info'],$lang['space.info100'],0,'','',$lang['url'],$lang['cmdback']);
		exit;
		}
	}
}
function ad_list(){
	global $dv,$db,$ad_info;
	$ad_info=array();
	$sql=$db->query("SELECT s_topnews,s_managenews FROM {$dv}space_system");
	while ($arr=$db->fetch_array($sql)){
		$ad_info[]=$arr;
	}
}
function ad_manager($type){
	global $lang,$dv,$db,$spacetopnews,$spacemanagenews;
	$spacetopnews=trim($_POST['spacetopnews']);
	$spacemanagenews=trim($_POST['spacemanagenews']);
	$type=intval($type);
	if($type==0 or $type=="" or !is_numeric($type)){
		show_msg($lang['sys.info'],$lang['space.info95'],0,'','',$lang['url'],$lang['cmdback']);
	exit;
	}
	if($type==1){
		$sql=$db->query("UPDATE {$dv}space_system SET s_topnews='".$spacetopnews."'");
		include_once INC_PATH.'BoardCache.class.php';
		$mycache =& new BoardCache($db);
		$mycache->createspaceConfig();
		unset ($mycache);
		if($sql){
			show_msg($lang['sys.info'],$lang['space.info97'],1,'','',$lang['url'],$lang['cmdback']);
		exit;
		}
		else{
			show_msg($lang['sys.info'],$lang['space.info98'],0,'','',$lang['url'],$lang['cmdback']);
		exit;
		}
	}
	else{
		$sql=$db->query("UPDATE {$dv}space_system SET s_managenews='".$spacemanagenews."'");
		include_once INC_PATH.'BoardCache.class.php';
		$mycache =& new BoardCache($db);
		$mycache->createspaceConfig();
		unset ($mycache);
		if($sql){
			show_msg($lang['sys.info'],$lang['space.info97'],1,'','',$lang['url'],$lang['cmdback']);
		exit;
		}
		else{
			show_msg($lang['sys.info'],$lang['space.info98'],0,'','',$lang['url'],$lang['cmdback']);
		exit;
		}
	}
}
function keyword_list(){
	global $lang,$dv,$db,$keyword,$page_size,$page,$total,$page_count,$offset,$p,$userinfo_list;
	$userinfo_list=array();
	$keyword=str_replace(" ","",$keyword);	$space_user_fielt="k.keyid,k.userid,k.keyword,k.nkeyword,k.linkurl,k.linktitle,k.newwindows";
	if($keyword<>""){
		$total=$db->scalar("SELECT count(1) FROM {$dv}space_keyword k inner join {$dv}space_user u on k.userid=u.userid WHERE u.username LIKE '%".$keyword."%' OR u.spacename LIKE '%".$keyword."%' OR k.keyword LIKE '%".$keyword."%' OR k.keyword LIKE '%".$keyword."%' OR k.linkurl LIKE '%".$keyword."%' OR k.linktitle LIKE '%".$keyword."%'");
		page_info(20);
		$sql=$db->query("SELECT ".$space_user_fielt.",u.username,u.spacename FROM {$dv}space_keyword k inner join {$dv}space_user u on k.userid=u.userid WHERE u.username LIKE '%".$keyword."%' OR u.spacename LIKE '%".$keyword."%' OR k.keyword LIKE '%".$keyword."%' OR k.keyword LIKE '%".$keyword."%' OR k.linkurl LIKE '%".$keyword."%' OR k.linktitle LIKE '%".$keyword."%' order by keyid desc",array('absolutePage'=>$offset,'pageSize'=>$page_size));
	}
	else{
		$total=$db->scalar("SELECT count(1) FROM {$dv}space_keyword k inner join {$dv}space_user u on k.userid=u.userid");
		page_info(20);
		$sql=$db->query("SELECT ".$space_user_fielt.",u.username,u.spacename FROM {$dv}space_keyword k inner join {$dv}space_user u on k.userid=u.userid order by keyid desc",array('absolutePage'=>$offset,'pageSize'=>$page_size));
	}
	while ($arr=$db->fetch_array($sql)){
		$userinfo_list[]=$arr;
	}
}
function keyword_editlist(){
	global $lang,$dv,$db,$keyid,$lanmu_edit_list;
	$lanmu_edit_list=array();
	$keyid=$_GET['keyid'];
	if($keyid=="" or $keyid==0 or !is_numeric($keyid)){
		show_msg($lang['sys.info'],$lang['space.info95'],0,'','',$lang['url'],$lang['cmdback']);
	exit;
	}
	$sql=$db->query("SELECT keyid,userid,keyword,nkeyword,linkurl,linktitle,newwindows FROM {$dv}space_keyword WHERE keyid=".intval($keyid)."");
	while ($arr=$db->fetch_array($sql)){
		$lanmu_edit_list[]=$arr;
	}
}
function keyword_editok(){
	global $lang,$dv,$db,$keyid,$keyword,$nkeyword,$linkurl,$linktitle,$newwindows;
	$keyid=$_GET['keyid'];
	$keyword=htmlspecialchars($_POST['keyword']);
	$nkeyword=htmlspecialchars($_POST['nkeyword']);
	$linkurl=htmlspecialchars($_POST['linkurl']);
	$linktitle=htmlspecialchars($_POST['linktitle']);
	$newwindows=$newwindows;
	if($keyid=="" or $keyid==0 or !is_numeric($keyid)){
		show_msg($lang['sys.info'],$lang['space.info95'],0,'','',$lang['url'],$lang['cmdback']);
	exit;
	}
	if($keyword=="" or $nkeyword=="" or $linkurl=="" or $linktitle=="" or $newwindows==""){
		show_msg($lang['sys.info'],$lang['space.info96'],0,'','',$lang['url'],$lang['cmdback']);
	exit;
	}
	$sql=$db->query("UPDATE {$dv}space_keyword SET keyword='".$keyword."',nkeyword='".str_replace("'","''",$nkeyword)."',linkurl='".$linkurl."',linktitle='".$linktitle."',newwindows=".$newwindows." WHERE keyid=".intval($keyid)."");
	if($sql){
		show_msg($lang['sys.info'],$lang['space.info162'],1,'','',$lang['url'],$lang['cmdback']);
	exit;
	}
	else{
		show_msg($lang['sys.info'],$lang['space.info163'],0,'','',$lang['url'],$lang['cmdback']);
	exit;
	}
}
function keyword_del(){
	global $lang,$dv,$db,$keyid;
	$keyid=$_POST['keyid'];
	if(count($keyid)<=0){
		show_msg($lang['sys.info'],$lang['space.info164'],0,'','',$lang['url'],$lang['cmdback']);
	exit;
	}
	else{
		$num=count($keyid);
		for($i=0;$i<$num;$i++){
			$id.=$keyid[$i].",";
		}
		$id=substr($id,0,-1);
		$sql=$db->query("DELETE FROM {$dv}space_keyword WHERE keyid in (".$id.")");
		if($sql){
			show_msg($lang['sys.info'],$lang['space.info162'],1,'','',$lang['url'],$lang['cmdback']);
		exit;
		}
		else{
			show_msg($lang['sys.info'],$lang['space.info163'],0,'','',$lang['url'],$lang['cmdback']);
		exit;
		}
	}
}
function file_list(){
	global $lang,$dv,$db,$file_list,$page_size,$page,$total,$page_count,$offset,$p;
	$file_list=array();
	$total=$db->scalar("SELECT count(1) FROM {$dv}space_upfile");
	page_info(20);
	$sql=$db->query("SELECT id,spaceuserid,userid,username,catid,stype,topicid,postid,istopic,title,filename,sfilename,filetype,filesize,filenote,downnum,viewnum,dateandtime,previewimage,islock FROM {$dv}space_upfile order by id desc",array('absolutePage'=>$offset,'pageSize'=>$page_size));
	while($arr=$db->fetch_array($sql)){
		$file_list[]=$arr;
	}
}
function file_del(){
	global $lang,$dv,$db,$fid;
	$f_root="../";
	$fid=$_GET['fid'];
	if($fid=="" or $fid==0 or !is_numeric($fid)){
		show_msg($lang['sys.info'],$lang['space.info95'],0,'','',$lang['url'],$lang['cmdback']);
	exit;
	}
	$sql=$db->query("SELECT id,spaceuserid,userid,username,catid,stype,topicid,postid,istopic,title,filename,sfilename,filetype,filesize,filenote,downnum,viewnum,dateandtime,previewimage,islock FROM {$dv}space_upfile WHERE id=".intval($fid)."");
	while ($arr=$db->fetch_array($sql)){
		$file_size=intval((intval($arr['filesize'])/1024)/1024);
		$view_path=$arr['previewimage'];
		$file_path=$arr['filename'];
		if($file_path<>""){
			$file_path =$systemUpSetting[19].$file_path;
		}
		$stmt=$db->query("SELECT spacesize FROM {$dv}space_user WHERE userid=".$arr['spaceuserid']."");
		while ($set=$db->fetch_array($stmt)){
			if(intval($set['spacesize'])>0){
				$space_size =$set['spacesize']-$file_size;
				if($space_size<0){
					$space_size=0;
				}
				$sql_2=$db->query("UPDATE {$dv}space_user SET spacesize=".$space_size." WHERE userid=".$arr['spaceuserid']."");
			}
		}
		$del_sql=$db->query("DELETE FROM {$dv}space_upfile WHERE id=".$fid."");
		if($view_path<>""){
			if(is_file($f_root.$view_path)){
				unlink($f_root.$view_path);
			}
		}
		if($file_path<>""){
			if(is_file($f_root.$file_path)){
				unlink($f_root.$file_path);
			}
		}
	}
	if($del_sql){
		show_msg($lang['sys.info'],$lang['space.info162'],1,'','',$lang['url'],$lang['cmdback']);
	exit;
	}
	else{
		show_msg($lang['sys.info'],$lang['space.info163'],0,'','',$lang['url'],$lang['cmdback']);
	exit;
	}
}
function space_user_count(){
	global $lang,$dv,$db;
	$total=$db->scalar("SELECT count(*) FROM {$dv}space_user");
	$sql=$db->query("UPDATE {$dv}space_system SET s_usernum=".$total."");
	include_once INC_PATH.'BoardCache.class.php';
	$mycache =& new BoardCache($db);
	$mycache->createspaceConfig();
	unset ($mycache);
	if($sql){
		show_msg($lang['sys.info'],$lang['space.info197'].$total.$lang['space.info198'],1,'','',$lang['url'],$lang['cmdback']);
	exit;
	}
	else{
		show_msg($lang['sys.info'],$lang['space.info199'],0,'','',$lang['url'],$lang['cmdback']);
	exit;
	}
}
function space_total_data(){
	global $lang,$dv,$db,$pageSize;
	$S_TopicNum=$db->scalar("SELECT count(*) FROM {$dv}space_topic WHERE stype='0'");
	$S_PhotoNum=$db->scalar("SELECT count(*) FROM {$dv}space_topic WHERE stype='4'");
	$S_FavNum=$db->scalar("SELECT count(*) FROM {$dv}space_topic WHERE stype='1'");
	$S_PostNum=$db->scalar("SELECT count(*) FROM {$dv}space_post WHERE parentid>0");
	$S_TodayNum=$db->scalar("SELECT count(*) FROM {$dv}space_post WHERE jointime between ".dv_gmtimestamp(gmdate('Y-m-d 00:00:00'))." and ".dv_gmtimestamp(gmdate('Y-m-d 23:59:59'))."");
	$sql=$db->query("SELECT jointime FROM {$dv}space_post order by jointime desc",array('pageSize'=>1));
	$topnum=$db->num_rows($sql);
	if($topnum<=0){
		$S_LastPostTime=strtotime("now");
	}
	else{
		$arr=$db->fetch_array($sql);
		$S_LastPostTime=$arr['jointime'];
	}
	$stmt=$db->query("UPDATE {$dv}space_system SET s_lastposttime='".$S_LastPostTime."',s_topicnum=".$S_TopicNum.",s_photonum=".$S_PhotoNum.",s_favnum=".$S_FavNum.",s_todaynum=".$S_TodayNum.",s_postnum=".$S_PostNum."");
	include_once INC_PATH.'BoardCache.class.php';
	$mycache =& new BoardCache($db);
	$mycache->createspaceConfig();
	unset ($mycache);	$info=$lang['space.info200'].$lang['space.info201'].$S_TopicNum.$lang['space.info202'].$S_PhotoNum.$lang['space.info203'].$S_FavNum.$lang['space.info204'].$S_PostNum.$lang['space.info205'].$S_TodayNum.$lang['space.info206'].gmdate('Y-m-d H:i',$S_LastPostTime+getUserTimeZoneOffset());
	if($stmt){
		show_msg($lang['sys.info'],$info,1,'','',$lang['url'],$lang['cmdback']);
	exit;
	}
	else{
		show_msg($lang['sys.info'],$lang['space.info207'],0,'','',$lang['url'],$lang['cmdback']);
	exit;
	}
}
function space_index_data(){
	global $lang,$dv,$db,$spaceConfig_Syscat;
	$into_str="";
	if(count($spaceConfig_Syscat)>0){
		foreach ($spaceConfig_Syscat as $note_value){
			$uCatNum=$db->scalar("SELECT count(*) FROM {$dv}space_user WHERE syscatid=".$note_value['scatid']."");
			$TopicNum=$db->scalar("SELECT sum(topicnum) FROM {$dv}space_user WHERE syscatid=".$note_value['scatid']."");
			$PostNum=$db->scalar("SELECT sum(postnum) FROM {$dv}space_user WHERE syscatid=".$note_value['scatid']."");
			$TodayNum=$db->scalar("SELECT sum(todaynum) FROM {$dv}space_user WHERE syscatid=".$note_value['scatid']."");
			$sql=$db->query("SELECT lastuptime FROM {$dv}space_user WHERE syscatid=".$note_value['scatid']." order by lastuptime desc",array('pageSize'=>1));
			$num=$db->num_rows($sql);
			if($num<=0){
				$LastUpTime=strtotime("now");
			}
			else{
				$arr=$db->fetch_array($sql);
				$LastUpTime=$arr['lastuptime'];
			}
			if(is_null($TopicNum)){
				$TopicNum=0;
			}
			if(is_null($PostNum)){
				$PostNum=0;
			}
			if(is_null($TodayNum)){
				$TodayNum=0;
			}
			$stmt=$db->query("UPDATE {$dv}space_syscat SET ucatnum=".$uCatNum.",topicnum=".$TopicNum.",postnum=".$PostNum.",todaynum=".$TodayNum.",lastuptime='".$LastUpTime."' where scatid=".$note_value['scatid']."");
			$into_str.="<b>".$note_value['scattitle']."</b>".$lang['space.info208'].$uCatNum.$lang['space.info209'].$TopicNum.$lang['space.info210'].$PostNum.$lang['space.info211'].$TodayNum.$lang['space.info212'].gmdate('Y-m-d H:i',$LastUpTime+getUserTimeZoneOffset())."<br>";
		}
		if($stmt){
			show_msg($lang['sys.info'],$into_str,1,'','',$lang['url'],$lang['cmdback']);
		exit;
		}
		else{
			show_msg($lang['sys.info'],$lang['space.info207'],0,'','',$lang['url'],$lang['cmdback']);
		exit;
		}
	}
}
function space_topic_data(){
	global $lang,$dv,$db,$spaceConfig_Syschatcat;
	$info_str="";
	if(count($spaceConfig_Syschatcat)>0){
		foreach($spaceConfig_Syschatcat as $note_value){
			$TopicNum= $db->scalar("SELECT count(topicid) FROM {$dv}space_topic WHERE scatid=".$note_value['scatid']."");
			$PostNum=$db->scalar("SELECT count(postid) FROM {$dv}space_post WHERE parentid>0 and  scatid=".$note_value['scatid']."");
			$TodayNum=$db->scalar("SELECT count(postid) FROM {$dv}space_post WHERE scatid=".$note_value['scatid']." and jointime between ".dv_gmtimestamp(gmdate('Y-m-d'))." and ".dv_gmtimestamp(gmdate('Y-m-d 23:59:59'))."");

			$sql=$db->query("SELECT jointime FROM {$dv}space_post WHERE scatid=".$note_value['scatid']." order by jointime desc",array('pageSize'=>1));
			$num=$db->num_rows($sql);
			if($num<=0){
				$LastUpTime=strtotime("now");
			}
			else{
				$arr=$db->fetch_array($sql);
				$LastUpTime=$arr['jointime'];
			}
			$stmt=$db->query("UPDATE {$dv}space_syscat SET  topicnum=".$TopicNum.",postnum=".$PostNum.",todaynum=".$TodayNum.",lastuptime='".$LastUpTime."' where scatid=".$note_value['scatid']."");
			$info_str.="<b>".$note_value['scattitle']."</b>".$lang['space.info208'].$TopicNum.$lang['space.info210'].$PostNum.$lang['space.info211'].$TodayNum.$lang['space.info212'].gmdate('Y-m-d H:i',$LastUpTime+getUserTimeZoneOffset())."<br>";
		}
		if($stmt){
			show_msg($lang['sys.info'],$info_str,1,'','',$lang['url'],$lang['cmdback']);
		exit;
		}
		else{
			show_msg($lang['sys.info'],$lang['space.info207'],0,'','',$lang['url'],$lang['cmdback']);
		exit;
		}
	}
}
function space_total_updata(){
	global $lang,$dv,$db,$spaceConfig_UserCat,$space_setting;
	static $load_usercat = array( 'result_set' => array() ,'spacetopic' => array() ,'spacelink' => array() ,'spacephoto' => array() ,'spacepost' => array() ,'spacekeyword' => array() );
	$spaceUserCount=$db->scalar("SELECT count(1) FROM {$dv}space_user");
	if($spaceUserCount=="" or is_null($spaceUserCount)){
		exit;
	}
	else{
		$sql=$db->query("SELECT userid,spacename,xmldata FROM {$dv}space_user");
		while ($arr=$db->fetch_array($sql)){
			$arr_xml=unserialize($arr['xmldata']);
			$uTopicNum =$db->scalar("SELECT count(1) FROM {$dv}space_topic WHERE stype='0' and userid=".$arr['userid']."");
			$uFavNum =$db->scalar("SELECT count(1) FROM {$dv}space_topic WHERE stype='1' and userid=".$arr['userid']."");
			$uPhotoNum =$db->scalar("SELECT count(1) FROM {$dv}space_topic WHERE stype='4' and userid=".$arr['userid']."");
			$uTodayNum =$db->scalar("SELECT count(1) FROM {$dv}space_post WHERE spaceuserid=".$arr['userid']." and jointime between ".dv_gmtimestamp(gmdate('Y-m-d'))." and ".dv_gmtimestamp(gmdate('Y-m-d 23:59:59'))."");
			$uPostNum =$db->scalar("SELECT count(1) FROM {$dv}space_post WHERE parentid>0 and spaceuserid=".$arr['userid']."");
			if( !is_numeric($space_setting[6])){
				$space_setting[6]=10;
			}
			$stmt=$db->query("SELECT topicid,catid,scatid,userid,username,title,titlenote,posttime,child,hits,isview,islock,stype,lastposttime,isbest,s_key,weather FROM {$dv}space_topic WHERE userid=".$arr['userid']." and stype<>2 order by posttime desc",array('pageSize'=>$space_setting[6]));
			for ( $i = 0 ; ($set=$db->fetch_array($stmt))!==false ; $i++ ){
				$spaceConfig_UserCat['spacetopic'][$i] = $set;
				if($set['titlenote']=="" or is_null($titlenote)){
					$space_body=$db->scalar("SELECT content FROM {$dv}space_post WHERE parentid=0 and rootid=".$set['topicid']."");
					if(strlen($space_body)>250){
						$space_body=more_substr($space_body,0,500);
					}
				}
				else{
					$space_body=$set['titlenote'];
				}
				$space_body=&spaceUbbCode($space_body)."...<br>[<a href=\"../space.php?".$arr['spacename'].".showtopic.".$set['topicid'].".html\">".$lang['space.info256']."</a>]";
				$spaceConfig_UserCat['spacetopic'][$i]['titlenote']=$space_body;
			}
			$xml_str=$db->escape_string(serialize($load_usercat));
			$upsql=$db->query("Update {$dv}space_user SET xmldata='".$xml_str."',topicnum=".$uTopicNum.",favnum=".$uFavNum.",photonum=".$uPhotoNum.",todaynum=".$uTodayNum.",postnum=".$uPostNum." WHERE userid=".$arr['userid']."");

			require_once '../inc/dv_spacemain.php';
			Update_TopicToXml($arr['userid']);
		}
		if($upsql>0){
			show_msg($lang['sys.info'],$lang['space.info234'].$spaceUserCount.$lang['space.info235'],1,'','',$lang['url'],$lang['cmdback']);
		exit;
		}
		else{
			show_msg($lang['sys.info'],$lang['space.info236'],0,'','',$lang['url'],$lang['cmdback']);
		exit;
		}
	}
}

//更新首页主题数据,这个函数比前台的多传了一个参数$spaceUserID
function Update_TopicToXml($spaceUserID,$mustupdatedb=true){
	global $dv,$db,$lang,$spaceUserCat,$spaceSetting,$spaceName,$_objEnc;
	if( !is_numeric($spaceSetting[6]) ){
		$spaceSetting[6] = 10;
	}
	$spaceconfig_usercat =array( 'result_set' => array() ,'spacetopic' => array() ,'spacelink' => array() ,'spacephoto' => array() ,'spacepost' => array() ,'spacekeyword' => array(), 'spacemusic' => array(), 'selected_templates_prev' => 'default.' );
	if ($spaceSetting[6] < 1) {
		$spaceSetting[6] = 20;
	}
	unset($spaceconfig_usercat['spacetopic']);
	if ($query = $db->query("SELECT /*!40001 SQL_CACHE */ topicid,catid,scatid,userid,username,title,titlenote,posttime,child,hits,isview,islock,stype,lastposttime,isbest,s_key,weather FROM {$dv}space_topic /*!32312 USE INDEX(newly_topic_by_user) */ WHERE userid='{$spaceUserID}' AND stype>=0 AND islock<3 ORDER BY topicid DESC",array('pageSize'=>$spaceSetting[6]))) {
		while ($topicinfo =& $db->fetch_array($query)) {
			$titlenote = trim($topicinfo['titlenote']);
			if ('' === $titlenote) {
				$titlenote = trim($db->scalar("SELECT content FROM {$dv}space_post WHERE parentid=0 AND rootid='{$topicinfo['topicid']}'"));
			}
			if ($titlenote !== '' ) {
				$_ubbcode = stripslashes(spaceUbbCode($titlenote, false));
				$titlenote =& getTitleNote($_ubbcode, 0, $spaceSetting[2]);
				$titlenote =& _imgaddjscode($titlenote);
				$db->query("UPDATE {$dv}space_topic SET titlenote='".$db->escape_string($titlenote)."' WHERE topicid='{$topicinfo['topicid']}'");
			}
			$topicinfo['titlenote'] = $titlenote;
			$spaceconfig_usercat['spacetopic'][] =& $topicinfo;
		}
		$db->free_result($query);
	}
	if (empty($spaceconfig_usercat['spacetopic'])) {
		$spaceconfig_usercat['spacetopic'] = array();
	}
	if (true === $mustupdatedb) {
		$db->query("UPDATE {$dv}space_user SET xmldata='".$db->escape_string(base64_encode(serialize($spaceconfig_usercat)))."' WHERE userid='{$spaceUserID}'");
	}
}//end function Update_TopicToXml

function tmplate_list(){
	global $lang,$dv,$db,$tmp_list,$page_size,$page,$total,$page_count,$offset,$p;
	$tmp_list=array();
	$total=$db->scalar("SELECT count(1) FROM {$dv}space_skins");
	page_info(20);
	$sql=$db->query("SELECT s_id,s_skinname,s_path,s_viewpic,s_info,s_builder FROM {$dv}space_skins",array('absolutePage'=>$offset,'pageSize'=>$page_size));
	while ($arr=$db->fetch_array($sql)){
		$tmp_list[]=$arr;
	}
}
function add_tmplate(){
	global $lang,$db,$dv,$tmp_name,$provide,$tmp_path,$demo_pic,$info_explain;
	$tmp_name=str_replace(" ","",$_POST['tmp_name']);
	$provide=str_replace(" ","",$_POST['provide']);
	$tmp_path=str_replace(" ","",$_POST['tmp_path']);
	$demo_pic=str_replace(" ","",$_POST['demo_pic']);
	$info_explain=$_POST['info_explain'];
	if($tmp_name=="" or $tmp_path=="" or $info_explain==""){
		show_msg($lang['sys.info'],$lang['space.info237'],0,'','',$lang['url'],$lang['cmdback']);
	exit;
	}
	else{
		$sql=$db->query("INSERT INTO {$dv}space_skins (s_skinname,s_path,s_viewpic,s_info,s_builder) values ('".$tmp_name."','".$tmp_path."','".$demo_pic."','".$info_explain."','".$provide."')");
		if($sql){
			show_msg($lang['sys.info'],$lang['space.info238'],1,'','',$lang['url'],$lang['cmdback']);
		exit;
		}
		else{
			show_msg($lang['sys.info'],$lang['space.info239'],0,'','',$lang['url'],$lang['cmdback']);
		exit;
		}
	}
}
function tmplate_del(){
	global $lang,$dv,$db,$id;
	$id=$_GET['id'];
	if($id=="" or !is_numeric($id)){
		show_msg($lang['sys.info'],$lang['space.info95'],0,'','',$lang['url'],$lang['cmdback']);
	exit;
	}
	else{
		$skins_num=$db->scalar("SELECT count(1) FROM {$dv}space_system WHERE skinid=".intval($id)."");
		if($skins_num>0){
			show_msg($lang['sys.info'],$lang['space.info247'],0,'','',$lang['url'],$lang['cmdback']);
		exit;
		}
		else{
			$sql=$db->query("DELETE FROM {$dv}space_skins WHERE s_id=".intval($id)."");
			if($sql){
				show_msg($lang['sys.info'],$lang['space.info162'],1,'','',$lang['url'],$lang['cmdback']);
			exit;
			}
			else{
				show_msg($lang['sys.info'],$lang['space.info163'],0,'','',$lang['url'],$lang['cmdback']);
			exit;
			}
		}
	}
}
function tmplate_edit(){
	global $lang,$dv,$db,$id,$tmp_name,$provide,$tmp_path,$demo_pic,$info_explain;
	$tmp_name=str_replace(" ","",$_POST['tmp_name']);
	$provide=str_replace(" ","",$_POST['provide']);
	$tmp_path=str_replace(" ","",$_POST['tmp_path']);
	$demo_pic=str_replace(" ","",$_POST['demo_pic']);
	$info_explain=$_POST['info_explain'];
	$id=$_GET['id'];
	if($id=="" or !is_numeric($id)){
		show_msg($lang['sys.info'],$lang['space.info95'],0,'','',$lang['url'],$lang['cmdback']);
	exit;
	}
	else{
		$sql=$db->query("UPDATE {$dv}space_skins SET s_skinname='".$tmp_name."',s_path='".$tmp_path."',s_viewpic='".$demo_pic."',s_info='".$info_explain."',s_builder='".$provide."' WHERE s_id=".$id."");
		if($sql){
			show_msg($lang['sys.info'],$lang['space.info242'],1,'','',$lang['url'],$lang['cmdback']);
		exit;
		}
		else{
			show_msg($lang['sys.info'],$lang['space.info243'],0,'','',$lang['url'],$lang['cmdback']);
		exit;
		}
	}
}
function tmplate_sysdef(){
	global $lang,$dv,$db,$id,$s_name;
	$s_name=$_GET['s_name'];
	$id=$_GET['id'];
	if($id=="" or !is_numeric($id)){
		show_msg($lang['sys.info'],$lang['space.info95'],0,'','',$lang['url'],$lang['cmdback']);
	exit;
	}
	else{
		$sql=$db->query("UPDATE {$dv}space_system SET skinid=".intval($id)."");
		include_once INC_PATH.'BoardCache.class.php';
		$mycache =& new BoardCache($db);
		$mycache->createspaceConfig();
		unset ($mycache);
		if($sql){
			show_msg($lang['sys.info'],$lang['space.info244'].$s_name.$lang['space.info245'],1,'','',$lang['url'],$lang['cmdback']);
		exit;
		}
		else{
			show_msg($lang['sys.info'],$lang['space.info246'],0,'','',$lang['url'],$lang['cmdback']);
		exit;
		}
	}
}
function weather_info(){
	global $lang,$dv,$db,$spacename,$spaceurl,$spacedomain,$nweather_a,$nweather_b;
	$spacename=$_POST['spacename'];
	$spaceurl=$_POST['spaceurl'];
	$spacedomain=$_POST['spacedomain'];
	$weather_a=$_POST['weather_a'];
	$weather_b=$_POST['weather_b'];
	$nweather_a=$_POST['nweather_a'];
	$nweather_b=$_POST['nweather_b'];
	$weathernum=$_POST['weathernum'];
	$str_space_setting=$_POST['str_space_setting'];
	$uploadsetting = "";
	$setting_info=$db->scalar("SELECT s_setting FROM {$dv}space_system order by s_id",array('pageSize'=>1));
	$setting_info=explode(",",$setting_info);
	if($weathernum<>-1){
		for($j=0;$j<=$weathernum;$j++){
			$tempstr_a=$weather_a[$j];
			$tempstr_b=$weather_b[$j];
			if($tempstr_a<>"" and $tempstr_b<>""){
				$iweather_a.=str_replace(",","",str_replace("|","",$tempstr_a));
				$iweather_b.=str_replace(",","",str_replace("|","",$tempstr_b));
			}
			if($j<intval($weathernum) and $tempstr_a<>"" and $tempstr_b<>""){
				$iweather_a.="|";
				$iweather_b.="|";
			}
		}
	}
	$iweather_a=substr($iweather_a,0,-1);
	$iweather_b=substr($iweather_b,0,-1);
	if($nweather_a<>"" and $nweather_b<>""){
		if($iweather_a<>""){
			$iweather_a.="|".$nweather_a;
			$iweather_b.="|".$nweather_b;
		}
		else{
			$iweather_a=$nweather_a;
			$iweather_b=$nweather_b;
		}
	}
	$setting_str="";
	for($i=0;$i<=100;$i++){
		if($i==13){
			$setting_str.=$iweather_a.",";
		}
		elseif($i==14){
			$setting_str.=$iweather_b.",";
		}
		else{
			$setting_str.=$setting_info[$i].",";
		}
	}
	$setting_str=substr($setting_str,0,-1);
	$sql=$db->query("UPDATE {$dv}space_system SET s_name='".$spacename."',s_url='".$spaceurl."',s_sdomain='".$spacedomain."',s_setting='".$setting_str."'");
	include_once INC_PATH.'BoardCache.class.php';
	$mycache =& new BoardCache($db);
	$mycache->createspaceConfig();
	unset ($mycache);
	if($sql){
		show_msg($lang['sys.info'],$lang['space.info79'],1,'','',$lang['url'],$lang['cmdback']);
	exit;
	}
	else{
		show_msg($lang['sys.info'],$lang['space.info80'],0,'','',$lang['url'],$lang['cmdback']);
	exit;
	}
}
function action_load($action){
	global $lang,$ad_type;
	$ad_type=intval($_GET['ad_type']);
	switch($action){
		case "save":
			space_info_setting();
		break;
		case "lanmu_editok":
			lanmu_edit();
		break;
		case "lan_del":
			lanmu_del();
		break;
		case "lanmu_addok":
			lanmu_add();
		break;
		case "lanmu":
			lanmu_list();
		break;
		case "lan_edit":
			lanum_editlist();
		break;
		case "user_search":
			user_manager();
		break;
		case "user_manage":
			user_manager();
		break;
		case "user_edit":
			user_editinfo();
		break;
		case "user_editok":
			user_infoedit();
		break;
		case "user_del":
			user_infodel();
		break;
		case "user_lanmu_search":
			user_item_list();
		break;
		case "user_lanmu":
			user_item_list();
		break;
		case "useritem_edit":
			item_editlist();
		break;
		case "item_editok":
			item_edit();
		break;
		case "useritem_del":
			item_del();
		break;
		case "ad_manage":
			ad_list();
		break;
		case "ad_edit":
			ad_manager($ad_type);
		break;
		case "key_word":
			keyword_list();
		break;
		case "keyword_search":
			keyword_list();
		break;
		case "kw_edit":
			keyword_editlist();
		break;
		case "kw_editok":
			keyword_editok();
		break;
		case "kw_del":
			keyword_del();
		break;
		case "file":
			file_list();
		break;
		case "f_del":
			file_del();
		break;
		case "add_tmpok":
			add_tmplate();
		break;
		case "tmplate":
			tmplate_list();
		break;
		case "tmp_del":
			tmplate_del();
		break;
		case "edit_tmpok":
			tmplate_edit();
		break;
		case "tmp_edit":
			tmplate_list();
		break;
		case "tmp_sysdef":
			tmplate_sysdef();
		break;
		case "weather_save":
			weather_info();
		break;
		case "today_recommend":
			today_recommend();
		break;
		case "today_star":
			today_star();
		break;
		case "do_today_star":
			do_today_star();
		break;
		default:
			top1_spaceinfo();
		break;
	}
}
?>