<?php
/**
 * class result_controller
 *
 * Description for class result_controller
 *
 * @author:
*/
namespace area\presentation\controller;

use core\presentation;
use core\url;

class result_controller extends _controller {
	private $p = null;
	private $urlStep = "";

	public function __construct() {
		global $__routing;

		parent::__construct();
		
		$this->p = new presentation(isset($__routing[1]["id"]) ? $__routing[1]["id"] : "");
		if(!$this->p->exists()) {
			$this->viewError("404");
		}

		$this->urlStep = url::root()."r/{$this->p->presentationId}/{step}";
	}

	public function index_action($vars) {
		$step = isset($vars["step"]) ? (int)$vars["step"] : 1;
		if($step < 1) {
			$step = 1;
		}

		$result = $this->p->result($step-1);
		if($result === false) {
			$this->viewError("404");
		}
		
		$this->setVariable("url_next", str_replace("{step}", $step+1, $this->urlStep));
		return $this->view($result);
	}
}
?>