<?php

  /**
   * Init
   */
  if (!defined("_VALID_PHP"))
      die('Acesso direto a esta classe não é permitido.');
?>
<?php
	date_default_timezone_set("America/Argentina/Buenos_Aires");
	set_time_limit(0);
	ini_set('memory_limit', -1);
	ini_set('max_execution_time', -1);
	ini_set('fastcgi_read_timeout', -1);

  if (substr(PHP_OS, 0, 3) == "WIN") {
      $BASEPATH = str_replace("init.php", "", realpath(__FILE__));
  } else {
      $BASEPATH = str_replace("init.php", "", realpath(__FILE__));
  }
  define("BASEPATH", $BASEPATH);

  $configFile = BASEPATH . "lib/config.ini.php";
  $cookies = BASEPATH . "cookies/";

  define("COOKIELOCAL", $cookies);

  if (file_exists($configFile)) {
      require_once($configFile);
  } else {
      header("Location: _error/");
  }

  $enotas_apikey = 'MDFiMzJlN2ItMjkwYS00ODcyLTkwOGYtNjVlMTUwYjYwNTAw';
  require_once('enotas/eNotasGW.php');

  require_once(BASEPATH . "lib/class_db.php");

  require_once(BASEPATH . "lib/class_registry.php");
  Registry::set('Database',new Database(DB_SERVER, DB_USER, DB_PASS, DB_DATABASE));
  $db = Registry::get("Database");
  $db->connect();

  //Include Functions
  require_once(BASEPATH . "lib/functions.php");
  require_once(BASEPATH . "lib/functions_receita.php");
  include(BASEPATH . "lib/headerRefresh.php");

  require_once(BASEPATH . "lib/class_filter.php");
  $request = new Filter();

  //Start Core Class
  require_once(BASEPATH . "lib/class_core.php");
  Registry::set('Core',new Core());
  $core = Registry::get("Core");

  //StartUser Class
  require_once(BASEPATH . "lib/class_usuario.php");
  Registry::set('Usuario',new Usuario());
  $usuario = Registry::get("Usuario");
  
  //Load Faturamento
  require_once(BASEPATH . "lib/class_faturamento.php");
  Registry::set('Faturamento',new Faturamento());
  $faturamento = Registry::get("Faturamento");

  //Load Produto
  require_once(BASEPATH . "lib/class_produto.php");
  Registry::set('Produto',new Produto());
  $produto = Registry::get("Produto");

  //Load Cadastro
  require_once(BASEPATH . "lib/class_cadastro.php");
  Registry::set('Cadastro',new Cadastro());
  $cadastro = Registry::get("Cadastro");

  //Load Empresa
  require_once(BASEPATH . "lib/class_empresa.php");
  Registry::set('Empresa',new Empresa());
  $empresa = Registry::get("Empresa");

  //Load Boleto
  require_once(BASEPATH . "lib/class_boleto.php");
  Registry::set('Boleto',new Boleto());
  $boleto = Registry::get("Boleto");

  //Load ORDEM DE SERVICO
  require_once(BASEPATH . "lib/class_pix.php");
  Registry::set('Pix',new Pix());
  $pagamento_pix = Registry::get("Pix");

  define("SITEURL", $core->site_url);
  define("ADMINURL", $core->site_url);
  define("UPLOADS", BASEPATH."uploads/data/");
  define("UPLOADURL", SITEURL."/uploads/");
  define("UPLOADSHTML", "./uploads/data/");
  define("UPLOADNOTAS", BASEPATH."/uploads/enotas/");
  define("UPLOADCERTIFICADO", BASEPATH."/uploads/certificados/");
?>