uejejje
This commit is contained in:
parent
a2ff9876ac
commit
5cc3f02c65
155
admin.php
155
admin.php
@ -1,122 +1,98 @@
|
||||
<?php
|
||||
session_start();
|
||||
require_once 'db/config.php'; // Assuming you have a db connection setup
|
||||
|
||||
// Handle logout
|
||||
if (isset($_GET['logout'])) {
|
||||
session_unset();
|
||||
session_destroy();
|
||||
header('Location: login.php');
|
||||
exit;
|
||||
}
|
||||
|
||||
// If the user is not logged in as admin, redirect to the login page.
|
||||
// Check if user is admin
|
||||
if (!isset($_SESSION['user']) || $_SESSION['user'] !== 'admin') {
|
||||
// If not admin, redirect to login page
|
||||
header('Location: login.php');
|
||||
exit;
|
||||
}
|
||||
|
||||
// --- Data Fetching ---
|
||||
require_once 'db/config.php';
|
||||
$attendees = [];
|
||||
try {
|
||||
$pdo = db();
|
||||
// Updated to select first_name and new fields
|
||||
$stmt = $pdo->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);
|
||||
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Admin Board</title>
|
||||
<title>Admin Dashboard</title>
|
||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
|
||||
<style>
|
||||
body {
|
||||
background-color: #121212;
|
||||
color: #e0e0e0;
|
||||
}
|
||||
.container {
|
||||
width: 100%;
|
||||
max-width: 1400px;
|
||||
padding: 2rem;
|
||||
}
|
||||
h1 {
|
||||
color: #ffd700;
|
||||
}
|
||||
.table {
|
||||
color: #e0e0e0;
|
||||
}
|
||||
.table-dark {
|
||||
--bs-table-bg: #212529;
|
||||
border-color: #373b3e;
|
||||
}
|
||||
.logout-btn {
|
||||
position: absolute;
|
||||
top: 1rem;
|
||||
right: 1rem;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="container">
|
||||
<a href="admin.php?logout=1" class="btn btn-secondary logout-btn">Logout</a>
|
||||
<h1 class="mb-4 text-center">Webinar Attendees</h1>
|
||||
<div class="container mt-5">
|
||||
<h2>Admin Dashboard</h2>
|
||||
<p>Welcome, <?php echo htmlspecialchars($_SESSION['user'] ?? 'Admin'); ?>!</p>
|
||||
|
||||
<?php if ($message): ?>
|
||||
<div class="alert alert-info">
|
||||
<?php echo htmlspecialchars($message); ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<div class="d-flex justify-content-between align-items-center">
|
||||
<h3 class="mt-4">Registered Attendees</h3>
|
||||
<a href="export_csv.php" class="btn btn-success">Download CSV</a>
|
||||
</div>
|
||||
|
||||
<div class="table-responsive">
|
||||
<table class="table table-dark table-striped table-hover">
|
||||
<table class="table table-striped">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>ID</th>
|
||||
<th>Webinar</th>
|
||||
<th>First Name</th>
|
||||
<th>Last Name</th>
|
||||
<th>Email</th>
|
||||
<th>Company</th>
|
||||
<th>How did you hear?</th>
|
||||
<th>Consented</th>
|
||||
<th>Registered At</th>
|
||||
<th>Timezone</th>
|
||||
<th>UTM Source</th>
|
||||
<th>UTM Medium</th>
|
||||
<th>UTM Campaign</th>
|
||||
<th>Referrer</th>
|
||||
<th>GCLID</th>
|
||||
<th>FBCLID</th>
|
||||
<th>Registered At</th>
|
||||
<th>Actions</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php if (empty($attendees)): ?>
|
||||
<tr>
|
||||
<td colspan="17" class="text-center">No attendees yet.</td>
|
||||
<td colspan="8" class="text-center">No attendees found.</td>
|
||||
</tr>
|
||||
<?php else: ?>
|
||||
<?php foreach ($attendees as $attendee): ?>
|
||||
<tr>
|
||||
<td><?= htmlspecialchars($attendee['id']) ?></td>
|
||||
<td><?= htmlspecialchars($attendee['webinar_title']) ?></td>
|
||||
<td><?= htmlspecialchars($attendee['first_name']) ?></td>
|
||||
<td><?= htmlspecialchars($attendee['last_name']) ?></td>
|
||||
<td><?= htmlspecialchars($attendee['email']) ?></td>
|
||||
<td><?= htmlspecialchars($attendee['company']) ?></td>
|
||||
<td><?= htmlspecialchars($attendee['how_did_you_hear']) ?></td>
|
||||
<td><?= $attendee['consented'] ? 'Yes' : 'No' ?></td>
|
||||
<td><?= htmlspecialchars($attendee['created_at']) ?></td>
|
||||
<td><?= htmlspecialchars($attendee['timezone']) ?></td>
|
||||
<td><?= htmlspecialchars($attendee['utm_source']) ?></td>
|
||||
<td><?= htmlspecialchars($attendee['utm_medium']) ?></td>
|
||||
<td><?= htmlspecialchars($attendee['utm_campaign']) ?></td>
|
||||
<td><?= htmlspecialchars($attendee['referrer']) ?></td>
|
||||
<td><?= htmlspecialchars($attendee['gclid']) ?></td>
|
||||
<td><?= htmlspecialchars($attendee['fbclid']) ?></td>
|
||||
<td><?php echo htmlspecialchars($attendee['id']); ?></td>
|
||||
<td><?php echo htmlspecialchars($attendee['first_name']); ?></td>
|
||||
<td><?php echo htmlspecialchars($attendee['last_name']); ?></td>
|
||||
<td><?php echo htmlspecialchars($attendee['email']); ?></td>
|
||||
<td><?php echo htmlspecialchars($attendee['company']); ?></td>
|
||||
<td><?php echo htmlspecialchars($attendee['utm_source']); ?></td>
|
||||
<td><?php echo htmlspecialchars($attendee['created_at']); ?></td>
|
||||
<td>
|
||||
<form action="delete_attendee.php" method="POST" onsubmit="return confirm('Are you sure you want to delete this attendee?');">
|
||||
<input type="hidden" name="id" value="<?= $attendee['id'] ?>">
|
||||
<button type="submit" class="btn btn-danger btn-sm">Delete</button>
|
||||
<a href="edit_attendee.php?id=<?php echo $attendee['id']; ?>" class="btn btn-sm btn-primary">Edit</a>
|
||||
<form action="delete_attendee.php" method="POST" style="display: inline-block;">
|
||||
<input type="hidden" name="id" value="<?php echo $attendee['id']; ?>">
|
||||
<button type="submit" class="btn btn-sm btn-danger" onclick="return confirm('Are you sure?')">Delete</button>
|
||||
</form>
|
||||
</td>
|
||||
</tr>
|
||||
@ -125,6 +101,23 @@ try {
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<nav aria-label="Page navigation">
|
||||
<ul class="pagination justify-content-center">
|
||||
<?php if ($page > 1): ?>
|
||||
<li class="page-item"><a class="page-link" href="?page=<?php echo $page - 1; ?>">Previous</a></li>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php for ($i = 1; $i <= $total_pages; $i++): ?>
|
||||
<li class="page-item <?php if ($i == $page) echo 'active'; ?>"><a class="page-link" href="?page=<?php echo $i; ?>"><?php echo $i; ?></a></li>
|
||||
<?php endfor; ?>
|
||||
|
||||
<?php if ($page < $total_pages): ?>
|
||||
<li class="page-item"><a class="page-link" href="?page=<?php echo $page + 1; ?>">Next</a></li>
|
||||
<?php endif; ?>
|
||||
</ul>
|
||||
</nav>
|
||||
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
BIN
assets/pasted-20251025-190102-dd19def2.png
Normal file
BIN
assets/pasted-20251025-190102-dd19def2.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 153 KiB |
@ -1,26 +1,29 @@
|
||||
<?php
|
||||
session_start();
|
||||
require_once 'db/config.php';
|
||||
|
||||
// If the user is not logged in as admin, do nothing.
|
||||
if (!isset($_SESSION['user']) || $_SESSION['user'] !== 'admin') {
|
||||
header('HTTP/1.1 403 Forbidden');
|
||||
header('Location: login.php');
|
||||
exit;
|
||||
}
|
||||
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['id'])) {
|
||||
require_once 'db/config.php';
|
||||
try {
|
||||
$pdo = db();
|
||||
$stmt = $pdo->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;
|
||||
|
||||
115
edit_attendee.php
Normal file
115
edit_attendee.php
Normal file
@ -0,0 +1,115 @@
|
||||
<?php
|
||||
session_start();
|
||||
require_once 'db/config.php';
|
||||
|
||||
// If the user is not logged in as admin, redirect to the login page.
|
||||
if (!isset($_SESSION['user']) || $_SESSION['user'] !== 'admin') {
|
||||
header('Location: login.php');
|
||||
exit;
|
||||
}
|
||||
|
||||
$attendee = null;
|
||||
$message = '';
|
||||
|
||||
if (!isset($_GET['id']) && $_SERVER['REQUEST_METHOD'] !== 'POST') {
|
||||
header('Location: admin.php');
|
||||
exit;
|
||||
}
|
||||
|
||||
$id = $_GET['id'] ?? $_POST['id'];
|
||||
|
||||
try {
|
||||
$pdo = db();
|
||||
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
// Update logic
|
||||
$fields = ['first_name', 'last_name', 'email', 'company', 'how_did_you_hear', 'consented'];
|
||||
$sql = 'UPDATE attendees SET ';
|
||||
$params = [];
|
||||
foreach ($fields as $field) {
|
||||
if (isset($_POST[$field])) {
|
||||
$sql .= "$field = ?, ";
|
||||
$params[] = $_POST[$field];
|
||||
}
|
||||
}
|
||||
$sql = rtrim($sql, ', ') . ' WHERE id = ?';
|
||||
$params[] = $_POST['id'];
|
||||
|
||||
$stmt = $pdo->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());
|
||||
}
|
||||
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Edit Attendee</title>
|
||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
|
||||
<style>
|
||||
body {
|
||||
background-color: #121212;
|
||||
color: #e0e0e0;
|
||||
}
|
||||
.container {
|
||||
max-width: 600px;
|
||||
padding-top: 2rem;
|
||||
}
|
||||
h1 {
|
||||
color: #ffd700;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="container">
|
||||
<h1 class="mb-4">Edit Attendee #<?= htmlspecialchars($attendee['id']) ?></h1>
|
||||
<form method="POST">
|
||||
<input type="hidden" name="id" value="<?= htmlspecialchars($attendee['id']) ?>">
|
||||
<div class="mb-3">
|
||||
<label for="first_name" class="form-label">First Name</label>
|
||||
<input type="text" class="form-control" id="first_name" name="first_name" value="<?= htmlspecialchars($attendee['first_name']) ?>">
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="last_name" class="form-label">Last Name</label>
|
||||
<input type="text" class="form-control" id="last_name" name="last_name" value="<?= htmlspecialchars($attendee['last_name']) ?>">
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="email" class="form-label">Email</label>
|
||||
<input type="email" class="form-control" id="email" name="email" value="<?= htmlspecialchars($attendee['email']) ?>">
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="company" class="form-label">Company</label>
|
||||
<input type="text" class="form-control" id="company" name="company" value="<?= htmlspecialchars($attendee['company']) ?>">
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="how_did_you_hear" class="form-label">How did you hear?</label>
|
||||
<input type="text" class="form-control" id="how_did_you_hear" name="how_did_you_hear" value="<?= htmlspecialchars($attendee['how_did_you_hear']) ?>">
|
||||
</div>
|
||||
<div class="mb-3 form-check">
|
||||
<input type="hidden" name="consented" value="0">
|
||||
<input type="checkbox" class="form-check-input" id="consented" name="consented" value="1" <?= $attendee['consented'] ? 'checked' : '' ?>>
|
||||
<label class="form-check-label" for="consented">Consented</label>
|
||||
</div>
|
||||
<button type="submit" class="btn btn-primary">Save Changes</button>
|
||||
<a href="admin.php" class="btn btn-secondary">Cancel</a>
|
||||
</form>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
37
export_csv.php
Normal file
37
export_csv.php
Normal file
@ -0,0 +1,37 @@
|
||||
<?php
|
||||
session_start();
|
||||
require_once 'db/config.php';
|
||||
|
||||
// Check if user is admin
|
||||
if (!isset($_SESSION['user']) || $_SESSION['user'] !== 'admin') {
|
||||
http_response_code(403);
|
||||
echo "Forbidden";
|
||||
exit;
|
||||
}
|
||||
|
||||
$pdo = db();
|
||||
$stmt = $pdo->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;
|
||||
Loading…
x
Reference in New Issue
Block a user