| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146 |
- <?php
- $pageTitle = ($action === 'create' ? 'Create New Page' : 'Edit Page') . ' - Admin Panel';
- $headerTitle = $action === 'create' ? 'Create New Page' : 'Edit Page';
- ob_start();
- ?>
- <?php if (isset($success)): ?>
- <div class="bg-green-50 border border-green-200 rounded-lg p-4 mb-6">
- <div class="flex">
- <svg class="w-5 h-5 text-green-400 mr-3 mt-0.5" fill="currentColor" viewBox="0 0 20 20">
- <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"/>
- </svg>
- <p class="text-sm text-green-700"><?= htmlspecialchars($success) ?></p>
- </div>
- </div>
- <?php endif; ?>
- <?php if (isset($error)): ?>
- <div class="bg-red-50 border border-red-200 rounded-lg p-4 mb-6">
- <div class="flex">
- <svg class="w-5 h-5 text-red-400 mr-3 mt-0.5" fill="currentColor" viewBox="0 0 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"/>
- </svg>
- <p class="text-sm text-red-700"><?= htmlspecialchars($error) ?></p>
- </div>
- </div>
- <?php endif; ?>
- <div class="bg-white shadow rounded-lg">
- <div class="px-6 py-4 border-b border-gray-200">
- <h3 class="text-lg font-medium text-gray-900">
- <?= $action === 'create' ? 'Create New Page' : 'Edit Page' ?>
- </h3>
- </div>
- <div class="px-6 py-6">
- <form method="POST" action="/admin/pages/">
- <input type="hidden" name="action" value="<?= $action ?>">
- <?php if ($action === 'edit'): ?>
- <input type="hidden" name="id" value="<?= $page['id'] ?>">
- <?php endif; ?>
- <div class="space-y-6">
- <!-- Basic Page Information -->
- <div class="grid grid-cols-1 lg:grid-cols-3 gap-6">
- <div>
- <label for="name" class="block text-sm font-medium text-gray-700 mb-2">Page Name *</label>
- <input type="text" name="name" id="name" required
- value="<?= htmlspecialchars($page['name'] ?? '') ?>"
- 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">
- </div>
- <div>
- <label for="slug" class="block text-sm font-medium text-gray-700 mb-2">Slug</label>
- <input type="text" name="slug" id="slug"
- value="<?= htmlspecialchars($page['slug'] ?? '') ?>"
- placeholder="Auto-generated from name if empty"
- 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">
- <p class="text-xs text-gray-500 mt-1">Leave empty to auto-generate from page name</p>
- </div>
- <div>
- <label for="layout" class="block text-sm font-medium text-gray-700 mb-2">Layout</label>
- <select name="layout" id="layout"
- 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">
- <?php foreach ($layouts as $layoutValue => $layoutLabel): ?>
- <option value="<?= $layoutValue ?>" <?= ($page['layout'] ?? 'default') === $layoutValue ? 'selected' : '' ?>>
- <?= htmlspecialchars($layoutLabel) ?>
- </option>
- <?php endforeach; ?>
- </select>
-
- <div class="flex items-center mt-3">
- <input type="hidden" name="is_homepage" value="0">
- <input type="checkbox" name="is_homepage" value="1" id="is_homepage"
- <?= !empty($page['is_homepage']) ? 'checked' : '' ?>
- class="h-4 w-4 text-blue-600 focus:ring-blue-500 border-gray-300 rounded">
- <label for="is_homepage" class="ml-2 block text-sm text-gray-900">Set as Homepage</label>
- </div>
- </div>
- </div>
- <?php if ($action === 'create'): ?>
- <!-- For new pages, show only basic info and a note -->
- <div class="bg-blue-50 border border-blue-200 rounded-lg p-4">
- <div class="flex">
- <svg class="w-5 h-5 text-blue-400 mr-3 mt-0.5" fill="currentColor" viewBox="0 0 20 20">
- <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"/>
- </svg>
- <div>
- <h4 class="text-sm font-medium text-blue-800">Create Page First</h4>
- <p class="text-sm text-blue-700 mt-1">Save this page to access layout-specific content fields and advanced options.</p>
- </div>
- </div>
- </div>
- <?php else: ?>
- <!-- For existing pages, show title field and layout-specific forms -->
- <div>
- <label for="title" class="block text-sm font-medium text-gray-700 mb-2">Page Title</label>
- <input type="text" name="title" id="title"
- value="<?= htmlspecialchars($page['title'] ?? '') ?>"
- 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">
- </div>
- <!-- Layout-Specific Forms (only for edit mode) -->
- <div>
- <?php
- $currentLayout = $page['layout'] ?? 'default';
- $layoutFormPath = __DIR__ . "/layouts/{$currentLayout}.php";
- if (file_exists($layoutFormPath)) {
- include $layoutFormPath;
- } else {
- // Fallback to default form
- include __DIR__ . "/layouts/default.php";
- }
- ?>
- </div>
- <?php endif; ?>
- <div class="flex justify-between pt-6 border-t border-gray-200">
- <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">
- <svg class="w-5 h-5 mr-2" fill="currentColor" viewBox="0 0 20 20">
- <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"/>
- </svg>
- Cancel
- </a>
- <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">
- <svg class="w-5 h-5 mr-2" fill="currentColor" viewBox="0 0 20 20">
- <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"/>
- </svg>
- <?= $action === 'create' ? 'Create Page' : 'Update Page' ?>
- </button>
- </div>
- </div>
- </form>
- </div>
- </div>
- <?php
- $content = ob_get_clean();
- include __DIR__ . '/../partials/layout.php';
- ?>
|