A Task List Manager is a software application designed to help users organize, prioritize, and track their tasks or to-do items. It serves as a digital organizer, replacing traditional paper-based lists. The primary goal is to enhance productivity and ensure that important tasks are not overlooked.
Key functionalities typically found in a Task List Manager include:
1. Adding Tasks: Users can input new tasks, often with details like a title, description, due date, and priority level.
2. Viewing Tasks: Displaying a list of all current tasks. This often includes options to filter (e.g., by due date, priority, completion status) or sort them.
3. Marking as Complete: Users can mark tasks as done, moving them from an active state to a completed state. This provides a sense of accomplishment and helps track progress.
4. Editing Tasks: Modifying the details of an existing task.
5. Deleting Tasks: Removing tasks that are no longer relevant.
6. Persistence: Tasks need to be saved so they are available even after the application is closed or refreshed. This can be achieved using various storage methods, such as local files (CSV, JSON), databases (MySQL, PostgreSQL, SQLite), or cloud-based services.
In a web context, a Task List Manager typically involves a front-end (HTML, CSS, JavaScript) for user interaction and a back-end (PHP, Python, Node.js, etc.) for processing requests, managing data storage, and serving dynamic content. For a simple PHP example, we might use a JSON file to simulate data persistence without needing a full database setup. This demonstrates the core logic of managing tasks: reading, adding, updating, and deleting records, and is perfect for illustrating how web applications handle state and user input.
Example Code
<?php
// Define the file path for storing tasks
define('TASK_FILE', 'tasks.json');
/
* Reads tasks from the JSON file.
* @return array An array of tasks.
*/
function getTasks() {
if (!file_exists(TASK_FILE)) {
file_put_contents(TASK_FILE, json_encode([])); // Create an empty file if it doesn't exist
}
$tasks_json = file_get_contents(TASK_FILE);
return json_decode($tasks_json, true) ?: [];
}
/
* Saves tasks to the JSON file.
* @param array $tasks The array of tasks to save.
*/
function saveTasks(array $tasks) {
file_put_contents(TASK_FILE, json_encode($tasks, JSON_PRETTY_PRINT));
}
/
* Adds a new task.
* @param string $description The description of the task.
*/
function addTask($description) {
if (empty(trim($description))) {
return; // Don't add empty tasks
}
$tasks = getTasks();
$newTask = [
'id' => uniqid(), // Unique ID for the task
'description' => htmlspecialchars($description, ENT_QUOTES, 'UTF-8'),
'completed' => false,
'created_at' => date('Y-m-d H:i:s')
];
$tasks[] = $newTask;
saveTasks($tasks);
}
/
* Marks a task as complete or incomplete.
* @param string $id The ID of the task to update.
* @param bool $completed The completion status.
*/
function toggleTaskCompletion($id, $completed) {
$tasks = getTasks();
foreach ($tasks as &$task) { // Pass by reference to modify the original array
if ($task['id'] === $id) {
$task['completed'] = (bool)$completed;
break;
}
}
saveTasks($tasks);
}
/
* Deletes a task.
* @param string $id The ID of the task to delete.
*/
function deleteTask($id) {
$tasks = getTasks();
$tasks = array_filter($tasks, function($task) use ($id) {
return $task['id'] !== $id;
});
saveTasks($tasks);
}
// Handle form submissions
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
if (isset($_POST['action'])) {
switch ($_POST['action']) {
case 'add':
if (isset($_POST['description'])) {
addTask($_POST['description']);
}
break;
case 'toggle_complete':
if (isset($_POST['id'], $_POST['completed'])) {
toggleTaskCompletion($_POST['id'], $_POST['completed'] === 'true');
}
break;
case 'delete':
if (isset($_POST['id'])) {
deleteTask($_POST['id']);
}
break;
}
}
// Redirect to prevent form re-submission on refresh (Post/Redirect/Get pattern)
header('Location: ' . $_SERVER['PHP_SELF']);
exit;
}
// Get all tasks to display
$tasks = getTasks();
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Task List Manager</title>
<style>
body { font-family: Arial, sans-serif; margin: 20px; background-color: #f4f4f4; color: #333; }
.container { max-width: 800px; margin: auto; background: #fff; padding: 20px; border-radius: 8px; box-shadow: 0 0 10px rgba(0,0,0,0.1); }
h1 { text-align: center; color: #0056b3; }
form { display: flex; margin-bottom: 20px; }
form input[type="text"] { flex-grow: 1; padding: 10px; border: 1px solid #ddd; border-radius: 4px 0 0 4px; font-size: 16px; }
form button { padding: 10px 15px; background-color: #007bff; color: white; border: none; border-radius: 0 4px 4px 0; cursor: pointer; font-size: 16px; }
form button:hover { background-color: #0056b3; }
ul { list-style: none; padding: 0; }
li { background: #e9ecef; border: 1px solid #ddd; margin-bottom: 10px; padding: 15px; border-radius: 4px; display: flex; align-items: center; justify-content: space-between; }
li.completed { background: #d4edda; text-decoration: line-through; color: #666; }
li .task-description { flex-grow: 1; }
li .actions button { background: #dc3545; color: white; border: none; padding: 8px 12px; border-radius: 4px; cursor: pointer; margin-left: 10px; }
li .actions button:hover { opacity: 0.9; }
li .actions .complete-btn { background-color: #28a745; }
li .actions .complete-btn:hover { background-color: #218838; }
li .actions .incomplete-btn { background-color: #ffc107; }
li .actions .incomplete-btn:hover { background-color: #e0a800; }
</style>
</head>
<body>
<div class="container">
<h1>Task List Manager</h1>
<form action="<?php echo htmlspecialchars($_SERVER['PHP_SELF']); ?>" method="POST">
<input type="hidden" name="action" value="add">
<input type="text" name="description" placeholder="Add a new task..." required>
<button type="submit">Add Task</button>
</form>
<?php if (empty($tasks)): ?>
<p style="text-align: center; color: #777;">No tasks yet. Add one above!</p>
<?php else: ?>
<ul>
<?php foreach ($tasks as $task): ?>
<li class="<?php echo $task['completed'] ? 'completed' : ''; ?>">
<span class="task-description"><?php echo $task['description']; ?></span>
<div class="actions">
<form style="display:inline;" action="<?php echo htmlspecialchars($_SERVER['PHP_SELF']); ?>" method="POST">
<input type="hidden" name="action" value="toggle_complete">
<input type="hidden" name="id" value="<?php echo $task['id']; ?>">
<?php if ($task['completed']): ?>
<input type="hidden" name="completed" value="false">
<button type="submit" class="incomplete-btn">Mark Incomplete</button>
<?php else: ?>
<input type="hidden" name="completed" value="true">
<button type="submit" class="complete-btn">Mark Complete</button>
<?php endif; ?>
</form>
<form style="display:inline;" action="<?php echo htmlspecialchars($_SERVER['PHP_SELF']); ?>" method="POST">
<input type="hidden" name="action" value="delete">
<input type="hidden" name="id" value="<?php echo $task['id']; ?>">
<button type="submit">Delete</button>
</form>
</div>
</li>
<?php endforeach; ?>
</ul>
<?php endif; ?>
</div>
</body>
</html>








Task List Manager