<?php 
/****************************************************************/
/*          e-mo.pl © 2017                                      */
/*          http://www.e-mo.com.pl                              */
/*          e-mail: info@e-mo.pl                                */
/*          produkt: Action2osCommerce                          */
/*          wersja: 1.9.7                                       */
/*          webserwis: oscGold                                  */
/*          sciezka: https://www.e-mo.com.pl/plikit,1918,533545b244d7d.php*/
/*          data: 2017-09-25                                    */
/*          godz: 10:45:42                                      */
/****************************************************************/

class uzytkownicy { 
	public $Conn = 0;
	public $errMsg = '';
	public $errNo= 0;
	public $u_Id=0;
	public $u_User=0;
	public $u_Pwd=0;
	public $u_Imie=0;
	public $u_Nazwisko=0;
	public $u_Telefon=0;
    public $u_gender='';
	public $u_customers_status=1;
	public $u_customers_agreement = 0;
	public $u_customers_polecajacy_id =0;
	public $u_customers_default_address_id=0;
	public $u_customers_info_id=0;
	public $u_customers_info_date_account_created=0;
	
	
	
	public function Dodaj(){
		$zwrot=true;
		$query="Insert customers (customers_gender, customers_firstname, customers_lastname, customers_email_address, customers_telephone, customers_password, customers_status, customers_agreement,	customers_polecajacy_id) values ( :u_gender, :u_Imie, :u_Nazwisko, :u_User, :u_Telefon, :u_Pwd, :u_customers_status, :u_customers_agreement, :u_customers_polecajacy_id)";
		$sth = $this->Conn->prepare($query);

		$sth->bindParam(':u_gender' , $this->u_gender, PDO::PARAM_STR);
		$sth->bindParam(':u_Imie', $this->u_Imie, PDO::PARAM_STR);
		$sth->bindParam(':u_Nazwisko', $this->u_Nazwisko, PDO::PARAM_STR);
		$sth->bindParam(':u_User', $this->u_User, PDO::PARAM_STR);
		$sth->bindParam(':u_Telefon', $this->u_Telefon, PDO::PARAM_INT);
		$sth->bindParam(':u_Pwd', $this->u_Pwd, PDO::PARAM_STR);
		$sth->bindParam(':u_customers_status', $this->u_customers_status, PDO::PARAM_INT);
		$sth->bindParam(':u_customers_agreement', $this->u_customers_agreement, PDO::PARAM_INT);
		$sth->bindParam(':u_customers_polecajacy_id', $this->u_customers_polecajacy_id, PDO::PARAM_STR);
	    //sth->bindParam(':u_Id', $this->u_Id, PDO::PARAM_INT);
		
		$sth->execute();
		$this->u_Id=$this->Conn->lastInsertId();

		if($sth->errorCode() != 0){
			$zwrot=false;
			$this->errMsg = $sth->errorInfo();
			$this->errNo = $sth->errorCode();			
		}

		 return $zwrot;
	 } 
	 public function DodajInfo(){
		$zwrot=true;
		$query="Insert customers_info (customers_info_id, customers_info_date_account_created) VALUES (:u_customers_info_id, :u_customers_info_date_account_created)";
		$sth = $this->Conn->prepare($query);

		$sth->bindParam(':u_customers_info_id' , $this->u_customers_info_id, PDO::PARAM_STR);
		$sth->bindParam(':u_customers_info_date_account_created', $this->u_customers_info_date_account_created, PDO::PARAM_STR);
				
		$sth->execute();
		//print_r($sth->errorInfo());
		if($sth->errorCode() != 0){
			$zwrot=false;
			$this->errMsg = $sth->errorInfo();
			$this->errNo = $sth->errorCode();			
		}

		 return $zwrot;
	 } 
	 public function UpdateAdres($customers_default_address_id)
	{
	    $zwrot=true;
		$query="Update customers SET customers_default_address_id=:customers_default_address_id where customers_id=:u_Id";
		$sth = $this->Conn->prepare($query);
	
		$sth->bindParam(':customers_default_address_id', $customers_default_address_id, PDO::PARAM_INT);		
		$sth->bindParam(':u_Id', $this->u_Id, PDO::PARAM_INT);
		
		$sth->execute();
		
		
		
		if($sth->errorCode() != "0"){
			$zwrot=false;
			$this->errMsg = $sth->errorInfo();
			$this->errNo = $sth->errorCode();
		}

		 return $zwrot;
		
	}
	
	public function ZnajdzId($email){
		$zwrot=0;
		$query="Select customers_id from customers Where customers_email_address=:u_User";

		$sth = $this->Conn->prepare($query);
		$sth->bindParam(':u_User', $email, PDO::PARAM_STR);

		$sth->execute();

		while ($row = $sth->fetch(PDO::FETCH_ASSOC, PDO::FETCH_ORI_NEXT))
		{			
			
			$zwrot=$row['customers_id'];
			$this->u_Id = $zwrot;
		}

		 return $zwrot;
	 } 	 
	 
}
?>
