From 38881c7a8f95373418e591d79547d0aa98d81514 Mon Sep 17 00:00:00 2001 From: Flatlogic Bot Date: Thu, 18 Sep 2025 10:46:41 +0000 Subject: [PATCH] fully working 1st version --- assets/css/custom.css | 33 ++++++ assets/js/main.js | 36 +++++++ index.php | 242 ++++++++++++++++++++---------------------- results.php | 92 ++++++++++++++++ submit_vote.php | 60 +++++++++++ 5 files changed, 338 insertions(+), 125 deletions(-) create mode 100644 assets/css/custom.css create mode 100644 assets/js/main.js create mode 100644 results.php create mode 100644 submit_vote.php diff --git a/assets/css/custom.css b/assets/css/custom.css new file mode 100644 index 0000000..fda36cc --- /dev/null +++ b/assets/css/custom.css @@ -0,0 +1,33 @@ +:root { + --primary-color: #4F46E5; + --secondary-color: #10B981; + --background-color: #F9FAFB; + --surface-color: #FFFFFF; + --text-color: #1F2937; +} + +body { + background-color: var(--background-color); + color: var(--text-color); + font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif; +} + +.btn-primary { + background-color: var(--primary-color); + border-color: var(--primary-color); +} + +.btn-secondary { + background-color: var(--secondary-color); + border-color: var(--secondary-color); +} + +.card { + border-radius: 0.75rem; + box-shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1); +} + +header { + background-image: linear-gradient(to right, var(--primary-color), var(--secondary-color)); + color: white; +} diff --git a/assets/js/main.js b/assets/js/main.js new file mode 100644 index 0000000..fb33baa --- /dev/null +++ b/assets/js/main.js @@ -0,0 +1,36 @@ +document.addEventListener('DOMContentLoaded', function () { + const beautifulForm = document.getElementById('beautiful-form'); + const funnyForm = document.getElementById('funny-form'); + const toastLiveExample = document.getElementById('liveToast'); + const toast = new bootstrap.Toast(toastLiveExample); + + const handleFormSubmit = (form, event) => { + event.preventDefault(); + const formData = new FormData(form); + const data = Object.fromEntries(formData.entries()); + + fetch('submit_vote.php', { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + body: JSON.stringify(data), + }) + .then(response => response.json()) + .then(data => { + if (data.success) { + toast.show(); + form.reset(); + } else { + alert('Error: ' + data.error); + } + }) + .catch((error) => { + console.error('Error:', error); + alert('An error occurred while submitting your votes.'); + }); + }; + + beautifulForm.addEventListener('submit', (event) => handleFormSubmit(beautifulForm, event)); + funnyForm.addEventListener('submit', (event) => handleFormSubmit(funnyForm, event)); +}); diff --git a/index.php b/index.php index e13ae95..6bb97ab 100644 --- a/index.php +++ b/index.php @@ -1,131 +1,123 @@ - - + - - - New Style - - - - + + + Flatlogic Website Awards + + -
-
-

Analyzing your requirements and generating your website…

-
- Loading… -
-

Flatlogic AI is collecting your requirements and applying the first changes.

-

This page will update automatically as the plan is implemented.

-

Runtime: PHP — UTC

+ +
+
+

Flatlogic Website Awards

+

Vote for the most beautiful and most funny/interesting websites!

+
+
+ +
+ +
+
+
+ An aesthetically pleasing abstract design. +
+

Most Beautiful Website

+
+
+ + +
+
+ + + + +
+ + +
+
+
+
+
+
+ A quirky and amusing abstract design. +
+

Most Funny/Interesting Website

+
+
+ + +
+
+ + + + +
+ + +
+
+
+
+
+
+ +
+

View Results

+

© 2025 Flatlogic. All rights reserved.

+
+ +
+
-
- + + + - + \ No newline at end of file diff --git a/results.php b/results.php new file mode 100644 index 0000000..1aab1f0 --- /dev/null +++ b/results.php @@ -0,0 +1,92 @@ +exec('TRUNCATE TABLE votes'); + $message = 'All votes have been cleared.'; + } + else { + if (!isset($_SESSION['loggedin']) || !$_SESSION['loggedin']) { + $error = 'Invalid password'; + } + } +} + +if (isset($_GET['logout'])) { + session_destroy(); + header('Location: results.php'); + exit; +} + +if (isset($_SESSION['loggedin']) && $_SESSION['loggedin']) { + // Display results + echo '

Voting Results

'; + if ($message) { + echo "

$message

"; + } + // Database connection + require_once 'db/config.php'; + $pdo = db(); + + // Fetch results + $stmt = $pdo->query('SELECT category, website_number, COUNT(*) as votes FROM votes GROUP BY category, website_number ORDER BY category, votes DESC'); + $results = $stmt->fetchAll(PDO::FETCH_ASSOC); + + echo '

Most Beautiful Website

'; + echo ''; + + echo '

Most Funny/Interesting Website

'; + echo ''; + + echo '
'; + echo '
Logout'; + +} else { + // Display password form + ?> + + + + View Results + + +

Enter Password to View Results

+
+ + +
+ +

+ + + + \ No newline at end of file diff --git a/submit_vote.php b/submit_vote.php new file mode 100644 index 0000000..b7a6edb --- /dev/null +++ b/submit_vote.php @@ -0,0 +1,60 @@ +exec($sql); +} catch (PDOException $e) { + echo json_encode(['success' => false, 'error' => 'Database error: ' . $e->getMessage()]); + exit; +} + +$data = json_decode(file_get_contents('php://input'), true); + +if (!$data) { + echo json_encode(['success' => false, 'error' => 'Invalid input']); + exit; +} + +$voterName = $data['voter_name'] ?? ''; +$category = $data['category'] ?? ''; +$website_numbers = [ + $data['website_number_1'] ?? 0, + $data['website_number_2'] ?? 0, + $data['website_number_3'] ?? 0, +]; + +if (empty($voterName) || empty($category) || !in_array($category, ['beauty', 'funny'])) { + echo json_encode(['success' => false, 'error' => 'Invalid data provided.']); + exit; +} + +try { + $pdo = db(); + $stmt = $pdo->prepare("INSERT INTO votes (voter_name, category, website_number) VALUES (:voter_name, :category, :website_number)"); + + foreach ($website_numbers as $number) { + if ($number >= 1 && $number <= 30) { + $stmt->execute([ + ':voter_name' => $voterName, + ':category' => $category, + ':website_number' => $number + ]); + } + } + + echo json_encode(['success' => true]); +} catch (PDOException $e) { + echo json_encode(['success' => false, 'error' => 'Database error: ' . $e->getMessage()]); +}