<?php
/*
* This example demonstrates usage of the "list" function exposed by any
* Adabas SOA Gateway "WebService" from PHP, retrieving selected records
* from the Adabas demo file "Employees", and formatting it, in 4 easy steps.
*/
/*
* Step 1: Instantiate the PHP "SoapClient" class
*/
try {
$soapclient = new SoapClient("http://localhost:8022/adabas_EmployeesMini?WSDL");
} catch (SoapFault $soapfault) {
echo "<pre>";
print_r($soapfault);
echo "</pre>";
return;
}
/*
* Step 2: Build the key ("descriptor") array, due to parser requirements ALL
* key elements need to be specified, but elements may be left empty
* when unused.
*/
$listkey = array(
'personnel_id' => '50005*',
'first_name' => '',
'name' => '',
'city' => '');
/*
* Step 3: Execute the "list" request, passing the key array as the only parameter,
* the response object will consist of an "adabasEmployees" element containing
* an array of "adabasEmployee" elements.
*/
try {
$listresponse = $soapclient->list($listkey);
} catch (SoapFault $soapfault) {
echo "<pre>";
print_r($soapfault);
echo "</pre>";
return;
}
echo "List of Employees by personnel id - Ascending<br><br>";
formatResponse($listresponse);
/*
* Step 4: Build the SOAP Header structure to trigger a DESCENDING
* read instead of an ascending one.
*/
$headers = array(
'SOAGateway_Internal_Adabas_Read_Direction' => "Descending"
);
$header = new SoapHeader("http://www.risaris.com/namespaces/xmiddle",
"adabasEmployeeHeader",
$headers, false);
$soapclient->__setSoapHeaders(array($header));
/*
* Step 5: Execute the "list" request, passing the key array as the only parameter,
* the response object will consist of an "adabasEmployees" element containing
* an array of "adabasEmployee" elements.
*/
try {
$listresponse = $soapclient->list($listkey);
} catch (SoapFault $soapfault) {
echo "<pre>";
print_r($soapfault);
echo "</pre>";
return;
}
echo "<br><hr><br>List of Employees by personnel id - Descending<br><br>";
formatResponse($listresponse);
/*
* Sub: Format the Employee records nicely into a HTML table.
*/
function formatResponse($listresponse){
echo "<table border=1 cellpadding=5>";
echo "<tr><th>Personnel Id</th><th>Name</th><th>First Name</th><th>City</th><th width=200>Address Line</td>";
/*
* Loop through all "adabasEmployee" elements, creating a table row for every single one
*/
if ( isset($listresponse->adabasEmployees->adabasEmployee) )
{
$Employees = $listresponse->adabasEmployees->adabasEmployee;
if (!is_array($Employees))
$Employees = $listresponse->adabasEmployees;
foreach ($Employees as $Employee) {
echo "<tr><td>$Employee->personnel_id</td><td>$Employee->name</td><td>$Employee->first_name</td><td>$Employee->city</td><td>";
echo "<table>";
if (!is_array($Employee->address_line)) {
echo "<tr><td width=200>$Employee->address_line</td></tr>";
} else {
foreach ($Employee->address_line as $addr) {
echo "<tr><td width=200>$addr</td></tr>";
}
}
echo "</table>";
echo "</td></tr>";
}
}
echo "</table>";
}
/*
* Proceed to ex03_SoaGatewayEmpAdd.php - Add a new employee record
*/
?>