<?php
include('../connection.php');
header("Content-Type: application/json");
mysqli_set_charset($conn, 'utf8mb4');
if (isset($_POST['id'])) {
    // Retrieve POST data
    $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'];
    $created_at = $_POST['created_at'];
    


    // Use prepared statements to prevent SQL injection
    $stmt = $conn->prepare("UPDATE ticket SET problem=?, assign=?, location=?,created_at=?, status=?, end_time=?, recharge_id=?,user_id=?, name=?, phone=?, priroty=?, create_by=? WHERE id=?");
    $stmt->bind_param("ssssssssssssi", $problem, $assign, $location,$created_at, $status, $end_time, $recharge_id,$userID, $name, $phone, $priority, $create_by, $id);

    if ($stmt->execute()) {
        $response = [
            'status' => 'success',
            'message' => 'Ticket Reopen successfully',
        ];
    } else {
        $response = [
            'status' => 'error',
            'message' => 'Database error: ' . $stmt->error,
        ];
    }
    // Close the statement
    $stmt->close();
} else {
    $response = [
        'status' => 'error',
        'message' => 'No data found',
    ];
}

// Return JSON response
echo json_encode($response);

// Close the database connection
$conn->close();
?>
