<?php
/**
 * [LJCMS] (C)2012-2099 LJdev,Inc.
 * <E-Mail：aspcms@qq.com>
 * Url http://www.liangjing.org
 *     http://www.8CMS.com
 * Update 2014.04.03
*/

class control extends oabase {
    public function action_run(){
                $model = parent::model('system', 'oa');
                $user_count=$model->get_user_count();
                $dept_count=$model->get_dept_count();
                $file_count=$model->get_file_count();
                $file_spage=$model->get_file_spage();
                $var_array = array(
                    'user_count'=>$user_count,
                    'dept_count'=>$dept_count,
                    'file_count'=>$file_count,
                    'file_spage'=>$file_spage,
                  );
               unset($model);
		TPL::assign($var_array);
//
//		$file_spage = M("File") -> sum('size');
//		$this -> assign('file_spage', $file_spage);
//
//		$where_size['type'] = array('eq', 1);
//		//$where_size['time']=array('gt',time()-2592000);
//		$file_size = M("SystemLog") -> where($where_size) -> getField('time,data');
//
//		$file_size = conv_flot($file_size);
         TPL::display($this->cptpl.'system.tpl');
    }
    
    
    public function action_config(){
        $model = parent::model('system', 'oa');
        $system_data=$model->getconfig("system");
        $data=array();
        foreach($system_data as $val){
            $data[$val['code']]=$val['val'];
        }
         $var_array = array(
                    'system_data'=>$data,
                  );
               unset($model);
		TPL::assign($var_array);
        TPL::display($this->cptpl.'system_config.tpl');
    }
    public function action_save(){
        $data_type = $_POST['data_type'];
        	if ($data_type == 'system') {
			$this -> set_val('system_name', 'system');
			$this -> set_val('system_license', 'system');
			$this -> set_val('upload_file_ext', 'system');
			$this -> set_val('login_verify_code', 'system');
			 XHandle::halt('编辑成功', $this->cpfile.'?c=System&a=config', 0);
			die ; 
		}
    }
    	function set_val($key, $type) {
                $model = parent::model('system', 'oa');
		$data['val'] = $_POST[$key];
		$data['data_type'] = $type;
                $vo=$model->getconfiginfo($key);
		if (!empty($vo)) {
			$id = $vo['id'];
			$list =$model->save($data,$id);
		} else {
                        $list=$model->add($data);
		}

		if ($list !== false) {
			return true;
		} else {
			return false;
		}
	}

    public function action_get_flot_data() {
		$range=$_REQUEST['range'];	
		switch ($range) {
			case 'm':
				$offset=mktime(0, 0 , 0,date("m")-1,date("d"),date("Y"));
				break;

			case 'q':
				$offset=mktime(0, 0 , 0,date("m")-3,date("d"),date("Y"));
				break;
				
			case 'y':
				$offset=mktime(0, 0 , 0,date("m")-112,date("d"),date("Y"));
				break;							
			default:
				
				break;
		}   
                $model = parent::model('system', 'oa');
                $file_size=$model->get_file_size($offset,1);
                 $data=array();
                foreach($file_size as $value){
                     $data[$value['time']]=$value['data'];
                 }
                $data = $this->conv_flot($data);  
                $file_count=$model->get_file_size($offset,2);
                 $data1=array();
                foreach($file_count as $value){
                     $data1[$value['time']]=$value['data'];
                 }
		$data1 = $this->conv_flot($data1);  
		$return['file_size']=$data;
		$return['file_count']=$data1;
		echo json_encode($return);			
	}
        protected function conv_flot($data) {
	$return = '[';
	if (empty($data)) {
		return "[]";
	} else {
		foreach ($data as $key => $val) {
			$return .= "[{$key}000,{$val}],";
		}
	}
	return substr($return, 0, -1) . ']';
}

    
   
    
}
?>
   