    <main>
<?php if(!isset($_SESSION["user"]) && $uyelikmodul["durum"]=="1"){ header("Location: ".$site); exit; } 
if($puser["ad"]==Null || $puser["soyad"]==Null || $puser["telefon"]==Null || $puser["ulke"]==Null || $puser["sehir"]==Null || $puser["ilce"]==Null || $puser["adres"]==Null) { if($uyelikmodul["durum"]=="1"){ header("Location: ".$site); exit;} } 
?>
<?php if(isset($_SESSION["sepet"])){ $add= count($_SESSION["sepet"]); } else{ header("Location: ".$site); exit;} 
if($add=="0"){
	header("Location: ".$site); exit;
}
	$fiyat="0";
									$total="0";
									$indirimlifiyat="0";
									$kdv="0";
									
									foreach($_SESSION["sepet"] as $deg => $val){
								
										$adet=$val["adet"];
										$product=$val["product"];
	$data_query = $db->prepare("SELECT * FROM urun WHERE id=?");
    $data_query->execute(array($product));
    $data = $data_query->fetch(PDO::FETCH_ASSOC);
	
	
	
	$data["fiyat"]=$data["fiyat"]*$adet;
	$say=0;
	$inputops=array();
	while(isset($val["opsiyon"][$say])){
		$opt=$val["opsiyon"][$say];
		$opt=opsiyon($opt);
		if($opt["id"]!=Null && $opt["urun"]==$product){
			$opfiyat=$opt["fiyat"]*$adet;
			$data["fiyat"]=$data["fiyat"]+$opfiyat;
			$inputops[]=$_POST["opsiyon"][$say];
		}
		$say++;
	}
	
	if($data["kargo_ucret"]!=Null){ 
	$data["fiyat"]=$data["fiyat"]+$data["kargo_ucret"];
	}
	
	if($data["fiyat_indirim"]!=Null){ 
	$data["fiyat_indirim"]=$data["fiyat_indirim"]*$adet;
	$say=0;
	while(isset($val["opsiyon"][$say])){
		$opt=$val["opsiyon"][$say];
		$opt=opsiyon($opt);
		if($opt["id"]!=Null && $opt["urun"]==$product){
			$opfiyat=$opt["fiyat"]*$adet;
			$data["fiyat_indirim"]=$data["fiyat_indirim"]+$opfiyat;
		}
		$say++;
	}
	// $indirimlifiyat=$data["fiyat_indirim"];
	if($data["kargo_ucret"]!=Null){ 
	$data["fiyat_indirim"]=$data["fiyat_indirim"]+$data["kargo_ucret"];
	}
	
	
	}
	
                            if($data["fiyat_indirim"]!=Null){
								$indirimlifiyat=$indirimlifiyat+$data["fiyat_indirim"];
								$total=$total+$data["fiyat_indirim"];
								$yaz=$data["fiyat_indirim"];
							}
							else{
								$total=$total+$data["fiyat"];
								$yaz=$data["fiyat"];
							}
	if(json_decode(settings("kdv"))->durum=="1"){ 
							$kdv=$kdv+$kdv2;
	}
								$fiyat=$fiyat+$data["fiyat"];
							
				
									}
?>
    <!-- Page brea -->
    <!-- .page brea -->
    <div class="section moblhd">
        <div class="container">
        <div class="infoview">
            <div class="viewtop">
                <h3><i class="ri-archive-line"></i> Ürün İçeriği</h3>
                <span>İşleminizin ürün içeriği</span>
            </div>
            <div class="viewproduct">
                <img src="<?=$site;?>upload/urun/<?php echo $data["resim"]; ?>" alt="">
                <span><?php echo $data["ad"];?></span>
            </div>
            </div>
        </div>
    </div>
    <!-- Order Form Start -->
    <section id="order-form" class="sepet-step">
            <form action="" method="post">
                <div class="container">
                    <div class="basket__container clear row">
                        <div class="col-xl-9 col-lg-8 col-md-12 form-left">
						
						
                        <div class="order-steps">
                            <form action="">
                                <div class="order-top">
                                    <span><i class="ri-file-list-2-line"></i> Sipariş Formu</span>
                                    <p>
                                        Lütfen bilgileri eksiksiz ve hatasız doldurunuz.
                                    </p>
                                </div>
                                <div class="steps row">
                                    <div class="form-group col-md-12">
                                        <label class="c-label">İsim ve Soyisim</label>
                                        <input type="text" class="form-control" required name="ad" value="<?php if(@$puser["ad"]!=Null){ echo $puser["ad"]." ".$puser["soyad"]; } ?>" id="OrderFormName" placeholder="İsim ve Soyisim">
                                    </div>
                                    <div class="form-group col-md-12">
                                        <label class="c-label">E-Mail Adresiniz</label>
                                        <input type="email" class="form-control" required name="mail" value="<?=@$puser["mail"];?>" id="ContactFormEmail" placeholder="E-Mail Adresiniz">
                                    </div>
                                    <div class="form-group col-md-12">
                                        <label class="c-label">Telefon Numaranız</label>
                                        <input type="tel" class="form-control" required maxlength="13" value="<?=@$puser["telefon"];?>" name="telefon" id="OrderFormTelephone" placeholder="Telefon Numaranız">
                                    </div>
                                    <div class="col-md-12 form-group">
                                        <label class="c-label" for="disabledSelect">Ödeme Seçeneği</label>
                                        <div class="select_box">
                                            <select class="c-control w-100 selectpicker" required name="odeme_yontem" onchange="yontem(this.value)">
                                            <option value="">Seçiniz</option>
                                                <?php 					 $query = $db->query("select * from pay where durum='1' ORDER BY id desc");
                                                while ($datapay = $query->fetch(PDO::FETCH_OBJ)) {
                                                ?>
                                                <option value="<?php echo $datapay->ad; ?>"><?php echo $datapay->gor_ad; ?>
                                                    (%<?php echo $datapay->komisyon; ?> Komisyon)</option>
                                                <?php } ?>
                                                <option value="Havale">Havale / EFT Ödemesi</option>
                                        </select>
                                            <i class="ri-arrow-down-s-line"></i>
                                        </div>
                                    </div>
                                    <div class="form-group col-md-12 mb-0">
                                        <label class="c-label">Not (opsiyonel)</label>
                                        <textarea class="form-control" name="note" placeholder="Sipariş ile ilgili herhangi bir notunuz varsa buraya yazınız..."></textarea>
                                    </div>
                                </div>
                            </form>
                        </div>
						
						
						<div class="continue-shop-btn">
                            <a href="<?=$site;?>" class="btn focus-reset"><i class="ri-arrow-left-line"></i>Alışverişe Devam Et</a>
                        </div>
						
                      
                        </div>
                        <div class="col-xl-3 col-lg-4 col-md-12 order-info">
                    
                            <div class="order-info-inner">
                                <div class="inner-top">
                                    <span> <i class="ri-window-line"></i> Ücret Bilgisi</span>
                                    <p>İşlemlerinizin ücret detayı</p>
                                </div><?php if(isset($_SESSION["sepet"]) && $add!="0"){  ?>
                                <div class="inner-middle" style="padding-bottom:0px !important;">
                                    <ul>
		
                                        <?php if($indirimlifiyat!="0"){ ?>
                                            <li class="order-price">
                                                <span class="txt"><i class="ri-check-line"></i>Normal Fiyatı:</span>
                                                <span class="order-old-price ms-auto">
                                                    <del><?php echo $fiyat;?><strong>₺</strong></del>
                                                </span>
                                            </li>
                                            <li class="order-price">
                                                <span class="txt"><i class="ri-check-line"></i> İndirimli Fiyatı:</span>
                                                <span class="order-new-price ms-auto">
                                                <?php echo $total;?><strong>₺</strong>
                                                </span>
                                            </li>
                                        <?php } else{ ?>
                                            <li class="order-price">
                                                <span class="txt"><i class="ri-check-line"></i>Normal Fiyatı:</span>
                                                <span class="order-new-price ms-auto">
                                                   <?php echo $fiyat;?><strong>₺</strong>
                                                </span>
                                            </li>
                                        <?php } ?>
					
                                        <?php if(json_decode(settings("kdv"))->durum=="1"){
	$kdv=yuzdeHesaplama($total,json_decode(settings("kdv"))->yuzde); 
$total=$total+$kdv;	?>
                                            <li class="order-price">
                                                <span class="txt"> <i class="ri-check-line"></i> Kdv Tutarı:</span>
                                                <span class="order-new-price ms-auto">
                                                    <?php echo $kdv;?><strong>₺</strong>
                                                </span>
                                            </li>
                                        <?php } ?>
                                        <li class="order-price" id="komisyonli" style="display:none;">
                                            <span class="txt"><i class="ri-check-line"></i>Ödeme Komisyonu:</span>
                                            <span class="order-new-price ms-auto" id="komisyonode">
                                                0<strong>₺</strong>
                                            </span>
                                            </li>
                                        <li class="order-price">
                                            <span class="txt"><i class="ri-check-line"></i> Genel Toplam:</span>
                                            <span class="order-new-price ms-auto" id='komisyongenel'>
<div id="ntutar" style="display:none;"><?php
echo $total; ?></div>
                                            <?php 
                                            echo $total;?><strong>₺</strong>
                                         
                                            </span>
                                        </li>
                                    </ul>	  <?php 
$indirimkod=moduller("indirimkod");
if($indirimkod["durum"]=="1"){ ?>
        <div class="form-group mt-3" style="border-top: 1px solid var(--line);padding-top: 10px;">
                                            <label class="c-label" style="font-size: 15px;color: #111111;font-weight: 500;margin-bottom:10px;">İndirim Kodu (opsiyonel)</label>
                                            <input type="text" class="form-control" value="<?=$_SESSION["sepetindirim"];?>" style="border-radius: 16px;border: 1px solid #dfecf5;" name="indirim" onchange="indirimcheck(this.value)">
                                        </div>
                                        <div id="indirimdurum">
<div id="indx" style="display:none;">0</div>
</div><?php } ?>
                                </div>
                                <div class="inner-bottom" style="opacity:1;">
                                    <button type="submit" name="al" value="2">
                                        Şimdi Satın Al
                                    </button>
                                </div>
								
								<?php } else{ ?>
                                <div class="inner-bottom" style="opacity:0.2;">
                                    <button type="submit" disabled>
                                        Şimdi Satın Al
                                    </button>
                                </div>
								
								<?php } ?>
                            </div>
                        </div>
                    </div>
                </div>
            </form>
    </section>
    <!-- Order Form End -->
    <script>
        var odemefiyat = <?php
echo $total; ?>;
        function yontem(deger) {
                $.post("<?=$site;?>sepet", {
                    'odemetutar': odemefiyat,
                    'odemesaglayici': deger,
                }, function(donenVeri) {
                    if (donenVeri == "0") {
                        document.getElementById("komisyonli").style.display = "none";
                        $("#komisyongenel").html('<div id="ntutar" style="display:none;">'+odemefiyat+'</div>'+odemefiyat + "<strong>₺</strong>");
                        <?php if($indirimkod["durum"]=="1"){ ?>
                        var tutar=$("#ntutar").html();
                        var intutar=$("#indx").html();
var hesap=tutar-intutar;
                        $("#komisyongenel").html('<div id="ntutar" style="display:none;">'+odemefiyat+'</div>'+hesap + "<strong>₺</strong>");
<?php } ?>
                    } else {
                        document.getElementById("komisyonli").style.display = "flex";
                        $("#komisyonode").html(donenVeri + "<strong>₺</strong>");
                        var fiyat = Number(odemefiyat) + Number(donenVeri);
                        fiyat = fiyat.toFixed(2);
                        $("#komisyongenel").html('<div id="ntutar" style="display:none;">'+fiyat+'</div>'+fiyat + "<strong>₺</strong>");
                        <?php if($indirimkod["durum"]=="1"){ ?>
                        var tutar=$("#ntutar").html();
                        var intutar=$("#indx").html();
var hesap=tutar-intutar;
                        $("#komisyongenel").html('<div id="ntutar" style="display:none;">'+fiyat+'</div>'+hesap + "<strong>₺</strong>");
<?php } ?>
                    }
                });
        }
    </script>
<script>
function indirimcheck(val){
	               $.post("<?=$site;?>sepet", {
                    'indirimkodcheck': val
                }, function(donenVeri) {
                    if (donenVeri == "-") {
                        $("#indirimdurum").html('<div id="indx" style="display:none;">0</div><div class="alert alert-danger">Hatalı indirim kodu girildi.</div>');
                        <?php if($indirimkod["durum"]=="1"){ ?>
                        var tutar=$("#ntutar").html();
                        var intutar=$("#indx").html();
var hesap=tutar-intutar;
                        $("#komisyongenel").html('<div id="ntutar" style="display:none;">'+tutar+'</div>'+hesap + "<strong>₺</strong>");
<?php } ?>
                    } else {
                        $("#indirimdurum").html('<div id="indx" style="display:none;">'+donenVeri+'</div><div class="alert alert-success">'+donenVeri+'₺ değerinde indirim kodu girildi.</div>');
        <?php if($indirimkod["durum"]=="1"){ ?>
                        var tutar=$("#ntutar").html();
                        var intutar=$("#indx").html();
var hesap=tutar-intutar;
                        $("#komisyongenel").html('<div id="ntutar" style="display:none;">'+tutar+'</div>'+hesap + "<strong>₺</strong>");
<?php } ?>
                    }
                });
}
</script>
<?php if(isset($_SESSION["sepetindirim"]) && $_SESSION["sepetindirim"]!=Null){ ?>
<script>
window.addEventListener('load', function () {
indirimcheck("<?=$_SESSION["sepetindirim"];?>");
});
</script>
<?php } ?>