v1.0.0.1
StocketBase
- <?php
-
- declare(strict_types=1);
-
- if (count(get_included_files()) === 1) {
- http_response_code(403);
- exit;
- }
-
- if (!Auth::hasRoleAtLeast(Auth::ROLE_STORE_MANAGER)) {
- echo '<p>You don\'t have access to pages.</p>';
- return;
- }
-
- $db = Database::site();
-
- try {
- SiteFront::homePage();
- } catch (Throwable $exception) {
- }
-
- $pageId = (int) ($_GET['page_id'] ?? 0) ?: null;
- $editingPage = null;
- $showForm = $pageId !== null || isset($_GET['new']);
-
- if ($pageId !== null) {
- $statement = $db->prepare('SELECT * FROM pages WHERE id = :id LIMIT 1');
- $statement->execute(['id' => $pageId]);
- $editingPage = $statement->fetch() ?: null;
- }
-
- $pages = $db->query('SELECT * FROM pages ORDER BY is_home DESC, sort_order ASC, title ASC')->fetchAll();
- $isHomeEditing = $editingPage !== null && (int) ($editingPage['is_home'] ?? 0) === 1;
- $blocksJson = $editingPage['content_blocks'] ?? '{"blocks":[]}';
- if ($isHomeEditing) {
- $blocksJson = BlockEditor::sanitize((string) $blocksJson, false, true);
- }
-
- ?>
- <div class="dash-header-row">
- <h1 class="dash-title"><?= Icons::icon("pages", "icon icon-lg") ?>Pages</h1>
- <?php if (!$showForm): ?>
- <a href="dashboard.php?view=pages&new=1" class="dash-btn dash-btn-primary"><?= Icons::icon('plus', 'icon icon-sm') ?>New page</a>
- <?php endif; ?>
- </div>
-
- <table class="dash-table">
- <thead><tr><th><?= Icons::icon('heading', 'icon icon-sm') ?>Title</th><th><?= Icons::icon('flag', 'icon icon-sm') ?>Status</th><th><?= Icons::icon('menu', 'icon icon-sm') ?>In menu</th><th></th></tr></thead>
- <tbody>
- <?php foreach ($pages as $page): ?>
- <?php $isHomeRow = (int) ($page['is_home'] ?? 0) === 1; ?>
- <tr<?= $isHomeRow ? ' class="page-row-home"' : '' ?>>
- <td><?php if ($isHomeRow): ?><?= Icons::icon('home', 'icon icon-sm') ?> <?php endif; ?><?= htmlspecialchars($page['title']) ?><?php if ($isHomeRow): ?> <span class="status-pill status-published">Home page</span><?php endif; ?></td>
- <td><span class="status-pill status-<?= htmlspecialchars($page['status']) ?>"><?= htmlspecialchars(StatusLabel::get((string) $page['status'])) ?></span></td>
- <td><?= $isHomeRow ? 'Always' : ($page['show_in_menu'] ? 'Yes' : 'No') ?></td>
- <td class="dash-table-actions">
- <a href="dashboard.php?view=pages&page_id=<?= (int) $page['id'] ?>" class="dash-btn-small"><?= Icons::icon('edit', 'icon icon-sm') ?><?= $isHomeRow ? 'Design' : 'Edit' ?></a>
- <?php if (Languages::enabled()): ?>
- <a href="translate.php?type=page&id=<?= (int) $page['id'] ?>" class="dash-btn-small"><?= Icons::icon('translate', 'icon icon-sm') ?>Translate</a>
- <?php endif; ?>
- <?php if (!$isHomeRow): ?>
- <form method="post" style="display:inline;" onsubmit="return confirm('Delete this page? This can\'t be undone.');">
- <?= Csrf::field() ?>
- <input type="hidden" name="action" value="delete_page">
- <input type="hidden" name="page_id" value="<?= (int) $page['id'] ?>">
- <button type="submit" class="dash-btn-small dash-btn-danger"><?= Icons::icon('trash', 'icon icon-sm') ?>Delete</button>
- </form>
- <?php endif; ?>
- </td>
- </tr>
- <?php endforeach; ?>
- <?php if (empty($pages)): ?>
- <tr><td colspan="4">No pages yet. Add one for things like About us or Shipping info.</td></tr>
- <?php endif; ?>
- </tbody>
- </table>
-
- <?php if ($showForm): ?>
- <div class="sidebar-box" style="margin-top:20px;">
- <h2 class="dash-subtitle" style="margin-top:0;"><?= Icons::icon($isHomeEditing ? 'home' : 'pages', 'icon icon-sm') ?><?= $isHomeEditing ? 'Design home page' : ($editingPage ? 'Edit page' : 'New page') ?></h2>
- <?php if ($isHomeEditing): ?>
- <p style="color:var(--muted);margin:0 0 14px;">This is your store's front page. <strong>Featured products</strong> and <strong>Product list</strong> always stay on it. You can move them up or down, and add anything you like around them. The title is only for you, customers won't see it.</p>
- <?php endif; ?>
-
- <form method="post" id="page-form">
- <?= Csrf::field() ?>
- <input type="hidden" name="action" value="save_page">
- <?php if ($editingPage): ?>
- <input type="hidden" name="page_id" value="<?= (int) $editingPage['id'] ?>">
- <?php endif; ?>
- <input type="hidden" name="blocks_json" id="blocks_json_input">
-
- <label><?= Icons::icon('heading', 'icon icon-sm') ?>Title</label>
- <input type="text" name="title" value="<?= htmlspecialchars($editingPage['title'] ?? '') ?>" required>
-
- <label><?= Icons::icon('quote', 'icon icon-sm') ?>Content</label>
- <?php if ($isHomeEditing): ?>
- <div id="block-editor-root" data-initial-blocks='<?= htmlspecialchars($blocksJson, ENT_QUOTES) ?>' data-home="1"></div>
- <?php else: ?>
- <div id="block-editor-root" data-initial-blocks='<?= htmlspecialchars($blocksJson, ENT_QUOTES) ?>'<?= (SiteFront::settings()['contact_enabled'] ?? '0') === '1' ? ' data-allow-contact="1"' : '' ?>></div>
-
- <label><input type="checkbox" name="show_in_menu" <?= !empty($editingPage['show_in_menu']) ? 'checked' : '' ?>> Show in the store menu</label>
-
- <label><?= Icons::icon('flag', 'icon icon-sm') ?>Status</label>
- <select name="status">
- <option value="draft" <?= ($editingPage['status'] ?? 'draft') === 'draft' ? 'selected' : '' ?>>Draft</option>
- <option value="published" <?= ($editingPage['status'] ?? '') === 'published' ? 'selected' : '' ?>>Live</option>
- </select>
- <?php endif; ?>
-
- <div class="publish-actions">
- <button type="submit" class="dash-btn dash-btn-primary"><?= Icons::icon('check', 'icon icon-sm') ?>Save page</button>
- <a href="dashboard.php?view=pages" class="dash-btn"><?= Icons::icon('x', 'icon icon-sm') ?>Cancel</a>
- </div>
- </form>
- </div>
-
- <?= Asset::js('assets/block-editor.js') ?>
- <?php require_once __DIR__ . '/../includes/ai.php'; ?>
- <?= Ai::widgetMarkup() ?>
- <?php endif; ?>
-