<?php

/**
 *      【橙创家校通v4.0】 (C)2010-2012 Tuntron Inc.
 *      
 *    	 http://www.tuntron.com   QQ：1121251729
 *
 *      &系统管理类文件&
 */

if (!defined('IS_RUN')) die('Forbidden');

class tj_system extends tj_model {

    var $table = 'dbpre_system';
	var $key = 'variable';
    function __construct() {
        parent::__construct();
		$this->S =  G_class('setsms');   //加载短信配置类
        $this->init_field();
    }

    function tj_usergroup() {
        $this->__construct();
    }

    function init_field() {
        $this->add_field('SiteName,SiteUrl,cfg_if_site_open,cfg_site_open_reason,name,SiteTel,SiteVerifyCode,SiteBeian,Sitedesc,SafeCode');
		$this->add_field_fun('SiteName,Sitedesc,SafeCode', '_T');
    }
	
	 function read_all($type=null) {
        $this->db->from($this->table);
        $this->db->select('variable,value');
        return $this->db->fetch_all_assoc();
    }


    function update(& $post) {
        if(!is_array($post)) return;
        foreach($post as $key => $val) {
			$p = array('value'=>$val);
            $this->save($p, $key, FALSE);
        }
        $this->write_cache();
    }

    function save($post,$variable=null) {
		
        $variable = parent::save($post,$variable);
        return $variable;
    }

    
    function write_cache() {
		
		$arrsystems = $this->read_all();
		foreach($arrsystems as $item){
				$arrsystem[$item['variable']] = $item['value'];
		}
		writecache('siteinfo.php','dat',$arrsystem);
      
    }

    function check_post(& $post, $edit = FALSE) {
        //if($edit && isset($post['groupname']) && !$post['groupname']) redirect('membercp_usergroup_empty_name');
      //  if(!$edit && !$post['groupname']) redirect('membercp_usergroup_empty_name');
       // if(!$edit && !in_array($post['grouptype'],array('member','special','system'))) redirect('membercp_usergroup_empty_type');
      //  if(!$edit && $post['grouptype']=='member' && !is_numeric($post['point'])) redirect('membercp_usergroup_empty_point');
    }
}
?>