Private intErrId
Private strReason

Public Sub main()
    If Request.ServerVariables("REQUEST_METHOD") = "POST" Then
        Call doPost
    Else
        Call doGet
    End If
End Sub

Private Sub doGet()
    Echo "<html>"
    Echo "<head>"
    Echo "<meta http-equiv=""cache-control"" content=""no-cache"" />"
    Echo "<meta http-equiv=""cache-control"" content=""max-age=0"" />"
    Echo "<meta http-equiv=""content-type"" content=""text/html; charset=gb2312"" />"
    Echo "<title>" & MyKernel.Env("ProVName") & " - Ա¼</title>"
    Echo "<link rel=""stylesheet"" href=""images/xw.css"" />"
    Echo "<script language=""javascript"" src=""jspp/jspp.js""></script>"
    Echo "<script language=""javascript"">"
    Echo "<!--"
    Echo "if (top != self)"
    Echo "{"
    Echo "    top.location = location.href;"
    Echo "}"
    Echo "else"
    Echo "{"
    Echo "    jspp.Caption = """ & MyKernel.Env("ProName") & """;"
    Echo "    _import(""mocom.WAPmo.Kernel"");"
    Echo "}"
    Echo "-->"
    Echo "</script>"
    Echo "</head>"
    Echo "<body class=""system"">"
    Echo "<form action=""admin_login.asp"" method=""post"" onsubmit=""return(false)"">"
    Echo "<table border=""0"" cellpadding=""0"" cellspacing=""0"" style=""width:100%;height:100%"">"
    Echo "    <tr>"
    Echo "        <td align=""center"" valign=""middle"">"
    Echo "            <table width=""300"" border=""1"" cellpadding=""2"" cellspacing=""0"" bordercolor=""#000000"" style=""border-collapse:collapse"">"
    Echo "                <tr>"
    Echo "                    <td class=""winT0"" colspan=""2""><b>" & MyKernel.Env("ProVName") & " Ա¼</b></td>"
    Echo "                </tr>"
    Echo "                <tr class=""winT1"">"
    Echo "                    <td width=""100"" align=""right"">ʡ</td>"
    Echo "                    <td width=""200""><input type=""text"" name=""UserId"" class=""txt"" /></td>"
    Echo "                </tr>"
    Echo "                <tr class=""winT1"">"
    Echo "                    <td align=""right"">ܡ</td>"
    Echo "                    <td><input type=""password"" name=""Passwd"" class=""txt"" /></td>"
    Echo "                </tr>"
    Echo "                <tr class=""winT1"">"
    Echo "                    <td align=""right"">֤</td>"
    Echo "                    <td><input type=""text"" name=""Code"" class=""txt"" size=""5"" maxlength=""5"" /> <img src=""code.asp"" border=""0"" valign=""absBottom"" /></td>"
    Echo "                </tr>"
    Echo "                <tr class=""winT1"">"
    Echo "                    <td colspan=""2"" align=""center""><input type=""button"" value=""ȷ  "" class=""btn"" onclick=""Form.submit(this)"" /></td>"
    Echo "                </tr>"
    Echo "            </table>"
    Echo "        </td>"
    Echo "    </tr>"
    Echo "</table>"
    Echo "</form>"
    Echo "</body>"
    Echo "</html>"
End Sub

Private Sub doPost()
    Dim strName, strPass
    Dim strCode
    strName = Trim(Request.Form("UserId"))
    strPass = Trim(Request.Form("Passwd"))
    strCode = Trim(Request.Form("Code"))
    If strName = "" Then
        intErrId = 1
        strReason = "Աʺ"
    ElseIf strPass = "" Then
        intErrId = 2
        strReason = "Ա"
    ElseIf strCode = "" Then
        intErrId = 3
        strReason = "֤"
    ElseIf strCode <> Session.Contents("Code") Then
        intErrId = 4
        strReason = "֤"
    ElseIf MyAdmin.Exec("*", "Name='" & SafeString(strName) & "'") = False Then
        intErrId = 5
        strReason = "ʺŻ"
    ElseIf MyAdmin.Item("Passwd") <> MD5(strPass) Then
        intErrId = 6
        strReason = "ʺŻ"
    ElseIf MyAdmin.Item("Forbid") = 1 Then
        intErrId = 7
        strReason = "ʺѱԱ"
    Else
        intErrId = 100
        strReason = "¼ɹ"
        Dim strSQL
        Dim lngTime
        lngTime = getTime(Now())
        strSQL = "UPDATE $(Table) SET LoginCount=LoginCount+1,Outime=$(Timeval) WHERE SeqId=$(SeqId)"
        strSQL = Replace(strSQL, "$(Table)", T_ADMIN)
        strSQL = Replace(strSQL, "$(SeqId)", MyAdmin.Item("SeqId"))
        strSQL = Replace(strSQL, "$(Timeval)", lngTime)
        SafeExecute strSQL
        Dim objMem
        Set objMem = MyKernel.Memory
        objMem("WM_Admin_Name") = strName
        objMem("WM_Admin_Pass") = strPass
        objMem("WM_Admin_Time") = lngTime
        objMem("WM_Admin_Power") = getRecord(getLimitSQL(1, "Power", T_ADMIN_GROUP, "SeqId=" & MyAdmin.Item("GroupId"), "", ""))
        Set objMem = Nothing
    End If
    Echo "<html>"
    Echo "<head>"
    Echo "<meta http-equiv=""cache-control"" content=""no-cache"" />"
    Echo "<meta http-equiv=""cache-control"" content=""max-age=0"" />"
    Echo "<meta http-equiv=""content-type"" content=""text/html; charset=gb2312"" />"
    If intErrId = 100 Then
        Echo "<meta http-equiv=""refresh"" content=""1;url=admin.asp"" />"
    End If
    Echo "<title>" & MyKernel.Env("ProVName") & " - Ա¼</title>"
    Echo "<link rel=""stylesheet"" href=""images/xw.css"" />"
    Echo "</head>"
    Echo "<body class=""system"">"
    Echo "<table border=""0"" cellpadding=""0"" cellspacing=""0"" style=""width:100%;height:100%"">"
    Echo "    <tr>"
    Echo "        <td align=""center"" valign=""middle"">"
    Echo "            <table width=""300"" border=""1"" cellpadding=""2"" cellspacing=""0"" bordercolor=""#000000"" style=""border-collapse:collapse"">"
    Echo "                <tr>"
    Echo "                    <td class=""winT0""><b>" & MyKernel.Env("ProVName") & " Ա¼</b></td>"
    Echo "                </tr>"
    If intErrId = 100 Then
        Echo "                <tr class=""winT1"">"
        Echo "                    <td align=""center"">"
        Echo "                        <font color=""#0000FF"">" & strReason & "</font><br/>"
        Echo "                        ֧ض<a href=""admin.asp"" target=""_top"">˽</a>"
        Echo "                    </td>"
        Echo "                </tr>"
    Else
        Echo "                <tr class=""winT1"">"
        Echo "                    <td align=""center""><font color=""#FF0000"">¼ʧܣ" & strReason & "</font></td>"
        Echo "                </tr>"
        Echo "                <tr class=""winT1"">"
        Echo "                    <td align=""center""><input type=""button"" value=""  "" class=""btn"" onclick=""location.replace('admin_login.asp')"" /></td>"
        Echo "                </tr>"
    End If
    Echo "            </table>"
    Echo "        </td>"
    Echo "    </tr>"
    Echo "</table>"
    Echo "</body>"
    Echo "</html>"
End Sub
