<?php
session_start();  ob_start();
error_reporting(1);
if(is_dir("deppo")){$cpath="";}else{$cpath="../";}
//if (is_readable($path . $cpath . "config/subdomain.php")) { include $path . $cpath . "config/subdomain.php"; }

if(is_dir("".$cpath."account/")){
	include("".$cpath."account/cookies.php");
}
$useragent = $_SERVER['HTTP_USER_AGENT'];
// Mobil cihazları tespit etmek için regex kullanılır
$mobile_regex = '/(android|bb\d+|meego.+mobile|avantgo|bada|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino)/i';
$mobile_devices = preg_match($mobile_regex, $useragent);
if ($mobile_devices) { $mobile = "1"; }
$acc_lang = substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2);
include($path . $path2 . "sql.php");

$conerr = "<div style='width:500px; height:50px; margin-top:200px; margin-left:auto; margin-right:auto; text-align:center;'><h1>Sql Connection <u>Error</u>!</h1>" . $cinstall . "</div>";

// MySQL bağlantısı
$conn = mysqli_connect($V3Server, $V3User, $V3Pass, $V3Db);
if (!$conn) die($conerr);
mysqli_set_charset($conn, 'utf8');

// MySQL Close
function csql(){ global $conn; mysqli_close($conn); }

//-- Order No -->
foreach ($_SESSION as $key => $value){
	if(substr($key,0,5)=="Order"){
		//echo $key." = ".$value."<br>";
	}
}

// Sepet verilerini al
$orderDataPath = ''.$cpath.'deppo/cache/' . ($_COOKIE["Order_No"] ?? '') . '.json';

// Dosya var mı kontrol et
if (file_exists($orderDataPath)) {
    $oData = json_decode(file_get_contents($orderDataPath), true);
    // Dosyayı hemen sil (okuduktan sonra)
    unlink($orderDataPath);

    // Veriyi session'a aktar veya yeni sepet oluştur
    if (!empty($oData[0]["Order_No"])) {
        // Order_No var, veriyi session'a aktar
        foreach ($oData[0] as $key => $value) {
            $_SESSION[$key] = $value;
        }
    } elseif (empty($_SESSION["Order_No"])) {
        // Yeni sepet oluştur
        $_SESSION["Order_No"] = "OID-" . date("ymdHis");
    } else {
        // Sepet veritabanını güncelle
        $query = "SELECT id FROM eticaret WHERE ne = 'sepet' AND t5 = 'sepet' AND (s1 = '{$_SESSION["User_ID"]}' OR t4 = '{$_SESSION["Order_No"]}')"; $result = mysqli_query($conn, $query); while ($basket = mysqli_fetch_assoc($result)) { if (!empty($_SESSION["User_ID"])) { $updateQuery = "UPDATE eticaret SET t4 = '{$_SESSION["Order_No"]}', s1 = '{$_SESSION["User_ID"]}' WHERE ne = 'sepet' AND id = {$basket["id"]}"; mysqli_query($conn, $updateQuery);}
        }
    }
} else {
    // Dosya hiç yoksa fallback
    if (empty($_SESSION["Order_No"])) {
        $_SESSION["Order_No"] = "OID-" . date("ymdHis");
    }
}

////////////Language Set\\\\\\\\\\\\\\\\\\
$lang1 = mysqli_fetch_assoc(mysqli_query($conn, "SELECT n18 FROM lang1 WHERE ne = 'ayarlar'"));  
$mode = json_decode($lang1["n18"], true);

$dlang = $mode["dlang"];
$valid_languages = explode(",", $mode["m1"]);
$lcount = count($valid_languages);

// URL sorgusunu ayır
$lbol = explode("/", str_replace("%2F", "/", $_SERVER['QUERY_STRING']));

// Varsayılan dil kontrolü
if (empty($_SESSION["lang"])) {
    $flang = array_search(strtolower($dlang), array_map('strtolower', $valid_languages));
    $_SESSION["lang"] = ($flang !== false) ? "lang" . ($flang + 1) : "lang1";
}
if (strpos($_SESSION["lang"], "lang") !== 0) {
    $_SESSION["lang"] = "lang1";
}

// URL parametresi ile gelen dil kontrolü
if (!empty($_GET["lang"])) {
    $flang = array_search(strtolower($_GET["lang"]), array_map('strtolower', $valid_languages));
    $lastChar = substr($_GET["lang"], -1);

    if (is_numeric($lastChar)) {
        $_SESSION["lang"] = ($lastChar <= $lcount) ? $_GET["lang"] : "lang1";
    } else {
        $_SESSION["lang"] = ($flang !== false) ? "lang" . ($flang + 1) : "lang1";
    }
}

// URL yolundaki dil kontrolü (ör: /tr/ veya /en/)
if (!empty($lbol[0]) && ctype_alpha($lbol[0]) && strlen($lbol[0]) == 2) {
    $flang = array_search(strtolower($lbol[0]), array_map('strtolower', $valid_languages));
    if ($flang !== false) {
        $_SESSION["lang"] = "lang" . ($flang + 1);
    }
}

// Mevcut dil ayarları
$sqla = mysqli_query($conn, "SELECT * FROM {$_SESSION['lang']} WHERE ne = 'ayarlar'"); 
$rsa = mysqli_fetch_assoc($sqla); 
$module = json_decode($rsa["n18"], true);

$dill = $valid_languages[($_SESSION["lang"][-1] - 1)];
$clanguage = $dill;
$_SESSION["clang"] = $dill;

// Zaman dilimi ayarı
$timezone = $module["wtimezone"] ?: 'Europe/Istanbul';
date_default_timezone_set($timezone);
////////////Language Set\\\\\\\\\\\\\\\\\\

$n5=$rsa["n5"]; $n6=$rsa["n6"]; $n7=$rsa["n7"]; $n9=$rsa["n9"]; $n12=$rsa["n12"]; $n13=$rsa["n13"]; $n14=$rsa["n14"]; $n16=$rsa["n16"]; $n17=$rsa["n17"]; $n18=$rsa["n18"]; $n19=$rsa["n19"]; $n20=$rsa["n20"]; 
$s1=$module["s1"]; $s2=$module["s2"]; $s3=$module["s3"]; $s4=$module["s4"]; $s5=$module["s5"]; $s6=$module["s6"]; $s7=$module["s7"]; $s8=$module["s8"]; $s9=$module["s9"]; $s10=$module["s10"]; $s12=$module["s12"]; $s13=$module["s13"]; $s20=$module["s20"]; 
$pb1=$module["pb1"]; $pb2=$module["pb2"]; $pb3=$module["pb3"];
$m1=$module["m1"]; $m2=$module["m2"]; $m3=$module["m3"]; $m4=$module["m4"]; $m5=$module["m5"]; $m6=$module["m6"]; $m7=$module["m7"]; $m8=$module["m8"]; $m9=$module["m9"]; $m10=$module["m10"]; 
$m11=$module["m11"]; $m12=$module["m12"]; $m13=$module["m13"]; $m14=$module["m14"]; $m15=$module["m15"]; $m16=$module["m16"]; $m17=$module["m17"]; $m18=$module["m18"]; $m19=$module["m19"]; $m20=$module["m20"]; 
$t1=$tbox["t1"]; $t2=$tbox["t2"]; $t3=$tbox["t3"]; $t4=$tbox["t4"]; $t5=$tbox["t5"]; $t6=$tbox["t6"]; $t7=$tbox["t7"]; $t8=$tbox["t8"]; $t9=$tbox["t9"]; $t10=$tbox["t10"];  $t11=$tbox["t11"]; $t12=$tbox["t12"];
$t23=$rsa["t23"];  $t26=$rsa["t26"]; $t27=$rsa["t27"]; $t28=$rsa["t28"]; $t29=$rsa["t29"]; $t30=$rsa["t30"]; $t31=$rsa["t31"]; $t32=$rsa["t32"]; $t33=$rsa["t33"]; $t34=$rsa["t34"]; $t35=$rsa["t35"]; $t36=$rsa["t36"]; $t37=$rsa["t37"]; $t38=$rsa["t38"]; $t39=$rsa["t39"]; $t40=$rsa["t40"]; 
$t41=$rsa["t41"]; $t42=$rsa["t42"]; $t43=$rsa["t43"]; $t44=$rsa["t44"]; $t45=$rsa["t45"]; $t46=$rsa["t46"]; $t47=$rsa["t47"]; $t48=$rsa["t48"]; $t49=$rsa["t49"]; $t50=$rsa["t50"]; 
$a1=$module["a1"]; $a2=$module["a2"]; $a3=$module["a3"]; $a4=$module["a4"]; $a5=$module["a5"]; $a6=$module["a6"]; $a7=$module["a7"]; $a8=$module["a8"]; $a9=$module["a9"]; $a10=$module["a10"]; 
$b1=$module["b1"]; $b2=$module["b2"]; $b3=$module["b3"]; $b4=$module["b4"]; $b5=$module["b5"]; $b6=$module["b6"]; $b7=$module["b7"]; $b8=$module["b8"]; $b9=$module["b9"]; $b10=$module["b10"]; 
$c1=$module["c1"]; $c2=$module["c2"]; $c3=$module["c3"]; $c4=$module["c4"]; $c5=$module["c5"]; $c6=$module["c6"]; $c7=$module["c7"]; $c8=$module["c8"]; $c9=$module["c9"]; $c10=$module["c10"]; 
$d1=$module["d1"]; $d2=$module["d2"]; $d3=$module["d3"]; $d4=$module["d4"]; $d5=$module["d5"]; $d6=$module["d6"]; $d7=$module["d7"]; $d8=$module["d8"]; $d9=$module["d9"]; $d10=$module["d10"]; 
$e1=$module["e1"]; $e2=$module["e2"]; $e3=$module["e3"]; $e4=$module["e4"]; $e5=$module["e5"]; $e6=$module["e6"]; $e7=$module["e7"]; $e8=$module["e8"]; $e9=$module["e9"]; $e10=$module["e10"]; 
$f1=$module["f1"]; $f2=$module["f2"]; $f3=$module["f3"]; $f4=$module["f4"]; $f5=$module["f5"]; $f6=$module["f6"]; $f7=$module["f7"]; $f8=$module["f8"]; $f9=$module["f9"]; $f10=$module["f10"]; 
$g1=$module["g1"]; $g2=$module["g2"]; $g3=$module["g3"]; $g4=$module["g4"]; $g5=$module["g5"]; $g6=$module["g6"]; $g7=$module["g7"]; $g8=$module["g8"]; $g9=$module["g9"]; $g10=$module["g10"]; 
$h1=$module["h1"]; $h2=$module["h2"]; $h3=$module["h3"]; $h4=$module["h4"]; $h5=$module["h5"]; $h6=$module["h6"]; $h7=$module["h7"]; $h8=$module["h8"]; $h9=$module["h9"]; $h10=$module["h10"]; $h11=$module["h11"];
$i1=$rsa["i1"]; $i2=$rsa["i2"]; $i3=$rsa["i3"]; $i4=$rsa["i4"]; $i5=$rsa["i5"]; $i6=$rsa["i6"]; $i7=$rsa["i7"]; $i8=$rsa["i8"]; $i9=$rsa["i9"]; $i10=$rsa["i10"]; $i11=$rsa["i11"]; $i12=$rsa["i12"]; $i13=$rsa["i13"]; $i14=$rsa["i14"]; $i15=$rsa["i15"]; $i16=$rsa["i16"]; $i17=$rsa["i17"]; $i18=$rsa["i18"]; $i19=$rsa["i19"]; $i20=$rsa["i20"];
$colors = explode(",",$rsa["i2"]);
$llx = explode(',',$m1); foreach($llx as $ll) {$lx++; if($lx > 10) {$lx = 1;}}
if($module["cdnurl"]<>""){
	$cdnurl	= $module["cdnurl"];
}else{
	$cdnurl	= "crmplus.com.tr";
}

//-- Kur Ayarları -->
$basket = mysqli_query($conn, "select * from eticaret where ne='sepet' and t4='".$_SESSION["Order_No"]."' and t5='sepet' order by id desc");
if($sayfa=="kur" or $_POST["kur"]<>""){
if(mysqli_num_rows($basket)==0){	//Sepette Ürün varsa kur değiştirme
	if($sayfa=="kur"){
		$kpb=$sayfa1;
	}elseif($_POST["kur"]<>""){
		$kpb=$_POST["kur"];
	}
	$_SESSION["kur"]=$kpb;
	if($sayfa=="kur"){
		echo "<script>window.location.href='?".str_replace(',', '/', $sayfa3)."'</script>";
	}
}else{
	echo "<script>window.location.href='?".str_replace(',', '/', $sayfa3)."/err'</script>";
}
}elseif($sayfa=="" and $_SESSION["kur"]==""){
	$kpb=$module["currency"];
	$_SESSION["kur"]=$module["currency"];
}elseif($_SESSION["kur"]<>""){
	$kpb=$_SESSION["kur"];
	$_SESSION["kur"]=trim($_SESSION["kur"]);
}
	$ikpb="<i class=\"fa fa-".strtolower($kpb)."\"></i>";
//-- Kur Ayarları -->

// -- Json Decoded --
$module = json_decode($rsa["n18"], true);
$tbox = json_decode($rsa["n19"], true);
$firm = json_decode($rsa["n11"], true);
$social = json_decode($rsa["n16"], true);
$doviz = json_decode($rsa["t40"], true);
// CRM Path Ayarı
$crmpath = !empty($rsa["t1"]) ? $rsa["t1"] : "crmplus";
// Media Path Ayarı
$media_path = !empty($module["media_path"]) ? $module["media_path"] : "";
$media_path_slash = !empty($media_path) ? $media_path . "/" : "";
// -- Json Decoded -->
function ssl2($metin){  
	global $f4;
    return ($f4 == "1") ? str_replace('http:', 'https:', $metin) : $metin;
}
$title				= $rsa["n1"];
$keywords 	= $rsa["n4"];
$description	= $rsa["n2"];
$srvname = ssl2("http://") . $_SERVER['SERVER_NAME'];
$srvpaths = explode('?', ssl2("http://") . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI']);
$weburl = (strpos($rsa["n9"], "/") === 0) ? ssl2("http:") . $rsa["n9"] : $rsa["n9"];
if($weburl[0]=="/"){$weburl=ssl2("http:").$weburl;}
// Web URL ile domain kontrolü
if ("//" . $_SERVER['SERVER_NAME'] !== $rsa["n9"] && $module["app"] == "") {
	$directory = str_replace("//" . $_SERVER['SERVER_NAME'] . "/", "", $rsa["n9"]) . "/";
}
// Media path kontrolü
$srvpath = $_media_path ?: $rsa["n9"];
$gdogrulama	= $rsa["n13"];		//Google Doğrulama
//$ganalytics	= $rsa["n14"];		//Google Analytics
$satis			= $module["s1"];	//Alışveriş Aç Kapat
$s2				= $module["s2"];	//Kapıda Ödeme Aç Kapat
$s3				= $module["s3"];	//Havale Aç Kapat
$s4				= $module["s4"];	//Payu Aç Kapat
$s5				= $module["s5"];	//Kredi kartı Aç Kapat
$s6				= $module["s6"];	//Mail Order Aç Kapat
$s11				= $module["s11"];	//Kdv
$prc				= $module["prc"];	//Prc
$s13				= $module["s13"];	//Havale indirim
$s15				= $module["s15"];	//Vitrin Say
$s16				= $module["s16"];	//list Say
$s18				= $module["s18"];
$s19				= $module["s19"];
if ($module["fseo"] == "2" && $sayfa1 != "") {
    $jss = "/";
}

//-- Sabit Dil -->
function drep($metin) {
    return preg_replace('/[\[\]0-9]/', '', $metin);
}
$sdil = explode(' + ', preg_replace('/[\[\]0-9]/', '', $rsa["n3"]));
$cdil = explode(' + ', preg_replace('/[\[\]0-9]/', '', $rsa["n5"]));
function srep($metin) {
    return preg_replace('/[\[\]]/', '', $metin); // Hem [ hem de ] karakterlerini kaldırır
}
//-- Powered -->
$power 		= json_decode($rsa["n10"], true);
$pow1		= $power["company"];	// Firma
$pow2		= $power["ver"];			// Versiyon
$pow3		= $power["web"];			// Web Adres
$pow4		= $power["phone"];		// Tel
$pow5		= $power["email"];			// E-Mail
$pow6		= $power["date"];			// Update
$powered 	= $power["company"];	// Firma
$pweb		= $power["web"];			// Web Adres
$pver		= $power["ver"];			// Versiyon
$ptel			= $power["phone"];		// Tel
$pmail		= $power["email"];			// E-Mail
//-- Firma -->
$firma		= $firm["firma"];			// Firma
$ftel			= $firm["ftel"];				// Tel
$ftel2		= $firm["ftel2"];				// Tel
$ftel3		= $firm["ftel3"];				// Tel
$ffax			= $firm["ffax"];				// Fax
$fgsm		= $firm["fgsm"];				// Gsm
$fgsm2		= $firm["fgsm2"];			// Gsm
$fmail		= $firm["fmail"];				// Email
$fmail2		= $firm["fmail2"];			// Email
$ifmail		= "<img src=\"//cdn.".$cdnurl."/tools/email/?txt=".$firm["fmail"]."\">";			// Email
$fadres		= $firm["fadres"];			// Adres
$fadres2	= $firm["fadres2"];			// Adres
$fwhatsapp= $firm["fwhatsapp"];		// Whatsapp
$fvd			= $firm["fvd"];					// VDairesi
$fvn			= $firm["fvn"];					// VNumarası
$fmn			= $firm["fmn"];				// MNumarası
$fmo			= $firm["fmo"];				// MOdası
$fkep		= $firm["fkep"];				// Kep
$fdesc		= $firm["fdesc"];				// Firma Tanımı

//-- Sosyal -->
$facebook	= $social["facebook"];		// facebook
$lfacebook	= $social["facebook"];		// facebook
$twitter			= $social["twitter"];			// twitter
$ltwitter		= $social["twitter"];			// twitter
$gplus			= $social["gplus"];				// gplus
$lgplus			= $social["gplus"];				// gplus
$instagram	= $social["instagram"];		// instagram
$linstagram= $social["instagram"];		// instagram
$linkedin	= $social["linkedin"];			// linkedin
$llinkedin	= $social["linkedin"];			// linkedin
$youtube	= $social["youtube"];		// youtube
$lyoutube	= $social["youtube"];		// youtube
$skype		= $social["skype"];			// skype
$skype		= "skype:-".$skype."-?chat";
//$qrcode  = "http://api.qrserver.com/v1/create-qr-code/?data=".$rsa["n9"]."&size=";
$lwhatsapp = "https://".($mobile ? "api" : "web").".whatsapp.com/send?phone=".$fwhatsapp;
//-- e-mail /fonksiyon burada çalışmaz/-->
if($_GET["mn"] == ""){ $mn=0; }else{ $mn=$_GET["mn"]; } // Mail sıra no İle mail gönderme
$dmail 			= mysqli_query($conn, "select id,n1,n2,n3 from genel where ne='tanim' and t2='email' and s10=".$mn.""); $rsmd=mysqli_fetch_assoc($dmail);
$mail			= base64_decode($rsmd["n1"]);	//Email
$msifre			= base64_decode($rsmd["n2"]);	//Email Şifre
$sunucu		= $rsmd["n3"];							//Email Sunucu
//-- e-mail -->
$wcode		= $rsa["n15"];
$kdvdh		= $module["s11"];
// Kargo limitini belirleme
$kargolmt = ($_SESSION["Order_Location_country"] == "" || $_SESSION["Order_Location_country"] == $module["countrycode"]) ? $module["pb2"] : $module["pb3"];

// Logo, favicon ve diğer görselleri belirleme
$defaultLogo = "//cdn.".$cdnurl."/images/crm.png";
$logo2 = !empty($rsa["t48"]) ? $weburl."/deppo/image/".$rsa["t48"] : $defaultLogo;
$favicon = !empty($rsa["t49"]) ? $weburl."/deppo/image/".$rsa["t49"] : "https://cdn.".$cdnurl."/images/crm.png";
$stamp = !empty($module["stamp"]) ? $weburl."/deppo/image/".$module["stamp"] : $defaultLogo;
$logo_app = !empty($module["logo_app"]) ? $weburl."/deppo/image/".$module["logo_app"] : $defaultLogo;
$logo_pay = !empty($module["logo_pay"]) ? $weburl."/deppo/image/".$module["logo_pay"] : $defaultLogo;
$logo_oim = !empty($module["logo_oim"]) ? $weburl."/deppo/image/".$module["logo_oim"] : $defaultLogo;
$sqle = mysqli_query($conn, "SELECT id FROM t5 WHERE n17 LIKE '%".$_SERVER['SERVER_NAME']."%'"); $rse = mysqli_fetch_assoc($sqle);
if ($module["crm_info"] == "1" && mysqli_num_rows($sqle) > 0) {
    $rsi = mysqli_query($conn, "SELECT id, t1 FROM medya WHERE ne='resim' AND s1=".$rse["id"]." AND s2=1 AND s4=0 AND s13=1");
    $rsi = mysqli_fetch_assoc($rsi);
    $jsei = json_decode($rse["n17"], true);
    $firma = $jsei["ifirma"]; // Firma
    $ftel = $rse["t7"]; // Tel
    $fgsm = $rse["t7"]; // Gsm
    $fmail = base64_decode($rse["t2"]); // Email
    $fadres = $rsei["n5"]; // Adres
    // Firma logosunu belirleme
    $logo = $weburl . "/deppo/image/" . $rsi["t1"];
} else { 
    $logo = !empty($rsa["t50"]) ? $weburl . "/deppo/image/" . $rsa["t50"] : "//cdn." . $cdnurl . "/images/sample_logo.png";
}
$usd = $doviz["usd"]; $eur = $doviz["eur"]; $gbp = $doviz["gbp"]; $grgold = $doviz["grgold"]; $btc = $doviz["btc"]; $timestamp=date("dmYHis");
if (!empty($module["loc"])) {
    static $locations = null;
    if ($locations === null) {
        $locationjson = file_get_contents($_SERVER['DOCUMENT_ROOT'] . '/deppo/tools/jsons/locations.json');
        $locations = json_decode($locationjson, true);
    }
}
?>