<?php
/**
 * Database Connection & Global Settings Loader
 */

require_once 'config.php';

try {
    $pdo = new PDO("mysql:host=" . DB_HOST . ";dbname=" . DB_NAME . ";charset=utf8mb4", DB_USER, DB_PASS);
    $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    $pdo->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);
} catch (PDOException $e) {
    die("Database Connection Failed: " . $e->getMessage());
}

// Global Settings Loader
function get_global_settings($pdo) {
    $stmt = $pdo->prepare("SELECT * FROM settings WHERE id = 1 LIMIT 1");
    $stmt->execute();
    return $stmt->fetch();
}

$site_settings = get_global_settings($pdo);

/**
 * Image URL Helper
 * লোগো বা প্রোডাক্টের ছবি ঠিকমতো দেখানোর জন্য এই ফাংশনটি আপডেট করা হয়েছে
 */
function get_image_url($type, $filename) {
    if (empty($filename)) return SITE_URL . '/assets/images/placeholder.jpg';
    
    // লোগোর জন্য আলাদা পাথ চেক
    if ($type === 'logo') {
        return SITE_URL . '/uploads/logo/' . $filename;
    }
    
    return SITE_URL . '/uploads/' . $type . '/' . $filename;
}
?>