Add online menu management, modernized and hardened

Adds a public menu page (menu.php) and an admin CRUD interface
(admin/menu.php + admin/menu.js) backed by new menu_categories and
menu_items tables, replacing the "menu lives on Facebook" placeholder
on the homepage.

The admin JS/PHP came out of an AI-assisted pass that used outdated
JS (var, .then() chains, string-built HTML) and had some rough edges
security-wise, so this also:

- Rewrites the admin JS to modern ES (const/let, async/await,
  template literals, dataset API) and splits it out of admin/menu.php
  into admin/menu.js for proper separation of concerns
- Adds declare(strict_types=1) and PHP 8 match-based action dispatch
  in place of an if-chain
- Validates category_id/item_id/category_id server-side before use,
  so a bad ID returns a clean JSON error instead of an uncaught
  PDOException or a null item breaking the client
- Rejects non-string POST fields instead of crashing trim() on them
- Replaces the category-save handler's full-page location.reload()
  with in-place DOM updates (panel insert/update, resort by
  sort_order, keep the item modal's category dropdown in sync), so
  every admin action is now AJAX with no reload
- Sets data-name/data-desc via dataset assignment rather than string-
  interpolating them into an HTML attribute, closing a stored-XSS
  path through the category name/description fields

Removes seed-menu.php, a leftover stub with no working code left in
it after the AI's one-time seeding run.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
David DyerandClaude Sonnet 5 committed 2026-08-30 21:35:22 -04:00
1 parent 21ad6c31cf
commit f1bbf59548
8 files changed
+1382 -27

No files matched your search

+206 -1
View File
@@ -764,7 +764,7 @@
/* menu band */
.menu-band .container {
max-width: 47.5rem;
max-width: 60rem;
text-align: center;
}
@@ -1236,4 +1236,209 @@
.empty-state p {
font-size: 0.95rem;
margin-bottom: 1.25rem;
}
/* admin nav links */
.admin-nav-links {
display: flex;
gap: 1.25rem;
align-items: center;
}
.admin-nav-links a {
font-family: var(--font-mono);
font-size: 0.82rem;
letter-spacing: 0.05em;
text-decoration: none;
color: var(--ink-muted);
padding: 0.35rem 0.65rem;
border-radius: 0.125rem;
transition: color .15s ease, background .15s ease;
}
.admin-nav-links a:hover {
color: var(--gold-bright);
background: var(--surface);
}
.admin-nav-links a.active {
color: var(--gold-bright);
background: var(--surface);
border-bottom: 1px solid var(--gold);
}
/* public online menu section */
.menu-grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(20rem, 1fr));
gap: 2.5rem;
margin-top: 3rem;
text-align: left;
}
.menu-category {
background: var(--surface);
border: 1px solid var(--rule);
border-radius: 0.25rem;
padding: 2rem;
}
.menu-category-header {
margin-bottom: 1.5rem;
padding-bottom: 0.75rem;
border-bottom: 1px solid var(--rule);
}
.menu-category-header h3 {
font-size: 1.45rem;
color: var(--gold-bright);
}
.menu-category-header p {
margin-top: 0.35rem;
font-size: 0.88rem;
color: var(--ink-muted);
}
.menu-items-list {
display: flex;
flex-direction: column;
gap: 1.4rem;
}
.menu-item-row {
display: flex;
flex-direction: column;
gap: 0.25rem;
}
.menu-item-top {
display: flex;
justify-content: space-between;
align-items: baseline;
gap: 0.75rem;
}
.menu-item-name {
font-family: var(--font-serif);
font-weight: 600;
font-size: 1.05rem;
color: var(--ink);
display: inline-flex;
align-items: center;
gap: 0.5rem;
flex-wrap: wrap;
}
.menu-item-price {
font-family: var(--font-mono);
font-weight: 500;
font-size: 0.95rem;
color: var(--gold-bright);
white-space: nowrap;
}
.menu-item-desc {
font-size: 0.88rem;
color: var(--ink-muted);
line-height: 1.45;
}
.menu-item-badge {
font-family: var(--font-mono);
font-size: 0.65rem;
letter-spacing: 0.08em;
text-transform: uppercase;
padding: 0.15rem 0.45rem;
border-radius: 0.125rem;
background: rgba(201, 163, 92, 0.15);
border: 1px solid var(--gold-dim);
color: var(--gold-bright);
font-weight: normal;
}
/* ---------- admin modal dialogs ---------- */
.admin-modal-backdrop {
position: fixed;
inset: 0;
background: rgba(15, 12, 10, 0.8);
backdrop-filter: blur(0.25rem);
display: flex;
align-items: center;
justify-content: center;
z-index: 1000;
padding: 1.5rem;
opacity: 0;
pointer-events: none;
transition: opacity .2s ease;
}
.admin-modal-backdrop.is-open {
opacity: 1;
pointer-events: auto;
}
.admin-modal {
background: var(--surface);
border: 1px solid var(--rule);
border-radius: 0.25rem;
width: 100%;
max-width: 36rem;
max-height: 90vh;
overflow-y: auto;
padding: 2rem;
box-shadow: 0 1.5rem 3rem rgba(0, 0, 0, 0.6);
transform: translateY(0.75rem);
transition: transform .2s ease;
}
.admin-modal-backdrop.is-open .admin-modal {
transform: translateY(0);
}
.modal-header {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 1.5rem;
padding-bottom: 0.75rem;
border-bottom: 1px solid var(--rule);
}
.modal-header h2 {
font-size: 1.35rem;
color: var(--gold-bright);
margin: 0;
}
.modal-close {
background: transparent;
border: none;
color: var(--ink-muted);
font-size: 1.5rem;
cursor: pointer;
padding: 0.25rem;
line-height: 1;
transition: color .15s ease;
}
.modal-close:hover {
color: var(--gold-bright);
}
.admin-toolbar {
display: flex;
justify-content: flex-start;
gap: 0.75rem;
align-items: center;
margin-bottom: 2rem;
}
/* menu page specific headers & spacing */
.menu-page-header {
padding-block: 4.5rem 2.5rem;
}
.menu-page-content {
padding-bottom: 5.5rem;
}