( ′∀`)σ≡σ☆))Д′)レ(゚∀゚;)ヘ=З=З=Зε≡(ノ´_ゝ`)ノ HEX
HEX
Server: Apache/2.4.58 (Ubuntu)
System: Linux mail.thebrand.ai 6.8.0-107-generic #107-Ubuntu SMP PREEMPT_DYNAMIC Fri Mar 13 19:51:50 UTC 2026 x86_64
User: www-data (33)
PHP: 8.3.6
Disabled: NONE
Upload Files
File: /var/www/html/tmpr/../tmpr/../tmpr/../tmpr/../looksy/setup.php
<?php
/**
 * Looksy - Database Setup Script
 * 
 * This script initializes the database and creates sample data
 */

// Include configuration
require_once 'config/config.php';

// Include ImageUtils
require_once 'includes/utils/ImageUtils.php';

// Function to create database and tables
function setupDatabase() {
    try {
        // Create database connection without selecting a database
        $pdo = new PDO("mysql:host=" . DB_HOST, DB_USER, DB_PASS);
        $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
        
        // Create database if it doesn't exist
        $pdo->exec("CREATE DATABASE IF NOT EXISTS " . DB_NAME . " CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci");
        
        echo "Database created successfully.<br>";
        
        // Select the database
        $pdo->exec("USE " . DB_NAME);
        
        // Read SQL file
        $sql = file_get_contents('database/looksy_db.sql');
        
        // Execute SQL
        $pdo->exec($sql);
        
        echo "Tables created successfully.<br>";
        
        return $pdo;
    } catch (PDOException $e) {
        die("Database setup failed: " . $e->getMessage());
    }
}

// Function to create sample data
function createSampleData($pdo) {
    try {
        // Check if sample data already exists
        $stmt = $pdo->query("SELECT COUNT(*) FROM users");
        $userCount = $stmt->fetchColumn();
        
        if ($userCount > 0) {
            echo "Sample data already exists.<br>";
            return;
        }
        
        // Create admin user
        $password = password_hash('admin123', PASSWORD_DEFAULT);
        $stmt = $pdo->prepare("INSERT INTO users (username, email, password, first_name, last_name, business_type, is_admin, created_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?)");
        $stmt->execute(['admin', 'admin@looksy.com', $password, 'Admin', 'User', 'Platform', 1, date('Y-m-d H:i:s')]);
        
        echo "Admin user created.<br>";
        
        // Create sample models
        $models = [
            ['Male Model', 'Professional male model for product photography'],
            ['Female Model', 'Professional female model for product photography'],
            ['Child Model', 'Child model for kids products'],
            ['Senior Model', 'Senior model for mature products'],
            ['Mannequin', 'Neutral mannequin for clothing display']
        ];
        
        $stmt = $pdo->prepare("INSERT INTO models (name, description, image_path, created_at) VALUES (?, ?, ?, ?)");
        
        foreach ($models as $model) {
            $name = $model[0];
            $description = $model[1];
            
            // Create model image
            $filename = 'model_' . strtolower(str_replace(' ', '_', $name)) . '.jpg';
            $imagePath = 'uploads/models/' . $filename;
            $fullPath = __DIR__ . '/' . $imagePath;
            
            // Ensure directory exists
            if (!is_dir(dirname($fullPath))) {
                mkdir(dirname($fullPath), 0755, true);
            }
            
            // Create sample image
            ImageUtils::createSampleImage('model', $name, $fullPath);
            
            // Insert into database
            $stmt->execute([$name, $description, $imagePath, date('Y-m-d H:i:s')]);
        }
        
        echo "Sample models created.<br>";
        
        // Create sample backgrounds
        $backgrounds = [
            ['White Studio', 'Clean white studio background'],
            ['Gradient Blue', 'Smooth blue gradient background'],
            ['Natural Outdoor', 'Natural outdoor setting'],
            ['Urban Street', 'Urban street scene background'],
            ['Abstract Pattern', 'Abstract pattern background']
        ];
        
        $stmt = $pdo->prepare("INSERT INTO backgrounds (name, description, image_path, created_at) VALUES (?, ?, ?, ?)");
        
        foreach ($backgrounds as $bg) {
            $name = $bg[0];
            $description = $bg[1];
            
            // Create background image
            $filename = 'bg_' . strtolower(str_replace(' ', '_', $name)) . '.jpg';
            $imagePath = 'uploads/backgrounds/' . $filename;
            $fullPath = __DIR__ . '/' . $imagePath;
            
            // Ensure directory exists
            if (!is_dir(dirname($fullPath))) {
                mkdir(dirname($fullPath), 0755, true);
            }
            
            // Create sample image
            ImageUtils::createSampleImage('background', $name, $fullPath);
            
            // Insert into database
            $stmt->execute([$name, $description, $imagePath, date('Y-m-d H:i:s')]);
        }
        
        echo "Sample backgrounds created.<br>";
        
        // Create sample products for admin
        $products = [
            ['Blue T-Shirt', 'Comfortable cotton t-shirt in blue', 'Clothing'],
            ['Wireless Headphones', 'Premium wireless headphones with noise cancellation', 'Electronics'],
            ['Coffee Mug', 'Ceramic coffee mug with modern design', 'Home & Kitchen'],
            ['Running Shoes', 'Lightweight running shoes with cushioned sole', 'Sports'],
            ['Sunglasses', 'Stylish UV protection sunglasses', 'Accessories']
        ];
        
        $stmt = $pdo->prepare("INSERT INTO products (user_id, name, description, category, image_path, created_at) VALUES (?, ?, ?, ?, ?, ?)");
        
        foreach ($products as $product) {
            $name = $product[0];
            $description = $product[1];
            $category = $product[2];
            
            // Create product image
            $filename = 'product_' . strtolower(str_replace(' ', '_', $name)) . '.jpg';
            $imagePath = 'uploads/products/' . $filename;
            $fullPath = __DIR__ . '/' . $imagePath;
            
            // Ensure directory exists
            if (!is_dir(dirname($fullPath))) {
                mkdir(dirname($fullPath), 0755, true);
            }
            
            // Create sample image
            ImageUtils::createSampleImage('product', $name, $fullPath);
            
            // Insert into database
            $stmt->execute([1, $name, $description, $category, $imagePath, date('Y-m-d H:i:s')]);
        }
        
        echo "Sample products created.<br>";
        
        // Create sample generated content
        $stmt = $pdo->prepare("INSERT INTO generated_content (user_id, product_id, model_id, background_id, name, description, prompt, ai_model, image_path, created_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
        
        // Get product IDs
        $productStmt = $pdo->query("SELECT id FROM products LIMIT 3");
        $productIds = $productStmt->fetchAll(PDO::FETCH_COLUMN);
        
        // Get model IDs
        $modelStmt = $pdo->query("SELECT id FROM models LIMIT 3");
        $modelIds = $modelStmt->fetchAll(PDO::FETCH_COLUMN);
        
        // Get background IDs
        $bgStmt = $pdo->query("SELECT id FROM backgrounds LIMIT 3");
        $bgIds = $bgStmt->fetchAll(PDO::FETCH_COLUMN);
        
        // Create 3 sample generated contents
        for ($i = 0; $i < 3; $i++) {
            $name = "Sample Generated Content " . ($i + 1);
            $description = "This is a sample generated content for demonstration";
            $prompt = "Create a professional product image with model and background";
            $aiModel = "standard";
            
            // Create generated image
            $filename = 'generated_sample_' . ($i + 1) . '.jpg';
            $imagePath = 'uploads/generated/' . $filename;
            $fullPath = __DIR__ . '/' . $imagePath;
            
            // Ensure directory exists
            if (!is_dir(dirname($fullPath))) {
                mkdir(dirname($fullPath), 0755, true);
            }
            
            // Create sample image
            ImageUtils::createSampleImage('generated', $name, $fullPath);
            
            // Insert into database
            $stmt->execute([
                1, // user_id
                $productIds[$i % count($productIds)], // product_id
                $modelIds[$i % count($modelIds)], // model_id
                $bgIds[$i % count($bgIds)], // background_id
                $name,
                $description,
                $prompt,
                $aiModel,
                $imagePath,
                date('Y-m-d H:i:s')
            ]);
        }
        
        echo "Sample generated content created.<br>";
        
    } catch (PDOException $e) {
        die("Sample data creation failed: " . $e->getMessage());
    }
}

// Main execution
echo "<h1>Looksy Platform Setup</h1>";

// Setup database
$pdo = setupDatabase();

// Create sample data
createSampleData($pdo);

echo "<h2>Setup completed successfully!</h2>";
echo "<p>You can now <a href='index.php'>access the platform</a>.</p>";
echo "<p>Default admin credentials:</p>";
echo "<ul>";
echo "<li>Username: admin</li>";
echo "<li>Password: admin123</li>";
echo "</ul>";
?>