<?php
	header("Content-Type: text/html;charset=utf-8");
	header('Content-Encoding: UTF-8');
	$path="../../";
	include("../../map.php");
	include("../../scripts.php");
	include("../../secure.php");
	foreach ($_POST as $key => $value){
		$values=explode(',',$value);
		if(substr($key,0,1)=="i" and $value<>"" and $values[1]==""){
			$filters .="and (n17 LIKE '%".$value."%')";
		}
	}
?>
<form method="post" target="modal" action="?ne=<?php echo $_GET['ne'];?>&islem=<?php echo $_GET['islem'];?>&durum=filter" id="search" style="display:flow-root; width: 100%; background: beige; border-radius: 5px; padding-top:15px; padding-bottom:15px;" autocomplete="off">
	<div class="v3-col-md-2 v3-col-sm-3 v3-col-xs-12">
		<input name="q" style=""  class="form-control" placeholder="<?php echo ctranslate("Kelime")?>">
	</div>
	<div class="v3-col-md-2 v3-col-sm-3 v3-col-xs-12">
		<select size=1 name="s13" class="form-control">
			<option value=""><?php echo ctranslate("Lütfen Seçiniz")?></option>
			<option value="0" >[0] <?php echo ctranslate("#Pasif")?></option>
			<option value="1" >[1] <?php echo ctranslate("#Aktif")?></option>
			<option value="3" >[3] <?php echo ctranslate("#Tedarik Edilemiyor")?></option>
		</select>
	</div>
	<div class="v3-col-md-2 v3-col-sm-3 v3-col-xs-12">
		<select name="cat" style=""  class="form-control" id="s1">
			<option value=""><?php echo ctranslate("Tüm Gruplar")?></option>
			<?php $sqlx=mysqli_query($conn, "select * from kategoriler where ne='ukategori' order by sira asc"); while($rsx=mysqli_fetch_assoc($sqlx)){?>
				<option value="<?php echo $rsx["Cat_ID"];?>">+ <?php echo $rsx["Cat_".$_SESSION['lang'].""];?></option>
				<?php $sqly=mysqli_query($conn, "select * from kategoriler where ne='ualt_kategori' and c1='".$rsx["Cat_ID"]."' order by sira asc"); while($rsy=mysqli_fetch_assoc($sqly)){?>
					<option value="<?php echo $rsy["Cat_ID"];?>">- <?php echo $rsy["Cat_".$_SESSION['lang'].""];?></option>
				<?php }?>
			<?php }?>
		</select>
	</div>
	<div class="v3-col-md-2 v3-col-sm-3 v3-col-xs-12" style="<?php if($e5<1){echo "display:none";}?>">
		<input name="min_pb1" style="width:45%; float:left;" class="form-control" placeholder="<?php echo ctranslate("Min Fiyat")?>">
		<input name="max_pb1" style="width:45%; float:right;" class="form-control" placeholder="<?php echo ctranslate("Max Fiyat")?>">
	</div>
	<div class="v3-col-md-2 v3-col-sm-3 v3-col-xs-12" style="<?php if($f7<1){echo "display:none";}?>">
		<input name="min_s5" style="width:45%; float:left;" class="form-control" placeholder="<?php echo ctranslate("Min Stok")?>">
		<input name="max_s5" style="width:45%; float:right;" class="form-control" placeholder="<?php echo ctranslate("Max Stok")?>">
	</div>
	<?php $i=0; $fci="i"; $sqli=mysqli_query($conn, "select * from genel where ne='inputs' $linputs and (t2='All' or t2='".$_SESSION["lang"]."') and (n3='".$_GET["ne"]."' or n3='".$_GET["islem"]."') and n4<>'switch' and s1=0 $luye order by s10,id asc"); while($rsi=mysqli_fetch_assoc($sqli)){$i++;?>
<?php if($rsi["n13"]=="filter"){?>
	<div class="<?php echo $col?> <?php if($rsi["n15"]==""){echo "v3-col-md-2 v3-col-sm-3 v3-col-xs-12";}else{echo $rsi["n15"];}?>" style="margin-bottom:15px;">
		<?php if($rsi["n4"]=="input"){?>
			<input class="form-control <?php echo $rsi["n13"]?>" list="l<?php echo $rsi["id"]?>" type="<?php echo $rsi["n5"]?>" name="<?php echo $fci.$i;?>" value="" placeholder="<?php echo $rsi["n1"];?>" style="" <?php echo $rsi["n6"]?>>
			<datalist id="l<?php echo $rsi["id"]?>">
			<?php
				$dlist=[];
				$sqlu = mysqli_query($conn, "select * from ".$_SESSION['lang']." where ne='".$_GET["ne"]."' order by id desc"); while($rsu=mysqli_fetch_assoc($sqlu)){
				$jsui = json_decode($rsu["n17"], true);
					$dlist[] = $jsui[$fci.$i];
				}
			?>
			<?php foreach (array_unique($dlist) as $is){?>
				<option value="<?php echo $is?>"></option>
			<?php }?>
			</datalist>
		<?php }elseif($rsi["n4"]=="select"){?>
			<select class="form-control <?php echo $rsi["n13"]?> populate" data-plugin-selecttwo="" name="<?php echo $fci.$i;?>[]" style="">
				<option value=""><?php echo $sdil[221]; //Lütfen Seçiniz?></option>
				<?php $o=0;$sqlo=mysqli_query($conn, "select * from genel where ne='inputs' and s1=".$rsi["id"]." order by s10 asc"); while($rso=mysqli_fetch_assoc($sqlo)){$o++;?>
					<option value="<?php echo $rso["n2"]?>" <?php $q="";foreach($jsi["".$fci.$i.""] as $q){?><?php if($q==$rso["n2"]){echo "selected";}} if($jsi["".$fci.$i.""][0]=="" and $rso["n3"]=="1"){echo "selected";}?>><?php echo $rso["n1"]?></option>
				<?php }?>
			</select>
		<?php }elseif($rsi["n4"]=="radio"){?>
			<?php $o=0;$sqlo=mysqli_query($conn, "select * from genel where ne='inputs' and s1=".$rsi["id"]." order by s10 asc"); while($rso=mysqli_fetch_assoc($sqlo)){$o++;?>
				<div style="float:left; margin-right: 5px;">
					<label style="float:left; margin-right:5px;"><?php echo $rso["n1"];?>
					<input type="radio" name="<?php echo $fci.$i;?>" value="<?php echo $rso["n2"];?>" <?php echo $rsi["n8"]?>></label>
				</div>
			<?php }?>
		<?php }elseif($rsi["n4"]=="checkbox"){?>
			<ul class="clist" style="z-index:99999;position:absolute; display:none;height: 200px; overflow: auto;width: 95.5%;" id="cl<?php echo $rsi["id"];?>">
				<?php $o=0;$sqlo=mysqli_query($conn, "select * from genel where ne='inputs' and s1=".$rsi["id"]." order by s10 asc"); while($rso=mysqli_fetch_assoc($sqlo)){$o++;?>
					<li onclick="cbox('#cl<?php echo $rsi["id"];?>c<?php echo $o;?>')" style="cursor:pointer;"><input type="checkbox" onclick="cbox('#cl<?php echo $rsi["id"];?>c<?php echo $o;?>')" id="cl<?php echo $rsi["id"];?>c<?php echo $o;?>" name="<?php echo $fci.$i;?>[]" value="<?php echo $rso["n2"];?>"> <?php echo $rso["n1"];?></li>
				<?php }?>
			</ul>
			<div style="cursor:pointer;height: 60px; overflow: auto;" onclick="toggle('#cl<?php echo $rsi["id"];?>')"><?php if($ql<>""){echo substr($ql,0,-2);}else{echo $sdil[221];} //Lütfen Seçiniz?> <i class="fa fa-angle-down" style="float:right;"></i></div>
			<?php $ql="";$q="";}?>
		</div>
	<?php }?>
<?php }?>
	<div class="v3-col-md-12 v3-col-sm-12 v3-col-xs-12 tar">
		<button type="submit" class="v3-btn v3-btn-danger mfrm" data-toggle="modal" data-target="#myModal" data-url="" data-title="Filter"><?php echo ctranslate("Filtrele")?></button>
	</div>
</form>
<?php if(!empty($_POST)){?>
<table class="v3-table exls" style="font-size:13px;">
<tr>
	<td><?php echo $t24s[0];?></td>
<?php
	foreach ($_POST as $key => $value){
		if(substr($key,0,1)=="i"){
			echo "<td>".translate("+".$key."")."</td>";
		}
	}
?>
<?php if($f7>0){echo "<td class=\"w10\">".ctranslate("Stok")."</td>";}?>
<?php if($e5>0){echo "<td class=\"w10\">".ctranslate("Fiyat")."</td>";}?>
<?php if($e5>0){echo "<td class=\"w5\">".ctranslate("Birim")."</td>";}?>
</tr>
<?php
	if($_POST["min_pb1"]<>"" and $_POST["max_pb1"]<>""){$filters .= " and (pb1>=".$_POST["min_pb1"]." and pb1<=".$_POST["max_pb1"].")";}
	if($_POST["s13"]<>""){$filters .= " and (s13=".$_POST["s13"].")";}
	if($_POST["cat"]<>""){$filters .= " and (s9='".$_POST["cat"]."' or s10='".$_POST["cat"]."')";}
	if($_POST["min_s5"]<>"" and $_POST["max_s5"]<>""){$filters .= " and (s5>=".$_POST["min_s5"]." and s5<=".$_POST["max_s5"].")";}
	$sql = mysqli_query($conn, "select * from ".$_SESSION['lang']." where ne='".$_GET["ne"]."' and (t1 LIKE '%".$_POST["q"]."%' or n2 LIKE '%".$_POST["q"]."%' or n4 LIKE '%".$_POST["q"]."%') $filters order by id desc"); while($rs=mysqli_fetch_assoc($sql)){
	$jsi = json_decode($rs["n17"], true);
?>
<tr onclick="window.open('<?php echo $weburl?>/<?php echo $crmpath?>/?islem=dkayit&ne=kayit&id=<?php echo $rs["id"]?>');" style="cursor:pointer; <?php foreach ($_POST as $key => $value){ $values=explode(',',$value); if(substr($key,0,1)=="i" and $values[1]<>""){ if($jsi[$key] > $values[0] and $jsi[$key] < $values[1]){}else{echo "display:none;";} } } ?>">
	<td><i class="fa fa-cubes" aria-hidden="true"></i> <?php echo $rs["t1"]?></td>
<?php
	foreach ($_POST as $key => $value){
		if(substr($key,0,1)=="i"){
			if ( is_numeric($jsi[$key]) ) {
						echo "<td>".wprice($jsi[$key])."</td>";
			}else{
						echo "<td>".$jsi[$key]."</td>";
			}
		}
	}
?>
<?php if($f7>0){echo "<td>".$rs["s5"]."</td>";}?>
<?php if($e5>0){echo "<td>".wprice($rs["pb1"])."</td>";}?>
<?php if($e5>0){echo "<td>".$rs["t2"]."</td>";}?>
</tr>
<?php }?>
</table>
<script src="https://cdn.<?php echo $cdnurl?>/js/jquery.table2excel.js"></script>
 <button class="btn btn-success">Export</button></div>
<script>
	jQuery(function() {
		jQuery("button").click(function(){
		jQuery(".exls").table2excel({
			exclude: ".noExl",
			name: "filter.xls"
		}); 
		 });
	});
</script>
<?php }?>