<?php echo !defined("GUVENLIK") ? die("Vaoww! Bu ne cesaret?") : null;?>
<?php
$page_header_setting = $db->prepare("select * from page_header where page_id='products' order by id");
$page_header_setting->execute();
$pagehead = $page_header_setting->fetch(PDO::FETCH_ASSOC);
?>
<?php
$productsayar = $db->prepare("select * from urunmodul_ayar where id=:id");
$productsayar->execute(array(
    'id' => 1
));
$prodayar = $productsayar->fetch(PDO::FETCH_ASSOC);
?>
<?php
$cat_id = $_GET['cat_id'];
$product_kat_info = $db->prepare("select * from urun_cat where id=:id and durum=:durum and dil=:dil");
$product_kat_info->execute(array(
        'id'=>$cat_id,
        'durum' => 1,
        'dil' => $_SESSION['dil']
));
$procat = $product_kat_info->fetch(PDO::FETCH_ASSOC);
?>
<?php
$product_ust_kat = $db->prepare("select * from urun_cat where id=:id and durum=:durum and dil=:dil");
$product_ust_kat->execute(array(
        'id' => $procat['ust_id'],
        'durum' => 1,
        'dil' => $_SESSION['dil']
));
$proustcat = $product_ust_kat->fetch(PDO::FETCH_ASSOC);
?>
<?php
$Sayfa = @intval($_GET['s']); if(!$Sayfa) $Sayfa = 1;
$Say = $db->query("SELECT * FROM urun WHERE durum='1' and dil='$_SESSION[dil]' and kat_id IN (
                                                          SELECT id FROM urun_cat  WHERE id = $_GET[cat_id] OR ust_id = $_GET[cat_id]) order by id desc");
$ToplamVeri = $Say->rowCount();
$Limit = 24;
$Sayfa_Sayisi = ceil($ToplamVeri/$Limit); if($Sayfa > $Sayfa_Sayisi){$Sayfa = 1;}
$Goster = $Sayfa * $Limit - $Limit;
$GorunenSayfa = 5;

if(!empty($_GET)){

    $urun_listele = $db->query("SELECT * FROM urun WHERE durum='1' and dil='$_SESSION[dil]' and kat_id IN (
                                                          SELECT id FROM urun_cat  WHERE id = $_GET[cat_id] OR ust_id = $_GET[cat_id]) order by id desc limit $Goster,$Limit");
    $UrunAl = $urun_listele->fetchAll(PDO::FETCH_ASSOC);

}


if($_GET['sirala'] == 1){

$urun_listele = $db->query("SELECT * FROM urun WHERE durum='1' and dil='$_SESSION[dil]' and kat_id IN (
                                                          SELECT id FROM urun_cat  WHERE id = $_GET[cat_id] OR ust_id = $_GET[cat_id]) order by id desc limit $Goster,$Limit");
$UrunAl = $urun_listele->fetchAll(PDO::FETCH_ASSOC);

}

if($_GET['sirala'] == 2){

    $urun_listele = $db->query("SELECT * FROM urun WHERE durum='1' and dil='$_SESSION[dil]' and kat_id IN (
                                                          SELECT id FROM urun_cat  WHERE id = $_GET[cat_id] OR ust_id = $_GET[cat_id]) order by hit desc limit $Goster,$Limit");
    $UrunAl = $urun_listele->fetchAll(PDO::FETCH_ASSOC);

}

if($_GET['sirala'] == 3){

    $urun_listele = $db->query("SELECT * FROM urun WHERE durum='1' and dil='$_SESSION[dil]' and kat_id IN (
                                                          SELECT id FROM urun_cat  WHERE id = $_GET[cat_id] OR ust_id = $_GET[cat_id]) order by fiyat asc limit $Goster,$Limit");
    $UrunAl = $urun_listele->fetchAll(PDO::FETCH_ASSOC);

}

if($_GET['sirala'] == 4){

    $urun_listele = $db->query("SELECT * FROM urun WHERE durum='1' and dil='$_SESSION[dil]' and kat_id IN (
                                                          SELECT id FROM urun_cat  WHERE id = $_GET[cat_id] OR ust_id = $_GET[cat_id]) order by fiyat desc limit $Goster,$Limit");
    $UrunAl = $urun_listele->fetchAll(PDO::FETCH_ASSOC);

}

?>
<?php
if($product_kat_info->rowCount() == 0)
{
    header('Location:'.$siteurl.'');

    exit;

}
?>
<title><?php echo ucwords_tr($procat['baslik']) ?> | <?php echo $ayar['site_baslik']?></title>
<meta name="description" content="<?php echo"$procat[meta_desc]" ?>">
<meta name="keywords" content="<?php echo"$procat[tags]" ?>">
<meta name="news_keywords" content="<?php echo"$procat[tags]" ?>">
<meta name="author" content="<?php echo"$ayar[site_baslik]" ?>" />
<meta itemprop="author" content="<?php echo"$ayar[site_baslik]" ?>" />
<meta name="robots" content="index follow">
<meta name="googlebot" content="index follow">
<meta property="og:type" content="website" />

<?php include "includes/config/header_libs.php";?>

</head>
<body>
<?php include 'includes/template/pre-loader.php'?>
<?php include 'includes/template/header.php'?>


<!-- Page Header ====================== !-->
<style>
    .page-headers-main{width:<?php if($pagehead['width']==1){?> 90%; <?php }else {?> 100% <?php }?> ;  padding:<?php echo $pagehead['padding'] ?>px 0 <?php echo $pagehead['padding'] ?>px 0 ; border:1px solid #<?php echo $pagehead[border_color] ?>;

        <?php if($pagehead['shadow'] == 1 ) {?>

        -webkit-box-shadow: inset 0px 5px 10px -7px rgba(0,0,0,0.1);
        -moz-box-shadow: inset 0px 5px 10px -7px rgba(0,0,0,0.1);
        box-shadow: inset 0px 5px 10px -7px rgba(0,0,0,0.1);

        <?php } ?>

        <?php if($pagehead['tip'] == 0 ) {?>

        background:#<?php echo $pagehead['bg_color'] ?> ;

        <?php } ?>

        <?php if($pagehead['tip'] == 1 ) {?>

        background:url(images/uploads/<?php echo $pagehead['bg_image'] ?>) ;

        box-shadow: inset 5000px 0 0 0 rgba(0, 0, 0, 0.7); border-color: rgba(0, 0, 0, 1);

        <?php } ?>

    }

    .product-main-box-img .buttons .text{background-color: #<?php echo $prodayar['incele_button_back'] ?>; }
</style>
<div class="page-headers-main page-headers-main about-title about-title-bg">
    <div class="d-table">
        <div class="d-table-cell">
            <div class="container">
                <div class="about-title-text">
                    <h2 style="color:#<?php echo $pagehead[text_color] ?>">
                        <?php echo ucwords_tr($procat['baslik']) ?>
                    </h2>
                    <span style="color:#<?php echo $pagehead[pasif_text_color] ?>; padding-right: 15px;"><?php echo $diller['buradasiniz'] ?>:</span>
                    <ul>
                        <li>
                            <a href="index.html" style="color:#<?php echo $pagehead[text_color] ?> !important;"><span style="padding-right: 15px; font-weight: 600;color:#<?php echo $pagehead[text_color] ?> !important;"><?php echo $diller['anasayfa'] ?></span></a>
                        </li>
                        <li>
                            <i class="icofont-rounded-double-right" style="color:#<?php echo $pagehead[pasif_text_color] ?>; padding-right: 15px;"></i>
                            <a href="urunler" style="color:#<?php echo $pagehead[text_color] ?>;"><span style="padding-right: 15px;  font-weight: 600; color:#<?php echo $pagehead[text_color] ?>;"><?php echo ucwords_tr($diller['urunlerimiz']) ?></span></a>

                        </li>
                        <li>
                            <i class="icofont-rounded-double-right" style="color:#<?php echo $pagehead[pasif_text_color] ?>; padding-right: 15px;"></i>
                            <span style="padding-right: 15px; color:#<?php echo $pagehead[text_color] ?>;"><?php echo ucwords_tr($procat['baslik']) ?></span>
                        </li>
                    </ul>
                </div>
            </div>
        </div>
    </div>
</div>  
<div class="recent-style-two main-service-area pt-100 pb-70">
    <div class="container">
        <div class="row">
            <div class="col-lg-8">
             <?php foreach($UrunAl as $prohit){

                $pro_list_cat = $db->prepare("select * from urun_cat where id=:id and durum=:durum and dil=:dil order by id desc limit 1 ");
                $pro_list_cat->execute(
                    array(
                        'id' => $prohit['kat_id'],
                        'durum'=> 1,
                        'dil' => $_SESSION['dil']
                    )
                );
                $pro_cat = $pro_list_cat->fetch(PDO::FETCH_ASSOC);

                ?>
                <div class="product-main-box">
                    <div class="product-main-box-in">
                        <div class="product-main-box-img">

                            <img src="images/product/<?php echo $prohit[gorsel] ?>" alt="<?php echo $prohit[baslik] ?>">
                            <a href="urun/<?php echo $prohit[id] ?>/<?php echo seo($prohit[baslik]) ?>"><div class="ovrly"></div></a>
                            <div class="buttons">
                                <a href="urun/<?php echo $prohit[id] ?>/<?php echo seo($prohit[baslik]) ?>" class="text" style="color:#<?php echo $prodayar[incele_button_color]?>;"><i class="fa fa-search" style="color:#<?php echo $prodayar[incele_button_color]?>"></i> <?php echo $diller['incele'] ?></a>
                            </div>

                        </div>
                        <div class="product-main-box-baslik">
                            <div class="product-main-box-baslik-in">
                                <a href="urun/<?php echo $prohit[id] ?>/<?php echo seo($prohit[baslik]) ?>"><?php echo $prohit[baslik] ?></a>
                            </div>
                        </div>
                        <div class="product-main-box-category">
                            <?php echo $pro_cat[baslik] ?>
                        </div>

                    </div>
                </div>

            <?php } ?>
        </div>
        <div class="col-lg-4 service-sidebar">
            <?php include'includes/template/products-cat-leftbar.php'; ?>
        </div>
    </div>
    <?php if($Sayfa >= 1){?>
        <nav aria-label="Page navigation example" style="margin-top: 50px;">
            <ul class="pagination pagination-sm justify-content-center">
            <?php } ?>

            <?php if($Sayfa > 1){?>

                <?php if($_GET[sirala] == null){ ?>
                    <li class="page-item"><a class="page-link" href="urunler?s=1"><?=$diller['sayfalama-ilk']?></a></li>
                    <li class="page-item"><a class="page-link" href="urunler?s=<?=$Sayfa - 1?>"><?=$diller['sayfalama-onceki']?></a></li>
                <?php } else { ?>
                    <li class="page-item"><a class="page-link" href="urunler?s=1&sirala=<?=$_GET[sirala]?>"><?=$diller['sayfalama-ilk']?></a></li>
                    <li class="page-item"><a class="page-link" href="urunler?s=<?=$Sayfa - 1?>&sirala=<?=$_GET[sirala]?>"><?=$diller['sayfalama-onceki']?></a></li>
                <?php } ?>

            <?php } ?>
            <?php
            for($i = $Sayfa - $GorunenSayfa; $i < $Sayfa + $GorunenSayfa +1; $i++){ if($i > 0 and $i <= $Sayfa_Sayisi){
                if($i == $Sayfa){
                  ?>

                  <li class="page-item active" aria-current="page">

                    <?php if($_GET[sirala] == null){ ?>

                      <a class="page-link" href="urunler?s=<?=$i?>"><?=$i?><span class="sr-only">(current)</span></a>

                  <?php } else { ?>

                      <a class="page-link" href="urunler?s=<?=$i?>&sirala=<?=$_GET[sirala]?>"><?=$i?><span class="sr-only">(current)</span></a>


                  <?php } ?>

              </li>

              <?php
          }else{ ?>

            <?php if($_GET[sirala] == null){ ?>

                <li class="page-item"><a class="page-link" href="urunler?s=<?=$i?>"><?=$i?></a></li>

            <?php } else { ?>

                <li class="page-item"><a class="page-link" href="urunler?s=<?=$i?>&sirala=<?=$_GET[sirala]?>"><?=$i?></a></li>

            <?php } ?>

            <?php
        }
    }
}
?>

<?php if($urun_listele->rowCount() <=0) { } else { ?>
    <?php if($Sayfa != $Sayfa_Sayisi){?>


        <?php if($_GET[sirala] == null){ ?>

            <li class="page-item"><a class="page-link" href="urunler?s=<?=$Sayfa + 1?>"><?=$diller['sayfalama-sonraki']?></a></li>
            <li class="page-item"><a class="page-link" href="urunler?s=<?=$Sayfa_Sayisi?>"><?=$diller['sayfalama-son']?></a></li>

        <?php } else { ?>

            <li class="page-item"><a class="page-link" href="urunler?s=<?=$Sayfa + 1?>&sirala=<?=$_GET[sirala]?>"><?=$diller['sayfalama-sonraki']?></a></li>
            <li class="page-item"><a class="page-link" href="urunler?s=<?=$Sayfa_Sayisi?>&sirala=<?=$_GET[sirala]?>"><?=$diller['sayfalama-son']?></a></li>

        <?php } ?>



    <?php }} ?>

    <?php if($Sayfa >= 1){?>
    </ul>
</nav>
<?php } ?>
</div>
</div>
<?php include 'includes/template/footer.php'?>
</body>
    </html>
<?php include "includes/config/footer_libs.php";?>

