<?php
class ConfigModel{
	private $_model;
	public function __construct(){
		$this->_model = ZibanmaModel::get_instance();
	}
	
	/**
	 * 记录设置
	 * @param array $config
	 */
	public function zibanma_set_sys_config($config){
		if($config){
			$config['config_content'] = $this->_model->_common->json_convert(json_encode($config['config_content']));
			$select = $this->_model->_db->query("select * from ".ZIBANMA_DB_PREFIX."site_config where config_id='{$config[config_id]}'; ");
			if($select){
				return $this->_model->_db->execute("update ".ZIBANMA_DB_PREFIX."site_config set config_content='{$config[config_content]}' where config_id='{$config[config_id]}'; ");
			}else{
				return $this->_model->_db->execute("insert into ".ZIBANMA_DB_PREFIX."site_config (config_id, config_content, `describe`) values ('{$config[config_id]}', '{$config[config_content]}', '全局设置'); ");
			}
		}
		return false;
	}
	
	/**
	 * 获取设置
	 */
	public function zibanma_get_sys_config($config_id){
		if($config_id){
			$config = $this->_model->_db->query("select * from [prefix]site_config where config_id='{$config_id}'; ");
			$config[0]->config_content = json_decode($config[0]->config_content);
			return $config[0];
		}
		return null;
	}
}
?>