Path : /home/vishqocm/pcib.in/admin/
File Upload :
Current File : //home/vishqocm/pcib.in/admin/create_sliders_table_manual.php

<?php
// Direct database configuration to ensure it works
$db_host = 'localhost';
$db_user = 'root';
$db_pass = '';
$db_name = 'popularcomputer';

// Create connection
$conn = new mysqli($db_host, $db_user, $db_pass, $db_name);

// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}

echo "<h1>Sliders Table Creation Tool</h1>";

// Check if the sliders table already exists
$tableExists = $conn->query("SHOW TABLES LIKE 'sliders'");

if ($tableExists && $tableExists->num_rows > 0) {
    echo "<p style='color:green'>The sliders table already exists in the database.</p>";
} else {
    // Create the sliders table
    $createTableSQL = "CREATE TABLE IF NOT EXISTS `sliders` (
        `id` int(11) NOT NULL AUTO_INCREMENT,
        `title` varchar(255) NOT NULL,
        `subtitle` varchar(255) DEFAULT NULL,
        `description` text DEFAULT NULL,
        `button_text` varchar(50) DEFAULT NULL,
        `button_url` varchar(255) DEFAULT NULL,
        `content_type` enum('image','video') NOT NULL DEFAULT 'image',
        `media_url` varchar(255) NOT NULL,
        `overlay_color` varchar(30) DEFAULT 'rgba(0, 0, 0, 0.4)',
        `text_color` varchar(30) DEFAULT '#ffffff',
        `animation` varchar(20) DEFAULT 'fade',
        `status` enum('active','inactive') NOT NULL DEFAULT 'active',
        `sort_order` int(11) NOT NULL DEFAULT 0,
        `date_created` datetime NOT NULL DEFAULT current_timestamp(),
        `date_updated` datetime DEFAULT NULL ON UPDATE current_timestamp(),
        PRIMARY KEY (`id`)
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;";

    if ($conn->query($createTableSQL)) {
        echo "<p style='color:green'>Sliders table created successfully!</p>";
        
        // Insert default sliders
        $insertDefaultSlidersSQL = "INSERT INTO `sliders` (`title`, `subtitle`, `description`, `button_text`, `button_url`, `content_type`, `media_url`, `overlay_color`, `text_color`, `animation`, `status`, `sort_order`) VALUES
        ('Empowering Future Technology Leaders', 'Cutting-edge technology courses for modern careers', 'Our courses are designed by industry experts to prepare you for the challenges of tomorrow\'s technology landscape.', 'Explore Courses', 'courses.php', 'image', 'assets/img/slider/default-slide-1.jpg', 'rgba(0, 0, 0, 0.4)', '#ffffff', 'zoom', 'active', 0),
        ('Learn From Industry Experts', 'Get certified with our professional courses', 'Join our community of learners and gain practical skills taught by professionals with years of industry experience.', 'Join Now', 'register.php', 'image', 'assets/img/slider/default-slide-2.jpg', 'rgba(0, 36, 125, 0.5)', '#ffffff', 'fade', 'active', 1),
        ('Achieve Your Career Goals', 'Practical skills for real-world success', 'Transform your career with our comprehensive curriculum focused on building job-ready skills for today\'s market.', 'Get Started', 'courses.php', 'image', 'assets/img/slider/default-slide-3.jpg', 'rgba(28, 35, 49, 0.6)', '#ffffff', 'slide', 'active', 2);";
        
        if ($conn->query($insertDefaultSlidersSQL)) {
            echo "<p style='color:green'>Default sliders have been added.</p>";
        } else {
            echo "<p style='color:red'>Error inserting default sliders: " . $conn->error . "</p>";
        }
    } else {
        echo "<p style='color:red'>Error creating sliders table: " . $conn->error . "</p>";
    }
}

// Create image directory if it doesn't exist
$slider_dir = __DIR__ . '/../assets/img/slider';
if (!file_exists($slider_dir)) {
    if (mkdir($slider_dir, 0755, true)) {
        echo "<p style='color:green'>Created slider image directory.</p>";
        
        // Copy placeholder images for default sliders
        $placeholder_images = [
            'default-slide-1.jpg',
            'default-slide-2.jpg',
            'default-slide-3.jpg'
        ];
        
        foreach ($placeholder_images as $image) {
            $image_path = $slider_dir . '/' . $image;
            if (!file_exists($image_path)) {
                // Create a simple colored placeholder image
                $width = 1920;
                $height = 1080;
                $img = imagecreatetruecolor($width, $height);
                
                // Random pastel background color for each slide
                $colors = [
                    [66, 133, 244],  // Blue
                    [219, 68, 55],   // Red
                    [15, 157, 88]    // Green
                ];
                
                $index = array_search($image, $placeholder_images);
                $color = $colors[$index % count($colors)];
                $bg = imagecolorallocate($img, $color[0], $color[1], $color[2]);
                imagefill($img, 0, 0, $bg);
                
                // Add some simple design elements
                for ($i = 0; $i < 5; $i++) {
                    $shade = imagecolorallocatealpha($img, 255, 255, 255, 110);
                    $x1 = rand(0, $width);
                    $y1 = rand(0, $height);
                    $x2 = rand(0, $width);
                    $y2 = rand(0, $height);
                    imagefilledellipse($img, $x1, $y1, 200, 200, $shade);
                }
                
                // Save the image
                imagejpeg($img, $image_path, 90);
                imagedestroy($img);
                
                echo "<p style='color:green'>Created placeholder image: $image</p>";
            }
        }
    } else {
        echo "<p style='color:red'>Failed to create slider image directory. Please create it manually at 'assets/img/slider'.</p>";
    }
}

echo "<p><a href='sliders.php'>Go to Sliders Management</a></p>";