<?php
include('../include/auth.php');
include('../include/lskfjwfe.php');

$id = $_POST['id'];
$name = $_POST['name'];
$alias = strtolower(str_replace(' ', '', $_POST['alias']));

$sql = "UPDATE availability_groups SET name='$name', alias='$alias' WHERE id='$id'";
mysqli_query($db2, $sql);

// Log action
$user = $_SESSION['user_id'];
$action = "Edit Availability Group";
$details = "Edited availability group ID: $id, new name: $name, alias: $alias";
mysqli_query($db2, "INSERT INTO action_logs (action, details, user, timestamp) VALUES ('$action', '$details', '$user', NOW())");

echo json_encode(["success" => true]);
?>
