<?php
/********************************************************************
 *                              dircmslist类
 *                            -------------------
 *   update               : 2010-12-8
 *   copyright            : (C) 2009 DirCMS
 *   email                : uuturn@126.com
 *
 *   $Id: list.class.php,v 1.0.0 2010-4-11 16:24:01 M Exp $
 ********************************************************************/
class dircmslist
{
	public $db;
	public $pages;
	public $number;
	
	function __construct()
	{
		global $db;
		$this->db=$db;
	}
	
	function getlist($table,$where,$orderby,$page=1,$pagesize=15,$totalnumber=0,$align='right')  // 2010-12-8 优化，避免了SELECT COUNT(*)的使用以缓存代替，适合更大数量级的数据
	{
		$where=empty($where)?'':'WHERE '.$where;
		$orderby=empty($orderby)?'':'ORDER BY '.$orderby;
		if(!$totalnumber)
		{
			$number=get_cache_counts("SELECT COUNT(*) AS count FROM `$table` $where"); 
		}
		else
		{
			$number=$totalnumber;
		}
		$pagenum=ceil($number/$pagesize);
		$page=max(1,min(max(intval($page),1),$pagenum));
		$start=($page-1)*$pagesize;
		$limit="LIMIT $start,$pagesize";
		$this->pages=getpages($number,$page,$pagesize,0,$align);
		$array=$this->db->fetch_all("SELECT * FROM `$table` $where $orderby $limit");
		return $array;
	}

	function deleteinfo($table,$id)
	{	
		return $this->db->mysql_delete($table,$id);
	}

	function dosql($sql)
	{
		return $this->db->query($sql,true);
	}
}
?>