<?php 
if(!defined('IN_TM')) 
{
	exit('Access Denied');
}

if($_SESSION["admin"]!="Silence")
{	
	include template('login.htm');
	exit;
}
$a = getgpc('do');
if($a == 'config')
{
	if(empty($_POST['Submit'])) 
	{
	
		$rs = $db->query("SELECT * FROM {$tablepre}sysconfig ");
		while($row = mysql_fetch_array($rs))
		{ 
			$$row['varname'] = $row['value']; 
		}
			$tplid = 1 ;
			include template('config.htm');
			exit;
	}
	else
	{
		$SiteName = getgpc('SiteName');
		$SiteDomain = getgpc('SiteDomain');
		$SiteDescription = getgpc('SiteDescription');
		$SiteKeywords = getgpc('SiteKeywords');
		$SitePrivate = getgpc('SitePrivate');
		$SitePhone = getgpc('SitePhone');
		$SiteFax = getgpc('SiteFax');
		$SiteQq = getgpc('SiteQq');
		$SiteMsn = getgpc('SiteMsn');
		$SiteEmail = getgpc('SiteEmail');
		$SystemStatus = getgpc('SystemStatus');
		$SystemStat = getgpc('SystemStat');
		$SiteIcp = getgpc('SiteIcp');
		$CopyRight = getgpc('CopyRight');
		$SiteAdd = getgpc('SiteAdd');
		$db->query("Delete From {$tablepre}sysconfig ");
		$sql = "INSERT INTO {$tablepre}sysconfig (`varname`, `value`) VALUES";
		$sql.="('SiteName','$SiteName'),";
		$sql.="('SiteDomain','$SiteDomain'),";
		$sql.="('SiteDescription','$SiteDescription'),";
		$sql.="('SiteKeywords','$SiteKeywords'),";
		$sql.="('SitePrivate','$SitePrivate'),";
		$sql.="('SitePhone','$SitePhone'),";
		$sql.="('SiteFax','$SiteFax'),";
		$sql.="('SiteQq','$SiteQq'),";
		$sql.="('SiteMsn','$SiteMsn'),";
		$sql.="('SiteEmail','$SiteEmail'),";
		$sql.="('SiteAdd','$SiteAdd'),";
		$sql.="('SiteIcp','$SiteIcp'),";
		$sql.="('SystemStatus','$SystemStatus'),";
		$sql.="('SystemStat','$SystemStat'),";
		$sql.="('CopyRight','$CopyRight');";
		$db->query($sql);
		$db->close();
		$configfile = TM_ROOT.'./data/website.inc.php';
		$fp = fopen($configfile, 'w')or die("写入文件 $configfile 失败!");
		$config = "<?php\r\n";
		$config .= "//程序基本 设置\r\n";	
		$config .= '$SiteName'. "= '".$SiteName."';\r\n";
		$config .= '$SiteDomain'. "= '".$SiteDomain."';\r\n";
		$config .= '$SiteDescription'. "= '".$SiteDescription."';\r\n";
		$config .= '$SiteKeywords'. "= '".$SiteKeywords."';\r\n";
		$config .= '$SitePrivate'. "= '".$SitePrivate."';\r\n";
		$config .= '$SitePhone'. "= '".$SitePhone."';\r\n";
		$config .= '$SiteFax'. "= '".$SiteFax."';\r\n";
		$config .= '$SiteQq'. "= '".$SiteQq."';\r\n";
		$config .= '$SiteMsn'. "= '".$SiteMsn."';\r\n";
		$config .= '$SiteEmail'. "= '".$SiteEmail."';\r\n";
		$config .= '$SiteAdd'. "= '".$SiteAdd."';\r\n";
		$config .= '$SiteIcp'. "= '".$SiteIcp."';\r\n";
		$config .= '$SystemStatus'. "= '".$SystemStatus."';\r\n";
		$config .= '$SystemStat'. "= '".$SystemStat."';\r\n";
		$config .= '$CopyRight'. "= '".$CopyRight."';\r\n";
		$config .= "?>";fwrite($fp, $config);
		fclose($fp);
		$messageid = 6;
		include template('message.htm');
		exit();
	}
}
elseif($a == 'seccode')
{
	if(empty($_POST['Submit'])) {
		include_once TM_ROOT.'data/seccode.inc.php';
		$tplid = 2;
		include template('config.htm');
		exit;
	}else{
		$login = getgpc('login');
		$reg = getgpc('reg');
		$admin = getgpc('admin');
		$edit = getgpc('edit');
		if(!getgpc('login')== 1) {$login = 0;}
		if(!getgpc('reg')== 1) {$reg = 0;}
		if(!getgpc('admin')== 1) {$admin = 0;}
		if(!getgpc('edit')== 1) {$edit = 0;}
		//note 写入 配置文件 config.inc.php
		$type = getgpc('codetype');$width = getgpc('codewidth');
		$height = getgpc('codeheight');
		$background = getgpc('codebackground');
		$adulterate = getgpc('codeadulterate');
		$ttf = getgpc('codettf');
		$angle = getgpc('codeangle');
		$color = getgpc('codecolor');
		$size = getgpc('codesize');
		$shadow = getgpc('codeshadow');
		$animator = getgpc('codeanimator');
    	$configfile = TM_ROOT.'./data/seccode.inc.php';
    	$fp = fopen($configfile, 'w')or die("写入文件 $configfile 失败!");
   	    $config = "<?php\r\n";
   	    $config .= "//程序验证码设置\r\n";
   	    $config .= '$seccodedata = array('."\r\n";
   	    $config .= "'type' =>"."$type".",\r\n";
   	    $config .= "'width' =>"."$width".",\r\n";
   	    $config .= "'height' =>"."$height".",\r\n";
   	    $config .= "'background' =>"."$background".",\r\n";
   	    $config .= "'adulterate' =>"."$adulterate".",\r\n";
   	    $config .= "'ttf' =>"."$ttf".",\r\n";
   	    $config .= "'angle' =>"."$angle".",\r\n";
   	    $config .= "'color' =>"."$color".",\r\n";
   	    $config .= "'size' =>"."$size".",\r\n";
   	    $config .= "'shadow' =>"."$shadow".",\r\n";
   	    $config .= "'animator' =>"."$animator".",\r\n";
   	    $config .= ");\r\n";
		$config .= "//验证码开关\r\n";
		$config .= '$seccodestatus = array('."\r\n";
		$config .= "'login' =>"."$login".",\r\n";
		$config .= "'register' =>"."$reg".",\r\n";
		$config .= "'admin' =>"."$admin".",\r\n";
		$config .= "'edit' =>"."$edit".",\r\n";
		$config .= ");\r\n";
		$config .= "?>";
		fwrite($fp, $config);fclose($fp);
		$messageid = 6;
		include template('message.htm');
		exit();
	}
}
elseif($a == 'tpl')
{
	if(empty($_POST['Submit'])) {
		include TM_ROOT.'./data/template.inc.php';
		$dir_name = TM_ROOT._TPLPatha_."/";
		$dir = opendir($dir_name);
		$file_list = "<select name=\"view\">";
		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);
		$tplid=3;
		include template('config.htm');
		exit;
	}else{
		$tplpath = getgpc('tplpath');
		$view = getgpc('view');
		$tplcachelimit = getgpc('tplcachelimit');
		//note 写入 UCenter 配置文件 config.inc.php
    	$configfile = TM_ROOT.'./data/template.inc.php';
    	$fp = fopen(TM_ROOT.'./data/template.inc.php', 'w')or die("写入文件 ../data/template.inc.php 失败!");
    	$config = "<?php\r\n";
    	$config .= "define('_TPLPatha_', '$tplpath');//总目录\r\n";
    	$config .= "define('_TPLPathb_', '$view');//模板目录\r\n";
    	$config .= "define('_TPLCacheLimitview_', '$tplcachelimit');//模板缓存有效期\r\n";
		$config .= "?>";
		fwrite($fp, $config);
		fclose($fp);
		$messageid = 6;//未定义错误！
		include template('message.htm');
		exit();
	}
}
?>