Add: add_player
This commit is contained in:
@@ -15,6 +15,55 @@
|
||||
display: none;
|
||||
}
|
||||
|
||||
.player_list {
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
#add_player {
|
||||
float: left;
|
||||
line-height: 2em;
|
||||
width: 400px;
|
||||
padding: 10px;
|
||||
background-color: #aaaaff;
|
||||
}
|
||||
|
||||
#player_list_result {
|
||||
float: right;
|
||||
line-height: 2em;
|
||||
width: 500px;
|
||||
padding: 10px;
|
||||
background-color: #ffaaaa;
|
||||
}
|
||||
|
||||
#player_list_result_contents {
|
||||
vertical-align: top;
|
||||
}
|
||||
|
||||
#registered_player_list {
|
||||
list-style: none;
|
||||
}
|
||||
|
||||
#registered_player_list > li {
|
||||
display: inline-block;
|
||||
vertical-align: middle;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
#registered_player_list .registered_player_list_name {
|
||||
width: 200px;
|
||||
background-color: #ffdddd;
|
||||
}
|
||||
|
||||
#registered_player_list .registered_player_list_entercode {
|
||||
width: 200px;
|
||||
background-color: #ddffdd;
|
||||
}
|
||||
|
||||
#registered_player_list .registered_player_update {
|
||||
width: 200px;
|
||||
background-color: #ddddff;
|
||||
}
|
||||
|
||||
</style>
|
||||
|
||||
|
||||
@@ -57,6 +106,56 @@ function tabClicked(tabNo) {
|
||||
}
|
||||
}
|
||||
|
||||
function addPlayer() {
|
||||
let maestroID = sessionStorage.getItem("maestroID");
|
||||
let playerName = $("#add_player_name").val();
|
||||
let enterCode = $("#add_player_enter_code").val();
|
||||
|
||||
if(playerName.length === 0) {
|
||||
$("#add_player_notice").val("학생 이름을 입력하세요.");
|
||||
$("#add_player_name").focus();
|
||||
} else if(enterCode.length === 0) {
|
||||
$("#add_player_notice").val("엔터 코드를 입력하세요.");
|
||||
$("#add_player_enter_code").focus();
|
||||
}
|
||||
|
||||
let xhr = new XMLHttpRequest(); //new로 생성.
|
||||
xhr.open('POST', './../server/user/add_player.php', true);
|
||||
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
|
||||
xhr.send("maestro_id=" + maestroID + "&player_name=" + playerName + "&enter_code=" + enterCode);
|
||||
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;
|
||||
}
|
||||
|
||||
console.log("update player list");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
</script>
|
||||
|
||||
|
||||
@@ -73,46 +172,54 @@ function tabClicked(tabNo) {
|
||||
|
||||
|
||||
<div class="player_list">
|
||||
<h2>추가</h2>
|
||||
<span id="add_player">
|
||||
<h2>추가</h2>
|
||||
|
||||
<h3>1명 추가</h3>
|
||||
<h3>1명 추가</h3>
|
||||
|
||||
<form action="/action_page.php" method="get" id="add_user">
|
||||
<input type="text" name="name">
|
||||
<input type="text" name="entercode">
|
||||
<button type="submit" form="add_user">추가</button>
|
||||
</form>
|
||||
<div>
|
||||
학생 이름 <input type="text" name="name" id="add_player_name"><br/>
|
||||
입장 코드 <input type="text" name="entercode" id="add_player_enter_code">
|
||||
<input type="submit" name="추가" onClick="addPlayer()">
|
||||
</div>
|
||||
|
||||
<textarea>
|
||||
<textarea id="add_player_notice">
|
||||
학생 이름 : (한글) 10글자, (영문) 20글자까지 입력 가능
|
||||
입장 코드 : 숫자 1~6자리 수
|
||||
</textarea>
|
||||
</textarea>
|
||||
|
||||
|
||||
<h3>단체 추가</h3>
|
||||
<h3>단체 추가</h3>
|
||||
|
||||
<form action="/action_page.php" method="get" id="add_users">
|
||||
<textarea>
|
||||
<form action="/action_page.php" method="get" id="add_users">
|
||||
<textarea>
|
||||
엑셀에서 아래와 같이 셀에 입력한 후에 복사하고 붙여넣기
|
||||
학생 이름 | 입장 코드
|
||||
학생 이름 | 입장 코드
|
||||
...
|
||||
</textarea>
|
||||
<button type="submit" form="add_users">추가</button>
|
||||
</form>
|
||||
</textarea>
|
||||
<button type="submit" form="add_users">추가</button>
|
||||
</form>
|
||||
|
||||
<textarea>
|
||||
<textarea>
|
||||
학생 이름 : (한글) 10글자, (영문) 20글자까지 입력 가능
|
||||
입장 코드 : 숫자 1~6자리 수
|
||||
</textarea>
|
||||
</textarea>
|
||||
</span>
|
||||
|
||||
|
||||
<h2>목록</h2>
|
||||
|
||||
<div>
|
||||
<span id="player_list_result">
|
||||
목록
|
||||
<button>보기</button>
|
||||
</div>
|
||||
<div id="player_list_result_contents">
|
||||
<ul id="registered_player_list">
|
||||
<li class="registered_player_list_name">
|
||||
이름
|
||||
</li>
|
||||
<li class="registered_player_list_entercode">
|
||||
입장 코드
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<div class="search hide">
|
||||
|
||||
@@ -25,7 +25,13 @@ $result = mysqli_query($db_conn, $query);
|
||||
function send_error_message($replyJSON, $error_message) {
|
||||
$replyJSON["ERROR"] = $error_message;
|
||||
echo json_encode($replyJSON, JSON_UNESCAPED_UNICODE);
|
||||
$db_conn->close();
|
||||
// $db_conn->close();
|
||||
}
|
||||
|
||||
function send_result_message($replyJSON, $result_message) {
|
||||
$replyJSON["RESULT"] = $result_message;
|
||||
echo json_encode($replyJSON, JSON_UNESCAPED_UNICODE);
|
||||
// $db_conn->close();
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,72 @@
|
||||
<?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";
|
||||
|
||||
function send_error_message2($replyJSON, $error_message) {
|
||||
$replyJSON["ERROR"] = $error_message;
|
||||
echo json_encode($replyJSON, JSON_UNESCAPED_UNICODE);
|
||||
// $db_conn->close();
|
||||
}
|
||||
|
||||
$result = hasPlayerName($maestroID, $playerName, $enterCode);
|
||||
if($result !== null) {
|
||||
send_error_message2($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();
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -1,7 +1,7 @@
|
||||
<?php
|
||||
header('Content-Type: application/json');
|
||||
|
||||
$maestro_name = $_POST["maestro_name"];
|
||||
$maestroName = $_POST["maestro_name"];
|
||||
$name = $_POST["name"];
|
||||
$enterCode = $_POST["enter_code"];
|
||||
/*
|
||||
@@ -16,15 +16,15 @@ if(!is_numeric($enterCode)) {
|
||||
|
||||
include "./../setup/connect_db.php";
|
||||
|
||||
$maestro_id = get_maestro_id($maestro_name);
|
||||
if($maestro_id == null) {
|
||||
$maestroID = get_maestro_id($maestroName);
|
||||
if($maestroID === null) {
|
||||
send_error_message($replyJSON, "입력한 마에스트로 계정이 없습니다");
|
||||
$db_conn->close();
|
||||
exit;
|
||||
}
|
||||
|
||||
$replyJSON = get_login_data($maestro_id, $name, $enterCode);
|
||||
if($replyJSON["UserID"] == null) {
|
||||
$replyJSON = get_login_data($maestroID, $name, $enterCode);
|
||||
if($replyJSON["UserID"] === null) {
|
||||
send_error_message($replyJSON, "입력한 이름/입장번호와 일치하는 계정이 없습니다");
|
||||
$db_conn->close();
|
||||
exit;
|
||||
@@ -34,36 +34,36 @@ echo json_encode($replyJSON, JSON_UNESCAPED_UNICODE);
|
||||
$db_conn->close();
|
||||
|
||||
|
||||
function get_maestro_id($maestro_name) {
|
||||
function get_maestro_id($maestroName) {
|
||||
global $db_conn;
|
||||
|
||||
$query = "SELECT MaestroID FROM moty_maestro WHERE Name=?";
|
||||
$stmt = $db_conn->prepare($query);
|
||||
$stmt->bind_param('s', $maestro_name);
|
||||
$stmt->bind_param('s', $maestroName);
|
||||
$stmt->execute();
|
||||
$stmt->bind_result($maestro_id);
|
||||
$stmt->bind_result($maestroID);
|
||||
// while($stmt->fetch()) {
|
||||
// ;
|
||||
// }
|
||||
$stmt->fetch();
|
||||
$stmt->close();
|
||||
|
||||
return $maestro_id;
|
||||
return $maestroID;
|
||||
}
|
||||
|
||||
function get_login_data($maestro_id, $name, $enterCode) {
|
||||
function get_login_data($maestroID, $name, $enterCode) {
|
||||
global $db_conn;
|
||||
|
||||
$query = "SELECT UserID FROM moty_user WHERE MaestroID=? AND Name=? AND enterCode=?";
|
||||
$query = "SELECT UserID FROM moty_user WHERE MaestroID=? AND Name=? AND EnterCode=?";
|
||||
$stmt = $db_conn->prepare($query);
|
||||
$stmt->bind_param('iss', $maestro_id, $name, $enterCode);
|
||||
$stmt->bind_param('iss', $maestroID, $name, $enterCode);
|
||||
$stmt->execute();
|
||||
$stmt->bind_result($user_id);
|
||||
// while($stmt->fetch())
|
||||
$stmt->fetch();
|
||||
$stmt->close();
|
||||
|
||||
$replyJSON["MaestroID"] = $maestro_id;
|
||||
$replyJSON["MaestroID"] = $maestroID;
|
||||
$replyJSON["UserID"] = $user_id;
|
||||
|
||||
return $replyJSON;
|
||||
|
||||
Reference in New Issue
Block a user