<?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:24                                      */
/****************************************************************/

class firmy_adresy { 
	public $Conn = 0;
	public $errMsg = '';
	public $errNo= 0;
	public $fa_Id=0;
	public $fa_Ulica=0;
	public $fa_Nazwa=0;
	public $fa_Miasto=0;
	public $fa_Kod=0;	
	public $fa_NIP=0;	
	public $fa_Numer ='';
	public $fa_Lokal ='';
	public $fa_Imie=0;
	public $fa_Nazwisko=0;
	public $fa_customer_id=0;
	public $fa_entry_gender='';
	public $Out = array();
	public $In = array();
	public $fa_countries_id=0;
		
	public function Dodaj(){
		$zwrot=true;
		$query="Insert address_book (customers_id, entry_gender, entry_company, entry_nip, entry_firstname, entry_lastname, entry_street_address, entry_postcode, entry_city, entry_country_id) VALUES (:fa_customer_id, :fa_entry_gender, :fa_Nazwa, :fa_NIP, :fa_Imie, :fa_Nazwisko, :fa_Ulica, :fa_Kod, :fa_Miasto, :fa_countries_id)";
		$sth = $this->Conn->prepare($query);

		
		$sth->bindParam(':fa_customer_id', $this->fa_customer_id, PDO::PARAM_INT);
		$sth->bindParam(':fa_entry_gender', $this->fa_entry_gender, PDO::PARAM_STR);
		$sth->bindParam(':fa_Nazwa', $this->fa_Nazwa, PDO::PARAM_STR);
		$sth->bindParam(':fa_NIP', $this->fa_NIP, PDO::PARAM_STR);
		$sth->bindParam(':fa_Imie', $this->fa_Imie, PDO::PARAM_STR);
		$sth->bindParam(':fa_Nazwisko', $this->fa_Nazwisko, PDO::PARAM_STR);
		$sth->bindParam(':fa_Ulica', $this->fa_Ulica, PDO::PARAM_STR);
		$sth->bindParam(':fa_Kod', $this->fa_Kod, PDO::PARAM_STR);
		$sth->bindParam(':fa_Miasto', $this->fa_Miasto, PDO::PARAM_STR);
		$sth->bindParam(':fa_countries_id', $this->fa_countries_id, PDO::PARAM_INT);
		
		$sth->execute();
		
		
		if($sth->errorCode() != "0"){
			$zwrot=false;
			$this->errMsg = $sth->errorInfo();
			$this->errNo = $sth->errorCode();
		}

		 return $zwrot;
	 }
	public function ZnajdzIdKraju($Iso){
		$zwrot=0;
		$query="SELECT countries_id FROM  `countries` where countries_iso_code_2=:iso";

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

		$sth->execute();

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

		 return $zwrot;
	 } 	 
	 
	
	public function SprawdzFirme($customers_id)
	{
	    $zwrot = false;
		$query='Select customers_firstname, customers_lastname from customers where customers_id=:customers_id';
		$sth = $this->Conn->prepare($query);
		$sth->bindParam(':customers_id', $customers_id, PDO::PARAM_INT);
		$sth->execute();
		$zwrot = 0;		

		while ($row = $sth->fetch(PDO::FETCH_ASSOC, PDO::FETCH_ORI_NEXT))
		{
			$this->fa_Imie= $row['customers_firstname'];
            $this->fa_Nazwisko=$row['customers_lastname'];		
		}
		return $zwrot;
	}
	
	public function GetId(){
		$query='Select address_book_id from  address_book  Where entry_company=:fa_Nazwa';
		$sth = $this->Conn->prepare($query);
		$sth->bindParam(':fa_Nazwa', $this->fa_Nazwa, PDO::PARAM_STR);
		$sth->execute();
		$zwrot = 0;		

		while ($row = $sth->fetch(PDO::FETCH_ASSOC, PDO::FETCH_ORI_NEXT))
		{
			$zwrot=$row['address_book_id'];			
		}
		return $zwrot;
	}
	
}
?>
