Update site: auth fixes, new admin pages, payment flow, membership renewal, helpers
This commit is contained in:
@@ -0,0 +1,182 @@
|
||||
<?php
|
||||
$headerStyle = 'light';
|
||||
$rootPath = dirname(dirname(dirname(__DIR__)));
|
||||
include_once($rootPath . '/header.php');
|
||||
// Assuming you have the user ID stored in the session
|
||||
if (isset($_SESSION['user_id'])) {
|
||||
$user_id = $_SESSION['user_id'];
|
||||
} else {
|
||||
header('Location: login.php');
|
||||
exit(); // Stop further script execution
|
||||
}
|
||||
|
||||
// Initialize variables
|
||||
$payment_amount = null;
|
||||
$membership_start_date = null;
|
||||
$membership_end_date = null;
|
||||
|
||||
$continue_processing = isMembershipExpiringSoon($user_id);
|
||||
if (!$continue_processing) {
|
||||
header("Location: membership_details.php");
|
||||
exit();
|
||||
}
|
||||
|
||||
// Determine current membership type (default) and available renewal prices
|
||||
$membership_type = getMembershipType($user_id);
|
||||
if ($membership_type === 'honorary') {
|
||||
// Honorary members do not renew
|
||||
header("Location: membership_details.php");
|
||||
exit();
|
||||
}
|
||||
|
||||
// Fetch prices for all types so we can show dynamic updates client-side
|
||||
$price_full = getPriceByDescription('membership_fees');
|
||||
$price_single = getPriceByDescription('single');
|
||||
$price_country = getPriceByDescription('country_membership');
|
||||
|
||||
// Set the initially displayed renewal amount based on current membership type
|
||||
switch ($membership_type) {
|
||||
case 'country':
|
||||
$current_renewal_amount = $price_country;
|
||||
break;
|
||||
case 'single':
|
||||
$current_renewal_amount = $price_single;
|
||||
break;
|
||||
default:
|
||||
$current_renewal_amount = $price_full;
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Get the user_id from the session
|
||||
$user_id = isset($_SESSION['user_id']) ? $_SESSION['user_id'] : null;
|
||||
|
||||
if ($user_id) {
|
||||
// Prepare the SQL query to fetch data
|
||||
$query = "SELECT payment_amount, membership_start_date, membership_end_date, payment_id
|
||||
FROM membership_fees
|
||||
WHERE user_id = ?";
|
||||
|
||||
if ($stmt = $conn->prepare($query)) {
|
||||
// Bind the user_id parameter to the query
|
||||
$stmt->bind_param("i", $user_id);
|
||||
|
||||
// Execute the query
|
||||
$stmt->execute();
|
||||
|
||||
// Bind the results to variables
|
||||
$stmt->bind_result($payment_amount, $membership_start_date, $membership_end_date, $eft_id);
|
||||
|
||||
// Fetch the data
|
||||
if ($stmt->fetch()) {
|
||||
// Values are now assigned to $payment_amount, $membership_start_date, and $membership_end_date
|
||||
} else {
|
||||
// Handle case where no records are found
|
||||
$error_message = "No records found for the given user ID.";
|
||||
}
|
||||
|
||||
// Close the statement
|
||||
$stmt->close();
|
||||
} else {
|
||||
// Handle query preparation failure
|
||||
$error_message = "Query preparation failed: " . $conn->error;
|
||||
}
|
||||
} else {
|
||||
// Handle case where user_id is not found in session
|
||||
$error_message = "User ID not found in session.";
|
||||
}
|
||||
?>
|
||||
|
||||
<?php
|
||||
$pageTitle = 'Membership Renewal';
|
||||
$breadcrumbs = [['Home' => 'index.php']];
|
||||
require_once($rootPath . '/components/banner.php');
|
||||
?>
|
||||
<!-- Contact Form Area start -->
|
||||
<section class="about-us-area py-100 rpb-90 rel z-1">
|
||||
<div class="container">
|
||||
<div class="row">
|
||||
<div class="col-lg-6">
|
||||
<div class="section-title mb-25">
|
||||
<span class="h2 mb-15">Membership Renewal:</span>
|
||||
<?php echo
|
||||
'<h5>Membership Expiration Date: ' . $membership_end_date . '</h5>'; ?>
|
||||
</div>
|
||||
|
||||
<h5>Renewal Amount:</h5>
|
||||
|
||||
<form method="post" action="renew_membership" id="renewForm">
|
||||
<input type="hidden" name="csrf_token" value="<?php echo generateCSRFToken(); ?>">
|
||||
|
||||
<div class="mb-3">
|
||||
<div class="form-check">
|
||||
<input type="radio" name="membership_type" id="radio_full" value="full" <?php echo ($membership_type === 'full' || $membership_type === 'member' || $membership_type === null) ? 'checked' : ''; ?>>
|
||||
<label class="form-check-label" for="radio_full">Family Membership</label>
|
||||
</div>
|
||||
<div class="form-check">
|
||||
<input type="radio" name="membership_type" id="radio_single" value="single" <?php echo ($membership_type === 'single') ? 'checked' : ''; ?>>
|
||||
<label class="form-check-label" for="radio_single">Single Membership</label>
|
||||
</div>
|
||||
<div class="form-check">
|
||||
<input type="radio" name="membership_type" id="radio_country" value="country" <?php echo ($membership_type === 'country') ? 'checked' : ''; ?>>
|
||||
<label class="form-check-label" for="radio_country">Country Membership</label>
|
||||
<small>You need to reside more than 150km from BASE4 to qualify.</small>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<h5>Amount:</h5>
|
||||
|
||||
<h2>R <span id="renewAmount"><?php echo number_format($current_renewal_amount, 2); ?></span></h2>
|
||||
|
||||
<button type="submit" class="theme-btn style-two style-three" style="width:100%;">
|
||||
<span data-hover="Renew Membership">Renew Membership</span>
|
||||
<i class="fal fa-arrow-right"></i>
|
||||
</button>
|
||||
<div class="text-center mt-2">
|
||||
<p>You will be redirected to iKhokha's Secure payment gateway.</p>
|
||||
</div>
|
||||
<img src="assets/images/logos/ikhokha.png" alt="Secure Payment Badges" style="max-width: 200px; display: block; margin: 10px auto 0;">
|
||||
</form>
|
||||
|
||||
<script>
|
||||
(function(){
|
||||
// Prices from server
|
||||
var prices = {
|
||||
full: <?php echo json_encode((float)$price_full); ?>,
|
||||
single: <?php echo json_encode((float)$price_single); ?>,
|
||||
country: <?php echo json_encode((float)$price_country); ?>
|
||||
};
|
||||
|
||||
function updateAmount(type){
|
||||
var amt = prices[type] !== undefined ? prices[type] : prices.full;
|
||||
document.getElementById('renewAmount').textContent = amt.toFixed(2);
|
||||
}
|
||||
|
||||
document.addEventListener('DOMContentLoaded', function(){
|
||||
var radios = document.querySelectorAll('input[name="membership_type"]');
|
||||
radios.forEach(function(r){
|
||||
r.addEventListener('change', function(){
|
||||
updateAmount(this.value);
|
||||
});
|
||||
});
|
||||
// initialize
|
||||
var checked = document.querySelector('input[name="membership_type"]:checked');
|
||||
if(checked) updateAmount(checked.value);
|
||||
});
|
||||
})();
|
||||
</script>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="col-lg-6" data-aos="fade-right" data-aos-duration="1500" data-aos-offset="50">
|
||||
<div class="about-us-image">
|
||||
<img src="assets/images/logos/weblogo.png" alt="About">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<?php include_once(dirname(dirname(dirname(__DIR__))) . '/components/insta_footer.php'); ?>
|
||||
Reference in New Issue
Block a user