📁 File Manager
Editing:
/home/wvl7mof7402e/public_html/domain/domain-ledger.php
<?php /** * ============================================================ * CAPAPP IT SOLUTION * DOMAIN LEDGER / BALANCE SHEET * ============================================================ */ declare(strict_types=1); session_start(); require_once 'db.php'; /* ============================================================ LOGIN CHECK ============================================================ */ if (!isset($_SESSION['user_id'])) { header("Location: login.php"); exit; } /* ============================================================ HELPER ============================================================ */ function e($value): string { return htmlspecialchars((string)$value, ENT_QUOTES, 'UTF-8'); } function money($value): string { return '₹' . number_format((float)$value, 2); } /* ============================================================ PAGINATION ============================================================ */ $limit = 10; $page = isset($_GET['page']) ? (int)$_GET['page'] : 1; $page = max(1, $page); $start = ($page - 1) * $limit; /* ============================================================ TOTAL LEDGER RECORDS ============================================================ */ $countSql = " SELECT COUNT(*) AS total FROM ( SELECT dc.id FROM domain_charges dc UNION ALL SELECT p.id FROM payments p ) AS ledger_count "; $countRes = mysqli_query($conn, $countSql); $totalRows = 0; if ($countRes) { $countRow = mysqli_fetch_assoc($countRes); $totalRows = (int)($countRow['total'] ?? 0); } $totalPages = max(1, (int)ceil($totalRows / $limit)); if ($page > $totalPages) { $page = $totalPages; $start = ($page - 1) * $limit; } /* ============================================================ LEDGER QUERY ============================================================ */ $sql = " SELECT * FROM ( /* ======================================================== DOMAIN CHARGES = DEBIT ======================================================== */ SELECT dc.created_at AS dt, d.domain_name, COALESCE( ( SELECT i.client_name FROM invoices i WHERE i.domain_name = d.domain_name ORDER BY i.id DESC LIMIT 1 ), '-' ) AS client_name, CONCAT(dc.charge_type, ' Charge') AS description, CAST(dc.total_amount AS DECIMAL(15,2)) AS debit, CAST(0 AS DECIMAL(15,2)) AS credit FROM domain_charges dc INNER JOIN domains d ON d.id = dc.domain_id UNION ALL /* ======================================================== PAYMENTS = CREDIT ======================================================== */ SELECT p.payment_date AS dt, d.domain_name, COALESCE( ( SELECT i.client_name FROM invoices i WHERE i.domain_name = d.domain_name ORDER BY i.id DESC LIMIT 1 ), p.client_name, '-' ) AS client_name, COALESCE(p.description, 'Payment Received') AS description, CAST(0 AS DECIMAL(15,2)) AS debit, CAST(p.amount AS DECIMAL(15,2)) AS credit FROM payments p INNER JOIN domains d ON d.id = p.domain_id ) AS ledger ORDER BY dt DESC LIMIT $start, $limit "; $res = mysqli_query($conn, $sql); /* ============================================================ SUMMARY ============================================================ */ $totalDebit = 0; $totalCredit = 0; $closingBalance = 0; $rows = []; if ($res) { while ($row = mysqli_fetch_assoc($res)) { $debit = (float)($row['debit'] ?? 0); $credit = (float)($row['credit'] ?? 0); $totalDebit += $debit; $totalCredit += $credit; $rows[] = $row; } } $closingBalance = $totalDebit - $totalCredit; /* ============================================================ CURRENT PAGE BALANCE ============================================================ */ $runningBalance = 0; /* ============================================================ PAGINATION RANGE ============================================================ */ $paginationStart = max(1, $page - 2); $paginationEnd = min($totalPages, $page + 2); ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Domain Ledger | CAPAPP</title> <!-- Bootstrap --> <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet"> <!-- Bootstrap Icons --> <link href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.css" rel="stylesheet"> <style> /* ============================================================ ROOT ============================================================ */ :root{ --primary:#2563eb; --primary-dark:#1d4ed8; --navy:#0f172a; --navy-2:#1e293b; --bg:#eef4ff; --text:#0f172a; --muted:#64748b; --success:#16a34a; --danger:#dc2626; --warning:#f59e0b; --white:#ffffff; --border:#e5e7eb; --shadow: 0 10px 35px rgba(15,23,42,.07); --shadow-lg: 0 20px 50px rgba(15,23,42,.12); } /* ============================================================ RESET ============================================================ */ *{ margin:0; padding:0; box-sizing:border-box; } html{ scroll-behavior:smooth; } body{ font-family: "Segoe UI", Arial, sans-serif; background:var(--bg); color:var(--text); min-height:100vh; } /* ============================================================ SIDEBAR ============================================================ */ .sidebar{ position:fixed; left:0; top:0; width:260px; height:100vh; background: linear-gradient( 180deg, #0f172a 0%, #172554 55%, #1e293b 100% ); padding:20px 15px; z-index:1000; overflow-y:auto; transition:.3s ease; box-shadow: 10px 0 35px rgba(15,23,42,.12); } /* Sidebar scrollbar */ .sidebar::-webkit-scrollbar{ width:5px; } .sidebar::-webkit-scrollbar-thumb{ background:#334155; border-radius:10px; } /* ============================================================ LOGO ============================================================ */ .logo-box{ text-align:center; padding: 10px 8px 24px; margin-bottom:10px; border-bottom: 1px solid rgba(255,255,255,.08); } .logo-icon{ width:58px; height:58px; margin:0 auto 10px; border-radius:18px; display:flex; align-items:center; justify-content:center; color:#fff; font-size:28px; background: linear-gradient( 135deg, #2563eb, #7c3aed ); box-shadow: 0 12px 25px rgba(37,99,235,.35); } .logo-box h2{ color:#fff; font-size:25px; font-weight:800; letter-spacing:.5px; margin-bottom:3px; } .logo-box p{ color:#94a3b8; font-size:12px; margin:0; } /* ============================================================ MENU ============================================================ */ .menu{ margin-top:18px; } .menu-title{ color:#64748b; text-transform:uppercase; font-size:10px; font-weight:800; letter-spacing:1.5px; padding: 8px 14px 10px; } .menu a{ display:flex; align-items:center; gap:13px; color:#cbd5e1; text-decoration:none; padding: 13px 14px; border-radius:13px; margin-bottom:6px; font-size:14px; font-weight:600; transition:.25s ease; position:relative; } .menu a i{ width:22px; font-size:19px; text-align:center; flex-shrink:0; } .menu a:hover{ background: rgba(37,99,235,.18); color:#fff; transform: translateX(3px); } .menu a.active{ background: linear-gradient( 135deg, #2563eb, #1d4ed8 ); color:#fff; box-shadow: 0 8px 20px rgba(37,99,235,.25); } .menu a.active::before{ content:""; position:absolute; left:-15px; top:12px; width:4px; height:28px; background:#60a5fa; border-radius:0 5px 5px 0; } /* ============================================================ MAIN ============================================================ */ .main{ margin-left:260px; padding:25px; min-height:100vh; transition:.3s ease; } /* ============================================================ TOPBAR ============================================================ */ .topbar{ background:#fff; border: 1px solid rgba(226,232,240,.8); border-radius:20px; padding: 15px 20px; margin-bottom:25px; display:flex; align-items:center; justify-content:space-between; gap:15px; box-shadow:var(--shadow); } .topbar-left{ display:flex; align-items:center; gap:14px; } .menu-btn{ width:42px; height:42px; border:0; border-radius:12px; background:#eff6ff; color:var(--primary); display:none; align-items:center; justify-content:center; font-size:22px; cursor:pointer; } .page-icon{ width:48px; height:48px; border-radius:14px; display:flex; align-items:center; justify-content:center; background: linear-gradient( 135deg, #dbeafe, #eff6ff ); color:var(--primary); font-size:23px; } .topbar h1{ font-size:21px; font-weight:800; margin:0; color:var(--navy); } .topbar-subtitle{ font-size:12px; color:var(--muted); margin-top:2px; } .admin-profile{ display:flex; align-items:center; gap:10px; } .admin-avatar{ width:42px; height:42px; border-radius:50%; background: linear-gradient( 135deg, #2563eb, #7c3aed ); color:#fff; display:flex; align-items:center; justify-content:center; font-size:19px; box-shadow: 0 7px 18px rgba(37,99,235,.25); } .admin-name{ font-size:13px; font-weight:700; color:var(--navy); } .admin-role{ display:block; font-size:11px; color:var(--muted); } /* ============================================================ SUMMARY CARDS ============================================================ */ .summary-grid{ display:grid; grid-template-columns: repeat(3,1fr); gap:18px; margin-bottom:24px; } .summary-card{ position:relative; overflow:hidden; background:#fff; border-radius:20px; padding:22px; min-height:145px; box-shadow:var(--shadow); border: 1px solid rgba(226,232,240,.8); transition:.3s ease; } .summary-card:hover{ transform: translateY(-4px); box-shadow:var(--shadow-lg); } .summary-card::after{ content:""; position:absolute; right:-35px; bottom:-45px; width:120px; height:120px; border-radius:50%; background: currentColor; opacity:.05; } .summary-top{ display:flex; align-items:center; justify-content:space-between; } .summary-label{ color:var(--muted); font-size:13px; font-weight:600; } .summary-icon{ width:45px; height:45px; border-radius:13px; display:flex; align-items:center; justify-content:center; font-size:21px; } .summary-card h2{ font-size:27px; font-weight:800; margin-top:17px; margin-bottom:0; color:var(--navy); } .summary-note{ font-size:11px; color:var(--muted); margin-top:4px; } /* Total */ .card-total{ color:#2563eb; } .card-total .summary-icon{ background:#eff6ff; color:#2563eb; } /* Credit */ .card-credit{ color:#16a34a; } .card-credit .summary-icon{ background:#ecfdf5; color:#16a34a; } /* Balance */ .card-balance{ color:#f59e0b; } .card-balance .summary-icon{ background:#fffbeb; color:#d97706; } /* ============================================================ LEDGER CARD ============================================================ */ .ledger-card{ background:#fff; border-radius:22px; box-shadow:var(--shadow); border: 1px solid rgba(226,232,240,.8); overflow:hidden; } /* ============================================================ CARD HEADER ============================================================ */ .ledger-header{ padding: 20px 22px; display:flex; align-items:center; justify-content:space-between; gap:15px; border-bottom: 1px solid #eef2f7; } .ledger-title{ display:flex; align-items:center; gap:12px; } .ledger-title-icon{ width:42px; height:42px; border-radius:12px; background:#eff6ff; color:var(--primary); display:flex; align-items:center; justify-content:center; font-size:20px; } .ledger-title h3{ font-size:17px; font-weight:800; margin:0; } .ledger-title p{ font-size:11px; color:var(--muted); margin:2px 0 0; } .record-badge{ background:#f1f5f9; color:#475569; padding: 7px 12px; border-radius:20px; font-size:11px; font-weight:700; } /* ============================================================ TABLE ============================================================ */ .table-wrap{ width:100%; overflow-x:auto; } .ledger-table{ width:100%; min-width:850px; border-collapse:separate; border-spacing:0; } .ledger-table thead th{ background:#f8fafc; color:#64748b; font-size:11px; text-transform:uppercase; letter-spacing:.5px; font-weight:800; padding: 14px 16px; border-bottom: 1px solid #e2e8f0; white-space:nowrap; } .ledger-table tbody td{ padding: 15px 16px; border-bottom: 1px solid #f1f5f9; font-size:13px; color:#334155; vertical-align:middle; } .ledger-table tbody tr{ transition:.2s ease; } .ledger-table tbody tr:hover{ background:#f8fbff; } .date-box{ display:flex; align-items:center; gap:8px; white-space:nowrap; color:#64748b; } .date-box i{ color:#2563eb; font-size:15px; } .domain-name{ font-weight:700; color:#0f172a; max-width:190px; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; } .client-name{ font-weight:600; color:#334155; } .description-box{ display:flex; align-items:center; gap:8px; } .description-icon{ width:30px; height:30px; border-radius:9px; background:#f1f5f9; display:flex; align-items:center; justify-content:center; color:#64748b; font-size:14px; } .debit{ color:#dc2626 !important; font-weight:800; } .credit{ color:#16a34a !important; font-weight:800; } .amount-empty{ color:#cbd5e1; font-weight:600; } .balance-pill{ display:inline-flex; align-items:center; padding: 6px 10px; border-radius:9px; background:#f8fafc; color:#0f172a; font-weight:800; white-space:nowrap; } /* ============================================================ EMPTY STATE ============================================================ */ .empty-state{ text-align:center; padding: 65px 20px; } .empty-icon{ width:70px; height:70px; border-radius:20px; margin:0 auto 15px; background:#eff6ff; color:#2563eb; display:flex; align-items:center; justify-content:center; font-size:30px; } .empty-state h4{ font-size:18px; font-weight:800; color:#0f172a; margin-bottom:5px; } .empty-state p{ color:#64748b; font-size:13px; margin:0; } /* ============================================================ FOOTER SUMMARY ============================================================ */ .ledger-footer{ display:flex; align-items:center; justify-content:flex-end; gap:12px; padding: 17px 22px; background:#f8fafc; border-top: 1px solid #e2e8f0; } .footer-total{ display:flex; align-items:center; gap:8px; font-size:13px; color:#64748b; } .footer-total strong{ color:#0f172a; font-size:15px; } /* ============================================================ PAGINATION ============================================================ */ .pagination-wrap{ display:flex; align-items:center; justify-content:space-between; gap:15px; margin-top:20px; flex-wrap:wrap; } .pagination-info{ color:#64748b; font-size:12px; } .pagination{ margin:0; gap:5px; } .pagination .page-link{ border:0; width:38px; height:38px; border-radius:10px !important; display:flex; align-items:center; justify-content:center; color:#475569; font-size:13px; font-weight:700; background:#fff; box-shadow: 0 3px 10px rgba(15,23,42,.05); } .pagination .page-link:hover{ background:#eff6ff; color:#2563eb; } .pagination .active .page-link{ background:#2563eb; color:#fff; box-shadow: 0 7px 15px rgba(37,99,235,.25); } .pagination .disabled .page-link{ color:#cbd5e1; background:#f8fafc; cursor:not-allowed; } /* ============================================================ OVERLAY ============================================================ */ .sidebar-overlay{ display:none; position:fixed; inset:0; background: rgba(15,23,42,.55); z-index:999; backdrop-filter:blur(2px); } /* ============================================================ MOBILE ============================================================ */ @media(max-width:991px){ .sidebar{ left:-100%; width:280px; } .sidebar.active{ left:0; } .sidebar-overlay.active{ display:block; } .main{ margin-left:0; padding:15px; } .menu-btn{ display:flex; } .summary-grid{ grid-template-columns: repeat(2,1fr); } .topbar{ padding:14px 16px; } .admin-name, .admin-role{ display:none; } } @media(max-width:600px){ .main{ padding:10px; } .topbar{ border-radius:15px; margin-bottom:15px; } .page-icon{ width:40px; height:40px; font-size:19px; } .topbar h1{ font-size:17px; } .topbar-subtitle{ font-size:10px; } .admin-avatar{ width:38px; height:38px; font-size:17px; } .summary-grid{ grid-template-columns:1fr; gap:12px; } .summary-card{ min-height:125px; padding:18px; } .summary-card h2{ font-size:24px; } .ledger-card{ border-radius:16px; } .ledger-header{ padding:16px; align-items:flex-start; } .record-badge{ display:none; } .ledger-footer{ padding:14px 16px; justify-content:center; } .pagination-wrap{ justify-content:center; flex-direction:column; } .pagination{ flex-wrap:wrap; justify-content:center; } } /* ============================================================ PRINT ============================================================ */ @media print{ .sidebar, .topbar, .pagination-wrap{ display:none !important; } .main{ margin:0; padding:0; } body{ background:#fff; } .summary-grid{ display:none; } .ledger-card{ box-shadow:none; border:1px solid #ddd; } } </style> </head> <body> <!-- ========================================================= SIDEBAR ========================================================= --> <div class="sidebar" id="sidebar"> <div class="logo-box"> <div class="logo-icon"> <i class="bi bi-grid-1x2-fill"></i> </div> <h2>CAPAPP</h2> <p>Domain Management Panel</p> </div> <div class="menu"> <div class="menu-title"> Main Menu </div> <a href="dashboard.php"> <i class="bi bi-speedometer2"></i> <span>Dashboard</span> </a> <a href="index.php"> <i class="bi bi-globe2"></i> <span>All Domains</span> </a> <a href="add-domain.php"> <i class="bi bi-plus-circle"></i> <span>Add Domain</span> </a> <div class="menu-title mt-3"> Finance </div> <a href="domain-charges.php"> <i class="bi bi-cash-stack"></i> <span>Domain Charges</span> </a> <a href="add-payment.php"> <i class="bi bi-wallet2"></i> <span>Receive Payment</span> </a> <a href="domain-ledger.php" class="active"> <i class="bi bi-journal-text"></i> <span>Balance Sheet</span> </a> <a href="bill.php"> <i class="bi bi-receipt"></i> <span>Generate Invoice</span> </a> <div class="menu-title mt-3"> Management </div> <a href="expired-domains.php"> <i class="bi bi-clock-history"></i> <span>Expired Domains</span> </a> <a href="logout.php"> <i class="bi bi-box-arrow-right"></i> <span>Logout</span> </a> </div> </div> <!-- MOBILE OVERLAY --> <div class="sidebar-overlay" id="sidebarOverlay" onclick="closeMenu()"> </div> <!-- ========================================================= MAIN ========================================================= --> <div class="main"> <!-- TOPBAR --> <div class="topbar"> <div class="topbar-left"> <button type="button" class="menu-btn" onclick="toggleMenu()"> <i class="bi bi-list"></i> </button> <div class="page-icon"> <i class="bi bi-journal-check"></i> </div> <div> <h1>Domain Ledger</h1> <div class="topbar-subtitle"> Complete domain charges & payment balance </div> </div> </div> <div class="admin-profile"> <div class="text-end"> <div class="admin-name"> Admin </div> <span class="admin-role"> Administrator </span> </div> <div class="admin-avatar"> <i class="bi bi-person-fill"></i> </div> </div> </div> <!-- ===================================================== SUMMARY ====================================================== --> <div class="summary-grid"> <!-- TOTAL DEBIT --> <div class="summary-card card-total"> <div class="summary-top"> <div> <div class="summary-label"> Total Charges </div> <h2> <?= money($totalDebit) ?> </h2> <div class="summary-note"> Total domain charges </div> </div> <div class="summary-icon"> <i class="bi bi-arrow-down-circle"></i> </div> </div> </div> <!-- TOTAL CREDIT --> <div class="summary-card card-credit"> <div class="summary-top"> <div> <div class="summary-label"> Total Received </div> <h2> <?= money($totalCredit) ?> </h2> <div class="summary-note"> Payments received </div> </div> <div class="summary-icon"> <i class="bi bi-arrow-up-circle"></i> </div> </div> </div> <!-- BALANCE --> <div class="summary-card card-balance"> <div class="summary-top"> <div> <div class="summary-label"> Outstanding Balance </div> <h2> <?= money($closingBalance) ?> </h2> <div class="summary-note"> Charges minus payments </div> </div> <div class="summary-icon"> <i class="bi bi-wallet2"></i> </div> </div> </div> </div> <!-- ===================================================== LEDGER CARD ====================================================== --> <div class="ledger-card"> <!-- HEADER --> <div class="ledger-header"> <div class="ledger-title"> <div class="ledger-title-icon"> <i class="bi bi-list-columns-reverse"></i> </div> <div> <h3> Transaction Ledger </h3> <p> Domain charges and received payments </p> </div> </div> <div class="record-badge"> <i class="bi bi-file-earmark-text me-1"></i> <?= number_format($totalRows) ?> Records </div> </div> <!-- ================================================= TABLE ================================================== --> <?php if (count($rows) > 0): ?> <div class="table-wrap"> <table class="ledger-table"> <thead> <tr> <th> Date </th> <th> Domain </th> <th> Client </th> <th> Description </th> <th> Debit </th> <th> Credit </th> <th> Balance </th> </tr> </thead> <tbody> <?php foreach ($rows as $r): ?> <?php $debit = (float)($r['debit'] ?? 0); $credit = (float)($r['credit'] ?? 0); $runningBalance += $debit; $runningBalance -= $credit; ?> <tr> <!-- DATE --> <td> <div class="date-box"> <i class="bi bi-calendar3"></i> <span> <?= e( date( "d M Y", strtotime( (string)$r['dt'] ) ) ) ?> </span> </div> </td> <!-- DOMAIN --> <td> <div class="domain-name" title="<?= e($r['domain_name']) ?>"> <i class="bi bi-globe2 text-primary me-1"></i> <?= e($r['domain_name']) ?> </div> </td> <!-- CLIENT --> <td> <div class="client-name"> <?= e($r['client_name']) ?> </div> </td> <!-- DESCRIPTION --> <td> <div class="description-box"> <div class="description-icon"> <?php if ($credit > 0): ?> <i class="bi bi-wallet2"></i> <?php else: ?> <i class="bi bi-receipt"></i> <?php endif; ?> </div> <span> <?= e($r['description']) ?> </span> </div> </td> <!-- DEBIT --> <td class="debit"> <?php if ($debit > 0): ?> -<?= money($debit) ?> <?php else: ?> <span class="amount-empty"> — </span> <?php endif; ?> </td> <!-- CREDIT --> <td class="credit"> <?php if ($credit > 0): ?> +<?= money($credit) ?> <?php else: ?> <span class="amount-empty"> — </span> <?php endif; ?> </td> <!-- BALANCE --> <td> <span class="balance-pill"> <?= money($runningBalance) ?> </span> </td> </tr> <?php endforeach; ?> </tbody> </table> </div> <!-- FOOTER --> <div class="ledger-footer"> <div class="footer-total"> <i class="bi bi-calculator"></i> Page Total: <strong> <?= money($totalDebit - $totalCredit) ?> </strong> </div> </div> <?php else: ?> <!-- EMPTY --> <div class="empty-state"> <div class="empty-icon"> <i class="bi bi-journal-x"></i> </div> <h4> No Ledger Records Found </h4> <p> Domain charges and received payments will appear here. </p> </div> <?php endif; ?> </div> <!-- ===================================================== PAGINATION ====================================================== --> <?php if ($totalPages > 1): ?> <div class="pagination-wrap"> <div class="pagination-info"> Showing <strong> <?= min($start + 1, $totalRows) ?> </strong> – <strong> <?= min($start + $limit, $totalRows) ?> </strong> of <strong> <?= number_format($totalRows) ?> </strong> records </div> <nav> <ul class="pagination"> <!-- PREVIOUS --> <li class="page-item <?= ($page <= 1) ? 'disabled' : '' ?>"> <?php if ($page > 1): ?> <a class="page-link" href="?page=<?= $page - 1 ?>" aria-label="Previous"> <i class="bi bi-chevron-left"></i> </a> <?php else: ?> <span class="page-link"> <i class="bi bi-chevron-left"></i> </span> <?php endif; ?> </li> <!-- FIRST --> <?php if ($paginationStart > 1): ?> <li class="page-item"> <a class="page-link" href="?page=1"> 1 </a> </li> <?php if ($paginationStart > 2): ?> <li class="page-item disabled"> <span class="page-link"> … </span> </li> <?php endif; ?> <?php endif; ?> <!-- PAGE NUMBERS --> <?php for ( $i = $paginationStart; $i <= $paginationEnd; $i++ ): ?> <li class="page-item <?= ($i === $page) ? 'active' : '' ?>"> <a class="page-link" href="?page=<?= $i ?>"> <?= $i ?> </a> </li> <?php endfor; ?> <!-- LAST --> <?php if ($paginationEnd < $totalPages): ?> <?php if ($paginationEnd < $totalPages - 1): ?> <li class="page-item disabled"> <span class="page-link"> … </span> </li> <?php endif; ?> <li class="page-item"> <a class="page-link" href="?page=<?= $totalPages ?>"> <?= $totalPages ?> </a> </li> <?php endif; ?> <!-- NEXT --> <li class="page-item <?= ($page >= $totalPages) ? 'disabled' : '' ?>"> <?php if ($page < $totalPages): ?> <a class="page-link" href="?page=<?= $page + 1 ?>" aria-label="Next"> <i class="bi bi-chevron-right"></i> </a> <?php else: ?> <span class="page-link"> <i class="bi bi-chevron-right"></i> </span> <?php endif; ?> </li> </ul> </nav> </div> <?php endif; ?> </div> <!-- ========================================================= JAVASCRIPT ========================================================= --> <script> function toggleMenu(){ const sidebar = document.getElementById('sidebar'); const overlay = document.getElementById('sidebarOverlay'); sidebar.classList.toggle('active'); overlay.classList.toggle('active'); } function closeMenu(){ const sidebar = document.getElementById('sidebar'); const overlay = document.getElementById('sidebarOverlay'); sidebar.classList.remove('active'); overlay.classList.remove('active'); } /* Close mobile menu after clicking link */ document.querySelectorAll('.sidebar a').forEach(function(link){ link.addEventListener('click', function(){ if(window.innerWidth <= 991){ closeMenu(); } }); }); /* Escape key */ document.addEventListener('keydown', function(e){ if(e.key === 'Escape'){ closeMenu(); } }); </script> </body> </html>
Save
Cancel