<?php 
/* APLIKASI PENJUALAN DPOS GROSIR MLS
 *
 * Framework DPOS-PHP
 *
 * Developed by djavasoft.com
 * Copyright (c) 2018, Djavasoft Smart Technology
 *
 * @author	Mohamad Anton Arizal, S.T
 * @copyright	Copyright (c) 2008 Djavasoft. (https://djavasoft.com/)
 *
 *
*/

date_default_timezone_set("Asia/Jakarta");

// ============================================
// AUTO DETECT CORE_URL - TIDAK PERLU EDIT MANUAL
// ============================================
// Fungsi untuk auto-detect URL aplikasi
function autoDetectCoreURL() {
	// Cek apakah sudah di-set manual (untuk override)
	// Jika ingin manual, uncomment baris di bawah dan set URL-nya:
	// return "https://namadomain.com";
	
	// Pastikan $_SERVER tersedia
	if (!isset($_SERVER) || empty($_SERVER)) {
		// Fallback jika $_SERVER tidak tersedia
		return "http://localhost";
	}
	
	// Auto detect dari server
	$protocol = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' || (isset($_SERVER['SERVER_PORT']) && $_SERVER['SERVER_PORT'] == 443)) ? "https://" : "http://";
	$host = isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : (isset($_SERVER['SERVER_NAME']) ? $_SERVER['SERVER_NAME'] : 'localhost');
	
	// Deteksi path aplikasi
	$scriptPath = isset($_SERVER['SCRIPT_NAME']) ? dirname($_SERVER['SCRIPT_NAME']) : '';
	
	// Jika di root, scriptPath akan menjadi "/" atau kosong
	// Jika di subfolder, scriptPath akan menjadi "/folder"
	if ($scriptPath == '/' || $scriptPath == '\\' || empty($scriptPath) || $scriptPath == '.') {
		$basePath = '';
	} else {
		// Normalisasi path (hilangkan trailing slash)
		$basePath = rtrim(str_replace('\\', '/', $scriptPath), '/');
	}
	
	// Gabungkan URL
	$url = $protocol . $host . $basePath;
	
	// Normalisasi: pastikan tidak ada trailing slash
	$url = rtrim($url, '/');
	
	return $url;
}

// Set CORE_URL dengan auto-detect (atau manual jika diperlukan)
$CORE_URL = autoDetectCoreURL();

// ============================================
// KONFIGURASI APLIKASI
// ============================================
$SID				= "1002";
$SNAME				= "DPOS GROSIR MLS";
$version			= file_get_contents("app/version.txt");
$database_engine	="mysql"; 					//Anda bisa mengganti dengan sqlite atau mysql


/*------------------------------------ DATABASE MYSQL ------------------------------*/

if($database_engine=="mysql"){
	//MENGGUNAKAN MYSQLI (PHP 8 Compatible)
	include 			"libraries/Database/mysqli.class.php";	//class mysqli database
	$db 				= new Database();			// instance database
	$db->dbHost			="localhost";				// database host
	$db->dbUser			="root";					// database username
	$db->dbPass			=""; 						// dabatabse password
	$db->dbName			="dbpos1"; 				// database name
	include 			"libraries/Database/mysqli.db.php";		// fungsi mysqli

/*------------------------------------ DATABASE SQLITE ------------------------------*/

}elseif($database_engine=="sqlite"){
	//MENGGUNAKAN SQLITE3
	$storagelocation 	= __DIR__ ."/"; 						//direktori root
	$db_file 			= $storagelocation."/db/database.db";	//direktori menyimpan file database sqlite
	$db					= new SQLite3($db_file);				// instance database
	include 			"libraries/Database/sqlite.db.php";				// fungsi sqlite
}

/*------------------------------------ LIBRARIES ------------------------------*/

include "libraries/main.php";

$dir="libraries/Core";
$getDir=dirToArray($dir);
foreach($getDir as $d)
{
	include $dir."/".$d;
}

include "libraries/Helper/ox000fx.inc";

/*------------------------------------ APP ------------------------------*/

$APP_DIR= __DIR__."/app";
$ASSETS_DIR= __DIR__."/assets";
$MLS_LEVEL=7;
?>
