Pop submit ready
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -2,3 +2,4 @@
|
|||||||
/vendor/
|
/vendor/
|
||||||
.htaccess
|
.htaccess
|
||||||
|
|
||||||
|
/uploads/pop/
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
php_flag display_errors On
|
php_flag display_errors On
|
||||||
# php_value error_reporting -1
|
php_value error_reporting -1
|
||||||
RedirectMatch 403 ^/\.well-known
|
RedirectMatch 403 ^/\.well-known
|
||||||
Options -Indexes
|
Options -Indexes
|
||||||
|
|
||||||
|
|||||||
@@ -235,7 +235,7 @@ function sendAdminNotification($subject, $message)
|
|||||||
{
|
{
|
||||||
global $mailjet;
|
global $mailjet;
|
||||||
|
|
||||||
$message = [
|
$mail = [
|
||||||
'Messages' => [
|
'Messages' => [
|
||||||
[
|
[
|
||||||
'From' => [
|
'From' => [
|
||||||
@@ -244,7 +244,7 @@ function sendAdminNotification($subject, $message)
|
|||||||
],
|
],
|
||||||
'To' => [
|
'To' => [
|
||||||
[
|
[
|
||||||
'Email' => "info@4wdcsa.co.za",
|
'Email' => $_ENV['NOTIFICATION_ADDR'],
|
||||||
'Name' => 'Jacqui Boshoff'
|
'Name' => 'Jacqui Boshoff'
|
||||||
]
|
]
|
||||||
],
|
],
|
||||||
@@ -264,7 +264,7 @@ function sendAdminNotification($subject, $message)
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
$response = $client->request('POST', 'send', [
|
$response = $client->request('POST', 'send', [
|
||||||
'json' => $message,
|
'json' => $mail,
|
||||||
'auth' => ['1a44f8d5e847537dbb8d3c76fe73a93c', 'ec98b45c53a7694c4f30d09eee9ad280']
|
'auth' => ['1a44f8d5e847537dbb8d3c76fe73a93c', 'ec98b45c53a7694c4f30d09eee9ad280']
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
|||||||
106
submit_pop.php
106
submit_pop.php
@@ -10,6 +10,8 @@ if (!$user_id) {
|
|||||||
// Handle POST submission
|
// Handle POST submission
|
||||||
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||||
$eft_id = $_POST['eft_id'] ?? null;
|
$eft_id = $_POST['eft_id'] ?? null;
|
||||||
|
$file_name = str_replace(' ', '_', $eft_id);
|
||||||
|
|
||||||
|
|
||||||
if (!$eft_id || !isset($_FILES['pop_file'])) {
|
if (!$eft_id || !isset($_FILES['pop_file'])) {
|
||||||
echo "<div class='alert alert-danger'>Invalid submission: missing eft_id or file.</div>";
|
echo "<div class='alert alert-danger'>Invalid submission: missing eft_id or file.</div>";
|
||||||
@@ -20,7 +22,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|||||||
} else {
|
} else {
|
||||||
$file = $_FILES['pop_file'];
|
$file = $_FILES['pop_file'];
|
||||||
$target_dir = "uploads/pop/";
|
$target_dir = "uploads/pop/";
|
||||||
$target_file = $target_dir . $eft_id . ".pdf";
|
$target_file = $target_dir . $file_name . ".pdf";
|
||||||
|
|
||||||
// Check for upload errors first
|
// Check for upload errors first
|
||||||
if ($file['error'] !== UPLOAD_ERR_OK) {
|
if ($file['error'] !== UPLOAD_ERR_OK) {
|
||||||
@@ -49,18 +51,58 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|||||||
|
|
||||||
if (move_uploaded_file($file['tmp_name'], $target_file)) {
|
if (move_uploaded_file($file['tmp_name'], $target_file)) {
|
||||||
// Update EFT and booking status
|
// Update EFT and booking status
|
||||||
$stmt1 = $conn->prepare("UPDATE efts SET status = 'PROCESSING' WHERE eft_id = ?");
|
$payment_type = $_POST['payment_type'] ?? 'booking';
|
||||||
$stmt1->bind_param("s", $eft_id);
|
|
||||||
$stmt1->execute();
|
|
||||||
|
|
||||||
$stmt2 = $conn->prepare("UPDATE bookings SET status = 'PROCESSING' WHERE eft_id = ?");
|
if ($payment_type === 'membership') {
|
||||||
$stmt2->bind_param("s", $eft_id);
|
// Update EFT and booking status
|
||||||
$stmt2->execute();
|
$stmt1 = $conn->prepare("UPDATE efts SET status = 'PROCESSING' WHERE eft_id = ?");
|
||||||
|
$stmt1->bind_param("s", $eft_id);
|
||||||
|
$stmt1->execute();
|
||||||
|
// Update membership fee status
|
||||||
|
$stmt = $conn->prepare("UPDATE membership_fees SET payment_status = 'PROCESSING' WHERE payment_id = ?");
|
||||||
|
$stmt->bind_param("s", $eft_id);
|
||||||
|
$stmt->execute();
|
||||||
|
} else {
|
||||||
|
// Update EFT and booking status
|
||||||
|
$stmt1 = $conn->prepare("UPDATE efts SET status = 'PROCESSING' WHERE eft_id = ?");
|
||||||
|
$stmt1->bind_param("s", $eft_id);
|
||||||
|
$stmt1->execute();
|
||||||
|
|
||||||
//TODO send mail with pop attachment to jacqui & louise
|
$stmt2 = $conn->prepare("UPDATE bookings SET status = 'PROCESSING' WHERE eft_id = ?");
|
||||||
|
$stmt2->bind_param("s", $eft_id);
|
||||||
|
$stmt2->execute();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Notify n8n and send the path to the uploaded file
|
||||||
|
$webhook_url = 'https://n8n.4wdcsa.co.za/webhook/process-pop';
|
||||||
|
|
||||||
|
$postData = [
|
||||||
|
'eft_id' => $eft_id,
|
||||||
|
'payment_type' => $payment_type,
|
||||||
|
];
|
||||||
|
|
||||||
|
$ch = curl_init($webhook_url);
|
||||||
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||||
|
curl_setopt($ch, CURLOPT_POST, true);
|
||||||
|
curl_setopt($ch, CURLOPT_HTTPHEADER, [
|
||||||
|
'Content-Type: application/json'
|
||||||
|
]);
|
||||||
|
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($postData));
|
||||||
|
|
||||||
|
$response = curl_exec($ch);
|
||||||
|
$error = curl_error($ch);
|
||||||
|
$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||||
|
curl_close($ch);
|
||||||
|
|
||||||
|
if ($error) {
|
||||||
|
error_log("Webhook Error: $error");
|
||||||
|
$_SESSION['message'] = $error;
|
||||||
|
header("Location: bookings.php");
|
||||||
|
} else {
|
||||||
|
$_SESSION['message'] = "Thank you! We are busy processing your payment!";
|
||||||
|
header("Location: bookings.php");
|
||||||
|
}
|
||||||
|
|
||||||
$_SESSION['message'] = "We have received your P.O.P. We will process it soon.";
|
|
||||||
header("Location: bookings.php");
|
|
||||||
exit;
|
exit;
|
||||||
} else {
|
} else {
|
||||||
echo "<div class='alert alert-danger'>Unable to move uploaded file.</div>";
|
echo "<div class='alert alert-danger'>Unable to move uploaded file.</div>";
|
||||||
@@ -73,12 +115,18 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|||||||
|
|
||||||
|
|
||||||
// Fetch bookings for dropdown
|
// Fetch bookings for dropdown
|
||||||
$stmt = $conn->prepare("SELECT eft_id FROM bookings WHERE user_id = ? AND status = 'AWAITING PAYMENT'");
|
$stmt = $conn->prepare("
|
||||||
//TODO add membership id as well
|
SELECT eft_id AS id, 'booking' AS type FROM bookings WHERE user_id = ? AND status = 'AWAITING PAYMENT'
|
||||||
$stmt->bind_param("i", $user_id);
|
UNION
|
||||||
|
SELECT payment_id AS id, 'membership' AS type FROM membership_fees WHERE user_id = ? AND payment_status = 'PENDING'
|
||||||
|
");
|
||||||
|
$stmt->bind_param("ii", $user_id, $user_id);
|
||||||
$stmt->execute();
|
$stmt->execute();
|
||||||
$result = $stmt->get_result();
|
$result = $stmt->get_result();
|
||||||
$bookings = $result->fetch_all(MYSQLI_ASSOC);
|
$items = $result->fetch_all(MYSQLI_ASSOC);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
$bannerFolder = 'assets/images/banners/';
|
$bannerFolder = 'assets/images/banners/';
|
||||||
$bannerImages = glob($bannerFolder . '*.{jpg,jpeg,png,webp}', GLOB_BRACE);
|
$bannerImages = glob($bannerFolder . '*.{jpg,jpeg,png,webp}', GLOB_BRACE);
|
||||||
@@ -112,26 +160,29 @@ if (!empty($bannerImages)) {
|
|||||||
<div class="section-title">
|
<div class="section-title">
|
||||||
<h3>Submit Proof of Payment</h3>
|
<h3>Submit Proof of Payment</h3>
|
||||||
<div style="text-align: center;" id="responseMessage"></div>
|
<div style="text-align: center;" id="responseMessage"></div>
|
||||||
<p>To finalise your booking, select the booking that you have paid for below, and then upload your PDF proof of payment.</p> <!-- Message display area -->
|
<p>To finalise your booking/membership, select the payment reference below, and then upload your PDF proof of payment.</p> <!-- Message display area -->
|
||||||
</div>
|
</div>
|
||||||
<?php if (count($bookings) > 0) {?>
|
<?php if (count($items) > 0) {?>
|
||||||
|
|
||||||
<form enctype="multipart/form-data" method="POST">
|
<form enctype="multipart/form-data" method="POST">
|
||||||
|
|
||||||
<div class="row mt-35">
|
<div class="row mt-35">
|
||||||
<ul class="tickets clearfix">
|
<ul class="tickets clearfix">
|
||||||
<li>
|
<li>
|
||||||
Select Booking
|
Select Payment Reference:
|
||||||
<select name="eft_id" id="eft_id" required>
|
<select name="eft_id" id="eft_id" required onchange="updatePaymentType(this)">
|
||||||
<?php
|
<?php
|
||||||
if (count($bookings) > 0) {
|
if (count($items) > 0) {
|
||||||
foreach ($bookings as $booking) {
|
foreach ($items as $item) {
|
||||||
echo '<option value="' . htmlspecialchars($booking['eft_id']) . '">' . htmlspecialchars($booking['eft_id']) . '</option>';
|
$label = strtoupper($item['type']) . ' - ' . htmlspecialchars($item['id']);
|
||||||
|
echo '<option value="' . htmlspecialchars($item['id']) . '" data-type="' . $item['type'] . '">' . $label . '</option>';
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
echo '<option value="" disabled selected>No bookings available</option>';
|
echo '<option value="" disabled selected>No payments available</option>';
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
</select>
|
</select>
|
||||||
|
<input type="hidden" name="payment_type" id="payment_type">
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
<li>
|
<li>
|
||||||
@@ -153,5 +204,16 @@ if (!empty($bannerImages)) {
|
|||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
function updatePaymentType(selectEl) {
|
||||||
|
const selectedOption = selectEl.options[selectEl.selectedIndex];
|
||||||
|
const type = selectedOption.getAttribute('data-type');
|
||||||
|
document.getElementById('payment_type').value = type;
|
||||||
|
}
|
||||||
|
window.onload = function() {
|
||||||
|
const dropdown = document.getElementById('eft_id');
|
||||||
|
updatePaymentType(dropdown); // set default value on page load
|
||||||
|
};
|
||||||
|
</script>
|
||||||
|
|
||||||
<?php include_once("insta_footer.php"); ?>
|
<?php include_once("insta_footer.php"); ?>
|
||||||
Binary file not shown.
Reference in New Issue
Block a user