index.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421
  1. <?php
  2. // index.php – Activity selection page
  3. require_once __DIR__ . '/db.php';
  4. $pdo = get_pdo();
  5. // Fetch all groups with their activities
  6. $sql = "
  7. SELECT
  8. ag.groupID,
  9. ag.groupName AS groupName,
  10. ag.sortOrder AS groupSort,
  11. a.activityID,
  12. a.activityName,
  13. a.sortOrder AS actSort,
  14. a.hidden
  15. FROM activity_groups ag
  16. JOIN activities a ON a.groupID = ag.groupID
  17. ORDER BY ag.sortOrder, ag.groupID, a.sortOrder, a.activityID
  18. ";
  19. $rows = $pdo->query($sql)->fetchAll();
  20. // Group by category. Hidden activities are easter eggs: they are rendered into
  21. // a section that stays hidden until the page script reveals it.
  22. $byVisibility = ['visible' => [], 'secret' => []];
  23. foreach ($rows as $row) {
  24. $gid = $row['groupID'];
  25. $vis = $row['hidden'] ? 'secret' : 'visible';
  26. if (!isset($byVisibility[$vis][$gid])) {
  27. $byVisibility[$vis][$gid] = ['name' => $row['groupName'], 'activities' => []];
  28. }
  29. $byVisibility[$vis][$gid]['activities'][] = [
  30. 'id' => $row['activityID'],
  31. 'name' => $row['activityName'],
  32. ];
  33. }
  34. $groups = $byVisibility['visible'];
  35. $secretGroups = $byVisibility['secret'];
  36. function render_activity_group(array $group): void { ?>
  37. <div class="activity-group">
  38. <div class="section-title"><?= htmlspecialchars($group['name']) ?></div>
  39. <div class="activity-grid">
  40. <?php foreach ($group['activities'] as $act): ?>
  41. <div class="activity-card">
  42. <input type="checkbox" name="aID[]"
  43. id="act_<?= $act['id'] ?>"
  44. value="<?= (int)$act['id'] ?>"
  45. onchange="updateCount()">
  46. <label for="act_<?= $act['id'] ?>">
  47. <span class="check-icon">
  48. <svg width="10" height="8" viewBox="0 0 10 8" fill="none">
  49. <path d="M1 4l3 3 5-6" stroke="#0f1117" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
  50. </svg>
  51. </span>
  52. <?= htmlspecialchars($act['name']) ?>
  53. </label>
  54. </div>
  55. <?php endforeach; ?>
  56. </div>
  57. </div>
  58. <?php }
  59. ?>
  60. <!DOCTYPE html>
  61. <html lang="en">
  62. <head>
  63. <meta charset="UTF-8">
  64. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  65. <title>PackIt – Choose Your Activities</title>
  66. <link rel="manifest" href="/manifest.webmanifest">
  67. <meta name="theme-color" content="#e8c547">
  68. <link rel="icon" type="image/png" sizes="192x192" href="/img/icon-192.png">
  69. <link rel="preconnect" href="https://fonts.googleapis.com">
  70. <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
  71. <link href="https://fonts.googleapis.com/css2?family=Bebas+Neue&family=DM+Sans:wght@300;400;500;600&display=swap" rel="stylesheet">
  72. <style>
  73. :root {
  74. --bg: #0f1117;
  75. --surface: #181c27;
  76. --border: #2a2f3f;
  77. --accent: #e8c547;
  78. --accent2: #4fd1c5;
  79. --text: #e8eaf0;
  80. --muted: #7a8099;
  81. --danger: #e05555;
  82. --radius: 10px;
  83. --gap: 1.5rem;
  84. }
  85. *, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
  86. body {
  87. background: var(--bg);
  88. color: var(--text);
  89. font-family: 'DM Sans', sans-serif;
  90. font-size: 15px;
  91. min-height: 100vh;
  92. display: flex;
  93. flex-direction: column;
  94. }
  95. /* ---------- header ---------- */
  96. header {
  97. padding: 2.5rem var(--gap) 1.5rem;
  98. border-bottom: 1px solid var(--border);
  99. display: flex;
  100. align-items: flex-end;
  101. gap: 1rem;
  102. position: relative;
  103. overflow: hidden;
  104. }
  105. header::before {
  106. content: '';
  107. position: absolute;
  108. inset: 0;
  109. background: radial-gradient(ellipse 60% 80% at 10% 50%, rgba(232,197,71,.08) 0%, transparent 70%);
  110. pointer-events: none;
  111. }
  112. .logo {
  113. font-family: 'Bebas Neue', sans-serif;
  114. font-size: clamp(2.8rem, 6vw, 4.5rem);
  115. letter-spacing: .04em;
  116. color: var(--accent);
  117. line-height: 1;
  118. position: relative;
  119. }
  120. .tagline {
  121. font-size: .85rem;
  122. color: var(--muted);
  123. letter-spacing: .08em;
  124. text-transform: uppercase;
  125. padding-bottom: .25rem;
  126. position: relative;
  127. }
  128. /* ---------- main layout ---------- */
  129. main {
  130. flex: 1;
  131. max-width: 760px;
  132. width: 100%;
  133. margin: 0 auto;
  134. padding: 2.5rem var(--gap) 6rem;
  135. }
  136. .section-title {
  137. font-family: 'Bebas Neue', sans-serif;
  138. font-size: 1.15rem;
  139. letter-spacing: .12em;
  140. color: var(--accent2);
  141. text-transform: uppercase;
  142. margin-bottom: .75rem;
  143. display: flex;
  144. align-items: center;
  145. gap: .6rem;
  146. }
  147. .section-title::after {
  148. content: '';
  149. flex: 1;
  150. height: 1px;
  151. background: var(--border);
  152. }
  153. .activity-group {
  154. margin-bottom: 2rem;
  155. }
  156. .activity-grid {
  157. display: grid;
  158. grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  159. gap: .6rem;
  160. }
  161. /* Custom checkbox card */
  162. .activity-card {
  163. position: relative;
  164. }
  165. .activity-card input[type="checkbox"] {
  166. position: absolute;
  167. opacity: 0;
  168. width: 0; height: 0;
  169. }
  170. .activity-card label {
  171. display: flex;
  172. align-items: center;
  173. gap: .7rem;
  174. padding: .7rem 1rem;
  175. background: var(--surface);
  176. border: 1.5px solid var(--border);
  177. border-radius: var(--radius);
  178. cursor: pointer;
  179. transition: border-color .15s, background .15s, transform .1s;
  180. user-select: none;
  181. }
  182. .check-icon {
  183. width: 18px; height: 18px;
  184. border: 1.5px solid var(--border);
  185. border-radius: 5px;
  186. flex-shrink: 0;
  187. display: flex; align-items: center; justify-content: center;
  188. transition: background .15s, border-color .15s;
  189. background: var(--bg);
  190. }
  191. .check-icon svg { display: none; }
  192. .activity-card input:checked + label {
  193. border-color: var(--accent);
  194. background: rgba(232,197,71,.07);
  195. }
  196. .activity-card input:checked + label .check-icon {
  197. background: var(--accent);
  198. border-color: var(--accent);
  199. }
  200. .activity-card input:checked + label .check-icon svg { display: block; }
  201. .activity-card input:checked + label { transform: scale(1.01); }
  202. /* ---------- sticky footer bar ---------- */
  203. .action-bar {
  204. position: fixed;
  205. bottom: 0; left: 0; right: 0;
  206. background: rgba(15,17,23,.92);
  207. backdrop-filter: blur(12px);
  208. border-top: 1px solid var(--border);
  209. padding: 1rem var(--gap);
  210. display: flex;
  211. align-items: center;
  212. justify-content: space-between;
  213. gap: 1rem;
  214. z-index: 100;
  215. }
  216. .selection-count {
  217. font-size: .85rem;
  218. color: var(--muted);
  219. }
  220. .selection-count strong {
  221. color: var(--accent);
  222. font-variant-numeric: tabular-nums;
  223. }
  224. .btn-primary {
  225. background: var(--accent);
  226. color: #0f1117;
  227. font-family: 'DM Sans', sans-serif;
  228. font-weight: 600;
  229. font-size: .95rem;
  230. letter-spacing: .03em;
  231. padding: .7rem 1.8rem;
  232. border: none;
  233. border-radius: var(--radius);
  234. cursor: pointer;
  235. transition: background .15s, transform .1s, opacity .15s;
  236. touch-action: manipulation; /* rapid taps must not turn into double-tap zoom */
  237. }
  238. .btn-primary:hover { background: #f0d260; transform: translateY(-1px); }
  239. .btn-primary:active { transform: translateY(0); }
  240. .btn-primary[aria-disabled="true"] { opacity: .35; cursor: not-allowed; transform: none; }
  241. .btn-primary.nope { animation: nope .3s; }
  242. @keyframes nope {
  243. 20%, 60% { transform: translateX(-4px); }
  244. 40%, 80% { transform: translateX(4px); }
  245. }
  246. /* Easter egg: hidden activities flicker in like a failing fluorescent tube. */
  247. .secret-activities .section-title { color: var(--danger); }
  248. .secret-activities .activity-card input:checked + label {
  249. border-color: var(--danger);
  250. background: rgba(224,85,85,.08);
  251. }
  252. .secret-activities .activity-card input:checked + label .check-icon {
  253. background: var(--danger);
  254. border-color: var(--danger);
  255. }
  256. .secret-activities.revealing { animation: flicker 1.2s linear; }
  257. @keyframes flicker {
  258. 0%, 12%, 22%, 48% { opacity: 0; }
  259. 10%, 20%, 45%, 100% { opacity: 1; }
  260. }
  261. @media (prefers-reduced-motion: reduce) {
  262. .btn-primary.nope, .secret-activities.revealing { animation: none; }
  263. }
  264. /* select-all row */
  265. .controls {
  266. display: flex;
  267. gap: .75rem;
  268. margin-bottom: 2rem;
  269. flex-wrap: wrap;
  270. }
  271. .btn-ghost {
  272. background: transparent;
  273. color: var(--muted);
  274. border: 1.5px solid var(--border);
  275. border-radius: var(--radius);
  276. padding: .45rem 1rem;
  277. font-family: 'DM Sans', sans-serif;
  278. font-size: .8rem;
  279. font-weight: 500;
  280. letter-spacing: .04em;
  281. text-transform: uppercase;
  282. cursor: pointer;
  283. transition: color .15s, border-color .15s;
  284. }
  285. .btn-ghost:hover { color: var(--text); border-color: var(--muted); }
  286. footer {
  287. text-align: center;
  288. padding: 1rem;
  289. font-size: .75rem;
  290. color: var(--border);
  291. }
  292. footer a { color: var(--muted); text-decoration: none; }
  293. footer a:hover { color: var(--text); }
  294. </style>
  295. </head>
  296. <body>
  297. <header>
  298. <div class="logo">PackIt</div>
  299. <div class="tagline">Your smart packing companion</div>
  300. </header>
  301. <main>
  302. <div class="controls">
  303. <button class="btn-ghost" type="button" onclick="toggleAll(true)">Select all</button>
  304. <button class="btn-ghost" type="button" onclick="toggleAll(false)">Clear all</button>
  305. </div>
  306. <form id="actForm" action="list.php" method="GET">
  307. <?php foreach ($groups as $group) render_activity_group($group); ?>
  308. <?php if ($secretGroups): ?>
  309. <div id="secretActivities" class="secret-activities" hidden>
  310. <?php foreach ($secretGroups as $group) render_activity_group($group); ?>
  311. </div>
  312. <?php endif; ?>
  313. </form>
  314. </main>
  315. <div class="action-bar">
  316. <div class="selection-count"><strong id="cnt">0</strong> activities selected</div>
  317. <!-- aria-disabled rather than disabled: a disabled button swallows clicks,
  318. and the clicks on an empty selection are what reveal the easter egg. -->
  319. <button class="btn-primary" id="packBtn" type="button" aria-disabled="true"
  320. onclick="packIt()">
  321. Pack it! →
  322. </button>
  323. </div>
  324. <footer><a href="admin/">Admin</a></footer>
  325. <script>
  326. function selectedCount() {
  327. return document.querySelectorAll('input[name="aID[]"]:checked').length;
  328. }
  329. function updateCount() {
  330. const n = selectedCount();
  331. document.getElementById('cnt').textContent = n;
  332. document.getElementById('packBtn').setAttribute('aria-disabled', n === 0 ? 'true' : 'false');
  333. }
  334. function toggleAll(on) {
  335. // Secret activities stay out of "Select all" until they have been found.
  336. document.querySelectorAll('input[name="aID[]"]').forEach(cb => {
  337. if (!cb.closest('[hidden]')) cb.checked = on;
  338. });
  339. updateCount();
  340. }
  341. // Easter egg: hammering the button with nothing selected reveals the hidden
  342. // activities. Each click must follow the previous one within EGG_MAX_GAP_MS.
  343. const EGG_CLICKS = 10;
  344. const EGG_MAX_GAP_MS = 500;
  345. let eggClicks = 0;
  346. let eggLastClick = 0;
  347. function packIt() {
  348. if (selectedCount() > 0) {
  349. document.getElementById('actForm').submit();
  350. return;
  351. }
  352. const btn = document.getElementById('packBtn');
  353. btn.classList.remove('nope');
  354. void btn.offsetWidth; // restart the shake on every click
  355. btn.classList.add('nope');
  356. const now = Date.now();
  357. eggClicks = now - eggLastClick <= EGG_MAX_GAP_MS ? eggClicks + 1 : 1;
  358. eggLastClick = now;
  359. if (eggClicks >= EGG_CLICKS) {
  360. eggClicks = 0;
  361. revealSecrets(true);
  362. }
  363. }
  364. function revealSecrets(select) {
  365. const secret = document.getElementById('secretActivities');
  366. if (!secret || !secret.hidden) return;
  367. secret.hidden = false;
  368. if (select) {
  369. secret.querySelectorAll('input[name="aID[]"]').forEach(cb => cb.checked = true);
  370. secret.classList.add('revealing');
  371. secret.addEventListener('animationend', () => secret.classList.remove('revealing'), { once: true });
  372. secret.scrollIntoView({ behavior: 'smooth', block: 'center' });
  373. }
  374. updateCount();
  375. }
  376. // Back/forward navigation restores ticked checkboxes, including a secret one
  377. // that would otherwise be ticked but invisible.
  378. window.addEventListener('pageshow', () => {
  379. if (document.querySelector('#secretActivities input:checked')) revealSecrets(false);
  380. updateCount();
  381. });
  382. // Offline support: installs the worker that keeps visited lists readable
  383. // without signal.
  384. if ('serviceWorker' in navigator) {
  385. window.addEventListener('load', () => navigator.serviceWorker.register('/sw.js').catch(() => {}));
  386. }
  387. </script>
  388. </body>
  389. </html>