# Repository Overview

This project is a PHP (procedural) web application running on XAMPP (Windows). It manages academic data: students, teachers, subjects, exams, mark entry, uploads, and reports.

## Tech Stack
- PHP 7+/8+
- MySQL/MariaDB (PDO in PHP)
- Frontend: basic HTML/Bootstrap/JS
- Environment: Windows (XAMPP), Apache

## Key Directories
- /admin: Admin pages (users, settings, backups)
- /assets: CSS and JS assets
- /attendance: Attendance entry
- /bulk_upload: CSV upload flows for students/teachers (+ Bengali variant)
- /classes: Class management
- /config: Database config (database.php)
- /exams: Exam management, routine, seat card
- /fees: Fee management
- /groups: Student groups
- /includes: Shared helpers (e.g., email_validator.php)
- /library: Library documents
- /marks: Marks entry and setup (entry.php is central)
- /notices: Notice uploads
- /reports: Report pages
- /students: CRUD and views for students
- /subjects: Subject management and selection
- /uploads: File storage endpoints and folders

## Database Tables (relevant to marks)
- mark_distributions: Fallback mark distribution per subject/class/session/exam_type (includes cq_marks, mcq_marks, practical_marks, assignment_marks, attendance_marks, total_marks, overall_pass_marks, cq_pass_marks, mcq_pass_marks, practical_pass_marks)
- subject_mark_distribution: Primary mark distribution per subject/class/session/exam_type and optionally group_name (preferred when present)
- results: Per student result rows (marks breakdown + grade)
- students, classes, subjects, academic_sessions, student_groups: Reference tables

## Marks Entry Flow
1. On search (GET): marks/entry.php tries subject_mark_distribution first (respect group_name), then falls back to mark_distributions.
2. On save (POST): same preference order is used. Hard validation is enabled:
   - Any component (CQ/MCQ/Practical/Assignment/Attendance) exceeding its configured limit or negative will SKIP that student's save and list the errors; no auto-capping.
   - Valid students are saved in one transaction; invalid ones are counted as skipped with messages shown beneath the success banner.
3. Grade is calculated with individual pass checks (CQ/MCQ/Practical) and overall pass threshold (overall_pass_marks or 40%).

## Common Pages/Files
- index.php: Landing/login routing
- login.php / logout.php: Authentication
- marks/entry.php: Marks search and save logic
- marks/setup.php: Mark distribution setup UI
- subjects/subject_selection.php and helpers: Subject selection feature

## Configuration
- config/database.php: PDO connection settings
- php.ini at project root overrides for upload/limits

## Known Pitfalls
- Mismatch between subject_mark_distribution vs. mark_distributions can cause unexpected limits. Prefer configuring subject_mark_distribution for group-specific setups.
- Ensure group_name in UI exactly matches DB when using group-specific distributions.
- When no distribution exists, defaults are auto-created in mark_distributions (based on exam_type) — adjust them as needed.

## Environment Notes
- Tested on Windows 11 (XAMPP). Apache serves the project under /bidda. Ensure correct permissions for /uploads.

## Maintenance Tips
- Use test_*.php scripts for quick diagnostics (DB connection, marks, encoding).
- Backups under /backups and admin/backup.php.
