<?php
/**
 * Bot Test File — DELETE after testing
 * Upload to: /studytrack/api/bot-test.php
 * Visit: https://studytrack.edurx.icu/studytrack/api/bot-test.php
 */

header('Content-Type: application/json');

// Check telegram-bot.php version
$tbPath    = __DIR__ . '/telegram-bot.php';
$tbContent = file_exists($tbPath) ? file($tbPath, FILE_IGNORE_NEW_LINES) : [];
$top20     = implode(' ', array_slice($tbContent, 0, 20));

$isOld = (
    strpos($top20, 'X-Bot-Secret') !== false ||
    strpos($top20, 'HTTP_X_BOT') !== false ||
    strpos($top20, 'BOT_SECRET') !== false && strpos($top20, 'HTTP_') !== false
);

echo json_encode([
    'php_ok'      => true,
    'php_version' => PHP_VERSION,
    'post_data'   => $_POST,
    'get_data'    => $_GET,
    'method'      => $_SERVER['REQUEST_METHOD'],
    'telegram_bot_php' => [
        'exists'          => file_exists($tbPath),
        'is_OLD_version'  => $isOld,
        'is_NEW_version'  => !$isOld,
        'first_5_lines'   => array_slice($tbContent, 0, 8),
    ],
    'verdict' => $isOld
        ? 'OLD FILE — replace telegram-bot.php!'
        : 'NEW FILE — correct version',
], JSON_PRETTY_PRINT);