<?php
class Users{
	public $tbName;
	public $userId;
	
	public function __construct($tbName, $userId){
		require_once("connectdb.php");
		$con = new DbConnect;
		$this->con = $con->connect();
		
		$this->tbName = $tbName;
		$this->userId = $userId;
		
	}
	
	public function getFirstName(){
		$sql = mysqli_query($this->con, "SELECT * FROM $this->tbName WHERE account_id = $this->userId ");
		$row = mysqli_fetch_array($sql);  
		$firstname = $row['first_name']; 
		
		return $firstname;
	}
	
	public function getPassword(){
		$sql = mysqli_query($this->con, "SELECT * FROM $this->tbName WHERE account_id = $user_id ");
		$row = mysqli_fetch_array($sql);
		$password = $row['password'];
		return $password;
	}
	
	public function getLastName(){
		$sql = mysqli_query($this->con, "SELECT * FROM $this->tbName WHERE account_id = $this->userId ");
		$row = mysqli_fetch_array($sql);
		$lastname = $row['lastname'];
		return $lastname;
	}
	
	public function getUserEmail(){
		$sql = mysqli_query($this->con, "SELECT * FROM $this->tbName WHERE account_id = $this->userId ");
		$row = mysqli_fetch_array($sql);
		$email = $row['email'];
		return $email;
	}
	
	public function isRegisteredEmail($email){
		$sql = mysqli_query($this->con, "SELECT * FROM $this->tbName WHERE email = '$email' ");
		$count = mysqli_num_rows($sql);
		if($count == 1){
			return true;
		}else{
			return false;
		}
	}
	
	public function getShippingAddress(){
		$sql = mysqli_query($this->con, "SELECT * FROM $this->tbName WHERE account_id = '$this->userId' ");
		$row = mysqli_fetch_array($sql);
		$c_address = $row['c_address'];
		return $c_address;
	}
	
	public function getUserIdByEmail($email){
		$sql = mysqli_query($this->con, "SELECT * FROM $this->tbName WHERE email = '$email' ");
		$row = mysqli_fetch_array($sql);
		$user_id = $row['account_id'];
		return $user_id;
	}
	
	public function getFirstNameByEmail($email){
		$sql = mysqli_query($this->con, "SELECT * FROM $this->tbName WHERE email = '$email' ");
		$row = mysqli_fetch_array($sql);
		$first_name = $row['first_name'];
		return $first_name;
	}
	
	
	public function getUserPhone(){
		$sql = mysqli_query($this->con, "SELECT * FROM $this->tbName WHERE account_id = $this->userId ");
		$row = mysqli_fetch_array($sql);
		$phone = $row['phone'];
		return $phone;
	}
	
	public function updateUserPassword($pass){
		$password = hash('sha256', $pass);
		$sql = mysqli_query($this->con, "UPDATE $this->tbName SET password = '$password' WHERE account_id = $this->userId ");

		return $sql;
	}
	
}




?>