form.php 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  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. <!-- Tabs System for Content and SEO -->
  89. <div x-data="{ activePageTab: 'content' }" class="mt-6">
  90. <!-- Tabs Navigation -->
  91. <div class="bg-white rounded-lg shadow-sm">
  92. <div class="border-b border-gray-200">
  93. <nav class="-mb-px flex space-x-8 px-6">
  94. <button type="button" @click="activePageTab = 'content'"
  95. :class="activePageTab === 'content' ? 'border-blue-500 text-blue-600' : 'border-transparent text-gray-500 hover:text-gray-700 hover:border-gray-300'"
  96. class="py-4 px-1 border-b-2 font-medium text-sm whitespace-nowrap transition-colors">
  97. <svg class="w-5 h-5 inline mr-2" fill="currentColor" viewBox="0 0 20 20">
  98. <path d="M9 2a1 1 0 000 2h2a1 1 0 100-2H9z"/>
  99. <path fill-rule="evenodd" d="M4 5a2 2 0 012-2h8a2 2 0 012 2v6a2 2 0 01-2 2H6a2 2 0 01-2-2V5zm3 1a1 1 0 000 2h.01a1 1 0 100-2H7zm3 0a1 1 0 000 2h3a1 1 0 100-2h-3zm-3 4a1 1 0 100 2h.01a1 1 0 100-2H7zm3 0a1 1 0 100 2h3a1 1 0 100-2h-3z" clip-rule="evenodd"/>
  100. </svg>
  101. Content
  102. </button>
  103. <button type="button" @click="activePageTab = 'seo'"
  104. :class="activePageTab === 'seo' ? 'border-blue-500 text-blue-600' : 'border-transparent text-gray-500 hover:text-gray-700 hover:border-gray-300'"
  105. class="py-4 px-1 border-b-2 font-medium text-sm whitespace-nowrap transition-colors">
  106. <svg class="w-5 h-5 inline mr-2" fill="currentColor" viewBox="0 0 20 20">
  107. <path fill-rule="evenodd" d="M12.316 3.051a1 1 0 01.633 1.265l-4 12a1 1 0 11-1.898-.632l4-12a1 1 0 011.265-.633zM5.707 6.293a1 1 0 010 1.414L3.414 10l2.293 2.293a1 1 0 11-1.414 1.414l-3-3a1 1 0 010-1.414l3-3a1 1 0 011.414 0zm8.586 0a1 1 0 011.414 0l3 3a1 1 0 010 1.414l-3 3a1 1 0 11-1.414-1.414L16.586 10l-2.293-2.293a1 1 0 010-1.414z" clip-rule="evenodd"/>
  108. </svg>
  109. SEO & Meta
  110. </button>
  111. </nav>
  112. </div>
  113. </div>
  114. <!-- Content Tab -->
  115. <div x-show="activePageTab === 'content'"
  116. x-transition:enter="transition ease-out duration-200"
  117. x-transition:enter-start="opacity-0"
  118. x-transition:enter-end="opacity-100"
  119. x-transition:leave="transition ease-in duration-150"
  120. x-transition:leave-start="opacity-100"
  121. x-transition:leave-end="opacity-0"
  122. class="bg-white rounded-lg shadow-sm mt-6">
  123. <div class="p-6">
  124. <!-- Page Title -->
  125. <div class="mb-6">
  126. <label for="title" class="block text-sm font-medium text-gray-700 mb-2">Page Title</label>
  127. <input type="text" name="title" id="title"
  128. value="<?= htmlspecialchars($page['title'] ?? '') ?>"
  129. 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">
  130. </div>
  131. <!-- Layout-Specific Forms -->
  132. <?php
  133. $currentLayout = $page['layout'] ?? 'default';
  134. $layoutFormPath = __DIR__ . "/layouts/{$currentLayout}.php";
  135. if (file_exists($layoutFormPath)) {
  136. include $layoutFormPath;
  137. } else {
  138. // Fallback to default form
  139. include __DIR__ . "/layouts/default.php";
  140. }
  141. ?>
  142. </div>
  143. </div>
  144. <!-- SEO Tab -->
  145. <div x-show="activePageTab === 'seo'"
  146. x-transition:enter="transition ease-out duration-200"
  147. x-transition:enter-start="opacity-0"
  148. x-transition:enter-end="opacity-100"
  149. x-transition:leave="transition ease-in duration-150"
  150. x-transition:leave-start="opacity-100"
  151. x-transition:leave-end="opacity-0"
  152. class="bg-white rounded-lg shadow-sm mt-6">
  153. <div class="p-6">
  154. <h3 class="text-lg font-medium text-gray-900 mb-6">SEO & Meta Information</h3>
  155. <div class="space-y-6">
  156. <div>
  157. <label for="seo_title" class="block text-sm font-medium text-gray-700 mb-2">Meta Title</label>
  158. <input type="text" name="seo[title]" id="seo_title"
  159. value="<?= htmlspecialchars($seoMeta['title'] ?? '') ?>"
  160. 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"
  161. placeholder="Enter SEO title for search engines">
  162. <p class="text-xs text-gray-500 mt-1">Recommended length: 50-60 characters</p>
  163. </div>
  164. <div>
  165. <label for="seo_description" class="block text-sm font-medium text-gray-700 mb-2">Meta Description</label>
  166. <textarea name="seo[description]" id="seo_description" rows="3"
  167. 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"
  168. placeholder="Enter meta description for search engines"><?= htmlspecialchars($seoMeta['description'] ?? '') ?></textarea>
  169. <p class="text-xs text-gray-500 mt-1">Recommended length: 150-160 characters</p>
  170. </div>
  171. <div>
  172. <label for="seo_keywords" class="block text-sm font-medium text-gray-700 mb-2">Meta Keywords</label>
  173. <input type="text" name="seo[keywords]" id="seo_keywords"
  174. value="<?= htmlspecialchars($seoMeta['keywords'] ?? '') ?>"
  175. 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"
  176. placeholder="keyword1, keyword2, keyword3">
  177. <p class="text-xs text-gray-500 mt-1">Separate keywords with commas</p>
  178. </div>
  179. <div class="grid grid-cols-1 lg:grid-cols-2 gap-6">
  180. <div class="grid grid-cols-1 lg:grid-cols-4 gap-4">
  181. <div class="lg:col-span-3">
  182. <label for="seo_canonical" class="block text-sm font-medium text-gray-700 mb-2">Canonical URL</label>
  183. <input type="url" name="seo[canonical]" id="seo_canonical"
  184. value="<?= htmlspecialchars($seoMeta['canonical'] ?? '') ?>"
  185. 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"
  186. placeholder="https://example.com/page">
  187. </div>
  188. <div>
  189. <label for="seo_locale" class="block text-sm font-medium text-gray-700 mb-2">Locale</label>
  190. <input type="text" name="seo[extra_fields][locale]" id="seo_locale"
  191. value="<?= htmlspecialchars($seoMeta['extra_fields']['locale'] ?? 'en') ?>"
  192. 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"
  193. placeholder="en">
  194. </div>
  195. </div>
  196. <div>
  197. <label for="seo_image" class="block text-sm font-medium text-gray-700 mb-2">Social Share Image</label>
  198. <input type="url" name="seo[image]" id="seo_image"
  199. value="<?= htmlspecialchars($seoMeta['image'] ?? '') ?>"
  200. 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"
  201. placeholder="https://example.com/image.jpg">
  202. </div>
  203. </div>
  204. </div>
  205. </div>
  206. </div>
  207. </div>
  208. <?php endif; ?>
  209. <div class="flex justify-between pt-6 border-t border-gray-200">
  210. <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">
  211. <svg class="w-5 h-5 mr-2" fill="currentColor" viewBox="0 0 20 20">
  212. <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"/>
  213. </svg>
  214. Cancel
  215. </a>
  216. <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">
  217. <svg class="w-5 h-5 mr-2" fill="currentColor" viewBox="0 0 20 20">
  218. <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"/>
  219. </svg>
  220. <?= $action === 'create' ? 'Create Page' : 'Update Page' ?>
  221. </button>
  222. </div>
  223. </div>
  224. </form>
  225. </div>
  226. </div>
  227. <?php
  228. $content = ob_get_clean();
  229. include __DIR__ . '/../partials/layout.php';
  230. ?>