Add: edit player

This commit is contained in:
2018-07-04 20:09:17 +09:00
parent 401d90e3f9
commit 81860d6800
2 changed files with 131 additions and 2 deletions
+51 -2
View File
@@ -290,12 +290,61 @@
editPlayer(inputButton) { editPlayer(inputButton) {
// console.log(inputButton); // console.log(inputButton);
let clickedObjectID = this.getClickedObjectID(inputButton);
let id = $(inputButton).siblings(".player_id"); let id = $(inputButton).siblings(".player_id");
// console.log(id);
let playerID = id.text(); let playerID = id.text();
// console.log(playerID);
console.log(playerID); let name = $(inputButton).siblings(".player_name");
let playerName = name.val();
// console.log(playerName);
let enterCode = $(inputButton).siblings(".player_entercode");
let playerEnterCode = enterCode.val();
// console.log(playerEnterCode);
let xhr = new XMLHttpRequest(); //new로 생성.
xhr.open('POST', './../server/user/edit_player.php', true);
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xhr.send("maestro_id=" + maestroID + "&player_id=" + playerID + "&player_name=" + playerName + "&enter_code=" + playerEnterCode);
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(clickedObjectID);
if(clickedObjectID === "add_player_list") {
self.setupAddPlayerList();
} else if(clickedObjectID === "search_player_list") {
let playerName = $("#search_name").val();
self.setupSearchPlayerList(playerName);
}
}
}
} }
deletePlayer(inputButton) { deletePlayer(inputButton) {
+80
View File
@@ -0,0 +1,80 @@
<?php
header('Content-Type: application/json');
$maestroID = $_POST["maestro_id"];
$playerID = $_POST["player_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 = hasSamePlayerData($maestroID, $playerID, $playerName, $enterCode);
if($result !== null) {
send_error_message($replyJSON, "이미 등록된 학생과 입장 코드 정보입니다.");
// $db_conn->close();
exit;
}
editPlayer($maestroID, $playerID, $playerName, $enterCode);
$result = hasPlayerName($maestroID, $playerName, $enterCode);
if($result === null) {
send_result_message($replyJSON, "fail");
exit;
}
$replyJSON["RESULT"] = "success";
echo json_encode($replyJSON, JSON_UNESCAPED_UNICODE);
$db_conn->close();
function hasSamePlayerData($maestroID, $playerID, $playerName, $enterCode) {
global $db_conn;
$query = "SELECT UserID FROM moty_user WHERE MaestroID=? AND UserID<>? AND Name=? AND EnterCode=?";
$stmt = $db_conn->prepare($query);
$stmt->bind_param('iiss', $maestroID, $playerID, $playerName, $enterCode);
$stmt->execute();
$stmt->bind_result($userID);
// while($stmt->fetch())
$stmt->fetch();
$stmt->close();
// $replyJSON["UserID"] = $userID;
return $userID;
}
function editPlayer($maestroID, $playerID, $playerName, $enterCode) {
global $db_conn;
$query = "UPDATE moty_user SET Name=?, EnterCode=? WHERE MaestroID=? AND UserID=?";
$stmt = $db_conn->prepare($query);
$stmt->bind_param('ssii', $playerName, $enterCode, $maestroID, $playerID);
$stmt->execute();
}
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;
}
?>