form.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. <?php
  2. ob_start();
  3. ?>
  4. <div class="min-h-screen bg-gray-50 py-6" x-data="authorForm">
  5. <div class="max-w-4xl mx-auto px-4 sm:px-6 lg:px-8">
  6. <!-- Header -->
  7. <div class="mb-8">
  8. <div class="md:flex md:items-center md:justify-between">
  9. <div class="flex-1 min-w-0">
  10. <h2 class="text-2xl font-bold leading-7 text-gray-900 sm:text-3xl sm:truncate">
  11. <?= $action === 'create' ? 'Add New Author' : 'Edit Author' ?>
  12. </h2>
  13. <p class="mt-1 text-sm text-gray-500">
  14. <?= $action === 'create' ? 'Create a new author profile' : 'Update author information' ?>
  15. </p>
  16. </div>
  17. </div>
  18. </div>
  19. <!-- Success/Error Messages -->
  20. <?php if (isset($success)): ?>
  21. <div class="mb-6 bg-green-50 border border-green-200 rounded-md p-4">
  22. <div class="flex">
  23. <div class="flex-shrink-0">
  24. <svg class="h-5 w-5 text-green-400" viewBox="0 0 20 20" fill="currentColor">
  25. <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"/>
  26. </svg>
  27. </div>
  28. <div class="ml-3">
  29. <p class="text-sm font-medium text-green-800"><?= htmlspecialchars($success) ?></p>
  30. </div>
  31. </div>
  32. </div>
  33. <?php endif; ?>
  34. <?php if (isset($error)): ?>
  35. <div class="mb-6 bg-red-50 border border-red-200 rounded-md p-4">
  36. <div class="flex">
  37. <div class="flex-shrink-0">
  38. <svg class="h-5 w-5 text-red-400" viewBox="0 0 20 20" fill="currentColor">
  39. <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"/>
  40. </svg>
  41. </div>
  42. <div class="ml-3">
  43. <p class="text-sm font-medium text-red-800"><?= htmlspecialchars($error) ?></p>
  44. </div>
  45. </div>
  46. </div>
  47. <?php endif; ?>
  48. <!-- Form -->
  49. <form method="POST" enctype="multipart/form-data" class="space-y-6">
  50. <input type="hidden" name="action" value="<?= $action ?>">
  51. <?php if ($action === 'edit'): ?>
  52. <input type="hidden" name="id" value="<?= $author['id'] ?>">
  53. <?php endif; ?>
  54. <div class="bg-white shadow rounded-lg">
  55. <div class="px-6 py-4 border-b border-gray-200">
  56. <h3 class="text-lg font-medium text-gray-900">Author Information</h3>
  57. <p class="mt-1 text-sm text-gray-500">Basic information about the author.</p>
  58. </div>
  59. <div class="px-6 py-4 space-y-6">
  60. <!-- Author Name -->
  61. <div>
  62. <label for="name" class="block text-sm font-medium text-gray-700 mb-2">Author Name *</label>
  63. <input type="text" name="name" id="name" required
  64. value="<?= htmlspecialchars($author['name'] ?? '') ?>"
  65. 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"
  66. placeholder="Enter author name">
  67. </div>
  68. <!-- Image Upload -->
  69. <div>
  70. <label for="image" class="block text-sm font-medium text-gray-700 mb-2">Author Photo</label>
  71. <div class="flex items-center space-x-4">
  72. <?php if (!empty($author['image'])): ?>
  73. <div class="flex-shrink-0">
  74. <img src="/<?= htmlspecialchars($author['image']) ?>" alt="Current image" class="h-20 w-20 rounded-full object-cover border border-gray-300">
  75. </div>
  76. <?php endif; ?>
  77. <div class="flex-1">
  78. <input type="file" name="image_upload" id="image_upload" accept="image/*"
  79. class="block w-full text-sm text-gray-500 file:mr-4 file:py-2 file:px-4 file:rounded-md file:border-0 file:text-sm file:font-medium file:bg-blue-50 file:text-blue-700 hover:file:bg-blue-100">
  80. <input type="hidden" name="current_image" value="<?= htmlspecialchars($author['image'] ?? '') ?>">
  81. <p class="mt-1 text-xs text-gray-500">Upload a photo for the author profile</p>
  82. </div>
  83. </div>
  84. </div>
  85. <!-- Description -->
  86. <div>
  87. <label for="description" class="block text-sm font-medium text-gray-700 mb-2">Description</label>
  88. <textarea name="description" id="description" rows="4"
  89. 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"
  90. placeholder="Author bio and description"><?= htmlspecialchars($author['description'] ?? '') ?></textarea>
  91. </div>
  92. </div>
  93. </div>
  94. <!-- Social Media Links -->
  95. <div class="bg-white shadow rounded-lg">
  96. <div class="px-6 py-4 border-b border-gray-200">
  97. <h3 class="text-lg font-medium text-gray-900">Social Media Links</h3>
  98. <p class="mt-1 text-sm text-gray-500">Add social media profiles for this author.</p>
  99. </div>
  100. <div class="px-6 py-4">
  101. <div class="space-y-4">
  102. <template x-for="(link, index) in socialLinks" :key="index">
  103. <div class="flex items-center space-x-4 p-4 border border-gray-200 rounded-lg">
  104. <div class="flex-1">
  105. <label class="block text-sm font-medium text-gray-700 mb-1">Platform</label>
  106. <input type="text" :name="'social_links[' + index + '][platform]'" x-model="link.platform"
  107. 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"
  108. placeholder="e.g. Twitter, Facebook, LinkedIn">
  109. </div>
  110. <div class="flex-1">
  111. <label class="block text-sm font-medium text-gray-700 mb-1">URL</label>
  112. <input type="url" :name="'social_links[' + index + '][url]'" x-model="link.url"
  113. 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"
  114. placeholder="https://...">
  115. </div>
  116. <button type="button" @click="removeSocialLink(index)"
  117. class="mt-6 px-3 py-2 text-sm font-medium text-red-600 hover:text-red-800 border border-red-300 rounded-md hover:bg-red-50">
  118. Remove
  119. </button>
  120. </div>
  121. </template>
  122. <button type="button" @click="addSocialLink()"
  123. 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">
  124. <svg class="w-5 h-5 mr-2" fill="currentColor" viewBox="0 0 20 20">
  125. <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"/>
  126. </svg>
  127. Add Social Link
  128. </button>
  129. </div>
  130. </div>
  131. </div>
  132. <!-- Form Actions -->
  133. <div class="flex justify-between pt-6 border-t border-gray-200">
  134. <a href="/admin/authors/" 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">
  135. <svg class="w-5 h-5 mr-2" fill="currentColor" viewBox="0 0 20 20">
  136. <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"/>
  137. </svg>
  138. Back to List
  139. </a>
  140. <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">
  141. <svg class="w-5 h-5 mr-2" fill="currentColor" viewBox="0 0 20 20">
  142. <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"/>
  143. </svg>
  144. <?= $action === 'create' ? 'Create Author' : 'Update Author' ?>
  145. </button>
  146. </div>
  147. </form>
  148. </div>
  149. </div>
  150. <script>
  151. document.addEventListener('alpine:init', () => {
  152. Alpine.data('authorForm', () => ({
  153. socialLinks: <?= json_encode($author['social_links'] ?? [['platform' => '', 'url' => '']]) ?>,
  154. addSocialLink() {
  155. this.socialLinks.push({ platform: '', url: '' });
  156. },
  157. removeSocialLink(index) {
  158. this.socialLinks.splice(index, 1);
  159. }
  160. }));
  161. });
  162. </script>
  163. <?php
  164. $content = ob_get_clean();
  165. include __DIR__ . '/../partials/layout.php';
  166. ?>