<?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>Terms of Use - <?= 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">Terms of Use</h1>
    <p><strong>Effective Date:</strong> July 04, 2025</p>

    <p>Welcome to <?= htmlspecialchars($brandName); ?> at <?= htmlspecialchars($domainName); ?>. By accessing or using this free marketing system, you agree to the following Terms of Use. If you do not agree with these terms, please discontinue use immediately.</p>

    <h4>1. System Use</h4>
    <p>You are granted a non-exclusive, revocable license to use this platform to build, promote, and manage your affiliate or network marketing funnels. Abuse, misuse, or unethical behavior may result in account termination.</p>

    <h4>2. Account Responsibility</h4>
    <p>You are responsible for maintaining the confidentiality of your login information. Any activity under your account is your responsibility, including how you market and what claims you make.</p>

    <h4>3. Third-Party Programs</h4>
    <p>Our system promotes third-party programs. We do not operate, endorse, or guarantee the success, accuracy, or safety of these external platforms. Please do your own research before joining any opportunity.</p>

    <h4>4. Member Conduct</h4>
    <p>You agree to follow ethical marketing practices and avoid making misleading or exaggerated claims. Violation of these standards may result in removal from the system without notice.</p>

    <h4>5. Intellectual Property</h4>
    <p>The content, structure, and tools of <?= htmlspecialchars($brandName); ?> are protected intellectual property. You may not copy, resell, or duplicate this platform without written permission.</p>

    <h4>6. Communication</h4>
    <p>By signing up, you agree to receive emails from the system including updates, support, and training content. You may unsubscribe at any time, but doing so may impact access to key features.</p>

    <h4>7. Termination</h4>
    <p>We reserve the right to terminate or restrict access to any user who violates these terms or misuses the system, with or without notice.</p>

    <h4>8. Limitation of Liability</h4>
    <p>We are not liable for losses, damages, or outcomes that result from using this platform or participating in the external income streams promoted through it.</p>

    <h4>9. Updates to Terms</h4>
    <p>We may update these terms at any time. Continued use of the system indicates acceptance of the latest version.</p>

    <h4>10. Contact</h4>
    <p>If you have any questions regarding these terms, please contact the system administrator through <?= htmlspecialchars($domainName); ?>.</p>
</div>

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

</body>
</html>
