form.php 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321
  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 = 'faq'"
  104. :class="activePageTab === 'faq' ? '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="M18 10a8 8 0 11-16 0 8 8 0 0116 0zm-8-3a1 1 0 00-.867.5 1 1 0 11-1.731-1A3 3 0 0113 8a3.001 3.001 0 01-2 2.83V11a1 1 0 11-2 0v-1a1 1 0 011-1 1 1 0 100-2zm0 8a1 1 0 100-2 1 1 0 000 2z" clip-rule="evenodd"/>
  108. </svg>
  109. FAQ
  110. </button>
  111. <button type="button" @click="activePageTab = 'seo'"
  112. :class="activePageTab === 'seo' ? 'border-blue-500 text-blue-600' : 'border-transparent text-gray-500 hover:text-gray-700 hover:border-gray-300'"
  113. class="py-4 px-1 border-b-2 font-medium text-sm whitespace-nowrap transition-colors">
  114. <svg class="w-5 h-5 inline mr-2" fill="currentColor" viewBox="0 0 20 20">
  115. <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"/>
  116. </svg>
  117. SEO & Meta
  118. </button>
  119. </nav>
  120. </div>
  121. </div>
  122. <!-- Content Tab -->
  123. <div x-show="activePageTab === 'content'"
  124. x-transition:enter="transition ease-out duration-200"
  125. x-transition:enter-start="opacity-0"
  126. x-transition:enter-end="opacity-100"
  127. x-transition:leave="transition ease-in duration-150"
  128. x-transition:leave-start="opacity-100"
  129. x-transition:leave-end="opacity-0"
  130. class="bg-white rounded-lg shadow-sm mt-6">
  131. <div class="p-6">
  132. <!-- Page Title -->
  133. <div class="mb-6">
  134. <label for="title" class="block text-sm font-medium text-gray-700 mb-2">Page Title</label>
  135. <input type="text" name="title" id="title"
  136. value="<?= htmlspecialchars($page['title'] ?? '') ?>"
  137. 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">
  138. </div>
  139. <!-- Layout-Specific Forms -->
  140. <?php
  141. $currentLayout = $page['layout'] ?? 'default';
  142. $layoutFormPath = __DIR__ . "/layouts/{$currentLayout}.php";
  143. if (file_exists($layoutFormPath)) {
  144. include $layoutFormPath;
  145. } else {
  146. // Fallback to default form
  147. include __DIR__ . "/layouts/default.php";
  148. }
  149. ?>
  150. </div>
  151. </div>
  152. <!-- FAQ Tab -->
  153. <?php
  154. $faqItemsJson = !empty($faqs['extra_fields']) ? htmlspecialchars(json_encode($faqs['extra_fields']), ENT_QUOTES, 'UTF-8') : '[]';
  155. ?>
  156. <div x-show="activePageTab === 'faq'"
  157. x-data='{ faqItems: <?= $faqItemsJson ?> }'
  158. x-transition:enter="transition ease-out duration-200"
  159. x-transition:enter-start="opacity-0"
  160. x-transition:enter-end="opacity-100"
  161. x-transition:leave="transition ease-in duration-150"
  162. x-transition:leave-start="opacity-100"
  163. x-transition:leave-end="opacity-0"
  164. class="bg-white rounded-lg shadow-sm mt-6">
  165. <div class="p-6">
  166. <h3 class="text-lg font-medium text-gray-900 mb-6">FAQ Management</h3>
  167. <div class="mb-6">
  168. <label for="faq_title" class="block text-sm font-medium text-gray-700 mb-2">FAQ Section Title</label>
  169. <input type="text" name="faq[title]" id="faq_title"
  170. value="<?= htmlspecialchars($faqs['title'] ?? '') ?>"
  171. placeholder="Enter FAQ section title..."
  172. 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">
  173. </div>
  174. <div class="space-y-4">
  175. <template x-for="(item, index) in faqItems" :key="index">
  176. <div class="faq-item bg-gray-50 rounded-lg p-4 border border-gray-200">
  177. <div class="space-y-4">
  178. <div>
  179. <label class="block text-sm font-medium text-gray-700 mb-2">Question</label>
  180. <input type="text" :name="`faq[items][${index}][question]`" x-model="item.question"
  181. placeholder="Enter FAQ question..."
  182. 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">
  183. </div>
  184. <div>
  185. <label class="block text-sm font-medium text-gray-700 mb-2">Answer</label>
  186. <textarea :name="`faq[items][${index}][answer]`" x-model="item.answer" rows="3"
  187. placeholder="Enter FAQ answer..."
  188. 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"></textarea>
  189. </div>
  190. <button type="button" @click="faqItems.splice(index, 1)"
  191. class="inline-flex items-center px-3 py-2 border border-transparent text-sm font-medium rounded-md text-white bg-red-600 hover:bg-red-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-red-500">
  192. Remove
  193. </button>
  194. </div>
  195. </div>
  196. </template>
  197. <button type="button" @click="faqItems.push({ question: '', answer: '' })"
  198. 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">
  199. <svg class="w-5 h-5 mr-2" fill="currentColor" viewBox="0 0 20 20">
  200. <path fill-rule="evenodd" d="M10 3a1 1 0 011 1v5h5a1 1 0 110 2h-5v5a1 1 0 11-2 0v-5H4a1 1 0 110-2h5V4a1 1 0 011-1z" clip-rule="evenodd"/>
  201. </svg>
  202. Add FAQ Item
  203. </button>
  204. </div>
  205. </div>
  206. </div>
  207. <!-- SEO Tab -->
  208. <div x-show="activePageTab === 'seo'"
  209. x-transition:enter="transition ease-out duration-200"
  210. x-transition:enter-start="opacity-0"
  211. x-transition:enter-end="opacity-100"
  212. x-transition:leave="transition ease-in duration-150"
  213. x-transition:leave-start="opacity-100"
  214. x-transition:leave-end="opacity-0"
  215. class="bg-white rounded-lg shadow-sm mt-6">
  216. <div class="p-6">
  217. <h3 class="text-lg font-medium text-gray-900 mb-6">SEO & Meta Information</h3>
  218. <div class="space-y-6">
  219. <div>
  220. <label for="seo_title" class="block text-sm font-medium text-gray-700 mb-2">Meta Title</label>
  221. <input type="text" name="seo[title]" id="seo_title"
  222. value="<?= htmlspecialchars($seoMeta['title'] ?? '') ?>"
  223. 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"
  224. placeholder="Enter SEO title for search engines">
  225. <p class="text-xs text-gray-500 mt-1">Recommended length: 50-60 characters</p>
  226. </div>
  227. <div>
  228. <label for="seo_description" class="block text-sm font-medium text-gray-700 mb-2">Meta Description</label>
  229. <textarea name="seo[description]" id="seo_description" rows="3"
  230. 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"
  231. placeholder="Enter meta description for search engines"><?= htmlspecialchars($seoMeta['description'] ?? '') ?></textarea>
  232. <p class="text-xs text-gray-500 mt-1">Recommended length: 150-160 characters</p>
  233. </div>
  234. <div>
  235. <label for="seo_keywords" class="block text-sm font-medium text-gray-700 mb-2">Meta Keywords</label>
  236. <input type="text" name="seo[keywords]" id="seo_keywords"
  237. value="<?= htmlspecialchars($seoMeta['keywords'] ?? '') ?>"
  238. 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"
  239. placeholder="keyword1, keyword2, keyword3">
  240. <p class="text-xs text-gray-500 mt-1">Separate keywords with commas</p>
  241. </div>
  242. <div class="grid grid-cols-1 lg:grid-cols-2 gap-6">
  243. <div class="grid grid-cols-1 lg:grid-cols-4 gap-4">
  244. <div class="lg:col-span-3">
  245. <label for="seo_canonical" class="block text-sm font-medium text-gray-700 mb-2">Canonical URL</label>
  246. <input type="url" name="seo[canonical]" id="seo_canonical"
  247. value="<?= htmlspecialchars($seoMeta['canonical'] ?? '') ?>"
  248. 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"
  249. placeholder="https://example.com/page">
  250. </div>
  251. <div>
  252. <label for="seo_locale" class="block text-sm font-medium text-gray-700 mb-2">Locale</label>
  253. <input type="text" name="seo[extra_fields][locale]" id="seo_locale"
  254. value="<?= htmlspecialchars($seoMeta['extra_fields']['locale'] ?? 'en') ?>"
  255. 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"
  256. placeholder="en">
  257. </div>
  258. </div>
  259. <div>
  260. <label for="seo_image" class="block text-sm font-medium text-gray-700 mb-2">Social Share Image</label>
  261. <input type="url" name="seo[image]" id="seo_image"
  262. value="<?= htmlspecialchars($seoMeta['image'] ?? '') ?>"
  263. 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"
  264. placeholder="https://example.com/image.jpg">
  265. </div>
  266. </div>
  267. </div>
  268. </div>
  269. </div>
  270. </div>
  271. <?php endif; ?>
  272. <div class="flex justify-between pt-6 border-t border-gray-200">
  273. <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">
  274. <svg class="w-5 h-5 mr-2" fill="currentColor" viewBox="0 0 20 20">
  275. <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"/>
  276. </svg>
  277. Cancel
  278. </a>
  279. <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">
  280. <svg class="w-5 h-5 mr-2" fill="currentColor" viewBox="0 0 20 20">
  281. <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"/>
  282. </svg>
  283. <?= $action === 'create' ? 'Create Page' : 'Update Page' ?>
  284. </button>
  285. </div>
  286. </div>
  287. </form>
  288. </div>
  289. </div>
  290. <?php
  291. $content = ob_get_clean();
  292. include __DIR__ . '/../partials/layout.php';
  293. ?>