33 lines
1.1 KiB
PHP
33 lines
1.1 KiB
PHP
<?php
|
|
ob_start();
|
|
include 'koneksi.php';
|
|
$output = ob_get_clean();
|
|
|
|
header('Content-Type: application/json');
|
|
|
|
$id = $_POST['id_restriction'] ?? '';
|
|
$day = $_POST['day_of_week'] ?? '';
|
|
$timeFrom = $_POST['time_from'] ?? '';
|
|
$timeTo = $_POST['time_to'] ?? '';
|
|
|
|
if (empty($id) || empty($day) || empty($timeFrom) || empty($timeTo)) {
|
|
echo json_encode(['status' => 'error', 'message' => 'All fields are required.']);
|
|
exit;
|
|
}
|
|
|
|
// Ensure correct format for MySQL TIME column compatibility
|
|
if (strlen($timeFrom) === 5) $timeFrom .= ':00';
|
|
if (strlen($timeTo) === 5) $timeTo .= ':00';
|
|
|
|
try {
|
|
$stmt = $pdo->prepare("UPDATE room_restrictions SET day_of_week = ?, time_from = ?, time_to = ? WHERE id_restriction = ?");
|
|
$result = $stmt->execute([$day, $timeFrom, $timeTo, $id]);
|
|
if ($result) {
|
|
echo json_encode(['status' => 'success', 'message' => 'Restriction updated successfully.']);
|
|
} else {
|
|
echo json_encode(['status' => 'error', 'message' => 'Failed to update: ' . implode(' ', $stmt->errorInfo())]);
|
|
}
|
|
} catch (Exception $e) {
|
|
echo json_encode(['status' => 'error', 'message' => 'Exception: ' . $e->getMessage()]);
|
|
}
|