<?php
if(!$_SESSION['admin_id']){
	pe_goto("index.php");
}
switch ($act) {
	//#####################@ 邮箱信息 @#####################//
	case 'email':
		$menumark = 'setting_email';
		$info = $db->index('setting_key')->pe_selectall('setting');

		$seo = pe_seo('邮箱信息', '', '', 'admin');
		$action = 'admin.php?mod=setting&act=emailsql';
		include(pe_tpl('setting_email.html'));
	break;
	//#####################@ 邮箱信息设置sql @#####################//
	case 'emailsql':
		$sql = "update `".dbpre."setting` set `setting_value` = case `setting_key`
			when 'email_smtp' then '".pe_dbhold($_p_info['email_smtp'])."'
			when 'email_port' then '".pe_dbhold($_p_info['email_port'])."'
			when 'email_name' then '".pe_dbhold($_p_info['email_name'])."'
			when 'email_pw' then '".pe_dbhold($_p_info['email_pw'])."'
			when 'email_nname' then '".pe_dbhold($_p_info['email_nname'])."'
			when 'web_wlname' then '".pe_dbhold($_p_info['web_wlname'])."' end
			where `setting_key` in ('email_smtp','email_port','email_name','email_pw','email_nname','web_wlname')";
		if ($db->sql_update($sql)) {
			cache::write('setting', 'setting_key');
			pe_success('邮箱信息设置成功!');
		}
		else {
			pe_error('邮箱信息设置失败...');
		}
	break;
	case 'alipay':
		if($_POST['dosubmit']){	
			foreach($_p_bank as $k=>$v){
				if(empty($v['bankname']))unset($_p_bank[$k]);
			}
			$_p_info['bank_info']=base64_encode(serialize($_p_bank));
			if($_p_disabled)$_p_info['alipay_id']=NULL;
			$sql = "update `".dbpre."setting` set `setting_value` = case `setting_key`
			when 'alipay_id' then '".pe_dbhold($_p_info['alipay_id'])."'
			when 'alipay_pid' then '".pe_dbhold($_p_info['alipay_pid'])."'
			when 'alipay_key' then '".pe_dbhold($_p_info['alipay_key'])."'
			when 'service_type' then '".pe_dbhold($_p_info['service_type'])."'
			when 'alipay_rate' then '".pe_dbhold($_p_info['alipay_rate'])."'
			when 'bank_info' then '".pe_dbhold($_p_info['bank_info'])."'
			when 'web_alipayurl' then '".pe_dbhold($_p_info['web_alipayurl'])."' end
			where `setting_key` in ('alipay_id','alipay_pid','alipay_key','service_type','alipay_rate','web_alipayurl','bank_info')";
			if ($db->sql_update($sql)){
				cache::write('setting', 'setting_key');
				pe_alert('支付宝接口设置成功!');
			}
			else {
				pe_alert('支付宝接口设置失败...');
			}
		}
		else{
			$menumark = 'setting_base';
			$info = $db->index('setting_key')->pe_selectall('setting');
			$bank=unserialize(base64_decode($info['bank_info']['setting_value']));
			$seo = pe_seo('支付宝接口', '', '', 'admin');
			include(pe_tpl('setting_alipay.html'));
		}
	break;
	case 'tip':
		if($_p_dosubmit){	
			$sql = "update `".dbpre."editsetting` set `content` = case `name`
			when 'tip_buy_tj' then '".pe_dbhold($_p_info['tip_buy_tj'])."'
			when 'tip_vip' then '".pe_dbhold($_p_info['tip_vip'])."' end
			where `name` in ('tip_buy_tj','tip_vip')";
			if ($db->sql_update($sql)) {
				pe_success('提示语设置成功!');
			}
			else {
				pe_error('提示语设置失败...');
			}
		}
		else{
			$menumark = 'setting_base';
			$info = $db->index('name')->pe_selectall('editsetting');
			$seo = pe_seo('提示语设置', '', '', 'admin');
			include(pe_tpl('setting_tip.html'));
		}
	break;
	case 'point':
		if($_p_dosubmit){
			$i['pa']=$_p_pa;$i['pb']=$_p_pb;
			$i['ta']=$_p_ta;$i['tb']=$_p_tb;
			$i=base64_encode(serialize($i));
			$vip1=base64_encode(serialize($_p_vip1));
			$vip2=base64_encode(serialize($_p_vip2));
			$vip3=base64_encode(serialize($_p_vip3));
			if(empty($_p_vip['vip_disabled']))$_p_vip['vip_disabled']=0;
			$_p_vip['vip_tc']=$_p_vip['vip_tc']/100;
			$vip=base64_encode(serialize($_p_vip));
			$sql = "update `".dbpre."setting` set `setting_value` = case `setting_key`
			when 'vip_ti1' then '".$vip1."'
            when 'vip_ti2' then '".$vip2."'
            when 'vip_ti3' then '".$vip3."'
            when 'vip_point' then '".$vip."'			
			when 'huilv' then '".$i."' end
			where `setting_key` in ('huilv','vip_point','vip_ti1','vip_ti2','vip_ti3')";
			if ($db->sql_update($sql)) {
				pe_success('积分设置成功!');
			}
			else {
				pe_error('积分设置失败...');
			}
		}
		else{
			$menumark = 'setting_base';
			$info = $db->index('setting_key')->pe_selectall('setting');
			$i=unserialize(base64_decode($info['huilv']['setting_value']));
			$vip=unserialize(base64_decode($info['vip_point']['setting_value']));
			$vip1=unserialize(base64_decode($info['vip_ti1']['setting_value']));
			$vip2=unserialize(base64_decode($info['vip_ti2']['setting_value']));
			$vip3=unserialize(base64_decode($info['vip_ti3']['setting_value']));
			$vip['vip_tc']=$vip['vip_tc']*100;
			$seo = pe_seo('积分设置', '', '', 'admin');
			include(pe_tpl('setting_point.html'));
		}
	break;
	case 'qq':
		if($_p_dosubmit){
			foreach($_p_qq as $k=>$v){
				if(empty($v['id']))unset($_p_qq[$k]);
			}
			$qq=base64_encode(serialize($_p_qq));
			//p($_p_qq,4);p($qq);
			$sql = "update `".dbpre."setting` set `setting_value` = case `setting_key`
			when 'qq' then '".$qq."'			
			when 'web_kefu' then '".pe_dbhold($_p_info['web_kefu'])."' end
			where `setting_key` in ('qq','web_kefu')";
			if ($db->sql_update($sql)) {
				pe_success('客服设置成功!');
			}
			else {
				pe_error('客服设置失败...');
			}
		}
		else{
			$menumark = 'setting_base';
			$info = $db->index('setting_key')->pe_selectall('setting');
			if($info['qq']['setting_value']){
				$qq=unserialize(base64_decode($info['qq']['setting_value']));
			}
			else $qq=array();
			$seo = pe_seo('积分语设置', '', '', 'admin');
			include(pe_tpl('setting_qq.html'));
		}
		print_r($qq);
	break;
	//#####################@ 基本信息设置sql @#####################//
	case 'basesql':
		$sql = "update `".dbpre."setting` set `setting_value` = case `setting_key`
			when 'web_title' then '".pe_dbhold($_p_info['web_title'])."'
			when 'web_keywords' then '".pe_dbhold($_p_info['web_keywords'])."'
			when 'web_description' then '".pe_dbhold($_p_info['web_description'])."'
			when 'web_tpl' then '".pe_dbhold($_p_info['web_tpl'])."'
			when 'web_weibo' then '".pe_dbhold($_p_info['web_weibo'])."'
            when 'web_huanyy' then '".pe_dbhold($_p_info['web_huanyy'])."'
            when 'web_xinweibo' then '".pe_dbhold($_p_info['web_xinweibo'])."'
			when 'web_name' then '".pe_dbhold($_p_info['web_name'])."'
			when 'web_dianhua' then '".pe_dbhold($_p_info['web_dianhua'])."'
			when 'web_copyright' then '".pe_dbhold($_p_info['web_copyright'])."'
			when 'web_icp' then '".pe_dbhold($_p_info['web_icp'])."'
			when 'lesson_ipnum' then '".intval($_p_info['lesson_ipnum'])."'
			when 'comment_shownum' then '".intval($_p_info['comment_shownum'])."'
			when 'web_tongji' then '".pe_dbhold($_p_info['web_tongji'], 'all')."' end
			where `setting_key` in ('web_title','web_keywords','web_description','alipay_id','alipay_pid','alipay_key','service_type','alipay_rate','web_tpl','web_weibo','web_dianhua','web_copyright','web_icp','web_alipayurl','lesson_ipnum','comment_shownum','web_tongji','web_huanyy','web_xinweibo','web_name')";
		if ($db->sql_update($sql)) {
			cache::write('setting', 'setting_key');
			pe_success('基本信息设置成功!');
		}
		else {
			pe_error('基本信息设置失败...');
		}
	break;
	//#####################@ 基本信息 @#####################//
	default:
		$menumark = 'setting_base';

		$tpl_arr = glob("{$pe['path_root']}template/*");
		foreach ($tpl_arr as $k => $v) {
			$tpl_arr[$k] = trim(substr(stristr($v, 'template/'), 9), '/');
		}
		$info = $db->index('setting_key')->pe_selectall('setting');
		
		$seo = pe_seo('基本信息', '', '', 'admin');
		$action = 'admin.php?mod=setting&act=basesql';
		include(pe_tpl('setting_base.html'));
	break;
}
pe_result();
?>