<?php
ob_start();
define('THIS_SCRIPT', 'audit_settings');
include_once 'global.php';
$lang = load_lang($lang, THIS_SCRIPT);
checklogin();
require_once INC_PATH.'dv_fsettings.global.php';
header("content-Type: text/html; charset=".$charset);

head();
if ( strpos($sysinfo['flag'],'48,') === false ){
	show_msg($lang['readme_tit'],$lang['error.str1'],0,'','','','');
	exit;
}
if ('deletesettings' === $action) {//删除所选设置
	$actionresult = array();
	if(!empty($settingsid) AND is_array($settingsid)) {
		$tablelist =& getTableList();
		foreach ($settingsid AS $index => $currsettingsid) {
			if (!is_numeric($currsettingsid) OR $currsettingsid <= 0) {
				continue;
			}
			$settingsname = ${"settingsname_{$currsettingsid}"};
			if ($allboard =& $db->getResultSet("SELECT boardid,boardtype FROM {$dv}board WHERE audit_settings_id='{$currsettingsid}'")) {
				foreach ($allboard AS $currboard) {
					$topiccount = $db->scalar("SELECT COUNT(1) FROM {$dv}topic /*!32312 USE INDEX(audit_list)*/ WHERE boardid=777 AND locktopic='{$allboard['boardid']}'");
					if ($topiccount > 0) {
						$actionresult[$index] = str_replace(array('{$TPL_settingsname}', '{$TPL_count}'), array($settingsname, $topiccount), $lang['tpl.error1']);
					} else {
						foreach ($tablelist AS $dbinfo) {
							$posttable = $db->escape_string($dbinfo['tablename']);
							$postcount = $db->scalar("SELECT COUNT(1) FROM {$posttable} /*!32312 USE INDEX(audit_list)*/ WHERE boardid=777 AND locktopic='{$allboard['boardid']}' and forumtype=0");
							if ($postcount > 0) {
								$actionresult[$index] = str_replace(array('{$TPL_settingsname}', '{$TPL_count}'), array($settingsname, $postcount), $lang['tpl.error2']);
							}
						}
					}
					if($actionresult[$index] == '')
						$actionresult[$index]= '<b>'.$currboard['boardtype'].'</b>&nbsp;&nbsp;'.$lang['tpl.error3'];
				}
			} else {
				if ($db->query("UPDATE {$dv}board SET audit_settings_id=0 WHERE audit_settings_id='{$currsettingsid}'")) {
					$db->query("DELETE FROM {$dv}fsettings WHERE id='{$currsettingsid}'");
					$actionresult[$index] = str_replace('{$TPL_settingsname}', $settingsname, $lang['tpl.str1']);
				}
			}
		}
		require_once INC_PATH.'BoardCache.class.php';
		$objcache = new BoardCache($db);
		$objcache->createAll();
		//防止客户端再次刷新时重复提交
	}
} elseif ('save' === $action) {
	if (!empty($submitsettings)) {
		processSubmitSettings($submitsettings);
		if (is_numeric($settingsid) AND $settingsid > 0) {//修改设置
			updateSettingsById($settingsid, $submitsettings);
		} else {//新建设置
			$result =& addNewAccessSettings($submitsettings);
			$settingsid = $result['settingsid'];
		}
		require_once INC_PATH.'BoardCache.class.php';
		$objcache = new BoardCache($db);
		$objcache->createAll();
		header("Location: ?action=modify&settingsid={$settingsid}");
		exit;
	}
}
readme($lang['page_title'],$lang['page_readme'],$lang['nav']);
require_once printout('audit_settings');
footer();

function &processSubmitSettings(&$submitsettings)
{
	//Start 审核设置部分处理
		$submitsettings['isenable'] = (1 == $submitsettings['isenable']? true : false);
		$submitsettings['scope']['newtopic'] = (1 == $submitsettings['scope']['newtopic']? true : false);
		$submitsettings['scope']['newreply'] = (1 == $submitsettings['scope']['newreply']? true : false);
		$submitsettings['scope']['reedit'] = (1 == $submitsettings['scope']['reedit']? true : false);
		if (!empty($submitsettings['grade']) AND is_array($submitsettings['grade'])) {
			foreach ($submitsettings['grade'] AS $position => $currgrade) {
				$submitsettings['grade'][$position]['isenable'] = (1 == $submitsettings['grade'][$position]['isenable'] ? true : false);
				$submitsettings['grade'][$position]['shield'] = (1 == $submitsettings['grade'][$position]['shield'] ? true : false);
				$submitsettings['grade'][$position]['check_content'] = (1 == $submitsettings['grade'][$position]['check_content'] ? true : false);
			}
		}
		$submitsettings['check_content_misc']['pic_audit'] = (1 == $submitsettings['check_content_misc']['pic_audit']? true : false);
		$submitsettings['check_content_misc']['link_audit'] = (1 == $submitsettings['check_content_misc']['link_audit']? true : false);
		$submitsettings['check_content_misc']['flash_audit'] = (1 == $submitsettings['check_content_misc']['flash_audit']? true : false);
		$submitsettings['check_content_misc']['media_audit'] = (1 == $submitsettings['check_content_misc']['media_audit']? true : false);
		$submitsettings['check_content_misc']['realplayer_audit'] = (1 == $submitsettings['check_content_misc']['realplayer_audit']? true : false);
		if (!empty($submitsettings['sensitive_character_list'])) {
			$submitsettings['sensitive_character_list'] = explode("\n", str_replace("\r", '', trim($submitsettings['sensitive_character_list'])));
		} else {
			$submitsettings['sensitive_character_list'] = array();
		}
		if (!empty($submitsettings['exempt_user_list'])) {
			$submitsettings['exempt_user_list'] = explode("\n", str_replace("\r", '', trim($submitsettings['exempt_user_list'])));
		} else {
			$submitsettings['exempt_user_list'] = array();
		}
	//End 审核设置部分处理
	return $submitsettings;
}

function &getTableList()
{
	global $dv, $db;
	static $tablelist = array();
	if (empty($tablelist)) {
		$tablelist = $db->getResultSet("SELECT id, tablename, tabletype FROM {$dv}tablelist");
	}
	return $tablelist;
}

?>