Add: sql - login, history_record

This commit is contained in:
2018-05-17 18:51:09 +09:00
parent 976e5563b7
commit 235327cd3e
19 changed files with 529 additions and 91 deletions
+56
View File
@@ -0,0 +1,56 @@
<!doctype html>
<html>
<head>
<meta charset="UTF-8" />
<title>hello phaser!</title>
<script src="//cdn.jsdelivr.net/phaser/2.5.0/phaser.min.js"></script>
<script type="text/javascript" src="./../../../jquery/jquery-3.2.1.min.js"></script>
<script type="text/javascript" language="JavaScript">
function checkAll() {
var chk = document.getElementsByName("active_stage[]");
var cnt = chk.length;
for(var i = 0; i < cnt; i++) {
chk[i].checked = document.frm.chkAll.checked;
}
}
</script>
</head>
<body>
<form name="frm" action="activate_stage.php" method="post">
<input type="checkbox" name="chkAll" onClick="javascript:checkAll();" />전체 선택<br />
<br/><br/>
<label type="label">한글</label><br/>
<input type="checkbox" name="active_stage[]" value="korean_basic" />기본자리<br />
<input type="checkbox" name="active_stage[]" value="korean_left_upper" />왼손 윗글쇠<br />
<input type="checkbox" name="active_stage[]" value="korean_second_finger" />검지 글쇠<br />
<input type="checkbox" name="active_stage[]" value="korean_right_upper" />오른손 윗글쇠<br />
<input type="checkbox" name="active_stage[]" value="korean_left_lower" />왼손 밑글쇠<br />
<input type="checkbox" name="active_stage[]" value="korean_right_lower" />오른손 밑글쇠<br />
<input type="checkbox" name="active_stage[]" value="korean_left_upper_double" />쌍자음<br />
<input type="checkbox" name="active_stage[]" value="korean_right_upper_double" />쌍모음<br />
<input type="checkbox" name="active_stage[]" value="korean_word" />짧은 글<br />
<input type="checkbox" name="active_stage[]" value="korean_sentence" />긴 글<br />
<br/><br/>
<label type="label">영문</label><br/>
<input type="checkbox" name="active_stage[]" value="english_basic" />기본자리<br />
<input type="checkbox" name="active_stage[]" value="english_left_upper" />왼손 윗글쇠<br />
<input type="checkbox" name="active_stage[]" value="english_second_finger" />검지 글쇠<br />
<input type="checkbox" name="active_stage[]" value="english_right_upper" />오른손 윗글쇠<br />
<input type="checkbox" name="active_stage[]" value="english_left_lower" />왼손 밑글쇠<br />
<input type="checkbox" name="active_stage[]" value="english_right_lower" />오른손 밑글쇠<br />
<input type="checkbox" name="active_stage[]" value="english_word" />짧은 글<br />
<input type="checkbox" name="active_stage[]" value="english_sentence" />긴 글<br />
<br/><br/>
<input type="button" value="업데이트" onClick="document.frm.submit();" />
</form>
</body>
</html>
+29
View File
@@ -0,0 +1,29 @@
<?php
// header('Content-Type: application/json');
include "send_error_code.php";
$active_stage_list = $_POST['active_stage'];
$cnt = count($active_stage_list);
include "./connect_db.php";
$query = "UPDATE afterschool_activated_stage SET Activated = 0";
$result = $db_conn->query($query);
for($i = 0; $i < $cnt; $i++) {
$array_item = $active_stage_list[$i];
$query = "UPDATE afterschool_activated_stage SET Activated = 1 WHERE StageName = ?";
$stmt = $db_conn->prepare($query);
$stmt->bind_param('s', $array_item);
$stmt->execute();
if($stmt->affected_rows > 0) {
echo($array_item." : activated<br/>");
} else {
echo $array_item." : db error<br/>";
}
}
?>
+23
View File
@@ -0,0 +1,23 @@
<!doctype html>
<html>
<head>
<meta charset="UTF-8" />
<title>hello phaser!</title>
<script src="//cdn.jsdelivr.net/phaser/2.5.0/phaser.min.js"></script>
</head>
<body>
<form name="add_user" method="post" action="add_user.php">
이름 : <input type="text" name="name" /><br />
생년월일 : <input type="text" name="birthday" /><br />
<input type="submit" value="추가">
</form>
<br/><br/>
<form name="delete_test_user_data" method="get" action="delete_test_user_data.php">
<input type="submit" value="test 유저 데이터 삭제">
</form>
</body>
</html>
+31
View File
@@ -0,0 +1,31 @@
<?php
// header('Content-Type: application/json');
$name = $_POST["name"];
$birthday = $_POST["birthday"];
if(!is_numeric($birthday)) {
echo '생년월일이 숫자가 아닙니다.';
return;
} else if(strlen($birthday) != 6) {
echo '6자리 숫자값을 정확히 입력하세요 : YYMMDD (예 : 120131)';
return;
}
include "./connect_db.php";
$query = "INSERT INTO afterschool_user(UserID, Name, Birthday) values (null,?,?)";
$stmt = $db_conn->prepare($query);
$stmt->bind_param('ss', $name, $birthday);
$stmt->execute();
if($stmt->affected_rows > 0) {
echo("succeed");
} else {
echo "fail";
}
$db_conn->close();
?>
+11
View File
@@ -0,0 +1,11 @@
<?php
// header('Content-Type: application/json');
include "./connect_db.php";
$query = "DELETE FROM afterschool_record WHERE UserID=31;";
$result = $db_conn->query($query);
$db_conn->close();
?>
+1
View File
@@ -18,6 +18,7 @@
<script src="../../game/lib/input_type_text.js"></script>
<script src="../../game/lib/round_rect_button.js"></script>
<script src="../../game/lib/fullscreen_button.js"></script>
<script src="../../game/lib/db_connect_manager.js"></script>
<!-- source files -->
<script src="../../game/login/login.js"></script>
-15
View File
@@ -1,15 +0,0 @@
<?php
$db_host = "localhost";
$db_user = "afterschool";
$db_passwd = "sEobMPuJ2A8KTfwU";
$db_name = "jisangs";
$db_conn = new mysqli($db_host, $db_user, $db_passwd, $db_name);
if ($db_conn->connect_error) {
send_error_code("Connection failed: ".$db_conn->connect_error);
exit;
}
?>
+8
View File
@@ -0,0 +1,8 @@
<?php
$db_host = "localhost";
$db_user = "jisangs";
$db_passwd = "Fr12nds95";
$db_name = "jisangs";
?>
@@ -0,0 +1,38 @@
<?php
header('Content-Type: application/json');
include "send_error_code.php";
include "connect_db.php";
$return_array = array();
$query = "SELECT * FROM afterschool_activated_stage";
$result = mysqli_query($db_conn, $query);
$return_array = array();
if ( $result ) {
// echo "조회된 행의 수 : ".mysqli_num_rows($result)."<br />";
if($result) {
$rows = array();
while($row = mysqli_fetch_assoc($result)) {
// $row_array['Language'] = $row['Language'];
$row_array['StageName'] = $row['StageName'];
$row_array['Activated'] = $row['Activated'];
array_push($return_array, $row_array);
}
}
} else {
send_error_code("Error : ".mysqli_error($db_conn));
}
echo json_encode($return_array, JSON_UNESCAPED_UNICODE);
// 결과 해제
mysqli_free_result($result);
$db_conn->close();
?>
+42
View File
@@ -0,0 +1,42 @@
<?php
header('Content-Type: application/json');
include "./../send_error_code.php";
$user_id = $_POST["UserID"];
$app_name = $_POST["AppName"];
include "./../connect_db.php";
// my ranking
$query = "
SELECT DATE(DateTime) AS Date, MAX(Score) AS HighScore, AppName AS AppName
FROM moty_record D
WHERE UserID = ?
GROUP BY DATE(DateTime)
ORDER BY DateTime ASC
LIMIT 7;
";
$stmt = $db_conn->prepare($query);
$stmt->bind_param('s', $user_id);
$stmt->execute();
$stmt->bind_result($date, $score, $app_name);
$bestRecordArray = array();
while($stmt->fetch()) {
$best_record['Date'] = $date;
$best_record['HighScore'] = $score;
$best_record['AppName'] = $app_name;
array_push($bestRecordArray, $best_record);
array_push($return_array, $best_record);
}
$return_array['history'] = $bestRecordArray;
echo json_encode($return_array, JSON_UNESCAPED_UNICODE);
$db_conn->close();
?>
@@ -0,0 +1,32 @@
<?php
header('Content-Type: application/json');
include "send_error_code.php";
$user_id = $_POST["UserID"];
$language = $_POST["language"];
$stageName = $_POST["stageName"];
$record = $_POST["Record"];
$stage_name = $language."_".$stageName;
// $user_id = $_GET["UserID"];
// $language = $_GET["language"];
// $stageName = $_GET["stageName"];
// $best_record = $_GET["BestRecord"];
// $typing_stage = $language."_".$stageName;
// echo $user_id."\n";
// echo $typingStage."\n";
include "connect_db.php";
$query = "
INSERT INTO afterschool_record (UserID, Record, RecordDateTime, StageName)
VALUES (?, ?, NOW(), ?);
";
$stmt = $db_conn->prepare($query);
$stmt->bind_param('ids', $user_id, $record, $stage_name);
$stmt->execute();
$db_conn->close();
?>
+118
View File
@@ -0,0 +1,118 @@
<?php
header('Content-Type: application/json');
include "send_error_code.php";
$user_id = $_POST["UserID"];
$language = $_POST["language"];
$stageNameDetail = $_POST["stageName"];
$stageName = $language."_".$stageNameDetail;
include "connect_db.php";
// my ranking
$query = "
SELECT DATE(RecordDateTime) AS Date, MAX(Record) AS BestRecord, StageName AS StageName
FROM afterschool_record D
WHERE UserID = ?
GROUP BY DATE(RecordDateTime)
ORDER BY RecordDateTime DESC;
";
$stmt = $db_conn->prepare($query);
$stmt->bind_param('s', $user_id);
$stmt->execute();
$stmt->bind_result($date, $record, $stage_name);
$bestRecordArray = array();
while($stmt->fetch()) {
$best_record['Date'] = $date;
$best_record['BestRecord'] = $record;
$best_record['StageName'] = $stage_name;
array_push($bestRecordArray, $best_record);
array_push($return_array, $best_record);
}
$return_array['myRanking'] = $bestRecordArray;
// ranking hour
$query = "
SELECT D.userID As UserID, U.Name AS Name, MAX(D.record) AS BestRecord
FROM afterschool_record D, afterschool_user U
WHERE D.userID = U.userID AND DATE(D.RecordDateTime) = DATE(NOW()) AND HOUR(D.RecordDateTime) = HOUR(NOW()) AND StageName = ?
GROUP BY D.userID
ORDER BY max(D.Record) DESC;
";
$stmt = $db_conn->prepare($query);
$stmt->bind_param('s', $stageName);
$stmt->execute();
$stmt->bind_result($userID, $name, $record);
$bestRecordArray = array();
while($stmt->fetch()) {
$best_record['UserID'] = $userID;
$best_record['Name'] = $name;
$best_record['BestRecord'] = $record;
array_push($bestRecordArray, $best_record);
// array_push($return_array, $best_record);
}
$return_array['rankingHour'] = $bestRecordArray;
// ranking day
$query = "
SELECT D.userID As UserID, U.Name AS Name, MAX(D.record) AS BestRecord
FROM afterschool_record D, afterschool_user U
WHERE D.userID = U.userID AND DATE(D.RecordDateTime) = DATE(NOW()) AND StageName = ?
GROUP BY D.userID
ORDER BY max(D.Record) DESC;
";
$stmt = $db_conn->prepare($query);
$stmt->bind_param('s', $stageName);
$stmt->execute();
$stmt->bind_result($userID, $name, $record);
$bestRecordArray = array();
while($stmt->fetch()) {
$best_record['UserID'] = $userID;
$best_record['Name'] = $name;
$best_record['BestRecord'] = $record;
array_push($bestRecordArray, $best_record);
// array_push($return_array, $best_record);
}
$return_array['rankingDay'] = $bestRecordArray;
// ranking month
$query = "
SELECT D.userID As UserID, U.Name AS Name, MAX(D.record) AS BestRecord
FROM afterschool_record D, afterschool_user U
WHERE D.userID = U.userID AND MONTH(D.RecordDateTime) = MONTH(NOW()) AND StageName = ?
GROUP BY D.userID
ORDER BY max(D.Record) DESC;
";
$stmt = $db_conn->prepare($query);
$stmt->bind_param('s', $stageName);
$stmt->execute();
$stmt->bind_result($userID, $name, $record);
$bestRecordArray = array();
while($stmt->fetch()) {
$best_record['UserID'] = $userID;
$best_record['Name'] = $name;
$best_record['BestRecord'] = $record;
array_push($bestRecordArray, $best_record);
// array_push($return_array, $best_record);
}
$return_array['rankingMonth'] = $bestRecordArray;
echo json_encode($return_array, JSON_UNESCAPED_UNICODE);
$db_conn->close();
?>
@@ -1,25 +1,27 @@
<?php
header('Content-Type: application/json');
include "send_error_code.php";
include "./../send_error_code.php";
$name = $_POST["name"];
$birthday = $_POST["birthday"];
if(!is_numeric($birthday)) {
send_error_code('생년월일이 숫자가 아닙니다. : '.$birthday);
$enterCode = $_POST["enter_code"];
/*
if(!is_numeric($enterCode)) {
send_error_code('생년월일이 숫자가 아닙니다. : '.$enterCode);
exit;
} else if(strlen($birthday) != 6) {
send_error_code('6자리 숫자값을 정확히 입력하세요 : YYMMDD (예 : 120131) : '.$birthday);
} else if(strlen($enterCode) != 6) {
send_error_code('6자리 숫자값을 정확히 입력하세요 : YYMMDD (예 : 120131) : '.$enterCode);
exit;
}
*/
include "connect_db.php";
include "./../connect_db.php";
$return_array = array();
$query = "SELECT UserID FROM afterschool_user WHERE Name=? AND Birthday=?";
$query = "SELECT UserID FROM moty_user WHERE Name=? AND enterCode=?";
$stmt = $db_conn->prepare($query);
$stmt->bind_param('ss', $name, $birthday);
$stmt->bind_param('ss', $name, $enterCode);
$stmt->execute();
$stmt->bind_result($user_id);
// while($stmt->fetch())