<?php
// ✅ Enable error reporting during development
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);

require_once 'db.php';

// ✅ Fetch Branding Details
$stmt = $pdo->query("SELECT * FROM branding WHERE id = 1");
$branding = $stmt->fetch(PDO::FETCH_ASSOC);
$brandName = $branding['brand_name'] ?? 'Marketing System';
$logoImage = $branding['logo_image'] ?? '';
$footerNote = $branding['footer_note'] ?? '';
$domainName = str_replace(['https://', 'http://', 'www.'], '', $_SERVER['HTTP_HOST']);
?>

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Privacy Policy - <?= htmlspecialchars($brandName); ?></title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap/5.3.0/css/bootstrap.min.css">
    <style>
        body {
            padding: 30px;
            font-family: Arial, sans-serif;
            background-color: #f4f4f4;
        }
        .container {
            background: #fff;
            padding: 40px;
            border-radius: 10px;
            box-shadow: 0 0 15px rgba(0,0,0,0.1);
        }
        .logo {
            max-height: 80px;
            margin-bottom: 20px;
        }
        footer {
            margin-top: 60px;
            text-align: center;
            font-size: 14px;
            color: #777;
        }
    </style>
</head>
<body>

<div class="container">
    <?php if (!empty($logoImage)): ?>
        <div class="text-center">
            <img src="<?= htmlspecialchars($logoImage); ?>" alt="Logo" class="logo">
        </div>
    <?php endif; ?>

    <h1 class="text-center mb-4">Privacy Policy</h1>
    <p><strong>Effective Date:</strong> July 04, 2025</p>

    <p>At <?= htmlspecialchars($brandName); ?>, your privacy is important to us. This Privacy Policy explains how we collect, use, and protect your information when you use our free marketing system available at <?= htmlspecialchars($domainName); ?>.</p>

    <h4>1. Information We Collect</h4>
    <p>We collect basic personal information such as name, email address, and referral ID when you register or use the platform. We also collect anonymous tracking data for analytics and user experience improvements.</p>

    <h4>2. Use of Information</h4>
    <p>We use your information to provide access to tools, generate lead capture pages, connect with external autoresponders, and track referrals. Data is never sold or shared beyond these operational needs.</p>

    <h4>3. LeadsLeap Integration</h4>
    <p>Leads generated via our platform may be passed to your connected LeadsLeap account if configured. LeadsLeap operates under its own privacy policies.</p>

    <h4>4. Third-Party Programs</h4>
    <p>Our platform promotes third-party income streams. We are not responsible for their terms, payments, or support. Please read their respective policies before joining.</p>

    <h4>5. Member Conduct</h4>
    <p>Members must not misrepresent the system, promote false claims, or spam. We reserve the right to suspend or delete accounts for violations of ethical marketing standards.</p>

    <h4>6. Communication</h4>
    <p>By registering, you consent to receive email communications from us, including onboarding instructions, updates, and training content. You may unsubscribe at any time, but it may impact your ability to use the platform effectively.</p>

    <h4>7. Cookies and Tracking</h4>
    <p>Cookies are used for session tracking, sponsor attribution, and experience improvements. No sensitive data is stored in cookies.</p>

    <h4>8. Data Deletion</h4>
    <p>You may request account deletion at any time. Data stored in connected tools like LeadsLeap must be managed within those platforms.</p>

    <h4>9. Updates</h4>
    <p>We may update this Privacy Policy without notice. Continued use of the system implies agreement to the latest version.</p>

    <h4>10. Contact</h4>
    <p>If you have any questions about this Privacy Policy, please contact us through the support form at <?= htmlspecialchars($domainName); ?>.</p>
</div>

<footer>
    <?= $footerNote ?: "&copy; $domainName. All rights reserved." ?>
</footer>

</body>
</html>
