<?php
header('Access-Control-Allow-Origin: *');
header("Access-Control-Allow-Methods: POST");

require_once "../config.php";

$conn = connect_db();

$res = array();

if ($conn->connect_error) {
	die('Connection failed: ' . $conn->connect_error);
} else {
	$sql = "
		SELECT *
		FROM `user`
		ORDER BY registered
	";
	$result = $conn->query($sql);

	if ($result->num_rows > 0) {
		while ($row = $result->fetch_assoc()) {
			$temp = array(
				"username" => $row['username'],
				"name" => $row['name'],
				"nameZh" => $row['nameZh'],
				"email" => $row['email'],
				"contact" => $row['contact'],
				"dob" => $row['dob'],
				"dob_time" => $row['dob_time'],
				"referrer" => $row['referrer'],
				"referral_code" => $row['referral_code'],
				"registered" => $row['registered'],
				"role" => $row['role'],
				"last_login" => $row['last_login'],
			);

			array_push($res, $temp);
		}
	}
}

$conn->close();
echo json_encode($res);
