<?php
/**
 *  system.php
 *
 * @copyright			(C) 2005-2010 NewsTeng Inc.
 * @license				This is NOT a freeware, use is subject to license terms
 * @lastmodify			2010-12-16
   $Id: system.php 2 2010-12-16 10:59:13Z xuchao $
 */
defined('IN_XTCMS') or exit('No permission resources.');
base::load_app_class('admin', 'admin', 0);

class system extends admin {

	private $db;
	/**
	 * 析构函数
	 */
	public function __construct() {
		parent::__construct(1);
		$this->db = base::load_model('settings_model');
	}

	/**
	 * 首页
	 */
	public function init() {
		if (isset($_POST['dosubmit'])) {
			$site_name = isset($_POST['site_name']) ? new_stripslashes(trim($_POST['site_name'])) : '';
			$this->db->insert(array('name'=>'site_name', 'data'=>$site_name), 1, 1);
			$index_page_size = isset($_POST['index_page_size']) ? new_stripslashes(trim($_POST['index_page_size'])) : 50;
			$this->db->insert(array('name'=>'index_page_size', 'data'=>$index_page_size), 1, 1);
			$page_size = isset($_POST['page_size']) ? new_stripslashes(trim($_POST['page_size'])) : 20;
			$this->db->insert(array('name'=>'page_size', 'data'=>$page_size), 1, 1);
			$js_size = isset($_POST['js_size']) ? new_stripslashes(trim($_POST['js_size'])) : 20;
			$this->db->insert(array('name'=>'js_size', 'data'=>$js_size), 1, 1);
			$js_content_length = isset($_POST['js_content_length']) ? new_stripslashes(trim($_POST['js_content_length'])) : 20;
			$this->db->insert(array('name'=>'js_content_length', 'data'=>$js_content_length), 1, 1);

			$meta_keyword = isset($_POST['meta_keyword']) ? new_stripslashes(trim($_POST['meta_keyword'])) : '';
			$this->db->insert(array('name'=>'meta_keyword', 'data'=>$meta_keyword), 1, 1);
			$meta_description = isset($_POST['meta_description']) ? new_stripslashes(trim($_POST['meta_description'])) : '';
			$this->db->insert(array('name'=>'meta_description', 'data'=>$meta_description), 1, 1);

			$denystr = isset($_POST['denystr']) ? new_stripslashes(trim($_POST['denystr'])) : '';
			$denystrdata = array2string(explode("\r\n", $denystr));
			$this->db->insert(array('name'=>'denystr', 'data'=>$denystrdata), 1, 1);
			/*写入缓存*/
			setcache('settings', array('site_name'=>$site_name,'index_page_size'=>$index_page_size,'page_size'=>$page_size,'js_size'=>$js_size,'js_content_length'=>$js_content_length,'meta_keyword'=>$meta_keyword,'meta_description'=>$meta_description,'denyestr'=>explode("\r\n", $denystr)));
			showmessage(L('operation_success'), HTTP_REFERER);
		}
		$where = to_sqls(array('site_name','index_page_size','page_size','js_size','js_content_length','meta_keyword','meta_description','denystr'), '', 'name');
		$settingarr = $this->db->listinfo($where);
		foreach ($settingarr as $v) {
			if($v['name'] == 'denystr') {
				$setting[$v['name']] = string2array($v['data']);
			}else{
				$setting[$v['name']] = $v['data'];
			}
		}
		include $this->admin_tpl('system');
	}

}
?>