This commit is contained in:
Flatlogic Bot 2025-10-17 11:10:28 +00:00
parent ac0f115fb6
commit 7b84a1fc13
3 changed files with 131 additions and 209 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 90 KiB

View File

@ -147,10 +147,11 @@
</div> </div>
</div> </div>
<div class="col-lg-5"> <div class="col-lg-5">
<div class="right-column"> <div class="right-column" id="right-column-content">
<h2>Register now</h2> <h2>Register now</h2>
<p>Don't miss this chance to learn and get your questions answered</p> <p>Don't miss this chance to learn and get your questions answered</p>
<form action="register.php" method="POST"> <div id="form-message" class="mb-3" style="color: #ffc107;"></div>
<form id="registration-form" method="POST" action="register.php">
<div class="row mb-3"> <div class="row mb-3">
<div class="col"> <div class="col">
<input type="text" class="form-control" name="first_name" placeholder="First name" required> <input type="text" class="form-control" name="first_name" placeholder="First name" required>
@ -184,6 +185,7 @@
<label class="form-check-label" for="other">Other</label> <label class="form-check-label" for="other">Other</label>
</div> </div>
</div> </div>
<input type="hidden" name="webinar_id" value="1">
<button type="submit" class="btn-register">Register Now</button> <button type="submit" class="btn-register">Register Now</button>
</form> </form>
<div class="what-you-learn"> <div class="what-you-learn">
@ -199,5 +201,53 @@
</div> </div>
</div> </div>
</div> </div>
<script>
document.getElementById('registration-form').addEventListener('submit', function(event) {
event.preventDefault();
const form = event.target;
const formData = new FormData(form);
const messageDiv = document.getElementById('form-message');
const rightColumn = document.getElementById('right-column-content');
messageDiv.textContent = ''; // Clear previous messages
fetch('register.php', {
method: 'POST',
body: formData
})
.then(response => response.json())
.then(data => {
if (data.success) {
const successHtml = `
<h2>You're Registered!</h2>
<p>Thank you for registering for the webinar. An email confirmation has been sent to you.</p>
<p>Add this event to your calendar:</p>
<div class="d-grid gap-2 mt-4">
<a href="${data.google_link}" target="_blank" class="btn btn-light">Add to Google Calendar</a>
<a href="${data.outlook_link}" download="webinar.ics" class="btn btn-outline-light">Add to Outlook/iCal</a>
</div>
<div class="what-you-learn" style="margin-top: 60px;">
<h4>SCHEDULE</h4>
<ul>
<li>Intro ~10 min</li>
<li>Creating Apps ~40-50 min</li>
<li>Q&A</li>
</ul>
</div>
`;
rightColumn.innerHTML = successHtml;
} else {
messageDiv.textContent = data.error || 'An unknown error occurred.';
}
})
.catch(error => {
console.error('Error:', error);
messageDiv.textContent = 'A network error occurred. Please try again.';
});
});
</script>
</body> </body>
</html> </html>

View File

@ -3,7 +3,9 @@ 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 header('Content-Type: application/json');
// --- Helper function to fetch webinar details ---
function get_webinar_details($id) { function get_webinar_details($id) {
if (empty($id)) return null; if (empty($id)) return null;
try { try {
@ -16,222 +18,92 @@ function get_webinar_details($id) {
} }
} }
$webinar_id = filter_input(INPUT_GET, 'webinar_id', FILTER_VALIDATE_INT) ?: filter_input(INPUT_POST, 'webinar_id', FILTER_VALIDATE_INT) ?: 1; // --- Only allow POST requests ---
if ($_SERVER["REQUEST_METHOD"] !== "POST") {
echo json_encode(['success' => false, 'error' => 'Invalid request method.']);
exit;
}
$webinar_id = filter_input(INPUT_POST, 'webinar_id', FILTER_VALIDATE_INT) ?: 1;
$webinar = get_webinar_details($webinar_id); $webinar = get_webinar_details($webinar_id);
if (!$webinar) { if (!$webinar) {
http_response_code(404); http_response_code(404);
echo "Webinar not found."; echo json_encode(['success' => false, 'error' => 'Webinar not found.']);
exit; exit;
} }
$error_message = null; // --- DATA CAPTURE ---
$success_message = null; $email = filter_input(INPUT_POST, 'email', FILTER_VALIDATE_EMAIL);
$form_data = $_SESSION['form_data'] ?? []; $first_name = filter_input(INPUT_POST, 'first_name', FILTER_SANITIZE_STRING);
unset($_SESSION['form_data']); $last_name = filter_input(INPUT_POST, 'last_name', FILTER_SANITIZE_STRING);
$company = filter_input(INPUT_POST, 'company', FILTER_SANITIZE_STRING);
$how_did_you_hear = filter_input(INPUT_POST, 'how_did_you_hear', FILTER_SANITIZE_STRING);
$password = $_POST['password'] ?? null; // Not sanitizing for comparison
$confirm_password = $_POST['confirm_password'] ?? null;
$timezone = filter_input(INPUT_POST, 'timezone', FILTER_SANITIZE_STRING);
// --- FORM SUBMISSION (POST REQUEST) --- // --- VALIDATION ---
if ($_SERVER["REQUEST_METHOD"] == "POST") { if (!$first_name || !$last_name || !$email) {
// --- DATA CAPTURE --- echo json_encode(['success' => false, 'error' => 'Please fill out all required fields.']);
$email = filter_input(INPUT_POST, 'email', FILTER_VALIDATE_EMAIL); exit;
$first_name = filter_input(INPUT_POST, 'first_name', FILTER_SANITIZE_STRING); }
$last_name = filter_input(INPUT_POST, 'last_name', FILTER_SANITIZE_STRING); // Password validation can be added here if needed, e.g., length
$company = filter_input(INPUT_POST, 'company', FILTER_SANITIZE_STRING); // For now, just checking if they match if provided
$how_did_you_hear = filter_input(INPUT_POST, 'how_did_you_hear', FILTER_SANITIZE_STRING); if (isset($password) && $password !== $confirm_password) {
$password = filter_input(INPUT_POST, 'password', FILTER_UNSAFE_RAW); echo json_encode(['success' => false, 'error' => 'Passwords do not match.']);
$confirm_password = filter_input(INPUT_POST, 'confirm_password', FILTER_UNSAFE_RAW); exit;
$timezone = filter_input(INPUT_POST, 'timezone', FILTER_SANITIZE_STRING); }
// Store form data in session to repopulate on error
$_SESSION['form_data'] = $_POST;
if (!$first_name || !$last_name || !$email) { try {
$error_message = 'Please fill out all required fields.'; // --- CHECK IF ALREADY REGISTERED ---
} elseif ($password !== $confirm_password) { $stmt = db()->prepare("SELECT id FROM attendees WHERE webinar_id = ? AND email = ?");
$error_message = 'Passwords do not match.'; $stmt->execute([$webinar_id, $email]);
} else { if ($stmt->fetch()) {
try { echo json_encode(['success' => false, 'error' => 'You are already registered for this webinar.']);
$stmt = db()->prepare("SELECT id FROM attendees WHERE webinar_id = ? AND email = ?");
$stmt->execute([$webinar_id, $email]);
if ($stmt->fetch()) {
$error_message = 'You are already registered for this webinar.';
} else {
$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)
VALUES (?, ?, ?, ?, ?, ?, ?, ?)";
$stmt = db()->prepare($sql);
$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']);
$subject = "Confirmation: You're Registered for " . $webinar['title'];
$body_html = "<h1>You're in!</h1><p>Thanks for registering for our webinar: <strong>{$webinar['title']}</strong>.</p><p>It will take place on <strong>" . $webinar_date_obj->format('l, F j, Y \a\t g:i A T') . "</strong>.</p><p>You can now log in to your dashboard to see the details.</p>";
MailService::sendMail($email, $subject, $body_html);
// --- PREPARE SUCCESS RESPONSE ---
$webinar_date = new DateTime($webinar['scheduled_at'], new DateTimeZone('UTC'));
$start_time_utc = $webinar_date->format('Ymd\THis\Z');
$webinar_date->add(new DateInterval('PT1H')); // Assume 1 hour duration
$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';
$ics_content = implode("\r\n", [
'BEGIN:VCALENDAR', 'VERSION:2.0', 'BEGIN:VEVENT',
'URL:' . 'http://' . $_SERVER['HTTP_HOST'],
'DTSTART:' . $start_time_utc, 'DTEND:' . $end_time_utc,
'SUMMARY:' . $webinar['title'], 'DESCRIPTION:' . $webinar['description'],
'END:VEVENT', 'END:VCALENDAR'
]);
$outlook_link = 'data:text/calendar;charset=utf-8,' . rawurlencode($ics_content);
$success_message = "<h1>Youre in!</h1>
<p>Thanks for registering for <strong>" . htmlspecialchars($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='" . 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) {
error_log("Registration error: " . $e->getMessage());
$error_message = 'An unexpected error occurred. Please try again.';
}
}
if ($error_message) {
// Redirect back to the form with the error message
$_SESSION['error_message'] = $error_message;
header("Location: register.php?webinar_id = " . $webinar_id);
exit; exit;
} }
} else {
// On GET request, check for session error messages // --- REGISTER USER ---
if (isset($_SESSION['error_message'])) { $password_hash = isset($password) ? password_hash($password, PASSWORD_DEFAULT) : null;
$error_message = $_SESSION['error_message']; $sql = "INSERT INTO attendees (webinar_id, first_name, last_name, email, company, how_did_you_hear, password, timezone)
unset($_SESSION['error_message']); VALUES (?, ?, ?, ?, ?, ?, ?, ?)";
} $stmt = db()->prepare($sql);
$stmt->execute([$webinar_id, $first_name, $last_name, $email, $company, $how_did_you_hear, $password_hash, $timezone]);
// --- SEND CONFIRMATION EMAIL ---
$webinar_date_obj = new DateTime($webinar['scheduled_at']);
$subject = "Confirmation: You're Registered for " . $webinar['title'];
$body_html = "<h1>You're in!</h1><p>Thanks for registering for our webinar: <strong>{$webinar['title']}</strong>.</p><p>It will take place on <strong>" . $webinar_date_obj->format('l, F j, Y \a\t g:i A T') . "</strong>.</p><p>You can now log in to your dashboard to see the details.</p>";
MailService::sendMail($email, $subject, $body_html);
// --- PREPARE SUCCESS RESPONSE ---
$webinar_date = new DateTime($webinar['scheduled_at'], new DateTimeZone('UTC'));
$start_time_utc = $webinar_date->format('Ymd H is Z');
$webinar_date->add(new DateInterval('PT1H')); // Assume 1 hour duration
$end_time_utc = $webinar_date->format('Ymd H is 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';
$ics_content = implode("\n", [
'BEGIN:VCALENDAR', 'VERSION:2.0', 'BEGIN:VEVENT',
'URL:' . 'http://' . $_SERVER['HTTP_HOST'],
'DTSTART:' . $start_time_utc, 'DTEND:' . $end_time_utc,
'SUMMARY:' . $webinar['title'], 'DESCRIPTION:' . $webinar['description'],
'END:VEVENT', 'END:VCALENDAR'
]);
$outlook_link = 'data:text/calendar;charset=utf-8,' . rawurlencode($ics_content);
echo json_encode([
'success' => true,
'webinar_title' => $webinar['title'],
'google_link' => $google_link,
'outlook_link' => $outlook_link
]);
} catch (Exception $e) {
error_log("Registration error: " . $e->getMessage());
http_response_code(500);
echo json_encode(['success' => false, 'error' => 'An unexpected server error occurred. Please try again.']);
} }
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Register for <?= htmlspecialchars($webinar['title']) ?></title>
<style>
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; 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 .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; }
.speakers { margin-top: 2rem; }
.speakers h3 { font-size: 1.2rem; color: #cbd5e0; margin-bottom: 1rem; }
.speaker { display: flex; align-items: center; margin-bottom: 1rem; }
.speaker img { width: 50px; height: 50px; border-radius: 50%; margin-right: 1rem; background-color: #4a5568; }
.right-pane .card { background-color: #2d3748; border-radius: 0.5rem; padding: 2rem; border: 1px solid #4a5568; }
.right-pane h2 { margin-top: 0; font-size: 1.5rem; color: #f6e05e; text-align: center; }
.form-group { margin-bottom: 1.5rem; }
label { display: block; margin-bottom: 0.5rem; font-weight: bold; }
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:hover { background-color: #f6d32d; }
.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; color: #cbd5e0; font-size: 1.1rem; line-height: 1.6; }
.success-message h1 { color: #f6e05e; font-size: 2rem; margin-top: 0; }
.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; }
@media (max-width: 768px) { .container { grid-template-columns: 1fr; } }
</style>
</head>
<body>
<div class="container">
<div class="left-pane">
<h1><?= htmlspecialchars($webinar['title']) ?></h1>
<div class="date-time" id="local-date-time">Loading date...</div>
<p class="value-prop"><?= htmlspecialchars($webinar['description']) ?></p>
<div class="speakers">
<h3>Speakers</h3>
<div class="speaker"><img src="assets/images/pexels/22601971.jpg" alt="Philip Daineka"> <span>Philip Daineka</span></div>
<div class="speaker"><img src="assets/images/pexels/34285016.jpg" alt="Alex Rubanau"> <span>Alex Rubanau</span></div>
<div class="speaker"><img src="assets/images/pexels/34238049.jpg" alt="Alexey Vertel"> <span>Alexey Vertel</span></div>
</div>
</div>
<div class="right-pane">
<div class="card">
<?php if ($success_message): ?>
<div class="success-message">
<?= $success_message ?>
<div style="margin-top: 2rem;">
<a href="index.php" style="color: #f6e05e; text-decoration: underline;">Back to Home</a>
</div>
</div>
<?php elseif ($error_message && strpos($error_message, 'You are already registered') !== false): ?>
<div class="success-message">
<h1>Already Registered</h1>
<p><?= htmlspecialchars($error_message) ?></p>
<p>You can view webinar details on your dashboard.</p>
<div style="margin-top: 2rem;">
<a href="dashboard.php" style="color: #f6e05e; text-decoration: underline;">Go to Dashboard</a>
<a href="index.php" style="color: #f6e05e; text-decoration: underline; margin-left: 1rem;">Back to Home</a>
</div>
</div>
<?php else: ?>
<?php if ($error_message): ?>
<div class="error-message"><?= htmlspecialchars($error_message) ?></div>
<?php endif; ?>
<form id="registration-form" method="POST" action="register.php?webinar_id=<?= $webinar['id'] ?>">
<h2>Register & Get Calendar Invite</h2>
<div class="form-group">
<label for="email">Email (required)</label>
<input type="email" id="email" name="email" required value="<?= htmlspecialchars($form_data['email'] ?? '') ?>">
</div>
<div class="form-group">
<label for="first_name">First name</label>
<input type="text" id="first_name" name="first_name" required value="<?= htmlspecialchars($form_data['first_name'] ?? '') ?>">
</div>
<div class="form-group">
<label for="last_name">Last name</label>
<input type="text" id="last_name" name="last_name" required value="<?= htmlspecialchars($form_data['last_name'] ?? '') ?>">
</div>
<div class="form-group">
<label for="company">Company</label>
<input type="text" id="company" name="company" value="<?= htmlspecialchars($form_data['company'] ?? '') ?>">
</div>
<div class="form-group">
<label for="how_did_you_hear">How did you hear about this webinar?</label>
<input type="text" id="how_did_you_hear" name="how_did_you_hear" value="<?= htmlspecialchars($form_data['how_did_you_hear'] ?? '') ?>">
</div>
<div class="form-group">
<label for="password">Password</label>
<input type="password" id="password" name="password" required>
</div>
<div class="form-group">
<label for="confirm_password">Confirm Password</label>
<input type="password" id="confirm_password" name="confirm_password" required>
</div>
<input type="hidden" name="webinar_id" value="<?= $webinar['id'] ?>">
<input type="hidden" name="timezone" id="timezone">
<button type="submit" class="submit-btn">Register Now</button>
</form>
<?php endif; ?>
</div>
</div>
</div>
<script>
// --- TIMEZONE & DATE LOCALIZATION ---
document.getElementById('timezone').value = Intl.DateTimeFormat().resolvedOptions().timeZone;
const webinarDateUTC = '<?= $webinar["scheduled_at"] ?>';
const localDate = new Date(webinarDateUTC + 'Z');
const options = { weekday: 'long', year: 'numeric', month: 'long', day: 'numeric', hour: 'numeric', minute: 'numeric' };
document.getElementById('local-date-time').textContent = localDate.toLocaleDateString(undefined, options);
</script>
</body>
</html>