diff --git a/src/config/functions.php b/src/config/functions.php index 679ebc99..81f8cf3b 100644 --- a/src/config/functions.php +++ b/src/config/functions.php @@ -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) {