<?php
session_start();
error_reporting(0);
include('includes/dbconnection.php');

// Check if BrandIcon column exists
$check_column = mysqli_query($con, "SHOW COLUMNS FROM tblbrand LIKE 'BrandIcon'");

if (mysqli_num_rows($check_column) == 0) {
    // Add BrandIcon column
    $add_column = mysqli_query($con, "ALTER TABLE `tblbrand` ADD `BrandIcon` VARCHAR(255) NULL AFTER `BrandName`");
    
    if ($add_column) {
        echo "<script>alert('BrandIcon column added successfully!');</script>";
        
        // Update existing brands with default icons
        $update_icons = mysqli_query($con, "UPDATE `tblbrand` SET `BrandIcon` = '📱' WHERE `BrandIcon` IS NULL OR `BrandIcon` = ''");
        
        if ($update_icons) {
            echo "<script>alert('Default icons assigned to existing brands!');</script>";
        }
        
        echo "<script>window.location.href = 'manage-brand.php';</script>";
    } else {
        echo "<script>alert('Error adding column: " . mysqli_error($con) . "');</script>";
    }
} else {
    echo "<script>alert('BrandIcon column already exists!');</script>";
    echo "<script>window.location.href = 'manage-brand.php';</script>";
}
?>
