<?php

	namespace Mocha\UI\Pages;
	use Mocha\Core\InstanceKey;
	use Mocha\Core\KnownInstanceGuids;
	use Mocha\Core\OmsContext;
	use Mocha\UI\Renderers\HTML\HTMLRenderer;
	use Phast\RenderingEventArgs;
	use Phast\WebPage;

	class RelatedTaskPage extends WebPage
	{

		protected function OnRendering(RenderingEventArgs $re)
		{
			parent::OnRendering($re);

			/**
			 * @var \Mocha\Oms\MySQLDatabaseOms
			 */
			$oms = mocha_get_oms();

			//mocha_init_spot_timer($this->Page);

			$instanceKey = InstanceKey::Parse($this->Page->GetPathVariableValue("instid"));
			$relatedTaskKey = InstanceKey::Parse($this->Page->GetPathVariableValue("reltaskid"));

			$instance = $oms->getInstanceByKey($instanceKey);
			$relatedTaskInstance = $oms->getInstanceByKey($relatedTaskKey);

			$context = new OmsContext();

			$context->setWorkData(KnownInstanceGuids::WorkSet__RelatedInstance, $instance);
			$context->setWorkData($oms->getParentClass($instance), $instance);

			$taskRenderer = new HTMLRenderer($context);
			$taskRenderer->TargetInstance = $instance;
			$taskRenderer->IsPostback = $this->Page->IsPostback;
			if ($this->IsPostback)
			{
				//$taskRenderer->processPostback($defaultTask);
			}
			else
			{
				$taskRenderer->renderTask($relatedTaskInstance, $instance);
			}
			exit();
		}

	}
?>