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



class sl_cechy { 

	public $Conn = 0;
	public $errMsg = '';
	public $errNo= 0;
	public $c_Id=0;
	public $c_Nazwa='';
	public $Jezyk = 0;

	public function Dodaj(){

		$zwrot=true;

		$query="Insert INTO products_options_values (products_options_values_id, language_id, products_options_values_name) VALUES (:c_Id, :Jezyk, :c_Nazwa) ";

		$sth = $this->Conn->prepare($query);
		$this->c_Id = $this->GetId();

		$sth->bindParam(':c_Id', $this->c_Id, PDO::PARAM_INT);
		$sth->bindParam(':c_Nazwa', $this->c_Nazwa, PDO::PARAM_STR);
		$sth->bindParam(':Jezyk', $this->Jezyk, PDO::PARAM_INT);
		$sth->execute();

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



		 return $zwrot;

	 } 
	public function GetId(){
		$query='SELECT case when MAX(products_options_values_id) is not null then MAX(products_options_values_id)+1 else 1 end as Max FROM products_options_values';
		$sth = $this->Conn->prepare($query);
		$sth->execute();
		$zwrot=0;

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

		return $zwrot;
	}
	public function Zmien(){

		$zwrot=true;

		$query="Update products_options_values SET products_options_values_name=:c_Nazwa Where products_options_values_id=:c_Id";
		$sth = $this->Conn->prepare($query);


		$sth->bindParam(':c_Nazwa', $this->c_Nazwa, PDO::PARAM_STR);
		$sth->bindParam(':c_Id', $this->c_Id, PDO::PARAM_INT);
		$sth->bindParam(':c_Opis', $this->c_Opis, PDO::PARAM_STR);
		$sth->bindParam(':c_Typ', $this->c_Typ, 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_options_values Where products_options_values_id=:c_Id";



		$sth = $this->Conn->prepare($query);

		$sth->bindParam(':c_Id', $this->c_Id, PDO::PARAM_INT);



		$sth->execute();



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

			$zwrot=false;

			$this->errMsg = $sth->errorInfo();

			$this->errNo = $sth->errorCode();

		}



		 return $zwrot;

	 } 
	

	public function ListaXML(){

		

		$query2='SELECT  products_options_id as id, products_options_name as nazwa from products_options';

		$sth2 = $this->Conn->prepare($query2);

		$sth2->execute();

		$zwrot = '<cechy>';



		while ($row2 = $sth2->fetch(PDO::FETCH_ASSOC, PDO::FETCH_ORI_NEXT))

		{

			$zwrot .='<cecha ';

				

				foreach ($row2 as $k => $v)

				{

					$zwrot .=$k.'="'.trim($v).'" ';

				}

			

			$zwrot .='>';



			$query='SELECT b.products_options_values_id as id, b.products_options_values_name as nazwa FROM `products_options_values_to_products_options` a 	Inner JOIN  products_options_values b on (b.products_options_values_id=a.products_options_values_id)	WHERE a.`products_options_id`=:typ';

			$sth = $this->Conn->prepare($query);

			$sth->bindParam(':typ', $row2['id'], PDO::PARAM_INT);

			$sth->execute();

			$zwrot .= '<wartosci>';

			$x=0;



			while ($row = $sth->fetch(PDO::FETCH_ASSOC, PDO::FETCH_ORI_NEXT))

			{

				$zwrot .='<wartosc ';

				

				foreach ($row as $k => $v)

				{

					$zwrot .=$k.'="'.trim($v).'" ';

				}

				

				$zwrot .='/>';



			}

			

			$zwrot .= '</wartosci>';

			$zwrot .='</cecha>';



		}



		$zwrot .= '</cechy>';



		return $zwrot;

	}
	

	public function Sprawdz2(){

		$query='Select products_options_values_id as c_Id from products_options_values Where language_id=:Jezyk and products_options_values_name=:Nazwa';

		$sth = $this->Conn->prepare($query);
		$sth->bindParam(':Nazwa', $this->c_Nazwa, PDO::PARAM_STR);
		$sth->bindParam(':Jezyk', $this->Jezyk, PDO::PARAM_INT);
		$sth->execute();

		$zwrot=0;				

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

		return $zwrot;

	}

	

	

}

?>
