<?php
/*
* @ServerMon v1.1
* @Developed by Maksa988
* @www.Server-Mon.ru
* @Copyright (C) 2014
*/
 if(!defined('SMON'))
	die('Hacking attempt!');

class Controller extends Load {
	protected $data = array();
	
	public function action($action) {
		if(empty($action)):
			$this->loadController('main', 'index');
		else:
			$path = explode("/", $action);
			if($path[0] == 'admin'){
				if(empty($path[1])){
					$this->loadController($path[0].'/main', $path[2]);
				} else {
					$this->loadController($path[0].'/'.$path[1], $path[2]);
				}			
			} else {
				$this->loadController($path[0], $path[1]);
			}
		endif;
	}
	
	public function loadController($dir, $file) {
		if(empty($file))
			$file = 'index';
		if(is_readable(APPLICATION_DIR . 'controllers/'.$dir.'/'.$file.'.php')) {
			require_once(APPLICATION_DIR . 'controllers/'.$dir.'/'.$file.'.php');
		} else {
			exit('Ошибка: Не удалось загрузить контролер '.$dir.'/'.$file.'!');
		}
	}
	
	public function newController($action){
		if(empty($action)):
			return 'main';
		else:
			$nController = explode("/", $action);
			if($nController[0] == 'admin'){
				if(empty($nController[1])){
					return 'main';
				} else {
					return $nController[1];
				}
			} else {
				return $nController[0];
			}
		endif;
	}
}