<?php

/*
 * awframework from aw.inc present aw config
 * it will help you develop easy and fast with secure tools
 * you can edit and add what you feel right
 * don't change in strucure of file
 */

require_once __DIR__ . '/../vendor/autoload.php';

use Monolog\Handler\FirePHPHandler;
use Monolog\Handler\StreamHandler;
use Monolog\Logger;

ini_set("display_errors", "off");
//ini_set("display_errors", "on");
ini_set('max_input_time', 600);
ini_set('max_execution_time', 36000);
date_default_timezone_set('Africa/Cairo');
ini_set('memory_limit', '2048M');



//here the hosturl
//$hosturl = 'http://192.168.1.120/alahram';
$hosturl = get_base_url() . '/dental';
$hosturl_ERP = get_base_url() . '/erp';

function get_base_url() {
    if (isset($_SERVER['HTTPS'])) {
        $protocol = ($_SERVER['HTTPS'] && $_SERVER['HTTPS'] != "off") ? "https" : "http";
    } else {
        $protocol = 'http';
    }
    return $protocol . "://" . $_SERVER['HTTP_HOST'];
}

//connection with main db
require_once('../../_library/db_main/rb.php');

//db connection
$db_host = 'localhost';
$db_name = 'dental';
//$db_name = 'royal_5-11-2022';
$db_user = 'root';
$db_password = '';

//connect to database
R::setup('mysql:host=' . $db_host . ';dbname=' . $db_name . '', '' . $db_user . '', '' . $db_password . '');
R::exec('SET NAMES latin1');
//R::freeze(true);
define("HOST_URL_ERP", $hosturl_ERP);
#here smarty library
//use smarty template , it will found in public folder
require_once('../../_library/smarty_plg/libs/Smarty.class.php');
//use smarty paginate to paging the records from db
require_once('../../_library/smarty_plg/libs/SmartyPaginate.class.php');
//use trucate method to munipliate the restore data
require_once('../../_library/smarty_plg/libs/modifier.mb_truncate.php');

/* if there login must this conif here */
#db connection
define("DB_HOST", $db_host);
define("DB_NAME", $db_name);
define("DB_USER", $db_user);
define("DB_PASS", $db_password);
#cookies config
define("COOKIE_RUNTIME", 1209600); //time of cookies // 2 weeks
define("COOKIE_DOMAIN", null); //for website must be like '.mydomain.com'
define("COOKIE_SECRET_KEY", "1gp@TMPS{+$78sfpMJFe-92s");  //a random value here
#Configuration for: Email server credentials
define("EMAIL_USE_SMTP", true);
define("EMAIL_SMTP_HOST", "ssl://smtp.gmail.com");
define("EMAIL_SMTP_AUTH", true);
define("EMAIL_SMTP_USERNAME", "");
define("EMAIL_SMTP_PASSWORD", "");
define("EMAIL_SMTP_PORT", 587);
define("EMAIL_SMTP_ENCRYPTION", "tls");
//if ther email server
/* define("EMAIL_USE_SMTP", false);
  define("EMAIL_SMTP_HOST", "yourhost");
  define("EMAIL_SMTP_AUTH", true);
  define("EMAIL_SMTP_USERNAME", "yourusername");
  define("EMAIL_SMTP_PASSWORD", "yourpassword");
  define("EMAIL_SMTP_PORT", 465);
  define("EMAIL_SMTP_ENCRYPTION", "ssl"); */
#Configuration for: password reset email data
define("EMAIL_PASSWORDRESET_URL", $hosturl . "/login/passrest");
define("EMAIL_PASSWORDRESET_FROM", "ahmed.taha.developer@gmail.com");
define("EMAIL_PASSWORDRESET_FROM_NAME", "AW Admin panel");
define("EMAIL_PASSWORDRESET_SUBJECT", "Password reset for PROJECT XY");
define("EMAIL_PASSWORDRESET_CONTENT", "Please click on this link to reset your password:");
#Configuration for: verification email data
define("EMAIL_VERIFICATION_URL", $hosturl . "/register");
define("EMAIL_VERIFICATION_FROM", "ahmed.freedeveloper@gmail.com");
define("EMAIL_VERIFICATION_FROM_NAME", "AW Admin panel");
define("EMAIL_VERIFICATION_SUBJECT", "Account activation for PROJECT XY");
define("EMAIL_VERIFICATION_CONTENT", "Please click on this link to activate your account:");
#Configuration for: Hashing strength
//it might be useful to increase the cost factor to 11
define("HASH_COST_FACTOR", "10");
// inactive in seconds
$inactive = 900;
if (!isset($_SESSION['timeout']))
    $_SESSION['timeout'] = time() + $inactive;

$session_life = time() - $_SESSION['timeout'];

if ($session_life > $inactive) {
    session_destroy();
    header('Location:' . $hosturl . '/controllers/login.php?ac=logout');
}

$_SESSION['timeout'] = time();

function logger($file_name = 'app.log', $reset_logger = 0) {
    // reset this logger
    if ($reset_logger && file_exists(__DIR__ . '/../logs/' . $file_name)) {
        unlink(__DIR__ . '/../logs/' . $file_name);
    }

    // Create some handlers
    $stream = new StreamHandler(__DIR__ . '/../logs/' . $file_name, Logger::DEBUG);
    $firephp = new FirePHPHandler();

    // Create the main logger of the app
    $logger = new Logger('ions');
    $logger->pushHandler($stream);
    $logger->pushHandler($firephp);

    return $logger;
}
