| <?php | 
| include_once "/Common/Logging.php"; | 
| include_once "/Account/User.php"; | 
| include_once "/db/DBOper.php"; | 
| include_once "/language/lang.php"; | 
|   | 
| function CreateSuperAdmin() | 
| { | 
|     global $msg; | 
|   | 
|     $UserAccount = $_POST["UserAccount"]; | 
|     $Psw = $_POST["Psw"]; | 
|     $PswConfirm = $_POST["PswConfirm"]; | 
|   | 
|     if (!$UserAccount || !$Psw) { | 
|         $msg = "账号密码不能为空!"; | 
|         \Logging\LogError($msg); | 
|         return; | 
|     } | 
|   | 
|     if ($Psw != $PswConfirm) { | 
|         $msg = "账号密码不一致!"; | 
|         \Logging\LogError($msg); | 
|         return; | 
|     } | 
|   | 
|     if (!\DBOper\FindOne("GMTUser", array("UserLV" => \User\UserLV::ADMIN_SUPER), $userData)) { | 
|         $msg = "数据异常!"; | 
|         \Logging\LogError($msg); | 
|         return; | 
|     } | 
|   | 
|     if (isset($userData)) { | 
|         $msg = "已经存在超级管理员账号,不能重复创建!"; | 
|         \Logging\LogError($msg); | 
|         return true; | 
|     } | 
|   | 
|     $Psw = \Commfunc\GetEncodePsw($Psw); | 
|     if (!$Psw) { | 
|         $msg = "密码异常!"; | 
|         \Logging\LogError($msg); | 
|         return; | 
|     } | 
|   | 
|     $OrganizationList = \CommFunc\GetAllOrganization(); | 
|     if (!isset($OrganizationList) || count($OrganizationList) < 0) { | 
|         $msg = "没有配置组织!"; | 
|         \Logging\LogError($msg); | 
|         return; | 
|     } | 
|   | 
|     if (!\DBOper\Insert("GMTUser", array( | 
|         "UserAccount" => $UserAccount, | 
|         "Psw" => $Psw, | 
|         "UserLV" => \User\UserLV::ADMIN_SUPER, | 
|         "Organization" => $OrganizationList[0], #超管默认属于第一个组织 | 
|         "CreateTime" => date("Y-m-d H:i:s") | 
|     ))) { | 
|         $msg = "创建失败!"; | 
|         \Logging\LogError($msg); | 
|         return; | 
|     } | 
|   | 
|     \Logging\LogInfo("创建成功!" . $UserAccount); | 
|     return 1; | 
| } | 
|   | 
| \Logging\CreateLogging("account.super.php"); | 
| \Logging\LogInfo("_POST: " . print_r($_POST, true)); | 
|   | 
| $msg = ""; | 
| $ok = 0; | 
| if (array_key_exists('UserAccount', $_POST)) { | 
|     $ok = CreateSuperAdmin(); | 
| } else { | 
|     if (\DBOper\FindOne("GMTUser", array("UserLV" => \User\UserLV::ADMIN_SUPER), $userData) && isset($userData)) { | 
|         $ok = 2; | 
|         $msg = "已经存在超级管理员账号,不用创建!"; | 
|         \Logging\LogError($msg); | 
|     } | 
| } | 
|   | 
| if ($msg) { | 
|     echo "<script>alert('" . $msg . "')</script>"; | 
| } | 
|   | 
| // echo $ok; | 
| if ($ok > 0) { | 
|     header("Location:/Account/login.php?superok=" . $ok); | 
|     exit; | 
| } | 
|   | 
| ?> | 
|   | 
| <html> | 
|   | 
| <head> | 
|     <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> | 
|     <title>GM工具</title> | 
|     <link rel="stylesheet" type="text/css" href="/css/tableform.css"> | 
| </head> | 
|   | 
| <body> | 
|     <div class="divForm"> | 
|         <form id="super" name="super" action="super.php" method="post"> | 
|             <table id="tt" class="formTable"> | 
|                 <caption> | 
|                     <b>请先创建超级管理员</b><br /><br /> | 
|                 </caption> | 
|                 <tr> | 
|                     <td class="formTableTDName">超级管理员账号: </td> | 
|                     <td class="formTableTDValue"> | 
|                         <input type="text" id="UserAccount" name="UserAccount" value="" placeholder="至少3个字符" /> | 
|                     </td> | 
|                 </tr> | 
|                 <tr> | 
|                     <td class="formTableTDName">密码: </td> | 
|                     <td class="formTableTDValue"> | 
|                         <input type="password" id="Psw" name="Psw" value="" placeholder="" /> | 
|                     </td> | 
|                 </tr> | 
|                 <tr> | 
|                     <td class="formTableTDName">重复输入密码: </td> | 
|                     <td class="formTableTDValue"> | 
|                         <input type="password" id="PswConfirm" name="PswConfirm" value="" placeholder="" /> | 
|                     </td> | 
|                 </tr> | 
|                 <tr> | 
|                     <td class="formTableTDName"></td> | 
|                     <td class="formTableTDValue"> | 
|                         <input type="submit" name="submit" value="提交" onclick="return CheckSubmit();" /> | 
|                     </td> | 
|                 </tr> | 
|             </table> | 
|         </form> | 
|     </div> | 
|   | 
|     <script type="text/javascript"> | 
|         function CheckSubmit() { | 
|             if (!document.getElementById("UserAccount").value || document.getElementById("UserAccount").value.length < 3) { | 
|                 alert("账号不符合要求!"); | 
|                 document.getElementById('UserAccount').focus(); | 
|                 return false; | 
|             } | 
|             if (!document.getElementById("Psw").value) { | 
|                 alert("密码不能为空!"); | 
|                 document.getElementById('Psw').focus(); | 
|                 return false; | 
|             } | 
|             if (!document.getElementById("PswConfirm").value) { | 
|                 alert("密码不能为空!"); | 
|                 document.getElementById('PswConfirm').focus(); | 
|                 return false; | 
|             } | 
|             if (document.getElementById("Psw").value != document.getElementById("PswConfirm").value) { | 
|                 alert("密码不一致!"); | 
|                 document.getElementById('PswConfirm').focus(); | 
|                 return false; | 
|             } | 
|             return true; | 
|         } | 
|     </script> | 
| </body> | 
|   | 
| <style type="text/css"> | 
|     .divForm { | 
|         position: absolute; | 
|         width: 400px; | 
|         height: 300px; | 
|         text-align: center; | 
|         top: 50%; | 
|         left: 50%; | 
|         /* width heigh 一半 */ | 
|         margin-left: -200px; | 
|         margin-top: -150px; | 
|     } | 
| </style> | 
|   | 
| </html> |