<?php
// Apabila user belum login
if (empty($_SESSION['namauser']) AND empty($_SESSION['passuser'])){
  echo "<link href=\"../../css/style_login.css\" rel=\"stylesheet\" type=\"text/css\" />
        <div id=\"login\"><h1 class=\"fail\">Untuk mengakses modul, Anda harus login dulu.</h1>
        <p class=\"fail\"><a href=\"../../index.php\">LOGIN</a></p></div>";  
}
// Apabila user sudah login dengan benar, maka terbentuklah session
else{
  $aksi = "modul/mod_hubungi/aksi_hubungi.php";

  // mengatasi variabel yang belum di definisikan (notice undefined index)
  $act = isset($_GET['act']) ? $_GET['act'] : ''; 

  switch($act){
    // Tampil Hubungi Kami
    default:
      echo "<h2>Detail Pendaftaran </h2>
      <br/>
          
          <div class=\"table-responsive\">
          <table class=\"table text-start align-middle table-bordered table-hover mb-0\">
          <thead>
          <tr class=\"text-white\"><th>No</th><th>Nama Pendaftar</th><th>Paket_Umroh</th><th>Tanggal_Pendaftaran</th><th>Aksi</th></tr>
          </thead>
            <tbody>";

      $query  = "SELECT * FROM pendaftaran ORDER BY id_pendaftaran DESC";
      $tampil = mysqli_query($konek, $query);
 
      $no = 1;
      while ($r=mysqli_fetch_array($tampil)){  
        $tanggal=tgl_indo($r['tanggal']);
        echo "<tr><td>$no</td>
                  <td>$r[namaku]</td>
                  <td>$r[paket]</td>
                  
                  
                  <td>$tanggal</a></td>
                  <td><a href=\"?module=hubungi&act=detail&id=$r[id_pendaftaran]\" class=\"btn btn-sm btn-primary\">Detail</a> |
                      <a href=\"$aksi?module=hubungi&act=hapus&id=$r[id_pendaftaran]\" class=\"btn btn-sm btn-primary\">Hapus</a></td>
              </tr>";
        $no++;
      }
      echo "</tbody>
        </table><br> </div>";
    break;

    case "detail":
      $query = "SELECT * FROM pendaftaran WHERE id_pendaftaran='$_GET[id]'";
      $hasil = mysqli_query($konek, $query);
      $r     = mysqli_fetch_array($hasil);
      
      echo "<h2>Data Detail Pendaftaran</h2>
     <div class=\"table-responsive\">
          <table class=\"table text-start align-middle table-bordered table-hover mb-0\">

          <tr class=\"text-white\"><td width=\"120\"><b>Nama_Lengkap_Sesuai_Paspor</b></td><td>:   $r[namaku]</td></tr>
          <tr class=\"text-white\"><td width=\"120\"><b>Bin / Binti</b></td><td>:   $r[bin]</td></tr>
          <tr class=\"text-white\"><td width=\"120\"><b>No.KTP</b></td><td>:   $r[ktp]</td></tr>
          <tr class=\"text-white\"><td width=\"120\"><b>Tanggal Lahir</b></td><td>:   $r[ttl]</td></tr>
          <tr class=\"text-white\"><td width=\"120\"><b>Jenis Kelamin</b></td><td>:   $r[jl]</td></tr>
          <tr class=\"text-white\"><td width=\"120\"><b>Alamat Lengkap</b></td><td>:   $r[alamat]</td></tr>";
          
          $query1 = "SELECT * FROM wilayah WHERE kode='$r[form_prov]'";
          $hasil1 = mysqli_query($konek, $query1);
          $r1     = mysqli_fetch_array($hasil1);
          
           $query2 = "SELECT * FROM wilayah WHERE kode='$r[form_kab]'";
          $hasil2 = mysqli_query($konek, $query2);
          $r2     = mysqli_fetch_array($hasil2);
          
           $query3 = "SELECT * FROM wilayah WHERE kode='$r[form_kec]'";
          $hasil3 = mysqli_query($konek, $query3);
          $r3     = mysqli_fetch_array($hasil3);
          
           $query4 = "SELECT * FROM wilayah WHERE kode='$r[form_des]'";
          $hasil4 = mysqli_query($konek, $query4);
          $r4     = mysqli_fetch_array($hasil4);
          
          
          
          echo"
          <tr class=\"text-white\"><td width=\"120\"><b>Provinsi</b></td><td>:   $r1[nama]</td></tr>
          <tr class=\"text-white\"><td width=\"120\"><b>Kabupaten/Kota</b></td><td>:   $r2[nama]</td></tr>
          <tr class=\"text-white\"><td width=\"120\"><b>Kecamatan</b></td><td>:   $r3[nama]</td></tr>
          <tr class=\"text-white\"><td width=\"120\"><b>Desa/Kelurahan</b></td><td>:   $r4[nama]</td></tr>
          <tr class=\"text-white\"><td width=\"120\"><b>Telphone</b></td><td>:   $r[tlp]</td></tr>
          <tr class=\"text-white\"><td width=\"120\"><b>Pekerjaan</b></td><td>:   $r[pekerjaan]</td></tr>
          <tr class=\"text-white\"><td width=\"120\"><b>Kamar_Yang_dipilih_Hemat</b></td><td>:   $r[kamar]</td></tr>
          <tr class=\"text-white\"><td width=\"120\"><b>Pilihan Paket Umroh</b></td><td>:   $r[paket]</td></tr>
          <tr class=\"text-white\"><td width=\"120\"><b>Tanggal Keberangkatan</b></td><td>:   $r[tanggal]</td></tr>
          <tr class=\"text-white\"><td width=\"120\"><b>Uang Muka</b></td><td>:   $r[uang]</td></tr>
          
          
         
         
         
          </table>
          </div>
           


          ";
    break;
    
    case "kirimemail":
      $query = "SELECT nama_pemilik,email FROM identitas LIMIT 1";
      $hasil = mysqli_query($konek, $query);
      $r     = mysqli_fetch_array($hasil);
      
      $kepada = $_POST['email']; 
      $subjek = $_POST['subjek'];
      $pesan  = $_POST['pesan'];
       
      $dari  = "from: $r[nama_pemilik] <$r[email]> \r\n";
      $dari .= "Content-type: text/html \r\n"; // isi email support html

      mail($email,$subjek,$pesan,$dari);
      
      echo "<h2>Status Email</h2>
            <p>Email telah terkirim.</p>";	 		  
    break;  
  }
}
?>
