<?php
// api/db.php - Generated by Setup Wizard
define('SYSTEM_VERSION', '2.0.5');
$isLocal = false;
if (PHP_SAPI === 'cli' || !isset($_SERVER['SERVER_NAME'])) {
    $isLocal = true;
} else {
    $server = $_SERVER['SERVER_NAME'];
    if ($server === 'localhost' || $server === '127.0.0.1' || strpos($server, '192.168.') === 0 || strpos($server, '10.') === 0 || strpos($server, '172.') === 0) {
        $isLocal = true;
    }
}

if ($isLocal) {
    $host = 'localhost';
    $dbname = 'justsale';
    $username = 'root';
    $password = '';
} else {
    $host = 'localhost';
    $dbname = 'u709820750_justpos';
    $username = 'u709820750_justpos';
    $password = 'Bib@2012aa++'; 
}

try {
    $pdo = new PDO("mysql:host=$host;dbname=$dbname;charset=utf8", $username, $password);
    $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    $pdo->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);
} catch (PDOException $e) {
    header('Content-Type: application/json');
    die(json_encode(['success' => false, 'message' => 'Database connection failed.']));
}

// Licensing Gatekeeper
require_once 'license_check_middleware.php';
?>