-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdelete_slot.php
More file actions
31 lines (25 loc) · 806 Bytes
/
delete_slot.php
File metadata and controls
31 lines (25 loc) · 806 Bytes
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
<?php
//delete time slot in JSOn file by day and time
//check if user logged in
session_start();
if (empty($_SESSION['user'])) {
//set status code to 401
http_response_code(401);
echo "Please login first";
exit();
}
if (isset($_GET['day']) && isset($_GET['time'])) {
$day = $_GET['day'];
$time = $_GET['time'];
// Load and decode the JSON file
$jsonFile = 'timeslot.json';
$jsonStr = file_get_contents($jsonFile);
$timeSlots = json_decode($jsonStr, true);
// Remove the time slot
unset($timeSlots[$day][$time]);
// Convert the array to JSON format
$jsonData = json_encode($timeSlots, JSON_PRETTY_PRINT);
// Write JSON data to the file
file_put_contents($jsonFile, $jsonData);
echo "Time slot for $day at $time has been deleted.";
}