<?php
include('../connection.php');
mysqli_set_charset($conn, 'utf8mb4');
header("Content-Type: application/json");

if (isset($_POST['id'])) {
    $id = $_POST['id'];
    $problem = $_POST['problem'];
    $assign = $_POST['assign'];
    $location = $_POST['location'];
    $status = $_POST['status'];
    $end_time = $_POST['end_time'];
    $recharge_id = $_POST['recharge_id'];
    $name = $_POST['name'];
    $phone = $_POST['phone'];
    $priority = $_POST['priority'];
    $create_by = $_POST['create_by'];
    $userID = $_POST['user_id'];
    $remark = $_POST['remark'];
    $assign_at = isset($_POST['assign_at']) ? $_POST['assign_at'] : '';

    $stmt = $conn->prepare("UPDATE ticket SET problem=?, assign=?, location=?, status=?, end_time=?, recharge_id=?, user_id=?, name=?, phone=?, priroty=?, create_by=?, remark=?, assign_at=? WHERE id=?");
    $stmt->bind_param("sssssssssssssi", $problem, $assign, $location, $status, $end_time, $recharge_id, $userID, $name, $phone, $priority, $create_by, $remark, $assign_at, $id);

    if ($stmt->execute()) {
        $response = [
            'status' => 'success',
            'message' => 'Data updated successfully',
        ];
    } else {
        $response = [
            'status' => 'error',
            'message' => 'Database error: ' . $stmt->error,
        ];
    }

    $stmt->close();
} else {
    $response = [
        'status' => 'error',
        'message' => 'No data found',
    ];
}

echo json_encode($response);
$conn->close();
?>
