Add: additional DB tables
This commit is contained in:
@@ -21,4 +21,10 @@ if ($db_conn->connect_error) {
|
|||||||
$query = "USE jisangs";
|
$query = "USE jisangs";
|
||||||
$result = mysqli_query($db_conn, $query);
|
$result = mysqli_query($db_conn, $query);
|
||||||
|
|
||||||
|
|
||||||
|
function send_error_message($replyJSON, $error_message) {
|
||||||
|
$replyJSON["ERROR"] = $error_message;
|
||||||
|
echo json_encode($replyJSON, JSON_UNESCAPED_UNICODE);
|
||||||
|
}
|
||||||
|
|
||||||
?>
|
?>
|
||||||
@@ -18,32 +18,56 @@ if(!is_numeric($enterCode)) {
|
|||||||
|
|
||||||
include "./../setup/connect_db.php";
|
include "./../setup/connect_db.php";
|
||||||
|
|
||||||
$return_array = array();
|
$maestro_id = get_maestro_id($maestro_name);
|
||||||
|
if($maestro_id == null) {
|
||||||
|
send_error_message($replyJSON, "no maestro id");
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
$query = "SELECT MaestroID FROM moty_maestro WHERE Name=?";
|
$replyJSON = get_login_data($maestro_id, $name, $enterCode);
|
||||||
$stmt = $db_conn->prepare($query);
|
if($replyJSON["UserID"] == null) {
|
||||||
$stmt->bind_param('s', $maestro_name);
|
send_error_message($replyJSON, "invalid username and entercode");
|
||||||
$stmt->execute();
|
exit;
|
||||||
$stmt->bind_result($maestro_id);
|
}
|
||||||
// while($stmt->fetch()) {
|
|
||||||
// ;
|
|
||||||
// }
|
|
||||||
$stmt->fetch();
|
|
||||||
$stmt->close();
|
|
||||||
|
|
||||||
// $maestro_id = 1;
|
echo json_encode($replyJSON, JSON_UNESCAPED_UNICODE);
|
||||||
$query = "SELECT UserID FROM moty_user WHERE MaestroID=? AND Name=? AND enterCode=?";
|
|
||||||
$stmt = $db_conn->prepare($query);
|
|
||||||
$stmt->bind_param('iss', $maestro_id, $name, $enterCode);
|
|
||||||
$stmt->execute();
|
|
||||||
$stmt->bind_result($user_id);
|
|
||||||
// while($stmt->fetch())
|
|
||||||
$stmt->fetch();
|
|
||||||
$stmt->close();
|
|
||||||
$db_conn->close();
|
|
||||||
|
|
||||||
$jsonUserData["MaestroID"] = $maestro_id;
|
|
||||||
$jsonUserData["UserID"] = $user_id;
|
|
||||||
echo json_encode($jsonUserData, JSON_UNESCAPED_UNICODE);
|
function get_maestro_id($maestro_name) {
|
||||||
|
global $db_conn;
|
||||||
|
|
||||||
|
$query = "SELECT MaestroID FROM moty_maestro WHERE Name=?";
|
||||||
|
$stmt = $db_conn->prepare($query);
|
||||||
|
$stmt->bind_param('s', $maestro_name);
|
||||||
|
$stmt->execute();
|
||||||
|
$stmt->bind_result($maestro_id);
|
||||||
|
// while($stmt->fetch()) {
|
||||||
|
// ;
|
||||||
|
// }
|
||||||
|
$stmt->fetch();
|
||||||
|
$stmt->close();
|
||||||
|
|
||||||
|
return $maestro_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
function get_login_data($maestro_id, $name, $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', $maestro_id, $name, $enterCode);
|
||||||
|
$stmt->execute();
|
||||||
|
$stmt->bind_result($user_id);
|
||||||
|
// while($stmt->fetch())
|
||||||
|
$stmt->fetch();
|
||||||
|
$stmt->close();
|
||||||
|
$db_conn->close();
|
||||||
|
|
||||||
|
$replyJSON["MaestroID"] = $maestro_id;
|
||||||
|
$replyJSON["UserID"] = $user_id;
|
||||||
|
|
||||||
|
return $replyJSON;
|
||||||
|
}
|
||||||
|
|
||||||
?>
|
?>
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
USE jisangs;
|
||||||
|
|
||||||
|
INSERT INTO moty_app VALUES
|
||||||
|
(1, 'korean_basic', 1),
|
||||||
|
(2, 'korean_left_upper', 1),
|
||||||
|
(3, 'korean_second_finger', 1),
|
||||||
|
(4, 'korean_right_upper', 1),
|
||||||
|
(5, 'korean_left_lower', 1),
|
||||||
|
(6, 'korean_right_lower', 1),
|
||||||
|
(7, 'korean_left_upper_double', 1),
|
||||||
|
(8, 'korean_right_upper_double', 1),
|
||||||
|
(9, 'korean_word', 1),
|
||||||
|
(10, 'korean_sentence', 1),
|
||||||
|
|
||||||
|
(11, 'english_basic', 1),
|
||||||
|
(12, 'english_left_upper', 1),
|
||||||
|
(13, 'english_second_finger', 1),
|
||||||
|
(14, 'english_right_upper', 1),
|
||||||
|
(15, 'english_left_lower', 1),
|
||||||
|
(16, 'english_right_lower', 1),
|
||||||
|
(19, 'english_word', 1),
|
||||||
|
(20, 'english_sentence', 1);
|
||||||
|
|
||||||
|
INSERT INTO moty_app VALUES
|
||||||
|
(101, 'space_invaders', 101);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
INSERT INTO moty_activate_app VALUES
|
||||||
|
(1, 1, 1),
|
||||||
|
(2, 1, 9),
|
||||||
|
(3, 1, 10),
|
||||||
|
(4, 1, 19),
|
||||||
|
(5, 1, 20),
|
||||||
|
(6, 1, 101);
|
||||||
@@ -0,0 +1,65 @@
|
|||||||
|
CREATE TABLE moty_maestro (
|
||||||
|
MaestroID INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
|
||||||
|
Name CHAR(50) NOT NULL,
|
||||||
|
EnterCode CHAR(10) NOT NULL,
|
||||||
|
Email CHAR(50) NOT NULL,
|
||||||
|
AccountType INT UNSIGNED NOT NULL,
|
||||||
|
AccountStatus INT UNSIGNED NOT NULL,
|
||||||
|
UserCount INT UNSIGNED NOT NULL,
|
||||||
|
AcceptClausesDateTime DATETIME NOT NULL,
|
||||||
|
MaestroTestID INT UNSIGNED
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE moty_user (
|
||||||
|
UserID INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
|
||||||
|
MaestroID INT UNSIGNED NOT NULL,
|
||||||
|
Name CHAR(50) NOT NULL,
|
||||||
|
EnterCode CHAR(6) NOT NULL
|
||||||
|
|
||||||
|
FOREIGN KEY (MaestroID) REFERENCES moty_maestro(MaestroID)
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
CREATE TABLE moty_app (
|
||||||
|
AppID INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
|
||||||
|
AppName CHAR(40) NOT NULL,
|
||||||
|
AppType INT UNSIGNED NOT NULL
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE moty_activate_app (
|
||||||
|
ActivateAppID INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
|
||||||
|
MaestroID INT UNSIGNED NOT NULL,
|
||||||
|
AppID INT UNSIGNED NOT NULL,
|
||||||
|
|
||||||
|
FOREIGN KEY (MaestroID) REFERENCES moty_maestro(MaestroID),
|
||||||
|
FOREIGN KEY (AppID) REFERENCES moty_app(AppID)
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
CREATE TABLE moty_best_record (
|
||||||
|
BestRecordID INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
|
||||||
|
MaestroID INT UNSIGNED NOT NULL,
|
||||||
|
AppID INT UNSIGNED NOT NULL,
|
||||||
|
UserID INT UNSIGNED NOT NULL,
|
||||||
|
BestRecord FLOAT NOT NULL,
|
||||||
|
RecordDateTime DATETIME NOT NULL,
|
||||||
|
|
||||||
|
FOREIGN KEY (MaestroID) REFERENCES moty_maestro(MaestroID),
|
||||||
|
FOREIGN KEY (AppID) REFERENCES moty_app(AppID),
|
||||||
|
FOREIGN KEY (UserID) REFERENCES moty_user(UserID)
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE moty_ranking (
|
||||||
|
RankingID INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
|
||||||
|
MaestroID INT UNSIGNED NOT NULL,
|
||||||
|
AppID INT UNSIGNED NOT NULL,
|
||||||
|
RankingType INT UNSIGNED NOT NULL,
|
||||||
|
Rank INT UNSIGNED NOT NULL,
|
||||||
|
UserID INT UNSIGNED NOT NULL,
|
||||||
|
|
||||||
|
FOREIGN KEY (MaestroID) REFERENCES moty_maestro(MaestroID),
|
||||||
|
FOREIGN KEY (AppID) REFERENCES moty_app(AppID),
|
||||||
|
FOREIGN KEY (UserID) REFERENCES moty_user(UserID)
|
||||||
|
);
|
||||||
Reference in New Issue
Block a user