<?php
define('IBVTE_ACCESS', true);
require 'config.php';
require 'includes/db.php';

try {
    $pdo = new PDO("mysql:host=" . DB_HOST . ";dbname=" . DB_NAME, DB_USERNAME, DB_PASSWORD);
    $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

    // Check live schema
    $hasCatId = false;
    try { $pdo->query("SELECT category_id FROM courses LIMIT 1"); $hasCatId = true; } catch(Exception $e) {}

    $departments = [
        'Aviation Education' => [
            ['IBVTE-AVI-001', 'Diploma in Aviation Management', 'Diploma', '1 Year', '10+2', 'Regular', 38950],
            ['IBVTE-AVI-002', 'Diploma in Airport Management', 'Diploma', '1 Year', '10+2', 'Regular', 38950],
            ['IBVTE-AVI-003', 'Diploma in Airport Ground Operations', 'Diploma', '1 Year', '10+2', 'Regular', 38950],
            ['IBVTE-AVI-004', 'Diploma in Cabin Crew & Hospitality Management', 'Diploma', '1 Year', '10+2', 'Regular', 38950],
            ['IBVTE-AVI-005', 'Diploma in Air Cargo & Logistics Management', 'Diploma', '1 Year', '10+2', 'Regular', 38950],
            ['IBVTE-AVI-006', 'Diploma in Airline Customer Service Management', 'Diploma', '1 Year', '10+2', 'Regular', 38950],
            ['IBVTE-AVI-007', 'Diploma in Airport Terminal Operations', 'Diploma', '1 Year', '10+2', 'Regular', 38950],
            ['IBVTE-AVI-008', 'Diploma in Aviation Hospitality & Travel Management', 'Diploma', '1 Year', '10+2', 'Regular', 38950],
            ['IBVTE-AVI-009', 'Diploma in Air Ticketing & Reservation Management', 'Diploma', '1 Year', '10+2', 'Regular', 38950],
            ['IBVTE-AVI-010', 'Diploma in Ground Handling Operations', 'Diploma', '1 Year', '10+2', 'Regular', 38950],
            ['IBVTE-AVI-011', 'Certificate in Cabin Crew Services', 'Certificate', '6 Months', '10th', 'Regular', 22575],
            ['IBVTE-AVI-012', 'Certificate in Airport Ground Staff Management', 'Certificate', '6 Months', '10th', 'Regular', 22575],
            ['IBVTE-AVI-013', 'Certificate in Air Ticketing & Reservation', 'Certificate', '6 Months', '10th', 'Regular', 22575],
            ['IBVTE-AVI-014', 'Certificate in Passenger Handling Services', 'Certificate', '6 Months', '10th', 'Regular', 22575],
            ['IBVTE-AVI-015', 'Certificate in Aviation Hospitality Services', 'Certificate', '6 Months', '10th', 'Regular', 22575],
            ['IBVTE-AVI-016', 'Certificate in Airport Customer Service', 'Certificate', '6 Months', '10th', 'Regular', 22575],
            ['IBVTE-AVI-017', 'Certificate in Airline Reservation Executive', 'Certificate', '6 Months', '10th', 'Regular', 22575],
            ['IBVTE-AVI-018', 'Certificate in Baggage Handling Operations', 'Certificate', '6 Months', '10th', 'Regular', 22575],
            ['IBVTE-AVI-019', 'Short Term Course in Airport Ground Handling', 'Short Term', '3 Months', '10th', 'Regular', 8960],
            ['IBVTE-AVI-020', 'Short Term Course in Air Ticketing Executive', 'Short Term', '3 Months', '10th', 'Regular', 8960],
            ['IBVTE-AVI-021', 'Short Term Course in Airport Customer Assistance', 'Short Term', '3 Months', '10th', 'Regular', 8960],
            ['IBVTE-AVI-022', 'Short Term Course in Cabin Crew Grooming & Personality Development', 'Short Term', '3 Months', '10th', 'Regular', 8960],
            ['IBVTE-AVI-023', 'Short Term Course in Aviation Communication Skills', 'Short Term', '3 Months', '10th', 'Regular', 8960],
            ['IBVTE-AVI-024', 'Short Term Course in Airline Hospitality Services', 'Short Term', '3 Months', '10th', 'Regular', 8960],
            ['IBVTE-AVI-025', 'Short Term Course in Airport Safety Awareness', 'Short Term', '3 Months', '10th', 'Regular', 8960]
        ],
        'Beautician Education' => [
            ['IBVTE-BEA-001', 'Diploma in Beauty Therapy & Cosmetology', 'Diploma', '1 Year', '10th', 'Regular', 85000],
            ['IBVTE-BEA-002', 'Diploma in Professional Makeup Artistry', 'Diploma', '1 Year', '10th', 'Regular', 95000],
            ['IBVTE-BEA-003', 'Diploma in Hair Designing & Styling', 'Diploma', '1 Year', '10th', 'Regular', 75000],
            ['IBVTE-BEA-004', 'Diploma in Salon Management', 'Diploma', '1 Year', '10th', 'Regular', 65000],
            ['IBVTE-BEA-005', 'Diploma in Advanced Cosmetology', 'Diploma', '1 Year', '10th', 'Regular', 120000],
            ['IBVTE-BEA-006', 'Diploma in Spa Therapy & Wellness', 'Diploma', '1 Year', '10th', 'Regular', 80000],
            ['IBVTE-BEA-007', 'Diploma in Bridal Makeup & Beauty Care', 'Diploma', '1 Year', '10th', 'Regular', 90000],
            ['IBVTE-BEA-008', 'Diploma in Nail Technology & Art', 'Diploma', '1 Year', '10th', 'Regular', 70000],
            ['IBVTE-BEA-009', 'Diploma in Skin Care & Aesthetics', 'Diploma', '1 Year', '10th', 'Regular', 95000],
            ['IBVTE-BEA-010', 'Diploma in Hair & Beauty Management', 'Diploma', '1 Year', '10th', 'Regular', 80000],
            ['IBVTE-BEA-011', 'Certificate in Beautician Course', 'Certificate', '6 Months', '8th Pass', 'Regular', 25000],
            ['IBVTE-BEA-012', 'Certificate in Beauty Culture', 'Certificate', '6 Months', '8th Pass', 'Regular', 28000],
            ['IBVTE-BEA-013', 'Certificate in Makeup Artistry', 'Certificate', '6 Months', '8th Pass', 'Regular', 35000],
            ['IBVTE-BEA-014', 'Certificate in Hair Cutting & Styling', 'Certificate', '6 Months', '8th Pass', 'Regular', 30000],
            ['IBVTE-BEA-015', 'Certificate in Bridal Makeup', 'Certificate', '6 Months', '8th Pass', 'Regular', 40000],
            ['IBVTE-BEA-016', 'Certificate in Nail Art & Extensions', 'Certificate', '6 Months', '8th Pass', 'Regular', 32000],
            ['IBVTE-BEA-017', 'Certificate in Facial & Skin Care', 'Certificate', '6 Months', '8th Pass', 'Regular', 30000],
            ['IBVTE-BEA-018', 'Certificate in Mehndi Artistry', 'Certificate', '6 Months', '8th Pass', 'Regular', 22000],
            ['IBVTE-BEA-019', 'Short Term Course in Basic Beautician', 'Short Term', '3 Months', '8th Pass', 'Regular', 12000],
            ['IBVTE-BEA-020', 'Short Term Course in Bridal Makeup Techniques', 'Short Term', '3 Months', '8th Pass', 'Regular', 18000],
            ['IBVTE-BEA-021', 'Short Term Course in Hair Styling Techniques', 'Short Term', '3 Months', '8th Pass', 'Regular', 15000],
            ['IBVTE-BEA-022', 'Short Term Course in Nail Art & Design', 'Short Term', '3 Months', '8th Pass', 'Regular', 14000],
            ['IBVTE-BEA-023', 'Short Term Course in Professional Facial Therapy', 'Short Term', '3 Months', '8th Pass', 'Regular', 15000],
            ['IBVTE-BEA-024', 'Short Term Course in Saree Draping & Grooming', 'Short Term', '3 Months', '8th Pass', 'Regular', 10000],
            ['IBVTE-BEA-025', 'Short Term Course in Beauty Parlour Assistant', 'Short Term', '3 Months', '8th Pass', 'Regular', 12000]
        ],
        'Automobile Education' => [
            ['IBVTE-AUT-001', 'Diploma in Automobile Engineering Services', 'Diploma', '1 Year', '10th Pass', 'Regular', 75000],
            ['IBVTE-AUT-002', 'Diploma in Automobile Technician', 'Diploma', '1 Year', '10th Pass', 'Regular', 95000],
            ['IBVTE-AUT-003', 'Diploma in Motor Vehicle Mechanic (4 Wheeler)', 'Diploma', '1 Year', '10th Pass', 'Regular', 70000],
            ['IBVTE-AUT-004', 'Diploma in Automotive Service Engineering', 'Diploma', '1 Year', '10th Pass', 'Regular', 85000],
            ['IBVTE-AUT-005', 'Diploma in Vehicle Diagnostics Technology', 'Diploma', '1 Year', '10th Pass', 'Regular', 90000],
            ['IBVTE-AUT-006', 'Diploma in Automotive Electrical Systems', 'Diploma', '1 Year', '10th Pass', 'Regular', 80000],
            ['IBVTE-AUT-007', 'Diploma in Automotive Electronics & ECU Technology', 'Diploma', '1 Year', '10th Pass', 'Regular', 95000],
            ['IBVTE-AUT-008', 'Diploma in Electric Vehicle (EV) Technology', 'Diploma', '1 Year', '10th Pass', 'Regular', 110000],
            ['IBVTE-AUT-009', 'Diploma in Hybrid Vehicle Technology', 'Diploma', '1 Year', '10th Pass', 'Regular', 115000],
            ['IBVTE-AUT-010', 'Diploma in Automobile Workshop Management', 'Diploma', '1 Year', '10th Pass', 'Regular', 75000],
            ['IBVTE-AUT-011', 'Certificate in Automobile Technician', 'Certificate', '6 Months', '10th Pass', 'Regular', 40000],
            ['IBVTE-AUT-012', 'Certificate in Four Wheeler Service Technician', 'Certificate', '6 Months', '10th Pass', 'Regular', 35000],
            ['IBVTE-AUT-013', 'Certificate in Two Wheeler Service Technician', 'Certificate', '6 Months', '10th Pass', 'Regular', 30000],
            ['IBVTE-AUT-014', 'Certificate in Automotive Electrical Technician', 'Certificate', '6 Months', '10th Pass', 'Regular', 38000],
            ['IBVTE-AUT-015', 'Certificate in Engine Repair & Maintenance', 'Certificate', '6 Months', '10th Pass', 'Regular', 35000],
            ['IBVTE-AUT-016', 'Certificate in Automobile Painting Technology', 'Certificate', '6 Months', '10th Pass', 'Regular', 32000],
            ['IBVTE-AUT-017', 'Certificate in Auto Body Repair Technician', 'Certificate', '6 Months', '10th Pass', 'Regular', 35000],
            ['IBVTE-AUT-018', 'Certificate in Vehicle Inspection & Quality Control', 'Certificate', '6 Months', '10th Pass', 'Regular', 40000],
            ['IBVTE-AUT-019', 'Short Term Course in Car Servicing Technician', 'Short Term', '3 Months', '8th Pass', 'Regular', 15000],
            ['IBVTE-AUT-020', 'Short Term Course in Bike Repair Technician', 'Short Term', '3 Months', '8th Pass', 'Regular', 12000],
            ['IBVTE-AUT-021', 'Short Term Course in Wheel Alignment & Balancing', 'Short Term', '3 Months', '8th Pass', 'Regular', 18000],
            ['IBVTE-AUT-022', 'Short Term Course in Vehicle Diagnostic Tools', 'Short Term', '3 Months', '8th Pass', 'Regular', 20000],
            ['IBVTE-AUT-023', 'Short Term Course in EV Maintenance Technician', 'Short Term', '3 Months', '8th Pass', 'Regular', 25000],
            ['IBVTE-AUT-024', 'Short Term Course in Car Detailing & Polishing', 'Short Term', '3 Months', '8th Pass', 'Regular', 12000],
            ['IBVTE-AUT-025', 'Short Term Course in Automobile Workshop Assistant', 'Short Term', '3 Months', '8th Pass', 'Regular', 10000]
        ],
        'Business Education' => [
            ['IBVTE-BUS-001', 'Diploma in Business Management', 'Diploma', '1 Year', '10+2', 'Regular', 75000],
            ['IBVTE-BUS-002', 'Diploma in Financial Management', 'Diploma', '1 Year', '10+2', 'Regular', 85000],
            ['IBVTE-BUS-003', 'Diploma in Marketing Management', 'Diploma', '1 Year', '10+2', 'Regular', 80000],
            ['IBVTE-BUS-004', 'Diploma in Human Resource Management', 'Diploma', '1 Year', '10+2', 'Regular', 80000],
            ['IBVTE-BUS-005', 'Diploma in Retail Management', 'Diploma', '1 Year', '10+2', 'Regular', 70000],
            ['IBVTE-BUS-006', 'Diploma in Entrepreneurship Development', 'Diploma', '1 Year', '10+2', 'Regular', 90000],
            ['IBVTE-BUS-007', 'Diploma in Banking & Finance', 'Diploma', '1 Year', '10+2', 'Regular', 95000],
            ['IBVTE-BUS-008', 'Diploma in International Business Management', 'Diploma', '1 Year', '10+2', 'Regular', 110000],
            ['IBVTE-BUS-009', 'Diploma in Supply Chain & Logistics Management', 'Diploma', '1 Year', '10+2', 'Regular', 90000],
            ['IBVTE-BUS-010', 'Diploma in Office Administration & Management', 'Diploma', '1 Year', '10+2', 'Regular', 65000],
            ['IBVTE-BUS-011', 'Certificate in Business Administration', 'Certificate', '6 Months', '10th Pass', 'Regular', 30000],
            ['IBVTE-BUS-012', 'Certificate in Accounting & Bookkeeping', 'Certificate', '6 Months', '10th Pass', 'Regular', 35000],
            ['IBVTE-BUS-013', 'Certificate in GST & Taxation', 'Certificate', '6 Months', '10th Pass', 'Regular', 40000],
            ['IBVTE-BUS-014', 'Certificate in Retail Store Management', 'Certificate', '6 Months', '10th Pass', 'Regular', 28000],
            ['IBVTE-BUS-015', 'Certificate in Sales & Marketing', 'Certificate', '6 Months', '10th Pass', 'Regular', 35000],
            ['IBVTE-BUS-016', 'Certificate in Human Resource Assistant', 'Certificate', '6 Months', '10th Pass', 'Regular', 32000],
            ['IBVTE-BUS-017', 'Certificate in Office Management', 'Certificate', '6 Months', '10th Pass', 'Regular', 28000],
            ['IBVTE-BUS-018', 'Certificate in Entrepreneurship Skills', 'Certificate', '6 Months', '10th Pass', 'Regular', 38000],
            ['IBVTE-BUS-019', 'Short Term Course in Business Communication', 'Short Term', '3 Months', '8th Pass', 'Regular', 12000],
            ['IBVTE-BUS-020', 'Short Term Course in Tally & Accounting Basics', 'Short Term', '3 Months', '8th Pass', 'Regular', 15000],
            ['IBVTE-BUS-021', 'Short Term Course in Digital Marketing Fundamentals', 'Short Term', '3 Months', '8th Pass', 'Regular', 20000],
            ['IBVTE-BUS-022', 'Short Term Course in Customer Relationship Management', 'Short Term', '3 Months', '8th Pass', 'Regular', 15000],
            ['IBVTE-BUS-023', 'Short Term Course in Small Business Management', 'Short Term', '3 Months', '8th Pass', 'Regular', 18000],
            ['IBVTE-BUS-024', 'Short Term Course in Office Assistant Skills', 'Short Term', '3 Months', '8th Pass', 'Regular', 10000],
            ['IBVTE-BUS-025', 'Short Term Course in E-Commerce Operations', 'Short Term', '3 Months', '8th Pass', 'Regular', 22000]
        ],
        'Child Education' => [
            ['IBVTE-CHD-001', 'Diploma in Early Childhood Care & Education (ECCE)', 'Diploma', '1 Year', '10+2', 'Regular', 65000],
            ['IBVTE-CHD-002', 'Diploma in Nursery Teacher Training (NTT)', 'Diploma', '1 Year', '10+2', 'Regular', 70000],
            ['IBVTE-CHD-003', 'Diploma in Montessori Teacher Training', 'Diploma', '1 Year', '10+2', 'Regular', 75000],
            ['IBVTE-CHD-004', 'Diploma in Pre-Primary Teacher Education', 'Diploma', '1 Year', '10+2', 'Regular', 68000],
            ['IBVTE-CHD-005', 'Diploma in Child Psychology & Development', 'Diploma', '1 Year', '10+2', 'Regular', 85000],
            ['IBVTE-CHD-006', 'Diploma in Child Care & Education Management', 'Diploma', '1 Year', '10+2', 'Regular', 72000],
            ['IBVTE-CHD-007', 'Diploma in Inclusive & Special Child Education', 'Diploma', '1 Year', '10+2', 'Regular', 90000],
            ['IBVTE-CHD-008', 'Diploma in Play School Management', 'Diploma', '1 Year', '10+2', 'Regular', 65000],
            ['IBVTE-CHD-009', 'Diploma in Child Health & Nutrition Education', 'Diploma', '1 Year', '10+2', 'Regular', 80000],
            ['IBVTE-CHD-010', 'Diploma in Educational Psychology for Children', 'Diploma', '1 Year', '10+2', 'Regular', 85000],
            ['IBVTE-CHD-011', 'Certificate in Nursery Teacher Training', 'Certificate', '6 Months', '10th Pass', 'Regular', 28000],
            ['IBVTE-CHD-012', 'Certificate in Montessori Education', 'Certificate', '6 Months', '10th Pass', 'Regular', 35000],
            ['IBVTE-CHD-013', 'Certificate in Child Care & Development', 'Certificate', '6 Months', '10th Pass', 'Regular', 30000],
            ['IBVTE-CHD-014', 'Certificate in Preschool Education', 'Certificate', '6 Months', '10th Pass', 'Regular', 32000],
            ['IBVTE-CHD-015', 'Certificate in Child Psychology Basics', 'Certificate', '6 Months', '10th Pass', 'Regular', 38000],
            ['IBVTE-CHD-016', 'Certificate in Special Child Care', 'Certificate', '6 Months', '10th Pass', 'Regular', 40000],
            ['IBVTE-CHD-017', 'Certificate in Creative Teaching Methods', 'Certificate', '6 Months', '10th Pass', 'Regular', 30000],
            ['IBVTE-CHD-018', 'Certificate in Play School Management', 'Certificate', '6 Months', '10th Pass', 'Regular', 35000],
            ['IBVTE-CHD-019', 'Short Term Course in Storytelling & Classroom Activities', 'Short Term', '3 Months', '8th Pass', 'Regular', 10000],
            ['IBVTE-CHD-020', 'Short Term Course in Child Behaviour Management', 'Short Term', '3 Months', '8th Pass', 'Regular', 15000],
            ['IBVTE-CHD-021', 'Short Term Course in Preschool Teaching Skills', 'Short Term', '3 Months', '8th Pass', 'Regular', 12000],
            ['IBVTE-CHD-022', 'Short Term Course in Educational Toys & Learning Materials', 'Short Term', '3 Months', '8th Pass', 'Regular', 10000],
            ['IBVTE-CHD-023', 'Short Term Course in Child Nutrition Awareness', 'Short Term', '3 Months', '8th Pass', 'Regular', 12000],
            ['IBVTE-CHD-024', 'Short Term Course in Parent Counselling Skills', 'Short Term', '3 Months', '8th Pass', 'Regular', 18000],
            ['IBVTE-CHD-025', 'Short Term Course in Day Care Assistant Training', 'Short Term', '3 Months', '8th Pass', 'Regular', 10000]
        ]
    ];

    foreach ($departments as $catName => $courses) {
        // Ensure category exists
        $slug = strtolower(trim(preg_replace('/[^A-Za-z0-9-]+/', '-', $catName), '-'));
        $stmt = $pdo->prepare("SELECT id FROM course_categories WHERE slug = ?");
        $stmt->execute([$slug]);
        $catId = $stmt->fetchColumn();

        if (!$catId) {
            $pdo->prepare("INSERT INTO course_categories (name, slug, description, is_active, display_order) VALUES (?, ?, '', 1, 99)")->execute([$catName, $slug]);
            $catId = $pdo->lastInsertId();
        }

        foreach ($courses as $c) {
            $code = $c[0];
            $name = $c[1];
            $type = $c[2]; // Diploma, Certificate, Short Term
            $typeSlug = strtolower(str_replace(' Course', '', $type)); // diploma, certificate, short term
            if ($typeSlug == 'certificate') $typeSlug = 'certification';
            
            $duration = $c[3];
            $eligibility = $c[4];
            $mode = strtolower($c[5]); // regular -> offline
            if ($mode == 'regular') $mode = 'offline';
            $fee = $c[6];
            
            $dur_m = strpos($duration, 'Year') !== false ? 12 : (strpos($duration, 'Months') !== false ? intval($duration) : 6);
            $dur_t = strpos($duration, 'Year') !== false ? 'years' : 'months';
            $dur_v = intval($duration);
            if ($dur_v == 0) $dur_v = 1;

            // Ensure sub category exists based on type
            $subCatId = null;
            if ($hasCatId) {
                $subStmt = $pdo->prepare("SELECT id FROM course_sub_categories WHERE category_id = ? AND name LIKE ?");
                $subStmt->execute([$catId, $type . '%']);
                $subCatId = $subStmt->fetchColumn();
                if (!$subCatId) {
                    $subSlug = $slug . '-' . strtolower(str_replace(' ', '-', $type));
                    $pdo->prepare("INSERT INTO course_sub_categories (category_id, name, slug, is_active) VALUES (?, ?, ?, 1)")->execute([$catId, $type . ' Course', $subSlug]);
                    $subCatId = $pdo->lastInsertId();
                }
            }

            $typeSlugLocal = $typeSlug;
            if ($typeSlugLocal == 'short term') $typeSlugLocal = 'certification';

            // Check if course exists
            $stmt = $pdo->prepare("SELECT id FROM courses WHERE course_code = ?");
            $stmt->execute([$code]);
            $courseId = $stmt->fetchColumn();

            if ($courseId) {
                // Update course
                if ($hasCatId) {
                    $stmt = $pdo->prepare("UPDATE courses SET course_name=?, category_id=?, sub_category_id=?, course_type=?, duration_text=?, duration_months=?, duration_value=?, eligibility=?, mode=? WHERE id=?");
                    $stmt->execute([$name, $catId, $subCatId, $type . ' Course', $duration, $dur_m, $dur_v, $eligibility, $mode, $courseId]);
                } else {
                    $stmt = $pdo->prepare("UPDATE courses SET course_name=?, short_name=?, category=?, course_type=?, duration=?, duration_months=?, duration_type=?, duration_value=?, eligibility=?, mode=? WHERE id=?");
                    $stmt->execute([$name, $catName, $type . ' Course', $typeSlugLocal, $duration, $dur_m, $dur_t, $dur_v, $eligibility, $mode, $courseId]);
                }

                // Update Fee
                $feeStmt = $pdo->prepare("SELECT id FROM course_fees WHERE course_id = ? AND user_type='college'");
                $feeStmt->execute([$courseId]);
                if ($feeStmt->fetchColumn()) {
                    $pdo->prepare("UPDATE course_fees SET total_fee=? WHERE course_id=? AND user_type='college'")->execute([$fee, $courseId]);
                } else {
                    $pdo->prepare("INSERT INTO course_fees (course_id, user_type, admission_fee, exam_fee, total_fee, valid_from) VALUES (?, 'college', 0, 0, ?, '2026-01-01')")->execute([$courseId, $fee]);
                }
            } else {
                // Insert course
                if ($hasCatId) {
                    $stmt = $pdo->prepare("INSERT INTO courses (category_id, sub_category_id, course_type, course_name, course_code, short_name, duration_text, duration_months, duration_value, eligibility, mode, is_active) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
                    $stmt->execute([$catId, $subCatId, $type . ' Course', $name, $code, $catName, $duration, $dur_m, $dur_v, $eligibility, $mode, 1]);
                } else {
                    $stmt = $pdo->prepare("INSERT INTO courses (course_code, course_name, short_name, category, course_type, duration, duration_months, duration_type, duration_value, eligibility, mode, is_active) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
                    $stmt->execute([$code, $name, $catName, $type . ' Course', $typeSlugLocal, $duration, $dur_m, $dur_t, $dur_v, $eligibility, $mode, 1]);
                }
                $courseId = $pdo->lastInsertId();
                
                // Insert Fee
                $pdo->prepare("INSERT INTO course_fees (course_id, user_type, admission_fee, exam_fee, total_fee, valid_from) VALUES (?, 'college', 0, 0, ?, '2026-01-01')")->execute([$courseId, $fee]);
            }
        }
    }
    echo "All courses imported successfully!\n";

} catch(Exception $e) {
    echo "Error: " . $e->getMessage() . "\n";
}
