<?php

$query = $db->prepare("SELECT * FROM urun where sef=:sef LIMIT 1");
$urun = $query->execute(array(":sef"=>$_GET['sef']));
$urun = $query->fetch(PDO::FETCH_ASSOC);

if(!$urun){
  echo '<meta http-equiv="refresh" content="0;URL=index.php">';
}

$_title         =  $urun['baslik'];
$_description   =  $urun['description'];

?>
<div class="container-fluid adres_cubugu">
  <div class="row">
  	<div class="container">
  		<div class="row">
  			<div class="col-md-12">
  				<ul>
  					<li><a href="index.php"><i class="fa fa-home"></i> Anasayfa</a> <span><i class="fa fa-arrow-right"></i></span></li>
  					<li><a href="urun/<?php echo $urun['sef']; ?>"><?php echo $urun['baslik']; ?></a></li>
  				</ul>
  			</div>
  		</div>
  	</div>
  </div>
</div>

<section class="bg-dis">
	<div class="container">
		<div class="row mt-15">
			<div class="col-md-6">
				<div class="alan">
					<div id="banner" class="mb-20">
						<?php
						$img = '';
						$query = $db->query("SELECT * FROM urun_img WHERE urun_id = '{$urun['id']}' ", PDO::FETCH_ASSOC);
						if($query->rowCount()){
							foreach($query as $row){
								$img .= $row['img'].'|';
								echo '<div class="item"><img alt="'.$urun['baslik'].'" src="upload/'.$row['img'].'" class="img-responsive img-center"></div>';
							}
						}
						?>
                    </div>
                    <div id="banner_kucuk" class="owl-carousel urun-detay-kucuk-slider hidden-xs">
                       <?php
                       		foreach (explode('|', $img) as $i) {
                       			if(!empty($i)){
                       				echo '<div class="item"><img alt="'.$urun['baslik'].'" src="upload/'.$i.'" class="img-responsive"></div>';
                       			}
                       		}
                       ?>
                    </div>
				</div>
			</div>
			<div class="col-md-6 urun_detay">
				<div class="alan">
					<h1><?php echo $urun['baslik']; ?></h1>
					<?php if(!empty($urun['eski_fiyat'])){ ?>
					<div class="indirim">%<?php echo ceil((($urun['eski_fiyat'] - $urun['fiyat']) / $urun['eski_fiyat']) * 100); ?> <br> İndirim</div>
					<?php } ?>
					<div class="fiyat"><?php echo !empty($urun['eski_fiyat']) ? '<span>'.$urun['eski_fiyat'].' TL</span>': '<span></span>'; ?><span id="asil_fiyat" data-asilfiyat="<?php echo $urun['fiyat']; ?>"><?php echo $urun['fiyat']; ?> TL</span></div>
					<?php
						if($urun['marka_id'] > 0){
							$marka = $db->query("SELECT * FROM marka WHERE id = '{$urun['marka_id']}' LIMIT 1")->fetch(PDO::FETCH_ASSOC);
							echo '<div class="marka"><span>Marka:</span><span><img src="upload/'.$marka['img'].'" alt="'.$marka['baslik'].'" class="img-responsive"></span></div>';
						}
					
						if(!empty($urun['stok_kodu'])){ 
							echo '<div class="stok"><span>Stok Kodu:</span> <span>'.$urun['stok_kodu'].'</span></div>'; 
						}
					?>
					<p style="float: left;width: 100%" class="mt-10"><?php echo $urun['description']; ?></p>
				</div>

				<?php
			      $query = $db->query("SELECT * FROM urun_secenek WHERE urun_id = '{$urun['id']}' ", PDO::FETCH_ASSOC);
			      foreach( $query as $row ){
			    ?>
				<div class="alan">
					<span class="varyant_baslik"><?php echo $row['baslik']; ?></span>
					<ul class="varyant">
						<?php
				          $query1 = $db->query("SELECT * FROM urun_secenek_alt WHERE urun_secenek_id = '{$row['id']}' ", PDO::FETCH_ASSOC);
				          if($query1->rowCount()){
				            foreach( $query1 as $row1 ){
				              echo ' <li><div data-stok="'.$row1['stok'].'" data-fiyat="'.$row1['fiyat'].'" data-secenek-id="'.$row1['id'].'">'.$row1['baslik'].'</div></li>';
				            }
				          }
				          ?>
					</ul>
				</div>
				<?php } ?>

				<?php
			      $renkler = $db->query("SELECT * FROM urun_renk WHERE urun_id = '{$urun['id']}' ", PDO::FETCH_ASSOC);
			      if($renkler->rowCount()){
			    ?>
				<div class="alan">
					<span class="varyant_baslik">Diğer Renk Seçenekleri</span>
					<ul class="varyant_renk">
						<?php
				            foreach($renkler as $r){
				              $rurun = $db->query("SELECT * FROM urun WHERE id = '{$r['renk_urun_id']}' LIMIT 1")->fetch(PDO::FETCH_ASSOC);
				              $img1 = $db->query("SELECT * FROM urun_img WHERE urun_id = '{$r['renk_urun_id']}' LIMIT 0,1")->fetch(PDO::FETCH_ASSOC);
				              echo '<li><a href="urun/'.$rurun['sef'].'"><img src="upload/'.$img1['img'].'" class="img-responsive"></a></li>';
				            }
				        ?>
					</ul>
				</div>
				<?php } ?>

				<div id="sepet_durum"></div>

				<div class="alan">
					<div class="row">
						<div class="col-md-4 mb-10">
							<div class="input-group">
	                            <span class="input-group-btn azalt">
	                                <button type="button" class="btn btn-primary btn-number">
	                                  <span class="glyphicon glyphicon-minus"></span>
	                                </button>
	                            </span>
	                            <input type="text" id="adet" name="adet" class="form-control" value="1">
	                            <span class="input-group-btn arttir">
	                                <button type="button" class="btn btn-primary btn-number">
	                                    <span class="glyphicon glyphicon-plus"></span>
	                                </button>
	                            </span>
	                        </div>
						</div>
						<div class="col-md-4 col-xs-6">
							<button class="btn icon-btn btn-success pull-right" id="ekle" data-id="<?php echo $urun['id']; ?>" style="width: 100%"><i class="fa fa-shopping-basket"></i> Sepete Ekle</button>
						</div>
						<div class="col-md-4 col-xs-6">
							<button class="btn icon-btn btn-warning" id="al" data-id="<?php echo $urun['id']; ?>" style="width: 100%"><i class="fa fa-heart-o"></i> Hemen Al</button>
						</div>
					</div>
				</div>
				<div class="alan">
					<div class="row">
						<div class="col-md-6 mb-10"><a href="https://api.whatsapp.com/send?phone=9<?php echo $cek['whatsapp']; ?>&text=Merhaba, <?php echo $site.'urun/'.$urun['sef']; ?> ürününü sipariş vermek istiyorum." class="btn icon-btn btn-default" style="color: green;border: 1px solid green;width: 100%;"><i class="fa fa-whatsapp"></i> Whatsapp ile Sipariş Ver</a></div>
						<div class="col-md-6 mb-10"><a href="tel:<?php echo $cek['telefon']; ?>" class="btn icon-btn btn-default" style="color: red;border: 1px solid red;width: 100%;"><i class="fa fa-phone"></i> <?php echo $cek['telefon']; ?></a></div>
					</div>
				</div>
			</div>
		</div>
		<div class="row mb-15">
			<div class="col-md-12">

				<div class="tabs">
				  <div class="tab-button-outer">
				    <ul id="tab-button">
				      <li><a href="#tab01">Ürün Hakkında Bilgi</a></li>
				    </ul>
				  </div>
				  <div id="tab01" class="tab-contents">
				    <?php echo $urun['aciklama']; ?>
				  </div>
				</div>

			</div>
		</div>


	  <div class="row mb-20">
	    <div class="col-md-12">
	      <div class="div-baslik text-center"><h4>Önerilen Ürünler</h4></div>
	    </div>
	  </div>
	  <div class="row mb-20">
	    <div class="col-md-12">
	      <div class="owl-carousel urun-slider owl-theme">
	        <?php
	            $query = $db->query("SELECT * FROM urun ORDER BY RAND() LIMIT 7", PDO::FETCH_ASSOC);
	            if($query->rowCount()){
	              foreach($query as $row){
	                $img1 = $db->query("SELECT * FROM urun_img WHERE urun_id = '{$row['id']}' LIMIT 0,1")->fetch(PDO::FETCH_ASSOC);
	                $img2 = $db->query("SELECT * FROM urun_img WHERE urun_id = '{$row['id']}' LIMIT 1,1")->fetch(PDO::FETCH_ASSOC);
	                if(!$img2){
	                  $img2['img'] = $img1['img'];
	                }
	        ?>
	        <div class="item">
	          <a href="urun/<?php echo $row['sef']; ?>" title="<?php echo $row['baslik']; ?>" class="urun">
	            <img src="upload/<?php echo $img1['img']; ?>" alt="<?php echo $row['baslik']; ?>" class="img-responsive img1">
	            <img src="upload/<?php echo $img2['img']; ?>" alt="<?php echo $row['baslik']; ?>" class="img-responsive img2">
	            <b><?php echo $row['baslik']; ?></b>
	            <div>
	                <span><?php echo $row['fiyat']; ?> TL</span>
	                <span><?php echo !empty($row['eski_fiyat']) ? $row['eski_fiyat'].' TL' : ''; ?></span>
	            </div>
	          </a>
	        </div>
	        <?php } } ?>
	      </div>
	    </div>
	  </div>


	</div>
</section>