<?php session_start();
if (!isset($_SESSION['site_user'])){ 
header('location:giris.php'); exit();
} 
include('baglanti.php');
include('../include/tarihfonksiyonu.php');
?>

<!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 Ekle</title>

	<link rel="stylesheet" href="css/bootstrap.css">
	<script type="text/javascript" src="ckeditor/ckeditor.js"></script>
	<link rel="stylesheet" href="css/bootstrap-theme.css">
	<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/vendor/jquery.js"></script>
	<script src="css/dist/lity.js"></script> 	
	<link rel="stylesheet" href="sweetalert/sweetalert.css">
	<script src="sweetalert/sweetalert.min.js"></script>
	<script src="js/jquery-ui.js"></script>
<style type="text/css">
.sortable { cursor: move; }
</style>
<script type="text/javascript">
$(document).ready(function() {
$("#listele").sortable({ revert:'true', opacity:'1', placeholder:'ui-state-highlight',
update: function() {
var order = $(this).sortable('serialize');
$.post("siraguncelle.php",order,function(returnMsg){
alert( 'Yeniden sıralandı' );
});
}
});
});
</script>

</head>



<body>

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

    <div class="container-fuild">

      <div class="starter-template">
       







<div class="col-md-8 col-md-offset-2">
	   
<div class="panel panel-primary">
  <div class="panel-heading">
	<h3 class="panel-title">YENİ İLAN EKLE</h3>
  </div>
<div class="panel-body">
    
<?php
if ( isset($_POST['kaydet']) ){
include('etiketfonksiyonu.php');
	
$tarih		= date('Y-m-d');
$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"];

$kaynak     = $_FILES["dosya"]["tmp_name"];
$dosyaadi   = $_FILES["dosya"]["name"];
$dboyut     = $_FILES["dosya"]["size"];
$dosyatipi  = $_FILES["dosya"]["type"];	

if(strpos($dosyatipi,"JPEG") || strpos($dosyatipi,"PNG") || strpos($dosyatipi,"JPG") || strpos($dosyatipi,"GIF") || strpos($dosyatipi,"jpeg") || strpos($dosyatipi,"png") || strpos($dosyatipi,"jpg") || strpos($dosyatipi,"gif")) {
	
$queryB = $conn->query('SELECT * FROM uyeler WHERE 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{	
	
$uzanti        = explode(".", $dosyaadi);
$resimturu     = end($uzanti);
$yeniad        = $seo.'-'.date('YmdHis');
$yeniresimadi  = $yeniad.'.'.$resimturu;
move_uploaded_file($kaynak, "../ModelResim/" . $yeniresimadi);
$resimyolu 	   = $yeniresimadi;

$zaman = date("Y-m-d"); 
if( $btarih > $zaman or $btarih == $zaman){
$durumu = 'Yayında';
}else{ 
$durumu = 'Pasif';
}

$Ekle = $conn->prepare("INSERT INTO uyeler (kategori, isim, adi, telefon, whatsapp, seviye, ekstra, aciklama, anahtar, meta, sehir, semt, sira, durum, tarih, btarih, seo, iletisim, resim) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)");

$Ekle->execute(array($kategori, $isim, $adi, $telefon, $whatsapp, $seviye, $ekstra, $aciklama, $anahtar, $meta, $sehir, $semt, $sira, $durumu, $tarih, $btarih, $seo, $iletisim, $resimyolu));

$SonID 	 = $conn->lastInsertId();
$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($SonID, $etiketim, $seolarim));
}

echo '<center><div class="alert alert-success" role="alert">İlan eklendi!</div></center>';
echo '<meta http-equiv="refresh" content="1;URL=ilanlar.php">';	
}
}else{	
echo "<script type='text/javascript'>alert('Dosya formatı desteklenmiyor!');</script>";
echo '<meta http-equiv="refresh" content="0;URL='.$ref.'">';
}
}	
?>
 
	
	<form class="form-group" method="post" action="" enctype="multipart/form-data">

  <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">
    </div>
  </div>
  
  <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)" autocomplete="on">
</div>
</div>
  
 <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...">
    </div>
  </div>

<!-------------------------------------------------------------------------------------->

<div class="row">
<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">
    </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 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">
    </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" placeholder="0123 456 78 90">	  
    </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" placeholder="+901234567890">	  
    </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">Arama + Whatsapp</option>
	  <option value="1">Sadece Arama</option>
	  <option value="2">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">
    </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" placeholder="Şişli+Fulya">
    </div>
  </div>
  </div>
  </div>
<!-------------------------------------------------------------------------------------->

  <div class="form-group">
    <div class="input-group">
      <div class="input-group-addon">Hakkında</div>
      <textarea class="form-control" name="aciklama" id="aciklama"></textarea>
    </div>
  </div>
 
 <!-------------------------------------------------------------------------------------->   

  <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"></textarea>
    </div>
  </div>

<!--------------------------------------------------------------------------------------> 

  <div class="form-group">
    <div class="input-group">
      <div class="input-group-addon">Anahtar Kelimeler</div>
      <input type="text" class="form-control" name="anahtar" data-role="tagsinput" placeholder="">
    </div>
  </div>
  
  <!-------------------------------------------------------------------------------------->
<div class="form-group">
<div class="input-group">
<div class="input-group-addon">Vitrin Resim</div>
<input type="file" name="dosya" id="dosya" class="btn btn-sm btn-default form-control"> 
</div>
</div>

<!-------------------------------------------------------------------------------------->

<div class="col-md-6">
  <div class="form-group">
	  <div class="input-group">
      <div class="input-group-addon">Seviye</div>
	  <select class="form-control" name="seviye">
	  <option value="1">Platin İlan</option>
	  <option value="2">Gold İlan</option>
	 </select>
	</div>
	</div>
	</div>
 <div class="col-md-6">
 <div class="form-group">
	  <div class="input-group">
      <div class="input-group-addon">Yayın Süresi</div>
	  <select class="form-control" name="btarih">
	  <option value="<?php echo date('Y-m-d', strtotime('+1 days')) ?>">1 Gün / <?php echo date('Y-m-d', strtotime('+1 days')) ?> tarihine kadar</option>
	  <option value="<?php echo date('Y-m-d', strtotime('+2 days')) ?>">2 Gün / <?php echo date('Y-m-d', strtotime('+2 days')) ?> tarihine kadar</option>
	  <option value="<?php echo date('Y-m-d', strtotime('+3 days')) ?>">3 Gün / <?php echo date('Y-m-d', strtotime('+3 days')) ?> tarihine kadar</option>
	  <option value="<?php echo date('Y-m-d', strtotime('+4 days')) ?>">4 Gün / <?php echo date('Y-m-d', strtotime('+4 days')) ?> tarihine kadar</option>
	  <option value="<?php echo date('Y-m-d', strtotime('+5 days')) ?>">5 Gün / <?php echo date('Y-m-d', strtotime('+5 days')) ?> tarihine kadar</option>
	  <option value="<?php echo date('Y-m-d', strtotime('+6 days')) ?>">6 Gün / <?php echo date('Y-m-d', strtotime('+6 days')) ?> tarihine kadar</option>
	  <option value="<?php echo date('Y-m-d', strtotime('+1 week')) ?>">1 Hafta / <?php echo date('Y-m-d', strtotime('+1 week')) ?> tarihine kadar</option>
	  <option value="<?php echo date('Y-m-d', strtotime('+2 week')) ?>">2 Hafta / <?php echo date('Y-m-d', strtotime('+2 week')) ?> tarihine kadar</option>
	  <option value="<?php echo date('Y-m-d', strtotime('+3 week')) ?>">3 Hafta / <?php echo date('Y-m-d', strtotime('+3 week')) ?> tarihine kadar</option>
	  <option value="<?php echo date('Y-m-d', strtotime('+1 month')) ?>">1 Ay / <?php echo date('Y-m-d', strtotime('+1 month')) ?> tarihine kadar</option>
	  <option value="<?php echo date('Y-m-d', strtotime('+2 month')) ?>">2 Ay / <?php echo date('Y-m-d', strtotime('+2 month')) ?> tarihine kadar</option>
	  <option value="<?php echo date('Y-m-d', strtotime('+3 month')) ?>">3 Ay / <?php echo date('Y-m-d', strtotime('+3 month')) ?> tarihine kadar</option>
	  <option value="<?php echo date('Y-m-d', strtotime('+4 month')) ?>">4 Ay / <?php echo date('Y-m-d', strtotime('+4 month')) ?> tarihine kadar</option>
	  <option value="<?php echo date('Y-m-d', strtotime('+5 month')) ?>">5 Ay / <?php echo date('Y-m-d', strtotime('+5 month')) ?> tarihine kadar</option>
	  <option value="<?php echo date('Y-m-d', strtotime('+6 month')) ?>">6 Ay / <?php echo date('Y-m-d', strtotime('+6 month')) ?> tarihine kadar</option>
	  <option value="<?php echo date('Y-m-d', strtotime('+1 year')) ?>">1 Yıl / <?php echo date('Y-m-d', strtotime('+1 year')) ?> tarihine kadar</option>
	  </select>
	</div>
	</div>
	</div>

<!--------------------------------------------------------------------------------------> 
<input type="submit" class="btn btn-block btn-success" name="kaydet" value="Kaydet">
 
 <!-------------------------------------------------------------------------------------->
 
</form>
	
	</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 İlan ve Ona Ait Olan Fotoğraflar 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: "ilansil.php",
data: info,
success: function(){	
}
});
swal({
title: "Başarılı", 
text: "İlan 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>
$(document).ready(function(){
    $('[data-toggle="tooltip"]').tooltip();
    $('.btn-default').tooltip({trigger: "click"}); 

});
</script>
<!-- Arama -->
<script>
(function(document) {
	'use strict';

	var LightTableFilter = (function(Arr) {

		var _input;

		function _onInputEvent(e) {
			_input = e.target;
			var tables = document.getElementsByClassName(_input.getAttribute('data-table'));
			Arr.forEach.call(tables, function(table) {
				Arr.forEach.call(table.tBodies, function(tbody) {
					Arr.forEach.call(tbody.rows, _filter);
				});
			});
		}

		function _filter(row) {
			var text = row.textContent.toLowerCase(), val = _input.value.toLowerCase();
			row.style.display = text.indexOf(val) === -1 ? 'none' : 'table-row';
		}

		return {
			init: function() {
				var inputs = document.getElementsByClassName('light-table-filter');
				Arr.forEach.call(inputs, function(input) {
					input.oninput = _onInputEvent;
				});
			}
		};
	})(Array.prototype);

	document.addEventListener('readystatechange', function() {
		if (document.readyState === 'complete') {
			LightTableFilter.init();
		}
	});

})(document);
</script>
<!-- Arama -->
<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>