From 070b87004426e1f89360c4d1c091943252c5b80c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=8B=E1=85=A2=E1=84=91=E1=85=B3=E1=86=AF=20=E1=84=82?= =?UTF-8?q?=E1=85=A9=E1=84=90=E1=85=B3=E1=84=87=E1=85=AE=E1=86=A8?= Date: Thu, 12 Jul 2018 07:20:44 +0900 Subject: [PATCH] Fix: revised php code to admin --- src/web/admin/admin_register_list.html | 126 ++---- src/web/admin/login.html | 4 +- src/web/js/maestro_list.js | 86 ---- src/web/js/maestro_list_manager.js | 411 ------------------ src/web/js/maestro_list_navigator.js | 54 --- src/web/server/admin/register_maestro.php | 17 +- .../server/admin/registered_maestro_list.php | 54 ++- src/web/server/maestro/login.php | 12 +- 8 files changed, 77 insertions(+), 687 deletions(-) delete mode 100644 src/web/js/maestro_list.js delete mode 100644 src/web/js/maestro_list_manager.js delete mode 100644 src/web/js/maestro_list_navigator.js diff --git a/src/web/admin/admin_register_list.html b/src/web/admin/admin_register_list.html index 08aa4c6..326eeb2 100644 --- a/src/web/admin/admin_register_list.html +++ b/src/web/admin/admin_register_list.html @@ -11,9 +11,7 @@ - - - + diff --git a/src/web/admin/login.html b/src/web/admin/login.html index 5562e99..1a006d7 100644 --- a/src/web/admin/login.html +++ b/src/web/admin/login.html @@ -22,14 +22,14 @@ let name = $("#maestro_name").val(); let password = $("#password").val(); - sendRequestServer( //url, sendParams, onSuccess, onFail, isDebugMode); "./../server/maestro/login.php", "maestro_name=" + name + "&password=" + password, (jsonData) => { - maestroID = jsonData["MaestroID"]; + maestroID = jsonData["maestroID"]; sessionStorage.setItem("maestroID", maestroID); + location.href = 'admin_register_list.html'; }, diff --git a/src/web/js/maestro_list.js b/src/web/js/maestro_list.js deleted file mode 100644 index 24c600e..0000000 --- a/src/web/js/maestro_list.js +++ /dev/null @@ -1,86 +0,0 @@ -class MaestroListRow { - - constructor(maestroID, maestroName, password, editButton, deleteButton) { - this.maestroID = maestroID; - this.maestroName = maestroName; - this.password = password; - this.editButton = editButton; - this.deleteButton = deleteButton; - } - -} - -class MaestroList { - - constructor(tagDiv, parent) { - let self = this; - this.parent = parent; - // console.log(tagDiv); - - this.maestroCount = 0; - this.activePageNo = 1; - - let id_list = tagDiv.find(".maestro_id"); - // console.log(id_list); - - this.listRows = new Array(); - for(let i = 0; i < id_list.length; i++) { - this.listRows[i] = new PaestroListRow( - id_list[i], // span - $(id_list[i]).siblings(".maestro_name"), - $(id_list[i]).siblings(".maestro_password"), - $(id_list[i]).siblings(".maestro_edit"), - $(id_list[i]).siblings(".maestro_delete") - ); - - this.disableItem(this.listRows[i]); - - $(id_list[i]).siblings(".maestro_edit").click(function() { - parent.editMaestro(this); - }) - - $(id_list[i]).siblings(".maestro_delete").click(function() { - parent.deleteMaestro(this); - }) - // console.log(this.listRows[i].maestroName.val()); - // console.log(this.listRows[i]); - } - } - - disableItem(item) { - $(item.maestroID).empty(); - $(item.maestroName).prop("disabled", true); - $(item.password).prop("disabled", true); - $(item.editButton).prop("disabled", true); - $(item.deleteButton).prop("disabled", true); - } - - enableItem(item) { - $(item.maestroName).prop("disabled", false); - $(item.password).prop("disabled", false); - $(item.editButton).prop("disabled", false); - $(item.deleteButton).prop("disabled", false); - } - - updatemaestroList(jsonData) { - // console.log(jsonData); - - for(let i = 0; i < 10; i++) { - $(this.listRows[i].maestroID).empty(); - - if(i < jsonData.length) { - $(this.listRows[i].maestroID).append(jsonData[i]["maestroID"]); - $(this.listRows[i].maestroName).val(jsonData[i]["Name"]); - $(this.listRows[i].password).val(jsonData[i]["Password"]); - - this.enableItem(this.listRows[i]); - } else { - $(this.listRows[i].maestroName).val(""); - $(this.listRows[i].password).val(""); - - this.disableItem(this.listRows[i]); - } - } - } - -} \ No newline at end of file diff --git a/src/web/js/maestro_list_manager.js b/src/web/js/maestro_list_manager.js deleted file mode 100644 index 9f6f933..0000000 --- a/src/web/js/maestro_list_manager.js +++ /dev/null @@ -1,411 +0,0 @@ -class MaestroListManager { - - constructor(docList, docNav) { - let self = this; - this.docList = docList; - this.docNav = docNav; - - this.list = new MaestroList(this.docList, this); - this.listNavigator = new MaestroListNavigator(this.docNav); - - this.maestroCount = 0; - this.activePageNo = 1; - this.lastPageNo = 0; - - } - - - setupRegisteredMaestroList() { - let self = this; - - let xhr = new XMLHttpRequest(); //new로 생성. - xhr.open('POST', './../server/maestro/registered_maestro_count.php', true); - xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); - xhr.send("maestro_id=" + maestroID); - xhr.onload = function() { - if(xhr.readyState === 4 && xhr.status === 200) { - // console.log(xhr.responseText); - // console.log(xhr.responseText.length); - if(xhr.responseText.length === 0 || xhr.responseText === null) { - console.log("no data from server"); - return; - } - - let replyJSON = JSON.parse(xhr.responseText); - // console.log(replyJSON); - - if(replyJSON === null) { - console.log("no data from server"); - return; - } - - if(replyJSON["ERROR"] !== undefined || replyJSON["RESULT"] === undefined) { - console.log(replyJSON["ERROR"]); - return; - } - - if(replyJSON["RESULT"] === "fail") { - console.log(replyJSON["RESULT"]); - return; - } - - self.maestroCount = replyJSON["Count"]; - self.lastPageNo = Math.ceil( (self.maestroCount + 1) / 10 ); - self.activePageNo = 1; - - self.loadRegisteredMaestroListPage(self.activePageNo); - self.listNavigator.updateNavigator(self.activePageNo, self.lastPageNo); - } - } - } - - loadRegisteredMaestroListPage(pageNo) { - self = this; - this.activePageNo = pageNo; - - let pageIndex = pageNo - 1; - let startNo = pageIndex * 10; - let endNo = pageIndex * 10 + 9; - - let xhr = new XMLHttpRequest(); //new로 생성. - xhr.open('POST', './../server/maestro/registered_maestro_list.php', true); - xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); - xhr.send("maestro_id=" + maestroID + "&start_no=" + startNo + "&end_no=" + endNo); - xhr.onload = function() { - if(xhr.readyState === 4 && xhr.status === 200) { - // console.log(xhr.responseText); - // console.log(xhr.responseText.length); - if(xhr.responseText.length === 0 || xhr.responseText === null) { - console.log("no data from server"); - return; - } - - let replyJSON = JSON.parse(xhr.responseText); - // console.log(replyJSON); - - if(replyJSON === null) { - console.log("no data from server"); - return; - } - - if(replyJSON["ERROR"] !== undefined || replyJSON["RESULT"] === undefined) { - console.log(replyJSON["ERROR"]); - return; - } - - if(replyJSON["RESULT"] === "fail") { - console.log(replyJSON["RESULT"]); - return; - } - - // console.log(replyJSON["MaestroList"]); - // updateMaestroListPage(replyJSON["MaestroList"]); - self.list.updateMaestroList(replyJSON["MaestroList"]); - - self.maestroCount = replyJSON["MaestroList"].length; - } - } - } - - - updateRegisteredMaestroListPage(pageNo) { - self = this; - this.maestroListPage = pageNo; - - let pageIndex = pageNo - 1; - let startNo = pageIndex * 10; - let endNo = pageIndex * 10 + 9; - - let xhr = new XMLHttpRequest(); //new로 생성. - xhr.open('POST', './../server/maestro/registered_maestro_list.php', true); - xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); - xhr.send("maestro_id=" + maestroID + "&start_no=" + startNo + "&end_no=" + endNo); - xhr.onload = function() { - if(xhr.readyState === 4 && xhr.status === 200) { - // console.log(xhr.responseText); - // console.log(xhr.responseText.length); - if(xhr.responseText.length === 0 || xhr.responseText === null) { - console.log("no data from server"); - return; - } - - let replyJSON = JSON.parse(xhr.responseText); - // console.log(replyJSON); - - if(replyJSON === null) { - console.log("no data from server"); - return; - } - - if(replyJSON["ERROR"] !== undefined || replyJSON["RESULT"] === undefined) { - console.log(replyJSON["ERROR"]); - return; - } - - if(replyJSON["RESULT"] === "fail") { - console.log(replyJSON["RESULT"]); - return; - } - - // console.log(replyJSON["MaestroList"]); - self.list.updateMaestroList(replyJSON["MaestroList"]); - - self.maestroCount = replyJSON["MaestroList"].length; - // console.log(self.maestroCount); - // self.lastPageNo = Math.ceil( (self.maestroCount + 1) / 10 ); - // self.activePageNo = 1; - - self.listNavigator.updateNavigator(self.activePageNo, self.lastPageNo); - } - } - } - - - - setupUpgradeMaestroList(maestroName) { - let self = this; - - let xhr = new XMLHttpRequest(); //new로 생성. - xhr.open('POST', './../server/maestro/search_maestro_count.php', true); - xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); - xhr.send("maestro_id=" + maestroID + "&maestro_name=" + maestroName); - xhr.onload = function() { - if(xhr.readyState === 4 && xhr.status === 200) { - // console.log(xhr.responseText); - // console.log(xhr.responseText.length); - if(xhr.responseText.length === 0 || xhr.responseText === null) { - console.log("no data from server"); - return; - } - - let replyJSON = JSON.parse(xhr.responseText); - // console.log(replyJSON); - - if(replyJSON === null) { - console.log("no data from server"); - return; - } - - if(replyJSON["ERROR"] !== undefined || replyJSON["RESULT"] === undefined) { - console.log(replyJSON["ERROR"]); - return; - } - - if(replyJSON["RESULT"] === "fail") { - console.log(replyJSON["RESULT"]); - return; - } - - self.maestroCount = replyJSON["Count"]; - self.lastPageNo = Math.ceil( (self.maestroCount + 1) / 10 ); - self.activePageNo = 1; - - self.updateSearchMaestroListPage(maestroName, 1); - } - } - } - - updateUpgradeMaestroListPage(maestroName, pageNo) { - let self = this; - this.maestroListPage = pageNo; - - let pageIndex = pageNo - 1; - let startNo = pageIndex * 10; - let endNo = pageIndex * 10 + 9; - - let xhr = new XMLHttpRequest(); //new로 생성. - xhr.open('POST', './../server/maestro/search_maestro_list.php', true); - xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); - xhr.send("maestro_id=" + maestroID + "&maestro_name=" + maestroName + "&start_no=" + startNo + "&end_no=" + endNo); - xhr.onload = function() { - if(xhr.readyState === 4 && xhr.status === 200) { - // console.log(xhr.responseText); - // console.log(xhr.responseText.length); - if(xhr.responseText.length === 0 || xhr.responseText === null) { - console.log("no data from server"); - return; - } - - let replyJSON = JSON.parse(xhr.responseText); - // console.log(replyJSON); - - if(replyJSON === null) { - console.log("no data from server"); - return; - } - - if(replyJSON["ERROR"] !== undefined || replyJSON["RESULT"] === undefined) { - console.log(replyJSON["ERROR"]); - return; - } - - if(replyJSON["RESULT"] === "fail") { - console.log(replyJSON["RESULT"]); - return; - } - - // console.log(replyJSON["MaestroList"]); - self.list.updateMaestroList(replyJSON["MaestroList"]); - - self.maestroCount = replyJSON["MaestroList"].length; - // self.lastPageNo = Math.ceil( (self.maestroCount + 1) / 10 ); - // self.activePageNo = 1; - - self.listNavigator.updateNavigator(self.activePageNo, self.lastPageNo); - } - } - } - - - onClickMaestroListPage(pageNo) { - switch(pageNo) { - case "first": - this.activePageNo = 1; - self.loadAddMaestroListPage(self.activePageNo); - return; - - case "prev": - if(this.activePageNo > 1) - this.activePageNo -= 1; - self.loadAddMaestroListPage(self.activePageNo); - return; - - case "next": - if(this.activePageNo < this.lastPageNo) - this.activePageNo += 1; - self.loadAddMaestroListPage(self.activePageNo); - return; - - case "last": - this.loadAddMaestroListPage(this.lastPageNo); - return; - } - - this.activePageNo = pageNo; - self.loadAddMaestroListPage(self.activePageNo); - } - - - registMaestro(inputButton) { - // console.log(inputButton); - let clickedObjectID = this.getClickedObjectID(inputButton); - - - let id = $(inputButton).siblings(".maestro_id"); - let maestroID = id.text(); - // console.log(maestroID); - - let name = $(inputButton).siblings(".maestro_name"); - let maestroName = name.val(); - // console.log(maestroName); - - let enterCode = $(inputButton).siblings(".maestro_entercode"); - let maestroEnterCode = enterCode.val(); - // console.log(maestroEnterCode); - - let xhr = new XMLHttpRequest(); //new로 생성. - xhr.open('POST', './../server/maestro/edit_maestro.php', true); - xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); - xhr.send("maestro_id=" + maestroID + "&maestro_id=" + maestroID + "&maestro_name=" + maestroName + "&enter_code=" + maestroEnterCode); - xhr.onload = function() { - if(xhr.readyState === 4 && xhr.status === 200) { - // console.log(xhr.responseText); - // console.log(xhr.responseText.length); - if(xhr.responseText.length === 0 || xhr.responseText === null) { - console.log("no data from server"); - return; - } - - let replyJSON = JSON.parse(xhr.responseText); - // console.log(replyJSON); - - if(replyJSON === null) { - console.log("no data from server"); - return; - } - - if(replyJSON["ERROR"] !== undefined || replyJSON["RESULT"] === undefined) { - console.log(replyJSON["ERROR"]); - return; - } - - if(replyJSON["RESULT"] === "fail") { - console.log(replyJSON["RESULT"]); - return; - } - - console.log(clickedObjectID); - if(clickedObjectID === "registered_maestro_list") { - self.setupRegisteredMaestroList(); - } else if(clickedObjectID === "search_maestro_list") { - let maestroName = $("#search_name").val(); - self.setupUpdateMaestroList(maestroName); - } - } - } - } - - deleteMaestro(inputButton) { - let self = this; - - let id = $(inputButton).siblings(".maestro_id"); - let maestroID = id.text(); - - let clickedObjectID = this.getClickedObjectID(inputButton); - - if(maestroID === null || maestroID === "") - return; - - let xhr = new XMLHttpRequest(); //new로 생성. - xhr.open('POST', './../server/maestro/delete_maestro.php', true); - xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); - xhr.send("maestro_id=" + maestroID + "&maestro_id=" + maestroID); - xhr.onload = function() { - if(xhr.readyState === 4 && xhr.status === 200) { - // console.log(xhr.responseText); - // console.log(xhr.responseText.length); - if(xhr.responseText.length === 0 || xhr.responseText === null) { - console.log("no data from server"); - return; - } - - let replyJSON = JSON.parse(xhr.responseText); - // console.log(replyJSON); - - if(replyJSON === null) { - console.log("no data from server"); - return; - } - - if(replyJSON["ERROR"] !== undefined || replyJSON["RESULT"] === undefined) { - console.log(replyJSON["ERROR"]); - return; - } - - if(replyJSON["RESULT"] === "fail") { - console.log(replyJSON["RESULT"]); - return; - } - - console.log(clickedObjectID); - if(clickedObjectID === "registered_maestro_list") { - self.setupRegisteredMaestroList(); - } else if(clickedObjectID === "upgrade_maestro_list") { - let maestroName = $("#search_name").val(); - self.setupUpgradeMaestroList(maestroName); - } - } - } - } - - getClickedObjectID(clickedObject) { - let tagDiv = $(clickedObject).closest(".maestro_list"); - let tagDivID = tagDiv.prop("id"); - // console.log(tagDivIDName); - - return tagDivID; - } - - - -} \ No newline at end of file diff --git a/src/web/js/maestro_list_navigator.js b/src/web/js/maestro_list_navigator.js deleted file mode 100644 index 1255f79..0000000 --- a/src/web/js/maestro_list_navigator.js +++ /dev/null @@ -1,54 +0,0 @@ -class MaestroListNavigator { - - constructor(pageNoArea) { - let self = this; - this.pageNoArea = pageNoArea; - // console.log(parent); - - this.activePageNo = 1; - this.lastPageNo = 1; - } - - updateNavigator(activePageNo, lastPageNo) { - this.activePageNo = activePageNo; - this.lastPageNo = lastPageNo; - // this.lastPageNo = Math.ceil( (maestroCount + 1) / 10 ); - - $(this.pageNoArea).empty(); - - for(let pageNo = 1; pageNo < this.lastPageNo + 1; pageNo++) { - $(this.pageNoArea).append( - " " + pageNo + " " - ); - } - } - - onClickMaestroListPage(pageNo) { - switch(pageNo) { - case "first": - this.activePageNo = 1; - this.maestroList.loadMaestroListPage(this.activePageNo); - return; - - case "prev": - if(this.activePageNo > 1) - this.activePageNo -= 1; - this.maestroList.loadMaestroListPage(this.activePageNo); - return; - - case "next": - if(this.activePageNo < this.lastPageNo) - this.activePageNo += 1; - this.maestroList.loadMaestroListPage(this.activePageNo); - return; - - case "last": - this.maestroList.loadMaestroListPage(this.lastPageNo); - return; - } - - this.activePageNo = pageNo; - this.maestroList.loadMaestroListPage(this.activePageNo); - } - -} \ No newline at end of file diff --git a/src/web/server/admin/register_maestro.php b/src/web/server/admin/register_maestro.php index 64525ea..0965053 100644 --- a/src/web/server/admin/register_maestro.php +++ b/src/web/server/admin/register_maestro.php @@ -1,23 +1,24 @@ prepare($query); -$stmt->bind_param('i', $maestro_id); +$stmt->bind_param("i", $maestro_id); $stmt->execute(); if($stmt->affected_rows <= 0) { - send_error_message($replyJSON, "마에스트로 계정 활성화 실패"); - $db_conn->close(); + set_error_message("마에스트로 계정 활성화 실패"); + send_result_fail(); exit; } -$replyJSON["RESULT"] = "ok"; -echo json_encode($replyJSON, JSON_UNESCAPED_UNICODE); -$db_conn->close(); +send_result_success(); +exit; ?> \ No newline at end of file diff --git a/src/web/server/admin/registered_maestro_list.php b/src/web/server/admin/registered_maestro_list.php index e24e929..832282c 100644 --- a/src/web/server/admin/registered_maestro_list.php +++ b/src/web/server/admin/registered_maestro_list.php @@ -1,28 +1,28 @@ close(); +if(strlen($maestroList) === 0) { + set_error_message("오늘의 랭킹 기록 없음"); + send_result_fail(); exit; } -$replyJSON["RESULT"] = "ok"; -echo json_encode($replyJSON, JSON_UNESCAPED_UNICODE); -$db_conn->close(); +set_data("maestroList", $maestroList); +send_result_success(); +exit; + function get_maestro_list() { @@ -34,21 +34,20 @@ function get_maestro_list() { ORDER BY MaestroID DESC "; $stmt = $db_conn->prepare($query); - // $stmt->bind_param('iii', $maestroID, $startNo, $endNo); - // $stmt->bind_param('ii', $maestroName, $startNo); + // $stmt->bind_param("iii", $maestroID, $startNo, $endNo); + // $stmt->bind_param("ii", $maestroName, $startNo); $stmt->execute(); $stmt->bind_result($maestroID, $name, $accountType); $maestroList = array(); while($stmt->fetch()) { - $maestro['MaestroID'] = $maestroID; - $maestro['Name'] = $name; - $maestro['AccountType'] = $accountType; + $maestro["maestroID"] = $maestroID; + $maestro["maestroName"] = $name; + $maestro["accountType"] = $accountType; array_push($maestroList, $maestro); } - $return_array['MaestroList'] = $maestroList; - return $return_array; + return $maestroList; } function get_maestro_list_by_name($maestroName) { @@ -60,21 +59,20 @@ function get_maestro_list_by_name($maestroName) { ORDER BY MaestroID DESC "; $stmt = $db_conn->prepare($query); - // $stmt->bind_param('iii', $maestroID, $startNo, $endNo); - $stmt->bind_param('s', $maestroName); + // $stmt->bind_param("iii", $maestroID, $startNo, $endNo); + $stmt->bind_param("s", $maestroName); $stmt->execute(); $stmt->bind_result($maestroID, $name, $accountType); $maestroList = array(); while($stmt->fetch()) { - $maestro['MaestroID'] = $maestroID; - $maestro['Name'] = $name; - $maestro['AccountType'] = $accountType; + $maestro["maestroID"] = $maestroID; + $maestro["maestroName"] = $name; + $maestro["accountType"] = $accountType; array_push($maestroList, $maestro); } - $return_array['MaestroList'] = $maestroList; - return $return_array; + return $maestroList; } ?> \ No newline at end of file diff --git a/src/web/server/maestro/login.php b/src/web/server/maestro/login.php index 786f919..18113bd 100644 --- a/src/web/server/maestro/login.php +++ b/src/web/server/maestro/login.php @@ -1,5 +1,5 @@ prepare($query); - $stmt->bind_param('s', $maestro_name); + $stmt->bind_param("s", $maestro_name); $stmt->execute(); $stmt->bind_result($maestro_id); // while($stmt->fetch()) { @@ -58,7 +58,7 @@ function login($maestro_name, $password) { $query = "SELECT MaestroID FROM moty_maestro WHERE Name=? AND Password=PASSWORD(?)"; $stmt = $db_conn->prepare($query); - $stmt->bind_param('ss', $maestro_name, $password); + $stmt->bind_param("ss", $maestro_name, $password); $stmt->execute(); $stmt->bind_result($maestro_id); // while($stmt->fetch())