<?php

// File: dashboard_awal/redirect-kab-demak.php

session_start();



// Check if the system is open for this region

require_once "../admin/config.php";

$conn = connectDB();



$sql = "SELECT status FROM status_lomba WHERE name = 'kab_demak'";

$result = $conn->query($sql);

$status = ($result && $result->num_rows > 0) ? $result->fetch_assoc()['status'] : 'open';



if ($status == 'closed') {

    // If closed, redirect to main dashboard

    header("Location: index.php?error=closed");

    exit;

}



// Set authorization flag for Kabupaten

$_SESSION['allow_kabupaten_access'] = true;

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



// Redirect ke cabang_lomba_kab_2

header("Location: ../cabang_lomba_kab_2/index.php");

exit;

?>
