<?php
if(!defined('IN_TM')) exit('Access Denied');
class type{
	var $db;
	var $table;
	var $pages;
    var $TM;

    function __construct(){
    	global $db,$TM;
        $this->db = &$db;
        $this->table = DB_PRE.'type';
        $this->TM = $TM;
    }

    function type(){
        $this->__construct();
    }	
	function get_row($where = '1'){
		$WHERE = "where lx =".$where;
		$r = $this->db->get_one("SELECT count(*) as num FROM $this->table $WHERE");
		return $r['num'];
	}
    /*
     * 删除
     */
    function del($id){
       $result = $this->db->query("DELETE FROM $this->table WHERE id=$id");
	if($result){
		return true;
	}
    return false;
    }
    /*
     * 修改
     */
    function updata($id,$title){
        $info =array ();
        $info['title'] = $title;
        $result = $this->db->update($this->table, $info, "id='$id'");
		if($result){
			return true;
		}
        return false;
    }
	function get($id, $fields = '*'){
		$id = intval($id);
		return $this->db->get_one("SELECT $fields FROM $this->table WHERE id='$id'");
	}
/**
	 * 查询用户信息
	 *
	 * @param string $where
	 * @param char $order
	 * @param int $page
	 * @param int $pagesize
	 * @return 所有用户信息
	 */
	function listinfo($where = '', $order = '', $page = 1, $pagesize = 100){
		$limit = $result = '';
		if($where) $where = "$where";
		if($order) $order = " ORDER BY $order";
		$page = max(intval($page), 1);
        $offset = $pagesize*($page-1);
        $limit = " LIMIT $offset, $pagesize";
		$array = array();
		$sql = "SELECT * FROM $this->table $where $order $limit";
		$result = $this->db->query($sql);
		while($r = $this->db->fetch_array($result)){			
			$array[] = $r;
		}
      	$this->db->free_result($result);
		return $array;
	}

    
        /**
	 * 注册方法
	 *
	 * @param ARRAY $info
	 * @param ARRAY $moreinfo
	 * @return INT用户ID
	 */
	function add($info = ARRAY()){
        $this->db->insert($this->table, $info);
        $id = $this->db->insert_id();
		if(!$id){
			unset($info);
			return false;
		}
        return $id;
	}
}
?>