Compare commits

..

No commits in common. "ai-dev" and "master" have entirely different histories.

7 changed files with 140 additions and 393 deletions

View File

@ -1,27 +0,0 @@
body {
background-color: #F5F5F5;
}
.gradient-header {
background: linear-gradient(to right, #1976D2, #42A5F5);
color: white;
}
.card {
border-radius: 0.375rem;
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}
.btn-primary {
background-color: #1976D2;
border-color: #1976D2;
}
.btn-primary:hover {
background-color: #1565C0;
border-color: #1565C0;
}
.table {
background-color: #FFFFFF;
}

View File

@ -15,32 +15,3 @@ function db() {
} }
return $pdo; return $pdo;
} }
function run_migrations() {
$pdo = db();
$migrations_dir = __DIR__ . '/migrations';
if (!is_dir($migrations_dir)) {
return;
}
$migration_files = glob($migrations_dir . '/*.sql');
foreach ($migration_files as $file) {
$p = pathinfo($file);
$migration_name = $p['basename'];
try {
$stmt = $pdo->query("SELECT 1 FROM migrations WHERE name = '$migration_name'");
if ($stmt->fetchColumn()) {
continue;
}
} catch (PDOException $e) {
// migrations table doesn't exist, create it
$pdo->exec("CREATE TABLE IF NOT EXISTS migrations (name VARCHAR(255) PRIMARY KEY, created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP)");
}
$sql = file_get_contents($file);
$pdo->exec($sql);
$stmt = $pdo->prepare("INSERT INTO migrations (name) VALUES (?)");
$stmt->execute([$migration_name]);
}
}
run_migrations();

View File

@ -1,9 +0,0 @@
CREATE TABLE IF NOT EXISTS registrations (
id INT AUTO_INCREMENT PRIMARY KEY,
fullname VARCHAR(255) NOT NULL,
email VARCHAR(255) NOT NULL,
mobile_no VARCHAR(50) NOT NULL,
job_description TEXT,
edit_token VARCHAR(255) NOT NULL UNIQUE,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);

View File

@ -1,25 +0,0 @@
<?php
require_once 'db/config.php';
session_start();
if (isset($_GET['token'])) {
$token = $_GET['token'];
try {
$pdo = db();
$stmt = $pdo->prepare('DELETE FROM registrations WHERE edit_token = ?');
$stmt->execute([$token]);
if ($stmt->rowCount() > 0) {
$_SESSION['success_message'] = 'Registration deleted successfully.';
} else {
$_SESSION['error_message'] = 'Invalid token or registration already deleted.';
}
} catch (PDOException $e) {
error_log($e->getMessage());
$_SESSION['error_message'] = 'An error occurred.';
}
}
header('Location: index.php');
exit;

View File

@ -1,98 +0,0 @@
<?php
require_once 'db/config.php';
session_start();
$registration = null;
$error = '';
if (isset($_GET['token'])) {
$token = $_GET['token'];
$pdo = db();
$stmt = $pdo->prepare('SELECT * FROM registrations WHERE edit_token = ?');
$stmt->execute([$token]);
$registration = $stmt->fetch();
if (!$registration) {
$error = 'Invalid registration token.';
}
} else {
$error = 'No token provided.';
}
if ($_SERVER['REQUEST_METHOD'] === 'POST' && $registration) {
$fullname = trim($_POST['fullname'] ?? '');
$email = trim($_POST['email'] ?? '');
$mobile_no = trim($_POST['mobile_no'] ?? '');
$job_description = trim($_POST['job_description'] ?? '');
if (empty($fullname) || empty($email) || empty($mobile_no)) {
$error = 'Full Name, Email, and Mobile Number are required.';
} elseif (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
$error = 'Invalid email format.';
} else {
try {
$stmt = $pdo->prepare(
'UPDATE registrations SET fullname = ?, email = ?, mobile_no = ?, job_description = ? WHERE id = ?'
);
$stmt->execute([$fullname, $email, $mobile_no, $job_description, $registration['id']]);
$_SESSION['success_message'] = 'Registration updated successfully!';
header('Location: index.php');
exit;
} catch (PDOException $e) {
error_log($e->getMessage());
$error = 'An error occurred while updating.';
}
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Edit Registration</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
<link href="assets/css/custom.css" rel="stylesheet">
</head>
<body>
<div class="container mt-5">
<div class="row justify-content-center">
<div class="col-md-8">
<div class="card">
<div class="card-header gradient-header">
<h4>Edit Registration</h4>
</div>
<div class="card-body">
<?php if ($error): ?>
<div class="alert alert-danger"><?php echo htmlspecialchars($error); ?></div>
<?php endif; ?>
<?php if ($registration): ?>
<form action="edit.php?token=<?php echo htmlspecialchars($token); ?>" 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" value="<?php echo htmlspecialchars($registration['fullname']); ?>" required>
</div>
<div class="mb-3">
<label for="email" class="form-label">Email address</label>
<input type="email" class="form-control" id="email" name="email" value="<?php echo htmlspecialchars($registration['email']); ?>" required>
</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" value="<?php echo htmlspecialchars($registration['mobile_no']); ?>" required>
</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"><?php echo htmlspecialchars($registration['job_description']); ?></textarea>
</div>
<button type="submit" class="btn btn-primary">Update Registration</button>
<a href="index.php" class="btn btn-secondary">Cancel</a>
</form>
<?php endif; ?>
</div>
</div>
</div>
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>

276
index.php
View File

@ -1,152 +1,150 @@
<?php <?php
require_once 'db/config.php'; declare(strict_types=1);
session_start(); @ini_set('display_errors', '1');
@error_reporting(E_ALL);
$success_message = $_SESSION['success_message'] ?? null; @date_default_timezone_set('UTC');
$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();
$phpVersion = PHP_VERSION;
$now = date('Y-m-d H:i:s');
?> ?>
<!DOCTYPE html> <!doctype html>
<html lang="en"> <html lang="en">
<head> <head>
<meta charset="UTF-8"> <meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Registration App</title> <title>New Style</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet"> <?php
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.min.css"> // Read project preview data from environment
<link href="assets/css/custom.css?v=<?php echo time(); ?>" rel="stylesheet"> $projectDescription = $_SERVER['PROJECT_DESCRIPTION'] ?? '';
$projectImageUrl = $_SERVER['PROJECT_IMAGE_URL'] ?? '';
?>
<?php if ($projectDescription): ?>
<!-- Meta description -->
<meta name="description" content='<?= htmlspecialchars($projectDescription) ?>' />
<!-- Open Graph meta tags -->
<meta property="og:description" content="<?= htmlspecialchars($projectDescription) ?>" />
<!-- Twitter meta tags -->
<meta property="twitter:description" content="<?= htmlspecialchars($projectDescription) ?>" />
<?php endif; ?>
<?php if ($projectImageUrl): ?>
<!-- Open Graph image -->
<meta property="og:image" content="<?= htmlspecialchars($projectImageUrl) ?>" />
<!-- Twitter image -->
<meta property="twitter:image" content="<?= htmlspecialchars($projectImageUrl) ?>" />
<?php endif; ?>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;700&display=swap" rel="stylesheet">
<style>
:root {
--bg-color-start: #6a11cb;
--bg-color-end: #2575fc;
--text-color: #ffffff;
--card-bg-color: rgba(255, 255, 255, 0.01);
--card-border-color: rgba(255, 255, 255, 0.1);
}
body {
margin: 0;
font-family: 'Inter', sans-serif;
background: linear-gradient(45deg, var(--bg-color-start), var(--bg-color-end));
color: var(--text-color);
display: flex;
justify-content: center;
align-items: center;
min-height: 100vh;
text-align: center;
overflow: hidden;
position: relative;
}
body::before {
content: '';
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-image: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="100" height="100" viewBox="0 0 100 100"><path d="M-10 10L110 10M10 -10L10 110" stroke-width="1" stroke="rgba(255,255,255,0.05)"/></svg>');
animation: bg-pan 20s linear infinite;
z-index: -1;
}
@keyframes bg-pan {
0% { background-position: 0% 0%; }
100% { background-position: 100% 100%; }
}
main {
padding: 2rem;
}
.card {
background: var(--card-bg-color);
border: 1px solid var(--card-border-color);
border-radius: 16px;
padding: 2rem;
backdrop-filter: blur(20px);
-webkit-backdrop-filter: blur(20px);
box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.1);
}
.loader {
margin: 1.25rem auto 1.25rem;
width: 48px;
height: 48px;
border: 3px solid rgba(255, 255, 255, 0.25);
border-top-color: #fff;
border-radius: 50%;
animation: spin 1s linear infinite;
}
@keyframes spin {
from { transform: rotate(0deg); }
to { transform: rotate(360deg); }
}
.hint {
opacity: 0.9;
}
.sr-only {
position: absolute;
width: 1px; height: 1px;
padding: 0; margin: -1px;
overflow: hidden;
clip: rect(0, 0, 0, 0);
white-space: nowrap; border: 0;
}
h1 {
font-size: 3rem;
font-weight: 700;
margin: 0 0 1rem;
letter-spacing: -1px;
}
p {
margin: 0.5rem 0;
font-size: 1.1rem;
}
code {
background: rgba(0,0,0,0.2);
padding: 2px 6px;
border-radius: 4px;
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
footer {
position: absolute;
bottom: 1rem;
font-size: 0.8rem;
opacity: 0.7;
}
</style>
</head> </head>
<body> <body>
<main>
<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">
<div class="card-header"> <h1>Analyzing your requirements and generating your website…</h1>
<h4><i class="bi bi-person-plus-fill"></i> New Registration</h4> <div class="loader" role="status" aria-live="polite" aria-label="Applying initial changes">
<span class="sr-only">Loading…</span>
</div> </div>
<div class="card-body"> <p class="hint"><?= ($_SERVER['HTTP_HOST'] ?? '') === 'appwizzy.com' ? 'AppWizzy' : 'Flatlogic' ?> AI is collecting your requirements and applying the first changes.</p>
<?php if ($success_message): ?> <p class="hint">This page will update automatically as the plan is implemented.</p>
<div class="alert alert-success" id="flash-success"><?php echo htmlspecialchars($success_message); ?></div> <p>Runtime: PHP <code><?= htmlspecialchars($phpVersion) ?></code> — UTC <code><?= htmlspecialchars($now) ?></code></p>
<?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>
<div class="mb-3"> </main>
<label for="email" class="form-label">Email address</label> <footer>
<input type="email" class="form-control" id="email" name="email" required> Page updated: <?= htmlspecialchars($now) ?> (UTC)
<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> </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> </body>
</html> </html>

View File

@ -1,63 +0,0 @@
<?php
require_once 'db/config.php';
require_once 'mail/MailService.php';
session_start();
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$fullname = trim($_POST['fullname'] ?? '');
$email = trim($_POST['email'] ?? '');
$mobile_no = trim($_POST['mobile_no'] ?? '');
$job_description = trim($_POST['job_description'] ?? '');
// Validation
if (empty($fullname) || empty($email) || empty($mobile_no)) {
$_SESSION['error_message'] = 'Full Name, Email, and Mobile Number are required.';
header('Location: index.php');
exit;
}
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
$_SESSION['error_message'] = 'Invalid email format.';
header('Location: index.php');
exit;
}
$edit_token = bin2hex(random_bytes(32));
try {
$pdo = db();
$stmt = $pdo->prepare(
'INSERT INTO registrations (fullname, email, mobile_no, job_description, edit_token) VALUES (?, ?, ?, ?, ?)'
);
$stmt->execute([$fullname, $email, $mobile_no, $job_description, $edit_token]);
$_SESSION['success_message'] = 'Registration successful!';
// Send admin notification
$admin_email = getenv('MAIL_TO') ?: 'admin@example.com'; // Fallback
$admin_subject = 'New Registration Submitted';
$admin_body = "<p>A new registration has been submitted:</p>
<ul>
<li><strong>Name:</strong> " . htmlspecialchars($fullname) . "</li>
<li><strong>Email:</strong> " . htmlspecialchars($email) . "</li>
<li><strong>Mobile:</strong> " . htmlspecialchars($mobile_no) . "</li>
</ul>";
MailService::sendMail($admin_email, $admin_subject, $admin_body, strip_tags($admin_body));
// Send user the edit link
$edit_link = "http://{$_SERVER['HTTP_HOST']}/edit.php?token={$edit_token}";
$user_subject = 'Your Registration Details';
$user_body = "<p>Thank you for registering.</p>
<p>You can edit or delete your registration using this link: <a href='{$edit_link}'>{$edit_link}</a></p>";
MailService::sendMail($email, $user_subject, $user_body, strip_tags($user_body));
} catch (PDOException $e) {
error_log($e->getMessage());
$_SESSION['error_message'] = 'An error occurred. Please try again.';
}
header('Location: index.php');
exit;
}