<?php
	function object_to_array($data) {
		if (is_array($data) || is_object($data)){
			$result = [];
			foreach ($data as $key => $value)
			{
				$result[$key] = (is_array($data) || is_object($data)) ? object_to_array($value) : $value;
			}
			return $result;
		}
		return $data;
	}
	ini_set("soap.wsdl_cache_enabled", "0"); // wsdl cache 'ini devre disi birak
	$invoice = file_get_contents(''.$weburl.'/ws/?module='.$_GET["ne"].'&itemid='.$_GET["id"].'');
	$Username = v3d($rsi["n1"]);
	$Password = v3d($rsi["n2"]);
	$Eposta = $fmail;
	$client = new SoapClient($rsi["n11"]);
try {
	$Req["USER_NAME"]	=	$Username;
	$Req["PASSWORD"]	=	$Password;
	$RequestHeader["SESSION_ID"] = "-1";
	$Req["REQUEST_HEADER"] = $RequestHeader;
	$Res = $client->Login($Req);
	$Client = new SoapClient($rsi["n11"]);
	$content = file_get_contents(''.$weburl.'/'.$crmpath.'/modules/integration/gib/efatura/xml.php?ne='.$_GET["ne"].'&id='.$_GET["id"].'');
	//Print_r($content);
	//exit();
	$Request = array(
		"REQUEST_HEADER"	=>	array(
			"SESSION_ID"	=>	$Res->SESSION_ID,
			"COMPRESSED"	=>	"N"
		),
			"INVOICE"	=>	array(
				"CONTENT"	=>	$content
		)
	);
	//print_r($Request);
	$sendF = $Client->SendInvoice($Request);
	//print_r($sendF);
} catch (Exception $exc) { // Hata olusursa yakala
  //echo "Son yapilan istek asagidadir<br/><pre>";
  //echo htmlentities($client->__getLastRequest());
  //echo "</pre>";
  //echo "Son yapilan istegin header kismi<br/><pre>";
  //echo htmlentities($client->__getLastRequestHeaders());
  //echo "</pre>";
  //echo "Son yapilan metod cagrisinin yaniti<br/><pre>";
  //echo htmlentities($client->__getLastResponse());
  //echo "</pre>";
  //echo "Son yapilan metod cagrisinin yanitinin header kismi<br/><pre>";
  //echo htmlentities($client->__getLastResponseHeaders());
  //echo "</pre>";
  //echo "Soap Hatasi Olustu: " . $exc->getMessage()."<br>";
  $rinvoice = object_to_array($exc);
}
?>