<?php
!defined('P_W') && exit('Forbidden');
include_once(D_P.'data/bbscache/level.php');

$basename .= '&admintype='.$admintype;
$settingdb = array();
foreach ($rightset['settings'] as $key => $value) {
	if ($key!='all') {
		if (If_manager && $admintype=='all') {
			$settingdb[$key] = true;
		} else {
			$settingdb[$key] = false;
		}
	}
}
if ($_POST['step']!=2) {
	$action = '';
	if ($admintype=='basic' || $settingdb['basic']) {
		if (!$settingdb['basic']) {
			$action = $_COOKIE['admin_basic'];
			!$action && $action = 'state';
		}
		//state
		${'bbsifopen_'.(int)$db_bbsifopen} = 'CHECKED';
		list($db_opensch,$db_schstart,$db_schend) = explode("\t",$db_opensch);
		list($db_openpost,$db_poststart,$db_postend) = explode("\t",$db_openpost);
		$db_whybbsclose = str_replace(array('<br />','<br>'),"\n",$db_whybbsclose);
		$db_visituser = trim($db_visituser,',');
		$db_schend = (int)$db_schend;
		$db_postend = (int)$db_postend;
		$db_schstart = (int)$db_schstart;
		$db_poststart = (int)$db_poststart;
		$db_bbsname = htmlspecialchars($db_bbsname);
		ifcheck($db_opensch,'opensch');
		ifcheck($db_openpost,'openpost');
		ifcheck($db_visitopen,'visitopen');
		$visitgroup = ''; $num = 0;
		foreach ($ltitle as $key => $value) {
			if ($key!=1 && $key!=2) {
				$num++;
				$htm_tr = $num % 3 == 0 ? '</tr><tr>' : '';
				$s_checked = strpos($db_visitgroup,','.$key.',')!==false ? 'CHECKED' : '';
				$visitgroup .= '<td><input type="checkbox" name="visitgroup[]" value="'.$key.'" '.$s_checked.'>'.$value.'</td>'.$htm_tr;
			}
		}
		$visitgroup && $visitgroup = '<table cellspacing="0" cellpadding="0" border="0" width="100%" align="center"><tr>'.$visitgroup.'</tr></table>';
		//global
		$sltstyles = '';
		if ($fp = opendir(D_P.'data/style/')) {
			while (($skinfile = readdir($fp))!==false) {
				if (preg_match('/([^\.]+?)\.php$/i',$skinfile,$rt) && (empty($db_styledb[$rt[1]]) || $db_styledb[$rt[1]][1])) {
					$skinname = $db_styledb[$rt[1]][0] ? $db_styledb[$rt[1]][0] : $rt[1];
					if ($rt[1]==$db_defaultstyle) {
						$sltstyles .= '<option value="'.$rt[1].'" SELECTED>'.$skinname.'</option>';
					} else {
						$sltstyles .= '<option value="'.$rt[1].'">'.$skinname.'</option>';
					}
				}
			}
			closedir($fp);
		}
		${'charset_'.str_replace('-','',$db_charset)} = ${'columns_'.(int)$db_columns} = 'SELECTED';
		$temptimedf = str_replace('.','_',abs($db_timedf));
		$db_timedf < 0 ? ${'zone_0'.$temptimedf} = 'SELECTED' : ${'zone_'.$temptimedf} = 'SELECTED';
		${'forumdir_'.(int)$db_forumdir} = $check_24 = 'CHECKED';
		if ($db_datefm) {
			if (strpos($db_datefm,'h:i A')!==false) {
				$db_datefm = str_replace(' h:i A','',$db_datefm);
				$check_12 = 'CHECKED';
				$check_24 = '';
			} else {
				$db_datefm = str_replace(' H:i','',$db_datefm);
			}
			$db_datefm = str_replace(array('m','n','d','j','y','Y'),array('mm','m','dd','d','yy','yyyy'),$db_datefm);
		} else {
			$db_datefm = 'yyyy-mm-dd';
		}
		$db_onlinetime /= 60;
		!$db_ckpath && $db_ckpath = '/';
		$db_cvtime = (int)$db_cvtime;
		$db_schwait = (int)$db_schwait;
		$db_txtadnum = (int)$db_txtadnum;
		$db_maxmember = (int)$db_maxmember;
		$db_maxresult = (int)$db_maxresult;
		$db_refreshtime = (int)$db_refreshtime;
		ifcheck($db_today,'today');
		ifcheck($db_debug,'debug');
		ifcheck($db_ifjump,'ifjump');
		ifcheck($db_recycle,'recycle');
		ifcheck($db_msgsound,'msgsound');
		ifcheck($db_adminset,'adminset');
		ifcheck($db_ifbookinfo,'ifbookinfo');
		ifcheck($db_footertime,'footertime');
		ifcheck($db_enterreason,'enterreason');
		ifcheck($db_forcecharset,'forcecharset');
		for ($i=0;$i<5;$i++) {
			${'menu_'.$i} = ($db_menu & pow(2,$i)) ? 'CHECKED' : '';
			${'ajax_'.$i} = ($db_ajax & pow(2,$i)) ? 'CHECKED' : '';
		}
	}
	if ($admintype=='safe' || $settingdb['safe']) {
		if (!$settingdb['safe']) {
			$action = $_COOKIE['admin_safe'];
			!$action && $action = 'speed';
		}
		//speed
		$db_obstart = (int)$db_obstart;
		$db_onlinelmt = (int)$db_onlinelmt;
		ifcheck($db_lp,'lp');
		ifcheck($db_online,'online');
		ifcheck($db_redundancy,'redundancy');
		//gdcode
		${'gdtype_'.(int)$db_gdtype} = 'SELECTED';
		for ($i=0;$i<6;$i++) {
			${'gdcheck_'.$i} = ($db_gdcheck & pow(2,$i)) ? 'CHECKED' : '';
			${'gdstyle_'.$i} = ($db_gdstyle & pow(2,$i)) ? 'CHECKED' : '';
		}
		$gdsize = explode("\t",$db_gdsize);
		list($regq,$loginq,$postq,$msgq) = explode("\t",$db_qcheck);
		$postq = (int)$postq;
		$db_postgd = (int)$db_postgd;
		ifcheck($msgq,'msgq');
		ifcheck($regq,'regq');
		ifcheck($loginq,'loginq');
		//dir
		$imgdisabled = $attdisabled = $htmdisabled = '';
		if (file_exists($imgdir) && !pwWritable($imgdir)) {
			$imgdisabled = 'DISABLED';
		}
		if (file_exists($attachdir) && !pwWritable($attachdir)) {
			$attdisabled = 'DISABLED';
		}
		if (file_exists(R_P.$db_htmdir) && !pwWritable(R_P.$db_htmdir)) {
			$htmdisabled = 'DISABLED';
		}
		ifcheck($db_autochange,'autochange');
		${'hour_'.(int)$db_hour} = 'SELECTED';
		!$db_http && $db_http = 'N';
		!$db_attachurl && $db_attachurl = 'N';
		//safe
		${'cc_'.(int)$db_cc} = 'CHECKED';
		$db_loadavg = (int)$db_loadavg;
		ifcheck($db_ipcheck,'ipcheck');
		ifcheck($db_ifsafecv,'ifsafecv');
		ifcheck($db_xforwardip,'xforwardip');
		$safegroup = ''; $num = 0;
		foreach ($ltitle as $key => $value) {
			if ($key != 1 && $key != 2) {
				$num++;
				$htm_tr = $num % 3 == 0 ? '</tr><tr>' : '';
				$s_checked = strpos($db_safegroup,','.$key.',')!==false ? 'CHECKED' : '';
				$safegroup .= '<td><input type="checkbox" name="safegroup[]" value="'.$key.'" '.$s_checked.'>'.$value.'</td>'.$htm_tr;
			}
		}
		$safegroup && $safegroup = '<table cellspacing="0" cellpadding="0" border="0" width="100%" align="center"><tr>'.$safegroup.'</tr></table>';
	}
	if ($admintype=='att' || $settingdb['att']) {
		if (!$settingdb['att']) {
			$action = $_COOKIE['admin_att'];
			!$action && $action = 'att';
		}
		//att
		(int)$db_attachnum<1 && $db_attachnum = 4;
		$db_attachhide = (int)$db_attachhide;
		ifcheck($db_attfg,'attfg');
		ifcheck($db_allowupload,'allowupload');
		$attachdir_ck[(int)$db_attachdir] = 'SELECTED';
		$maxuploadsize = ini_get('upload_max_filesize');
		!is_array($db_uploadfiletype = unserialize($db_uploadfiletype)) && $db_uploadfiletype = array();
		//pic
		list($db_athumbwidth,$db_athumbheight) = explode("\t",$db_athumbsize);
		${'ifgif_'.(int)$db_ifgif} = 'CHECKED';
		${'waterpos_ck_'.(int)$db_waterpos} = 'SELECTED';
		
		$enoption = $choption = '';
		if ($fp = opendir($imgdir.'/fonts/en/')) {
			while (($file = readdir($fp))!==false) {
				if (substr($file,-4)=='.ttf') {
					$filename = substr($file,0,-4);
					$enslted = $db_waterfonts=='en/'.$filename ? 'SELECTED' : '';
					$enoption .= '<option value="en/'.$filename.'" '.$enslted.'>'.$filename.'</option>';
				}
			}
			closedir($fp);
		}
		if ($fp = opendir($imgdir.'/fonts/ch/')) {
			while (($file = readdir($fp))!==false) {
				if (substr($file,-4)=='.ttf') {
					$filename = substr($file,0,-4);
					$chslted = $db_waterfonts=='ch/'.$filename ? 'SELECTED' : '';
					$choption .= '<option value="ch/'.$filename.'" '.$enslted.'>'.$filename.'</option>';
				}
			}
			closedir($fp);
		}
		!$enoption && $enoption = '<option value="en/PilsenPlakat">PilsenPlakat</option>';
		
		$db_waterpct = (int)$db_waterpct;
		$db_waterfont = (int)$db_waterfont;
		$db_jpgquality = (int)$db_jpgquality;
		$db_waterwidth = (int)$db_waterwidth;
		$db_waterheight = (int)$db_waterheight;
		$db_athumbwidth = (int)$db_athumbwidth;
		$db_athumbheight = (int)$db_athumbheight;
		
		ifcheck($db_ifathumb,'ifathumb');
		ifcheck($db_watermark,'watermark');
		//ftp
		@include_once(D_P.'data/bbscache/ftp_config.php');
		(int)$ftp_port<1 && $ftp_port = '21';
		(int)$ftp_timeout<1 && $ftp_timeout = '10';
		ifcheck($db_ifftp,'ifftp');
		$ftp_pass = substr($ftp_pass,0,1).'********'.substr($ftp_pass,-1);
	}
	if ($admintype=='credit' || $settingdb['credit']) {
		require_once(R_P.'require/credit.php');
		!is_array($creditset = unserialize($db_creditset)) && $creditset = array();
		$creditlog = array();
		foreach ($db_creditlog as $key => $value) {
			foreach ($value as $k => $v) {
				$creditlog[$key][$k] = 'CHECKED';
			}
		}
		$db_virerate = (int)$db_virerate;
		$db_virelimit = (int)$db_virelimit;
	}
	if ($admintype=='reg' || $settingdb['reg']) {
		require_once(R_P.'require/credit.php');
		require_once(D_P.'data/bbscache/dbreg.php');
		$rg_rgpermit = str_replace(array('<br />','<br>'),"\n",$rg_rgpermit);
		$rg_welcomemsg = str_replace(array('<br />','<br>'),"\n",$rg_welcomemsg);
		$rg_whyregclose = str_replace(array('<br />','<br>'),"\n",$rg_whyregclose);
		ifcheck($rg_reg,'reg');
		ifcheck($rg_ifcheck,'ifcheck');
		ifcheck($rg_rglower,'rglower');
		ifcheck($db_regpopup,'regpopup');
		ifcheck($rg_npdifferf,'npdifferf');
		ifcheck($rg_regdetail,'regdetail');
		ifcheck($rg_emailcheck,'emailcheck');
		ifcheck($rg_regsendmsg,'regsendmsg');
		ifcheck($rg_regsendemail,'regsendemail');
		ifcheck($rg_allowregister,'allowregister');
		$rg_timeend = (int)$rg_timeend;
		$rg_timestart = (int)$rg_timestart;
		$db_postallowtime = (int)$db_postallowtime;
		list($rg_regminpwd,$rg_regmaxpwd) = explode("\t",$rg_pwdlen);
		list($rg_regminname,$rg_regmaxname) = explode("\t",$rg_namelen);
		for ($i=1;$i<5;$i++) {
			${'pwdcomplex_'.$i} = strpos($rg_pwdcomplex,','.$i.',')===false ? '' : 'CHECKED';
		}
	}
	if ($admintype=='member' || $settingdb['member']) {
		if (!$settingdb['member']) {
			$action = $_COOKIE['admin_member'];
			!$action && $action = 'post';
		}
		require_once(R_P.'require/credit.php');
		$sellset = $enhideset = $signcurtype = '';
		foreach ($credit->cType as $key => $value) {
			//post
			$sellcked  = in_array($key,$db_sellset['type']) ? 'CHECKED' : '';
			$sellset .= ' <input type="checkbox" name="sellset[type][]" value="'.$key.'" '.$sellcked.' /> '.$value;
			$enhidechked  = in_array($key,$db_enhideset['type']) ? 'CHECKED' : '';
			$enhideset .= ' <input type="checkbox" name="enhideset[type][]" value="'.$key.'" '.$enhidechked.' /> '.$value;
			//face
			if (!is_numeric($key)) {
				if ($db_signcurtype==$key) {
					$signcurtype .= '<option value="'.$key.'" SELECTED>'.$value.'</option>';
				} else {
					$signcurtype .= '<option value="'.$key.'">'.$value.'</option>';
				}
			}
		}
		//post
		$db_cvtimes = (int)$db_cvtimes;
		$db_postmax = (int)$db_postmax;
		$db_postmin = (int)$db_postmin;
		$db_selcount = (int)$db_selcount;
		$db_titlemax = (int)$db_titlemax;
		$db_showreplynum = (int)$db_showreplynum;
		$db_windpost['size'] = (int)$db_windpost['size'];
		$db_windpost['price'] = (int)$db_windpost['price'];
		$db_windpost['income'] = (int)$db_windpost['income'];
		$db_windpost['picwidth'] = (int)$db_windpost['picwidth'];
		$db_windpost['picheight'] = (int)$db_windpost['picheight'];
		ifcheck($db_tcheck,'tcheck');
		ifcheck($db_pwcode,'pwcode');
		ifcheck($db_setform,'setform');
		ifcheck($db_autoimg,'autoimg');
		ifcheck($db_windmagic,'windmagic');
		ifcheck($db_selectgroup,'selectgroup');
		ifcheck($db_replysendmail,'replysendmail');
		ifcheck($db_replysitemail,'replysitemail');
		ifcheck($db_windpost['pic'],'windpost_pic');
		ifcheck($db_windpost['mpeg'],'windpost_mpeg');
		ifcheck($db_windpost['flash'],'windpost_flash');
		ifcheck($db_windpost['iframe'],'windpost_iframe');
		ifcheck($db_windpost['checkurl'],'windpost_checkurl');
		//face
		list($db_upload,$db_imglen,$db_imgwidth,$db_imgsize) = explode("\t",$db_upload);
		list($db_fthumbwidth,$db_fthumbheight) = explode("\t",$db_fthumbsize);
		$signgroup = ''; $num = 0;
		foreach ($ltitle as $key => $value) {
			if ($key!=1 && $key!=2) {
				$num++;
				$htm_tr = $num%3==0 ? '</tr><tr>' : '';
				$signcked = strpos($db_signgroup,",$key,")!==false ? 'CHECKED' : '';
				$signgroup .= '<td><input type="checkbox" name="signgroup[]" value="'.$key.'" '.$signcked.'> '.$value.'</td>'.$htm_tr;
			}
		}
		$signgroup && $signgroup = '<table cellspacing="0" cellpadding="0" border="0" width="100%" align="center"><tr>'.$signgroup.'</tr></table>';
		for ($i=0;$i<3;$i++) {
			${'logintype_'.$i} = ($db_logintype & pow(2,$i)) ? 'CHECKED' : '';
		}
		
		$db_imglen = (int)$db_imglen;
		$db_imgsize = (int)$db_imgsize;
		$db_imgwidth = (int)$db_imgwidth;
		$db_signmoney = (int)$db_signmoney;
		$db_signheight = (int)$db_signheight;
		$db_fthumbwidth = (int)$db_fthumbwidth;
		$db_fthumbheight = (int)$db_fthumbheight;
		$db_windpic['size'] = (int)$db_windpic['size'];
		$db_windpic['picwidth'] = (int)$db_windpic['picwidth'];
		$db_windpic['picheight'] = (int)$db_windpic['picheight'];
		
		ifcheck($db_upload,'upload');
		ifcheck($db_iffthumb,'iffthumb');
		ifcheck($db_signwindcode,'signwindcode');
		ifcheck($db_windpic['pic'],'windpic_pic');
		ifcheck($db_windpic['flash'],'windpic_flash');
	}
	if ($admintype=='pcache' || $settingdb['pcache']) {
		if (!$settingdb['pcache']) {
			$action = $_COOKIE['admin_pcache'];
			!$action && $action = 'thread';
		}
		//thread
		$db_fcachenum = (int)$db_fcachenum;
		$db_fcachetime = (int)$db_fcachetime;
		//guest
		$db_fguestnum = (int)$db_fguestnum;
		$db_tguestnum = (int)$db_tguestnum;
		$db_guestread = (int)$db_guestread;
		$db_guestindex = (int)$db_guestindex;
		$db_guestthread = (int)$db_guestthread;
	}
	if ($admintype=='index' || $settingdb['index']) {
		${'indexfmlogo_'.(int)$db_indexfmlogo} = 'CHECKED';
		$gporder = explode(',',$db_showgroup);
		$usergroup = ''; $num = 0;
		foreach ($ltitle as $key => $value) {
			if ($key!=1 && $key!=2) {
				$num++;
				$htm_tr = $num % 2 == 0 ? '</tr><tr>' : '';
				if (in_array($key,$gporder)) {
					$g_ck    = 'CHECKED';
					$g_order = array_search($key,$gporder);
				} else {
					$g_order = $g_ck = '';
				}
				$usergroup .= '<td><input type="checkbox" name="gpshow['.$key.']" value="'.$key.'" '.$g_ck.'><input name="gporder['.$key.']" value="'.$g_order.'" size="1"> '.$value.'</td>'.$htm_tr;
			}
		}
		$usergroup && $usergroup = '<table cellspacing="0" cellpadding="0" border="0" width="100%" align="center"><tr>'.$usergroup.'</tr></table>';
		
		ifcheck($db_setindex,'setindex');
		ifcheck($db_todaypost,'todaypost');
		ifcheck($db_showguest,'showguest');
		ifcheck($db_adminshow,'adminshow');
		ifcheck($db_indexlink,'indexlink');
		ifcheck($db_indexonline,'indexonline');
		ifcheck($db_ifselfshare,'ifselfshare');
		ifcheck($db_bdayautohide,'bdayautohide');
		ifcheck($db_indexmqshare,'indexmqshare');
		ifcheck($db_indexshowbirth,'indexshowbirth');
	}
	if ($admintype=='thread' || $settingdb['thread']) {
		$hithour_sel[(int)$db_hithour] = 'SELECTED';
		
		$db_newtime = (int)$db_newtime;
		$db_perpage = (int)$db_perpage;
		$db_maxpage = (int)$db_maxpage;
		$db_maxtypenum = (int)$db_maxtypenum;
		
		ifcheck($db_topped,'topped');
		ifcheck($db_threadonline,'threadonline');
		ifcheck($db_threademotion,'threademotion');
		ifcheck($db_threadshowpost,'threadshowpost');
	}
	if ($admintype=='read' || $settingdb['read']) {
		$showcustom = ''; $num = 0;
		foreach ($_CREDITDB as $key => $value) {
			$num++;
			$htm_tr = $num%4==0 ? '</tr><tr>' : '';
			$ctcked = strpos($db_showcustom,",$key,")!==false ? 'CHECKED' : '';
			$showcustom .= '<td><input type="checkbox" name="showcustom['.$key.']" value="'.$key.'" '.$ctcked.'> '.$value[0].'</td>'.$htm_tr;
		}
		$showcustom && $showcustom = '<table cellspacing="0" cellpadding="0" border="0" width="100%" align="center"><tr>'.$showcustom.'</tr></table>';
		
		$db_pingtime = (int)$db_pingtime;
		$db_readperpage = (int)$db_readperpage;
		
		ifcheck($db_shield,'shield');
		ifcheck($db_ipfrom,'ipfrom');
		ifcheck($db_showonline,'showonline');
		ifcheck($db_showcolony,'showcolony');
		ifcheck($db_ifonlinetime,'ifonlinetime');
	}
	if ($admintype=='other' || $settingdb['other']) {
		if (!$settingdb['other']) {
			$action = $_COOKIE['admin_other'];
			!$action && $action = 'email';
		}
		include_once(D_P.'data/bbscache/mail_config.php');
		//mail
		${'mailmethod_'.(int)$ml_mailmethod} = 'CHECKED';
		$ml_smtppass = substr($ml_smtppass,0,1).'********'.substr($ml_smtppass,-1);
		
		$ml_smtpport = (int)$ml_smtpport;
		
		ifcheck($ml_smtpauth,'smtpauth');
		ifcheck($ml_mailifopen,'mailifopen');
		//wap
		$showforums = ''; $num = 0;
		$query = $db->query("SELECT fid,name FROM pw_forums WHERE type<>'category' AND allowvisit='' AND f_type!='hidden' AND cms='0'");
		while ($rt = $db->fetch_array($query,MYSQL_NUM)) {
			$num++;
			$htm_tr = $num%2==0 ? '</tr><tr>' : '';
			$forumscked = strpos(','.$db_wapfids.',',','.$rt[0].',')!==false ? 'CHECKED' : '';
			$showforums .= '<td><input type="checkbox" name="wapfids[]" value="'.$rt[0].'" '.$forumscked.'>'.$rt[1].'</td>'.$htm_tr;
		}
		$showforums && $showforums = '<table cellspacing="0" cellpadding="0" border="0" width="100%" align="center"><tr>'.$showforums.'</tr></table>';
		
		$db_waplimit = (int)$db_waplimit;
		
		ifcheck($db_wapifopen,'wapifopen');
		ifcheck($db_wapcharset,'wapcharset');
		//js
		$db_jsper = (int)$db_jsper;
		
		ifcheck($db_jsifopen,'jsifopen');
	}
	$display = '';
	if ($action) {
		${'cls_'.$action} = 'class="two"';
		$display = 'none';
	}
	include PrintEot('setting');exit;
} else {
	InitGP(array('config'),'P',0);
	
	$names = $configdb = array();
	if (!pwWritable(D_P.'data/bbscache/config.php') && !chmod(D_P.'data/bbscache/config.php',0777)) {
		adminmsg('config_777');
	}
	if ($admintype=='basic' || $settingdb['basic']) {
		InitGP(array('visitgroup','postctl','schctl','menu','ajax'),'P',2);
		//state
		$config['visitmsg'] = ieconvert($config['visitmsg']);
		$config['whybbsclose'] = ieconvert($config['whybbsclose']);
		$postctl['poststart']>23 && $postctl['poststart'] = 0;
		$postctl['postend']>23 && $postctl['postend'] = 0;
		$schctl['schstart']>23 && $schctl['schstart'] = 0;
		$schctl['schend']>23 && $schctl['schend'] = 0;
		$config['openpost'] = $postctl['openpost']."\t".$postctl['poststart']."\t".$postctl['postend'];
		$config['opensch'] = $schctl['opensch']."\t".$schctl['schstart']."\t".$schctl['schend'];
		$config['visituser'] = ','.trim($config['visituser']).',';
		$config['visitgroup'] = $visitgroup ? ','.implode(',',$visitgroup).',' : '';
		//info
		substr($config['bbsurl'],0,4)!='http' && adminmsg('bbsurl_http');
		substr($config['bbsurl'],-1)=='/' && $config['bbsurl'] = substr($config['bbsurl'],0,-1);
		//global
		if ($config['datefm']) {
			if (strpos($config['datefm'],'mm')!==false) {
				$config['datefm'] = str_replace('mm','m',$config['datefm']);
			} else {
				$config['datefm'] = str_replace('m','n',$config['datefm']);
			}
			if (strpos($config['datefm'],'dd')!==false) {
				$config['datefm'] = str_replace('dd','d',$config['datefm']);
			} else {
				$config['datefm'] = str_replace('d','j',$config['datefm']);
			}
			$config['datefm'] = str_replace(array('yyyy','yy'),array('Y','y'),$config['datefm']);
			$config['datefm'] .= GetGP('time_f','P')=='12' ? ' h:i A' :' H:i';
		} else {
			$config['datefm'] = 'Y-n-j H:i';
		}
		$config['menu'] = intval(array_sum($menu));
		$config['ajax'] = intval(array_sum($ajax));
		$config['onlinetime'] *= 60;
		substr($config['ckpath'],-1)!='/' && $config['ckpath'].='/';
		unset($postctl,$schctl,$menu,$ajax);
	}
	if ($admintype=='safe' || $settingdb['safe']) {
		InitGP(array('answer'),'P');
		InitGP(array('question'),'P',0);
		InitGP(array('safegroup','gdcheck','gdstyle','gdsize','qcheck'),'P',2);
		//speed
		(int)$config['onlinelmt']<1 && $config['onlinelmt'] = 5000;
		(int)$config['obstart']>9 && $config['obstart'] = 9;
		//seo
		$config['bbstitle'] = Char_cv(strip_tags($config['bbstitle']));
		$config['metakeyword'] = Char_cv(strip_tags($config['metakeyword']));
		$config['metadescrip'] = Char_cv(strip_tags($config['metadescrip']));
		//gdcode
		$config['gdsize']  = implode("\t",$gdsize);
		$config['safegroup'] = $safegroup ? ','.implode(',',$safegroup).',' : '';
		$config['qcheck'] = $qcheck['regq']."\t".$qcheck['loginq']."\t".$qcheck['postq']."\t".$qcheck['msgq'];
		$config['gdcheck'] = !empty($gdcheck) ? intval(array_sum($gdcheck)) : 0;
		$config['gdstyle'] = !empty($gdstyle) ? intval(array_sum($gdstyle)) : 0;
		$q_array = $a_array = array();
		if (is_array($question) && is_array($answer)) {
			foreach ($question as $key => $value) {
				$value = trim($value);
				if ($value) {
					$q_array[] = stripslashes($value);
					$a_array[] = stripslashes($answer[$key]);
				}
			}
		}
		$config['question'] = !empty($q_array) ? addslashes(serialize($q_array)) : '';
		$config['answer'] = !empty($a_array) ? addslashes(serialize($a_array)) : '';
		//dir
		if (!$config['picpath']) {
			if (is_dir('images')) {
				$config['picpath'] = 'images';
			} else {
				adminmsg('settings_picdir_dfnotfind');
			}
		} elseif (!is_dir(R_P.$config['picpath']) && $db_picpath!=$config['picpath']) {
			!preg_match('/^[a-zA-Z0-9\_]+$/i',$config['picpath']) && adminmsg('settings_picdir_error');
			if (!$db_picpath || !is_dir(R_P.$db_picpath)) {
				if (is_dir('images')) {
					$db_picpath = 'images';
				} else {
					adminmsg('settings_picdir_dfnotfind');
				}
			}
			if (!rename(R_P.$db_picpath,R_P.$config['picpath'])) {
				$config['picpath'] = $db_picpath;
			}
		}
		if (!$config['attachname']) {
			if (is_dir('attachment')) {
				$config['attachname'] = 'attachment';
			} else {
				adminmsg('settings_attdir_dfnotfind');
			}
		} elseif (!is_dir(R_P.$config['attachname']) && $db_attachname!=$config['attachname']) {
			!preg_match('/^[a-zA-Z0-9\_]+$/i',$config['attachname']) && adminmsg('settings_attdir_error');
			if (!$db_attachname || !is_dir(R_P.$db_attachname)) {
				if (is_dir('attachment')) {
					$db_attachname = 'attachment';
				} else {
					adminmsg('settings_attdir_dfnotfind');
				}
			}
			if (!rename(R_P.$db_attachname,R_P.$config['attachname'])) {
				$config['attachname'] = $db_attachname;
			}
		}
		if (!$config['htmdir']) {
			if (is_dir('htm_data')) {
				$config['htmdir'] = 'htm_data';
			} else {
				adminmsg('settings_htmdir_dfnotfind');
			}
		} elseif (!is_dir(R_P.$config['htmdir']) && $db_htmdir!=$config['htmdir']) {
			!preg_match('/^[a-zA-Z0-9\_]+$/i',$config['htmdir']) && adminmsg('settings_htmdir_error');
			if (!$db_htmdir || !is_dir(R_P.$db_htmdir)) {
				if (is_dir('htm_data')) {
					$db_htmdir = 'htm_data';
				} else {
					adminmsg('settings_htmdir_dfnotfind');
				}
			}
			if (!rename(R_P.$db_htmdir,R_P.$config['htmdir'])) {
				$config['htmdir'] = $db_htmdir;
			}
		}
		if ($config['http']!='N') {
			if (!$config['http']) {
				$config['http'] = 'N';
			} elseif (substr($config['http'],0,4)!='http') {
				$config['http'] = $db_http ? $db_http : 'N';
			}
		}
		if ($config['attachurl']!='N') {
			if (!$config['attachurl']) {
				$config['attachurl'] = 'N';
			} elseif (substr($config['attachurl'],0,4)!='http') {
				$config['attachurl'] = $db_attachurl ? $db_attachurl : 'N';
			}
		}
		if ($config['autochange'] && (!pwWritable(R_P.$config['picpath']) || !pwWritable(R_P.$config['attachname']))) {
			$config['autochange'] = 0;
		}
		//safe
		$config['iplimit'] = trim($config['iplimit'],',');
		if (!$config['registerfile']) {
			if (file_exists('register.php')) {
				$config['registerfile'] = 'register.php';
			} else {
				adminmsg('settings_regfile_dfnotfind');
			}
		} elseif (!file_exists(R_P.$config['registerfile']) && $db_registerfile!=$config['registerfile']) {
			!preg_match('/^[a-zA-Z][a-zA-Z0-9\_]+\.php$/is',$config['registerfile']) && adminmsg('settings_regfile_error');
			if (!$db_registerfile || !file_exists(R_P.$db_registerfile)) {
				if (file_exists('register.php')) {
					$db_registerfile = 'register.php';
				} else {
					adminmsg('settings_regfile_dfnotfind');
				}
			}
			if (!rename(R_P.$db_registerfile,R_P.$config['registerfile'])) {
				$config['registerfile'] = $db_registerfile;
			}
		}
		if (!$config['adminfile']) {
			if (file_exists('admin.php')) {
				$config['adminfile'] = 'admin.php';
			} else {
				adminmsg('settings_adminfile_dfnotfind');
			}
		} elseif (!file_exists(R_P.$config['adminfile']) && $db_adminfile!=$config['adminfile']) {
			!preg_match('/^[a-zA-Z][a-zA-Z0-9\_]+\.php$/is',$config['adminfile']) && adminmsg('settings_adminfile_error');
			if (!$db_adminfile || !file_exists(R_P.$db_adminfile)) {
				if (file_exists('admin.php')) {
					$db_adminfile = 'admin.php';
				} else {
					adminmsg('settings_adminfile_dfnotfind');
				}
			}
			if (!rename(R_P.$db_adminfile,R_P.$config['adminfile'])) {
				$config['adminfile'] = $db_adminfile;
			}
		}
		unset($answer,$question,$safegroup,$gdcheck,$gdstyle,$gdsize,$qcheck);
	}
	if ($admintype=='att' || $settingdb['att']) {
		//att
		InitGP(array('filetype','ftp'),'P');
		InitGP(array('maxsize','athumbsize'),'P',2);
		$uploadfiletype = array();
		foreach ($filetype as $key => $value) {
			$value && $uploadfiletype[$value] = $maxsize[$key];
		}
		$config['uploadfiletype'] = $uploadfiletype ? serialize($uploadfiletype) : '';
		unset($filetype,$maxsize,$uploadfiletype);
		//pic
		if ($config['watermark'] && (!function_exists('imagecreatefromgif') || !function_exists('imagettfbbox') || !function_exists('imagealphablending'))) {
			$config['watermark'] = 0;
		}
		$config['athumbsize'] = $athumbsize['athumbwidth']."\t".$athumbsize['athumbheight'];
		@include_once(D_P.'data/bbscache/ftp_config.php');
		if ($ftp['pass'] == substr($ftp_pass,0,1).'********'.substr($ftp_pass,-1)) {
			$ftp['pass'] = $ftp_pass;
		}
	}
	if ($admintype=='credit' || $settingdb['credit']) {
		InitGP(array('creditpay'),'P');
		InitGP(array('creditset','creditlog'),'P',2);
		$config['creditset'] = $config['creditpay'] = $config['creditlog'] = '';
		if (is_array($creditset) && !empty($creditset)) {
			foreach ($creditset as $key => $value) {
				foreach ($value as $k => $v) {
					$creditset[$key][$k] = round($v,($k=='rvrc' ? 1 : 0));
				}
			}
			$config['creditset'] = addslashes(serialize($creditset));
		}
		if (is_array($creditpay['name']) && !empty($creditpay['name'])) {
			$cpay = array();
			require_once(R_P.'require/credit.php');
			foreach ($creditpay['name'] as $key => $value) {
				if (isset($credit->cType[$value]) && !isset($cpay[$value])) {
					$cpay[$value] = array(
						'rmbrate'	=> intval($creditpay['rmbrate'][$key]),
						'rmblest'	=> intval($creditpay['rmblest'][$key]),
						'virement'	=> intval($creditpay['virement'][$key])
					);
				}
			}
			is_array($cpay) && !empty($cpay) && $config['creditpay'] = addslashes(serialize($cpay));
		}
		is_array($creditlog) && !empty($creditlog) && $config['creditlog'] = addslashes(serialize($creditlog));
		unset($creditpay,$creditset,$creditlog);
	}
	if ($admintype=='reg' || $settingdb['reg']) {
		if (!pwWritable(D_P.'data/bbscache/dbreg.php') && !chmod(D_P.'data/bbscache/dbreg.php',0777)) {
			adminmsg('dbreg_777');
		}
		InitGP(array('reg'),'P',0);
		InitGP(array('namelen','pwdlen','regcredit'),'P',2);
		$reg['email'] = trim($reg['email'],',');
		$reg['banname'] = trim($reg['banname'],',');
		$reg['allowsameip'] = trim($reg['allowsameip'],',');
		$reg['rgpermit'] = ieconvert($reg['rgpermit']);
		$reg['welcomemsg'] = ieconvert($reg['welcomemsg']);
		$reg['whyregclose'] = ieconvert($reg['whyregclose']);
		if ($reg['timeend']-$reg['timestart']>150 || $reg['timeend']-$reg['timestart']<0) {
			adminmsg('reg_timelimit');
		}
		if ($namelen['max']<1 || $namelen['max']>15) {
			$namelen['max'] = 15;
		}
		if ($namelen['min']<1 || $namelen['min']>$namelen['max']) {
			adminmsg('reg_username_limit');
		}
		if ($pwdlen['min']<1 || ($pwdlen['max'] && $pwdlen['min']>$pwdlen['max'])) {
			adminmsg('reg_password_limit');
		}
		$reg['pwdlen'] = $pwdlen['min']."\t".$pwdlen['max'];
		$reg['namelen'] = $namelen['min']."\t".$namelen['max'];
		$reg['regcredit'] = addslashes(serialize($regcredit));
		foreach ($reg['pwdcomplex'] as $key => $value) {
			if ((int)$value<1) {
				unset($reg['pwdcomplex'][$key]);
			}
		}
		if (count($reg['pwdcomplex'])) {
			$reg['pwdcomplex'] = ','.implode(',',$reg['pwdcomplex']).',';
		} else {
			$reg['pwdcomplex'] = '';
		}
		unset($namelen,$pwdlen,$regcredit);
	}
	if ($admintype=='member' || $settingdb['member']) {
		InitGP(array('sellset','enhideset'),'P');
		InitGP(array('windpost','upload','signgroup','logintype','fthumbsize','windpic'),'P',2);
		//post
		$config['sellset'] = $sellset ? addslashes(serialize($sellset)) : '';
		$config['windpic'] = $windpic ? addslashes(serialize($windpic)) : '';
		$config['windpost'] = $windpost ? addslashes(serialize($windpost)) : '';
		$config['enhideset'] = $enhideset ? addslashes(serialize($enhideset)) : '';
		(int)$config['postmax']<1 && $config['postmax'] = 50000;
		//face
		$upload['imglen']<1 && $upload['imglen'] = 160;
		$upload['imgsize']<1 && $upload['imgsize'] = 20;
		$upload['imgwidth']<1 && $upload['imgwidth'] = 160;
		$config['logintype'] = intval(array_sum($logintype));
		$config['signgroup'] = $signgroup ? ','.implode(',',$signgroup).',' : '';
		$config['fthumbsize'] = $fthumbsize['fthumbwidth']."\t".$fthumbsize['fthumbheight'];
		$config['upload'] = $upload['upload']."\t".$upload['imglen']."\t".$upload['imgwidth']."\t".$upload['imgsize'];
	}
	if ($admintype=='pcache' || $settingdb['pcache']) {
		//guest
		substr($config['guestdir'],-1)=='/' && $config['guestdir'] = substr($config['guestdir'],0,-1);
	}
	if ($admintype=='index' || $settingdb['index']) {
		InitGP(array('gpshow','gporder'),'P',2);
		if (is_array($gpshow)) {
			$showgroup = array();
			foreach ($gpshow as $key => $value) {
				$showgroup[$value] = $gporder[$key];
			}
			asort($showgroup);
			$showgroup = array_keys($showgroup);
			$config['showgroup'] = ','.implode(',',$showgroup).',';
		} else {
			$config['showgroup'] = '';
		}
	}
	if ($admintype=='thread' || $settingdb['thread']) {
		(int)$config['perpage']<1 && $config['perpage'] = 25;
	}
	if ($admintype=='read' || $settingdb['read']) {
		InitGP(array('showcustom'),'P',2);
		(int)$config['readperpage']<1 && $config['readperpage'] = 10;
		$config['showcustom'] = $showcustom ? ','.implode(',',$showcustom).',' : '';
	}
	if ($admintype=='other' || $settingdb['other']) {
		InitGP(array('mail'),'P');
		InitGP(array('wapfids'),'P',2);
		//mail
		(int)$mail['smtpport']<1 && $mail['smtpport'] = 25;
		//wap
		$config['wapfids'] = implode(',',$wapfids);
		//js
		$config['bindurl'] = trim($config['bindurl'],',');
	}
	
	$temppre = array('config' => 'db_', 'ftp' => 'ftp_', 'reg' => 'rg_', 'mail' => 'ml_');
	foreach ($temppre as $key => $value) {
		$key_a = ${$key};
		if (is_array($key_a)) {
			foreach ($key_a as $k => $v) {
				$names[] = $value.$k;
				$configdb[$value.$k] = array($value.$k,$v);
			}
		}
	}
	
	if (!empty($names)) {
		$query = $db->query('SELECT db_name,db_value FROM pw_config WHERE db_name IN ('.pwImplode($names,false).')');
		while ($rt = $db->fetch_array($query)) {
			if (isset($configdb[$rt['db_name']])) {
				$configdb[$rt['db_name']][1]!=$rt['db_value'] && $db->update('UPDATE pw_config SET db_value='.pwEscape($configdb[$rt['db_name']][1]).'WHERE db_name='.pwEscape($rt['db_name']));
				$configdb[$rt['db_name']] = '';
			}
		}
		$db->free_result($query);
		$pwSqlMulti = pwSqlMulti($configdb);
		$pwSqlMulti && $db->update('INSERT INTO pw_config (db_name,db_value) VALUES'.$pwSqlMulti);
		updatecache_c();
		if (!empty($ftp)) {
			updatecache_ftp();
		}
		if (!empty($mail)) {
			updatecache_ml();
		}
	}
	adminmsg('operate_success');
}
?>