<?php
require __DIR__.'/../vendor/autoload.php';
	if(isset($_GET['aaaaaa'])){echo __DIR__;exit;} 
    define('ERP' ,'erp');
	
	define('LOCAL' ,'local');
	define('SITE_NAME' ,'ERP');
    
	if(__DIR__=='/home/websuppo/baharipanno.com/erp/class'){
        define('PROJECT',ERP);
      
    }
    else{
        define('PROJECT',LOCAL);
    }
    
    
	
	if(!isset($crn))session_start();//ক্রোনের ক্ষেত্রে সেশন স্টার্টের দরকার নাই
	date_default_timezone_set('Asia/Dhaka');
	header('Content-Type: text/html; charset=utf-8');
	// print_r($_SERVER);
	define('DB_SERVER', 'localhost');
    
    $localServers=[
        'erp_sohel.as',
        'erp_sohel.moi',
        'erp_sohel.oo'
    ];
	if (isset($_SERVER['SERVER_NAME'])) {
        if (in_array($_SERVER['SERVER_NAME'],$localServers)) {
            define('LOCAL_SERVER_NAME', $_SERVER['SERVER_NAME']);
        } else {
            define('LOCAL_SERVER_NAME', 'localhost');
        }
    } else {
        define('LOCAL_SERVER_NAME', 'localhost');
    }
	$useWWW='';
	if(isset($_SERVER['SERVER_NAME'])){
		if(preg_match("/www/i", $_SERVER['SERVER_NAME'])){
			$useWWW='www.';
		}
	}
	define('GRECAPTCHA_SITE_KEY','6Lcf8UMpAAAAAGx58H-F2k9_aRrEdGfaYTmChq12');
	define('GRECAPTCHA_SECRET_KEY','6Lcf8UMpAAAAALCJ9rqiL42SnOqswjIqiV2we51r');

	if(PROJECT==ERP){
		define('URL','https://baharipanno.com/erp');
		define('DB_USERNAME'		, 'websuppo_rijon');
		define('DB_PASSWORD'		, 'rijon@2023#');
		define('DB_DATABASE', 'websuppo_erp_baharipanno');
	}
	else{
		define('DB_USERNAME', 'root');
		define('DB_PASSWORD', '');

		if($_SERVER['SERVER_NAME']=='erp_sohel.moi'){
			define('URL' ,'http://erp_sohel.moi');
			define('DB_DATABASE', 'erp_sohel');
		}
		else if($_SERVER['SERVER_NAME']=='erp_sohel.oo'){
			define('URL' ,'http://erp_sohel.oo');
			define('DB_DATABASE', 'erp_sohel');
		}
		else{
			define('URL' ,'https://erp_sohel.as');
			define('DB_DATABASE', 'erp_sohel');
			
		}
	}
	//echo PROJECT;echo '<br>'; echo DB_DATABASE;exit();
	$GLOBALS['connection'] = mysqli_connect(DB_SERVER, DB_USERNAME, DB_PASSWORD,DB_DATABASE) or die('Oops connection error 1'.mysqli_connect_error());
	mysqli_set_charset($GLOBALS['connection'],'utf8mb4');

	$_POST = sanitize($_POST);
	$_GET = sanitize($_GET);
	if(isset($SFU)){$SFU = sanitize($SFU);}
	function cleanInput($input){
		$search = array(
			'@<script[^>]*?>.*?</script>@si',   // Strip out javascript
			/*'@<[\/\!]*?[^<>]*?>@si',            // Strip out HTML tags*/
			'@<style[^>]*?>.*?</style>@siU',    // Strip style tags properly
			'@<![\s\S]*?--[ \t\n\r]*>@'         // Strip multi-line comments
		);

		$output = preg_replace($search, '', $input);
		return $output;
	}
	function sanitize($input) {
		$output = array();
		if (is_array($input)) {
			foreach($input as $var=>$val) {
				$output[$var] = sanitize($val);
			}
		}
		else {
			/*if(get_magic_quotes_gpc()) {
			$input = stripslashes($input);
			}*/
			$input  = cleanInput($input);
			$output = mysqli_real_escape_string($GLOBALS['connection'],trim(@$input));
			$output = preg_replace('/\s+/', ' ',$output);
		}
		return $output;
	}
	function textFileWrite($data,$fileName="error.txt"){
		$handle = fopen($fileName, 'a');
		if(is_array($data)){
			$data=json_encode($data);
		}
		//echo $fileName;echo '<br>';
		fwrite($handle, $data."\n");
		fclose($handle);
		return true;
	}
	function fl() {//file line
		$details=debug_backtrace();
		$file=basename($details[0]['file'],'.php');
		return 'EL#'.$details[0]['line'].'_'.$file;
	}
	function exception_error_return(Exception $e,object $object,string $fl,array &$jArray=[]): void{
        setMessage(1,$e->getMessage());
        $count=0;
		$jArray[$fl.'_'.$count++]=[$e->getMessage().' '.$e->getFile().' '.$e->getLine()];
        $jArray[$fl.'_'.$count++]=$e->getFile();
        $jArray[$fl.'_'.$count++]=$e->getCode();
        $jArray[$fl.'_'.$count++]=$e->getLine();
        $jArray[$fl.'_'.$count++]=$e->getPrevious();
        $jArray[$fl.'_'.$count++]=$e->getTrace();
        $jArray[$fl.'_'.$count++]=$e->getTraceAsString();
        if(method_exists($object,'getLog')){
            $log=$object->getLog();
            $jArray[$fl.'_'.$count++]=$log;
        }
    }