<%
Response.Buffer = EW_RESPONSE_BUFFER
%>
<!--#include file="ewcfg7.asp"-->
<!--#include file="zlogininfo.asp"-->
<!--#include file="aspfn7.asp"-->
<!--#include file="userfn7.asp"-->
<% Session.Timeout = 900 %>
<%
Response.Expires = 0
Response.ExpiresAbsolute = Now() - 1
Response.AddHeader "pragma", "no-cache"
Response.AddHeader "cache-control", "private, no-cache, no-store, must-revalidate"
%>
<%

' Define page object
Dim zlogin_view
Set zlogin_view = New czlogin_view
Set Page = zlogin_view

' Page init processing
Call zlogin_view.Page_Init()

' Page main processing
Call zlogin_view.Page_Main()
%>
<!--#include file="header.asp"-->
<% If zlogin.Export = "" Then %>
<script type="text/javascript">
<!--
// Create page object
var zlogin_view = new ew_Page("zlogin_view");
// page properties
zlogin_view.PageID = "view"; // page ID
var EW_PAGE_ID = zlogin_view.PageID; // for backward compatibility
// extend page with Form_CustomValidate function
zlogin_view.Form_CustomValidate = 
 function(fobj) { // DO NOT CHANGE THIS LINE!
 	// Your custom validation code here, return false if invalid. 
 	return true;
 }
zlogin_view.SelectAllKey = function(elem) {
	ew_SelectAll(elem);
}
<% If EW_CLIENT_VALIDATE Then %>
zlogin_view.ValidateRequired = true; // uses JavaScript validation
<% Else %>
zlogin_view.ValidateRequired = false; // no JavaScript validation
<% End If %>
//-->
</script>
<script language="JavaScript" type="text/javascript">
<!--
// Write your client script here, no need to add script tags.
// To include another .js script, use:
// ew_ClientScriptInclude("my_javascript.js"); 
//-->
</script>
<% End If %>
<p><span class="aspmaker">查看 表: 管理员
<br><br>
<% If zlogin.Export = "" Then %>
<a href="zloginlist.asp">返回列表</a>&nbsp;
<% If Security.CanAdd Then %>
<a href="<%= zlogin.AddUrl %>">增加</a>&nbsp;
<% End If %>
<% If Security.CanEdit Then %>
<a href="<%= zlogin.EditUrl %>">编辑</a>&nbsp;
<% End If %>
<% If Security.CanAdd Then %>
<a href="<%= zlogin.CopyUrl %>">复制</a>&nbsp;
<% End If %>
<% If Security.CanDelete Then %>
<a href="<%= zlogin.DeleteUrl %>">删除</a>&nbsp;
<% End If %>
<% End If %>
</span></p>
<% zlogin_view.ShowMessage %>
<p>
<% If zlogin.Export = "" Then %>
<form name="ewpagerform" id="ewpagerform" class="ewForm" action="<%= ew_CurrentPage %>">
<table border="0" cellspacing="0" cellpadding="0" class="ewPager">
	<tr>
		<td>
<% If Not IsObject(zlogin_view.Pager) Then Set zlogin_view.Pager = ew_NewPrevNextPager(zlogin_view.lStartRec, zlogin_view.lDisplayRecs, zlogin_view.lTotalRecs) %>
<% If zlogin_view.Pager.RecordCount > 0 Then %>
	<table border="0" cellspacing="0" cellpadding="0"><tr><td><span class="aspmaker">页&nbsp;</span></td>
<!--first page button-->
	<% If zlogin_view.Pager.FirstButton.Enabled Then %>
	<td><a href="<%= zlogin_view.PageUrl %>start=<%= zlogin_view.Pager.FirstButton.Start %>"><img src="images/first.gif" alt="首页" width="16" height="16" border="0"></a></td>
	<% Else %>
	<td><img src="images/firstdisab.gif" alt="首页" width="16" height="16" border="0"></td>
	<% End If %>
<!--previous page button-->
	<% If zlogin_view.Pager.PrevButton.Enabled Then %>
	<td><a href="<%= zlogin_view.PageUrl %>start=<%= zlogin_view.Pager.PrevButton.Start %>"><img src="images/prev.gif" alt="上一页" width="16" height="16" border="0"></a></td>
	<% Else %>
	<td><img src="images/prevdisab.gif" alt="上一页" width="16" height="16" border="0"></td>
	<% End If %>
<!--current page number-->
	<td><input type="text" name="<%= EW_TABLE_PAGE_NO %>" id="<%= EW_TABLE_PAGE_NO %>" value="<%= zlogin_view.Pager.CurrentPage %>" size="4"></td>
<!--next page button-->
	<% If zlogin_view.Pager.NextButton.Enabled Then %>
	<td><a href="<%= zlogin_view.PageUrl %>start=<%= zlogin_view.Pager.NextButton.Start %>"><img src="images/next.gif" alt="下一页" width="16" height="16" border="0"></a></td>
	<% Else %>
	<td><img src="images/nextdisab.gif" alt="下一页" width="16" height="16" border="0"></td>
	<% End If %>
<!--last page button-->
	<% If zlogin_view.Pager.LastButton.Enabled Then %>
	<td><a href="<%= zlogin_view.PageUrl %>start=<%= zlogin_view.Pager.LastButton.Start %>"><img src="images/last.gif" alt="尾页" width="16" height="16" border="0"></a></td>	
	<% Else %>
	<td><img src="images/lastdisab.gif" alt="尾页" width="16" height="16" border="0"></td>
	<% End If %>
	<td><span class="aspmaker">&nbsp;的 <%= zlogin_view.Pager.PageCount %></span></td>
	</tr></table>
<% Else %>
	<% If Security.CanList Then %>
	<% If zlogin_view.sSrchWhere = "0=101" Then %>
	<span class="aspmaker">请输入查询条件</span>
	<% Else %>
	<span class="aspmaker">没有找到记录</span>
	<% End If %>
	<% Else %>
	<span class="aspmaker">你无权查看</span>
	<% End If %>
<% End If %>
		</td>
	</tr>
</table>
</form>
<br>
<% End If %>
<table cellspacing="0" class="ewGrid"><tr><td class="ewGridContent">
<div class="ewGridMiddlePanel">
<table cellspacing="0" class="ewTable">
<% If zlogin.id.Visible Then ' id %>
	<tr<%= zlogin.id.RowAttributes %>>
		<td class="ewTableHeader">编号</td>
		<td<%= zlogin.id.CellAttributes %>>
<div<%= zlogin.id.ViewAttributes %>><%= zlogin.id.ViewValue %></div>
</td>
	</tr>
<% End If %>
<% If zlogin.username.Visible Then ' username %>
	<tr<%= zlogin.username.RowAttributes %>>
		<td class="ewTableHeader">用户名</td>
		<td<%= zlogin.username.CellAttributes %>>
<div<%= zlogin.username.ViewAttributes %>><%= zlogin.username.ViewValue %></div>
</td>
	</tr>
<% End If %>
<% If zlogin.password.Visible Then ' password %>
	<tr<%= zlogin.password.RowAttributes %>>
		<td class="ewTableHeader">密码</td>
		<td<%= zlogin.password.CellAttributes %>>
<div<%= zlogin.password.ViewAttributes %>><%= zlogin.password.ViewValue %></div>
</td>
	</tr>
<% End If %>
<% If zlogin.levels.Visible Then ' levels %>
	<tr<%= zlogin.levels.RowAttributes %>>
		<td class="ewTableHeader">等级</td>
		<td<%= zlogin.levels.CellAttributes %>>
<div<%= zlogin.levels.ViewAttributes %>><%= zlogin.levels.ViewValue %></div>
</td>
	</tr>
<% End If %>
</table>
</div>
</td></tr></table>
<% If zlogin.Export = "" Then %>
<br>
<form name="ewpagerform" id="ewpagerform" class="ewForm" action="<%= ew_CurrentPage %>">
<table border="0" cellspacing="0" cellpadding="0" class="ewPager">
	<tr>
		<td>
<% If Not IsObject(zlogin_view.Pager) Then Set zlogin_view.Pager = ew_NewPrevNextPager(zlogin_view.lStartRec, zlogin_view.lDisplayRecs, zlogin_view.lTotalRecs) %>
<% If zlogin_view.Pager.RecordCount > 0 Then %>
	<table border="0" cellspacing="0" cellpadding="0"><tr><td><span class="aspmaker">页&nbsp;</span></td>
<!--first page button-->
	<% If zlogin_view.Pager.FirstButton.Enabled Then %>
	<td><a href="<%= zlogin_view.PageUrl %>start=<%= zlogin_view.Pager.FirstButton.Start %>"><img src="images/first.gif" alt="首页" width="16" height="16" border="0"></a></td>
	<% Else %>
	<td><img src="images/firstdisab.gif" alt="首页" width="16" height="16" border="0"></td>
	<% End If %>
<!--previous page button-->
	<% If zlogin_view.Pager.PrevButton.Enabled Then %>
	<td><a href="<%= zlogin_view.PageUrl %>start=<%= zlogin_view.Pager.PrevButton.Start %>"><img src="images/prev.gif" alt="上一页" width="16" height="16" border="0"></a></td>
	<% Else %>
	<td><img src="images/prevdisab.gif" alt="上一页" width="16" height="16" border="0"></td>
	<% End If %>
<!--current page number-->
	<td><input type="text" name="<%= EW_TABLE_PAGE_NO %>" id="<%= EW_TABLE_PAGE_NO %>" value="<%= zlogin_view.Pager.CurrentPage %>" size="4"></td>
<!--next page button-->
	<% If zlogin_view.Pager.NextButton.Enabled Then %>
	<td><a href="<%= zlogin_view.PageUrl %>start=<%= zlogin_view.Pager.NextButton.Start %>"><img src="images/next.gif" alt="下一页" width="16" height="16" border="0"></a></td>
	<% Else %>
	<td><img src="images/nextdisab.gif" alt="下一页" width="16" height="16" border="0"></td>
	<% End If %>
<!--last page button-->
	<% If zlogin_view.Pager.LastButton.Enabled Then %>
	<td><a href="<%= zlogin_view.PageUrl %>start=<%= zlogin_view.Pager.LastButton.Start %>"><img src="images/last.gif" alt="尾页" width="16" height="16" border="0"></a></td>	
	<% Else %>
	<td><img src="images/lastdisab.gif" alt="尾页" width="16" height="16" border="0"></td>
	<% End If %>
	<td><span class="aspmaker">&nbsp;的 <%= zlogin_view.Pager.PageCount %></span></td>
	</tr></table>
<% Else %>
	<% If Security.CanList Then %>
	<% If zlogin_view.sSrchWhere = "0=101" Then %>
	<span class="aspmaker">请输入查询条件</span>
	<% Else %>
	<span class="aspmaker">没有找到记录</span>
	<% End If %>
	<% Else %>
	<span class="aspmaker">你无权查看</span>
	<% End If %>
<% End If %>
		</td>
	</tr>
</table>
</form>
<% End If %>
<p>
<% If zlogin.Export = "" Then %>
<script language="JavaScript" type="text/javascript">
<!--
// Write your table-specific startup script here
// document.write("page loaded");
//-->
</script>
<% End If %>
<!--#include file="footer.asp"-->
<%

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

' -----------------------------------------------------------------
' Page Class
'
Class czlogin_view

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

	' Table Name
	Public Property Get TableName()
		TableName = "login"
	End Property

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

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

	' Page Url
	Public Property Get PageUrl()
		PageUrl = ew_CurrentPage() & "?"
		If zlogin.UseTokenInUrl Then PageUrl = PageUrl & "t=" & zlogin.TableVar & "&" ' add page token
	End Property

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

	Public Property Let Message(v)
		If Session(EW_SESSION_MESSAGE) <> "" Then ' Append
			Session(EW_SESSION_MESSAGE) = Session(EW_SESSION_MESSAGE) & "<br>" & v
		Else
			Session(EW_SESSION_MESSAGE) = v
		End If
	End Property

	' Show Message
	Public Sub ShowMessage()
		If Message <> "" Then ' Message in Session, display
			Response.Write "<p><span class=""ewMessage"">" & Message & "</span></p>"
			Session(EW_SESSION_MESSAGE) = "" ' Clear message in Session
		End If
	End Sub

	' -----------------------
	'  Validate Page request
	'
	Public Function IsPageRequest()
		If zlogin.UseTokenInUrl Then
			IsPageRequest = False
			If Not (ObjForm Is Nothing) Then
				IsPageRequest = (zlogin.TableVar = ObjForm.GetValue("t"))
			End If
			If Request.QueryString("t").Count > 0 Then
				IsPageRequest = (zlogin.TableVar = Request.QueryString("t"))
			End If
		Else
			IsPageRequest = True
		End If
	End Function

	' -----------------------------------------------------------------
	'  Class initialize
	'  - init objects
	'  - open ADO connection
	'
	Private Sub Class_Initialize()

		' Initialize table object
		Set zlogin = New czlogin

		' Initialize form object
		Set ObjForm = Nothing

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

		' Initialize table name (for backward compatibility)
		EW_TABLE_NAME = "login"

		' Open connection to the database
		Set Conn = Server.CreateObject("ADODB.Connection")
		Conn.Open EW_DB_CONNECTION_STRING
	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
		If Not Security.IsLoggedIn() Then Call Security.AutoLogin()
		If Not Security.IsLoggedIn() Then
			Call Security.SaveLastUrl()
			Call Page_Terminate("login.asp")
		End If

		' Table Permission loading event
		Call Security.TablePermission_Loading()
		Call Security.LoadCurrentUserLevel(TableName)

		' Table Permission loaded event
		Call Security.TablePermission_Loaded()
		If Not Security.CanView Then
			Call Security.SaveLastUrl()
			Call Page_Terminate("zloginlist.asp")
		End If

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

		' Page load event, used in current page
		Call 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()
		If Not (Conn Is Nothing) Then Conn.Close ' Close Connection
		Set Conn = Nothing
		Set Security = Nothing
		Set zlogin = Nothing

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

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

	Dim lDisplayRecs ' Number of display records
	Dim lStartRec, lStopRec, lTotalRecs, lRecRange
	Dim lRecCnt

	' -----------------------------------------------------------------
	' Page main processing
	'
	Sub Page_Main()

		' Paging variables
		lDisplayRecs = 1
		lRecRange = 10

		' Load current record
		Dim bLoadCurrentRecord
		bLoadCurrentRecord = False
		Dim sReturnUrl
		sReturnUrl = ""
		Dim bMatchRecord
		bMatchRecord = False
		If IsPageRequest Then ' Validate request
			If Request.QueryString("id").Count > 0 Then
				zlogin.id.QueryStringValue = Request.QueryString("id")
			Else
				bLoadCurrentRecord = True
			End If

			' Get action
			zlogin.CurrentAction = "I" ' Display form
			Select Case zlogin.CurrentAction
				Case "I" ' Get a record to display
					lStartRec = 1 ' Initialize start position
					Set Rs = LoadRecordset() ' Load records
					lTotalRecs = Rs.RecordCount ' Get record count
					If lTotalRecs <= 0 Then ' No record found
						Message = "没有找到记录" ' Set no record message
						sReturnUrl = "zloginlist.asp"
					ElseIf bLoadCurrentRecord Then ' Load current record position
						SetUpStartRec() ' Set up start record position

						' Point to current record
						If CLng(lStartRec) <= CLng(lTotalRecs) Then
							bMatchRecord = True
							Rs.Move lStartRec-1
						End If
					Else ' Match key values
						Do While Not Rs.Eof
							If CStr(zlogin.id.CurrentValue) = CStr(Rs("id")) Then
								zlogin.StartRecordNumber = lStartRec ' Save record position
								bMatchRecord = True
								Exit Do
							Else
								lStartRec = lStartRec + 1
								Rs.MoveNext
							End If
						Loop
					End If
					If Not bMatchRecord Then
						Message = "没有找到记录" ' Set no record message
						sReturnUrl = "zloginlist.asp" ' No matching record, return to list
					Else
						Call LoadRowValues(Rs) ' Load row values
					End If
			End Select
		Else
			sReturnUrl = "zloginlist.asp" ' Not page request, return to list
		End If
		If sReturnUrl <> "" Then Call Page_Terminate(sReturnUrl)

		' Render row
		zlogin.RowType = EW_ROWTYPE_VIEW
		Call RenderRow()
	End Sub
	Dim Pager

	' -----------------------------------------------------------------
	' Set up Starting Record parameters based on Pager Navigation
	'
	Sub SetUpStartRec()
		Dim nPageNo

		' Exit if lDisplayRecs = 0
		If lDisplayRecs = 0 Then Exit Sub
		If IsPageRequest Then ' Validate request

			' Check for a START parameter
			If Request.QueryString(EW_TABLE_START_REC).Count > 0 Then
				lStartRec = Request.QueryString(EW_TABLE_START_REC)
				zlogin.StartRecordNumber = lStartRec
			ElseIf Request.QueryString(EW_TABLE_PAGE_NO).Count > 0 Then
				nPageNo = Request.QueryString(EW_TABLE_PAGE_NO)
				If IsNumeric(nPageNo) Then
					lStartRec = (nPageNo-1)*lDisplayRecs+1
					If lStartRec <= 0 Then
						lStartRec = 1
					ElseIf lStartRec >= ((lTotalRecs-1)\lDisplayRecs)*lDisplayRecs+1 Then
						lStartRec = ((lTotalRecs-1)\lDisplayRecs)*lDisplayRecs+1
					End If
					zlogin.StartRecordNumber = lStartRec
				End If
			End If
		End If
		lStartRec = zlogin.StartRecordNumber

		' Check if correct start record counter
		If Not IsNumeric(lStartRec) Or lStartRec = "" Then ' Avoid invalid start record counter
			lStartRec = 1 ' Reset start record counter
			zlogin.StartRecordNumber = lStartRec
		ElseIf CLng(lStartRec) > CLng(lTotalRecs) Then ' Avoid starting record > total records
			lStartRec = ((lTotalRecs-1)\lDisplayRecs)*lDisplayRecs+1 ' Point to last page first record
			zlogin.StartRecordNumber = lStartRec
		ElseIf (lStartRec-1) Mod lDisplayRecs <> 0 Then
			lStartRec = ((lStartRec-1)\lDisplayRecs)*lDisplayRecs+1 ' Point to page boundary
			zlogin.StartRecordNumber = lStartRec
		End If
	End Sub

	' -----------------------------------------------------------------
	' Load recordset
	'
	Function LoadRecordset()

		' Call Recordset Selecting event
		Call zlogin.Recordset_Selecting(zlogin.CurrentFilter)

		' Load list page sql
		Dim sSql
		sSql = zlogin.ListSQL
		If EW_DEBUG_ENABLED Then Response.Write sSql ' Show SQL for debugging

		' Load recordset
		Dim RsRecordset
		Set RsRecordset = Server.CreateObject("ADODB.Recordset")
		RsRecordset.CursorLocation = EW_CURSORLOCATION
		RsRecordset.Open sSql, Conn, 1, 2

		' Call Recordset Selected event
		Call zlogin.Recordset_Selected(RsRecordset)
		Set LoadRecordset = RsRecordset
	End Function

	' -----------------------------------------------------------------
	' Load row based on key values
	'
	Function LoadRow()
		Dim RsRow, sSql, sFilter
		sFilter = zlogin.KeyFilter

		' Call Row Selecting event
		Call zlogin.Row_Selecting(sFilter)

		' Load sql based on filter
		zlogin.CurrentFilter = sFilter
		sSql = zlogin.SQL
		If EW_DEBUG_ENABLED Then Response.Write sSql ' Show SQL for debugging
		Set RsRow = Server.CreateObject("ADODB.Recordset")
		RsRow.Open sSql, Conn
		If RsRow.Eof Then
			LoadRow = False
		Else
			LoadRow = True
			RsRow.MoveFirst
			Call LoadRowValues(RsRow) ' Load row values

			' Call Row Selected event
			Call zlogin.Row_Selected(RsRow)
		End If
		RsRow.Close
		Set RsRow = Nothing
	End Function

	' -----------------------------------------------------------------
	' Load row values from recordset
	'
	Sub LoadRowValues(RsRow)
		zlogin.id.DbValue = RsRow("id")
		zlogin.username.DbValue = RsRow("username")
		zlogin.password.DbValue = RsRow("password")
		zlogin.levels.DbValue = RsRow("levels")
	End Sub

	' -----------------------------------------------------------------
	' Render row values based on field settings
	'
	Sub RenderRow()

		' Call Row Rendering event
		Call zlogin.Row_Rendering()

		' ---------------------------------------
		'  Common render codes for all row types
		' ---------------------------------------
		' id

		zlogin.id.CellCssStyle = ""
		zlogin.id.CellCssClass = ""

		' username
		zlogin.username.CellCssStyle = ""
		zlogin.username.CellCssClass = ""

		' password
		zlogin.password.CellCssStyle = ""
		zlogin.password.CellCssClass = ""

		' levels
		zlogin.levels.CellCssStyle = ""
		zlogin.levels.CellCssClass = ""

		' -----------
		'  View  Row
		' -----------

		If zlogin.RowType = EW_ROWTYPE_VIEW Then ' View row

			' id
			zlogin.id.ViewValue = zlogin.id.CurrentValue
			zlogin.id.CssStyle = ""
			zlogin.id.CssClass = ""
			zlogin.id.ViewCustomAttributes = ""

			' username
			zlogin.username.ViewValue = zlogin.username.CurrentValue
			zlogin.username.CssStyle = ""
			zlogin.username.CssClass = ""
			zlogin.username.ViewCustomAttributes = ""

			' password
			zlogin.password.ViewValue = zlogin.password.CurrentValue
			zlogin.password.CssStyle = ""
			zlogin.password.CssClass = ""
			zlogin.password.ViewCustomAttributes = ""

			' levels
			If (Security.CurrentUserLevel And EW_ALLOW_ADMIN) = EW_ALLOW_ADMIN Then ' System admin
			If zlogin.levels.CurrentValue & "" <> "" Then
				sSqlWrk = "SELECT [UserLevelName] FROM [UserLevels] WHERE [UserLevelID] = " & ew_AdjustSql(zlogin.levels.CurrentValue) & ""
				Set RsWrk = Conn.Execute(sSqlWrk)
				If Not RsWrk.Eof Then
					zlogin.levels.ViewValue = RsWrk("UserLevelName")
				Else
					zlogin.levels.ViewValue = zlogin.levels.CurrentValue
				End If
				RsWrk.Close
				Set RsWrk = Nothing
			Else
				zlogin.levels.ViewValue = Null
			End If
			Else
				zlogin.levels.ViewValue = "********"
			End If
			zlogin.levels.CssStyle = ""
			zlogin.levels.CssClass = ""
			zlogin.levels.ViewCustomAttributes = ""

			' View refer script
			' id

			zlogin.id.HrefValue = ""

			' username
			zlogin.username.HrefValue = ""

			' password
			zlogin.password.HrefValue = ""

			' levels
			zlogin.levels.HrefValue = ""
		End If

		' Call Row Rendered event
		Call zlogin.Row_Rendered()
	End Sub

	' Page Load event
	Sub Page_Load()

		'Response.Write "Page Load"
	End Sub

	' Page Unload event
	Sub Page_Unload()

		'Response.Write "Page Unload"
	End Sub
End Class
%>
