/**
* SUSHI report
*/
function sushiXML()
{
$this->validate();
$plugin =& $this->plugin;
$this->setupTemplate(true);
$templateManager =& TemplateManager::getManager();
$SOAPRequest = file_get_contents('php://input');
// crude handling of namespaces in the input
// FIXME: only the last prefix in the input will be used for each namespace
$soapEnvPrefix = '';
$sushiPrefix = '';
$counterPrefix = '';
$re = '/xmlns:([^=]+)="([^"]+)"/';
preg_match_all($re, $SOAPRequest, $mat, PREG_SET_ORDER);
foreach ($mat as $xmlns) {
$modURI = $xmlns[2];
if (strrpos($modURI, '/') + 1 == strlen($modURI)) {
$modURI = substr($modURI, 0, -1);
}
switch ($modURI) {
case 'http://schemas.xmlsoap.org/soap/envelope':
$soapEnvPrefix = $xmlns[1];
break;
case 'http://www.niso.org/schemas/sushi':
$sushiPrefix = $xmlns[1];
break;
case 'http://www.niso.org/schemas/sushi/counter':
$counterPrefix = $xmlns[1];
break;
}
}
if (strlen($soapEnvPrefix) > 0) {
$soapEnvPrefix .= ':';
}
if (strlen($sushiPrefix) > 0) {
$sushiPrefix .= ':';
}
if (strlen($counterPrefix) > 0) {
$counterPrefix .= ':';
}
$parser = new XMLParser();
$tree = $parser->parseText($SOAPRequest);
$parser->destroy();
// is this necessary?
if (!$tree) {
$templateManager->assign('Faultcode', 'Client');
$templateManager->assign('Faultstring', 'The parser was unable to parse the input.');
header("HTTP/1.0 500 Internal Server Error");
$templateManager->display($plugin->getTemplatePath() . 'soaperror.tpl', 'text/xml');
} else {
$reportRequestNode = $tree->getChildByName($soapEnvPrefix . 'Body')->getChildByName($counterPrefix . 'ReportRequest');
$requestorID = $reportRequestNode->getChildByName($sushiPrefix . 'Requestor')->getChildByName($sushiPrefix . 'ID')->getValue();
$requestorName = $reportRequestNode->getChildByName($sushiPrefix . 'Requestor')->getChildByName($sushiPrefix . 'Name')->getValue();
$requestorEmail = $reportRequestNode->getChildByName($sushiPrefix . 'Requestor')->getChildByName($sushiPrefix . 'Email')->getValue();
$customerReferenceID = $reportRequestNode->getChildByName($sushiPrefix . 'CustomerReference')->getChildByName($sushiPrefix . 'ID')->getValue();
$reportName = $reportRequestNode->getChildByName($sushiPrefix . 'ReportDefinition')->getAttribute('Name');
$reportRelease = $reportRequestNode->getChildByName($sushiPrefix . 'ReportDefinition')->getAttribute('Release');
$usageDateRange = $reportRequestNode->getChildByName($sushiPrefix . 'ReportDefinition')->getChildByName($sushiPrefix . 'Filters')->getChildByName($sushiPrefix . 'UsageDateRange');
$usageDateBegin = $usageDateRange->getChildByName($sushiPrefix . 'Begin')->getValue();
$usageDateEnd = $usageDateRange->getChildByName($sushiPrefix . 'End')->getValue();
CounterHandler::_assignTemplateCounterXML($templateManager, $usageDateBegin, $usageDateEnd);
$templateManager->assign('requestorID', $requestorID);
$templateManager->assign('requestorName', $requestorName);
$templateManager->assign('requestorEmail', $requestorEmail);
$templateManager->assign('customerReferenceID', $customerReferenceID);
$templateManager->assign('reportName', $reportName);
$templateManager->assign('reportRelease', $reportRelease);
$templateManager->assign('usageDateBegin', $usageDateBegin);
$templateManager->assign('usageDateEnd', $usageDateEnd);
$templateManager->assign('templatePath', $plugin->getTemplatePath());
$templateManager->display($plugin->getTemplatePath() . 'sushixml.tpl', 'text/xml');
}
}