浏览代码

新增 新增身分功能

manto07m 3 年之前
父节点
当前提交
0a6ae34944

二进制
assets/excels/公司人員資料.xlsx


+ 93 - 0
assets/stylesheets/role.css

@@ -0,0 +1,93 @@
+.btn-User {
+    color: #ffffff;
+    text-shadow: 0 -1px 0 rgb(0 0 0 / 25%);
+    background-color: #0088cc;
+    border-color: #0088cc;
+}
+
+.btn-User:hover {
+    border-color: #0099e6 !important;
+    background-color: #0099e6;
+    color: white;
+}
+
+.btn-User:disabled {
+    background-color: #008ae6;
+    border-color: #008ae6;
+}
+
+.btn-D-Editor {
+    color: #ffffff;
+    text-shadow: 0 -1px 0 rgb(0 0 0 / 25%);
+    background-color: #f8701b;
+    border-color: #f8701b;
+}
+
+.btn-D-Editor:hover {
+    border-color: #fa843f !important;
+    background-color: #fa843f;
+    color: white;
+}
+
+.btn-B-Editor {
+    color: #ffffff;
+    text-shadow: 0 -1px 0 rgb(0 0 0 / 25%);
+    background-color: #003cc8;
+    border-color: #003cc8;
+}
+
+.btn-B-Editor:hover {
+    border-color: #135aff !important;
+    background-color: #135aff;
+    color: white;
+}
+
+.btn-Manager {
+    color: #ffffff;
+    text-shadow: 0 -1px 0 rgb(0 0 0 / 25%);
+    background-color: #400080;
+    border-color: #400080;
+}
+
+.btn-Manager:hover {
+    border-color: #7300e6 !important;
+    background-color: #7300e6;
+    color: white;
+}
+
+.btn-Guest {
+    color: #ffffff;
+    text-shadow: 0 -1px 0 rgb(0 0 0 / 25%);
+    background-color: #00b92e;
+    border-color: #00b92e;
+}
+
+.btn-Guest:hover {
+    border-color: #2dff62 !important;
+    background-color: #2dff62;
+    color: white;
+}
+
+
+
+.dropdown-menu > .li-User > a{
+    color: #0088cc;
+}
+
+.dropdown-menu >.li-D-Editor > a {
+   
+    color: #f8701b;
+    
+}
+
+.dropdown-menu > .li-B-Editor > a{
+    color: #003cc8;
+}
+
+.dropdown-menu > .li-Manager > a{
+    color: #400080;
+}
+
+.dropdown-menu > .li-Guest > a{
+    color: #00b92e;
+}

+ 126 - 37
index.php

@@ -2,7 +2,7 @@
 include($_SERVER['DOCUMENT_ROOT'] . "/Authorization/script/php/permission/check_right.php");
 ?>
 <!doctype html>
-<html class="fixed">
+<html class="fixed sidebar-left-collapsed">
 
 <head>
 	<!-- Basic -->
@@ -36,6 +36,9 @@ include($_SERVER['DOCUMENT_ROOT'] . "/Authorization/script/php/permission/check_
 	<!-- Theme Custom CSS -->
 	<link rel="stylesheet" href="assets/stylesheets/theme-custom.css">
 
+	<!-- Role Custom CSS -->
+	<link rel="stylesheet" href="assets/stylesheets/role.css" />
+
 	<!-- Head Libs -->
 	<script src="assets/vendor/modernizr/modernizr.js"></script>
 	<script src="assets/vendor/jquery/jquery.js"></script>
@@ -49,13 +52,19 @@ include($_SERVER['DOCUMENT_ROOT'] . "/Authorization/script/php/permission/check_
 	<script src="./script/js/global.js"></script>
 
 	<style>
-		td{
-			font-size:20px;
-			color:black;
+		td {
+			font-size: 20px;
+			color: black;
+		}
+
+		select {
+			font-size: 12px;
+			color: black;
 		}
-		select{
-			font-size:12px;
-			color:black;
+
+		.right {
+			position: absolute;
+			right: 8px;
 		}
 	</style>
 
@@ -64,54 +73,132 @@ include($_SERVER['DOCUMENT_ROOT'] . "/Authorization/script/php/permission/check_
 		var pageHeader = '帳號權限管理系統';
 		var role = '<?php echo ($groupName); ?>';
 		var roles;
-		getDeptUser();
+		var users;
+		var groups;
+		var groupDropdown;
 
+		var test;
 
 		function getDeptUser() {
 			$.ajax({
-				url: "./script/php/get_data/get_dept_user.php",
+				url: "./script/php/API/get_dept_user.php",
 				type: "POST",
 				dataType: "json"
 			}).done(function(result) {
-				console.log(result);
-				result.forEach(function(data){
+				roles = result.permissions;
+				users = result.users;
+				users.forEach(function(data) {
+					let btn = getPermissions(data.GroupID, data.GroupName);
 					$('#table-data').append(`<tr>
 						<td>${data.UserID}</td>
 						<td>${data.Account}</td>
 						<td>${data.UserName}</td>
 						<td>${data.DepartmentID}</td>
-						<td>
-							<select name="right" id="right">
-								<option value="User">一般用戶</option>
-								<option value="Editor">上傳人員</option>
-								<option value="Dadmin">部門管理員</option>
-							</select>
+						<td id="${data.UserID}">
+							<div class="btn-group">
+								<button type="button" class="mb-xs mt-xs mr-xs btn btn-default dropdown-toggle" data-toggle="dropdown">新增身分 <span class="caret"></span></button>
+								<ul class="dropdown-menu" role="menu" style="cursor: default;">
+									${groupDropdown}
+								</ul>
+							</div>
+							${btn}
 						</td>
-				</tr>`);
+					</tr>`);
+
 				});
-				
+
 			}).error(function(error) {
 				console.log(error);
+			}).complete(function(e) {
+				$('#datatable').DataTable({
+					bProcessing: true,
+					responsive: true,
+					"searching": true,
+					"pageLength": 10,
+					"language": {
+						"processing": "處理中...",
+						"loadingRecords": "載入中...",
+						"lengthMenu": "顯示 _MENU_ 項結果",
+						"zeroRecords": "沒有符合的結果或是沒有資料",
+						"info": "顯示第 _START_ 至 _END_ 項結果,共 _TOTAL_ 項",
+						"infoEmpty": "顯示第 0 至 0 項結果,共 0 項",
+						"infoFiltered": "(從 _MAX_ 項結果中過濾)",
+						"infoPostFix": "",
+						"search": "",
+						"paginate": {
+							"first": '<i class="fa fa-step-backward"></i>',
+							"previous": '<i class="fa fa-backward"></i>',
+							"next": '<i class="fa fa-forward"></i>',
+							"last": '<i class="fa fa-step-forward"></i>'
+						},
+						"aria": {
+							"sortAscending": ": 升冪排列",
+							"sortDescending": ": 降冪排列"
+						}
+					},
+				});
+				$('body .dropdown-toggle').dropdown();
+				$("body").on('click', '.groupDropdown', function(e) {
+					let groupName = $(this).text();
+					let groupID = $(this).attr('groupID');
+					let userAccount = $(this).closest("td").attr('id');
+					$(this).closest("td").append(addPermission(groupID, groupName, userAccount));
+				})
 			});
 		}
 
-		function getPageGroup() {
+		function getGroup() {
 			$.ajax({
-				url: "./script/php/get_data/get_page_group.php",
+				url: "./script/php/API/get_group.php",
 				type: "POST",
 				dataType: "json"
 			}).done(function(result) {
-				for (const [key, value] of Object.entries(result)) {
-					object = {};
-					object['id'] = 't';
-					object['idd'] = 'tt';
-					object["title"] = key;
-					roles.push(object);
-					result[key].forEach(function(item) {
-
-					})
-				}
+				groups = result;
+				groupDropdown = '';
+				groups.forEach(function(group) {
+					groupDropdown += `<li class="li-${group.GroupID}"><a groupID="${group.GroupID}" class="groupDropdown" >${group.GroupName}</a></li>`;
+				});
+			}).error(function(error) {
+				console.log(error);
+			});
+		}
 
+		function getPermissions(id, roles) {
+			var result = "";
+
+			roles.forEach(function(role, index) {
+				disabled = (role == '一般用戶' || role == '來賓') ? '' : '';
+				result += `<button class="btn btn-${id[index]}" ${disabled}>${role}</button>  `;
+			});
+			return result;
+		}
+
+		function addPermission(id, role, userID) {
+			var result = "";
+			user = users.find(user => user.UserID == userID);
+			if (!user.GroupName.includes(role)) {
+				result += `<button class="btn btn-${id}">${role}</button>  `;
+				addPermissionDB(user.UserID, id);
+				user.GroupName.push(role);
+				user.GroupID.push(id);
+				return result;
+			} else {
+				return result;
+			}
+
+		}
+
+		function addPermissionDB(userID, groupID) {
+			$.ajax({
+				url: "./script/php/API/insert_role.php",
+				type: "POST",
+				dataType: "text",
+				data: {
+					UserID: userID,
+					GroupID:groupID,
+				}
+			}).done(function(result) {
+				console.log(result);
 			}).error(function(error) {
 				console.log(error);
 			});
@@ -126,13 +213,13 @@ include($_SERVER['DOCUMENT_ROOT'] . "/Authorization/script/php/permission/check_
 		<!-- end: header -->
 		<div class="inner-wrapper">
 			<!-- start: sidebar -->
-			<side-bar></side-bar>
+			<side-bar-hide></side-bar-hide>
 			<!-- end: sidebar -->
 			<section role="main" class="content-body" id="contentBody">
 				<header class="page-header">
 					<h2>{{pageHeader}}</h2>
 				</header>
-				<role-block v-for="item in roles" v-bind:tbodyId='item.id' v-bind:title='item.title' v-bind:tableId='item.idd'></role-block>
+				<!-- <role-block v-for="item in roles" v-bind:tbodyId='item.id' v-bind:title='item.title' v-bind:tableId='item.idd'></role-block> -->
 
 				<section class="panel">
 					<header class="panel-heading">
@@ -140,7 +227,7 @@ include($_SERVER['DOCUMENT_ROOT'] . "/Authorization/script/php/permission/check_
 							<a href="#" class="fa fa-caret-down"></a>
 							<a href="#" class="fa fa-times"></a>
 						</div>
-						<h2 class="panel-title">設計資料庫查詢系統</h2>
+						<h2 id="testID" class="panel-title">所有系統</h2>
 					</header>
 					<div class="panel-body">
 						<table class="table table-bordered table-striped mb-none" id="datatable">
@@ -167,10 +254,12 @@ include($_SERVER['DOCUMENT_ROOT'] . "/Authorization/script/php/permission/check_
 
 	<script>
 		vm.mount('.body');
+		getGroup();
+		getDeptUser();
+		$(function() {
+
 
-		$(document).ready(function() {
-			$('#datatable').dataTable();
-		})
+		});
 	</script>
 
 

+ 4 - 2
insert_user.php

@@ -2,6 +2,8 @@
 include("./script/php/permission/connect_sql.php");
 include("./script/php/excel/read_excel.php");
 
+$group = array();
+
 $data = $excelData["人員帳號資料"];
 
 for ($i = 1; $i < count($data); $i++) {
@@ -21,7 +23,7 @@ for ($i = 1; $i < count($data); $i++) {
     ,[GroupID])
 VALUES
     (?,?)';
-    $stmt = sqlsrv_query($conn, $sql, array($data[$i][0], 'User'));
+    //$stmt = sqlsrv_query($conn, $sql, array($data[$i][0], 'User'));
 }
 echo ("<br>");
 echo ("<br>");
@@ -44,5 +46,5 @@ for ($i = 1; $i < count($data); $i++) {
     ,[GroupID])
 VALUES
     (?,?)';
-    $stmt = sqlsrv_query($conn, $sql, array($data[$i][0], 'Dadmin'));
+    //$stmt = sqlsrv_query($conn, $sql, array($data[$i][0], 'User'));
 }

+ 25 - 0
script/js/global.js

@@ -41,6 +41,31 @@ vm.component('side-bar', {
     </aside>`
 });
 
+vm.component('side-bar-hide', {
+    data() {
+        return {
+            banner: bimSupport,
+        }
+    },
+    template: `<aside id="sidebar-left" class="sidebar-left">
+        <div class="sidebar-header">
+            <div class="sidebar-title"> 導覽 </div>
+            <div class="sidebar-toggle hidden-xs" data-toggle-class="sidebar-left-collapsed" data-target="html" data-fire-event="sidebar-left-toggle"> <i class="fa fa-bars" aria-label="Toggle sidebar"></i> </div>
+        </div>
+        <div class="nano">
+            <div class="nano-content">
+                <nav id="menu" class="nav-main" role="navigation">
+                    <ul class="nav nav-main">
+                        <li style="display:none;">
+                            <a href="home.php"> <i class="fa fa-home" aria-hidden="true"></i> <span>首頁</span> </a>
+                        </li>
+                    </ul>
+                </nav>
+            </div>
+        </div>
+    </aside>`
+});
+
 vm.component('header-menu', {
     data() {
         return {

+ 42 - 0
script/php/API/get_dept_user.php

@@ -0,0 +1,42 @@
+<?php
+session_start();
+include('../permission/connect_sql.php');
+$user_list = array();
+$sql = "SELECT DISTINCT [User].[UserID],[Account],[UserName],[DepartmentID],[Group].[GroupID],[GroupName] FROM [User] 
+LEFT JOIN [UserGroup] ON [User].[UserID] = [UserGroup].[UserID] 
+LEFT JOIN [Group] ON [UserGroup].[GroupID] = [Group].[GroupID]
+LEFT JOIN [GroupRight] ON [GroupRight].[GroupID] = [Group].[GroupID] 
+LEFT JOIN [WebPage] ON [WebPage].[PgroupID] = [GroupRight].[PgroupID]
+WHERE [DepartmentID] = (SELECT [DepartmentID] FROM [User] WHERE [UserID] = ?) ORDER BY [GroupName]";
+$stmt = sqlsrv_query($conn, $sql, array($_SESSION['UserID']));
+$users = array();
+$permissions = array();
+while ($row = sqlsrv_fetch_array($stmt, SQLSRV_FETCH_ASSOC)) {
+    if (in_array($row["UserID"], $user_list)) {
+        $index = array_search($row["UserID"],$user_list);
+        array_push($users[$index]["GroupID"],$row["GroupID"]);
+        array_push($users[$index]["GroupName"],$row["GroupName"]);
+    } else {
+        $temp = array();
+        $temp["UserID"] = $row["UserID"];
+        $temp["Account"] = $row["Account"];
+        $temp["UserName"] = $row["UserName"];
+        $temp["DepartmentID"] = $row["DepartmentID"];
+        $temp["GroupID"] = array($row["GroupID"]);
+        $temp["GroupName"] = array($row["GroupName"]);
+        array_push($users, $temp);
+        array_push($user_list, $row["UserID"]);
+    }
+}
+
+$sql = "SELECT [GroupID],[GroupName] FROM [Group] WHERE [GroupID] != 'Admin'";
+$stmt = sqlsrv_query($conn, $sql, array($_SESSION['UserID']));
+while ($row = sqlsrv_fetch_array($stmt, SQLSRV_FETCH_ASSOC)) {
+    $temp = array();
+    $temp["GroupID"] = $row["GroupID"];
+    $temp["GroupName"] = $row["GroupName"];
+    array_push($permissions, $temp);
+}
+$data["users"] = $users;
+$data["permissions"] = $permissions;
+echo json_encode($data);

+ 14 - 0
script/php/API/get_group.php

@@ -0,0 +1,14 @@
+<?php
+session_start();
+include('../permission/connect_sql.php');
+$group = array();
+$sql = "SELECT [GroupID],[GroupName] FROM [Group] WHERE [GroupID] != 'Admin' AND [GroupID] != 'User' AND [GroupID] != 'Guest'";
+$stmt = sqlsrv_query($conn, $sql);
+while ($row = sqlsrv_fetch_array($stmt, SQLSRV_FETCH_ASSOC)) {    
+        $temp = array();
+        $temp["GroupID"] = $row["GroupID"];
+        $temp["GroupName"] = $row["GroupName"];
+        array_push($group, $temp);    
+}
+
+echo json_encode($group);

+ 27 - 0
script/php/API/insert_role.php

@@ -0,0 +1,27 @@
+<?php
+include($_SERVER['DOCUMENT_ROOT'] . "/Authorization/script/php/permission/check_right.php");
+include('../permission/connect_sql.php');
+if (isset($_POST['UserID']) && $_POST['GroupID']) {
+    $UserID = $_POST['UserID'];
+    $GroupID = $_POST['GroupID'];
+    $sql = "BEGIN
+                IF NOT EXISTS (SELECT [UserID],[GroupID] FROM [UserGroup] 
+                    WHERE [UserID] = ? AND [GroupID] = ?)
+                BEGIN
+                    INSERT INTO [UserGroup] ([UserID],[GroupID])
+                    VALUES  (?, ?)
+                END
+            END";
+    $stmt = sqlsrv_query($conn, $sql, array($UserID, $GroupID, $UserID, $GroupID));
+    if ($stmt === false) {
+        if (($errors = sqlsrv_errors()) != null) {
+            foreach ($errors as $error) {
+                echo "SQLSTATE: " . $error['SQLSTATE'] . "<br />";
+                echo "code: " . $error['code'] . "<br />";
+                echo "message: " . $error['message'] . "<br />";
+            }
+        }
+    }else{
+        echo('身分新增成功!');
+    }
+}

+ 1 - 1
script/php/excel/read_excel.php

@@ -1,6 +1,6 @@
 <?php
 
-require '../../../vendor/autoload.php';
+require './vendor/autoload.php';
 use PhpOffice\PhpSpreadsheet\Spreadsheet;
 use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
 

+ 0 - 16
script/php/get_data/get_dept_user.php

@@ -1,16 +0,0 @@
-<?php
-session_start();
-include('../permission/connect_sql.php');
-
-$sql = "SELECT [UserID],[Account],[UserName],[DepartmentID] FROM [User] WHERE [DepartmentID] = ?";
-$stmt = sqlsrv_query($conn, $sql, array($_SESSION['UserID']));
-$users = array();
-while ($row = sqlsrv_fetch_array($stmt, SQLSRV_FETCH_ASSOC)) {
-    $temp = array();
-    $temp["UserID"] = $row["UserID"];
-    $temp["Account"] = $row["Account"];
-    $temp["UserName"] = $row["UserName"];
-    $temp["DepartmentID"] = $row["DepartmentID"];
-    array_push($users, $temp);
-}
-echo json_encode($users);

+ 0 - 18
script/php/get_data/get_page_group.php

@@ -1,18 +0,0 @@
-<?php
-session_start();
-include('../permission/connect_sql.php');
-
-$sql = "SELECT [PageID],[PgroupName] FROM [WebPage] LEFT JOIN [PageGroup] ON [WebPage].[PgroupID] = [PageGroup].[PgroupID] ";
-$stmt = sqlsrv_query($conn, $sql);
-
-while ($row = sqlsrv_fetch_array($stmt, SQLSRV_FETCH_ASSOC)) {
-    
-    
-    $pGroupName = $row["PgroupName"];
-    if(!isset($group[$pGroupName])){
-        $group[$pGroupName] = array();
-    }
-    $pageID = $row["PageID"];    
-    array_push($group[$pGroupName], $pageID);
-}
-echo json_encode($group);