LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-24-2008, 09:36 AM   #1
bagends
LQ Newbie
 
Registered: Mar 2008
Posts: 2

Rep: Reputation: 0
PHP / MYSQL - Employee / Customer Login and Permission


Hey guys, I need some advice on the best way to set this up. The project is being done in mysql and php. It's a really simple question, but I can't decide.

I need to have a user system where employees and customers can log in. Both groups need to have different restrictions based on what they can do / view on the site. Each customer will also be able to set up "sub-customers", their employees, with access to anything in which they (the "top-level" customer) are currently granted access. Also, unlike employees, customers will only be able to access files directly related to that customer.

I was considering a mysql database setup something like this:

PHP Code:
[employee.table]
  
employee-id
  employee
-name
  etc
...

## Example Data
1Brenda Jones, ...

[
customer.table]
  
customer-id
  customer
-company
  customer
-code

## Example Data
1Widgets R UsC001
2
Widgets CoD005

[user.table]
  
user-id
  user
-name
  user
-pass
  user
-type
  user
-restriction

## Example Data
1John Smith, ***, customerC001
2
Brenda Jones, ***, employee''

[userperm.table]
  
user-id
  program
  perm

## Example Data
1usersedit
2
userview 
Of course, this isn't the exact way, just a rough idea. I know I'll need some way to link employees in the user table to the employ table.
I'm trying to keep it simple, avoid data redundancy, etc...
I don't know what the best way to accomplish this would be, even considered two seperate user tables (customer-users and employee-users.) Another requirement is that any action done needs to be associated with the user that did it (e.g. if a user is added, who did it?)

Any ideas? Thank you.
 
Old 03-24-2008, 07:49 PM   #2
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,359

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
sounds like you need a parent_id column on the customer table, contains the id of the customer that created the 'sub-customer'.
For a 'top-level' customer, possibly use a special value eg zero, or add a row for admin user and use their id for top-customers. (of course you'll need to add zero for the admins parent_id).
In SQL terms, that's prob simpler than having top-level customers have their own id as their parent id.
It does sound like separate table for actual employees would be a good idea.
You can have audit tables for tracking actions ie cols for who/what/when etc.
If you've got 5.0 or better, you may be able to use a DB trigger.
 
Old 03-24-2008, 08:18 PM   #3
BrianK
Senior Member
 
Registered: Mar 2002
Location: Los Angeles, CA
Distribution: Debian, Ubuntu
Posts: 1,334

Rep: Reputation: 51
Not sure if I follow the question... it sounds like you want one user table but then be able to determine if a user is an employee or not. is that right?

if that's the case, then you could have one user table with a tinyint (or bool) column "is_employee".
you could also have an enum column "user_type" with values "EMPLOYEE,CUSTOMER"
you could also have a user table with general user info, then an employee column with specific employee data, one field of which will be a reference to the user_id, so you can do something like :

SELECT empoyee_spefic_thing, user_general_thing, <other_fields> FROM user,employee WHERE empoyee_user_ref = user_id AND employee_name = "Bob Smith";

does that help?

Last edited by BrianK; 03-24-2008 at 08:37 PM.
 
Old 03-26-2008, 09:09 AM   #4
bagends
LQ Newbie
 
Registered: Mar 2008
Posts: 2

Original Poster
Rep: Reputation: 0
Thanks.

Thanks guys, I appreciate the good advice. It does help a bit. Sorry it took me so long to respond back.

--Bagends
 
  


Reply



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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP login script using mysql issue ACDII Linux - Server 4 01-20-2007 04:58 AM
apache mysql php remote login? tripmix Linux - Newbie 8 01-16-2007 07:24 PM
SQUID login with PHP,MySQL ujjwal_wadhawan Linux - Software 0 03-20-2006 07:12 AM
MySQl account login, PHP agallant Programming 2 07-16-2004 11:01 AM
PHP and MySQL - login elapse time Manuel-H Linux - General 0 08-08-2003 08:00 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:24 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration