╔═══════════════════════════════════════════════════════════════════╗
║          COMMON SUBJECTS - AUTOMATIC ASSIGNMENT GUIDE            ║
╚═══════════════════════════════════════════════════════════════════╝

✅ PROBLEM FIXED!
Common subjects (Bangla, English, ICT, Economics, Statistics) are now 
automatically assigned to ALL groups when you select them for any group.

═══════════════════════════════════════════════════════════════════

📋 HOW IT WORKS

COMMON SUBJECTS (Auto-assigned to ALL groups):
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
1. Bangla (বাংলা)
2. English (ইংরেজি)
3. Information and Communication Technology (ICT)
4. Economics (অর্থনীতি)
5. Statistics (পরিসংখ্যান)

When you check ANY of these subjects for a group, they are automatically 
assigned to ALL groups (Science, Commerce, Arts).

GROUP-SPECIFIC SUBJECTS:
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
All other subjects (Physics, Chemistry, Accounting, etc.) are 
group-specific and only assigned to the selected group.

═══════════════════════════════════════════════════════════════════

🎯 STEP-BY-STEP USAGE

STEP 1: Assign subjects to Science Group
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

1. Go to: http://localhost/bidda/subjects/assign_by_class.php
2. Select: Class 9, Group: Science
3. Click: লোড (Load)

You'll see subjects divided into two sections:

   ┌─────────────────────────────────────────────────────────────┐
   │ সাধারণ বিষয় (সকল গ্রুপে প্রযোজ্য)                         │
   │ Common Subjects (Apply to All Groups)                       │
   ├─────────────────────────────────────────────────────────────┤
   │ ☐ Bangla (বাংলা) [সাধারণ]                                  │
   │ ☐ English (ইংরেজি) [সাধারণ]                                │
   │ ☐ ICT [সাধারণ]                                              │
   │ ☐ Economics (অর্থনীতি) [সাধারণ]                            │
   │ ☐ Statistics (পরিসংখ্যান) [সাধারণ]                         │
   │                                                              │
   │ গ্রুপ-ভিত্তিক বিষয়                                         │
   │ Group-Specific Subjects                                      │
   ├─────────────────────────────────────────────────────────────┤
   │ ☐ Physics (পদার্থবিজ্ঞান)                                  │
   │ ☐ Chemistry (রসায়ন)                                        │
   │ ☐ Biology (জীববিজ্ঞান)                                     │
   │ ☐ Higher Math (উচ্চতর গণিত)                                │
   └─────────────────────────────────────────────────────────────┘

4. Check: Bangla, English, ICT (common subjects)
5. Check: Physics, Chemistry, Biology, Higher Math (Science-specific)
6. Click: সংরক্ষণ করুন (Save)

✅ RESULT: 
   - Bangla, English, ICT → Assigned to ALL groups (Science, Commerce, Arts)
   - Physics, Chemistry, Biology, Higher Math → Assigned ONLY to Science

STEP 2: Assign subjects to Commerce Group
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

1. Select: Class 9, Group: Commerce
2. Click: লোড (Load)

You'll see:
   ┌─────────────────────────────────────────────────────────────┐
   │ সাধারণ বিষয় (সকল গ্রুপে প্রযোজ্য)                         │
   ├─────────────────────────────────────────────────────────────┤
   │ ☑ Bangla (বাংলা) [সাধারণ] ← Already checked (read-only)    │
   │ ☑ English (ইংরেজি) [সাধারণ] ← Already checked (read-only)  │
   │ ☑ ICT [সাধারণ] ← Already checked (read-only)                │
   │ ☐ Economics (অর্থনীতি) [সাধারণ]                            │
   │ ☐ Statistics (পরিসংখ্যান) [সাধারণ]                         │
   │                                                              │
   │ গ্রুপ-ভিত্তিক বিষয়                                         │
   ├─────────────────────────────────────────────────────────────┤
   │ ☐ Accounting (হিসাববিজ্ঞান)                                │
   │ ☐ Business Studies (ব্যবসায় শিক্ষা)                       │
   │ ☐ Finance (ফিন্যান্স)                                       │
   └─────────────────────────────────────────────────────────────┘

Notice: Bangla, English, ICT are already checked and DISABLED (read-only)
        because they were assigned from Science group.

3. Check: Economics, Statistics (common subjects - will apply to all groups)
4. Check: Accounting, Business Studies, Finance (Commerce-specific)
5. Click: সংরক্ষণ করুন (Save)

✅ RESULT: 
   - Economics, Statistics → Assigned to ALL groups
   - Accounting, Business Studies, Finance → Assigned ONLY to Commerce
   - Bangla, English, ICT remain assigned to ALL groups

STEP 3: Assign subjects to Arts Group
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

1. Select: Class 9, Group: Arts
2. Click: লোড (Load)

You'll see all 5 common subjects already checked (read-only):
   ┌─────────────────────────────────────────────────────────────┐
   │ সাধারণ বিষয় (সকল গ্রুপে প্রযোজ্য)                         │
   ├─────────────────────────────────────────────────────────────┤
   │ ☑ Bangla (বাংলা) [সাধারণ] ← Read-only                      │
   │ ☑ English (ইংরেজি) [সাধারণ] ← Read-only                    │
   │ ☑ ICT [সাধারণ] ← Read-only                                  │
   │ ☑ Economics (অর্থনীতি) [সাধারণ] ← Read-only                │
   │ ☑ Statistics (পরিসংখ্যান) [সাধারণ] ← Read-only             │
   │                                                              │
   │ গ্রুপ-ভিত্তিক বিষয়                                         │
   ├─────────────────────────────────────────────────────────────┤
   │ ☐ History (ইতিহাস)                                          │
   │ ☐ Geography (ভূগোল)                                        │
   │ ☐ Civics (পৌরনীতি)                                         │
   └─────────────────────────────────────────────────────────────┘

3. Check: History, Geography, Civics (Arts-specific)
4. Click: সংরক্ষণ করুন (Save)

✅ RESULT:
   - All 5 common subjects remain assigned to ALL groups
   - History, Geography, Civics → Assigned ONLY to Arts

═══════════════════════════════════════════════════════════════════

📊 FINAL RESULT

After completing all three groups:

Science Group:
   ✓ Bangla, English, ICT, Economics, Statistics (common)
   ✓ Physics, Chemistry, Biology, Higher Math (specific)

Commerce Group:
   ✓ Bangla, English, ICT, Economics, Statistics (common)
   ✓ Accounting, Business Studies, Finance (specific)

Arts Group:
   ✓ Bangla, English, ICT, Economics, Statistics (common)
   ✓ History, Geography, Civics (specific)

═══════════════════════════════════════════════════════════════════

🎨 VISUAL INDICATORS

In the interface:

1. Common subjects are marked with a badge: [সাধারণ]

2. When a common subject is already assigned (from another group):
   - Checkbox is CHECKED and DISABLED (read-only)
   - Badge color is GREEN [সাধারণ]

3. When a common subject is not yet assigned:
   - Checkbox is UNCHECKED but can be checked
   - Badge color is GRAY [সাধারণ]

4. Group-specific subjects:
   - Normal checkboxes, no badge
   - Can be checked/unchecked freely

═══════════════════════════════════════════════════════════════════

⚙️ TECHNICAL DETAILS

HOW IT WORKS BEHIND THE SCENES:
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

1. When you save subjects for a group, the system:
   
   a) Identifies which selected subjects are COMMON subjects
   b) Identifies which selected subjects are GROUP-SPECIFIC
   
   c) Inserts COMMON subjects to ALL active groups:
      - Science
      - Commerce
      - Arts
   
   d) Inserts GROUP-SPECIFIC subjects ONLY to the selected group

2. When you load subjects for a group, the system:
   
   a) Shows common subjects that are already assigned as read-only
   b) Shows common subjects that are not assigned as selectable
   c) Shows group-specific subjects as normal checkboxes

COMMON SUBJECTS LIST (defined in code):
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
The system recognizes these subject names (both English and Bengali):
- Bangla, বাংলা
- English, ইংরেজি
- Information and Communication Technology, তথ্য ও যোগাযোগ প্রযুক্তি, ICT
- Economics, অর্থনীতি
- Statistics, পরিসংখ্যান

Make sure your subject names in the database match one of these names.

═══════════════════════════════════════════════════════════════════

💡 IMPORTANT NOTES

✓ You MUST select a group to load/save subjects
  (The "সব গ্রুপ" option is no longer valid)

✓ Common subjects automatically apply to all groups
  (No need to manually assign them to each group separately)

✓ Once a common subject is assigned from any group, it becomes 
  read-only in other groups (but remains assigned)

✓ To remove a common subject from all groups, you need to manually
  delete it from the database or uncheck it in ALL groups

✓ Group-specific subjects work independently for each group

═══════════════════════════════════════════════════════════════════

🔧 TROUBLESHOOTING

Problem: Common subjects not appearing as read-only
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Solution: Make sure the subject names in your database exactly match
          the common subject names listed above

Problem: Getting duplicate entry errors
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Solution: Run the fix_database_structure.sql script to ensure proper
          database constraints

Problem: Can't save subjects
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Solution: Make sure you have selected both Class AND Group

Problem: A subject appears in both sections
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Solution: Check the exact name of the subject in the database.
          Only subjects with exact name match are considered common.

═══════════════════════════════════════════════════════════════════

✅ YOU'RE READY!

This new system ensures that common subjects are ALWAYS assigned to 
all groups, preventing inconsistencies and making your work easier!

Visit: http://localhost/bidda/subjects/assign_by_class.php

═══════════════════════════════════════════════════════════════════