<?php
require_once TM_ROOT.'include/cache.func.php';
/*
 * 网站配置设置
 * array   $setting:  网站配置数组
 */
function set_config($config){
	if(!is_array($config)) return FALSE;
	$configfile = TM_ROOT.'data/config.inc.php';
	if(!is_writable($configfile)) showmessage('Please chmod ./data/config.inc.php to 0777 !');
	$pattern = $replacement = array();
	foreach($config as $k=>$v){
		$pattern[$k] = "/define\(\s*['\"]".strtoupper($k)."['\"]\s*,\s*([']?)[^']*([']?)\s*\)/is";
                $replacement[$k] = "define('".$k."', \${1}".$v."\${2})";
	}
	$str = file_get_contents($configfile);
	$str = preg_replace($pattern, $replacement, $str);
	return file_put_contents($configfile, $str);
}
/*
 * 网站配置设置
 * string   $tablename:  数据库表名称
 * string   $where:  条件
 * array   $setting:  网站配置数组
 */
function setting_set($where, $setting){
	global $db;
	if(!is_array($setting)) return false;
	$setting = serialize($setting);
	return $db->query("UPDATE `".DB_PRE."settings` SET `setting`='$setting' WHERE `name` = '{$where}'");
}
/*
 * 后台模板
 */
function admin_tpl($tpl){
	$tpl = TM_ROOT.'admin/template/'.$tpl.'.tpl.php';
	return $tpl;
}
/*
 *  检测PHP设置参数
 */
function getcon($varName){
	switch($res = get_cfg_var($varName)){
    	case 0:
      		return NO;
    	break;
    	case 1:
            return YES;
    	break;
    	default:
            return $res;
    	break;
	}
}
?>