MINI
C:
/
siak
/
app
/
ktpel
/
Upload File:
files >> C:/siak/app/ktpel/search.php
<?php require_once __DIR__ . '/config/database.php'; /* ========================================================= FUNGSI ========================================================= */ function e($v) { return htmlspecialchars( isset($v) ? $v : '', ENT_QUOTES, 'UTF-8' ); } function tanggal($v) { if (empty($v)) { return ''; } return substr(trim($v), 0, 10); } function jk($v) { if ((string)$v === '1') { return 'LAKI-LAKI'; } if ((string)$v === '2') { return 'PEREMPUAN'; } return $v; } function hubungan($v) { $data = array( '1' => 'KEPALA KELUARGA', '2' => 'SUAMI', '3' => 'ISTRI', '4' => 'ANAK', '5' => 'MENANTU', '6' => 'CUCU', '7' => 'ORANG TUA', '8' => 'MERTUA', '9' => 'FAMILI LAIN', '10' => 'PEMBANTU', '11' => 'LAINNYA' ); $kode = trim((string)$v); return isset($data[$kode]) ? $data[$kode] : $kode; } function status_kawin($v) { $data = array( '1' => 'BELUM KAWIN', '2' => 'KAWIN', '3' => 'CERAI HIDUP', '4' => 'CERAI MATI' ); $kode = trim((string)$v); return isset($data[$kode]) ? $data[$kode] : $kode; } /* ========================================================= INPUT ========================================================= */ $q = isset($_GET['q']) ? trim($_GET['q']) : ''; $error = ''; $hasil = array(); $keluarga = array(); /* ========================================================= KONEKSI ========================================================= */ $conn = null; if ($q !== '') { list($conn, $error_conn) = oracle_connect(); if (!$conn) { $error = $error_conn; } else { /* ================================================= 1. PENCARIAN NIK ================================================= */ if (preg_match('/^[0-9]{16}$/', $q)) { $sql = " SELECT B.NIK, B.NO_KK, B.NAMA_LGKP, B.JENIS_KLMIN, B.TMPT_LHR, B.TGL_LHR, B.STAT_KWN, B.STAT_HBKEL, B.AGAMA, B.GOL_DRH, B.PDDK_AKH, B.JENIS_PKRJN, B.STAT_KTP, B.EKTP_CURRENT_STATUS_CODE FROM BIODATA_WNI B WHERE B.NIK = :q ORDER BY B.NAMA_LGKP "; $param = $q; /* ================================================= 2. PENCARIAN NO KK ================================================= */ } elseif (preg_match('/^[0-9]+$/', $q)) { /* * PENTING: * * NO_KK diambil dari DATA_KELUARGA. * * Setelah KK ditemukan, * semua anggota dicari di BIODATA_WNI. */ $sql = " SELECT K.NO_KK, K.NAMA_KEP, K.ALAMAT, K.NO_RT, K.NO_RW, K.DUSUN, K.KODE_POS, K.TELP, K.NIK_KK, K.NO_PROP, K.NO_KAB, K.NO_KEC, K.NO_KEL FROM DATA_KELUARGA K WHERE TO_CHAR(K.NO_KK) = :q "; $param = $q; /* ================================================= 3. PENCARIAN NAMA ================================================= */ } else { $sql = " SELECT B.NIK, B.NO_KK, B.NAMA_LGKP, B.JENIS_KLMIN, B.TMPT_LHR, B.TGL_LHR, B.STAT_KWN, B.STAT_HBKEL, B.AGAMA, B.GOL_DRH, B.PDDK_AKH, B.JENIS_PKRJN, B.STAT_KTP, B.EKTP_CURRENT_STATUS_CODE FROM BIODATA_WNI B WHERE UPPER(B.NAMA_LGKP) LIKE UPPER(:q) ORDER BY B.NAMA_LGKP "; $param = '%' . $q . '%'; } /* ================================================= EKSEKUSI QUERY ================================================= */ $stmt = oci_parse($conn, $sql); if (!$stmt) { $err = oci_error($conn); $error = isset($err['message']) ? $err['message'] : 'Gagal menyiapkan query Oracle.'; } else { oci_bind_by_name( $stmt, ':q', $param ); if (!oci_execute($stmt)) { $err = oci_error($stmt); $error = isset($err['message']) ? $err['message'] : 'Query Oracle gagal.'; } else { while ($row = oci_fetch_assoc($stmt)) { $hasil[] = $row; } } oci_free_statement($stmt); } /* ================================================= JIKA YANG DICARI ADALAH NO KK ================================================= */ if ( $q !== '' && preg_match('/^[0-9]+$/', $q) && count($hasil) > 0 ) { /* * DATA_KELUARGA menghasilkan informasi KK. */ foreach ($hasil as $kk) { $noKK = $kk['NO_KK']; /* ========================================= AMBIL SEMUA ANGGOTA KK ========================================= */ $sqlAnggota = " SELECT B.NIK, B.NO_KK, B.NAMA_LGKP, B.JENIS_KLMIN, B.TMPT_LHR, B.TGL_LHR, B.STAT_KWN, B.STAT_HBKEL, B.AGAMA, B.GOL_DRH, B.PDDK_AKH, B.JENIS_PKRJN, B.STAT_KTP, B.EKTP_CURRENT_STATUS_CODE FROM BIODATA_WNI B WHERE B.NO_KK = :no_kk ORDER BY CASE WHEN B.STAT_HBKEL = 1 THEN 1 WHEN B.STAT_HBKEL = 2 THEN 2 WHEN B.STAT_HBKEL = 3 THEN 3 WHEN B.STAT_HBKEL = 4 THEN 4 WHEN B.STAT_HBKEL = 5 THEN 5 ELSE 6 END, B.NAMA_LGKP "; $stmtA = oci_parse( $conn, $sqlAnggota ); if ($stmtA) { oci_bind_by_name( $stmtA, ':no_kk', $noKK ); if (oci_execute($stmtA)) { $anggota = array(); while ( $rowA = oci_fetch_assoc($stmtA) ) { $anggota[] = $rowA; } $keluarga[] = array( 'kk' => $kk, 'anggota' => $anggota ); } oci_free_statement($stmtA); } } /* ================================================= JIKA NIK ATAU NAMA ================================================= */ } elseif ( $q !== '' && !preg_match('/^[0-9]+$/', $q) ) { /* * Untuk NIK/NAMA, ambil KK dari hasil BIODATA * kemudian cari DATA_KELUARGA. */ $daftarKK = array(); foreach ($hasil as $row) { if ( isset($row['NO_KK']) && $row['NO_KK'] !== '' ) { $daftarKK[ (string)$row['NO_KK'] ] = true; } } foreach ($daftarKK as $noKK => $dummy) { $sqlKK = " SELECT K.NO_KK, K.NAMA_KEP, K.ALAMAT, K.NO_RT, K.NO_RW, K.DUSUN, K.KODE_POS, K.TELP, K.NIK_KK, K.NO_PROP, K.NO_KAB, K.NO_KEC, K.NO_KEL FROM DATA_KELUARGA K WHERE TO_CHAR(K.NO_KK) = :no_kk "; $stmtKK = oci_parse( $conn, $sqlKK ); if ($stmtKK) { oci_bind_by_name( $stmtKK, ':no_kk', $noKK ); if (oci_execute($stmtKK)) { $kkData = oci_fetch_assoc( $stmtKK ); if ($kkData) { $sqlAnggota = " SELECT B.NIK, B.NO_KK, B.NAMA_LGKP, B.JENIS_KLMIN, B.TMPT_LHR, B.TGL_LHR, B.STAT_KWN, B.STAT_HBKEL, B.AGAMA, B.GOL_DRH, B.PDDK_AKH, B.JENIS_PKRJN, B.STAT_KTP, B.EKTP_CURRENT_STATUS_CODE FROM BIODATA_WNI B WHERE B.NO_KK = :no_kk ORDER BY CASE WHEN B.STAT_HBKEL = 1 THEN 1 WHEN B.STAT_HBKEL = 2 THEN 2 WHEN B.STAT_HBKEL = 3 THEN 3 WHEN B.STAT_HBKEL = 4 THEN 4 ELSE 5 END, B.NAMA_LGKP "; $stmtA = oci_parse( $conn, $sqlAnggota ); if ($stmtA) { oci_bind_by_name( $stmtA, ':no_kk', $noKK ); if ( oci_execute( $stmtA ) ) { $anggota = array(); while ( $rowA = oci_fetch_assoc( $stmtA ) ) { $anggota[] = $rowA; } $keluarga[] = array( 'kk' => $kkData, 'anggota' => $anggota ); } oci_free_statement( $stmtA ); } } } oci_free_statement( $stmtKK ); } } } } } ?> <!DOCTYPE html> <html lang="id"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title> Pencarian Data SIAK </title> <style> * { box-sizing:border-box; } body { margin:0; padding:25px; background:#eef2f7; font-family: Arial, Helvetica, sans-serif; color:#1e293b; } .container { max-width:1400px; margin:auto; } /* ========================================================= CARD ========================================================= */ .card { background:#fff; border-radius:12px; padding:24px; margin-bottom:20px; box-shadow: 0 5px 20px rgba(0,0,0,.10); } /* ========================================================= HEADER ========================================================= */ .title { font-size:24px; font-weight:bold; margin-bottom:7px; } .subtitle { color:#64748b; font-size:14px; margin-bottom:20px; } /* ========================================================= SEARCH ========================================================= */ .search-box { display:flex; gap:10px; } .search-box input { flex:1; height:48px; padding:0 15px; border:1px solid #cbd5e1; border-radius:7px; font-size:16px; outline:none; } .search-box input:focus { border-color:#2563eb; box-shadow: 0 0 0 3px rgba(37,99,235,.10); } .btn { height:48px; padding:0 20px; border:0; border-radius:7px; cursor:pointer; text-decoration:none; display:inline-flex; align-items:center; justify-content:center; font-weight:bold; } .btn-search { background:#2563eb; color:#fff; } .btn-reset { background:#64748b; color:#fff; } /* ========================================================= INFO ========================================================= */ .info { margin-top:15px; padding:12px; background:#f8fafc; border-radius:7px; color:#475569; font-size:14px; } .error { padding:14px; margin-top:15px; background:#fee2e2; color:#991b1b; border-radius:7px; font-weight:bold; } /* ========================================================= RESULT TABLE ========================================================= */ .table-wrap { overflow-x:auto; } table { width:100%; border-collapse:collapse; min-width:900px; } th { background:#1e293b; color:white; padding:12px; text-align:left; white-space:nowrap; } td { padding:11px; border-bottom:1px solid #e2e8f0; white-space:nowrap; } tr:hover td { background:#f8fafc; } .btn-ktp { background:#16a34a; color:white; padding:7px 12px; border-radius:5px; text-decoration:none; font-size:12px; font-weight:bold; } /* ========================================================= KK ========================================================= */ .kk-card { border:1px solid #cbd5e1; border-radius:10px; overflow:hidden; margin-top:20px; } .kk-header { background:#0f172a; color:white; padding:16px 20px; } .kk-number { font-size:20px; font-weight:bold; } .kk-name { margin-top:5px; color:#cbd5e1; font-size:14px; } /* ========================================================= KK INFO ========================================================= */ .kk-info { display:grid; grid-template-columns: repeat(4, 1fr); gap:1px; background:#cbd5e1; border-bottom:1px solid #cbd5e1; } .kk-info-item { background:white; padding:13px; } .kk-label { font-size:11px; color:#64748b; margin-bottom:4px; text-transform:uppercase; } .kk-value { font-weight:bold; font-size:14px; } /* ========================================================= FAMILY TITLE ========================================================= */ .family-title { padding:15px 20px; background:#f8fafc; border-bottom:1px solid #e2e8f0; font-size:17px; font-weight:bold; } /* ========================================================= KEPALA KELUARGA ========================================================= */ .kepala td { background:#eff6ff; font-weight:bold; } /* ========================================================= RELATION ========================================================= */ .relation { font-weight:bold; color:#1d4ed8; } .badge { display:inline-block; padding:4px 7px; background:#e0f2fe; color:#0369a1; border-radius:4px; font-size:11px; font-weight:bold; } /* ========================================================= EMPTY ========================================================= */ .empty { text-align:center; padding:35px; color:#64748b; } /* ========================================================= MOBILE ========================================================= */ @media(max-width:800px) { body { padding:10px; } .card { padding:15px; } .search-box { flex-direction:column; } .btn { width:100%; } .kk-info { grid-template-columns: repeat(2, 1fr); } } </style> </head> <body> <div class="container"> <!-- ===================================================== PENCARIAN ===================================================== --> <div class="card"> <div class="title"> ๐ Pencarian Data SIAK </div> <div class="subtitle"> Cari berdasarkan <strong>NIK</strong>, <strong>Nama</strong>, atau <strong>No. KK</strong>. </div> <div style="margin-bottom:15px;"> <a href="index.php" class="btn btn-home"> โ Kembali ke Halaman Utama </a> </div> <form method="get" action="search.php"> <div class="search-box"> <input type="text" name="q" value="<?=e($q)?>" placeholder="Masukkan NIK, Nama, atau No. KK" autocomplete="off" autofocus> <button type="submit" class="btn btn-search"> ๐ CARI </button> <a href="search.php" class="btn btn-reset"> RESET </a> </div> </form> <?php if ($error): ?> <div class="error"> <?=e($error)?> </div> <?php endif; ?> </div> <!-- ===================================================== HASIL PENCARIAN ===================================================== --> <?php if ($q !== '' && !$error): ?> <div class="card"> <div class="info"> Pencarian : <strong><?=e($q)?></strong> | Ditemukan : <strong><?=count($hasil)?></strong> hasil. </div> <?php if (count($hasil) > 0): ?> <div class="table-wrap"> <table> <thead> <tr> <th>No</th> <th>NIK</th> <th>Nama</th> <th>No. KK</th> <th>Tempat Lahir</th> <th>Tgl Lahir</th> <th>Jenis Kelamin</th> <th>Hubungan</th> <th>Aksi</th> </tr> </thead> <tbody> <?php $no = 1; foreach ($hasil as $row): ?> <tr> <td> <?= $no++ ?> </td> <td> <strong> <?=e($row['NIK'])?> </strong> </td> <td> <?=e($row['NAMA_LGKP'])?> </td> <td> <?=e($row['NO_KK'])?> </td> <td> <?=e($row['TMPT_LHR'])?> </td> <td> <?=e(tanggal($row['TGL_LHR']))?> </td> <td> <?=e(jk($row['JENIS_KLMIN']))?> </td> <td> <span class="relation"> <?=e(hubungan($row['STAT_HBKEL']))?> </span> </td> <td> <a href="preview.php?nik=<?=urlencode($row['NIK'])?>" class="btn-ktp"> DATA </a> </td> </tr> <?php endforeach; ?> </tbody> </table> </div> <?php else: ?> <div class="empty"> Data tidak ditemukan. </div> <?php endif; ?> </div> <?php endif; ?> <!-- ===================================================== DATA KELUARGA ===================================================== --> <?php if (count($keluarga) > 0): ?> <?php foreach ($keluarga as $family): ?> <?php $kk = $family['kk']; $anggota = $family['anggota']; ?> <div class="card"> <div class="kk-card"> <!-- HEADER KK --> <div class="kk-header"> <div class="kk-number"> NO. KK : <?=e($kk['NO_KK'])?> </div> <div class="kk-name"> Kepala Keluarga : <?=e($kk['NAMA_KEP'])?> </div> </div> <!-- INFORMASI KK --> <div class="kk-info"> <div class="kk-info-item"> <div class="kk-label"> Alamat </div> <div class="kk-value"> <?=e($kk['ALAMAT'])?> </div> </div> <div class="kk-info-item"> <div class="kk-label"> RT / RW </div> <div class="kk-value"> <?=e($kk['NO_RT'])?> / <?=e($kk['NO_RW'])?> </div> </div> <div class="kk-info-item"> <div class="kk-label"> Dusun </div> <div class="kk-value"> <?=e($kk['DUSUN'])?> </div> </div> <div class="kk-info-item"> <div class="kk-label"> Kode Pos </div> <div class="kk-value"> <?=e($kk['KODE_POS'])?> </div> </div> <div class="kk-info-item"> <div class="kk-label"> Telepon </div> <div class="kk-value"> <?=e($kk['TELP'])?> </div> </div> <div class="kk-info-item"> <div class="kk-label"> NIK Kepala Keluarga </div> <div class="kk-value"> <?=e($kk['NIK_KK'])?> </div> </div> </div> <!-- DAFTAR PENGIKUT --> <div class="family-title"> ๐จโ๐ฉโ๐งโ๐ฆ Pengikut Dalam Satu KK โ <?=count($anggota)?> Orang </div> <div class="table-wrap"> <table> <thead> <tr> <th>No</th> <th>NIK</th> <th>Nama</th> <th>Hubungan Keluarga</th> <th>Jenis Kelamin</th> <th>Tempat Lahir</th> <th>Tgl Lahir</th> <th>Status Perkawinan</th> <th>Aksi</th> </tr> </thead> <tbody> <?php $nomor = 1; foreach ($anggota as $a): $isKepala = trim($a['STAT_HBKEL']) === '1'; ?> <tr class="<?=( $isKepala ? 'kepala' : '' )?>"> <td> <?= $nomor++ ?> </td> <td> <strong> <?=e($a['NIK'])?> </strong> </td> <td> <?=e($a['NAMA_LGKP'])?> </td> <td> <span class="relation"> <?=e( hubungan( $a['STAT_HBKEL'] ) )?> </span> </td> <td> <?=e( jk( $a['JENIS_KLMIN'] ) )?> </td> <td> <?=e( $a['TMPT_LHR'] )?> </td> <td> <?=e( tanggal( $a['TGL_LHR'] ) )?> </td> <td> <?=e( status_kawin( $a['STAT_KWN'] ) )?> </td> <td> <a href="preview.php?nik=<?=urlencode($a['NIK'])?>" class="btn-ktp"> KTP-el </a> </td> </tr> <?php endforeach; ?> </tbody> </table> </div> </div> </div> <?php endforeach; ?> <?php endif; ?> </div> </body> </html>
Copyright ©2021 || Defacer Indonesia