<?php
include("include/baglan.php");
include("include/fonksiyonlar.php");
ob_start();
session_start();
oturumkontrolana();

$id=$_SESSION['id'];
$hesabim=$db->query("select * from yonetici where id='$id'")->fetch(PDO::FETCH_ASSOC);

if(isset($_POST['sil'])){
	$sil=$_POST['toplu_sil'];
	$sill = implode(",",$sil);
	foreach($sil as $s){
	$resim_sorgu1=$db->query("select * from urunler where id='$s'")->fetch(PDO::FETCH_ASSOC);
	 unlink('lib/images/urunler/'.$resim_sorgu1['resim']);
	$simdii=$db->query("delete from urunler where id='$s'")->fetch(PDO::FETCH_ASSOC);
	}
}

if($_GET['sill']){
	$idd=$_GET['sill'];
	$resim_sorgu=$db->query("select * from urunler where id='$idd'")->fetch(PDO::FETCH_ASSOC);
	unlink('lib/images/urunler/'.$resim_sorgu['resim']);
	$simdi=$db->query("delete from urunler where id='$idd'")->fetch(PDO::FETCH_ASSOC);
}
?>

<!DOCTYPE html>
<html lang="tr">
<head>
	<link rel="stylesheet" href="ifancybox/jquery.fancybox.css" />
	<script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
	<script src="ifancybox/jquery.fancybox.js"></script>
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<meta http-equiv="X-UA-Compatible" content="ie=edge">
	<title><?=$isimler['urunler']?> Listele - <?=$ayar['site_title']?> </title>
	<link rel="stylesheet" href="assets/vendors/core/core.css">
	<link rel="stylesheet" href="assets/vendors/datatables.net-bs4/dataTables.bootstrap4.css">
	<link rel="stylesheet" href="assets/fonts/feather-font/css/iconfont.css">
	<link rel="stylesheet" href="assets/vendors/flag-icon-css/css/flag-icon.min.css">
	<link rel="stylesheet" href="assets/css/demo_2/style.css">
	<link rel="shortcut icon" href="lib/images/logo/<?=$ayar['favicon']?>" />
</head>
<body>
	<div class="main-wrapper">

		<?php include("include/menu.php");?>
	
		<div class="page-wrapper">
				
		<?php include("include/header.php");?>
		
			<div class="page-content">
				<?=$idd?>
				<nav class="page-breadcrumb">
					<ol class="breadcrumb">
						<li class="breadcrumb-item"><a href="./">Anasayfa</a></li>
						<li class="breadcrumb-item active" aria-current="page"><?=$isimler['urunler']?> Listele</li>
					</ol>
				</nav>

				<div class="row">
					<div class="col-md-12 grid-margin stretch-card">
            <div class="card">
              <div class="card-body">
                <h6 class="card-title"><?=$isimler['urunler']?> Listele</h6>
                <form method="post">
                <div class="table-responsive">
                <div>
                <input type="submit" name="sil" class="btn btn-danger" value="Seçilenleri Sil">
                <a href="urunekle" class="btn btn-secondary"><?=$isimler['urunler']?> Ekle</a>
                </div>
                <br>
                <table id="dataTableExample" class="table">
				<thead>
				<tr>
				<th></th>
				<th>Sıra</th>
				<th><?=$isimler['urunler']?> Adı</th>
				<?php
				if($izin['urun_kategori']==0){
				?>
				<th>Kategori</th>
				<?php }?>
				<th>Resim</th>
				<th>Hit</th>
				<th>Eklenme Tarihi</th>
				<th>Durum</th>
				<th>İşlem</th>
				</tr>
				</thead>
				<tbody>
				<?php
				$listele=$db->query("select * from urunler  order by id desc",PDO::FETCH_ASSOC);
				if($listele->rowCount()){foreach($listele as $l){
				?>
				<tr>
				<td><input type="checkbox"  class="form-control" style="width:20px;" name="toplu_sil[]" value="<?=$l['id']?>"></td>
				<td><?=$l['sira']?></td>
				<td><?=$l['adi']?></td>
				<?php
				if($izin['urun_kategori']==0)
				{
				?>
				<td>
				<?php
				$katguncelleme = $l['kategori'];
				$katguncelleme = explode(',',$katguncelleme);
				foreach($katguncelleme as $kg =>$deger){
				$katadibelirle=$db->query("select * from urun_kategori where id='$deger'",PDO::FETCH_ASSOC);
				if($katadibelirle->rowCount()){foreach($katadibelirle as $ka){
				?>
				<p><?=$ka['kategori_adi']?></p>
				<?php }  } }?>
				</td>
				<?php }?>
				<td>
				<?php
				if($l['resim']=='resim-yok'){
				?>
				<a href="lib/noimage.png" target="_blank"><img src="lib/noimage.png" ></a>
				<?php } else {?>
				<a data-fancybox="gallery" href="lib/images/urunler/<?=$l['resim']?>"><img src="lib/images/urunler/<?=$l['resim']?>"></a>
				<?php }?>
				</td>
				<td><?=$l['hit']?></td>
				<td><?=$l['tarih']?></td>
				<td><?php if($l['durum']==0){?>  <button type="button" class="btn btn-success btn-icon">
				<i data-feather="eye"></i>
				</button> <?php } else {?>  <button type="button" class="btn btn-warning btn-icon">
				<i data-feather="eye-off"></i>
				</button> <?php }?></td>
				<td><a href="urunekle?islem=duzenle&id=<?=$l['id']?>" target="_blank">   <button type="button" class="btn btn-primary btn-icon">
				<i data-feather="check-square"></i>
				</button></a></td>
				</tr>
				<?php } }?>
				</tbody>
				</table>
                </div>
                </form>
              </div>
            </div>
					</div>
				</div>

			</div>

			<?php include("include/footer.php");?>
	
		</div>
	</div>

	<script src="assets/vendors/core/core.js"></script>
	<script src="assets/vendors/datatables.net/jquery.dataTables.js"></script>
	<script src="assets/vendors/datatables.net-bs4/dataTables.bootstrap4.js"></script>
	<script src="assets/vendors/feather-icons/feather.min.js"></script>
	<script src="assets/js/template.js"></script>
	<script src="assets/js/data-table.js"></script>
</body>
</html>