-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathedit_schedule.php
42 lines (35 loc) · 963 Bytes
/
edit_schedule.php
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
<?php
require_once 'includes/auth.php';
requireLogin();
function getSchedule($index)
{
$schedules = json_decode(file_get_contents('schedules.json'), true);
return $schedules[$index] ?? null;
}
function updateSchedule($index, $title, $date, $time)
{
$schedules = json_decode(file_get_contents('schedules.json'), true);
$schedules[$index] = [
'title' => $title,
'date' => $date,
'time' => $time,
];
file_put_contents('schedules.json', json_encode($schedules));
}
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$index = $_POST['id'];
$title = $_POST['title'];
$date = $_POST['date'];
$time = $_POST['time'];
updateSchedule($index, $title, $date, $time);
header('Location: dashboard.php');
exit;
}
$index = $_GET['id'] ?? null;
$schedule = getSchedule($index);
if (!$schedule) {
header('Location: dashboard.php');
exit;
}
?>
<!-- Add HTML for the edit_schedule.php form -->