<?php
/**
 * Copyright (C) LJCMS All rights reserved.
 * <E-Mail：aspcms@qq.com>
 * Url http://www.liangjing.org
 *     http://www.8CMS.com
 * Update 2016.03.19
 */

class systemOModel extends X {

        public function get_user_count(){
	        $sql = "SELECT COUNT(*) FROM ".DB_PREFIXOA."user WHERE is_del='0'";
                $total= parent::$obj->fetch_count($sql);
                return $total;
        }
         public function get_dept_count(){
	        $sql = "SELECT COUNT(*) FROM ".DB_PREFIXOA."dept WHERE is_del='0'";
                $total= parent::$obj->fetch_count($sql);
                return $total;
        }
        public function get_file_count(){
	        $sql = "SELECT COUNT(*) FROM ".DB_PREFIXOA."file";
                $total= parent::$obj->fetch_count($sql);
                return $total;
        }
        public function get_file_spage(){
	        $sql = "SELECT sum(size) FROM ".DB_PREFIXOA."file";
                $size= parent::$obj->fetch_count($sql);
                return $this->sizecount($size);
        }
         public function get_file_size($time,$type){
	        $sql = "SELECT `time`,`data` FROM `oa_system_log` WHERE `type` = '$type' AND `time` > $time ";
                return parent::$obj->getall($sql);
        }      
        public function sizecount($filesize) {
                if($filesize >= 1073741824) {
                 $filesize = round($filesize / 1073741824 * 100) / 100 . ' gb';
                } elseif($filesize >= 1048576) {
                 $filesize = round($filesize / 1048576 * 100) / 100 . ' mb';
                } elseif($filesize >= 1024) {
                 $filesize = round($filesize / 1024 * 100) / 100 . ' kb';
                } else {
                 $filesize = $filesize . ' bytes';
                }
                return $filesize;
       }
       
       public function getconfig($name){
           $sql = "SELECT `code`,`val` FROM ".DB_PREFIXOA."system_config WHERE `data_type` = '$name'";
           return parent::$obj->getall($sql);
       }
       public function getconfiginfo($code){
           $sql = "SELECT * FROM ".DB_PREFIXOA."system_config WHERE `code` = '$code'";
           return parent::$obj->fetch_first($sql);
       }
       
       public function save($arr,$id){        
                $result = parent::$obj->update(DB_PREFIXOA.'system_config', $arr, 'id='.$id.'');
                return $result;
       }
      public function add($array) {
           return parent::$obj->insert(DB_PREFIXOA.'system_config', $array); 
      }
}
?>
