<?php

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

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

class tj_help extends tj_model {

	var $table = 'dbpre_help';
    var $key = 'id';

	function __construct() {
		parent::__construct();
		$this->C =  G_class('help_cat');      //加载帮助分类基类
		$this->init_field();
	}

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

	function init_field() {
		$this->add_field('title,catid,available,content');
		$this->add_field_fun('catid,available', 'intval');
        $this->add_field_fun('title', '_T');
        $this->add_field_fun('content', '_HTML');
	}

	function read_all($type=null) {
        $this->db->from($this->table);
		
        if(intval($type)>0) {
            $this->db->where('catid', $type);
			$this->db->order_by('dateline','DESC');//必须为大写DESC或ASC
        }else{
			if($type=='new') $this->db->order_by('dateline','DESC');//必须为大写DESC或ASC
			if($type=='hot') $this->db->order_by('pageview','DESC');//必须为大写DESC或ASC
			$this->db->limit(0,20);
			
		}
        return $this->db->fetch_all_assoc();
    }
	
	function read_one($id) {
        $this->db->from($this->table);
        $this->db->where('id', $id);
        return $this->db->once_fetch_assoc();
    }
	
	
	
    function save(& $post, $id=NULL, $cache=TRUE) {
        $this->check_post($post);
		
        if(!$id) {
            $post['dateline'] = $this->global['timestamp'];
        }
        return parent::save($post, $id, $cache, FALSE);
    }

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

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

    function check_post($post,$is_edit=false) {
        if(!$post['title']) Note('标题不能为空！');
        if(!$post['content']) Note('帮助内容不能为空！');
    }
}
?>