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

<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
  <meta name="description" content="">
  <meta name="author" content="">
  <title>Edit Data</title>

  <!-- Custom fonts -->
  <link href="../vendor/fontawesome-free/css/all.min.css" rel="stylesheet" type="text/css">
  <link href="https://fonts.googleapis.com/css?family=Nunito:200,200i,300,300i,400,400i,600,600i,700,700i,800,800i,900,900i" rel="stylesheet">

  <!-- Custom styles -->
  <link href="../css/sb-admin-2.min.css" rel="stylesheet">
</head>

<body id="page-top">

<div class="card shadow">
  <div class="card-header">
    Edit Data Masyarakat
  </div>
  <div class="card-body">

    <a href="admin.php?url=lihat_masyarakat" class="btn btn-primary btn-icon-split mb-3">
      <span class="icon text-white-50"><i class="fas fa-angle-left"></i></span>
      <span class="text">Kembali</span>
    </a>

    <?php
    require '../koneksi.php';

    // Amankan NIK dari URL
    $nik = isset($_GET['id']) ? mysqli_real_escape_string($conn, $_GET['id']) : '';

    $query = mysqli_query($conn, "SELECT * FROM masyarakat WHERE nik = '$nik'");
    if ($data = mysqli_fetch_assoc($query)) {
    ?>

    <form action="admin.php?url=update_masyarakat" method="post" class="form-horizontal">
      <div class="form-group col-sm-6">
        <label>NIK</label>
        <input type="text" name="nik" value="<?= htmlspecialchars($data['nik']); ?>" class="form-control" readonly>
      </div>
      <div class="form-group col-sm-6">
        <label>Nama</label>
        <input type="text" name="nama" value="<?= htmlspecialchars($data['nama']); ?>" class="form-control" required>
      </div>
      <div class="form-group col-sm-6">
        <label>Username</label>
        <input type="text" name="username" value="<?= htmlspecialchars($data['username']); ?>" class="form-control" required>
      </div>
      <div class="form-group col-sm-6">
        <label>Password</label>
        <input type="text" name="password" value="<?= htmlspecialchars($data['password']); ?>" class="form-control" required>
      </div>
      <div class="form-group col-sm-6">
        <label>Telp</label>
        <input type="text" name="telp" value="<?= htmlspecialchars($data['telp']); ?>" class="form-control" required>
      </div>

      <div class="form-group col-sm-6">
        <input type="submit" value="Edit Data" class="btn btn-success">
        <input type="reset" value="Kosongkan" class="btn btn-warning">
      </div>
    </form>

    <?php } else { ?>
      <div class="alert alert-danger">Data tidak ditemukan.</div>
    <?php } ?>

  </div>
</div>

<!-- Bootstrap core JavaScript-->
<script src="../vendor/jquery/jquery.min.js"></script>
<script src="../vendor/bootstrap/js/bootstrap.bundle.min.js"></script>
<script src="../vendor/jquery-easing/jquery.easing.min.js"></script>
<script src="../js/sb-admin-2.min.js"></script>

</body>
</html>
