STUDENT MANAGEMENT SYSTEM - INSTALLATION GUIDE
===============================================

This guide will walk you through installing the system on your web server (tmudd.net).

PREREQUISITES
-------------
✓ Web hosting with PHP 7.4+ and MySQL
✓ cPanel access (or SSH access)
✓ FTP client (FileZilla, Cyberduck) or cPanel File Manager
✓ Python 3.7+ installed on server (optional, for Excel export)


STEP 1: UPLOAD FILES
--------------------

Via cPanel File Manager:
1. Log into cPanel
2. Open "File Manager"
3. Navigate to public_html (or your desired directory)
4. Create a new folder called "student_db"
5. Upload all files from the student_db folder
6. Extract if uploaded as ZIP

Via FTP:
1. Connect to your server using FTP client
2. Navigate to public_html
3. Create folder "student_db"
4. Upload all files from student_db folder

Files should be organized as:
/public_html/student_db/
├── config.php
├── index.php
├── logout.php
├── schema.sql
├── .htaccess
├── teacher/
│   ├── dashboard.php
│   ├── students.php
│   ├── attendance.php
│   ├── behaviour.php
│   ├── meetings.php
│   ├── goals.php
│   ├── classes.php
│   ├── grades.php
│   ├── export.php
│   └── scripts/
│       └── csv_to_excel.py
└── student/
    └── dashboard.php


STEP 2: CREATE DATABASE
------------------------

Via cPanel:
1. In cPanel, go to "MySQL Databases"
2. Under "Create New Database":
   - Database Name: student_management
   - Click "Create Database"
3. Under "MySQL Users" → "Add New User":
   - Username: Choose a username (e.g., student_admin)
   - Password: Create a STRONG password
   - Click "Create User"
4. Under "Add User To Database":
   - Select the user you just created
   - Select the database
   - Click "Add"
   - Check "ALL PRIVILEGES"
   - Click "Make Changes"

Write down these details:
- Database Name: _______________________
- Database User: _______________________
- Database Password: ___________________
- Database Host: Usually "localhost"


STEP 3: IMPORT DATABASE SCHEMA
-------------------------------

Via phpMyAdmin (Recommended):
1. In cPanel, click "phpMyAdmin"
2. Click on your database name (student_management) in left sidebar
3. Click "Import" tab at top
4. Click "Choose File"
5. Select "schema.sql" from your student_db folder
6. Scroll down and click "Go"
7. Wait for "Import has been successfully finished"

Via MySQL Command Line (Advanced):
mysql -u your_username -p student_management < schema.sql


STEP 4: CONFIGURE DATABASE CONNECTION
--------------------------------------

1. Open config.php in a text editor
2. Find these lines and update with YOUR database details:

   define('DB_HOST', '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

3. Update the site URL:
   
   define('SITE_URL', 'https://tmudd.net/student_db/');

4. Save the file
5. Re-upload to server (overwrite existing)


STEP 5: SET FILE PERMISSIONS (If using SSH)
--------------------------------------------

chmod 755 student_db/
chmod 644 student_db/*.php
chmod 644 student_db/teacher/*.php
chmod 644 student_db/student/*.php
chmod 755 student_db/teacher/scripts/
chmod 755 student_db/teacher/scripts/csv_to_excel.py


STEP 6: INSTALL PYTHON PACKAGES (Optional - For Excel Export)
--------------------------------------------------------------

This enables formatted Excel exports instead of CSV.

Via SSH:
pip3 install pandas openpyxl --user

Via cPanel Terminal (if available):
1. Open "Terminal" in cPanel
2. Run: pip3 install pandas openpyxl --user

If you can't install Python packages:
- The system will work fine, exports will be in CSV format
- You can still import CSVs into Excel


STEP 7: SECURITY SETUP
----------------------

1. CHANGE DEFAULT PASSWORD IMMEDIATELY:
   - Log in as admin/teacher123
   - Go to MySQL/phpMyAdmin
   - Find "users" table
   - Generate new password hash in PHP:
     <?php echo password_hash('YOUR_NEW_PASSWORD', PASSWORD_DEFAULT); ?>
   - Update the password_hash field for admin user

2. Enable HTTPS:
   - In cPanel, install SSL certificate (Let's Encrypt is free)
   - Update config.php:
     define('SITE_URL', 'https://tmudd.net/student_db/');

3. Restrict config.php access (already in .htaccess):
   - .htaccess blocks direct access to config.php
   - Verify by trying to access: yourdomain.com/student_db/config.php
   - Should get "Forbidden" error


STEP 8: TEST THE INSTALLATION
------------------------------

1. Open browser and go to: https://tmudd.net/student_db/
2. You should see the login page
3. Log in with:
   Username: admin
   Password: teacher123 (CHANGE THIS!)
4. You should see the teacher dashboard
5. Test each section:
   ✓ Manage Students
   ✓ Behaviour Tracking
   ✓ Attendance
   ✓ Meetings
   ✓ Goals


STEP 9: ADD YOUR FIRST STUDENT
-------------------------------

1. Click "Manage Students"
2. Click "+ Add Student"
3. Fill in the form:
   - Student Number: (e.g., 20260001)
   - First Name, Last Name
   - Chinese Name (optional)
   - Grade Level (e.g., Grade 7)
   - Other fields as needed
4. Click "Add Student"
5. Note the username and default password shown


STEP 10: TEST STUDENT LOGIN
----------------------------

1. Log out from teacher account
2. Log in with student credentials:
   - Username: Student number (lowercase)
   - Password: student123
3. Student should see their dashboard
4. Students should change their password


TROUBLESHOOTING
---------------

Problem: White screen / blank page
Solution: 
- Check PHP error logs in cPanel
- Enable error display in config.php temporarily:
  ini_set('display_errors', 1);
  error_reporting(E_ALL);

Problem: Database connection failed
Solution:
- Verify database credentials in config.php
- Check if database user has proper privileges
- Confirm database exists

Problem: Can't log in
Solution:
- Verify schema.sql was imported successfully
- Check users table exists and has admin user
- Clear browser cookies/cache

Problem: Excel export not working
Solution:
- Python packages may not be installed
- System will fall back to CSV automatically
- Try installing: pip3 install pandas openpyxl --user

Problem: Permission denied errors
Solution:
- Check file permissions (755 for directories, 644 for files)
- Ensure web server can read files


NEXT STEPS
----------

1. ✓ Change default admin password
2. ✓ Add your students
3. ✓ Create subjects and classes (via SQL or future interface)
4. ✓ Start taking attendance
5. ✓ Begin tracking behaviour
6. ✓ Schedule one-on-one meetings
7. ✓ Set student goals


SUPPORT
-------

For technical issues:
- Check server error logs
- Review PHP error logs
- Check MySQL error logs
- Verify all files uploaded correctly


SECURITY CHECKLIST
------------------

□ Changed default admin password
□ HTTPS/SSL enabled
□ Strong database password
□ config.php protected by .htaccess
□ Regular database backups enabled
□ File permissions set correctly
□ Error display turned OFF in production
□ Students instructed to change default passwords


BACKUP RECOMMENDATIONS
----------------------

Set up automatic backups in cPanel:
1. Go to "Backup" in cPanel
2. Enable automatic backups
3. Download full backup monthly
4. Store backups in secure location


CONGRATULATIONS!
----------------

Your Student Management System is now installed and ready to use.

Access URLs:
- Teacher Login: https://tmudd.net/student_db/
- Student Login: https://tmudd.net/student_db/

Default Credentials:
- Username: admin
- Password: teacher123 (CHANGE THIS IMMEDIATELY!)

