================================================================================
  DEPLOY PRIMARY GRADES (G4-G7) - QUICK DEPLOYMENT GUIDE
================================================================================

WHAT YOU GET:
-------------
✓ Grade 4-7 added to your system
✓ 48 primary school subjects
✓ Toggle switch to show/hide primary grades
✓ Visual distinction (green = primary, blue = secondary)
✓ Moodle auto-enrollment support

================================================================================
DEPLOYMENT STEPS (10 MINUTES):
================================================================================

STEP 1: RUN SQL SCRIPTS (phpMyAdmin)
================================================================================

1.1. ADD PRIMARY GRADES
------------------------

Login to phpMyAdmin:
https://test.melanegroup.com:2083/phpMyAdmin

Select database: melane_multi_tenant_skoloi

Click: SQL tab

Paste this:
-----------
INSERT IGNORE INTO grades (name) VALUES
('Grade 4'),
('Grade 5'),
('Grade 6'),
('Grade 7');

Click: Go

Expected: 4 rows inserted


1.2. ADD PRIMARY SUBJECTS
--------------------------

Still in SQL tab, clear the box

Open file: C:\xampp\htdocs\Multi-Tanent\database\seeds\primary_school_subjects_g4_g7.sql

Copy ALL contents (Ctrl+A, Ctrl+C)

Paste into SQL box

Click: Go

Expected:
- 11 rows inserted (Grade 4 subjects)
- 12 rows inserted (Grade 5 subjects)
- 13 rows inserted (Grade 6 subjects)
- 12 rows inserted (Grade 7 subjects)
- X rows inserted (grade-subject links)

Total: 48 subjects created and linked!

================================================================================
STEP 2: UPLOAD UPDATED FILE TO cPANEL
================================================================================

2.1. OPEN cPANEL FILE MANAGER
------------------------------

Go to: cPanel → File Manager

Navigate to: public_html/test.melanegroup.com/Multi-Tanent/admin/


2.2. UPLOAD configure_subjects.php
-----------------------------------

Find: configure_subjects.php (old version)

Delete it (click Delete button)

Click: Upload button

Select from your computer:
C:\xampp\htdocs\Multi-Tanent\admin\configure_subjects.php

Wait for upload complete

Done!

================================================================================
STEP 3: TEST THE NEW FEATURE
================================================================================

3.1. LOGIN
----------
Go to: https://test.melanegroup.com/Multi-Tanent/admin/login.php

Login as admin


3.2. OPEN CONFIGURE SUBJECTS
-----------------------------
Go to: https://test.melanegroup.com/Multi-Tanent/admin/configure_subjects.php

OR click: Configure Subjects in navigation


3.3. VERIFY TOGGLE VISIBLE
---------------------------
At the top, you should see:

┌──────────────────────────────────────────────┐
│ 🎚️ Primary School Grades (Grade 4-7)         │
│                                               │
│ Enable this to show and configure subjects   │
│ for Grade 4, 5, 6, and 7. If your school     │
│ only offers secondary education (Forms),     │
│ keep this disabled.                          │
│                              [Toggle Switch]  │
└──────────────────────────────────────────────┘

Toggle should be OFF (default)

Below, you should see:
- Form 1 (blue, "Secondary" badge)
- Form 2 (blue, "Secondary" badge)
- Form 3 (blue, "Secondary" badge)
- Form 4 (blue, "Secondary" badge)
- Form 5 (blue, "Secondary" badge)


3.4. ENABLE PRIMARY GRADES
---------------------------
Click toggle switch to ON

Page reloads automatically

Now you should see:
- Grade 4 (green, "Primary" badge) ← NEW!
- Grade 5 (green, "Primary" badge) ← NEW!
- Grade 6 (green, "Primary" badge) ← NEW!
- Grade 7 (green, "Primary" badge) ← NEW!
- Form 1 (blue, "Secondary" badge)
- Form 2 (blue, "Secondary" badge)
- Form 3 (blue, "Secondary" badge)
- Form 4 (blue, "Secondary" badge)
- Form 5 (blue, "Secondary" badge)

Total: 9 grades visible! ✓


3.5. CONFIGURE SUBJECTS FOR GRADE 7
------------------------------------
Click on "Grade 7" card

You'll see all available subjects

Select the ones you want:
☑ English Language (Grade 7)
☑ SiSwati Language (Grade 7)
☑ Mathematics (Grade 7)
☑ Integrated Science (Grade 7)
☑ Social Studies (Grade 7)
☑ Religious Education (Grade 7)
☑ ICT / Computer Studies (Grade 7)

Click: Update Subjects

Success message: "Subject mappings updated successfully!"

Grade 7 now has 7 subjects configured ✓


3.6. VERIFY PARENT PAYMENT
---------------------------
Go to parent portal

Make payment for a Grade 7 student

Should see ONLY the 7 subjects you configured

Perfect! ✓

================================================================================
OPTIONAL: MOODLE AUTO-ENROLLMENT SETUP
================================================================================

If you want students to auto-enroll in Moodle when subjects assigned:

STEP 1: Run Moodle Mapping SQL
-------------------------------
In phpMyAdmin, run:
database/migrations/create_moodle_mapping_table.sql


STEP 2: Upload Moodle Files
----------------------------
Upload to server:
- admin/moodle/configure_mapping.php
- admin/moodle/test_mappings.php
- includes/moodle_enrollment_handler.php


STEP 3: Configure Moodle Settings
----------------------------------
Go to: admin/settings.php

Scroll to: Moodle Integration

Configure:
- Moodle URL: https://yourschool.moodle.com
- Moodle Token: your_webservice_token
- Enable Moodle: ✓

Save


STEP 4: Map Subjects to Courses
--------------------------------
Go to: admin/moodle/configure_mapping.php

For each subject:
- Select subject (e.g., "English Language (Grade 7)")
- Map to Moodle course (e.g., "G7-ENG")
- Enable auto-enroll
- Save


STEP 5: Test Mappings
----------------------
Go to: admin/moodle/test_mappings.php

Verify:
- Connection: Green (success)
- All mappings: Valid (green indicators)
- Moodle courses: Listed correctly


STEP 6: Test with Student
--------------------------
- Assign subject to student
- Check Moodle - student should be enrolled
- View enrollment log for confirmation

================================================================================
VERIFICATION CHECKLIST:
================================================================================

DATABASE:
[ ] Grade 4 exists in grades table
[ ] Grade 5 exists in grades table
[ ] Grade 6 exists in grades table
[ ] Grade 7 exists in grades table
[ ] 48 subjects exist with G4-, G5-, G6-, G7- codes
[ ] grade_subject table has links

ADMIN INTERFACE:
[ ] configure_subjects.php shows toggle at top
[ ] Toggle defaults to OFF
[ ] Only Form 1-5 visible when OFF
[ ] Grade 4-7 visible when ON
[ ] Green color for primary grades
[ ] Blue color for secondary grades
[ ] Badges show "Primary" vs "Secondary"

FUNCTIONALITY:
[ ] Can configure subjects for Grade 4
[ ] Can configure subjects for Grade 5
[ ] Can configure subjects for Grade 6
[ ] Can configure subjects for Grade 7
[ ] Toggle setting persists after navigation
[ ] Different schools can have different settings

PARENT EXPERIENCE:
[ ] Parent with Grade 4 student sees Grade 4 subjects
[ ] Parent with Grade 7 student sees Grade 7 subjects
[ ] Parent with Form 1 student sees Form 1 subjects
[ ] Subjects filtered correctly by grade level

MOODLE (OPTIONAL):
[ ] Moodle mapping tables created
[ ] Can map Grade 4-7 subjects to Moodle courses
[ ] Test interface shows mapping status
[ ] Auto-enrollment works

================================================================================
QUICK REFERENCE:
================================================================================

SQL SCRIPTS TO RUN:
-------------------
1. database/seeds/add_primary_grades.sql (4 grades)
2. database/seeds/primary_school_subjects_g4_g7.sql (48 subjects)
3. database/migrations/create_moodle_mapping_table.sql (optional)

FILES TO UPLOAD:
----------------
1. admin/configure_subjects.php (required)
2. admin/moodle/configure_mapping.php (optional)
3. admin/moodle/test_mappings.php (optional)

URLS TO TEST:
-------------
1. https://test.melanegroup.com/Multi-Tanent/admin/configure_subjects.php
2. https://test.melanegroup.com/Multi-Tanent/admin/moodle/test_mappings.php

================================================================================
EXPECTED RESULT:
================================================================================

BEFORE DEPLOYMENT:
------------------
Configure Subjects page:
- Form 1
- Form 2
- Form 3
- Form 4
- Form 5
(5 grades only)

AFTER DEPLOYMENT:
-----------------
Configure Subjects page:
- Toggle switch at top (OFF by default)
- Form 1, 2, 3, 4, 5 visible

When toggle switched ON:
- Grade 4 (green)
- Grade 5 (green)
- Grade 6 (green)
- Grade 7 (green)
- Form 1 (blue)
- Form 2 (blue)
- Form 3 (blue)
- Form 4 (blue)
- Form 5 (blue)
(9 grades total!)

================================================================================
DOCUMENTATION:
================================================================================

- PRIMARY_GRADES_TOGGLE_COMPLETE.txt (this file)
- PRIMARY_SCHOOL_MOODLE_SETUP.md (Moodle setup guide)
- MOODLE_QUICK_START.txt (Moodle quick reference)
- SQL_FIXED_READY_TO_RUN.txt (SQL troubleshooting)

================================================================================

FILES READY IN WINDOWS EXPLORER!

Follow the 3 setup steps and your admins will be able to toggle primary grades!

================================================================================

