alex version

This commit is contained in:
Flatlogic Bot 2025-10-17 11:02:25 +00:00
parent a2b2e8ae3b
commit f400adcf7c
4 changed files with 101 additions and 164 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 89 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 89 KiB

View File

@ -184,7 +184,7 @@
<label class="form-check-label" for="other">Other</label> <label class="form-check-label" for="other">Other</label>
</div> </div>
</div> </div>
<button type="submit" class="btn-register">Register</button> <button type="submit" class="btn-register">Register Now</button>
</form> </form>
<div class="what-you-learn"> <div class="what-you-learn">
<h4>SCHEDULE</h4> <h4>SCHEDULE</h4>

View File

@ -1,12 +1,11 @@
<?php <?php
session_start();
require_once 'db/config.php'; require_once 'db/config.php';
require_once 'mail/MailService.php'; require_once 'mail/MailService.php';
// Helper function to fetch webinar details // Helper function to fetch webinar details
function get_webinar_details($id) { function get_webinar_details($id) {
if (empty($id)) { if (empty($id)) return null;
return null;
}
try { try {
$stmt = db()->prepare("SELECT id, title, description, scheduled_at, presenter FROM webinars WHERE id = ?"); $stmt = db()->prepare("SELECT id, title, description, scheduled_at, presenter FROM webinars WHERE id = ?");
$stmt->execute([$id]); $stmt->execute([$id]);
@ -17,15 +16,23 @@ function get_webinar_details($id) {
} }
} }
// --- AJAX FORM SUBMISSION (POST REQUEST) --- $webinar_id = filter_input(INPUT_GET, 'webinar_id', FILTER_VALIDATE_INT) ?: filter_input(INPUT_POST, 'webinar_id', FILTER_VALIDATE_INT) ?: 1;
$webinar = get_webinar_details($webinar_id);
if (!$webinar) {
http_response_code(404);
echo "Webinar not found.";
exit;
}
$error_message = null;
$success_message = null;
$form_data = $_SESSION['form_data'] ?? [];
unset($_SESSION['form_data']);
// --- FORM SUBMISSION (POST REQUEST) ---
if ($_SERVER["REQUEST_METHOD"] == "POST") { if ($_SERVER["REQUEST_METHOD"] == "POST") {
header('Content-Type: application/json');
$response = [];
// --- DATA CAPTURE --- // --- DATA CAPTURE ---
$webinar_id = filter_input(INPUT_POST, 'webinar_id', FILTER_VALIDATE_INT) ?: filter_input(INPUT_GET, 'webinar_id', FILTER_VALIDATE_INT) ?: 1;
$webinar = get_webinar_details($webinar_id);
$email = filter_input(INPUT_POST, 'email', FILTER_VALIDATE_EMAIL); $email = filter_input(INPUT_POST, 'email', FILTER_VALIDATE_EMAIL);
$first_name = filter_input(INPUT_POST, 'first_name', FILTER_SANITIZE_STRING); $first_name = filter_input(INPUT_POST, 'first_name', FILTER_SANITIZE_STRING);
$last_name = filter_input(INPUT_POST, 'last_name', FILTER_SANITIZE_STRING); $last_name = filter_input(INPUT_POST, 'last_name', FILTER_SANITIZE_STRING);
@ -35,34 +42,25 @@ if ($_SERVER["REQUEST_METHOD"] == "POST") {
$confirm_password = filter_input(INPUT_POST, 'confirm_password', FILTER_UNSAFE_RAW); $confirm_password = filter_input(INPUT_POST, 'confirm_password', FILTER_UNSAFE_RAW);
$timezone = filter_input(INPUT_POST, 'timezone', FILTER_SANITIZE_STRING); $timezone = filter_input(INPUT_POST, 'timezone', FILTER_SANITIZE_STRING);
// Tracking data // Store form data in session to repopulate on error
$utm_source = filter_input(INPUT_POST, 'utm_source', FILTER_SANITIZE_STRING); $_SESSION['form_data'] = $_POST;
$utm_medium = filter_input(INPUT_POST, 'utm_medium', FILTER_SANITIZE_STRING);
$utm_campaign = filter_input(INPUT_POST, 'utm_campaign', FILTER_SANITIZE_STRING);
$utm_term = filter_input(INPUT_POST, 'utm_term', FILTER_SANITIZE_STRING);
$utm_content = filter_input(INPUT_POST, 'utm_content', FILTER_SANITIZE_STRING);
$referrer = filter_input(INPUT_POST, 'referrer', FILTER_SANITIZE_STRING);
$gclid = filter_input(INPUT_POST, 'gclid', FILTER_SANITIZE_STRING);
$fbclid = filter_input(INPUT_POST, 'fbclid', FILTER_SANITIZE_STRING);
if (!$webinar) { if (!$first_name || !$last_name || !$email) {
$response = ['success' => false, 'error' => 'Webinar not found. Tried to find webinar with ID: ' . $webinar_id]; $error_message = 'Please fill out all required fields.';
} elseif (!$first_name || !$last_name || !$email) {
$response = ['success' => false, 'error' => 'Please fill out all required fields.'];
} elseif ($password !== $confirm_password) { } elseif ($password !== $confirm_password) {
$response = ['success' => false, 'error' => 'Passwords do not match.']; $error_message = 'Passwords do not match.';
} else { } else {
try { try {
$stmt = db()->prepare("SELECT id FROM attendees WHERE webinar_id = ? AND email = ?"); $stmt = db()->prepare("SELECT id FROM attendees WHERE webinar_id = ? AND email = ?");
$stmt->execute([$webinar_id, $email]); $stmt->execute([$webinar_id, $email]);
if ($stmt->fetch()) { if ($stmt->fetch()) {
$response = ['success' => false, 'error' => 'You are already registered for this webinar.']; $error_message = 'You are already registered for this webinar.';
} else { } else {
$password_hash = password_hash($password, PASSWORD_DEFAULT); $password_hash = password_hash($password, PASSWORD_DEFAULT);
$sql = "INSERT INTO attendees (webinar_id, first_name, last_name, email, company, how_did_you_hear, password, timezone, utm_source, utm_medium, utm_campaign, utm_term, utm_content, referrer, gclid, fbclid) $sql = "INSERT INTO attendees (webinar_id, first_name, last_name, email, company, how_did_you_hear, password, timezone)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"; VALUES (?, ?, ?, ?, ?, ?, ?, ?)";
$stmt = db()->prepare($sql); $stmt = db()->prepare($sql);
$stmt->execute([$webinar_id, $first_name, $last_name, $email, $company, $how_did_you_hear, $password_hash, $timezone, $utm_source, $utm_medium, $utm_campaign, $utm_term, $utm_content, $referrer, $gclid, $fbclid]); $stmt->execute([$webinar_id, $first_name, $last_name, $email, $company, $how_did_you_hear, $password_hash, $timezone]);
$webinar_date_obj = new DateTime($webinar['scheduled_at']); $webinar_date_obj = new DateTime($webinar['scheduled_at']);
$subject = "Confirmation: You're Registered for " . $webinar['title']; $subject = "Confirmation: You're Registered for " . $webinar['title'];
@ -71,9 +69,9 @@ if ($_SERVER["REQUEST_METHOD"] == "POST") {
// --- PREPARE SUCCESS RESPONSE --- // --- PREPARE SUCCESS RESPONSE ---
$webinar_date = new DateTime($webinar['scheduled_at'], new DateTimeZone('UTC')); $webinar_date = new DateTime($webinar['scheduled_at'], new DateTimeZone('UTC'));
$start_time_utc = $webinar_date->format('Ymd H is Z'); $start_time_utc = $webinar_date->format('Ymd\THis\Z');
$webinar_date->add(new DateInterval('PT1H')); // Assume 1 hour duration $webinar_date->add(new DateInterval('PT1H')); // Assume 1 hour duration
$end_time_utc = $webinar_date->format('Ymd H is Z'); $end_time_utc = $webinar_date->format('Ymd\THis\Z');
$google_link = 'https://www.google.com/calendar/render?action=TEMPLATE&text=' . urlencode($webinar['title']) . '&dates=' . $start_time_utc . '/' . $end_time_utc . '&details=' . urlencode($webinar['description']) . '&ctz=UTC'; $google_link = 'https://www.google.com/calendar/render?action=TEMPLATE&text=' . urlencode($webinar['title']) . '&dates=' . $start_time_utc . '/' . $end_time_utc . '&details=' . urlencode($webinar['description']) . '&ctz=UTC';
@ -86,30 +84,33 @@ if ($_SERVER["REQUEST_METHOD"] == "POST") {
]); ]);
$outlook_link = 'data:text/calendar;charset=utf-8,' . rawurlencode($ics_content); $outlook_link = 'data:text/calendar;charset=utf-8,' . rawurlencode($ics_content);
$response = [ $success_message = "<h1>Youre in!</h1>
'success' => true, <p>Thanks for registering for <strong>" . htmlspecialchars($webinar['title']) . "</strong>.</p>
'webinar_title' => $webinar['title'], <p>Check your email for your confirmation. You can now log in to see the details.</p>
'google_link' => $google_link, <div class='calendar-buttons'>
'outlook_link' => $outlook_link <a href='" . htmlspecialchars($google_link) . "' target='_blank'>Add to Google Calendar</a>
]; <a href='" . htmlspecialchars($outlook_link) . "' download='webinar.ics'>Add to Outlook (ICS)</a>
</div>";
unset($_SESSION['form_data']); // Clear form data on success
} }
} catch (Exception $e) { } catch (Exception $e) {
error_log("Registration error: " . $e->getMessage()); error_log("Registration error: " . $e->getMessage());
$response = ['success' => false, 'error' => 'An unexpected error occurred. Please try again.']; $error_message = 'An unexpected error occurred. Please try again.';
} }
} }
echo json_encode($response); if ($error_message) {
exit; // Redirect back to the form with the error message
} $_SESSION['error_message'] = $error_message;
header("Location: register.php?webinar_id = " . $webinar_id);
// --- RENDER PAGE (Initial GET Request) --- exit;
$webinar_id = filter_input(INPUT_GET, 'webinar_id', FILTER_VALIDATE_INT) ?: 1; }
$webinar = get_webinar_details($webinar_id); } else {
// On GET request, check for session error messages
if (!$webinar) { if (isset($_SESSION['error_message'])) {
http_response_code(404); $error_message = $_SESSION['error_message'];
echo "Webinar not found."; unset($_SESSION['error_message']);
exit; }
} }
?> ?>
<!DOCTYPE html> <!DOCTYPE html>
@ -119,8 +120,8 @@ if (!$webinar) {
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Register for <?= htmlspecialchars($webinar['title']) ?></title> <title>Register for <?= htmlspecialchars($webinar['title']) ?></title>
<style> <style>
body { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif; background-color: #1a202c; color: #e2e8f0; margin: 0; padding: 2rem; } body { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif; background-color: #1a202c; color: #e2e8f0; margin: 0; padding: 2rem; display: flex; justify-content: center; align-items: center; min-height: 100vh; }
.container { max-width: 900px; margin: auto; display: grid; grid-template-columns: 1fr 1fr; gap: 4rem; align-items: start; } .container { max-width: 900px; width: 100%; display: grid; grid-template-columns: 1fr 1fr; gap: 4rem; align-items: start; }
.left-pane h1 { font-size: 2.5rem; color: #f6e05e; margin-bottom: 1rem; } .left-pane h1 { font-size: 2.5rem; color: #f6e05e; margin-bottom: 1rem; }
.left-pane .date-time { font-size: 1.25rem; font-weight: bold; margin-bottom: 1.5rem; } .left-pane .date-time { font-size: 1.25rem; font-weight: bold; margin-bottom: 1.5rem; }
.left-pane .value-prop { font-size: 1.1rem; color: #a0aec0; line-height: 1.6; } .left-pane .value-prop { font-size: 1.1rem; color: #a0aec0; line-height: 1.6; }
@ -136,13 +137,11 @@ if (!$webinar) {
input[type="email"], input[type="text"], input[type="password"] { width: 100%; padding: 0.75rem; background-color: #1a202c; border: 1px solid #4a5568; border-radius: 0.375rem; color: #e2e8f0; font-size: 1rem; box-sizing: border-box; } input[type="email"], input[type="text"], input[type="password"] { width: 100%; padding: 0.75rem; background-color: #1a202c; border: 1px solid #4a5568; border-radius: 0.375rem; color: #e2e8f0; font-size: 1rem; box-sizing: border-box; }
.submit-btn { display: block; width: 100%; background-color: #f6e05e; color: #1a202c; padding: 0.85rem; border: none; border-radius: 0.375rem; font-weight: bold; font-size: 1.125rem; cursor: pointer; transition: background-color 0.2s; } .submit-btn { display: block; width: 100%; background-color: #f6e05e; color: #1a202c; padding: 0.85rem; border: none; border-radius: 0.375rem; font-weight: bold; font-size: 1.125rem; cursor: pointer; transition: background-color 0.2s; }
.submit-btn:hover { background-color: #f6d32d; } .submit-btn:hover { background-color: #f6d32d; }
.submit-btn:disabled { background-color: #a0aec0; cursor: not-allowed; }
.error-message { background-color: #c53030; color: #fff; padding: 1rem; border-radius: 0.375rem; text-align: center; margin-bottom: 1.5rem; } .error-message { background-color: #c53030; color: #fff; padding: 1rem; border-radius: 0.375rem; text-align: center; margin-bottom: 1.5rem; }
.success-message { text-align: center; } .success-message { text-align: center; color: #cbd5e0; font-size: 1.1rem; line-height: 1.6; }
.success-message h1 { color: #f6e05e; font-size: 2rem; margin-top: 0; } .success-message h1 { color: #f6e05e; font-size: 2rem; margin-top: 0; }
.success-message p { color: #cbd5e0; font-size: 1.1rem; line-height: 1.6; }
.calendar-buttons a { display: inline-block; background-color: #4a5568; color: #e2e8f0; padding: 0.75rem 1.5rem; border-radius: 0.375rem; text-decoration: none; margin: 1rem 0.5rem 0; font-weight: bold; transition: background-color 0.2s; } .calendar-buttons a { display: inline-block; background-color: #4a5568; color: #e2e8f0; padding: 0.75rem 1.5rem; border-radius: 0.375rem; text-decoration: none; margin: 1rem 0.5rem 0; font-weight: bold; transition: background-color 0.2s; }
.calendar-buttons a:hover { background-color: #5a6578; } .calendar-buttons a:hover { background-color: #5a6578; }
@ -150,9 +149,6 @@ if (!$webinar) {
</style> </style>
</head> </head>
<body> <body>
<header style="padding: 1rem;">
<a href="index.php" style="color: #1a202c; text-decoration: none; background-color: #f6e05e; padding: 0.75rem 1.5rem; border-radius: 0.375rem; font-weight: bold; font-size: 1.125rem;">Back to Home</a>
</header>
<div class="container"> <div class="container">
<div class="left-pane"> <div class="left-pane">
<h1><?= htmlspecialchars($webinar['title']) ?></h1> <h1><?= htmlspecialchars($webinar['title']) ?></h1>
@ -167,51 +163,54 @@ if (!$webinar) {
</div> </div>
<div class="right-pane"> <div class="right-pane">
<div id="registration-container" class="card"> <div class="card">
<div id="error-container"></div> <?php if ($success_message): ?>
<form id="registration-form" method="POST" action="register.php?webinar_id=<?= $webinar['id'] ?>"> <div class="success-message">
<h2>Register & Get Calendar Invite</h2> <?= $success_message ?>
<div class="form-group"> <div style="margin-top: 2rem;">
<label for="email">Email (required)</label> <a href="index.php" style="color: #f6e05e; text-decoration: underline;">Back to Home</a>
<input type="email" id="email" name="email" required> </div>
</div> </div>
<div class="form-group"> <?php else: ?>
<label for="first_name">First name</label> <?php if ($error_message): ?>
<input type="text" id="first_name" name="first_name" required> <div class="error-message"><?= htmlspecialchars($error_message) ?></div>
</div> <?php endif; ?>
<div class="form-group"> <form id="registration-form" method="POST" action="register.php?webinar_id=<?= $webinar['id'] ?>">
<label for="last_name">Last name</label> <h2>Register & Get Calendar Invite</h2>
<input type="text" id="last_name" name="last_name" required> <div class="form-group">
</div> <label for="email">Email (required)</label>
<div class="form-group"> <input type="email" id="email" name="email" required value="<?= htmlspecialchars($form_data['email'] ?? '') ?>">
<label for="company">Company</label> </div>
<input type="text" id="company" name="company"> <div class="form-group">
</div> <label for="first_name">First name</label>
<div class="form-group"> <input type="text" id="first_name" name="first_name" required value="<?= htmlspecialchars($form_data['first_name'] ?? '') ?>">
<label for="how_did_you_hear">How did you hear about this webinar?</label> </div>
<input type="text" id="how_did_you_hear" name="how_did_you_hear"> <div class="form-group">
</div> <label for="last_name">Last name</label>
<div class="form-group"> <input type="text" id="last_name" name="last_name" required value="<?= htmlspecialchars($form_data['last_name'] ?? '') ?>">
<label for="password">Password</label> </div>
<input type="password" id="password" name="password" required> <div class="form-group">
</div> <label for="company">Company</label>
<div class="form-group"> <input type="text" id="company" name="company" value="<?= htmlspecialchars($form_data['company'] ?? '') ?>">
<label for="confirm_password">Confirm Password</label> </div>
<input type="password" id="confirm_password" name="confirm_password" required> <div class="form-group">
</div> <label for="how_did_you_hear">How did you hear about this webinar?</label>
<input type="hidden" name="webinar_id" value="<?= $webinar['id'] ?>"> <input type="text" id="how_did_you_hear" name="how_did_you_hear" value="<?= htmlspecialchars($form_data['how_did_you_hear'] ?? '') ?>">
<input type="hidden" name="timezone" id="timezone"> </div>
<input type="hidden" name="utm_source" id="utm_source"> <div class="form-group">
<input type="hidden" name="utm_medium" id="utm_medium"> <label for="password">Password</label>
<input type="hidden" name="utm_campaign" id="utm_campaign"> <input type="password" id="password" name="password" required>
<input type="hidden" name="utm_term" id="utm_term"> </div>
<input type="hidden" name="utm_content" id="utm_content"> <div class="form-group">
<input type="hidden" name="referrer" id="referrer"> <label for="confirm_password">Confirm Password</label>
<input type="hidden" name="gclid" id="gclid"> <input type="password" id="confirm_password" name="confirm_password" required>
<input type="hidden" name="fbclid" id="fbclid"> </div>
<input type="hidden" name="webinar_id" value="<?= $webinar['id'] ?>">
<button type="submit" class="submit-btn">Register Now</button> <input type="hidden" name="timezone" id="timezone">
</form>
<button type="submit" class="submit-btn">Register Now</button>
</form>
<?php endif; ?>
</div> </div>
</div> </div>
</div> </div>
@ -223,68 +222,6 @@ if (!$webinar) {
const localDate = new Date(webinarDateUTC + 'Z'); const localDate = new Date(webinarDateUTC + 'Z');
const options = { weekday: 'long', year: 'numeric', month: 'long', day: 'numeric', hour: 'numeric', minute: 'numeric' }; const options = { weekday: 'long', year: 'numeric', month: 'long', day: 'numeric', hour: 'numeric', minute: 'numeric' };
document.getElementById('local-date-time').textContent = localDate.toLocaleDateString(undefined, options); document.getElementById('local-date-time').textContent = localDate.toLocaleDateString(undefined, options);
// --- TRACKING PARAMS ---
const urlParams = new URLSearchParams(window.location.search);
['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content', 'gclid', 'fbclid'].forEach(param => {
if (urlParams.has(param)) {
document.getElementById(param).value = urlParams.get(param);
}
});
document.getElementById('referrer').value = document.referrer;
// --- AJAX FORM SUBMISSION ---
const form = document.getElementById('registration-form');
const container = document.getElementById('registration-container');
const errorContainer = document.getElementById('error-container');
form.addEventListener('submit', function(event) {
event.preventDefault();
const submitButton = form.querySelector('.submit-btn');
submitButton.disabled = true;
submitButton.textContent = 'Processing...';
errorContainer.innerHTML = '';
const formData = new FormData(form);
fetch(form.action, {
method: 'POST',
body: formData
})
.then(response => response.json())
.then(data => {
if (data.success) {
container.innerHTML = `
<div class="success-message">
<h1>Youre in!</h1>
<p>Thanks for registering for <strong>${escapeHTML(data.webinar_title)}</strong>.</p>
<p>Check your email for your confirmation. You can now log in to see the details.</p>
<div class="calendar-buttons">
<a href="${escapeHTML(data.google_link)}" target="_blank">Add to Google Calendar</a>
<a href="${escapeHTML(data.outlook_link)}" download="webinar.ics">Add to Outlook (ICS)</a>
</div>
</div>
`;
} else {
errorContainer.innerHTML = `<div class="error-message">${escapeHTML(data.error)}</div>`;
submitButton.disabled = false;
submitButton.textContent = 'Register Now';
}
})
.catch(error => {
console.error('Error:', error);
errorContainer.innerHTML = '<div class="error-message">A network error occurred. Please try again.</div>';
submitButton.disabled = false;
submitButton.textContent = 'Register Now';
});
});
function escapeHTML(str) {
var p = document.createElement("p");
p.appendChild(document.createTextNode(str));
return p.innerHTML;
}
</script> </script>
</body> </body>
</html> </html>