<?php 
if(file_exists('../../../'.$_REQUEST['tenant'].'/config.php')) {
    require_once('../../../'.$_REQUEST['tenant'].'/config.php');
}
if(file_exists('/config.php')) {
    require_once('/config.php');
}
// Check if POST request and ticket ID is provided
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    if (!empty($_POST['ticket_id'])) {
        $ticket_id = mysqli_real_escape_string($admin_con, $_POST['ticket_id']);
        
        // Confirm that tenant value and ticket ID are received correctly
        //echo "Ticket ID: $ticket_id, Tenant: " . $_REQUEST['tenant'] . "\n";

        $update_status = "UPDATE support_tickets SET status = 'completed', last_updated = NOW() WHERE id = '$ticket_id'";

        if (mysqli_query($admin_con, $update_status)) {
            echo "success";
        } else {
            echo "Database error: " . mysqli_error($admin_con);
        }
    } else {
        echo "Error: Ticket ID is missing.";
    }
} else {
    echo "Error: Invalid request method.";
}
?>