User Documentation
User Controller Documentation
File: /controllers/userController.php
Purpose: Manages system users, accounts, permissions, and authentication
Last Updated: December 19, 2024
Total Functions: 12
Lines of Code: ~940
---
๐ Overview
The User Controller is the core component for managing user accounts and access control in the ERP system. It handles:
- โข Creating and editing user accounts
- โข User authentication and session management
- โข User group assignments and permissions
- โข Store, branch, and save assignments
- โข Employee integration
- โข Security settings and access control
- โข Saudi electronic invoice settings
- โข Multi-factor authentication (questions/answers)
- โข License limitations and user blocking
Primary Functions
- โ Create new user accounts
- โ Edit existing user accounts
- โ Soft delete/activate users
- โ View users by group or all users
- โ Assign user groups and permissions
- โ Manage store and branch access
- โ Set save (cash register) access
- โ Employee account integration
- โ Project and bank account access
- โ Security question/answer setup
- โ File upload for user documents
- โ Saudi electronic invoice configuration
Related Controllers
- โข usergroupController.php - User group management
- โข sellbillController.php - Sales operations
- โข buyBillController.php - Purchase operations
- โข storeController.php - Store management
- โข branchController.php - Branch management
- โข employeeController.php - Employee management
- โข bankController.php - Bank management
- โข projectController.php - Project management
- โข saveController.php - Cash register management
---
๐๏ธ Database Tables
Primary Tables (Direct Operations)
| Table Name | Purpose | Key Columns | |
|---|---|---|---|
| **user** | Main user accounts | userid, username, password, employeename, usergroupid, saveid, userstoreid, conditions | |
| **usergroup** | User roles/groups | usergroupid, usergroupname, permissions | |
| **esaudiusersetting** | Saudi e-invoice config | userid, licensetype, licensenumber, companytaxregistrationnumber |
| Table Name | Purpose | Relationship | |
|---|---|---|---|
| **save** | Cash registers/safes | user.saveid, user.saveids | |
| **store** | Warehouses/branches | user.userstoreid, user.storeids | |
| **branch** | System branches | user.branchid | |
| **project** | Business projects | user.projectids | |
| **bank** | Bank accounts | user.bankids | |
| **charities** | Charity organizations | user.charityids |
| Table Name | Purpose | Key Columns | |
|---|---|---|---|
| **employee** | Employee master data | empid, employeeName, salary | |
| **programsettings** | System configuration | programsettingsid, saudielectronicinvoice |
๐ง Key Functions
1. add() - Create New User
Location: Line 388
Purpose: Create a new user account with full permissions and settings
Function Signature:
function add()
Parameters (via $_POST):
- โข
username- Login username - โข
password- User password - โข
employeename- Display name - โข
usergroupid- User group/role ID - โข
saveid- Default cash register ID - โข
userstoreid- Allowed stores (comma-separated) - โข
userstoreidDef- Default store ID - โข
awardrate- Commission rate (float) - โข
searchinonesave- Search limitation flag - โข
branchid- Branch assignment - โข
question- Security question - โข
answer- Security answer - โข
addEmployeeToo- Create employee record flag - โข
salary- Employee salary - โข
projectids- Accessible projects array - โข
bankids- Accessible banks array - โข
saveids- Accessible cash registers array - โข
storeids- Accessible stores array - โข
charityids- Accessible charities array
Process Flow:
Key Features:
- โข License limitation checking
- โข Employee account creation
- โข File upload handling
- โข Array processing for multi-select permissions
- โข Saudi electronic invoice setup
2. showByUsergroupId() - Display Users by Group
Location: Line 579
Purpose: Show users filtered by user group
Parameters:
- โข
usergroupId- Group ID to filter by
3. showAll() - Display All Users
Location: Line 596
Purpose: Display all users except current session user
4. delete() - Soft Delete User
Location: Line 612
Purpose: Temporarily disable/enable user accounts
Parameters:
- โข
conditions- Current status (0=active, 1=disabled) - โข
userid- User ID to modify
5. deleteFinaly() - Permanent Delete
Location: Line 634
Purpose: Permanently remove user from database
6. edit() - Load User for Editing
Location: Line 646
Purpose: Load user data and prepare for editing
Returns: User object with exploded array fields
7. update() - Update User Account
Location: Line 676
Purpose: Update existing user account with new settings
Key Features:
- โข Session update for current user
- โข Permission validation
- โข User login validation
8. CURL_IT2() - Internal API Call
Location: Line 904
Purpose: Make internal cURL requests for employee creation
---
๐ Business Logic Flow
User Creation Workflow
Permission Management System
- โข Store Access: Primary store + additional stores
- โข Save Access: Default save + additional cash registers
- โข Project Access: All projects (0) or specific projects
- โข Bank Access: All banks (0) or specific banks
- โข Branch Access: Single branch or all branches (-1)
---
โ ๏ธ Common Issues
PHP 8.2 Compatibility Issues
Issue: String concatenation in salary/employee creation
// โ
FIXED: Line 446 - Employee creation with proper type casting
$empid = (int) CURL_IT2(array('empName' => $userName, 'empSalary' => $salary), 'employeeController.php?do=add');
Security Considerations
- โข Password Storage: Plain text passwords (consider hashing)
- โข Session Management: Updates session for current user edits
- โข License Enforcement: Blocks user creation beyond license limits
- โข Access Control: Multi-level permission system
User Limitations
- โข Maximum users controlled by
$_SESSION['lic_userno'] - โข Blocked users have
blockedByLimits = 1 - โข Soft delete preserves data integrity
---
๐ Dependencies
Required DAOs
- โข
UserMySqlDAO- User database operations - โข
UserMySqlExtDAO- Extended user queries - โข
UsergroupMySqlDAO- User group operations - โข
SaveMySqlDAO- Cash register operations - โข
StoreMySqlDAO- Store operations - โข
BranchMySqlDAO- Branch operations - โข
BankMySqlDAO- Bank operations - โข
ProjectMySqlDAO- Project operations - โข
EmployeeMySqlDAO- Employee operations
Required Files
- โข
../public/impOpreation.php- Core operations - โข
../public/authentication.php- Session validation - โข
../library/uploadImages.php- File upload handling - โข
initiateStaticSessionCommingWithCurl.php- cURL session management
External Systems
- โข Employee management system (via CURL)
- โข Saudi ZATCA e-invoice system
- โข File storage system for user documents
---
๐ Performance Notes
- โข License checking on every user creation
- โข Multi-table permission queries
- โข File upload processing
- โข Session validation on protected routes
- โข Array processing for comma-separated permissions
The User Controller is critical for system security and should be thoroughly tested for permission leaks and access control vulnerabilities.