diff --git a/admin/builder.php b/admin/builder.php new file mode 100644 index 0000000..1f669a8 --- /dev/null +++ b/admin/builder.php @@ -0,0 +1,264 @@ +prepare("SELECT * FROM sessions WHERE id = ? AND occasion = 'custom'"); + $stmt->execute([(int)$_GET['id']]); + $session = $stmt->fetch(); + if (!$session) { + header('Location: ' . BASE_URL . '/admin/'); + exit; + } + if (!$is_admin && (int)$session['user_id'] !== $uid) { + header('Location: ' . BASE_URL . '/admin/'); + exit; + } + // Load steps with prayer data + $step_stmt = $pdo->prepare(" + SELECT bs.prayer_id, bs.attribution, + cp.name, cp.leader_text, cp.all_text, cp.is_global, cp.created_by, + IF(cp.is_global=1 AND u.role='superadmin','standard', + IF(cp.is_global=1,'global','mine')) AS source_tag + FROM builder_steps bs + JOIN custom_prayers cp ON cp.id = bs.prayer_id + LEFT JOIN users u ON u.id = cp.created_by + WHERE bs.session_id = ? + ORDER BY bs.step_order ASC + "); + $step_stmt->execute([(int)$session['id']]); + $edit_steps = $step_stmt->fetchAll(); +} + +// ── Load prayer library ─────────────────────────────────────────────────────── +$lib_stmt = $pdo->prepare(" + SELECT cp.id, cp.name, cp.leader_text, cp.all_text, cp.is_global, cp.created_by, + IF(cp.is_global=1 AND u.role='superadmin','standard', + IF(cp.is_global=1,'global','mine')) AS source_tag + FROM custom_prayers cp + LEFT JOIN users u ON u.id = cp.created_by + WHERE cp.is_global = 1 OR cp.created_by = ? + ORDER BY (cp.is_global=1 AND u.role='superadmin') DESC, cp.name ASC +"); +$lib_stmt->execute([$uid]); +$prayers_data = $lib_stmt->fetchAll(); + +$page_title = $session ? 'Edit: ' . htmlspecialchars($session['name']) : 'Rosary Builder'; +?> + + +
+ + + +