Fix: player list manager
This commit is contained in:
@@ -1,19 +1,9 @@
|
||||
let maestroID = -1;
|
||||
// let playerCount = 0;
|
||||
// let playerListPage = 0;
|
||||
// let lastPageNo = 0;
|
||||
|
||||
let addPlayerListManager;
|
||||
let searchPlayerListManager;
|
||||
|
||||
// let addPlayerList;
|
||||
// let addPlayerListNavigator;
|
||||
|
||||
// let searchPlayerList;
|
||||
// let searchPlayerListNavigator;
|
||||
|
||||
let mouseAppList;
|
||||
|
||||
let typingAppList;
|
||||
|
||||
|
||||
@@ -41,7 +31,11 @@ function tabClicked(tabNo) {
|
||||
break;
|
||||
case 2:
|
||||
$("#section_add_player").addClass("hide");
|
||||
|
||||
$("#search_name").val("");
|
||||
searchPlayerListManager.setupSearchPlayerList("");
|
||||
$("#search").removeClass("hide");
|
||||
|
||||
$("#mouse_app_list").addClass("hide");
|
||||
$("#typing_app_list").addClass("hide");
|
||||
break;
|
||||
|
||||
@@ -135,7 +135,7 @@ class PlayerList {
|
||||
}
|
||||
|
||||
console.log("update player list");
|
||||
loadPlayerListPage(1);
|
||||
self.loadPlayerListPage(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -149,7 +149,7 @@ class PlayerList {
|
||||
let endNo = pageIndex * 10 + 9;
|
||||
|
||||
let xhr = new XMLHttpRequest(); //new로 생성.
|
||||
xhr.open('POST', './../server/user/registered_player_list_page.php', true);
|
||||
xhr.open('POST', './../server/user/registered_player_list.php', true);
|
||||
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
|
||||
xhr.send("maestro_id=" + maestroID + "&start_no=" + startNo + "&end_no=" + endNo);
|
||||
xhr.onload = function() {
|
||||
@@ -188,5 +188,3 @@ class PlayerList {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -56,7 +56,7 @@
|
||||
self.activePageNo = 1;
|
||||
|
||||
self.list.loadPlayerListPage(self.activePageNo);
|
||||
self.listNavigator.updateNavigator(self.playerCount);
|
||||
self.listNavigator.updateNavigator(self.activePageNo, self.lastPageNo);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -71,7 +71,7 @@
|
||||
let endNo = pageIndex * 10 + 9;
|
||||
|
||||
let xhr = new XMLHttpRequest(); //new로 생성.
|
||||
xhr.open('POST', './../server/user/registered_player_list_page.php', true);
|
||||
xhr.open('POST', './../server/user/registered_player_list.php', true);
|
||||
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
|
||||
xhr.send("maestro_id=" + maestroID + "&start_no=" + startNo + "&end_no=" + endNo);
|
||||
xhr.onload = function() {
|
||||
@@ -106,7 +106,57 @@
|
||||
|
||||
self.playerCount = replyJSON["PlayerList"].length;
|
||||
console.log(self.playerCount);
|
||||
self.listNavigator.updateNavigator(self.playerCount);
|
||||
// self.lastPageNo = Math.ceil( (self.playerCount + 1) / 10 );
|
||||
// self.activePageNo = 1;
|
||||
|
||||
self.listNavigator.updateNavigator(self.activePageNo, self.lastPageNo);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
setupSearchPlayerList(playerName) {
|
||||
let self = this;
|
||||
|
||||
let xhr = new XMLHttpRequest(); //new로 생성.
|
||||
xhr.open('POST', './../server/user/search_player_count.php', true);
|
||||
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
|
||||
xhr.send("maestro_id=" + maestroID + "&player_name=" + playerName);
|
||||
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;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
self.playerCount = replyJSON["Count"];
|
||||
self.lastPageNo = Math.ceil( (self.playerCount + 1) / 10 );
|
||||
self.activePageNo = 1;
|
||||
|
||||
// self.list.loadPlayerListPage(self.activePageNo);
|
||||
// self.listNavigator.updateNavigator(self.playerCount);
|
||||
self.updateSearchPlayerListPage(playerName, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -120,9 +170,9 @@
|
||||
let endNo = pageIndex * 10 + 9;
|
||||
|
||||
let xhr = new XMLHttpRequest(); //new로 생성.
|
||||
xhr.open('POST', './../server/user/registered_player_list_page.php', true);
|
||||
xhr.open('POST', './../server/user/search_player_list.php', true);
|
||||
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
|
||||
xhr.send("maestro_id=" + maestroID + "&playerName=" + playerName + "&start_no=" + startNo + "&end_no=" + endNo);
|
||||
xhr.send("maestro_id=" + maestroID + "&player_name=" + playerName + "&start_no=" + startNo + "&end_no=" + endNo);
|
||||
xhr.onload = function() {
|
||||
if(xhr.readyState === 4 && xhr.status === 200) {
|
||||
// console.log(xhr.responseText);
|
||||
@@ -154,14 +204,14 @@
|
||||
self.list.updatePlayerList(replyJSON["PlayerList"]);
|
||||
|
||||
self.playerCount = replyJSON["PlayerList"].length;
|
||||
self.listNavigator.updateNavigator(self.playerCount);
|
||||
// self.lastPageNo = Math.ceil( (self.playerCount + 1) / 10 );
|
||||
// self.activePageNo = 1;
|
||||
|
||||
self.listNavigator.updateNavigator(self.activePageNo, self.lastPageNo);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// onClickPlayerListPage(pageNo) {
|
||||
// this.listNavigator.onClickPlayerListPage(pageNo);
|
||||
// }
|
||||
|
||||
onClickPlayerListPage(pageNo) {
|
||||
switch(pageNo) {
|
||||
@@ -192,5 +242,3 @@
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -9,8 +9,10 @@
|
||||
this.lastPageNo = 1;
|
||||
}
|
||||
|
||||
updateNavigator(playerCount) {
|
||||
this.lastPageNo = Math.ceil( (playerCount + 1) / 10 );
|
||||
updateNavigator(activePageNo, lastPageNo) {
|
||||
this.activePageNo = activePageNo;
|
||||
this.lastPageNo = lastPageNo;
|
||||
// this.lastPageNo = Math.ceil( (playerCount + 1) / 10 );
|
||||
|
||||
$(this.pageNoArea).empty();
|
||||
|
||||
@@ -50,6 +52,3 @@
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -55,7 +55,7 @@ function addPlayer() {
|
||||
return;
|
||||
}
|
||||
|
||||
loadPlayerListPage(1);
|
||||
addPlayerListManager.updateAddPlayerListPage(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ $(document).ready(function() {
|
||||
|
||||
// searchPlayerList = new PlayerList($("#search_player_list"));
|
||||
// searchPlayerListNavigator = new PlayerListNavigator($("#search_player_list_navigator > #page_no_area"));
|
||||
searchPlayerListManager.updateSearchPlayerListPage(1);
|
||||
searchPlayerListManager.setupSearchPlayerList("");
|
||||
});
|
||||
|
||||
|
||||
@@ -20,40 +20,7 @@ function searchPlayer() {
|
||||
$("#add_player_name").focus();
|
||||
}
|
||||
|
||||
let xhr = new XMLHttpRequest(); //new로 생성.
|
||||
xhr.open('POST', './../server/user/search_player.php', true);
|
||||
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
|
||||
xhr.send("maestro_id=" + maestroID + "&player_name=" + playerName);
|
||||
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;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
loadPlayerListPage(1);
|
||||
}
|
||||
}
|
||||
searchPlayerListManager.setupSearchPlayerList(playerName);
|
||||
}
|
||||
|
||||
</script>
|
||||
@@ -61,9 +28,10 @@ function searchPlayer() {
|
||||
|
||||
|
||||
<span id="search_player">
|
||||
검색
|
||||
아이디
|
||||
<input type="text" id="search_name"><button>찾기</button><br/>
|
||||
<h1>검색</h1>
|
||||
|
||||
학생 이름
|
||||
<input type="text" id="search_name"><input type="submit" name="찾기" onClick="searchPlayer()"><br/>
|
||||
<br/>
|
||||
|
||||
<!--
|
||||
|
||||
@@ -1,66 +0,0 @@
|
||||
<?php
|
||||
header('Content-Type: application/json');
|
||||
|
||||
$maestroID = $_POST["maestro_id"];
|
||||
$playerName = $_POST["player_name"];
|
||||
$enterCode = $_POST["enter_code"];
|
||||
/*
|
||||
if(!is_numeric($enterCode)) {
|
||||
send_error_code('생년월일이 숫자가 아닙니다. : '.$enterCode);
|
||||
exit;
|
||||
} else if(strlen($enterCode) != 6) {
|
||||
send_error_code('6자리 숫자값을 정확히 입력하세요 : YYMMDD (예 : 120131) : '.$enterCode);
|
||||
exit;
|
||||
}
|
||||
*/
|
||||
|
||||
include "./../setup/connect_db.php";
|
||||
|
||||
$result = hasPlayerName($maestroID, $playerName, $enterCode);
|
||||
if($result !== null) {
|
||||
send_error_message($replyJSON, "이미 등록된 학생과 입장 코드 정보입니다.");
|
||||
// $db_conn->close();
|
||||
exit;
|
||||
}
|
||||
|
||||
addPlayer($maestroID, $playerName, $enterCode);
|
||||
|
||||
$result = hasPlayerName($maestroID, $playerName, $enterCode);
|
||||
if($result === null) {
|
||||
send_result_message($replyJSON, "fail");
|
||||
exit;
|
||||
} else {
|
||||
send_result_message($replyJSON, "success");
|
||||
exit;
|
||||
}
|
||||
|
||||
// echo json_encode($replyJSON, JSON_UNESCAPED_UNICODE);
|
||||
// $db_conn->close();
|
||||
|
||||
|
||||
function hasPlayerName($maestroID, $playerName, $enterCode) {
|
||||
global $db_conn;
|
||||
|
||||
$query = "SELECT UserID FROM moty_user WHERE MaestroID=? AND Name=? AND EnterCode=?";
|
||||
$stmt = $db_conn->prepare($query);
|
||||
$stmt->bind_param('iss', $maestroID, $playerName, $enterCode);
|
||||
$stmt->execute();
|
||||
$stmt->bind_result($userID);
|
||||
// while($stmt->fetch())
|
||||
$stmt->fetch();
|
||||
$stmt->close();
|
||||
|
||||
// $replyJSON["UserID"] = $userID;
|
||||
return $userID;
|
||||
}
|
||||
|
||||
function addPlayer($maestroID, $playerName, $enterCode) {
|
||||
global $db_conn;
|
||||
|
||||
$query = "INSERT INTO moty_user (MaestroID, Name, EnterCode) VALUES (?, ?, ?)";
|
||||
$stmt = $db_conn->prepare($query);
|
||||
$stmt->bind_param('iss', $maestroID, $playerName, $enterCode);
|
||||
$stmt->execute();
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
header('Content-Type: application/json');
|
||||
|
||||
$maestroID = $_POST["maestro_id"];
|
||||
$playerName = $_POST["player_name"];
|
||||
/*
|
||||
if(!is_numeric($enterCode)) {
|
||||
send_error_code('생년월일이 숫자가 아닙니다. : '.$enterCode);
|
||||
exit;
|
||||
} else if(strlen($enterCode) != 6) {
|
||||
send_error_code('6자리 숫자값을 정확히 입력하세요 : YYMMDD (예 : 120131) : '.$enterCode);
|
||||
exit;
|
||||
}
|
||||
*/
|
||||
|
||||
include "./../setup/connect_db.php";
|
||||
|
||||
$result = getPlayerCount($maestroID, $playerName);
|
||||
if($result === null) {
|
||||
send_error_message($replyJSON, "등록된 학생이 없습니다.");
|
||||
// $db_conn->close();
|
||||
exit;
|
||||
}
|
||||
|
||||
$replyJSON["Count"] = $result;
|
||||
$replyJSON["RESULT"] = "ok";
|
||||
echo json_encode($replyJSON, JSON_UNESCAPED_UNICODE);
|
||||
$db_conn->close();
|
||||
|
||||
|
||||
function getPlayerCount($maestroID, $playerName) {
|
||||
global $db_conn;
|
||||
|
||||
$query = "SELECT COUNT(UserID) FROM moty_user WHERE MaestroID = ? AND Name = ?";
|
||||
$stmt = $db_conn->prepare($query);
|
||||
$stmt->bind_param('is', $maestroID, $playerName);
|
||||
$stmt->execute();
|
||||
$stmt->bind_result($userCount);
|
||||
$stmt->fetch();
|
||||
$stmt->close();
|
||||
|
||||
return $userCount;
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
header('Content-Type: application/json');
|
||||
|
||||
$maestroID = $_POST["maestro_id"];
|
||||
$playerName = $_POST["player_name"];
|
||||
$startNo = $_POST["start_no"];
|
||||
$endNo = $_POST["end_no"];
|
||||
|
||||
include "./../setup/connect_db.php";
|
||||
|
||||
|
||||
$replyJSON = get_player_list_page($maestroID, $playerName, $startNo, $endNo);
|
||||
if($replyJSON.length === 0) {
|
||||
send_error_message($replyJSON, "해당 이름으로 등록된 학생 없음");
|
||||
$db_conn->close();
|
||||
exit;
|
||||
}
|
||||
|
||||
$replyJSON["RESULT"] = "ok";
|
||||
echo json_encode($replyJSON, JSON_UNESCAPED_UNICODE);
|
||||
$db_conn->close();
|
||||
|
||||
|
||||
function get_player_list_page($maestroID, $playerName, $startNo, $endNo) {
|
||||
global $db_conn;
|
||||
|
||||
$query = "
|
||||
SELECT UserID, Name, EnterCode FROM moty_user
|
||||
WHERE MaestroID=? AND Name=?
|
||||
ORDER BY UserID DESC
|
||||
LIMIT ?, 10;
|
||||
";
|
||||
$stmt = $db_conn->prepare($query);
|
||||
// $stmt->bind_param('iii', $maestroID, $startNo, $endNo);
|
||||
$stmt->bind_param('isi', $maestroID, $playerName, $startNo);
|
||||
$stmt->execute();
|
||||
$stmt->bind_result($userID, $name, $enterCode);
|
||||
|
||||
$playerList = array();
|
||||
while($stmt->fetch()) {
|
||||
$player['UserID'] = $userID;
|
||||
$player['Name'] = $name;
|
||||
$player['EnterCode'] = $enterCode;
|
||||
array_push($playerList, $player);
|
||||
}
|
||||
|
||||
$return_array['PlayerList'] = $playerList;
|
||||
return $return_array;
|
||||
}
|
||||
|
||||
?>
|
||||
Reference in New Issue
Block a user