<?php

session_name('super_admin_session');

if (!is_dir(dirname(__DIR__) . '/session_data/super')) { mkdir(dirname(__DIR__) . '/session_data/super', 0700, true); } session_save_path(dirname(__DIR__) . '/session_data/super');

session_set_cookie_params(['path' => '/', 'httponly' => true, 'samesite' => 'Strict']);

session_start();

include('includes/dbconnection.php');
require_once 'includes/session_term_helper.php';
$stResult = resolveCurrentSessionTerm($con);
$currentSessionName = $stResult['session_name'];
$currentTermName    = $stResult['term_name'];




if (!isset($_SESSION['sid'])) {

    header('location:logout.php');

    exit();

}



// Function to determine current term based on date

function getCurrentTermAndSession($con) {

    $currentDate = date('Y-m-d');

    

    // Get the calendar entry where current date is between resumption and closing

    $result = mysqli_query($con, "

        SELECT c.*, s.session_name, t.term_name 

        FROM school_calendar c

        JOIN school_sessions s ON s.id = c.session_id

        JOIN school_terms t ON t.id = c.term_id

        WHERE c.resumption_date <= '$currentDate' 

        AND c.closing_date >= '$currentDate'

        ORDER BY c.resumption_date DESC

        LIMIT 1

    ");

    

    // If found, return it

    if ($result && mysqli_num_rows($result) > 0) {

        return mysqli_fetch_assoc($result);

    }

    

    // If no current term found, get the most recent one

    $result = mysqli_query($con, "

        SELECT c.*, s.session_name, t.term_name 

        FROM school_calendar c

        JOIN school_sessions s ON s.id = c.session_id

        JOIN school_terms t ON t.id = c.term_id

        ORDER BY c.resumption_date DESC

        LIMIT 1

    ");

    

    return ($result && mysqli_num_rows($result) > 0) ? mysqli_fetch_assoc($result) : null;

}



// Get current term and session

$currentTermSession = getCurrentTermAndSession($con);



$success = $error = "";

$edit_holiday_id = 0;



// Save or Update Calendar

if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['save_calendar'])) {

    $sessionId   = intval($_POST['session']);

    $termId      = intval($_POST['term']);

    $resumption  = $_POST['resumption_date'];

    $closing     = $_POST['closing_date'];



    

    if ($sessionId && $termId && $resumption && $closing) {

        // Check if this session-term combination already exists

        $checkStmt = $con->prepare("SELECT id FROM school_calendar WHERE session_id = ? AND term_id = ?");

        $checkStmt->bind_param("ii", $sessionId, $termId);

        $checkStmt->execute();

        $checkStmt->store_result();

        

        if ($checkStmt->num_rows > 0) {

            // Update existing record

            $stmt = $con->prepare("UPDATE school_calendar SET resumption_date = ?, closing_date = ? WHERE session_id = ? AND term_id = ?");

            $stmt->bind_param("ssii", $resumption, $closing, $sessionId, $termId);

        } else {

            // Insert new record

            $stmt = $con->prepare("INSERT INTO school_calendar (session_id, term_id, resumption_date, closing_date) VALUES (?, ?, ?, ?)");

            $stmt->bind_param("iiss", $sessionId, $termId, $resumption, $closing);

        }

        

        if ($stmt->execute()) {

            $success = "School calendar saved successfully.";

            // Refresh current term/session data

            $currentTermSession = getCurrentTermAndSession($con);

        } else {

            $error = "Failed to save calendar: " . $con->error;

        }

    } else {

        $error = "All fields are required.";

    }

}



// Add Holiday

if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['add_holiday'])) {

    $sessionId   = intval($_POST['session_id']);

    $termId      = intval($_POST['term_id']);

    $holidayDate = $_POST['holiday_date'];

    $description = $_POST['description'];



    if ($holidayDate && $sessionId && $termId) {

        $stmt = $con->prepare("INSERT INTO public_holidays (holiday_date, description, session_id, term_id) VALUES (?, ?, ?, ?)");

        $stmt->bind_param("ssii", $holidayDate, $description, $sessionId, $termId);

        if ($stmt->execute()) {

            $success = "Holiday added successfully.";

        } else {

            $error = "Failed to add holiday: " . $con->error;

        }

    } else {

        $error = "Please select session, term, and date for the holiday.";

    }

}



// Update Holiday

if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['update_holiday'])) {

    $id = intval($_POST['holiday_id']);

    $sessionId   = intval($_POST['session_id']);

    $termId      = intval($_POST['term_id']);

    $holidayDate = $_POST['holiday_date'];

    $description = $_POST['description'];



    if ($id && $holidayDate && $sessionId && $termId) {

        $stmt = $con->prepare("UPDATE public_holidays SET holiday_date=?, description=?, session_id=?, term_id=? WHERE id=?");

        $stmt->bind_param("ssiii", $holidayDate, $description, $sessionId, $termId, $id);

        if ($stmt->execute()) {

            $success = "Holiday updated successfully.";

        } else {

            $error = "Failed to update holiday: " . $con->error;

        }

    } else {

        $error = "All fields are required.";

    }

}



// Delete Holiday

if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['delete_holiday'])) {

    $id = intval($_POST['id']);

    $stmt = $con->prepare("DELETE FROM public_holidays WHERE id=?");

    $stmt->bind_param("i", $id);

    if ($stmt->execute()) {

        $success = "Holiday deleted successfully.";

    } else {

        $error = "Failed to delete holiday: " . $con->error;

    }

}



// Delete Calendar

if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['delete_calendar'])) {

    $id = intval($_POST['id']);

    $stmt = $con->prepare("DELETE FROM school_calendar WHERE id=?");

    $stmt->bind_param("i", $id);

    if ($stmt->execute()) {

        $success = "Calendar record deleted successfully.";

        // Refresh current term/session data

        $currentTermSession = getCurrentTermAndSession($con);

    } else {

        $error = "Failed to delete calendar record: " . $con->error;

    }

}



// Set holiday to edit

if (isset($_GET['edit_holiday'])) {

    $edit_holiday_id = intval($_GET['edit_holiday']);

}



// Fetch Sessions, Terms

$sessions = mysqli_query($con, "SELECT id, session_name FROM school_sessions ORDER BY id DESC");

$terms    = mysqli_query($con, "SELECT id, term_name FROM school_terms ORDER BY id ASC");



// Fetch specific holiday to edit if needed

$edit_holiday = null;

if ($edit_holiday_id) {

    $result = mysqli_query($con, "SELECT * FROM public_holidays WHERE id = $edit_holiday_id");

    $edit_holiday = mysqli_fetch_assoc($result);

}



// Use the current term/session for display instead of the latest one

$calendar = $currentTermSession;



// Fetch all calendar records for the table

$calendarRecords = [];

$calendarResult = mysqli_query($con, "

    SELECT c.*, s.session_name, t.term_name 

    FROM school_calendar c

    JOIN school_sessions s ON s.id = c.session_id

    JOIN school_terms t ON t.id = c.term_id

    ORDER BY c.resumption_date DESC

");

while ($row = mysqli_fetch_assoc($calendarResult)) {

    $calendarRecords[] = $row;

}



// Fetch Holidays with session and term names

$holidays = [];

$res = mysqli_query($con, "

    SELECT h.*, s.session_name, t.term_name 

    FROM public_holidays h

    JOIN school_sessions s ON s.id=h.session_id

    JOIN school_terms t ON t.id=h.term_id

    ORDER BY h.holiday_date ASC

");

while ($row = mysqli_fetch_assoc($res)) {

    $holidays[] = $row;

}



// Function to Calculate Total Open Days

function calculateOpenDays($resumption, $closing, $holidays) {

    $totalDays = 0;

    $start = new DateTime($resumption);

    $end   = new DateTime($closing);



    $holidayDates = array_map(fn($row) => $row['holiday_date'], $holidays);



    while ($start <= $end) {

        $dayOfWeek = $start->format("N"); // 6=Sat, 7=Sun

        $dateStr   = $start->format("Y-m-d");



        if ($dayOfWeek < 6 && !in_array($dateStr, $holidayDates)) {

            $totalDays++;

        }

        $start->modify("+1 day");

    }

    return $totalDays;

}



$totalOpenDays = ($calendar) ? calculateOpenDays($calendar['resumption_date'], $calendar['closing_date'], $holidays) : 0;



?>

<!DOCTYPE html>

<html>

<?php @include("includes/head.php"); ?>

<body class="hold-transition sidebar-mini layout-fixed">

<div class="wrapper">

<?php @include("includes/header.php"); ?>

<?php @include("includes/sidebar.php"); ?>



<div class="content-wrapper">

<section class="content-header premium-header">

    <div class="container-fluid">

        <div class="header-glass-card">

            <div class="row align-items-center">

                <div class="col-md-8">

                    <div class="title-section">

                        <div class="icon-box bg-primary-gradient shadow-sm">

                            <i class="fas fa-calendar-alt"></i>

                        </div>

                        <div>

                            <h1 class="premium-title text-primary">

                                Academic Calendar Management

                                <span class="premium-subtitle text-secondary">Manage Calendar</span>

                            </h1>
                            <div class="mt-1">
                              <?php if ($currentSessionName): ?>
                                <span class="badge badge-primary mr-1">
                                  <i class="fas fa-calendar-alt"></i>
                                  <?= htmlspecialchars($currentSessionName) ?>
                                </span>
                              <?php endif; ?>
                              <?php if ($currentTermName): ?>
                                <span class="badge badge-success">
                                  <i class="fas fa-bookmark"></i>
                                  <?= htmlspecialchars($currentTermName) ?>
                                </span>
                              <?php else: ?>
                                <span class="badge badge-warning">
                                  <i class="fas fa-exclamation-triangle"></i> No active term
                                </span>
                              <?php endif; ?>
                            </div>

                        </div>

                    </div>

                </div>

                <div class="col-md-4">

                    <nav aria-label="breadcrumb">

                        <ol class="breadcrumb premium-breadcrumb">

                            <li class="breadcrumb-item"><a href="dashboard.php" class="text-primary">Home</a></li>

                            <li class="breadcrumb-item active" aria-current="page">Calendar</li>

                        </ol>

                    </nav>

                </div>

            </div>

        </div>

    </div>

</section>   



    <section class="content">

        <div class="container-fluid">



            <!-- Display Alerts -->

            <?php if ($success): ?>

            <div class="alert alert-success alert-dismissible">

                <button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>

                <h5><i class="icon fas fa-check"></i> Success!</h5>

                <?php echo $success; ?>

            </div>

            <?php endif; ?>



            <?php if ($error): ?>

            <div class="alert alert-danger alert-dismissible">

                <button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>

                <h5><i class="icon fas fa-ban"></i> Error!</h5>

                <?php echo $error; ?>

            </div>

            <?php endif; ?>



            <style>

                /* Cards Styling */

                .small-box {

                    border-radius: 12px;

                    transition: 0.3s ease-in-out;

                    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);

                    overflow: hidden;

                    background: white;

                }



                .small-box:hover {

                    transform: translateY(-4px);

                    box-shadow: 0 10px 20px rgba(0, 0, 0, 0.15);

                }



                .small-box .inner {

                    padding: 20px;

                }



                .small-box p {

                    font-size: 1rem;

                    font-weight: bold;

                    color: whitesmoke;

                }



                .small-box span {

                    font-size: 1rem;

                    color: #666;

                    font-weight: bold;

                }



                .small-box .icon {

                    position: absolute;

                    right: 20px;

                    top: 20px;

                    font-size: 3rem;

                    color: rgba(255, 255, 255, 0.8);

                }



                .small-box-footer {

                    display: block;

                    padding: 12px;

                    font-weight: 600;

                    font-size: 1rem;

                    text-align: center;

                    background: rgba(0, 0, 0, 0.1);

                    border-top: 1px solid rgba(255, 255, 255, 0.2);

                }



                .small-box-footer:hover {

                    background: rgba(0, 0, 0, 0.15);

                }

                

                .status-badge {

                    padding: 5px 10px;

                    border-radius: 12px;

                    font-size: 0.8rem;

                    font-weight: bold;

                }

            </style>



            <!-- Academic Calendar Summary -->

            <div class="card shadow-sm border-0">

                <div class="card-header bg-primary text-white">

                    <h5 class="card-title"> <i class="fas fa-info-circle"></i> Academic Calendar Summary</h5>

                </div>

                <div class="card-body">

                    <div class="container mt-4">

                        <div class="row g-3">

                            <?php if($calendar): ?>

                                <!-- Session -->

                                <div class="col-6 col-md-6 col-lg-4">

                                    <div class="small-box bg-primary">

                                        <div class="inner">

                                            <b><h4><?= $calendar['session_name']; ?></h4></b>

                                            <b><p>Session</p></b>

                                        </div>

                                        <div class="icon">

                                            <i class="fa fa-calendar-alt"></i>

                                        </div>

                                        <a href="#" class="small-box-footer">Current Academic Year <i class="fas fa-arrow-circle-right"></i></a>

                                    </div>

                                </div>



                                <!-- Term -->

                                <div class="col-6 col-md-6 col-lg-4">

                                    <div class="small-box bg-success">

                                        <div class="inner">

                                            <b><h4><?= $calendar['term_name']; ?></h4></b>

                                            <b><p>Term</p></b>

                                        </div>

                                        <div class="icon">

                                            <i class="fa fa-layer-group"></i>

                                        </div>

                                        <a href="#" class="small-box-footer">Ongoing Term <i class="fas fa-arrow-circle-right"></i></a>

                                    </div>

                                </div>



                                <!-- Resumption -->

                                <div class="col-6 col-md-6 col-lg-4">

                                    <div class="small-box bg-info">

                                        <div class="inner">

                                            <b><h4><?= date("F j, Y", strtotime($calendar['resumption_date'])); ?></h4></b>

                                            <b><p>Resumption Date</p></b>

                                        </div>

                                        <div class="icon">

                                            <i class="fa fa-door-open"></i>

                                        </div>

                                        <a href="#" class="small-box-footer">Term Start <i class="fas fa-arrow-circle-right"></i></a>

                                    </div>

                                </div>



                                <!-- Closing -->

                                <div class="col-6 col-md-6 col-lg-4">

                                    <div class="small-box bg-danger">

                                        <div class="inner">

                                            <b><h4><?= date("F j, Y", strtotime($calendar['closing_date'])); ?></h4></b>

                                            <b><p>Vacation Date</p></b>

                                        </div>

                                        <div class="icon">

                                            <i class="fa fa-door-closed"></i>

                                        </div>

                                        <a href="#" class="small-box-footer">Term Ends <i class="fas fa-arrow-circle-right"></i></a>

                                    </div>

                                </div>



                                <!-- Total Open Days -->

                                <div class="col-6 col-md-6 col-lg-4">

                                    <div class="small-box bg-warning text-dark">

                                        <div class="inner">

                                            <b><h4><?= $totalOpenDays; ?> days</h4>

                                            <p>Open Days</p></b>

                                        </div>

                                        <div class="icon">

                                            <i class="fa fa-clock"></i>

                                        </div>

                                        <a href="#" class="small-box-footer text-dark">Total active days <i class="fas fa-arrow-circle-right"></i></a>

                                    </div>

                                </div>

                            <?php else: ?>

                                <div class="col-12">

                                    <div class="alert alert-secondary text-center">

                                        No calendar set yet.

                                    </div>

                                </div>

                            <?php endif; ?>

                        </div>

                    </div>

                </div>

            </div>



            <!-- Calendar Form -->

            <div class="card shadow-sm border-0 mt-4">

                <div class="card-header bg-primary text-white">

                    <h3 class="card-title"><i class="fas fa-edit"></i> Set Term Calendar</h3>

                </div>

                <div class="card-body">

                    <form method="POST">

                        <div class="row">

                            <div class="form-group col-md-6">

                                <label>Academic Session</label>

                                <select name="session" class="form-control" required>

                                    <option value="">Select Session</option>

                                    <?php 

                                    // Reset pointer for sessions

                                    mysqli_data_seek($sessions, 0);

                                    while ($row = mysqli_fetch_assoc($sessions)) { 

                                        $selected = ($calendar && $calendar['session_id'] == $row['id']) ? 'selected' : '';

                                    ?>

                                        <option value="<?= $row['id']; ?>" <?= $selected; ?>><?= $row['session_name']; ?></option>

                                    <?php } ?>

                                </select>

                            </div>

                            <div class="form-group col-md-6">

                                <label>Term</label>

                                <select name="term" class="form-control" required>

                                    <option value="">Select Term</option>

                                    <?php 

                                    // Reset pointer for terms

                                    mysqli_data_seek($terms, 0);

                                    while ($row = mysqli_fetch_assoc($terms)) { 

                                        $selected = ($calendar && $calendar['term_id'] == $row['id']) ? 'selected' : '';

                                    ?>

                                        <option value="<?= $row['id']; ?>" <?= $selected; ?>><?= $row['term_name']; ?></option>

                                    <?php } ?>

                                </select>

                            </div>

                            <div class="form-group col-md-6">

                                <label>Resumption Date</label>

                                <input type="date" name="resumption_date" class="form-control" 

                                       value="<?= $calendar['resumption_date'] ?? ''; ?>" required>

                            </div>

                            <div class="form-group col-md-6">

                                <label>Closing Date</label>

                                <input type="date" name="closing_date" class="form-control" 

                                       value="<?= $calendar['closing_date'] ?? ''; ?>" required>

                            </div>

                        </div>

                        <div class="form-group col-md-12 text-center">

                            <button type="submit" name="save_calendar" class="btn btn-primary"><i class="fas fa-save"></i> Save Calendar</button>

                        </div>

                    </form>

                </div>

            </div>



            <!-- Academic Calendar Records Table -->

            <div class="card mt-4 shadow-sm border-0">

                <div class="card-header bg-info text-white">

                    <h3 class="card-title"><i class="fas fa-table"></i> Academic Calendar Records</h3>

                </div>

                <div class="card-body">

                    <div class="table-responsive">

                        <table class="table table-bordered table-striped" id="calendarTable">

                            <thead>

                                <tr>

                                    <th>#</th>

                                    <th>Session</th>

                                    <th>Term</th>

                                    <th>Resumption Date</th>

                                    <th>Closing Date</th>

                                    <th>Status</th>

                                    <th>Action</th>

                                </tr>

                            </thead>

                            <tbody>

                                <?php 

                                $sn = 1; 

                                $currentDate = date('Y-m-d');

                                foreach($calendarRecords as $record): 

                                    $status = '';

                                    $badgeClass = '';

                                    

                                    if ($currentDate >= $record['resumption_date'] && $currentDate <= $record['closing_date']) {

                                        $status = 'Current';

                                        $badgeClass = 'badge-success';

                                    } elseif ($currentDate < $record['resumption_date']) {

                                        $status = 'Upcoming';

                                        $badgeClass = 'badge-warning';

                                    } else {

                                        $status = 'Completed';

                                        $badgeClass = 'badge-secondary';

                                    }

                                ?>

                                <tr>

                                    <td><?= $sn++; ?></td>

                                    <td><?= htmlspecialchars($record['session_name']); ?></td>

                                    <td><?= htmlspecialchars($record['term_name']); ?></td>

                                    <td><?= date("F j, Y", strtotime($record['resumption_date'])); ?></td>

                                    <td><?= date("F j, Y", strtotime($record['closing_date'])); ?></td>

                                    <td>

                                        <span class="badge <?= $badgeClass; ?> status-badge"><?= $status; ?></span>

                                    </td>

                                    <td>

                                        <form method="POST" style="display:inline;">

                                            <input type="hidden" name="id" value="<?= $record['id']; ?>">

                                            <button type="submit" name="delete_calendar" class="btn btn-danger btn-sm" 

                                                    onclick="return confirm('Are you sure you want to delete this calendar record? This will also delete associated holidays.')">

                                                <i class="fas fa-trash"></i> Delete

                                            </button>

                                        </form>

                                    </td>

                                </tr>

                                <?php endforeach; ?>

                                <?php if(empty($calendarRecords)): ?>

                                <tr>

                                    <td colspan="7" class="text-center">No calendar records found</td>

                                </tr>

                                <?php endif; ?>

                            </tbody>

                        </table>

                    </div>

                </div>

            </div>



            <!-- Holidays Section -->

            <div class="card mt-4 shadow-sm border-0">

                <div class="card-header bg-primary text-white">

                    <h3 class="card-title"><i class="fas fa-umbrella-beach"></i> Manage Public Holidays</h3>

                </div>

                <div class="card-body">

                    <form method="POST" class="mb-3">

                        <input type="hidden" name="holiday_id" value="<?= $edit_holiday['id'] ?? ''; ?>">

                        <div class="row">

                            <div class="form-group col-md-6">

                                <label>Academic Session</label>

                                <select name="session_id" class="form-control" required>

                                    <option value="">Select Session</option>

                                    <?php 

                                    // Reset pointer for sessions

                                    mysqli_data_seek($sessions, 0);

                                    while ($row = mysqli_fetch_assoc($sessions)) { 

                                        $selected = (isset($edit_holiday['session_id']) && $edit_holiday['session_id'] == $row['id']) ? 'selected' : '';

                                    ?>

                                        <option value="<?= $row['id']; ?>" <?= $selected; ?>><?= $row['session_name']; ?></option>

                                    <?php } ?>

                                </select>

                            </div>

                            <div class="form-group col-md-6">

                                <label>Term</label>

                                <select name="term_id" class="form-control" required>

                                    <option value="">Select Term</option>

                                    <?php 

                                    // Reset pointer for terms

                                    mysqli_data_seek($terms, 0);

                                    while ($row = mysqli_fetch_assoc($terms)) { 

                                        $selected = (isset($edit_holiday['term_id']) && $edit_holiday['term_id'] == $row['id']) ? 'selected' : '';

                                    ?>

                                        <option value="<?= $row['id']; ?>" <?= $selected; ?>><?= $row['term_name']; ?></option>

                                    <?php } ?>

                                </select>

                            </div>

                            <div class="form-group col-md-6">

                                <label>Holiday Date</label>

                                <input type="date" name="holiday_date" class="form-control" 

                                       value="<?= $edit_holiday['holiday_date'] ?? ''; ?>" required>

                            </div>

                            <div class="form-group col-md-6">

                                <label>Description</label>

                                <input type="text" name="description" class="form-control" 

                                       value="<?= $edit_holiday['description'] ?? ''; ?>" placeholder="Holiday description">

                            </div>

                            <div class="form-group col-md-12 text-center">

                                <?php if (isset($edit_holiday)): ?>

                                    <button type="submit" name="update_holiday" class="btn btn-warning mt-4"><i class="fas fa-edit"></i> Update</button>

                                <?php else: ?>

                                    <button type="submit" name="add_holiday" class="btn btn-primary mt-4"><i class="fas fa-plus"></i> Add</button>

                                <?php endif; ?>

                            </div>

                        </div>

                    </form>



                    <table class="table table-bordered table-striped" id="example1">

                        <thead>

                            <tr>

                                <th>#</th>

                                <th>Date</th>

                                <th>Description</th>

                                <th>Session</th>

                                <th>Term</th>

                                <th>Action</th>

                            </tr>

                        </thead>

                        <tbody>

                            <?php $sn=1; foreach($holidays as $h): ?>

                            <tr>

                                <td><?= $sn++; ?></td>

                                <td><?= date("F j, Y", strtotime($h['holiday_date'])); ?></td>

                                <td><?= htmlspecialchars($h['description']); ?></td>

                                <td><?= htmlspecialchars($h['session_name']); ?></td>

                                <td><?= htmlspecialchars($h['term_name']); ?></td>

                                <td>

                                    <a href="?edit_holiday=<?= $h['id']; ?>" class="btn btn-primary btn-sm"><i class="fas fa-edit"></i></a>

                                    <form method="POST" style="display:inline;">

                                        <input type="hidden" name="id" value="<?= $h['id']; ?>">

                                        <button type="submit" name="delete_holiday" class="btn btn-danger btn-sm" 

                                                onclick="return confirm('Are you sure you want to delete this holiday?')">

                                            <i class="fas fa-trash"></i>

                                        </button>

                                        </form>

                                </td>

                            </tr>

                            <?php endforeach; ?>

                            <?php if(empty($holidays)) echo "<tr><td colspan='6' class='text-center'>No holidays set</td></tr>"; ?>

                        </tbody>

                    </table>

                </div>

            </div>



        </div>

    </section>

</div>



<?php @include("includes/foot.php"); ?>

<?php @include("includes/footer.php"); ?>

</div>



<script>

// Auto-dismiss alerts after 5 seconds

setTimeout(function() {

    $('.alert').alert('close');

}, 5000);



$(document).ready(function() {

    // Apply Select2 to all select elements

    $('select').select2();

    

    // Initialize DataTable for calendar records

    $('#calendarTable').DataTable({

        "responsive": true,

        "autoWidth": false,

        "ordering": true,

        "pageLength": 10,

        "lengthMenu": [10, 25, 50, 100]

    });

});

</script>

</body>

</html>