<?php
class TransferReason{

	private $conn;
	private $table_name = "transfer_reason";

	public $id;	
	public $transfer_reason;	
	public $city;

	public function __construct($db){
		$this->conn = $db;
	}

	function create(){
		$query = "INSERT INTO " . $this->table_name . " SET transfer_reason=:transfer_reason";
		$stmt = $this->conn->prepare($query);

		$stmt->bindParam(":transfer_reason", $this->transfer_reason);

		if($stmt->execute()){
			return true;
		}	 
		return false;
	}

	function getAllRows(){
		$condition = "";
		if($this->city){
			$condition .= " where city=:city ";
		}

		$query = "SELECT * FROM " . $this->table_name . $condition . " group by transfer_reason ORDER BY transfer_reason ";
		$stmt = $this->conn->prepare($query);
		if($this->city) $stmt->bindParam(":city", $this->city);
		$stmt->execute();
		return $stmt;
	}
	function exist(){
		$query = "SELECT * FROM " . $this->table_name . " WHERE transfer_reason = ? LIMIT 0,1";
		$stmt = $this->conn->prepare( $query );
		// $this->name=htmlspecialchars(strip_tags($this->name));
	 
		$stmt->bindParam(1, $this->transfer_reason);
		
		$stmt->execute();
		if($stmt->rowCount()>0){
			return true;
		}
		return false;
	}

	function delete(){
		$query = "DELETE FROM " . $this->table_name . " WHERE id = ?";
		$stmt = $this->conn->prepare($query);
		$this->id = htmlspecialchars(strip_tags($this->id));
		$stmt->bindParam(1, $this->id);
		if($stmt->execute()){
			return true;
		}
		return false;
	}
}
?>
