<?php
include 'common.php';
function WalletPendingTxList($user_id){
	$dbhandle = DB_Connect();	
	
	$db_selected = mysqli_select_db($dbhandle, DB_NAME)
	or die("Could not select db");
	
	mysqli_query($dbhandle,"set session character_set_connection=utf8;");
	mysqli_query($dbhandle,"set session character_set_results=utf8;");
	mysqli_query($dbhandle,"set session character_set_client=utf8;");

	$dataArray = array();

	$return = "NOT_EXIST_DATA";
	$error ="No Data";
	$response = array('result'=>$return,'list'=>"", 'error'=>$error);

	//-------------------------------------------------------------------------------------------------------------//
	// wallet_exchange_elt_to_wp_log
	//-------------------------------------------------------------------------------------------------------------//
	
	$stmt = $dbhandle->prepare("SELECT * FROM wallet_exchange_elt_to_wp_log WHERE completed = 0 and user_id=?");
    $stmt->bind_param("s", $user_id);
    $stmt->execute();
    $result = $stmt->get_result();

	$result_count =  $result->num_rows;

	if($result->num_rows > 0) 
	{
		while($row = $result->fetch_assoc()) {
			$dataArray[] = $row['tx_hash'];
		}
		$return = "PENDING_TX_LIST_OK";
		$error ="";
		$response = array('result'=>$return,'list'=>$dataArray, 'error'=>$error);
	}

   

	$stmt->close();

	//-------------------------------------------------------------------------------------------------------------//
	// 
	//-------------------------------------------------------------------------------------------------------------//
	
	$stmt2 = $dbhandle->prepare("SELECT * FROM wallet_exchange_wp_to_elt_log WHERE completed = 0 and user_id=?");
    $stmt2->bind_param("s", $user_id);
    $stmt2->execute();
    $result2 = $stmt2->get_result();
	$result_count2 =  $result2->num_rows;

	if($result2->num_row > 0)
	{
		while($row2 = $result2->fetch_assoc()) {
			$dataArray[] = $row2['tx_hash'];
		}
		$return = "PENDING_TX_LIST_OK";
		$error ="";
		$response = array('result'=>$return,'list'=>$dataArray, 'error'=>$error);
	}
    
	$stmt2->close();
	
	
	mysqli_close($dbhandle);
	 
	$isXmlHttpRequest = (isset($_SERVER['HTTP_X_REQUESTED_WITH'])) ?
	(strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') ? true : false: false;
	($isXmlHttpRequest) ? header('Content-type: application/json') : header('Content-type: text/plain');
	
	echo json_encode($response);
}


//$json = json_decode(file_get_contents('php://input'));
//$id = $json->id;

WalletPendingTxList($_GET['user_id']);

?>