<?php session_start();
if (!isset($_SESSION['site_user'])){ 
header('location:giris.php'); exit(); 
} 
include('baglanti.php');
include('../include/tarihfonksiyonu.php');
include('../include/zamanfonksiyonu.php');
$id = htmlspecialchars($_GET["id"], ENT_QUOTES, 'utf-8');
?>

<!DOCTYPE html>
<html lang="tr">

<head>

	<meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>İlan Düzenle</title> 
	<link rel="stylesheet" href="css/bootstrap.css">
	<link rel="stylesheet" href="css/bootstrap-theme.css">
	<script type="text/javascript" src="ckeditor/ckeditor.js"></script>
	<link href="css/bootstrap-tagsinput.css" rel="stylesheet"/>
	<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
	<link href="css/dist/lity.css" rel="stylesheet"/>

<script src="css/dist/lity.js"></script>
<link rel="stylesheet" href="sweetalert/sweetalert.css">
	<script src="sweetalert/sweetalert.min.js"></script>
	<link href="css/facebox.css" media="screen" rel="stylesheet" type="text/css" />
<script src="js/facebox.js" type="text/javascript"></script>
<script type="text/javascript">
jQuery(document).ready(function($) {
$('a[rel*=facebox]').facebox({
loadingImage : 'img/loading.gif',
closeImage   : 'img/closelabel.png'
})
})
</script>


</head>



<body>


<?php include('menu.php'); ?>

    <div class="container-fuild">

      <div class="starter-template">
       
<?php
	$query = $conn->prepare("select * from uyeler where id = ?");
	$query->execute(array($id));
	$row      = $query->fetch();
	$kategori = $row['kategori'];
	$iletisim = $row['iletisim'];
	$btarih   = $row['btarih'];
	$ilanseo  = $row['seo'];
	$seviye   = $row['seviye'];
?>



<div class="col-md-9 col-sm-12">
	   
<div class="panel panel-default">
  <div class="panel-heading">
    <a href="javascript:history.back(-1)" class="btn btn-xs btn-primary pull-left">&laquo; Geri</a>
	<h3 class="panel-title"><?php echo $row["isim"]; ?></h3>
  </div>
  <div class="panel-body">
    
<?php	
if(isset($_POST['guncelle'])){
include('etiketfonksiyonu.php');	
	
$id			= htmlspecialchars($_POST["id"], ENT_QUOTES, 'utf-8');
$btarih		= $_POST["btarih"];
$kategori	= $_POST["kategori"];
$isim		= $_POST['isim'];
$adi			= $_POST['adi'];
$sira		= $_POST["sira"];
$seo	    		= $_POST["seo"];
$aciklama 	= $_POST['aciklama'];
$anahtar 	= $_POST["anahtar"];
$meta 		= $_POST['meta'];
$telefon		= $_POST["telefon"];
$sehir		= $_POST["sehir"];
$semt		= $_POST["semt"];
$iletisim	= $_POST["iletisim"];
$whatsapp	= $_POST["whatsapp"];
$seviye		= $_POST["seviye"];
$ekstra		= $_POST["ekstra"];

$queryB = $conn->query('SELECT * FROM uyeler WHERE id != '.$id.' AND seo LIKE "%' . $seo . '%"', PDO::FETCH_ASSOC);

if ( $queryB->rowCount() ){
echo "<script type='text/javascript'>alert('Girdiğiniz Seo URL veritabanında zaten mevcut! Benzersiz bir link oluşturun.');</script>";
}else{
	
$zaman = date("Y-m-d"); 
if( $btarih > $zaman or $btarih == $zaman){
$durumu = 'Yayında';
}else{ 
$durumu = 'Pasif';
}	

$up = $conn->prepare("update uyeler set kategori=?, isim=?, adi=?, telefon=?, whatsapp=?, seviye=?, ekstra=?, aciklama=?, anahtar=?, meta=?, sehir=?, semt=?, sira=?, btarih=?, seo=?, iletisim=?, durum=? where id=?");
$up->execute(array($kategori, $isim, $adi, $telefon, $whatsapp, $seviye, $ekstra, $aciklama, $anahtar, $meta, $sehir, $semt, $sira, $btarih, $seo, $iletisim, $durumu, $id));

$EtiketBosalt = $conn->prepare("DELETE FROM uyeetiketler WHERE konu=?");
$EtiketBosalt->execute(array($id));

$Parcala = explode("," , $anahtar);
foreach ( $Parcala as $Yaz ){
$etiketim = trim($Yaz);
$seolarim = strtolower(trim(str_replace($etikettr,$etiketen,$etiketim)));
$EtiketEkle = $conn->prepare("INSERT INTO uyeetiketler SET konu=?, baslik=?, seo=?");
$EtiketEkle->execute(array($id, $etiketim, $seolarim));
}

echo '<center><div class="alert alert-success" role="alert">İlan güncellendi!</div></center>';
echo '<meta http-equiv="refresh" content="1;URL=ilanlar.php">';
}
}	
?>

	
	<form class="form-group" method="post" action="">
	<div class="row">
  <div class="col-md-12">
  <div class="form-group">
    <div class="input-group">
      <div class="input-group-addon">Başlık</div>
      <input type="text" class="form-control" name="isim" id="isim" value="<?php echo $row["isim"]; ?>">
    </div>
  </div>
  </div>
  <div class="col-md-12">
  <div class="form-group">
<div class="input-group">
<div class="input-group-addon">Seo URL</div>
<input type="text" class="form-control" name="seo" id="seourl" placeholder="Otomatik tanımlanır (düzenleyebilirsiniz)" value="<?php echo $row["seo"]; ?>">
</div>
</div>
</div>
<div class="col-md-12">
<div class="form-group">
    <div class="input-group">
      <div class="input-group-addon">Link</div>
      <input type="text" class="form-control" name="ekstra" placeholder="Link eklerseniz direkt yönlenir..." value="<?php echo $row["ekstra"]; ?>">
    </div>
  </div>
  </div>
  
   <div class="col-md-4 col-sm-12">
  <div class="form-group">
    <div class="input-group">
      <div class="input-group-addon">Adı</div>
      <input type="text" class="form-control" name="adi" value="<?php echo $row["adi"]; ?>">
    </div>
  </div>
  </div>

<!-------------------------------------------------------------------------------------->
 <div class="col-md-4 col-sm-12">
  <div class="form-group">
	  <div class="input-group">
      <div class="input-group-addon">Kategori</div>
	  <select class="form-control" name="kategori">
	  <option></option>
		  <?php $query = $conn->query("SELECT * FROM kategori ORDER BY baslik ASC");
		  while($row2 = $query->fetch()){  ?>
		  <option value="<?php echo $row2['id']; ?>" <?php if($row2['id']==$kategori){ ?>selected<?php } ?>><?php echo $row2['baslik']; ?></option>
		  <?php } ?>
	  </select>
	</div>
	</div>
	</div>
	
	<div class="col-md-4 col-sm-12">
	<div class="form-group">
    <div class="input-group">
      <div class="input-group-addon">Sıra</div>
      <input type="number" class="form-control" name="sira" value="<?php echo $row["sira"]; ?>">
    </div>
  </div>
  </div>

<!-------------------------------------------------------------------------------------->
	<div class="col-md-4 col-sm-12">
  <div class="form-group">
    <div class="input-group">
      <div class="input-group-addon">Telefon</div>
      <input type="text" class="form-control" name="telefon" value="<?php echo $row["telefon"]; ?>">
    </div>
  </div>
  </div>
  
  <div class="col-md-4 col-sm-12">
  <div class="form-group">
    <div class="input-group">
      <div class="input-group-addon">Whatsapp</div>
      <input type="text" class="form-control" name="whatsapp" value="<?php echo $row["whatsapp"]; ?>">
    </div>
  </div>
  </div>
  
  <div class="col-md-4 col-sm-12">
  <div class="form-group">
	  <div class="input-group">
      <div class="input-group-addon">İletişim Tercihi</div>
	  <select class="form-control" name="iletisim">
		  <option value="0" <?php if($iletisim == 0){ ?>selected<?php } ?>>Arama + Whatsapp</option>
		  <option value="1" <?php if($iletisim == 1){ ?>selected<?php } ?>>Sadece Arama</option>
		  <option value="2" <?php if($iletisim == 2){ ?>selected<?php } ?>>Sadece Whatsapp</option>
	  </select>
	</div>
	</div>
	</div>
  
  
<!-------------------------------------------------------------------------------------->
	<div class="col-md-6 col-sm-12">
  <div class="form-group">
    <div class="input-group">
      <div class="input-group-addon">Şehir</div>
      <input type="text" class="form-control" name="sehir" value="<?php echo $row["sehir"]; ?>">
    </div>
  </div>
  </div>
<!-------------------------------------------------------------------------------------->
	<div class="col-md-6 col-sm-12">
  <div class="form-group">
    <div class="input-group">
      <div class="input-group-addon">İlçe+Semt</div>
      <input type="text" class="form-control" name="semt" value="<?php echo $row["semt"]; ?>">
    </div>
  </div>
  </div>
  
 <!--------------------------------------------------------------------------------------> 
  <div class="col-md-12 col-sm-12">
  <div class="form-group">
    <div class="input-group">
      <div class="input-group-addon">Hakkında</div>
      <textarea class="form-control" name="aciklama" id="aciklama"><?php echo $row["aciklama"]; ?></textarea>
    </div>
  </div>
  </div> 
</div>  

 <!--------------------------------------------------------------------------------------> 
<div class="row">
   <div class="col-md-12 col-sm-12">
  <div class="form-group">
    <div class="input-group">
      <div class="input-group-addon">Meta Açıklama</div>
	  <textarea class="form-control" name="meta" rows="3"><?php echo $row["meta"]; ?></textarea>
    </div>
  </div>
  </div>
<!--------------------------------------------------------------------------------------> 
<div class="col-md-12 col-sm-12"> 
  <div class="form-group">
    <div class="input-group">
      <div class="input-group-addon">Anahtar Kelimer</div>
	  <input type="text" class="form-control" name="anahtar" data-role="tagsinput" value="<?php echo $row["anahtar"]; ?>">
    </div>
  </div>
  </div>
<!-------------------------------------------------------------------------------------->

<div class="col-md-5 col-sm-12">

  <div class="form-group">
	  <div class="input-group">
      <div class="input-group-addon">Seviye</div>
	  <select class="form-control" name="seviye">
	  <option value="1" <?php if($seviye == 1){ ?>selected<?php } ?>>Platin İlan</option>
	  <option value="2" <?php if($seviye == 2){ ?>selected<?php } ?>>Gold İlan</option>
	 </select>
	</div>
	</div>
  </div>

<div class="col-md-7"> 
<div class="form-group">
	  <div class="input-group">
      <div class="input-group-addon">Bitiş Tarihi</div>
	  <select class="form-control" name="btarih">
		<option value="<?php echo $btarih; ?>" selected>! Değişiklik Yapma / <?php echo $btarih; ?> </option>
		<option value="<?php echo date('Y-m-d', strtotime('+1 week')) ?>">+1 Hafta Ekle / <?php echo date('Y-m-d', strtotime('+1 week')) ?></option>
		<option value="<?php echo date('Y-m-d', strtotime('+2 week')) ?>">+2 Hafta Ekle / <?php echo date('Y-m-d', strtotime('+2 week')) ?></option>
		<option value="<?php echo date('Y-m-d', strtotime('+3 week')) ?>">+3 Hafta Ekle / <?php echo date('Y-m-d', strtotime('+3 week')) ?></option>
		<option value="<?php echo date('Y-m-d', strtotime('+1 month')) ?>">+1 Ay Ekle / <?php echo date('Y-m-d', strtotime('+1 month')) ?></option>
		<option value="<?php echo date('Y-m-d', strtotime('+2 month')) ?>">+2 Ay Ekle / <?php echo date('Y-m-d', strtotime('+2 month')) ?></option>
		<option value="<?php echo date('Y-m-d', strtotime('+3 month')) ?>">+3 Ay Ekle / <?php echo date('Y-m-d', strtotime('+1 month')) ?></option>
		<option value="<?php echo date('Y-m-d', strtotime('+4 month')) ?>">+4 Ay Ekle / <?php echo date('Y-m-d', strtotime('+4 month')) ?></option>
		<option value="<?php echo date('Y-m-d', strtotime('+5 month')) ?>">+5 Ay Ekle / <?php echo date('Y-m-d', strtotime('+5 month')) ?></option>
		<option value="<?php echo date('Y-m-d', strtotime('+6 month')) ?>">+6 Ay Ekle / <?php echo date('Y-m-d', strtotime('+6 month')) ?></option>
		<option value="<?php echo date('Y-m-d', strtotime('+1 year')) ?>">+1 Yıl Ekle / <?php echo date('Y-m-d', strtotime('+1 year')) ?></option>
		<option value="<?php echo date('Y-m-d', strtotime('-1 days')) ?>">Yayından Kaldır</option>
	  </select>
	</div>
	</div>
	</div>
</div>
<!--------------------------------------------------------------------------------------> 

<input type="hidden" name="id" value="<?php echo $row["id"]; ?>">

<input type="submit" class="btn btn-block btn-success" name="guncelle" value="Güncelle">

 
 <!-------------------------------------------------------------------------------------->
 
</form>
	
  </div>
</div>

</div>	



<div class="col-md-3 col-sm-12">
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title">VİTRİN RESMİ</h3>
</div>
<div class="panel-body">
<div class="form-group">
<center>
<?php if($row["resim"] != ''){ ?>
<img src="<?php if($row["resim"] != ''){ echo '../ModelResim/'.$row["resim"]; }else{ echo '../img/resimsiz.jpg'; } ?>" class="img-rounded img-responsive" width="300px">
<?php }else{ ?>
<img src="img/resimsiz.png" class="img-rounded img-responsive">
<?php } ?>
<br/><br/>
<a rel="facebox" class="btn btn-block btn-primary" href="ilanresimguncelle.php?id=<?php echo $id ?>">Resmi Değiştir</a>
</a>
</center>
</div>
</div>
</div>
</div>

</div>
   
	   
      </div>

    </div><!-- /.container -->
<script type="text/javascript">
$(function() {
$(".silbuton").click(function(){
var element = $(this);
var del_id = element.attr("id");
var info = 'id=' + del_id;
swal({
title: "Emin misiniz?",
text: "Bu Resim Silinecek",
type: "warning",
showCancelButton: true,
confirmButtonColor: "#DD6B55",
confirmButtonText: "Evet, silinsin!",
cancelButtonText: "Hayır, vazgeç!",
closeOnConfirm: false,
closeOnCancel: false
},
function(isConfirm){
if (isConfirm) {
$.ajax({
type: "GET",
url: "ilangaleriresimsil.php",
data: info,
success: function(){
}
});
swal({
title: "Başarılı", 
text: "Resim Silindi", 
type: "success",
timer: 1000},
function(){ 
location.reload();
}
);
$(this).parents(".kayitlar").animate({ backgroundColor: "#000" }, "fast")
.animate({ opacity: "hide" }, "slow");
}else{
swal({
title: "İptal",
text: "Silme İşlemi İptal Edildi",
type: "error",
timer: 1000
});	 
}
}); 
return false;
});
});
</script>	
<script type="text/javascript">
var editor = CKEDITOR.replace( 'aciklama' );
</script>

<script>
$(function () {
  $('[data-toggle="tooltip"]').tooltip()
})
</script>
<script type="text/javascript" src="js/jquery.friendurl.js"></script>
<script type="text/javascript">
$(function(){
$('#isim').friendurl({id : 'seourl', divider: '-', transliterate: true});
});
</script>

	<script src="js/bootstrap-tagsinput.min.js"></script>
    <script src="js/bootstrap.js"></script>
   
</body>



</html>