<?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';

// Get all users with a specific status
$query = "SELECT * FROM `Employees`";
$result = mysqli_query( $con, $query );
if ( $result ) {
  $users = array();
  $i = 0;
  while ( $row = mysqli_fetch_assoc( $result ) ) {
    $users[$i]['employeeId'] = $row['employeeId'];
    $users[$i]['fname'] = $row['fname'];
    $users[$i]['lname'] = $row['lname'];
    $users[$i]['username'] = $row['username'];
    $users[$i]['email'] = $row['email'];
    $users[$i]['role'] = $row['role'];
    $users[$i]['status'] = $row['status'];
    $users[$i]['dateCreated'] = $row['date_created'];
    $i++;
  }
  $response = array(
    'status' => 'success',
    'employees' => $users
  );
} else {
  $response = array(
    'status' => 'error',
    'employees' => mysqli_error( $con )
  );
}

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

?>