From 90859a47ee4251bca5df219d525cd359c0c12e2a Mon Sep 17 00:00:00 2001 From: 5803024011 Date: Fri, 29 Aug 2025 02:45:46 -0400 Subject: [PATCH] Upload files to "/" --- todolist.php | 791 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 791 insertions(+) create mode 100644 todolist.php diff --git a/todolist.php b/todolist.php new file mode 100644 index 0000000..33ba293 --- /dev/null +++ b/todolist.php @@ -0,0 +1,791 @@ + PDO::ERRMODE_EXCEPTION, + PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC + ]); + + // Create tables if they don't exist + $create_groups_table = "CREATE TABLE IF NOT EXISTS groups ( + group_id SERIAL PRIMARY KEY, + group_name VARCHAR(100) NOT NULL + )"; + + $create_tasks_table = "CREATE TABLE IF NOT EXISTS tasks ( + task_id SERIAL PRIMARY KEY, + task_name VARCHAR(255) NOT NULL, + task_description TEXT, + group_id INTEGER NOT NULL, + is_done BOOLEAN DEFAULT FALSE, + created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, + FOREIGN KEY (group_id) REFERENCES groups(group_id) ON DELETE CASCADE + )"; + + $pdo->exec($create_groups_table); + $pdo->exec($create_tasks_table); + +} catch(PDOException $e) { + die("Connection failed: " . $e->getMessage()); +} + +// Handle form submissions +if ($_SERVER['REQUEST_METHOD'] == 'POST') { + if (isset($_POST['add_group'])) { + $group_name = trim($_POST['group_name']); + if (!empty($group_name)) { + $stmt = $pdo->prepare("INSERT INTO groups (group_name) VALUES (?)"); + $stmt->execute([$group_name]); + } + } + + if (isset($_POST['add_task'])) { + $task_name = trim($_POST['task_name']); + $task_description = trim($_POST['task_description']); + $group_id = $_POST['group_id']; + + if (!empty($task_name) && !empty($group_id)) { + $stmt = $pdo->prepare("INSERT INTO tasks (task_name, task_description, group_id) VALUES (?, ?, ?)"); + $stmt->execute([$task_name, $task_description, $group_id]); + } + } + + if (isset($_POST['update_task'])) { + $task_id = $_POST['task_id']; + $task_name = trim($_POST['task_name']); + $task_description = trim($_POST['task_description']); + $group_id = $_POST['group_id']; + + if (!empty($task_name) && !empty($group_id)) { + $stmt = $pdo->prepare("UPDATE tasks SET task_name = ?, task_description = ?, group_id = ? WHERE task_id = ?"); + $stmt->execute([$task_name, $task_description, $group_id, $task_id]); + } + } + + if (isset($_POST['toggle_task'])) { + $task_id = $_POST['task_id']; + $stmt = $pdo->prepare("UPDATE tasks SET is_done = NOT is_done WHERE task_id = ?"); + $stmt->execute([$task_id]); + } + + if (isset($_POST['delete_task'])) { + $task_id = $_POST['delete_task']; + $stmt = $pdo->prepare("DELETE FROM tasks WHERE task_id = ?"); + $stmt->execute([$task_id]); + } + + if (isset($_POST['delete_group'])) { + $group_id = $_POST['delete_group']; + $stmt = $pdo->prepare("DELETE FROM groups WHERE group_id = ?"); + $stmt->execute([$group_id]); + } + + // Redirect to prevent form resubmission + header("Location: " . $_SERVER['PHP_SELF']); + exit(); +} + +// Get task to edit if requested +$edit_task = null; +if (isset($_GET['edit_task'])) { + $task_id = $_GET['edit_task']; + $stmt = $pdo->prepare("SELECT * FROM tasks WHERE task_id = ?"); + $stmt->execute([$task_id]); + $edit_task = $stmt->fetch(PDO::FETCH_ASSOC); +} + +// Fetch groups and tasks organized by groups +$groups = $pdo->query("SELECT * FROM groups ORDER BY group_name")->fetchAll(PDO::FETCH_ASSOC); + +// Fetch tasks grouped by group_id +$tasks_by_group = []; +if (!empty($groups)) { + $stmt = $pdo->query("SELECT t.*, g.group_name FROM tasks t + JOIN groups g ON t.group_id = g.group_id + ORDER BY t.is_done ASC, t.created_at DESC"); + $all_tasks = $stmt->fetchAll(PDO::FETCH_ASSOC); + + foreach ($all_tasks as $task) { + $tasks_by_group[$task['group_id']][] = $task; + } +} + +// Calculate statistics +$total_tasks = 0; +$completed_tasks = 0; +foreach ($tasks_by_group as $tasks) { + foreach ($tasks as $task) { + $total_tasks++; + if ($task['is_done']) $completed_tasks++; + } +} +$pending_tasks = $total_tasks - $completed_tasks; +?> + + + + + + + Royal Todo List + + + +
+
+

+ + Royal Todo List + +

+

Manage your tasks with royal elegance

+
+
+ +
+
+ + Groups +
+
+ + Total Tasks +
+
+ + Completed +
+
+ + Pending +
+
+ + + +
+

♛ Edit Task

+
+ + +
+ + +
+ +
+ + +
+ +
+
+ + +
+
+ + Cancel +
+
+
+
+ + + +
+

♛ Create New Group

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

♜ Add New Task

+
+
+ + +
+ +
+ + +
+ +
+
+ + +
+
+ +
+
+
+
+ + + + +
+
+ 👑 + Your royal kingdom awaits! Create your first group to start organizing tasks. +
+
+ + +
+
+

+
+
+ +
+
+
+ +
+ +
+ No tasks in this group yet. Add some tasks to get started! +
+ + +
+
+ +
+

+ +

+
+ + +
+ +
+ + +
+ Created: + | Status: +
+ +
+
+ + +
+ + + ✎ Edit + + +
+ +
+
+
+ + +
+
+ + +
+ + + + \ No newline at end of file