<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta charset="utf-8">
<?php
$path="../../";
include("../../map.php");
header("Content-Type: text/html; charset=UTF-8");
header('Content-Encoding: UTF-8');
function exportExcel($filename='ExportExcel',$columns=array(),$data,$replaceDotCol=array()){
$file="export_".date("dmyHis").".xls";
 header("Content-type: application/vnd.ms-excel");
 header("Content-Disposition: attachment; filename=".$file."");
 header("Pragma: no-cache");
 header("Expires: 0");
 echo "\xEF\xBB\xBF"; //UTF-8 BOM
 echo $out;
	$say=count($columns);
	echo '<table border="0" width="100%"><tr>';
	foreach($columns as $v){
		echo '<th style="">'.trim($v).'</th>';
	}
	echo '</tr>';
	foreach($data as $val){
		echo '<tr>';
		for($i=0; $i < $say; $i++){
			if(in_array($i,$replaceDotCol)){
				echo '<td>'.str_replace('.',',',$val[$i]).'</td>';
			}else{
				echo '<td>'.$val[$i].'</td>';
			}
		}
		echo '</tr>';
	}
		echo '</table>';
}
if($_POST["exp"]<>""){
	$columns=array();
	$rw=array();
	$SID0 = implode(',',$_POST["exp"]); $SIDS = explode(',',$SID0); foreach($SIDS as $SID){
		$items = explode(':',$SID);
		$columns[]=$items[0];
		$rw[]=$items[1];
	}
}
$a['index'] = [];
$b['index'] = [];
$replaceDotCol=array(0);
if($_GET["ne"]=="kayit"){
	if($_POST['c1']<>0 and $_POST['c2']==0){
		$sorgu="and s9='".$_POST["c1"]."'";
	}elseif($_POST['c2']<>0 and $_POST['c3']==0){
		$sorgu="and s10='".$_POST["c2"]."'";
	}elseif($_POST['c3']<>0){
		$sorgu="and s11='".$_POST["c3"]."'";
	}
	if($_GET['py']<>""){
		$sorgu= "".$sorgu. " and s5<>0 and pb1<>0 and t5<>''";
	}
	$sql = mysqli_query($conn, "select * from ".$_SESSION['lang']." where ne='kayit' and (t1 like '%".$_POST["q"]."%' or n4 like '%".$_POST["q"]."%') $sorgu $luye and s13=1 order by t1 desc");	while($rs=mysqli_fetch_assoc($sql)){
			//echo $rs["t1"]."<br>";
			$jsl = json_decode($rs["n16"], true);
			$jsi = json_decode($rs["n17"], true);
			foreach($rw as $val){
				$resimler="";
				if($val=="t4"){
						$a['index'][]=i2a($rs[$val],7);
				}elseif($val=="pb1" or $val=="pb2"){
						$a['index'][]=number_format($rs[$val],2,',','.');
				}elseif($val=="s9" or $val=="s10" or $val=="s11" or $val=="t12"){
						$a['index'][]=kategori($rs[$val]);
				}elseif(substr($val,0,1)=="i" and $val<>"images" and $val<>"image" and $val<>"id"){
					if($jsi[$val]<>""){
						$a['index'][]=str_replace('"','',json_encode($jsi[$val], JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_NUMERIC_CHECK));
					}else{
						$a['index'][]="-";
					}
				}elseif($val=="varyasyon"){
						$sqlv=mysqli_query($conn, "select t1,pb1,s5 from genel where ne='varyant' and s1=".$rs["id"].""); while($rsv=mysqli_fetch_assoc($sqlv)){
								$var = "".$rsv["t1"]."|".$rsv["pb1"]."|".$rsv["s5"].",";
						}
						$a['index']=$var;
				}elseif(substr($val,0,5)=="image"){
						$sqlr=mysqli_query($conn, "select t1 from medya where ne='resim' and s1=".$rs["id"]." and s2=1"); while($rsr=mysqli_fetch_assoc($sqlr)){
							$filename= "".$weburl."/deppo/image/".$rsr["t1"]."";
							$imageInfo = @getimagesize($filename);
							if($imageInfo <> ''){
								$is21 = "".$weburl."/deppo/image/".$rsr["t1"]."";
							}
						}
						$sqlr=mysqli_query($conn, "select t1 from medya where ne='resim' and s1=".$rs["id"]." and s2=0"); while($rsr=mysqli_fetch_assoc($sqlr)){
							$filename= "".$weburl."/deppo/image/".$rsr["t1"]."";
							$imageInfo = @getimagesize($filename);
							if($imageInfo <> ''){
								$is20 = "".$weburl."/deppo/image/".$rsr["t1"]."";
							}
						}
						if($_GET["py"]<>"" and $val=="images"){
							$a['index'][]="".$is21.",".rtrim($is20,",")."";
						}else{
							$a['index'][]=$is21;
						}
						
				}else{
					if($rs[$val]<>""){
						$a['index'][]=trim($rs[$val]);
					}else{
						$a['index'][]="-";
					}
				}
			}
			 $b['index'][]=$a['index'];  $a['index']=[]; $resimler=""; $is20 = ""; $is21 = "";
	}
}elseif($_GET["ne"]=="uye"){
	if($_POST['c1']<>0){
		$sorgu="where s2='".$_POST["c1"]."'";
	}
	$sql = mysqli_query($conn, "select * from t5 $sorgu $luye order by t1 desc");	while($rs=mysqli_fetch_assoc($sql)){
		$jsl = json_decode($rs["n16"], true);
		$jsi = json_decode($rs["n17"], true);
		foreach($rw as $val){
			if($val=="sehir" or $val=="ulke" or $val=="ilce" or $val=="semt"){
				$a['index'][] = loc($jsl[$val]);
			}elseif(substr($val,0,1)=="i" and $val<>"ilce"){
				if($jsi[$val]<>""){
					$a['index'][] = str_replace('"','',json_encode($jsi[$val], JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_NUMERIC_CHECK));
				}else{
					$a['index'][] = "-";
				}
			}elseif($val=="t2" or $val=="t3"){
				$a['index'][] = V3d($rs[$val]);
			}elseif($val=="puan"){
				$a['index'][] = wcount(getpoint($rs["id"],"","../../../"));
			}else{
				$a['index'][] = $rs[$val];
			}
		}
		$b['index'][] = $a['index']; $a['index']=[];
	}
}
//Print_r($b['index']);
exportExcel($_GET["ne"],$columns,$b['index'],$replaceDotCol);
//include("../../log.php";