From fd6af01e3c2f727446bcf76ca6bd7ca49126a132 Mon Sep 17 00:00:00 2001 From: Flatlogic Bot Date: Sat, 22 Nov 2025 11:23:43 +0000 Subject: [PATCH] v1 --- assets/css/custom.css | 27 ++ db/config.php | 29 ++ .../001_create_registrations_table.sql | 9 + delete.php | 25 ++ edit.php | 98 ++++++ index.php | 282 +++++++++--------- submit.php | 63 ++++ 7 files changed, 393 insertions(+), 140 deletions(-) create mode 100644 assets/css/custom.css create mode 100644 db/migrations/001_create_registrations_table.sql create mode 100644 delete.php create mode 100644 edit.php create mode 100644 submit.php diff --git a/assets/css/custom.css b/assets/css/custom.css new file mode 100644 index 0000000..a7f2eb2 --- /dev/null +++ b/assets/css/custom.css @@ -0,0 +1,27 @@ +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; +} diff --git a/db/config.php b/db/config.php index 7d8e021..f600023 100644 --- a/db/config.php +++ b/db/config.php @@ -15,3 +15,32 @@ function db() { } 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(); diff --git a/db/migrations/001_create_registrations_table.sql b/db/migrations/001_create_registrations_table.sql new file mode 100644 index 0000000..644aa75 --- /dev/null +++ b/db/migrations/001_create_registrations_table.sql @@ -0,0 +1,9 @@ +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 +); diff --git a/delete.php b/delete.php new file mode 100644 index 0000000..a745774 --- /dev/null +++ b/delete.php @@ -0,0 +1,25 @@ +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; diff --git a/edit.php b/edit.php new file mode 100644 index 0000000..6d15d70 --- /dev/null +++ b/edit.php @@ -0,0 +1,98 @@ +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.'; + } + } +} + +?> + + + + + + Edit Registration + + + + +
+
+
+
+
+

Edit Registration

+
+
+ +
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+ + Cancel +
+ +
+
+
+
+
+ + + diff --git a/index.php b/index.php index 7205f3d..47d5eb3 100644 --- a/index.php +++ b/index.php @@ -1,150 +1,152 @@ query('SELECT * FROM registrations ORDER BY created_at DESC'); +$registrations = $stmt->fetchAll(); -$phpVersion = PHP_VERSION; -$now = date('Y-m-d H:i:s'); ?> - + - - - New Style - - - - - - - - - - - - - - - - - - - + + + Registration App + + + -
-
-

Analyzing your requirements and generating your website…

-
- Loading… -
-

AI is collecting your requirements and applying the first changes.

-

This page will update automatically as the plan is implemented.

-

Runtime: PHP — UTC

+ +
+
+

Registration App

+

A simple application to manage registrations.

-
- + + +
+
+
+
+
+

New Registration

+
+
+ +
+ + +
+ + +
+
+ + +
Full Name is required.
+
+
+ + +
A valid Email is required.
+
+
+ + +
Mobile Number is required.
+
+
+ + +
+ +
+
+
+
+ +
+
+
+

Registered Users

+
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + +
NameEmailMobileActions
No registrations yet.
+ + +
+
+
+
+
+
+
+ + + + + + diff --git a/submit.php b/submit.php new file mode 100644 index 0000000..a331fa5 --- /dev/null +++ b/submit.php @@ -0,0 +1,63 @@ +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 = "

A new registration has been submitted:

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

Thank you for registering.

+

You can edit or delete your registration using this link: {$edit_link}

"; + 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; +}