<?php 
// FMPro XML-RPC Client
// (c) 2001, Bill Humphries

include("../xmlrpc/xmlrpc.inc");

global $SERVER,$PATH,$PORT;
$SERVER	= "localhost";
$PATH	= "/FMPro/FMProServer.php";
$PORT	= 80;

function getAllRecords($dbName)
{
	$client = new xmlrpc_client("/FMPro/FMProServer.php","localhost",80);
	$client->setDebug(1);
	
	$msg = new xmlrpcmsg("FMPro.allRecords");
	$msg->addParam(new xmlrpcval($dbName, $xmlrpcString));

	// Dump the wire message sent
	print "<p>Sending message:</p>";
	print "<pre>". htmlentities($msg->serialize()) . "</pre>";
	
	$result = $client->send($msg,30);
	
	if ($result)
	{
		print "<p>Got a response.</p>";
		if ($result->value())
		{
			print "<p>Got a valid response.</p>";
			// The result is a Base64 encoded string
			$encodedResult = xmlrpc_decode($result->value(),$xmlrpcString);
			$decodedResult = base64_decode($encodedResult);
			// Dump the response sent
			print "<p>Got response:</p>";
			print "<pre>" . htmlentities($decodedResult) . "</pre>";
			return $decodedResult;
		}
		else
		{
			print "<p>A fault occured.</p>";
			print "<p>".
					$base64Result->faultCode().
					", explaination: ".
					$base64Result->faultString().
					"</p>";
		}
		
	}
	else
	{
		print "<p>A Low Level Error Occured.</p>";
		print "<p>Error # " . $client->errno . ": ".
				$client->errstr . "</p>";
		exit(0);
	}
}

// Test the server

//print "<html><head><title>Test XML-RPC</title></head><body>";
//$db = "phonelist.fp5";
//print "<p>Trying to get $db.</p>";
//$xml = getAllRecords($db);
//print "<p>Final response is:</p>";
//print "<pre>" . htmlentities($xml) . "</pre>";
//print "</body></html>";
?>