262 lines
6.3 KiB
PHP
262 lines
6.3 KiB
PHP
<?php
|
|
header("Content-Type: application/json");
|
|
|
|
error_reporting( E_ALL );
|
|
ini_set( "display_errors", 1 );
|
|
|
|
include "./../setup/connect_db.php";
|
|
include "./../lib/send_reply_json.php";
|
|
include "./../lib/db_maestro.php";
|
|
include "./../lib/maestro_log.php";
|
|
|
|
include './../mail/mail_setting.php';
|
|
include './../mail/mail_contents.php';
|
|
include './../lib/maestro_account_info.php';
|
|
include "./../mail/send_naver_mail.php";
|
|
|
|
|
|
$maestro_name = $_POST["maestro_name"];
|
|
$password = $_POST["password"];
|
|
$email = $_POST["email"];
|
|
$account_type = $_POST["account_type"];
|
|
|
|
|
|
$maestroID = has_maestro_name($maestro_name);
|
|
if($maestroID !== null) {
|
|
set_error_message($maestro_name." : 이미 등록된 마에스트로 계정입니다.");
|
|
send_result_fail();
|
|
exit;
|
|
}
|
|
|
|
add_maestro($maestro_name, $password, $email, $account_type);
|
|
|
|
$maestroID = has_maestro_name($maestro_name);
|
|
if($maestroID === null) {
|
|
set_error_message($maestro_name." : 알 수 없는 이유로 마에스트로 계정 등록이 취소되었습니다.");
|
|
send_result_fail();
|
|
exit;
|
|
}
|
|
|
|
add_maestro_test_player($maestroID);
|
|
|
|
$playerID = get_maestro_test_player($maestroID);
|
|
if($playerID === null) {
|
|
set_error_message("마에스트로 테스트 플레이어 생성 실패");
|
|
send_result_fail();
|
|
exit;
|
|
}
|
|
|
|
$result = set_maestro_test_player($maestroID, $playerID);
|
|
if($result === null || $result === 0) {
|
|
set_error_message("마에스트로 테스트 플레이어 등록 실패");
|
|
send_result_fail();
|
|
exit;
|
|
}
|
|
|
|
add_default_activated_apps($maestroID);
|
|
|
|
add_maestro_sample_player_data($maestroID);
|
|
$count = count_registered_player($maestroID);
|
|
update_count_registered_player($maestroID, $count);
|
|
|
|
sendMailTrialRegisterDone($maestro_name, $email, $account_type);
|
|
insertMaestroLog("add_maestro", $maestroID, $maestro_name." / ".$email." / ".$account_type);
|
|
|
|
send_result_success();
|
|
exit;
|
|
|
|
|
|
|
|
function has_maestro_name($maestroName) {
|
|
global $db_conn;
|
|
|
|
$query = "
|
|
SELECT MaestroID
|
|
FROM 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 add_maestro($maestro_name, $password, $email, $account_type) {
|
|
global $db_conn;
|
|
|
|
$query = "
|
|
INSERT INTO maestro (Name, Password, Email, AccountType, ActivateStatus, AvailableActivateDateTime, PlayerCount, AcceptClausesDateTime, AllowEditEnterCode, MaestroTestID)
|
|
VALUES (?, PASSWORD(?), ?, ?, 1, DATE_ADD(NOW(), INTERVAL 2 WEEK), 0, NOW(), 0, 0)";
|
|
$stmt = $db_conn->prepare($query);
|
|
$stmt->bind_param("sssi", $maestro_name, $password, $email, $account_type);
|
|
$stmt->execute();
|
|
}
|
|
|
|
function add_maestro_test_player($maestroID) {
|
|
global $db_conn;
|
|
|
|
$query = "
|
|
INSERT INTO player (MaestroID, Name, EnterCode, AccountType)
|
|
VALUES (?, '마에스트로', '', 1)
|
|
";
|
|
$stmt = $db_conn->prepare($query);
|
|
$stmt->bind_param("i", $maestroID);
|
|
$stmt->execute();
|
|
}
|
|
|
|
function get_maestro_test_player($maestroID) {
|
|
global $db_conn;
|
|
|
|
$query = "
|
|
SELECT PlayerID
|
|
FROM player
|
|
WHERE MaestroID = ? AND AccountType = 1
|
|
";
|
|
$stmt = $db_conn->prepare($query);
|
|
$stmt->bind_param("i", $maestroID);
|
|
$stmt->execute();
|
|
$stmt->bind_result($playerID);
|
|
$stmt->fetch();
|
|
$stmt->close();
|
|
|
|
return $playerID;
|
|
}
|
|
|
|
function set_maestro_test_player($maestroID, $playerID) {
|
|
global $db_conn;
|
|
|
|
$query = "
|
|
UPDATE maestro
|
|
SET MaestroTestID = ?
|
|
WHERE MaestroID = ?
|
|
";
|
|
$stmt = $db_conn->prepare($query);
|
|
$stmt->bind_param("ii", $playerID, $maestroID);
|
|
$stmt->execute();
|
|
|
|
return $stmt->affected_rows;
|
|
}
|
|
|
|
function add_default_activated_apps($maestroID) {
|
|
global $db_conn;
|
|
|
|
$query = "
|
|
SELECT AppID
|
|
FROM app
|
|
WHERE Status = 1;
|
|
";
|
|
$stmt = $db_conn->prepare($query);
|
|
$stmt->execute();
|
|
$stmt->bind_result($appID);
|
|
|
|
$activeAppList = array();
|
|
while($stmt->fetch()) {
|
|
array_push($activeAppList, $appID);
|
|
}
|
|
$stmt->close();
|
|
|
|
$count = count($activeAppList);
|
|
for($i = 0; $i < $count; $i++) {
|
|
$activeAppID = $activeAppList[$i];
|
|
|
|
$query = "
|
|
INSERT INTO active_app (MaestroID, AppID)
|
|
VALUES (?, ?);
|
|
";
|
|
$stmt = $db_conn->prepare($query);
|
|
$stmt->bind_param("ii", $maestroID, $activeAppID);
|
|
$stmt->execute();
|
|
$stmt->close();
|
|
}
|
|
}
|
|
|
|
function add_maestro_sample_player_data($maestro_id) {
|
|
$samplePlayerList = make_sample_player_list($maestro_id);
|
|
for($i = 0; $i < count($samplePlayerList); $i++) {
|
|
insert_maestro_sample_player_data($maestro_id, $samplePlayerList[$i]);
|
|
}
|
|
}
|
|
|
|
|
|
function insert_maestro_sample_player_data($maestro_id, $player) {
|
|
global $db_conn;
|
|
|
|
$query = "
|
|
INSERT INTO player (MaestroID, Name, EnterCode, AccountType)
|
|
VALUES (?, ?, ?, ?)
|
|
";
|
|
$stmt = $db_conn->prepare($query);
|
|
$stmt->bind_param("issi",
|
|
$maestro_id,
|
|
$player["Name"],
|
|
$player["EnterCode"],
|
|
$player["AccountType"]
|
|
);
|
|
$stmt->execute();
|
|
$stmt->close();
|
|
}
|
|
|
|
function make_sample_player_list() {
|
|
$samplePlayerList = array();
|
|
|
|
$player["Name"] = "050215";
|
|
$player["EnterCode"] = "050215";
|
|
$player["AccountType"] = 0;
|
|
array_push($samplePlayerList, $player);
|
|
|
|
$player["Name"] = "6-3_이철수";
|
|
$player["EnterCode"] = "1111";
|
|
$player["AccountType"] = 0;
|
|
array_push($samplePlayerList, $player);
|
|
|
|
$player["Name"] = "3-1김영희";
|
|
$player["EnterCode"] = "0301";
|
|
$player["AccountType"] = 0;
|
|
array_push($samplePlayerList, $player);
|
|
|
|
$player["Name"] = "홍길동";
|
|
$player["EnterCode"] = "181231";
|
|
$player["AccountType"] = 0;
|
|
array_push($samplePlayerList, $player);
|
|
|
|
return $samplePlayerList;
|
|
}
|
|
|
|
function count_registered_player($maestroID) {
|
|
global $db_conn;
|
|
|
|
$query = "
|
|
SELECT COUNT(PlayerID)
|
|
FROM player
|
|
WHERE MaestroID = ? AND AccountType = 0
|
|
";
|
|
$stmt = $db_conn->prepare($query);
|
|
$stmt->bind_param("i", $maestroID);
|
|
$stmt->execute();
|
|
$stmt->bind_result($countPlayer);
|
|
// while($stmt->fetch())
|
|
$stmt->fetch();
|
|
$stmt->close();
|
|
|
|
return $countPlayer;
|
|
}
|
|
|
|
function update_count_registered_player($maestroID, $countPlayer) {
|
|
global $db_conn;
|
|
|
|
$query = "
|
|
UPDATE maestro
|
|
SET PlayerCount = ?
|
|
WHERE MaestroID = ?
|
|
";
|
|
$stmt = $db_conn->prepare($query);
|
|
$stmt->bind_param("ii", $countPlayer, $maestroID);
|
|
$stmt->execute();
|
|
}
|
|
|
|
?>
|