<?php require_once __DIR__ . "/../util/web.php"; require_once __DIR__ . "/../service/data_service.php"; require_once __DIR__ . "/../util/validators.php"; require_once __DIR__ . "/../config/constants.php"; require_once __DIR__ . "/../controller/ensure_session.php"; if (!isset($_SESSION["todoId"])) { redirect(VIEWS . "/home.php"); } $taskId = $_SESSION["todoId"]; $taskDesc = $_POST["description"]; $taskStatus = $_POST["status"]; //validate task description $valid = validateRequired($taskDesc); if ($valid) { update_todo($taskId, $taskDesc, $taskStatus); } else { $_SESSION["error"] = "Task description is required and can have upto 120 characters"; } redirect(VIEWS . "/home.php"); exit;
exit; } else { if ($action === "Delete") { todolog("todo.php | Trying to delete a todo"); if (isset($_POST["todoId"])) { todolog("todo.php | todo id: " . $_POST["todoId"]); delete_todo($_POST["todoId"]); } else { $_SESSION["errors"] = array("Select a todo"); } redirect(VIEWS . "/home.php"); exit; } else { if ($action == "Update") { //$_SESSION["errors"] = array("Feature not implemented"); // var_dump($_POST); // die(); $todoId = $_POST["taskId"]; $description = $_POST["description"]; $status = $_POST["status"]; $updated = update_todo($todoId, $description, $status); if (!$updated) { $errors = array('You can only change the status by the ordor "Not Started=>Started=>Mid-way=>Completed"<br/>Completed task is read only'); $_SESSION['errors'] = $errors; } redirect(VIEWS . "/home.php"); exit; } } } }
redirect(VIEWS . "/home.php"); } // Delete } else { if ($action == "Delete") { if (isset($_POST["taskId"])) { $todoId = $_POST["taskId"]; delete_todo($todoId); } else { $_SESSION["error"] = "Select a task"; } redirect(VIEWS . "/home.php"); } else { if ($action == "Update") { // Update if (isset($_POST["taskId"])) { $todoId = $_POST["taskId"]; $description = $_POST["description"]; $status = $_POST["status"]; $updated = update_todo($description, $status, $todoId); if (!$updated) { $_SESSION['error'] = 'You can only change the status by the ordor "Not Started=>Started=>Mid-way=>Completed"<br/>Completed task is read only'; } } else { $_SESSION["error"] = "Select a task"; } redirect(VIEWS . "/home.php"); } } } }