WebOrbiton
v1.0.0.0

StocketBase

103 lines · 4.2 KB
  1. <?php
  2. ​
  3. declare(strict_types=1);
  4. ​
  5. if (count(get_included_files()) === 1) {
  6. http_response_code(403);
  7. exit;
  8. }
  9. ​
  10. if (!Auth::hasRoleAtLeast(Auth::ROLE_STORE_MANAGER)) {
  11. echo '<p>You do not have permission to manage pages.</p>';
  12. return;
  13. }
  14. ​
  15. $db = Database::site();
  16. ​
  17. $pageId = (int) ($_GET['page_id'] ?? 0) ?: null;
  18. $editingPage = null;
  19. $showForm = $pageId !== null || isset($_GET['new']);
  20. ​
  21. if ($pageId !== null) {
  22. $statement = $db->prepare('SELECT * FROM pages WHERE id = :id LIMIT 1');
  23. $statement->execute(['id' => $pageId]);
  24. $editingPage = $statement->fetch() ?: null;
  25. }
  26. ​
  27. $pages = $db->query('SELECT * FROM pages ORDER BY sort_order ASC, title ASC')->fetchAll();
  28. $blocksJson = $editingPage['content_blocks'] ?? '{"blocks":[]}';
  29. ​
  30. ?>
  31. <div class="dash-header-row">
  32. <h1 class="dash-title"><?= Icons::icon("pages", "icon icon-lg") ?>Pages</h1>
  33. <?php if (!$showForm): ?>
  34. <a href="dashboard.php?view=pages&new=1" class="dash-btn dash-btn-primary"><?= Icons::icon('plus', 'icon icon-sm') ?>New page</a>
  35. <?php endif; ?>
  36. </div>
  37. ​
  38. <table class="dash-table">
  39. <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>
  40. <tbody>
  41. <?php foreach ($pages as $page): ?>
  42. <tr>
  43. <td><?= htmlspecialchars($page['title']) ?></td>
  44. <td><span class="status-pill status-<?= htmlspecialchars($page['status']) ?>"><?= htmlspecialchars($page['status']) ?></span></td>
  45. <td><?= $page['show_in_menu'] ? 'Yes' : 'No' ?></td>
  46. <td class="dash-table-actions">
  47. <a href="dashboard.php?view=pages&page_id=<?= (int) $page['id'] ?>" class="dash-btn-small"><?= Icons::icon('edit', 'icon icon-sm') ?>Edit</a>
  48. <?php if (Languages::enabled()): ?>
  49. <a href="translate.php?type=page&id=<?= (int) $page['id'] ?>" class="dash-btn-small"><?= Icons::icon('translate', 'icon icon-sm') ?>Translate</a>
  50. <?php endif; ?>
  51. <form method="post" style="display:inline;" onsubmit="return confirm('Delete this page?');">
  52. <?= Csrf::field() ?>
  53. <input type="hidden" name="action" value="delete_page">
  54. <input type="hidden" name="page_id" value="<?= (int) $page['id'] ?>">
  55. <button type="submit" class="dash-btn-small dash-btn-danger"><?= Icons::icon('trash', 'icon icon-sm') ?>Delete</button>
  56. </form>
  57. </td>
  58. </tr>
  59. <?php endforeach; ?>
  60. <?php if (empty($pages)): ?>
  61. <tr><td colspan="4">No pages yet.</td></tr>
  62. <?php endif; ?>
  63. </tbody>
  64. </table>
  65. ​
  66. <?php if ($showForm): ?>
  67. <div class="sidebar-box" style="margin-top:20px;">
  68. <h2 class="dash-subtitle" style="margin-top:0;"><?= Icons::icon('pages', 'icon icon-sm') ?><?= $editingPage ? 'Edit page' : 'New page' ?></h2>
  69. ​
  70. <form method="post" id="page-form">
  71. <?= Csrf::field() ?>
  72. <input type="hidden" name="action" value="save_page">
  73. <?php if ($editingPage): ?>
  74. <input type="hidden" name="page_id" value="<?= (int) $editingPage['id'] ?>">
  75. <?php endif; ?>
  76. <input type="hidden" name="blocks_json" id="blocks_json_input">
  77. ​
  78. <label><?= Icons::icon('heading', 'icon icon-sm') ?>Title</label>
  79. <input type="text" name="title" value="<?= htmlspecialchars($editingPage['title'] ?? '') ?>" required>
  80. ​
  81. <label><?= Icons::icon('quote', 'icon icon-sm') ?>Content</label>
  82. <div id="block-editor-root" data-initial-blocks='<?= htmlspecialchars($blocksJson, ENT_QUOTES) ?>'<?= (SiteFront::settings()['contact_enabled'] ?? '0') === '1' ? ' data-allow-contact="1"' : '' ?>></div>
  83. ​
  84. <label><input type="checkbox" name="show_in_menu" <?= !empty($editingPage['show_in_menu']) ? 'checked' : '' ?>> Show in site menu</label>
  85. ​
  86. <label><?= Icons::icon('flag', 'icon icon-sm') ?>Status</label>
  87. <select name="status">
  88. <option value="draft" <?= ($editingPage['status'] ?? 'draft') === 'draft' ? 'selected' : '' ?>>Draft</option>
  89. <option value="published" <?= ($editingPage['status'] ?? '') === 'published' ? 'selected' : '' ?>>Published</option>
  90. </select>
  91. ​
  92. <div class="publish-actions">
  93. <button type="submit" class="dash-btn dash-btn-primary"><?= Icons::icon('check', 'icon icon-sm') ?>Save page</button>
  94. <a href="dashboard.php?view=pages" class="dash-btn"><?= Icons::icon('x', 'icon icon-sm') ?>Cancel</a>
  95. </div>
  96. </form>
  97. </div>
  98. ​
  99. <?= Asset::js('assets/block-editor.js') ?>
  100. <?php require_once __DIR__ . '/../includes/ai.php'; ?>
  101. <?= Ai::widgetMarkup() ?>
  102. <?php endif; ?>
  103. ​