📁 File Manager
Editing:
/home/wvl7mof7402e/www/chem/admin/faqs.php
<?php /** * Pure Chemical Admin * File: admin/faqs.php * * Existing tables: * - faqs * - categories * * No new tables. */ if (session_status() !== PHP_SESSION_ACTIVE) { session_start(); } require_once __DIR__ . '/includes/db.php'; if (file_exists(__DIR__ . '/includes/auth.php')) { require_once __DIR__ . '/includes/auth.php'; } if (function_exists('requireAdmin')) { requireAdmin(); } /* ========================================================= HELPERS ========================================================= */ function pc_faq_e($value) { return htmlspecialchars((string)$value, ENT_QUOTES, 'UTF-8'); } function pc_faq_csrf_field() { if (function_exists('csrf_field')) { return csrf_field(); } if (empty($_SESSION['csrf_token'])) { $_SESSION['csrf_token'] = bin2hex(random_bytes(32)); } return '<input type="hidden" name="csrf_token" value="' . pc_faq_e($_SESSION['csrf_token']) . '">'; } function pc_faq_verify_csrf() { if (function_exists('csrf_verify')) { csrf_verify(); return true; } $token = $_POST['csrf_token'] ?? ''; if ( empty($_SESSION['csrf_token']) || !hash_equals($_SESSION['csrf_token'], $token) ) { throw new RuntimeException( 'Invalid security token. Please refresh the page and try again.' ); } return true; } function pc_faq_flash($type, $message) { $_SESSION['faq_flash'] = [ 'type' => $type, 'message' => $message ]; } function pc_faq_get_flash() { $flash = $_SESSION['faq_flash'] ?? null; unset($_SESSION['faq_flash']); return $flash; } function pc_faq_redirect($url) { header('Location: ' . $url); exit; } /* ========================================================= INITIAL STATE ========================================================= */ $flash = pc_faq_get_flash(); $editId = isset($_GET['edit']) ? (int)$_GET['edit'] : 0; $categoryFilter = isset($_GET['category_id']) ? (int)$_GET['category_id'] : 0; $statusFilter = isset($_GET['status']) ? $_GET['status'] : ''; $search = trim($_GET['search'] ?? ''); /* ========================================================= CATEGORIES ========================================================= */ $categories = []; try { $categoryStmt = $pdo->query(" SELECT id, name, slug FROM categories ORDER BY name ASC, id ASC "); $categories = $categoryStmt->fetchAll(); } catch (Throwable $e) { $categories = []; } /* ========================================================= FORM DEFAULTS ========================================================= */ $form = [ 'id' => 0, 'category_id' => null, 'question' => '', 'answer' => '', 'sort_order' => 0, 'status' => 1 ]; /* ========================================================= LOAD EDIT FAQ ========================================================= */ if ($editId > 0) { try { $stmt = $pdo->prepare(" SELECT id, category_id, question, answer, sort_order, status, created_at, updated_at FROM faqs WHERE id = ? LIMIT 1 "); $stmt->execute([$editId]); $faq = $stmt->fetch(); if (!$faq) { pc_faq_flash( 'error', 'FAQ record nahi mila.' ); pc_faq_redirect('faqs.php'); } $form = array_merge($form, $faq); } catch (Throwable $e) { pc_faq_flash( 'error', 'FAQ load nahi ho saka.' ); pc_faq_redirect('faqs.php'); } } /* ========================================================= POST ACTIONS ========================================================= */ if ($_SERVER['REQUEST_METHOD'] === 'POST') { try { pc_faq_verify_csrf(); $action = $_POST['action'] ?? ''; /* ================================================= SAVE / UPDATE ================================================= */ if ($action === 'save') { $id = (int)($_POST['id'] ?? 0); $categoryId = (int)($_POST['category_id'] ?? 0); $question = trim($_POST['question'] ?? ''); $answer = trim($_POST['answer'] ?? ''); $sortOrder = (int)($_POST['sort_order'] ?? 0); $status = isset($_POST['status']) ? 1 : 0; if ($question === '') { throw new RuntimeException( 'Question required hai.' ); } if ($answer === '') { throw new RuntimeException( 'Answer required hai.' ); } /* * category_id database me nullable hai. * 0 ko NULL store karenge. */ $categoryDb = $categoryId > 0 ? $categoryId : null; if ($id > 0) { $stmt = $pdo->prepare(" UPDATE faqs SET category_id = ?, question = ?, answer = ?, sort_order = ?, status = ? WHERE id = ? LIMIT 1 "); $stmt->execute([ $categoryDb, $question, $answer, $sortOrder, $status, $id ]); pc_faq_flash( 'success', 'FAQ successfully updated.' ); } else { $stmt = $pdo->prepare(" INSERT INTO faqs ( category_id, question, answer, sort_order, status ) VALUES (?, ?, ?, ?, ?) "); $stmt->execute([ $categoryDb, $question, $answer, $sortOrder, $status ]); pc_faq_flash( 'success', 'New FAQ successfully created.' ); } pc_faq_redirect('faqs.php'); } /* ================================================= DELETE ================================================= */ if ($action === 'delete') { $id = (int)($_POST['id'] ?? 0); if ($id <= 0) { throw new RuntimeException( 'Invalid FAQ ID.' ); } $stmt = $pdo->prepare(" DELETE FROM faqs WHERE id = ? LIMIT 1 "); $stmt->execute([$id]); pc_faq_flash( 'success', 'FAQ deleted successfully.' ); pc_faq_redirect('faqs.php'); } /* ================================================= TOGGLE STATUS ================================================= */ if ($action === 'toggle_status') { $id = (int)($_POST['id'] ?? 0); if ($id <= 0) { throw new RuntimeException( 'Invalid FAQ ID.' ); } $stmt = $pdo->prepare(" UPDATE faqs SET status = IF(status = 1, 0, 1) WHERE id = ? LIMIT 1 "); $stmt->execute([$id]); pc_faq_flash( 'success', 'FAQ status updated.' ); pc_faq_redirect('faqs.php'); } /* ================================================= QUICK SORT ================================================= */ if ($action === 'quick_sort') { $id = (int)($_POST['id'] ?? 0); $sortOrder = (int)( $_POST['sort_order'] ?? 0 ); if ($id <= 0) { throw new RuntimeException( 'Invalid FAQ ID.' ); } $stmt = $pdo->prepare(" UPDATE faqs SET sort_order = ? WHERE id = ? LIMIT 1 "); $stmt->execute([ $sortOrder, $id ]); pc_faq_flash( 'success', 'FAQ order updated.' ); pc_faq_redirect('faqs.php'); } } catch (Throwable $e) { $flash = [ 'type' => 'error', 'message' => $e->getMessage() ]; } } /* ========================================================= FAQ LIST ========================================================= */ $faqs = []; try { $where = []; $params = []; if ($categoryFilter > 0) { $where[] = 'f.category_id = ?'; $params[] = $categoryFilter; } if ( $statusFilter !== '' && in_array($statusFilter, ['0', '1'], true) ) { $where[] = 'f.status = ?'; $params[] = (int)$statusFilter; } if ($search !== '') { $where[] = " ( f.question LIKE ? OR f.answer LIKE ? ) "; $like = '%' . $search . '%'; $params[] = $like; $params[] = $like; } $whereSql = ''; if (!empty($where)) { $whereSql = 'WHERE ' . implode( ' AND ', $where ); } $sql = " SELECT f.id, f.category_id, f.question, f.answer, f.sort_order, f.status, f.created_at, f.updated_at, c.name AS category_name, c.slug AS category_slug FROM faqs f LEFT JOIN categories c ON c.id = f.category_id {$whereSql} ORDER BY f.sort_order ASC, f.id DESC "; $stmt = $pdo->prepare($sql); $stmt->execute($params); $faqs = $stmt->fetchAll(); } catch (Throwable $e) { $faqs = []; if (!$flash) { $flash = [ 'type' => 'error', 'message' => 'FAQs load nahi ho sake.' ]; } } /* ========================================================= STATISTICS ========================================================= */ $totalFaqs = count($faqs); $activeFaqs = 0; $inactiveFaqs = 0; $categorizedFaqs = 0; $uncategorizedFaqs = 0; foreach ($faqs as $faq) { if ((int)$faq['status'] === 1) { $activeFaqs++; } else { $inactiveFaqs++; } if ( !empty($faq['category_id']) && !empty($faq['category_name']) ) { $categorizedFaqs++; } else { $uncategorizedFaqs++; } } ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0" > <title> FAQs | Pure Chemical Admin </title> <meta name="robots" content="noindex,nofollow" > <link rel="preconnect" href="https://fonts.googleapis.com" > <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin > <link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&display=swap" rel="stylesheet" > <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.2/css/all.min.css" > <style> :root { --primary: #0f766e; --primary-dark: #115e59; --primary-soft: #ecfdf5; --blue: #2563eb; --blue-soft: #eff6ff; --orange: #ea580c; --orange-soft: #fff7ed; --purple: #7c3aed; --purple-soft: #f5f3ff; --red: #dc2626; --red-soft: #fef2f2; --green: #16a34a; --green-soft: #f0fdf4; --dark: #0f172a; --text: #334155; --muted: #64748b; --border: #e2e8f0; --surface: #ffffff; --surface-soft: #f8fafc; --shadow-sm: 0 1px 2px rgba(15, 23, 42, .04); --shadow-md: 0 10px 30px rgba(15, 23, 42, .07); --shadow-lg: 0 20px 60px rgba(15, 23, 42, .10); --radius: 18px; } * { box-sizing: border-box; } html { scroll-behavior: smooth; } body { margin: 0; background: linear-gradient( 180deg, #f8fafc 0%, #f1f5f9 100% ); color: var(--text); font-family: "Inter", sans-serif; font-size: 14px; } a { color: inherit; text-decoration: none; } button, input, select, textarea { font: inherit; } /* ===================================================== TOPBAR ===================================================== */ .pc-topbar { position: sticky; top: 0; z-index: 1000; min-height: 76px; margin-left: 280px; padding: 14px 30px; display: flex; align-items: center; justify-content: space-between; gap: 20px; background: rgba(255,255,255,.93); backdrop-filter: blur(18px); border-bottom: 1px solid rgba(226,232,240,.85); box-shadow: 0 8px 30px rgba(15,23,42,.04); } .pc-top-title { display: flex; align-items: center; gap: 13px; } .pc-top-icon { width: 44px; height: 44px; display: grid; place-items: center; border-radius: 14px; color: #fff; background: linear-gradient( 135deg, var(--primary), var(--primary-dark) ); box-shadow: 0 10px 24px rgba(15,118,110,.22); } .pc-top-title h1 { margin: 0; color: var(--dark); font-size: 18px; font-weight: 800; letter-spacing: -.35px; } .pc-top-title p { margin: 3px 0 0; color: var(--muted); font-size: 12px; } .pc-top-actions { display: flex; align-items: center; gap: 10px; } .pc-top-link { height: 42px; padding: 0 15px; display: inline-flex; align-items: center; justify-content: center; gap: 8px; border: 1px solid var(--border); border-radius: 12px; background: #fff; color: var(--text); font-size: 13px; font-weight: 700; transition: .2s ease; } .pc-top-link:hover { border-color: #cbd5e1; transform: translateY(-1px); box-shadow: var(--shadow-sm); } /* ===================================================== MAIN ===================================================== */ .pc-main { margin-left: 280px; padding: 30px; min-height: calc(100vh - 76px); } .pc-container { max-width: 1700px; margin: 0 auto; } /* ===================================================== HERO ===================================================== */ .pc-hero { position: relative; overflow: hidden; padding: 30px; border-radius: 24px; color: #fff; background: linear-gradient( 135deg, #0f172a 0%, #134e4a 55%, #0f766e 100% ); box-shadow: var(--shadow-lg); margin-bottom: 22px; } .pc-hero::before { content: ""; position: absolute; width: 280px; height: 280px; right: -100px; top: -120px; border-radius: 50%; background: rgba(255,255,255,.07); } .pc-hero::after { content: ""; position: absolute; width: 190px; height: 190px; right: 170px; bottom: -125px; border-radius: 50%; background: rgba(255,255,255,.05); } .pc-hero-inner { position: relative; z-index: 2; display: flex; align-items: center; justify-content: space-between; gap: 25px; } .pc-hero h2 { margin: 0 0 8px; font-size: 27px; font-weight: 800; letter-spacing: -.7px; } .pc-hero p { max-width: 780px; margin: 0; color: rgba(255,255,255,.76); line-height: 1.7; } .pc-hero-btn { flex-shrink: 0; height: 46px; padding: 0 19px; display: inline-flex; align-items: center; gap: 9px; border: 1px solid rgba(255,255,255,.15); border-radius: 13px; background: rgba(255,255,255,.12); color: #fff; font-weight: 800; backdrop-filter: blur(10px); transition: .2s ease; } .pc-hero-btn:hover { background: rgba(255,255,255,.2); transform: translateY(-1px); } /* ===================================================== ALERT ===================================================== */ .pc-alert { margin-bottom: 20px; padding: 14px 16px; display: flex; align-items: center; gap: 11px; border-radius: 14px; font-weight: 600; } .pc-alert.success { color: #166534; background: var(--green-soft); border: 1px solid #bbf7d0; } .pc-alert.error { color: #991b1b; background: var(--red-soft); border: 1px solid #fecaca; } /* ===================================================== STATS ===================================================== */ .pc-stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; margin-bottom: 22px; } .pc-stat { padding: 20px; display: flex; align-items: center; gap: 14px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-sm); } .pc-stat-icon { width: 48px; height: 48px; flex-shrink: 0; display: grid; place-items: center; border-radius: 14px; font-size: 18px; } .pc-stat:nth-child(1) .pc-stat-icon { color: var(--primary); background: var(--primary-soft); } .pc-stat:nth-child(2) .pc-stat-icon { color: var(--blue); background: var(--blue-soft); } .pc-stat:nth-child(3) .pc-stat-icon { color: var(--green); background: var(--green-soft); } .pc-stat:nth-child(4) .pc-stat-icon { color: var(--orange); background: var(--orange-soft); } .pc-stat-label { margin-bottom: 3px; color: var(--muted); font-size: 12px; font-weight: 600; } .pc-stat-value { color: var(--dark); font-size: 22px; font-weight: 800; } /* ===================================================== CARD ===================================================== */ .pc-card { overflow: hidden; margin-bottom: 22px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-md); } .pc-card-head { padding: 20px 22px; display: flex; align-items: center; justify-content: space-between; gap: 15px; border-bottom: 1px solid var(--border); } .pc-card-head h3 { margin: 0; color: var(--dark); font-size: 15px; font-weight: 800; } .pc-card-head p { margin: 4px 0 0; color: var(--muted); font-size: 12px; } .pc-card-body { padding: 22px; } /* ===================================================== FILTER ===================================================== */ .pc-filters { display: grid; grid-template-columns: minmax(220px, 1.4fr) minmax(210px, 1fr) minmax(170px, .7fr) auto; gap: 12px; align-items: end; } .pc-field { min-width: 0; } .pc-field label { display: block; margin: 0 0 7px; color: #475569; font-size: 12px; font-weight: 800; } .pc-input, .pc-select, .pc-textarea { width: 100%; border: 1px solid #dbe3ec; border-radius: 11px; background: #fff; color: var(--dark); outline: none; transition: .2s ease; } .pc-input, .pc-select { height: 43px; padding: 0 13px; } .pc-textarea { min-height: 140px; padding: 12px 13px; resize: vertical; line-height: 1.65; } .pc-input:focus, .pc-select:focus, .pc-textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 4px rgba(15,118,110,.09); } .pc-filter-actions { display: flex; gap: 8px; } /* ===================================================== BUTTONS ===================================================== */ .pc-btn { min-height: 43px; padding: 0 15px; display: inline-flex; align-items: center; justify-content: center; gap: 8px; border: 1px solid transparent; border-radius: 11px; cursor: pointer; font-size: 13px; font-weight: 800; transition: .2s ease; } .pc-btn:hover { transform: translateY(-1px); } .pc-btn-primary { color: #fff; background: var(--primary); box-shadow: 0 8px 20px rgba(15,118,110,.18); } .pc-btn-primary:hover { background: var(--primary-dark); } .pc-btn-light { color: #334155; background: #fff; border-color: var(--border); } .pc-btn-danger { color: #b91c1c; background: #fff; border-color: #fecaca; } .pc-btn-danger:hover { background: var(--red-soft); } .pc-btn-small { min-height: 35px; padding: 0 10px; border-radius: 9px; font-size: 12px; } /* ===================================================== TABLE ===================================================== */ .pc-table-wrap { width: 100%; overflow-x: auto; } .pc-table { width: 100%; min-width: 1050px; border-collapse: collapse; } .pc-table th { padding: 13px 16px; background: #f8fafc; border-bottom: 1px solid var(--border); color: #64748b; text-align: left; font-size: 11px; font-weight: 800; text-transform: uppercase; letter-spacing: .05em; white-space: nowrap; } .pc-table td { padding: 15px 16px; border-bottom: 1px solid #edf1f5; vertical-align: middle; } .pc-table tbody tr { transition: .18s ease; } .pc-table tbody tr:hover { background: #fbfefd; } /* ===================================================== FAQ QUESTION ===================================================== */ .pc-question-wrap { display: flex; align-items: flex-start; gap: 12px; } .pc-question-icon { width: 40px; height: 40px; flex-shrink: 0; display: grid; place-items: center; border-radius: 12px; color: var(--primary); background: var(--primary-soft); } .pc-question { max-width: 460px; color: var(--dark); font-weight: 800; line-height: 1.45; } .pc-answer-preview { max-width: 420px; margin-top: 4px; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; color: var(--muted); font-size: 11px; line-height: 1.55; } /* ===================================================== CATEGORY ===================================================== */ .pc-category { display: inline-flex; align-items: center; gap: 7px; padding: 6px 10px; border-radius: 9px; color: #475569; background: #f1f5f9; font-size: 11px; font-weight: 800; } .pc-category i { color: var(--primary); } .pc-no-category { color: #94a3b8; font-size: 12px; font-style: italic; } /* ===================================================== STATUS ===================================================== */ .pc-status { display: inline-flex; align-items: center; gap: 6px; padding: 6px 9px; border-radius: 999px; font-size: 11px; font-weight: 800; } .pc-status.active { color: #166534; background: #dcfce7; } .pc-status.inactive { color: #991b1b; background: #fee2e2; } .pc-dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; } /* ===================================================== ACTIONS ===================================================== */ .pc-actions { display: flex; align-items: center; gap: 7px; } .pc-icon-btn { width: 35px; height: 35px; display: grid; place-items: center; border: 1px solid var(--border); border-radius: 9px; background: #fff; color: #64748b; cursor: pointer; transition: .2s ease; } .pc-icon-btn:hover { color: var(--primary); border-color: #99f6e4; background: #f0fdfa; } .pc-icon-btn.danger:hover { color: var(--red); border-color: #fecaca; background: var(--red-soft); } /* ===================================================== FORM ===================================================== */ .pc-form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; } .pc-form-grid .full { grid-column: 1 / -1; } .pc-form-section { margin-top: 24px; padding-top: 22px; border-top: 1px solid var(--border); } .pc-form-section:first-child { margin-top: 0; padding-top: 0; border-top: 0; } .pc-form-section-title { display: flex; align-items: center; gap: 9px; margin-bottom: 16px; color: var(--dark); font-size: 13px; font-weight: 800; } .pc-form-section-title i { color: var(--primary); } .pc-help { margin-top: 6px; color: var(--muted); font-size: 11px; line-height: 1.5; } /* ===================================================== SWITCH ===================================================== */ .pc-switch-row { height: 43px; padding: 0 12px; display: flex; align-items: center; justify-content: space-between; border: 1px solid #dbe3ec; border-radius: 11px; background: #fff; } .pc-switch-label { color: #334155; font-weight: 700; } .pc-switch { position: relative; width: 42px; height: 23px; } .pc-switch input { opacity: 0; width: 0; height: 0; } .pc-slider { position: absolute; inset: 0; cursor: pointer; border-radius: 999px; background: #cbd5e1; transition: .2s ease; } .pc-slider::before { content: ""; position: absolute; width: 17px; height: 17px; left: 3px; top: 3px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.2); transition: .2s ease; } .pc-switch input:checked + .pc-slider { background: var(--primary); } .pc-switch input:checked + .pc-slider::before { transform: translateX(19px); } /* ===================================================== EMPTY ===================================================== */ .pc-empty { padding: 60px 25px; text-align: center; } .pc-empty-icon { width: 64px; height: 64px; margin: 0 auto 15px; display: grid; place-items: center; border-radius: 18px; color: var(--primary); background: var(--primary-soft); font-size: 24px; } .pc-empty h3 { margin: 0 0 7px; color: var(--dark); font-size: 16px; } .pc-empty p { max-width: 520px; margin: 0 auto; color: var(--muted); line-height: 1.6; } /* ===================================================== FORM FOOTER ===================================================== */ .pc-form-footer { margin-top: 24px; padding-top: 20px; display: flex; align-items: center; justify-content: space-between; gap: 15px; border-top: 1px solid var(--border); } .pc-form-actions { display: flex; gap: 9px; } /* ===================================================== RESPONSIVE ===================================================== */ @media (max-width: 1200px) { .pc-stats { grid-template-columns: repeat(2, 1fr); } .pc-filters { grid-template-columns: repeat(2, 1fr); } .pc-filter-actions { grid-column: 1 / -1; } } @media (max-width: 1100px) { .pc-topbar, .pc-main { margin-left: 0; } .pc-main { padding: 22px; } } @media (max-width: 760px) { .pc-topbar { min-height: auto; padding: 13px 16px; } .pc-top-title p { display: none; } .pc-top-actions .pc-top-link span { display: none; } .pc-top-link { width: 42px; padding: 0; justify-content: center; } .pc-main { padding: 15px; } .pc-hero { padding: 23px; border-radius: 19px; } .pc-hero-inner { align-items: flex-start; flex-direction: column; } .pc-hero h2 { font-size: 23px; } .pc-stats { grid-template-columns: 1fr 1fr; gap: 10px; } .pc-stat { padding: 15px; } .pc-stat-value { font-size: 19px; } .pc-stat-icon { width: 42px; height: 42px; } .pc-filters { grid-template-columns: 1fr; } .pc-filter-actions { grid-column: auto; } .pc-form-grid { grid-template-columns: 1fr; } .pc-form-grid .full { grid-column: auto; } .pc-card-head, .pc-card-body { padding: 17px; } .pc-form-footer { align-items: stretch; flex-direction: column; } .pc-form-actions { width: 100%; } .pc-form-actions .pc-btn { flex: 1; } } @media (max-width: 480px) { .pc-stats { grid-template-columns: 1fr; } .pc-top-title h1 { font-size: 15px; } .pc-top-icon { width: 39px; height: 39px; } } </style> </head> <body> <?php /* |-------------------------------------------------------------------------- | Existing sidebar — separately included |-------------------------------------------------------------------------- */ require_once __DIR__ . '/sidebar.php'; ?> <!-- ========================================================= TOPBAR ========================================================= --> <header class="pc-topbar"> <div class="pc-top-title"> <div class="pc-top-icon"> <i class="fa-solid fa-circle-question"></i> </div> <div> <h1> FAQs </h1> <p> Frequently asked questions management </p> </div> </div> <div class="pc-top-actions"> <a href="faqs.php" class="pc-top-link" > <i class="fa-solid fa-rotate"></i> <span>Refresh</span> </a> <a href="categories.php" class="pc-top-link" > <i class="fa-solid fa-folder-tree"></i> <span>Categories</span> </a> </div> </header> <!-- ========================================================= MAIN ========================================================= --> <main class="pc-main"> <div class="pc-container"> <!-- ================================================= HERO ================================================== --> <section class="pc-hero"> <div class="pc-hero-inner"> <div> <h2> FAQ Management </h2> <p> Manage your website's frequently asked questions, organize them by category, control display order and publish status from one premium admin interface. </p> </div> <a href="faqs.php#faq-editor" class="pc-hero-btn" > <i class="fa-solid fa-plus"></i> Add FAQ </a> </div> </section> <!-- ================================================= FLASH ================================================== --> <?php if ($flash): ?> <div class="pc-alert <?= $flash['type'] === 'success' ? 'success' : 'error' ?>" > <i class="fa-solid <?= $flash['type'] === 'success' ? 'fa-circle-check' : 'fa-circle-exclamation' ?>"></i> <span> <?= pc_faq_e($flash['message']) ?> </span> </div> <?php endif; ?> <!-- ================================================= STATS ================================================== --> <section class="pc-stats"> <div class="pc-stat"> <div class="pc-stat-icon"> <i class="fa-solid fa-circle-question"></i> </div> <div> <div class="pc-stat-label"> Total FAQs </div> <div class="pc-stat-value"> <?= number_format($totalFaqs) ?> </div> </div> </div> <div class="pc-stat"> <div class="pc-stat-icon"> <i class="fa-solid fa-circle-check"></i> </div> <div> <div class="pc-stat-label"> Active FAQs </div> <div class="pc-stat-value"> <?= number_format($activeFaqs) ?> </div> </div> </div> <div class="pc-stat"> <div class="pc-stat-icon"> <i class="fa-solid fa-folder"></i> </div> <div> <div class="pc-stat-label"> Categorized </div> <div class="pc-stat-value"> <?= number_format($categorizedFaqs) ?> </div> </div> </div> <div class="pc-stat"> <div class="pc-stat-icon"> <i class="fa-solid fa-circle-pause"></i> </div> <div> <div class="pc-stat-label"> Inactive / Uncategorized </div> <div class="pc-stat-value"> <?= number_format( $inactiveFaqs + $uncategorizedFaqs ) ?> </div> </div> </div> </section> <!-- ================================================= FILTER CARD ================================================== --> <section class="pc-card"> <div class="pc-card-head"> <div> <h3> Filter FAQs </h3> <p> Search FAQs and filter them by category or status. </p> </div> </div> <div class="pc-card-body"> <form method="get" action="faqs.php" > <div class="pc-filters"> <div class="pc-field"> <label for="search"> Search </label> <input type="text" name="search" id="search" class="pc-input" value="<?= pc_faq_e($search) ?>" placeholder="Search question or answer..." > </div> <div class="pc-field"> <label for="category_id"> Category </label> <select name="category_id" id="category_id" class="pc-select" > <option value=""> All Categories </option> <?php foreach ($categories as $category): ?> <option value="<?= (int)$category['id'] ?>" <?= $categoryFilter === (int)$category['id'] ? 'selected' : '' ?> > <?= pc_faq_e( $category['name'] ) ?> <?php if (!empty($category['slug'])): ?> — <?= pc_faq_e( $category['slug'] ) ?> <?php endif; ?> </option> <?php endforeach; ?> </select> </div> <div class="pc-field"> <label for="status"> Status </label> <select name="status" id="status" class="pc-select" > <option value=""> All Status </option> <option value="1" <?= $statusFilter === '1' ? 'selected' : '' ?> > Active </option> <option value="0" <?= $statusFilter === '0' ? 'selected' : '' ?> > Inactive </option> </select> </div> <div class="pc-filter-actions"> <button type="submit" class="pc-btn pc-btn-primary" > <i class="fa-solid fa-filter"></i> Apply </button> <a href="faqs.php" class="pc-btn pc-btn-light" > <i class="fa-solid fa-rotate-left"></i> Reset </a> </div> </div> </form> </div> </section> <!-- ================================================= FAQ LIST ================================================== --> <section class="pc-card"> <div class="pc-card-head"> <div> <h3> FAQ List </h3> <p> <?= number_format($totalFaqs) ?> FAQ(s) found. </p> </div> <a href="faqs.php#faq-editor" class="pc-btn pc-btn-primary pc-btn-small" > <i class="fa-solid fa-plus"></i> New FAQ </a> </div> <?php if (empty($faqs)): ?> <div class="pc-empty"> <div class="pc-empty-icon"> <i class="fa-solid fa-circle-question"></i> </div> <h3> No FAQs found </h3> <p> Abhi koi FAQ available nahi hai. New FAQ button se apna first FAQ create karein. </p> </div> <?php else: ?> <div class="pc-table-wrap"> <table class="pc-table"> <thead> <tr> <th> Question </th> <th> Category </th> <th> Order </th> <th> Status </th> <th> Updated </th> <th> Actions </th> </tr> </thead> <tbody> <?php foreach ($faqs as $faq): ?> <tr> <!-- QUESTION --> <td> <div class="pc-question-wrap"> <div class="pc-question-icon"> <i class="fa-solid fa-question"></i> </div> <div> <div class="pc-question"> <?= pc_faq_e( $faq['question'] ) ?> </div> <div class="pc-answer-preview"> <?= pc_faq_e( trim( strip_tags( $faq['answer'] ) ) ) ?> </div> </div> </div> </td> <!-- CATEGORY --> <td> <?php if ( !empty($faq['category_id']) && !empty($faq['category_name']) ): ?> <span class="pc-category"> <i class="fa-solid fa-folder"></i> <?= pc_faq_e( $faq['category_name'] ) ?> </span> <?php else: ?> <span class="pc-no-category"> No category </span> <?php endif; ?> </td> <!-- ORDER --> <td> <form method="post" style=" display:flex; align-items:center; gap:6px; " > <?= pc_faq_csrf_field() ?> <input type="hidden" name="action" value="quick_sort" > <input type="hidden" name="id" value="<?= (int)$faq['id'] ?>" > <input type="number" name="sort_order" value="<?= (int)$faq['sort_order'] ?>" min="0" class="pc-input" style=" width:72px; height:34px; padding:0 8px; " > <button type="submit" class="pc-icon-btn" title="Save order" > <i class="fa-solid fa-check"></i> </button> </form> </td> <!-- STATUS --> <td> <?php if ( (int)$faq['status'] === 1 ): ?> <span class="pc-status active"> <span class="pc-dot"></span> Active </span> <?php else: ?> <span class="pc-status inactive"> <span class="pc-dot"></span> Inactive </span> <?php endif; ?> </td> <!-- UPDATED --> <td> <span style=" color:#64748b; font-size:12px; " > <?= !empty($faq['updated_at']) ? pc_faq_e( date( 'd M Y, h:i A', strtotime( $faq['updated_at'] ) ) ) : '—' ?> </span> </td> <!-- ACTIONS --> <td> <div class="pc-actions"> <!-- EDIT --> <a href="faqs.php?edit=<?= (int)$faq['id'] ?>" class="pc-icon-btn" title="Edit FAQ" > <i class="fa-solid fa-pen"></i> </a> <!-- TOGGLE --> <form method="post" onsubmit="return confirm('FAQ status change karna hai?');" > <?= pc_faq_csrf_field() ?> <input type="hidden" name="action" value="toggle_status" > <input type="hidden" name="id" value="<?= (int)$faq['id'] ?>" > <button type="submit" class="pc-icon-btn" title="Toggle status" > <i class="fa-solid fa-power-off"></i> </button> </form> <!-- DELETE --> <form method="post" onsubmit="return confirm('Ye FAQ permanently delete ho jayega. Continue?');" > <?= pc_faq_csrf_field() ?> <input type="hidden" name="action" value="delete" > <input type="hidden" name="id" value="<?= (int)$faq['id'] ?>" > <button type="submit" class="pc-icon-btn danger" title="Delete FAQ" > <i class="fa-solid fa-trash"></i> </button> </form> </div> </td> </tr> <?php endforeach; ?> </tbody> </table> </div> <?php endif; ?> </section> <!-- ================================================= ADD / EDIT FAQ ================================================== --> <section class="pc-card" id="faq-editor" > <div class="pc-card-head"> <div> <h3> <?php if ((int)$form['id'] > 0): ?> Edit FAQ #<?= (int)$form['id'] ?> <?php else: ?> Create New FAQ <?php endif; ?> </h3> <p> FAQ data existing <strong>faqs</strong> table me save hoga. </p> </div> <?php if ((int)$form['id'] > 0): ?> <a href="faqs.php" class="pc-btn pc-btn-light pc-btn-small" > <i class="fa-solid fa-plus"></i> New FAQ </a> <?php endif; ?> </div> <div class="pc-card-body"> <form method="post" action="faqs.php<?= (int)$form['id'] > 0 ? '?edit=' . (int)$form['id'] : '' ?>" > <?= pc_faq_csrf_field() ?> <input type="hidden" name="action" value="save" > <input type="hidden" name="id" value="<?= (int)$form['id'] ?>" > <!-- BASIC --> <div class="pc-form-section"> <div class="pc-form-section-title"> <i class="fa-solid fa-circle-question"></i> FAQ Information </div> <div class="pc-form-grid"> <!-- CATEGORY --> <div class="pc-field"> <label for="form_category_id"> Category </label> <select name="category_id" id="form_category_id" class="pc-select" > <option value=""> No Category </option> <?php foreach ($categories as $category): ?> <option value="<?= (int)$category['id'] ?>" <?= (int)$form['category_id'] === (int)$category['id'] ? 'selected' : '' ?> > <?= pc_faq_e( $category['name'] ) ?> <?php if ( !empty($category['slug']) ): ?> — <?= pc_faq_e( $category['slug'] ) ?> <?php endif; ?> </option> <?php endforeach; ?> </select> <div class="pc-help"> Category optional hai; database me <code>NULL</code> allowed hai. </div> </div> <!-- SORT --> <div class="pc-field"> <label for="form_sort_order"> Sort Order </label> <input type="number" name="sort_order" id="form_sort_order" class="pc-input" value="<?= (int)$form['sort_order'] ?>" min="0" > <div class="pc-help"> Lower number FAQ ko pehle display karega. </div> </div> <!-- QUESTION --> <div class="pc-field full"> <label for="form_question"> Question <span style="color:#dc2626;">*</span> </label> <input type="text" name="question" id="form_question" class="pc-input" value="<?= pc_faq_e( $form['question'] ) ?>" maxlength="500" placeholder="Enter frequently asked question..." required > <div class="pc-help"> Maximum 500 characters. </div> </div> <!-- ANSWER --> <div class="pc-field full"> <label for="form_answer"> Answer <span style="color:#dc2626;">*</span> </label> <textarea name="answer" id="form_answer" class="pc-textarea" rows="9" placeholder="Enter detailed answer..." required ><?= pc_faq_e( $form['answer'] ) ?></textarea> <div class="pc-help"> Detailed FAQ answer existing <code>answer</code> longtext column me save hoga. </div> </div> </div> </div> <!-- PUBLISHING --> <div class="pc-form-section"> <div class="pc-form-section-title"> <i class="fa-solid fa-toggle-on"></i> Publishing </div> <div class="pc-form-grid"> <div class="pc-field"> <label> FAQ Status </label> <div class="pc-switch-row"> <span class="pc-switch-label"> Publish FAQ </span> <label class="pc-switch"> <input type="checkbox" name="status" value="1" <?= (int)$form['status'] === 1 ? 'checked' : '' ?> > <span class="pc-slider"></span> </label> </div> </div> </div> </div> <!-- FOOTER --> <div class="pc-form-footer"> <div style=" color:#64748b; font-size:12px; " > <?php if ((int)$form['id'] > 0): ?> Editing FAQ <strong> #<?= (int)$form['id'] ?> </strong> <?php else: ?> New FAQ will be added to <strong>faqs</strong>. <?php endif; ?> </div> <div class="pc-form-actions"> <?php if ((int)$form['id'] > 0): ?> <a href="faqs.php" class="pc-btn pc-btn-light" > Cancel </a> <?php endif; ?> <button type="submit" class="pc-btn pc-btn-primary" > <i class="fa-solid fa-floppy-disk"></i> <?php if ((int)$form['id'] > 0): ?> Update FAQ <?php else: ?> Save FAQ <?php endif; ?> </button> </div> </div> </form> </div> </section> </div> </main> <script> document.addEventListener( 'DOMContentLoaded', function () { /* * When editing an FAQ, automatically * scroll to the editor. */ const params = new URLSearchParams( window.location.search ); if (params.has('edit')) { const editor = document.getElementById( 'faq-editor' ); if (editor) { setTimeout( function () { editor.scrollIntoView({ behavior: 'smooth', block: 'start' }); }, 150 ); } } } ); </script> </body> </html>
Save
Cancel