Fix: revised php code to maestro app typing list

This commit is contained in:
2018-07-12 11:14:29 +09:00
parent f23665a5f0
commit 07b65f004b
4 changed files with 103 additions and 173 deletions
+44 -100
View File
@@ -1,47 +1,28 @@
<script type="text/javascript">
$(document).ready(function() {
loadMouseApp();
});
function loadMouseApp() {
let self = this;
let xhr = new XMLHttpRequest(); //new로 생성.
xhr.open('POST', './../server/app/mouse_app_list.php', true);
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xhr.send("maestro_id=" + maestroID);
xhr.onload = function() {
if(xhr.readyState === 4 && xhr.status === 200) {
// console.log(xhr.responseText);
// console.log(xhr.responseText.length);
if(xhr.responseText.length === 0 || xhr.responseText === null) {
console.log("no data from server");
return;
sendRequestServer( //url, sendParams, onSuccess, onFail, isDebugMode);
"./../server/app/mouse_app_list.php",
"maestro_id=" + maestroID,
(jsonData) => {
makeMouseAppList(jsonData["appList"]);
activateMouseApp(jsonData["activatedAppList"]);
},
(errorMessage) => {
if($("#error_message").length) {
$("#error_message").text(errorMessage);
}
let replyJSON = JSON.parse(xhr.responseText);
// console.log(replyJSON);
if(replyJSON === null) {
console.log("no data from server");
return;
}
if(replyJSON["ERROR"] !== undefined || replyJSON["RESULT"] === undefined) {
console.log(replyJSON["ERROR"]);
return;
}
if(replyJSON["RESULT"] === "fail") {
console.log(replyJSON["RESULT"]);
return;
}
makeMouseAppList(replyJSON["List"]);
activateMouseApp(replyJSON["ActivatedList"]);
}
}
);
}
function makeMouseAppList(appList) {
@@ -52,12 +33,12 @@ function makeMouseAppList(appList) {
$("#mouse_app_content").append(
"<span>"
+ "<input type='checkbox' id='checkbox" + appData.AppID + "' data-app-id='" + appData.AppID + "' />"
+ "<label for='checkbox" + appData.AppID + "'>" + appData.KoreanName + "</label>"
+ "<input type='checkbox' id='checkbox" + appData.appID + "' data-app-id='" + appData.appID + "' />"
+ "<label for='checkbox" + appData.appID + "'>" + appData.koreanName + "</label>"
+ "</span>"
);
$("#checkbox" + appData.AppID).change(function() {
$("#checkbox" + appData.appID).change(function() {
if($(this).is(":checked")) {
activateApp($(this).data("appId"));
} else {
@@ -69,7 +50,7 @@ function makeMouseAppList(appList) {
function activateMouseApp(activatedList) {
for(let i = 0; i < activatedList.length; i++) {
let activatedAppID = activatedList[i].AppID;
let activatedAppID = activatedList[i].appID;
let input = $("#checkbox" + activatedAppID);
input.prop("checked", true);
@@ -78,76 +59,39 @@ function activateMouseApp(activatedList) {
function activateApp(appID) {
let xhr = new XMLHttpRequest(); //new로 생성.
xhr.open('POST', './../server/app/activate_app.php', true);
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xhr.send("maestro_id=" + maestroID + "&app_id=" + appID);
xhr.onload = function() {
if(xhr.readyState === 4 && xhr.status === 200) {
// console.log(xhr.responseText);
// console.log(xhr.responseText.length);
if(xhr.responseText.length === 0 || xhr.responseText === null) {
console.log("no data from server");
return;
sendRequestServer( //url, sendParams, onSuccess, onFail, isDebugMode);
"./../server/app/activate_app.php",
"maestro_id=" + maestroID + "&app_id=" + appID,
(jsonData) => {
// addPlayerListManager.updateAddPlayerListPage(1);
},
(errorMessage) => {
if($("#error_message").length) {
$("#error_message").text(errorMessage);
}
let replyJSON = JSON.parse(xhr.responseText);
// console.log(replyJSON);
if(replyJSON === null) {
console.log("no data from server");
return;
}
if(replyJSON["ERROR"] !== undefined || replyJSON["RESULT"] === undefined) {
console.log(replyJSON["ERROR"]);
return;
}
if(replyJSON["RESULT"] === "fail") {
console.log(replyJSON["RESULT"]);
return;
}
}
}
);
}
function deactivateApp(appID) {
sendRequestServer( //url, sendParams, onSuccess, onFail, isDebugMode);
"./../server/app/deactivate_app.php",
"maestro_id=" + maestroID + "&app_id=" + appID,
let xhr = new XMLHttpRequest(); //new로 생성.
xhr.open('POST', './../server/app/deactivate_app.php', true);
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xhr.send("maestro_id=" + maestroID + "&app_id=" + appID);
xhr.onload = function() {
if(xhr.readyState === 4 && xhr.status === 200) {
// console.log(xhr.responseText);
// console.log(xhr.responseText.length);
if(xhr.responseText.length === 0 || xhr.responseText === null) {
console.log("no data from server");
return;
(jsonData) => {
// addPlayerListManager.updateAddPlayerListPage(1);
},
(errorMessage) => {
if($("#error_message").length) {
$("#error_message").text(errorMessage);
}
let replyJSON = JSON.parse(xhr.responseText);
// console.log(replyJSON);
if(replyJSON === null) {
console.log("no data from server");
return;
}
if(replyJSON["ERROR"] !== undefined || replyJSON["RESULT"] === undefined) {
console.log(replyJSON["ERROR"]);
return;
}
if(replyJSON["RESULT"] === "fail") {
console.log(replyJSON["RESULT"]);
return;
}
}
}
);
}
</script>
+25 -43
View File
@@ -1,47 +1,29 @@
<script type="text/javascript">
$(document).ready(function() {
loadTypingApp();
});
function loadTypingApp() {
let self = this;
let xhr = new XMLHttpRequest(); //new로 생성.
xhr.open('POST', './../server/app/typing_app_list.php', true);
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xhr.send("maestro_id=" + maestroID);
xhr.onload = function() {
if(xhr.readyState === 4 && xhr.status === 200) {
// console.log(xhr.responseText);
// console.log(xhr.responseText.length);
if(xhr.responseText.length === 0 || xhr.responseText === null) {
console.log("no data from server");
return;
sendRequestServer( //url, sendParams, onSuccess, onFail, isDebugMode);
"./../server/app/typing_app_list.php",
"maestro_id=" + maestroID,
(jsonData) => {
makeTypingAppList(jsonData["appList"]);
activateTypingApp(jsonData["activatedAppList"]);
},
(errorMessage) => {
console.log(errorMessage);
if($("#error_message").length) {
$("#error_message").text(errorMessage);
}
let replyJSON = JSON.parse(xhr.responseText);
// console.log(replyJSON);
if(replyJSON === null) {
console.log("no data from server");
return;
}
if(replyJSON["ERROR"] !== undefined || replyJSON["RESULT"] === undefined) {
console.log(replyJSON["ERROR"]);
return;
}
if(replyJSON["RESULT"] === "fail") {
console.log(replyJSON["RESULT"]);
return;
}
makeTypingAppList(replyJSON["List"]);
activateTypingApp(replyJSON["ActivatedList"]);
}
}
);
}
function makeTypingAppList(appList) {
@@ -53,28 +35,28 @@ function makeTypingAppList(appList) {
for(let i = 0; i < appList.length; i++) {
let appData = appList[i];
if(appData.KoreanName === "")
if(appData.koreanName === "")
continue;
let divTag = null;
if(appData.AppID <= 10)
if(appData.appID <= 10)
divTag = $("#typing_practice_kor");
else if(appData.AppID <= 20)
else if(appData.appID <= 20)
divTag = $("#typing_practice_eng");
else if(appData.AppID <= 30)
else if(appData.appID <= 30)
divTag = $("#typing_test_kor");
else if(appData.AppID <= 40)
else if(appData.appID <= 40)
divTag = $("#typing_test_eng");
else
divTag = $("#typing_app");
divTag.append(
"<span>"
+ "<input type='checkbox' id='checkbox" + appData.AppID + "' data-app-id='" + appData.AppID + "' />"
+ "<label for='checkbox" + appData.AppID + "'>" + appData.KoreanName + "</label>"
+ "<input type='checkbox' id='checkbox" + appData.appID + "' data-app-id='" + appData.appID + "' />"
+ "<label for='checkbox" + appData.appID + "'>" + appData.koreanName + "</label>"
+ "</span>"
);
$("#checkbox" + appData.AppID).change(function() {
$("#checkbox" + appData.appID).change(function() {
if($(this).is(":checked")) {
activateApp($(this).data("appId"));
} else {
@@ -86,7 +68,7 @@ function makeTypingAppList(appList) {
function activateTypingApp(activatedList) {
for(let i = 0; i < activatedList.length; i++) {
let activatedAppID = activatedList[i].AppID;
let activatedAppID = activatedList[i].appID;
let input = $("#checkbox" + activatedAppID);
input.prop("checked", true);
+17 -15
View File
@@ -1,24 +1,26 @@
<?php
header('Content-Type: application/json');
header("Content-Type: application/json");
include "./../lib/send_reply_json.php";
include "./../setup/connect_db.php";
$maestroID = $_POST["maestro_id"];
include "./../setup/connect_db.php";
$mouse_app_list = get_mouse_app_list();
if($mouse_app_list.length === 0) {
send_error_message($replyJSON, "등록된 마우스 앱 없음");
$db_conn->close();
set_error_message("등록된 마우스 앱 없음");
send_result_fail();
exit;
}
$activated_mouse_app_list = get_activated_mouse_app_list($maestroID);
$replyJSON["List"] = $mouse_app_list;
$replyJSON["ActivatedList"] = $activated_mouse_app_list;
$replyJSON["RESULT"] = "ok";
echo json_encode($replyJSON, JSON_UNESCAPED_UNICODE);
$db_conn->close();
set_data("appList", $mouse_app_list);
set_data("activatedAppList", $activated_mouse_app_list);
send_result_success();
exit;
function get_mouse_app_list() {
@@ -35,9 +37,9 @@ function get_mouse_app_list() {
$playerList = array();
while($stmt->fetch()) {
$player['AppID'] = $appID;
$player['AppName'] = $appName;
$player['KoreanName'] = $koreanName;
$player["appID"] = $appID;
$player["appName"] = $appName;
$player["koreanName"] = $koreanName;
array_push($playerList, $player);
}
@@ -53,13 +55,13 @@ function get_activated_mouse_app_list($maestroID) {
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->bind_param("i", $maestroID);
$stmt->execute();
$stmt->bind_result($appID);
$playerList = array();
while($stmt->fetch()) {
$player['AppID'] = $appID;
$player["appID"] = $appID;
array_push($playerList, $player);
}
+17 -15
View File
@@ -1,24 +1,26 @@
<?php
header('Content-Type: application/json');
header("Content-Type: application/json");
include "./../lib/send_reply_json.php";
include "./../setup/connect_db.php";
$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();
set_error_message("등록된 타자 앱 없음");
send_result_fail();
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();
set_data("appList", $typing_app_list);
set_data("activatedAppList", $activated_typing_app_list);
send_result_success();
exit;
function get_typing_app_list() {
@@ -35,9 +37,9 @@ function get_typing_app_list() {
$playerList = array();
while($stmt->fetch()) {
$player['AppID'] = $appID;
$player['AppName'] = $appName;
$player['KoreanName'] = $koreanName;
$player["appID"] = $appID;
$player["appName"] = $appName;
$player["koreanName"] = $koreanName;
array_push($playerList, $player);
}
@@ -53,13 +55,13 @@ function get_activated_typing_app_list($maestroID) {
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->bind_param("i", $maestroID);
$stmt->execute();
$stmt->bind_result($appID);
$playerList = array();
while($stmt->fetch()) {
$player['AppID'] = $appID;
$player["appID"] = $appID;
array_push($playerList, $player);
}