<?php
//
session_start();

//
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);

//ini_set('soap.wsdl_cache_enabled', '0');
//ini_set('soap.wsdl_cache_ttl', '0');

require_once 'application/config/config.client.php';	// Konfiguration
//require_once 'controllers/mysql.client.php';
//require_once 'controllers/com.client.php';

//
require_once 'controllers/class.db.php' ;				// MySQL-DB
require_once 'controllers/class.selectline.api.php';	// Selectline Rest-API
require_once 'controllers/fima_shop.php';				// Schnittstellen-Erweiterung Import FiMA-Shop

// SOAP-Einstellungen (Zertifikate-Fehler ignorieren, ...)
$context = stream_context_create([
    'ssl' => [
        // set some SSL/TLS specific options
        'verify_peer' => false,
        'verify_peer_name' => false,
        'allow_self_signed' => true
    ]
]);


// 
$ArrParams = array(

	//
	"run_All" => false,			// true = Alle Funktionen ausführen
	'error_log_file' => 'artikel_error.log',
	// SelectLine to Shop
	"run_SelectLine_to_CMS" => array(
		//"kunden" 	=> array( "download" => true, "import" => true ),
		"artikel" 	=> array( "download" => true, "import" => true ),
		//"preise" 	=> array( "download" => true, "import" => true ),
		//"bilder" 	=> array( "download" => true, "import" => true ),
		//"dokumente" => array( "download" => true, "import" => true )
	),

	// Shop to CMS
	"run_CMS_to_SelectLine" => array( 
		//"belege", 
		//"kunden",  			// TODO: in Entwicklung
		//"lieferadressen" 		// TODO: in Entwicklung
	)

);


try {
	// SOAP-Verbindung aufbauen
	$clientSOAP = new SoapClient(
		$SOAPServerURL, 
		array( 
			"trace" => 1,
			'stream_context' => $context
		)
	);
	
	// FiMA-Shop Klasse erstellen
	$fimaShop = new fimaShop(
		$clientSOAP,
		$ArrParams
		//$_GET
	);

} catch (Exception $e) {
	
	echo( '----------------------------------------------------------------------------------------------------------' . PHP_EOL);
	echo( 'Fehler :: Verbindung via SOAP-Schnittstelle fehlgeschlagen!' . PHP_EOL );
	echo( $e->getMessage() . PHP_EOL );
	echo( '----------------------------------------------------------------------------------------------------------' . PHP_EOL);
	die();

}

?>