<?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);

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

    // Deactivate old computer courses
    if ($isLive) {
        $pdo->query("UPDATE courses SET is_active = 0 WHERE category_id = 3");
    } else {
        $pdo->query("UPDATE courses SET is_active = 0 WHERE short_name = 'Computer Education'");
    }

    $coursesData = [
        // Civil & Architecture Education
        ['IBVTE-CAE-001', 'Diploma in Civil Engineering Technology', 'Diploma', '1 Year', '10th Pass', 'Regular', 'Theory + Practical', '85000', 'Civil & Architecture Education'],
        ['IBVTE-CAE-002', 'Diploma in Construction Management', 'Diploma', '1 Year', '10+2', 'Regular', 'Theory + Project', '95000', 'Civil & Architecture Education'],
        ['IBVTE-CAE-003', 'Diploma in Architectural Draftsmanship', 'Diploma', '1 Year', '10+2', 'Regular', 'Practical + Portfolio', '90000', 'Civil & Architecture Education'],
        ['IBVTE-CAE-004', 'Diploma in Building Design & Planning', 'Diploma', '1 Year', '10+2', 'Regular', 'Theory + Practical', '100000', 'Civil & Architecture Education'],
        ['IBVTE-CAE-005', 'Diploma in Quantity Surveying & Estimation', 'Diploma', '1 Year', '10+2', 'Regular', 'Theory + Project', '95000', 'Civil & Architecture Education'],
        ['IBVTE-CAE-006', 'Diploma in Land Surveying Technology', 'Diploma', '1 Year', '10th Pass', 'Regular', 'Practical + Field Work', '80000', 'Civil & Architecture Education'],
        ['IBVTE-CAE-007', 'Diploma in Structural Design Technology', 'Diploma', '1 Year', '10+2', 'Regular', 'Theory + Practical', '110000', 'Civil & Architecture Education'],
        ['IBVTE-CAE-008', 'Diploma in Interior Architecture & Space Planning', 'Diploma', '1 Year', '10+2', 'Regular', 'Design Project + Viva', '120000', 'Civil & Architecture Education'],
        ['IBVTE-CAE-009', 'Diploma in Construction Site Supervision', 'Diploma', '1 Year', '10th Pass', 'Regular', 'Theory + Practical', '75000', 'Civil & Architecture Education'],
        ['IBVTE-CAE-010', 'Diploma in Building Information Modeling (BIM)', 'Diploma', '1 Year', '10+2', 'Regular', 'Project + Practical', '125000', 'Civil & Architecture Education'],
        ['IBVTE-CAE-011', 'Certificate in AutoCAD for Civil & Architecture', 'Certificate', '6 Months', '10th Pass', 'Regular', 'Practical Assessment', '35000', 'Civil & Architecture Education'],
        ['IBVTE-CAE-012', 'Certificate in Building Construction Technology', 'Certificate', '6 Months', '10th Pass', 'Regular', 'Theory + Practical', '40000', 'Civil & Architecture Education'],
        ['IBVTE-CAE-013', 'Certificate in Quantity Surveying', 'Certificate', '6 Months', '10th Pass', 'Regular', 'Practical + Viva', '45000', 'Civil & Architecture Education'],
        ['IBVTE-CAE-014', 'Certificate in Architectural Drawing', 'Certificate', '6 Months', '10th Pass', 'Regular', 'Portfolio Assessment', '42000', 'Civil & Architecture Education'],
        ['IBVTE-CAE-015', 'Certificate in Surveying Techniques', 'Certificate', '6 Months', '10th Pass', 'Regular', 'Field Practical', '38000', 'Civil & Architecture Education'],
        ['IBVTE-CAE-016', 'Certificate in Interior Design Fundamentals', 'Certificate', '6 Months', '10th Pass', 'Regular', 'Design Project', '50000', 'Civil & Architecture Education'],
        ['IBVTE-CAE-017', 'Certificate in Construction Safety Management', 'Certificate', '6 Months', '10th Pass', 'Regular', 'Theory + Practical', '35000', 'Civil & Architecture Education'],
        ['IBVTE-CAE-018', 'Certificate in Building Estimation & Costing', 'Certificate', '6 Months', '10th Pass', 'Regular', 'Project Work', '45000', 'Civil & Architecture Education'],
        ['IBVTE-CAE-019', 'Short Term Course in AutoCAD Drafting', 'Short Term', '3 Months', '8th Pass', 'Regular', 'Practical Test', '15000', 'Civil & Architecture Education'],
        ['IBVTE-CAE-020', 'Short Term Course in Construction Site Management', 'Short Term', '3 Months', '8th Pass', 'Regular', 'Practical Assessment', '18000', 'Civil & Architecture Education'],
        ['IBVTE-CAE-021', 'Short Term Course in Building Estimation Basics', 'Short Term', '3 Months', '8th Pass', 'Regular', 'Theory + Practical', '15000', 'Civil & Architecture Education'],
        ['IBVTE-CAE-022', 'Short Term Course in Land Surveying Assistant', 'Short Term', '3 Months', '8th Pass', 'Regular', 'Field Test', '18000', 'Civil & Architecture Education'],
        ['IBVTE-CAE-023', 'Short Term Course in Interior Design Sketching', 'Short Term', '3 Months', '8th Pass', 'Regular', 'Portfolio Review', '20000', 'Civil & Architecture Education'],
        ['IBVTE-CAE-024', 'Short Term Course in Construction Materials Technology', 'Short Term', '3 Months', '8th Pass', 'Regular', 'Practical Test', '12000', 'Civil & Architecture Education'],
        ['IBVTE-CAE-025', 'Short Term Course in Site Supervisor Assistant Training', 'Short Term', '3 Months', '8th Pass', 'Regular', 'Practical + Viva', '15000', 'Civil & Architecture Education'],

        // Computer Education
        ['IBVTE-COM-001', 'Diploma in Computer Applications (DCA)', 'Diploma', '1 Year', '10+2', 'Regular', 'Theory + Practical', '45000', 'Computer Education'],
        ['IBVTE-COM-002', 'Diploma in Advanced Computer Applications (ADCA)', 'Diploma', '1 Year', '10+2', 'Regular', 'Theory + Practical + Project', '60000', 'Computer Education'],
        ['IBVTE-COM-003', 'Diploma in Software Development', 'Diploma', '1 Year', '10+2', 'Regular', 'Theory + Project', '95000', 'Computer Education'],
        ['IBVTE-COM-004', 'Diploma in Web Designing & Development', 'Diploma', '1 Year', '10+2', 'Regular', 'Practical + Portfolio', '80000', 'Computer Education'],
        ['IBVTE-COM-005', 'Diploma in Full Stack Development', 'Diploma', '1 Year', '10+2', 'Regular', 'Project + Viva', '120000', 'Computer Education'],
        ['IBVTE-COM-006', 'Diploma in Data Analytics', 'Diploma', '1 Year', '10+2', 'Regular', 'Theory + Project', '110000', 'Computer Education'],
        ['IBVTE-COM-007', 'Diploma in Artificial Intelligence & Machine Learning', 'Diploma', '1 Year', '10+2', 'Regular', 'Project + Practical', '150000', 'Computer Education'],
        ['IBVTE-COM-008', 'Diploma in Cyber Security & Ethical Hacking', 'Diploma', '1 Year', '10+2', 'Regular', 'Practical + Lab Assessment', '140000', 'Computer Education'],
        ['IBVTE-COM-009', 'Diploma in Cloud Computing', 'Diploma', '1 Year', '10+2', 'Regular', 'Project + Practical', '130000', 'Computer Education'],
        ['IBVTE-COM-010', 'Diploma in Computer Hardware & Networking', 'Diploma', '1 Year', '10+2', 'Regular', 'Theory + Practical', '75000', 'Computer Education'],
        ['IBVTE-COM-011', 'Certificate in Computer Applications (CCA)', 'Certificate', '6 Months', '10th Pass', 'Regular', 'Theory + Practical', '20000', 'Computer Education'],
        ['IBVTE-COM-012', 'Certificate in Tally Prime & GST', 'Certificate', '6 Months', '10th Pass', 'Regular', 'Practical Assessment', '25000', 'Computer Education'],
        ['IBVTE-COM-013', 'Certificate in Web Designing', 'Certificate', '6 Months', '10th Pass', 'Regular', 'Project Work', '35000', 'Computer Education'],
        ['IBVTE-COM-014', 'Certificate in Graphic Designing', 'Certificate', '6 Months', '10th Pass', 'Regular', 'Portfolio Assessment', '40000', 'Computer Education'],
        ['IBVTE-COM-015', 'Certificate in Digital Marketing', 'Certificate', '6 Months', '10th Pass', 'Regular', 'Project + Viva', '45000', 'Computer Education'],
        ['IBVTE-COM-016', 'Certificate in Python Programming', 'Certificate', '6 Months', '10th Pass', 'Regular', 'Practical Test', '40000', 'Computer Education'],
        ['IBVTE-COM-017', 'Certificate in Computer Hardware Maintenance', 'Certificate', '6 Months', '10th Pass', 'Regular', 'Practical Assessment', '30000', 'Computer Education'],
        ['IBVTE-COM-018', 'Certificate in Networking Fundamentals', 'Certificate', '6 Months', '10th Pass', 'Regular', 'Theory + Practical', '35000', 'Computer Education'],
        ['IBVTE-COM-019', 'Short Term Course in MS Office Automation', 'Short Term', '3 Months', '8th Pass', 'Regular', 'Practical Test', '8000', 'Computer Education'],
        ['IBVTE-COM-020', 'Short Term Course in Internet & Email Applications', 'Short Term', '3 Months', '8th Pass', 'Regular', 'Practical Assessment', '8000', 'Computer Education'],
        ['IBVTE-COM-021', 'Short Term Course in Computer Typing & Data Entry', 'Short Term', '3 Months', '8th Pass', 'Regular', 'Speed Test + Practical', '10000', 'Computer Education'],
        ['IBVTE-COM-022', 'Short Term Course in Canva & Basic Graphic Design', 'Short Term', '3 Months', '8th Pass', 'Regular', 'Project Assessment', '15000', 'Computer Education'],
        ['IBVTE-COM-023', 'Short Term Course in Social Media Marketing', 'Short Term', '3 Months', '8th Pass', 'Regular', 'Project Work', '18000', 'Computer Education'],
        ['IBVTE-COM-024', 'Short Term Course in Computer Hardware Basics', 'Short Term', '3 Months', '8th Pass', 'Regular', 'Practical Test', '12000', 'Computer Education'],
        ['IBVTE-COM-025', 'Short Term Course in AI Tools & Productivity', 'Short Term', '3 Months', '8th Pass', 'Regular', 'Practical + Viva', '25000', 'Computer Education'],

        // Fashion Designing Education
        ['IBVTE-FAS-001', 'Diploma in Fashion Designing', 'Diploma', '1 Year', '10th Pass', 'Regular', 'Theory + Practical + Portfolio', '85000', 'Fashion Designing Education'],
        ['IBVTE-FAS-002', 'Diploma in Apparel Designing', 'Diploma', '1 Year', '10th Pass', 'Regular', 'Design Project + Viva', '90000', 'Fashion Designing Education'],
        ['IBVTE-FAS-003', 'Diploma in Fashion Technology', 'Diploma', '1 Year', '10+2', 'Regular', 'Theory + Practical', '95000', 'Fashion Designing Education'],
        ['IBVTE-FAS-004', 'Diploma in Textile Design Technology', 'Diploma', '1 Year', '10+2', 'Regular', 'Practical + Project', '90000', 'Fashion Designing Education'],
        ['IBVTE-FAS-005', 'Diploma in Fashion CAD & Digital Design', 'Diploma', '1 Year', '10+2', 'Regular', 'CAD Project + Portfolio', '110000', 'Fashion Designing Education'],
        ['IBVTE-FAS-006', 'Diploma in Fashion Illustration & Styling', 'Diploma', '1 Year', '10th Pass', 'Regular', 'Portfolio Assessment', '85000', 'Fashion Designing Education'],
        ['IBVTE-FAS-007', 'Diploma in Garment Construction Technology', 'Diploma', '1 Year', '10th Pass', 'Regular', 'Practical Examination', '80000', 'Fashion Designing Education'],
        ['IBVTE-FAS-008', 'Diploma in Fashion Merchandising & Retail Management', 'Diploma', '1 Year', '10+2', 'Regular', 'Project + Viva', '100000', 'Fashion Designing Education'],
        ['IBVTE-FAS-009', 'Diploma in Boutique Management & Entrepreneurship', 'Diploma', '1 Year', '10th Pass', 'Regular', 'Project Work', '75000', 'Fashion Designing Education'],
        ['IBVTE-FAS-010', 'Diploma in Bridal Wear & Couture Designing', 'Diploma', '1 Year', '10th Pass', 'Regular', 'Portfolio + Practical', '95000', 'Fashion Designing Education'],
        ['IBVTE-FAS-011', 'Certificate in Fashion Designing', 'Certificate', '6 Months', '10th Pass', 'Regular', 'Practical Assessment', '35000', 'Fashion Designing Education'],
        ['IBVTE-FAS-012', 'Certificate in Fashion CAD', 'Certificate', '6 Months', '10th Pass', 'Regular', 'CAD Practical Test', '50000', 'Fashion Designing Education'],
        ['IBVTE-FAS-013', 'Certificate in Textile Designing', 'Certificate', '6 Months', '10th Pass', 'Regular', 'Project Work', '40000', 'Fashion Designing Education'],
        ['IBVTE-FAS-014', 'Certificate in Fashion Illustration', 'Certificate', '6 Months', '10th Pass', 'Regular', 'Portfolio Assessment', '35000', 'Fashion Designing Education'],
        ['IBVTE-FAS-015', 'Certificate in Garment Manufacturing', 'Certificate', '6 Months', '10th Pass', 'Regular', 'Practical Test', '38000', 'Fashion Designing Education'],
        ['IBVTE-FAS-016', 'Certificate in Boutique Management', 'Certificate', '6 Months', '10th Pass', 'Regular', 'Project + Viva', '32000', 'Fashion Designing Education'],
        ['IBVTE-FAS-017', 'Certificate in Fashion Styling', 'Certificate', '6 Months', '10th Pass', 'Regular', 'Practical Assessment', '42000', 'Fashion Designing Education'],
        ['IBVTE-FAS-018', 'Certificate in Pattern Making & Draping', 'Certificate', '6 Months', '10th Pass', 'Regular', 'Practical Test', '45000', 'Fashion Designing Education'],
        ['IBVTE-FAS-019', 'Short Term Course in Basic Tailoring & Stitching', 'Short Term', '3 Months', '8th Pass', 'Regular', 'Practical Test', '12000', 'Fashion Designing Education'],
        ['IBVTE-FAS-020', 'Short Term Course in Designer Blouse Making', 'Short Term', '3 Months', '8th Pass', 'Regular', 'Practical Assessment', '18000', 'Fashion Designing Education'],
        ['IBVTE-FAS-021', 'Short Term Course in Boutique Startup Skills', 'Short Term', '3 Months', '8th Pass', 'Regular', 'Project Work', '15000', 'Fashion Designing Education'],
        ['IBVTE-FAS-022', 'Short Term Course in Fashion Sketching', 'Short Term', '3 Months', '8th Pass', 'Regular', 'Portfolio Review', '15000', 'Fashion Designing Education'],
        ['IBVTE-FAS-023', 'Short Term Course in Embroidery & Surface Ornamentation', 'Short Term', '3 Months', '8th Pass', 'Regular', 'Practical Test', '18000', 'Fashion Designing Education'],
        ['IBVTE-FAS-024', 'Short Term Course in Fashion Accessories Design', 'Short Term', '3 Months', '8th Pass', 'Regular', 'Practical Assessment', '20000', 'Fashion Designing Education'],
        ['IBVTE-FAS-025', 'Short Term Course in Saree Draping & Fashion Grooming', 'Short Term', '3 Months', '8th Pass', 'Regular', 'Practical + Viva', '10000', 'Fashion Designing Education'],

        // Gem & Jewellery Education
        ['IBVTE-GJE-001', 'Diploma in Gemology & Diamond Grading', 'Diploma', '1 Year', '10+2', 'Regular', 'Theory + Practical', '125000', 'Gem & Jewellery Education'],
        ['IBVTE-GJE-002', 'Diploma in Jewellery Design & Manufacturing', 'Diploma', '1 Year', '10th Pass', 'Regular', 'Practical + Portfolio', '110000', 'Gem & Jewellery Education'],
        ['IBVTE-GJE-003', 'Diploma in CAD Jewellery Designing', 'Diploma', '1 Year', '10+2', 'Regular', 'CAD Project + Viva', '140000', 'Gem & Jewellery Education'],
        ['IBVTE-GJE-004', 'Diploma in Diamond Processing Technology', 'Diploma', '1 Year', '10th Pass', 'Regular', 'Theory + Practical', '120000', 'Gem & Jewellery Education'],
        ['IBVTE-GJE-005', 'Diploma in Gemstone Identification & Certification', 'Diploma', '1 Year', '10+2', 'Regular', 'Practical Assessment', '135000', 'Gem & Jewellery Education'],
        ['IBVTE-GJE-006', 'Diploma in Jewellery Retail Management', 'Diploma', '1 Year', '10+2', 'Regular', 'Theory + Project', '95000', 'Gem & Jewellery Education'],
        ['IBVTE-GJE-007', 'Diploma in Precious Stone Technology', 'Diploma', '1 Year', '10+2', 'Regular', 'Theory + Practical', '115000', 'Gem & Jewellery Education'],
        ['IBVTE-GJE-008', 'Diploma in Jewellery Merchandising', 'Diploma', '1 Year', '10+2', 'Regular', 'Project + Viva', '90000', 'Gem & Jewellery Education'],
        ['IBVTE-GJE-009', 'Diploma in Goldsmith Technology', 'Diploma', '1 Year', '10th Pass', 'Regular', 'Workshop + Practical', '85000', 'Gem & Jewellery Education'],
        ['IBVTE-GJE-010', 'Diploma in Luxury Jewellery Business Management', 'Diploma', '1 Year', '10+2', 'Regular', 'Theory + Project', '150000', 'Gem & Jewellery Education'],
        ['IBVTE-GJE-011', 'Certificate in Jewellery Designing', 'Certificate', '6 Months', '10th Pass', 'Regular', 'Portfolio Assessment', '45000', 'Gem & Jewellery Education'],
        ['IBVTE-GJE-012', 'Certificate in Gemology', 'Certificate', '6 Months', '10th Pass', 'Regular', 'Theory + Practical', '55000', 'Gem & Jewellery Education'],
        ['IBVTE-GJE-013', 'Certificate in Diamond Grading', 'Certificate', '6 Months', '10th Pass', 'Regular', 'Practical Assessment', '60000', 'Gem & Jewellery Education'],
        ['IBVTE-GJE-014', 'Certificate in CAD Jewellery Design', 'Certificate', '6 Months', '10th Pass', 'Regular', 'CAD Project', '65000', 'Gem & Jewellery Education'],
        ['IBVTE-GJE-015', 'Certificate in Jewellery Manufacturing', 'Certificate', '6 Months', '10th Pass', 'Regular', 'Practical Test', '50000', 'Gem & Jewellery Education'],
        ['IBVTE-GJE-016', 'Certificate in Goldsmith Skills', 'Certificate', '6 Months', '10th Pass', 'Regular', 'Workshop Assessment', '40000', 'Gem & Jewellery Education'],
        ['IBVTE-GJE-017', 'Certificate in Gemstone Identification', 'Certificate', '6 Months', '10th Pass', 'Regular', 'Practical Assessment', '55000', 'Gem & Jewellery Education'],
        ['IBVTE-GJE-018', 'Certificate in Jewellery Retail Sales', 'Certificate', '6 Months', '10th Pass', 'Regular', 'Theory + Viva', '35000', 'Gem & Jewellery Education'],
        ['IBVTE-GJE-019', 'Short Term Course in Artificial Jewellery Design', 'Short Term', '3 Months', '8th Pass', 'Regular', 'Practical Test', '15000', 'Gem & Jewellery Education'],
        ['IBVTE-GJE-020', 'Short Term Course in Bead Jewellery Making', 'Short Term', '3 Months', '8th Pass', 'Regular', 'Practical Assessment', '12000', 'Gem & Jewellery Education'],
        ['IBVTE-GJE-021', 'Short Term Course in Fashion Jewellery Design', 'Short Term', '3 Months', '8th Pass', 'Regular', 'Portfolio Review', '18000', 'Gem & Jewellery Education'],
        ['IBVTE-GJE-022', 'Short Term Course in Gemstone Basics', 'Short Term', '3 Months', '8th Pass', 'Regular', 'Theory + Practical', '20000', 'Gem & Jewellery Education'],
        ['IBVTE-GJE-023', 'Short Term Course in Jewellery Photography & Cataloging', 'Short Term', '3 Months', '8th Pass', 'Regular', 'Project Assessment', '22000', 'Gem & Jewellery Education'],
        ['IBVTE-GJE-024', 'Short Term Course in Jewellery Packaging & Branding', 'Short Term', '3 Months', '8th Pass', 'Regular', 'Practical Test', '15000', 'Gem & Jewellery Education'],
        ['IBVTE-GJE-025', 'Short Term Course in Jewellery Store Assistant Training', 'Short Term', '3 Months', '8th Pass', 'Regular', 'Practical + Viva', '12000', 'Gem & Jewellery Education'],

        // Hotel Management
        ['IBVTE-HMH-001', 'Diploma in Hotel Management', 'Diploma', '1 Year', '10+2', 'Regular', 'Theory + Practical + Internship', '95000', 'Hotel Management'],
        ['IBVTE-HMH-002', 'Diploma in Hospitality Management', 'Diploma', '1 Year', '10+2', 'Regular', 'Theory + Practical', '90000', 'Hotel Management'],
        ['IBVTE-HMH-003', 'Diploma in Food Production & Culinary Arts', 'Diploma', '1 Year', '10th Pass', 'Regular', 'Practical + Kitchen Assessment', '110000', 'Hotel Management'],
        ['IBVTE-HMH-004', 'Diploma in Bakery & Confectionery', 'Diploma', '1 Year', '10th Pass', 'Regular', 'Practical + Project', '95000', 'Hotel Management'],
        ['IBVTE-HMH-005', 'Diploma in Front Office Management', 'Diploma', '1 Year', '10+2', 'Regular', 'Theory + Practical', '80000', 'Hotel Management'],
        ['IBVTE-HMH-006', 'Diploma in Food & Beverage Service Management', 'Diploma', '1 Year', '10th Pass', 'Regular', 'Practical + Viva', '90000', 'Hotel Management'],
        ['IBVTE-HMH-007', 'Diploma in Housekeeping Operations', 'Diploma', '1 Year', '10th Pass', 'Regular', 'Theory + Practical', '75000', 'Hotel Management'],
        ['IBVTE-HMH-008', 'Diploma in Travel, Tourism & Hospitality Management', 'Diploma', '1 Year', '10+2', 'Regular', 'Project + Internship', '100000', 'Hotel Management'],
        ['IBVTE-HMH-009', 'Diploma in Resort & Event Management', 'Diploma', '1 Year', '10+2', 'Regular', 'Project + Practical', '105000', 'Hotel Management'],
        ['IBVTE-HMH-010', 'Diploma in Cruise Hospitality Management', 'Diploma', '1 Year', '10+2', 'Regular', 'Theory + Internship', '125000', 'Hotel Management'],
        ['IBVTE-HMH-011', 'Certificate in Hotel Management', 'Certificate', '6 Months', '10th Pass', 'Regular', 'Theory + Practical', '40000', 'Hotel Management'],
        ['IBVTE-HMH-012', 'Certificate in Food Production', 'Certificate', '6 Months', '10th Pass', 'Regular', 'Kitchen Practical', '50000', 'Hotel Management'],
        ['IBVTE-HMH-013', 'Certificate in Bakery & Confectionery', 'Certificate', '6 Months', '10th Pass', 'Regular', 'Practical Assessment', '45000', 'Hotel Management'],
        ['IBVTE-HMH-014', 'Certificate in Front Office Operations', 'Certificate', '6 Months', '10th Pass', 'Regular', 'Practical + Viva', '35000', 'Hotel Management'],
        ['IBVTE-HMH-015', 'Certificate in Food & Beverage Service', 'Certificate', '6 Months', '10th Pass', 'Regular', 'Practical Test', '40000', 'Hotel Management'],
        ['IBVTE-HMH-016', 'Certificate in Housekeeping Operations', 'Certificate', '6 Months', '10th Pass', 'Regular', 'Practical Assessment', '30000', 'Hotel Management'],
        ['IBVTE-HMH-017', 'Certificate in Restaurant Management', 'Certificate', '6 Months', '10th Pass', 'Regular', 'Project Work', '42000', 'Hotel Management'],
        ['IBVTE-HMH-018', 'Certificate in Hospitality Customer Service', 'Certificate', '6 Months', '10th Pass', 'Regular', 'Theory + Viva', '35000', 'Hotel Management'],
        ['IBVTE-HMH-019', 'Short Term Course in Food Production Assistant', 'Short Term', '3 Months', '8th Pass', 'Regular', 'Practical Test', '15000', 'Hotel Management'],
        ['IBVTE-HMH-020', 'Short Term Course in Barista Skills', 'Short Term', '3 Months', '8th Pass', 'Regular', 'Practical Assessment', '20000', 'Hotel Management'],
        ['IBVTE-HMH-021', 'Short Term Course in Bakery Fundamentals', 'Short Term', '3 Months', '8th Pass', 'Regular', 'Practical Test', '18000', 'Hotel Management'],
        ['IBVTE-HMH-022', 'Short Term Course in Housekeeping Assistant', 'Short Term', '3 Months', '8th Pass', 'Regular', 'Practical Assessment', '12000', 'Hotel Management'],
        ['IBVTE-HMH-023', 'Short Term Course in Front Office Assistant', 'Short Term', '3 Months', '8th Pass', 'Regular', 'Practical + Viva', '15000', 'Hotel Management'],
        ['IBVTE-HMH-024', 'Short Term Course in Hospitality Grooming & Communication', 'Short Term', '3 Months', '8th Pass', 'Regular', 'Practical Assessment', '12000', 'Hotel Management'],
        ['IBVTE-HMH-025', 'Short Term Course in Catering Service Assistant', 'Short Term', '3 Months', '8th Pass', 'Regular', 'Practical Test', '15000', 'Hotel Management'],
    ];

    $count = 0;
    foreach ($coursesData as $course) {
        $code = $course[0];
        $name = $course[1];
        $type = $course[2];
        $duration = $course[3];
        $eligibility = $course[4];
        $mode = 'offline';
        $fee = floatval($course[7]);
        $catName = $course[8];

        $durParts = explode(' ', $duration);
        $dur_v = $durParts[0];
        $dur_t = count($durParts) > 1 ? strtolower($durParts[1]) : 'months';
        if ($dur_t == 'year') $dur_t = 'years';
        
        $dur_m = 0;
        if ($dur_t == 'years') {
            $dur_m = intval($dur_v) * 12;
        } else if ($dur_t == 'months') {
            $dur_m = intval($dur_v);
        }

        $typeSlugLive = '';
        $typeSlugLocal = '';
        if (stripos($type, 'diploma') !== false) {
            $typeSlugLive = '2'; 
            $typeSlugLocal = 'diploma';
        } else if (stripos($type, 'short term') !== false) {
            $typeSlugLive = '1';
            $typeSlugLocal = 'certification'; 
        } else if (stripos($type, 'certificate') !== false) {
            $typeSlugLive = '1';
            $typeSlugLocal = 'certification';
        }

        if ($isLive) {
            // Find category
            $slug = strtolower(trim(preg_replace('/[^A-Za-z0-9-]+/', '-', $catName), '-'));
            $stmt = $pdo->prepare("SELECT id FROM course_categories WHERE slug = ? OR name = ? ORDER BY display_order ASC LIMIT 1");
            $stmt->execute([$slug, $catName]);
            $catId = $stmt->fetchColumn();

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

            // Find or create sub_category
            $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();
            }

            // Insert course
            $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, $typeSlugLive, $name, $code, $catName, $duration, $dur_m, $dur_v, $eligibility, $mode, 1]);
            $courseId = $pdo->lastInsertId();
            
            // Insert fee
            $stmt = $pdo->prepare("INSERT INTO course_fees (course_id, user_type, admission_fee, exam_fee, total_fee, valid_from) VALUES (?, ?, 0, 0, ?, '2026-01-01')");
            $stmt->execute([$courseId, 'college', $fee]);
            
        } else {
            // Local Schema
            $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
            $stmt = $pdo->prepare("INSERT INTO course_fees (course_id, user_type, admission_fee, exam_fee, total_fee, valid_from) VALUES (?, ?, 0, 0, ?, '2026-01-01')");
            $stmt->execute([$courseId, 'college', $fee]);

            // Add category if not exists
            $slug = strtolower(trim(preg_replace('/[^A-Za-z0-9-]+/', '-', $catName), '-'));
            $stmt = $pdo->prepare("SELECT id FROM course_categories WHERE name = ?");
            $stmt->execute([$catName]);
            if (!$stmt->fetchColumn()) {
                $stmt = $pdo->prepare("INSERT INTO course_categories (name, slug, display_order, is_active) VALUES (?, ?, 0, 1)");
                $stmt->execute([$catName, $slug]);
            }
        }
        $count++;
    }

    echo "Successfully imported $count courses!\n";

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