🚀 Hostinger Optimized
🖥️ Server: LiteSpeed
💻 System: Linux s20058.bom1.stableserver.net 5.14.0-611.55.1.el9_7.x86_64 #1 SMP PREEMPT_DYNAMIC Tue May 19 15:19:29 EDT 2026 x86_64
👤 User: skhata (1324)
🐘 PHP: 8.4.20
🚫 Disabled: ✨ NONE

💻 Terminal

📁 /home/skhata/chandrasons.com/public
$

📄 program_form.php

📁 Path: //home2/skhata/excellenteducation.com.np/admin/program_form.php
📊 Size: 9.06 KB
🔒 Perm: 0644
📝 MIME: text/x-php
<?php
require_once __DIR__ . '/../includes/auth.php';
require_login();

$id = isset($_GET['id']) ? (int) $_GET['id'] : null;
$isEdit = $id !== null;
$pageTitle = ($isEdit ? 'Edit' : 'Add') . ' Test Prep Program';

$program = [];
if ($isEdit) {
    $stmt = db()->prepare('SELECT * FROM test_preparations WHERE id = ?');
    $stmt->execute([$id]);
    $program = $stmt->fetch() ?: [];
    if (!$program) { http_response_code(404); die('Program not found.'); }
}

$errors = [];

if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    if (!csrf_verify()) {
        $errors[] = 'Session expired, please try again.';
    } else {
        $name = trim($_POST['name'] ?? '');
        $slug = trim($_POST['slug'] ?? '') ?: slugify($name);

        $data = [
            'name' => $name,
            'slug' => slugify($slug),
            'full_name' => trim($_POST['full_name'] ?? ''),
            'overview' => trim($_POST['overview'] ?? ''),
            'syllabus' => lines_to_json($_POST['syllabus'] ?? ''),
            'duration' => trim($_POST['duration'] ?? ''),
            'fee' => trim($_POST['fee'] ?? ''),
            'schedule' => schedule_lines_to_json($_POST['schedule'] ?? ''),
            'faqs' => faq_lines_to_json($_POST['faqs'] ?? ''),
            'seo_title' => trim($_POST['seo_title'] ?? ''),
            'seo_description' => trim($_POST['seo_description'] ?? ''),
            'sort_order' => (int) ($_POST['sort_order'] ?? 0),
            'status' => in_array($_POST['status'] ?? '', ['active', 'inactive']) ? $_POST['status'] : 'active',
        ];

        if ($name === '') $errors[] = 'Program name is required.';

        if (!$errors) {
            $oldSlug = $program['slug'] ?? null;
            if ($isEdit) {
                $set = implode(', ', array_map(fn($k) => "$k = :$k", array_keys($data)));
                $stmt = db()->prepare("UPDATE test_preparations SET $set WHERE id = :id");
                $data['id'] = $id;
                $stmt->execute($data);
            } else {
                $cols = implode(', ', array_keys($data));
                $ph = implode(', ', array_map(fn($k) => ":$k", array_keys($data)));
                $stmt = db()->prepare("INSERT INTO test_preparations ($cols) VALUES ($ph)");
                $stmt->execute($data);
            }
            write_route_stub('test-preparation-', $data['slug'], 'test-preparation-single.php', $oldSlug);
            flash_set('success', 'Test preparation program saved.');
            redirect('test_preparations.php');
        } else {
            $program = array_merge($program, $data);
        }
    }
}

require __DIR__ . '/partials/header.php';
require __DIR__ . '/partials/sidebar.php';
require __DIR__ . '/partials/topbar.php';
?>

<?php if ($errors): ?>
  <div class="mb-6 px-4 py-3 rounded-xl bg-red-50 text-brand-red text-sm font-medium border border-red-200">
    <ul class="list-disc list-inside"><?php foreach ($errors as $err): ?><li><?= e($err) ?></li><?php endforeach; ?></ul>
  </div>
<?php endif; ?>

<form method="post" class="space-y-6 max-w-4xl">
  <?= csrf_field() ?>

  <div class="bg-white rounded-2xl shadow-sm p-6">
    <h2 class="font-heading font-bold text-lg mb-5"><i class="fa-solid fa-book-open-reader text-brand-red mr-2"></i>Basics</h2>
    <div class="grid md:grid-cols-2 gap-5">
      <div><label class="block text-sm font-medium mb-1.5">Short Name (e.g. IELTS) <span class="text-brand-red">*</span></label>
        <input type="text" name="name" value="<?= e($program['name'] ?? '') ?>" required class="w-full rounded-xl border border-gray-300 px-4 py-2.5 text-sm focus:outline-none focus:ring-2 focus:ring-brand-green"></div>
      <div><label class="block text-sm font-medium mb-1.5">Slug (leave blank to auto-generate)</label>
        <input type="text" name="slug" value="<?= e($program['slug'] ?? '') ?>" placeholder="e.g. ielts" class="w-full rounded-xl border border-gray-300 px-4 py-2.5 text-sm focus:outline-none focus:ring-2 focus:ring-brand-green">
        <p class="text-xs text-gray-400 mt-1">Public URL: test-preparation-<?= e($program['slug'] ?? '{slug}') ?>.php</p></div>
      <div class="md:col-span-2"><label class="block text-sm font-medium mb-1.5">Full Name (e.g. International English Language Testing System)</label>
        <input type="text" name="full_name" value="<?= e($program['full_name'] ?? '') ?>" class="w-full rounded-xl border border-gray-300 px-4 py-2.5 text-sm focus:outline-none focus:ring-2 focus:ring-brand-green"></div>
      <div class="md:col-span-2"><label class="block text-sm font-medium mb-1.5">Overview</label>
        <textarea name="overview" rows="3" class="w-full rounded-xl border border-gray-300 px-4 py-2.5 text-sm focus:outline-none focus:ring-2 focus:ring-brand-green"><?= e($program['overview'] ?? '') ?></textarea></div>
      <div><label class="block text-sm font-medium mb-1.5">Duration</label>
        <input type="text" name="duration" value="<?= e($program['duration'] ?? '') ?>" placeholder="e.g. 6-8 Weeks" class="w-full rounded-xl border border-gray-300 px-4 py-2.5 text-sm focus:outline-none focus:ring-2 focus:ring-brand-green"></div>
      <div><label class="block text-sm font-medium mb-1.5">Fee</label>
        <input type="text" name="fee" value="<?= e($program['fee'] ?? '') ?>" placeholder="e.g. NPR 12,000" class="w-full rounded-xl border border-gray-300 px-4 py-2.5 text-sm focus:outline-none focus:ring-2 focus:ring-brand-green"></div>
      <div class="grid grid-cols-2 gap-4 md:col-span-2">
        <div><label class="block text-sm font-medium mb-1.5">Sort Order</label>
          <input type="number" name="sort_order" value="<?= e((string) ($program['sort_order'] ?? 0)) ?>" class="w-full rounded-xl border border-gray-300 px-4 py-2.5 text-sm focus:outline-none focus:ring-2 focus:ring-brand-green"></div>
        <div><label class="block text-sm font-medium mb-1.5">Status</label>
          <select name="status" class="w-full rounded-xl border border-gray-300 px-4 py-2.5 text-sm focus:outline-none focus:ring-2 focus:ring-brand-green">
            <option value="active" <?= ($program['status'] ?? 'active') === 'active' ? 'selected' : '' ?>>Active</option>
            <option value="inactive" <?= ($program['status'] ?? '') === 'inactive' ? 'selected' : '' ?>>Inactive</option>
          </select></div>
      </div>
    </div>
  </div>

  <div class="bg-white rounded-2xl shadow-sm p-6">
    <h2 class="font-heading font-bold text-lg mb-2"><i class="fa-solid fa-list-check text-brand-green mr-2"></i>Syllabus</h2>
    <p class="text-xs text-gray-400 mb-3">One topic per line.</p>
    <textarea name="syllabus" rows="6" class="w-full rounded-xl border border-gray-300 px-4 py-2.5 text-sm font-mono focus:outline-none focus:ring-2 focus:ring-brand-green"><?= e(json_to_lines($program['syllabus'] ?? '[]')) ?></textarea>
  </div>

  <div class="bg-white rounded-2xl shadow-sm p-6">
    <h2 class="font-heading font-bold text-lg mb-2"><i class="fa-solid fa-clock text-brand-gold mr-2"></i>Class Schedule</h2>
    <p class="text-xs text-gray-400 mb-3">One batch per line, format: <code>Batch Name|Days|Time</code> &mdash; e.g. <code>Morning Batch|Sun-Fri|7:00 - 8:30 AM</code></p>
    <textarea name="schedule" rows="4" class="w-full rounded-xl border border-gray-300 px-4 py-2.5 text-sm font-mono focus:outline-none focus:ring-2 focus:ring-brand-green"><?= e(json_to_schedule_lines($program['schedule'] ?? '[]')) ?></textarea>
  </div>

  <div class="bg-white rounded-2xl shadow-sm p-6">
    <h2 class="font-heading font-bold text-lg mb-2"><i class="fa-solid fa-circle-question text-brand-red mr-2"></i>FAQs</h2>
    <p class="text-xs text-gray-400 mb-3">One FAQ per line, format: <code>Question|Answer</code></p>
    <textarea name="faqs" rows="5" class="w-full rounded-xl border border-gray-300 px-4 py-2.5 text-sm font-mono focus:outline-none focus:ring-2 focus:ring-brand-green"><?= e(json_to_faq_lines($program['faqs'] ?? '[]')) ?></textarea>
  </div>

  <div class="bg-white rounded-2xl shadow-sm p-6">
    <h2 class="font-heading font-bold text-lg mb-5"><i class="fa-solid fa-magnifying-glass text-brand-green mr-2"></i>Page SEO</h2>
    <div class="grid gap-5">
      <div><label class="block text-sm font-medium mb-1.5">SEO Title</label>
        <input type="text" name="seo_title" value="<?= e($program['seo_title'] ?? '') ?>" class="w-full rounded-xl border border-gray-300 px-4 py-2.5 text-sm focus:outline-none focus:ring-2 focus:ring-brand-green"></div>
      <div><label class="block text-sm font-medium mb-1.5">SEO Description</label>
        <textarea name="seo_description" rows="2" class="w-full rounded-xl border border-gray-300 px-4 py-2.5 text-sm focus:outline-none focus:ring-2 focus:ring-brand-green"><?= e($program['seo_description'] ?? '') ?></textarea></div>
    </div>
  </div>

  <div class="flex items-center gap-3">
    <button type="submit" class="bg-gradient-to-r from-brand-red to-brand-green text-white font-semibold px-8 py-3 rounded-xl hover:brightness-110 transition">
      <i class="fa-solid fa-floppy-disk mr-2"></i>Save Program
    </button>
    <a href="test_preparations.php" class="text-gray-500 text-sm font-medium hover:text-gray-700">Cancel</a>
  </div>
</form>

<?php require __DIR__ . '/partials/footer.php'; ?>
← Back📥 Raw✏️ Edit🔒 Chmod
✨ File Manager Magic ✨