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

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

    function link(){
        $this->__construct();
    }
    function del($userid){
       $result = $this->db->query("DELETE FROM $this->table WHERE id=$userid");
	if($result){
		return true;
	}
    return false;
    }
    /*
     * 修改用户密码
     */
    function updata($id,$info){
        $result = $this->db->update($this->table, $info, "id='$id'");
		if($result){
			return true;
		}
        return false;
    }
    /**
     * 根据用户ID,获得某个用户的信息
     *
     * @param CHAR $fields
     * @param INT $userid
     * @param BOOL $ismore
     * @return ARRAY
     */
	function get($id, $fields = '*'){
		$userid = intval($id);
		return $this->db->get_one("SELECT $fields FROM $this->table WHERE id='$userid'");
	}
	function gettype($id){
		$id = intval($id);
		$type = $this->db->get_one("SELECT title FROM ".DB_PRE."type WHERE id='$id'");
		return $type['title'];
	}
/**
	 * 查询用户信息
	 *
	 * @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;
	}
}
?>