StudentSettings Documentation

Student Settings Controller Documentation

File: /controllers/studentSettings.php

Purpose: Manages student system settings, payment configurations, and administrative controls

Last Updated: December 21, 2024

Total Functions: 3

Lines of Code: ~419

---

๐Ÿ“‹ Overview

The Student Settings Controller handles the configuration and administration of the student management system. It provides functionality for:

Primary Functions

Related Controllers

---

๐Ÿ—„๏ธ Database Tables

Primary Tables (Direct Operations)

Table NamePurposeKey Columns
**studentsetting**Main system settingsstudentsettingid, studentorplayer, paymentsystems1-3, payonemonths-payeightmonths, payyear, welcomemessage, studentaddsubjectid, showdel
**studentsettingpays**Payment plan configurationsstudentsettingpayid, name, countmonths, price, stopping, addtoday, adduserid
**usergroup**User permission groupsusergroupid, groupname, permissions
### Referenced Tables

Table NamePurposeKey Columns
**studentaddsubjects**Student-subject assignmentsstudentaddsubjectid, studentsubjectid, studentsubjectgroupid
**studentsubjects**Available subjectsstudentsubjectid, subjectname, subjectprice
**studentsubjectgroups**Subject group classificationsstudentsubjectgroupid, subjectgroupname, subjectgroupprice
**user**System usersuserid, username, usergroupid
---

๐Ÿ”‘ Key Functions

1. Default Action - Settings Management Interface

Location: Lines 8-107

Purpose: Main settings configuration interface and update processing

Function Signature:

// Triggered when: empty $do
$studentsetting = R::load('studentsetting', 1);
$studentsettingpaysitr = filter_input(INPUT_POST, 'studentsettingpaysitr');

Process Flow:

1. Load main settings record (ID=1)

2. Load user groups for permission assignment

3. Process payment plan iterations

4. Create or update payment plans

5. Update main settings if studentsettingid = 1

6. Load related subject/group data

7. Display settings form

Payment Plan Processing:

for ($i1 = 1; $i1 <= $studentsettingpaysitr; $i1++) {
    $studentsettingpayid = filter_input(INPUT_POST, 'studentsettingpayid' . $i1);
    if (!$studentsettingpayid) {
        $studentsettingpayssave = R::dispense('studentsettingpays'); // New
    } else {
        $studentsettingpayssave = R::load('studentsettingpays', $studentsettingpayid); // Update
    }
}

---

2. pays - Payment Plan Row Generator

Location: Lines 108-113

Purpose: Generate additional payment plan rows for dynamic form building

Function Signature:

// Triggered when: do=pays
$itr = filter_input(INPUT_POST, 'itr');

Process Flow:

1. Receive iteration count from AJAX

2. Assign iteration number to Smarty

3. Display payment row template

4. Return HTML for dynamic insertion

---

3. removeappend - Payment Plan Deletion

Location: Lines 114-120

Purpose: Remove payment plan configurations

Function Signature:

// Triggered when: do=removeappend
$id = filter_input(INPUT_POST, 'id');

Process Flow:

1. Load payment plan by ID

2. Permanently delete (R::trash)

3. Return success status (1)

---

4. studentsPay() - Payment Processing Function

Location: Lines 319-412

Purpose: Generate student payment records and update student payment status

Function Signature:

function studentsPay()

Process Flow:

1. Load all students from database

2. Find student subject details for each student

3. Calculate payment dates and amounts

4. Create payment records in studentspays table

5. Update student records with payment information

6. Handle payment period calculations

Payment Calculation Logic:

$paystartdate = $startdate;
$payenddate = date('Y-m-d', strtotime("+1 month", strtotime($startdate)));
$studentspaymentsystems = R::load('studentspaymentsystems', $student->parentsphone);
$paymonths = $studentspaymentsystems->paymentmonth;
$payprice = $studentspaymentsystems->paymentprice;

---

๐Ÿ”„ Workflows

Workflow 1: Payment System Configuration

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
START: Configure Payment Systems
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
1Load Current Settings
- Load studentsetting record (ID=1)
- Load existing payment plans
- Load user groups for permissions
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
2Process Payment Plans
FOR EACH payment plan iteration:
โ”‚
โ†’ Check if new or existing plan
โ”‚
โ†’ Validate plan data (name, price > 0)
โ”‚
โ†’ Create/Update payment plan record
โ”‚ โ”œโ”€ Set name, months, price, stopping
โ”‚ โ”œโ”€ Set audit fields (user, date)
โ”‚ โ”‚ โ””โ”€ Store in studentsettingpays โ”‚
โ”‚
โ”‚ โ””โ”€โ†’ Continue to next iteration โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
3Update Main Settings
- Set student vs player designation
- Configure payment systems (1-3)
- Set payment periods (1-8 months, yearly)
- Set welcome message
- Configure permissions (edit/delete)
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
4Load Related Data & Display
- Load subject/group information
- Assign data to template
- Display settings interface
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

---

๐ŸŒ URL Routes & Actions

URL ParameterFunction CalledDescription
`do=` (empty)Default actionMain settings configuration interface
`do=pays`Row generatorGenerate additional payment plan rows
`do=removeappend`Delete functionRemove payment plan configuration
`do=excel`Import functionExcel data import (commented out)
### Required Parameters by Action

Main Settings (empty do):

Payment Plans (dynamic):

AJAX Actions:

---

๐Ÿงฎ Calculation Methods

Payment Period Configuration

// Multiple payment period options
$studentsetting->paythreemonths = $paythreemonths;
$studentsetting->paysixmonths = $paysixmonths;
$studentsetting->payeightmonths = $payeightmonths;
$studentsetting->paytwomonths = $paytwomonths;
$studentsetting->payonemonths = $payonemonths;
$studentsetting->payfourmonths = $payfourmonths;
$studentsetting->payyear = $payyear;

Payment System Selection

// Ensure at least one payment system is active
if (!$paymentsystems1 && !$paymentsystems2 && !$paymentsystems3) {
    $paymentsystems1 = 1; // Default to system 1
}

Permission Array Processing

// Convert permission arrays to comma-separated strings
$studentsetting->showpayedit = 'aa,' . implode(",", $showpayedit);
$studentsetting->showpaydel = 'aa,' . implode(",", $showpaydel);

---

๐Ÿ”’ Security & Permissions

User Permission Integration

$usergroup = R::getAll('select * from usergroup where 1');
$smarty->assign("usergroup", $usergroup);

Input Validation

Audit Trail

- addtoday - Creation timestamp

- adduserid - Creating user ID

- updatetoday - Last update timestamp

- updateuserid - Last updating user ID

---

๐Ÿ“Š Performance Considerations

Database Optimization

1. Single Settings Record: Uses ID=1 for main settings (singleton pattern)

2. Efficient Queries: Direct loads by primary key

3. Minimal Joins: Simple table relationships

Memory Management

Potential Issues

---

๐Ÿ› Common Issues & Troubleshooting

1. Settings Not Saving

Issue: Changes to settings don't persist

Cause: studentsettingid != 1 check fails

Debug:

// Verify settings ID
if($studentsettingid == 1) {
    echo "Settings will be saved";
} else {
    echo "Settings ID: " . $studentsettingid . " - must be 1";
}

2. Payment Plans Not Creating

Issue: Payment plans don't save despite form submission

Cause: Validation fails on name or price

Fix:

// Check validation logic
if (!$name || $price < 1) {
    echo "Validation failed - Name: " . $name . " Price: " . $price;
    continue;
}

3. Permission Arrays Empty

Issue: Permission settings reset to default

Cause: Array implode on non-array data

Fix:

// Ensure arrays exist before imploding
$showpayedit = isset($_POST['showpayedit']) && is_array($_POST['showpayedit']) 
    ? $_POST['showpayedit'] : [];

---

๐Ÿงช Testing Scenarios

Test Case 1: Basic Settings Update

1. Navigate to student settings
2. Modify payment systems and periods
3. Update welcome message
4. Save settings
5. Verify changes persist after reload

Test Case 2: Payment Plan Management

1. Add new payment plan with valid data
2. Verify plan appears in list
3. Edit existing payment plan
4. Delete payment plan
5. Confirm deletion successful

Test Case 3: Permission Configuration

1. Set edit/delete permissions for user groups
2. Login as different user group
3. Verify permission enforcement
4. Test with multiple user groups

---

๐Ÿ“š Related Documentation

---

Documented By: AI Assistant

Review Status: โœ… Complete

Next Review: When major changes occur