diff --git a/add_task.php b/add_task.php new file mode 100644 index 0000000..d447b18 --- /dev/null +++ b/add_task.php @@ -0,0 +1,17 @@ +prepare("INSERT INTO todos (task) VALUES (?)"); + $stmt->execute([$task]); + $id = $pdo->lastInsertId(); + + echo json_encode(['success' => true, 'id' => $id]); + } else { + echo json_encode(['success' => false]); + } +} diff --git a/assets/css/custom.css b/assets/css/custom.css new file mode 100644 index 0000000..83ba61d --- /dev/null +++ b/assets/css/custom.css @@ -0,0 +1,40 @@ +body { + font-family: 'Poppins', sans-serif; + background-color: #F2F2F2; +} + +.hero-section { + position: relative; +} + +.hero-section img { + width: 100%; + height: 400px; + object-fit: cover; +} + +.hero-text { + position: absolute; + top: 50%; + left: 50%; + transform: translate(-50%, -50%); +} + +.card { + border-radius: 8px; +} + +.btn-primary { + background-color: #6C63FF; + border-color: #6C63FF; +} + +.btn-primary:hover { + background-color: #574fd8; + border-color: #574fd8; +} + +.list-group-item.done span { + text-decoration: line-through; + color: #aaa; +} diff --git a/assets/js/main.js b/assets/js/main.js new file mode 100644 index 0000000..cfdcf26 --- /dev/null +++ b/assets/js/main.js @@ -0,0 +1,85 @@ +document.addEventListener('DOMContentLoaded', function () { + const todoList = document.getElementById('todo-list'); + const addForm = document.getElementById('add-todo-form'); + const taskInput = document.getElementById('task-input'); + + addForm.addEventListener('submit', function (e) { + e.preventDefault(); + const taskText = taskInput.value.trim(); + if (taskText !== '') { + fetch('add_task.php', { + method: 'POST', + headers: { + 'Content-Type': 'application/x-www-form-urlencoded', + }, + body: `task=${encodeURIComponent(taskText)}` + }) + .then(response => response.json()) + .then(data => { + if (data.success) { + const newTodo = document.createElement('li'); + newTodo.className = 'list-group-item d-flex justify-content-between align-items-center'; + newTodo.dataset.id = data.id; + newTodo.innerHTML = ` + ${escapeHTML(taskText)} +
+ +
+ `; + todoList.prepend(newTodo); + taskInput.value = ''; + addEventListeners(newTodo); + } + }); + } + }); + + function addEventListeners(item) { + const doneBtn = item.querySelector('.done-btn'); + if (doneBtn) { + doneBtn.addEventListener('click', function () { + updateTask(item.dataset.id, 1, item); + }); + } + + const undoBtn = item.querySelector('.undo-btn'); + if (undoBtn) { + undoBtn.addEventListener('click', function () { + updateTask(item.dataset.id, 0, item); + }); + } + } + + function updateTask(id, isDone, item) { + fetch('update_task.php', { + method: 'POST', + headers: { + 'Content-Type': 'application/x-www-form-urlencoded', + }, + body: `id=${id}&is_done=${isDone}` + }) + .then(response => response.json()) + .then(data => { + if (data.success) { + item.classList.toggle('done'); + const buttonDiv = item.querySelector('div'); + if (isDone) { + buttonDiv.innerHTML = ''; + } else { + buttonDiv.innerHTML = ''; + } + addEventListeners(item); + } + }); + } + + document.querySelectorAll('.list-group-item').forEach(item => { + addEventListeners(item); + }); + + function escapeHTML(str) { + var p = document.createElement("p"); + p.appendChild(document.createTextNode(str)); + return p.innerHTML; + } +}); diff --git a/db/config.php b/db/config.php index d630275..0b22faf 100644 --- a/db/config.php +++ b/db/config.php @@ -1,17 +1,28 @@ PDO::ERRMODE_EXCEPTION, - PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC, - ]); - } - return $pdo; + $host = '127.0.0.1'; + $db = 'webapp'; + $user = 'webapp'; + $pass = 'webapp'; + $charset = 'utf8mb4'; + + $dsn = "mysql:host=$host;dbname=$db;charset=$charset"; + $options = [ + PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, + PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC, + PDO::ATTR_EMULATE_PREPARES => false, + ]; + try { + return new PDO($dsn, $user, $pass, $options); + } catch (\PDOException $e) { + throw new \PDOException($e->getMessage(), (int)$e->getCode()); + } } + +// Run migrations +$pdo = db(); +$migration_files = glob(__DIR__ . '/migrations/*.sql'); +foreach ($migration_files as $file) { + $pdo->exec(file_get_contents($file)); +} \ No newline at end of file diff --git a/db/migrations/001_create_todos_table.sql b/db/migrations/001_create_todos_table.sql new file mode 100644 index 0000000..00be35c --- /dev/null +++ b/db/migrations/001_create_todos_table.sql @@ -0,0 +1,8 @@ +CREATE TABLE IF NOT EXISTS todos ( + id INT AUTO_INCREMENT PRIMARY KEY, + task VARCHAR(255) NOT NULL, + is_done BOOLEAN NOT NULL DEFAULT 0, + guest_id INT, + warden_id INT, + created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP +); diff --git a/index.php b/index.php index e13ae95..8fab92b 100644 --- a/index.php +++ b/index.php @@ -1,131 +1,76 @@ query("SELECT * FROM todos ORDER BY created_at DESC"); +$todos = $stmt->fetchAll(); ?> - + - - - New Style - - - - + + + To-Do List + + + + + + -
-
-

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

+
+
+ A person organizing their tasks on a whiteboard. +
+

My To-Do List

+

Organize your life, one task at a time.

+
+
+ +
+
+
+
+
+

Add a new task

+
+
+ + +
+
+
+

Tasks

+
    + +
  • + +
    + + + + + +
    +
  • + +
+
+
+
+
+
+ A notebook and pen on a desk. +
+
+ A person checking off a to-do list on their phone. +
+
+
+
-
- + + + - + \ No newline at end of file diff --git a/update_task.php b/update_task.php new file mode 100644 index 0000000..fe372e7 --- /dev/null +++ b/update_task.php @@ -0,0 +1,13 @@ +prepare("UPDATE todos SET is_done = ? WHERE id = ?"); + $stmt->execute([$is_done, $id]); + + echo json_encode(['success' => true]); +}