<?php
define('THIS_SCRIPT', 'forum_settings');
include_once 'global.php';
$lang = load_lang($lang,'forum_settings');
checklogin();
global $doaction;
header("content-Type: text/html; charset=".$charset);
head();
if ( strpos($sysinfo['flag'],'1,') === false ){
	show_msg($lang['readme_tit'],$lang['error.str1'],0,'','','','');
	exit;
}
if ($action == 'save'){
	if (isDate($_POST['forum_setting(74)']) === FALSE){
		show_msg($lang['forum.title'],$lang['err.info1'],0,'','',$lang['url'],$lang['comback']);
		exit;
	}
	if (isDate($_POST['forum_maxpost_date']) === FALSE){
		show_msg($lang['forum.title'],$lang['err.info1'],0,'','',$lang['url'],$lang['comback']);
		exit;
	}
	if (isDate($_POST['forum_maxonline_date']) === FALSE){
		show_msg($lang['forum.title'],$lang['err.info1'],0,'','',$lang['url'],$lang['comback']);
		exit;
	}
	if (!is_numeric($forum_maxonline) || !is_numeric($_POST['forum_topicnum']) || !is_numeric($_POST['forum_postnum']) || !is_numeric($_POST['forum_usernum']) || !is_numeric($forum_maxpost_num)){
		show_msg($lang['forum.title'],$lang['err.info1'],0,'','',$lang['url'],$lang['comback']);
		exit;
	}
	for ($i=0; $i<21; $i++){
		if ($i == 0){
			$uploadsetting = $_POST["uploadsetting($i)"];
		}else{
			$uploadsetting .= '|' .$_POST["uploadsetting($i)"];
		}
	}
	$ft_settings = $separator = '';
	for ($i = 0; $i < 3 ; $i++) {
		$ft_settings .= $separator.$_POST["ft_settings($i)"];
		$separator = '|';
	}//end for
	$bogushtml_settings = $separator = '';
	for ($i = 0; $i < 1 ; $i++) {
		$bogushtml_settings .= $separator.$_POST["bogushtml_settings($i)"];
		$separator = '|';
	}//end for

	if (defined('MAIN_DOMAIN_NAME')) {
		$_POST['forum_setting(87)'] = 1;			//	发送邮件方式设为系统默认
		$_POST['forum_info(4)'] = '';				//	SMTP 地址设为空
		$_POST['forum_info(12)'] = '';				//	电子邮件地址设为空
		$_POST['forum_setting(86)'] = '';			//	电子邮件登录用户名设为空
		$_POST['forum_setting(86)'] = '';			//	邮件登录密码设为空
		$_POST['forum_admin_folder'] = 'admin/';	//	后台管理目录设为默认的 admin/
		$_POST['forum_setting(76)'] = 'uploadfile/'.USER_DOMAIN_NAME.MAIN_DOMAIN_NAME.'/';	//	上传目录设定设为默认的 uploadfile/论坛域名
	}

	for ($i=0; $i<=125; $i++){
		if ($_POST["forum_setting($i)"] == '' || $i == 70 || $i == 7){
			$isetting = 0;
			if ($i == 7){$isetting = $uploadsetting;}
			if ($i == 70){
				$isetting = '';
				for ($j=0; $j<24; $j++){
					if ($isetting == ''){
						if (intval($_POST["forum_setting(70)$j"]) == 1){
							$isetting = '1';
						}else{
							$isetting = '0';
						}
					}else{
						if (intval($_POST["forum_setting(70)$j"]) == 1){
							$isetting .= '|1';
						}else{
							$isetting .= '|0';
						}
					}
				}
			} elseif (101 === $i) {	//	全文检索设置
				$isetting = str_replace(',', '', $ft_settings);
			} elseif (102 === $i) {	//	伪 HTML 设置
				$isetting =$forum_setting[102];
			}
		} else {
			$isetting = str_replace(',', '', $_POST["forum_setting($i)"]);
		}
		if ($i == 0){
			$sforum_setting = str_replace('|||', '', $isetting);
		}else{
			$sforum_setting .= ',' .str_replace('|||', '', $isetting);
		}
	}
	for ($i=0; $i<15; $i++){
		if ($_POST["forum_info($i)"] == '' && $i != 4 && $i != 12 && $i != 13){
			$isetting = 0;
		}else{
			$isetting = str_replace(',','',$_POST["forum_info($i)"]);
		}
		if ($i == 0){
			$sforum_info = str_replace('|||', '', $isetting);
		}else{
			$sforum_info .= ',' .str_replace('|||', '', $isetting);
		}
	}
	$forum_adminfolder=$_POST['forum_admin_folder'];
	//defined('MAIN_DOMAIN_NAME') AND ($forum_adminfolder = 'admin/');
	$sforum_info = $db->escape_string($sforum_info);
	$sforum_setting = $db->escape_string($sforum_setting);
	$query=$db->query("Select forum_setting,forum_adminfolder From {$dv}setup Limit 1");
	$fs = $db->fetch_array($query);
	$db->free_result($query);
	$iforum_setting = explode('|||', $fs['forum_setting']);
	$mforum_setting = trim($sforum_info. '|||' .str_replace('|||', '', $sforum_setting). '|||' .$db->escape_string(str_replace('|||', '', $iforum_setting[2])). '|||' .str_replace('|||', '', $_POST['copyright']). '|||' .$db->escape_string(str_replace('|||', '', $iforum_setting[4])). '|||' .str_replace('|||', '', $_POST['stopreadme']));
	if ($forum_adminfolder != ''){
	}else{
		$forum_adminfolder = $fs['forum_adminfolder'];
	}
	$forum_tpl = $forum_sid. '|' .$forum_cid. '|' .$forum_lang;
	//$mforum_setting = $db->escape_string($fs['forum_setting']);
	$forum_ads_id=$_POST['ads_id'];
	$forum_maxonline_date=strtotime($forum_maxonline_date)+date('Z')-getUserTimeZoneOffset();
	$forum_maxpost_date=strtotime($forum_maxpost_date)+date('Z')-getUserTimeZoneOffset();
	$db->query("update {$dv}setup set forum_adminfolder='{$forum_adminfolder}',forum_setting='{$mforum_setting}',forum_tpl='{$forum_tpl}',forum_maxonline='{$forum_max_online}',forum_topicnum='{$_POST['forum_topicnum']}',forum_postnum='{$_POST['forum_postnum']}',forum_usernum='{$_POST['forum_usernum']}',forum_maxpostnum='{$forum_maxpost_num}',forum_maxpostdate='{$forum_maxpost_date}',forum_maxonlinedate='{$forum_maxonline_date}',forum_adsid='{$forum_ads_id}' where id<>-1", array('debug'=>false));
	require_once INC_PATH.'BoardCache.class.php';
	$mycache =& new BoardCache($db);
	$mycache->createForumSetting();
	$mycache->createmailconfig();
	show_msg($lang['forum.title'],$lang['suc.info1'],1,'','',$lang['url'],$lang['comback']);
	exit;
}elseif($action == 'restore'){
}else{
	require_once printout('forum_settings');
}
footer();

function get_actionvalue(){
	global $doaction,$dv,$db,$lang;
	if($doaction=='basic'){
		$beviewtable=$lang['forum_settings.info2'];//显示
	}
	if($doaction=='appearance'){
		$beviewtable=$lang['forum_settings.info322'];//显示
	}
	elseif($doaction=='datasetup'){
		$beviewtable=$lang['forum_settings.info3'];//显示		
	}
	elseif($doaction=='stealthily'){
		$beviewtable=$lang['forum_settings.info4'];//显示		
	}
	elseif($doaction=='firstoption'){
		$beviewtable=$lang['forum_settings.info5'];//显示		
	}
	elseif($doaction=='reg'){
		$beviewtable=$lang['forum_settings.info6'];//显示		
	}
	elseif($doaction=='system'){
		$beviewtable=$lang['forum_settings.info7'];//显示		
	}
	elseif($doaction=='userfrom'){
		$beviewtable=$lang['forum_settings.info8'];//显示		
	}
	elseif($doaction=='postoption'){
		$beviewtable=$lang['forum_settings.info9'];//显示		
	}
	elseif($doaction=='upload'){
		$beviewtable=$lang['forum_settings.info10'];//显示		
	}
	elseif($doaction=='useroption'){
		$beviewtable=$lang['forum_settings.info11'];//显示		
	}
	elseif($doaction=='forumoption'){
		$beviewtable=$lang['forum_settings.info12'];//显示		
	}
	elseif($doaction=='refurbish'){
		$beviewtable=$lang['forum_settings.info13'];//显示		
	}
	elseif($doaction=='pagedesign'){
		$beviewtable=$lang['forum_settings.info14'];//显示		
	}
	elseif($doaction=='menpai'){
		$beviewtable=$lang['forum_settings.info15'];//显示		
	}
	elseif($doaction=='search'){
		$beviewtable=$lang['forum_settings.info16'];//显示		
	}
	elseif($doaction=='plus'){
		$beviewtable=$lang['forum_settings.info17'];//显示		
	}
	elseif($doaction=='safe'){
		$beviewtable=$lang['forum_settings.info18'];//显示		
	}
	elseif($doaction=='vipuser'){
		$beviewtable=$lang['forum_settings.info20'];//显示		
	}
	else{
		$beviewtable=$lang['forum_settings.info2'];//显示		
	}
	echo $beviewtable;
}
?>