diff --git a/assets/vm-shot-2025-10-17T11-08-35-321Z.jpg b/assets/vm-shot-2025-10-17T11-08-35-321Z.jpg new file mode 100644 index 0000000..b01714a Binary files /dev/null and b/assets/vm-shot-2025-10-17T11-08-35-321Z.jpg differ diff --git a/index.php b/index.php index 9494aa3..bf1324c 100644 --- a/index.php +++ b/index.php @@ -147,10 +147,11 @@
-
+

Register now

Don't miss this chance to learn and get your questions answered

-
+
+
@@ -184,6 +185,7 @@
+
@@ -199,5 +201,53 @@
+ + + \ No newline at end of file diff --git a/register.php b/register.php index 33eb394..39447b9 100644 --- a/register.php +++ b/register.php @@ -3,7 +3,9 @@ session_start(); require_once 'db/config.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) { if (empty($id)) return null; 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); if (!$webinar) { http_response_code(404); - echo "Webinar not found."; + echo json_encode(['success' => false, 'error' => 'Webinar not found.']); exit; } -$error_message = null; -$success_message = null; -$form_data = $_SESSION['form_data'] ?? []; -unset($_SESSION['form_data']); +// --- DATA CAPTURE --- +$email = filter_input(INPUT_POST, 'email', FILTER_VALIDATE_EMAIL); +$first_name = filter_input(INPUT_POST, 'first_name', FILTER_SANITIZE_STRING); +$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) --- -if ($_SERVER["REQUEST_METHOD"] == "POST") { - // --- DATA CAPTURE --- - $email = filter_input(INPUT_POST, 'email', FILTER_VALIDATE_EMAIL); - $first_name = filter_input(INPUT_POST, 'first_name', FILTER_SANITIZE_STRING); - $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 = filter_input(INPUT_POST, 'password', FILTER_UNSAFE_RAW); - $confirm_password = filter_input(INPUT_POST, 'confirm_password', FILTER_UNSAFE_RAW); - $timezone = filter_input(INPUT_POST, 'timezone', FILTER_SANITIZE_STRING); - - // Store form data in session to repopulate on error - $_SESSION['form_data'] = $_POST; +// --- VALIDATION --- +if (!$first_name || !$last_name || !$email) { + echo json_encode(['success' => false, 'error' => 'Please fill out all required fields.']); + exit; +} +// Password validation can be added here if needed, e.g., length +// For now, just checking if they match if provided +if (isset($password) && $password !== $confirm_password) { + echo json_encode(['success' => false, 'error' => 'Passwords do not match.']); + exit; +} - if (!$first_name || !$last_name || !$email) { - $error_message = 'Please fill out all required fields.'; - } elseif ($password !== $confirm_password) { - $error_message = 'Passwords do not match.'; - } else { - try { - $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 = "

You're in!

Thanks for registering for our webinar: {$webinar['title']}.

It will take place on " . $webinar_date_obj->format('l, F j, Y \a\t g:i A T') . ".

You can now log in to your dashboard to see the details.

"; - 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 = "

You’re in!

-

Thanks for registering for " . htmlspecialchars($webinar['title']) . ".

-

Check your email for your confirmation. You can now log in to see the details.

-
- Add to Google Calendar - Add to Outlook (ICS) -
"; - - 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); +try { + // --- CHECK IF ALREADY REGISTERED --- + $stmt = db()->prepare("SELECT id FROM attendees WHERE webinar_id = ? AND email = ?"); + $stmt->execute([$webinar_id, $email]); + if ($stmt->fetch()) { + echo json_encode(['success' => false, 'error' => 'You are already registered for this webinar.']); exit; } -} else { - // On GET request, check for session error messages - if (isset($_SESSION['error_message'])) { - $error_message = $_SESSION['error_message']; - unset($_SESSION['error_message']); - } + + // --- REGISTER USER --- + $password_hash = isset($password) ? password_hash($password, PASSWORD_DEFAULT) : null; + $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]); + + // --- SEND CONFIRMATION EMAIL --- + $webinar_date_obj = new DateTime($webinar['scheduled_at']); + $subject = "Confirmation: You're Registered for " . $webinar['title']; + $body_html = "

You're in!

Thanks for registering for our webinar: {$webinar['title']}.

It will take place on " . $webinar_date_obj->format('l, F j, Y \a\t g:i A T') . ".

You can now log in to your dashboard to see the details.

"; + 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.']); } -?> - - - - - - Register for <?= htmlspecialchars($webinar['title']) ?> - - - -
-
-

-
Loading date...
-

-
-

Speakers

-
Philip Daineka Philip Daineka
-
Alex Rubanau Alex Rubanau
-
Alexey Vertel Alexey Vertel
-
-
- -
-
- -
- - -
- -
-

Already Registered

-

-

You can view webinar details on your dashboard.

- -
- - -
- -
-

Register & Get Calendar Invite

-
- - -
-
- - -
-
- - -
-
- - -
-
- - -
-
- - -
-
- - -
- - - - -
- -
-
-
- - - - \ No newline at end of file