<?php
// Start session if not already started
if (session_status() === PHP_SESSION_NONE) {
    session_start();
}

// Database Configuration
define('DB_HOST', 'localhost');
define('DB_USER', 'ntsazwmq_bmyaaauser');
define('DB_PASS', '@Anupsinha@321');
define('DB_NAME', 'ntsazwmq_bmyaaa');

// Site Configuration
define('SITE_NAME', 'Bishnupriya Manipuri Youth Association');
define('SITE_URL', 'http://bmyouth.org/bmya/');  // Update this to your live URL when deploying
define('ADMIN_URL', SITE_URL . 'admin/');
define('UPLOAD_PATH', dirname(__DIR__) . '/uploads/');
define('UPLOAD_URL', SITE_URL . 'uploads/');
define('SITE_EMAIL', 'noreply@bmyouth.org');

// Email Configuration for cPanel
// Option 1: Using SSL on port 465 (Recommended)
define('SMTP_HOST', 'mail.bmyouth.org');
define('SMTP_PORT', 465);
define('SMTP_USER', 'noreply@bmyouth.org');
define('SMTP_PASS', '@Anupsinha@321');
define('SMTP_SECURE', 'ssl');

// Option 2: If port 465 doesn't work, try TLS on port 587 (uncomment below, comment above)
// define('SMTP_HOST', 'mail.bmyouth.org');
// define('SMTP_PORT', 587);
// define('SMTP_USER', 'noreply@bmyouth.org');
// define('SMTP_PASS', '@Anupsinha@321');
// define('SMTP_SECURE', 'tls');

// For development, set to true when SMTP is configured
define('ENABLE_EMAILS', false); // Set to false for localhost development

// Error Reporting (disable on production)
error_reporting(E_ALL);
ini_set('display_errors', 1);

// Timezone
date_default_timezone_set('Asia/Kolkata');

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("Connection failed: " . $e->getMessage());
}

// Include functions
require_once __DIR__ . '/functions.php';

// Get system setting function (if not exists in functions.php)
if (!function_exists('getSystemSetting')) {
    function getSystemSetting($pdo, $key) {
        try {
            $stmt = $pdo->prepare("SELECT setting_value FROM settings WHERE setting_key = ?");
            $stmt->execute([$key]);
            $result = $stmt->fetch();
            return $result ? $result['setting_value'] : '';
        } catch (Exception $e) {
            return '';
        }
    }
}
?>