<?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 `module`
		ORDER BY order_sequence
	";
	$result = $conn->query($sql);

	if ($result->num_rows > 0) {
		while ($row = $result->fetch_assoc()) {
			$temp = array(
				"ID" => intval($row['ID']),
				"name" => $row['name'],
				"nameZh" => $row['nameZh'],
				"link" => $row['link'],
				"order_sequence" => intval($row["order_sequence"]),
				"access" => $row['access'],
				"active" => intval($row['active']),
			);

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

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