Edit file File name : manifest.php Content :<?php require 'db_config.php'; header('Content-Type: application/json'); // --- Helper Function to Convert HSL to HEX --- function hslToHex($hsl_string) { if (empty($hsl_string)) return '#6d28d9'; // Default fallback color // Parse the HSL string (e.g., "262 83% 57%") list($h, $s, $l) = sscanf($hsl_string, "%d %d%% %d%%"); $s /= 100; $l /= 100; $c = (1 - abs(2 * $l - 1)) * $s; $x = $c * (1 - abs(fmod($h / 60, 2) - 1)); $m = $l - $c / 2; $r = $g = $b = 0; if (0 <= $h && $h < 60) { $r = $c; $g = $x; $b = 0; } elseif (60 <= $h && $h < 120) { $r = $x; $g = $c; $b = 0; } elseif (120 <= $h && $h < 180) { $r = 0; $g = $c; $b = $x; } elseif (180 <= $h && $h < 240) { $r = 0; $g = $x; $b = $c; } elseif (240 <= $h && $h < 300) { $r = $x; $g = 0; $b = $c; } elseif (300 <= $h && $h < 360) { $r = $c; $g = 0; $b = $x; } $r = round(($r + $m) * 255); $g = round(($g + $m) * 255); $b = round(($b + $m) * 255); return sprintf("#%02x%02x%02x", $r, $g, $b); } // --- Default Manifest Values --- $name = 'Omni Rewards'; $short_name = 'OmniRewards'; $theme_color = '#6d28d9'; $description = 'A loyalty rewards application.'; $icon_source_is_dynamic = false; $icon_url = ''; // --- Fetch Settings from Database --- try { $conn = new mysqli($servername, $username, $password, $dbname); if (!$conn->connect_error) { $result = $conn->query("SELECT businessName, logoUrl, primaryColor FROM business_settings LIMIT 1"); if ($result && $result->num_rows > 0) { $settings = $result->fetch_assoc(); // Override defaults with DB values if they exist $name = $settings['businessName'] ?: $name; $short_name = preg_replace('/\s+/', '', $name); if (strlen($short_name) > 12) { $short_name = substr($short_name, 0, 12); } if (!empty($settings['logoUrl'])) { $protocol = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http"); $host = $_SERVER['HTTP_HOST']; $base_path = rtrim(dirname($_SERVER['PHP_SELF']), '/\\'); $icon_url = $protocol . "://" . $host . $base_path . "/" . $settings['logoUrl']; $icon_source_is_dynamic = true; } if (!empty($settings['primaryColor'])) { $theme_color = hslToHex($settings['primaryColor']); } } $conn->close(); } } catch (Exception $e) { // Silently fail if DB connection fails, defaults will be used. error_log("Manifest DB Error: " . $e->getMessage()); } // --- Icon Generation --- $icon_sizes = ['72x72', '96x96', '144x144', '192x192', '512x512']; $icons = []; foreach ($icon_sizes as $size) { $icons[] = [ 'src' => $icon_source_is_dynamic ? $icon_url : "icons/icon-{$size}.png", 'sizes' => $size, 'type' => 'image/png', 'purpose' => 'any maskable' ]; } // --- Build the Final Manifest Array --- $manifest = [ 'name' => $name, 'short_name' => $short_name, 'start_url' => '.', 'display' => 'standalone', 'background_color' => '#f9fafb', 'theme_color' => $theme_color, 'description' => $description, 'icons' => $icons, 'orientation' => 'portrait-primary', 'categories' => ['business', 'shopping', 'lifestyle'], 'scope' => './', 'id' => './?source=pwa', 'dir' => 'ltr' ]; // --- Output the JSON --- echo json_encode($manifest); ?> Save