📁 File Manager
Editing:
/home/wvl7mof7402e/www/chem/admin/form_submissions.php
<?php /** * Pure Chemical Admin * Form Submissions Manager * * File: admin/form_submissions.php * * Existing table used: * form_submissions * * Related table: * forms * form_submission_values * form_fields */ 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 (file_exists(__DIR__ . '/includes/functions.php')) { require_once __DIR__ . '/includes/functions.php'; } if (file_exists(__DIR__ . '/includes/csrf.php')) { require_once __DIR__ . '/includes/csrf.php'; } /* --------------------------------------------------------- AUTH --------------------------------------------------------- */ if (function_exists('requireAdmin')) { requireAdmin(); } /* --------------------------------------------------------- HELPERS --------------------------------------------------------- */ if (!function_exists('e')) { function e($value) { return htmlspecialchars((string)$value, ENT_QUOTES, 'UTF-8'); } } function fs_csrf_field() { if (function_exists('csrf_field')) { return csrf_field(); } if (empty($_SESSION['_csrf'])) { $_SESSION['_csrf'] = bin2hex(random_bytes(32)); } return '<input type="hidden" name="_csrf" value="' . e($_SESSION['_csrf']) . '">'; } function fs_verify_csrf() { if (function_exists('csrf_verify')) { csrf_verify(); return; } $token = $_POST['_csrf'] ?? ''; if ( empty($_SESSION['_csrf']) || empty($token) || !hash_equals($_SESSION['_csrf'], $token) ) { http_response_code(419); exit('Invalid CSRF token.'); } } function fs_redirect($url) { header('Location: ' . $url); exit; } function fs_flash($type, $message) { $_SESSION['form_submission_flash'] = [ 'type' => $type, 'message' => $message ]; } function fs_get_flash() { $flash = $_SESSION['form_submission_flash'] ?? null; unset($_SESSION['form_submission_flash']); return $flash; } function fs_table_exists(PDO $pdo, $table) { try { $stmt = $pdo->prepare(" SELECT COUNT(*) FROM information_schema.tables WHERE table_schema = DATABASE() AND table_name = ? "); $stmt->execute([$table]); return (bool)$stmt->fetchColumn(); } catch (Throwable $e) { return false; } } function fs_column_exists(PDO $pdo, $table, $column) { try { $stmt = $pdo->prepare(" SELECT COUNT(*) FROM information_schema.columns WHERE table_schema = DATABASE() AND table_name = ? AND column_name = ? "); $stmt->execute([$table, $column]); return (bool)$stmt->fetchColumn(); } catch (Throwable $e) { return false; } } function fs_detect_column(PDO $pdo, $table, array $candidates) { foreach ($candidates as $candidate) { if (fs_column_exists($pdo, $table, $candidate)) { return $candidate; } } return null; } function fs_status_label($status) { $labels = [ 'new' => 'New', 'read' => 'Read', 'processed' => 'Processed', 'spam' => 'Spam' ]; return $labels[$status] ?? ucfirst($status); } function fs_status_class($status) { switch ($status) { case 'new': return 'status-new'; case 'read': return 'status-read'; case 'processed': return 'status-processed'; case 'spam': return 'status-spam'; default: return 'status-read'; } } function fs_format_date($date) { if (!$date) { return '—'; } $timestamp = strtotime($date); if (!$timestamp) { return e($date); } return date('d M Y, h:i A', $timestamp); } function fs_get_enum_values(PDO $pdo, $table, $column, array $fallback = []) { try { $stmt = $pdo->query( "SHOW COLUMNS FROM `" . str_replace('`', '', $table) . "` LIKE " . $pdo->quote($column) ); $columnData = $stmt->fetch(); if ($columnData && !empty($columnData['Type'])) { if (preg_match("/^enum\((.*)\)$/", $columnData['Type'], $matches)) { $values = str_getcsv($matches[1], ',', "'"); $values = array_map(function ($value) { return str_replace("''", "'", $value); }, $values); if (!empty($values)) { return $values; } } } } catch (Throwable $e) { // fallback } return $fallback; } /* --------------------------------------------------------- CHECK TABLES --------------------------------------------------------- */ if (!fs_table_exists($pdo, 'form_submissions')) { http_response_code(500); exit('form_submissions table not found.'); } $hasFormsTable = fs_table_exists($pdo, 'forms'); $hasValuesTable = fs_table_exists($pdo, 'form_submission_values'); $hasFieldsTable = fs_table_exists($pdo, 'form_fields'); $statusOptions = fs_get_enum_values( $pdo, 'form_submissions', 'status', ['new', 'read', 'processed', 'spam'] ); /* --------------------------------------------------------- RELATED COLUMNS --------------------------------------------------------- */ $valueSubmissionColumn = null; $valueFieldColumn = null; $valueValueColumn = null; if ($hasValuesTable) { $valueSubmissionColumn = fs_detect_column( $pdo, 'form_submission_values', [ 'submission_id', 'form_submission_id', 'submission', 'form_submission' ] ); $valueFieldColumn = fs_detect_column( $pdo, 'form_submission_values', [ 'field_id', 'form_field_id', 'form_fields_id' ] ); $valueValueColumn = fs_detect_column( $pdo, 'form_submission_values', [ 'value', 'field_value', 'submission_value' ] ); } /* --------------------------------------------------------- POST ACTIONS --------------------------------------------------------- */ if ($_SERVER['REQUEST_METHOD'] === 'POST') { fs_verify_csrf(); $action = $_POST['action'] ?? ''; /* --------------------------------------------- UPDATE STATUS --------------------------------------------- */ if ($action === 'update_status') { $submissionId = (int)($_POST['submission_id'] ?? 0); $status = trim($_POST['status'] ?? ''); if ($submissionId <= 0) { fs_flash('error', 'Invalid submission selected.'); fs_redirect('form_submissions.php'); } if (!in_array($status, $statusOptions, true)) { fs_flash('error', 'Invalid submission status.'); fs_redirect('form_submissions.php'); } try { $stmt = $pdo->prepare(" UPDATE form_submissions SET status = ? WHERE id = ? "); $stmt->execute([ $status, $submissionId ]); fs_flash( 'success', 'Submission status updated successfully.' ); } catch (Throwable $e) { error_log('Form submission status error: ' . $e->getMessage()); fs_flash( 'error', 'Unable to update submission status.' ); } fs_redirect('form_submissions.php'); } /* --------------------------------------------- DELETE SUBMISSION --------------------------------------------- */ if ($action === 'delete') { $submissionId = (int)($_POST['submission_id'] ?? 0); if ($submissionId <= 0) { fs_flash('error', 'Invalid submission selected.'); fs_redirect('form_submissions.php'); } try { $pdo->beginTransaction(); /* * Delete related submission values first * if the existing table has a recognizable * submission relation column. */ if ( $hasValuesTable && $valueSubmissionColumn ) { $sql = " DELETE FROM form_submission_values WHERE `" . $valueSubmissionColumn . "` = ? "; $stmt = $pdo->prepare($sql); $stmt->execute([$submissionId]); } $stmt = $pdo->prepare(" DELETE FROM form_submissions WHERE id = ? "); $stmt->execute([$submissionId]); if ($stmt->rowCount() === 0) { $pdo->rollBack(); fs_flash( 'error', 'Submission not found or already deleted.' ); fs_redirect('form_submissions.php'); } $pdo->commit(); fs_flash( 'success', 'Submission deleted successfully.' ); } catch (Throwable $e) { if ($pdo->inTransaction()) { $pdo->rollBack(); } error_log('Form submission delete error: ' . $e->getMessage()); fs_flash( 'error', 'Unable to delete submission. Please try again.' ); } fs_redirect('form_submissions.php'); } } /* --------------------------------------------------------- FILTERS --------------------------------------------------------- */ $q = trim($_GET['q'] ?? ''); $formId = (int)($_GET['form_id'] ?? 0); $statusFilter = trim($_GET['status'] ?? ''); $page = max(1, (int)($_GET['page'] ?? 1)); $perPage = 15; /* --------------------------------------------------------- FORMS --------------------------------------------------------- */ $forms = []; if ($hasFormsTable) { try { $formsStmt = $pdo->query(" SELECT id, name, slug FROM forms ORDER BY name ASC, id ASC "); $forms = $formsStmt->fetchAll(); } catch (Throwable $e) { $forms = []; } } /* --------------------------------------------------------- VIEW SUBMISSION --------------------------------------------------------- */ $viewId = (int)($_GET['view'] ?? 0); $viewSubmission = null; $viewValues = []; if ($viewId > 0) { try { if ($hasFormsTable) { $stmt = $pdo->prepare(" SELECT fs.*, f.name AS form_name, f.slug AS form_slug FROM form_submissions fs LEFT JOIN forms f ON f.id = fs.form_id WHERE fs.id = ? LIMIT 1 "); } else { $stmt = $pdo->prepare(" SELECT * FROM form_submissions WHERE id = ? LIMIT 1 "); } $stmt->execute([$viewId]); $viewSubmission = $stmt->fetch(); /* * Load dynamic field/value information. */ if ( $viewSubmission && $hasValuesTable && $valueSubmissionColumn && $valueValueColumn ) { if ($hasFieldsTable && $valueFieldColumn) { $stmt = $pdo->prepare(" SELECT f.id AS field_id, f.field_name, f.label, f.field_type, v.`" . $valueValueColumn . "` AS field_value FROM form_submission_values v LEFT JOIN form_fields f ON f.id = v.`" . $valueFieldColumn . "` WHERE v.`" . $valueSubmissionColumn . "` = ? ORDER BY COALESCE(f.sort_order, 999999) ASC, f.id ASC "); $stmt->execute([$viewId]); $viewValues = $stmt->fetchAll(); } else { $stmt = $pdo->prepare(" SELECT * FROM form_submission_values WHERE `" . $valueSubmissionColumn . "` = ? ORDER BY id ASC "); $stmt->execute([$viewId]); $viewValues = $stmt->fetchAll(); } } } catch (Throwable $e) { error_log( 'Form submission view error: ' . $e->getMessage() ); $viewSubmission = null; $viewValues = []; } } /* --------------------------------------------------------- STATS --------------------------------------------------------- */ $stats = [ 'total' => 0, 'new' => 0, 'read' => 0, 'processed' => 0, 'spam' => 0 ]; try { $statsStmt = $pdo->query(" SELECT COUNT(*) AS total, SUM(status = 'new') AS new_count, SUM(status = 'read') AS read_count, SUM(status = 'processed') AS processed_count, SUM(status = 'spam') AS spam_count FROM form_submissions "); $statsRow = $statsStmt->fetch(); if ($statsRow) { $stats['total'] = (int)$statsRow['total']; $stats['new'] = (int)$statsRow['new_count']; $stats['read'] = (int)$statsRow['read_count']; $stats['processed'] = (int)$statsRow['processed_count']; $stats['spam'] = (int)$statsRow['spam_count']; } } catch (Throwable $e) { // Keep zero values. } /* --------------------------------------------------------- LIST QUERY --------------------------------------------------------- */ $where = []; $params = []; if ($q !== '') { $where[] = " ( fs.ip_address LIKE ? OR fs.source_url LIKE ? OR fs.user_agent LIKE ? ) "; $like = '%' . $q . '%'; $params[] = $like; $params[] = $like; $params[] = $like; } if ($formId > 0) { $where[] = "fs.form_id = ?"; $params[] = $formId; } if ($statusFilter !== '' && in_array($statusFilter, $statusOptions, true)) { $where[] = "fs.status = ?"; $params[] = $statusFilter; } $whereSql = ''; if (!empty($where)) { $whereSql = 'WHERE ' . implode(' AND ', $where); } /* --------------------------------------------------------- TOTAL RECORDS --------------------------------------------------------- */ $totalRows = 0; try { $countSql = " SELECT COUNT(*) FROM form_submissions fs $whereSql "; $countStmt = $pdo->prepare($countSql); $countStmt->execute($params); $totalRows = (int)$countStmt->fetchColumn(); } catch (Throwable $e) { $totalRows = 0; } $totalPages = max( 1, (int)ceil($totalRows / $perPage) ); if ($page > $totalPages) { $page = $totalPages; } $offset = ($page - 1) * $perPage; /* --------------------------------------------------------- SUBMISSIONS --------------------------------------------------------- */ $submissions = []; try { if ($hasFormsTable) { $listSql = " SELECT fs.*, f.name AS form_name, f.slug AS form_slug FROM form_submissions fs LEFT JOIN forms f ON f.id = fs.form_id $whereSql ORDER BY CASE WHEN fs.status = 'new' THEN 0 WHEN fs.status = 'read' THEN 1 WHEN fs.status = 'processed' THEN 2 WHEN fs.status = 'spam' THEN 3 ELSE 4 END, fs.created_at DESC, fs.id DESC LIMIT $perPage OFFSET $offset "; } else { $listSql = " SELECT * FROM form_submissions fs $whereSql ORDER BY fs.created_at DESC, fs.id DESC LIMIT $perPage OFFSET $offset "; } $listStmt = $pdo->prepare($listSql); $listStmt->execute($params); $submissions = $listStmt->fetchAll(); } catch (Throwable $e) { error_log( 'Form submissions list error: ' . $e->getMessage() ); $submissions = []; } /* --------------------------------------------------------- FLASH --------------------------------------------------------- */ $flash = fs_get_flash(); /* --------------------------------------------------------- PAGINATION URL --------------------------------------------------------- */ function fs_page_url($pageNumber) { $query = $_GET; $query['page'] = $pageNumber; return 'form_submissions.php?' . http_build_query($query); } ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0" > <title>Form Submissions | Pure Chemical Admin</title> <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; --dark: #0f172a; --muted: #64748b; --border: #e2e8f0; --bg: #f8fafc; --white: #ffffff; --danger: #dc2626; --danger-soft: #fef2f2; --warning: #d97706; --warning-soft: #fffbeb; --blue: #2563eb; --blue-soft: #eff6ff; --purple: #7c3aed; --purple-soft: #f5f3ff; --green: #059669; --green-soft: #ecfdf5; --shadow-sm: 0 1px 2px rgba(15, 23, 42, .04); --shadow: 0 12px 35px rgba(15, 23, 42, .07); --radius: 18px; } * { box-sizing: border-box; } html { scroll-behavior: smooth; } body { margin: 0; font-family: "Inter", sans-serif; background: var(--bg); color: var(--dark); } a { color: inherit; text-decoration: none; } button, input, select { font: inherit; } /* ------------------------------------------- MAIN LAYOUT ------------------------------------------- */ .page { min-height: 100vh; margin-left: 280px; } .main { padding: 24px 28px 40px; max-width: 1800px; } /* ------------------------------------------- TOPBAR ------------------------------------------- */ .topbar { position: sticky; top: 0; z-index: 50; height: 76px; display: flex; align-items: center; justify-content: space-between; padding: 0 28px; background: rgba(255,255,255,.94); backdrop-filter: blur(18px); border-bottom: 1px solid var(--border); box-shadow: 0 4px 20px rgba(15,23,42,.04); } .topbar-left { display: flex; align-items: center; gap: 16px; } .page-icon { width: 44px; height: 44px; display: flex; align-items: center; justify-content: center; border-radius: 13px; color: var(--primary); background: var(--primary-soft); font-size: 18px; } .topbar-title h1 { margin: 0; font-size: 18px; font-weight: 800; letter-spacing: -.3px; } .breadcrumb { display: flex; align-items: center; gap: 7px; margin-top: 3px; font-size: 12px; color: var(--muted); } .breadcrumb i { font-size: 9px; } .topbar-right { display: flex; align-items: center; gap: 10px; } .admin-chip { display: flex; align-items: center; gap: 9px; padding: 8px 12px; background: #fff; border: 1px solid var(--border); border-radius: 12px; color: var(--dark); font-size: 13px; font-weight: 600; } .admin-avatar { width: 30px; height: 30px; display: flex; align-items: center; justify-content: center; border-radius: 9px; background: var(--primary); color: #fff; font-size: 12px; } /* ------------------------------------------- PAGE HEADER ------------------------------------------- */ .page-header { display: flex; align-items: flex-end; justify-content: space-between; gap: 20px; margin-bottom: 22px; } .page-header h2 { margin: 0; font-size: 28px; line-height: 1.2; letter-spacing: -.7px; font-weight: 800; } .page-header p { margin: 8px 0 0; color: var(--muted); font-size: 14px; } .header-actions { display: flex; align-items: center; gap: 10px; } /* ------------------------------------------- BUTTONS ------------------------------------------- */ .btn { border: 0; cursor: pointer; min-height: 42px; display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 0 15px; border-radius: 11px; font-size: 13px; font-weight: 700; transition: .2s ease; } .btn:hover { transform: translateY(-1px); } .btn-primary { color: #fff; background: var(--primary); box-shadow: 0 8px 20px rgba(15,118,110,.20); } .btn-primary:hover { background: var(--primary-dark); } .btn-light { color: var(--dark); background: #fff; border: 1px solid var(--border); } .btn-danger { color: #fff; background: var(--danger); } .btn-sm { min-height: 36px; padding: 0 11px; font-size: 12px; } /* ------------------------------------------- ALERT ------------------------------------------- */ .alert { display: flex; align-items: flex-start; gap: 12px; padding: 14px 16px; margin-bottom: 20px; border-radius: 14px; font-size: 13px; font-weight: 600; } .alert i { margin-top: 2px; } .alert-success { color: #065f46; background: var(--green-soft); border: 1px solid #a7f3d0; } .alert-error { color: #991b1b; background: var(--danger-soft); border: 1px solid #fecaca; } /* ------------------------------------------- STATS ------------------------------------------- */ .stats-grid { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 15px; margin-bottom: 22px; } .stat-card { position: relative; padding: 18px; background: #fff; border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-sm); overflow: hidden; } .stat-card::after { content: ""; position: absolute; width: 70px; height: 70px; right: -25px; bottom: -25px; border-radius: 50%; background: rgba(15,118,110,.05); } .stat-top { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; } .stat-icon { width: 38px; height: 38px; display: flex; align-items: center; justify-content: center; border-radius: 11px; font-size: 15px; } .stat-total .stat-icon { color: var(--primary); background: var(--primary-soft); } .stat-new .stat-icon { color: var(--blue); background: var(--blue-soft); } .stat-read .stat-icon { color: var(--warning); background: var(--warning-soft); } .stat-processed .stat-icon { color: var(--green); background: var(--green-soft); } .stat-spam .stat-icon { color: var(--danger); background: var(--danger-soft); } .stat-label { color: var(--muted); font-size: 12px; font-weight: 600; } .stat-value { margin-top: 4px; font-size: 25px; font-weight: 800; letter-spacing: -.5px; } /* ------------------------------------------- FILTER PANEL ------------------------------------------- */ .filter-card { background: #fff; border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; margin-bottom: 18px; box-shadow: var(--shadow-sm); } .filters { display: grid; grid-template-columns: minmax(220px, 1.4fr) minmax(180px, .8fr) minmax(160px, .7fr) auto; gap: 10px; } .input-wrap { position: relative; } .input-wrap > i { position: absolute; left: 13px; top: 50%; transform: translateY(-50%); color: #94a3b8; font-size: 13px; } .input, .select { width: 100%; height: 43px; padding: 0 13px; border: 1px solid var(--border); border-radius: 11px; outline: none; color: var(--dark); background: #fff; font-size: 13px; transition: .2s ease; } .input.with-icon { padding-left: 38px; } .input:focus, .select:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(15,118,110,.09); } .filter-actions { display: flex; gap: 8px; } /* ------------------------------------------- TABLE CARD ------------------------------------------- */ .table-card { background: #fff; border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-sm); overflow: hidden; } .table-head { padding: 18px 20px; display: flex; align-items: center; justify-content: space-between; gap: 15px; border-bottom: 1px solid var(--border); } .table-title { display: flex; align-items: center; gap: 10px; } .table-title h3 { margin: 0; font-size: 15px; font-weight: 800; } .record-count { padding: 4px 8px; color: var(--primary); background: var(--primary-soft); border-radius: 20px; font-size: 11px; font-weight: 800; } .table-wrap { width: 100%; overflow-x: auto; } table { width: 100%; border-collapse: collapse; min-width: 1050px; } th { padding: 13px 18px; text-align: left; background: #f8fafc; color: #64748b; font-size: 10px; font-weight: 800; text-transform: uppercase; letter-spacing: .7px; border-bottom: 1px solid var(--border); } td { padding: 15px 18px; color: #334155; font-size: 13px; border-bottom: 1px solid #f1f5f9; vertical-align: middle; } tr:last-child td { border-bottom: 0; } tbody tr { transition: .15s ease; } tbody tr:hover { background: #fbfefd; } .submission-id { color: var(--primary); font-weight: 800; } .form-name { color: var(--dark); font-weight: 700; } .form-slug { margin-top: 3px; color: #94a3b8; font-size: 11px; } .meta { color: #64748b; font-size: 12px; } .meta strong { color: #334155; font-weight: 600; } .source-url { max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: #64748b; font-size: 12px; } /* ------------------------------------------- STATUS ------------------------------------------- */ .status { display: inline-flex; align-items: center; gap: 6px; padding: 6px 9px; border-radius: 8px; font-size: 11px; font-weight: 800; } .status::before { content: ""; width: 6px; height: 6px; border-radius: 50%; } .status-new { color: #1d4ed8; background: #eff6ff; } .status-new::before { background: #2563eb; } .status-read { color: #92400e; background: #fffbeb; } .status-read::before { background: #d97706; } .status-processed { color: #047857; background: #ecfdf5; } .status-processed::before { background: #059669; } .status-spam { color: #b91c1c; background: #fef2f2; } .status-spam::before { background: #dc2626; } /* ------------------------------------------- ACTIONS ------------------------------------------- */ .actions { display: flex; align-items: center; gap: 7px; } .icon-btn { width: 34px; height: 34px; display: inline-flex; align-items: center; justify-content: center; border-radius: 9px; border: 1px solid var(--border); color: #475569; background: #fff; cursor: pointer; transition: .2s ease; } .icon-btn:hover { color: var(--primary); border-color: #99f6e4; background: var(--primary-soft); } .icon-btn.danger:hover { color: var(--danger); border-color: #fecaca; background: var(--danger-soft); } /* ------------------------------------------- EMPTY ------------------------------------------- */ .empty-state { text-align: center; padding: 70px 20px; } .empty-icon { width: 65px; height: 65px; margin: 0 auto 15px; display: flex; align-items: center; justify-content: center; border-radius: 18px; color: var(--primary); background: var(--primary-soft); font-size: 25px; } .empty-state h3 { margin: 0; font-size: 16px; font-weight: 800; } .empty-state p { max-width: 450px; margin: 8px auto 0; color: var(--muted); font-size: 13px; line-height: 1.6; } /* ------------------------------------------- PAGINATION ------------------------------------------- */ .pagination { padding: 16px 18px; display: flex; align-items: center; justify-content: space-between; gap: 15px; border-top: 1px solid var(--border); } .pagination-info { color: var(--muted); font-size: 12px; } .pagination-links { display: flex; align-items: center; gap: 5px; } .page-link { min-width: 34px; height: 34px; padding: 0 8px; display: inline-flex; align-items: center; justify-content: center; border: 1px solid var(--border); border-radius: 9px; background: #fff; color: #475569; font-size: 12px; font-weight: 700; } .page-link.active { color: #fff; background: var(--primary); border-color: var(--primary); } .page-link.disabled { opacity: .45; pointer-events: none; } /* ------------------------------------------- MODAL ------------------------------------------- */ .modal-backdrop { position: fixed; inset: 0; z-index: 200; display: none; align-items: center; justify-content: center; padding: 20px; background: rgba(15,23,42,.52); backdrop-filter: blur(5px); } .modal-backdrop.show { display: flex; } .modal { width: 100%; max-width: 760px; max-height: 90vh; overflow: hidden; background: #fff; border-radius: 22px; box-shadow: 0 30px 80px rgba(15,23,42,.25); animation: modalIn .2s ease; } @keyframes modalIn { from { opacity: 0; transform: translateY(12px) scale(.98); } to { opacity: 1; transform: translateY(0) scale(1); } } .modal-head { padding: 18px 20px; display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--border); } .modal-title { display: flex; align-items: center; gap: 11px; } .modal-title-icon { width: 38px; height: 38px; display: flex; align-items: center; justify-content: center; border-radius: 10px; color: var(--primary); background: var(--primary-soft); } .modal-title h3 { margin: 0; font-size: 15px; font-weight: 800; } .modal-title p { margin: 3px 0 0; color: var(--muted); font-size: 11px; } .close-modal { width: 34px; height: 34px; display: flex; align-items: center; justify-content: center; border: 1px solid var(--border); border-radius: 9px; background: #fff; color: #64748b; cursor: pointer; } .modal-body { max-height: calc(90vh - 140px); overflow-y: auto; padding: 20px; } .detail-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; } .detail-card { padding: 15px; border: 1px solid var(--border); border-radius: 14px; background: #fff; } .detail-card.full { grid-column: 1 / -1; } .detail-label { margin-bottom: 6px; color: #94a3b8; font-size: 10px; font-weight: 800; text-transform: uppercase; letter-spacing: .6px; } .detail-value { color: var(--dark); font-size: 13px; font-weight: 600; line-height: 1.6; word-break: break-word; } .value-list { display: grid; gap: 9px; } .value-item { padding: 12px 13px; border-radius: 11px; background: #f8fafc; border: 1px solid #eef2f7; } .value-item-label { margin-bottom: 4px; color: #64748b; font-size: 10px; font-weight: 800; text-transform: uppercase; } .value-item-value { color: #1e293b; font-size: 13px; white-space: pre-wrap; word-break: break-word; } .modal-footer { padding: 14px 20px; display: flex; justify-content: space-between; align-items: center; gap: 10px; border-top: 1px solid var(--border); background: #fbfdff; } .status-form { display: flex; align-items: center; gap: 8px; } .status-form select { height: 38px; padding: 0 10px; border: 1px solid var(--border); border-radius: 9px; background: #fff; font-size: 12px; } /* ------------------------------------------- RESPONSIVE ------------------------------------------- */ @media (max-width: 1250px) { .stats-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); } .filters { grid-template-columns: 1fr 1fr; } .filter-actions { grid-column: 1 / -1; } } @media (max-width: 1100px) { .page { margin-left: 0; } .main { padding: 20px; } } @media (max-width: 760px) { .topbar { height: auto; min-height: 70px; padding: 12px 16px; } .topbar-title h1 { font-size: 15px; } .topbar-right { display: none; } .main { padding: 18px 14px 30px; } .page-header { align-items: flex-start; flex-direction: column; } .page-header h2 { font-size: 23px; } .stats-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } .filters { grid-template-columns: 1fr; } .filter-actions { grid-column: auto; } .pagination { align-items: flex-start; flex-direction: column; } .detail-grid { grid-template-columns: 1fr; } .detail-card.full { grid-column: auto; } .modal-footer { align-items: flex-start; flex-direction: column; } } @media (max-width: 480px) { .stats-grid { grid-template-columns: 1fr; } .page-icon { width: 38px; height: 38px; } .page-header { margin-bottom: 18px; } .header-actions { width: 100%; } .header-actions .btn { width: 100%; } } </style> </head> <body> <?php /* |-------------------------------------------------------------------------- | SIDEBAR |-------------------------------------------------------------------------- | Sidebar intentionally included separately. | Do NOT include admin/header.php here. |-------------------------------------------------------------------------- */ require_once __DIR__ . '/sidebar.php'; ?> <div class="page"> <!-- ========================================== TOPBAR =========================================== --> <header class="topbar"> <div class="topbar-left"> <div class="page-icon"> <i class="fa-solid fa-inbox"></i> </div> <div class="topbar-title"> <h1>Form Submissions</h1> <div class="breadcrumb"> <span>Admin</span> <i class="fa-solid fa-chevron-right"></i> <span>Forms</span> <i class="fa-solid fa-chevron-right"></i> <strong>Submissions</strong> </div> </div> </div> <div class="topbar-right"> <div class="admin-chip"> <div class="admin-avatar"> <i class="fa-solid fa-user"></i> </div> <span> <?php echo e( $_SESSION['ADMIN_NAME'] ?? $_SESSION['admin_name'] ?? 'Administrator' ); ?> </span> </div> </div> </header> <!-- ========================================== MAIN =========================================== --> <main class="main"> <!-- PAGE HEADER --> <div class="page-header"> <div> <h2>Form Submissions</h2> <p> Website forms se received enquiries aur submissions manage karein. </p> </div> <div class="header-actions"> <a href="forms.php" class="btn btn-light" > <i class="fa-solid fa-file-lines"></i> Manage Forms </a> </div> </div> <!-- FLASH --> <?php if ($flash): ?> <div class="alert <?php echo $flash['type'] === 'success' ? 'alert-success' : 'alert-error'; ?>" > <i class="fa-solid <?php echo $flash['type'] === 'success' ? 'fa-circle-check' : 'fa-circle-exclamation'; ?>"></i> <div> <?php echo e($flash['message']); ?> </div> </div> <?php endif; ?> <!-- ====================================== STATS ======================================= --> <section class="stats-grid"> <div class="stat-card stat-total"> <div class="stat-top"> <div class="stat-icon"> <i class="fa-solid fa-inbox"></i> </div> </div> <div class="stat-label"> Total Submissions </div> <div class="stat-value"> <?php echo number_format($stats['total']); ?> </div> </div> <div class="stat-card stat-new"> <div class="stat-top"> <div class="stat-icon"> <i class="fa-solid fa-bell"></i> </div> </div> <div class="stat-label"> New </div> <div class="stat-value"> <?php echo number_format($stats['new']); ?> </div> </div> <div class="stat-card stat-read"> <div class="stat-top"> <div class="stat-icon"> <i class="fa-solid fa-eye"></i> </div> </div> <div class="stat-label"> Read </div> <div class="stat-value"> <?php echo number_format($stats['read']); ?> </div> </div> <div class="stat-card stat-processed"> <div class="stat-top"> <div class="stat-icon"> <i class="fa-solid fa-circle-check"></i> </div> </div> <div class="stat-label"> Processed </div> <div class="stat-value"> <?php echo number_format($stats['processed']); ?> </div> </div> <div class="stat-card stat-spam"> <div class="stat-top"> <div class="stat-icon"> <i class="fa-solid fa-ban"></i> </div> </div> <div class="stat-label"> Spam </div> <div class="stat-value"> <?php echo number_format($stats['spam']); ?> </div> </div> </section> <!-- ====================================== FILTERS ======================================= --> <section class="filter-card"> <form method="get" action="form_submissions.php" > <div class="filters"> <div class="input-wrap"> <i class="fa-solid fa-magnifying-glass"></i> <input type="text" name="q" class="input with-icon" value="<?php echo e($q); ?>" placeholder="Search IP address, source URL..." > </div> <select name="form_id" class="select" > <option value=""> All Forms </option> <?php foreach ($forms as $form): ?> <option value="<?php echo (int)$form['id']; ?>" <?php echo $formId === (int)$form['id'] ? 'selected' : ''; ?> > <?php echo e($form['name']); ?> </option> <?php endforeach; ?> </select> <select name="status" class="select" > <option value=""> All Statuses </option> <?php foreach ($statusOptions as $status): ?> <option value="<?php echo e($status); ?>" <?php echo $statusFilter === $status ? 'selected' : ''; ?> > <?php echo e(fs_status_label($status)); ?> </option> <?php endforeach; ?> </select> <div class="filter-actions"> <button type="submit" class="btn btn-primary" > <i class="fa-solid fa-filter"></i> Filter </button> <a href="form_submissions.php" class="btn btn-light" > <i class="fa-solid fa-rotate-left"></i> Reset </a> </div> </div> </form> </section> <!-- ====================================== TABLE ======================================= --> <section class="table-card"> <div class="table-head"> <div class="table-title"> <h3> Received Submissions </h3> <span class="record-count"> <?php echo number_format($totalRows); ?> </span> </div> <div class="meta"> Page <?php echo $page; ?> of <?php echo $totalPages; ?> </div> </div> <?php if (!empty($submissions)): ?> <div class="table-wrap"> <table> <thead> <tr> <th> ID </th> <th> Form </th> <th> IP Address </th> <th> Source </th> <th> Status </th> <th> Submitted </th> <th> Actions </th> </tr> </thead> <tbody> <?php foreach ($submissions as $submission): ?> <tr> <td> <div class="submission-id"> #<?php echo (int)$submission['id']; ?> </div> </td> <td> <div class="form-name"> <?php echo e( $submission['form_name'] ?? ('Form #' . (int)$submission['form_id']) ); ?> </div> <?php if (!empty($submission['form_slug'])): ?> <div class="form-slug"> /<?php echo e($submission['form_slug']); ?> </div> <?php endif; ?> </td> <td> <div class="meta"> <?php if (!empty($submission['ip_address'])): ?> <strong> <?php echo e($submission['ip_address']); ?> </strong> <?php else: ?> — <?php endif; ?> </div> </td> <td> <?php if (!empty($submission['source_url'])): ?> <div class="source-url" title="<?php echo e($submission['source_url']); ?>" > <?php echo e($submission['source_url']); ?> </div> <?php else: ?> <span class="meta">—</span> <?php endif; ?> </td> <td> <span class="status <?php echo e( fs_status_class($submission['status']) ); ?>" > <?php echo e( fs_status_label($submission['status']) ); ?> </span> </td> <td> <div class="meta"> <?php echo fs_format_date( $submission['created_at'] ?? null ); ?> </div> </td> <td> <div class="actions"> <!-- VIEW --> <a href="form_submissions.php?<?php echo http_build_query( array_merge( $_GET, [ 'view' => (int)$submission['id'] ] ) ); ?>" class="icon-btn" title="View Submission" > <i class="fa-regular fa-eye"></i> </a> <!-- QUICK STATUS --> <button type="button" class="icon-btn" title="Change Status" onclick="openStatusModal( <?php echo (int)$submission['id']; ?>, '<?php echo e($submission['status']); ?>' )" > <i class="fa-solid fa-sliders"></i> </button> <!-- DELETE --> <button type="button" class="icon-btn danger" title="Delete" onclick="openDeleteModal( <?php echo (int)$submission['id']; ?> )" > <i class="fa-regular fa-trash-can"></i> </button> </div> </td> </tr> <?php endforeach; ?> </tbody> </table> </div> <!-- PAGINATION --> <?php if ($totalPages > 1): ?> <div class="pagination"> <div class="pagination-info"> Showing <strong> <?php echo $totalRows > 0 ? $offset + 1 : 0; ?> </strong> – <strong> <?php echo min( $offset + $perPage, $totalRows ); ?> </strong> of <strong> <?php echo number_format($totalRows); ?> </strong> </div> <div class="pagination-links"> <a href="<?php echo $page > 1 ? e(fs_page_url($page - 1)) : '#'; ?>" class="page-link <?php echo $page <= 1 ? 'disabled' : ''; ?>" > <i class="fa-solid fa-chevron-left"></i> </a> <?php $startPage = max(1, $page - 2); $endPage = min( $totalPages, $page + 2 ); for ( $p = $startPage; $p <= $endPage; $p++ ): ?> <a href="<?php echo e( fs_page_url($p) ); ?>" class="page-link <?php echo $p === $page ? 'active' : ''; ?>" > <?php echo $p; ?> </a> <?php endfor; ?> <a href="<?php echo $page < $totalPages ? e(fs_page_url($page + 1)) : '#'; ?>" class="page-link <?php echo $page >= $totalPages ? 'disabled' : ''; ?>" > <i class="fa-solid fa-chevron-right"></i> </a> </div> </div> <?php endif; ?> <?php else: ?> <div class="empty-state"> <div class="empty-icon"> <i class="fa-regular fa-inbox"></i> </div> <h3> No submissions found </h3> <p> Abhi selected filters ke according koi form submission available nahi hai. </p> </div> <?php endif; ?> </section> </main> </div> <!-- ============================================== VIEW SUBMISSION MODAL ================================================ --> <?php if ($viewSubmission): ?> <div class="modal-backdrop show" id="viewModal" onclick="closeViewModal(event)" > <div class="modal" onclick="event.stopPropagation()" > <div class="modal-head"> <div class="modal-title"> <div class="modal-title-icon"> <i class="fa-solid fa-inbox"></i> </div> <div> <h3> Submission #<?php echo (int)$viewSubmission['id']; ?> </h3> <p> <?php echo e( $viewSubmission['form_name'] ?? ('Form #' . (int)$viewSubmission['form_id']) ); ?> </p> </div> </div> <button type="button" class="close-modal" onclick="closeViewModal()" > <i class="fa-solid fa-xmark"></i> </button> </div> <div class="modal-body"> <div class="detail-grid"> <div class="detail-card"> <div class="detail-label"> Form </div> <div class="detail-value"> <?php echo e( $viewSubmission['form_name'] ?? ('Form #' . (int)$viewSubmission['form_id']) ); ?> </div> </div> <div class="detail-card"> <div class="detail-label"> Status </div> <div class="detail-value"> <span class="status <?php echo e( fs_status_class($viewSubmission['status']) ); ?>" > <?php echo e( fs_status_label($viewSubmission['status']) ); ?> </span> </div> </div> <div class="detail-card"> <div class="detail-label"> IP Address </div> <div class="detail-value"> <?php echo e( $viewSubmission['ip_address'] ?? '—' ); ?> </div> </div> <div class="detail-card"> <div class="detail-label"> Submitted At </div> <div class="detail-value"> <?php echo fs_format_date( $viewSubmission['created_at'] ?? null ); ?> </div> </div> <?php if (!empty($viewSubmission['source_url'])): ?> <div class="detail-card full"> <div class="detail-label"> Source URL </div> <div class="detail-value"> <?php echo e($viewSubmission['source_url']); ?> </div> </div> <?php endif; ?> <?php if (!empty($viewSubmission['user_agent'])): ?> <div class="detail-card full"> <div class="detail-label"> User Agent </div> <div class="detail-value"> <?php echo e($viewSubmission['user_agent']); ?> </div> </div> <?php endif; ?> <div class="detail-card full"> <div class="detail-label"> Submitted Data </div> <div class="value-list"> <?php if (!empty($viewValues)): ?> <?php foreach ($viewValues as $value): ?> <div class="value-item"> <div class="value-item-label"> <?php if ( isset($value['label']) && $value['label'] !== '' ) { echo e($value['label']); } elseif ( isset($value['field_name']) && $value['field_name'] !== '' ) { echo e($value['field_name']); } else { echo 'Field'; } ?> </div> <div class="value-item-value"> <?php echo e( $value['field_value'] ?? $value[$valueValueColumn ?? 'value'] ?? '' ); ?> </div> </div> <?php endforeach; ?> <?php else: ?> <div class="value-item"> <div class="value-item-value"> <?php if ($hasValuesTable): ?> No submission field values found. <?php else: ?> The <strong>form_submission_values</strong> table is not available. <?php endif; ?> </div> </div> <?php endif; ?> </div> </div> </div> </div> <div class="modal-footer"> <form method="post" class="status-form" > <?php echo fs_csrf_field(); ?> <input type="hidden" name="action" value="update_status" > <input type="hidden" name="submission_id" value="<?php echo (int)$viewSubmission['id']; ?>" > <select name="status"> <?php foreach ($statusOptions as $status): ?> <option value="<?php echo e($status); ?>" <?php echo $viewSubmission['status'] === $status ? 'selected' : ''; ?> > <?php echo e(fs_status_label($status)); ?> </option> <?php endforeach; ?> </select> <button type="submit" class="btn btn-primary btn-sm" > <i class="fa-solid fa-check"></i> Update Status </button> </form> <button type="button" class="btn btn-light btn-sm" onclick="closeViewModal()" > Close </button> </div> </div> </div> <?php endif; ?> <!-- ============================================== STATUS MODAL ================================================ --> <div class="modal-backdrop" id="statusModal" > <div class="modal" onclick="event.stopPropagation()" style="max-width:440px;" > <div class="modal-head"> <div class="modal-title"> <div class="modal-title-icon"> <i class="fa-solid fa-sliders"></i> </div> <div> <h3> Change Status </h3> <p> Submission status update karein. </p> </div> </div> <button type="button" class="close-modal" onclick="closeStatusModal()" > <i class="fa-solid fa-xmark"></i> </button> </div> <form method="post"> <?php echo fs_csrf_field(); ?> <input type="hidden" name="action" value="update_status" > <input type="hidden" name="submission_id" id="statusSubmissionId" value="" > <div class="modal-body"> <label class="detail-label" style="display:block;margin-bottom:8px;" > Submission Status </label> <select name="status" id="statusSelect" class="select" > <?php foreach ($statusOptions as $status): ?> <option value="<?php echo e($status); ?>" > <?php echo e( fs_status_label($status) ); ?> </option> <?php endforeach; ?> </select> </div> <div class="modal-footer"> <button type="button" class="btn btn-light" onclick="closeStatusModal()" > Cancel </button> <button type="submit" class="btn btn-primary" > <i class="fa-solid fa-check"></i> Save Status </button> </div> </form> </div> </div> <!-- ============================================== DELETE MODAL ================================================ --> <div class="modal-backdrop" id="deleteModal" > <div class="modal" onclick="event.stopPropagation()" style="max-width:440px;" > <div class="modal-head"> <div class="modal-title"> <div class="modal-title-icon" style="color:#dc2626;background:#fef2f2;" > <i class="fa-regular fa-trash-can"></i> </div> <div> <h3> Delete Submission </h3> <p> This action cannot be undone. </p> </div> </div> <button type="button" class="close-modal" onclick="closeDeleteModal()" > <i class="fa-solid fa-xmark"></i> </button> </div> <form method="post"> <?php echo fs_csrf_field(); ?> <input type="hidden" name="action" value="delete" > <input type="hidden" name="submission_id" id="deleteSubmissionId" value="" > <div class="modal-body"> <div style=" padding:14px; border-radius:12px; background:#fef2f2; border:1px solid #fecaca; color:#991b1b; font-size:13px; line-height:1.6; " > <i class="fa-solid fa-triangle-exclamation" style="margin-right:6px;" ></i> Kya aap sure hain ki aap is submission ko permanently delete karna chahte hain? Related submission values bhi remove kiye jayenge jab relation available hoga. </div> </div> <div class="modal-footer"> <button type="button" class="btn btn-light" onclick="closeDeleteModal()" > Cancel </button> <button type="submit" class="btn btn-danger" > <i class="fa-regular fa-trash-can"></i> Delete Permanently </button> </div> </form> </div> </div> <script> /* ------------------------------------------ VIEW MODAL ------------------------------------------ */ function closeViewModal(event) { if (event && event.target !== event.currentTarget) { return; } const modal = document.getElementById('viewModal'); if (modal) { modal.classList.remove('show'); const url = new URL(window.location.href); url.searchParams.delete('view'); window.history.replaceState( {}, '', url.toString() ); } } /* ------------------------------------------ STATUS MODAL ------------------------------------------ */ function openStatusModal(id, status) { const modal = document.getElementById('statusModal'); const idInput = document.getElementById('statusSubmissionId'); const select = document.getElementById('statusSelect'); if (!modal || !idInput || !select) { return; } idInput.value = id; select.value = status; modal.classList.add('show'); } function closeStatusModal() { const modal = document.getElementById('statusModal'); if (modal) { modal.classList.remove('show'); } } /* ------------------------------------------ DELETE MODAL ------------------------------------------ */ function openDeleteModal(id) { const modal = document.getElementById('deleteModal'); const idInput = document.getElementById('deleteSubmissionId'); if (!modal || !idInput) { return; } idInput.value = id; modal.classList.add('show'); } function closeDeleteModal() { const modal = document.getElementById('deleteModal'); if (modal) { modal.classList.remove('show'); } } /* ------------------------------------------ ESC KEY ------------------------------------------ */ document.addEventListener( 'keydown', function(event) { if (event.key !== 'Escape') { return; } closeViewModal(); closeStatusModal(); closeDeleteModal(); } ); /* ------------------------------------------ BACKDROP CLICK ------------------------------------------ */ document.getElementById('statusModal') ?.addEventListener( 'click', function(event) { if (event.target === this) { closeStatusModal(); } } ); document.getElementById('deleteModal') ?.addEventListener( 'click', function(event) { if (event.target === this) { closeDeleteModal(); } } ); </script> </body> </html>
Save
Cancel