<?php
include 'connect.php';
session_start();

	$query="Select * from alamat ORDER BY `nama_pengirim` ASC";
	$result= mysqli_query($conn,$query);
	
	$idAlamat=$_GET['idAlamat'];
	
	$query1="Select * from alamat where `alamatID`='".$idAlamat."'";
	$result1= mysqli_query($conn,$query1);
	$row1 = mysqli_fetch_array($result1);

?>


<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="utf-8">
  <meta content="width=device-width, initial-scale=1.0" name="viewport">

  <title>Sistem Pendaftaran Surat</title>
  <meta content="" name="description">
  <meta content="" name="keywords">

  <!-- Favicons -->
  <link href="assets/img/logo_tab.png" rel="icon">

  <!-- Google Fonts -->
  <link href="https://fonts.gstatic.com" rel="preconnect">
  <link href="https://fonts.googleapis.com/css?family=Open+Sans:300,300i,400,400i,600,600i,700,700i|Nunito:300,300i,400,400i,600,600i,700,700i|Poppins:300,300i,400,400i,500,500i,600,600i,700,700i" rel="stylesheet">

  <!-- Vendor CSS Files -->
  <link href="assets/vendor/bootstrap/css/bootstrap.min.css" rel="stylesheet">
  <link href="assets/vendor/bootstrap-icons/bootstrap-icons.css" rel="stylesheet">
  <link href="assets/vendor/boxicons/css/boxicons.min.css" rel="stylesheet">
  <link href="assets/vendor/quill/quill.snow.css" rel="stylesheet">
  <link href="assets/vendor/quill/quill.bubble.css" rel="stylesheet">
  <link href="assets/vendor/remixicon/remixicon.css" rel="stylesheet">
  <link href="assets/vendor/simple-datatables/style.css" rel="stylesheet">

  <!-- Template Main CSS File -->
  <link href="assets/css/style.css" rel="stylesheet">

  <!-- Script logout -->
  <script type="text/javascript" src="internalPage/logoutConfirmation.js"></script>

  <!-- =======================================================
  * Template Name: NiceAdmin - v2.2.0
  * Template URL: https://bootstrapmade.com/nice-admin-bootstrap-admin-html-template/
  * Author: BootstrapMade.com
  * License: https://bootstrapmade.com/license/
  ======================================================== -->
</head>

<body>

  <?php 
  include 'header.php';
  
  ?>

  <main id="main" class="main">

    <div class="pagetitle">
      <h1>Pendaftaran Alamat</h1>
      <nav>
        <ol class="breadcrumb">
          <li class="breadcrumb-item"><a href=""></a></li>          
        </ol>
      </nav>
    </div><!-- End Page Title -->
    <section class="section">
      <div class="row">
               

         <div class="card">
            <div class="card-body">
              <h5 class="card-title">Maklumat Alamat</h5>

              <!-- No Labels Form -->
			  <?php 
			  
			  if($idAlamat=="")
			  {
					
				?>
              <form class="row g-3" action="internalPage/insertAlamat.php" method="post">
                <div class="row mb-3">
                  <label for="inputText" class="col-sm-2 col-form-label">Nama Pengirim:</label>
                  <div class="col-sm-6">
                    <input type="text" class="form-control" name="namaPengirim" id="namaPengirim">
                  </div>
                </div>
                
                <div class="row mb-3">
                  <label for="inputNumber" class="col-sm-2 col-form-label">Alamat:</label>
                  <div class="col-sm-6">
                    <input type="text" class="form-control" name="alamat1" id="alamat1">
					<input type="text" class="form-control" name="alamat2" id="alamat2">
					<input type="text" class="form-control" name="alamat3" id="alamat3">						
                  </div>
                </div>
				<div class="row mb-3">
                  <label for="inputNumber" class="col-sm-2 col-form-label">No. Telefon:</label>
                  <div class="col-sm-6">
                    <input type="text" class="form-control" name="noTel" id="noTel">						
                  </div>
                </div>
				<div class="row mb-3">
				  <label for="inputNumber" class="col-sm-2 col-form-label">Email:</label>
				  <div class="col-sm-6">
					<input type="text" class="form-control" name="email" id="email">						
				  </div>
				</div>					
                <div class="text-center">
                  <button type="submit" class="btn btn-primary">Tambah</button>
                  <button type="reset" class="btn btn-secondary">Reset</button>
                </div>
              </form><!-- End No Labels Form -->
				<?php
			  }
			  else
			  {
					$query1="Select * from alamat where `alamatID`='".$idAlamat."'";
					$result1= mysqli_query($conn,$query1);
					$row1 = mysqli_fetch_array($result1);
					
			 ?>
				  <form class="row g-3" action="internalPage/ubahsuaiAlamat.php?idAlamat=<?php echo $row1['alamatID'];?>" method="post">
                <div class="row mb-3">
                  <label for="inputText" class="col-sm-2 col-form-label">Nama Pengirim:</label>
                  <div class="col-sm-6">
                    <input type="text" class="form-control" name="namaPengirim" id="namaPengirim" value="<?php echo $row1['nama_pengirim'];?>">
                  </div>
                </div>
                
                <div class="row mb-3">
                  <label for="inputNumber" class="col-sm-2 col-form-label">Alamat:</label>
                  <div class="col-sm-6">
                    <input type="text" class="form-control" name="alamat1" id="alamat1" value="<?php echo $row1['alamat1'];?>">
					<input type="text" class="form-control" name="alamat2" id="alamat2" value="<?php echo $row1['alamat2'];?>">
					<input type="text" class="form-control" name="alamat3" id="alamat3" value="<?php echo $row1['alamat3'];?>">						
                  </div>
                </div>
				<div class="row mb-3">
				  <label for="inputNumber" class="col-sm-2 col-form-label">No. Telefon:</label>
				  <div class="col-sm-6">
					<input type="text" class="form-control" name="noTel" id="noTel" value="<?php echo $row1['no_tel'];?>">						
				  </div>
				</div>
				<div class="row mb-3">
				  <label for="inputNumber" class="col-sm-2 col-form-label">Email:</label>
				  <div class="col-sm-6">
					<input type="text" class="form-control" name="email" id="email" value="<?php echo $row1['email'];?>">						
				  </div>
				</div>						
                <div class="text-center">
                  <button type="submit" class="btn btn-primary">Ubahsuai</button>
                  <button type="reset" class="btn btn-secondary">Reset</button>
                </div>
              </form><!-- End No Labels Form -->
			  <?php
			  }
			  ?>
            </div>
          </div>

          

            
          </div>

        </div>
      </div>
    </section>
	
	
	<!-- Section Table -->
	<section class="section">
      <div class="row">
        <div class="col-lg-12">

          <div class="card">
            <div class="card-body">
              <h5 class="card-title">Alamat Pengirim</h5>
              <p>Senarai alamat pengirim </p>

              <!-- Table with stripped rows -->
              <table class="table datatable">
                <thead>
                  <tr>
                    <th scope="col">#</th>
                    <th scope="col">Nama Pengirim</th>
                    <th scope="col">Alamat</th>
					<th scope="col">No. Telefon</th>
					<th scope="col">Email</th>
                    <th scope="col">Ubahsuai alamat</th>
                  </tr>
                </thead>
                <tbody>
				<?php
				
					$no=0;
					
					while ($row = mysqli_fetch_array($result))
					{
						$no++;
				
				?>
                  <tr>
                    <th scope="row"><?php echo $no; ?></th>
                    <td><?php echo $row["nama_pengirim"]; ?></td>
                    <td><?php echo $row["alamat1"]." ".$row["alamat2"]." ".$row["alamat3"]; ?></td>
					<td><?php echo $row["no_tel"]; ?></td>
					<td><?php echo $row["email"]; ?></td>
                    <td><a href="daftarAlamat.php?idAlamat=<?php echo $row["alamatID"]; ?>"><center><i class="bi bi-pencil"></i></center></a></td>
                  </tr>
                <?php
					}
					
				?>	
                </tbody>
              </table>
              <!-- End Table with stripped rows -->

            </div>
          </div>

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

  </main><!-- End #main -->

  <!-- ======= Footer ======= -->
  <footer id="footer" class="footer">
    <!--<div class="copyright">
      &copy; Copyright <strong><span>NiceAdmin</span></strong>. All Rights Reserved
    </div>-->
    <div class="credits">
      <!-- All the links in the footer should remain intact. -->
      <!-- You can delete the links only if you purchased the pro version. -->
      <!-- Licensing information: https://bootstrapmade.com/license/ -->
      <!-- Purchase the pro version with working PHP/AJAX contact form: https://bootstrapmade.com/nice-admin-bootstrap-admin-html-template/ -->
      <!--Designed by <a href="https://bootstrapmade.com/">BootstrapMade</a>-->
    </div>
  </footer><!-- End Footer -->

  <a href="#" class="back-to-top d-flex align-items-center justify-content-center"><i class="bi bi-arrow-up-short"></i></a>

  <!-- Vendor JS Files -->
  <script src="assets/vendor/apexcharts/apexcharts.min.js"></script>
  <script src="assets/vendor/bootstrap/js/bootstrap.bundle.min.js"></script>
  <script src="assets/vendor/chart.js/chart.min.js"></script>
  <script src="assets/vendor/echarts/echarts.min.js"></script>
  <script src="assets/vendor/quill/quill.min.js"></script>
  <script src="assets/vendor/simple-datatables/simple-datatables.js"></script>
  <script src="assets/vendor/tinymce/tinymce.min.js"></script>
  <script src="assets/vendor/php-email-form/validate.js"></script>

  <!-- Template Main JS File -->
  <script src="assets/js/main.js"></script>

</body>

</html>