<?php
include("../deppo/tools/script/cevir.php");
$path="../"; $path2="config/"; include("".$path."config/map.php");
include("../deppo/tools/script/fonksiyon".$ver.".php");
$ubol = explode("/", cevirf($_SERVER['QUERY_STRING']));
$usay=count($ubol); $sayfa=$ubol[0]; $sayfa1=$ubol[1]; $sayfa2=$ubol[2]; $sayfa3=$ubol[3]; $sayfa4=$ubol[4]; $sayfa5=$ubol[5];
?>
<?php
if($_GET["ne"]=="research"){
	if($_REQUEST["q"]==""){exit();}
	?>
	<style>
		::-webkit-scrollbar { width: 10px; }
		::-webkit-scrollbar-track { background: #f1f1f1;}
		::-webkit-scrollbar-thumb { background: #888; }
		::-webkit-scrollbar-thumb:hover { background: #555; }
		.reSearch {position:absolute;z-index: 999; background: whitesmoke; max-height:250px; overflow:hidden; width:93%;left: 25px; border-radius:0px 0px 10px 10px;}
		.reSearch:hover { overflow-y: scroll; }
		.reSearch li {width:100%; display:block; padding:8px; border-bottom: 1px solid #ccc;cursor:pointer;color:black;}
		.reSearch li:hover {background:grey; color:white;}
	</style>
	<ul class="reSearch">
		<?php
		$types = explode(',', $_GET["type"]);
	$q = mysqli_real_escape_string($conn, $_REQUEST["q"]); // SQL injection'dan korunmak için

	foreach ($types as $type) {
		$tbl = "";
		$where = "";
		
		if (in_array($type, ["kayit", "sayfa", "haber", "xmodule"])) {
			$tbl = $_SESSION['lang'];
			$where = "ne='$type' AND t1 LIKE '%$q%'";
		} elseif ($type == "uye") {
			$tbl = "t5";
			$where = "ne='$type' AND t1 LIKE '%$q%'";
		} elseif (substr($type, -8) == "kategori") {
			$tbl = "kategoriler";
			$where = "Cat_{$_SESSION['lang']} LIKE '%$q%' AND (ne='ukategori' OR ne='ualt_kategori' OR ne='ualt_kategori2')";
		}

		if ($tbl && $where) {
			$sql = mysqli_query($conn, "SELECT * FROM $tbl WHERE $where");
			$count = 0;

			while ($rs = mysqli_fetch_assoc($sql)) {
				if (++$count > 10) break;

				$ne = $rs["ne"] ?? $type;
				$nedir = substr($ne, 0, 1);

				if (substr($type, -8) == "kategori") {
					$catName = $rs["Cat_" . $_SESSION["lang"]];
					$catID = $rs["Cat_ID"];

					if ($rs["s4"] == 0 && $rs["s3"] > 0 && $rs["c2"] > 0 && $rs["c1"] > 0) {
						$nedir = "w";
						$kategori = kategori($rs["c1"]) . " > " . kategori($rs["c2"]) . " > " . kategori($rs["s3"]) . " > <b>$catName</b>";
					} elseif ($rs["s3"] == 0 && $rs["c2"] > 0 && $rs["c1"] > 0) {
						$nedir = "z";
						$kategori = kategori($rs["c1"]) . " > " . kategori($rs["c2"]) . " > <b>$catName</b>";
					} elseif ($rs["c2"] == 0 && $rs["c1"] > 0) {
						$nedir = "y";
						$kategori = kategori($rs["c1"]) . " > <b>$catName</b>";
					} elseif ($rs["c1"] == 0) {
						$nedir = "x";
						$kategori = "<b>$catName</b>";
					}

					echo "<li class=\"cp searchli\" data-q=\"$catID\" title=\"$catName\" onclick=\"location.href='" . linked($nedir, $catID) . "'\">$kategori</li>";
				} else {
					$title = $rs["t1"];
					echo "<li class=\"cp searchli\" data-q=\"$title\" title=\"$title\" onclick=\"location.href='" . linked($nedir, $rs["id"]) . "'\">$title</li>";
				}
			}
		}
	}
	?>
</ul>

<script>
	jQuery(function($) {
		jQuery('.searchli').click(function() {
			//var q = jQuery(this).attr('data-q');
			//jQuery('#q').val(q);
			hide('.reSearch');
		});
	});
</script>
<?php
}elseif($_GET["ne"]=="products"){
	if($_GET["q"]<>""){
		$sorgu=" and t1 like '%".$_GET["q"]."%'";
	}
	?>
	<div class="row">
		<?php 
			$sqlu = mysqli_query($conn, "select * from ".$_SESSION["lang"]." where ne='kayit' ".$sorgu." order by id desc limit 0,10"); while($rsu=mysqli_fetch_assoc($sqlu)){?>
				<div class="col-xs-6 col-sm-4 col-md-3 cp" onclick="location.href='?q=<?php echo $rsu["t5"];?>'">
					<div class="product-card" style="position:relative; margin-bottom:15px; border:1px solid #eee; border-radius:10px; overflow:hidden; background:#fff; box-shadow:0 2px 6px rgba(0,0,0,0.08);">
						
						<!-- Üstte + butonu -->
						<a class="add-btn" style="position:absolute; right:0; top:0; padding:8px 12px; background:rgba(255,228,181,0.9); border-radius:0 0 0 15px; z-index:10;">
							<i class="fa fa-plus cp" style="font-size:20px; color:chocolate;"></i>
						</a>
						
						<!-- Resim -->
						<a href="?q=<?php echo $rsu["t5"];?>" style="display:block; width:100%; height:160px; overflow:hidden; text-align:center; background:#fafafa;">
							<img src="<?php echo medya($rsu["id"],1,"kresim","t1","", $weburl)?>" style="max-height:100%; max-width:100%; object-fit:contain;" />
						</a>
						
						<!-- Başlık ve Stok -->
						<div style="padding:8px 10px; font-size:13px; font-weight:600; color:#333; white-space:nowrap; overflow:hidden; text-overflow:ellipsis;">
							<?php echo kisalt($rsu["t1"],19);?> 
							<span style="color:#999; font-weight:400;">(<?php echo $rsu["s5"];?>)</span>
						</div>
						
						<!-- Fiyat -->
						<div style="padding:0 10px 10px; font-size:14px; font-weight:700; color:#e67e22;">
							<?php echo price($rsu["id"],"pb1"); ?> <?php echo $ikpb;?>
						</div>
					</div>
				</div>
			<?php }?>

	</div>

<?php }elseif($_GET["islem"]=="options"){?>
	<option value=""><?php echo translate("Lütfen Seçiniz")?></option>
	<?php $sql=mysqli_query($conn, "select id,t1,n2,n17 from ".$_SESSION["lang"]." where ne='".$_GET["ne"]."' and s2='".$_GET["s2"]."' and s13=1 order by s1 asc"); while($rs=mysqli_fetch_assoc($sql)){?>
		<option value="<?php echo $rs["id"]?>"><?php echo $rs["t1"]?></option>
	<?php }?>

	<?php
}elseif($_GET["islem"]=="appointment"){
	function hours($start="",$end="",$min=""){
		$results = array();
		if($end <= $start){
			$tStart = strtotime($start);
			$tEnd = strtotime("24:00");
			$tNow = $tStart;
			while($tNow <= $tEnd){
				$results[] = date("H:i",$tNow);
				$tNow = strtotime('+'.$min.' minutes',$tNow);
			}
			$tStart = strtotime("00:00");
			$tEnd = strtotime($end);
			$tNow = $tStart;
			while($tNow <= $tEnd){
				$results[] = date("H:i",$tNow);
				$tNow = strtotime('+'.$min.' minutes',$tNow);
			}
		}else{
			$tStart = strtotime($start);
			$tEnd = strtotime($end);
			$tNow = $tStart;
			while($tNow <= $tEnd){
				$results[] = date("H:i",$tNow);
				$tNow = strtotime('+'.$min.' minutes',$tNow);
			}
		}
		return $results;
	}
	$d=date('w', strtotime($_GET["date"]));
	if($d==6 or $d==0){$w="out";}else{$w="in";}
	$clocks=explode("-",$module["appointment_clocks_".$w.""]);
	if(!in_array($d, $module["appointment_days"])){
		$min=$module["appointment_min"];
		
		$hoursf=$clocks[0]; $hoursl=$clocks[1];
		$arrays = hours($hoursf,$hoursl,$min);
		foreach($arrays as $value){
			$sqle=mysqli_query($conn, "select id from genel where ne='not' and t4='".$_GET["date"]."' and t2='".$value."'"); $event=mysqli_fetch_assoc($sqle);
			if(mysqli_num_rows($sqle)>0){$cls="disabled";}
			if($value < date("H:i") and ($_GET["date"]=="undefined" or $_GET["date"]==date("Y-m-d"))){$dn="dn";}
			echo "<label form=\"".cevir($value)."\" class=\"v3-btn-sm v3-btn-success mr2 cp ".$dn."\"><input type=\"radio\" id=\"".cevir($value)."\" ".$cls." value=\"".$value."\" style=\"display:none;\"> ".$value."</label>";
			$cls=""; $dn="";
		}
	}else{
		echo "Malesef Kapalı :(";
	}

}elseif($_GET["islem"]=="jbasket"){
	basket($_GET["id"], $_GET["qty"]);
	echo "Teklif Güncellendi"; 
}
?>
<?php mysqli_close($conn);?>