<?php
ob_start();
?>
<?php
// T07: display_errors removed — errors are logged server-side only
// ini_set('display_errors', 1);
// error_reporting(E_ALL);
$base_public = file_exists(__DIR__ . '/../../public/connection.php') ? __DIR__ . '/../../public/' : (file_exists(__DIR__ . '/../public/connection.php') ? __DIR__ . '/../public/' : 'public/');
require_once($base_public . "staff_session.php");
require_once($base_public . "connection.php");
require_once($base_public . "functions.php");
require_once($base_public . "csrf.php");       // T02: CSRF helper
require_once($base_public . "upload_helper.php"); // T06: Secure upload helper
//require_once("staff_dashboard_processor.php");
?>
<?php
// T01: Fixed — login sets $_SESSION['staff'], not $_SESSION['admin']
if (!isset($_SESSION['staff'])) {
    header('Location: ../../login.php');
    exit();
}
?>
<?php
//////////////// DEFAULT NULL VALUES ///////////////
date_default_timezone_set('Africa/Lagos');
$date = date('d-M-Y');
$select = "--select--";
$oge = time();
$time = date('H:i:s', $oge);
$error = array();
$year = date('Y');
?>
<?php
//////////////////// GET USERS DATA FROM DATABASE AND DISPLAY IT ON DASHBOARD IF LOGIN IS SUCCESSFUL USING SESSION FROM LOGIN PAGE ////////////////
// T04: Fixed — was directly interpolating $_SESSION['admin'] into SQL
// T01: Also updated to use the correct session key: $_SESSION['staff']
$staff_id_session = (int) $_SESSION['staff'];
$stmt_user = $connection->prepare("SELECT * FROM `users` WHERE id = ?");
$stmt_user->bind_param("i", $staff_id_session);
$stmt_user->execute();
$run_query = $stmt_user->get_result();
$stmt_user->close();
if ($run_query->num_rows === 1) {
    while ($result = $run_query->fetch_assoc()) {
        $user_id = $result['id'];
        $user_passport = "./" . $result['passport'];
        $user_title = $result['title'];
        $user_fullname = ucwords($result['fullname']);
        $user_address = ucwords($result['address']);
        $user_phone = $result['phone'];
        $user_state = ucwords($result['state']);
        $user_lga = ucwords($result['lga']);
        $user_nationality = ucwords($result['nationality']);
        $user_email = $result['email'];

        if ($user_title === "Mr") {
            $gender = "Male";
        } elseif ($user_title === "Mrs") {
            $gender = "Female";
        } elseif ($user_title === "Miss") {
            $gender = "Female";
        }

        $msg_fullname = $user_fullname;
        $msg_title = $user_title;
    }
}
?>
<?php
////////// POST ACTION TO VIEW ALL THE UPLOADED ADMINISTRATIVE INFORMATION ////////////
$query = " SELECT * FROM `administratives` ";
$run_query = mysqli_query($connection, $query);

if (mysqli_num_rows($run_query) > 0) {
    while ($result = mysqli_fetch_assoc($run_query)) {
        $administratives_id = $result['id'];
        $admin_name = $result['school_name'];
        $admin_motto = $result['school_motto'];
        $admin_logo = $result['school_logo'];
        $school_initial = $result['adm_no_initials'];
        $admin_stamp = $result['school_stamp'];
        //echo "<img src='$admin_logo' />";
    }
}
?>
<?php
$query = " SELECT * FROM `current_season` ";
$run_query = mysqli_query($connection, $query);
if (mysqli_num_rows($run_query) == 1) {
    while ($result = mysqli_fetch_assoc($run_query)) {
        $current_term = $result['current_term'];
        $current_session = $result['current_session'];
    }
}
?>
<!DOCTYPE html>
<html>

<head>
    <meta charset='utf-8'>
    <!-- T16: Removed duplicate <meta charset> -->
    <meta http-equiv='X-UA-Compatible' content='IE=edge'>
    <meta name='viewport' content='width=device-width, initial-scale=1'>
    <!-- CSS-->
    <link rel='stylesheet' type='text/css' href='assets/css/table.css'>
    <link rel='stylesheet' type='text/css' href='assets/css/main.css'>
    <link rel='stylesheet' type='text/css' href='assets/css/whatsapp.css'>
    <link rel='stylesheet' type='text/css' href='/assets/css/defined.css'>
    <link rel='stylesheet' type='text/css' href='/assets/css/bootstrapp5_30.min.css'>
    <link rel='stylesheet' type='text/css' href='/assets/bootstrap.min.css'>
    <link rel="shortcut icon" href="img/favicon.png">
    <!-- Font-icon css-->
    <link rel="stylesheet" href="assets/css/font-awesome-4.7.0/css/font-awesome.css">
    <link href="assets/DataTables/datatables.min.css" rel="stylesheet">
    <link href="assets/SweetAlerts/sweetalert.css" rel="stylesheet">
    <link href="assets/Datepicker/bootstrap-datepicker.min.css" rel="stylesheet">

    
    

    <title><?php echo $user_fullname; ?> ~ <?php echo $admin_name; ?></title>
    <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries-->
    <!--if lt IE 9
    script(src='https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js')
    script(src='https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js')
    -->
    <script src="assets/js/jquery-2.1.4.min.js"></script>
    <script type="text/javascript">
        $(function() {
            // add multiple select / deselect functionality
            $("#selectall").click(function() {
                $('.subgroup').attr('checked', this.checked);
            });
            // if all checkbox are selected, then check the select all checkbox
            // and viceversa
            $(".subgroup").click(function() {
                if ($(".subgroup").length == $(".subgroup:checked").length) {
                    $("#selectall").attr("checked", "checked");
                } else {
                    $("#selectall").removeAttr("checked");
                }
            });
        });
    </script>
    <script type="text/javascript">
        window.onload = initClock;

        function initClock() {
            var now = new Date();
            var hr = now.getHours();
            var min = now.getMinutes();
            var sec = now.getSeconds();
            if (min < 10) min = "0" + min; // insert a leading zero
            if (sec < 10) sec = "0" + sec;
            document.getElementById('clockDisplay').innerHTML = hr + ":" + min + ":" + sec;
            setTimeout('initClock()', 500);
        }
    </script>
    <style type="text/css">
        .print_div {
            /*width: 21cm;
        min-height: 29.7cm;
        padding: 2cm;
        margin: 1cm auto;
        border: 1px #D3D3D3 solid;
        border-radius: 5px;
        background: white;
        box-shadow: 0 0 5px rgba(0, 0, 0, 0.1);*/
        }

        @page {
            size: A4;
            margin: 0;
        }

        @media print {
            .print_div {
                margin: 0;
                margin-top: -20%;
                padding-right: 4%;
                padding-left: 4%;
                border: 0;
                font-size: 12px;
                border-radius: 5px;
                /*width: 21cm;*/
                /*min-height: 29.7cm;*/
                box-shadow: 0 0 5px rgba(0, 0, 0, 0.1);
                background: white;
                page-break-after: always;
            }

            table.table-bordered {
                border: 2px solid #dee2e6;
                /* Light gray border for the table */
            }

            table.table-bordered th,
            table.table-bordered td {
                border: 1px solid #dee2e6;
                /* Borders around cells */
            }
        } /* T15: Closing brace for @media print */
    </style>
        <style>
        /* WhatsApp Floating Button */
        .whatsapp-button {
            position: fixed;
            bottom: 20px;
            right: 20px;
            background-color: #25D366;
            color: white;
            width: 60px;
            height: 60px;
            border-radius: 50%;
            display: flex;
            justify-content: center;
            align-items: center;
            font-size: 28px;
            cursor: pointer;
            box-shadow: 0px 4px 10px rgba(0, 0, 0, 0.2);
            z-index: 1000;
            transition: background 0.3s ease;
        }

        .whatsapp-button:hover {
            background-color: #1ebd5a;
        }

        /* Chat Box */
        .chat-box {
            position: fixed;
            bottom: 90px;
            right: 20px;
            width: 300px;
            background: white;
            border-radius: 10px;
            box-shadow: 0px 4px 10px rgba(0, 0, 0, 0.2);
            display: none;
            flex-direction: column;
            overflow: hidden;
        }

        /* Chat Header */
        .chat-header {
            background: #25D366;
            color: white;
            padding: 10px;
            text-align: center;
            font-weight: bold;
            font-size: 16px;
            position: relative;
        }

        .close-btn {
            position: absolute;
            right: 10px;
            top: 50%;
            transform: translateY(-50%);
            background: none;
            border: none;
            color: white;
            font-size: 18px;
            cursor: pointer;
        }

        /* Chat Messages */
        .chat-body {
            padding: 10px;
            height: 200px;
            overflow-y: auto;
            background: #f5f5f5;
        }

        .chat-message {
            background: #DCF8C6;
            padding: 8px;
            border-radius: 5px;
            margin: 5px 0;
            font-size: 14px;
            width: fit-content;
            max-width: 80%;
        }

        /* Chat Input Area */
        .chat-footer {
            display: flex;
            align-items: center;
            padding: 5px;
            background: white;
            border-top: 1px solid #ddd;
        }

        .chat-footer input {
            flex: 1;
            padding: 8px;
            border: none;
            outline: none;
            font-size: 14px;
            border-radius: 5px;
            background: #f0f0f0;
        }

        .chat-footer button {
            background: #25D366;
            color: white;
            border: none;
            padding: 8px 12px;
            font-size: 16px;
            margin-left: 5px;
            cursor: pointer;
            border-radius: 5px;
        }

        .chat-footer button:hover {
            background: #1ebd5a;
        }

        /* Responsive Design */
        @media (max-width: 400px) {
            .chat-box {
                width: 90%;
                right: 5%;
            }
        }
    </style>
</head>

<body class='sidebar-mini fixed'>
    <div class='wrapper'>
        <!-- Navbar-->
        <header class='main-header hidden-print'><a class='logo' href='#'><?php echo $admin_name; ?></a>
            <nav class='navbar navbar-static-top'>
                <!-- Sidebar toggle button-->
                <a class='sidebar-toggle' href='#' data-toggle='offcanvas'></a>
                <!-- Navbar Right Menu-->
                <div class='navbar-custom-menu'>
                    <ul class='top-nav'>
                        <!--Notification Menu-->

                        <!-- User Menu-->
                        <li class='dropdown'><a class='dropdown-toggle' href='#' data-toggle='dropdown' role='button' aria-haspopup='true' aria-expanded='false'><img class='img-circle' src='<?php echo $user_passport; ?>' width='31' alt='User Image'></a>
                            <ul class='dropdown-menu settings-menu'>
                                <li><a href='modules.php?settings'><i class='fa fa-cog fa-lg'></i> Settings</a></li>
                                <li><a href='modules.php?staff_profile'><i class='fa fa-user fa-lg'></i> Profile</a></li>
                                <li><a href='modules.php?logout'><i class='fa fa-sign-out fa-lg'></i> Logout</a></li>
                            </ul>
                        </li>
                    </ul>
                </div>
            </nav>
        </header>
        <!-- Side-Nav-->
        <aside class='main-sidebar hidden-print'>
            <section class='sidebar'>
                <!-- Sidebar Menu-->
                <ul class='sidebar-menu'>
                    <li class='active'><a href='modules.php?dashboard'><i class='fa fa-dashboard'></i><span>Dashboard</span></a></li>
                    <li><a href='modules.php?staff_profile'><i class='fa fa-user'></i><span>Profile</span></a></li>
                    <li class='treeview'><a href='#'><i class='fa fa-laptop'></i><span>Administrative Manager</span><i class='fa fa-angle-right'></i></a>
                        <ul class='treeview-menu'>                         
                            <li><a href='modules.php?manage_school_info'><i class='fa fa-circle-o'></i> Edit School Information</a></li>
                            <li><a href='modules.php?view_school_info'><i class='fa fa-circle-o'></i> View School Information</a></li>
                            <li><a href='modules.php?session_term'><i class='fa fa-circle-o'></i> Session, Term and Dates</a></li>
                        </ul>
                    </li>
                    <li class='treeview'><a href='#'><i class='fa fa-laptop'></i><span>Result Pin Management</span><i class='fa fa-angle-right'></i></a>
                        <ul class='treeview-menu'>
                            <li><a href='modules.php?generate_pins'><i class='fa fa-circle-o'></i> Generate Result Pins</a></li>
                            <li><a href='modules.php?view_uploaded_pins'><i class='fa fa-circle-o'></i> View Uploaded Pin</a></li>
                            <li><a href='modules.php?view_used_pins'><i class='fa fa-circle-o'></i> View Used Pin</a></li>
                            <li><a href='modules.php?view_unused_pins'><i class='fa fa-circle-o'></i> View Unsued Pin</a></li>
                        </ul>
                    </li>
                    <li class='treeview'><a href='#'><i class='fa fa-users'></i><span>Student Management</span><i class='fa fa-angle-right'></i></a>
                        <ul class='treeview-menu'>
                            <li><a href='modules.php?add_new_student'><i class='fa fa-circle-o'></i> Register New Student</a></li>
                            <li><a href='modules.php?view_students'><i class='fa fa-circle-o'></i> View Students</a></li>
                            <li><a href='modules.php?promote_students'><i class='fa fa-circle-o'></i> Promote All Students</a></li>
                            <li><a href='modules.php?promote_selected_students'><i class='fa fa-circle-o'></i> Promote Selected Students</a></li>
                            <li><a href='modules.php?demote_students'><i class='fa fa-circle-o'></i> Demote Students</a></li>                            
                            <li><a href='modules.php?transfer_list'><i class='fa fa-circle-o'></i>Transfer Certificate</a></li>
                        </ul>
                    </li>
                    <li class='treeview'><a href='#'><i class='fa fa-edit'></i><span>Behavioral Management</span><i class='fa fa-angle-right'></i></a>
                        <ul class='treeview-menu'>
                            <li><a href='modules.php?students_conducts'><i class='fa fa-circle-o'></i> Record Behaviour</a></li>
                            <li><a href='modules.php?view_conducts'><i class='fa fa-circle-o'></i> View Behaviour</a></li>
                        </ul>
                    </li>                    
                    <li class='treeview'><a href='#'><i class='fa fa-pie-chart'></i><span>Class Attendance</span><i class='fa fa-angle-right'></i></a>
                        <ul class='treeview-menu'>
                            <li><a href='modules.php?class_attendance'><i class='fa fa-circle-o'></i> Record Attendance</a></li>
                            <li><a href='modules.php?view_attendance_records'><i class='fa fa-circle-o'></i> View Attendance</a></li>
                        </ul>
                    </li>
                    <li><a href='modules.php?class'><i class='fa fa-home'></i><span>Class Management</span></a></li>
                    <li class='treeview'><a href='#'><i class='fa fa-file-text'></i><span>Subject Management</span><i class='fa fa-angle-right'></i></a>
                        <ul class='treeview-menu'>                            
                            <li><a href='modules.php?view_added_subjects'><i class='fa fa-circle-o'></i> All Subjects</a></li>
                            <li><a href='modules.php?register_student_subject'><i class='fa fa-circle-o'></i> Register Student Subject</a></li>
                            <li><a href='modules.php?view_registered_subjects'><i class='fa fa-circle-o'></i> View Registered Subject</a></li>
                            <li><a href='modules.php?specify_subjects_level'><i class='fa fa-circle-o'></i> Specify Subject Levels</a></li>
                            <!--li><a href='modules.php?subject_number_specification'><i class='fa fa-circle-o'></i> No of Subject Specification</a></li-->
                        </ul>
                    </li>
                    <li class='treeview'><a href='#'><i class='fa fa-book'></i><span>Result Management</span><i class='fa fa-angle-right'></i></a>
                        <ul class='treeview-menu'>
                            <li><a href='modules.php?admin_upload_ca'><i class='fa fa-circle-o'></i> Upload CA Test Scores</a></li>
                            <li><a href='modules.php?admin_upload_exam'><i class='fa fa-circle-o'></i> Upload Exam Scores</a></li>
                            <li><a href='modules.php?excel_result_upload'><i class='fa fa-file-excel-o text-success'></i> Excel / CSV Result Upload</a></li>
                            <li><a href='modules.php?update_subject_rank'><i class='fa fa-circle-o'></i> Update Scores Rank</a></li>
                            <!--<li><a href='modules.php?upload_result'><i class='fa fa-circle-o'></i> Upload Result Directly</a></li>-->
                            <li><a href='modules.php?view_uploaded_results'><i class='fa fa-circle-o'></i> View Uploaded Result</a></li>
                            <li><a href='modules.php?view_class_broadsheet'><i class='fa fa-circle-o'></i> View Class Broadsheet</a></li>
                            <li><a href='modules.php?publish_result'><i class='fa fa-circle-o'></i> Publish Result</a></li>
                            <li><a href='modules.php?view_published_result'><i class='fa fa-circle-o'></i> View Published Result</a></li>
                            <li><a href='modules.php?admin_check_result'><i class='fa fa-circle-o'></i> Check Result</a></li>
                        </ul>
                    </li>
                    <li class='treeview'><a href='#'><i class='fa fa-tasks'></i><span>Fees Management</span><i class='fa fa-angle-right'></i></a>
                        <ul class='treeview-menu'>
                            <li><a href='modules.php?allocate_class_fee'><i class='fa fa-circle-o'></i> Allocate Class Fee</a></li>
                            <li><a href='modules.php?fee_payment'><i class='fa fa-circle-o'></i> Register Fee Payment</a></li>
                            <li><a href='modules.php?outstanding_fees'><i class='fa fa-circle-o'></i> Outstanding Fee Payment</a></li>
                            <!--<li><a href='adminpage.php?p=view_student_fee'><i class='fa fa-circle-o'></i> View Each Student Fee Record</a></li>-->
                        </ul>
                    </li>
                    <!--<li class='treeview'><a href='#'><i class='fa fa-user'></i><span>Admin</span><i class='fa fa-angle-right'></i></a>
              <ul class='treeview-menu'>
                <li><a href='modules.php?add_admin'><i class='fa fa-circle-o'></i> Add an Admin</a></li>
                <li><a href='modules.php?view_all_admin'><i class='fa fa-circle-o'></i> View All Admins</a></li>
	  </ul>
            </li>
            <li class='treeview'><a href='#'><i class='fa fa-user'></i><span>Principal</span><i class='fa fa-angle-right'></i></a>
              <ul class='treeview-menu'>
                <li><a href='modules.php?add_principal'><i class='fa fa-circle-o'></i> Add New Principal</a></li>
                <li><a href='modules.php?view_all_principals'><i class='fa fa-circle-o'></i> View Principals</a></li>
			  </ul>
            </li>
            <li class='treeview'><a href='#'><i class='fa fa-user'></i><span>Accountant</span><i class='fa fa-angle-right'></i></a>
              <ul class='treeview-menu'>
                <li><a href='modules.php?add_accountant'><i class='fa fa-circle-o'></i> Add New Accountant</a></li>
                <li><a href='modules.php?view_accountants'><i class='fa fa-circle-o'></i> View Accountants</a></li>
	  </ul>
            </li>-->
                    <li class='treeview'><a href='#'><i class='fa fa-user'></i><span>Teachers</span><i class='fa fa-angle-right'></i></a>
                        <ul class='treeview-menu'>
                            <li><a href='modules.php?add_teacher'><i class='fa fa-circle-o'></i> Add A Teacher</a></li>
                            <li><a href='modules.php?assign_class_to_teacher'><i class='fa fa-circle-o'></i> Teachers and their Classes</a></li>
                            <li><a href='modules.php?view_teachers_portfolio'><i class='fa fa-circle-o'></i> View Teachers Portfolio</a></li>
                        </ul>
                    </li>
                    <li><a href='modules.php?staff_reset_password'><i class='fa fa-key'></i><span>Password Reset</span></a></li>
                    <!--<li><a href='modules.php?mails'><i class='fa fa-envelope'></i><span>Mails</span></a></li>-->
                    <li class='treeview'><a href='#'><i class='fa fa-user'></i><span>Generate Contacts</span><i class='fa fa-angle-right'></i></a>
                        <ul class='treeview-menu'>
                            <li><a href='modules.php?all_contact'><i class='fa fa-circle-o'></i> All Contacts</a></li>
                        </ul>
                    </li>
                </ul>
            </section>
        </aside>
        <div class='content-wrapper'>
            <?php
            if (isset($_GET['portal_request'])) {
                require_once("portal_request.php");
            } elseif (isset($_GET['staff_profile'])) {
                require("staff_profile.php");
            } elseif (isset($_GET['manage_school_info'])) {
                require("manage_school_info.php");
            } elseif (isset($_GET['view_school_info'])) {
                require("view_school_info.php");
            } elseif (isset($_GET['current_term'])) {
                require("current_term.php");
            } elseif (isset($_GET['session_term'])) {
                require("session_term.php");
            } elseif (isset($_GET['print_certificate'])) {
                require("print_certificate.php");
            } elseif (isset($_GET['add_new_session'])) {
                require("new_session.php");
            } elseif (isset($_GET['generator'])) {
                require("generator.php");
            } elseif (isset($_GET['add_new_student'])) {
                require("add_new_student.php");
            } elseif (isset($_GET['promote_students'])) {
                require("promote_students.php");
            } elseif (isset($_GET['promote_selected_students'])) {
                require_once("promote_selected_students.php");
            } elseif (isset($_GET['demote_students'])) {
                require("demote_student.php");
            } elseif (isset($_GET['view_students'])) {
                require("view_students.php");
            } elseif (isset($_GET['class_attendance'])) {
                require("class_attendance.php");
            } elseif (isset($_GET['transfer_list'])) {
                require("transfer_list.php");
            } elseif (isset($_GET['view_attendance_records'])) {
                require("view_attendance_records.php");
            } elseif (isset($_GET['class'])) {
                require("class.php");
            } elseif (isset($_GET['view_classes'])) {
                require("view_classes.php");
            } elseif (isset($_GET['students_conducts'])) {
                require("student_conduct.php");
            } elseif (isset($_GET['export_conduct_sheet'])) {
                require("export_conduct.php");
            } elseif (isset($_GET['upload_conducts'])) {
                require("upload_conduct.php");
            } elseif (isset($_GET['view_conducts'])) {
                require("view_conducts.php");
            } elseif (isset($_GET['add_subjects'])) {
                require("add_subject.php");
            } elseif (isset($_GET['view_added_subjects'])) {
                require("view_subject.php");
            } elseif (isset($_GET['register_student_subject'])) {
                require("register_student_subject.php");
            } elseif (isset($_GET['view_registered_subjects'])) {
                require("view_registered_subjects.php");
            } elseif (isset($_GET['subject_number_specification'])) {
                require("specify_subject_number.php");
            } elseif (isset($_GET['specify_subjects_level'])) {
                require("specify_subjects_level.php");
            } elseif (isset($_GET['specify_senior'])) {
                require("specify_senior.php");
            } elseif (isset($_GET['update_subject_rank'])) {
                require("update_subject_rank.php");
            } elseif (isset($_GET['upload_result'])) {
                require("result_upload.php");
            } elseif (isset($_GET['admin_upload_ca'])) {
                require_once("admin_upload_ca.php");
            } elseif (isset($_GET['admin_upload_exam'])) {
                require_once("admin_upload_exam.php");
            } elseif (isset($_GET['excel_result_upload'])) {
                require("excel_result_upload.php");
            } elseif (isset($_GET['view_uploaded_results'])) {
                require("view_upload.php");
            } elseif (isset($_GET['issue_transfer'])) {
                require("issue_transfer.php");
            } elseif (isset($_GET['save_resumption'])) {
                require("save_resumption.php");
            } elseif (isset($_GET['view_resumption'])) {
                require("view_resumption.php");
            } elseif (isset($_GET['publish_result'])) {
                require("publish_result.php");
            } elseif (isset($_GET['view_published_result'])) {
                require("view_published_result.php");
            } elseif (isset($_GET['allocate_class_fee'])) {
                require("allocate_fees.php");
            } elseif (isset($_GET['fee_payment'])) {
                require("fee_payment.php");
            } elseif (isset($_GET['outstanding_fees'])) {
                require("outsatanding_bills.php");
            } elseif (isset($_GET['slip'])) {
                require("slip.php");
            } elseif (isset($_GET['add_admin'])) {
                require("add_admin.php");
            } elseif (isset($_GET['view_all_admin'])) {
                require("view_all_admin.php");
            } elseif (isset($_GET['add_principal'])) {
                require("add_principal.php");
            } elseif (isset($_GET['view_all_principals'])) {
                require("view_all_principals.php");
            } elseif (isset($_GET['add_accountant'])) {
                require("add_accountant.php");
            } elseif (isset($_GET['view_accountants'])) {
                require("view_accountants.php");
            } elseif (isset($_GET['add_teacher'])) {
                require("add_teacher.php");
            } elseif (isset($_GET['assign_class_to_teacher'])) {
                require("assign_class_to_teacher.php");
            } elseif (isset($_GET['view_teachers_portfolio'])) {
                require("view_teachers_portfolio.php");
            } elseif (isset($_GET['calendar'])) {
                require("calendar.php");
            } elseif (isset($_GET['staff_reset_password'])) {
                require("staff_reset_password.php");
            } elseif (isset($_GET['admin_check_result'])) {
                require_once("admin_check_result.php");
            } elseif (isset($_GET['view_class_broadsheet'])) {
                require_once("view_class_broadsheet.php");
            } elseif (isset($_GET['all_contact'])) {
                require("all_contact.php");
            } elseif (isset($_GET['settings'])) {
                require_once("settings.php");
            } elseif (isset($_GET['generate_pins'])) {
                require_once("generate_pins.php");
            } elseif (isset($_GET['view_uploaded_pins'])) {
                require_once("view_uploaded_pins.php");
            } elseif (isset($_GET['db_management'])) {
                require_once("db_management.php");
            } elseif (isset($_GET['sync_manager'])) {
                require_once("sync_manager.php");
            } elseif (isset($_GET['defaulters_tracker'])) {
                require_once("defaulters_tracker.php");
            } elseif (isset($_GET['elibrary'])) {
                require_once("elibrary.php");
            } elseif (isset($_GET['mailbox'])) {
                require_once("mailbox.php");
            } elseif (isset($_GET['qr_attendance'])) {
                require_once("qr_attendance.php");
            } elseif (isset($_GET['view_unused_pins'])) {
                require_once("view_unused_pins.php");
            } elseif (isset($_GET['view_used_pins'])) {
                require_once("view_used_pins.php");
            } elseif (isset($_GET['logout'])) {
                SESSION_UNSET(); // this unset every session and thus logs the user out
                redirect_to("../index.php");
            } else {
                require_once("dashboard.php");
            }
            ?>
            <!-- WhatsApp Chat Button -->
			<div class="whatsapp-button" id="toggleButton" onclick="toggleChat()">
				<svg id="whatsappIcon" xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 24 24" fill="white">
				    <path d="M19.05 4.91a9.91 9.91 0 0 0-14.04 0 9.9 9.9 0 0 0-2.9 7.04c0 1.74.45 3.44 1.31 4.94l-1.36 4.97 5.03-1.32a9.87 9.87 0 0 0 4.92 1.32c2.65 0 5.16-1.04 7.04-2.9a9.89 9.89 0 0 0 0-14.05zm-2.18 11.86c-.8.8-2.37 1.74-4.14 1.74-1.77 0-3.26-.67-4.42-1.83a6.28 6.28 0 0 1-1.83-4.42c0-1.77.94-3.34 1.74-4.14.45-.44.9-.52 1.35-.26.45.26 1.13 1.57 1.26 1.8.13.23.13.45 0 .7-.13.26-.2.45-.39.64-.2.19-.39.45-.58.58-.19.13-.26.32-.13.58.13.26.58.9 1.22 1.35s1.09.77 1.39.9c.26.13.45.13.58-.13.13-.26.64-.77.9-1.09.26-.32.45-.26.7-.13.26.13 1.55.83 1.8 1.03.26.13.26.39.26.64s-.58 1.48-.84 1.74z"/>
				</svg>
			</div>

			<!-- Chat Box -->
			<div class="chat-box" id="chatBox">
				<div class="chat-header">
				    <?php echo $school_initial;?> ADMIN
				    <button class="close-btn" onclick="toggleChat()">✖</button>
				</div>
				<div class="chat-body">
				    <div class="chat-message">How can I assist you?</div>
				</div>
				<div class="chat-footer">
				    <input type="text" id="chatInput" placeholder="Type a message...">
				    <button onclick="sendMessage()">➤</button>
				</div>
			</div>
        </div>
    </div>
    <script>
        let chatOpen = false;

        function toggleChat() {
            const chatBox = document.getElementById("chatBox");
            const whatsappIcon = document.getElementById("whatsappIcon");

            if (!chatOpen) {
                chatBox.style.display = "flex";
                whatsappIcon.innerHTML = '<path d="M6 19l12-12M6 7l12 12" stroke="white" stroke-width="3" stroke-linecap="round" stroke-linejoin="round"/>';
            } else {
                chatBox.style.display = "none";
                whatsappIcon.innerHTML = '<path d="M19.05 4.91a9.91 9.91 0 0 0-14.04 0 9.9 9.9 0 0 0-2.9 7.04c0 1.74.45 3.44 1.31 4.94l-1.36 4.97 5.03-1.32a9.87 9.87 0 0 0 4.92 1.32c2.65 0 5.16-1.04 7.04-2.9a9.89 9.89 0 0 0 0-14.05z"/>';
            }
            chatOpen = !chatOpen;
        }

        function sendMessage() {
            const inputField = document.getElementById("chatInput");
            const message = encodeURIComponent(inputField.value.trim());
            if (message) {
                window.open(`https://wa.me/<?php echo $admin_phone; ?>?text=${message}`, "_blank");
                inputField.value = "";
            }
        }

        document.getElementById("chatInput").addEventListener("keypress", function (event) {
            if (event.key === "Enter") sendMessage();
        });
    </script>
    <!-- Javascripts-->
    <script src="assets/lga/js/lga.js"></script>
    <!-- T13: Removed duplicate jQuery 2.x — keeping CDN 3.6.0 only -->
    <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
    <!-- T13: Removed: <script src="assets/js/jquery-2.1.4.min.js"></script> -->
    <script src="assets/js/bootstrap.min.js"></script>
    <script src="assets/js/plugins/pace.min.js"></script>
    <script src="assets/js/main.js"></script>
    <script src="assets/js/whatsapp.js"></script>
    <script type="text/javascript" src="assets/js/plugins/moment.min.js"></script>
    <script type="text/javascript" src="assets/js/plugins/jquery-ui.custom.min.js"></script>
    <script type="text/javascript" src="assets/js/plugins/jquery.dataTables.min.js"></script>
    <script type="text/javascript" src="assets/js/plugins/dataTables.bootstrap.min.html"></script>
    <script src="assets/Datepicker/bootstrap-datepicker.min.js"></script>
        <script type="text/javascript" src="assets/Datatables/dataTables.buttons.js"></script>
    <script type="text/javascript" src="assets/Datatables/buttons.dataTables.js"></script>
    <script type="text/javascript" src="assets/Datatables/buttons.print.min.js"></script>
    <script src="assets/SweetAlerts/sweetalert.js"></script>
    <!-- T14: Removed duplicate lga.js (already loaded at line 651) -->
    <!-- SweetAlert Trigger -->
    <?php
    require_once("all_scripts.php");
    ?>
</body>

</html>
