diff --git a/index.php b/index.php index 84f8ec6..a5677b9 100644 --- a/index.php +++ b/index.php @@ -254,8 +254,14 @@ else if (!empty($_POST["action"])) { $action = $_POST["action"]; $modified = false; - if ($action === "add") + if ($action === "add" || $action == "edit") { + if (!empty($_POST["todo_item_id"])) + { + $id_to_edit = $_POST["todo_item_id"]; + } + + if (!empty($_POST["todo_title"])) { $title = $_POST["todo_title"]; @@ -285,7 +291,7 @@ else if (!empty($_POST["action"])) $model["list"] = array(); } - $model["list"][] = array( + $new_item = array( "title" => $title, "description" => $description, "deadline" => $deadline, @@ -294,6 +300,15 @@ else if (!empty($_POST["action"])) "modified" => $now, ); + if (!empty($id_to_edit) && !empty($model["list"][$id_to_edit])) + { + $model["list"][$id_to_edit] = $new_item; + } + else + { + $model["list"][] = $new_item; + } + $modified = true; } } @@ -369,7 +384,7 @@ function todo_list(array $model = []) : string $te = new template_engine(); $te->set_block("TITLE", $model["username"] . "'s to-do List"); - $te->append_block_template("CONTENT", "TODO_LIST"); + $te->append_block_template("CONTENT", "MAIN_LIST"); $te->append_block_template("CONTENT", "ADD_FORM"); $te->append_block_template("CONTENT", "NAVBAR"); @@ -455,7 +470,7 @@ function todo_list(array $model = []) : string if (!empty($categories)) { - $te->set_block("TODO_ITEMS", ""); + $te->set_block("MAIN_ITEMS", ""); } $te->set_block("DATALIST_AUTOFILLS", ""); @@ -466,7 +481,7 @@ function todo_list(array $model = []) : string { $category_name = $category["title"]; $category_basis = $category["basis"]; - $te->set_block("TODO_CATEGORY_ITEMS", ""); + $te->set_block("MAIN_CATEGORY_ITEMS", ""); if ($category_basis == "custom") { @@ -481,23 +496,23 @@ function todo_list(array $model = []) : string if (empty($item["description"])) { - $te->set_block_template("TODO_ITEM_SUMMARY", "TODO_ITEM_SUMMARY_NODESC"); + $te->set_block_template("MAIN_ITEM_SUMMARY", "MAIN_ITEM_SUMMARY_NODESC"); } else { - $te->set_block_template("TODO_ITEM_SUMMARY", "TODO_ITEM_SUMMARY_DESC"); + $te->set_block_template("MAIN_ITEM_SUMMARY", "MAIN_ITEM_SUMMARY_DESC"); } - $te->append_argumented_block("TODO_CATEGORY_ITEMS", "TODO_ITEM", [ - "TODO_ITEM_ID" => $key, - "TODO_ITEM_TITLE" => $item["title"], - "TODO_ITEM_DESCRIPTION" => $item["description"], + $te->append_argumented_block("MAIN_CATEGORY_ITEMS", "MAIN_ITEM", [ + "MAIN_ITEM_ID" => $key, + "MAIN_ITEM_TITLE" => $item["title"], + "MAIN_ITEM_DESCRIPTION" => $item["description"], ]); } - $te->append_argumented_block("TODO_ITEMS", "TODO_CATEGORY", [ - "TODO_CATEGORY_ID" => $category_key, - "TODO_CATEGORY_TITLE" => $category_name, + $te->append_argumented_block("MAIN_ITEMS", "MAIN_CATEGORY", [ + "MAIN_CATEGORY_ID" => $category_key, + "MAIN_CATEGORY_TITLE" => $category_name, ]); } $te->append_argumented_block("DATALISTS", "DATALIST", [ @@ -515,8 +530,8 @@ function todo_list(array $model = []) : string "DATALIST_ID" => "todo_titles", ]); - // $te->append_block("TODO_ITEMS", "
dump".print_r($model, true)."
"); - // $te->append_block("TODO_ITEMS", "
dump".print_r($categories, true)."
"); + // $te->append_block("MAIN_ITEMS", "
dump".print_r($model, true)."
"); + // $te->append_block("MAIN_ITEMS", "
dump".print_r($categories, true)."
"); return $te->get_html(); exit(0); } diff --git a/templates/main-category.html b/templates/main-category.html new file mode 100644 index 0000000..5545543 --- /dev/null +++ b/templates/main-category.html @@ -0,0 +1,4 @@ +
+

{{ MAIN_CATEGORY_TITLE }}

+ {{ MAIN_CATEGORY_ITEMS }} +
\ No newline at end of file diff --git a/templates/main-item-summary-desc.html b/templates/main-item-summary-desc.html new file mode 100644 index 0000000..eef6169 --- /dev/null +++ b/templates/main-item-summary-desc.html @@ -0,0 +1 @@ +{{ MAIN_ITEM_TITLE }}: {{ MAIN_ITEM_DESCRIPTION }} \ No newline at end of file diff --git a/templates/main-item-summary-nodesc.html b/templates/main-item-summary-nodesc.html new file mode 100644 index 0000000..2cd519d --- /dev/null +++ b/templates/main-item-summary-nodesc.html @@ -0,0 +1 @@ +{{ MAIN_ITEM_TITLE }} \ No newline at end of file diff --git a/templates/todo-item.html b/templates/main-item.html similarity index 74% rename from templates/todo-item.html rename to templates/main-item.html index 32fd32d..6d59364 100644 --- a/templates/todo-item.html +++ b/templates/main-item.html @@ -1,18 +1,18 @@ -
+
- {{ TODO_ITEM_SUMMARY }} + {{ MAIN_ITEM_SUMMARY }}
- +
- +
@@ -21,14 +21,14 @@
- +
- +
@@ -37,7 +37,7 @@
- +
diff --git a/templates/todo-items.html b/templates/main-items.html similarity index 100% rename from templates/todo-items.html rename to templates/main-items.html diff --git a/templates/main-list.html b/templates/main-list.html new file mode 100644 index 0000000..f62bbad --- /dev/null +++ b/templates/main-list.html @@ -0,0 +1 @@ +
{{ MAIN_ITEMS }}
\ No newline at end of file diff --git a/templates/todo-category.html b/templates/todo-category.html deleted file mode 100644 index 0c4664d..0000000 --- a/templates/todo-category.html +++ /dev/null @@ -1,4 +0,0 @@ -
-

{{ TODO_CATEGORY_TITLE }}

- {{ TODO_CATEGORY_ITEMS }} -
\ No newline at end of file diff --git a/templates/todo-item-summary-desc.html b/templates/todo-item-summary-desc.html deleted file mode 100644 index 994df4e..0000000 --- a/templates/todo-item-summary-desc.html +++ /dev/null @@ -1 +0,0 @@ -{{ TODO_ITEM_TITLE }}: {{ TODO_ITEM_DESCRIPTION }} \ No newline at end of file diff --git a/templates/todo-item-summary-nodesc.html b/templates/todo-item-summary-nodesc.html deleted file mode 100644 index 95773b8..0000000 --- a/templates/todo-item-summary-nodesc.html +++ /dev/null @@ -1 +0,0 @@ -{{ TODO_ITEM_TITLE }} \ No newline at end of file diff --git a/templates/todo-list.html b/templates/todo-list.html deleted file mode 100644 index 4807b47..0000000 --- a/templates/todo-list.html +++ /dev/null @@ -1 +0,0 @@ -
{{ TODO_ITEMS }}
\ No newline at end of file