Add: typing app list, activate/deactivate app

This commit is contained in:
2018-07-05 18:25:23 +09:00
parent ae523ea4ad
commit 8a4ff2053a
8 changed files with 338 additions and 36 deletions
+30
View File
@@ -0,0 +1,30 @@
<?php
header('Content-Type: application/json');
$maestroID = $_POST["maestro_id"];
$appID = $_POST["app_id"];
include "./../setup/connect_db.php";
activate_app($maestroID, $appID);
$replyJSON["RESULT"] = "ok";
echo json_encode($replyJSON, JSON_UNESCAPED_UNICODE);
$db_conn->close();
function activate_app($maestroID, $appID) {
global $db_conn;
$query = "
INSERT INTO moty_active_app (MaestroID, AppID)
VALUES (?, ?);
";
$stmt = $db_conn->prepare($query);
$stmt->bind_param('ii', $maestroID, $appID);
$stmt->execute();
$stmt->bind_result();
}
?>
+30
View File
@@ -0,0 +1,30 @@
<?php
header('Content-Type: application/json');
$maestroID = $_POST["maestro_id"];
$appID = $_POST["app_id"];
include "./../setup/connect_db.php";
deactivate_app($maestroID, $appID);
$replyJSON["RESULT"] = "ok";
echo json_encode($replyJSON, JSON_UNESCAPED_UNICODE);
$db_conn->close();
function deactivate_app($maestroID, $appID) {
global $db_conn;
$query = "
DELETE FROM moty_active_app
WHERE MaestroID = ? AND AppID = ?;
";
$stmt = $db_conn->prepare($query);
$stmt->bind_param('ii', $maestroID, $appID);
$stmt->execute();
$stmt->bind_result();
}
?>
+1 -1
View File
@@ -27,7 +27,7 @@ function get_mouse_app_list() {
$query = "
SELECT AppID, AppName, KoreanName FROM moty_app
WHERE AppType=100
ORDER BY AppID DESC
ORDER BY AppID ASC
";
$stmt = $db_conn->prepare($query);
$stmt->execute();
+69
View File
@@ -0,0 +1,69 @@
<?php
header('Content-Type: application/json');
$maestroID = $_POST["maestro_id"];
include "./../setup/connect_db.php";
$typing_app_list = get_typing_app_list();
if($typing_app_list.length === 0) {
send_error_message($replyJSON, "등록된 타자 앱 없음");
$db_conn->close();
exit;
}
$activated_typing_app_list = get_activated_typing_app_list($maestroID);
$replyJSON["List"] = $typing_app_list;
$replyJSON["ActivatedList"] = $activated_typing_app_list;
$replyJSON["RESULT"] = "ok";
echo json_encode($replyJSON, JSON_UNESCAPED_UNICODE);
$db_conn->close();
function get_typing_app_list() {
global $db_conn;
$query = "
SELECT AppID, AppName, KoreanName FROM moty_app
WHERE AppType < 100
ORDER BY AppID ASC
";
$stmt = $db_conn->prepare($query);
$stmt->execute();
$stmt->bind_result($appID, $appName, $koreanName);
$playerList = array();
while($stmt->fetch()) {
$player['AppID'] = $appID;
$player['AppName'] = $appName;
$player['KoreanName'] = $koreanName;
array_push($playerList, $player);
}
return $playerList;
}
function get_activated_typing_app_list($maestroID) {
global $db_conn;
$query = "
SELECT A.AppID
FROM moty_app AS A
INNER JOIN moty_active_app AS AA ON A.AppID = AA.AppID AND A.AppType < 100 AND AA.MaestroID=?"
;
$stmt = $db_conn->prepare($query);
$stmt->bind_param('i', $maestroID);
$stmt->execute();
$stmt->bind_result($appID);
$playerList = array();
while($stmt->fetch()) {
$player['AppID'] = $appID;
array_push($playerList, $player);
}
return $playerList;
}
?>