diff --git a/functions.php b/functions.php index 2050442..295757e 100644 --- a/functions.php +++ b/functions.php @@ -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(); diff --git a/newppr.php b/newppr.php index cb8aa26..cf30719 100644 --- a/newppr.php +++ b/newppr.php @@ -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 = " -
Click the button below to edit your entry securely:
+This is to confirm we have received your PPR. To view or cancel your PPR please click the button:
Edit Entry "; diff --git a/cancelppr.php b/pilotppr.php similarity index 85% rename from cancelppr.php rename to pilotppr.php index ca8ea6a..37b51b5 100644 --- a/cancelppr.php +++ b/pilotppr.php @@ -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 "Your PPR has been canceled. Thank you for letting us know!
"; + +} + 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 "Phone: " . $row['phone'] . "
"; echo "Notes: " . $row['notes'] . "
"; - + echo ''; + } else { - echo "No details found for the given ID."; + echo "No details found for the given ID. This could mean the PPR has been canceled already.
"; } $conn->close(); - echo ''; - } ?> @@ -148,8 +157,6 @@ function opView($entryId) { - - -