Click to See Complete Forum and Search --> : Showing images depending on access level?


stevem2004
06-18-2004, 08:36 AM
If I have a Logon page which checks the username and password from a Access DB and then depending on the access level send the user to particular default page. See code below

Session("blnIsUserGood") = True
Session("userLevel") = rsCheckUser("accesslevel")

If rsCheckUser("accesslevel") = "0" Then Response.Redirect"default_view.asp?name=" &strUserName End If
If rsCheckUser("accesslevel") = "1" Then Response.Redirect"default_create.asp?name=" &strUserName End If
If rsCheckUser("accesslevel") = "2" Then Response.Redirect"default_yield.asp?name=" &strUserName End If
If rsCheckUser("accesslevel") = "3" Then Response.Redirect"default_esol.asp?name=" &strUserName End If
If rsCheckUser("accesslevel") = "4" Then Response.Redirect"default_auth.asp?name=" &strUserName End If
If rsCheckUser("accesslevel") = "5" Then Response.Redirect"default_admin.asp?name=" &strUserName End If

Can this be modified, so that I can have 1 default page, but will display various images depending on their access level?

Any help would be appreciated.
Steve

buntine
06-18-2004, 10:53 AM
Yer, you just need to use an If statement tree.

Dim intUserLevel, arrImages(3)
intUserLevel = CInt(Session("userLevel"))

If intUserLevel = 0 Then
'| Fill array with correct images.
arrImages(0) = "imageOne.jpg"
arrImages(1) = "imageTwo.jpg"
arrImages(2) = "imageThree.jpg"
ElseIf intUserLevel = 1 Then
arrImages(0) = "imageOne.gif"
arrImages(1) = "imageTwo.gif"
arrImages(2) = "imageThree.gif"
ElseIf intUserLevel = 2 Then
arrImages(0) = "imageSix.jpg"
arrImages(1) = "imageSeven.jpg"
arrImages(2) = "imageEight.jpg"
Else
arrImages(0) = "imageTen.jpg"
arrImages(1) = "imageEleven.jpg"
arrImages(2) = "imageTwelve.jpg"
End If

Dim i

'| Display each image in the array.
For i = 0 To UBound(arrImages) - 1
Response.Write ("<img src=""" & arrImages(i) & """ alt=""image"" border=""0"" />")
Next

That will just create an array and populate it with different images depending on the access level of the current user.

Regards,
Andrew Buntine.

russell
06-18-2004, 10:57 AM
Sure. You are already storing the access level in a session variable, so use that wherever you need it. After they log in, redirect to the target page. On that page:

With Response
Select Case clng(Session("AccessLevel"))

Case 0
.Write "<img src=""viewImg"">"
Case 1
.Write "<img src=""createImg"">"
Case 2
.Write "<img src=""yieldImg"">"
...

Case Else
.Write "You must firsy log in to view this page"
.Redirect "login.asp"
End Select

End With

You could even put the image paths in a database, and load them from a recordset:

sql ="SELECT img FROM Default_Images WHERE accessLevel = " & accessLevel"

buntine
06-18-2004, 11:04 AM
True, a Select-Case tree would be more suitable.

stevem2004
06-21-2004, 08:12 AM
Many Thanks everybody

Quality help as usual