<?php

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

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

class tj_folder extends tj_model {

	var $table = 'dbpre_folder';
    var $key = 'fid';

	function __construct() {
		parent::__construct();
		$this->init_field();
	}

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

	function init_field() {
		$this->add_field('fid,name,bid,uid,uptime');
		$this->add_field_fun('fid,bid,uid,uptime', 'intval');
        $this->add_field_fun('name', '_T');
	}

	function read_all($type=null) {
        $this->db->from($this->table);
        if($type) {
			if(strpos($type,'/')){
			$type=explode("/",'1/'.$type);
			}
            $this->db->where('bid', $type);
        }
		$this->db->order_by('uptime','DESC');//必须为大写DESC或ASC
        $this->db->select('fid,name,bid,uid,uptime');
        return $this->db->fetch_all_assoc();
    }
	
	function read_one($fid) {
        $this->db->from($this->table);
        $this->db->where('fid', $fid);
        $this->db->select('fid,name,bid,uid,uptime');
        return $this->db->once_fetch_assoc();
    }
	
	
	
    function save(& $post, $fid=NULL, $cache=TRUE) {
        $this->check_post($post);
		
        if(!$fid) {
			global $_CO;
            $post['uid'] = '';//准许用户下载
            $post['uptime'] = $this->global['timestamp'];
        }
        return parent::save($post, $fid, $cache, FALSE);
    }

    function update($post) {
        if(!is_array($post)) Note('global_op_unselect');
        foreach($post as $fid => $val) {
            $val['uid'] = (int) $val['uid'];
            $this->db->from($this->table);
            $this->db->set($val);
            $this->db->where('fid',$fid);
            $this->db->update();
        }
    }
	
	function delfolder($fid) {
		
        $this->db->where('fid', $fid);
		
		$this->db->from($this->table);

        $this->db->delete();
		
        
    }

    function check_post($post,$is_edit=false) {
        if(!$post['name']) Note('文件名不能为空！');
		if(!$post['bid']) Note('权限设置失败！');
    }
}
?>