From 24b5956fd13cf7f0b58826a7a097aac3ddec9398 Mon Sep 17 00:00:00 2001 From: Tu TV Date: Sun, 10 May 2015 01:07:50 +0700 Subject: [PATCH] =?UTF-8?q?=C4=90=C3=A3=20th=C3=AAm=20ch=E1=BB=A9c=20n?= =?UTF-8?q?=C4=83ng=20=C4=91=C4=83ng=20nh=E1=BA=ADp?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/{ => getData}/BuoiHoc.php | 0 api/{ => getData}/LopMH.php | 0 api/{ => getData}/MonHoc.php | 0 api/{ => getData}/getmonhoc.php | 2 +- api/sign/getStatus.php | 14 ++++ api/sign/signin.php | 55 ++++++++++++++++ api/sign/signout.php | 5 ++ css/main.css | 47 ++++++++++++++ includes/form-signin.php | 19 ++++++ includes/header.php | 30 +++++---- index.php | 4 +- js/main.js | 112 +++++++++++++++++++++++++++++++- 12 files changed, 272 insertions(+), 16 deletions(-) rename api/{ => getData}/BuoiHoc.php (100%) rename api/{ => getData}/LopMH.php (100%) rename api/{ => getData}/MonHoc.php (100%) rename api/{ => getData}/getmonhoc.php (98%) create mode 100644 api/sign/getStatus.php create mode 100644 api/sign/signin.php create mode 100644 api/sign/signout.php create mode 100644 includes/form-signin.php diff --git a/api/BuoiHoc.php b/api/getData/BuoiHoc.php similarity index 100% rename from api/BuoiHoc.php rename to api/getData/BuoiHoc.php diff --git a/api/LopMH.php b/api/getData/LopMH.php similarity index 100% rename from api/LopMH.php rename to api/getData/LopMH.php diff --git a/api/MonHoc.php b/api/getData/MonHoc.php similarity index 100% rename from api/MonHoc.php rename to api/getData/MonHoc.php diff --git a/api/getmonhoc.php b/api/getData/getmonhoc.php similarity index 98% rename from api/getmonhoc.php rename to api/getData/getmonhoc.php index 7ccca7f..caf4750 100644 --- a/api/getmonhoc.php +++ b/api/getData/getmonhoc.php @@ -12,7 +12,7 @@ require "MonHoc.php"; require "LopMH.php"; require "BuoiHoc.php"; -require "../config.php"; +require "../../config.php"; $ds_monhoc = array(); diff --git a/api/sign/getStatus.php b/api/sign/getStatus.php new file mode 100644 index 0000000..841ec29 --- /dev/null +++ b/api/sign/getStatus.php @@ -0,0 +1,14 @@ + $status, "user" => $user]); + } +?> diff --git a/api/sign/signin.php b/api/sign/signin.php new file mode 100644 index 0000000..751a56e --- /dev/null +++ b/api/sign/signin.php @@ -0,0 +1,55 @@ + 0) { + $row = mysqli_fetch_array($result, MYSQL_ASSOC); + $pass = $row['pass']; + return $pass; + } + + return false; +} + +function getName($username) { + global $conn; + $sql = "select name from nguoidung where email = '$username'"; + $result = mysqli_query($conn, $sql); + + if (mysqli_num_rows($result ) > 0) { + $row = mysqli_fetch_array($result, MYSQL_ASSOC); + $name = $row['name']; + if ($name == "") { + return $username; + } + return $name; + } + + return "Bạn"; +} + +function echoJson($result) { + echo json_encode(array("result" => $result)); +} + +if (isset($_POST['user']) and isset($_POST['pass'])) { + $pass = getPassword($_POST['user']); + if ($pass == false) { + echoJson(false); + } else { + if (md5( $_POST['pass']) == $pass) { + $_SESSION['user'] = getName($_POST['user']); + echoJson(true); + } else { + echoJson(false); + } + } +} +else { + echoJson(false); +} \ No newline at end of file diff --git a/api/sign/signout.php b/api/sign/signout.php new file mode 100644 index 0000000..7b68525 --- /dev/null +++ b/api/sign/signout.php @@ -0,0 +1,5 @@ + + + \ No newline at end of file diff --git a/includes/header.php b/includes/header.php index fe62292..a59ca5c 100644 --- a/includes/header.php +++ b/includes/header.php @@ -5,21 +5,29 @@
+
+ + diff --git a/index.php b/index.php index bc37c16..adf5d1c 100644 --- a/index.php +++ b/index.php @@ -15,10 +15,10 @@ -
+
- +
diff --git a/js/main.js b/js/main.js index 5ab9fea..a858932 100644 --- a/js/main.js +++ b/js/main.js @@ -124,7 +124,7 @@ function infoLesson() { // Get dữ liệu từ phía server $(document).ready(function () { $.ajax({ - url : "./api/getmonhoc.php", + url : "./api/getData/getmonhoc.php", method : "GET", dataType: "json", success : function(data) { @@ -160,6 +160,21 @@ $(document).ready(function () { }, cache: true }); + + + //Kiểm tra trạng thái đăng nhập? + $.ajax({ + url: "api/sign/getStatus.php", + method: "GET", + dataType: "json", + success: function(data) { + if (data.status == true) { + signin(); + } else { + signout(); + } + } + }); }); //Thêm lớp môn học vào lịch tuần @@ -371,4 +386,97 @@ function thongBao(text, type) { speed: 500 // unavailable - no need } }); -} \ No newline at end of file +} + +$("#btn-signin-submit").click(function () { + var user = $("#inputEmail").val(); + var pass = $("#inputPassword").val(); + + $.ajax({ + url : "api/sign/signin.php", + method : "POST", + dataType: "json", + data : {user: user, pass: pass}, + success : function(data) { + var resultDOM = $("#result-signin"); + if (data.result == true) { + $("#form-signin").modal("hide"); + signin(); + } else { + resultDOM.text("Đăng nhập thất bại"); + resultDOM.addClass("bg-danger"); + resultDOM.show(); + + } + } + }); +}); + +$("#btn-signout").click(function() { + $.get("api/sign/signout.php"); + signout(); +}); + +function signout() { + var signinDOM = $("#signined"); + signinDOM.hide(); + signinDOM.attr("data-target", "out"); + $("#btn-signup").show(); + $("#btn-signin").show(); +} + +function signin() { + $.ajax({ + url: "api/sign/getStatus.php", + method: "GET", + dataType: "json", + success: function(data) { + if (data.status == true) { + $("#hello-user").text(data.user); + var signinDOM = $("#signined"); + signinDOM.show(); + signinDOM.attr("data-target", "in"); + $("#btn-signup").hide(); + $("#btn-signin").hide(); + } + } + }); +} + +function getStatusSign() { + var status = $("#signined").attr("data-target"); + return (status == "in"); +} + +$("#btn-save-table").click(function () { + var sign = getStatusSign(); + if (!sign) { + $("#form-signin").modal("show"); + return; + } + + //Nếu đã đăng nhập thì xử lý theo tool + alert("Chức năng đang hoàn thiện"); +}); + +$("#btn-share-table").click(function () { + var sign = getStatusSign(); + if (!sign) { + $("#form-signin").modal("show"); + return; + } + + //Nếu đã đăng nhập thì xử lý theo tool + alert("Chức năng đang hoàn thiện"); +}); + +$("#btn-export-table").click(function () { + var sign = getStatusSign(); + if (!sign) { + $("#form-signin").modal("show"); + return; + } + + //Nếu đã đăng nhập thì xử lý theo tool + alert("Chức năng đang hoàn thiện"); +}); \ No newline at end of file