<?php
	require_once dirname(__FILE__)."/dalBase.php";
	class htaccessDAL extends dalBase{
		public $ID;
		public $ActionName;
		public $HtmlName;
		public $Visible;
		public $OrderNO;

		public function loadRecord(){
			$sql = "SELECT a.* FROM `htaccess` a WHERE a.`ID`='".$this->ID."'";
			$reader = $this->data->executeReader($sql);

			$this->ID = $reader["ID"];
			$this->ActionName = $reader["ActionName"];
			$this->HtmlName = $reader["HtmlName"];
			$this->Visible = $reader["Visible"];
			$this->OrderNO = $reader["OrderNO"];

			if(!$this->data->error)
				return true;
			return false;
		}
		public function insertRecord(){
			$sql = "INSERT INTO `htaccess` (`ActionName`, `HtmlName`, `Visible`, `OrderNO`)" .
				" VALUES (@ActionName,@HtmlName,@Visible,@OrderNO)";
			$sql = str_replace("@ActionName","'".$this->ActionName."'",$sql);
			$sql = str_replace("@HtmlName","'".$this->HtmlName."'",$sql);
			$sql = str_replace("@Visible","'".$this->Visible."'",$sql);
			$sql = str_replace("@OrderNO","'".$this->OrderNO."'",$sql);

			$this->data->executeNonQuery($sql);
			if(!$this->data->error)
				return $this->data->getInsertID();
			return false;
		}
		public function updateRecord(){
			$sql = "UPDATE `htaccess` SET " .
				"`HtmlName`=@HtmlName" .
				",`Visible`=@Visible" .
				",`OrderNO`=@OrderNO" .
				" WHERE `ID`=@ID";
			$sql = str_replace("@ID","'".$this->ID."'",$sql);
			$sql = str_replace("@HtmlName","'".$this->HtmlName."'",$sql);
			$sql = str_replace("@Visible","'".$this->Visible."'",$sql);
			$sql = str_replace("@OrderNO","'".$this->OrderNO."'",$sql);

			$this->data->executeNonQuery($sql);
			if(!$this->data->error)
				return true;
			return false;
		}
		//查詢
		public function executeRecordset($filter="",$orderExp="",$start=0,$length=-1){
			$sql = "SELECT a.* FROM `htaccess` a";
			if(trim($filter) != "")
				$sql .= " WHERE ".$filter;
			if(trim($orderExp) != "")
				$sql .= " ORDER BY ".$orderExp;
			else
				$sql .= " ORDER BY a.`OrderNO`";

			return $this->data->executeRecordset($sql,$start,$length);
		}
		//查詢計數
		public function countRecordset($filter){
			$sql = "SELECT COUNT(*) FROM `htaccess` a";
			if($filter != "")
				$sql .= " WHERE ".$filter;

			return $this->data->executeScalar($sql);
		}
	}
?>