<?php
//数据库连接类

class ConnDB{
	
	var $dbtype;
	var $host;
    var $user;
    var $pwd;
    var $dbname;
    var $debug;
    var $conn;
    
	//构造方法
    function ConnDB($dbtype,$host,$user,$pwd,$dbname,$debug=false){
		$this->dbtype=$dbtype;
    	$this->host=$host;
		$this->user=$user;
		$this->pwd=$pwd;
		$this->dbname=$dbname;
		$this->debug=$debug;
	}

    //实现数据库的连接并返回连接对象
    function GetConnId(){
    	
    	require("adodb/adodb.inc.php");
    	
    	if($this->dbtype=="mysql" || $this->dbtype=="mssql"){
    	    
    		if($this->dbtype=="mysql")
    		   $this->conn=NewADOConnection("mysql");
    		else 
    	       $this->conn=NewADOConnection("mssql");
    		
    	    $this->conn->Connect($this->host,$this->user,$this->pwd,$this->dbname);
    	
    	}elseif($this->dbtype=="access"){
    	    $this->conn=NewADOConnection("access");
    	    $this->conn->Connect("Driver={Microsoft Access Driver (*.mdb)};Dbq=".$this->dbname.";Uid=".$this->user.";Pwd=".$this->pwd.";");
    	}
    	$this->conn->Execute("set names gb2312");
    	if($this->dbtype=="mysql")
    	    $this->conn->debug=$this->debug;
    	return $this->conn;
     	
    }	
    
    //关闭与数据库的连接
    function CloseConnId(){
    	
    	$this->conn->Disconnect();
    }
    
}

//数据库管理类
class AdminDB{
	
	
	function ExecSQL($sqlstr,$conn){
		
		$sqltype=strtolower(substr(trim($sqlstr),0,6));
		$rs=$conn->Execute($sqlstr);
		if($sqltype=="select"){
			$array=$rs->GetRows();
			if(count($array)==0 || $rs==false)
				return false;
			else
				return $array;
			
		
		}elseif ($sqltype=="update" || $sqltype=="insert" || $sqltype=="delete"){
			
			if($rs)
			    return true;
			else 
			    return false;    
		}
	}
}

//分页类
class SepPage{
	
	var $rs;
	var $pagesize;
	var $nowpage;
	var $array;
	var $conn;
	var $sqlstr;
	
	function ShowDate($sqlstr,$conn,$pagesize,$nowpage){
		
		if(!isset($nowpage) || $nowpage=="")
			$this->nowpage=1;
		else
			$this->nowpage=$nowpage;
			
		$this->pagesize=$pagesize;	
		$this->conn=$conn;
		$this->sqlstr=$sqlstr;
		$this->rs=$this->conn->PageExecute($this->sqlstr,$this->pagesize,$this->nowpage);
		@$this->array=$this->rs->GetRows();
			if(count($this->array)==0 || $this->rs==false)
				return false;
			else
				return $this->array;
			
	}
	
	function ShowPage($contentname,$utits,$anothersearchstr,$class){
		
		$allrs=$this->conn->Execute($this->sqlstr);
		$record=count($allrs->GetRows());	
		$pagecount=ceil($record/$this->pagesize);
		
		
		$str.="共有".$contentname."&nbsp;".$record."&nbsp;".$utits."&nbsp;每页显示&nbsp;".$this->pagesize."&nbsp;".$utits."&nbsp;第&nbsp;".$this->rs->AbsolutePage()."&nbsp;页/共&nbsp;".$pagecount."&nbsp;页";
		
		$str.="&nbsp;&nbsp;&nbsp;&nbsp;";
		
		if(!$this->rs->AtFirstPage())
			$str.="<a href=".$_SERVER['PHP_SELF']."?page=1".$anothersearchstr." class=".$class.">首页</a>";
		else
			$str.="<font color='#555555'>首页</font>";
		
		$str.="&nbsp;";
		
		if(!$this->rs->AtFirstPage())
			$str.="<a href=".$_SERVER['PHP_SELF']."?page=".($this->rs->AbsolutePage()-1).$anothersearchstr." class=".$class.">上一页</a>";
		else
			$str.="<font color='#555555'>上一页</font>";
		
		$str.="&nbsp;";	
				
		if(!$this->rs->AtLastPage())
			$str.="<a href=".$_SERVER['PHP_SELF']."?page=".($this->rs->AbsolutePage()+1).$anothersearchstr." class=".$class.">下一页</a>";
		else
			$str.="<font color='#555555'>下一页</font>";	
		
		$str.="&nbsp;";
			
		
		if(!$this->rs->AtLastPage())
			$str.="<a href=".$_SERVER['PHP_SELF']."?page=".$pagecount.$anothersearchstr." class=".$class.">尾页</a>";
		else
			$str.="<font color='#555555'>尾页</font>";
			
		if(count($this->array)==0 || $this->rs==false)			
			return "";
		else
		    return $str;	
		    		
	}
	
}

//系统常用方法
class UseFun{
	
	function UnHtml($text){
	   $content=(nl2br(htmlspecialchars($text)));
	   $content=str_replace("[strong]","<strong>",$content);
	   $content=str_replace("[/strong]","</strong>",$content);
	   $content=str_replace("[em]","<em>",$content);
	   $content=str_replace("[/em]","</em>",$content);
	   $content=str_replace("[u]","<u>",$content);
	   $content=str_replace("[/u]","</u>",$content);
	
	
	   $content=str_replace("[font color=#FF0000]","<font color=#FF0000>",$content);
	   $content=str_replace("[font color=#00FF00]","<font color=#00FF00>",$content);
	   $content=str_replace("[font color=#0000FF]","<font color=#0000FF>",$content);
	
	   $content=str_replace("[font face=楷体_GB2312]","<font face=楷体_GB2312>",$content);
	   $content=str_replace("[font face=宋体]","<font face=新宋体>",$content);
	   $content=str_replace("[font face=隶书]","<font face=隶书>",$content);
       $content=str_replace("[/font]","</font>",$content);
	   //$content=str_replace(chr(32)," ",$content);
	   $content=str_replace("[font size=1]","<font size=1>",$content);
	   $content=str_replace("[font size=2]","<font size=2>",$content);
	   $content=str_replace("[font size=3]","<font size=3>",$content);
	   $content=str_replace("[font size=4]","<font size=4>",$content);
       $content=str_replace("[font size=5]","<font size=5>",$content);
	   $content=str_replace("[font size=6]","<font size=6>",$content);
	   
	   $content=str_replace("[FIELDSET][LEGEND]","<FIELDSET><LEGEND>",$content);
	   $content=str_replace("[/LEGEND]","</LEGEND>",$content);
	   $content=str_replace("[/FIELDSET]","</FIELDSET>",$content);
	   return $content;
	}
	
}

?>