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

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


        <!-- 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);">Traders</a></li>
                            <li class="breadcrumb-item"><a href="javascript:void(0);">Board</a></li>
                            <li class="breadcrumb-item active">Traders Tables</li>
                        </ol>
                        <h4 class="page-title">Traders Plan</h4>
                    </div>
                    <!-- End page title box -->




                    <div class="row">
                        <div class="col-12">
                            <div class="card-box">
                                <a class='btn btn-primary btn-sm' href='add_new_trader.php'>New Trader</a>
                                <table id="datatable-buttons" class="table table-striped table-bordered dt-responsive nowrap">
                                    <thead>
                                    <tr>
                                        <th>Name</th>
                                        <th>Username</th>
                                        <th>Gain Percentage</th>
                                        <th>Risk Level</th>
                                        <th>Total Trades</th>
                                        <th>Traders Capital</th>
                                        <th>Avg Trade Time</th>
                                        <th>Number of Copiers</th>
                                        <th>Avatar</th>
                                        <th>Action</th>
                                    </tr>
                                    </thead>
                                    <tbody>
                    
                                    <?php  
                                    // Query to fetch trader data
                                    $query_traders = "SELECT * FROM traders";
                                    $result = mysqli_query($myConn, $query_traders);
                                    while ($row = mysqli_fetch_array($result, MYSQLI_BOTH)) {
                                        $id = $row["id"];
                                        $name = $row["name"];
                                        $username = $row["username"];
                                        $gain_percentage = $row["gain_percentage"];
                                        $risk_level = $row["risk_level"];
                                        $trades = $row["trades"];
                                        $Traders_capital = $row["investment_capital"];
                                        $avg_trade_time = $row["avg_trade_time"];
                                        $copiers = $row["copiers"];
                                        $avatar = $row["avatar"];
                                    ?>
                                        <tr>
                                            <td><?php echo $name; ?></td>
                                            <td><?php echo $username; ?></td>
                                            <td><?php echo $gain_percentage; ?>%</td>
                                            <td><?php echo $risk_level; ?></td>
                                            <td><?php echo $trades; ?></td>
                                            <td><?php echo $Traders_capital; ?> USD</td>
                                            <td><?php echo $avg_trade_time; ?> mins</td>
                                            <td><?php echo $copiers; ?></td>
                                            <td>
                                                <?php if ($avatar) { ?>
                                                    <img src="../app/assets/images/currency/<?php echo $avatar; ?>" alt="Avatar" width="50" height="50">
                                                <?php } else { ?>
                                                    <span>No Avatar</span>
                                                <?php } ?>
                                            </td>
                                            <td>
                                                <a class='btn btn-primary btn-sm' href='edit_trader.php?id=<?=$id?>'>Edit</a>
                                                <a class='btn btn-danger btn-sm' href='delete-trader.php?id=<?=$id?>'>Delete</a>
                                            </td>
                                        </tr>
                                    <?php } ?>
                    
                                    </tbody>
                                </table>
                            </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;
}?>