%
Response.expires = 0
Response.expiresabsolute = Now() - 1
Response.addHeader "pragma", "no-cache"
Response.addHeader "cache-control", "private"
Response.CacheControl = "no-cache"
%>
<%
ewCurSec = 0 ' Initialise
' User levels
Const ewAllowAdd = 1
Const ewAllowDelete = 2
Const ewAllowEdit = 4
Const ewAllowView = 8
Const ewAllowList = 8
Const ewAllowReport = 8
Const ewAllowSearch = 8
Const ewAllowAdmin = 16
%>
<%
If Session("design-desk-shop-DAT_status") <> "login" Then
Response.Redirect "login.asp"
Else
' Restore Security Table - created in Login
arrSecurity = Session("ewSecurity")
' Get Current Table Security
sTmp1 = -1
For sTmp = 1 to UBound(arrSecurity, 2)
If arrSecurity(0, sTmp) = "Users" Then
sTmp1 = sTmp
Exit For
End If
Next
ewCurLvl = Session("design-desk-shop-DAT_status_UserLevel")
If IsNumeric(ewCurLvl) And sTmp1 <> -1 Then
If ewCurLvl = -1 Then ' System Administrator
ewCurSec = 31
ElseIf ewCurLvl > 0 and ewCurLvl <= 1 Then
ewCurSec = arrSecurity(ewCurLvl, sTmp1)
End If
End If
If (ewCurSec And ewAllowadd) <> ewAllowadd Then Response.Redirect "Userslist.asp"
End If
%>
<%
' Initialize common variables
x_ID = Null
x_Username = Null
x_password = Null
x_First_Name = Null
x_Last_Name = Null
x_AccesssLevel = Null
x_Create_Date = Null
%>
<%
Response.Buffer = True
' Get action
sAction = Request.Form("a_add")
If (sAction = "" Or IsNull(sAction)) Then
sKey = Request.Querystring("key")
If sKey <> "" Then
sAction = "C" ' Copy record
Else
sAction = "I" ' Display blank record
End If
Else
' Get fields from form
x_ID = Request.Form("x_ID")
x_Username = Request.Form("x_Username")
x_password = Request.Form("x_password")
x_First_Name = Request.Form("x_First_Name")
x_Last_Name = Request.Form("x_Last_Name")
x_AccesssLevel = Request.Form("x_AccesssLevel")
x_Create_Date = Request.Form("x_Create_Date")
End If
' Open connection to the database
Set conn = Server.CreateObject("ADODB.Connection")
conn.Open xDb_Conn_Str
Select Case sAction
Case "C": ' Get a record to display
If Not LoadData(sKey) Then ' Load Record based on key
Session("ewmsg") = "No Record Found for Key = " & sKey
conn.Close ' Close Connection
Set conn = Nothing
Response.Clear
Response.Redirect "Userslist.asp"
End If
Case "A": ' Add
If AddData() Then ' Add New Record
Session("ewmsg") = "Add New Record Successful"
conn.Close ' Close Connection
Set conn = Nothing
Response.Clear
Response.Redirect "Userslist.asp"
End If
End Select
%>
Add to TABLE: Users
Back to List
<%
conn.Close ' Close Connection
Set conn = Nothing
%>
<%
'-------------------------------------------------------------------------------
' Function LoadData
' - Load Data based on Key Value sKey
' - Variables setup: field variables
Function LoadData(sKey)
Dim sKeyWrk, sSql, rs, sWhere, sGroupBy, sHaving, sOrderBy
sKeyWrk = "" & AdjustSql(sKey) & ""
sSql = "SELECT * FROM [Users]"
sSql = sSql & " WHERE [ID] = " & sKeyWrk
sGroupBy = ""
sHaving = ""
sOrderBy = ""
If sGroupBy <> "" Then
sSql = sSql & " GROUP BY " & sGroupBy
End If
If sHaving <> "" Then
sSql = sSql & " HAVING " & sHaving
End If
If sOrderBy <> "" Then
sSql = sSql & " ORDER BY " & sOrderBy
End If
Set rs = Server.CreateObject("ADODB.Recordset")
rs.Open sSql, conn
If rs.Eof Then
LoadData = False
Else
LoadData = True
rs.MoveFirst
' Get the field contents
x_ID = rs("ID")
x_Username = rs("Username")
x_password = rs("password")
x_First_Name = rs("First_Name")
x_Last_Name = rs("Last_Name")
x_AccesssLevel = rs("AccesssLevel")
x_Create_Date = rs("Create_Date")
End If
rs.Close
Set rs = Nothing
End Function
%>
<%
'-------------------------------------------------------------------------------
' Function AddData
' - Add Data
' - Variables used: field variables
Function AddData()
Dim sSql, rs, sWhere, sGroupBy, sHaving, sOrderBy
' Add New Record
sSql = "SELECT * FROM [Users]"
sSql = sSql & " WHERE 0 = 1"
sGroupBy = ""
sHaving = ""
sOrderBy = ""
If sGroupBy <> "" Then
sSql = sSql & " GROUP BY " & sGroupBy
End If
If sHaving <> "" Then
sSql = sSql & " HAVING " & sHaving
End If
If sOrderBy <> "" Then
sSql = sSql & " ORDER BY " & sOrderBy
End If
Set rs = Server.CreateObject("ADODB.Recordset")
rs.CursorLocation = 3
rs.Open sSql, conn, 1, 2
rs.AddNew
' Field Username
sTmp = Trim(x_Username)
If Trim(sTmp) = "" Then sTmp = Null
rs("Username") = sTmp
' Field password
sTmp = Trim(x_password)
If Trim(sTmp) = "" Then sTmp = Null
rs("password") = sTmp
' Field First_Name
sTmp = Trim(x_First_Name)
If Trim(sTmp) = "" Then sTmp = Null
rs("First_Name") = sTmp
' Field Last_Name
sTmp = Trim(x_Last_Name)
If Trim(sTmp) = "" Then sTmp = Null
rs("Last_Name") = sTmp
' Field AccesssLevel
If (ewCurSec And ewAllowAdmin) = ewAllowAdmin Then ' System admin
sTmp = x_AccesssLevel
If Not IsNumeric(sTmp) Then
sTmp = Null
Else
sTmp = CLng(sTmp)
End If
rs("AccesssLevel") = sTmp
End If
' Field Create_Date
sTmp = x_Create_Date
If IsDate(sTmp) Then
rs("Create_Date") = CDate(sTmp)
Else
rs("Create_Date") = Null
End If
rs.Update
rs.Close
Set rs = Nothing
AddData = True
End Function
%>