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

include "./../lib/send_reply_json.php";
include "./../setup/connect_db.php";

$maestroID = $_POST["maestro_id"];
$appID = $_POST["app_id"];


activate_app($maestroID, $appID);
$appInfo = get_app_name($appID);

set_data("appName", $appInfo["AppName"]);
set_data("koreanName", $appInfo["KoreanName"]);
send_result_success();
exit;


function activate_app($maestroID, $appID) {
	global $db_conn;

	$query = "
		INSERT INTO active_app (MaestroID, AppID)
		VALUES (?, ?);
	";
	$stmt = $db_conn->prepare($query);
	$stmt->bind_param('ii', $maestroID, $appID);
	$stmt->execute();
	$stmt->bind_result();
}

function get_app_name($appID) {
	global $db_conn;

	$query = "
		SELECT AppName, KoreanName
		FROM app
		WHERE AppID = ?
	";
	$stmt = $db_conn->prepare($query);
	$stmt->bind_param('i', $appID);
	$stmt->execute();
	$stmt->bind_result($appName, $koreanName);
	$stmt->fetch();

	$result["AppName"] = $appName;
	$result["KoreanName"] = $koreanName;
	return $result;
}

?>