packing.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422
  1. <?php
  2. ini_set('display_errors', 1); ini_set('display_startup_errors', 1); error_reporting(E_ALL);
  3. // packing.php – displays the packing list for a given hash
  4. require_once __DIR__ . '/db.php';
  5. $pdo = get_pdo();
  6. $hash = isset($_GET['h']) ? trim($_GET['h']) : '';
  7. if (!preg_match('/^[a-f0-9]{64}$/', $hash)) {
  8. http_response_code(400);
  9. die('<p>Invalid or missing list hash.</p>');
  10. }
  11. // Resolve hash → activity IDs
  12. $stmt = $pdo->prepare("SELECT activity_ids FROM selection_hashes WHERE hash = ?");
  13. $stmt->execute([$hash]);
  14. $row = $stmt->fetch();
  15. if (!$row) {
  16. http_response_code(404);
  17. die('<p>List not found. It may have expired or the link is wrong.</p>');
  18. }
  19. $activityIds = array_map('intval', explode(',', $row['activity_ids']));
  20. if (empty($activityIds)) {
  21. die('<p>No activities stored for this hash.</p>');
  22. }
  23. // Fetch the selected activity names for display
  24. $ph = implode(',', array_fill(0, count($activityIds), '?'));
  25. $stmt = $pdo->prepare("
  26. SELECT a.activityName
  27. FROM activities a
  28. WHERE a.activityID IN ($ph)
  29. ORDER BY a.activityName
  30. ");
  31. $stmt->execute($activityIds);
  32. $activityNames = $stmt->fetchAll(PDO::FETCH_COLUMN);
  33. // Get all items for these activities, deduplicated, grouped by item_group
  34. $stmt = $pdo->prepare("
  35. SELECT DISTINCT
  36. ig.groupID,
  37. ig.groupName,
  38. ig.sortOrder AS groupSort,
  39. i.itemID,
  40. i.itemName,
  41. i.sortOrder AS itemSort
  42. FROM activity_item_map aim
  43. JOIN items i ON i.itemID = aim.itemID
  44. JOIN item_groups ig ON ig.groupID = i.groupID
  45. WHERE aim.activityID IN ($ph)
  46. ORDER BY ig.sortOrder, ig.groupID, i.sortOrder, i.itemID
  47. ");
  48. $stmt->execute($activityIds);
  49. $allItems = $stmt->fetchAll();
  50. // Group items by item_group
  51. $grouped = [];
  52. foreach ($allItems as $item) {
  53. $gid = $item['groupID'];
  54. if (!isset($grouped[$gid])) {
  55. $grouped[$gid] = ['name' => $item['groupName'], 'items' => []];
  56. }
  57. $grouped[$gid]['items'][] = ['id' => $item['itemID'], 'name' => $item['itemName']];
  58. }
  59. $pageUrl = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? 'https' : 'http')
  60. . '://' . $_SERVER['HTTP_HOST']
  61. . $_SERVER['REQUEST_URI'];
  62. $totalItems = count($allItems);
  63. ?>
  64. <!DOCTYPE html>
  65. <html lang="en">
  66. <head>
  67. <meta charset="UTF-8">
  68. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  69. <title>PackIt – Your Packing List</title>
  70. <link rel="preconnect" href="https://fonts.googleapis.com">
  71. <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
  72. <link href="https://fonts.googleapis.com/css2?family=Bebas+Neue&family=DM+Sans:wght@300;400;500;600&display=swap" rel="stylesheet">
  73. <style>
  74. :root {
  75. --bg: #0f1117;
  76. --surface: #181c27;
  77. --border: #2a2f3f;
  78. --accent: #e8c547;
  79. --accent2: #4fd1c5;
  80. --text: #e8eaf0;
  81. --muted: #7a8099;
  82. --green: #5cb85c;
  83. --radius: 10px;
  84. --gap: 1.5rem;
  85. }
  86. *, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
  87. body {
  88. background: var(--bg);
  89. color: var(--text);
  90. font-family: 'DM Sans', sans-serif;
  91. font-size: 15px;
  92. min-height: 100vh;
  93. display: flex;
  94. flex-direction: column;
  95. }
  96. header {
  97. padding: 2rem var(--gap) 1.5rem;
  98. border-bottom: 1px solid var(--border);
  99. display: flex;
  100. align-items: flex-end;
  101. justify-content: space-between;
  102. gap: 1rem;
  103. flex-wrap: wrap;
  104. position: relative;
  105. overflow: hidden;
  106. }
  107. header::before {
  108. content: '';
  109. position: absolute;
  110. inset: 0;
  111. background: radial-gradient(ellipse 60% 80% at 90% 50%, rgba(79,209,197,.06) 0%, transparent 70%);
  112. pointer-events: none;
  113. }
  114. .header-left { display: flex; align-items: flex-end; gap: 1rem; position: relative; }
  115. .logo {
  116. font-family: 'Bebas Neue', sans-serif;
  117. font-size: clamp(2.2rem, 5vw, 3.5rem);
  118. letter-spacing: .04em;
  119. color: var(--accent);
  120. line-height: 1;
  121. }
  122. .header-meta {
  123. font-size: .8rem;
  124. color: var(--muted);
  125. padding-bottom: .2rem;
  126. }
  127. .header-meta strong { color: var(--accent2); }
  128. .btn-row {
  129. display: flex;
  130. gap: .6rem;
  131. flex-wrap: wrap;
  132. position: relative;
  133. }
  134. .btn {
  135. display: inline-flex; align-items: center; gap: .5rem;
  136. padding: .55rem 1.1rem;
  137. border-radius: var(--radius);
  138. font-family: 'DM Sans', sans-serif;
  139. font-size: .82rem;
  140. font-weight: 500;
  141. letter-spacing: .03em;
  142. cursor: pointer;
  143. border: 1.5px solid transparent;
  144. transition: all .15s;
  145. text-decoration: none;
  146. }
  147. .btn-accent {
  148. background: var(--accent); color: #0f1117; border-color: var(--accent);
  149. }
  150. .btn-accent:hover { background: #f0d260; }
  151. .btn-outline {
  152. background: transparent; color: var(--text); border-color: var(--border);
  153. }
  154. .btn-outline:hover { border-color: var(--muted); }
  155. .btn-teal {
  156. background: transparent; color: var(--accent2); border-color: var(--accent2);
  157. }
  158. .btn-teal:hover { background: rgba(79,209,197,.08); }
  159. main {
  160. flex: 1;
  161. max-width: 760px;
  162. width: 100%;
  163. margin: 0 auto;
  164. padding: 2.5rem var(--gap) 3rem;
  165. }
  166. /* Activities pills */
  167. .activity-pills {
  168. display: flex;
  169. flex-wrap: wrap;
  170. gap: .4rem;
  171. margin-bottom: 2.5rem;
  172. }
  173. .pill {
  174. background: rgba(232,197,71,.1);
  175. border: 1px solid rgba(232,197,71,.3);
  176. color: var(--accent);
  177. font-size: .75rem;
  178. font-weight: 500;
  179. padding: .3rem .75rem;
  180. border-radius: 999px;
  181. letter-spacing: .03em;
  182. }
  183. /* Progress bar */
  184. .progress-bar-wrap {
  185. background: var(--surface);
  186. border: 1px solid var(--border);
  187. border-radius: var(--radius);
  188. padding: 1rem 1.25rem;
  189. margin-bottom: 2.5rem;
  190. display: flex;
  191. align-items: center;
  192. gap: 1.5rem;
  193. }
  194. .progress-track {
  195. flex: 1;
  196. height: 6px;
  197. background: var(--border);
  198. border-radius: 999px;
  199. overflow: hidden;
  200. }
  201. .progress-fill {
  202. height: 100%;
  203. background: linear-gradient(90deg, var(--accent2), var(--accent));
  204. border-radius: 999px;
  205. width: 0%;
  206. transition: width .3s ease;
  207. }
  208. .progress-label {
  209. font-size: .82rem;
  210. color: var(--muted);
  211. white-space: nowrap;
  212. }
  213. .progress-label strong { color: var(--accent); font-variant-numeric: tabular-nums; }
  214. .section-title {
  215. font-family: 'Bebas Neue', sans-serif;
  216. font-size: 1.1rem;
  217. letter-spacing: .12em;
  218. color: var(--accent2);
  219. text-transform: uppercase;
  220. margin-bottom: .75rem;
  221. display: flex;
  222. align-items: center;
  223. gap: .6rem;
  224. }
  225. .section-title::after {
  226. content: '';
  227. flex: 1;
  228. height: 1px;
  229. background: var(--border);
  230. }
  231. .item-group {
  232. margin-bottom: 2rem;
  233. }
  234. .item-list {
  235. display: flex;
  236. flex-direction: column;
  237. gap: .4rem;
  238. }
  239. .item-row {
  240. display: flex;
  241. align-items: center;
  242. gap: .75rem;
  243. padding: .6rem 1rem;
  244. background: var(--surface);
  245. border: 1.5px solid var(--border);
  246. border-radius: var(--radius);
  247. cursor: pointer;
  248. transition: border-color .15s, background .15s;
  249. user-select: none;
  250. }
  251. .item-row:hover { background: #1e2333; }
  252. .item-row.checked {
  253. border-color: rgba(92,184,92,.5);
  254. background: rgba(92,184,92,.05);
  255. }
  256. .item-row.checked .item-name {
  257. text-decoration: line-through;
  258. color: var(--muted);
  259. }
  260. .item-check {
  261. width: 20px; height: 20px;
  262. border: 1.5px solid var(--border);
  263. border-radius: 5px;
  264. flex-shrink: 0;
  265. display: flex; align-items: center; justify-content: center;
  266. background: var(--bg);
  267. transition: all .15s;
  268. }
  269. .item-row.checked .item-check {
  270. background: var(--green);
  271. border-color: var(--green);
  272. }
  273. .item-check svg { display: none; }
  274. .item-row.checked .item-check svg { display: block; }
  275. .item-name { flex: 1; font-size: .95rem; }
  276. /* Share box */
  277. .share-box {
  278. background: var(--surface);
  279. border: 1.5px solid var(--border);
  280. border-radius: var(--radius);
  281. padding: 1.25rem 1.5rem;
  282. margin-bottom: 2.5rem;
  283. display: flex;
  284. gap: .75rem;
  285. align-items: center;
  286. flex-wrap: wrap;
  287. }
  288. .share-url {
  289. flex: 1;
  290. font-size: .8rem;
  291. color: var(--muted);
  292. font-family: monospace;
  293. white-space: nowrap;
  294. overflow: hidden;
  295. text-overflow: ellipsis;
  296. min-width: 0;
  297. }
  298. .copy-feedback {
  299. font-size: .8rem;
  300. color: var(--green);
  301. opacity: 0;
  302. transition: opacity .3s;
  303. }
  304. .copy-feedback.show { opacity: 1; }
  305. @media print {
  306. header .btn-row, .share-box, .progress-bar-wrap { display: none !important; }
  307. body { background: #fff; color: #000; }
  308. .item-row { border-color: #ccc; background: none; }
  309. .section-title { color: #333; }
  310. .pill { background: #f5f5f5; color: #333; border-color: #ccc; }
  311. }
  312. </style>
  313. </head>
  314. <body>
  315. <header>
  316. <div class="header-left">
  317. <div class="logo">PackIt</div>
  318. <div class="header-meta">
  319. <strong><?= $totalItems ?></strong> items &nbsp;·&nbsp;
  320. <strong><?= count($activityNames) ?></strong> activities
  321. </div>
  322. </div>
  323. <div class="btn-row">
  324. <a href="index.php" class="btn btn-outline">← New list</a>
  325. <button class="btn btn-teal" onclick="window.print()">🖨 Print</button>
  326. <button class="btn btn-accent" onclick="copyLink()">🔗 Copy link</button>
  327. </div>
  328. </header>
  329. <main>
  330. <!-- Activity pills -->
  331. <div class="activity-pills">
  332. <?php foreach ($activityNames as $n): ?>
  333. <span class="pill"><?= htmlspecialchars($n) ?></span>
  334. <?php endforeach; ?>
  335. </div>
  336. <!-- Share box -->
  337. <div class="share-box">
  338. <span class="share-url" id="shareUrl"><?= htmlspecialchars($pageUrl) ?></span>
  339. <span class="copy-feedback" id="copyFb">Copied!</span>
  340. <button class="btn btn-teal" onclick="copyLink()">Copy link</button>
  341. </div>
  342. <!-- Progress -->
  343. <div class="progress-bar-wrap">
  344. <div class="progress-track"><div class="progress-fill" id="progressFill"></div></div>
  345. <div class="progress-label"><strong id="checkedCnt">0</strong> / <?= $totalItems ?> packed</div>
  346. </div>
  347. <!-- Grouped item list -->
  348. <?php foreach ($grouped as $gid => $group): ?>
  349. <div class="item-group">
  350. <div class="section-title"><?= htmlspecialchars($group['name']) ?></div>
  351. <div class="item-list">
  352. <?php foreach ($group['items'] as $item): ?>
  353. <div class="item-row" onclick="toggleItem(this)">
  354. <div class="item-check">
  355. <svg width="10" height="8" viewBox="0 0 10 8" fill="none">
  356. <path d="M1 4l3 3 5-6" stroke="#fff" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
  357. </svg>
  358. </div>
  359. <span class="item-name"><?= htmlspecialchars($item['name']) ?></span>
  360. </div>
  361. <?php endforeach; ?>
  362. </div>
  363. </div>
  364. <?php endforeach; ?>
  365. </main>
  366. <script>
  367. const total = <?= $totalItems ?>;
  368. function toggleItem(el) {
  369. el.classList.toggle('checked');
  370. updateProgress();
  371. }
  372. function updateProgress() {
  373. const checked = document.querySelectorAll('.item-row.checked').length;
  374. document.getElementById('checkedCnt').textContent = checked;
  375. document.getElementById('progressFill').style.width = (checked / total * 100) + '%';
  376. }
  377. function copyLink() {
  378. const url = document.getElementById('shareUrl').textContent;
  379. navigator.clipboard.writeText(url).then(() => {
  380. const fb = document.getElementById('copyFb');
  381. fb.classList.add('show');
  382. setTimeout(() => fb.classList.remove('show'), 2000);
  383. }).catch(() => {
  384. // Fallback
  385. const ta = document.createElement('textarea');
  386. ta.value = url;
  387. document.body.appendChild(ta);
  388. ta.select();
  389. document.execCommand('copy');
  390. document.body.removeChild(ta);
  391. });
  392. }
  393. </script>
  394. </body>
  395. </html>