<?php
session_start();
include "include.php";
$ajax_logout = 1;
include "session.php";

if($updte == 1){
    $o1->user_id = $_POST['user_id'];
    $o1 = $factory->get_object($o1->user_id, "users", "user_id");

    if($o1->user_id > 0){
        // Don't allow deleting Admin users
        if($o1->user_type == 'Admin'){
            $result['error'] = 1;
            $result['error_msg'] = "Cannot delete Admin user";
        } else {
            // Delete the user
            $sql_delete = "DELETE FROM users WHERE user_id = '".$o1->user_id."'";
            mysqli_query($conn, $sql_delete);

            $result['error'] = 0;
            $result['error_msg'] = "User deleted successfully";
        }
    } else {
        $result['error'] = 1;
        $result['error_msg'] = "User not found";
    }
} else {
    $result['error'] = 1;
    $result['error_msg'] = "Something went wrong. Please try again";
}

echo json_encode($result);
?>
