<?php
require_once __DIR__ . '/../config/dbConnection.php';

$db = DatabaseConnection::getInstance();
$conn = $db->getConnection();

$institution = [
    'name' => 'Katete Town Council',
    'phone' => '',
    'email' => '',
    'website' => ''
];

$query = "SELECT institution_name, phone_number, institution_email, website FROM setup LIMIT 1";
$result = $conn->query($query);

if ($result && $result->num_rows > 0) {
    $institution = $result->fetch_assoc();
}
?>
<footer class="footer mt-auto py-3 bg-white text-center">
    <div class="container">
        <span class="text-muted">
            Copyright © <span id="year"><?= date('Y') ?></span>
            <?php
            // Ensure website has correct scheme
            $website = $institution['website'] ?? '';
            if ($website && !preg_match('#^https?://#i', $website)) {
                $website = 'https://' . $website;
            }
            ?>
            <a href="<?= htmlspecialchars($website) ?>" class="text-dark fw-medium">
                <?= htmlspecialchars($institution['institution_name']) ?>
            </a>.

            Designed by
            <a href="https://smartsync.zm"><span class="fw-medium text-primary">SmartSync</span></a>
            All rights reserved.
        </span>

    </div>
</footer>
