feat: improve getUserMemberStatus to check linked memberships at all failure points

Previously, linked membership checks only occurred if there was no membership
application record. Now linked memberships are checked as fallback at every
stage of the direct membership validation:

- No membership application  check linked
- Indemnity not accepted  check linked
- No membership fees record  check linked
- Direct membership not active/expired  check linked

This ensures linked members see themselves as active across all member areas,
detail pages, and booking forms (trips, courses, campsites, driver training,
bush mechanics, rescue & recovery).
This commit is contained in:
twotalesanimation
2025-12-05 11:40:38 +02:00
parent c5112e1ce9
commit e63bd806f0

View File

@@ -430,7 +430,7 @@ function getUserMemberStatus($user_id)
return false;
}
// Step 3: Check the membership_application table for accept_indemnity status
// Step 2: Check the membership_application table for accept_indemnity status
$queryApplication = "SELECT accept_indemnity FROM membership_application WHERE user_id = ?";
$stmtApplication = $conn->prepare($queryApplication);
if (!$stmtApplication) {
@@ -444,7 +444,7 @@ function getUserMemberStatus($user_id)
$stmtApplication->close();
if ($resultApplication->num_rows === 0) {
error_log("No membership application found for user_id: $user_id");
error_log("No membership application found for user_id: $user_id - checking if linked to another membership");
// Check if user is linked to another user's membership
$linkedStatus = getUserMembershipLink($user_id);
$conn->close();
@@ -456,11 +456,14 @@ function getUserMemberStatus($user_id)
// Validate accept_indemnity
if ($accept_indemnity !== 1) {
error_log("User has not accepted indemnity for user_id: $user_id");
return false;
error_log("User has not accepted indemnity for user_id: $user_id - checking if linked to another membership");
// User hasn't accepted indemnity directly, but check if they're linked to an active membership
$linkedStatus = getUserMembershipLink($user_id);
$conn->close();
return $linkedStatus['has_access'];
}
// Step 2: Check membership fees table for valid payment status and membership_end_date
// Step 3: Check membership fees table for valid payment status and membership_end_date
$queryFees = "SELECT payment_status, membership_end_date FROM membership_fees WHERE user_id = ?";
$stmtFees = $conn->prepare($queryFees);
if (!$stmtFees) {
@@ -474,8 +477,11 @@ function getUserMemberStatus($user_id)
$stmtFees->close();
if ($resultFees->num_rows === 0) {
error_log("Membership fees not found for user_id: $user_id");
return false;
error_log("Membership fees not found for user_id: $user_id - checking if linked to another membership");
// No direct membership fees, check if linked
$linkedStatus = getUserMembershipLink($user_id);
$conn->close();
return $linkedStatus['has_access'];
}
$fees = $resultFees->fetch_assoc();
@@ -488,15 +494,17 @@ function getUserMemberStatus($user_id)
if ($payment_status === "PAID" && $current_date <= $membership_end_date_obj) {
$conn->close();
return true; // Membership is active
return true; // Direct membership is active
} else {
// Direct membership is not active, check if user is linked to another active membership
error_log("Direct membership not active for user_id: $user_id - checking linked memberships");
$linkedStatus = getUserMembershipLink($user_id);
$conn->close();
return false;
return $linkedStatus['has_access'];
}
return false; // Membership is not active
}
function getUserMemberStatusPending($user_id)
{