<?php
header('Access-Control-Allow-Origin: *');
header(
    'Access-Control-Allow-Methods: HEAD, GET, POST, PUT, PATCH, DELETE, OPTIONS'
);
header(
    'Access-Control-Allow-Headers: X-API-KEY, Origin, X-Requested-With, Content-Type, Accept, Access-Control-Request-Method,Access-Control-Request-Headers, Authorization'
);
header('Content-Type: application/json');
include '../../../../config/db.php';


$postData = file_get_contents('php://input');
if (isset($postData) && !empty($postData)) {
        //Extract the data
        $request = json_decode($postData);
        
        //Validate data
        if (
            trim($request->userId) === '') {
                $responseArray = [
                    'message' => 'Required fields are missing.',
                    'status' => -2,
                ];
                echo json_encode($responseArray);
                return http_response_code(406);
            }
      // Sanitize input
      $userId = mysqli_real_escape_string( $con, trim($request->userId) );
      // Ban user
      $query = "UPDATE users SET status = '2', dateModified = NOW() WHERE userId = $userId";
      $result = mysqli_query( $con, $query );
      if ( $result ) {
        $response = array(
          'status' => 'success'
        );
      } else {
        $response = array(
          'status' => 'error',
          'message' => mysqli_error( $con )
        );
      }

      // Return response as JSON
      header( 'Content-Type: application/json' );
      echo json_encode( $response );
}
?>


