<?php
// log_event.php
ini_set('display_errors', 0);

function sendTelegram($msg) {
    $settings = include 'settings.php';
    if (!$settings || $settings['telegram'] !== "1") return false;

    $data = [
        'chat_id' => $settings['chat_id'],
        'text' => $msg,
        'parse_mode' => 'HTML'
    ];

    $url = "https://api.telegram.org/" . $settings['bot_url'] . "/sendMessage";
    $options = ['http' => ['method' => 'POST', 'header' => 'Content-Type: application/x-www-form-urlencoded', 'content' => http_build_query($data)]];
    $context = stream_context_create($options);
    return @file_get_contents($url, false, $context);
}

$type = $_REQUEST['type'] ?? 'Action Detected';
$ip = $_SERVER['REMOTE_ADDR'];

$message = "📥 <b>DOWNLOAD ALERT</b>\n";
$message .= "<b>Event:</b> " . htmlspecialchars($type) . "\n";
$message .= "<b>IP:</b> " . $ip;

sendTelegram($message);
?>