-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
84 lines (84 loc) · 5.49 KB
/
index.php
File metadata and controls
84 lines (84 loc) · 5.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<?php
session_start();
if (!isset($_SESSION['user_id'])) {
$selected_lang = $_GET['lang'] ?? $_SESSION['lang'] ?? 'en';
header("Location: authenticate.php?lang=" . urlencode($selected_lang));
exit;
}
require "config.php";
$available_langs = ['en' => 'English', 'ru' => 'Русский', 'es' => 'Español', 'de' => 'Deutsch', 'pt' => 'Português', 'tr' => 'Türkçe', 'zh-CN' => '中文', 'uz' => 'Oʻzbekcha', 'fa' => 'فارسی', 'ar' => 'العربية'];
$selected_lang = $_GET['lang'] ?? $_SESSION['lang'] ?? 'en';
if (!array_key_exists($selected_lang, $available_langs)) {
$selected_lang = 'en';
}
$_SESSION['lang'] = $selected_lang;
$lang = file_exists(__DIR__ . "/lang/{$selected_lang}.php") ? require __DIR__ . "/lang/{$selected_lang}.php" : [];
$stmt = $pdo->query("SELECT * FROM tasks ORDER BY created_at DESC");
$tasks = $stmt->fetchAll(PDO::FETCH_ASSOC);
?>
<!DOCTYPE html>
<html lang="<?php echo htmlspecialchars($selected_lang); ?>">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title><?php echo htmlspecialchars($lang['title'] ?? 'To-Do List'); ?></title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.8/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-sRIl4kxILFvY47J16cr9ZwB07vP4J8+LH7qKQnuqkuIAvNWLzeN8tE5YBujZqJLB" crossorigin="anonymous">
<style>
body { background: linear-gradient(135deg, #E6F0FA, #FFF8E1); }
</style>
</head>
<body>
<div class="container mt-5">
<form method="get" class="mb-3" style="max-width:200px; float: right;">
<select name="lang" class="form-select" onchange="this.form.submit()">
<?php foreach ($available_langs as $key => $label): ?>
<option value="<?php echo htmlspecialchars($key); ?>" <?php if ($selected_lang === $key) echo 'selected'; ?>><?php echo htmlspecialchars($label); ?></option>
<?php endforeach; ?>
</select>
</form>
<h1><?php echo htmlspecialchars($lang['title'] ?? 'To-Do List'); ?></h1>
<form action="add_task.php?lang=<?php echo urlencode($selected_lang); ?>" method="POST" class="mb-4">
<div class="mb-3">
<label for="title" class="form-label"><?php echo htmlspecialchars($lang['task_name'] ?? 'Task Name'); ?></label>
<input type="text" class="form-control" id="title" name="title" required>
</div>
<div class="mb-3">
<label for="description" class="form-label"><?php echo htmlspecialchars($lang['description'] ?? 'Description'); ?></label>
<textarea class="form-control" id="description" name="description" rows="4"></textarea>
</div>
<button type="submit" class="btn btn-primary"><?php echo htmlspecialchars($lang['add_task'] ?? 'Add Task'); ?></button>
</form>
<table class="table">
<thead>
<tr>
<th><?php echo htmlspecialchars($lang['task_name'] ?? 'Task Name'); ?></th>
<th><?php echo htmlspecialchars($lang['description'] ?? 'Description'); ?></th>
<th><?php echo htmlspecialchars($lang['status'] ?? 'Status'); ?></th>
<th><?php echo htmlspecialchars($lang['created_at'] ?? 'Created At'); ?></th>
<th><?php echo htmlspecialchars($lang['actions'] ?? 'Actions'); ?></th>
</tr>
</thead>
<tbody>
<?php foreach ($tasks as $task): ?>
<tr>
<td><?php echo htmlspecialchars($task['title']); ?></td>
<td><?php echo htmlspecialchars($task['description'] ?? ''); ?></td>
<td class="<?php echo $task['status'] == 'completed' ? 'text-success' : 'text-secondary'; ?>">
<?php echo $task['status'] == 'pending' ? htmlspecialchars($lang['pending'] ?? 'Pending') : htmlspecialchars($lang['completed'] ?? 'Completed'); ?>
</td>
<td><?php echo htmlspecialchars($task['created_at']); ?></td>
<td>
<?php if ($task['status'] == 'pending'): ?>
<a href="complete_task.php?id=<?php echo $task['id']; ?>&lang=<?php echo urlencode($selected_lang); ?>" class="btn btn-success btn-sm"><?php echo htmlspecialchars($lang['complete_task'] ?? 'Complete Task'); ?></a>
<?php endif; ?>
<a href="edit_task.php?id=<?php echo $task['id']; ?>&lang=<?php echo urlencode($selected_lang); ?>" class="btn btn-warning btn-sm"><?php echo htmlspecialchars($lang['edit_task'] ?? 'Edit Task'); ?></a>
<a href="delete_task.php?id=<?php echo $task['id']; ?>&lang=<?php echo urlencode($selected_lang); ?>" class="btn btn-danger btn-sm" onclick="return confirm('<?php echo htmlspecialchars($lang['confirm_delete'] ?? 'Are you sure you want to delete this task?'); ?>');"><?php echo htmlspecialchars($lang['delete_task'] ?? 'Delete Task'); ?></a>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.8/dist/js/bootstrap.bundle.min.js" integrity="sha384-FKyoEForCGlyvwx9Hj09JcYn3nv7wiPVlz7YYwJrWVcXK/BmnVDxM+D2scQbITxI" crossorigin="anonymous"></script>
</body>
</html>