<?php
require('../../../config/config.inc.php');
require('../../../../init.php');
// SOAP DEFINES URL
if(!defined('_ZUGARA_GET_ACCOUNT_STATUS_'))
	define('_ZUGARA_GET_ACCOUNT_STATUS_', 'http://prestashop.webcamsocialshopper.com/index.php/getAccountStatus');

if (!defined('_ZUGARA_CREATE_GARMENT_URL_'))
	define('_ZUGARA_CREATE_GARMENT_URL_', 'http://prestashop.webcamsocialshopper.com/index.php/createGarment');

if (!defined('_ZUGARA_CREATE_GARMENT_COLOR_URL_'))
	define('_ZUGARA_CREATE_GARMENT_COLOR_URL_', 'http://prestashop.webcamsocialshopper.com/index.php/createGarmentColor');

if (!defined('_ZUGARA_UPDATE_GARMENT_URL_'))
	define('_ZUGARA_UPDATE_GARMENT_URL_', 'http://prestashop.webcamsocialshopper.com/index.php/updateGarment');

if (!defined('_ZUGARA_DELETE_GARMENT_URL_'))
	define('_ZUGARA_DELETE_GARMENT_URL_', 'http://prestashop.webcamsocialshopper.com/index.php/deleteGarment');
	
if (!defined('_ZUGARA_DELETE_GARMENT_COLOR_URL_'))
	define('_ZUGARA_DELETE_GARMENT_COLOR_URL_', 'http://prestashop.webcamsocialshopper.com/index.php/deleteGarmentColor');

function 				hello($string)
{
	/*
			Response: return code values: 
			 0 – success 
			 1 – domain does not match this website
			 2 – deactivation failed, unknown error (Db errors)
		
	if ($q = Db::getInstance()->getValue('SELECT id_module  FROM `'._DB_PREFIX_.'module` WHERE name LIKE \'%webcamsocialshopper%\''))
		{
			if(!Db::getInstance()->ExecuteS('UPDATE `'._DB_PREFIX_.'module` SET `active`= 0  WHERE `id_module` = $q'))
				$code = 2;
		}
			else $code = 2;
		$code = $domaine == $_SERVER['HTTP_HOST'] ? '1' : '0';
    	return $code;*/
		
	return $string.' Deactivate Account avec wsdl';
}

class			WssSc
{
	public		function __construct($domain)
	{
		$this->domain = $domain;
		
	}
	
	// SOAP : Gets the account status
	public 	function	getAccountStatus()
	  { 
		  $client = new soapclient(_ZUGARA_GET_ACCOUNT_STATUS_);
		  $res = array();
		  $res['0'] = $client->getStatus($_SERVER['HTTP_HOST']);
		  $res['1'] = '';
		  return ($res);	
	  }
	
	
	  
	// SOAP : Create a new Garment to Zugara DB
	public function 		createGarment($sku, $name, $skuurl, $ScalingValue = 1.0, $VoValue = 0)
	{
		/* SOAP INSTANCE */	
		$client = new soapclient(_ZUGARA_CREATE_GARMENT_URL_);
		$res = array();
		$data = array(
				'Domain' => $_SERVER['HTTP_HOST'],
				'GarmentName' => $name, //(optional)
				'SKU' => $sku,
				'Colors' => array(
					0 => array(
						'SKUUrl' => $skuurl,
						'ScalingValue' => $ScalingValue, //(optional, default: 1.0)
						'VerticalOffsetValue' => $VoValue //(optional, default: 0)
					),                
				)
			);
		$res['0'] = $client->createGarment($data);
		$res['1'] = '';
		return ($res);
	}
	
	public function			createGarmentColor($sku, $name, $skuurl, $ScalingValue = 1.0, $VoValue = 0)
	{
	$client = new SoapClient(_ZUGARA_CREATE_GARMENT_COLOR_URL_);
	$data = array(
					'Domain' => $_SERVER['HTTP_HOST'],
					'GarmentName' => $name,// (optional)
					'SKU' => $sku,
					'SKUUrl' => $skuurl,
				   'ScalingValue' => $ScalingValue, //(optional, default: 1.0)
				   'VerticalOffsetValue' => $VoValue //(optional, default: 0)          
				);
	$res = $client->createGarmentColor($data);
	 return $res;
	}
	
	public 			function deleteGarmentColor($sku, $skuurl)
	{	  
		 $client = new soapclient(_ZUGARA_DELETE_GARMENT_COLOR_URL_);
		 $data = array(
					  'Domain' => $_SERVER['HTTP_HOST'],
					  'SKU' => $sku,
					  'SKUUrl' => $skuurl, //(optional)
				  );
		 $res = array();
		 $res['0'] = $client->deleteGarmentColor($data);
		 $res['1'] = '';	 
		return ($res);
	}
	
	//SOAP : Update the Garment to Zugara DB
	public 		function updateGarment($sku, $name, $odlurl, $skuurl, $ScalingValue = 1.0, $VoValue = 0)
	{
		$client = new soapclient(_ZUGARA_UPDATE_GARMENT_URL_);
		$res = array();
		$data = array(
            'Domain' => $_SERVER['HTTP_HOST'],
            'GarmentName' => $name,//(optional)
            'SKU' => $sku,
            'Colors' => array(
                0 => array(
		 			'Old_SKUUrl' => $odlurl, //(optional)
                    'SKUUrl' => $skuurl,// (optional)
                    'ScalingValue' => $ScalingValue, //(optional)
                    'VerticalOffsetValue' => $VoValue, //(optional)
                ),                
            )
        );
		$res['0'] = $client->updateGarment($data);
		$res['1'] = '';
		return ($res);
	}
	
	public		function deleteGarment($sku)
	{
		$client = new soapclient(_ZUGARA_DELETE_GARMENT_URL_);
		$res = array();
		$data = array(
			'Domain' => $_SERVER['HTTP_HOST'],
			'SKU' => $sku);
		$res['0'] = $client->deleteGarment($data);
		$res['1'] = '';
		if($res['0'] != 0)
			$res['1'] = 'Delete Garment error.';
		return $res;
	}
	
	public 		function deactivateAccount()
	{
		//$server = new SoapServer("deactivateWSS.wsdl", array('uri' => 'urn://'.$_SERVER['REQUEST_URI'].''));
		//phpinfo();	
		ini_set("soap.wsdl_cache_enabled", "0"); 
		$server = new SoapServer('http://demos.nemesis-tech.com/prestashop/modules/webcamsocialshopper/wss.wsdl',
		array('soap_version' => SOAP_1_2)
		);
  		$server->addFunction("hello"); 
   		$server->handle();
		
	}
	
	
 
	
}



?>