📁 File Manager
Editing:
/home/wvl7mof7402e/public_html/chem/admin/site_settings.php
<?php /** * Pure Chemical Admin * File: admin/site_settings.php * * Existing tables used: * 1. site_settings * 2. site_setting_groups * * NO new table is created. */ 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'; } if (function_exists('requireAdmin')) { requireAdmin(); } /* ========================================================= HELPERS ========================================================= */ if (!function_exists('e')) { function e($value) { return htmlspecialchars( (string)$value, ENT_QUOTES, 'UTF-8' ); } } function siteSettingsCsrfField() { 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 siteSettingsVerifyCsrf() { if (function_exists('csrf_verify')) { csrf_verify(); return true; } $token = $_POST['_csrf'] ?? ''; if ( empty($_SESSION['_csrf']) || empty($token) || !hash_equals( $_SESSION['_csrf'], $token ) ) { throw new RuntimeException( 'Invalid security token. Please refresh the page and try again.' ); } return true; } function siteSettingsFlash( $type, $message ) { $_SESSION['site_settings_flash'] = [ 'type' => $type, 'message' => $message ]; } function siteSettingsGetFlash() { if ( empty( $_SESSION['site_settings_flash'] ) ) { return null; } $flash = $_SESSION['site_settings_flash']; unset( $_SESSION['site_settings_flash'] ); return $flash; } function siteSettingsRedirect( $url = 'site_settings.php' ) { header( 'Location: ' . $url ); exit; } function siteSettingsNormalizeKey( $key ) { $key = trim($key); /* * Allowed: * letters * numbers * underscore * hyphen * dot */ $key = preg_replace( '/[^a-zA-Z0-9_.\-]/', '_', $key ); return trim( $key, '._-' ); } /** * Check table exists. */ function siteSettingsTableExists( 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; } } /** * Get actual enum values from DB. */ function siteSettingsEnumValues( PDO $pdo, $table, $column ) { try { $stmt = $pdo->prepare( "SELECT COLUMN_TYPE FROM information_schema.columns WHERE table_schema = DATABASE() AND table_name = ? AND column_name = ? LIMIT 1" ); $stmt->execute([ $table, $column ]); $type = $stmt->fetchColumn(); if (!$type) { return []; } if ( !preg_match( "/^enum\((.*)\)$/i", $type, $matches ) ) { return []; } preg_match_all( "/'((?:[^'\\\\]|\\\\.)*)'/", $matches[1], $values ); return $values[1] ?? []; } catch (Throwable $e) { return []; } } /* ========================================================= DATABASE VALIDATION ========================================================= */ if ( !siteSettingsTableExists( $pdo, 'site_settings' ) ) { http_response_code(500); exit( '<div style=" font-family:Arial; padding:40px; color:#b91c1c; "> <h2>site_settings table not found</h2> <p> Please check the selected database. </p> </div>' ); } /* ========================================================= VALUE TYPE ENUM ========================================================= */ $valueTypes = siteSettingsEnumValues( $pdo, 'site_settings', 'value_type' ); /* * Fallback only if schema metadata * could not be read. * * These match the visible enum values * from the supplied schema. */ if (empty($valueTypes)) { $valueTypes = [ 'text', 'textarea', 'html', 'number', 'boolean' ]; } /* ========================================================= GROUP TABLE CHECK ========================================================= */ $groupTableExists = siteSettingsTableExists( $pdo, 'site_setting_groups' ); /* ========================================================= LOAD GROUPS ========================================================= */ $groups = []; if ($groupTableExists) { try { /* * We know site_setting_groups is the * related group table, but its complete * schema was not supplied in this message. * * Detect its available columns. */ $columnsStmt = $pdo->query( "SHOW COLUMNS FROM site_setting_groups" ); $groupColumns = []; foreach ( $columnsStmt->fetchAll() as $column ) { $groupColumns[] = $column['Field']; } $groupIdColumn = in_array( 'id', $groupColumns, true ) ? 'id' : null; $groupNameColumn = null; foreach ( [ 'name', 'title', 'group_name', 'label' ] as $candidate ) { if ( in_array( $candidate, $groupColumns, true ) ) { $groupNameColumn = $candidate; break; } } if ( $groupIdColumn && $groupNameColumn ) { $groupsStmt = $pdo->query( "SELECT `{$groupIdColumn}` AS group_id, `{$groupNameColumn}` AS group_name FROM site_setting_groups ORDER BY `{$groupNameColumn}` ASC" ); $groups = $groupsStmt->fetchAll(); } } catch (Throwable $e) { $groups = []; } } /* ========================================================= POST ACTIONS ========================================================= */ if ( $_SERVER['REQUEST_METHOD'] === 'POST' ) { try { siteSettingsVerifyCsrf(); $action = $_POST['action'] ?? ''; /* ================================================= SAVE ================================================= */ if ($action === 'save') { $id = (int)( $_POST['id'] ?? 0 ); $settingKey = siteSettingsNormalizeKey( $_POST['setting_key'] ?? '' ); $settingValue = $_POST['setting_value'] ?? ''; $valueType = trim( $_POST['value_type'] ?? 'text' ); $label = trim( $_POST['label'] ?? '' ); $description = trim( $_POST['description'] ?? '' ); $groupId = (int)( $_POST['group_id'] ?? 0 ); $isPublic = isset( $_POST['is_public'] ) ? 1 : 0; $sortOrder = (int)( $_POST['sort_order'] ?? 0 ); /* --------------------------------------------- BASIC VALIDATION --------------------------------------------- */ if ($settingKey === '') { throw new RuntimeException( 'Setting key is required.' ); } if ( !in_array( $valueType, $valueTypes, true ) ) { throw new RuntimeException( 'Invalid value type selected.' ); } if ($sortOrder < 0) { $sortOrder = 0; } /* * Boolean normalization. */ if ( $valueType === 'boolean' ) { $booleanValue = $_POST['setting_value'] ?? '0'; $settingValue = in_array( (string)$booleanValue, [ '1', 'true', 'on', 'yes' ], true ) ? '1' : '0'; } /* * Number validation. */ if ( $valueType === 'number' && $settingValue !== '' ) { if ( !is_numeric( $settingValue ) ) { throw new RuntimeException( 'Please enter a valid number.' ); } } /* * Group validation. */ $finalGroupId = $groupId > 0 ? $groupId : null; if ( $finalGroupId !== null && $groupTableExists ) { $groupExists = false; foreach ( $groups as $group ) { if ( (int)$group['group_id'] === $finalGroupId ) { $groupExists = true; break; } } if (!$groupExists) { throw new RuntimeException( 'Selected setting group does not exist.' ); } } /* --------------------------------------------- DUPLICATE KEY CHECK --------------------------------------------- */ if ($id > 0) { $duplicateStmt = $pdo->prepare( "SELECT id FROM site_settings WHERE setting_key = ? AND id <> ? LIMIT 1" ); $duplicateStmt->execute([ $settingKey, $id ]); } else { $duplicateStmt = $pdo->prepare( "SELECT id FROM site_settings WHERE setting_key = ? LIMIT 1" ); $duplicateStmt->execute([ $settingKey ]); } if ($duplicateStmt->fetch()) { throw new RuntimeException( 'This setting key already exists.' ); } /* --------------------------------------------- UPDATE --------------------------------------------- */ if ($id > 0) { $checkStmt = $pdo->prepare( "SELECT id FROM site_settings WHERE id = ? LIMIT 1" ); $checkStmt->execute([ $id ]); if (!$checkStmt->fetch()) { throw new RuntimeException( 'Setting record not found.' ); } $stmt = $pdo->prepare( "UPDATE site_settings SET group_id = ?, setting_key = ?, setting_value = ?, value_type = ?, label = ?, description = ?, is_public = ?, sort_order = ? WHERE id = ?" ); $stmt->execute([ $finalGroupId, $settingKey, $settingValue !== '' ? $settingValue : null, $valueType, $label !== '' ? $label : null, $description !== '' ? $description : null, $isPublic, $sortOrder, $id ]); siteSettingsFlash( 'success', 'Site setting updated successfully.' ); } else { /* ----------------------------------------- INSERT ----------------------------------------- */ $stmt = $pdo->prepare( "INSERT INTO site_settings ( group_id, setting_key, setting_value, value_type, label, description, is_public, sort_order ) VALUES ( ?, ?, ?, ?, ?, ?, ?, ? )" ); $stmt->execute([ $finalGroupId, $settingKey, $settingValue !== '' ? $settingValue : null, $valueType, $label !== '' ? $label : null, $description !== '' ? $description : null, $isPublic, $sortOrder ]); siteSettingsFlash( 'success', 'New site setting added successfully.' ); } siteSettingsRedirect( 'site_settings.php' ); } /* ================================================= DELETE ================================================= */ if ($action === 'delete') { $id = (int)( $_POST['id'] ?? 0 ); if ($id <= 0) { throw new RuntimeException( 'Invalid setting ID.' ); } $stmt = $pdo->prepare( "SELECT id, setting_key FROM site_settings WHERE id = ? LIMIT 1" ); $stmt->execute([ $id ]); $setting = $stmt->fetch(); if (!$setting) { throw new RuntimeException( 'Site setting not found.' ); } $deleteStmt = $pdo->prepare( "DELETE FROM site_settings WHERE id = ?" ); $deleteStmt->execute([ $id ]); siteSettingsFlash( 'success', 'Setting "' . $setting['setting_key'] . '" deleted successfully.' ); siteSettingsRedirect( 'site_settings.php' ); } } catch (Throwable $e) { siteSettingsFlash( 'error', $e->getMessage() ); siteSettingsRedirect( 'site_settings.php' ); } } /* ========================================================= FLASH ========================================================= */ $flash = siteSettingsGetFlash(); /* ========================================================= FILTERS ========================================================= */ $search = trim( $_GET['q'] ?? '' ); $groupFilter = (int)( $_GET['group_id'] ?? 0 ); $publicFilter = $_GET['public'] ?? ''; $page = max( 1, (int)( $_GET['page'] ?? 1 ) ); $perPage = 15; /* ========================================================= WHERE ========================================================= */ $where = []; $params = []; if ($search !== '') { $where[] = "( s.setting_key LIKE ? OR s.label LIKE ? OR s.description LIKE ? OR s.setting_value LIKE ? )"; $searchLike = '%' . $search . '%'; $params[] = $searchLike; $params[] = $searchLike; $params[] = $searchLike; $params[] = $searchLike; } if ($groupFilter > 0) { $where[] = "s.group_id = ?"; $params[] = $groupFilter; } if ( $publicFilter === '1' || $publicFilter === '0' ) { $where[] = "s.is_public = ?"; $params[] = (int)$publicFilter; } $whereSql = ''; if (!empty($where)) { $whereSql = 'WHERE ' . implode( ' AND ', $where ); } /* ========================================================= GROUP JOIN ========================================================= */ $groupJoin = ''; $groupSelect = 'NULL AS group_name'; if ( $groupTableExists && !empty($groups) ) { $groupJoin = "LEFT JOIN site_setting_groups g ON g.id = s.group_id"; /* * Detect actual group name column. */ try { $groupColumnsStmt = $pdo->query( "SHOW COLUMNS FROM site_setting_groups" ); $groupColumns = []; foreach ( $groupColumnsStmt->fetchAll() as $column ) { $groupColumns[] = $column['Field']; } $groupNameColumn = null; foreach ( [ 'name', 'title', 'group_name', 'label' ] as $candidate ) { if ( in_array( $candidate, $groupColumns, true ) ) { $groupNameColumn = $candidate; break; } } if ($groupNameColumn) { $groupSelect = "g.`{$groupNameColumn}` AS group_name"; } } catch (Throwable $e) { $groupJoin = ''; } } /* ========================================================= STATISTICS ========================================================= */ $totalSettings = 0; $totalPublic = 0; $totalPrivate = 0; $totalGroupsUsed = 0; try { $stmt = $pdo->query( "SELECT COUNT(*) FROM site_settings" ); $totalSettings = (int)$stmt->fetchColumn(); $stmt = $pdo->query( "SELECT COALESCE( SUM(is_public = 1), 0 ), COALESCE( SUM(is_public = 0), 0 ) FROM site_settings" ); $stats = $stmt->fetch( PDO::FETCH_NUM ); $totalPublic = (int)($stats[0] ?? 0); $totalPrivate = (int)($stats[1] ?? 0); $stmt = $pdo->query( "SELECT COUNT( DISTINCT group_id ) FROM site_settings WHERE group_id IS NOT NULL" ); $totalGroupsUsed = (int)$stmt->fetchColumn(); } catch (Throwable $e) { $totalSettings = 0; $totalPublic = 0; $totalPrivate = 0; $totalGroupsUsed = 0; } /* ========================================================= PAGINATION COUNT ========================================================= */ $countSql = " SELECT COUNT(*) FROM site_settings s {$whereSql} "; $countStmt = $pdo->prepare( $countSql ); $countStmt->execute( $params ); $totalFiltered = (int)$countStmt->fetchColumn(); $totalPages = max( 1, (int)ceil( $totalFiltered / $perPage ) ); if ($page > $totalPages) { $page = $totalPages; } $offset = ($page - 1) * $perPage; /* ========================================================= LIST ========================================================= */ $listSql = " SELECT s.id, s.group_id, s.setting_key, s.setting_value, s.value_type, s.label, s.description, s.is_public, s.sort_order, s.created_at, s.updated_at, {$groupSelect} FROM site_settings s {$groupJoin} {$whereSql} ORDER BY s.sort_order ASC, s.setting_key ASC LIMIT {$perPage} OFFSET {$offset} "; $listStmt = $pdo->prepare( $listSql ); $listStmt->execute( $params ); $settings = $listStmt->fetchAll(); /* ========================================================= EDIT ========================================================= */ $editSetting = null; if ( isset($_GET['edit']) ) { $editId = (int)$_GET['edit']; if ($editId > 0) { $stmt = $pdo->prepare( "SELECT id, group_id, setting_key, setting_value, value_type, label, description, is_public, sort_order, created_at, updated_at FROM site_settings WHERE id = ? LIMIT 1" ); $stmt->execute([ $editId ]); $editSetting = $stmt->fetch(); if (!$editSetting) { siteSettingsFlash( 'error', 'Requested setting was not found.' ); siteSettingsRedirect( 'site_settings.php' ); } } } $openForm = isset($_GET['add']) || $editSetting !== null; /* ========================================================= PAGINATION URL ========================================================= */ function siteSettingsPageUrl( $pageNumber ) { $params = []; if ( isset($_GET['q']) && $_GET['q'] !== '' ) { $params['q'] = $_GET['q']; } if ( isset($_GET['group_id']) && (int)$_GET['group_id'] > 0 ) { $params['group_id'] = (int)$_GET['group_id']; } if ( isset($_GET['public']) && $_GET['public'] !== '' ) { $params['public'] = $_GET['public']; } $params['page'] = $pageNumber; return 'site_settings.php?' . http_build_query($params); } ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0" > <title> Site Settings | Pure Chemical Admin </title> <!-- Google Font --> <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" > <!-- Font Awesome --> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.2/css/all.min.css" > <style> :root { --primary: #0f766e; --primary-2: #0d9488; --primary-soft: #ecfdf5; --dark: #0f172a; --dark-2: #1e293b; --text: #334155; --muted: #64748b; --border: #e2e8f0; --bg: #f8fafc; --white: #ffffff; --success: #059669; --danger: #dc2626; --warning: #d97706; --blue: #2563eb; --shadow: 0 12px 35px rgba(15, 23, 42, .07); --shadow-lg: 0 25px 70px rgba(15, 23, 42, .16); --radius: 18px; } * { box-sizing: border-box; } body { margin: 0; font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; font-size: 14px; color: var(--text); background: radial-gradient( circle at top right, rgba(13, 148, 136, .07), transparent 32% ), var(--bg); } button, input, textarea, select { font: inherit; } button { cursor: pointer; } a { text-decoration: none; color: inherit; } /* ===================================================== MAIN ===================================================== */ .site-settings-main { margin-left: 280px; min-height: 100vh; } /* ===================================================== TOPBAR ===================================================== */ .site-topbar { position: sticky; top: 0; z-index: 100; height: 76px; display: flex; align-items: center; justify-content: space-between; padding: 0 32px; background: rgba(255,255,255,.91); border-bottom: 1px solid rgba(226,232,240,.9); backdrop-filter: blur(18px); -webkit-backdrop-filter: blur(18px); } .topbar-left { display: flex; align-items: center; gap: 14px; } .topbar-icon { width: 44px; height: 44px; display: grid; place-items: center; color: var(--primary); background: linear-gradient( 135deg, #ecfdf5, #dff7f1 ); border: 1px solid #ccfbf1; border-radius: 13px; font-size: 18px; } .topbar-title h1 { margin: 0; color: var(--dark); font-size: 19px; font-weight: 800; letter-spacing: -.4px; } .topbar-title p { margin: 3px 0 0; color: var(--muted); font-size: 12px; } .topbar-right { display: flex; align-items: center; } .admin-badge { display: flex; align-items: center; gap: 10px; padding: 7px 12px; background: #fff; border: 1px solid var(--border); border-radius: 12px; } .admin-avatar { width: 35px; height: 35px; display: grid; place-items: center; color: #fff; background: linear-gradient( 135deg, var(--primary), #14b8a6 ); border-radius: 10px; font-size: 13px; } .admin-info strong { display: block; color: var(--dark); font-size: 12px; } .admin-info span { display: block; margin-top: 2px; color: var(--muted); font-size: 10px; } /* ===================================================== CONTENT ===================================================== */ .content { padding: 30px 32px 50px; } .page-heading { display: flex; align-items: flex-end; justify-content: space-between; gap: 20px; margin-bottom: 25px; } .page-heading h2 { margin: 0; color: var(--dark); font-size: 28px; font-weight: 800; letter-spacing: -.8px; } .page-heading p { margin: 8px 0 0; color: var(--muted); font-size: 13px; } /* ===================================================== BUTTONS ===================================================== */ .btn { min-height: 44px; display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 0 16px; border: 0; border-radius: 12px; font-size: 12px; font-weight: 700; transition: transform .18s ease, box-shadow .18s ease; } .btn:hover { transform: translateY(-1px); } .btn-primary { color: #fff; background: linear-gradient( 135deg, var(--primary), var(--primary-2) ); box-shadow: 0 10px 24px rgba(15,118,110,.20); } .btn-secondary { color: var(--dark); background: #fff; border: 1px solid var(--border); } .btn-danger { color: #fff; background: var(--danger); } /* ===================================================== FLASH ===================================================== */ .flash { display: flex; align-items: center; gap: 10px; margin-bottom: 20px; padding: 14px 16px; border-radius: 13px; font-size: 12px; font-weight: 600; } .flash-success { color: #065f46; background: #ecfdf5; border: 1px solid #a7f3d0; } .flash-error { color: #991b1b; background: #fef2f2; border: 1px solid #fecaca; } /* ===================================================== STATS ===================================================== */ .stats-grid { display: grid; grid-template-columns: repeat(4, minmax(0,1fr)); gap: 16px; margin-bottom: 22px; } .stat-card { position: relative; overflow: hidden; padding: 20px; background: #fff; border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); } .stat-icon { width: 42px; height: 42px; display: grid; place-items: center; margin-bottom: 14px; color: var(--primary); background: var(--primary-soft); border-radius: 12px; } .stat-card strong { display: block; color: var(--dark); font-size: 24px; font-weight: 800; letter-spacing: -.5px; } .stat-card span { display: block; margin-top: 5px; color: var(--muted); font-size: 11px; } /* ===================================================== TOOLBAR ===================================================== */ .toolbar { margin-bottom: 18px; padding: 17px; background: #fff; border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); } .filter-form { display: grid; grid-template-columns: minmax(220px, 1.7fr) minmax(170px, 1fr) minmax(150px, .8fr) auto auto; gap: 10px; } .input-wrap { position: relative; } .input-wrap i { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); color: #94a3b8; pointer-events: none; } .form-control { width: 100%; min-height: 44px; padding: 0 13px; color: var(--dark); background: #fff; border: 1px solid #dbe3ec; border-radius: 11px; outline: none; transition: border-color .18s ease, box-shadow .18s ease; } .input-wrap .form-control { padding-left: 39px; } textarea.form-control { min-height: 120px; padding: 13px; resize: vertical; } .form-control:focus { border-color: #5eead4; box-shadow: 0 0 0 4px rgba(20,184,166,.10); } select.form-control { cursor: pointer; } /* ===================================================== TABLE ===================================================== */ .table-card { overflow: hidden; background: #fff; border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); } .table-head { display: flex; align-items: center; justify-content: space-between; padding: 18px 20px; border-bottom: 1px solid var(--border); } .table-head h3 { margin: 0; color: var(--dark); font-size: 14px; font-weight: 800; } .table-head span { color: var(--muted); font-size: 11px; } .table-scroll { overflow-x: auto; } table { width: 100%; min-width: 1050px; border-collapse: collapse; } th { padding: 13px 17px; text-align: left; color: #64748b; background: #f8fafc; border-bottom: 1px solid var(--border); font-size: 10px; font-weight: 800; text-transform: uppercase; letter-spacing: .55px; } td { padding: 15px 17px; vertical-align: middle; border-bottom: 1px solid #edf1f5; font-size: 12px; } tbody tr:hover { background: #fbfefd; } tbody tr:last-child td { border-bottom: 0; } .setting-cell { display: flex; align-items: center; gap: 10px; } .setting-icon { flex: 0 0 auto; width: 36px; height: 36px; display: grid; place-items: center; color: var(--primary); background: var(--primary-soft); border-radius: 10px; } .setting-main strong { display: block; color: var(--dark); font-size: 12px; font-family: "SFMono-Regular", Consolas, monospace; word-break: break-word; } .setting-main small { display: block; margin-top: 4px; color: #94a3b8; font-size: 10px; } .type-badge { display: inline-flex; align-items: center; padding: 6px 9px; color: #334155; background: #f1f5f9; border: 1px solid #e2e8f0; border-radius: 8px; font-size: 10px; font-weight: 700; text-transform: uppercase; } .type-html { color: #7c3aed; background: #f5f3ff; border-color: #ddd6fe; } .type-number { color: #2563eb; background: #eff6ff; border-color: #bfdbfe; } .type-boolean { color: #047857; background: #ecfdf5; border-color: #a7f3d0; } .public-badge { display: inline-flex; align-items: center; gap: 5px; padding: 6px 9px; border-radius: 8px; font-size: 10px; font-weight: 700; } .public-yes { color: #047857; background: #ecfdf5; border: 1px solid #a7f3d0; } .public-no { color: #64748b; background: #f8fafc; border: 1px solid #e2e8f0; } .value-preview { max-width: 290px; color: #475569; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; } .boolean-on { color: #047857; font-weight: 800; } .boolean-off { color: #94a3b8; font-weight: 700; } .actions { display: flex; align-items: center; gap: 6px; } .icon-btn { width: 35px; height: 35px; display: grid; place-items: center; color: #475569; background: #fff; border: 1px solid var(--border); border-radius: 9px; transition: .15s ease; } .icon-btn:hover { color: var(--primary); background: #f0fdfa; border-color: #99f6e4; } .icon-btn.delete:hover { color: var(--danger); background: #fef2f2; border-color: #fecaca; } /* ===================================================== EMPTY ===================================================== */ .empty { padding: 65px 20px; text-align: center; } .empty-icon { width: 64px; height: 64px; display: grid; place-items: center; margin: 0 auto 15px; color: var(--primary); background: var(--primary-soft); border-radius: 18px; font-size: 24px; } .empty h3 { margin: 0; color: var(--dark); font-size: 16px; } .empty p { max-width: 430px; margin: 8px auto 0; color: var(--muted); font-size: 12px; line-height: 1.6; } /* ===================================================== PAGINATION ===================================================== */ .pagination { display: flex; align-items: center; justify-content: space-between; gap: 15px; padding: 17px 20px; border-top: 1px solid var(--border); } .pagination-info { color: var(--muted); font-size: 11px; } .pagination-links { display: flex; align-items: center; gap: 5px; } .page-link { min-width: 34px; height: 34px; display: grid; place-items: center; padding: 0 9px; color: #475569; background: #fff; border: 1px solid var(--border); border-radius: 8px; font-size: 11px; font-weight: 700; } .page-link:hover { color: var(--primary); background: #f0fdfa; border-color: #99f6e4; } .page-link.active { color: #fff; background: var(--primary); border-color: var(--primary); } /* ===================================================== MODAL - FIXED SIDEBAR CUT ISSUE ===================================================== */ .modal-backdrop { position: fixed; inset: 0; left: 280px; /* Sidebar width ko match karne ke liye taaki sidebar ke upar overlap na kare */ z-index: 1000; display: none; align-items: center; justify-content: center; padding: 20px; background: rgba(15,23,42,.64); backdrop-filter: blur(6px); } .modal-backdrop.show { display: flex; } .modal { width: min(760px, 100%); max-height: calc(100vh - 40px); overflow-y: auto; background: #fff; border-radius: 22px; box-shadow: var(--shadow-lg); animation: modalIn .18s ease; } @keyframes modalIn { from { opacity: 0; transform: translateY(12px) scale(.98); } to { opacity: 1; transform: translateY(0) scale(1); } } .modal-head { position: sticky; top: 0; z-index: 2; display: flex; align-items: center; justify-content: space-between; padding: 20px 22px; background: rgba(255,255,255,.95); border-bottom: 1px solid var(--border); backdrop-filter: blur(12px); } .modal-title { display: flex; align-items: center; gap: 11px; } .modal-title-icon { width: 41px; height: 41px; display: grid; place-items: center; color: var(--primary); background: var(--primary-soft); border-radius: 11px; } .modal-title h3 { margin: 0; color: var(--dark); font-size: 16px; font-weight: 800; } .modal-title p { margin: 3px 0 0; color: var(--muted); font-size: 10px; } .modal-close { width: 36px; height: 36px; display: grid; place-items: center; color: #64748b; background: #fff; border: 1px solid var(--border); border-radius: 10px; } .modal-close:hover { color: var(--danger); background: #fef2f2; } .modal-body { padding: 22px; } .form-grid { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 17px; } .form-group { display: flex; flex-direction: column; gap: 7px; } .form-group.full { grid-column: 1 / -1; } .form-label { color: #334155; font-size: 11px; font-weight: 800; } .required { color: var(--danger); } .help { color: #94a3b8; font-size: 10px; line-height: 1.5; } .checkbox-card { display: flex; align-items: center; justify-content: space-between; min-height: 44px; padding: 0 13px; background: #f8fafc; border: 1px solid #e2e8f0; border-radius: 11px; } .checkbox-label { display: flex; align-items: center; gap: 9px; color: #334155; font-size: 11px; font-weight: 700; } .checkbox-label input { width: 17px; height: 17px; accent-color: var(--primary); } .modal-footer { display: flex; align-items: center; justify-content: flex-end; gap: 9px; padding: 17px 22px; background: #f8fafc; border-top: 1px solid var(--border); } /* ===================================================== DELETE ===================================================== */ .delete-modal { width: min(430px, 100%); } .delete-body { padding: 28px; text-align: center; } .delete-icon { width: 62px; height: 62px; display: grid; place-items: center; margin: 0 auto 17px; color: var(--danger); background: #fef2f2; border: 1px solid #fecaca; border-radius: 18px; font-size: 22px; } .delete-body h3 { margin: 0; color: var(--dark); font-size: 17px; } .delete-body p { margin: 9px 0 0; color: var(--muted); font-size: 12px; line-height: 1.6; } .delete-key { display: inline-block; max-width: 100%; margin-top: 13px; padding: 8px 10px; color: #991b1b; background: #fef2f2; border: 1px solid #fecaca; border-radius: 8px; font-family: monospace; font-size: 11px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; } /* ===================================================== RESPONSIVE ===================================================== */ @media (max-width: 1150px) { .site-settings-main { margin-left: 0; } .modal-backdrop { left: 0; /* Jab screen choti ho aur sidebar hide/collapse ho jaye toh backdrop poori screen le */ } .stats-grid { grid-template-columns: repeat(2,1fr); } .filter-form { grid-template-columns: 1fr 1fr; } } @media (max-width: 700px) { .site-topbar { height: 68px; padding: 0 15px; } .topbar-title h1 { font-size: 16px; } .topbar-title p { display: none; } .admin-info { display: none; } .content { padding: 22px 15px 40px; } .page-heading { align-items: flex-start; flex-direction: column; } .page-heading h2 { font-size: 24px; } .stats-grid { grid-template-columns: 1fr; } .filter-form { grid-template-columns: 1fr; } .form-grid { grid-template-columns: 1fr; } .form-group.full { grid-column: auto; } .pagination { align-items: flex-start; flex-direction: column; } .pagination-links { width: 100%; overflow-x: auto; } } </style> </head> <body> <?php /* |-------------------------------------------------------------------------- | EXISTING ADMIN SIDEBAR |-------------------------------------------------------------------------- | | Sidebar is intentionally included separately. | */ require_once __DIR__ . '/sidebar.php'; ?> <div class="site-settings-main"> <!-- ===================================================== TOPBAR ====================================================== --> <header class="site-topbar"> <div class="topbar-left"> <div class="topbar-icon"> <i class="fa-solid fa-globe"></i> </div> <div class="topbar-title"> <h1> Site Settings </h1> <p> Manage public website configuration </p> </div> </div> <div class="topbar-right"> <div class="admin-badge"> <div class="admin-avatar"> <i class="fa-solid fa-user-shield"></i> </div> <div class="admin-info"> <strong> <?= e( $_SESSION['ADMIN_NAME'] ?? 'Administrator' ); ?> </strong> <span> Administrator </span> </div> </div> </div> </header> <!-- ===================================================== CONTENT ====================================================== --> <main class="content"> <!-- PAGE HEADING --> <div class="page-heading"> <div> <h2> Site Configuration </h2> <p> Create and manage structured website settings used across the Pure Chemical frontend. </p> </div> <button type="button" class="btn btn-primary" onclick="openSettingModal()" > <i class="fa-solid fa-plus"></i> Add Site Setting </button> </div> <!-- ================================================= FLASH ================================================== --> <?php if ($flash): ?> <div class="flash <?= $flash['type'] === 'success' ? 'flash-success' : 'flash-error'; ?>" > <i class="fa-solid <?= $flash['type'] === 'success' ? 'fa-circle-check' : 'fa-circle-exclamation'; ?>" ></i> <span> <?= e( $flash['message'] ); ?> </span> </div> <?php endif; ?> <!-- ================================================= STATS ================================================== --> <section class="stats-grid"> <div class="stat-card"> <div class="stat-icon"> <i class="fa-solid fa-sliders"></i> </div> <strong> <?= number_format( $totalSettings ); ?> </strong> <span> Total Settings </span> </div> <div class="stat-card"> <div class="stat-icon"> <i class="fa-solid fa-earth-americas"></i> </div> <strong> <?= number_format( $totalPublic ); ?> </strong> <span> Public Settings </span> </div> <div class="stat-card"> <div class="stat-icon"> <i class="fa-solid fa-lock"></i> </div> <strong> <?= number_format( $totalPrivate ); ?> </strong> <span> Private Settings </span> </div> <div class="stat-card"> <div class="stat-icon"> <i class="fa-solid fa-layer-group"></i> </div> <strong> <?= number_format( $totalGroupsUsed ); ?> </strong> <span> Groups In Use </span> </div> </section> <!-- ================================================= FILTERS ================================================== --> <section class="toolbar"> <form method="GET" action="site_settings.php" class="filter-form" > <div class="input-wrap"> <i class="fa-solid fa-magnifying-glass" ></i> <input type="text" name="q" class="form-control" placeholder="Search key, label, value..." value="<?= e( $search ); ?>" > </div> <!-- GROUP --> <select name="group_id" class="form-control" > <option value=""> All Groups </option> <?php foreach ( $groups as $group ): ?> <option value="<?= (int)$group['group_id']; ?>" <?= $groupFilter === (int)$group['group_id'] ? 'selected' : ''; ?> > <?= e( $group['group_name'] ); ?> </option> <?php endforeach; ?> </select> <!-- PUBLIC --> <select name="public" class="form-control" > <option value=""> Public + Private </option> <option value="1" <?= $publicFilter === '1' ? 'selected' : ''; ?> > Public Only </option> <option value="0" <?= $publicFilter === '0' ? 'selected' : ''; ?> > Private Only </option> </select> <button type="submit" class="btn btn-primary" > <i class="fa-solid fa-filter"></i> Filter </button> <?php if ( $search !== '' || $groupFilter > 0 || $publicFilter !== '' ): ?> <a href="site_settings.php" class="btn btn-secondary" > <i class="fa-solid fa-rotate-left" ></i> Reset </a> <?php endif; ?> </form> </section> <!-- ================================================= TABLE ================================================== --> <section class="table-card"> <div class="table-head"> <h3> Site Settings </h3> <span> <?= number_format( $totalFiltered ); ?> record<?= $totalFiltered == 1 ? '' : 's'; ?> </span> </div> <?php if ( empty($settings) ): ?> <div class="empty"> <div class="empty-icon"> <i class="fa-solid fa-globe" ></i> </div> <h3> No site settings found </h3> <p> No records match the current search or filters. Add a site setting to start configuring the website. </p> </div> <?php else: ?> <div class="table-scroll"> <table> <thead> <tr> <th> Setting </th> <th> Group </th> <th> Type </th> <th> Value </th> <th> Visibility </th> <th> Order </th> <th> Updated </th> <th> Actions </th> </tr> </thead> <tbody> <?php foreach ( $settings as $setting ): ?> <?php $type = $setting['value_type']; $rawValue = $setting['setting_value']; $preview = trim( (string)$rawValue ); $preview = preg_replace( '/\s+/', ' ', $preview ); ?> <tr> <!-- SETTING --> <td> <div class="setting-cell" > <div class="setting-icon" > <i class="fa-solid fa-key" ></i> </div> <div class="setting-main" > <strong> <?= e( $setting[ 'setting_key' ] ); ?> </strong> <small> <?php if ( !empty( $setting['label'] ) ): ?> <?= e( $setting[ 'label' ] ); ?> <?php else: ?> ID # <?= (int) $setting['id']; ?> <?php endif; ?> </small> </div> </div> </td> <!-- GROUP --> <td> <?php if ( !empty( $setting['group_name'] ) ): ?> <span class="type-badge" > <i class="fa-solid fa-layer-group" style="margin-right:5px;" ></i> <?= e( $setting[ 'group_name' ] ); ?> </span> <?php else: ?> <span style=" color:#94a3b8; font-size:11px; " > No group </span> <?php endif; ?> </td> <!-- TYPE --> <td> <span class="type-badge type-<?= e( $type ); ?>" > <?= e( $type ); ?> </span> </td> <!-- VALUE --> <td> <?php if ( $type === 'boolean' ): ?> <?php $isOn = in_array( (string)$rawValue, [ '1', 'true', 'yes', 'on' ], true ); ?> <?php if ($isOn): ?> <span class="boolean-on" > <i class="fa-solid fa-circle-check" ></i> Enabled </span> <?php else: ?> <span class="boolean-off" > <i class="fa-solid fa-circle-xmark" ></i> Disabled </span> <?php endif; ?> <?php elseif ( $preview === '' ): ?> <span style=" color:#94a3b8; font-style:italic; " > Empty / NULL </span> <?php else: ?> <div class="value-preview" title="<?= e( $preview ); ?>" > <?= e( $preview ); ?> </div> <?php endif; ?> </td> <!-- VISIBILITY --> <td> <?php if ( (int) $setting['is_public'] === 1 ): ?> <span class=" public-badge public-yes " > <i class="fa-solid fa-globe" ></i> Public </span> <?php else: ?> <span class=" public-badge public-no " > <i class="fa-solid fa-lock" ></i> Private </span> <?php endif; ?> </td> <!-- ORDER --> <td> <span style=" font-weight:700; color:#475569; " > <?= (int) $setting[ 'sort_order' ]; ?> </span> </td> <!-- UPDATED --> <td> <span style=" color:#64748b; font-size:10px; " > <?php if ( !empty( $setting[ 'updated_at' ] ) ) { echo e( date( 'd M Y, h:i A', strtotime( $setting[ 'updated_at' ] ) ) ); } else { echo '—'; } ?> </span> </td> <!-- ACTIONS --> <td> <div class="actions" > <a href="site_settings.php?edit=<?= (int)$setting['id']; ?>" class="icon-btn" title="Edit" > <i class="fa-solid fa-pen" ></i> </a> <button type="button" class="icon-btn delete" title="Delete" onclick="openDeleteModal( <?= (int)$setting['id']; ?>, '<?= e( $setting[ 'setting_key' ] ); ?>' )" > <i class="fa-solid fa-trash" ></i> </button> </div> </td> </tr> <?php endforeach; ?> </tbody> </table> </div> <!-- ================================================= PAGINATION ================================================== --> <?php if ( $totalPages > 1 ): ?> <div class="pagination" > <div class="pagination-info" > Showing <strong> <?= $totalFiltered > 0 ? $offset + 1 : 0; ?> </strong> to <strong> <?= min( $offset + $perPage, $totalFiltered ); ?> </strong> of <strong> <?= number_format( $totalFiltered ); ?> </strong> settings </div> <div class="pagination-links" > <?php if ( $page > 1 ): ?> <a href="<?= e( siteSettingsPageUrl( $page - 1 ) ); ?>" class="page-link" > <i class="fa-solid fa-chevron-left" ></i> </a> <?php else: ?> <span class=" page-link " style=" opacity:.4; pointer-events:none; " > <i class="fa-solid fa-chevron-left" ></i> </span> <?php endif; ?> <?php $startPage = max( 1, $page - 2 ); $endPage = min( $totalPages, $page + 2 ); for ( $p = $startPage; $p <= $endPage; $p++ ): ?> <a href="<?= e( siteSettingsPageUrl( $p ) ); ?>" class=" page-link <?= $p === $page ? 'active' : ''; ?> " > <?= $p; ?> </a> <?php endfor; ?> <?php if ( $page < $totalPages ): ?> <a href="<?= e( siteSettingsPageUrl( $page + 1 ) ); ?>" class="page-link" > <i class="fa-solid fa-chevron-right" ></i> </a> <?php else: ?> <span class="page-link" style=" opacity:.4; pointer-events:none; " > <i class="fa-solid fa-chevron-right" ></i> </span> <?php endif; ?> </div> </div> <?php endif; ?> <?php endif; ?> </section> </main> </div> <!-- ========================================================= ADD / EDIT MODAL ========================================================= --> <div class=" modal-backdrop <?= $openForm ? 'show' : ''; ?> " id="settingModal" > <div class="modal" role="dialog" aria-modal="true" > <div class="modal-head"> <div class="modal-title"> <div class="modal-title-icon"> <i class="fa-solid <?= $editSetting ? 'fa-pen' : 'fa-plus'; ?>" ></i> </div> <div> <h3> <?= $editSetting ? 'Edit Site Setting' : 'Add Site Setting'; ?> </h3> <p> Configure a structured website setting. </p> </div> </div> <button type="button" class="modal-close" onclick="closeSettingModal()" > <i class="fa-solid fa-xmark" ></i> </button> </div> <form method="POST" action="site_settings.php" id="settingForm" > <?= siteSettingsCsrfField(); ?> <input type="hidden" name="action" value="save" > <input type="hidden" name="id" value="<?= $editSetting ? (int)$editSetting['id'] : 0; ?>" > <div class="modal-body"> <div class="form-grid"> <!-- KEY --> <div class=" form-group full " > <label class="form-label" > Setting Key <span class="required"> * </span> </label> <input type="text" name="setting_key" class="form-control" maxlength="190" required placeholder="Example: site_name" value="<?= $editSetting ? e( $editSetting[ 'setting_key' ] ) : ''; ?>" > <div class="help"> Unique machine-readable key. Example: <strong> site_name </strong>, <strong> contact_email </strong>, <strong> whatsapp_number </strong>. </div> </div> <!-- LABEL --> <div class="form-group" > <label class="form-label" > Label </label> <input type="text" name="label" class="form-control" maxlength="255" placeholder="Human readable setting name" value="<?= $editSetting ? e( $editSetting[ 'label' ] ) : ''; ?>" > </div> <!-- GROUP --> <div class="form-group" > <label class="form-label" > Setting Group </label> <?php if ( !empty($groups) ): ?> <select name="group_id" class="form-control" > <option value=""> No Group </option> <?php foreach ( $groups as$group ): ?> <option value="<?= (int)$group['group_id']; ?>" <?= $editSetting && (int)$editSetting[ 'group_id' ] === (int)$group[ 'group_id' ] ? 'selected' : ''; ?> > <?= e( $group[ 'group_name' ] ); ?> </option> <?php endforeach; ?> </select> <?php else: ?> <select class="form-control" disabled > <option> No setting groups available </option> </select> <input type="hidden" name="group_id" value="" > <?php endif; ?> <div class="help"> Uses the existing <strong> site_setting_groups </strong> table. </div> </div> <!-- VALUE TYPE --> <div class="form-group" > <label class="form-label" > Value Type <span class="required"> * </span> </label> <select name="value_type" id="valueType" class="form-control" onchange="changeValueEditor()" required > <?php foreach ( $valueTypes as$type ): ?> <option value="<?= e( $type ); ?>" <?= $editSetting && $editSetting[ 'value_type' ] ===$type ? 'selected' : ''; ?> > <?= e( ucfirst( $type ) ); ?> </option> <?php endforeach; ?> </select> <div class="help"> This follows the actual database enum definition. </div> </div> <!-- SORT ORDER --> <div class="form-group" > <label class="form-label" > Sort Order </label> <input type="number" name="sort_order" class="form-control" min="0" step="1" value="<?= $editSetting ? (int)$editSetting[ 'sort_order' ] : 0; ?>" > <div class="help"> Lower values appear first. </div> </div> <!-- PUBLIC --> <div class="form-group full" > <div class="checkbox-card" > <label class="checkbox-label" > <input type="checkbox" name="is_public" value="1" <?= ( !$editSetting || (int)$editSetting[ 'is_public' ] === 1 ) ? 'checked' : ''; ?> > <span> Make this setting public </span> </label> <i class=" fa-solid fa-globe " style=" color:#0f766e; " ></i> </div> <div class="help"> Public settings can be used by the frontend where your application reads public site configuration. </div> </div> <!-- VALUE --> <div class=" form-group full " id="valueEditorGroup" > <label class="form-label" id="valueLabel" > Setting Value </label> <!-- TEXT --> <div id="textEditor" > <input type="text" name="setting_value" id="textValue" class="form-control" maxlength="100000" placeholder="Enter setting value..." > </div> <!-- NUMBER --> <div id="numberEditor" style="display:none;" > <input type="number" name="setting_value_number" id="numberValue" class="form-control" step="any" placeholder="Enter number..." disabled > </div> <!-- TEXTAREA --> <div id="textareaEditor" style="display:none;" > <textarea name="setting_value_textarea" id="textareaValue" class="form-control" placeholder="Enter detailed value..." disabled ></textarea> </div> <!-- HTML --> <div id="htmlEditor" style="display:none;" > <textarea name="setting_value_html" id="htmlValue" class="form-control" style=" min-height:180px; font-family: monospace; font-size:12px; " placeholder="Enter HTML..." disabled ></textarea> </div> <!-- BOOLEAN --> <div id="booleanEditor" style="display:none;" > <div class="checkbox-card" > <label class="checkbox-label" > <input type="checkbox" id="booleanValue" disabled > <span> Enable this setting </span> </label> <i class=" fa-solid fa-toggle-on " style=" color:#0f766e; font-size:19px; " ></i> </div> </div> <div class="help"> The input automatically changes according to the selected value type. </div> </div> <!-- DESCRIPTION --> <div class=" form-group full " > <label class="form-label" > Description </label> <textarea name="description" class="form-control" placeholder="Explain what this setting controls..." ><?= $editSetting ? e( $editSetting[ 'description' ] ) : ''; ?></textarea> </div> </div> </div> <div class="modal-footer"> <button type="button" class="btn btn-secondary" onclick="closeSettingModal()" > Cancel </button> <button type="submit" class="btn btn-primary" > <i class="fa-solid <?= $editSetting ? 'fa-floppy-disk' : 'fa-plus'; ?>" ></i> <?= $editSetting ? 'Update Setting' : 'Save Setting'; ?> </button> </div> </form> </div> </div> <!-- ========================================================= DELETE MODAL ========================================================= --> <div class="modal-backdrop" id="deleteModal" > <div class=" modal delete-modal " > <div class="delete-body"> <div class="delete-icon"> <i class="fa-solid fa-trash" ></i> </div> <h3> Delete Site Setting? </h3> <p> This setting will be permanently removed from the <strong>site_settings</strong> table. </p> <div class="delete-key" id="deleteSettingKey" ></div> </div> <form method="POST" action="site_settings.php" > <?= siteSettingsCsrfField(); ?> <input type="hidden" name="action" value="delete" > <input type="hidden" name="id" id="deleteSettingId" value="" > <div class="modal-footer"> <button type="button" class="btn btn-secondary" onclick="closeDeleteModal()" > Cancel </button> <button type="submit" class="btn btn-danger" > <i class="fa-solid fa-trash" ></i> Delete Setting </button> </div> </form> </div> </div> <script> /* ========================================================= EXISTING VALUE ========================================================= */ const existingSettingValue = <?= json_encode( $editSetting ? (string)$editSetting[ 'setting_value' ] : '', JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_QUOT | JSON_HEX_AMP ); ?>; /* ========================================================= MODAL ========================================================= */ const settingModal = document.getElementById( 'settingModal' ); function openSettingModal() { if (!settingModal) { return; } settingModal.classList.add( 'show' ); document.body.style.overflow = 'hidden'; setTimeout( function () { const input = document.querySelector( '#settingModal input[name="setting_key"]' ); if (input) { input.focus(); } }, 100 ); } function closeSettingModal() { if (!settingModal) { return; } settingModal.classList.remove( 'show' ); document.body.style.overflow = ''; const url = new URL( window.location.href ); url.searchParams.delete( 'add' ); url.searchParams.delete( 'edit' ); window.history.replaceState( {}, document.title, url.toString() ); } /* ========================================================= VALUE EDITOR ========================================================= */ function changeValueEditor() { const type = document.getElementById( 'valueType' ).value; const textEditor = document.getElementById( 'textEditor' ); const numberEditor = document.getElementById( 'numberEditor' ); const textareaEditor = document.getElementById( 'textareaEditor' ); const htmlEditor = document.getElementById( 'htmlEditor' ); const booleanEditor = document.getElementById( 'booleanEditor' ); const textValue = document.getElementById( 'textValue' ); const numberValue = document.getElementById( 'numberValue' ); const textareaValue = document.getElementById( 'textareaValue' ); const htmlValue = document.getElementById( 'htmlValue' ); const booleanValue = document.getElementById( 'booleanValue' ); /* * Hide all editors. */ textEditor.style.display = 'none'; numberEditor.style.display = 'none'; textareaEditor.style.display = 'none'; htmlEditor.style.display = 'none'; booleanEditor.style.display = 'none'; /* * Disable all controls. */ textValue.disabled = true; numberValue.disabled = true; textareaValue.disabled = true; htmlValue.disabled = true; booleanValue.disabled = true; /* * Select editor. */ if (type === 'number') { numberEditor.style.display = 'block'; numberValue.disabled = false; numberValue.name = 'setting_value'; textValue.name = 'setting_value_text'; numberValue.value = existingSettingValue; } else if (type === 'textarea') { textareaEditor.style.display = 'block'; textareaValue.disabled = false; textareaValue.name = 'setting_value'; textareaValue.value = existingSettingValue; } else if (type === 'html') { htmlEditor.style.display = 'block'; htmlValue.disabled = false; htmlValue.name = 'setting_value'; htmlValue.value = existingSettingValue; } else if (type === 'boolean') { booleanEditor.style.display = 'block'; booleanValue.disabled = false; booleanValue.name = 'setting_value'; booleanValue.value = '1'; booleanValue.checked = [ '1', 'true', 'yes', 'on' ].includes( existingSettingValue .toLowerCase() ); } else { textEditor.style.display = 'block'; textValue.disabled = false; textValue.name = 'setting_value'; textValue.value = existingSettingValue; } } /* ========================================================= INITIALIZE EDITOR ========================================================= */ document.addEventListener( 'DOMContentLoaded', function () { changeValueEditor(); } ); /* ========================================================= DELETE MODAL ========================================================= */ const deleteModal = document.getElementById( 'deleteModal' ); function openDeleteModal( id, key ) { document.getElementById( 'deleteSettingId' ).value = id; document.getElementById( 'deleteSettingKey' ).textContent = key; deleteModal.classList.add( 'show' ); document.body.style.overflow = 'hidden'; } function closeDeleteModal() { deleteModal.classList.remove( 'show' ); document.body.style.overflow = ''; } /* ========================================================= BACKDROP CLICK ========================================================= */ if (settingModal) { settingModal.addEventListener( 'click', function (event) { if ( event.target === settingModal ) { closeSettingModal(); } } ); } if (deleteModal) { deleteModal.addEventListener( 'click', function (event) { if ( event.target === deleteModal ) { closeDeleteModal(); } } ); } /* ========================================================= ESC ========================================================= */ document.addEventListener( 'keydown', function (event) { if ( event.key === 'Escape' ) { closeSettingModal(); closeDeleteModal(); } } ); /* ========================================================= CTRL + K SEARCH ========================================================= */ document.addEventListener( 'keydown', function (event) { if ( (event.ctrlKey || event.metaKey) && event.key.toLowerCase() === 'k' ) { event.preventDefault(); const search = document.querySelector( 'input[name="q"]' ); if (search) { search.focus(); } } } ); </script> </body> </html>
Save
Cancel