<?php include('auth_guard.php'); ?><?php
include("config.php"); // Database connection

// DB se users fetch karna
$query = "SELECT username FROM users";
$result = mysqli_query($conn, $query);
?>

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>All Users Remarks</title>
    <style>
        /* Background aur Main Page Styling */
        body { 
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; 
            background-color: #002366; /* Royal Blue Background */
            color: #ffffff; /* White Text */
            margin: 0;
            display: flex;
            justify-content: center;
            align-items: center;
            min-height: 100vh;
            padding: 20px;
            box-sizing: border-box;
        }

        .main-container {
            width: 100%;
            max-width: 500px; /* Mobile par centered rehne ke liye */
            background: rgba(255, 255, 255, 0.1); /* Halka sa glass effect */
            padding: 25px;
            border-radius: 15px;
            border: 1px solid rgba(255, 255, 255, 0.2);
            box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.3);
        }

        h2 { 
            text-align: center; 
            color: #00d4ff; /* Bright Blue/Cyan for Heading */
            margin-bottom: 25px;
            font-size: 1.5rem;
            text-transform: uppercase;
            letter-spacing: 1px;
        }

        /* Form Row Styling */
        .user-row { 
            display: flex; 
            flex-direction: row;
            align-items: center; 
            margin-bottom: 15px;
            gap: 10px;
        }

        .name-label { 
            flex: 1; 
            font-size: 1.1rem;
            font-weight: 500;
        }

        input[type="text"] { 
            flex: 2;
            padding: 10px; 
            border-radius: 8px;
            border: 1px solid #ccc;
            outline: none;
            background: #fff;
            color: #333;
        }

        /* Submit Button */
        .btn-submit { 
            width: 100%;
            padding: 12px;
            background-color: #00d4ff;
            color: #002366;
            border: none;
            border-radius: 8px;
            font-size: 1.1rem;
            font-weight: bold;
            cursor: pointer;
            margin-top: 20px;
            transition: 0.3s;
        }

        .btn-submit:hover { 
            background-color: #ffffff;
            transform: translateY(-2px);
        }

        /* Results Area (This Print) */
        .result-section {
            margin-top: 40px;
            background: #ffffff;
            color: #333;
            border-radius: 10px;
            padding: 15px;
            width: 100%;
        }

        .result-section h3 { 
            text-align: center; 
            color: #002366; 
            margin-top: 0;
        }

        .print-table { 
            width: 100%; 
            border-collapse: collapse; 
        }

        .print-table td { 
            border: 1px solid #ddd; 
            padding: 12px; 
            text-align: left;
        }

        /* Mobile Responsive adjustments */
        @media (max-width: 400px) {
            .user-row { flex-direction: column; align-items: flex-start; }
            input[type="text"] { width: 100%; box-sizing: border-box; }
        }
    </style>
</head>
<body>

    <div class="main-container">
        <h2>Multi-Remarks Entry</h2>
        
        <form action="" method="POST">
            <?php while($row = mysqli_fetch_assoc($result)): ?>
                <div class="user-row">
                    <span class="name-label"><?php echo htmlspecialchars($row['username']); ?></span>
                    <input type="hidden" name="usernames[]" value="<?php echo htmlspecialchars($row['username']); ?>">
                    <input type="text" name="remarks[]" placeholder="Type here...">
                </div>
            <?php endwhile; ?>
            
            <button type="submit" name="submit_all" class="btn-submit">SUBMIT DATA</button>
        </form>

        <!-- Output Section -->
        <?php
        if (isset($_POST['submit_all'])) {
            $names = $_POST['usernames'];
            $remarks = $_POST['remarks'];
            $has_data = false;

            // Check if any box has data
            foreach($remarks as $r) { if(!empty(trim($r))) { $has_data = true; break; } }

            if ($has_data) {
                echo "<div class='result-section'>";
                echo "<h3>This Print</h3>";
                echo "<table class='print-table'>";
                
                for ($i = 0; $i < count($names); $i++) {
                    if (!empty(trim($remarks[$i]))) {
                        echo "<tr>";
                        echo "<td style='font-weight:bold;'>" . htmlspecialchars($names[$i]) . "</td>";
                        echo "<td>" . htmlspecialchars($remarks[$i]) . "</td>";
                        echo "</tr>";
                    }
                }
                echo "</table>";
                echo "</div>";
            }
        }
        ?>
    </div>

</body>
</html>