<?php
	require_once dirname(__FILE__)."/dalBase.php";
	class limitDAL extends dalBase{
		public $ID;
		public $UserID;
		public $MenuID;

		public function insertRecord(){
			$sql = "INSERT INTO `limit` (`UserID`,`MenuID`) VALUES (@UserID,@MenuID)";
			$sql = str_replace("@UserID","'".$this->UserID."'",$sql);
			$sql = str_replace("@MenuID","'".$this->MenuID."'",$sql);

			$this->data->executeNonQuery($sql, true);
			$insertID = $this->data->getInsertID();

			if(!$this->data->error){
				return $insertID;
			}else{
				return false;
			}
		}
		//刪除
		public function deleteRecord($userID){
			$sql = "DELETE FROM `limit` WHERE `UserID`='".$userID."'";
			$this->data->executeNonQuery($sql,true);

			if(!$this->data->error){
				return true;
			}else{
				return false;
			}
		}

		//查詢
		public function executeRecordset($filter="", $orderExp="",$start=0,$length=-1){
			$sql = "SELECT a.`ID`,a.`UserID`,b.* FROM `limit` a LEFT JOIN `menu` b ON a.`MenuID`=b.`MenuID`";
			if(trim($filter) != "")
				$sql .= " WHERE ".$filter;
			if(trim($orderExp) != "")
				$sql .= " ORDER BY ".$orderExp;
			else
				$sql .= " ORDER BY a.`ID`";
			return $this->data->executeRecordset($sql,$start,$length);
		}

		//
		public function countRecordset($filter=""){
			$sql = "SELECT COUNT(*) FROM `limit` a LEFT JOIN `menu` b ON a.`MenuID`=b.`MenuID`";
			if(trim($filter) != "")
				$sql .= " WHERE ".$filter;
			return $this->data->executeScalar($sql);
		}
	}
?>