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
<?php
include_once "/Common/Logging.php";
include_once "/Account/User.php";
include_once "/db/DBOper.php";
include_once "/language/lang.php";
 
\Logging\CreateLogging("account.pergroupedit.php");
$Permission = \User\Permission::P_PermissionGroup;
 
$UserAccount = $_SESSION['UserAccount'];
$user = new \User\User($UserAccount);
if (!$user->HavePermission($Permission)) {
    exit;
}
 
$opType = $_GET["opType"];
$Organization = $_GET["Organization"];
$GroupName = $_GET["GroupName"];
if ($GroupName == \User\Permission::GroupAdmin && !$user->IsAdminSuper()) {
    exit;
}
 
$editInfo = array();
$pageTitle = \Lang\gettext("权限分组添加");
if ($opType == "upd") {
    $pageTitle = \Lang\gettext("权限分组修改");
    \DBOper\FindOne("GMTPermissionGroup", array("Organization" => $Organization, "GroupName" => $GroupName), $editInfo);
} else {
    \DBOper\FindOne("GMTPermissionGroup", array("Organization" => $Organization, "GroupName" => \User\Permission::GroupAdmin), $adminPInfo);
    $editInfo = $_GET;
    if (!$adminPInfo) {
        $GroupName = \User\Permission::GroupAdmin;
        $editInfo["GroupName"] = \User\Permission::GroupAdmin;
    }
}
 
$PermissionModules = \User\GetPermissionModules();
$ModuleIDs = array();
// echo "_GET:" . print_r($_GET, true), "<br/>";
// echo "editInfo:" . var_dump($editInfo), "<br/>";
// echo "GetUserPermissions:" . json_encode($user->GetUserPermissions()), "<br/>";
 
?>
 
<html>
 
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title><?php echo $pageTitle; ?></title>
    <link rel="stylesheet" type="text/css" href="/css/tableform.css">
</head>
 
<body>
    <center>
        <p><b><?php echo $pageTitle; ?></b></P>
    </center>
    <hr />
 
    <form action="pergroup.php" method="post">
        <table id="tt" class="formTable">
            <tr>
                <td class="formTableTDName"><?php echo \Lang\gettext("所属组织"); ?>: </td>
                <td class="formTableTDValue">
                    <?php
                    echo "<input type=\"text\" name=\"Organization\" id=\"Organization\" value=\"" . $Organization . "\" readonly/>";
                    ?>
                </td>
            </tr>
            <tr>
                <td class="formTableTDName"><?php echo \Lang\gettext("权限分组名"); ?>: </td>
                <td class="formTableTDValue">
                    <input type="text" name="GroupName" id="GroupName" value="<?php echo array_key_exists("GroupName", $editInfo)  ? $editInfo["GroupName"] : "" ?>" placeholder="" <?php echo ($opType == "upd" || $GroupName == \User\Permission::GroupAdmin) ? "readonly" : "" ?> />
                    <?php
                    if ($GroupName == \User\Permission::GroupAdmin) {
                        echo " <font color='red'>*该组为组织管理员权限,编辑修改时该组织所有管理员权限同时生效,其他成员权限向下兼容.</font>";
                    }
                    ?>
                </td>
            </tr>
            <tr>
            </tr>
            <tr>
                <td class="formTableTDName" style="text-align: center;"><b><?php echo \Lang\gettext("模块"); ?></b></td>
                <td class="formTableTDValue" style="text-align: center;"><b><?php echo \Lang\gettext("权限列表"); ?></b></td>
            </tr>
            <?php
            $Permissions = array_key_exists("Permissions", $editInfo) ? $editInfo["Permissions"] : array();
            foreach ($PermissionModules as $mInfo) {
                $has = false;
                $ModuleID = $mInfo["ModuleID"];
                $PList = $mInfo["PList"];
                foreach ($PList as $pName => $pInfo) {
                    if ($user->HavePermission($pName, false)) {
                        $has = true;
                        break;
                    }
                }
                if (!$has) {
                    continue;
                }
                array_push($ModuleIDs, $ModuleID);
                echo "<tr>";
                echo "<td class=\"formTableTDName\">" . $mInfo["Name"];
                echo "<input type=\"checkbox\" id=\"PMAll_" . $ModuleID . "\" onclick=\"checkPMALL('" . $ModuleID . "', this.checked)\" />";
                echo ": </td>";
                echo "<td class=\"formTableTDValue\">";
 
                echo "<table>";
                $i = 0;
                $lineCount = 5;
                foreach ($PList as $pName => $pInfo) {
                    if (!$user->HavePermission($pName, false)) {
                        continue;
                    }
                    if ($i % $lineCount  == 0) {
                        echo "<tr>";
                    }
                    echo "<td width='220'>";
                    echo "<input type=\"checkbox\" class=\"P_" . $ModuleID . "\" name=\"P_" . $ModuleID . "_" . $pName . "\"";
                    if (in_array($pName, $Permissions)) {
                        echo " checked";
                    }
                    echo "/>" . "<span title=\"" . $pInfo["Title"] . "\">" . $pInfo["Name"] . "</span>";
                    echo "&nbsp;&nbsp;";
                    echo "</td>";
                    if ($i % $lineCount  == $lineCount - 1) {
                        echo "</tr>";
                    }
                    $i += 1;
                }
                echo "</table>";
 
                echo "</td>";
                echo "</tr>";
            }
            ?>
            <tr></tr>
            <tr>
                <td class="formTableTDName">
                    <?php echo \Lang\gettext("全选"); ?><input type="checkbox" onclick="checkPALL(this.checked)" />
                </td>
                <td class="formTableTDValue">
                    <input type="submit" name="submit" align="center" value="<?php echo \Lang\gettext("提交"); ?>" onclick="return CheckSubmit()" />
                </td>
            </tr>
            <input type="hidden" name="opType" id="opType" value="<?php echo $opType ?>" />
        </table>
    </form>
 
    <script type="text/javascript">
        function checkPALL(checked) {
            var ModuleIDs = <?php echo json_encode($ModuleIDs); ?>;
            for (let index = 0; index < ModuleIDs.length; index++) {
                checkPMALL(ModuleIDs[index], checked);
            }
        }
 
        function checkPMALL(ModuleID, checked) {
            document.getElementById("PMAll_" + ModuleID).checked = checked;
            var items = document.getElementsByClassName("P_" + ModuleID);
            //循环设置所有复选框状态
            for (var i = 0; i < items.length; i++) {
                items[i].checked = checked;
            }
        }
 
        function CheckSubmit() {
            if (!document.getElementById("GroupName").value) {
                alert("<?php echo \Lang\gettext("权限分组名不能为空"); ?>");
                document.getElementById('GroupName').focus();
                return false;
            }
            return true;
        }
    </script>
</body>
 
</html>