<?php
ini_set('default_charset', 'UTF-8');
date_default_timezone_set("America/Caracas");
/* if (preg_match( "/app_config.php/", $_SERVER ["PHP_SELF"] ) || preg_match( "/app_config.php/", $HTTP_SERVER_VARS ["PHP_SELF"] ))
  die("Access denied!"); */
$ini_request = microtime(true);
//Directorios
//
$mssql_host = "192.168.4.124\SRVVIR03";
//$mssql_host = "192.168.4.102\SRVDYP01";
//$mssql_host = "192.168.4.121\SRVMDGP";
$mssql_database = "EFCCA";
$mssql_database_maquila = "EFCM2";
$mssql_user = "sa";
$mssql_password = "Mbsgp2016";
//developme
$mssql_host_dev = "192.168.4.124\SRVVIR03";
$mssql_database_dev = "TEST";
$mssql_user_dev = "sa";
$mssql_password_dev = "Mbsgp2016";
//$mssql_host = "SERVER-PC";
//$mssql_database = "TPC_A";
//$mssql_user = "profit";
//$mssql_password = "profit";
$mysql_host = "127.0.0.1";
//$mysql_host = "192.168.1.120";
$mysql_user = "root";
//$mysql_user = "tpch";
$mysql_password = "manager";
$mysql_database = "imputec_friocarnesexpress";
/*$mysql_pshop_host = "service.us-02.live-paas.net";
$mysql_pshop_user = "user756";
$mysql_pshop_password = "kp6SoKThhKvv8ESE";
$mysql_pshop_database = "fcxp_presta";*/
$mysql_pshop_database = "fcexpress2020";
$mysql_pshop_host = "127.0.0.1";
$mysql_pshop_user = "root";
$mysql_pshop_password = "manager";
//$mysql_pshop_database = "imputec_tupanacharcutero";
//
define("APPROOT", $_SERVER ['DOCUMENT_ROOT']."/");
define("INTROOT", $_SERVER ['DOCUMENT_ROOT']."/ventas/");														 
//define("PSHOP_TABLE_PREFIX", "pshm");
define("PSHOP_TABLE_PREFIX", "pshm");
define("MSSQL_BBDD", $mssql_database);
define("PROFIT_DEFAULT_ALM", "ALM-DES");
define("PROFIT_DEFAULT_VEND", "01");
define("PROFIT_DEFAULT_TYPE_CLIENT", "01");
define("PROFIT_DEFAULT_EGRE_COUNT", "001");
define("PROFIT_DEFAULT_PRICE", "01");
define("COREROOT", $_SERVER ['DOCUMENT_ROOT']."/");
define("INTROOT", $_SERVER ['DOCUMENT_ROOT']."/ventas/");
define("DOMAIN_ROOT", "http://" . $_SERVER ['SERVER_NAME'] .'/');
define("DOMAIN_INT_ROOT", "http://" . $_SERVER ['SERVER_NAME'] .'/ventas/');
define("DOMAIN_HOME", "http://" . $_SERVER ['SERVER_NAME'] .'/app/dashboard.php');
define("DOMAIN_APP_ROOT", "http://" . $_SERVER ['SERVER_NAME'] .'/app/');
define("DOMAIN_INT_ROOT", "http://" . $_SERVER ['SERVER_NAME'] .'/ventas/');
define("COOKIE_USERFULLNAME", "tpc_user_fullname");
define("COOKIE_USERLOGINNAME", "tpc_user_loginname");
define("COOKIE_USERAVATAR", "tpc_user_avatar");
define("COOKIE_USERROL", "tpc_user_rol");
define("COOKIE_USERROLID", "tpc_user_rol_id");
define('PS_SHOP_PATH', 'http://192.168.4.106/fcexpress/');  // Root path of your PrestaShop store
define('PS_SHOP_PATH_1', 'http://192.168.4.106/fcexpress/');  // Root path of your PrestaShop store
//define('PS_SHOP_PATH', 'http://localhost:8081/projects/prestashop_1-7');  // Root path of your PrestaShop store
//define('PS_SHOP_PATH', 'http://tpch.imputec.com/');  // Root path of your PrestaShop store
define('PS_WS_AUTH_KEY', 'NJSSIJX34WKRQFAX2HM4ADVFPLB96WD3'); // Auth key (Get it in your Back Office)
$arrDB = array("_MSSQL" => array("host" => $mssql_host, "user" => $mssql_user, "pass" => $mssql_password, "db" => $mssql_database),
"_MSSQLDEV" => array("host" => $mssql_host_dev, "user" => $mssql_user_dev, "pass" => $mssql_password_dev, "db" => $mssql_database_dev),
"_MYSQL_SHOP" => array("host" => $mysql_pshop_host, "user" => $mysql_pshop_user, "pass" => $mysql_pshop_password, "db" => $mysql_pshop_database.'?charset=utf8'),
    "_MYSQL" => array("host" => $mysql_host, "user" => $mysql_user, "pass" => $mysql_password, "db" => $mysql_database.'?charset=utf8'));
//require_once(APPROOT."lib/class/debug.class.php");
require_once(APPROOT . "lib/class/externals/cake/inflector.php");
require(APPROOT . "lib/class/session_manager.class.php");
ini_set("session.cookie_lifetime", "20000");
ini_set("session.gc_maxlifetime", "20000");
session_start();
require(APPROOT . "lib/class/autoloader.class.php");

require_once APPROOT . '/lib/orm/php-activerecord/ActiveRecord.php';

$connections = array('development' => 'mysql://' . $arrDB['_MYSQL']['user'] . ':' . $arrDB['_MYSQL']['pass'] . '@' . $arrDB['_MYSQL']['host'] . '/' . $arrDB['_MYSQL']['db'],
    'mssql' => 'Sqlsrv://' . $arrDB['_MSSQL']['user'] . ':' . $arrDB['_MSSQL']['pass'] . '@' . $arrDB['_MSSQL']['host'] . '/' . $arrDB['_MSSQL']['db'],
	'mssql_maquila' => 'Sqlsrv://' . $arrDB['_MSSQL']['user'] . ':' . $arrDB['_MSSQL']['pass'] . '@' . $arrDB['_MSSQL']['host'] . '/' . $mssql_database_maquila,
	'mssqldev' => 'Sqlsrv://' . $arrDB['_MSSQLDEV']['user'] . ':' . $arrDB['_MSSQLDEV']['pass'] . '@' . $arrDB['_MSSQLDEV']['host'] . '/' . $arrDB['_MSSQLDEV']['db'],
    'mysql_shop' => 'mysql://' . $arrDB['_MYSQL_SHOP']['user'] . ':' . $arrDB['_MYSQL_SHOP']['pass'] . '@' . $arrDB['_MYSQL_SHOP']['host'] . '/' . $arrDB['_MYSQL_SHOP']['db']
	);

//ActiveRecord\Config::initialize(function($cfg) {
//    global $arrCon;
//    $cfg->set_model_directory(APPROOT . 'lib/models');
//    $cfg->set_connections($arrCon);
//});
# must issue a "use" statement in your closure if passing variables
 ActiveRecord\Config::initialize(function($cfg) use ($connections)
 {
   $cfg->set_model_directory(APPROOT . 'lib/models');
   $cfg->set_connections($connections);
 });

Autoloader::Register();
$CORE_session = new SessionManager('FCX');
$CORE_general = new General();
Parameter::load_parameters();
$_varURL = explode('/', $_SERVER['SCRIPT_NAME'])[count(explode('/', $_SERVER['SCRIPT_NAME'])) - 1];
 if (file_exists(APPROOT.'lib/common/check_login.php')){
 $objaccess = new access($CORE_session);
 $required = $objaccess->get_required_pages($_SERVER['SCRIPT_NAME']);
 if ($required['pages_required']>0){
 require_once(APPROOT.'lib/common/check_login.php');
 }
 }

//habilitamos el error handler
$_SHOW_BREADCRUMP = false;
$_PAGE_HEADER = '&nbsp;';
?>