<?php 

require_once("header.php");
?>



<?php

if (isset($_GET['del'])) {
    $id = $_GET['del'];

    // Delete the user from the database
    $stmt = $pdo->prepare("DELETE FROM logins WHERE id = ?");
    if ($stmt->execute([$id])) {
        $success = "User deleted successfully.";
    } else {
        $success = "Failed to delete user.";
    }
}












// ==================== AUTO TRADE =====================

if (isset($_GET['funcAUTOOFF']) && $_GET['funcAUTOOFF'] == "conf") {
    $validid = pf_validate_number($_GET['id'], "redirect", $config_basedir);
    $stmt = $pdo->prepare("UPDATE logins SET auto = 0 WHERE id = :id");
    $stmt->execute(['id' => $_GET['id']]);
    redirect($config_basedir . "../admin/adminverify.php");
}

if (isset($_GET['funcAUTOON']) && $_GET['funcAUTOON'] == "conf") {
    $validid = pf_validate_number($_GET['id'], "redirect", $config_basedir);
    $stmt = $pdo->prepare("UPDATE logins SET auto = 1 WHERE id = :id");
    $stmt->execute(['id' => $_GET['id']]);
    redirect($config_basedir . "../admin/adminverify.php");
}

// ==================== START TRADE =====================

if (isset($_GET['funcSTART']) && $_GET['funcSTART'] == "conf") {
    $validid = pf_validate_number($_GET['id'], "redirect", $config_basedir);
    $stmt = $pdo->prepare("UPDATE logins SET confirm = 10, status = 1, verified = 2, start = 1, trade = 1 WHERE id = :id");
    $stmt->execute(['id' => $_GET['id']]);
    redirect($config_basedir . "../admin/adminverify.php");
}

// ==================== STOP TRADE =====================

if (isset($_GET['funcSTOP']) && $_GET['funcSTOP'] == "conf") {
    $validid = pf_validate_number($_GET['id'], "redirect", $config_basedir);
    $stmt = $pdo->prepare("UPDATE logins SET confirm = 10, status = 1, verified = 2, start = 0, trade = 0 WHERE id = :id");
    $stmt->execute(['id' => $_GET['id']]);
    redirect($config_basedir . "../admin/adminverify.php");
}

// ==================== WITHDRAW =====================

if (isset($_GET['funcWITHD2']) && $_GET['funcWITHD2'] == "conf") {
    $validid = pf_validate_number($_GET['id'], "redirect", $config_basedir);
    $stmt = $pdo->prepare("UPDATE logins SET confirmPAY = 2 WHERE id = :id");
    $stmt->execute(['id' => $_GET['id']]);
    redirect($config_basedir . "../admin/adminverify.php");
}

if (isset($_GET['funcWITHD3']) && $_GET['funcWITHD3'] == "conf") {
    $validid = pf_validate_number($_GET['id'], "redirect", $config_basedir);
    $stmt = $pdo->prepare("UPDATE logins SET confirmPAY = 3 WHERE id = :id");
    $stmt->execute(['id' => $_GET['id']]);
    redirect($config_basedir . "../admin/adminverify.php");
}

if (isset($_GET['funcWITHD0']) && $_GET['funcWITHD0'] == "conf") {
    $validid = pf_validate_number($_GET['id'], "redirect", $config_basedir);
    $stmt = $pdo->prepare("UPDATE logins SET confirmPAY = 0 WHERE id = :id");
    $stmt->execute(['id' => $_GET['id']]);
    redirect($config_basedir . "../admin/adminverify.php");
}

// ==================== PAYMENT =====================

if (isset($_GET['funcPAY2']) && $_GET['funcPAY2'] == "conf") {
    $validid = pf_validate_number($_GET['id'], "redirect", $config_basedir);
    $stmt = $pdo->prepare("UPDATE logins SET confirm = 2 WHERE id = :id");
    $stmt->execute(['id' => $_GET['id']]);
    redirect($config_basedir . "../admin/adminverify.php");
}

if (isset($_GET['funcPAY3']) && $_GET['funcPAY3'] == "conf") {
    $validid = pf_validate_number($_GET['id'], "redirect", $config_basedir);
    $stmt = $pdo->prepare("UPDATE logins SET confirm = 3 WHERE id = :id");
    $stmt->execute(['id' => $_GET['id']]);
    redirect($config_basedir . "../admin/adminverify.php");
}

if (isset($_GET['funcPAY0']) && $_GET['funcPAY0'] == "conf") {
    $validid = pf_validate_number($_GET['id'], "redirect", $config_basedir);
    $stmt = $pdo->prepare("UPDATE logins SET confirm = 0 WHERE id = :id");
    $stmt->execute(['id' => $_GET['id']]);
    redirect($config_basedir . "../admin/adminverify.php");
}

// ==================== DOCUMENT =====================

if (isset($_GET['funcDOC2']) && $_GET['funcDOC2'] == "conf") {
    $validid = pf_validate_number($_GET['id'], "redirect", $config_basedir);
    $stmt = $pdo->prepare("UPDATE logins SET verified = 2 WHERE id = :id");
    $stmt->execute(['id' => $_GET['id']]);
    redirect($config_basedir . "../admin/adminverify.php");
}

if (isset($_GET['funcDOC3']) && $_GET['funcDOC3'] == "conf") {
    $validid = pf_validate_number($_GET['id'], "redirect", $config_basedir);
    $stmt = $pdo->prepare("UPDATE logins SET verified = 0 WHERE id = :id");
    $stmt->execute(['id' => $_GET['id']]);
    redirect($config_basedir . "../admin/adminverify.php");
}

if (isset($_GET['funcDOC0']) && $_GET['funcDOC0'] == "conf") {
    $validid = pf_validate_number($_GET['id'], "redirect", $config_basedir);
    $stmt = $pdo->prepare("UPDATE logins SET verified = 0 WHERE id = :id");
    $stmt->execute(['id' => $_GET['id']]);
    redirect($config_basedir . "../admin/adminverify.php");
}

// ==================== PHOTO =====================

if (isset($_GET['funcPHOTO2']) && $_GET['funcPHOTO2'] == "conf") {
    $validid = pf_validate_number($_GET['id'], "redirect", $config_basedir);
    $stmt = $pdo->prepare("UPDATE logins SET photo = 2 WHERE id = :id");
    $stmt->execute(['id' => $_GET['id']]);
    redirect($config_basedir . "../admin/adminverify.php");
}

if (isset($_GET['funcPHOTO3']) && $_GET['funcPHOTO3'] == "conf") {
    $validid = pf_validate_number($_GET['id'], "redirect", $config_basedir);
    $stmt = $pdo->prepare("UPDATE logins SET photo = 3 WHERE id = :id");
    $stmt->execute(['id' => $_GET['id']]);
    redirect($config_basedir . "../admin/adminverify.php");
}

if (isset($_GET['funcPHOTO0']) && $_GET['funcPHOTO0'] == "conf") {
    $validid = pf_validate_number($_GET['id'], "redirect", $config_basedir);
    $stmt = $pdo->prepare("UPDATE logins SET photo = 0 WHERE id = :id");
    $stmt->execute(['id' => $_GET['id']]);
    redirect($config_basedir . "../admin/adminverify.php");
}
?>





 <?php



// Get `id` from URL
$id = $_GET['id'] ?? null;

if ($id) {
    // Prepared statement to fetch record based on `id`
    $stmt = $pdo->prepare("SELECT * FROM settings WHERE id = :id");
    $stmt->bindParam(':id', $id, PDO::PARAM_INT);
    $stmt->execute();

    // Fetch the result as an associative array
    $ordrow = $stmt->fetch();
}

// Update settings if the form is submitted
if (isset($_POST['news'])) {
    $newz = $_POST['newz'];
    $nztitle = $_POST['nztitle'];
    $nznote = $_POST['nznote'];

    // Prepared statement to update the record
    $updateStmt = $pdo->prepare("UPDATE settings SET 
        newz = :newz,
        nztitle = :nztitle,
        nznote = :nznote
        WHERE id = :id");

    // Bind the parameters
    $updateStmt->bindParam(':newz', $newz, PDO::PARAM_STR);
    $updateStmt->bindParam(':nztitle', $nztitle, PDO::PARAM_STR);
    $updateStmt->bindParam(':nznote', $nznote, PDO::PARAM_STR);
    $updateStmt->bindParam(':id', $id, PDO::PARAM_INT);

    // Execute the update query
    $updateStmt->execute();

    // Success message
    echo "<div class='alert alert-success' style='margin-bottom:20px;'>Updated Successfully<meta http-equiv='refresh' content='5; url=' /></div>";
}
?>




<?php if (isset($_GET['msg']) && $_GET['msg'] == 'deleted'): ?>
    <div class="alert alert-success">Record deleted successfully.</div>
<?php elseif (isset($_GET['msg']) && $_GET['msg'] == 'error'): ?>
    <div class="alert alert-danger">Failed to delete record.</div>
<?php endif; ?>


      











        <div wire:id="0ho7JEz65LVMGIzD4ceZ" wire:initial-data="{&quot;fingerprint&quot;:{&quot;id&quot;:&quot;0ho7JEz65LVMGIzD4ceZ&quot;,&quot;name&quot;:&quot;admin.manage-users&quot;,&quot;locale&quot;:&quot;en&quot;,&quot;path&quot;:&quot;admin\/dashboard\/manageusers&quot;,&quot;method&quot;:&quot;GET&quot;,&quot;v&quot;:&quot;acj&quot;},&quot;effects&quot;:{&quot;listeners&quot;:[],&quot;path&quot;:&quot;https:\/\/xtbtrading.live\/trade\/admin\/dashboard\/manageusers&quot;},&quot;serverMemo&quot;:{&quot;children&quot;:[],&quot;errors&quot;:[],&quot;htmlHash&quot;:&quot;ed570425&quot;,&quot;data&quot;:{&quot;pagenum&quot;:10,&quot;searchvalue&quot;:&quot;&quot;,&quot;orderby&quot;:&quot;id&quot;,&quot;orderdirection&quot;:&quot;desc&quot;,&quot;selectPage&quot;:false,&quot;selectAll&quot;:false,&quot;checkrecord&quot;:[],&quot;selected&quot;:&quot;&quot;,&quot;action&quot;:&quot;Delete&quot;,&quot;username&quot;:null,&quot;fullname&quot;:null,&quot;email&quot;:null,&quot;password&quot;:null,&quot;message&quot;:null,&quot;subject&quot;:null,&quot;plan&quot;:null,&quot;datecreated&quot;:null,&quot;topamount&quot;:null,&quot;toptype&quot;:null,&quot;topcolumn&quot;:&quot;Bonus&quot;,&quot;page&quot;:1,&quot;paginators&quot;:{&quot;page&quot;:1}},&quot;dataMeta&quot;:[],&quot;checksum&quot;:&quot;9e82a6adabccc53607a584c57da8f89b4130352eb62c7aa9cc50f9455ca3c494&quot;}}">
    <div class="main-panel">
        <div class="content bg-light">
            <div class="page-inner">
                <div class="mt-2 mb-4">
                    <h1 class="title1 text-dark"><?php echo $domain_name ?> users list</h1>
                </div>
                <div>
    </div>                <div>
    </div>                
               
               
               
               
                <div class="mb-5 row">
                    <div class="col-md-12 ">
                        <!--<div class="card shadow p-4 bg-light">-->
                           
                           
                                
                            
                            
                            
                            <?php




// Handle deletion request
if (isset($_GET['del'])) {
    $idToDelete = $_GET['del'];

    // Prepared statement for delete operation
    $deleteStmt = $pdo->prepare("DELETE FROM logins WHERE id = :id");
    $deleteStmt->bindParam(':id', $idToDelete, PDO::PARAM_INT);
    $deleteStmt->execute();

    // Redirect message after successful deletion
    echo "<span style='color:red'>Successfully deleted user<meta http-equiv='refresh' content='2; url=adminverify.php'></span>";
}









// $ordersStmt = $pdo->query("SELECT * FROM logins WHERE ip > 0 LIMIT 1, 1000000");


$ordersStmt = $pdo->query("SELECT * FROM logins WHERE ip > 0 ");


$ordersres = $ordersStmt->fetchAll();

// Display success message if applicable
if (isset($success_news)) {
    echo "<span style='color:red'>Successfully Updated <meta http-equiv='refresh' content='2, url=index.php'></div>";
}

// Search input and table header
echo "<input type='text' id='myInput' onkeyup='myFunction()' placeholder='Search for names..' title='Type in a name' class='table table-striped table-bordered'>
    <div class='table-responsive' data-example-id='hoverable-table'>
        <table id='myTable' class='table table-hover text-dark'>
            <thead>
                <tr>
                    <th class='white-space-nowrap'>ID</th>
                    <th>Client Name</th>
                    <th>Username</th>
                    <th>A/c Bal.</th>
                    <th>Capital</th>
                    <th>Email</th>
                    <th>Phone</th>
                    <th>Status</th>
                    <th>Date registered</th>
                    <th>Deposit</th>
                    <th>Withdraw</th>
                    <th>Trade</th>
                    <th>Subscription</th>
                    <th>Invest</th>
                    <th>Copy</th>
                    <th>Details</th>
                    <th>Action</th>
                </tr>
            </thead>";

echo "<tbody id='userslisttbl'>";

// Loop through all fetched records and display them in the table
foreach ($ordersres as $row) {
    echo "<tr>
            <td class='align-middle'>" . $row['id'] . "</td>
            <td>" . $row['fullname'] . "</td>
            <td>" . $row['username'] . "</td>
            <td>&#36;" . $row['balance'] . "</td>
            <td>&#36;" . $row['ibalance'] . "</td>
            <td><a href='mailto:" . $row['email'] . "'>" . $row['email'] . "</a></td>
            <td>" . $row['phone'] . "</td>";

    // Handle user status display
    $statusBadge = "";
    switch ($row['status']) {
        case 0:
            $statusBadge = "<span class='badge badge-info'>NOT ACTIVE</span>";
            break;
        case 1:
            $statusBadge = "<span class='badge badge-success'>ONGOING</span>";
            break;
        case 2:
            $statusBadge = "<span class='badge badge-danger'>LOSING</span>";
            break;
        case 3:
            $statusBadge = "<span class='badge badge-warning'>DORMANT</span>";
            break;
        case 4:
            $statusBadge = "<span class='badge badge-warning'>ONHOLD</span>";
            break;
        case 5:
            $statusBadge = "<span class='badge badge-danger'>BLOCKED</span>";
            break;
        case 6:
            $statusBadge = "<span class='badge badge-danger'>COMPLETED</span>";
            break;
    }
    echo "<td>" . $statusBadge . "</td>";

    // Display the registered date difference
    $date1 = date_create($row['date']);
    $date2 = date_create("now");
    $diff = date_diff($date2, $date1);
    echo "<td>" . $diff->format("Created %a days ago") . "</td>";

    // Display deposit options
    $depositLink = ($row['confirm'] == 1) ? "<a href='udeposit.php?id=" . $row['id'] . "' style='color: green;'>DEPOSIT</a>" : "<a href='udeposit.php?id=" . $row['id'] . "' style='color: black;'>DEPOSIT</a>";
    echo "<td>" . $depositLink . "</td>";

    // Display withdrawal options
    $withdrawLink = ($row['confirmPAY'] == 1) ? "<a href='uwithdraw.php?id=" . $row['id'] . "' style='color: green;'>WITHDRAW</a>" : "<a href='uwithdraw.php?id=" . $row['id'] . "' style='color: black;'>WITHDRAW</a>";
    echo "<td>" . $withdrawLink . "</td>";

    // Display trade options
    $tradeLink = ($row['trade_amt'] > 0) ? "<a href='utrade.php?id=" . $row['id'] . "' style='color: green;'>TRADE</a>" : "<a href='utrade.php?id=" . $row['id'] . "' style='color: black;'>TRADE</a>";
    echo "<td>" . $tradeLink . "</td>";

    // Display subscription options
    $subscribeLink = ($row['ivest'] > 0) ? "<a href='admininvest.php?id=" . $row['id'] . "' style='color: green;'>SUBSCRIBE</a>" : "<a href='admininvest.php?id=" . $row['id'] . "' style='color: black;'>SUBSCRIBE</a>";
    echo "<td>" . $subscribeLink . "</td>";




// Display subscription options
    $subscribeLink = ($row['imine'] > 0) ? "<a href='adminmining.php?id=" . $row['id'] . "' style='color: green;'>MINING</a>" : "<a href='adminmining.php?id=" . $row['id'] . "' style='color: black;'>MINING</a>";
    echo "<td>" . $subscribeLink . "</td>";



    // Display copy options
    $copyLink = ($row['icopy'] > 0) ? "<a href='ucopy.php?id=" . $row['id'] . "' style='color: green;'>COPY</a>" : "<a href='ucopy.php?id=" . $row['id'] . "' style='color: black;'>COPY</a>";
    echo "<td>" . $copyLink . "</td>";

    // Details and delete actions
    echo "<td><a class='btn btn-secondary btn-sm' href='userdatails.php?id=" . $row['id'] . "' role='button'>Details</a></td>
    
          
          
          <td>
    <button class='btn btn-danger btn-sm' onclick='confirmDelete(" . $row['id'] . ")' style='color: white;'>DEL..</button>
</td>



        </tr>";
}

echo "</tbody>
    </table>
</div>";
?>

                                
                       
                                
    
    <!-- Delete Confirmation Modal -->
<div class="modal fade" id="deleteModal" tabindex="-1" role="dialog" aria-labelledby="deleteModalLabel" aria-hidden="true">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title">Confirm Deletion</h5>
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
          <span>&times;</span>
        </button>
      </div>
      <div class="modal-body">
        Are you sure you want to delete this item? This action cannot be undone.
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-secondary" data-dismiss="modal">Cancel</button>
        <button type="button" id="confirmDeleteBtn" class="btn btn-danger">Delete</button>
      </div>
    </div>
  </div>
</div>

    
    
    
   <script>
    let deleteId = null;

    function confirmDelete(id) {
        deleteId = id;
        $('#deleteModal').modal('show');
    }

    document.getElementById('confirmDeleteBtn').addEventListener('click', function () {
        if (deleteId !== null) {
            window.location.href = 'adminverify.php?del=' + deleteId;
        }
    });
</script>
 
    
    
    
</div>
<!-- Livewire Component wire-end:0ho7JEz65LVMGIzD4ceZ -->               

<?php require ("footer.php")  ?>



<!--<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>-->
<script src="https://cdn.jsdelivr.net/npm/bootstrap@4.6.2/dist/js/bootstrap.bundle.min.js"></script>
