|
|
|
@@ -0,0 +1,386 @@
|
|
|
|
|
<?php
|
|
|
|
|
header('Content-Type: application/json');
|
|
|
|
|
|
|
|
|
|
$maestro_id = $_POST["MaestroID"];
|
|
|
|
|
$selected_app_id = $_POST["AppID"];
|
|
|
|
|
$best_record_id = $_POST["BestRecordID"];
|
|
|
|
|
|
|
|
|
|
include "./../lib/send_reply_json.php";
|
|
|
|
|
include "./../setup/connect_db.php";
|
|
|
|
|
include "./../lib/app_highest_record.php";
|
|
|
|
|
include "./../lib/util_app.php";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function sendSuccessReplyForTest() {
|
|
|
|
|
global $db_conn;
|
|
|
|
|
global $maestro_id;
|
|
|
|
|
global $selected_app_id;
|
|
|
|
|
global $best_record_id;
|
|
|
|
|
|
|
|
|
|
set_data("maestro_id", $maestro_id);
|
|
|
|
|
set_data("selected_app_id", $selected_app_id);
|
|
|
|
|
set_data("best_record_id", $best_record_id);
|
|
|
|
|
send_result_success();
|
|
|
|
|
|
|
|
|
|
$db_conn->close();
|
|
|
|
|
exit;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//sendSuccessReplyForTest();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 앱 종류에 따라
|
|
|
|
|
if($selected_app_id == 3000) { // 자격증 타이머
|
|
|
|
|
// 기록 삭제 : license_score
|
|
|
|
|
$deletedRecordCount = delete_license_score($best_record_id);
|
|
|
|
|
if($deletedRecordCount < 1) {
|
|
|
|
|
sendErrorMessageAndExit("자격증 타이머 기록 삭제 실패");
|
|
|
|
|
}
|
|
|
|
|
} else if($selected_app_id == 1004 || $selected_app_id == 1005) { // 긴글 (시험)
|
|
|
|
|
$record_info_array = get_typing_exam_record_info($best_record_id);
|
|
|
|
|
$player_id = $record_info_array["PlayerID"];
|
|
|
|
|
$writing_id = $record_info_array["WritingID"];
|
|
|
|
|
if($player_id === null || $writing_id === null) {
|
|
|
|
|
sendErrorMessageAndExit("긴글 (시험) 기록 오류");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 기록 삭제 : typing_exam_record
|
|
|
|
|
$deletedRecordCount = delete_typing_exam_record($best_record_id);
|
|
|
|
|
if($deletedRecordCount < 1) {
|
|
|
|
|
sendErrorMessageAndExit("긴글 (시험) 기록 삭제 실패");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// typing_exam_highest_record 업데이트
|
|
|
|
|
updateTypingExamHighestRecord($maestro_id, $player_id, $writing_id);
|
|
|
|
|
}
|
|
|
|
|
else { // 일반 앱
|
|
|
|
|
$record_info_array = get_best_record_info($best_record_id);
|
|
|
|
|
$player_id = $record_info_array["PlayerID"];
|
|
|
|
|
$app_id = $record_info_array["AppID"];
|
|
|
|
|
if($player_id === null || $app_id === null) {
|
|
|
|
|
sendErrorMessageAndExit("기록 오류");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 기록 삭제 : best_record
|
|
|
|
|
$deletedRecordCount = delete_best_record($best_record_id);
|
|
|
|
|
if($deletedRecordCount < 1) {
|
|
|
|
|
sendErrorMessageAndExit("기록 삭제 실패");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// app_highest_record 업데이트
|
|
|
|
|
updateAppHighestRecord($maestro_id, $player_id, $app_id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
set_data("message", "기록 삭제 성공");
|
|
|
|
|
send_result_success();
|
|
|
|
|
|
|
|
|
|
$db_conn->close();
|
|
|
|
|
exit;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function sendErrorMessageAndExit($message) {
|
|
|
|
|
global $db_conn;
|
|
|
|
|
|
|
|
|
|
set_error_message($message);
|
|
|
|
|
send_result_fail();
|
|
|
|
|
$db_conn->close();
|
|
|
|
|
exit;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function updateTypingExamHighestRecord($maestro_id, $player_id, $writing_id) {
|
|
|
|
|
global $db_conn;
|
|
|
|
|
|
|
|
|
|
$record_info_array = get_typing_exam_best_record_info($maestro_id, $player_id, $writing_id);
|
|
|
|
|
$record = $record_info_array["Record"];
|
|
|
|
|
$record_date_time = $record_info_array["RecordDateTime"];
|
|
|
|
|
if ($record === null || $record_date_time === null) {
|
|
|
|
|
delete_typing_exam_highest_record($maestro_id, $player_id, $writing_id);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$highest_record_id = get_typing_exam_highest_record_id($maestro_id, $player_id, $writing_id);
|
|
|
|
|
if ($highest_record_id !== null && $highest_record_id > 0) {
|
|
|
|
|
update_typing_exam_highest_record($highest_record_id, $record, $record_date_time);
|
|
|
|
|
} else {
|
|
|
|
|
insert_new_typing_exam_highest_record($maestro_id, $player_id, $writing_id, $record, $record_date_time);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function updateAppHighestRecord($maestro_id, $player_id, $app_id) {
|
|
|
|
|
$record_info_array = get_best_record_record_info($maestro_id, $player_id, $app_id);
|
|
|
|
|
$best_record = $record_info_array["BestRecord"];
|
|
|
|
|
$record_date_time = $record_info_array["RecordDateTime"];
|
|
|
|
|
if ($best_record === null || $record_date_time === null) {
|
|
|
|
|
delete_app_highest_record($maestro_id, $player_id, $app_id);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$highest_record_id = get_app_highest_record_id($maestro_id, $player_id, $app_id);
|
|
|
|
|
if ($highest_record_id !== null && $highest_record_id > 0) {
|
|
|
|
|
update_app_highest_record($highest_record_id, $best_record, $record_date_time);
|
|
|
|
|
} else {
|
|
|
|
|
insert_new_app_highest_record($maestro_id, $player_id, $app_id, $best_record, $record_date_time);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function delete_license_score($best_record_id) {
|
|
|
|
|
global $db_conn;
|
|
|
|
|
|
|
|
|
|
$query = "
|
|
|
|
|
DELETE FROM license_score
|
|
|
|
|
WHERE LicenseScoreID = ?
|
|
|
|
|
";
|
|
|
|
|
$stmt = $db_conn->prepare($query);
|
|
|
|
|
$stmt->bind_param("i", $best_record_id);
|
|
|
|
|
$result = $stmt->execute();
|
|
|
|
|
$stmt->close();
|
|
|
|
|
|
|
|
|
|
return $result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function get_typing_exam_record_info($best_record_id) {
|
|
|
|
|
global $db_conn;
|
|
|
|
|
|
|
|
|
|
$query = "
|
|
|
|
|
SELECT PlayerID, WritingID
|
|
|
|
|
FROM typing_exam_record
|
|
|
|
|
WHERE TypingExamRecordID = ?
|
|
|
|
|
";
|
|
|
|
|
$stmt = $db_conn->prepare($query);
|
|
|
|
|
$stmt->bind_param("i", $best_record_id);
|
|
|
|
|
$stmt->execute();
|
|
|
|
|
$stmt->bind_result($player_id, $writing_id);
|
|
|
|
|
$stmt->fetch();
|
|
|
|
|
$stmt->close();
|
|
|
|
|
|
|
|
|
|
return array("PlayerID" => $player_id, "WritingID" => $writing_id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function delete_typing_exam_record($best_record_id) {
|
|
|
|
|
global $db_conn;
|
|
|
|
|
|
|
|
|
|
$query = "
|
|
|
|
|
DELETE FROM typing_exam_record
|
|
|
|
|
WHERE TypingExamRecordID = ?
|
|
|
|
|
";
|
|
|
|
|
$stmt = $db_conn->prepare($query);
|
|
|
|
|
$stmt->bind_param("i", $best_record_id);
|
|
|
|
|
$result = $stmt->execute();
|
|
|
|
|
$stmt->close();
|
|
|
|
|
|
|
|
|
|
return $result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function get_typing_exam_best_record_info($maestro_id, $player_id, $writing_id) {
|
|
|
|
|
global $db_conn;
|
|
|
|
|
|
|
|
|
|
$query = "
|
|
|
|
|
SELECT Record, RecordDateTime
|
|
|
|
|
FROM typing_exam_record
|
|
|
|
|
WHERE MaestroID = ? AND PlayerID = ? AND WritingID = ? AND Record > 0
|
|
|
|
|
ORDER BY Record DESC
|
|
|
|
|
LIMIT 1
|
|
|
|
|
";
|
|
|
|
|
$stmt = $db_conn->prepare($query);
|
|
|
|
|
$stmt->bind_param("iii", $maestro_id, $player_id, $writing_id);
|
|
|
|
|
$stmt->execute();
|
|
|
|
|
$stmt->bind_result($record, $record_date_time);
|
|
|
|
|
$stmt->fetch();
|
|
|
|
|
$stmt->close();
|
|
|
|
|
|
|
|
|
|
return array("Record" => $record, "RecordDateTime" => $record_date_time);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function get_typing_exam_highest_record_id($maestro_id, $player_id, $writing_id) {
|
|
|
|
|
global $db_conn;
|
|
|
|
|
|
|
|
|
|
$query = "
|
|
|
|
|
SELECT TypingExamHighestRecordID
|
|
|
|
|
FROM typing_exam_highest_record
|
|
|
|
|
WHERE MaestroID = ? AND PlayerID = ? AND WritingID = ? AND HighestRecord > 0
|
|
|
|
|
ORDER BY HighestRecord DESC
|
|
|
|
|
LIMIT 1
|
|
|
|
|
";
|
|
|
|
|
$stmt = $db_conn->prepare($query);
|
|
|
|
|
$stmt->bind_param("iii", $maestro_id, $player_id, $writing_id);
|
|
|
|
|
$stmt->execute();
|
|
|
|
|
$stmt->bind_result($new_best_record_id);
|
|
|
|
|
$stmt->fetch();
|
|
|
|
|
$stmt->close();
|
|
|
|
|
|
|
|
|
|
return $new_best_record_id;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function delete_typing_exam_highest_record($maestro_id, $player_id, $writing_id)
|
|
|
|
|
{
|
|
|
|
|
global $db_conn;
|
|
|
|
|
|
|
|
|
|
$query = "
|
|
|
|
|
DELETE FROM typing_exam_highest_record
|
|
|
|
|
WHERE MaestroID = ? AND PlayerID = ? AND WritingID = ?
|
|
|
|
|
";
|
|
|
|
|
$stmt = $db_conn->prepare($query);
|
|
|
|
|
$stmt->bind_param("iii", $maestro_id, $player_id, $writing_id);
|
|
|
|
|
$result = $stmt->execute();
|
|
|
|
|
$stmt->close();
|
|
|
|
|
|
|
|
|
|
return $result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function update_typing_exam_highest_record($highest_record_id, $record, $record_date_time) {
|
|
|
|
|
global $db_conn;
|
|
|
|
|
|
|
|
|
|
$query = "
|
|
|
|
|
UPDATE typing_exam_highest_record
|
|
|
|
|
SET HighestRecord = ?, RecordDateTime = ?
|
|
|
|
|
WHERE TypingExamHighestRecordID = ?
|
|
|
|
|
";
|
|
|
|
|
$stmt = $db_conn->prepare($query);
|
|
|
|
|
$stmt->bind_param("dsi", $record, $record_date_time, $highest_record_id);
|
|
|
|
|
$result = $stmt->execute();
|
|
|
|
|
$stmt->close();
|
|
|
|
|
|
|
|
|
|
return $result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function insert_new_typing_exam_highest_record($maestro_id, $player_id, $writing_id, $record, $record_date_time) {
|
|
|
|
|
global $db_conn;
|
|
|
|
|
|
|
|
|
|
$query = "
|
|
|
|
|
INSERT INTO typing_exam_highest_record (MaestroID, PlayerID, WritingID, HighestRecord, RecordDateTime)
|
|
|
|
|
VALUES (?, ?, ?, ?, ?)
|
|
|
|
|
";
|
|
|
|
|
$stmt = $db_conn->prepare($query);
|
|
|
|
|
$stmt->bind_param("iiids", $maestro_id, $player_id, $writing_id, $record, $record_date_time);
|
|
|
|
|
$result = $stmt->execute();
|
|
|
|
|
$stmt->close();
|
|
|
|
|
|
|
|
|
|
return $result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function get_best_record_info($best_record_id) {
|
|
|
|
|
global $db_conn;
|
|
|
|
|
|
|
|
|
|
$query = "
|
|
|
|
|
SELECT PlayerID, AppID
|
|
|
|
|
FROM best_record
|
|
|
|
|
WHERE BestRecordID = ?
|
|
|
|
|
";
|
|
|
|
|
$stmt = $db_conn->prepare($query);
|
|
|
|
|
$stmt->bind_param("i", $best_record_id);
|
|
|
|
|
$stmt->execute();
|
|
|
|
|
$stmt->bind_result($player_id, $app_id);
|
|
|
|
|
$stmt->fetch();
|
|
|
|
|
$stmt->close();
|
|
|
|
|
|
|
|
|
|
return array("PlayerID" => $player_id, "AppID" => $app_id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function delete_best_record($best_record_id) {
|
|
|
|
|
global $db_conn;
|
|
|
|
|
|
|
|
|
|
$query = "
|
|
|
|
|
DELETE FROM best_record
|
|
|
|
|
WHERE BestRecordID = ?
|
|
|
|
|
";
|
|
|
|
|
$stmt = $db_conn->prepare($query);
|
|
|
|
|
$stmt->bind_param("i", $best_record_id);
|
|
|
|
|
$result = $stmt->execute();
|
|
|
|
|
$stmt->close();
|
|
|
|
|
|
|
|
|
|
return $result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function get_best_record_record_info($maestro_id, $player_id, $app_id) {
|
|
|
|
|
global $db_conn;
|
|
|
|
|
|
|
|
|
|
$orderStatement = is_highest_record_prefer_app($app_id) ? "ORDER BY BestRecord DESC" : "ORDER BY BestRecord ASC";
|
|
|
|
|
$query = "
|
|
|
|
|
SELECT BestRecord, RecordDateTime
|
|
|
|
|
FROM best_record
|
|
|
|
|
WHERE MaestroID = ? AND PlayerID = ? AND AppID = ?
|
|
|
|
|
".$orderStatement."
|
|
|
|
|
LIMIT 1
|
|
|
|
|
";
|
|
|
|
|
|
|
|
|
|
$stmt = $db_conn->prepare($query);
|
|
|
|
|
$stmt->bind_param("iii", $maestro_id, $player_id, $app_id);
|
|
|
|
|
$stmt->execute();
|
|
|
|
|
$stmt->bind_result($best_record, $record_date_time);
|
|
|
|
|
$stmt->fetch();
|
|
|
|
|
$stmt->close();
|
|
|
|
|
|
|
|
|
|
return array("BestRecord" => $best_record, "RecordDateTime" => $record_date_time);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function get_app_highest_record_id($maestro_id, $player_id, $app_id)
|
|
|
|
|
{
|
|
|
|
|
global $db_conn;
|
|
|
|
|
|
|
|
|
|
$orderStatement = is_highest_record_prefer_app($app_id) ? "ORDER BY HighestRecord DESC" : "ORDER BY HighestRecord ASC";
|
|
|
|
|
$query = "
|
|
|
|
|
SELECT AppHighestRecordID
|
|
|
|
|
FROM app_highest_record
|
|
|
|
|
WHERE MaestroID = ? AND PlayerID = ? AND AppID = ?
|
|
|
|
|
".$orderStatement."
|
|
|
|
|
LIMIT 1
|
|
|
|
|
";
|
|
|
|
|
$stmt = $db_conn->prepare($query);
|
|
|
|
|
$stmt->bind_param("iii", $maestro_id, $player_id, $app_id);
|
|
|
|
|
$stmt->execute();
|
|
|
|
|
$stmt->bind_result($highest_record_id);
|
|
|
|
|
$stmt->fetch();
|
|
|
|
|
$stmt->close();
|
|
|
|
|
|
|
|
|
|
return $highest_record_id;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function delete_app_highest_record($maestro_id, $player_id, $app_id)
|
|
|
|
|
{
|
|
|
|
|
global $db_conn;
|
|
|
|
|
|
|
|
|
|
$query = "
|
|
|
|
|
DELETE FROM app_highest_record
|
|
|
|
|
WHERE MaestroID = ? AND PlayerID = ? AND AppID = ?
|
|
|
|
|
";
|
|
|
|
|
$stmt = $db_conn->prepare($query);
|
|
|
|
|
$stmt->bind_param("iii", $maestro_id, $player_id, $app_id);
|
|
|
|
|
$result = $stmt->execute();
|
|
|
|
|
$stmt->close();
|
|
|
|
|
|
|
|
|
|
return $result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function update_app_highest_record($highest_record_id, $record, $record_date_time) {
|
|
|
|
|
global $db_conn;
|
|
|
|
|
|
|
|
|
|
$query = "
|
|
|
|
|
UPDATE app_highest_record
|
|
|
|
|
SET HighestRecord = ?, RecordDateTime = ?
|
|
|
|
|
WHERE AppHighestRecordID = ?
|
|
|
|
|
";
|
|
|
|
|
$stmt = $db_conn->prepare($query);
|
|
|
|
|
$stmt->bind_param("dsi", $record, $record_date_time, $highest_record_id);
|
|
|
|
|
$result = $stmt->execute();
|
|
|
|
|
$stmt->close();
|
|
|
|
|
|
|
|
|
|
return $result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function insert_new_app_highest_record($maestro_id, $player_id, $app_id, $record, $record_date_time) {
|
|
|
|
|
global $db_conn;
|
|
|
|
|
|
|
|
|
|
$query = "
|
|
|
|
|
INSERT INTO app_highest_record (MaestroID, PlayerID, AppID, HighestRecord, RecordDateTime)
|
|
|
|
|
VALUES (?, ?, ?, ?, ?)
|
|
|
|
|
";
|
|
|
|
|
$stmt = $db_conn->prepare($query);
|
|
|
|
|
$stmt->bind_param('iiids', $maestro_id, $player_id, $app_id, $record, $record_date_time);
|
|
|
|
|
$result = $stmt->execute();
|
|
|
|
|
$stmt->close();
|
|
|
|
|
|
|
|
|
|
return $result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
?>
|