Fix: player list manager

This commit is contained in:
2018-07-04 09:28:43 +09:00
parent 8d9e48af39
commit 4413f0de0b
10 changed files with 175 additions and 138 deletions
-66
View File
@@ -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;
}
?>