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

if (!isset($_POST['fleet_id']) || empty($_POST['fleet_id'])) {
    echo json_encode(['success' => false, 'message' => 'Invalid fleet ID']);
    exit;
}

$fleet_id = intval($_POST['fleet_id']);
$notes = mysqli_real_escape_string($db2, $_POST['notes']);

// Update query
$query = "UPDATE fleet SET notes = '$notes' WHERE fleet_id = $fleet_id";

if (mysqli_query($db2, $query)) {
    // Log the action
    $user_id = $_SESSION['user_id'];
    $log_message = "Updated notes for fleet ID $fleet_id.";
    $log_query = "INSERT INTO action_logs (user_id, action, details, timestamp) VALUES ('$user_id', 'Update Notes', '$log_message', NOW())";
    mysqli_query($db2, $log_query);

    echo json_encode(['success' => true, 'message' => 'Notes updated successfully']);
} else {
    echo json_encode(['success' => false, 'message' => 'Database update failed']);
}
?>
