# Student Management System

A complete web-based student management system built with PHP and MySQL for tracking student enrollment, grades, and attendance.

## Features

### Teacher Features
- **Student Management**: Add, edit, and view student information with Chinese name support
- **Attendance Tracking**: Take daily attendance with status options (Present, Absent, Late, Excused)
- **Behaviour Tracking**: 
  - Record positive and negative behaviour incidents
  - Points-based system with automatic calculation
  - Track severity, location, actions taken, parent notifications
  - View behaviour leaderboards
- **One-on-One Meetings**:
  - Schedule student meetings with agenda
  - Record meeting notes, action items, and student feedback
  - Track follow-up dates and meeting status
- **Goals Tracking**:
  - Set academic, behavioral, personal, social, and language goals
  - Monitor progress with percentage tracking
  - Record progress updates with timestamped notes
  - View goal achievement dates
- **Data Export**: Export all data (students, attendance, behaviour, meetings, goals, grades) to formatted Excel files
- **Grade Management**: Record and track student assessments and grades
- **Dashboard**: Overview statistics and quick access to all features

### Student Features
- **View Personal Dashboard**: See enrolled classes and overall statistics
- **View Grades**: Access all recorded grades and assessments
- **View Attendance**: See attendance records and summary statistics
- **View Behaviour Points**: See current behaviour point balance

## System Requirements

- PHP 7.4 or higher
- MySQL 5.7 or MariaDB 10.2 or higher
- Python 3.7+ (for Excel export functionality)
- Python packages: pandas, openpyxl (see installation below)
- Web server (Apache/Nginx)
- cPanel hosting (recommended for easy setup)

## Excel Export Setup

The system can export data to formatted Excel files. This requires Python and two packages:

```bash
# Install Python packages
pip3 install pandas openpyxl

# Or if using pip:
pip install pandas openpyxl
```

If you don't have Python installed or can't install packages, the export will fall back to CSV format automatically.

## Installation Instructions

### 1. Upload Files

Upload all files to your web server in a directory (e.g., `/public_html/student_db/`):

```
student_db/
├── config.php
├── index.php
├── logout.php
├── schema.sql
├── teacher/
│   ├── dashboard.php
│   ├── students.php
│   ├── attendance.php
│   ├── classes.php
│   └── grades.php
└── student/
    └── dashboard.php
```

### 2. Create Database

**Option A: Using cPanel**
1. Log into cPanel
2. Go to MySQL Databases
3. Create a new database (e.g., `yourname_student_management`)
4. Create a database user with a strong password
5. Add the user to the database with ALL PRIVILEGES

**Option B: Using phpMyAdmin**
1. Open phpMyAdmin
2. Click "New" to create a database
3. Import the `schema.sql` file

**Option C: Using MySQL command line**
```bash
mysql -u root -p
CREATE DATABASE student_management CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
exit;

mysql -u root -p student_management < schema.sql
```

### 3. Configure Database Connection

Edit `config.php` and update these lines:

```php
define('DB_HOST', 'localhost');              // Usually 'localhost'
define('DB_NAME', 'student_management');     // Your database name
define('DB_USER', 'your_db_username');       // Your database username
define('DB_PASS', 'your_db_password');       // Your database password
```

Also update the site URL:
```php
define('SITE_URL', 'https://tmudd.net/student_db/');
```

### 4. Import Database Schema

Run the SQL commands in `schema.sql` to create all necessary tables:

```bash
mysql -u your_username -p your_database_name < schema.sql
```

Or import through phpMyAdmin:
1. Select your database
2. Click "Import"
3. Choose `schema.sql`
4. Click "Go"

### 5. Set File Permissions

Ensure proper permissions (if on Linux/Unix):

```bash
chmod 755 student_db/
chmod 644 student_db/*.php
chmod 644 student_db/teacher/*.php
chmod 644 student_db/student/*.php
```

### 6. Access the System

Navigate to: `https://yourdomain.com/student_db/`

**Default Login:**
- Username: `admin`
- Password: `teacher123`

**IMPORTANT**: Change this password immediately after first login!

## Default Password Security

The default teacher password is set in the database. To change it:

```sql
-- Generate new password hash in PHP:
<?php echo password_hash('your_new_password', PASSWORD_DEFAULT); ?>

-- Then update in database:
UPDATE users 
SET password_hash = 'your_new_hash_here' 
WHERE username = 'admin';
```

## Adding Your First Students

### Method 1: Through the Web Interface
1. Log in as a teacher
2. Go to "Manage Students"
3. Click "Add Student"
4. Fill in the form

**Note**: When a student is added:
- A user account is automatically created
- Username = student number (lowercase)
- Default password = `student123`
- Students should change their password on first login

### Method 2: Direct SQL Insert

```sql
-- First create a user account
INSERT INTO users (username, password_hash, user_type) 
VALUES ('20240001', '$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi', 'student');

-- Then create student record
INSERT INTO students (user_id, student_number, first_name, last_name, grade_level) 
VALUES (LAST_INSERT_ID(), '20240001', 'John', 'Smith', 'Grade 7');
```

## Database Structure

### Main Tables

**users** - Login accounts for teachers and students
**students** - Student enrollment and personal information
**teachers** - Teacher information
**subjects** - Available subjects/courses
**classes** - Class sections taught by teachers
**class_enrollments** - Student enrollment in classes
**assessments** - Tests, quizzes, assignments
**assessment_types** - Categories of assessments
**grades** - Student scores on assessments
**attendance** - Daily attendance records
**behaviour_categories** - Types of behaviours (positive/negative/neutral) with point values
**behaviour_records** - Individual behaviour incidents with details
**behaviour_points** - Student behaviour point totals (summary table)
**meetings** - One-on-one meeting scheduling and notes
**goals** - Student goals with progress tracking
**goal_progress** - Historical progress updates for goals

## Usage Guide

### For Teachers

**Taking Attendance:**
1. Go to "Take Attendance"
2. Select a class and date
3. Mark each student (Present/Absent/Late/Excused)
4. For "Late" students, enter minutes late
5. Add notes if needed
6. Click "Save Attendance"

**Managing Students:**
1. Go to "Manage Students"
2. Use search and filters to find students
3. Click "Edit" to update information
4. Click "Add Student" for new enrollments

**Recording Behaviour:**
1. Go to "Behaviour Tracking"
2. Click "Add Record"
3. Select student and behaviour category
4. Add description, severity, location
5. Mark if parent was notified
6. System automatically calculates points

**Scheduling Meetings:**
1. Go to "One-on-One Meetings"
2. Click "Schedule Meeting"
3. Select student, date, time, and type
4. Add agenda items
5. After meeting, click "Update" to add notes

**Setting Goals:**
1. Go to "Student Goals"
2. Click "Add Goal"
3. Select student and goal type
4. Set target date and success criteria
5. Update progress regularly with notes

**Exporting Data:**
1. Go to any section (Students, Behaviour, etc.)
2. Click "Export to Excel"
3. File downloads as formatted .xlsx
4. Open in Excel, Numbers, or LibreOffice

**Recording Grades:** (Coming soon)
1. Select a class
2. Create an assessment
3. Enter scores for each student

### For Students

**Viewing Information:**
1. Log in with your student number and password
2. Dashboard shows:
   - Your classes
   - Recent grades
   - Attendance summary
3. All information is read-only

## Sample Data

The system includes:
- 1 teacher account (admin/teacher123)
- Default assessment types (Quiz, Test, Assignment, Project, etc.)
- Default behaviour categories:
  - Positive: Excellent Participation (+5), Helping Others (+5), Outstanding Work (+10), Leadership (+10), etc.
  - Negative: Late to Class (-3), Missing Homework (-5), Disruption (-5), Disrespect (-10), etc.
  - Neutral: Parent Contact (0), Counseling Referral (0), General Note (0)

To add sample students and data for testing, run additional SQL:

```sql
-- Add a subject
INSERT INTO subjects (subject_code, subject_name) 
VALUES ('ESL-B1', 'ESL B1 Level');

-- Add a class
INSERT INTO classes (subject_id, teacher_id, class_name, academic_year, semester) 
VALUES (1, 1, 'ESL B1 - Grade 7', '2025-2026', 'Spring');
```

## Troubleshooting

**Can't log in:**
- Check database connection in `config.php`
- Verify database tables were created
- Ensure default user exists in `users` table

**White screen/errors:**
- Check PHP error logs
- Enable error display in `config.php` (development only):
  ```php
  ini_set('display_errors', 1);
  ```

**Students can't see their info:**
- Verify student has a `user_id` linked in the `students` table
- Check that classes are marked as active
- Ensure student is enrolled in classes via `class_enrollments`

**Attendance not saving:**
- Check that the teacher has a valid `teacher_id`
- Verify students are enrolled in the selected class
- Check database error logs

## Security Recommendations

1. **Change default passwords immediately**
2. **Use HTTPS** (SSL certificate) in production
3. **Regular backups** of the database
4. **Restrict database access** to localhost only
5. **Keep PHP updated** to the latest version
6. **Set proper file permissions** (644 for files, 755 for directories)
7. **Enable error logging** instead of displaying errors in production

## Future Enhancements (Roadmap)

- [ ] Complete grades management interface
- [ ] Complete classes management interface
- [ ] Export reports (PDF, Excel)
- [ ] Parent portal access
- [ ] Email notifications
- [ ] Bulk import students from CSV
- [ ] Grade calculation and GPA
- [ ] Attendance reports and analytics
- [ ] Student photo uploads
- [ ] Calendar integration

## Support

For issues or questions:
1. Check the troubleshooting section
2. Review PHP error logs
3. Check MySQL error logs
4. Verify database connection settings

## License

This system is provided as-is for educational purposes.

## Credits

Created for tmudd.net - International Boarding School ESL Department
