<?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 gradacja { 

	public $Conn = 0;
	public $errMsg = '';
	public $errNo= 0;
	public $id_discount_type = 2;
	public $id_product = 0;	
	public $id_product_attribute = 0;
	public $quantity = 0;
	public $value=0;
	public $id_discount_quantity=0;
	public $prefiks = 'ps_';
	public $color=0;
	public $sk = '';

	public function Dodaj()
	{
		$zwrot=true;
		$query="Insert INTO ".$this->prefiks."discount_quantity (id_discount_type,	id_product,	id_product_attribute,	quantity,	value, sk) VALUES (:id_discount_type,	:id_product,	:id_product_attribute,	:quantity,	:value, :sk) ";

		$sth = $this->Conn->prepare($query);
		$sth->bindParam(':id_discount_type', $this->id_discount_type, PDO::PARAM_INT);
		$sth->bindParam(':id_product', $this->id_product, PDO::PARAM_INT);
		$sth->bindParam(':id_product_attribute', $this->id_product_attribute, PDO::PARAM_INT);
		$sth->bindParam(':quantity', $this->quantity, PDO::PARAM_INT);
		$sth->bindParam(':value', $this->value, PDO::PARAM_STR);
		$sth->bindParam(':sk', $this->sk, PDO::PARAM_STR);
		$sth->execute();
		

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

	 } 
	 public function Zmien()
	{
		$zwrot=true;
		$query="Update ".$this->prefiks."discount_quantity set id_discount_type=:id_discount_type,	id_product=:id_product,	id_product_attribute=:id_product_attribute,	quantity=:quantity,	value=:value, sk=:sk Where id_discount_quantity=:id_discount_quantity";

		$sth = $this->Conn->prepare($query);
		$sth->bindParam(':id_discount_type', $this->id_discount_type, PDO::PARAM_INT);
		$sth->bindParam(':id_product', $this->id_product, PDO::PARAM_INT);
		$sth->bindParam(':id_product_attribute', $this->id_product_attribute, PDO::PARAM_INT);
		$sth->bindParam(':quantity', $this->quantity, PDO::PARAM_INT);
		$sth->bindParam(':value', $this->value, PDO::PARAM_STR);
		$sth->bindParam(':id_discount_quantity', $this->id_discount_quantity, PDO::PARAM_INT);
		$sth->bindParam(':sk', $this->sk, PDO::PARAM_STR);
		$sth->execute();		

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

	public function Usun(){

		$zwrot=true;
		$query="Delete from ".$this->prefiks."discount_quantity Where sk<>:sk";
		$sth = $this->Conn->prepare($query);
		$sth->bindParam(':sk', $this->sk, PDO::PARAM_STR);
		$sth->execute();

		if($sth->errorCode() != 0){

			$zwrot=false;
			$this->errMsg = $sth->errorInfo();
			$this->errNo = $sth->errorCode();
		}
		return $zwrot;

	 } 	

	public function Sprawdz()
	{
		$query='Select id_discount_quantity as id from '.$this->prefiks.'discount_quantity Where id_discount_type=:id_discount_type and id_product=:id_product and quantity=:quantity';

		$sth = $this->Conn->prepare($query);
		$sth->bindParam(':id_discount_type', $this->id_discount_type, PDO::PARAM_INT);
		$sth->bindParam(':id_product', $this->id_product, PDO::PARAM_INT);
		//$sth->bindParam(':id_product_attribute', $this->id_product_attribute, PDO::PARAM_INT);
		$sth->bindParam(':quantity', $this->quantity, PDO::PARAM_INT);
		$sth->execute();

		$zwrot=0;				

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

		return $zwrot;

	}

	

	

}

?>
