<?php

	function loadView($module, $view, $class = null){
		if(is_dir(ROOT_PATH . 'modules/' . $module . '/views/')){

			if(strpos($view, '.php') != false){
				$file_path = ROOT_PATH . 'modules/' . $module . '/views/' . $view;
			}else{
				$file_path = ROOT_PATH . 'modules/' . $module . '/views/' . $view . '.php';
			}

			if(is_file($file_path) && file_exists($file_path)){

				if($class != null){
					if(is_array($class)){
						extract($class);
					}else{
						extract(
							array(
								$view => $class
							)
						);
					}
				}

				require($file_path);
			}

		}
	}

	function loadController($module, $controller){

		if(strpos($controller, '.php') != false){
			$file = ROOT_PATH . 'modules/' . $module . '/controllers/' . $controller;
		}else{
			$file = ROOT_PATH . 'modules/' . $module . '/controllers/' . $controller . '.php';
		}

		if(is_file($file) && file_exists($file)){
			require($file);
		}

	}

	function loadBaseView($view, $class = null){

		if(strpos($view, '.php') != false){
			$file_path = ROOT_PATH . 'base/views/' . $view;
		}else{
			$file_path = ROOT_PATH . 'base/views/' . $view . '.php';
		}

		if(is_file($file_path) && file_exists($file_path)){

			if($class != null){
				if(is_array($class)){
					extract($class);
				}else{
					extract(
						array(
							$view => $class
						)
					);
				}
			}
			require($file_path);
		}
	}

	function loadBaseController($controller){

		if(strpos($controller, '.php') != false){
			$file = ROOT_PATH . 'base/controllers/' . $controller;
		}else{
			$file = ROOT_PATH . 'base/controllers/' . $controller . '.php';
		}

		if(is_file($file) && file_exists($file)){
			require($file);
		}

	}
