<?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 sube_kategori where id='$s'")->fetch(PDO::FETCH_ASSOC);
	 unlink('lib/images/sube_kategori/'.$resim_sorgu1['kategori_resim']);
	$simdii=$db->query("delete from sube_kategori where id='$s'")->fetch(PDO::FETCH_ASSOC);
	}
}

if($_GET['sil']){
	$idd=$_GET['sil'];
	$resim_sorgu=$db->query("select * from sube_kategori where id='$idd'")->fetch(PDO::FETCH_ASSOC);
	unlink('lib/images/sube_kategori/'.$resim_sorgu['kategori_resim']);
	$simdi=$db->query("delete from sube_kategori 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['sube_kategori']?> 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">

				<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['sube_kategori']?> 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['hizmet_kategori']?> 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="subekategoriekle" class="btn btn-secondary"><?=$isimler['sube_kategori']?> Ekle</a>
                </div>
                <br>
					<table id="dataTableExample" class="table">
					<thead>
					<tr>
					<th></th>
					<th>Sıra</th>
					<th><?=$isimler['sube_kategori']?> Adı</th>
					<th>Kategori</th>
					<th>Resim</th>
					<th>Hit</th>
					<th>Durum</th>
					<th>İşlem</th>
					</tr>
					</thead>
					<tbody>
					<?php
					$listele=$db->query("select * from sube_kategori  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['kategori_adi']?></td>
					<td>
					<?php
					$katguncelleme  = $l['kategori'];
					$katguncelleme  =explode(',',$katguncelleme );
					foreach($katguncelleme  as $kg =>$deger){
					$kategorii=$db->query("select *  from sube_kategori where id='$deger'",PDO::FETCH_ASSOC);
					if($kategorii->rowCount()){foreach($kategorii as $k){
					?>
					<p><?=$k['kategori_adi']?></p>
					<?php } } }?>
					</td>
					<td>
					<?php
					if($l['kategori_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/sube_kategori/<?=$l['kategori_resim']?>"><img src="lib/images/sube_kategori/<?=$l['kategori_resim']?>"></a>
					<?php }?>
					</td>
					<td><?=$l['hit']?></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="subekategoriekle?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>