<?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>Gold İlanlar</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="//code.jquery.com/jquery-1.10.2.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-12">
	   
<div class="panel panel-default">
  <div class="panel-heading">
  
    <h3 class="panel-title">GOLD İLANLAR</h3>
  </div>
  <div class="panel-body">
    
	<div class="table-responsive">
	<div class="form-group">
    <div class="input-group">
      <div class="input-group-addon alert-info">Hızlı Üye Ara</div>
      <input type="search" class="light-table-filter form-control" data-table="Arama" placeholder="Aranacak kelime...">
    </div>
  </div>
	<table class="table table-bordered table-hover Arama">
 
		<thead>
		<tr>
			<th>Sıra</th>
			<th>Resim</th>
			<th>İlan Adı</th>
			<th>Kategori</th>
			<th>Durum</th>
			<th width="130px">İşlemler</th>
			
		</tr>
       </thead>
	   
<tbody id="listele">

<?php 
$verisayisi = count($conn->query("select * from uyeler WHERE seviye=2",PDO::FETCH_ASSOC)->fetchAll());
	$gosterilecek = 150;
	$sayfa;

	$sayfasayisi = ceil($verisayisi/$gosterilecek);
	if(isset($_GET['sayfa'])){
		$sayfa = htmlentities($_GET['sayfa'],  ENT_QUOTES,  "utf-8");
	}else{
		$sayfa = 1;
	}
	if($sayfa > $sayfasayisi){
		$sayfa  = 1;
	}elseif(!is_numeric($sayfa) || $sayfa < 1){
		$sayfa = 1;
	}
	$baslangic = ($gosterilecek * $sayfa)-$gosterilecek;
?>		
		
		<?php 
		$query = $conn->prepare("SELECT * FROM uyeler WHERE seviye=2 ORDER BY durum ASC, sira ASC LIMIT $baslangic,$gosterilecek");
		$query->execute();
		$count = $query->rowcount();
		if ($count > 0){ 
		while($row = $query->fetch()){
		$ilanID	   = $row['id'];
		$kategori  = $row['kategori'];
		$durum	   = $row['durum'];
		$isim      = $row['isim'];
		$tarih	   = $row['tarih'];
		$btarih	   = $row['btarih'];		
		$seviye	   = $row['seviye'];
		$resim	   = $row['resim'];
		$sira	   = $row['sira'];
		$Seo	   	   = $row['seo'];

date_default_timezone_set('Europe/Istanbul');
$zaman 	   = date("Y-m-d");

$zamansor = $conn->query("SELECT * FROM uyeler WHERE durum = 'Yayında' AND btarih <= '$zaman' ORDER BY id ASC");

while($zamanyaz = $zamansor->fetch()){

$guncelle = $conn->prepare("UPDATE uyeler SET durum = ? WHERE id = ?");
$guncelle->execute(array( 'Pasif' , $zamanyaz['id'] ));

}		
		?>
<tr height="120" class="kayitlar" id="listele_<?php echo $ilanID; ?>">
<td class="sortable"><span class="glyphicon glyphicon-sort aria-hidden="true"></span>  <?php echo $sira; ?></td>
				<td class="cerceve">
				<?php if($resim!=''){ ?>
				<a href="../ModelResim/<?php echo $resim; ?>" data-lity><img src="../ModelResim/<?php echo $resim; ?>" class="resim"></a>
				<?php }else{ ?>
				<img src="img/resimsiz.png" class="resim">
				<?php } ?>
				</td>			
				
				<td><?php echo '<strong><small>'.$isim.'</small></strong>'; ?></td>
				
				<td><small><?php 
				$query7 = $conn->prepare("select * from kategori where id = ? ");
				$query7->execute(array($kategori));
				$row7 = $query7->fetch();
				$gelenilBaslik	= $row7['baslik'];				
				echo $gelenilBaslik;  ?></small></td>
				
				<td>
				<?php 
				$zaman = date("Y-m-d"); 
				if( $btarih > $zaman or $btarih == $zaman){
					echo '<span style="color:green;font-weight:bold;"><span class="glyphicon glyphicon-ok" aria-hidden="true"></span><br/> Yayında</span><br><small>'.turkcetarih('j F Y',$btarih).' <br/>tarihinde sona erecek</small>'; 
					}else{ 
					echo '<span style="color:red;font-weight:bold;"><span class="glyphicon glyphicon-remove" aria-hidden="true"></span><br/> <small>'.turkcetarih('j F Y',$btarih).' <br/>tarihinde süresi doldu</small></span>';} 
					?>
				</td>

				<td>
				<a href="ilangaleri.php?id=<?php echo $ilanID; ?>" data-toggle="tooltip" data-placement="top" title="İlan Galeri" class="btn btn-xs btn-warning"><span class="glyphicon glyphicon-picture"></span></a>
				
				<a href="../Escort/<?php echo $Seo; ?>/<?php echo $ilanID; ?>" target="_blank" data-toggle="tooltip" data-placement="top" title="İlana Git" class="btn btn-xs btn-success"><span class="glyphicon glyphicon-search"></span></a>
				
				<a href="ilanduzenle.php?id=<?php echo $ilanID; ?>" data-toggle="tooltip" data-placement="top" title="Düzenle" class="btn btn-xs btn-primary"><span class="glyphicon glyphicon-pencil"></span></a> 
				
				<a href="#" title="Sil" data-toggle="tooltip" data-placement="top" class="btn btn-danger btn-xs silbuton" id="<?php echo $ilanID; ?>" ><span class="glyphicon glyphicon-minus-sign"></span></a>
				</td>                                    
			</tr>
		<?php } ?>
		<?php } else{ echo '<tr><td colspan="6"><div class="alert alert-warning" role="alert">Profil oluşturulmamış</div></td></tr>'; ?>  <?php } ?>

		</tbody>

 
	</table>
	</div>
	
  </div>
  
  
  <div class="panel-footer">
  
<nav aria-label="Page navigation">
<ul class="pagination pagination-sm">
<?php 
			if($sayfa > 1){
				echo '<li><a href="platin-ilanlar.php?sayfa=1">İlk</a></li>';
				echo '<li><a title="önceki" href="platin-ilanlar.php?sayfa='.($sayfa-1).'"><span aria-hidden="true">&laquo;</span></a></li>';
			}
			
		
			$ekgoster = 2;
			for($i = $sayfa - $ekgoster; $i <= $sayfa + $ekgoster;$i++){
				if($i > 0 && $i <= $sayfasayisi){
					if($i == $sayfa){
						
						echo '<li class="active"><a>'.$i.'</a></li>';
					}else{
						echo '<li><a href="platin-ilanlar.php?sayfa='.$i.'">'.$i.'</a></li>';
						
					}
				}
			}
			
			
			if($sayfa < $sayfasayisi){
				echo '<li><a title="sonraki" href="platin-ilanlar.php?sayfa='.($sayfa+1).'"><span aria-label="Next">&raquo;</span></a></li>';
				echo '<li><a href="platin-ilanlar.php?sayfa='.$sayfasayisi.'">Son</a></li>';

			}

		?>
</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 src="js/bootstrap-tagsinput.min.js"></script>
    <script src="js/bootstrap.js"></script>
</body>



</html>