<?php
// cek_file.php - taruh di folder yang sama dengan process.php
// Akses: http://localhost/escobarweb/cek_file.php

echo "<style>body{font-family:monospace;background:#111;color:#0f0;padding:20px} .err{color:#f44} .warn{color:#ff0} pre{background:#222;padding:10px;border-radius:5px}</style>";

echo "<h2>📁 Cek File process.php yang Aktif</h2>";

$file = __DIR__ . "/process.php";

echo "Lokasi: <b>" . $file . "</b><br><br>";

if (!file_exists($file)) {
    echo "<span class='err'>❌ process.php tidak ada di folder ini!</span><br>";
    die();
}

// Cek apakah file berisi kode baru (ada 'adb_debug.log' yang harusnya ada di versi baru)
$isi = file_get_contents($file);

echo "Ukuran file: <b>" . number_format(strlen($isi)) . " bytes</b><br>";
echo "Terakhir diubah: <b>" . date('Y-m-d H:i:s', filemtime($file)) . "</b><br><br>";

// Cek penanda kode lama vs baru
$checks = [
    'Ada adb_debug.log (versi baru)'       => strpos($isi, 'adb_debug.log') !== false,
    'Ada pause_overlay di process.php'      => strpos($isi, 'pause_overlay') !== false,
    'Ada controlTV($ip, \'pause_overlay\')' => strpos($isi, "controlTV(\$ip, 'pause_overlay')") !== false,
    'Ada case \'pause\':'                   => strpos($isi, "case 'pause':") !== false,
    'Ada sleep(1) sebelum pause'            => strpos($isi, "sleep(1)") !== false,
];

foreach ($checks as $label => $result) {
    $icon = $result ? "✅" : "❌";
    $color = $result ? "#0f0" : "#f44";
    echo "<span style='color:$color'>$icon $label</span><br>";
}

echo "<br>";

// Tampilkan isi sekitar case 'pause':
echo "<h2>Isi sekitar case 'pause': di process.php</h2>";
$lines = explode("\n", $isi);
$pause_line = -1;
foreach ($lines as $i => $line) {
    if (strpos($line, "case 'pause':") !== false) {
        $pause_line = $i;
        break;
    }
}

if ($pause_line === -1) {
    echo "<span class='err'>❌ TIDAK ADA 'case pause' di process.php ini!</span><br>";
    echo "<span class='err'>File ini BUKAN process.php yang benar!</span><br>";
} else {
    echo "Ditemukan di baris " . ($pause_line + 1) . ":<br>";
    $start = max(0, $pause_line - 2);
    $end   = min(count($lines) - 1, $pause_line + 30);
    $snippet = array_slice($lines, $start, $end - $start);
    echo "<pre>" . htmlspecialchars(implode("\n", $snippet)) . "</pre>";
}

echo "<br>";

// Cek config.php juga
echo "<h2>📁 Cek config.php</h2>";
$cfg = __DIR__ . "/config.php";
$cfg_isi = file_get_contents($cfg);

echo "Ukuran: <b>" . number_format(strlen($cfg_isi)) . " bytes</b><br>";
echo "Terakhir diubah: <b>" . date('Y-m-d H:i:s', filemtime($cfg)) . "</b><br><br>";

$cfg_checks = [
    'Ada adb_debug.log'                   => strpos($cfg_isi, 'adb_debug.log') !== false,
    'Ada case pause_overlay:'             => strpos($cfg_isi, "'pause_overlay'") !== false,
    'Ada sleep(1) di controlTV'           => strpos($cfg_isi, 'sleep(1)') !== false,
    'Ada handler.post PAUSE (bukan ini)'  => strpos($cfg_isi, 'handler.post') === false, // ini di Java bukan PHP
];

foreach ($cfg_checks as $label => $result) {
    $icon = $result ? "✅" : "❌";
    $color = $result ? "#0f0" : "#f44";
    echo "<span style='color:$color'>$icon $label</span><br>";
}

echo "<br>";
// Tampilkan controlTV pause_overlay
$cfg_lines = explode("\n", $cfg_isi);
foreach ($cfg_lines as $i => $line) {
    if (strpos($line, "pause_overlay") !== false) {
        $start = max(0, $i - 1);
        $end   = min(count($cfg_lines) - 1, $i + 5);
        echo "Baris " . ($i+1) . ":<br>";
        echo "<pre>" . htmlspecialchars(implode("\n", array_slice($cfg_lines, $start, $end - $start))) . "</pre>";
    }
}

echo "<hr>";
echo "<span style='color:#555'>Hapus file ini setelah selesai debug!</span>";
?>