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
<?php
include_once "/Common/Logging.php";
include_once "/Account/User.php";
include_once "/db/DBOper.php";
include_once "/language/lang.php";
 
function PergroupEdit($opType)
{
    global $alertMsg, $user;
 
    \Logging\LogInfo("_POST:" . print_r($_POST, true));
 
    $Organization = $_POST["Organization"];
    $GroupName = $_POST["GroupName"];
 
    $find = array(
        "Organization" => $Organization,
        "GroupName" => $GroupName
    );
 
    if ($opType == "del") {
        if (!DBOper\Remove("GMTPermissionGroup", $find)) {
            $alertMsg = \Lang\gettext("删除失败");
            \Logging\LogError("删除失败" . print_r($find, true));
            return false;
        }
        $alertMsg = \Lang\gettext("删除成功");
        \Logging\LogInfo("删除成功" . print_r($find, true));
        return true;
    }
 
    $Permissions = array();
    $PermissionModules = \User\GetPermissionModules();
    foreach ($PermissionModules as $mInfo) {
        $ModuleID = $mInfo["ModuleID"];
        foreach (array_keys($mInfo["PList"]) as $pName) {
            $key = "P_" . $ModuleID . "_" . $pName;
            if (!array_key_exists($key, $_POST) || $_POST[$key] != "on") {
                continue;
            }
            if (!$user->HavePermission($pName, false)) {
                continue;
            }
            array_push($Permissions, $pName);
        }
    }
 
    $editArray = array(
        "Organization" => $Organization,
        "GroupName" => $GroupName,
        "Permissions" => $Permissions
    );
 
    // 添加
    if ($opType == "add") {
        DBOper\FindOne("GMTPermissionGroup", $find, $findPer);
        if (count($findPer) > 0) {
            $alertMsg = \Lang\gettext("该分组已存在");
            return false;
        }
        if (!DBOper\Insert("GMTPermissionGroup", $editArray)) {
            $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("GMTPermissionGroup", $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.pergroup.php");
$Permission = \User\Permission::P_PermissionGroup;
 
$alertMsg = "";
$channel = $_SESSION['spid'];
$UserAccount = $_SESSION['UserAccount'];
$user = new \User\User($UserAccount);
if (!$user->HavePermission($Permission)) {
    exit;
}
 
$userOrganization = $user->GetAttr("Organization");
$Organization = $userOrganization;
if (array_key_exists("Organization", $_GET)) {
    $Organization = $_GET["Organization"];
}
if (array_key_exists("Organization", $_POST)) {
    $Organization = $_POST["Organization"];
}
if ($Organization != $userOrganization) {
    if (!$user->IsAdminSuper()) {
        echo \Lang\gettext("您没有该权限");
        exit;
    }
}
 
if ($_POST["opType"]) {
    PergroupEdit($_POST["opType"]);
}
 
$PermissionAll = \User\GetPermissionAll();
// echo print_r($PermissionAll, true), "<br/>";
\DBOper\Find("GMTPermissionGroup", array("Organization" => $Organization), $OrganizationPGroups);
 
//显示表格字段配置 key-参数名,value-说明
$tableArray = array(
    "GroupName" => array(\Lang\gettext("权限分组名"), "10%", "center"),
    "Permissions" => array(\Lang\gettext("权限列表"), "80%", "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='pergroupedit.php?opType=add&Organization=<?php echo $Organization; ?>'" />
    <hr />
    <table width="100%">
        <?php
        if ($OrganizationPGroups) {
            echo "<thead><tr>";
            foreach ($tableArray as $value) {
                echo "<th width=\"" . $value[1] . "\">" . $value[0] . "</td>";
            }
            echo "</tr></thead>";
            foreach ($OrganizationPGroups as $groupData) {
                echo "<tr class='trc'>";
                $GroupName = $groupData["GroupName"];
                if ($GroupName == \User\Permission::GroupAdmin && !$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='pergroupedit.php?opType=upd&Organization=$Organization&GroupName=$GroupName'\" />";
                        echo " <input type=\"button\" value=\"" . \Lang\gettext("删") . "\" onclick=\"return suredel('$Organization','$GroupName')\"/>&nbsp;";
                        echo "</td>";
                        continue;
                    }
                    $tdContent = $groupData[$key];
                    if ($key == "Permissions") {
                        $tdc = "";
                        foreach ($tdContent as $pName) {
                            if (!array_key_exists($pName, $PermissionAll)) {
                                continue;
                            }
                            if ($tdc) {
                                $tdc .= "、";
                            }
                            $tdc .= $PermissionAll[$pName]["Name"];
                        }
                        $tdContent = $tdc;
                    }
                    echo "<td align='" . $value[2] . "'>" . $tdContent . "</td>";
                }
                echo "</tr>";
            }
        } else {
            if ($user->IsAdminSuper()) {
                echo "*您是超级管理员,默认拥有所有权限,可管理所有组织的账号及权限!<br/>";
                echo "*每个项目可以有多个appID、可由多个组织同时管理,比如研发方、运营方A、运营方B等;<br/>";
                echo "*超级管理员可为每个组织分配不同的权限(即管理员权限,仅超级管理员可编辑,其他账号均不可见);<br/>";
                echo "*每个组织可以创建多个管理员、默认拥有该组织的所有权限及管理该组织下的所有账号及权限;<br/>";
                echo "*各组织相互独立,互不影响,由各自的管理员管理;超级管理员管理所有组织;<br/>";
                echo "<hr/>";
                echo "*该组织还未分配管理员权限,请先分配管理员限权(默认分组名 " . \User\Permission::GroupAdmin . ")<br/>";
                echo "<input type=\"button\" value=\"分配组织管理员权限\" onclick=\"window.location.href='pergroupedit.php?opType=add&Organization=" . $Organization . "'\" />";
            } else {
                echo \Lang\gettext("请添加权限分组"), "<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) {
            window.location.href = 'pergroup.php?Organization=' + Organization;
        }
 
        function suredel(Organization, GroupName) {
            var confirmstr = "<?php echo \Lang\gettext("确定删除权限分组:"); ?>";
            if (!window.confirm(confirmstr + GroupName)) {
                return false;
            }
            doPost("pergroup.php", {
                "opType": "del",
                "Organization": Organization,
                "GroupName": GroupName,
            });
            return true;
        }
    </script>
</body>
 
</html>