<?php
// config.php
session_start();

$db_host = 'localhost';
$db_user = 'svnscores';
$db_pass = 'aduke2024';
$db_name = 'isp_manager';

try {
    $pdo = new PDO("mysql:host=$db_host;dbname=$db_name", $db_user, $db_pass);
    $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch(PDOException $e) {
    die("Connection failed: " . $e->getMessage());
}

// MikroTik API configuration
$mikrotik_config = [
    'host' => '10.10.10.1',
    'user' => 'dual',
    'pass' => 'boot'
];

// Function to check if user is logged in
function isLoggedIn() {
    return isset($_SESSION['user_id']);
}

// Function to check if user is admin
function isAdmin() {
    return isset($_SESSION['role']) && $_SESSION['role'] === 'admin';
}

// Function to generate unique reference
function generateReference() {
    return 'TXN_' . time() . '_' . uniqid();
}

// Function to add to MikroTik PPPoE secret
function addMikroTikPPPoe($username, $password, $profile) {
    global $mikrotik_config;
    
    // This is a simplified example - you'd need to use SSH or API
    // Using MikroTik API library recommended
    $command = "/ppp secret add name={$username} password={$password} service=pppoe profile={$profile} disabled=no";
    
    // Execute via SSH or API
    // For now, return true as placeholder
    return true;
}
?>