<?php
date_default_timezone_set("America/Caracas");
ini_set("default_charset", "UTF-8");
mb_internal_encoding("UTF-8");

$ini_request = microtime(true);
if(isset($_SERVER["HTTP_USER_AGENT"])){
	$ua = strtolower($_SERVER["HTTP_USER_AGENT"]);
}else{
$ua ="other";
}

$isMob = is_numeric(strpos($ua, "mobile"));
if($isMob == 1){
	$isMob = true;
}else{
	$isMob = false;
}
/*$mysql_host = "localhost";
$mysql_user = "softhome_colinaca";
$mysql_password = "RBhFvT54Y23^";
$mysql_database = "softhome_colinaca";*/
//

function siteURL()
{
  $protocol = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' || $_SERVER['SERVER_PORT'] == 443) ? "https://" : "http://";
  $domainName = $_SERVER['HTTP_HOST'].'/';
  return $protocol.$domainName;
}

define( 'SITE_URL', siteURL() );
if(!defined('API_URL')){
  define( 'API_URL', siteURL() );
}
if(!defined('MODULE_NAME')){
  define( 'MODULE_NAME', 'friocarnes' );
}

define("INTROOT", dirname(__FILE__,2).DIRECTORY_SEPARATOR.MODULE_NAME.'/admin'.DIRECTORY_SEPARATOR);
define("INTROOT_AJI", dirname(__FILE__,2).DIRECTORY_SEPARATOR.'aji/admin'.DIRECTORY_SEPARATOR);
define("APPROOT", dirname(__FILE__,2).DIRECTORY_SEPARATOR);
define("APIROOT", $_SERVER ['DOCUMENT_ROOT'].DIRECTORY_SEPARATOR);
define("COREROOT", $_SERVER ['DOCUMENT_ROOT'].DIRECTORY_SEPARATOR);
define("DOMAIN_ROOT", "https://" . $_SERVER ['SERVER_NAME'] .'/');
/*if( !in_array(DOMAIN_ROOT, array(
  'https://apidemo.softhomesolutions.com/','https://api.softhomesolutions.com/','https://demo.softhomesolutions.com/','https://colinaca.softhomesolutions.com/'
  ))){
	  header('location: https://softhomesolutions.com/mantenimiento.php');
die('');
  }*/

define("DOMAIN_INT_ROOT", "https://" . $_SERVER ['SERVER_NAME'] .'/admin/');
define("DOMAIN_HOME", "https://" . $_SERVER ['SERVER_NAME'] .'/home.php');
define("DOMAIN_APP_ROOT", "https://" . $_SERVER ['SERVER_NAME'] .'/');
define("DOMAIN_BO_ROOT", "https://" . $_SERVER ['SERVER_NAME'] .'/admin/');
define("COOKIE_USERFULLNAME", "efc_user_fullname");
define("COOKIE_USER_ID", "efc_user_id");
define("COOKIE_USERLOGINNAME", "efc_user_loginname");
define("COOKIE_USERAVATAR", "efc_user_avatar");
define("COOKIE_USERROL", "efc_user_rol");
define("COOKIE_USERROLID", "efc_user_rol_id");
define("COOKIE_USER_BRANCH_ID", "efc_user_branch_id");
define("COOKIE_USER_BRANCH_NAME", "efc_user_branch_name");
define("DEFAULT_AVATAR","default_avatar.png");
////////////
define("COOKIE_EFCFULLNAME", "efc_fullname");
define("COOKIE_EFCNICKNAME", "efc_login");
define("COOKIE_EFCEMAIL", "efc_email");
define("COOKIE_EFCAVATAR", "efc_avatar");

/////////////
$arrDB = array(
"_MYSQL" => array("host" => MYSQL_HOST, "user" => MYSQL_USER, "pass" => MYSQL_PASS, "db" => MYSQL_DB)
);
/*$arrDB = array(
"_MYSQL" => array("host" => $mysql_host, "user" => $mysql_user, "pass" => $mysql_password, "db" => $mysql_database)
);*/
//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",3600000);
ini_set("session.gc_maxlifetime", 3600000);
session_set_cookie_params(3600000);
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'].'?charset=utf8'
);

 ActiveRecord\Config::initialize(function($cfg) use ($connections)
 {
   $cfg->set_model_directory(APPROOT . 'lib/models');
   $cfg->set_connections($connections);
 });
require_once APPROOT . 'lib/class/externals/phpmailer/PHPMailerAutoload.php';
Autoloader::Register();
$CORE_session = new SessionManager('EFC');
$CORE_general = new General();
//Parameter::load_parameters();
if( !in_array(DOMAIN_ROOT, array(
  'https://apiporcina.grupoefc.app/',
  'https://apiparamo.grupoefc.app/',
  'https://apifcval.grupoefc.app/',
  'https://apidalo.grupoefc.app/',
  ))){
    $_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');
      }
    }
  }
  $_show_search = false;
?>