ASP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingASP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old September 5th, 2002, 04:03 PM
rosejr rosejr is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Sep 2002
Location: US
Posts: 1 rosejr User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via AIM to rosejr
Question Limiting users views

I have an application that I am trying to restrict what the users can see. This is a free project management app that I found on the web, right now all users can see all projects. I would like to limit the users to only be able to view projects that they are assigned to.

The three tables that i think will apply to this problem are Users, Projects, and UserProjects.

UsersProjects contains 3 fields the UserId from the users table and ProjectId from the project table. and another field called UserProjectId.

Could someone help me with code for a function so that when the user clicks on the project button they will only see the projects that they are assigned to.

If more info is need then please let me know.

Thanks in advanced.

rosejr

Reply With Quote
  #2  
Old September 9th, 2002, 04:50 AM
rdoekes rdoekes is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2002
Location: Strasbourg, France
Posts: 181 rdoekes User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 m 20 sec
Reputation Power: 8
Send a message via AIM to rdoekes Send a message via Yahoo to rdoekes
Lightbulb use SQL joins

Hi rosejr,

This restiction can be done by using joins in your sql statement.

You select the fields from the project table (the ones you need to build the screen) and inner join on the UserProject table to find only projects the user has access to:

SQL Statement:
SELECT Projects.*
FROM Projects
INNER JOIN UserProjects ON
Projects.ProjectID = UserProjects.ProjectID
WHERE UserProjects.UserID = [the UserID]

You only need to now the UserID (and since the user is logged in, you probably have this in a Session Variable) and substitute [the UserID] with this variable and you are ready to go:


You asked for a function:
<%
Function fnSelectProjectsForUser(iUserID)

Dim oCnn, oRs, sSQL

Set oCnn = Server.CreateObject("ADODB.Connection")

oCnn.Open [YourConnectionString]

sSQL = "SELECT Projects.*" & _
" FROM Projects" & _
" INNER JOIN UserProjects ON" & _
" Projects.ProjectID = UserProjects.ProjectID" & _
"WHERE UserProjects.UserID = " & iUserID

Set oRs = oCnn.Execute(sSQL)

If oRs.EOF Then
fnSelectProjectsForUser = 0
Else
fnSelectProjectsForUser = oRs.GetRows
End If

oRs.Close
oCnn.Close

Set oRs = Nothing
Set oCnn = Nothing
End Function
%>

You can call this function with the following code:


<table>
<%
Dim aProjects, i, j

aProjects = fnSelectProjectsForUser(Session("userID"))

If IsArray(aProjects) Then

For i = 0 To UBound(aProjects, 2)
Response.Write "<tr>" & Vbcrlf
For j = 0 To UBound(aProjects, 1)
Response.Write "<td>" & aProjects(j,i) & "</td>" & vbcrlf
Next
Response.write "</tr>" & Vbcrlf
Next
End If
%>
</table>

Hope this will help
__________________
- Rogier Doekes

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingASP Development > Limiting users views


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump




 Free IT White Papers!
 
How to Present Effectively Online
This white paper offers practical and actionable advice on the key steps that any presenter should consider as they plan and execute a Webinar or online meeting.

Request Your Free Technology Downloads!
 
Open Source Security Myths
Open Source Software (OSS) is computer software whose source code is available to the general public with relaxed or non-existent intellectual property restrictions (or arrangement such as the public domain), and is usually developed with the input of many contributors.

Request Your Free Technology Downloads!
 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

Request Your Free Technology Downloads!
 
Scalable, Fault-Tolerant NAS for Oracle - The Next Generation
For several years NAS has been evolving as a storage alternative for Oracle databases, and for good reason: NAS is quite often the simplest, most cost-effective storage approach for Oracle. Learn about the benefits that HP's approach to scalable NAS brings to Oracle environments in this comprehensive white paper.

Request Your Free Technology Downloads!
 
Understanding Web Application Security Challenges
This white paper discusses many common threats and preventive measures for Web application security, and explains what you can do to help protect your organization.

Request Your Free Technology Downloads!
 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 




© 2003-2009 by Developer Shed. All rights reserved. DS Cluster 6 Hosted by Hostway
For more Enterprise Application Development news, visit eWeek