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

class products_description { 
	public $Conn = 0;
	public $errMsg = '';
	public $errNo= 0;
	public $products_id=0;
	public $language_id=0;
	public $products_name=0;
	public $products_description=0;
	public $products_url=0;
	public $products_viewed=0;
	public $products_short_description='';


	public function Dodaj(){
		$zwrot=true;
		$query="Insert products_description (products_id,language_id, products_name, products_description, products_url, products_viewed, products_short_description) SELECT :products_id,	languages_id, :products_name, :products_description, :products_url, :products_viewed, :products_short_description FROM languages ";
		$sth = $this->Conn->prepare($query);
 
		$sth->bindParam(':products_name', $this->products_name, PDO::PARAM_STR);
		$sth->bindParam(':products_description', $this->products_description, PDO::PARAM_STR);
		$sth->bindParam(':products_url', $this->products_url, PDO::PARAM_STR);
		$sth->bindParam(':products_viewed', $this->products_viewed, PDO::PARAM_INT);
		$sth->bindParam(':products_id', $this->products_id, PDO::PARAM_INT);
		$sth->bindParam(':products_short_description', $this->products_short_description, 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 products_description SET products_name=:products_name, products_description=:products_description, products_url=:products_url, products_short_description=:products_short_description Where products_id=:products_id and language_id=:language_id";
		$sth = $this->Conn->prepare($query);

		$sth->bindParam(':language_id', $this->language_id, PDO::PARAM_INT);
		$sth->bindParam(':products_name', $this->products_name, PDO::PARAM_STR);
		$sth->bindParam(':products_description', $this->products_description, PDO::PARAM_STR);
		$sth->bindParam(':products_url', $this->products_url, PDO::PARAM_STR);
		$sth->bindParam(':products_short_description', $this->products_short_description, PDO::PARAM_STR);
		$sth->bindParam(':products_id', $this->products_id, PDO::PARAM_INT);

		$sth->execute();

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

		 return $zwrot;
	 } 
         public function Zmien2(){
		$zwrot=true;
		$query="Update products_description SET products_name=:products_name Where products_id=:products_id and language_id=:language_id";
		$sth = $this->Conn->prepare($query);

		$sth->bindParam(':language_id', $this->language_id, PDO::PARAM_INT);
		$sth->bindParam(':products_name', $this->products_name, PDO::PARAM_STR);		
		$sth->bindParam(':products_id', $this->products_id, PDO::PARAM_INT);

		$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 products_description Where products_id=:products_id";

		$sth = $this->Conn->prepare($query);
		$sth->bindParam(':products_id', $this->products_id, PDO::PARAM_INT);

		$sth->execute();

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

		 return $zwrot;
	 } 
	public function Lista(){
		$query='Select * from products_description Where products_name=:products_name';
		$sth = $this->Conn->prepare($query);
		$sth->bindParam(':products_name', $this->products_name, PDO::PARAM_STR);
		$sth->execute();
		$tablica = array();
		$x=0;

		while ($row = $sth->fetch(PDO::FETCH_ASSOC, PDO::FETCH_ORI_NEXT))
		{
			foreach ($row as $k => $v)
			{
				$tablica[$x][$k]=trim($v);
			}
			$x++;
		}

		return $tablica;
	}
	
	public function Szukaj(){
		$query='Select Count(*) as Ile from products_description Where products_id=:products_id and language_id=:language_id';
		$sth = $this->Conn->prepare($query);
		$sth->bindParam(':products_id', $this->products_id, PDO::PARAM_INT);
		$sth->bindParam(':language_id', $this->language_id, PDO::PARAM_INT);
		$sth->execute();
		$zwrot=0;

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

		return $zwrot;
	}

}
?>
