๐Ÿ“š ERP Documentation Viewer

Beautiful, colorful documentation for your ERP system

Properties Controller Documentation

File: /controllers/propertiesController.php

Purpose: Manages system properties, permissions, and user group access rights

Last Updated: December 20, 2024

Total Functions: 4

Lines of Code: 228

---

๐Ÿ“‹ Overview

The Properties Controller is a system administration module that handles application properties, permissions, and user group access control. It provides:

Primary Functions

Related Controllers

---

๐Ÿ—„๏ธ Database Tables

Primary Tables (Direct Operations)

Table NamePurposeKey Columns
**properties**System property definitionspropertyid, propertyname, propertyname_en, propertyurl, propertyparent, propertydefault
**relusergroupproperties**User group property permissionspropertyid, usergroupid, propertyvalue
**usergroup**User group definitionsusergroupid, usergroupname, description
---

๐Ÿ”‘ Key Functions

1. Default Action / Property Management - Property Administration Interface

Location: Line 73

Purpose: Display property management interface with existing properties

Process Flow:

1. Load all existing properties via loadproperity()

2. Assign property data to Smarty template

3. Display via propertiesview/add.html

4. Provide interface for adding new properties

Function Signature:

// Triggered when: $do is empty (default action)
$propertiesData = loadproperity();
$smarty->assign("propertiesData", $propertiesData);

Features:

---

2. add() - Create New System Property

Location: Line 84

Purpose: Add new system property with automatic user group permission setup

Function Signature:

elseif ($do == "add")
// Called via: POST request with property data

Process Flow:

1. Validate and extract POST data

2. Create new property record

3. Query all existing user groups

4. Auto-assign property to all user groups with default value

5. Handle success/error redirection

Property Creation Logic:

$myProperities->propertyname = $propertyName;
$myProperities->propertyparent = $propertyParent;
$myProperities->propertydefault = $propertyDefault;
$myProperities->propertyurl = $propertyurl;
$myProperities->propertyname_en = $propertyname_en;
$propertyId = $myProperitiesRecord->insert($myProperities);

Auto-Assignment Process:

foreach ($usergroupData as $usergroup) {
    $myRelusergroup->propertyid = $propertyId;
    $myRelusergroup->usergroupid = $usergroupId;
    $myRelusergroup->propertyvalue = $propertyDefault;
    $myRelusergroupRecord->insert($myRelusergroup);
}

---

3. show() - Property Listing View

Location: Line 106

Purpose: Display all properties in listing format

Process Flow:

1. Query all properties from database

2. Load property data for form population

3. Display via propertiesview/add.html (same template as default)

---

4. edit() / update() - Property Modification

Location: Line 118 (edit), Line 129 (update)

Purpose: Edit existing property details

Edit Process Flow:

$theid = $_GET['id'];
$getallpropwithid = $myProperitiesRecord->load($theid);
$smarty->assign("getallpropwithid", $getallpropwithid);

Update Process Flow:

$newprop = new Propertie;
$newprop->propertyid = $idprp;
$newprop->propertyname = $nameprp;
$newprop->propertyurl = $urlprp;
$myProperitiesRecord->updates($newprop);

---

๐Ÿ”„ Workflows

Workflow 1: New Property Creation

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
START: Add New Property
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
1Property Definition
- Property name (Arabic)
- Property name (English)
- Property URL/controller
- Parent property (hierarchy)
- Default value (0/1)
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
2Property Creation
INSERT INTO properties:
โ”‚
โ†’ propertyname
โ†’ propertyname_en
โ†’ propertyurl
โ†’ propertyparent
โ”‚ โ””โ”€โ†’ propertydefault โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
3Auto-Assignment to User Groups
FOR EACH existing user group:
โ”‚
โ†’ Create relusergroupproperties record
โ†’ Set propertyvalue = propertydefault
โ”‚ โ””โ”€โ†’ Link property to user group โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
4Complete
- Property created and available
- All user groups have default access
- Property appears in permission matrix
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

---

Workflow 2: Property Permission Management

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
START: Manage Property Permissions
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
1Load Property Matrix
- Query all properties
- Query all user groups
- Load current permission assignments
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
2Display Permission Matrix
Properties (rows) ร— User Groups (columns)
โ”‚
โ†’ Show current permissions (0/1)
โ†’ Enable bulk editing
โ”‚ โ””โ”€โ†’ Highlight inherited permissions โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
3Permission Updates
UPDATE relusergroupproperties:
โ”‚
โ†’ Change propertyvalue (0 = deny, 1 = allow)
โ†’ Apply to multiple groups if bulk operation
โ”‚ โ””โ”€โ†’ Validate permission hierarchy โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

---

๐ŸŒ URL Routes & Actions

URL ParameterFunction CalledDescription
`do=` (empty)Default actionProperty management interface
`do=add``add()`Create new property
`do=show``show()`List all properties
`do=edit``edit()`Edit property form
`do=update``update()`Update property data
`do=sucess`Success pageOperation completed
`do=error`Error pageOperation failed
### Required Parameters by Action

Add Property (do=add):

Edit Property (do=edit):

Update Property (do=update):

---

๐Ÿ”’ Security & Permissions

Access Control

// Authentication required for all operations
// include_once("../public/authentication.php");

Input Sanitization

Permission Inheritance

---

๐Ÿ“Š Performance Considerations

Database Optimization Tips

1. Indexes Required:

- properties(propertyparent)

- relusergroupproperties(propertyid, usergroupid)

- usergroup(usergroupid)

2. Query Optimization:

- Batch inserts for user group assignments

- Efficient property hierarchy queries

- Minimal database calls in loops

Memory Management

---

๐Ÿ› Common Issues & Troubleshooting

1. Property Auto-Assignment Failures

Issue: New properties not assigned to all user groups

Cause: Transaction failures or missing user groups

Debug:

// Check user group count
$usergroupData = $myUserGroupRecord->queryAll();
echo "User groups found: " . count($usergroupData);

// Verify assignments after creation
$assignments = $myRelusergroupRecord->queryByPropertyId($propertyId);

2. Property Hierarchy Issues

Issue: Parent-child relationships not working

Cause: Circular references or invalid parent IDs

Debug:

-- Check for circular references
WITH RECURSIVE prop_tree AS (
  SELECT propertyid, propertyparent, 1 as level
  FROM properties WHERE propertyparent = 0
  UNION ALL
  SELECT p.propertyid, p.propertyparent, pt.level + 1
  FROM properties p
  JOIN prop_tree pt ON p.propertyparent = pt.propertyid
  WHERE pt.level < 10
)
SELECT * FROM prop_tree WHERE level > 5;

3. Permission Matrix Performance

Issue: Slow loading with many properties/groups

Cause: N+1 query problems or missing indexes

Solution:

---

๐Ÿงช Testing Scenarios

Test Case 1: Property Creation

1. Access property management interface
2. Fill out new property form
3. Submit and verify success redirect
4. Check property appears in listing
5. Verify all user groups have default permission

Test Case 2: Property Hierarchy

1. Create parent property
2. Create child property with parent reference
3. Verify hierarchy displays correctly
4. Test permission inheritance

Test Case 3: Permission Management

1. Access permission matrix
2. Change property permissions for user group
3. Verify changes saved correctly
4. Test user access with new permissions

Test Case 4: Multi-language Support

1. Create property with Arabic and English names
2. Verify both names stored correctly
3. Test display in different language contexts

---

๐Ÿ“š Related Documentation

---

Documented By: AI Assistant

Review Status: โœ… Complete

Next Review: When major changes occur

โ†‘