<?php
$path="../../";
include("../../map.php");
include("../../scripts.php");
?>
<style type="text/css">
.search-field {
	height: 25px;
	padding: 10px
}
</style>
<?php
if($_GET["durum"]=="il"){
  $sqlc=mysqli_query($conn, "select * from t2 where t1='".$_POST["t6"]."'"); $rsc=mysqli_fetch_assoc($sqlc);
  $_SESSION["t6"]=$rsc["id"];
  $rsu = mysqli_query($conn, "update t5 set t6='".$_POST["t6"]."' where id=".$_GET["id"]."");
  if($_POST["kaydet"]=="Kaydet"){
   echo location("".$weburl."/".$crmpath."/?ne=".$_GET["ne"]."&islem=duye&id=".$_GET["id"]."",top,500,1);
 }
}elseif($_GET["durum"]=="ilce"){
  $rsu = mysqli_query($conn, "update t5 set t9='".$_POST["t9"]."' where id=".$_GET["id"]."");
  if($_POST["kaydet"]=="Kaydet"){
   echo location("".$weburl."/".$crmpath."/?ne=".$_GET["ne"]."&islem=duye&id=".$_GET["id"]."",top,500,1);
 }
}elseif($_GET["durum"]=="semt"){
  $rsu = mysqli_query($conn, "update t5 set t10='".$_POST["t10"]."' where id=".$_GET["id"]."");
  echo location("".$weburl."/".$crmpath."/?ne=".$_GET["ne"]."&islem=duye&id=".$_GET["id"]."",top,500,1);
}
?>
<?php $sqlu=mysqli_query($conn, "select * from t5 where id=".$_GET["id"].""); $rsu=mysqli_fetch_assoc($sql); $s2=$rsu["s2"]; ?>
<?php if($_GET["durum"]==""){?>
  <form class="container" method="post" action="?ne=<?php echo $_GET["ne"];?>&islem=<?php echo $_GET["islem"];?>&id=<?php echo $_GET["id"];?>&durum=il">
    <div class="row" style="">
      <label>Şehir <span style="font-size:8px; color:#ccc;">(t6)</span></label>
      <select name="t6" class="chosen-select form-control" style="width:95%; height:35px;" multiple>
        <option value="0">İl Seçiniz</option>
        <?php
        $iller = explode(',',$rsu["t6"]);
        $sql=mysqli_query($conn, "select * from t2 where ne='il' order by t1 asc"); 	while($rsc=mysqli_fetch_assoc($sql)){
         ?>
         <option value="<?php echo $rsc["t1"];?>" <?php foreach($iller as $il){if($t1==$rsc["t1"]){echo "selected";}}?>><?php echo $rsc["t1"];?></option>
       <?php };?>
     </select>
   </div>
   <input class="btn btn-default" style="float:right; margin-right:5px; margin-top:20px;" type="submit" name="kaydet" value="İlçe Ekle" />
   <input class="btn btn-info" style="float:right; margin-right:5px; margin-top:20px;" type="submit" name="kaydet" value="Kaydet" />
 </form>
<?php }else if($_GET["durum"]=="il"){?>
  <form class="container" method="post" action="?ne=<?php echo $_GET["ne"];?>&islem=<?php echo $_GET["islem"];?>&id=<?php echo $_GET["id"];?>&durum=ilce">
    <div class="row" style="">
      <label>İlçe <?php echo $_SESSION["t6"];?><span style="font-size:8px; color:#ccc;">(t9)</span></label>
      <select name="t9" class="chosen-select form-control" style="width:95%;  height:35px;" multiple>
        <option value="0">İlçe Seçiniz</option>
        <?php
        $ilceler = explode(',',$rsu["t9"]);
        $sql2=mysqli_query($conn, "select * from t2 where ne='ilce' and s2=".$_SESSION["t6"]." order by s2 asc"); while($rsc2=mysqli_fetch_assoc($sql2)){
          $sql1=mysqli_query($conn, "select * from t2 where ne='il' and id=".$rsc2["s2"].""); $rsc1=mysqli_fetch_assoc($sql1)
          ?>
          <option value="<?php echo $rsc2["t1"];?>" <?php foreach($ilceler as $ilce){if($ilce==$rsc2["t1"]){echo "selected";}}?>><?php echo $rsc1["t1"];?> > <?php echo $rsc2["t1"];?></option>
        <?php }?>
      </select>
    </div>
    <input class="btn btn-default" style="float:right; margin-right:5px; margin-top:20px;" type="submit" name="kaydet" value="Semt Ekle" />
    <input class="btn btn-info" style="float:right; margin-right:5px; margin-top:20px;" type="submit" name="kaydet" value="Kaydet" />
  </form>
<?php }else if($_GET["durum"]=="ilce"){?>
  <form class="container" method="post" action="?ne=<?php echo $_GET["ne"];?>&islem=<?php echo $_GET["islem"];?>&id=<?php echo $_GET["id"];?>&durum=semt">
    <div class="row" style="">
      <label>Semt <span style="font-size:8px; color:#ccc;">(t10)</span></label>
      <select name="t10" class="chosen-select form-control" style="width:95%;  height:35px;" multiple>
        <option value="0">Seçiniz</option>
        <?php
        $semtler = explode(',',$rsu["t10"]);
        $sql3=mysqli_query($conn, "select * from t2 where ne='semt' and s2=".$_SESSION["t6"]." order by s3 asc"); while($rsc3=mysqli_fetch_assoc($sql3)){
          $sql2=mysqli_query($conn, "select * from t2 where ne='ilce' and id=".$rsc3["s3"].""); $rsc2=mysqli_fetch_assoc($sql2);
          $sql1=mysqli_query($conn, "select * from t2 where ne='il' and id=".$rsc3["s2"].""); $rsc1=mysqli_fetch_assoc($sql1);
          ?>
          <option value="<?php echo $rsc3["t1"];?>" title="<?php echo $rsc3["t1"];?>" alt="<?php echo $rsc3["t1"];?>" <?php foreach($semtler as $semt){if($semt==$rsc3["t1"]){echo "selected";}}?>><?php echo $rsc1["t1"];?> > <?php echo $rsc2["t1"];?> > <?php echo $rsc3["t1"];?></option>
        <?php }?>
      </select>
    </div>
    <input class="btn btn-info" style="float:right; margin-right:5px; margin-top:20px;" type="submit" name="kaydet" value="Kaydet" />
  </form>
<?php }?>
<script src="search_ajax/chosen.jquery.js" type="text/javascript"></script> 
<script type="text/javascript">
  var config = {
    '.chosen-select': {},
    '.chosen-select-deselect': { allow_single_deselect: true },
    '.chosen-select-no-single': { disable_search_threshold: 10 },
    '.chosen-select-no-results': { no_results_text: 'Oops, Kayıt Bulunamadı!' },
    '.chosen-select-width': { width: "95%" }
  }
  for (var selector in config) {
    jQuery(selector).chosen(config[selector]);
  }
</script>