| <?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 " <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')\"/> "; | 
|                         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> |