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:
- โข Complete student registration with personal and family information
- โข Academic/sports subject enrollment and group management
- โข Payment tracking and fee management with flexible pricing
- โข Image upload and management for student photos
- โข QR code generation for digital student identification
- โข Parent/guardian information management (multiple parents supported)
- โข Student status management (active, deleted, pending approval)
- โข Client integration for billing and payment systems
- โข Branch-based student management
- โข AJAX-powered data tables with advanced filtering
Primary Functions
- โ Student registration and profile management
- โ Subject/group enrollment tracking
- โ Payment and fee management
- โ QR code generation for student identification
- โ Multi-parent/guardian information support
- โ Image upload and photo management
- โ Advanced student search and filtering
- โ Status management (active/deleted/pending)
- โ Branch-based organization
- โ Client billing integration
Related Controllers
- โข clientController.php - Client billing management
- โข studentspaysController.php - Payment processing
- โข branchController.php - Branch management
- โข userController.php - User account management
---
๐๏ธ Database Tables
Primary Tables (Direct Operations)
| Table Name | Purpose | Key Columns | |
|---|---|---|---|
| **students** | Student master records | id, studentname, studentnumber, idnumber, studentphone, clientid, branchid, del | |
| **client** | Billing/payment clients | clientid, clientname, clientphone, studentid, typeclientid, priceTypeId | |
| **studentaddsubjects** | Subject enrollment | studentaddsubjectid, studentid, studentsubjectid, studentsubjectgroupid | |
| **studentaddsubjectdetails** | Enrollment details | studentid, studentsubjectid, studentsubjectgroupid, studentaddsubjectid |
| Table Name | Purpose | Key Columns | |
|---|---|---|---|
| **studentsubjects** | Available subjects | studentsubjectid, subjectname | |
| **studentsubjectgroups** | Subject groups | studentsubjectgroupid, subjectgroupname, subjectgroupprice | |
| **studentsetting** | System configuration | studentsettingid, studentaddsubjectid | |
| **studentspays** | Payment records | studentspayid, studentid, paystartdate, payenddate, del | |
| **branch** | Organization branches | branchId, branchName | |
| **user** | System users | userid, 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:
- โข
subjectgroups- Combined subject/group/price information - โข
studentaddsubjects- Default subject enrollment settings - โข
studentsetting- System configuration - โข
branchs- Available branches for selection
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:
- โข Normal view: All active students (
show != 2) - โข Pending approval: Students waiting for approval (
show == 2)
---
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:
- โข Date range filtering
- โข Student ID filtering
- โข Branch filtering
- โข Deletion status filtering
- โข General search across multiple fields
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
Workflow 2: Student Data Display with Filtering
---
๐ URL Routes & Actions
| URL Parameter | Function Called | Description | |
|---|---|---|---|
| `do=` (empty) | Default action | Display student registration form | |
| `do=show` | Show interface | Display student management interface | |
| `do=edit` | Edit interface | Display 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 |
Edit Student (do=edit):
- โข
id- Student ID to edit (via GET)
Save Student Data (do=savedata):
- โข
studentname- Student name (required, via POST) - โข
idnumber- Student ID number (via POST) - โข
studentphone- Student phone (via POST) - โข
parentsname- Parent name (via POST) - โข
parentsphone- Parent phone (via POST) - โข
branchid- Branch ID (via POST) - โข
studentimage- Photo file upload (via FILES) - โข Additional optional fields for complete profile
AJAX Data (do=showajax/do=showajax2):
- โข
start_date- Filter start date (via POST) - โข
end_date- Filter end date (via POST) - โข
del- Deletion status filter (via POST) - โข
data1- Student ID filter (via POST) - โข
data3- Branch ID filter (via POST) - โข DataTables standard parameters
Delete Student (do=removecontroller):
- โข
id- Student ID to delete (via POST)
---
๐งฎ 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");
- โข Required for show, edit, and management functions
- โข Registration form accessible without authentication
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
- โข Basic file upload validation for student photos
- โข Image resizing to standard dimensions (300x300)
- โข File path validation for image operations
Security Improvements Needed:
- โข Add file type validation for uploads
- โข Implement CSRF protection for forms
- โข Add more comprehensive input validation
- โข Sanitize all data before SQL operations
---
๐ 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
- โข CLAUDE.md - PHP 8.2 migration guide
- โข clientController.php - Client billing management
- โข studentspaysController.php - Payment processing
- โข QR Code Library Documentation - QR generation
---
Documented By: AI Assistant
Review Status: โ Complete
Next Review: When major changes occur