<?php

	error_reporting(E_ALL);
	ini_set("display_errors", 1);
	ini_set("display_startup_errors", 1);
	date_default_timezone_set('America/Sao_Paulo');

	require_once('libs/Session.class.php');

	define('ROOT_PATH', __DIR__ . DIRECTORY_SEPARATOR);

	$session = new Session;

	if($session->get('auth')){

		require_once('addons/PHP-FrontMinify/FrontMinify.class.php');
		require_once('addons/WideImage/WideImage.php');
		require_once('libs/Correios.class.php');
		require_once('libs/Modules.class.php');
		require_once('libs/db.php');
		require_once('libs/DBQuery.class.php');
		require_once('libs/Commons.class.php');
		require_once('libs/Html.class.php');
		require_once('libs/Balloon.class.php');
		require_once('libs/System.class.php');
		require_once('libs/mvc-control.php');

		$frontMinify = new FrontMinify;
		$db = new DBQuery;
		$system = new System;
		$commons = new Commons;

		setlocale(LC_MONETARY, 'pt_BR');


		$frontMinify->addFile(array(
			"css/detail-modal.css",
			"css/form-images.css",
			"css/form-styles.css",
			"css/switch-checkbox.css",
			"css/table.css",
			"css/default.css",
			"css/mobile.css",
			"css/grid.css"
		), "css/admin.min.css");

		$frontMinify->addFile(array(
			"js/detail-modal.js",
			"js/form-images.js",
			"js/switch-checkbox.js",
			"js/engine.js"
		), "js/admin.min.js");

		$frontMinify->execute(FrontMinify::ON);

		if(!isset($_GET['noui'])) {
			loadBaseController('header');
			loadBaseController('menu');
		}

		// Módulo
		$module = isset($_GET['um']) ? $_GET['um'] : 'base';

		// Controller
		$controller = isset($_GET['dois']) ? $_GET['dois'] : 'home';

		if($module == 'base'){
			loadBaseController($controller);
		}else{
			loadController($module, $controller);
		}

		if(!isset($_GET['noui'])) {
			loadBaseView('footer');
		}

	}else{
		header("Location: /sistema/login.php");
	}
