<?php

/* START SESSION SAFELY */
if(session_status() === PHP_SESSION_NONE){
    session_start();
}

/* DATABASE CONNECTION */
include __DIR__ . "/db.php";

/* PROJECT BASE PATH */
$base_url = "/digital_panchayat/admin/";

/* LOGIN CHECK */
if(!isset($_SESSION['user_id']))
{
    header("Location: ".$base_url."login.php");
    exit;
}

/* ROLE CHECK FUNCTION */
function allowRoles($roles)
{
    if(!isset($_SESSION['role_id']))
    {
        header("Location: /digital_panchayat/admin/login.php");
        exit;
    }

    if(!in_array($_SESSION['role_id'],$roles))
    {
        header("Location: /digital_panchayat/admin/dashboard.php");
        exit;
    }
}

/* COMMON SESSION VARIABLES */

$user_id     = $_SESSION['user_id'] ?? null;
$role_id     = $_SESSION['role_id'] ?? null;
$district_id = $_SESSION['district_id'] ?? null;
$block_id    = $_SESSION['block_id'] ?? null;
$village_id  = $_SESSION['village_id'] ?? null;

?>