File: /home/bigisxfd/public_html/cowork/vouchers.php
<?php
// Include necessary files
include_once("header.php");
include_once("sidebar.php");
include_once("functions.php");
// Fetch all members
$members = getExistingMembers();
// Initialize $memberVouchers as an empty array
$memberVouchers = array();
// Handle form submission
if ($_SERVER["REQUEST_METHOD"] == "POST") {
if (isset($_POST["memberId"])) {
$selectedMemberId = $_POST["memberId"];
// Fetch vouchers for the selected member
$memberVouchers = getMemberVouchers($selectedMemberId);
}
}
?>
<section>
<div class="column">
<div style="display: flex; align-items: center; justify-content: space-between;">
<h2>View Vouchers</h2>
<button class="add-button" onclick="location.href='buyvoucher.php'">Buy Vouchers</button>
</div>
<form method="post" action="vouchers.php">
<label for="member">Select Member:</label>
<select name="memberId" id="member">
<option value="" disabled selected>Select Member</option>
<?php foreach ($members as $member) : ?>
<option value="<?php echo $member['memberid']; ?>"><?php echo $member['firstname'] . ' ' . $member['lastname']; ?></option>
<?php endforeach; ?>
</select>
<button type="submit">Show Vouchers</button>
</form>
<?php if (!empty($memberVouchers)) : ?>
<table>
<thead>
<tr>
<th>Voucher Code</th>
<th>Package Name</th>
<th>Date</th>
<th>Used By</th>
</tr>
</thead>
<tbody>
<?php foreach ($memberVouchers as $voucher) : ?>
<tr <?php echo ($voucher['usedby'] == 0) ? 'style="background-color: lightgreen;"' : 'style="background-color: lightcoral;"'; ?>>
<td><?php echo $voucher['code']; ?></td>
<td><?php echo $voucher['packagename']; ?></td>
<td><?php echo $voucher['date']; ?></td>
<td><?php echo ($voucher['usedby'] == 0) ? 'Unused' : getMemberName($voucher['usedby']); ?></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<?php endif; ?>
</div>
</section>
</body>
</html>