From f98ffad4bf7d4df816e28d07c01f6069dfe987ca Mon Sep 17 00:00:00 2001
From: CXM <chenzixin202209@163.com>
Date: Wed, 20 Mar 2024 17:00:16 +0000
Subject: [PATCH] create admin side page

---
 Admin/admin_page.php       | 47 ++++++++++++++++++++++++++++++++++++++
 Logic/session_start.php    |  1 +
 Logic/translate.php        |  3 ++-
 Presentation/LoginPage.php |  1 +
 Presentation/interface.php | 18 ++++-----------
 Presentation/settings.php  |  4 ++--
 6 files changed, 58 insertions(+), 16 deletions(-)
 create mode 100644 Admin/admin_page.php

diff --git a/Admin/admin_page.php b/Admin/admin_page.php
new file mode 100644
index 0000000..0f52f0f
--- /dev/null
+++ b/Admin/admin_page.php
@@ -0,0 +1,47 @@
+<?php
+include_once '../Logic/session_start.php';
+include_once '../Logic/config.php';
+
+// 检查用户是否是管理员,如果不是则重定向到主页面
+if (!isset($_SESSION['user_type'])) {
+    header("Location: LoginPage.php");
+    exit;
+}
+?>
+<!DOCTYPE html>
+<html lang="zh-CN">
+<head>
+    <meta charset="UTF-8">
+    <meta name="viewport" content="width=device-width, initial-scale=1.0">
+    <title>管理员管理页面</title>
+    <link href="https://cdn.jsdelivr.net/npm/tailwindcss@2.2.19/dist/tailwind.min.css" rel="stylesheet">
+</head>
+<body class="bg-gray-100">
+<div class="flex h-screen">
+    <!-- 侧边栏 -->
+    <div class="w-64 bg-gray-800 text-white">
+        <div class="px-5 py-10">Welcome! Dear admin!</div>
+        <ul class="space-y-2">
+            <li><a href="#" data-src="manageUniMap.php" class="block px-5 py-3 hover:bg-gray-700">Manage uni Map</a></li>
+            <li><a href="#" data-src="user_manage.php" class="block px-5 py-3 hover:bg-gray-700">Manage user detail</a></li>
+            <li><a href="#" data-src="manageBristolMap.php" class="block px-5 py-3 hover:bg-gray-700">Manage Bristol Map</a></li>
+            <li><a href="#" data-src="manageQA.php" class="block px-5 py-3 hover:bg-gray-700">Question and answer management</a></li>
+        </ul>
+    </div>
+    <!-- 主内容区 -->
+    <div class="flex-1">
+        <iframe id="mainContent" class="w-full h-full overflow-auto" src="about:blank"></iframe>
+    </div>
+</div>
+<script>
+    document.querySelectorAll('a').forEach(link => {
+        link.addEventListener('click', function(event) {
+            event.preventDefault();
+            document.getElementById('mainContent').src = this.getAttribute('data-src');
+        });
+    });
+</script>
+</body>
+</html>
+
+
diff --git a/Logic/session_start.php b/Logic/session_start.php
index b6927c0..98f5780 100644
--- a/Logic/session_start.php
+++ b/Logic/session_start.php
@@ -9,4 +9,5 @@ if (!isset($_SESSION['user_id'])) {
 
 // 获取用户 ID
 $userID = $_SESSION['user_id'];
+$userType = $_SESSION['user_type'];
 ?>
diff --git a/Logic/translate.php b/Logic/translate.php
index 0c437c0..46bcded 100644
--- a/Logic/translate.php
+++ b/Logic/translate.php
@@ -4,7 +4,8 @@
         new google.translate.TranslateElement({
                 pageLanguage: 'en',//网页的语言
                 layout: google.translate.TranslateElement.FloatPosition.TOP_LEFT,
-                includedLanguages: 'en,zh-CN'},//可以翻译的语言,这里是可选的,默认是全部语言
+                // includedLanguages: 'en,zh-CN'
+            },//可以翻译的语言,这里是可选的,默认是全部语言
             'google_translate_element'
         );
     }
diff --git a/Presentation/LoginPage.php b/Presentation/LoginPage.php
index cfe82f6..6af1d0a 100644
--- a/Presentation/LoginPage.php
+++ b/Presentation/LoginPage.php
@@ -25,6 +25,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
                 if ($user['id'] == $studentId) {
                     // 登录成功,执行相应操作
                     $_SESSION['user_id'] = $user['id']; // 将用户 ID 存储在会话中
+                    $_SESSION['user_type'] = $user['user_Type']; //储存用户类型
 
                     // 更新用户的在线状态为 'online'
                     $updateOnlineStatus = DB->prepare("UPDATE user SET is_online = 'online' WHERE id = ?");
diff --git a/Presentation/interface.php b/Presentation/interface.php
index cc3591f..cf90c96 100644
--- a/Presentation/interface.php
+++ b/Presentation/interface.php
@@ -1,16 +1,3 @@
-<?php
-//session_start(); // 启动会话
-//
-//// 检查用户是否已登录,如果未登录则重定向到登录页面
-//if (!isset($_SESSION['user_id'])) {
-//    header("Location: LoginPage.php");
-//    exit;
-//}
-//
-//// 获取用户 ID
-//$userID = $_SESSION['user_id'];
-//?>
-
 <?php require_once '../Logic/session_start.php'; ?>
 <!DOCTYPE html>
 <html lang="en">
@@ -36,6 +23,11 @@
         <a href="city.php" class="sidebar-item" target="contentFrame">Around Bristol</a>
         <a href="chatPage.php" class="sidebar-item" target="contentFrame">Campus Voices</a>
         <a href="settings.php" class="sidebar-item" target="contentFrame"><i class="fas fa-home"></i> User Profile</a>
+        <?php
+        if (isset($userType) && $userType === 'admin') {
+            echo '<a href="../Admin/admin_page.php" class="sidebar-item" target="contentFrame">Admin Page</a>';
+        }
+        ?>
     </div>
 
     <div id="chatContainer">
diff --git a/Presentation/settings.php b/Presentation/settings.php
index be95dff..f83c8ed 100644
--- a/Presentation/settings.php
+++ b/Presentation/settings.php
@@ -4,9 +4,9 @@ require_once '../Logic/session_start.php';
 
 function updateUserInformation($userId, $name, $email, $major, $year)
 {
-    $sql = "UPDATE user SET user_Name = ?, email = ?, user_Major = ?, enrollment_Year = ? WHERE id = ?";
+    $sql = "UPDATE user SET user_Name = ?, email = ? WHERE id = ?";
     $stmt = DB->prepare($sql);
-    return $stmt->execute([$name, $email, $major, $year, $userId]);
+    return $stmt->execute([$name, $email, $userId]);
 }
 
 function updateAccountInfo($account, $password, $userId)
-- 
GitLab