<%
Response.Buffer = EW_RESPONSE_BUFFER
%>
<!--#include file="ewcfg11.asp"-->
<!--#include file="aspfn11.asp"-->
<!--#include file="zlogininfo.asp"-->
<!--#include file="md5.asp"-->
<!--#include file="userfn11.asp"-->
<% Session.Timeout = 900 %>
<% Call ew_Header(False, EW_CHARSET) %>
<%

' Define page object
Dim login
Set login = New clogin
Set Page = login

' Page init processing
login.Page_Init()

' Page main processing
login.Page_Main()

' Global Page Rendering event (in userfn*.asp)
Page_Rendering()

' Page Rendering event
login.Page_Render()
%>
<!DOCTYPE html>
<html>
<head>
	<title><%= Language.ProjectPhrase("BodyTitle") %></title>
<% If gsExport = "" Or gsExport = "print" Then %>
<link rel="stylesheet" type="text/css" href="bootstrap/css/bootstrap.css">
<% End If %>
<% If gsExport = "" Then %>
<link rel="stylesheet" type="text/css" href="css/jquery.fileupload-ui.css">
<% End If %>
<% If gsExport = "" Or gsExport = "print" Then %>
<link rel="stylesheet" type="text/css" href="<%= EW_PROJECT_STYLESHEET_FILENAME %>">
<% If ew_IsMobile() Then %>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" type="text/css" href="css/ewmobile.css">
<% End If %>
<% If gsExport = "print" And Request.QueryString("pdf") = "1" And EW_PDF_STYLESHEET_FILENAME <> "" Then ' ??? %>
<link rel="stylesheet" type="text/css" href="<%= EW_PDF_STYLESHEET_FILENAME %>">
<% End If %>
<script type="text/javascript" src="<%= ew_jQueryFile("jquery-%v.min.js") %>"></script>
<% If ew_IsMobile() Then %>
<link rel="stylesheet" type="text/css" href="<%= ew_jQueryFile("jquery.mobile-%v.min.css") %>">
<script type="text/javascript">
jQuery(document).bind("mobileinit", function() {
	jQuery.mobile.ajaxEnabled = false;
	jQuery.mobile.ignoreContentEnabled = true;
});
</script>

<script type="text/javascript" src="<%= ew_jQueryFile("jquery.mobile-%v.min.js") %>"></script>
<% End If %>
<% End If %>
<% If gsExport = "" Then %>
<script type="text/javascript" src="bootstrap/js/bootstrap.min.js"></script>
<script type="text/javascript" src="jqueryfileupload/jquery.ui.widget.js"></script>
<script type="text/javascript" src="jqueryfileupload/jqueryfileupload.min.js"></script>
<link href="calendar/calendar.css" rel="stylesheet" type="text/css">
<script type="text/javascript" src="calendar/calendar.min.js"></script>
<script type="text/javascript" src="calendar/lang/calendar-en.js"></script>
<script type="text/javascript" src="calendar/calendar-setup.js"></script>
<script type="text/javascript" src="js/ewcalendar.js"></script>
<script type="text/javascript" src="ckeditor/ckeditor.js"></script>
<script type="text/javascript" src="js/eweditor.js"></script>

<script type="text/javascript">
var EW_LANGUAGE_ID = "<%= gsLanguage %>";
var EW_DATE_SEPARATOR = "-" || "/"; // Default date separator
var EW_DECIMAL_POINT = "<%= EW_DECIMAL_POINT %>";
var EW_THOUSANDS_SEP = "<%= EW_THOUSANDS_SEP %>";
var EW_MAX_FILE_SIZE = <%= EW_MAX_FILE_SIZE %>; // Upload max file size
var EW_UPLOAD_ALLOWED_FILE_EXT = "<%= EW_UPLOAD_ALLOWED_FILE_EXT %>"; // Allowed upload file extension
var EW_FIELD_SEP = ", "; // Default field separator
// Ajax settings
var EW_LOOKUP_FILE_NAME = "ewlookup11.asp"; // Lookup file name
var EW_AUTO_SUGGEST_MAX_ENTRIES = <%= EW_AUTO_SUGGEST_MAX_ENTRIES %>; // Auto-Suggest max entries
// Common JavaScript messages
var EW_DISABLE_BUTTON_ON_SUBMIT = true;
var EW_IMAGE_FOLDER = "images/"; // Image folder
var EW_UPLOAD_URL = "<%= EW_UPLOAD_URL %>"; // Upload url
var EW_UPLOAD_THUMBNAIL_WIDTH = <%= EW_UPLOAD_THUMBNAIL_WIDTH %>; // Upload thumbnail width
var EW_UPLOAD_THUMBNAIL_HEIGHT = <%= EW_UPLOAD_THUMBNAIL_HEIGHT %>; // Upload thumbnail height
var EW_USE_JAVASCRIPT_MESSAGE = false;
<% If ew_IsMobile() Then %>
var EW_IS_MOBILE = true;
<% Else %>
var EW_IS_MOBILE = false;
<% End If %>
<% If EW_MOBILE_REFLOW Then %>
var EW_MOBILE_REFLOW = true;
<% Else %>
var EW_MOBILE_REFLOW = false;
<% End If %>
</script>
<% End If %>
<% If gsExport = "" Or gsExport = "print" Then %>
<script type="text/javascript" src="js/jsrender.min.js"></script>
<script type="text/javascript" src="js/ew11.js"></script>
<script type="text/javascript" src="js/ewvalidator.js"></script>
<% End If %>
<% If gsExport = "" Then %>
<script type="text/javascript" src="js/userfn11.js"></script>
<script type="text/javascript">
<%= Language.ToJSON() %>
</script>
<script type="text/javascript">
// Write your client script here, no need to add script tags.
</script>
<% End If %>
<meta name="generator" content="ASPMaker v11.0.3">
<style type="text/css">
body {
	background-image: url(images/bj.jpg);
	background-repeat: repeat-x;

}
a:link {
	text-decoration: none;
}
a:visited {
	text-decoration: none;
}
a:hover {
	text-decoration: none;
}
a:active {
	text-decoration: none;
}
</style>
</head>
<body>
<% If gsExport = "" Or gsExport = "print" Then %>
<% If ew_IsMobile() Then %>
<div data-role="page">
	<div data-role="header">
		<a href="mobilemenu.asp"><%= Language.Phrase("MobileMenu") %></a>
		<h1 id="ewPageTitle"></h1>
	<% If IsLoggedIn() Then %>
		<a href="logout.asp"><%= Language.Phrase("Logout") %></a>
	<% ElseIf Right(Request.ServerVariables("URL"), Len("login.asp")) <> "login.asp" Then %>
		<a href="login.asp"><%= Language.Phrase("Login") %></a>
	<% End If %>
	</div>
<% End If %>
<% End If %>


<script type="text/javascript">
// Write your client script here, no need to add script tags.
</script>
<script type="text/javascript">
var flogin = new ew_Form("flogin");
// Validate function
flogin.Validate = function()
{
	var fobj = this.Form;
	if (!this.ValidateRequired)
		return true; // Ignore validation
	if (!ew_HasValue(fobj.username))
		return this.OnError(fobj.username, ewLanguage.Phrase("EnterUid"));
	if (!ew_HasValue(fobj.password))
		return this.OnError(fobj.password, ewLanguage.Phrase("EnterPwd"));
	// Call Form Custom Validate event
	if (!this.Form_CustomValidate(fobj)) return false;
	return true;
}
// Form_CustomValidate function
flogin.Form_CustomValidate = 
 function(fobj) { // DO NOT CHANGE THIS LINE!
 	// Your custom validation code here, return false if invalid. 
 	return true;
 }
// Requires js validation

</script>


<table width="566" border="0" align="center" cellpadding="0" cellspacing="0"  style="background:url(images/1.jpg) no-repeat;margin-top:192px;" height="316">
  <tr>
    <td height="99" valign="top">&nbsp;</td>
    <td align="center">&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td width="116" height="217" valign="top"><br></td>
    <td width="77" align="center">&nbsp;</td>
    <td width="373" valign="top"><form name="flogin" id="flogin" class="ewForm form-horizontal" action="<%= ew_CurrentPage %>" method="post">
    <input type="hidden" value="a" name="rememberme" id="rememberme">
      <table border="0" cellpadding="4" cellspacing="0">
        <tr>
          <td><span class="aspmaker">ÓÃ»§Ãû</span></td>
          <td><span class="aspmaker">
          <input type="text" name="username" id="username" class="input-large" value="<%= ew_HtmlEncode(login.Username) %>" placeholder="<%= ew_HtmlEncode(Language.Phrase("Username")) %>"  style="width:150px; height:18px; border:1px solid #CCC">
           
          </span></td>
        </tr>
        <tr>
          <td height="35"><span class="aspmaker">ÃÜÂë</span></td>
          <td><span class="aspmaker">
          <input type="password" name="password" id="password" class="input-large" placeholder="<%= ew_HtmlEncode(Language.Phrase("Password")) %>"  style="width:150px; height:18px; border:1px solid #CCC">
        
          </span></td>
        </tr>
       
        <tr>
          <td height="30" colspan="2" align="center"><span class="aspmaker">
            <input type="submit" name="submit" id="submit" value="    µÇÂ¼    "></td>
          </tr>
        <tr>
          <td colspan="2" align="center" valign="top" style="color:#666">&nbsp;</td>
        </tr>
      </table>
      <span class="aspmaker">
      <% login.ShowMessage %>
      </span>
    </form></td>
  </tr>
</table>
<br>
<script type="text/javascript">
flogin.Init();
<% If EW_MOBILE_REFLOW And ew_IsMobile() Then %>
ew_Reflow();
<% End If %>
</script>
<%
login.ShowPageFooter()
If EW_DEBUG_ENABLED Then Response.Write ew_DebugMsg()
%>
<script type="text/javascript">
// Write your startup script here
// document.write("page loaded");
</script>

<%

' Drop page object
Set login = Nothing
%>
<%

' -----------------------------------------------------------------
' Page Class
'
Class clogin

	' Page ID
	Public Property Get PageID()
		PageID = "login"
	End Property

	' Project ID
	Public Property Get ProjectID()
		ProjectID = "{A697AD8C-67CB-4820-BF4F-84306CDBBEE7}"
	End Property

	' Page Object Name
	Public Property Get PageObjName()
		PageObjName = "login"
	End Property

	' Page Name
	Public Property Get PageName()
		PageName = ew_CurrentPage()
	End Property

	' Page Url
	Public Property Get PageUrl()
		PageUrl = ew_CurrentPage() & "?"
	End Property

	' Message
	Public Property Get Message()
		Message = Session(EW_SESSION_MESSAGE)
	End Property

	Public Property Let Message(v)
		Dim msg
		msg = Session(EW_SESSION_MESSAGE)
		Call ew_AddMessage(msg, v)
		Session(EW_SESSION_MESSAGE) = msg
	End Property

	Public Property Get FailureMessage()
		FailureMessage = Session(EW_SESSION_FAILURE_MESSAGE)
	End Property

	Public Property Let FailureMessage(v)
		Dim msg
		msg = Session(EW_SESSION_FAILURE_MESSAGE)
		Call ew_AddMessage(msg, v)
		Session(EW_SESSION_FAILURE_MESSAGE) = msg
	End Property

	Public Property Get SuccessMessage()
		SuccessMessage = Session(EW_SESSION_SUCCESS_MESSAGE)
	End Property

	Public Property Let SuccessMessage(v)
		Dim msg
		msg = Session(EW_SESSION_SUCCESS_MESSAGE)
		Call ew_AddMessage(msg, v)
		Session(EW_SESSION_SUCCESS_MESSAGE) = msg
	End Property

	Public Property Get WarningMessage()
		WarningMessage = Session(EW_SESSION_WARNING_MESSAGE)
	End Property

	Public Property Let WarningMessage(v)
		Dim msg
		msg = Session(EW_SESSION_WARNING_MESSAGE)
		Call ew_AddMessage(msg, v)
		Session(EW_SESSION_WARNING_MESSAGE) = msg
	End Property

	' Show Message
	Public Sub ShowMessage()
		Dim hidden, html, sMessage
		hidden = False
		html = ""

		' Message
		sMessage = Message
		Call Message_Showing(sMessage, "")
		If sMessage <> "" Then ' Message in Session, display
			If Not hidden Then sMessage = "<button type=""button"" class=""close"" data-dismiss=""alert"">&times;</button>" & sMessage
			html = html & "<div class=""alert alert-success ewSuccess"">" & sMessage & "</div>"
			Session(EW_SESSION_MESSAGE) = "" ' Clear message in Session
		End If

		' Warning message
		Dim sWarningMessage
		sWarningMessage = WarningMessage
		Call Message_Showing(sWarningMessage, "warning")
		If sWarningMessage <> "" Then ' Message in Session, display
			If Not hidden Then sWarningMessage = "<button type=""button"" class=""close"" data-dismiss=""alert"">&times;</button>" & sWarningMessage
			html = html & "<div class=""alert alert-warning ewWarning"">" & sWarningMessage & "</div>"
			Session(EW_SESSION_WARNING_MESSAGE) = "" ' Clear message in Session
		End If

		' Success message
		Dim sSuccessMessage
		sSuccessMessage = SuccessMessage
		Call Message_Showing(sSuccessMessage, "success")
		If sSuccessMessage <> "" Then ' Message in Session, display
			If Not hidden Then sSuccessMessage = "<button type=""button"" class=""close"" data-dismiss=""alert"">&times;</button>" & sSuccessMessage
			html = html & "<div class=""alert alert-success ewSuccess"">" & sSuccessMessage & "</div>"
			Session(EW_SESSION_SUCCESS_MESSAGE) = "" ' Clear message in Session
		End If

		' Failure message
		Dim sErrorMessage
		sErrorMessage = FailureMessage
		Call Message_Showing(sErrorMessage, "failure")
		If sErrorMessage <> "" Then ' Message in Session, display
			If Not hidden Then sErrorMessage = "<button type=""button"" class=""close"" data-dismiss=""alert"">&times;</button>" & sErrorMessage
			html = html & "<div class=""alert alert-error ewError"">" & sErrorMessage & "</div>"
			Session(EW_SESSION_FAILURE_MESSAGE) = "" ' Clear message in Session
		End If
		Response.Write "<table class=""ewStdTable""><tr><td><div class=""ewMessageDialog""" & ew_IIf(hidden, " style=""display: none;""", "") & ">" & html & "</div></td></tr></table>"
	End Sub
	Dim PageHeader
	Dim PageFooter

	' Show Page Header
	Public Sub ShowPageHeader()
		Dim sHeader
		sHeader = PageHeader
		Call Page_DataRendering(sHeader)
		If sHeader <> "" Then ' Header exists, display
			Response.Write "<p>" & sHeader & "</p>"
		End If
	End Sub

	' Show Page Footer
	Public Sub ShowPageFooter()
		Dim sFooter
		sFooter = PageFooter
		Call Page_DataRendered(sFooter)
		If sFooter <> "" Then ' Footer exists, display
			Response.Write "<p>" & sFooter & "</p>"
		End If
	End Sub

	' -----------------------
	'  Validate Page request
	'
	Public Function IsPageRequest()
		IsPageRequest = True
	End Function

	' -----------------------------------------------------------------
	'  Class initialize
	'  - init objects
	'  - open ADO connection
	'
	Private Sub Class_Initialize()
		If IsEmpty(StartTimer) Then StartTimer = Timer ' Init start time

		' Initialize language object
		If IsEmpty(Language) Then
			Set Language = New cLanguage
			Call Language.LoadPhrases()
		End If

		' Initialize table object
		If IsEmpty(zlogin) Then Set zlogin = New czlogin

		' Initialize form object
		Set ObjForm = Nothing

		' Intialize page id (for backward compatibility)
		EW_PAGE_ID = "login"

		' Open connection to the database
		If IsEmpty(Conn) Then Call ew_Connect()
	End Sub

	' -----------------------------------------------------------------
	'  Subroutine Page_Init
	'  - called before page main
	'  - check Security
	'  - set up response header
	'  - call page load events
	'
	Sub Page_Init()
		Set Security = New cAdvancedSecurity

		' Global page loading event (in userfn7.asp)
		Page_Loading()

		' Page load event, used in current page
		Page_Load()
	End Sub

	' -----------------------------------------------------------------
	'  Class terminate
	'  - clean up page object
	'
	Private Sub Class_Terminate()
		Call Page_Terminate("")
	End Sub

	' -----------------------------------------------------------------
	'  Subroutine Page_Terminate
	'  - called when exit page
	'  - clean up ADO connection and objects
	'  - if url specified, redirect to url
	'
	Sub Page_Terminate(url)

		' Page unload event, used in current page
		Call Page_Unload()

		' Global page unloaded event (in userfn60.asp)
		Call Page_Unloaded()
		Dim sRedirectUrl
		sReDirectUrl = url
		Call Page_Redirecting(sReDirectUrl)
		If Not (Conn Is Nothing) Then Conn.Close ' Close Connection
		Set Conn = Nothing
		Set Security = Nothing
		Set ObjForm = Nothing

		' Go to url if specified
		If sReDirectUrl <> "" Then
			If Response.Buffer Then Response.Clear
			Response.Redirect sReDirectUrl
		End If
	End Sub

	'
	'  Subroutine Page_Terminate (End)
	' ----------------------------------------

	Dim Username
	Dim LoginType

	' -----------------------------------------------------------------
	' Page main processing
	'
	Sub Page_Main()
		Dim bValidate, bValidPwd
		Dim sPassword
		Dim sLastUrl
		Set Breadcrumb = New cBreadcrumb
		Call Breadcrumb.Add("login", "LoginPage", ew_CurrentUrl, "", True)
		sLastUrl = Security.LastUrl ' Get Last Url
		If sLastUrl = "" Then sLastUrl = "default.asp"
		If IsLoggingIn() Then
			Username = Session(EW_SESSION_USER_PROFILE_USER_NAME)
			sPassword = Session(EW_SESSION_USER_PROFILE_PASSWORD)
			LoginType = Session(EW_SESSION_USER_PROFILE_LOGIN_TYPE)
			bValidPwd = Security.ValidateUser(Username, sPassword, False)
			If bValidPwd Then
				Session(EW_SESSION_USER_PROFILE_USER_NAME) = ""
				Session(EW_SESSION_USER_PROFILE_PASSWORD) = ""
				Session(EW_SESSION_USER_PROFILE_LOGIN_TYPE) = ""
			End If
		Else
			If Not Security.IsLoggedIn() Then Call Security.AutoLogin()
			Call Security.LoadUserLevel() ' Load user level
			Username = "" ' Initialize
			If Request.Form <> "" Then

				' Setup variables
				Username = ew_RemoveXSS(Request.Form("username"))
				sPassword = ew_RemoveXSS(Request.Form("password"))
				LoginType = LCase(ew_RemoveXSS(Request.Form("type")))
			End If
			If Username <> "" Then
				bValidate = ValidateForm(Username, sPassword)
				If Not bValidate Then
					FailureMessage = gsFormError
				End If
				Session(EW_SESSION_USER_PROFILE_USER_NAME) = Username ' Save login user name
				Session(EW_SESSION_USER_PROFILE_LOGIN_TYPE) = LoginType ' Save login type
			Else
				If Security.IsLoggedIn() Then
					If FailureMessage = "" Then Page_Terminate(sLastUrl) ' Return to last accessed page
				End If
				bValidate = False

				' Restore settings
				Username = Request.Cookies(EW_PROJECT_NAME)("username")
				If Request.Cookies(EW_PROJECT_NAME)("autologin") = "autologin" Then
					LoginType = "a"
				ElseIf Request.Cookies(EW_PROJECT_NAME)("autologin") = "rememberusername" Then
					LoginType = "u"
				Else
					LoginType = ""
				End If
			End If
			bValidPwd = False
			If bValidate Then

				' Call logging in event
				bValidate = User_LoggingIn(Username, sPassword)
				If bValidate Then
					bValidPwd = Security.ValidateUser(Username, sPassword, False) ' Manual login
					If Not bValidPwd Then
						If FailureMessage = "" Then FailureMessage = Language.Phrase("InvalidUidPwd") ' Invalid user id/password
					End If
				Else
					If FailureMessage = "" Then FailureMessage = Language.Phrase("LoginCancelled") ' Login cancelled
				End If
			End If
		End If
		If bValidPwd Then

			' Write cookies
			If LoginType = "a" Then ' Auto login
				Response.Cookies(EW_PROJECT_NAME)("autologin") = "autologin" ' Set up autologin cookies
				Response.Cookies(EW_PROJECT_NAME)("username") = Username ' Set up user name cookies
				Response.Cookies(EW_PROJECT_NAME)("password") = ew_Encode(ew_Encrypt(sPassword, EW_RANDOM_KEY)) ' Set up password cookies
			ElseIf LoginType = "u" Then ' Remember user name
				Response.Cookies(EW_PROJECT_NAME)("autologin") = "rememberusername" ' Set up remember user name cookies
				Response.Cookies(EW_PROJECT_NAME)("username") = Username ' Set up user name cookies
			Else
				Response.Cookies(EW_PROJECT_NAME)("autologin") = "" ' Clear autologin cookies
			End If
			Response.Cookies(EW_PROJECT_NAME).Expires = DateAdd("d", EW_COOKIE_EXPIRY_TIME, Now)

			' Call loggedin event
			Call User_LoggedIn(Username)
			Call Page_Terminate(sLastUrl) ' Return to last accessed url
		ElseIf Username <> "" And sPassword <> "" Then

			' Call user login error event
			Call User_LoginError(Username, sPassword)
		End If
	End Sub

	' -----------------------------------------------------------------
	' Validate form
	'
	Function ValidateForm(usr, pwd)

		' Initialize
		gsFormError = ""

		' Check if validation required
		If Not EW_SERVER_VALIDATE Then
			ValidateForm = True
			Exit Function
		End If
		If usr = "" Then
			Call ew_AddMessage(gsFormError, Language.Phrase("EnterUid"))
		End If
		If pwd = "" Then
			Call ew_AddMessage(gsFormError, Language.Phrase("EnterPwd"))
		End If

		' Return validate result
		ValidateForm = (gsFormError = "")

		' Call Form Custom Validate event
		Dim sFormCustomError
		sFormCustomError = ""
		ValidateForm = ValidateForm And Form_CustomValidate(sFormCustomError)
		If sFormCustomError <> "" Then
			Call ew_AddMessage(gsFormError, sFormCustomError)
		End If
	End Function

	' Page Load event
	Sub Page_Load()

		'Response.Write "Page Load"
	End Sub

	' Page Unload event
	Sub Page_Unload()

		'Response.Write "Page Unload"
	End Sub

	' Page Redirecting event
	Sub Page_Redirecting(url)

		'url = newurl
	End Sub

	' Message Showing event
	' typ = ""|"success"|"failure"
	Sub Message_Showing(msg, typ)

		' Example:
		'If typ = "success" Then msg = "your success message"

	End Sub

	' Page Render event
	Sub Page_Render()

		'Response.Write "Page Render"
	End Sub

	' Page Data Rendering event
	Sub Page_DataRendering(header)

		' Example:
		'header = "your header"

	End Sub

	' Page Data Rendered event
	Sub Page_DataRendered(footer)

		' Example:
		'footer = "your footer"

	End Sub

	' User Logging In event
	Function User_LoggingIn(usr, pwd)
		If Not EW_DEBUG_ENABLED Then On Error Resume Next

		' Enter your code here
		' To cancel, set return value to False

		User_LoggingIn = True
	End Function

	' User Logged In event
	Sub User_LoggedIn(usr)

		' Response.Write "User Logged In"
	End Sub

	' User Login Error event
	Sub User_LoginError(usr, pwd)

		' Response.Write "User Login Error"
	End Sub

	' Form Custom Validate event
	Function Form_CustomValidate(CustomError)

		'Return error message in CustomError
		Form_CustomValidate = True
	End Function
End Class
%>
