Student Documentation

Student Controller Documentation

File: /controllers/studentController.php

Purpose: Manages student registration, enrollment, and payment tracking for educational/sports academy systems

Last Updated: December 21, 2024

Total Functions: 4

Lines of Code: ~510

---

๐Ÿ“‹ Overview

The Student Controller is a comprehensive student management system designed for educational institutions or sports academies. It provides complete student lifecycle management including registration, enrollment in subject groups, payment tracking, and QR code generation for student identification. The controller handles:

Primary Functions

Related Controllers

---

๐Ÿ—„๏ธ Database Tables

Primary Tables (Direct Operations)

Table NamePurposeKey Columns
**students**Student master recordsid, studentname, studentnumber, idnumber, studentphone, clientid, branchid, del
**client**Billing/payment clientsclientid, clientname, clientphone, studentid, typeclientid, priceTypeId
**studentaddsubjects**Subject enrollmentstudentaddsubjectid, studentid, studentsubjectid, studentsubjectgroupid
**studentaddsubjectdetails**Enrollment detailsstudentid, studentsubjectid, studentsubjectgroupid, studentaddsubjectid
### Reference Tables

Table NamePurposeKey Columns
**studentsubjects**Available subjectsstudentsubjectid, subjectname
**studentsubjectgroups**Subject groupsstudentsubjectgroupid, subjectgroupname, subjectgroupprice
**studentsetting**System configurationstudentsettingid, studentaddsubjectid
**studentspays**Payment recordsstudentspayid, studentid, paystartdate, payenddate, del
**branch**Organization branchesbranchId, branchName
**user**System usersuserid, employeename
---

๐Ÿ”‘ Key Functions

1. Default Action - Student Registration Interface

Location: Line 9

Purpose: Display the student registration form with configuration and branch data

Process Flow:

1. Load system settings for default subject enrollment

2. Get subject and group information for display

3. Load available branches for selection

4. Display registration form template

5. Generate QR codes for existing students (commented out bulk generation)

Template Variables:

QR Code Generation (Commented):

// Bulk QR code generation for existing students
// $studentdata = R::findAll('students');
// foreach($studentdata as $student){
//     $studentid = $student->id;
//     $PNG_TEMP_DIR = "../views/default/images/studentsparcode/";
//     $filename = $PNG_TEMP_DIR.$studentid.'student.png';
//     $url = 'http://' . $_SERVER['HTTP_HOST'] . '...' . $studentid;
//     QRcode::png($url, $filename, 'L', 9, 2);     
// }

---

2. show - Student Display Interface

Location: Line 39

Purpose: Display student management interface with filtering and data tables

Process Flow:

1. Check authentication

2. Load system configuration

3. Set up display mode (normal or pending approval)

4. Load branch data for filtering

5. Display management interface with AJAX data tables

Display Modes:

---

3. edit - Student Edit Interface

Location: Line 58

Purpose: Display student editing form with pre-populated data

Process Flow:

1. Check authentication

2. Get student ID from request

3. Load student data for editing

4. Load available branches

5. Display edit form with student information

---

4. savedata() - Student Data Processing

Location: Line 83

Purpose: Handle student registration and updates with comprehensive data management

Function Signature:

function savedata()

Process Flow:

1. Extract Form Data:

- Personal information (name, phone, address, etc.)

- Parent/guardian information (supports 2 parents)

- Academic information (subjects, payment details)

- Branch and identification information

2. Handle Image Upload:

- Process student photo upload

- Resize to 300x300 pixels

- Handle updates vs new uploads

3. Database Operations:

- Create or update student record

- Create or update associated client record

- Handle subject enrollment if specified

- Generate QR code for student identification

4. Subject Enrollment:

- Link student to subject groups

- Create enrollment detail records

- Update subject group student lists

5. QR Code Generation:

- Generate QR code linking to student detail page

- Save as PNG file for printing/display

Key Variables:

$studentname = filter_input(INPUT_POST, 'studentname');
$idnumber = filter_input(INPUT_POST, 'idnumber');
$studentphone = filter_input(INPUT_POST, 'studentphone');
$parentsname = filter_input(INPUT_POST, 'parentsname');
$parentsphone = filter_input(INPUT_POST, 'parentsphone');
$parentsjob = filter_input(INPUT_POST, 'parentsjob');
$parentsname2 = filter_input(INPUT_POST, 'parentsname2'); // Second parent
$studentaddsubjectid = filter_input(INPUT_POST, 'studentaddsubjectid');
$clientid = filter_input(INPUT_POST, 'clientid');

Client Integration Logic:

if (!$clientid) {
    // Create new client record for billing
    R::exec("INSERT INTO `client`(`clientname`, `clientaddress`, `clientphone`, 
             `clientdate`, `userid`, `branchId`, `clientStoreIds`, `typeclientid`, 
             `priceTypeId`, `studentid`) VALUES 
             ('$studentname', '$studentaddress', '$studentphone','$date', 
              $userid, $branchid, '-10', ',-20,', -1, $studentid)");
} else {
    // Update existing client
    R::exec("UPDATE `client` SET `clientname`='$studentname',
             `clientaddress`='$studentaddress',`conditions`=0,
             `clientphone`='$studentphone',`branchId`=$branchid 
             WHERE clientid = $clientid");
}

QR Code Generation:

if ($students->del == 0 || $agrees == 5) {
    $PNG_TEMP_DIR = "../views/default/images/studentsparcode/";
    $filename = $PNG_TEMP_DIR.$studentid.'student.png';
    $url = 'http://' . $_SERVER['HTTP_HOST'] . explode('controllers', $_SERVER['REQUEST_URI'])[0] . 
           'controllers/studentControllerAjax.php?do=detailstudent&studentid=' . $studentid;
    QRcode::png($url, $filename, 'L', 9, 2);    
}

---

5. showajax() - Main Data Table Provider

Location: Line 225

Purpose: Provide AJAX data for student management DataTables with advanced filtering

Function Signature:

function showajax()

Process Flow:

1. Parse DataTables parameters and filters

2. Build dynamic query with multiple filter conditions

3. Apply search across multiple fields

4. Execute query with pagination and sorting

5. Format data for display including payment status

6. Return JSON response for DataTables

Filter Options:

Payment Status Logic:

$date = date('Y-m-d');
$studentspays = R::count('studentspays',"studentid = ? and del < 2 and payenddate > '$date'",[$row['id']]);
$studentpaylast = R::findone('studentspays',"studentid = ? and del < 2 order by id desc",[$row['id']]);

if ($studentspays > 0 && $row["del"] < 2) {
    $sub_array[] = '<a href="javascript:;" data-id="'. $row["id"] .'" 
                    type="button" class="btn btn-default btn-lm studentspaysend">ุงู„ูƒูˆุฏ</a>';
} else {
    $sub_array[] = 'ู„ุง ูŠูˆุฌุฏ';
}

Action Buttons:

if($row["del"] < 2){  
    $sub_array[] = '<a href="studentController.php?do=edit&id='. $row["id"] .'" 
                    type="button" class="btn btn-default btn-lg editicon"></a>';
    $sub_array[] = '<a href="javascript:;" data-id="'. $row["id"] .'" 
                    data-controll="studentController" type="button" 
                    class="btn btn-default btn-lg deleteicon removecontroller"></a>';
} else if($row["del"] == 5){
    $sub_array[] = '<a href="studentController.php?do=edit&id='. $row["id"] .'" 
                    type="button" class="btn btn-default btn-lg editicon"></a>';
    $sub_array[] = 'ุงู†ุชุธุงุฑ ุงู„ู‚ุจูˆู„ ';
}

---

6. showajax2() - Pending Approval Data Provider

Location: Line 355

Purpose: Provide data for students pending approval (del = 5 status)

Similar to showajax() but filters specifically for students.del = 5

---

7. removecontroller() - Student Deletion Handler

Location: Line 485

Purpose: Handle student soft deletion with cascade operations

Function Signature:

function removecontroller()

Process Flow:

1. Get student ID from POST data

2. Set student deletion status (del = 2)

3. Update related records:

- Set client conditions = 1

- Set subject enrollment details del = 3

- Set exam values del = 3

- Set payments del = 3

4. Return success/failure status

Cascade Deletion Logic:

$tables = R::load('students',$id);
$tables->del = 2;
$tables->deltoday = $today;
$tables->deluserid = $userid;

R::store($tables);
R::exec("UPDATE `client` SET `conditions`= 1 WHERE studentid = '" . $id . "' ");
R::exec("UPDATE `studentaddsubjectdetails` SET `del`= 3, `deltoday`= '$today', 
         `deluserid`= $userid WHERE studentid = '" . $id . "' ");
R::exec("UPDATE `studentsexamsval` SET `del`= 3, `deltoday`= '$today', 
         `deluserid`= '$userid' WHERE studentid = '" . $id . "' ");
R::exec("UPDATE `studentspays` SET `del`= 3, `deltoday`= '$today', 
         `deluserid`= '$userid' WHERE studentid = '" . $id . "' ");

---

๐Ÿ”„ Workflows

Workflow 1: Student Registration Process

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
START: New Student Registration
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
1Collect Student Information
- Personal details (name, phone, ID, address)
- Academic info (nickname, school, classroom)
- Sports preferences (favorite team/player)
- Parent/guardian information (up to 2 parents)
- Branch assignment
- Photo upload
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
2Process Image Upload
- Validate uploaded image file
- Resize to 300x300 pixels
- Save to students directory
- Handle update vs new upload scenarios
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
3Create Student Record
- Insert into students table
- Set initial status (del = 0 for new, del = 1 update)
- Record creation timestamp and user
- Store all personal and academic information
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
4Create Associated Client Record
IF new student (no existing clientid):
โ”‚
โ†’ Insert new client record for billing
โ†’ Link client to student via studentid
โ†’ Set default client type and price type
โ”‚ โ””โ”€โ†’ Update student record with clientid โ”‚
ELSE:
โ”‚
โ”‚ โ””โ”€โ†’ Update existing client information โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
5Handle Subject Enrollment
IF studentaddsubjectid provided:
โ”‚
โ†’ Load subject enrollment record
โ†’ Add student to enrollment student list
โ†’ Create studentaddsubjectdetails record
โ”‚ โ””โ”€โ†’ Link student to subject and group โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
6Generate QR Code
IF student is active or pending approval:
โ”‚
โ†’ Generate URL to student detail page
โ†’ Create QR code PNG file
โ†’ Save to studentsparcode directory
โ”‚ โ””โ”€โ†’ File named: {studentid}student.png โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
7Return Success/Failure
- Return 1 for success, 0 for failure
- Student ready for payment and service access
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Workflow 2: Student Data Display with Filtering

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
START: Student Data Request (AJAX)
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
1Parse Request Parameters
- Date range filters (start_date, end_date)
- Student ID filter (data1)
- Branch filter (data3)
- Deletion status filter (del)
- DataTables parameters (pagination, search, order)
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
2Build Dynamic Query
- Start with base query joining students/user/branch
- Add student ID filter if specified
- Add deletion status filter (default del < 2)
- Add branch filter if specified
- Add date range filter if specified
- Add general search across multiple fields
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
3Execute Query and Count Results
- Get total count for pagination
- Apply sorting based on DataTables order parameters
- Apply pagination limits (start, length)
- Execute main data query
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
4Process Each Student Record
FOR EACH student record:
โ”‚
โ†’ Check payment status:
โ”‚ โ”œโ”€ Count active payments (payenddate > today)
โ”‚ โ”‚ โ””โ”€ Get last payment record โ”‚
โ”‚
โ†’ Format display data:
โ”‚ โ”œโ”€ Student photo or default image
โ”‚ โ”œโ”€ Personal information
โ”‚ โ”œโ”€ Payment status and dates
โ”‚ โ”œโ”€ Branch and employee information
โ”‚ โ”‚ โ””โ”€ QR code download link โ”‚
โ”‚
โ”‚ โ””โ”€โ†’ Generate action buttons: โ”‚
โ”œโ”€ Attendance button
โ”œโ”€ Payment code button (if active payment)
โ”œโ”€ Edit button
โ”‚ โ””โ”€ Delete button (based on status) โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
5Return JSON Response
- DataTables formatted JSON
- Include draw, recordsTotal, recordsFiltered
- Return data array with all formatted records
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

---

๐ŸŒ URL Routes & Actions

URL ParameterFunction CalledDescription
`do=` (empty)Default actionDisplay student registration form
`do=show`Show interfaceDisplay student management interface
`do=edit`Edit interfaceDisplay student editing form
`do=savedata``savedata()`Process student registration/updates
`do=showajax``showajax()`AJAX data provider for active students
`do=showajax2``showajax2()`AJAX data provider for pending students
`do=removecontroller``removecontroller()`Soft delete student record
### Required Parameters by Action

Edit Student (do=edit):

Save Student Data (do=savedata):

AJAX Data (do=showajax/do=showajax2):

Delete Student (do=removecontroller):

---

๐Ÿงฎ Calculation Methods

Payment Status Calculation

$date = date('Y-m-d');
$studentspays = R::count('studentspays',"studentid = ? and del < 2 and payenddate > '$date'",[$studentId]);
$studentpaylast = R::findone('studentspays',"studentid = ? and del < 2 order by id desc",[$studentId]);

Subject Group Information Formatting

$studentsetting = R::load('studentsetting',1);
$studentaddsubjects = R::load('studentaddsubjects',$studentsetting->studentaddsubjectid);
$studentsubjects = R::load('studentsubjects',$studentaddsubjects->studentsubjectid);
$studentsubjectgroups = R::load('studentsubjectgroups',$studentaddsubjects->studentsubjectgroupid);
$subjectgroups = $studentsubjects->subjectname.'/'.$studentsubjectgroups->subjectgroupname.'/'.$studentsubjectgroups->subjectgroupprice;

Student List Management for Subject Groups

// Add student to existing enrollment
$studentaddsubjects->studentid = $studentaddsubjects->studentid.','.$studentid;
R::store($studentaddsubjects);

---

๐Ÿ”’ Security & Permissions

Authentication

include_once("../public/authentication.php");

Input Sanitization

// All inputs filtered using filter_input
$studentname = filter_input(INPUT_POST, 'studentname');
$idnumber = filter_input(INPUT_POST, 'idnumber');
$studentphone = filter_input(INPUT_POST, 'studentphone');

File Upload Security

Security Improvements Needed:

---

๐Ÿ“Š Performance Considerations

Database Optimization Tips

1. Critical Indexes Required:

- students(branchid, del) - For branch filtering

- students(addtoday) - For date range filtering

- studentspays(studentid, del, payenddate) - For payment status

- client(studentid) - For billing integration

2. Query Optimization:

- Use prepared statements for repeated operations

- Consider caching subject group information

- Optimize image upload/resize operations

3. File Management:

- QR code generation can be resource intensive

- Consider background job for bulk QR generation

- Implement proper image cleanup for deleted students

---

๐Ÿ› Common Issues & Troubleshooting

1. QR Code Generation Failures

Issue: QR codes not generating or displaying

Cause: Missing QR code library or file permission issues

Debug:

// Check if QR library exists
if (!class_exists('QRcode')) {
    echo "QR Code library not found";
}

// Check directory permissions
$PNG_TEMP_DIR = "../views/default/images/studentsparcode/";
if (!is_writable($PNG_TEMP_DIR)) {
    echo "QR code directory not writable";
}

2. Image Upload Issues

Issue: Student photos not uploading or displaying

Cause: File permissions, size limits, or upload configuration

Debug:

// Check upload settings
echo "upload_max_filesize: " . ini_get('upload_max_filesize');
echo "post_max_size: " . ini_get('post_max_size');

// Check image directory permissions
$imageDir = "../views/default/images/students/";
if (!is_writable($imageDir)) {
    echo "Student images directory not writable";
}

3. Payment Status Confusion

Issue: Payment status not displaying correctly

Cause: Incorrect date calculations or payment record issues

Debug:

-- Check payment records
SELECT studentid, paystartdate, payenddate, del 
FROM studentspays 
WHERE studentid = [STUDENT_ID] 
ORDER BY id DESC;

---

๐Ÿงช Testing Scenarios

Test Case 1: Complete Student Registration

1. Fill all required fields in registration form
2. Upload student photo
3. Select subject group enrollment
4. Submit and verify student created
5. Check QR code generated
6. Verify client record created

Test Case 2: Student Data Management

1. Use show interface with various filters
2. Test date range filtering
3. Test branch filtering
4. Verify payment status display
5. Test edit and delete operations

Test Case 3: Subject Enrollment

1. Register student with subject selection
2. Verify enrollment records created
3. Check subject group student list updated
4. Test enrollment detail tracking

---

๐Ÿ“š Related Documentation

---

Documented By: AI Assistant

Review Status: โœ… Complete

Next Review: When major changes occur