small updates
This commit is contained in:
193
functions.php
193
functions.php
@@ -189,6 +189,83 @@ function sendInvoice($email, $name, $eft_id, $amount, $description)
|
||||
}
|
||||
}
|
||||
|
||||
function getEFTDetails($eft_id) {
|
||||
$conn = openDatabaseConnection();
|
||||
$stmt = $conn->prepare("SELECT amount, description FROM efts WHERE eft_id = ? LIMIT 1");
|
||||
$stmt->bind_param("s", $eft_id);
|
||||
$stmt->execute();
|
||||
$result = $stmt->get_result();
|
||||
|
||||
if ($row = $result->fetch_assoc()) {
|
||||
return [
|
||||
'amount' => $row['amount'],
|
||||
'description' => $row['description']
|
||||
];
|
||||
} else {
|
||||
return false; // EFT not found
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function sendPOP($fullname, $eft_id, $amount, $description)
|
||||
{
|
||||
global $mailjet;
|
||||
|
||||
$message = [
|
||||
'Messages' => [
|
||||
[
|
||||
'From' => [
|
||||
'Email' => "info@4wdcsa.co.za",
|
||||
'Name' => "4WDCSA Web Admin"
|
||||
],
|
||||
'To' => [
|
||||
[
|
||||
'Email' => 'chrispintoza@gmail.com',
|
||||
'Name' => 'Chris Pinto'
|
||||
],
|
||||
[
|
||||
'Email' => 'info@4wdcsa.co.za',
|
||||
'Name' => 'Jacqui Boshoff'
|
||||
],
|
||||
[
|
||||
'Email' => 'louiseb@global.co.za',
|
||||
'Name' => 'Louise Blignault'
|
||||
]
|
||||
],
|
||||
'TemplateID' => 7054062,
|
||||
'TemplateLanguage' => true,
|
||||
'Subject' => "4WDCSA - Proof of Payment Received",
|
||||
'Variables' => [
|
||||
'fullname' => $fullname,
|
||||
'eft_id' => $eft_id,
|
||||
'amount' => $amount,
|
||||
'description' => $description,
|
||||
]
|
||||
]
|
||||
]
|
||||
];
|
||||
|
||||
$client = new Client([
|
||||
// Base URI is used with relative requests
|
||||
'base_uri' => 'https://api.mailjet.com/v3.1/',
|
||||
]);
|
||||
|
||||
$response = $client->request('POST', 'send', [
|
||||
'json' => $message,
|
||||
'auth' => ['1a44f8d5e847537dbb8d3c76fe73a93c', 'ec98b45c53a7694c4f30d09eee9ad280']
|
||||
]);
|
||||
|
||||
if ($response->getStatusCode() == 200) {
|
||||
$body = $response->getBody();
|
||||
$response = json_decode($body);
|
||||
if ($response->Messages[0]->Status == 'success') {
|
||||
return True;
|
||||
} else {
|
||||
return False;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function sendEmail($email, $subject, $message)
|
||||
{
|
||||
global $mailjet;
|
||||
@@ -414,6 +491,91 @@ function getUserMemberStatus($user_id)
|
||||
return false; // Membership is not active
|
||||
}
|
||||
|
||||
function getUserMemberStatusPending($user_id)
|
||||
{
|
||||
|
||||
$conn = openDatabaseConnection();
|
||||
|
||||
// Step 1: Check if the user is a member
|
||||
$queryUser = "SELECT member FROM users WHERE user_id = ?";
|
||||
$stmtUser = $conn->prepare($queryUser);
|
||||
if (!$stmtUser) {
|
||||
error_log("Failed to prepare user query: " . $conn->error);
|
||||
return false;
|
||||
}
|
||||
|
||||
$stmtUser->bind_param('i', $user_id);
|
||||
$stmtUser->execute();
|
||||
$resultUser = $stmtUser->get_result();
|
||||
$stmtUser->close();
|
||||
|
||||
if ($resultUser->num_rows === 0) {
|
||||
error_log("User not found for user_id: $user_id");
|
||||
return false;
|
||||
}
|
||||
|
||||
// Step 3: 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) {
|
||||
error_log("Failed to prepare application query: " . $conn->error);
|
||||
return false;
|
||||
}
|
||||
|
||||
$stmtApplication->bind_param('i', $user_id);
|
||||
$stmtApplication->execute();
|
||||
$resultApplication = $stmtApplication->get_result();
|
||||
$stmtApplication->close();
|
||||
|
||||
if ($resultApplication->num_rows === 0) {
|
||||
error_log("No membership application found for user_id: $user_id");
|
||||
return false;
|
||||
}
|
||||
|
||||
$application = $resultApplication->fetch_assoc();
|
||||
$accept_indemnity = $application['accept_indemnity'];
|
||||
|
||||
// Validate accept_indemnity
|
||||
if ($accept_indemnity !== 1) {
|
||||
error_log("User has not accepted indemnity for user_id: $user_id");
|
||||
return false;
|
||||
}
|
||||
|
||||
// Step 2: 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) {
|
||||
error_log("Failed to prepare fees query: " . $conn->error);
|
||||
return false;
|
||||
}
|
||||
|
||||
$stmtFees->bind_param('i', $user_id);
|
||||
$stmtFees->execute();
|
||||
$resultFees = $stmtFees->get_result();
|
||||
$stmtFees->close();
|
||||
|
||||
if ($resultFees->num_rows === 0) {
|
||||
error_log("Membership fees not found for user_id: $user_id");
|
||||
return false;
|
||||
}
|
||||
|
||||
$fees = $resultFees->fetch_assoc();
|
||||
$payment_status = $fees['payment_status'];
|
||||
$membership_end_date = $fees['membership_end_date'];
|
||||
|
||||
// Validate payment status and membership_end_date
|
||||
$current_date = new DateTime();
|
||||
$membership_end_date_obj = DateTime::createFromFormat('Y-m-d', $membership_end_date);
|
||||
|
||||
if ($payment_status === "AWAITING PAYMENT" && $current_date <= $membership_end_date_obj) {
|
||||
return true; // Membership is pending
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
return false; // Membership is not pending
|
||||
}
|
||||
|
||||
function checkUserSession()
|
||||
{
|
||||
|
||||
@@ -961,19 +1123,21 @@ function checkSuperAdmin()
|
||||
|
||||
function calculateProrata($prorata)
|
||||
{
|
||||
// Get the current month as a number (1 = January, 12 = December)
|
||||
// Get current month number (1 = January, 12 = December)
|
||||
$currentMonth = date('n');
|
||||
|
||||
// Total months in a year
|
||||
// Shift months so March becomes month 1 in the cycle
|
||||
// (March=1, April=2, ..., February=12)
|
||||
$shiftedMonth = ($currentMonth - 3 + 12) % 12 + 1;
|
||||
|
||||
// Total months in a "March to February" year
|
||||
$totalMonths = 12;
|
||||
|
||||
// Calculate the remaining months including the current month
|
||||
$remainingMonths = $totalMonths - $currentMonth + 1;
|
||||
// Calculate remaining months including the current month
|
||||
$remainingMonths = $totalMonths - $shiftedMonth + 1;
|
||||
|
||||
// Multiply by prorata value
|
||||
$prorataAmount = $remainingMonths * $prorata;
|
||||
|
||||
return $prorataAmount;
|
||||
return $remainingMonths * $prorata;
|
||||
}
|
||||
|
||||
function getFullName($user_id)
|
||||
@@ -1798,3 +1962,18 @@ function getCommentCount($page_id) {
|
||||
|
||||
return $count;
|
||||
}
|
||||
|
||||
function hasPhoneNumber($user_id) {
|
||||
|
||||
$conn = openDatabaseConnection();
|
||||
// Prepare SQL
|
||||
$stmt = $conn->prepare("SELECT phone_number FROM users WHERE id = ? LIMIT 1");
|
||||
$stmt->bind_param("i", $user_id);
|
||||
$stmt->execute();
|
||||
$stmt->bind_result($phone_number);
|
||||
$stmt->fetch();
|
||||
$stmt->close();
|
||||
|
||||
// Return true only if a phone number exists and is not empty
|
||||
return !empty($phone_number);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user