仰望星辰工作室

better-staridc-MNBT

Z zfhsh first commit 2 个月前
1<?php
2/**
3 * 管理员端 - 用户编辑
4 */
5if (!defined('IN_CRONLITE')) {
6 exit;
7}
8
9global $DB, $date;
10
11$user_id = (int)($_GET['id'] ?? 0);
12if ($user_id <= 0) {
13 echo '参数错误';
14 exit;
15}
16
17$row = $DB->get_row_prepare("SELECT * FROM MN_plugin_user WHERE id=? LIMIT 1", [$user_id]);
18if (!$row) {
19 echo '用户不存在';
20 exit;
21}
22
23// POST 保存
24if ($_SERVER['REQUEST_METHOD'] === 'POST') {
25 $email = trim((string)($_POST['email'] ?? ''));
26 $qq = trim((string)($_POST['qq'] ?? ''));
27 $status = isset($_POST['status']) ? ((int)$_POST['status'] === 1 ? 1 : 0) : (int)$row['status'];
28
29 if ($email !== '' && !filter_var($email, FILTER_VALIDATE_EMAIL)) {
30 echo '<div class="alert alert-danger m-3">邮箱格式不正确</div>';
31 exit;
32 }
33 if ($email !== '' && strlen($email) > 128) {
34 echo '<div class="alert alert-danger m-3">邮箱过长</div>';
35 exit;
36 }
37 if ($qq !== '' && !preg_match('/^[0-9]{5,12}$/', $qq)) {
38 echo '<div class="alert alert-danger m-3">QQ 号格式不正确</div>';
39 exit;
40 }
41
42 $now = $date ?: date('Y-m-d H:i:s');
43 $ok = $DB->query_prepare(
44 "UPDATE MN_plugin_user SET email=?, qq=?, status=?, updated_at=? WHERE id=?",
45 [$email, $qq, $status, $now, $user_id]
46 );
47 if ($ok) {
48 header('Location: plugin.php?p=user_info&page=users');
49 exit;
50 }
51 echo '<div class="alert alert-danger m-3">保存失败</div>';
52 exit;
53}
54
55$title = $title ?? '用户编辑';
56mnbt_admin_include('head');
57?>
58
59<div class="container-fluid p-t-15">
60 <div class="card">
61 <div class="card-header">
62 <h4 style="display:inline-block">编辑用户</h4>
63 <a href="plugin.php?p=user_info&page=users" class="btn btn-sm btn-outline-secondary float-right multitabs">返回列表</a>
64 </div>
65 <div class="card-body">
66 <form method="post">
67 <table class="table table-bordered">
68 <tbody>
69 <tr>
70 <th style="width:140px">用户 ID</th>
71 <td><?= (int)$row['id'] ?></td>
72 </tr>
73 <tr>
74 <th>用户名</th>
75 <td><code><?= htmlspecialchars($row['username'], ENT_QUOTES) ?></code><small class="text-muted ml-2">(用户名不可修改)</small></td>
76 </tr>
77 <tr>
78 <th>邮箱</th>
79 <td><input type="text" name="email" class="form-control" value="<?= htmlspecialchars($row['email'], ENT_QUOTES) ?>" placeholder="选填"></td>
80 </tr>
81 <tr>
82 <th>QQ</th>
83 <td><input type="text" name="qq" class="form-control" value="<?= htmlspecialchars($row['qq'], ENT_QUOTES) ?>" placeholder="选填"></td>
84 </tr>
85 <tr>
86 <th>状态</th>
87 <td>
88 <select name="status" class="form-control">
89 <option value="1" <?= (int)$row['status'] === 1 ? 'selected' : '' ?>>正常</option>
90 <option value="0" <?= (int)$row['status'] === 0 ? 'selected' : '' ?>>禁用</option>
91 </select>
92 </td>
93 </tr>
94 <tr>
95 <th>注册时间</th>
96 <td class="text-muted"><?= htmlspecialchars($row['created_at'], ENT_QUOTES) ?></td>
97 </tr>
98 <tr>
99 <th>更新时间</th>
100 <td class="text-muted"><?= htmlspecialchars($row['updated_at'], ENT_QUOTES) ?></td>
101 </tr>
102 </tbody>
103 </table>
104
105 <div class="text-center mt-3">
106 <button type="submit" class="btn btn-primary"><i class="mdi mdi-content-save-outline"></i> 保存修改</button>
107 <a href="plugin.php?p=user_info&page=users" class="btn btn-outline-secondary ml-2 multitabs">取消</a>
108 </div>
109 </form>
110 </div>
111 </div>
112</div>