<?php
// config.sample.php - Rename to config.php after installation
// This file contains placeholders that will be replaced during installation

session_start();

// Database Configuration (Placeholders - replaced by installer)
define('DB_HOST', 'localhost');
define('DB_NAME', 'DB_NAME_VALUE');
define('DB_USER', 'DB_USER_VALUE');
define('DB_PASS', 'DB_PASS_VALUE');
define('DB_PORT', '3306');

// System Configuration
define('SITE_NAME', 'UHD-Lite Healthcare System');
define('SITE_URL', '//' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['SCRIPT_NAME']) . '/');
define('BASE_PATH', dirname(__FILE__) . '/');

// Role-based paths
define('ADMIN_PATH', BASE_PATH . 'admin/');
define('DOCTOR_PATH', BASE_PATH . 'doctor/');
define('PATIENT_PATH', BASE_PATH . 'patient/');
define('NURSE_PATH', BASE_PATH . 'nurse/');
define('STAFF_PATH', BASE_PATH . 'staff/');

// Security
define('SALT', 'CHANGE_THIS_RANDOM_SALT_VALUE');
define('SESSION_TIMEOUT', 3600); // 1 hour

// Upload settings
define('UPLOAD_PATH', BASE_PATH . 'uploads/');
define('MAX_FILE_SIZE', 5242880); // 5MB
define('ALLOWED_EXTENSIONS', ['jpg', 'jpeg', 'png', 'pdf', 'doc', 'docx']);

// Error Reporting (Set to 0 for production)
error_reporting(E_ALL);
ini_set('display_errors', 0);
ini_set('log_errors', 1);
ini_set('error_log', BASE_PATH . 'error_log');

// Timezone
date_default_timezone_set('UTC');

// Database Connection Function
function getDBConnection() {
    try {
        $pdo = new PDO(
            "mysql:host=" . DB_HOST . ";dbname=" . DB_NAME . ";charset=utf8mb4",
            DB_USER,
            DB_PASS,
            [
                PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
                PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
                PDO::ATTR_EMULATE_PREPARES => false
            ]
        );
        return $pdo;
    } catch(PDOException $e) {
        die("Database connection failed. Please check your configuration.");
    }
}

// Helper Functions
function redirect($path) {
    header("Location: " . SITE_URL . $path);
    exit();
}

function isLoggedIn($role = null) {
    if(!isset($_SESSION['user_id'])) {
        return false;
    }
    if($role && (!isset($_SESSION['user_role']) || $_SESSION['user_role'] !== $role)) {
        return false;
    }
    return true;
}

function sanitize($input) {
    return htmlspecialchars(strip_tags(trim($input)), ENT_QUOTES, 'UTF-8');
}
?>