35995-vm/index.php
Flatlogic Bot fd6af01e3c v1
2025-11-22 11:23:43 +00:00

153 lines
6.9 KiB
PHP

<?php
require_once 'db/config.php';
session_start();
$success_message = $_SESSION['success_message'] ?? null;
$error_message = $_SESSION['error_message'] ?? null;
// Clear session messages
if (isset($_SESSION['success_message'])) unset($_SESSION['success_message']);
if (isset($_SESSION['error_message'])) unset($_SESSION['error_message']);
$pdo = db();
$stmt = $pdo->query('SELECT * FROM registrations ORDER BY created_at DESC');
$registrations = $stmt->fetchAll();
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Registration App</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.min.css">
<link href="assets/css/custom.css?v=<?php echo time(); ?>" rel="stylesheet">
</head>
<body>
<header class="p-5 mb-4 gradient-header text-white text-center">
<div class="container-fluid py-5">
<h1 class="display-5 fw-bold">Registration App</h1>
<p class="fs-4">A simple application to manage registrations.</p>
</div>
</header>
<div class="container">
<div class="row">
<div class="col-md-5 mb-4">
<div class="card">
<div class="card-header">
<h4><i class="bi bi-person-plus-fill"></i> New Registration</h4>
</div>
<div class="card-body">
<?php if ($success_message): ?>
<div class="alert alert-success" id="flash-success"><?php echo htmlspecialchars($success_message); ?></div>
<?php endif; ?>
<?php if ($error_message): ?>
<div class="alert alert-danger" id="flash-error"><?php echo htmlspecialchars($error_message); ?></div>
<?php endif; ?>
<form action="submit.php" method="POST" class="needs-validation" novalidate>
<div class="mb-3">
<label for="fullname" class="form-label">Full Name</label>
<input type="text" class="form-control" id="fullname" name="fullname" required>
<div class="invalid-feedback">Full Name is required.</div>
</div>
<div class="mb-3">
<label for="email" class="form-label">Email address</label>
<input type="email" class="form-control" id="email" name="email" required>
<div class="invalid-feedback">A valid Email is required.</div>
</div>
<div class="mb-3">
<label for="mobile_no" class="form-label">Mobile Number</label>
<input type="text" class="form-control" id="mobile_no" name="mobile_no" required>
<div class="invalid-feedback">Mobile Number is required.</div>
</div>
<div class="mb-3">
<label for="job_description" class="form-label">Job Description</label>
<textarea class="form-control" id="job_description" name="job_description" rows="3"></textarea>
</div>
<button type="submit" class="btn btn-primary w-100">Register</button>
</form>
</div>
</div>
</div>
<div class="col-md-7">
<div class="card">
<div class="card-header">
<h4><i class="bi bi-list-ul"></i> Registered Users</h4>
</div>
<div class="card-body">
<div class="table-responsive">
<table class="table table-striped table-hover">
<thead>
<tr>
<th>Name</th>
<th>Email</th>
<th>Mobile</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
<?php if (empty($registrations)): ?>
<tr>
<td colspan="4" class="text-center">No registrations yet.</td>
</tr>
<?php else: ?>
<?php foreach ($registrations as $reg): ?>
<tr>
<td><?php echo htmlspecialchars($reg['fullname']); ?></td>
<td><?php echo htmlspecialchars($reg['email']); ?></td>
<td><?php echo htmlspecialchars($reg['mobile_no']); ?></td>
<td>
<a href="edit.php?token=<?php echo htmlspecialchars($reg['edit_token']); ?>" class="btn btn-sm btn-outline-primary"><i class="bi bi-pencil-fill"></i></a>
<a href="delete.php?token=<?php echo htmlspecialchars($reg['edit_token']); ?>" class="btn btn-sm btn-outline-danger" onclick="return confirm('Are you sure you want to delete this registration?');"><i class="bi bi-trash-fill"></i></a>
</td>
</tr>
<?php endforeach; ?>
<?php endif; ?>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
</div>
<footer class="py-4 mt-5 text-center text-muted">
<p>Copyright &copy; <?php echo date('Y'); ?> Registration App</p>
</footer>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
<script>
// Bootstrap form validation
(function () {
'use strict'
var forms = document.querySelectorAll('.needs-validation')
Array.prototype.slice.call(forms)
.forEach(function (form) {
form.addEventListener('submit', function (event) {
if (!form.checkValidity()) {
event.preventDefault()
event.stopPropagation()
}
form.classList.add('was-validated')
}, false)
})
})()
// Auto-hide flash messages
setTimeout(function() {
let success = document.getElementById('flash-success');
if (success) success.style.display = 'none';
let error = document.getElementById('flash-error');
if (error) error.style.display = 'none';
}, 3000);
</script>
</body>
</html>