From 42c54ec652d28dd4a5408f67f896d8f696f75be9 Mon Sep 17 00:00:00 2001 From: bckelley Date: Thu, 5 Jun 2025 12:06:45 -0500 Subject: [PATCH] updated todo-list to use SimplePHPDB --- .gitmodules | 3 ++ _config.yml | 1 - db | 1 + index.php | 97 ++++++++++++++++++++++++++++++++++++++-------- server.php | 39 ++++++++++++++++--- style.css | 109 ++++++++++++++++++++++++++++++++++++++++++++-------- 6 files changed, 211 insertions(+), 39 deletions(-) create mode 100644 .gitmodules delete mode 100644 _config.yml create mode 160000 db diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..62a0672 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "db"] + path = db + url = https://github.com/bckelley/SimplePHPDB.git diff --git a/_config.yml b/_config.yml deleted file mode 100644 index 2f7efbe..0000000 --- a/_config.yml +++ /dev/null @@ -1 +0,0 @@ -theme: jekyll-theme-minimal \ No newline at end of file diff --git a/db b/db new file mode 160000 index 0000000..f3f6a5a --- /dev/null +++ b/db @@ -0,0 +1 @@ +Subproject commit f3f6a5a7de98a628511f3bd3c34170faeba43942 diff --git a/index.php b/index.php index c272c76..95be2ee 100644 --- a/index.php +++ b/index.php @@ -2,10 +2,12 @@ if (isset($_GET['edit'])) { $id = $_GET['edit']; $update = true; - $record = mysqli_query($db, "SELECT * FROM tasks WHERE id=".$id); - if ( $record ) { - $n = mysqli_fetch_array($record); - $task = $n['task']; + $row = $db->getRows("`todo-tasks`", ['where' => ['id' => $id]]); + if ( $row ) { + + foreach ( $row as $r ) { + $task = $r['task']; + } } } ?> @@ -17,6 +19,8 @@ Document + +

ToDo List

@@ -43,7 +47,7 @@ - + getRows("`todo-tasks`"); ?> @@ -52,20 +56,81 @@ - + - - - - - - + + + + + + + + +
Action
- Edit - - Delete -
+ + + + + Edit + Delete +
No tasks available.
+ + + \ No newline at end of file diff --git a/server.php b/server.php index 07674a5..69ef17e 100644 --- a/server.php +++ b/server.php @@ -1,7 +1,9 @@ $task]; + $insertId = $db->insert("`todo-tasks`", $data); + + if ($insertId) { + $_SESSION['message'] = "Task Added"; + } - $_SESSION['message'] = "Task Added"; header('Location: index.php'); } + +if ( isset($_POST['action']) && $_POST['action'] === 'update' ) { + $taskId = $_POST['taskId']; + $isCompleted = isset($_POST['isCompleted']) === 'true' ? 1 : 0; + + $data = ['isCompleted' => $isCompleted]; + $cond = ['id' => $taskId]; + + $updateRow = $db->update("`todo-tasks`", $data, $cond); + if ($updateRow) { + $_SESSION['message'] = "Task Status Updated!"; + } +} + if (isset($_POST['update'])) { $id = $_POST['id']; $task = $_POST['task']; - mysqli_query($db, "UPDATE tasks SET task='$task' WHERE id='$id'"); + $data = ['task' => $task]; + $cond = ['id' => $id]; + $updateRow = $db->update("`todo-tasks`", $data, $cond); + + if ($updateRow) { + $_SESSION['message'] = "Task Updated!"; + } - $_SESSION['message'] = "Task Updated!"; header('location: index.php'); + exit(); } + if (isset($_GET['del'])) { $id = $_GET['del']; - mysqli_query($db, "DELETE FROM tasks WHERE id='$id'"); + // mysqli_query($db, "DELETE FROM tasks WHERE id='$id'"); $_SESSION['message'] = "Task Removed!"; header('Location: index.php'); } \ No newline at end of file diff --git a/style.css b/style.css index a74a0ed..c6f4f07 100644 --- a/style.css +++ b/style.css @@ -1,27 +1,69 @@ +:root { + --text-color: black; + --background-color: white; + --border-color: #cbcbcb; + --hover-background: #F5F5F5; + --form-border-color: #bbbbbb; + --input-border-color: gray; + --btn-background: #5F9EA0; + --edit-btn-background: #5F9EA0; + --del-btn-background: #800000; + --msg-background: #dff0d8; + --msg-border-color: #3c763d; + --msg-text-color: #3c763d; +} + +@media (prefers-color-scheme: dark) { + :root { + --text-color: white; + --background-color: #393939; + --border-color: #4a4a4a; + --hover-background: #3a3a3a; + --form-border-color: #6b6b6b; + --input-border-color: #6b6b6b; + --btn-background: #5d7d59; + --edit-btn-background: #5d7d59; + --del-btn-background: #800000; + --msg-background: #3a3a3a; + --msg-border-color: #6b6b6b; + --msg-text-color: white; + } +} + body { font-size: 19px; font-family: 'Arial'; + color: var(--text-color); + background-color: var(--background-color); } + h2 { width: 45%; margin: 50px auto; + color: var(--text-color); } -table{ + +table { width: 50%; margin: 30px auto; border-collapse: collapse; text-align: left; + color: var(--text-color); } + tr { - border-bottom: 1px solid #cbcbcb; + border-bottom: 1px solid var(--border-color); } -th, td{ + +th, td { border: none; height: 30px; padding: 2px; + color: var(--text-color); } + tr:hover { - background: #F5F5F5; + background: var(--hover-background); } form { @@ -29,56 +71,91 @@ form { margin: 50px auto; text-align: left; padding: 20px; - border: 1px solid #bbbbbb; + border: 1px solid var(--form-border-color); border-radius: 5px; + background-color: var(--background-color); } .input-group { margin: 10px 0px 10px 0px; } + .input-group label { display: block; text-align: left; margin: 3px; + color: var(--text-color); } + .input-group input { height: 30px; width: 93%; padding: 5px 10px; font-size: 16px; border-radius: 5px; - border: 1px solid gray; + border: 1px solid var(--input-border-color); + background-color: var(--background-color); + color: var(--text-color); } + +.task-list { + cursor:default ; +} + +.strike { + text-decoration: line-through; +} + .btn { padding: 10px; font-size: 15px; color: white; - background: #5F9EA0; + background: var(--btn-background); border: none; border-radius: 5px; } + +.btn:hover { + filter: brightness(85%); +} + +.btn-group { width: 25%; } + .edit_btn { text-decoration: none; - padding: 2px 5px; - background: #2E8B57; + padding: 10px; + font-size: 16px; + background: var(--edit-btn-background); color: white; - border-radius: 3px; + border-radius: 5px; + width: 50%; +} + +.edit_btn:hover { + filter: brightness(85%); } .del_btn { text-decoration: none; - padding: 2px 5px; + padding: 10px; + font-size: 16px; color: white; - border-radius: 3px; - background: #800000; + border-radius: 5px; + background: var(--del-btn-background); + width: 50%; } + +.del_btn:hover { + filter: brightness(85%); +} + .msg { margin: 30px auto; padding: 10px; border-radius: 5px; - color: #3c763d; - background: #dff0d8; - border: 1px solid #3c763d; + color: var(--msg-text-color); + background: var(--msg-background); + border: 1px solid var(--msg-border-color); width: 50%; text-align: center; } \ No newline at end of file