<?php
	if($_POST){
		if(!isset($_POST['banka_havalesi'])){ $_POST['banka_havalesi'] = 0; }
		if(!isset($_POST['kapida_kredi_karti'])){ $_POST['kapida_kredi_karti'] = 0; }
		if(!isset($_POST['kapida_nakit'])){ $_POST['kapida_nakit'] = 0; }
		if(!isset($_POST['online_odeme'])){ $_POST['online_odeme'] = 0; }


		$islem = $db->prepare("UPDATE ayarlar SET logo = ?, fav = ?, site_ust_link = ?, title = ?, description = ?, email = ?, telefon = ?, adres = ?, whatsapp = ?, facebook = ?, twitter = ?, instagram = ?, youtube = ?, google_dogrulama_kodu = ?, analytics = ?, google_harita = ?, iban_bilgileri = ?, banka_havalesi = ?, kapida_kredi_karti = ?, kapida_nakit = ?, online_odeme = ?, kargo_bedava_limit = ?, kargo_ucreti = ?, kac_lira_uzeri_indirim = ?, kac_lira_uzeri_indirim_tutari = ?, kac_lira_uzeri_indirim_turu = ?, site_ust_img = ?, siparis_email = ?, kredi_karti_secim = ?, kapida_odeme_kargo_ucreti = ?, kdv = ?");
		$islem = $islem->execute(array($_POST['img1'],$_POST['img2'],$_POST['site_ust_link'],$_POST['title'],$_POST['description'],$_POST['email'],$_POST['telefon'],$_POST['adres'],$_POST['whatsapp'],$_POST['facebook'],$_POST['twitter'],$_POST['instagram'],$_POST['youtube'],$_POST['google_dogrulama_kodu'],$_POST['analytics'],$_POST['google_harita'],$_POST['iban_bilgileri'],$_POST['banka_havalesi'],$_POST['kapida_kredi_karti'],$_POST['kapida_nakit'],$_POST['online_odeme'],$_POST['kargo_bedava_limit'],$_POST['kargo_ucreti'],$_POST['kac_lira_uzeri_indirim'],$_POST['kac_lira_uzeri_indirim_tutari'],$_POST['kac_lira_uzeri_indirim_turu'],$_POST['img3'],$_POST['siparis_email'],$_POST['kredi_karti_secim'],$_POST['kapida_odeme_kargo_ucreti'],$_POST['kdv']));
		if($islem){
			echo b();
		}else{
			echo h();
		}
	}
	$duzenle = $db->query("SELECT * FROM ayarlar")->fetch(PDO::FETCH_ASSOC);
?>
<script type="text/javascript">
$(function(){
  <?php
	if($duzenle['logo'] !='' AND is_file('../upload/'.$duzenle['logo'])){
		?>
		  $('.uploaddis[data-id="1"] .yuklendi img').attr('src','../upload/<?php echo $duzenle['logo']; ?>');
		  $('.uploaddis[data-id="1"] input').val('<?php echo $duzenle['logo']; ?>');
		  $('.uploaddis[data-id="1"]').removeClass('aktif');
		  $('.uploaddis[data-id="1"]').addClass('pasif');
		<?php
	  }
	if($duzenle['fav'] !='' AND is_file('../upload/'.$duzenle['fav'])){
    ?>
      $('.uploaddis[data-id="2"] .yuklendi img').attr('src','../upload/<?php echo $duzenle['fav']; ?>');
      $('.uploaddis[data-id="2"] input').val('<?php echo $duzenle['fav']; ?>');
      $('.uploaddis[data-id="2"]').removeClass('aktif');
      $('.uploaddis[data-id="2"]').addClass('pasif');
    <?php
  	}
  	if($duzenle['site_ust_img'] !='' AND is_file('../upload/'.$duzenle['site_ust_img'])){
		?>
		  $('.uploaddis[data-id="3"] .yuklendi img').attr('src','../upload/<?php echo $duzenle['site_ust_img']; ?>');
		  $('.uploaddis[data-id="3"] input').val('<?php echo $duzenle['site_ust_img']; ?>');
		  $('.uploaddis[data-id="3"]').removeClass('aktif');
		  $('.uploaddis[data-id="3"]').addClass('pasif');
		<?php
	  }
  	?>



  	$('[name="kredi_karti_secim"][value="<?php echo $duzenle['kredi_karti_secim']; ?>"]').attr('checked','checked');
  	$('[name="banka_havalesi"][value="<?php echo $duzenle['banka_havalesi']; ?>"]').attr('checked','checked');
  	$('[name="kapida_kredi_karti"][value="<?php echo $duzenle['kapida_kredi_karti']; ?>"]').attr('checked','checked');
  	$('[name="kapida_nakit"][value="<?php echo $duzenle['kapida_nakit']; ?>"]').attr('checked','checked');
  	$('[name="online_odeme"][value="<?php echo $duzenle['online_odeme']; ?>"]').attr('checked','checked');
  	$('[name="kac_lira_uzeri_indirim_turu"] option[value="<?php echo $duzenle['kac_lira_uzeri_indirim_turu']; ?>"]').attr('selected','selected');
});
</script>
<div class="page-header">
	<div class="page-leftheader">
		<h4 class="page-title">Genel Ayarlar</h4>
	</div>
	<div class="page-rightheader ml-auto d-lg-flex d-none">
		<ol class="breadcrumb">
			<li class="breadcrumb-item"><a href="index.php">Anasayfa</a></li>
			<li class="breadcrumb-item active" aria-current="page">Genel Ayarlar</li>
		</ol>
	</div>
</div>
						
<div class="row">
	
	<div class="col-md-12">
		<div class="card">
			<div class="card-body">
				<div class="row">
					<div class="col-md-12">
						
						<form class="form-horizontal" method="post" action="">
								
							<div class="form-group row">
				                <div class="col-3"></div>
				                <div class="col-3">
				                    <div class="uploaddis aktif" data-id="1" style="background: #29327f;padding: 20px">
				        			  <div class="yuklendi">
				        				  <img src="">
				        				  <div class="icon" data-id="1"><span class="fa fa-trash"></span></div>
				        				  <input type="hidden" name="img1" value="" required="">
				        			  </div>
				        			  <div class="upload">
				        				  <span class="metin" style="width: 100%;float: left;">Logo Yükle</span>
				        				  <div class="icon"><span class="fa fa-upload" data-id="1"></span></div>
				        			  </div>
				        			</div>
				                </div>
				                <div class="col-3">
				                	<div class="uploaddis aktif" data-id="2" style="background: #29327f;padding: 20px">
				        			  <div class="yuklendi">
				        				  <img src="">
				        				  <div class="icon" data-id="2"><span class="fa fa-trash"></span></div>
				        				  <input type="hidden" name="img2" value="" required="">
				        			  </div>
				        			  <div class="upload">
				        				  <span class="metin" style="width: 100%;float: left;">Fav Icon Yükle</span>
				        				  <div class="icon"><span class="fa fa-upload" data-id="2"></span></div>
				        			  </div>
				        			</div>
				                </div>
				                <div class="col-3">
				                	<div class="uploaddis aktif" data-id="3" style="background: #29327f;padding: 20px">
				        			  <div class="yuklendi">
				        				  <img src="">
				        				  <div class="icon" data-id="3"><span class="fa fa-trash"></span></div>
				        				  <input type="hidden" name="img3" value="" required="">
				        			  </div>
				        			  <div class="upload">
				        				  <span class="metin" style="width: 100%;float: left;">Site Üst Görseli</span>
				        				  <div class="icon"><span class="fa fa-upload" data-id="3"></span></div>
				        			  </div>
				        			</div>
				                </div>
				            </div>

				            <div id="queue"></div>

							<div class="form-group row">
								<label class="col-md-3 form-label">Site Üst Fotoğraf Linki</label>
								<div class="col-md-9">
									<input type="text" class="form-control" name="site_ust_link" value="<?php echo @$duzenle['site_ust_link']; ?>">
								</div>
							</div>
							<div class="form-group row">
								<label class="col-md-3 form-label">Title</label>
								<div class="col-md-9">
									<input type="text" class="form-control" name="title" value="<?php echo @$duzenle['title']; ?>" required="">
								</div>
							</div>
							<div class="form-group row">
								<label class="col-md-3 form-label">Description</label>
								<div class="col-md-9">
									<textarea class="form-control" rows="3" name="description"><?php echo @$duzenle['description']; ?></textarea>
								</div>
							</div>
							<div class="form-group row">
								<label class="col-md-3 form-label">Email</label>
								<div class="col-md-9">
									<input type="email" class="form-control" name="email" value="<?php echo @$duzenle['email']; ?>">
								</div>
							</div>
							<div class="form-group row">
								<label class="col-md-3 form-label">Siparişler Bildirimi Hangi Emaile Gelsin</label>
								<div class="col-md-9">
									<input type="email" class="form-control" name="siparis_email" value="<?php echo @$duzenle['siparis_email']; ?>">
								</div>
							</div>
							<div class="form-group row">
								<label class="col-md-3 form-label">Telefon</label>
								<div class="col-md-9">
									<input type="text" class="form-control" name="telefon" value="<?php echo @$duzenle['telefon']; ?>">
								</div>
							</div>
							<div class="form-group row">
								<label class="col-md-3 form-label">Adres</label>
								<div class="col-md-9">
									<textarea class="form-control" rows="3" name="adres"><?php echo @$duzenle['adres']; ?></textarea>
								</div>
							</div>
							<div class="form-group row">
								<label class="col-md-3 form-label">Whatsapp Telefon No</label>
								<div class="col-md-9">
									<input type="text" class="form-control" name="whatsapp" value="<?php echo @$duzenle['whatsapp']; ?>">
								</div>
							</div>
							<div class="form-group row">
								<label class="col-md-3 form-label">Facebook Linki</label>
								<div class="col-md-9">
									<input type="text" class="form-control" name="facebook" value="<?php echo @$duzenle['facebook']; ?>">
								</div>
							</div>
							<div class="form-group row">
								<label class="col-md-3 form-label">Twitter Linki</label>
								<div class="col-md-9">
									<input type="text" class="form-control" name="twitter" value="<?php echo @$duzenle['twitter']; ?>">
								</div>
							</div>
							<div class="form-group row">
								<label class="col-md-3 form-label">Instagram Linki</label>
								<div class="col-md-9">
									<input type="text" class="form-control" name="instagram" value="<?php echo @$duzenle['instagram']; ?>">
								</div>
							</div>
							<div class="form-group row">
								<label class="col-md-3 form-label">Youtube Linki</label>
								<div class="col-md-9">
									<input type="text" class="form-control" name="youtube" value="<?php echo @$duzenle['youtube']; ?>">
								</div>
							</div>

							<div class="form-group row">
								<label class="col-md-3 form-label">Google Doğrulama Kodu</label>
								<div class="col-md-9">
									<textarea class="form-control" rows="3" name="google_dogrulama_kodu"><?php echo @$duzenle['google_dogrulama_kodu']; ?></textarea>
								</div>
							</div>

							<div class="form-group row">
								<label class="col-md-3 form-label">Google Analytics Kodu</label>
								<div class="col-md-9">
									<textarea class="form-control" rows="3" name="analytics"><?php echo @$duzenle['analytics']; ?></textarea>
								</div>
							</div>

							<div class="form-group row">
								<label class="col-md-3 form-label">Google Harita Kodu</label>
								<div class="col-md-9">
									<textarea class="form-control" rows="3" name="google_harita"><?php echo @$duzenle['google_harita']; ?></textarea>
								</div>
							</div>

							<div class="form-group row">
								<label class="col-md-3 form-label">Eft/Havale Hesap Bilgileri</label>
								<div class="col-md-9">
									<textarea class="form-control" rows="3" name="iban_bilgileri"><?php echo @$duzenle['iban_bilgileri']; ?></textarea>
								</div>
							</div>

							<div class="form-group row">
								<div class="col-md-3 form-label">Kredi Karı Ödeme Yöntemi</div>
								<div class="col-md-9 custom-controls-stacked">
									<label class="custom-control custom-checkbox">
										<input type="radio" class="custom-control-input" name="kredi_karti_secim" value="1">
										<span class="custom-control-label">Paytr</span>
									</label>
									<label class="custom-control custom-checkbox">
										<input type="radio" class="custom-control-input" name="kredi_karti_secim" value="2">
										<span class="custom-control-label">İyzico</span>
									</label>
									<label class="custom-control custom-checkbox">
										<input type="radio" class="custom-control-input" name="kredi_karti_secim" value="3">
										<span class="custom-control-label">Shopier</span>
									</label>
								</div>
							</div>


							<div class="form-group row">
								<div class="col-md-3 form-label">Ödeme Yöntemleri</div>
								<div class="col-md-9 custom-controls-stacked">
									<label class="custom-control custom-checkbox">
										<input type="checkbox" class="custom-control-input" name="banka_havalesi" value="1">
										<span class="custom-control-label">Banka Havalesi</span>
									</label>
									<label class="custom-control custom-checkbox">
										<input type="checkbox" class="custom-control-input" name="kapida_kredi_karti" value="1">
										<span class="custom-control-label">Kapıda Kredi Kartı</span>
									</label>
									<label class="custom-control custom-checkbox">
										<input type="checkbox" class="custom-control-input" name="kapida_nakit" value="1">
										<span class="custom-control-label">Kapıda Nakit</span>
									</label>
									<label class="custom-control custom-checkbox">
										<input type="checkbox" class="custom-control-input" name="online_odeme" value="1">
										<span class="custom-control-label">Online Ödeme</span>
									</label>
								</div>
							</div>

							<div class="form-group row">
								<label class="col-md-3 form-label">Kargo Kaç Lira ve Üzeri Bedava Olacak</label>
								<div class="col-md-9">
									<input type="text" class="form-control" name="kargo_bedava_limit" value="<?php echo @$duzenle['kargo_bedava_limit']; ?>">
								</div>
							</div>

							<div class="form-group row">
								<label class="col-md-3 form-label">Kargo Ücreti Ne Kadar</label>
								<div class="col-md-9">
									<input type="text" class="form-control" name="kargo_ucreti" value="<?php echo @$duzenle['kargo_ucreti']; ?>">
								</div>
							</div>



							<div class="form-group row">
								<label class="col-md-3 form-label">Kaç Lira Üzeri İndirim Olacak</label>
								<div class="col-md-9">
									<input type="text" class="form-control" name="kac_lira_uzeri_indirim" value="<?php echo @$duzenle['kac_lira_uzeri_indirim']; ?>">
								</div>
							</div>

							<div class="form-group row">
								<label class="col-md-3 form-label">Kaç Lira Üzeri İndirim Tutarı</label>
								<div class="col-md-9">
									<input type="text" class="form-control" name="kac_lira_uzeri_indirim_tutari" value="<?php echo @$duzenle['kac_lira_uzeri_indirim_tutari']; ?>">
								</div>
							</div>

							<div class="form-group row">
								<label class="col-md-3 form-label">Kaç Lira Üzeri İndirim Türü</label>
								<div class="col-md-9">
									<select name="kac_lira_uzeri_indirim_turu" class="form-control">
										<option value="1">%</option>
										<option value="2">-</option>
									</select>
								</div>
							</div>


							<div class="form-group row">
								<label class="col-md-3 form-label">Kapıda Ödeme Kargo Ücreti</label>
								<div class="col-md-9">
									<input type="text" class="form-control" name="kapida_odeme_kargo_ucreti" value="<?php echo @$duzenle['kapida_odeme_kargo_ucreti']; ?>">
								</div>
							</div>
							
							<div class="form-group row">
								<label class="col-md-3 form-label">KDV Yüzdesi</label>
								<div class="col-md-9">
									<input type="text" class="form-control" name="kdv" value="<?php echo @$duzenle['kdv']; ?>">
								</div>
							</div>

							<div class="form-group row">
								<div class="col-md-12"><center><button type="submit" class="btn btn-info">Kaydet</button></center></div>
							</div>

						</form>

					</div>
				</div>
			</div>
		</div>
	</div>
</div>
