<?php

define('IN_PHPQUAN', true);

require_once dirname(__FILE__) . '/include/common.php';

chkadmin('config');

$_REQUEST['act'] = $_REQUEST['act'] ? trim($_REQUEST['act']) : 'list' ;

$u = $_REQUEST['u'] ? trim($_REQUEST['u']) : 'con';

switch($_REQUEST['act'])

{

	case 'list':

		$CFG = '';

		$sql = "select setname,value from {$table}config";

		$res = $db->query($sql);

		while($row=$db->fetchRow($res)) {

			$CFG[$row['setname']] = $row['value'];

		}

		$tpl_dir = tpl_dir();

		include tpl('set_config');

	break;

	case 'set_config':

		if($_POST['token']!=$CFG['crypt']) show('提交错误');

		switch ($u)

		{

		case 'con':

			$_POST['webname']	    = $_POST['webname'] ? trim($_POST['webname']) : '';

			$_POST['weburl']		= trim($_POST['weburl']);

			$_POST['icp']			= trim($_POST['icp']);

			$_POST['tplname']		= trim($_POST['tplname']);

			$_POST['crypt']		    = trim($_POST['crypt']);

			$_POST['post_check']    = intval($_POST['post_check']);

			$_POST['comment_check']    = intval($_POST['comment_check']);

			$_POST['wap']		= intval($_POST['wap']);

			$_POST['description']   = trim($_POST['description']);

			$_POST['keywords']      = trim($_POST['keywords']);

			$_POST['copyright']     = trim($_POST['copyright']);

			$_POST['count']         = trim($_POST['count']);

			$_POST['postfile']      = trim($_POST['postfile']);

			$_POST['closesystem']   = intval($_POST['closesystem']);

			$_POST['close_tips']    = trim($_POST['close_tips']);

			$_POST['com_pagesize'] = intval($_POST['com_pagesize']);

			$_POST['email']	= trim($_POST['email']);

			$_POST['phone']	= trim($_POST['phone']);

			$_POST['close_register']	= intval($_POST['close_register']);

			$_POST['reg_check']	= intval($_POST['reg_check']);

			$_POST['indexpage']	= intval($_POST['indexpage']);

			$_POST['listpage']	= intval($_POST['listpage']);

			$_POST['juanpage']	= intval($_POST['juanpage']);

			$_POST['regip']	= intval($_POST['regip']);

			$_POST['ouath_reg']	= intval($_POST['ouath_reg']);

			if($_POST['weburl']=='') {

				$_POST['weburl'] = get_url();

			}

		break;

		}

		

		unset($_POST['act']);

		unset($_POST['submit']);

		foreach($_POST as $key=>$val) {

			$data = $db->getone("SELECT * FROM {$table}config WHERE setname='$key'");

			if($data) {

				$sql = "UPDATE {$table}config SET value = '$val' WHERE setname = '$key' ";

			} else {

				$sql = "INSERT INTO {$table}config (setname,value) VALUES ('$key','$val') ";

			}

			$res = $db->query($sql);

			$res ? $msg.='' : $msg.='1';

		}

		empty($msg) ? $msg = "修改配制成功": $msg = "修改配制失败";

		admin_log("$msg");

		clear_caches('phpcache');

		$link = "set_config.php?u=".$u;

		show($msg, $link);

	break;

}

//--------function--------

function tpl_dir()

{

	$datadir = opendir(PHPQUAN_ROOT . "templates");

	while($file = readdir($datadir)) {

		if($file!='.' && $file!='..' && $file!="index.htm"){

			$files[] = $file;

		}

	}

	closedir($datadir);

	return $files;

}

?>