<?php include 'header-link.php'; ?>

<?php
 
// Retrieve data
$sql = "SELECT manual_add_money.id, student.username, student.number, manual_add_money.bank_name,manual_add_money.trans_id,
manual_add_money.taka,manual_add_money.docs,manual_add_money.status FROM manual_add_money 
left join student on manual_add_money.userid = student.userid
ORDER BY FIELD(manual_add_money.status, 'Pending', 'Accepted', 'Rejected') ASC";
$result = $con->query($sql);
$sl=0;

if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['delete_id'])) {
$delete_id = $_POST['delete_id'];
$delete_sql = "DELETE FROM manual_add_money WHERE id = ?";
$stmt = $con->prepare($delete_sql);
$stmt->bind_param("i", $delete_id);
$stmt->execute();
header("Location: add-bal-manual.php"); 
exit();
}
?>


<main>
    <section>
        <div class="container mt-2 pb-5">
            <div class="row justify-content-center">
                <div class="col-md-6">
                    <div class="card custom-card">
                        <div class="card-body">
                            <div class="text-center">
                                <i class="profile-icon fa-solid fa-wallet"></i>
                            </div>

                            <h6 class="card-title text-center my-3"> Manual Balance Request (<?php echo $addBalMan; ?>) </h6>
                           
                            

                            <input type="text" class="form-control mb-4" id="searchInput" placeholder="Search User..." onkeyup="filterOffers()">


                            <div class="offer-list" id="offerList">
                                <?php if ($result->num_rows > 0): ?>
                                <?php while($row = $result->fetch_assoc()): ?>
                                    <div class="offer-card mb-5 p-3" data-sim="<?php echo $offer['offer_sim']; ?>">
                                        <div class="row">
                                            <div class="col">
                                                <small class="fw-bold">A/C Name: <?php echo $row['username']; ?></small><br>
                                                <small>A/C Contact: <?php echo $row['number']; ?></small><br>
                                                <small> Status : <?php echo $row['status']; ?></small>
                                            </div>
                                            <div class="col text-end">
                                                <small class="fw-bold">Bank: <?php echo $row['bank_name']; ?> </small><br>
                                                <small>Trans Id: <?php echo $row['trans_id']; ?> </small><br>
                                               
                                                <small class="fw-bold"> Amount : <?php echo $row['taka']; ?></small><br>
                                                <small> Docs: <?php
																	// Ensure the path is relative to your web root
																	$filePath = '../'.$row['docs']; // This is the path stored in the database
																	if (file_exists($filePath)) {
																		// Display the document as a link
																		echo '<a href="' . htmlspecialchars($filePath) . '">View Docs</a>';
																	} else {
																		echo 'Document not found';
																	}
																	?></small>
                                            </div>
                                        </div>
                                        <div class="d-grid text-center">
                                        <a class="btn custom-button mx-3" href="edit-bal-manual.php?id=<?php echo $row['id']; ?>"> <i
                                        class="font fa-solid fa-eye"></i> View </a>  
                                        </div>
                                    </div>
                                <?php endwhile; ?>
                                <?php else: ?>
									<small>No records found.</small>
									<?php endif; ?>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </section>
</main>
<script>
function filterOffers() {
    const searchInput = document.getElementById('searchInput').value.toLowerCase();
    const offerCards = document.querySelectorAll('.offer-card');

    offerCards.forEach(card => {
        const cardText = card.textContent.toLowerCase();
        
        if (cardText.includes(searchInput)) {
            card.style.display = ''; // Show the card
        } else {
            card.style.display = 'none'; // Hide the card
        }
    });
}
</script>


</body>
</html>
