-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathedit_task.php
More file actions
69 lines (66 loc) · 3.75 KB
/
edit_task.php
File metadata and controls
69 lines (66 loc) · 3.75 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
<?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" : [];
$task_id = $_GET['id'] ?? 0;
$stmt = $pdo->prepare("SELECT * FROM tasks WHERE id = :id");
$stmt->execute(['id' => $task_id]);
$task = $stmt->fetch(PDO::FETCH_ASSOC);
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$title = trim($_POST['title'] ?? '');
$description = trim($_POST['description'] ?? '');
if (!empty($title)) {
$stmt = $pdo->prepare("UPDATE tasks SET title = :title, description = :description WHERE id = :id");
$stmt->execute(['title' => $title, 'description' => $description ?: null, 'id' => $task_id]);
header("Location: index.php?lang=" . urlencode($selected_lang));
exit;
}
}
?>
<!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['edit_task'] ?? 'Edit Task'); ?></title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.8/dist/css/bootstrap.min.css" rel="stylesheet">
<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['edit_task'] ?? 'Edit Task'); ?></h1>
<form action="edit_task.php?id=<?php echo $task_id; ?>&lang=<?php echo urlencode($selected_lang); ?>" method="POST">
<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" value="<?php echo htmlspecialchars($task['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"><?php echo htmlspecialchars($task['description'] ?? ''); ?></textarea>
</div>
<button type="submit" class="btn btn-primary"><?php echo htmlspecialchars($lang['save'] ?? 'Save'); ?></button>
<a href="index.php?lang=<?php echo urlencode($selected_lang); ?>" class="btn btn-secondary"><?php echo htmlspecialchars($lang['cancel'] ?? 'Cancel'); ?></a>
</form>
</div>
</body>
</html>