<?php
/*
session_start();
if($_SESSION['adminkey'] !="security"){
	echo"You must be logged in as an administrator in order to export your menu.";
	exit;
}*/

//open db connection
$host = 'localhost'; 
$username = 'restaura_taste';
//include('../custom/db1.php');
$password = 'Daughters2'; 
//include ('../includes/mysql_connect.php');
$server = $_SERVER['SERVER_NAME'];
$image_path = $server . "/images/menu/";

$params = array();

$query="select linkpos_partner_name, linkpos_partner_pwd, linkpos_company, linkpos_store_name, linkpos_store_pwd from storePrefs";
$rt=mysql_query($query);
while($nt=mysql_fetch_array($rt)){
	$params['companyName'] = $nt[linkpos_company];
	$params['storeName'] = $nt[linkpos_store_name];
	$params['storePassword'] = $nt[linkpos_store_pwd];
	$params['partnerName'] = $nt[linkpos_partner_name];
	$params['partnerPassword'] = $nt[linkpos_partner_pwd];
	//$params['menuKey'] = "1";
	
	if((empty($nt[linkpos_company]))||(empty($nt[linkpos_store_name]))||(empty($nt[linkpos_store_pwd]))||(empty($nt[linkpos_partner_name]))||(empty($nt[linkpos_partner_pwd]))){
		echo $nt[linkpos_company].",". $nt[linkpos_store_name] . ",". $nt[linkpos_store_pwd].",". $nt[linkpos_partner_name].",". $nt[linkpos_partner_pwd];			
		echo"You need to setup your LinkPOS credentials before exporting your menu.";
		exit;
	}

	
}

$queryrk = 'SELECT * from cart WHERE customerID = ' .  $_SESSION['UserKey'];
$rtrk=mysql_query($queryrk);
while($ntrk=mysql_fetch_array($rtrk)){
	$recordkey = $ntrk[recordKey];
	$params['transactionNumber'] = '';
    $params['paymentAmount'] = $_POST["subtotal"];
    $params['tipAmount'] = $_POST['tipamount'];
    $params['cardNumber'] = $_SESSION['cardNumber'];
    $params['cardExpMonth'] = $_SESSION['cardExpMonth'];
    $params['cardExpYear'] = $_SESSION['cardExpYear'];
    $params['cardName'] = $_SESSION['cardholder'];
    $params['cardCVV2'] = $_SESSION['cardSec'];
    $params['zipCode'] = $_SESSION['cardzip'];
    $params['phoneNumber'] = $_POST{'Phone'};
    $params['ipAddress'] = $_SERVER['REMOTE_ADDR'];
	$params['paymentNumber'] = $recordkey;
}
	

//$params= htmlspecialchars($params, ENT_COMPAT,'ISO-8859-1', true);
//$params= htmlentities($params, ENT_COMPAT,'utf-8', true);

//print_r ($params);

//old urls
//$wsdl = "http://olypointofsale.com/POSMenu.asmx?WSDL";
//$wsdl = "http://www.olypointofsale.com/postest/posmenuetta.asmx?WSDL";

$prod_url ="https://olympuspos.net/pos/posmenuetta.asmx?WSDL";
$test_url ="https://olypointofsale.com/postest/posmenuetta.asmx?WSDL";

$wsdl = $test_url;

$client = new soapclient($wsdl, array('trace' => 1));

$result = $client->ProcessPayment($params);
/*
echo "<br><br>Returned from SOAP: ";
print_r($result);
*/

//echo "<br><br>Request:<br>";
$xmlDoc = DOMDocument::loadXML($client->__getLastRequest());
$xmlDoc->formatOutput=true;
print '<pre>' . htmlentities($xmlDoc->saveXML()).'</pre>';

//echo "<br><br>Response:<br>";

$xmlDoc = DOMDocument::loadXML($client->__getLastResponse());
$obj = simplexml_load_string($client->__getLastResponse());
$xmlDoc->formatOutput=true;
print '<pre>' . htmlentities($xmlDoc->saveXML()).'</pre>';
//global $approved;
foreach($obj->children('http://schemas.xmlsoap.org/soap/envelope/')->Body->children('http://olympuspos.net')->ProcessPaymentResponse->ProcessPaymentResult as $reslt)
{
	$success = (string)$reslt->success;
	if($success=='false'){
		$errorMessage =(string)$reslt->errorMessage;
		echo $errorMessage . "\n";
		$approved=0;
	}
	if($success=='true'){
		//if($reslt->paymentResult == 'Approved'){
		if($reslt->paymentResult == 'Approved'){
			echo "<center><font color='red'><br><br><br>Transaction completed successfully.<br>";
			echo "</font></center>";
			//$cc_ref_code = $response['PNREF'];	
			$cc_ref_code = "linkpos";
			$approved = 1;		
		} else{
			echo "<center><font color='red'><br><br><br>Transaction failed. Please confirm that you have your information entered correctly and try again.<br>";
			echo "</font></center>";	
			$approved = 0;	
		}
		//echo "approved = $approved";
	}
}
?>