diff --git a/admin.php b/admin.php index 7fb122d..e6c6c72 100644 --- a/admin.php +++ b/admin.php @@ -1,122 +1,98 @@ query('SELECT a.id, w.title AS webinar_title, a.first_name, a.last_name, a.email, a.company, a.how_did_you_hear, a.consented, a.created_at, a.timezone, a.utm_source, a.utm_medium, a.utm_campaign, a.referrer, a.gclid, a.fbclid FROM attendees a JOIN webinars w ON a.webinar_id = w.id ORDER BY a.created_at DESC'); - $attendees = $stmt->fetchAll(PDO::FETCH_ASSOC); -} catch (PDOException $e) { - die("Could not connect to the database: " . $e->getMessage()); +// Check for messages +$message = ''; +if (isset($_SESSION['message'])) { + $message = $_SESSION['message']; + unset($_SESSION['message']); } +$pdo = db(); + +// Pagination settings +$records_per_page = 10; +$page = isset($_GET['page']) && is_numeric($_GET['page']) ? (int)$_GET['page'] : 1; +$offset = ($page - 1) * $records_per_page; + +// Get total number of records +$total_stmt = $pdo->query("SELECT COUNT(*) FROM attendees"); +$total_records = $total_stmt->fetchColumn(); +$total_pages = ceil($total_records / $records_per_page); + +// Get records for the current page +$stmt = $pdo->prepare("SELECT id, first_name, last_name, email, company, utm_source, created_at FROM attendees ORDER BY first_name ASC, last_name ASC LIMIT :limit OFFSET :offset"); +$stmt->bindValue(':limit', $records_per_page, PDO::PARAM_INT); +$stmt->bindValue(':offset', $offset, PDO::PARAM_INT); +$stmt->execute(); +$attendees = $stmt->fetchAll(PDO::FETCH_ASSOC); + ?> - - Admin Board + Admin Dashboard - -
- Logout -

Webinar Attendees

+
+

Admin Dashboard

+

Welcome, !

+ + +
+ +
+ + +
+

Registered Attendees

+ Download CSV +
+
- +
- - - - - - - - - - + - + - - - - - - - - - - - - - - - - + + + + + + + @@ -125,6 +101,23 @@ try {
IDWebinar First Name Last Name Email CompanyHow did you hear?ConsentedRegistered AtTimezone UTM SourceUTM MediumUTM CampaignReferrerGCLIDFBCLIDRegistered At Actions
No attendees yet.No attendees found.
-
- - + Edit + + +
+ + +
diff --git a/assets/pasted-20251025-190102-dd19def2.png b/assets/pasted-20251025-190102-dd19def2.png new file mode 100644 index 0000000..b0e58e3 Binary files /dev/null and b/assets/pasted-20251025-190102-dd19def2.png differ diff --git a/delete_attendee.php b/delete_attendee.php index 27fb474..dbce2ef 100644 --- a/delete_attendee.php +++ b/delete_attendee.php @@ -1,26 +1,29 @@ prepare('DELETE FROM attendees WHERE id = :id'); - $stmt->bindParam(':id', $_POST['id'], PDO::PARAM_INT); - $stmt->execute(); - } catch (PDOException $e) { - // In a real app, you'd log this error. - // For this example, we'll just stop execution. - die("Database error: " . $e->getMessage()); + $id = $_POST['id']; + $pdo = db(); + $stmt = $pdo->prepare("DELETE FROM attendees WHERE id = ?"); + + if ($stmt->execute([$id])) { + if ($stmt->rowCount() > 0) { + $_SESSION['message'] = "Attendee with ID $id has been deleted successfully."; + } else { + $_SESSION['message'] = "Error: No attendee found with ID $id. Nothing was deleted."; + } + } else { + $_SESSION['message'] = "Error: Could not execute the delete statement."; } +} else { + $_SESSION['message'] = "Error: Invalid request."; } -// Redirect back to the admin page header('Location: admin.php'); exit; diff --git a/edit_attendee.php b/edit_attendee.php new file mode 100644 index 0000000..c9b41e9 --- /dev/null +++ b/edit_attendee.php @@ -0,0 +1,115 @@ +prepare($sql); + $stmt->execute($params); + header('Location: admin.php'); + exit; + } + + // Fetch logic + $stmt = $pdo->prepare('SELECT * FROM attendees WHERE id = ?'); + $stmt->execute([$id]); + $attendee = $stmt->fetch(PDO::FETCH_ASSOC); + + if (!$attendee) { + header('Location: admin.php'); + exit; + } + +} catch (PDOException $e) { + die("Database error: " . $e->getMessage()); +} + +?> + + + + + + Edit Attendee + + + + +
+

Edit Attendee #

+
+ +
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + > + +
+ + Cancel +
+
+ + diff --git a/export_csv.php b/export_csv.php new file mode 100644 index 0000000..5384d96 --- /dev/null +++ b/export_csv.php @@ -0,0 +1,37 @@ +query("SELECT first_name, last_name, email FROM attendees ORDER BY created_at DESC"); +$attendees = $stmt->fetchAll(PDO::FETCH_ASSOC); + +header('Content-Type: text/csv; charset=utf-8'); +header('Content-Disposition: attachment; filename=attendees.csv'); + +$output = fopen('php://output', 'w'); + +// Add BOM to fix UTF-8 in Excel +fputs($output, "\xEF\xBB\xBF"); + +// Add header row +fputcsv($output, ['First Name', 'Last Name', 'Email']); + +// Add data rows +foreach ($attendees as $attendee) { + fputcsv($output, [ + $attendee['first_name'], + $attendee['last_name'], + $attendee['email'] + ]); +} + +fclose($output); +exit;