<?php

	namespace Mocha\UI\Pages;
	
	use Phast\RenderingEventArgs;
	use Phast\System;
	use Phast\WebPage;

	class CCXPage extends WebPage
	{
		protected function OnRendering(RenderingEventArgs $re)
		{
			parent::OnRendering($re);
			
			$path = System::GetVirtualPath();
			$tenantName = null;
			if (count($path) >= 3)
			{
				$tenantName = $path[2];
			}
			
			if ($tenantName === null)
			{
				header("HTTP/1.1 404 Not Found");
				header("Content-Type: text/plain");
				echo ("\" Not Available \"");
				die();
			}
			else
			{
				$oms = mocha_get_oms();
				if ($oms != null)
				{
					$ti = $oms->getTenantByName($tenantName);
					if ($ti === null)
					{
						header("HTTP/1.1 404 Not Found");
						header("Content-Type: text/plain");
						echo("The requested resource could not be found.");
						die();
					}
					else
					{
						if (count($path) >= 4)
						{
							if (isset($_GET["wsdl"]))
							{
								header("HTTP/1.1 200 OK");
								header("Content-Type: application/xml");
								echo ("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
								
								$wsdl_name = "Mocha_Reporting";
								?>
<wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
	xmlns:xsd="http://www.w3.org/2001/XMLSchema"
	xmlns:soapbind="http://schemas.xmlsoap.org/wsdl/soap/"
	xmlns:httpbind="http://schemas.xmlsoap.org/wsdl/http/"
	xmlns:mimebind="http://schemas.xmlsoap.org/wsdl/mime/"
	name="<?php echo ($wsdl_name); ?>"
	targetNamespace="urn:com.mochapowered/bsvc/<?php echo($wsdl_name); ?>">
	<wsdl:documentation>
	</wsdl:documentation>
</wsdl:definitions>
								<?php
								die();
							}
							else
							{
								header("HTTP/1.1 404 Not Found");
								header("Content-Type: text/plain");
								echo ("The requested resource could not be found.");
								die();
							}
						}
						else
						{
							header("HTTP/1.1 404 Not Found");
							header("Content-Type: text/plain");
							echo("The requested resource could not be found.");
							die();
						}
					}
				}
			}
			
			$re->Cancel = true;
		}
	}

?>