hxp
2025-06-09 6c3f6335c70859ded94a1ad8d218acb0ac34239c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
<?php
include_once "/Common/Logging.php";
include_once "/Account/User.php";
include_once "/db/DBOper.php";
include_once "/language/lang.php";
 
/**可否编辑管理该账号,主要检查权限方面 */
function CanEdit($userData)
{
    global $user;
    if ($user->IsAdminSuper()) {
        return true;
    }
 
    // 只能管理自己组织内的账号
    if ($user->GetAttr("Organization") != $userData["Organization"]) {
        \Logging\LogError("Organization is different. userAccount:" . $user->GetAttr("UserAccount") . " editUserAccount:" . $userData["UserAccount"]);
        return false;
    }
 
    // 只能管理账号等级不超过自己的
    if ($user->GetAttr("UserLV") < $userData["UserLV"]) {
        \Logging\LogError("UserLV is less. userAccount:" . $user->GetAttr("UserAccount") . " editUserAccount:" . $userData["UserAccount"]);
        return false;
    }
 
    return true;
}
 
function UserEdit($opType)
{
    global $alertMsg, $user, $PGroups;
 
    \Logging\LogInfo("_POST:" . print_r($_POST, true));
 
    $UserAccount = $_POST["UserAccount"];
 
    $find = array(
        "UserAccount" => $UserAccount
    );
 
    DBOper\FindOne("GMTUser", $find, $findUser);
 
    // 添加
    if ($opType == "add") {
        if (count($findUser) > 0) {
            $alertMsg = \Lang\gettext("该账号已存在");
            return false;
        }
    } else {
        if (!isset($findUser) || count($findUser) == 0) {
            $alertMsg = \Lang\gettext("该账号不存在");
            return false;
        }
    }
 
    if ($opType == "del") {
        if ($user->GetAttr("UserAccount") == $findUser["UserAccount"]) {
            $alertMsg = \Lang\gettext("无法执行该操作");
            \Logging\LogError("无法执行该操作" . print_r($find, true));
            return false;
        }
        if (!CanEdit($findUser)) {
            $alertMsg = \Lang\gettext("您没有该权限");
            return false;
        }
        if (!DBOper\Remove("GMTUser", $find)) {
            $alertMsg = \Lang\gettext("删除失败");
            \Logging\LogError("删除失败" . print_r($find, true));
            return false;
        }
        $alertMsg = \Lang\gettext("删除成功");
        \Logging\LogInfo("删除成功" . print_r($find, true));
        return true;
    }
 
    $PswAdmin = \Commfunc\GetEncodePsw($_POST["PswAdmin"]);
    if (!$PswAdmin || $PswAdmin != $user->GetAttr("Psw")) {
        $alertMsg = \Lang\gettext("您的账号密码错误");
        return false;
    }
 
    $UserAccount = $_POST["UserAccount"];
    $UserLV = intval($_POST["UserLV"]);
    $Organization = $_POST["Organization"];
 
    $OrganizationList = \CommFunc\GetAllOrganization();
    if (!in_array($Organization, $OrganizationList)) {
        return false;
    }
 
    $editArray = array(
        "UserAccount" => $UserAccount,
        "UserLV" => $UserLV,
        "Organization" => $Organization,
    );
 
    if ($opType == "add" || $_POST["Psw"] != "") {
        $Psw = $_POST["Psw"];
        $PswConfirm = $_POST["PswConfirm"];
        if (!$Psw || $Psw != $PswConfirm) {
            $alertMsg = \Lang\gettext("密码不一致");
            return false;
        }
        $editArray["Psw"] = \Commfunc\GetEncodePsw($Psw);
    }
 
    // 渠道仅限自己的渠道权限内
    $SPList = array();
    foreach ($user->GetSPIDAll() as $value) {
        if ($_POST["SPID_" . $value] == "on") {
            array_push($SPList, $value);
        }
    }
    $editArray["SPList"] = $SPList;
 
    $PermissionGroups = array();
    foreach ($PGroups as $GroupName) {
        $checkBoxName = "PGroup_" . urlencode($GroupName);
        if ($_POST[$checkBoxName] == "on") {
            array_push($PermissionGroups, $GroupName);
        }
    }
    $editArray["PermissionGroups"] = $PermissionGroups;
 
    if (!CanEdit($editArray)) {
        $alertMsg = \Lang\gettext("您没有该权限");
        return false;
    }
 
    // 添加
    if ($opType == "add") {
        $editArray["CreateTime"] = date("Y-m-d H:i:s");
        if (!DBOper\Insert("GMTUser", $editArray, $find)) {
            $alertMsg = \Lang\gettext("添加失败");
            \Logging\LogError("添加失败" . print_r($editArray, true));
            return false;
        }
        $alertMsg = \Lang\gettext("添加成功");
        \Logging\LogInfo("添加成功" . print_r($editArray, true));
    }
    // 更新
    elseif ($opType == "upd") {
        if (!DBOper\Update("GMTUser", $find, $editArray, true)) {
            $alertMsg = \Lang\gettext("更新失败");
            \Logging\LogError("更新失败" . print_r($editArray, true));
            return false;
        }
        $alertMsg = \Lang\gettext("更新成功");
        \Logging\LogInfo("更新成功" . print_r($editArray, true));
    }
    return true;
}
 
\Logging\CreateLogging("account.userlist.php");
$Permission = \User\Permission::P_UserMgr;
 
$alertMsg = "";
$channel = $_SESSION['spid'];
$UserAccount = $_SESSION['UserAccount'];
$user = new \User\User($UserAccount);
if (!$user->HavePermission($Permission)) {
    exit;
}
 
// echo print_r($_POST, true), "<br/>";
$Organization = array_key_exists("Organization", $_POST) ? $_POST["Organization"] : $user->GetAttr("Organization");
 
\DBOper\Find("GMTPermissionGroup", array("Organization" => $Organization), $OrganizationPGroups);
$PGroups = array();
foreach ($OrganizationPGroups as $value) {
    array_push($PGroups, $value["GroupName"]);
}
 
if ($_POST["opType"]) {
    UserEdit($_POST["opType"]);
}
 
\DBOper\Find("GMTUser", array("Organization" => $Organization), $userArray, null, array("UserLV" => -1));
 
//显示表格字段配置 key-参数名,value-说明
$tableArray = array(
    "UserAccount" => array(\Lang\gettext("账号"), "10%", "center"),
    "UserLV" => array(\Lang\gettext("账号等级"), "8%", "center"),
    "SPList" => array(\Lang\gettext("可管理AppID列表"), "20%", "center"),
    "PermissionGroups" => array(\Lang\gettext("拥有权限"), "35%", "center"),
    // "CreateTime" => array(\Lang\gettext("创建时间"), "11%", "center"),
    "LoginTime" => array(\Lang\gettext("最近登录"), "11%", "center"),
    "IP" => array("IP", "9%", "center"),
    "" => array(\Lang\gettext("操作"), "", "center"),
);
 
if ($alertMsg) {
    echo "<script>alert('" . $alertMsg . "')</script>";
}
 
?>
 
<html>
 
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title><?php echo \Lang\gettext("账号管理"); ?></title>
    <link rel="stylesheet" type="text/css" href="/css/table.css">
</head>
 
<body>
    <center>
        <p><b><?php echo \Lang\gettext("账号管理"); ?></b></P>
    </center>
 
    <?php
    // 超级管理员可管理所有组织
    if ($user->IsAdminSuper()) {
        echo "切换组织: ";
        echo "<select name=\"Organization\" onchange=\"changeOrganization(this.value)\">";
        foreach (\CommFunc\GetAllOrganization() as $value) {
            echo "<option value=\"" . $value . "\"";
            if ($Organization == $value) {
                echo " selected";
            }
            echo ">" . $value . "</option>";
        }
        echo "</select>";
    }
    ?>
    <input type="button" value="<?php echo \Lang\gettext("添加用户"); ?>" onclick="window.location.href='useredit.php?opType=add&Organization=<?php echo $Organization; ?>'" />
    <hr />
    <table width="100%">
        <?php
        if ($userArray) {
            echo "<thead><tr>";
            foreach ($tableArray as $value) {
                echo "<th width=\"" . $value[1] . "\">" . $value[0] . "</td>";
            }
            echo "</tr></thead>";
            $UserLVNameInfo = \User\UserLV::LVNameInfo();
            foreach ($userArray as $userData) {
                echo "<tr class='trc'>";
                $UserAccount = $userData["UserAccount"];
                $UserLV = $userData["UserLV"];
                if ($UserLV == \User\UserLV::ADMIN_SUPER && !$user->IsAdminSuper()) {
                    continue;
                }
                foreach ($tableArray as $key => $value) {
                    if (!$key) {
                        echo "<td align='center'>";
                        echo "&nbsp;<input type=\"button\" value=\"" . \Lang\gettext("改") . "\" onclick=\"window.location.href='useredit.php?opType=upd&UserAccount=$UserAccount'\" />";
                        echo " <input type=\"button\" value=\"" . \Lang\gettext("删") . "\" onclick=\"return suredel('$Organization','$UserAccount')\"/>&nbsp;";
                        echo "</td>";
                        continue;
                    }
                    $tdContent = $userData[$key];
                    if ($key == "UserLV") {
                        $tdContent = $UserLVNameInfo[$tdContent];
                    } else if ($key == "SPList") {
                        if ($UserLV == \User\UserLV::ADMIN_SUPER) {
                            $tdContent = "全部";
                        } else {
                            if ($UserLV == \User\UserLV::ADMIN_ORG) {
                                $tdContent = \CommFunc\GetOrganizationChannel($Organization);
                            }
                            $tdc = "";
                            foreach ($tdContent as $value) {
                                if ($tdc != "") {
                                    $tdc .= "、";
                                }
                                $tdc .= $value;
                            }
                            $tdContent = $tdc;
                        }
                    } else if ($key == "PermissionGroups") {
                        if ($UserLV == \User\UserLV::ADMIN_SUPER) {
                            $tdContent = "全部";
                        } else if ($UserLV == \User\UserLV::ADMIN_ORG) {
                            $tdContent = \Lang\gettext("组织全部权限");
                        } else {
                            $tdc = "";
                            foreach ($tdContent as $value) {
                                if (!in_array($value, $PGroups)) {
                                    continue;
                                }
                                if ($tdc != "") {
                                    $tdc .= "&nbsp;&nbsp;";
                                }
                                $tdc .= $value;
                            }
                            $tdContent = $tdc;
                        }
                    }
                    echo "<td align='" . $value[2] . "'>" . $tdContent . "</td>";
                }
                echo "</tr>";
            }
        } else {
            echo "无账号,请添加!<br/>";
        }
        ?>
    </table>
 
    <script type="text/javascript">
        function doPost(to, p) { // to:提交动作(action),p:参数 
            var myForm = document.createElement("form");
            myForm.method = "post";
            myForm.action = to;
            for (var i in p) {
                var myInput = document.createElement("input");
                myInput.setAttribute("name", i); // 为input对象设置name 
                myInput.setAttribute("value", p[i]); // 为input对象设置value 
                myForm.appendChild(myInput);
            }
            document.body.appendChild(myForm);
            myForm.submit();
            document.body.removeChild(myForm); // 提交后移除创建的form 
        }
 
        function changeOrganization(Organization) {
            doPost("userlist.php", {
                "Organization": Organization
            });
        }
 
        function suredel(Organization, UserAccount) {
            var confirmstr = "<?php echo \Lang\gettext("确定删除账号? 目标账号:"); ?>";
            if (!window.confirm(confirmstr + UserAccount)) {
                return false;
            }
            doPost("userlist.php", {
                "opType": "del",
                "Organization": Organization,
                "UserAccount": UserAccount,
            });
            return true;
        }
    </script>
</body>
 
</html>