<?php

require_once('include/Configuration.php');

require_once('include/RepositoryModel.class.php');
require_once('include/View.class.php');

require_once('include/IOController.interface.php');
class IOController implements iIOController
{
	private $input;
	private $repositoryModel;
	private $view;

	public function __construct()
	{
		ob_clean();
		ob_start();
	}

	public function processRequest($input)
	{
		$this->view = new View();

		if(count($input) == 0)
			echo $this->view->getInputPage();
		else
		{
			$this->input = $input;
			$this->repositoryModel = new RepositoryModel();
			$error = $this->repositoryModel->setLocalData($this->input);
			if($error === true)
			{
				$error = $this->repositoryModel->processData();
				if($error === true)
				{
					echo $this->view->getMapPage($this->repositoryModel->getRange(),
						$this->repositoryModel->getCoordinates(),
						$this->repositoryModel->getPolyLine(),
						$this->repositoryModel->getStatistics(),
						$this->repositoryModel->getMean(),
						$this->repositoryModel->getVariance(),
						$this->repositoryModel->getAddresses(),
						$this->repositoryModel->getRadius(),
						$this->repositoryModel->getTimePeriod(),
						$this->repositoryModel->getDayType(),
						$this->repositoryModel->getWeatherType(),
						$this->repositoryModel->getMinTrafficSeverity());
				}
				else
					echo $this->view->getInputPage($error);
			}
			else
			{
				echo $this->view->getInputPage($error);
			}

		}				
	}

	public function getOutputBuffer()
	{
		return ob_get_clean();
	}
}

?>
