/home/devscfvi/app.devsquantum.com/test_screenshots.php
<?php
// test_screenshots.php
// Quick test to verify screenshot functionality

require_once 'config.php';

header('Content-Type: text/html; charset=utf-8');

echo "<h1>Screenshot Column Test</h1>";

try {
    $pdo = getDBConnection();
    
    // Test 1: Check if columns exist
    echo "<h2>Test 1: Column Structure</h2>";
    $stmt = $pdo->query("SHOW COLUMNS FROM crypto_trades WHERE Field LIKE '%screenshot%'");
    $columns = $stmt->fetchAll(PDO::FETCH_ASSOC);
    
    if (count($columns) > 0) {
        echo "✅ Screenshot columns found:<br>";
        echo "<table border='1' cellpadding='5'>";
        echo "<tr><th>Field</th><th>Type</th><th>Null</th><th>Default</th></tr>";
        foreach ($columns as $col) {
            echo "<tr>";
            echo "<td>{$col['Field']}</td>";
            echo "<td>{$col['Type']}</td>";
            echo "<td>{$col['Null']}</td>";
            echo "<td>" . ($col['Default'] ?? 'NULL') . "</td>";
            echo "</tr>";
        }
        echo "</table>";
    } else {
        echo "❌ No screenshot columns found!<br>";
        echo "Run this SQL:<br>";
        echo "<pre>ALTER TABLE crypto_trades 
ADD COLUMN entry_screenshot VARCHAR(255) DEFAULT NULL,
ADD COLUMN exit_screenshot VARCHAR(255) DEFAULT NULL;</pre>";
    }
    
    // Test 2: Try to insert a test screenshot path
    echo "<h2>Test 2: Insert Test</h2>";
    $testPath = '/uploads/screenshots/test_' . time() . '.jpg';
    
    $stmt = $pdo->prepare("
        INSERT INTO crypto_trades 
        (coin, position_size, entry_price, stop_loss_percent, take_profit_percent, 
         quantity, sl_price, tp_price, loss_amount, profit_amount, reward_risk_ratio, 
         fees, order_type, entry_screenshot)
        VALUES ('TEST', 100, 50000, 0.5, 1.5, 0.002, 49750, 50750, 25, 75, 3, 0.5, 'market', ?)
    ");
    
    $result = $stmt->execute([$testPath]);
    
    if ($result) {
        $testId = $pdo->lastInsertId();
        echo "✅ Test trade inserted with ID: $testId<br>";
        
        // Verify it was saved
        $stmt = $pdo->prepare("SELECT id, coin, entry_screenshot FROM crypto_trades WHERE id = ?");
        $stmt->execute([$testId]);
        $trade = $stmt->fetch(PDO::FETCH_ASSOC);
        
        echo "Retrieved data:<br>";
        echo "- ID: {$trade['id']}<br>";
        echo "- Coin: {$trade['coin']}<br>";
        echo "- Entry Screenshot: " . ($trade['entry_screenshot'] ?? 'NULL') . "<br>";
        
        if ($trade['entry_screenshot'] === $testPath) {
            echo "<strong style='color:green'>✅ Screenshot path saved correctly!</strong><br>";
        } else {
            echo "<strong style='color:red'>❌ Screenshot path NOT saved!</strong><br>";
        }
        
        // Clean up test trade
        $pdo->prepare("DELETE FROM crypto_trades WHERE id = ?")->execute([$testId]);
        echo "<br><em>Test trade deleted</em><br>";
        
    } else {
        echo "❌ Failed to insert test trade<br>";
        print_r($stmt->errorInfo());
    }
    
    // Test 3: Check recent trades
    echo "<h2>Test 3: Recent Trades</h2>";
    $stmt = $pdo->query("
        SELECT id, coin, entry_screenshot, exit_screenshot, created_at 
        FROM crypto_trades 
        ORDER BY created_at DESC 
        LIMIT 5
    ");
    $trades = $stmt->fetchAll(PDO::FETCH_ASSOC);
    
    echo "<table border='1' cellpadding='5'>";
    echo "<tr><th>ID</th><th>Coin</th><th>Entry Screenshot</th><th>Exit Screenshot</th><th>Created</th></tr>";
    foreach ($trades as $trade) {
        echo "<tr>";
        echo "<td>{$trade['id']}</td>";
        echo "<td>{$trade['coin']}</td>";
        echo "<td>" . ($trade['entry_screenshot'] ?? '<em>NULL</em>') . "</td>";
        echo "<td>" . ($trade['exit_screenshot'] ?? '<em>NULL</em>') . "</td>";
        echo "<td>{$trade['created_at']}</td>";
        echo "</tr>";
    }
    echo "</table>";
    
    echo "<h2>Summary</h2>";
    echo "<p>If columns exist and test passed, the issue is in the frontend JavaScript.</p>";
    echo "<p>Check browser console for: <code>console.log(calculatorState.entryScreenshot)</code></p>";
    
} catch (Exception $e) {
    echo "<p style='color:red'>❌ Error: " . $e->getMessage() . "</p>";
}
?>