<?php
declare(strict_types=1);

/**
 * EDEN LMS bootstrap
 * - No output here (no HTML, no closing "?>" tag)
 * - Save as UTF-8 **without BOM**
 */

if (session_status() !== PHP_SESSION_ACTIVE) {
  session_start();
}

/* ---------- Environment / errors ---------- */
if (!defined('APP_DEBUG')) { define('APP_DEBUG', true); }
if (APP_DEBUG) {
  error_reporting(E_ALL);
  ini_set('display_errors', '1');
} else {
  error_reporting(0);
  ini_set('display_errors', '0');
}

date_default_timezone_set('Asia/Colombo'); // change if needed

/* ---------- URLs ---------- */
// e.g. /admin.edencampus.lk/elms/admin/courses/index.php
$__script = $_SERVER['SCRIPT_NAME'] ?? '';
$__base   = rtrim(str_replace('\\','/', dirname($__script)), '/'); // e.g. /admin.edencampus.lk/elms/admin
if (!defined('BASE_URL')) define('BASE_URL', $__base);

// App root (outside admin area)
if (!defined('ROOT_URL'))  define('ROOT_URL', preg_replace('#/admin$#', '', BASE_URL));
if (!defined('ADMIN_URL')) define('ADMIN_URL', ROOT_URL . '/admin');

/* ---------- Core includes (no output) ---------- */
require_once __DIR__ . '/config.php';
require_once __DIR__ . '/helpers.php';
require_once __DIR__ . '/db.php';
require_once __DIR__ . '/auth.php';
if (is_file(__DIR__ . '/scope.php')) require_once __DIR__ . '/scope.php';
if (is_file(__DIR__ . '/app.php'))   require_once __DIR__ . '/app.php';

// Do NOT close the PHP tag in this file.
