Fix: DB user column -> player
This commit is contained in:
@@ -0,0 +1,65 @@
|
||||
<?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 PlayerID FROM moty_player WHERE MaestroID=? AND Name=? AND EnterCode=?";
|
||||
$stmt = $db_conn->prepare($query);
|
||||
$stmt->bind_param('iss', $maestroID, $playerName, $enterCode);
|
||||
$stmt->execute();
|
||||
$stmt->bind_result($playerID);
|
||||
// while($stmt->fetch())
|
||||
$stmt->fetch();
|
||||
$stmt->close();
|
||||
|
||||
return $playerID;
|
||||
}
|
||||
|
||||
function addPlayer($maestroID, $playerName, $enterCode) {
|
||||
global $db_conn;
|
||||
|
||||
$query = "INSERT INTO moty_player (MaestroID, Name, EnterCode) VALUES (?, ?, ?)";
|
||||
$stmt = $db_conn->prepare($query);
|
||||
$stmt->bind_param('iss', $maestroID, $playerName, $enterCode);
|
||||
$stmt->execute();
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,97 @@
|
||||
<?php
|
||||
header('Content-Type: application/json');
|
||||
|
||||
$maestroID = $_POST["maestro_id"];
|
||||
$playerID = $_POST["player_id"];
|
||||
/*
|
||||
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";
|
||||
|
||||
deletePlayer($maestroID, $playerID);
|
||||
|
||||
$result = hasPlayerID($maestroID, $playerID);
|
||||
if($result === true) {
|
||||
send_result_message($replyJSON, "학생 계정 삭제 실패");
|
||||
exit;
|
||||
}
|
||||
|
||||
$result = hasPlayerRecord($maestroID, $playerID);
|
||||
if($result === true) {
|
||||
send_result_message($replyJSON, "학생 플레이 기록 삭제 실패");
|
||||
exit;
|
||||
}
|
||||
|
||||
$replyJSON["RESULT"] = "success";
|
||||
echo json_encode($replyJSON, JSON_UNESCAPED_UNICODE);
|
||||
$db_conn->close();
|
||||
|
||||
|
||||
function deletePlayer($maestroID, $playerID) {
|
||||
global $db_conn;
|
||||
|
||||
$query = "DELETE FROM moty_best_record WHERE MaestroID = ? AND PlayerID = ?";
|
||||
$stmt = $db_conn->prepare($query);
|
||||
$stmt->bind_param('ii', $maestroID, $playerID);
|
||||
$result = $stmt->execute();
|
||||
$stmt->close();
|
||||
|
||||
// if($result) {
|
||||
// echo "deleted row count : ".$stmt->affected_rows;
|
||||
// }
|
||||
|
||||
$query = "DELETE FROM moty_player WHERE MaestroID = ? AND PlayerID = ?";
|
||||
$stmt = $db_conn->prepare($query);
|
||||
$stmt->bind_param('ii', $maestroID, $playerID);
|
||||
$result = $stmt->execute();
|
||||
$stmt->close();
|
||||
|
||||
// if($result) {
|
||||
// echo "deleted row count : ".$stmt->affected_rows;
|
||||
// }
|
||||
}
|
||||
|
||||
function hasPlayerID($maestroID, $playerID) {
|
||||
global $db_conn;
|
||||
|
||||
$query = "SELECT PlayerID FROM moty_player WHERE MaestroID=? AND PlayerID=?";
|
||||
$stmt = $db_conn->prepare($query);
|
||||
$stmt->bind_param('ii', $maestroID, $playerID);
|
||||
$stmt->execute();
|
||||
$stmt->bind_result($playerID);
|
||||
// while($stmt->fetch())
|
||||
$stmt->fetch();
|
||||
$stmt->close();
|
||||
|
||||
if($playerID !== null)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
function hasPlayerRecord($maestroID, $playerID) {
|
||||
global $db_conn;
|
||||
|
||||
$query = "SELECT PlayerID FROM moty_best_record WHERE MaestroID=? AND PlayerID=?";
|
||||
$stmt = $db_conn->prepare($query);
|
||||
$stmt->bind_param('ii', $maestroID, $playerID);
|
||||
$stmt->execute();
|
||||
$stmt->bind_result($playerID);
|
||||
// while($stmt->fetch())
|
||||
$stmt->fetch();
|
||||
$stmt->close();
|
||||
|
||||
if($playerID !== null)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,78 @@
|
||||
<?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 PlayerID FROM moty_player WHERE MaestroID=? AND PlayerID<>? AND Name=? AND EnterCode=?";
|
||||
$stmt = $db_conn->prepare($query);
|
||||
$stmt->bind_param('iiss', $maestroID, $playerID, $playerName, $enterCode);
|
||||
$stmt->execute();
|
||||
$stmt->bind_result($playerID);
|
||||
// while($stmt->fetch())
|
||||
$stmt->fetch();
|
||||
$stmt->close();
|
||||
|
||||
return $playerID;
|
||||
}
|
||||
|
||||
function editPlayer($maestroID, $playerID, $playerName, $enterCode) {
|
||||
global $db_conn;
|
||||
|
||||
$query = "UPDATE moty_player SET Name=?, EnterCode=? WHERE MaestroID=? AND PlayerID=?";
|
||||
$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 PlayerID FROM moty_player WHERE MaestroID=? AND Name=? AND EnterCode=?";
|
||||
$stmt = $db_conn->prepare($query);
|
||||
$stmt->bind_param('iss', $maestroID, $playerName, $enterCode);
|
||||
$stmt->execute();
|
||||
$stmt->bind_result($playerID);
|
||||
// while($stmt->fetch())
|
||||
$stmt->fetch();
|
||||
$stmt->close();
|
||||
|
||||
return $playerID;
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
header('Content-Type: application/json');
|
||||
|
||||
$maestroName = $_POST["maestro_name"];
|
||||
$name = $_POST["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";
|
||||
|
||||
$maestroID = get_maestro_id($maestroName);
|
||||
if($maestroID === null) {
|
||||
send_error_message($replyJSON, "입력한 마에스트로 계정이 없습니다");
|
||||
$db_conn->close();
|
||||
exit;
|
||||
}
|
||||
|
||||
$replyJSON = get_login_data($maestroID, $name, $enterCode);
|
||||
if($replyJSON["PlayerID"] === null) {
|
||||
send_error_message($replyJSON, "입력한 이름/입장번호와 일치하는 계정이 없습니다");
|
||||
$db_conn->close();
|
||||
exit;
|
||||
}
|
||||
|
||||
echo json_encode($replyJSON, JSON_UNESCAPED_UNICODE);
|
||||
$db_conn->close();
|
||||
|
||||
|
||||
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', $maestroName);
|
||||
$stmt->execute();
|
||||
$stmt->bind_result($maestroID);
|
||||
// while($stmt->fetch()) {
|
||||
// ;
|
||||
// }
|
||||
$stmt->fetch();
|
||||
$stmt->close();
|
||||
|
||||
return $maestroID;
|
||||
}
|
||||
|
||||
function get_login_data($maestroID, $name, $enterCode) {
|
||||
global $db_conn;
|
||||
|
||||
$query = "SELECT PlayerID FROM moty_player WHERE MaestroID=? AND Name=? AND EnterCode=?";
|
||||
$stmt = $db_conn->prepare($query);
|
||||
$stmt->bind_param('iss', $maestroID, $name, $enterCode);
|
||||
$stmt->execute();
|
||||
$stmt->bind_result($player_id);
|
||||
// while($stmt->fetch())
|
||||
$stmt->fetch();
|
||||
$stmt->close();
|
||||
|
||||
$replyJSON["MaestroID"] = $maestroID;
|
||||
$replyJSON["PlayerID"] = $player_id;
|
||||
|
||||
return $replyJSON;
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
header('Content-Type: application/json');
|
||||
|
||||
$maestroID = $_POST["maestro_id"];
|
||||
/*
|
||||
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);
|
||||
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) {
|
||||
global $db_conn;
|
||||
|
||||
$query = "SELECT COUNT(PlayerID) FROM moty_player WHERE MaestroID=?";
|
||||
$stmt = $db_conn->prepare($query);
|
||||
$stmt->bind_param('i', $maestroID);
|
||||
$stmt->execute();
|
||||
$stmt->bind_result($playerCount);
|
||||
$stmt->fetch();
|
||||
$stmt->close();
|
||||
|
||||
return $playerCount;
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
header('Content-Type: application/json');
|
||||
|
||||
$maestroID = $_POST["maestro_id"];
|
||||
$startNo = $_POST["start_no"];
|
||||
$endNo = $_POST["end_no"];
|
||||
|
||||
include "./../setup/connect_db.php";
|
||||
|
||||
|
||||
$replyJSON = get_player_list_page($maestroID, $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, $startNo, $endNo) {
|
||||
global $db_conn;
|
||||
|
||||
$query = "
|
||||
SELECT PlayerID, Name, EnterCode FROM moty_player
|
||||
WHERE MaestroID=?
|
||||
ORDER BY PlayerID DESC
|
||||
LIMIT ?, 10;
|
||||
";
|
||||
$stmt = $db_conn->prepare($query);
|
||||
// $stmt->bind_param('iii', $maestroID, $startNo, $endNo);
|
||||
$stmt->bind_param('ii', $maestroID, $startNo);
|
||||
$stmt->execute();
|
||||
$stmt->bind_result($playerID, $name, $enterCode);
|
||||
|
||||
$playerList = array();
|
||||
while($stmt->fetch()) {
|
||||
$player['PlayerID'] = $playerID;
|
||||
$player['Name'] = $name;
|
||||
$player['EnterCode'] = $enterCode;
|
||||
array_push($playerList, $player);
|
||||
}
|
||||
|
||||
$return_array['PlayerList'] = $playerList;
|
||||
return $return_array;
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -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(PlayerID) FROM moty_player WHERE MaestroID = ? AND Name = ?";
|
||||
$stmt = $db_conn->prepare($query);
|
||||
$stmt->bind_param('is', $maestroID, $playerName);
|
||||
$stmt->execute();
|
||||
$stmt->bind_result($playerCount);
|
||||
$stmt->fetch();
|
||||
$stmt->close();
|
||||
|
||||
return $playerCount;
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -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 PlayerID, Name, EnterCode FROM moty_player
|
||||
WHERE MaestroID=? AND Name=?
|
||||
ORDER BY PlayerID 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($playerID, $name, $enterCode);
|
||||
|
||||
$playerList = array();
|
||||
while($stmt->fetch()) {
|
||||
$player['PlayerID'] = $playerID;
|
||||
$player['Name'] = $name;
|
||||
$player['EnterCode'] = $enterCode;
|
||||
array_push($playerList, $player);
|
||||
}
|
||||
|
||||
$return_array['PlayerList'] = $playerList;
|
||||
return $return_array;
|
||||
}
|
||||
|
||||
?>
|
||||
Reference in New Issue
Block a user