Tidy email confirms

This commit is contained in:
2025-03-07 20:44:57 +00:00
parent 2b7d3e5d2a
commit 02f1d46493
3 changed files with 46 additions and 20 deletions

View File

@@ -6,6 +6,17 @@ $username = 'ppruser'; // Replace with your database username
$password = 'iJ8kN*5[g6P3jaqN'; // Replace with your database password
$database = 'pprdevdb'; // Replace with your database name
$mailHost = 'send.one.com'; // Your SMTP server
$mailSMTPAuth = true;
$mailUsername = 'noreply@swansea-airport.wales';
$mailPassword = 'SASAGoForward2155';
//$mailSMTPSecure = PHPMailer::ENCRYPTION_SMTPS;
$mailPort = 465;
$mailFromAddress = 'noreply@swansea-airport.wales';
$mailFromName = 'Swansea Airport';
$baseUrl = "https://ppr.swansea-airport.wales/dev";
function getUserIP() {
if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
return $_SERVER['HTTP_CLIENT_IP'];
@@ -32,8 +43,15 @@ function connectDb() {
function logJournal($conn, $id, $message) {
if (isset($_SERVER['PHP_AUTH_USER'])) {
$user = $_SERVER['PHP_AUTH_USER'];
} else {
$user = "None";
}
$stmt = $conn->prepare("INSERT INTO journal (ppr_id, entry, user, ip) VALUES (?, ?, ?, ?)");
$stmt->bind_param("isss", $id, $message, $_SERVER['PHP_AUTH_USER'], getUserIP());
$ip = getUserIP();
$stmt->bind_param("isss", $id, $message, $user, $ip);
$stmt->execute();
$stmt->close();

View File

@@ -47,28 +47,30 @@ if ($_SERVER["REQUEST_METHOD"] == "POST") {
}
function generatePprEmail($entryId) {
global $mailHost, $mailSMTPAuth, $mailUsername, $mailPassword, $mailPort, $baseUrl, $mailFromAddress, $mailFromName;
$token = generateSecureToken($_POST['email'], $entryId);
$secureLink = "https://ppr.swansea-airport.wales/dev/cancelppr.php?op=view&token=" . urlencode($token);
$secureLink = $baseUrl . "/pilotppr.php?op=view&token=" . urlencode($token);
echo $secureLink;
$mail = new PHPMailer(true);
try {
$mail->isSMTP();
$mail->Host = 'send.one.com'; // Your SMTP server
$mail->SMTPAuth = true;
$mail->Username = 'noreply@swansea-airport.wales';
$mail->Password = 'SASAGoForward2155';
$mail->Host = $mailHost;
$mail->SMTPAuth = $mailSMTPAuth;
$mail->Username = $mailUsername;
$mail->Password = $mailPassword;
$mail->SMTPSecure = PHPMailer::ENCRYPTION_SMTPS;
$mail->Port = 465;
$mail->Port = $mailPort;
$mail->setFrom('noreply@swansea-airport.wales', 'Swansea Airport');
$mail->setFrom($mailFromAddress, $mailFromName);
$mail->addAddress($_POST['email']);
$mail->isHTML(true);
$mail->Subject = "Edit Your Entry";
$mail->Subject = "PPR Confirmation";
$mail->Body = "
<p>Click the button below to edit your entry securely:</p>
<p>This is to confirm we have received your PPR. To view or cancel your PPR please click the button:</p>
<a href='$secureLink' style='display: inline-block; padding: 10px 20px; color: white; background-color: #007bff; text-decoration: none; border-radius: 5px;'>Edit Entry</a>
";

View File

@@ -87,7 +87,6 @@ if (isset($_GET['token'])) {
// Token is valid, allow changes to database entry
$email = $result['email'];
$entryId = $result['entryId'];
echo "Token valid, email is " . $email . " entryId is " . $entryId;
} else {
die("Invalid or expired token.");
}
@@ -95,7 +94,7 @@ if (isset($_GET['token'])) {
switch($_GET['op']) {
case "cancel":
opCancel();
opCancel($entryId);
break;
case "view":
opView($entryId);
@@ -104,10 +103,21 @@ switch($_GET['op']) {
}
function opCancel($entryId) {
$conn = connectDb();
$sql = "UPDATE submitted SET status = 'CANCELED' where id = " . $entryId;
$result = $conn->query($sql);
logJournal($conn, $entryId, "Marked Canceled by Pilot");
$conn->close();
echo "<p>Your PPR has been canceled. Thank you for letting us know!</p>";
}
function opView($entryId) {
$conn = connectDb();
$sql = "SELECT * FROM submitted WHERE id = " . $entryId;
$sql = "SELECT * FROM submitted WHERE status = 'NEW' AND id = " . $entryId;
$result = $conn->query($sql);
if ($result->num_rows > 0) {
@@ -132,15 +142,14 @@ function opView($entryId) {
echo "<p><strong>Phone:</strong> " . $row['phone'] . "</p>";
echo "<p><strong>Notes:</strong> " . $row['notes'] . "</p></div>";
echo '<button onclick="confirmWithSweetAlert(\'pilotppr.php?op=cancel&token=' . urlencode($_GET['token']) . '\')">Cancel PPR</button>';
} else {
echo "No details found for the given ID.";
echo "<p>No details found for the given ID. This could mean the PPR has been canceled already.</p>";
}
$conn->close();
echo '<button onclick="confirmWithSweetAlert(\'cancelppr.php?op=cancel&token=' . urlencode($_GET['token']) . '\')">Cancel PPR</button>';
}
?>
@@ -148,8 +157,6 @@ function opView($entryId) {
<!-- Include SweetAlert -->
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
<script>
function confirmWithSweetAlert(url) {
Swal.fire({
@@ -167,4 +174,3 @@ function confirmWithSweetAlert(url) {
});
}
</script>