<?php
require_once __DIR__ . '/app_paths.php';
require_once __DIR__ . '/app_runtime.php';
require_once __DIR__ . '/app_access.php';
require_once __DIR__ . '/security.php';
// admin/bootstrap.php
// Loads core libs + DB connection WITHOUT output, so pages can safely do header() redirects.

ua_session_start();

// Embed mode (for iframes): page.php?embed=1
if (!defined('UA_EMBED')) {
  define('UA_EMBED', isset($_GET['embed']) && $_GET['embed'] == '1');
}

ua_enforce_install_access();

require_once __DIR__ . '/helpers.php';
require_once __DIR__ . '/lang.php';
require_once __DIR__ . '/auth.php';
require_once __DIR__ . '/db_bootstrap.php';

if (function_exists('ensure_db')) {
  ensure_db(true);
}
$GLOBALS['conn'] = $GLOBALS['conn'] ?? ($conn ?? null);
$conn = $GLOBALS['conn'] ?? null;

// Auto-login guard for non-public pages (same behavior as header.php)
$cur = basename($_SERVER['PHP_SELF'] ?? '');
$PUBLIC = ['index.php','login.php','logout.php','setup_first_admin.php','install_link.php'];
if (!in_array($cur, $PUBLIC, true)) {
  if (function_exists('require_login')) {
    require_login('index.php?login=1');
  }
}
