<?php

$configFile = "config/theconfig.php";

// 1. Check if config file exists
if (!file_exists($configFile)) {
    header("Location: install/install.php");
    exit;
}

// 2. Include config file
include($configFile);

// 3. Validate DB connection
if (!isset($con) || !($con instanceof mysqli) || $con->connect_errno) {
    // If connection fails, send to installer
    header("Location: install/install.php");
    exit;
}

// 4. Fetch system settings
$settings = []; 

$stmt = $con->prepare("SELECT * FROM system_settings LIMIT 1");
if ($stmt) {
    $stmt->execute();
    $result = $stmt->get_result(); 
    if ($result && $result->num_rows > 0) {
        $settings = $result->fetch_assoc(); 
    }
    $stmt->close();
}

// 5. Fallback values
$favicon         = $settings['favicon'] ?? 'assets/images/brand/favicon_1758475458.ico';
$bank_name       = $settings['bank_name'] ?? 'Demo Bank';
$email           = $settings['email'] ?? 'help@firstmobilex.click';
$email2          = $settings['email2'] ?? 'help@firstmobilex.click';
$phone           = $settings['phone'] ?? '+(501) 355-0112';
$company_address = $settings['company_address'] ?? '724 Alder St, Edmonds, Washington 98020.';
$brand_logo      = $settings['brand_logo'] ?? 'assets/images/brand/logo_1758475458.png';
?>
