<?php
/**
 * @version $Id: setting.inc.php v2.0 $
 * @package PBDigg
 * @copyright Copyright (C) 2007 - 2008 PBDigg.com. All Rights Reserved.
 * @license PBDigg is free software and use is subject to license terms
 */

if(!defined('IN_ADMIN') || !isset($_PBDEV['PHP_SELF']) || !preg_match('/[\/\\\\]admincp\.php$/i', $_PBDEV['PHP_SELF']))
{
	exit('Access Denied');
}
define('PB_CSCRIPT', 'setting');
allowdo('setsys');

if (isset($submitted))
{
	$configs = array();
	$Cache->setCacheFileName('config');
	if (!$Cache->cacheMod(0777))
	{
		showMsg($a_message['cache_failed'], $actionurl);
	}
	//basic setting
	if ($type == 'basic' || empty($type))
	{
		$configs['pb_sitename'] = trim($_POST['config']['pb_sitename']);
		$configs['pb_siteurl'] = strtolower(trim($_POST['config']['pb_siteurl']));
		if ($configs['pb_siteurl'])
		{
			if (!preg_match('/^http:\/\/[a-z0-9\-_\/\.]*?\/$/is', $configs['pb_siteurl']))
			{
				showMsg($a_message['siteurl_error'], $actionurl);
			}
		}
		$configs['pb_adminmail'] = trim($_POST['config']['pb_adminmail']);
		if ($configs['pb_adminmail'] && !isEMAIL($configs['pb_adminmail']))
		{
			showMsg($a_message['email_error'], $actionurl);
		}
		$configs['pb_icp'] = '<a href="http://www.miibeian.gov.cn" target="_blank">'.trim($_POST['config']['pb_icp']).'</a>';
		$configs['pb_statistic'] = trim($_POST['config']['pb_statistic']);
		$configs['pb_ifopen'] = intval($_POST['config']['pb_ifopen']);
		$configs['pb_whyclosed'] = stripWhite($_POST['config']['pb_whyclosed']);
	}
	//core setting
	elseif ($type == 'core')
	{
		$configs['pb_gzip'] = (int)$_POST['config']['pb_gzip'];
		$configs['pb_ucenable'] = (int)$_POST['config']['pb_ucenable'];
		$configs['pb_rewrite'] = (int)$_POST['config']['pb_rewrite'];
		$configs['pb_editor'] = (int)$_POST['config']['pb_editor'];
		$configs['pb_getpw'] = (int)$_POST['config']['pb_getpw'];
		$configs['pb_cachetime'] = (int)$_POST['config']['pb_cachetime'];
		$configs['pb_visitcache'] = (int)$_POST['config']['pb_visitcache'];
		$configs['pb_style'] = $_POST['config']['pb_style'];
		$configs['pb_timezone'] = (int)$_POST['config']['pb_timezone'];
		$configs['pb_timeformat'] = (int)$_POST['config']['pb_timeformat'];
		$configs['pb_dateformat'] = trim($_POST['config']['pb_dateformat']);
		$configs['pb_lang'] = in_array($_POST['config']['pb_lang'], array('en', 'zh-cn', 'zh-tw')) ? $_POST['config']['pb_lang'] : 'zh-cn';
		if ($configs['pb_dateformat'] && !isDateTime($configs['pb_dateformat']))
		{
			$configs['pb_dateformat'] = 'Y-m-d';
		}
		$configs['pb_refreshtime'] = (int)$_POST['config']['pb_refreshtime'];
		$configs['pb_maxsearchctrl'] = (int)$_POST['config']['pb_maxsearchctrl'];
		$configs['pb_maxresult'] = (int)$_POST['config']['pb_maxresult'];
		$configs['pb_online'] = (int)$_POST['config']['pb_online'];
		$configs['pb_exectime'] = (int)$_POST['config']['pb_exectime'];
		$configs['pb_ckpath'] = $_POST['config']['pb_ckpath'];
		if ($configs['pb_ckpath'] != '/' && !preg_match('/^\/[a-zA-Z0-9]*?\/$/is', $configs['pb_ckpath']))
		{
			$configs['pb_ckpath'] != '/';
		}
		$configs['pb_ckdomain'] = $_POST['config']['pb_ckdomain'];
		if ($configs['pb_ckdomain'] != '' && !isDOMAIN($configs['pb_ckpath']))
		{
			$configs['pb_ckpath'] != '';
		}
	}
	//view setting
	elseif ($type == 'view')
	{
		$configs['pb_indextitle'] = (int)$_POST['config']['pb_indextitle'];
		$configs['pb_indexcontent'] = (int)$_POST['config']['pb_indexcontent'];
		$configs['pb_aperpage'] = (int)$_POST['config']['pb_aperpage'];
		$configs['pb_tday'] = (int)$_POST['config']['pb_tday'];
		$configs['pb_torder'] = trim($_POST['config']['pb_torder']);
		if (!in_array($configs['pb_torder'], array('diggdate', 'postdate', 'commentdate')))
		{
			showMsg($a_message['parameter_error'], $actionurl);
		}
		$configs['pb_dformat'] = (int)$_POST['config']['pb_dformat'];
		$configs['pb_titlelink'] = (int)$_POST['config']['pb_titlelink'];
		if (isset($_POST['config']['pb_titleubb']))
		{
			$configs['pb_titleubb'] = implode("\t", $_POST['config']['pb_titleubb']);
		}
		else
		{
			$configs['pb_titleubb'] = '';
		}
		$configs['pb_topicimgsize'] = (int)$_POST['config']['pb_topicimgh']."\t".(int)$_POST['config']['pb_topicimgw'];
		if (isset($_POST['config']['pb_tubbtype']))
		{
			$configs['pb_tubbtype'] = implode("\t", $_POST['config']['pb_tubbtype']);
		}
		else
		{
			$configs['pb_tubbtype'] = '';
		}
		$configs['pb_previewsize'] = (int)$_POST['config']['pb_previewh']."\t".(int)$_POST['config']['pb_previeww'];
		$configs['pb_mautoplay'] = (int)$_POST['config']['pb_mautoplay'];
		$configs['pb_fautoplay'] = (int)$_POST['config']['pb_fautoplay'];
		$configs['pb_mplayersize'] = (int)$_POST['config']['pb_mplayerh']."\t".(int)$_POST['config']['pb_mplayerw'];
		$configs['pb_cperpage'] = (int)$_POST['config']['pb_cperpage'];
		if (isset($_POST['config']['pb_cubbtype']))
		{
			$configs['pb_cubbtype'] = implode("\t", $_POST['config']['pb_cubbtype']);
		}
		else
		{
			$configs['pb_cubbtype'] = '';
		}
		$configs['pb_showsign'] = (int)$_POST['config']['pb_showsign'];
		if (isset($_POST['config']['pb_signubbtype']))
		{
			$configs['pb_signubbtype'] = implode("\t", $_POST['config']['pb_signubbtype']);
		}
		else
		{
			$configs['pb_signubbtype'] = '';
		}
		$configs['pb_tperpage'] = (int)$_POST['config']['pb_tperpage'];
	}
	//atc setting
	elseif ($type == 'atc')
	{
		$configs['pb_ifpost'] = (int)$_POST['config']['pb_ifpost'];
		$configs['pb_ifcomment'] = (int)$_POST['config']['pb_ifcomment'];
		$configs['pb_tftopicimg'] = (int)$_POST['config']['pb_tftopicimg'];
		$configs['pb_urlsaveimg'] = (int)$_POST['config']['pb_urlsaveimg'];
		$configs['pb_tcheck'] = (int)$_POST['config']['pb_tcheck'];
		$configs['pb_reposttime'] = (int)$_POST['config']['pb_reposttime'];
		$configs['pb_anonnews'] = (int)$_POST['config']['pb_anonnews'];
		$configs['pb_ifdigg'] = (int)$_POST['config']['pb_ifdigg'];
		$configs['pb_ifbury'] = (int)$_POST['config']['pb_ifbury'];
		$_POST['config']['pb_contentlenmin'] = (int)$_POST['config']['pb_contentlenmin'];
		$_POST['config']['pb_contentlenmax'] = (int)$_POST['config']['pb_contentlenmax'];
		exchange($_POST['config']['pb_contentlenmin'], $_POST['config']['pb_contentlenmax']);
		$configs['pb_contentlen'] = $_POST['config']['pb_contentlenmin']."\t".$_POST['config']['pb_contentlenmax'];
		$_POST['config']['pb_titlelenmin'] = (int)$_POST['config']['pb_titlelenmin'];
		$_POST['config']['pb_titlelenmax'] = (int)$_POST['config']['pb_titlelenmax'];
		exchange($_POST['config']['pb_titlelenmin'], $_POST['config']['pb_titlelenmax']);
		$configs['pb_titlelen'] = $_POST['config']['pb_titlelenmin']."\t".$_POST['config']['pb_titlelenmax'];
		$_POST['config']['pb_commentlenmin'] = (int)$_POST['config']['pb_commentlenmin'];
		$_POST['config']['pb_commentlenmax'] = (int)$_POST['config']['pb_commentlenmax'];
		exchange($_POST['config']['pb_commentlenmin'], $_POST['config']['pb_commentlenmax']);
		$configs['pb_commentlen'] = $_POST['config']['pb_commentlenmin']."\t".$_POST['config']['pb_commentlenmax'];
		$configs['pb_banwords'] = trim($_POST['config']['pb_banwords']);
		$configs['pb_banlinks'] = trim($_POST['config']['pb_banlinks']);
	}
	//member setting
	elseif ($type == 'member')
	{
		$configs['pb_selfad'] = (int)$_POST['config']['pb_selfad'];
		$configs['pb_selfavat'] = (int)$_POST['config']['pb_selfavat'];
		$configs['pb_avatupload'] = (int)$_POST['config']['pb_avatupload'];
		$configs['pb_avatsize'] = (int)$_POST['config']['pb_avatsize'] * 1024;
		$configs['pb_avathight'] = (int)$_POST['config']['pb_avathight'];
		$configs['pb_avatwidth'] = (int)$_POST['config']['pb_avatwidth'];
		$configs['pb_msg'] = (int)$_POST['config']['pb_msg'];
		$configs['pb_fav'] = (int)$_POST['config']['pb_fav'];
		$configs['reg_status'] = (int)$_POST['config']['reg_status'];
		$configs['reg_closereason'] = trim($_POST['config']['reg_closereason']);
		$configs['reg_invite'] = (int)$_POST['config']['reg_invite'];
		$configs['reg_emailactive'] = (int)$_POST['config']['reg_emailactive'];
		$configs['reg_sendemail'] = (int)$_POST['config']['reg_sendemail'];
		$configs['reg_emailcontent'] = trim($_POST['config']['reg_emailcontent']);
		$configs['reg_agreement'] = trim($_POST['config']['reg_agreement']);
		$configs['reg_allowsameip'] = (int)$_POST['config']['reg_allowsameip'];
		$configs['reg_bannames'] = trim($_POST['config']['reg_bannames']);
		$configs['reg_minname'] = (int)$_POST['config']['reg_minname'];
		$configs['reg_maxname'] = (int)$_POST['config']['reg_maxname'];
		exchange($configs['reg_minname'], $configs['reg_maxname']);
		$configs['reg_credit'] = (int)$_POST['config']['reg_credit'];
		updateConfig($configs);
		$Cache->reg();
		$Cache->config();
		redirect($a_message['setsysSuccess'], $actionurl);
	}
	//credit setting
	elseif ($type == 'credit')
	{
		$configs['pb_customcredit'] = trim($_POST['config']['pb_customcredit']);
		if (!$configs['pb_customcredit'])
		{
			showMsg($a_message['customcredit_empty'], $actionurl);
		}
		$configs['pb_creditdb'] = implode("\t", array_map('intval', $_POST['config']['pb_creditdb']));
	}
	//attachment setting
	elseif ($type == 'attachment')
	{
		$configs['pb_allowupload'] = (int)$_POST['config']['pb_allowupload'];
		$configs['pb_uploadtopicimg'] = (int)$_POST['config']['pb_uploadtopicimg'];
		$configs['pb_attoutlink'] = (int)$_POST['config']['pb_attoutlink'];
		$configs['pb_attachdir'] = (int)$_POST['config']['pb_attachdir'];
		$sysUploadMax = ini_bytes('upload_max_filesize');
		$configs['pb_uploadmaxsize'] = (int)$_POST['config']['pb_uploadmaxsize'] * 1024;
		$configs['pb_attachnum'] = (int)$_POST['config']['pb_attachnum'];
		if ($configs['pb_uploadmaxsize'] * $configs['pb_attachnum'] > $sysUploadMax)
		{
			showMsg($a_message['uploadThanMax'], $actionurl);
		}
		$configs['pb_uploadfiletype'] = strtolower(trim($_POST['config']['pb_uploadfiletype']));
		if ($configs['pb_uploadfiletype'])
		{
			if (strpos($configs['pb_uploadfiletype'], '£¬') !== FALSE)
			{
				$configs['pb_uploadfiletype'] = str_replace('£¬', ',', $configs['pb_uploadfiletype']);
			}
			if (!preg_match('/[a-z0-9,\.]*/i', $configs['pb_uploadfiletype']))
			{
				showMsg($a_message['forbiddenExt'], $actionurl);
			}
			$ext = array('exe', 'jsp', 'asp', 'asa', 'htr', 'stm', 'shtml', 'php3', 'aspx', 'cgi', 'fcgi', 'pl', 'php', 'bat');
			foreach ($ext as $value)
			{
				if (strpos($configs['pb_uploadfiletype'], $value) !== FALSE)
				{
					showMsg($a_message['forbiddenExt'], $actionurl);
				}
			}
		}
		$configs['pb_allowthumb'] = (int)$_POST['config']['pb_allowthumb'];
		$configs['pb_thumbsize'] = (int)$_POST['config']['pb_thumbh']."\t".(int)$_POST['config']['pb_thumbw'];
		$configs['pb_watertype'] = (int)$_POST['config']['pb_watertype'];
		$configs['pb_watertext'] = trim($_POST['config']['pb_watertext']);
		$configs['pb_waterfont'] = trim($_POST['config']['pb_waterfont']);
		if ($configs['pb_waterfont'] && !file_exists(PBDIGG_ROOT.'include/font/'.$configs['pb_waterfont']))
		{
			showMsg($a_message['waterFontNotExists'], $actionurl);
		}
		$configs['pb_waterfontsize'] = (int)$_POST['config']['pb_waterfontsize'];
		$configs['pb_waterfontcolor'] = strtolower(trim($_POST['config']['pb_waterfontcolor']));
		$configs['pb_waterfontcolor'] = preg_replace('/^rgb\((\d+),\s*(\d+),\s*(\d+)\)/iem', '"#".dechex(\\1).dechex(\\2).dechex(\\3)', $configs['pb_waterfontcolor']);
		if (!$configs['pb_waterfontcolor'] || !isColorCode($configs['pb_waterfontcolor']))
		{
			showMsg($a_message['waterfontcolor_error'], $actionurl);
		}
		$configs['pb_waterimg'] = strtolower(trim($_POST['config']['pb_waterimg']));
		if (!$configs['pb_waterimg'])
		{
			$configs['pb_waterimg'] = 'mark.png';
		}
		elseif (substr($configs['pb_waterimg'], strrpos($configs['pb_waterimg'], '.')) == 'gif')
		{
			showMsg($a_message['waterImgExt_error'], $actionurl);
		}
		if (!file_exists(PBDIGG_ROOT.'images/water/'.$configs['pb_waterimg']))
		{
			showMsg($a_message['waterImgNotExists'], $actionurl);
		}
		$configs['pb_watertransition'] = (int)$_POST['config']['pb_watertransition'];
		if ($configs['pb_watertransition'] > 100 || $configs['pb_watertransition'] < 0)
		{
			showMsg($a_message['watertransition_error'], $actionurl);
		}
		$configs['pb_waterquality'] = (int)$_POST['config']['pb_waterquality'];
		if ($configs['pb_waterquality'] > 100 || $configs['pb_waterquality'] < 0)
		{
			showMsg($a_message['waterquality_error'], $actionurl);
		}
		$configs['pb_waterminsize'] = (int)$_POST['config']['pb_waterminh']."\t".(int)$_POST['config']['pb_waterminw'];
		$configs['pb_waterposition'] = (int)$_POST['config']['pb_waterposition'];
	}
	//safe setting
	elseif ($type == 'safe')
	{
		$configs['pb_sitehash'] = trim($_POST['config']['pb_sitehash']);
		if (!$configs['pb_sitehash'] || !isHash($configs['pb_sitehash']))
		{
			showMsg($a_message['sitehash_error'], $actionurl);
		}
		$gdcheck = array('reg', 'login', 'reg', 'post', 'comment', 'admin');
		$_POST['config']['pb_gdcheck'] = (array)$_POST['config']['pb_gdcheck'];
		foreach ($gdcheck as $value)
		{
			if (in_array($value, $_POST['config']['pb_gdcheck']))
			{
				$configs['pb_gdcheck'][$value] = '1';
			}
			else
			{
				$configs['pb_gdcheck'][$value] = '0';
			}
		}
		$configs['pb_gdcheck'] = serialize($configs['pb_gdcheck']);
		unset($gdcheck);
		$configs['pb_ipallow'] = serialize(preg_replace('/(?:\r\n|\n\r|\r|\n)/i', "\n", trim($_POST['config']['pb_ipallow'])));
		$configs['pb_ipdeny'] = serialize(preg_replace('/(?:\r\n|\n\r|\r|\n)/i', "\n", trim($_POST['config']['pb_ipdeny'])));
		$configs['pb_adminipallow'] = serialize(preg_replace('/(?:\r\n|\n\r|\r|\n)/i', "\n", trim($_POST['config']['pb_adminipallow'])));
		$configs['pb_adminsafecode'] = (int)$_POST['config']['pb_adminsafecode'];
		$configs['pb_loadavg'] = (int)$_POST['config']['pb_loadavg'];
	}
	//seo setting
	elseif ($type == 'seo')
	{
		$configs['pb_rewriteext'] = (int)$_POST['config']['pb_rewriteext'];
		if ($configs['pb_rewriteext'] < 0 || $configs['pb_rewriteext'] > 6)
		{
			showMsg($a_message['rewriteext_error'], $actionurl);
		}
		$configs['pb_seotitle'] = trim($_POST['config']['pb_seotitle']);
		$configs['pb_seokeywords'] = trim($_POST['config']['pb_seokeywords']);
		$configs['pb_seodescription'] = trim($_POST['config']['pb_seodescription']);
		$configs['pb_seomore'] = trim($_POST['config']['pb_seomore']);
	}
	//email setting
	elseif ($type == 'email')
	{
		$configs['pb_mailtype'] = (int)$_POST['config']['pb_mailtype'];
		$configs['pb_smtphost'] = trim($_POST['config']['pb_smtphost']);
		if ($configs['pb_mailtype'] && !$configs['pb_smtphost'])
		{
			showMsg($a_message['smtphost_empty'], $actionurl);
		}
		$configs['pb_smtpauth'] = (int)$_POST['config']['pb_smtpauth'];
		$configs['pb_smtpuser'] = trim($_POST['config']['pb_smtpuser']);
		$configs['pb_smtppw'] = trim($_POST['config']['pb_smtppw']);
		$configs['pb_smtpport'] = (int)$_POST['config']['pb_smtpport'];
		if ($configs['pb_mailtype'] && (!$configs['pb_smtpuser'] || !$configs['pb_smtpport']))
		{
			showMsg($a_message['smtp_error'], $actionurl);
		}
	}
	//transfer setting
	elseif ($type == 'transfer')
	{
		$configs['pb_jstransfer'] = (int)$_POST['config']['pb_jstransfer'];
		$configs['pb_jstime'] = (int)$_POST['config']['pb_jstime'];
		$configs['pb_jsurl'] = trim($_POST['config']['pb_jsurl']);
		if ($configs['pb_jsurl'])
		{
			$domain = explode('|', $configs['pb_jsurl']);
			foreach ($domain as $value)
			{
				if (!isDOMAIN($value))
				{
					showMsg($a_message['domain_error'], $actionurl);
				}
			}
		}
		$configs['pb_trantags'] = (int)$_POST['config']['pb_trantags'];
		$configs['pb_tagcolor'] = (int)$_POST['config']['pb_tagcolor'];
		$configs['pb_opentran'] = (int)$_POST['config']['pb_opentran'][0]."\t".(int)$_POST['config']['pb_opentran'][1]."\t".(int)$_POST['config']['pb_opentran'][2]."\t".(int)$_POST['config']['pb_opentran'][3];
	}
	updateConfig($configs);
	$Cache->config();
	redirect($a_message['setsysSuccess'], $actionurl);
}
else
{
	//basic setting
	if ($type == 'basic' || empty($type))
	{
		$TPL->assign('pb_sitename', $pb_sitename);
		$TPL->assign('pb_siteurl', $pb_siteurl);
		$TPL->assign('pb_adminmail', $pb_adminmail);
		$pb_icp = str_replace(array('<a href="http://www.miibeian.gov.cn" target="_blank">','</a>'), '', $pb_icp);
		$TPL->assign('pb_icp', $pb_icp);
		$TPL->assign('pb_statistic', $pb_statistic);
		radioChecked('ifopen_', $pb_ifopen);
		$TPL->assign('ifopen_0', $ifopen_0);
		$TPL->assign('ifopen_1', $ifopen_1);
		$TPL->assign('pb_whyclosed', str_replace('<br />', "\n", $pb_whyclosed));
		$type = 'basic';
	}
	//core setting
	elseif ($type == 'core')
	{
		radioChecked('gzip_', $pb_gzip);
		$TPL->assign('gzip_0', $gzip_0);
		$TPL->assign('gzip_1', $gzip_1);
		radioChecked('ucenable_', $pb_ucenable);
		$TPL->assign('ucenable_0', $ucenable_0);
		$TPL->assign('ucenable_1', $ucenable_1);
		radioChecked('rewrite_', $pb_rewrite);
		$TPL->assign('rewrite_0', $rewrite_0);
		$TPL->assign('rewrite_1', $rewrite_1);
		radioChecked('editor_', $pb_editor, 3);
		$TPL->assign('editor_0', $editor_0);
		$TPL->assign('editor_1', $editor_1);
		$TPL->assign('editor_2', $editor_2);
		$TPL->assign('pb_cachetime', $pb_cachetime);
		radioChecked('visitcache_', $pb_visitcache);
		$TPL->assign('visitcache_0', $visitcache_0);
		$TPL->assign('visitcache_1', $visitcache_1);
		radioChecked('getpw_', $pb_getpw);
		$TPL->assign('getpw_0', $getpw_0);
		$TPL->assign('getpw_1', $getpw_1);
		$TPL->assign('pb_lang', siteLang($pb_lang));
		$TPL->assign('pb_style', siteStyle($pb_style));
		radioChecked('timeformat_', $pb_timeformat);
		$TPL->assign('timeformat_0', $timeformat_0);
		$TPL->assign('timeformat_1', $timeformat_1);
		$TPL->assign('pb_dateformat', $pb_dateformat);
		$TPL->assign('pb_refreshtime', $pb_refreshtime);
		$TPL->assign('pb_maxsearchctrl', $pb_maxsearchctrl);
		$TPL->assign('pb_maxresult', $pb_maxresult);
		$TPL->assign('pb_online', $pb_online);
		radioChecked('exectime_', $pb_exectime);
		$TPL->assign('exectime_0', $exectime_0);
		$TPL->assign('exectime_1', $exectime_1);
		$TPL->assign('pb_ckpath', $pb_ckpath);
		$TPL->assign('pb_ckdomain', $pb_ckdomain);
		include_once (PBDIGG_ROOT.'include/timezone.inc.php');
		$TPL->assign('pb_timezone', html_select($timezone, 'config[pb_timezone]', $pb_timezone, 'id="timezone"'));
		unset($gzip_0, $gzip_1, $rewrite_0, $rewrite_1, $rewrite_2, $editor_0, $editor_1, $editor_2, $visitcache_0, $visitcache_1, $getpw_0, $getpw_1, $timeformat_0, $timeformat_1, $exectime_0, $exectime_1);
	}
	//view setting
	elseif ($type == 'view')
	{
		$TPL->assign('pb_indextitle', $pb_indextitle);
		$TPL->assign('pb_indexcontent', $pb_indexcontent);
		$TPL->assign('pb_aperpage', $pb_aperpage);
		$TPL->assign('pb_torder', html_select($OPTIONS['torder'], 'config[pb_torder]', $pb_torder, 'id="torder"'));
		$TPL->assign('pb_tday', html_select($OPTIONS['tday'], 'config[pb_tday]', $pb_tday, 'id="tday"'));
		radioChecked('dformat_', $pb_dformat);
		$TPL->assign('dformat_0', $dformat_0);
		$TPL->assign('dformat_1', $dformat_1);
		radioChecked('titlelink_', $pb_titlelink);
		$TPL->assign('titlelink_0', $titlelink_0);
		$TPL->assign('titlelink_1', $titlelink_1);
		$TPL->assign('pb_titleubb', html_checkbox($OPTIONS['titleubb'],'config[pb_titleubb][]', explode("\t", $pb_titleubb), 4));
		$TPL->assign('pb_tubbtype', html_checkbox($OPTIONS['tubbtype'],'config[pb_tubbtype][]', explode("\t", $pb_tubbtype), 4));
		$TPL->assign('pb_cubbtype', html_checkbox($OPTIONS['cubbtype'],'config[pb_cubbtype][]', explode("\t", $pb_cubbtype), 4));
		radioChecked('mautoplay_', $pb_mautoplay);
		$TPL->assign('mautoplay_0', $mautoplay_0);
		$TPL->assign('mautoplay_1', $mautoplay_1);
		radioChecked('fautoplay_', $pb_fautoplay);
		$TPL->assign('fautoplay_0', $fautoplay_0);
		$TPL->assign('fautoplay_1', $fautoplay_1);
		$TPL->assign('pb_cperpage', $pb_cperpage);
		radioChecked('showsign_', $pb_showsign);
		$TPL->assign('showsign_0', $showsign_0);
		$TPL->assign('showsign_1', $showsign_1);
		$TPL->assign('pb_signubbtype', html_checkbox($OPTIONS['signubbtype'],'config[pb_signubbtype][]', explode("\t", $pb_signubbtype), 4));
		list($pb_topicimgh, $pb_topicimgw) = explode("\t", $pb_topicimgsize);
		$TPL->assign('pb_topicimgh', $pb_topicimgh);
		$TPL->assign('pb_topicimgw', $pb_topicimgw);
		list($pb_previewh, $pb_previeww) = explode("\t", $pb_previewsize);
		$TPL->assign('pb_previewh', $pb_previewh);
		$TPL->assign('pb_previeww', $pb_previeww);
		list($pb_mplayerh, $pb_mplayerw) = explode("\t", $pb_mplayersize);
		$TPL->assign('pb_mplayerh', $pb_mplayerh);
		$TPL->assign('pb_mplayerw', $pb_mplayerw);
		$TPL->assign('pb_tperpage', $pb_tperpage);
	}
	//atc setting
	elseif ($type == 'atc')
	{
		radioChecked('tcheck_', $pb_tcheck);
		$TPL->assign('tcheck_0', $tcheck_0);
		$TPL->assign('tcheck_1', $tcheck_1);
		radioChecked('tftopicimg_', $pb_tftopicimg);
		$TPL->assign('tftopicimg_0', $tftopicimg_0);
		$TPL->assign('tftopicimg_1', $tftopicimg_1);
		radioChecked('urlsaveimg_', $pb_urlsaveimg);
		$TPL->assign('urlsaveimg_0', $urlsaveimg_0);
		$TPL->assign('urlsaveimg_1', $urlsaveimg_1);
		radioChecked('anonnews_', $pb_anonnews);
		$TPL->assign('anonnews_0', $anonnews_0);
		$TPL->assign('anonnews_1', $anonnews_1);
		radioChecked('ifdigg_', $pb_ifdigg);
		$TPL->assign('ifdigg_0', $ifdigg_0);
		$TPL->assign('ifdigg_1', $ifdigg_1);
		radioChecked('ifbury_', $pb_ifbury);
		$TPL->assign('ifbury_0', $ifbury_0);
		$TPL->assign('ifbury_1', $ifbury_1);
		radioChecked('ifpost_', $pb_ifpost);
		$TPL->assign('ifpost_0', $ifpost_0);
		$TPL->assign('ifpost_1', $ifpost_1);
		radioChecked('ifcomment_', $pb_ifcomment);
		$TPL->assign('ifcomment_0', $ifcomment_0);
		$TPL->assign('ifcomment_1', $ifcomment_1);
		$TPL->assign('pb_reposttime', $pb_reposttime);
		list($pb_contentlenmin, $pb_contentlenmax) = explode("\t", $pb_contentlen);
		$TPL->assign('pb_contentlenmin', $pb_contentlenmin);
		$TPL->assign('pb_contentlenmax', $pb_contentlenmax);
		list($pb_titlelenmin, $pb_titlelenmax) = explode("\t", $pb_titlelen);
		$TPL->assign('pb_titlelenmin', $pb_titlelenmin);
		$TPL->assign('pb_titlelenmax', $pb_titlelenmax);
		list($pb_commentlenmin, $pb_commentlenmax) = explode("\t", $pb_commentlen);
		$TPL->assign('pb_commentlenmin', $pb_commentlenmin);
		$TPL->assign('pb_commentlenmax', $pb_commentlenmax);
		$TPL->assign('pb_banwords', $pb_banwords);
		$TPL->assign('pb_banlinks', $pb_banlinks);
	}
	//member setting
	elseif ($type == 'member')
	{
		@include_once(PBDIGG_ROOT.'data/cache/cache_reg.php');
		radioChecked('selfad_', $pb_selfad);
		$TPL->assign('selfad_0', $selfad_0);
		$TPL->assign('selfad_1', $selfad_1);
		radioChecked('selfavat_', $pb_selfavat);
		$TPL->assign('selfavat_0', $selfavat_0);
		$TPL->assign('selfavat_1', $selfavat_1);
		radioChecked('avatupload_', $pb_avatupload);
		$TPL->assign('avatupload_0', $avatupload_0);
		$TPL->assign('avatupload_1', $avatupload_1);
		$TPL->assign('pb_avatsize', floor($pb_avatsize / 1024));
		$TPL->assign('pb_avathight', $pb_avathight);
		$TPL->assign('pb_avatwidth', $pb_avatwidth);
		$TPL->assign('pb_msg', $pb_msg);
		$TPL->assign('pb_fav', $pb_fav);
		radioChecked('status_', $reg_status);
		$TPL->assign('status_0', $status_0);
		$TPL->assign('status_1', $status_1);
		$TPL->assign('reg_closereason', $reg_closereason);
		radioChecked('invite_', $reg_invite);
		$TPL->assign('invite_0', $invite_0);
		$TPL->assign('invite_1', $invite_1);
		radioChecked('emailactive_', $reg_emailactive);
		$TPL->assign('emailactive_0', $emailactive_0);
		$TPL->assign('emailactive_1', $emailactive_1);
		radioChecked('sendemail_', $reg_sendemail);
		$TPL->assign('sendemail_0', $sendemail_0);
		$TPL->assign('sendemail_1', $sendemail_1);
		$TPL->assign('reg_emailcontent', $reg_emailcontent);
		$TPL->assign('reg_agreement', $reg_agreement);
		$TPL->assign('reg_allowsameip', $reg_allowsameip);
		$TPL->assign('reg_bannames', $reg_bannames);
		$TPL->assign('reg_minname', $reg_minname);
		$TPL->assign('reg_maxname', $reg_maxname);
		$TPL->assign('reg_credit', $reg_credit);
	}
	//credit setting
	elseif ($type == 'credit')
	{
		$TPL->assign('pb_creditdb', explode("\t", $pb_creditdb));
		$TPL->assign('pb_customcredit', $pb_customcredit);
	}
	//attachment setting
	elseif ($type == 'attachment')
	{
		radioChecked('allowupload_', $pb_allowupload);
		$TPL->assign('allowupload_0', $allowupload_0);
		$TPL->assign('allowupload_1', $allowupload_1);
		radioChecked('uploadtopicimg_', $pb_uploadtopicimg);
		$TPL->assign('uploadtopicimg_0', $uploadtopicimg_0);
		$TPL->assign('uploadtopicimg_1', $uploadtopicimg_1);
		radioChecked('attoutlink_', $pb_attoutlink);
		$TPL->assign('attoutlink_0', $attoutlink_0);
		$TPL->assign('attoutlink_1', $attoutlink_1);
		$TPL->assign('pb_attachdir', html_select($OPTIONS['attachdir'], 'config[pb_attachdir]', $pb_attachdir, 'id="attachdir"'));
		$TPL->assign('pb_uploadmaxsize', floor($pb_uploadmaxsize / 1024));
		$TPL->assign('pb_attachnum', $pb_attachnum);
		$TPL->assign('pb_uploadfiletype', $pb_uploadfiletype);
		radioChecked('allowthumb_', $pb_allowthumb);
		$TPL->assign('allowthumb_0', $allowthumb_0);
		$TPL->assign('allowthumb_1', $allowthumb_1);
		list($pb_thumbh, $pb_thumbw) = explode("\t", $pb_thumbsize);
		$TPL->assign('pb_thumbh', $pb_thumbh);
		$TPL->assign('pb_thumbw', $pb_thumbw);
		$TPL->assign('pb_watertype', html_select($OPTIONS['watertype'], 'config[pb_watertype]', $pb_watertype, 'id="watertype"'));
		$TPL->assign('pb_watertext', $pb_watertext);
		$TPL->assign('pb_waterfont', $pb_waterfont);
		$TPL->assign('pb_waterfontsize', $pb_waterfontsize);
		$TPL->assign('pb_waterfontcolor', $pb_waterfontcolor);
		$TPL->assign('pb_waterimg', $pb_waterimg);
		$TPL->assign('pb_watertransition', $pb_watertransition);
		$TPL->assign('pb_waterquality', $pb_waterquality);
		list($pb_waterminh, $pb_waterminw) = explode("\t", $pb_waterminsize);
		$TPL->assign('pb_waterminh', $pb_waterminh);
		$TPL->assign('pb_waterminw', $pb_waterminw);
		radioChecked('waterposition_', $pb_waterposition, 9);
		$TPL->assign('waterposition_0', $waterposition_0);
		$TPL->assign('waterposition_1', $waterposition_1);
		$TPL->assign('waterposition_2', $waterposition_2);
		$TPL->assign('waterposition_3', $waterposition_3);
		$TPL->assign('waterposition_4', $waterposition_4);
		$TPL->assign('waterposition_5', $waterposition_5);
		$TPL->assign('waterposition_6', $waterposition_6);
		$TPL->assign('waterposition_7', $waterposition_7);
		$TPL->assign('waterposition_8', $waterposition_8);	
	}
	//safe setting
	elseif ($type == 'safe')
	{
		$TPL->assign('pb_sitehash', $pb_sitehash);
		$gdcheck_t = array();
		foreach ($pb_gdcheck as $key => $value)
		{
			if ($value)
			{
				$gdcheck_t[] = $key; 
			}
		}
		$TPL->assign('pb_gdcheck', html_checkbox($OPTIONS['gdcheck'],'config[pb_gdcheck][]', $gdcheck_t));	
		$TPL->assign('pb_ipallow', unserialize($pb_ipallow));
		$TPL->assign('pb_ipdeny', unserialize($pb_ipdeny));
		$TPL->assign('pb_adminipallow', unserialize($pb_adminipallow));
		radioChecked('adminsafecode_', $pb_adminsafecode);
		$TPL->assign('adminsafecode_0', $adminsafecode_0);
		$TPL->assign('adminsafecode_1', $adminsafecode_1);
		$TPL->assign('pb_loadavg', $pb_loadavg);
	}
	//seo setting
	elseif ($type == 'seo')
	{
		$ext = array('html', 'htm', 'shtml', 'php', 'asp', 'jsp', 'cgi');
		$TPL->assign('pb_rewriteext', html_select($ext, 'config[pb_rewriteext]', $pb_rewriteext, 'id="rewriteext"'));
		$TPL->assign('pb_seotitle', $pb_seotitle);
		$TPL->assign('pb_seokeywords', $pb_seokeywords);
		$TPL->assign('pb_seodescription', $pb_seodescription);
		$TPL->assign('pb_seomore', $pb_seomore);
	
	}
	//email setting
	elseif ($type == 'email')
	{
		radioChecked('mailtype_', $pb_mailtype);
		$TPL->assign('mailtype_0', $mailtype_0);
		$TPL->assign('mailtype_1', $mailtype_1);
		$TPL->assign('pb_smtphost', $pb_smtphost);
		$TPL->assign('pb_smtpuser', $pb_smtpuser);
		$TPL->assign('pb_smtppw', $pb_smtppw);
		radioChecked('smtpauth_', $pb_smtpauth);
		$TPL->assign('smtpauth_0', $smtpauth_0);
		$TPL->assign('smtpauth_1', $smtpauth_1);
		$TPL->assign('pb_smtpport', $pb_smtpport);
	}
	//transfer setting
	elseif ($type == 'transfer')
	{
		radioChecked('jstransfer_', $pb_jstransfer);
		$TPL->assign('jstransfer_0', $jstransfer_0);
		$TPL->assign('jstransfer_1', $jstransfer_1);
		$TPL->assign('pb_jstime', $pb_jstime);
		$TPL->assign('pb_jsurl', $pb_jsurl);
		$pb_opentran = explode("\t", $pb_opentran);
		radioChecked('opentrantags_', $pb_opentran[0]);
		$TPL->assign('opentrantags_0', $opentrantags_0);
		$TPL->assign('opentrantags_1', $opentrantags_1);
		radioChecked('opentranarticle_', $pb_opentran[1]);
		$TPL->assign('opentranarticle_0', $opentranarticle_0);
		$TPL->assign('opentranarticle_1', $opentranarticle_1);
		radioChecked('opentrancomment_', $pb_opentran[2]);
		$TPL->assign('opentrancomment_0', $opentrancomment_0);
		$TPL->assign('opentrancomment_1', $opentrancomment_1);
		radioChecked('opentranmember_', $pb_opentran[3]);
		$TPL->assign('opentranmember_0', $opentranmember_0);
		$TPL->assign('opentranmember_1', $opentranmember_1);
		radioChecked('tagcolor_', $pb_tagcolor);
		$TPL->assign('tagcolor_0', $tagcolor_0);
		$TPL->assign('tagcolor_1', $tagcolor_1);
		$TPL->assign('pb_trantags', $pb_trantags);
	}
}
function updateConfig($params)
{
	global $DB, $db_prefix;
	if (is_array($params))
	{
		foreach ($params as $key => $value)
		{
			$DB->db_query("UPDATE {$db_prefix}configs SET text = '$value' WHERE title = '$key'");
		}
	}
}
$TPL->assign('menu', $m_setting);
?>
