<?php
include ("ust.php");
session_start(); ## -> Oturum Başlatıldı
$giris_kontrol = $_SESSION['kullanici_id']; if(empty($giris_kontrol)){echo '<meta http-equiv="refresh" content="0;URL=index.php">';}else{


$dilgoster = g("dilgoster");
if(empty($dilgoster)){}else{$d_k_d = "&dilgoster=$dilgoster";}

## -> Silme İşlemi
$sil = g('sil');
switch($sil){
case "sil":

// İşlem Kayıt Modülü
$islemk_islem = "Bir sipariş kaydı silindi";
include("moduller/islemkayit_modul.php");

$id = g('id'); $id = mysql_real_escape_string($id);
$dosyabul=mysql_query("SELECT * FROM siparisler WHERE id='$id'"); 
$getir2=mysql_fetch_array($dosyabul); 
$resim = $getir2['resim'];
unlink('../'.$resim.'');
$sil = mysql_query("delete from siparisler where id='$id'") or die("Hata Olustu!");
if($sil){echo '<meta http-equiv="refresh" content="0;URL=siparisler.php?durum=basarili'.$d_k_d.'"> ';}
}
## ->  Silme İşlemi

$icerik_getir=mysql_query("SELECT * FROM diller WHERE id='$dilgoster'"); 
$getir=mysql_fetch_array($icerik_getir); 
$dil_g_u_baslik = $getir['baslik'];
?>
				<link rel="stylesheet" href="assets/plugins/html5-editor/bootstrap-wysihtml5.css" />
				<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
			
				<div class="container-fluid">
				
				<?php 
				$yonlendir = g("yonlendir");
				$numara = g("numara");
				if($yonlendir == "whatsapp"){
				echo '<meta http-equiv="refresh" content="0;URL=https://api.whatsapp.com/send?phone=9'.$numara.'"> ';	
				}
		
				?>
				<?php // Bakım modu aktif ise tüm siparislerda bakım uyarısı verir.
				if($geayar_bakim == "evet"){include("moduller/bakim-modul.php");} ?>
		
                <div class="row">
                <div class="col-12">

				<?php $durum = g('durum'); if($durum == "duzenleme-basarili") { ?>
				<div class="alert alert-success"> <i class="fa fa-check"></i> İşlem başarıyla gerçekleştirildi
				<button type="button" class="close" data-dismiss="alert" aria-label="Close"> </button>
				</div>
				<?php } ?>
				
				
                <div class="card">
                <div class="card-body">
				<div class="col-md-12">
				<div class="row">		
				<div class="col-md-8">
				<h4 class="card-title">Sipariş Kayıtları<h4>
                <h6 class="card-subtitle">Bu alanda sipariş kayıtlarınızı görebilirsiniz.</h6>
				</div>
				<div class="col-md-4">
				<?php 
				$islem = g("islem");
				if(empty($islem)){?>
	
				<?php }else{ ?>
				<a href="siparisler.php">
				<button type="button" class="btn waves-effect waves-light btn-danger" style="float:right;">
				<i class="fa fa-times"></i> İptal
				</button>
				</a>
				<?php } ?>
				</div>
				</div>
				</div>
                
				
				
				
				
				<!-- ################### -->
				<!-- Mesaj Okuma Alanı -->
				<!-- ################### -->

				<?php if($islem == "duzenle"){
				
				$id = g('id');
				$odemecevir = g("odemecevir");
				$sipariscevir = g("sipariscevir");
				
				if($odemecevir == "odendi" OR $odemecevir == "bekliyor")
				{ $duzenle = mysql_query("update siparisler set siparis_odeme_durum ='$odemecevir' where id='$id'") or die("Hata Olustu!"); }
				
				if($sipariscevir == "tamamlandi" OR $sipariscevir == "bekliyor")
				{ $duzenle = mysql_query("update siparisler set siparis_durum='$sipariscevir' where id='$id'") or die("Hata Olustu!"); }
				
				if($duzenle){echo '<meta http-equiv="refresh" content="0;URL=siparisler.php?islem=duzenle&id='.$id.'&durum=duzenleme-basarili">';}
				
				?>
				
				<?php 
				// Seçilen içeriğin detaylarını getiriyoruz
				$idal = g("id");
				$icerik_getir=mysql_query("SELECT * FROM siparisler WHERE id='$idal'"); 
				$getir=mysql_fetch_array($icerik_getir); 
				$siparis_adsoyad = $getir['siparis_adsoyad'];
				$siparis_telefon = $getir['siparis_telefon'];
				$siparis_mail = $getir['siparis_mail'];
				$siparis_tarih = $getir['siparis_tarih'];
				$siparis_saat = $getir['siparis_saat'];
				$siparis_kargo = $getir['siparis_kargo'];
				$siparis_not = $getir['siparis_not'];
				$siparis_tutar = $getir['siparis_tutar'];
				$siparis_ip = $getir['siparis_ip'];
				$siparis_odeme_durum = $getir['siparis_odeme_durum'];
				$siparis_durum = $getir['siparis_durum'];
				$siparis_tur = $getir['siparis_tur'];
				$siparis_veri = $getir['siparis_veri'];

				$tl_formati = number_format($siparis_tutar, 2, ',', '.');
				
				$m_kontrol=mysql_query("SELECT * FROM moduller WHERE modul_adi='urunler'"); 
				$getir=mysql_fetch_array($m_kontrol); 
				$modul_v8 = $getir['modul_v8'];
				$modul_v9 = $getir['modul_v9'];
				
				$m_kontrol=mysql_query("SELECT * FROM moduller WHERE modul_adi='fiyattablosu'"); 
				$getir=mysql_fetch_array($m_kontrol); 
				$paket_not = $getir['modul_v7'];
				
				?>
				
				<div id="whatsapp-modal" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" style="display: none;">
				<div class="modal-dialog">
				<div class="modal-content">
				<div class="modal-header">
				<h4 class="modal-title"><i class="fa fa-whatsapp" aria-hidden="true"></i> Müşteriye Whatsapptan Ulaş</h4>
				<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
				</div>
				<div class="modal-body">
				<form action="siparisler.php?yonlendir=whatsapp&numara=<?php echo $siparis_telefon;?>" method="post">
				<label>Müşterinizin Whatsapp Numarası</label>
				<input type="text" class="form-control" value="<?php echo $siparis_telefon;?>">
				<small class="form-control-feedback">Numara formatı örneği : 0507 XXX XX XX</small>
		
				</div>
				<div class="modal-footer">
				<button type="button" class="btn btn-default waves-effect" data-dismiss="modal">Kapat</button>
				<button type="submit" class="btn btn-danger waves-effect waves-light">Whatsappa Git</button>
				</form>
				</div>
				</div>
				</div>
				</div>
				
			
				<div class="col-lg-12">
                <div class="card card-outline-inverse">
                <div class="card-header">
                <h4 class="m-b-0 text-white"><?php echo "$siparis_adsoyad - Sipariş detayları";?></h4>
				
                </div>
				<form action="siparisler.php?islem=yeni&ileri=duzenle&id=<?php echo "$idal$d_k_d";?>" method="post" enctype="multipart/form-data">
				
				<div class="row p-t-20">
				<div class="col-md-12">
				<div class="col-md-12">
				<div class="row">
				
                <div class="col-md-6">
                <div class="form-group">
                <label class="control-label"><font color="#D24444"><i class="fa fa-user"></i> Adı Soyadı :</font></label><br>
                <?php echo $siparis_adsoyad;?>
                </div>
                </div>
				
				<div class="col-md-6">
                <div class="form-group">
                <label class="control-label"><font color="#D24444"><i class="fa fa-phone"></i> Telefon Numarası :</font></label><br>
                <?php echo $siparis_telefon;?>
                </div>
                </div>
				
				<div class="col-md-6">
                <div class="form-group">
                <label class="control-label"><font color="#D24444"><i class="fa fa-envelope"></i> Mail Adresi :</font></label><br>
                <?php echo $siparis_mail;?>
                </div>
                </div>
				
				<div class="col-md-6">
                <div class="form-group">
                <label class="control-label"><font color="#D24444"><i class="fa fa-pencil"></i> Sipariş Tutar :</font></label><br>
                <?php echo $tl_formati;?> TL
                </div>
                </div>
				
				<div class="col-md-6">
                <div class="form-group">
                <label class="control-label"><font color="#D24444"><i class="fa fa-clock-o"></i> Sipariş Tarihi :</font></label><br>
                <?php echo $siparis_tarih;?>
                </div>
                </div>
            
				<div class="col-md-6">
                <div class="form-group">
                <label class="control-label"><font color="#D24444"><i class="fa fa-desktop"></i> İp Adresi :</font></label><br>
                <?php echo $siparis_ip;?>
                </div>
                </div>
				
				<?php if($siparis_tur == "urun"){?>
				<?php if($modul_v8 == "evet"){ ?>
				<div class="col-md-6">
                <div class="form-group">
                <label class="control-label"><font color="#D24444"><i class="fa fa-comments"></i>Kargo Adresi :</font></label><br>
                <?php echo $siparis_kargo;?>
                </div>
                </div>
				<?php } ?>
				
				<?php if($modul_v9 == "evet"){ ?>
				<div class="col-md-6">
                <div class="form-group">
                <label class="control-label"><font color="#D24444"><i class="fa fa-comments"></i> Özel Not :</font></label><br>
                <?php echo $siparis_not;?>
                </div>
                </div>
				<?php }} ?>
				
				<?php if($siparis_tur == "urun"){?>
				<div class="col-md-6">
                <div class="form-group">
                <label class="control-label"><font color="#D24444"><i class="fa fa-shop"></i> Satın Alınan Ürün :</font></label><br>
				<?php 
				$m_kontrol=mysql_query("SELECT * FROM urunler WHERE id='$siparis_veri'"); 
				$getir=mysql_fetch_array($m_kontrol); 
				$urun_baslik = $getir['baslik'];
				$urun_url = $getir['seo_url'];
				echo "$urun_baslik <a href='$geayar_siteadresi/urun/$urun_url' target='_target'>(Ürünü Gör <i class='fa fa-external-link'></i>)</a>";
				?>
                </div>
                </div>
				<?php } ?>
				
				
				<?php if($siparis_tur == "paket"){?>
				
				<?php if($paket_not == "evet"){ ?>
				<div class="col-md-6">
                <div class="form-group">
                <label class="control-label"><font color="#D24444"><i class="fa fa-comments"></i> Özel Not :</font></label><br>
                <?php echo $siparis_not;?>
                </div>
                </div>
				<?php } ?>
				
				<div class="col-md-6">
                <div class="form-group">
                <label class="control-label"><font color="#D24444"><i class="fa fa-shop"></i> Satın Alınan Paket :</font></label><br>
				<?php 
				$m_kontrol=mysql_query("SELECT * FROM fiyattablosu WHERE id='$siparis_veri'"); 
				$getir=mysql_fetch_array($m_kontrol); 
				$urun_baslik = $getir['baslik'];
				$urun_url = $getir['seo_url'];
				$p_kategori = $getir['m15'];
				
				$m_kontrol=mysql_query("SELECT * FROM paket_kategori WHERE id='$p_kategori'"); 
				$getir=mysql_fetch_array($m_kontrol); 
				$kat_baslik = $getir['baslik'];
				$kat_url = $getir['seo_url'];
				
				echo "$kat_baslik > $urun_baslik <a href='$geayar_siteadresi/paketler/$kat_url' target='_target'>(Paketi Gör <i class='fa fa-external-link'></i>)</a>";
				?>
                </div>
                </div>
				<?php } ?>
				
			
				
			
			
				
				
				</div>
				
				<div class="row">
				<div class="col-md-3">
				<?php if($siparis_odeme_durum == "odendi"){?>
				<a class="btn btn-block btn-sm btn-danger text-white" href="siparisler.php?id=<?php echo $id;?>&odemecevir=bekliyor&islem=duzenle"><i class="fa fa-check"></i> Ödemeyi Bekliyor Yap</a>
				<?php } ?>
				<?php if($siparis_odeme_durum == "bekliyor"){?>
				<a class="btn btn-block btn-sm btn-warning text-dark" href="siparisler.php?id=<?php echo $id;?>&odemecevir=odendi&islem=duzenle" ><i class="fa fa-check"></i> Ödemeyi Tamamlandı Yap</a>
				<?php } ?>
				</div>
				<div class="col-md-3">
				<?php if($siparis_durum == "bekliyor"){?>
				<a class="btn btn-block btn-sm btn-primary text-white" href="siparisler.php?id=<?php echo $id;?>&sipariscevir=tamamlandi&islem=duzenle"><i class="fa fa-check"></i> Siparişi Tamamlandı Yap</a></div>
				<?php } ?>
				<?php if($siparis_durum == "tamamlandi"){?>
				<a class="btn btn-block btn-sm  btn-dark text-white" href="siparisler.php?id=<?php echo $id;?>&sipariscevir=bekliyor&islem=duzenle"><i class="fa fa-check"></i> Siparişi Bekliyor Yap</a></div>
				<?php } ?>
				
				<div class="col-md-3">
				<a class="btn btn-block btn-sm btn-success text-white" data-toggle="modal" data-target="#whatsapp-modal" title="Whatsapp" style="background:#149911;border:1px solid #149911;box-shadow: 10px 10px 0px -200px rgba(0,0,0,0.75);">
				<i class="fa fa-whatsapp"></i> Whatsapptan Yaz</a></div>
				
				<div class="col-md-3">
				<a class="btn btn-block btn-sm btn-danger text-white"  href="tel:<?php echo $siparis_telefon;?>" style="background:#006989;border:1px solid #006989;box-shadow: 10px 10px 0px -200px rgba(0,0,0,0.75);">
				<i class="fa fa-phone"></i> Müşteriyi Hızlı Ara</a></div>
				
				</div>
				
	
	
				</div>
				</div>
				</div>
             
				
                </div>
				
                </div>
                </div>
				<?php } ?>
				<!-- ################### -->
				<!-- Mesaj Okuma Alanı -->
				<!-- ################### -->				
				
				
				
				<?php if(empty($islem)){?>
				<div class="table-responsive">
                <table class="table">
                <thead>
                <tr>
                <th>İsim</th>
                <th>Telefon</th>
                <th>Tarih</th>
                <th>Tutar</th>
                <th>Ödeme</th>
                <th>Durum</th>
                <th>İşlemler</th>
                </tr>
                </thead>
                <tbody>
				<?php
				
		
				$siparisler_al = mysql_query("SELECT * FROM siparisler ORDER BY id DESC limit 0,999");
				while($yaz=mysql_fetch_array($siparisler_al)){
				$id = $yaz['id'];
				$siparis_adsoyad = $yaz['siparis_adsoyad'];
				$siparis_telefon = $yaz['siparis_telefon'];
				$siparis_tarih = $yaz['siparis_tarih'];
				$siparis_odeme_durum = $yaz['siparis_odeme_durum'];
				$siparis_durum = $yaz['siparis_durum'];
				$siparis_tutar = $yaz['siparis_tutar'];
				
				if($siparis_odeme_durum == "odendi"){$i_durum_yaz = "<font color='green'><i class='fa fa-check'></i> Ödendi</font>";}
				if($siparis_odeme_durum == "bekliyor"){$i_durum_yaz = "<font color='red'><i class='fa fa-clock-o'></i> Bekliyor</font>";}
				
				if($siparis_durum == "tamamlandi"){$s_durum_yaz = "<font color='green'><i class='fa fa-check'></i> Tamamlandı</font>";}
				if($siparis_durum == "bekliyor"){$s_durum_yaz = "<font color='red'><i class='fa fa-clock-o'></i> Bekliyor</font>";}
				$tl_formati = number_format($siparis_tutar, 2, ',', '.');
				echo "
				<tr>
                <td>$siparis_adsoyad</td>
                <td>$siparis_telefon</td>
                <td>$siparis_tarih</td>
                <td>$tl_formati TL</td>
                <td>$i_durum_yaz</td>
                <td>$s_durum_yaz</td>
                <td>
				<a href='siparisler.php?islem=duzenle&id=$id$d_k_d'> <button class='btn btn-info btn-sm' title='İncele'><i class='fa fa-eye' aria-hidden='true'></i></button></a> 
				"; if($kontrol_kullanici_yetki == "1"){echo "<a href='#' data-toggle='modal' data-target='#sil-modal$id'>";}else{echo "<a href='#' data-toggle='modal' data-target='#uyari-modal'>";}echo"<button class='btn btn-danger btn-sm' title='Sil'><i class='fa fa-trash-o' aria-hidden='true'></i></button>
				</td>
                </tr>
				";
				}?>
                
                <?php
				$sil_m_al = mysql_query("SELECT * FROM siparisler ORDER BY id DESC limit 0,999");
				while($yaz=mysql_fetch_array($sil_m_al)){
				$id = $yaz['id'];
				$baslik = $yaz['baslik'];	
			
				echo '
			
				<div id="sil-modal'.$id.'" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" style="display: none;">
				<div class="modal-dialog">
				<div class="modal-content">
				<div class="modal-header">
				<h4 class="modal-title"><i class="fa fa-times" aria-hidden="true"></i> Sipariş Sil</h4>
				<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
				</div>
				<div class="modal-body">
				<p>Bu sipariş kaydını gerçekten silmek istiyormusunuz ?</p>
				</div>
				<div class="modal-footer">
				<button type="button" class="btn btn-default waves-effect" data-dismiss="modal">Hayır</button>
				<a href="siparisler.php?sil=sil&id='.$id.''.$d_k_d.'"><button type="button" class="btn btn-danger waves-effect waves-light">Evet</button></a>
				</div>
				</div>
				</div>
				</div>
				';
				}?>   
				
                </tbody>
                </table>
                </div>
				<?php } ?>				
								
    
                </div>
                </div>
				</div>
                </div>
				</div>


	
<?php
include ("alt.php");
}
?>