Newer
Older
<?php
// admin.php
session_start();
include('db.php');
if (!isset($_SESSION['username'])) {
header('Location: index.php');
exit;
}
// 检查是否是管理员
$username = $_SESSION['username'];
$role_query = "SELECT role, id FROM users WHERE username='$username'";
$user_data = mysqli_fetch_assoc($role_result);
$role = $user_data['role'];
$user_id = $user_data['id'];
if ($role != 'admin' and $role != 'superadmin') {
echo "无权限访问!";
exit;
}
// 获取设备列表
if ($role == 'superadmin') {
$equipment_query = "SELECT * FROM equipment";
} else {
$equipment_query = "SELECT * FROM equipment WHERE admin_id='$user_id'";
}
$equipment_result = mysqli_query($conn, $equipment_query);
?>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<title>管理员页面</title>
<!-- 引入Bootstrap CSS -->
<link href="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/5.3.3/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
<!-- 导航栏 -->
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<!-- 省略,内容与index.php相同 -->
</nav>
<div class="container mt-3">
<a href="index.php" class="btn btn-secondary">返回主页</a>
<button onclick="history.back()" class="btn btn-secondary">返回上一级</button>
</div>
<div class="container mt-4">
<h2>预约审批</h2>
<a href="admin_approvals.php" class="btn btn-primary">查看待审批预约</a>
<h2>添加设备</h2>
<a href="add_equipment.php" class="btn btn-primary mb-3">添加新设备</a>
<h2>设备管理</h2>
<table class="table table-striped">
<thead>
<tr>
<th>设备名称</th>
<th>状态</th>
<th>操作</th>
</tr>
</thead>
<tbody>
<?php while ($equipment = mysqli_fetch_assoc($equipment_result)) { ?>
<tr>
<td><?php echo $equipment['name']; ?></td>
<td><?php echo $equipment['status'] == 'available' ? '可用' : '不可用'; ?></td>
<td>
<a href="edit_equipment.php?id=<?php echo $equipment['id']; ?>" class="btn btn-secondary btn-sm">编辑</a>
</td>
</tr>
<?php } ?>
</tbody>
</table>
</div>
</body>
</html>