form.php 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. <?php
  2. $pageTitle = ($action === 'create' ? 'Create New Page' : 'Edit Page') . ' - Admin Panel';
  3. $headerTitle = $action === 'create' ? 'Create New Page' : 'Edit Page';
  4. ob_start();
  5. ?>
  6. <?php if (isset($success)): ?>
  7. <div class="bg-green-50 border border-green-200 rounded-lg p-4 mb-6">
  8. <div class="flex">
  9. <svg class="w-5 h-5 text-green-400 mr-3 mt-0.5" fill="currentColor" viewBox="0 0 20 20">
  10. <path fill-rule="evenodd" d="M10 18a8 8 0 100-16 8 8 0 000 16zm3.707-9.293a1 1 0 00-1.414-1.414L9 10.586 7.707 9.293a1 1 0 00-1.414 1.414l2 2a1 1 0 001.414 0l4-4z" clip-rule="evenodd"/>
  11. </svg>
  12. <p class="text-sm text-green-700"><?= htmlspecialchars($success) ?></p>
  13. </div>
  14. </div>
  15. <?php endif; ?>
  16. <?php if (isset($error)): ?>
  17. <div class="bg-red-50 border border-red-200 rounded-lg p-4 mb-6">
  18. <div class="flex">
  19. <svg class="w-5 h-5 text-red-400 mr-3 mt-0.5" fill="currentColor" viewBox="0 0 20 20">
  20. <path fill-rule="evenodd" d="M10 18a8 8 0 100-16 8 8 0 000 16zM8.707 7.293a1 1 0 00-1.414 1.414L8.586 10l-1.293 1.293a1 1 0 101.414 1.414L10 11.414l1.293 1.293a1 1 0 001.414-1.414L11.414 10l1.293-1.293a1 1 0 00-1.414-1.414L10 8.586 8.707 7.293z" clip-rule="evenodd"/>
  21. </svg>
  22. <p class="text-sm text-red-700"><?= htmlspecialchars($error) ?></p>
  23. </div>
  24. </div>
  25. <?php endif; ?>
  26. <div class="bg-white shadow rounded-lg">
  27. <div class="px-6 py-4 border-b border-gray-200">
  28. <h3 class="text-lg font-medium text-gray-900">
  29. <?= $action === 'create' ? 'Create New Page' : 'Edit Page' ?>
  30. </h3>
  31. </div>
  32. <div class="px-6 py-6">
  33. <form method="POST" action="/admin/pages/">
  34. <input type="hidden" name="action" value="<?= $action ?>">
  35. <?php if ($action === 'edit'): ?>
  36. <input type="hidden" name="id" value="<?= $page['id'] ?>">
  37. <?php endif; ?>
  38. <div class="space-y-6">
  39. <!-- Basic Page Information -->
  40. <div class="grid grid-cols-1 lg:grid-cols-3 gap-6">
  41. <div>
  42. <label for="name" class="block text-sm font-medium text-gray-700 mb-2">Page Name *</label>
  43. <input type="text" name="name" id="name" required
  44. value="<?= htmlspecialchars($page['name'] ?? '') ?>"
  45. class="w-full px-3 py-2 border border-gray-300 rounded-md shadow-sm focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500">
  46. </div>
  47. <div>
  48. <label for="slug" class="block text-sm font-medium text-gray-700 mb-2">Slug</label>
  49. <input type="text" name="slug" id="slug"
  50. value="<?= htmlspecialchars($page['slug'] ?? '') ?>"
  51. placeholder="Auto-generated from name if empty"
  52. class="w-full px-3 py-2 border border-gray-300 rounded-md shadow-sm focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500">
  53. <p class="text-xs text-gray-500 mt-1">Leave empty to auto-generate from page name</p>
  54. </div>
  55. <div>
  56. <label for="layout" class="block text-sm font-medium text-gray-700 mb-2">Layout</label>
  57. <select name="layout" id="layout"
  58. class="w-full px-3 py-2 border border-gray-300 rounded-md shadow-sm focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500">
  59. <?php foreach ($layouts as $layoutValue => $layoutLabel): ?>
  60. <option value="<?= $layoutValue ?>" <?= ($page['layout'] ?? 'default') === $layoutValue ? 'selected' : '' ?>>
  61. <?= htmlspecialchars($layoutLabel) ?>
  62. </option>
  63. <?php endforeach; ?>
  64. </select>
  65. <div class="flex items-center mt-3">
  66. <input type="hidden" name="is_homepage" value="0">
  67. <input type="checkbox" name="is_homepage" value="1" id="is_homepage"
  68. <?= !empty($page['is_homepage']) ? 'checked' : '' ?>
  69. class="h-4 w-4 text-blue-600 focus:ring-blue-500 border-gray-300 rounded">
  70. <label for="is_homepage" class="ml-2 block text-sm text-gray-900">Set as Homepage</label>
  71. </div>
  72. </div>
  73. </div>
  74. <?php if ($action === 'create'): ?>
  75. <!-- For new pages, show only basic info and a note -->
  76. <div class="bg-blue-50 border border-blue-200 rounded-lg p-4">
  77. <div class="flex">
  78. <svg class="w-5 h-5 text-blue-400 mr-3 mt-0.5" fill="currentColor" viewBox="0 0 20 20">
  79. <path fill-rule="evenodd" d="M18 10a8 8 0 11-16 0 8 8 0 0116 0zm-7-4a1 1 0 11-2 0 1 1 0 012 0zM9 9a1 1 0 000 2v3a1 1 0 001 1h1a1 1 0 100-2v-3a1 1 0 00-1-1H9z" clip-rule="evenodd"/>
  80. </svg>
  81. <div>
  82. <h4 class="text-sm font-medium text-blue-800">Create Page First</h4>
  83. <p class="text-sm text-blue-700 mt-1">Save this page to access layout-specific content fields and advanced options.</p>
  84. </div>
  85. </div>
  86. </div>
  87. <?php else: ?>
  88. <!-- For existing pages, show title field and layout-specific forms -->
  89. <div>
  90. <label for="title" class="block text-sm font-medium text-gray-700 mb-2">Page Title</label>
  91. <input type="text" name="title" id="title"
  92. value="<?= htmlspecialchars($page['title'] ?? '') ?>"
  93. class="w-full px-3 py-2 border border-gray-300 rounded-md shadow-sm focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500">
  94. </div>
  95. <!-- Layout-Specific Forms (only for edit mode) -->
  96. <div>
  97. <?php
  98. $currentLayout = $page['layout'] ?? 'default';
  99. $layoutFormPath = __DIR__ . "/layouts/{$currentLayout}.php";
  100. if (file_exists($layoutFormPath)) {
  101. include $layoutFormPath;
  102. } else {
  103. // Fallback to default form
  104. include __DIR__ . "/layouts/default.php";
  105. }
  106. ?>
  107. </div>
  108. <?php endif; ?>
  109. <div class="flex justify-between pt-6 border-t border-gray-200">
  110. <a href="/admin/pages/" class="inline-flex items-center px-4 py-2 border border-gray-300 shadow-sm text-sm font-medium rounded-md text-gray-700 bg-white hover:bg-gray-50 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-blue-500 transition-colors">
  111. <svg class="w-5 h-5 mr-2" fill="currentColor" viewBox="0 0 20 20">
  112. <path fill-rule="evenodd" d="M7.707 14.707a1 1 0 01-1.414 0L2.586 11H9a1 1 0 010 2H2.586l3.707 3.707a1 1 0 01-1.414 1.414l-5.414-5.414a1 1 0 010-1.414L4.879 6.879a1 1 0 011.414 1.414L2.586 11H9a1 1 0 010 2H2.586l3.707 3.707z" clip-rule="evenodd"/>
  113. </svg>
  114. Cancel
  115. </a>
  116. <button type="submit" class="inline-flex items-center px-6 py-2 border border-transparent text-sm font-medium rounded-md text-white bg-blue-600 hover:bg-blue-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-blue-500 transition-colors">
  117. <svg class="w-5 h-5 mr-2" fill="currentColor" viewBox="0 0 20 20">
  118. <path fill-rule="evenodd" d="M16.707 5.293a1 1 0 010 1.414l-8 8a1 1 0 01-1.414 0l-4-4a1 1 0 011.414-1.414L8 12.586l7.293-7.293a1 1 0 011.414 0z" clip-rule="evenodd"/>
  119. </svg>
  120. <?= $action === 'create' ? 'Create Page' : 'Update Page' ?>
  121. </button>
  122. </div>
  123. </div>
  124. </form>
  125. </div>
  126. </div>
  127. <?php
  128. $content = ob_get_clean();
  129. include __DIR__ . '/../partials/layout.php';
  130. ?>