<?php 

require_once(CP_ENGINE_DIR . "_functions.php");

$main = new Main;

$action = explode("/", $action);

if(!empty($_SESSION['user_id'])){
	$user = $main->userInfo($_SESSION['user_id']);

	if($action[0] == ""){
		$main->loadModule("index");
	} elseif($action[0] == "project"){
		if($action[1] >= 1){
			if($action[2] == "items"){
				$main->loadModule("project/items", array("id" => $action[1]));
			} elseif($action[2] == "form"){
				$main->loadModule("project/form", array("id" => $action[1]));
			} elseif($action[2] == "setting"){
				$main->loadModule("project/setting", array("id" => $action[1]));
			} else {
				$main->loadModule("project/index", array("id" => $action[1]));
			}
		} elseif($action[1] == "new"){
			$main->loadModule("project/new");
		} elseif($action[1] == "all"){
			$main->loadModule("project/all");
		} else {
			$main->loadModule("index");
		}
	} elseif($action[0] == "support"){
		if($action[1] == "ticket"){
			if($action[2] >= 1){
				$main->loadModule("support/ticket", array("id" => $action[2]));
			} else {
				$main->loadModule("support/index");
			}	
		} elseif($action[1] == "new"){
			$main->loadModule("support/new");
		} elseif($action[1] == "all"){
			$main->loadModule("support/all");
		} else {
			$main->loadModule("support/index");
		}
	} elseif($action[0] == "user"){
		$main->loadModule("user/index");
	} elseif($action[0] == "money"){
		$main->loadModule("user/money");
    } elseif($action[0] == "stats"){
		$main->loadModule("user/stats");		
	} elseif($action[0] == "exit"){
		unset($_SESSION['user_id']);
		header("Location: /");
	}
} else {
	if($action[0] == "registration"){
		$main->loadModule("user/reg");
	} else { 
		$main->loadModule("user/login");
	}
}