<?php
if(!defined('IN_ADMIN')) exit('Access Denied');
if($_SESSION["admin"]!="NewsTeng")showmessage('请登陆', SCRIPT_NAME.'?file=login');
@set_time_limit(0);
if(!isset($action)) $action = 'setup';
switch ($action){
	case 'setup':
            if($dosubmit){
                if(empty($setting)) showmessage('操作失败', 'goback');
                if($setting['siteurl'] && substr($setting['siteurl'], -1, 1) != '/'){
					$setting['siteurl'] .= '/';
				}elseif(empty($setting['siteurl'])){
					$setting['siteurl'] = SITE_URL;
				}
                setting_set('setup',$setting);
                setting_set('seccodedata',$seccodedata);
                setting_set('seccode',$seccode);
                set_config($setconfig);
                cache_all();
				showmessage('保存成功！', 'goback');
            }else{     
            	$seccode = setting_get('seccode');
            	$seccodedata = setting_get('seccodedata');           
                $TM = setting_get('setup');
                $dir = opendir(TM_ROOT.TPL_ROOT);
                $file_list = "<select name=\"setconfig[TPL_NAME]\">";
		 		while ($file_name = readdir($dir)) {
					if (($file_name != ".") && ($file_name != "..")) {
						if($file_name == _TPLPathb_){
							$file_list .= "<option value=\"$file_name\"selected=\"selected\">$file_name</option>" ;
						}else{
							$file_list .= "<option value=\"$file_name\">$file_name</option>" ;
						}
					}
				}
                $file_list .= "</select>";
                closedir($dir);
                include admin_tpl('setting');
            }
	break;

         /*缓存更新*/
        case 'cache':
        	 $r = $db->get_one("SELECT count(userid) as cc FROM `".DB_PRE."member`");
        	 cache_all();
             include admin_tpl('setting');
	break;
	  /*商务引擎*/
        case 'business':
        	if($dosubmit){
        	 	setting_set('business',$setting);
        	 	cache_all();
        	 	showmessage('保存成功！', 'goback');
        	}else{
        		$business = setting_get('business');
             	include admin_tpl('setting');
        	}
	break;
	/*测试帐号*/
	case 'test_user':
		$http = load('http.class.php');
	    $is_ok = $http->get('http://www.newsteng.com/member/api/test_user.php?charset='.CHARSET.'&xtcms_username='.urlencode($xtcms_username).'&xtcms_password='.urlencode($xtcms_password));
	    echo $is_ok === false ? 0 : $http->get_data();
	break;
}
?>