forked from maxifaxipaxi-new/tasksmanager
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtasks.php
More file actions
51 lines (40 loc) · 1.27 KB
/
tasks.php
File metadata and controls
51 lines (40 loc) · 1.27 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
<?php
header("Content-Type: application/json");
header("Access-Control-Allow-Origin: *");
header("Access-Control-Allow-Methods: GET, POST, PUT, DELETE");
$filename = "tasks.json";
if (!file_exists($filename)) {
file_put_contents($filename, json_encode([]));
}
$action = $_GET['action'] ?? '';
if ($action == 'get') {
echo file_get_contents($filename);
}
elseif ($action == 'add') {
$data = json_decode(file_get_contents("php://input"), true);
$tasks = json_decode(file_get_contents($filename), true);
$newTask = [
"id" => count($tasks) + 1,
"title" => $data['title'],
"description" => $data['description'],
"category" => $data['category'],
"status" => "gemeldet"
];
$tasks[] = $newTask;
file_put_contents($filename, json_encode($tasks, JSON_PRETTY_PRINT));
echo json_encode(["success" => true]);
}
elseif ($action == 'update') {
$id = $_GET['id'];
$status = $_GET['status'];
$tasks = json_decode(file_get_contents($filename), true);
foreach ($tasks as &$task) {
if ($task['id'] == $id) {
$task['status'] = $status;
break;
}
}
file_put_contents($filename, json_encode($tasks, JSON_PRETTY_PRINT));
echo json_encode(["success" => true]);
}
?>