<?php
require('db_connection.php');

// Query to join mikrotik and payment_options based on id_router
$query = "SELECT m.id_router, m.dns, m.user_mikrotik, m.password_mikrotik, m.ip_mikrotik, m.mikrotik_port,
                 p.endpoint, p.apiKey, p.privateKey, p.merchantCode
          FROM mikrotik m
          JOIN payment_options p ON m.id_router = p.id_router";

$result = $db->query($query);
?>

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Data Mikrotik dan Payment</title>
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
</head>
<body>
    <div class="container mt-5">
        <h2 class="text-center mb-4">Data Mikrotik dan Payment</h2>
        <table class="table table-bordered">
            <thead>
                <tr>
                    <th>ID Router</th>
                    <th>DNS</th>
                    <th>User Mikrotik</th>
                    <th>Password Mikrotik</th>
                    <th>IP Mikrotik</th>
                    <th>Mikrotik Port</th>
                    <th>Endpoint</th>
                    <th>API Key</th>
                    <th>Private Key</th>
                    <th>Merchant Code</th>
                </tr>
            </thead>
            <tbody>
                <?php
                if ($result->num_rows > 0) {
                    while($row = $result->fetch_assoc()) {
                        echo "<tr>
                                <td>{$row['id_router']}</td>
                                <td>{$row['dns']}</td>
                                <td>{$row['user_mikrotik']}</td>
                                <td>{$row['password_mikrotik']}</td>
                                <td>{$row['ip_mikrotik']}</td>
                                <td>{$row['mikrotik_port']}</td>
                                <td>{$row['endpoint']}</td>
                                <td>{$row['apiKey']}</td>
                                <td>{$row['privateKey']}</td>
                                <td>{$row['merchantCode']}</td>
                              </tr>";
                    }
                } else {
                    echo "<tr><td colspan='10' class='text-center'>Tidak ada data yang ditemukan</td></tr>";
                }
                $db->close();
                ?>
            </tbody>
        </table>
    </div>
</body>
</html>
