<?php
header('Content-Type: application/json');

// get parameters from client
$maestroID = $_POST["maestroID"];
$playerID = $_POST["playerID"];
$appGroup = $_POST["appGroup"];
$language = $_POST["language"];


include "./../lib/json_builder.php";
include "./../lib/connect_db.php";

$jsonBuilder = new JsonBuilder();
$dbConnector = new DBConnector();

$isConnected = $dbConnector->connectDB();
if (!$isConnected) {
	$jsonBuilder->setErrorMessage("DB connection : failed");
	$jsonBuilder->sendResultFail();
	exit;
}


include "./../db/db_method_container.php";
include "./../db/writing_collection.php";
include "./../db/menu_collection.php";

$jsonBuilder->setData("appGroup", $appGroup);

$menuCollection = new MenuCollection($dbConnector->getMysqli());
$jsonBuilder->setData("appGroup", $appGroup);
$jsonBuilder->setData("appGroupName", $menuCollection->getAppGroupName($appGroup));
$jsonBuilder->setData("languageName", $menuCollection->getLanguageName($language));

$appList = $menuCollection->getAppList($maestroID, $playerID, $appGroup, $language);
$activeAppList = $menuCollection->getActiveAppList($maestroID, $playerID, $appGroup, $language);
if($appGroup === "2")	// typing exam
	$highestRecordList = $menuCollection->getWritingHighestRecordList($maestroID, $playerID, $appList);
else
	$highestRecordList = $menuCollection->getHighestRecordList($maestroID, $playerID, $appList);
// $highestRecordList = $menuCollection->getHighestRecordList($maestroID, $playerID, $appList);


$appData["appList"] = $appList;
$appData["activeAppList"] = $activeAppList;
$appData["highestRecordList"] = $highestRecordList;
// $jsonBuilder->setData("appList", $appList);
// $jsonBuilder->setData("activeAppList", $activeAppList);
// $jsonBuilder->setData("highestRecordList", $highestRecordList);
$jsonBuilder->setData("appData", $appData);

$jsonBuilder->sendResultSuccess();
?>