<?php echo !defined("GUVENLIK") ? die("Erisim Engellendi!.") : null;?>
<?php $id = g('id');?>
<?php $altkategori = Sonuc(Sorgu("SELECT * FROM alt_urun_kategori WHERE seo = '$id'"));?>
<?php $kategori = Sonuc(Sorgu("SELECT * FROM urun_kategori WHERE id = '$altkategori->ust_id'"));?>
<?php $link = Sonuc(Sorgu("SELECT * FROM alt_urun_kategori WHERE durum = '1'"));?>

<div class="columns-container">
    <div class="container" id="columns">
        <!-- breadcrumb -->
        <div class="breadcrumb clearfix">
            <a class="home" href="index.html" title="Anasayfaya Git">Anasayfa</a>
			<span class="navigation-pipe">&nbsp;</span>
            <span class="home"><?php echo $kategori->kategori_adi;?></span>
            <span class="navigation-pipe">&nbsp;</span>
            <span class="navigation_page"><?php echo $altkategori->kategori_adi;?></span>
        </div>
        <!-- ./breadcrumb -->
        <!-- row -->
        <div class="row">
            <!-- Left colunm -->
            <div class="column col-xs-12 col-sm-3" id="left_column">
                <!-- block category -->
                <div class="block left-module">
                    <p class="title_block">ÜRÜN KATEGORİSİ</p>
                    <div class="block_content">
                        <!-- layered -->
                        <div class="layered layered-category">
                            <div class="layered-content">
							<ul class="tree-menu">
							<?php $Sorgu = Sorgu("SELECT * FROM urun_kategori WHERE durum = '1' ORDER BY id ASC");
								while($Sonuc = Sonuc($Sorgu)){?>
								<?php $varmi = Sonuc(Sorgu("SELECT * FROM alt_urun_kategori WHERE durum = '1' AND ust_id = '$Sonuc->id'"));?>
                                    <li class="<?php echo($Sonuc->id == $altkategori->ust_id ? 'active' : '');?>">
                                        <span></span><a href="AnaKategori/<?php echo $Sonuc->seo;?>.html"><b><?php echo $Sonuc->kategori_adi;?></b></a>
										<?php $AltSorgu = Sorgu("SELECT * FROM alt_urun_kategori WHERE durum = '1' AND ust_id = '$Sonuc->id' ORDER BY sira ASC");
										if(!mysql_affected_rows()){
											
										}else{
                                            $ac = ($Sonuc->id == $altkategori->ust_id) ? 'style="display:block;"' : '';
											echo '<ul '.$ac.'>';
											while($AltSonuc = Sonuc($AltSorgu)){?>
												<li class="<?php echo($AltSonuc->seo == $id ? 'active' : '');?>"><span></span><a href="Kategori/<?php echo $AltSonuc->seo;?>.html"><b><?php echo $AltSonuc->kategori_adi;?></b></a></li>
											<?php } echo '</ul>';?>
										<?php }?>       
                                    </li>
								<?php }?>
                                </ul>
                            </div>
                        </div>
                        <!-- ./layered -->
                    </div>
                </div>
                <!-- ./block category  -->
                <!-- block filter -->
                <div class="block left-module">
                    <p class="title_block">ÜRÜN FİLTRESİ</p>
                    <div class="block_content">
                        <!-- layered -->
                        <div class="layered layered-filter-price">
                            <!-- filter categgory -->
                            <div class="layered_subtitle">KATEGORİLER</div>
                            <div class="layered-content">
                                <ul class="check-box-list">
								<?php $Sorgu = Sorgu("SELECT * FROM alt_urun_kategori WHERE durum = '1' AND ust_id = '$altkategori->ust_id' ORDER BY id ASC");
									while($Sonuc = Sonuc($Sorgu)){
                                    $checked = ($Sonuc->seo == $id) ? "checked" : ""; ?>
									<?php $Miktar = Sorgu("SELECT * FROM urunler WHERE durum = '1' AND altkategori = '$Sonuc->id'");?>
                                    <li>
                                        <input type="checkbox" id="<?php echo $Sonuc->seo;?>" name="kk" value="<?=$Sonuc->id;?>" data-name="<?=$Sonuc->kategori_adi;?>" <?=$checked?>/>
                                        <label for="<?php echo $Sonuc->seo;?>">
                                        <span class="button"></span>
                                        <?php echo $Sonuc->kategori_adi;?><span class="count">(<?php echo say($Miktar); ?>)</span>
                                        </label>
                                    </li>
									<?php }?>
                                </ul>
                            </div> 
                            <!-- ./filter categgory -->
                            <!-- filter price -->
                            <div class="layered_subtitle">FİYAT</div>
                            <div class="layered-content slider-range">
                                <ul class="check-box-list">
                                    <li>
                                        <input type="checkbox" id="p1" name="ff" value="1" />
                                        <label for="p1">
                                        <span class="button"></span>
                                        10 TL - 50 TL
                                        </label>   
                                    </li>
                                    <li>
                                        <input type="checkbox" id="p2" name="ff" value="2" />
                                        <label for="p2">
                                        <span class="button"></span>
                                        50 TL - 100 TL
                                        </label>   
                                    </li>
                                    <li>
                                        <input type="checkbox" id="p3" name="ff" value="3" />
                                        <label for="p3">
                                        <span class="button"></span>
                                        100 TL - 250 TL
                                        </label>   
                                    </li>
									<li>
                                        <input type="checkbox" id="p4" name="ff" value="4" />
                                        <label for="p4">
                                        <span class="button"></span>
                                        250 TL - 500 TL
                                        </label>   
                                    </li>
									<li>
                                        <input type="checkbox" id="p5" name="ff" value="5" />
                                        <label for="p5">
                                        <span class="button"></span>
                                        500 TL - 1000 TL
                                        </label>   
                                    </li>
									<li>
                                        <input type="checkbox" id="p6" name="ff" value="6" />
                                        <label for="p6">
                                        <span class="button"></span>
                                        1000 TL - 2000 TL
                                        </label>   
                                    </li>
									<li>
                                        <input type="checkbox" id="p7" name="ff" value="7" />
                                        <label for="p7">
                                        <span class="button"></span>
                                        2000 TL - 2500 TL
                                        </label>   
                                    </li>
									<li>
                                        <input type="checkbox" id="p8" name="ff" value="8" />
                                        <label for="p8">
                                        <span class="button"></span>
                                        2500 TL - Üzerinde
                                        </label>   
                                    </li>
                                </ul>
                            </div>
                            <!-- ./filter price -->
							<?php 
							$bol = explode("||",$altkategori->sec_kat);
							foreach ($bol as $b){
							$SecenekSorgu = Sorgu("SELECT * FROM secenek_kategori WHERE kategori_adi = '$b' ORDER BY id ASC");
							while($SecenekSonuc = Sonuc($SecenekSorgu)){?>
                            <!-- ./filter size -->
                            <div class="layered_subtitle"><?php echo $SecenekSonuc->kategori_adi;?></div>
                            <div class="layered-content filter-size">
                                <ul class="check-box-list">
								<?php 
									$Sorgu = Sorgu("SELECT * FROM secenek WHERE kategori = '$SecenekSonuc->id' ORDER BY id ASC");
									while($Sonuc = Sonuc($Sorgu)){?>
                                    <li>
                                        <input type="checkbox" id="<?php echo $Sonuc->id;?>" name="cc[]" value="<?php echo $Sonuc->id;?>" class="cc" />
                                        <label for="<?php echo $Sonuc->id;?>">
                                        <span class="button"></span><?php echo $Sonuc->adi;?>
                                        </label>   
                                    </li>
									<?php }?>
                                </ul>
                            </div>
							<?php }}?>
                        </div>
                        <!-- ./layered -->

                    </div>
                </div>
                <!-- ./block filter  -->
                
                <!-- left silide -->
				<div class="block left-module">
                <div class="col-left-slide left-module">
                    <ul class="owl-carousel owl-style2" data-loop="false" data-nav = "false" data-margin = "30" data-autoplayTimeout="1000" data-autoplayHoverPause = "true" data-items="1" data-autoplay="true">
                     <?php reklam();?>
                    </ul>
                </div>
                </div>
                <!-- TAGS -->
                <div class="block left-module">
                    <p class="title_block">ETİKETLER</p>
                    <div class="block_content">
                        <div class="tags">
						<?php $Sorgu = Sorgu("SELECT * FROM etiketler WHERE durum = '1' ORDER BY id DESC");
						while($Sonuc = Sonuc($Sorgu)){?>
                            <a href="<?php echo $Sonuc->url;?>"><span class="level<?php echo rand(1,5);?>"><?php echo $Sonuc->adi;?></span></a>
						<?php }?>
                        </div>
                    </div>
                </div>
                <!-- ./TAGS -->
            </div>
            <!-- ./left colunm -->
            <!-- Center colunm-->
            <div class="center_column col-xs-12 col-sm-9" id="center_column">
                <!-- view-product-list-->
                <div id="view-product-list" class="view-product-list">
                    <h2 class="page-heading">
                        <span class="page-heading-title"><?php echo $altkategori->kategori_adi;?></span>
                    </h2>
                    <ul class="display-product-option">
                        <li class="view-as-grid selected">
                            <span>Tablo</span>
                        </li>
                        <li class="view-as-list">
                            <span>Liste</span>
                        </li>
                    </ul>
                    <!-- PRODUCT LIST -->
                    <ul class="row product-list grid" name="uubry">
							<?php 
$page = @intval($_GET['s']);
 if(!$page) $page = 1;
 $total = mysql_num_rows(mysql_query("SELECT * FROM urunler WHERE durum = '1' AND altkategori = '$altkategori->id' ORDER BY id ASC LIMIT 0,9999"));
 $limit= 9;
 $page_count = ceil($total/$limit);
 if($page > $page_count) $page = 1;
 $show = $page * $limit - $limit;
$USorgu = Sorgu("SELECT * FROM urunler WHERE durum = '1' AND altkategori = '$altkategori->id' ORDER BY id DESC LIMIT $show,$limit"); 
if(!mysql_affected_rows()){?>
<div class="center_column col-xs-12 col-sm-12" id="center_column" style="margin-top:20px;">
					<div class="well margin-top-10"><b>Üzgünüz,</b>
						<br>Mağazamızda seçtiğiniz kriterlere ait ürün bulunamadı.
						<br>
						<br>
						<button type="button" class="btn btn-primary btn-sm margin-top-10" onclick="window.history.back();">Önceki Sayfaya Dön</button>
					</div>
					</div>
<?php }else{
while($USonuc = Sonuc($USorgu)){?>
                          <li class="col-sx-12 col-sm-4" style="height:390px;">
                            <div class="product-container">
                                <div class="left-block">
                                    <a href="Urun/<?php echo $USonuc->seo;?>.html">
                                        <img class="img-responsive" alt="<?php echo $USonuc->adi;?>" src="uploads/urunler/<?php echo $USonuc->resim;?>" />
                                    </a>
                                    <div class="quick-view">
                                            <a title="Karşılaştırmak için ekle" class="compare" href="?kekle=<?php echo $USonuc->id;?>"></a>
                                            <a title="Ürün Detay" class="search" href="Urun/<?php echo $USonuc->seo;?>.html"></a>
                                    </div>
                                    <?php if($USonuc->secenek != ""){?>
										<form action="Urun/<?php echo $USonuc->seo;?>.html" method="post">
										<?php }else{?>
										<form action="?ekle=<?php echo $USonuc->id;?>" method="post">
										<?php }?>
										<input type="hidden" name="adet" value="1" />
										<div class="add-to-cart">
											<button><i style="line-height: inherit;font-size: 20px;" class="fa fa-shopping-cart"></i> Sepete Ekle</button>
										</div>
										<div class="group-price">
											<?php if($USonuc->indirim == "1"){?>
											<?php 
											$fiyat1 	= $USonuc->fiyat - $USonuc->ifiyat; 
											$fiyat2 	= $USonuc->fiyat; 
											$yuzde 		= ($fiyat1 / $fiyat2) * 100;																	
											?>
                                                <span class="product-sale"> %<?php echo floor($yuzde);?> İNDİRİM</span>
											<?php }?>
                                            </div>
									</form>
                                </div>
                                <div class="right-block">
                                    <h5 class="product-name kisalt"><a href="Urun/<?php echo $USonuc->seo;?>.html"><?php echo $USonuc->adi;?></a></h5>
									<h5 class="product-name kisalt"><a href="Urun/<?php echo $USonuc->seo;?>.html">Ürün Kodu: <b><?php echo $USonuc->urun_kodu;?></b></a></h5>
 									<?php if($USonuc->fiyat == "0.00"){?>
									<?php }else{?>
                                    <div class="content_price">
										<?php if($USonuc->indirim == "1"){?>
										<span class="price product-price"> <?php echo number_format($USonuc->ifiyat, 2, ',', '.');?> TL</span>
										<span class="price old-price"> <?php echo number_format($USonuc->fiyat, 2, ',', '.');?> TL</span>
										<?php }elseif($USonuc->indirim == "0"){?>
										<span class="price product-price"> <?php echo number_format($USonuc->fiyat, 2, ',', '.');?> TL</span>
										<?php }?>				
									</div>
									 <?php } ?>
									<?php $YorumVarmi = Sonuc(Sorgu("SELECT * FROM urun_yorum WHERE durum = '1' AND urun_id = '$USonuc->id'"));?>
											<?php if($YorumVarmi > 0){?>
												<?php $YSorgu = Sorgu("SELECT * FROM urun_yorum WHERE durum = '1' AND urun_id = '$USonuc->id' ORDER BY id DESC");
												$ytoplam = 0;
												$ysay = 0;
												while($YSonuc = Sonuc($YSorgu)){?>
												<?php $ytoplam+=$YSonuc->puan;?>
												<?php $ysay++;?>
												<?php }?>
											<?php $yorumorani = ($ytoplam) / ($ysay*5) * 100;?>
											<?php 
											if($yorumorani <= 20){
												echo '
												<div class="product-star">
												<i class="fa fa-star"></i>
												<i class="fa fa-star-o"></i>
												<i class="fa fa-star-o"></i>
												<i class="fa fa-star-o"></i>
												<i class="fa fa-star-o"></i>
												</div>
												';
											}elseif($yorumorani <= 30){
												echo '
												<div class="product-star">
												<i class="fa fa-star"></i>
												<i class="fa fa-star-half-o"></i>
												<i class="fa fa-star-o"></i>
												<i class="fa fa-star-o"></i>
												<i class="fa fa-star-o"></i>
												</div>
												';
											}elseif($yorumorani <= 40){
												echo '
												<div class="product-star">
												<i class="fa fa-star"></i>
												<i class="fa fa-star"></i>
												<i class="fa fa-star-o"></i>
												<i class="fa fa-star-o"></i>
												<i class="fa fa-star-o"></i>
												</div>
												';
											}elseif($yorumorani <= 50){
												echo '
												<div class="product-star">
												<i class="fa fa-star"></i>
												<i class="fa fa-star"></i>
												<i class="fa fa-star-half-o"></i>
												<i class="fa fa-star-o"></i>
												<i class="fa fa-star-o"></i>
												</div>
												';
											}elseif($yorumorani <= 60){
												echo '
												<div class="product-star">
												<i class="fa fa-star"></i>
												<i class="fa fa-star"></i>
												<i class="fa fa-star"></i>
												<i class="fa fa-star-o"></i>
												<i class="fa fa-star-o"></i>
												</div>
												';
											}elseif($yorumorani <= 70){
												echo '
												<div class="product-star">
												<i class="fa fa-star"></i>
												<i class="fa fa-star"></i>
												<i class="fa fa-star"></i>
												<i class="fa fa-star-half-o"></i>
												<i class="fa fa-star-o"></i>
												</div>
												';
											}elseif($yorumorani <= 80){
												echo '
												<div class="product-star">
												<i class="fa fa-star"></i>
												<i class="fa fa-star"></i>
												<i class="fa fa-star"></i>
												<i class="fa fa-star"></i>
												<i class="fa fa-star-o"></i>
												</div>
												';
											}elseif($yorumorani <= 90){
												echo '
												<div class="product-star">
												<i class="fa fa-star"></i>
												<i class="fa fa-star"></i>
												<i class="fa fa-star"></i>
												<i class="fa fa-star"></i>
												<i class="fa fa-star-half-o"></i>
												</div>
												';
											}elseif($yorumorani <= 100){
												echo '
												<div class="product-star">
												<i class="fa fa-star"></i>
												<i class="fa fa-star"></i>
												<i class="fa fa-star"></i>
												<i class="fa fa-star"></i>
												<i class="fa fa-star"></i>
												<i class="fa fa-star"></i>
												</div>
												';
											}
											?>
											
											<?php }else{?>
											<div class="product-star">
												<i class="fa fa-star-o"></i>
												<i class="fa fa-star-o"></i>
												<i class="fa fa-star-o"></i>
												<i class="fa fa-star-o"></i>
												<i class="fa fa-star-o"></i>
											</div>
											<?php }?>
                                    <div class="info-orther">
                                        <p>Ürün Kodu: <?php echo $USonuc->urun_kodu;?></p>
                                        <p class="availability">Stok Durumu: <?php echo($USonuc->stok > 0 ? '<span class="in-stock"> Var </span>' : '<span class="out-stock"> Tükendi</span>');?></p>
                                        <div class="product-desc">
										<?php 
										 $parcala = explode("|",$USonuc->ozellik);
										 $index = end($parcala);
										 foreach($parcala as $ozellik){?>
											 <?php echo $ozellik;?><?php echo($ozellik != $index ? ',' : '');?>
										 <?php }?>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </li>
					<?php }}?>
					<div class="clearfix"></div>
                    </ul>
                    <!-- ./PRODUCT LIST -->
                </div>
				 <div class="sortPagiBar" style="margin-top:50px;">
                   <div class="pagination">
							<ul class="nolist pagination">
                          <?php
						  if($total <= 9){
						}else{
						$showing    = 3;
				
				
					for($i= $page - $showing; $i < $page + $showing + 1; $i++){
				
						if($i > 0 and $i <= $page_count){
							 if($i == $page){?>
								<li class="active current"><span><?php echo $i; ?></span></li>
							<?php }else{?>
								<li><a href="?sayfa=kategori&id=<?php echo $id; ?>&s=<?php echo $i; ?>"><?php echo $i; ?></a></li>
						   <?php }
						}
					}
					}  
				 ?> 
							</ul>
						</div><!-- .pagination -->
                    
                    
                </div>
            </div>
            <!-- ./ Center colunm -->
        </div>
        <!-- ./row-->
    </div>
</div>