<?php include 'inc/header.php';?>
<?php include 'inc/sidebar.php';?>
<?php include 'inc/navbar.php';?>

<!-- Page Content-->
<div class="page-content">
	<div class="container-fluid">
		<!-- Page-Title -->
		<div class="row">
			<div class="col-sm-12">
				<div class="page-title-box">
					<div class="row">
						<div class="col">
							<h4 class="page-title">Müşteri Listesi</h4>
							<ol class="breadcrumb">
								<li class="breadcrumb-item"><a href="index.php">Anasayfa</a></li> 
								<li class="breadcrumb-item active">Müşteri Listesi</li>
							</ol>
						</div><!--end col--> 
					</div><!--end row-->                                                              
				</div><!--end page-title-box-->
			</div><!--end col-->
		</div><!--end row-->
		<!-- end page title end breadcrumb -->

		<div class="row">
			<div class="col-12">
				<div class="card">
					<div class="card-header">
						<h4 class="card-title">Duyuru Listesi</h4>
						<p class="text-muted mb-0">Değerli kullanıcı, bu alan sayesinde sisteme kayıtlı müşterileriniz ile ilgili gerekli bilgileri görebilirsiniz.
						</p>
					</div><!--end card-header-->
					<style type="text/css">
						i { 
							font-size: 16px;
						}
					</style>
					<div class="card-body">  
						<table id="datatable-buttons" class="table table-striped table-bordered dt-responsive nowrap" style="border-collapse: collapse; border-spacing: 0; width: 100%;">
							<thead>
								<tr>
									<th>#</th>
									<th>İsim Soyisim</th>
									<th>Mail Adresi</th>
									<th>Telefon</th>
									<th>Tarih</th> 
									<th>İşlemler</th>
								</tr>
							</thead>


							<tbody>
								<?php
								$ebultensorgu  = $dbh->prepare("SELECT * FROM users ");
								$ebultensorgu-> execute(array());
								$ebultensorgu  = $ebultensorgu->fetchAll(PDO::FETCH_ASSOC);

								foreach ($ebultensorgu as $ebultensonuc) {

									$id = $ebultensonuc['id'];
									$name = $ebultensonuc['name']; 
									$mail = $ebultensonuc['mail'];  
									$phone = $ebultensonuc['phone']; 
									$tarih = $ebultensonuc['tarih'];
									$phpdate = strtotime( $tarih );
									$mysqldate = date( 'd-m-Y ', $phpdate ); 
									?>
									<tr>
										<td style="width: 10px; height: 10px;">#<?=$ebultensonuc['id'];?></td>
										<td><?=$ebultensonuc['name'];?></td>
										<td><?=$ebultensonuc['mail'];?></td>
										<td><?=$ebultensonuc['phone'];?></td>
										<td><?=$mysqldate?></td>

										<td style="width: 150px; ">
											<button type="button" class="btn btn-outline-primary btn-icon-circle-sm" data-toggle="modal" data-target="#exampleModalDanger1<?=$ebultensonuc['id'];?>"><i class="ti-settings"></i></button>

											<button type="button" class="btn btn-outline-danger btn-icon-circle-sm" data-toggle="modal" data-target="#exampleModalDanger<?=$ebultensonuc['id'];?>" ><i class="ti-trash"></i></button> 

										</td> 
									</tr>

									<div class="modal fade" id="exampleModalDanger1<?=$ebultensonuc['id'];?>" tabindex="-1" role="dialog" aria-labelledby="exampleModalDanger1<?=$ebultensonuc['id'];?>" aria-hidden="true">
										<div class="modal-dialog" role="document">
											<div class="modal-content">
												<div class="modal-header bg-primary">
													<h6 class="modal-title m-0 text-white" id="exampleModalDanger1<?=$ebultensonuc['id'];?>">Müşteriye ait adres bilgileri</h6>
													<button type="button" class="close " data-dismiss="modal" aria-label="Close">
														<span aria-hidden="true"><i class="la la-times text-white"></i></span>
													</button>
												</div><!--end modal-header-->
												<div class="modal-body">
													<div class="row"> 
														<div class="col-lg-12 col-xl-12">  

															<?php 

															$adres = $dbh -> prepare("SELECT * FROM users_adress WHERE uye = ?");
															$adres-> execute(array($id));
															$adres = $adres->fetchAll(PDO::FETCH_OBJ);
															foreach ($adres as $adre) {
																$mah = $dbh -> prepare("SELECT * FROM mahalle WHERE mahalle_key = ?");
																$mah-> execute(array($adre->mah));
																$mah = $mah->fetch(PDO::FETCH_OBJ);
																?>
																<div class="card">
																	<div class="card-header bg-primary">
																		<h4 class="card-title text-white">Adres başlığı: <?=$adre->baslik?></h4>
																	</div><!--end card-header-->
																	<div class="card-body">
																		<p class="card-text text-muted"><b>Adres detayı;</b><br><br> <?=$mah->mahalle_title?> / <?=$adre->adress?>  </p>                                        
																	</div><!--end card-body--> 
																</div><!--end card--> 
																<br><hr>  

															<?php } if(count(  $adres)==0){echo "Adres Bulunamadı";} ?>
															<br>

														</div><!--end col-->
													</div><!--end row-->                                                     
												</div><!--end modal-body-->
												<div class="modal-footer">
													<button type="button" class="btn btn-secondary btn-sm" data-dismiss="modal">Kapat</button>

												</div><!--end modal-footer-->
											</div><!--end modal-content-->
										</div><!--end modal-dialog-->
									</div><!--end modal-->

									<!-- silme başlangıçı -->

									<div class="modal fade" id="exampleModalDanger<?=$ebultensonuc['id'];?>" tabindex="-1" role="dialog" aria-labelledby="exampleModalDanger<?=$ebultensonuc['id'];?>" aria-hidden="true">
										<div class="modal-dialog" role="document">
											<div class="modal-content">
												<div class="modal-header bg-danger">
													<h6 class="modal-title m-0 text-white" id="exampleModalDanger<?=$ebultensonuc['id'];?>"><?=$ebultensonuc['title'];?></h6>
													<button type="button" class="close " data-dismiss="modal" aria-label="Close">
														<span aria-hidden="true"><i class="la la-times text-white"></i></span>
													</button>
												</div><!--end modal-header-->
												<div class="modal-body">
													<div class="row"> 
														<div class="col-lg-12">
															<h5>Bu veriyi silmek istiyormusunuz ?</h5>
															<span class="badge bg-soft-secondary">Eklenme Tarihi:</span>
															<small class="text-muted ml-2"> <?=$mysqldate?></small>
															<ul class="mt-3 mb-0">
																<li>Bu veri silinirse geri döndürülemez.</li> 
															</ul>
														</div><!--end col-->
													</div><!--end row-->                                                     
												</div><!--end modal-body-->
												<div class="modal-footer">
													<button type="button" class="btn btn-secondary btn-sm" data-dismiss="modal">Kapat</button>
													<a href="islem.php?id=<?=$ebultensonuc['id']; ?>&islem=musteri-sil"><button type="button" class="btn btn-danger btn-sm">Evet, Sil</button></a>
												</div><!--end modal-footer-->
											</div><!--end modal-content-->
										</div><!--end modal-dialog-->
									</div><!--end modal-->
								<?php } ?>
								<?php 
								if(count($ebultensorgu)==0){
									echo "<tr><td colspan='7'><center><br>Herhangi bir veri bulunamadı <br> <img src='assets/images/sad.png' width='30px;' ></center></td></tr>";
								}

								?>
							</tbody>
						</table>        
					</div>
				</div>
			</div> <!-- end col -->
		</div> <!-- end row -->



	</div><!-- container -->

	<?php include 'inc/footer.php';?>