---
description: Staff management system with protected admin2 account
---

# Staff Management System Implementation

## Objective
Create user/staff management with admin2 as protected system administrator.

## Implementation

### 1. Staff Management Page
**File:** `/__admin__/manage-staff.php`

**Features:**
- Create admin/staff/sales user accounts
- View all staff members in table
- Delete staff accounts
- Protect admin2 from deletion

### 2. User Roles

**Admin (Full Access):**
- Complete control over system
- Can create/edit/delete everything
- Access to all features

**Staff (Limited Access):**
- Manage products and orders
- Cannot access settings
- Cannot delete users

**Sales Person:**
- View orders and customers
- Track sales
- Limited edit permissions

### 3. Protected System Admin

**Username:** admin2
- Cannot be deleted
- Shows "System Admin" badge
- Lock icon displayed
- Attempting deletion shows error message

### 4. Create User Form

**Required Fields:**
- Username
- Full Name
- Email
- Password (min 6 chars)
- Role selection

**Optional Fields:**
- Phone number

**Process:**
1. Creates user in `users` table with role
2. Creates user details in `user_details` table
3. Success message and refresh

### 5. Delete User Functionality

**Checks:**
1. Verify not admin2
2. Delete from `user_details` table
3. Delete from `users` table
4. Redirect with success message

**Protection:**
```php
if ($adminData['username'] == 'admin2') {
    $_SESSION['error'] = "Cannot delete system administrator!";
}
```

## User Interface

**Table Columns:**
- Username (with System Admin badge if admin2)
- Full Name
- Email
- Phone
- Role (color-coded badge)
- Created Date
- Action (Delete button - disabled for admin2)

**Role Badge Colors:**
- Admin: Red
- Staff: Blue
- Sales: Cyan

## Sidebar Integration

**Location:** System > Staff Management

## Status: ✅ COMPLETE
Admin2 is protected and staff management fully functional!
