<?php
/**
 * Minimal QR Code Display Page
 * Shows only the QR code image for the specified image ID
 */

require_once 'connect.php';

// Validate image ID
if (!isset($_GET['id']) || !is_numeric($_GET['id']) || $_GET['id'] <= 0) {
    http_response_code(404);
    exit('QR code not found');
}

$imageId = (int)$_GET['id'];

try {
    // Check database connection
    if (!checkConnection($con)) {
        http_response_code(500);
        exit('Database connection failed');
    }
    
    // Get QR code data
    $stmt = $con->prepare("SELECT qr_path FROM qr_codes WHERE image_id = ?");
    $stmt->execute([$imageId]);
    $result = $stmt->fetch();
    
    if (!$result || !file_exists($result['qr_path'])) {
        http_response_code(404);
        exit('QR code not found');
    }
    
} catch (PDOException $e) {
    error_log('Database error in qr.php: ' . $e->getMessage());
    http_response_code(500);
    exit('Database error occurred');
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>QR Code</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }
        
        body {
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
            background: #000000;
            min-height: 100vh;
            padding: 20px;
            display: flex;
            justify-content: center;
            align-items: center;
        }
        
        .qr-container {
            background: white;
            border-radius: 15px;
            box-shadow: 0 10px 30px rgba(255,255,255,0.1);
            padding: 40px;
            text-align: center;
            max-width: 400px;
            width: 100%;
        }
        
        .qr-image {
            max-width: 100%;
            height: auto;
            border-radius: 8px;
        }
    </style>
</head>
<body>
    <div class="qr-container">
        <img src="<?php echo htmlspecialchars($result['qr_path']); ?>" 
             alt="QR Code" 
             class="qr-image">
    </div>
</body>
</html>
