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, 03: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, 03: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!
 
Create the Optimal Architecture for your Critical Applications
Warburton's the largest independently owned bakery in the UK faced a number of difficult challenges in providing the most robust yet efficient IT infrastructure for their organization's success. IBM's services combined with their xSeries servers created the perfect platform for their SAP environment with sufficient flexibility, and did so in very time effective fashion.

Request Your Free Technology Downloads!
 
Five Best Practices for Deploying a Successful Service-Oriented Architecture
This white paper describes the benefits you can expect with SOA, and how IBM can help take your business there.

Request Your Free Technology Downloads!
 
Gartner Magic Quadrant for Application Delivery Controllers
Gartner summarizes its view on Application Delivery Controllers, evaluates strengths and weaknesses of solutions, and provides Magic Quadrant reporting for a quick comparison across all vendors. Learn from Gartner how you can benefit from an all-in-one device like Citrix NetScaler that delivers the highest levels of availability, performance and security.

Request Your Free Technology Downloads!
 
Knowledge is Power
What you don't know can hurt you, and is likely costing you money and increasing your security risks during an era of scarce resources. This white paper proposes six key strategies that enterprise security managers can use to improve their network defense posture.

Request Your Free Technology Downloads!
 
Rationalizing the Multi-Tool Environment
The rationalized multi-tool approach is flexible, scalable and cost effective. It provides the necessary input to the IT service management business processes. It preserves prior investments in monitoring tools, empowers technologists to select the best tools with which to do their jobs, and enhances effective response to incidents.

Request Your Free Technology Downloads!
 

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




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