<%
Response.Buffer = EW_RESPONSE_BUFFER
%>
<!--#include file="ewcfg7.asp"-->
<!--#include file="UserLevelsinfo.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 userpriv
Set userpriv = New cuserpriv
Set Page = userpriv

' Page init processing
Call userpriv.Page_Init()

' Page main processing
Call userpriv.Page_Main()
%>
<!--#include file="header.asp"-->
<script type="text/javascript">
<!--
// Create page object
var userpriv = new ew_Page("userpriv");
// page properties
userpriv.PageID = "userpriv"; // page ID
var EW_PAGE_ID = userpriv.PageID; // for backward compatibility
// extend page with Form_CustomValidate function
userpriv.Form_CustomValidate = 
 function(fobj) { // DO NOT CHANGE THIS LINE!
 	// Your custom validation code here, return false if invalid. 
 	return true;
 }
userpriv.SelectAllKey = function(elem) {
	ew_SelectAll(elem);
}
<% If EW_CLIENT_VALIDATE Then %>
userpriv.ValidateRequired = true; // uses JavaScript validation
<% Else %>
userpriv.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>
<p><span class="aspmaker">用户级别<br><br>
<a href="UserLevelslist.asp">返回列表</a></span></p>
<p><span class="aspmaker">用户级别: <%= Security.GetUserLevelName(UserLevels.UserLevelID.CurrentValue) %>(<%= UserLevels.UserLevelID.CurrentValue %>)</span></p>
<% userpriv.ShowMessage %>
<table cellspacing="0" class="ewGrid"><tr><td class="ewGridContent">
<div class="ewGridMiddlePanel">
<form name="userpriv" id="userpriv" action="<%= ew_CurrentPage %>" method="post">
<input type="hidden" name="t" id="t" value="UserLevels">
<input type="hidden" name="a_edit" id="a_edit" value="U">
<!-- hidden tag for User Level ID -->
<input type="hidden" name="x_UserLevelID" id="x_UserLevelID" value="<%= UserLevels.UserLevelID.CurrentValue %>">
<table cellspacing="0" rowhighlightclass="ewTableHighlightRow" rowselectclass="ewTableSelectRow" roweditclass="ewTableEditRow" class="ewTable">
	<thead>
	<tr class="ewTableHeader">
		<td>表/视图</td>
		<td>增加/复制<input type="checkbox" name="Add" id="Add" onclick="ew_SelectAll(this);"<%= userpriv.sDisabled %>></td>
		<td>删除<input type="checkbox" name="Delete" id="Delete" onclick="ew_SelectAll(this);"<%= userpriv.sDisabled %>></td>
		<td>编辑<input type="checkbox" name="Edit" id="Edit" onclick="ew_SelectAll(this);"<%= userpriv.sDisabled %>></td>
<% If EW_USER_LEVEL_COMPAT Then %>
		<td>列表/搜索/查看<input type="checkbox" name="List" id="List" onclick="ew_SelectAll(this);"<%= userpriv.sDisabled %>></td>
<% Else %>
		<td>列表<input type="checkbox" name="List" id="List" onclick="ew_SelectAll(this);"<%= userpriv.sDisabled %>></td>
		<td>查看<input type="checkbox" name="View" id="View" onclick="ew_SelectAll(this);"<%= userpriv.sDisabled %>></td>
		<td>搜索<input type="checkbox" name="Search" id="Search" onclick="ew_SelectAll(this);"<%= userpriv.sDisabled %>></td>
<% End If %>
	</tr>
	</thead>
	<tbody>
<%
For i = LBound(EW_USER_LEVEL_TABLE_NAME) to UBound(EW_USER_LEVEL_TABLE_NAME)
	userpriv.TempPriv = Security.GetUserLevelPrivEx(EW_USER_LEVEL_TABLE_NAME(i), UserLevels.UserLevelID.CurrentValue)

	' Set row properties
	UserLevels.CssClass = ""
	UserLevels.CssStyle = ""
	UserLevels.RowClientEvents = "onmouseover='ew_MouseOver(event, this);' onmouseout='ew_MouseOut(event, this);' onclick='ew_Click(event, this);'"
%>
	<tr<%= UserLevels.RowAttributes %>>
		<td><span class="aspmaker"><%= EW_USER_LEVEL_TABLE_NAME(i) %></span></td>
		<td align="center"><input type="checkbox" name="Add_<%= i %>" id="Add_<%= i %>" value="1"<% If (userpriv.TempPriv And EW_ALLOW_ADD) = EW_ALLOW_ADD Then %> checked="checked"<% End If %><%= userpriv.sDisabled %>></td>
		<td align="center"><input type="checkbox" name="Delete_<%= i %>" id="Delete_<%= i %>" value="2"<% If (userpriv.TempPriv And EW_ALLOW_DELETE) = EW_ALLOW_DELETE Then %> checked="checked"<% End If %><%= userpriv.sDisabled %>></td>
		<td align="center"><input type="checkbox" name="Edit_<%= i %>" id="Edit_<%= i %>" value="4"<% If (userpriv.TempPriv And EW_ALLOW_EDIT) = EW_ALLOW_EDIT Then %> checked="checked"<% End If %><%= userpriv.sDisabled %>></td>
<% If EW_USER_LEVEL_COMPAT Then %>
		<td align="center"><input type="checkbox" name="List_<%= i %>" id="List_<%= i %>" value="8"<% If (userpriv.TempPriv And EW_ALLOW_LIST) = EW_ALLOW_LIST Then %> checked="checked"<% End If %><%= userpriv.sDisabled %>></td>
<% Else %>
		<td align="center"><input type="checkbox" name="List_<%= i %>" id="List_<%= i %>" value="8"<% If (userpriv.TempPriv And EW_ALLOW_LIST) = EW_ALLOW_LIST Then %> checked="checked"<% End If %><%= userpriv.sDisabled %>></td>
		<td align="center"><input type="checkbox" name="View_<%= i %>" id="View_<%= i %>" value="32"<% If (userpriv.TempPriv And EW_ALLOW_VIEW) = EW_ALLOW_VIEW Then %> checked="checked"<% End If %><%= userpriv.sDisabled %>></td>
		<td align="center"><input type="checkbox" name="Search_<%= i %>" id="Search_<%= i %>" value="64"<% If (userpriv.TempPriv And EW_ALLOW_SEARCH) = EW_ALLOW_SEARCH Then %> checked="checked"<% End If %><%= userpriv.sDisabled %>></td>
<% End If %>
	</tr>
<% Next %>
	</tbody>				
</table>
</div>
</td></tr></table>
<p>
<input type="submit" name="btnSubmit" id="btnSubmit" value="    更新    "<%= userpriv.sDisabled %>>
</form>
<script language="JavaScript" type="text/javascript">
<!--
// Write your startup script here
// document.write("page loaded");
//-->
</script>
<!--#include file="footer.asp"-->
<%

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

' -----------------------------------------------------------------
' Page Class
'
Class cuserpriv

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

	' Page Object Name
	Public Property Get PageObjName()
		PageObjName = "userpriv"
	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)
		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()
		IsPageRequest = True
	End Function

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

		' Initialize table object
		Set UserLevels = New cUserLevels

		' Initialize other table object
		Set zlogin = New czlogin

		' Initialize form object
		Set ObjForm = Nothing

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

		' 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("UserLevels")

		' Table Permission loaded event
		Call Security.TablePermission_Loaded()
		If Not Security.CanAdmin Then
			Call Security.SaveLastUrl()
			Call Page_Terminate( "login.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

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

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

	Dim TempPriv, sDisabled
	Dim arPriv

	' -----------------------------------------------------------------
	' Page main processing
	'
	Sub Page_Main()
		If Not IsArray(EW_USER_LEVEL_TABLE_NAME) Then
		    Message = "没有表格生成"
			Call Page_Terminate("UserLevelslist.asp") ' Return to list
		End If
		ReDim arPriv(UBound(EW_USER_LEVEL_TABLE_NAME))

		' Get action
		If Request.Form("a_edit").Count <= 0 Then
			UserLevels.CurrentAction = "I"	' Display with input box

			' Load key from QueryString
			If Request.QueryString("UserLevelID").Count > 0 Then
				UserLevels.UserLevelID.QueryStringValue = Request.QueryString("UserLevelID")
			Else
				Call Page_Terminate("UserLevelslist.asp") ' Return to list
			End If
			If UserLevels.UserLevelID.QueryStringValue = "-1" Then
				sDisabled = " disabled=""disabled"""
			Else
				sDisabled = ""
			End If
		Else
			UserLevels.CurrentAction = Request.Form("a_edit")

			' Get fields from form
			UserLevels.UserLevelID.FormValue = Request.Form("x_UserLevelID")
			For i = LBound(EW_USER_LEVEL_TABLE_NAME) to UBound(EW_USER_LEVEL_TABLE_NAME)
				If EW_USER_LEVEL_COMPAT Then
					arPriv(i) = CInt(Request.Form("Add_" & i)) + _
						CInt(Request.Form("Delete_" & i)) + CInt(Request.Form("Edit_" & i)) + _
						CInt(Request.Form("List_" & i))
				Else
					arPriv(i) = CInt(Request.Form("Add_" & i)) + _
						CInt(Request.Form("Delete_" & i)) + CInt(Request.Form("Edit_" & i)) + _
						CInt(Request.Form("List_" & i)) + CInt(Request.Form("View_" & i)) + _
						CInt(Request.Form("Search_" & i))
				End If
			Next
		End If
		Select Case UserLevels.CurrentAction
			Case "I" ' Display
				Security.SetUpUserLevelEx() ' Get all user level info
			Case "U" ' Update
				If EditRow() Then ' Update Record based on key
					Message = "更新成功" ' Set update success message

					' Alternatively, comment out the following line to go back to this page
					Call Page_Terminate("UserLevelslist.asp") ' Return to list
				End If
		End Select
	End Sub

	' -----------------------------------------------------------------
	' Update privileges
	'
	Function EditRow()
		Dim Sql
		Dim lRowCnt, i
		For i = LBound(EW_USER_LEVEL_TABLE_NAME) to UBound(EW_USER_LEVEL_TABLE_NAME)
			Sql = "UPDATE " & EW_USER_LEVEL_PRIV_TABLE & " SET " & EW_USER_LEVEL_PRIV_PRIV_FIELD & " = " & arPriv(i) & " WHERE " & _
				EW_USER_LEVEL_PRIV_TABLE_NAME_FIELD & " = '" & ew_AdjustSql(EW_USER_LEVEL_TABLE_NAME(i)) & "' AND " & _
				EW_USER_LEVEL_PRIV_USER_LEVEL_ID_FIELD & " = " & UserLevels.UserLevelID.CurrentValue
			Conn.Execute Sql, lRowCnt
			If lRowCnt = 0 Then
				Sql = "INSERT INTO " & EW_USER_LEVEL_PRIV_TABLE & " (" & EW_USER_LEVEL_PRIV_TABLE_NAME_FIELD & ", " & EW_USER_LEVEL_PRIV_USER_LEVEL_ID_FIELD & ", " & EW_USER_LEVEL_PRIV_PRIV_FIELD & ") VALUES ('" & ew_AdjustSql(EW_USER_LEVEL_TABLE_NAME(i)) & "', " & UserLevels.UserLevelID.CurrentValue & ", " & arPriv(i) & ")"
				Conn.Execute Sql, lRowCnt
			End If
		Next
		EditRow = True
	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
End Class
%>
