fix: 🧑‍💻 update pegawai dan hapus pegawai

This commit is contained in:
Kadek Arie Wira Kusuma 2025-03-09 18:58:33 +08:00
parent 0a5874276a
commit 8c8c53b417
3 changed files with 68 additions and 15 deletions

BIN
.DS_Store vendored

Binary file not shown.

View File

@ -3,6 +3,7 @@ setcookie('username', '', time(), '/');
setcookie('level_user', '', time(), '/');
setcookie('nama_lengkap', '', time(), '/');
setcookie('nis', '', time(), '/');
setcookie('angkatan', '', time(), '/');
setcookie('status', '', time(), '/');
echo "<script>alert('Berhasil Logout');window.location.href='login.php'</script>";
?>

View File

@ -1,22 +1,74 @@
<?php
if(!isset($_COOKIE['username'])) {
header("Location: ../login.php");
exit;
echo "<script>alert('anda belum login');window.location.href='../login.php'</script>";
}
$username = $_COOKIE['username'];
$data_update = mysqli_fetch_assoc(mysqli_query($koneksi, "SELECT * FROM pegawai INNER JOIN pengguna USING(Username) WHERE Username = '$username'"));
if (isset($_GET['delete_confirm'])) {
echo '<form action="" method="post">
<h3>Konfirmasi Penghapusan</h3>
<p>Masukkan password Anda untuk menghapus akun:</p>
<input type="password" name="delete_akun" required>
<br>
<button type="submit" class="btn btn-danger">Hapus Data Saya</button>
<a href="halaman_utama.php?page=pegawai" class="btn btn-secondary">Batal</a>
</form>';
} else {
if(isset($_POST['tombol_ubah'])){
$nama_lengkap = htmlspecialchars($_POST['nama_lengkap']);
$password = htmlspecialchars($_POST['password']);
$konfirmasi_pass = htmlspecialchars($_POST['konfirmasi_pass']);
if($password == NULL){
if($password !== $konfirmasi_pass){
echo "<script>alert('password dengan konfirmasi password tidak sama');window.location.href='halaman_utama.php?page=ubah_pegawai&username=".$username."'</script>";
}else{
$hasil = mysqli_query($koneksi, "UPDATE pegawai SET Nama_Lengkap='$nama_lengkap' WHERE Username = '$username'");
if(!$hasil){
echo "<script>alert('Gagal update data pegawai');window.location.href='halaman_utama.php?page=ubah_pegawai&username=".$username."'</script>";
}else{
echo "<script>alert('Berhasil update data pegawai');window.location.href='../logout.php';</script>";
}
}
}else{
if($password !== $konfirmasi_pass){
echo "<script>alert('password dengan konfirmasi password tidak sama');window.location.href='halaman_utama.php?page=ubah_pegawai&username=".$username."'</script>";
}else{
$hasil = mysqli_query($koneksi, "UPDATE pegawai SET Nama_Lengkap='$nama_lengkap' WHERE Username = '$username'");
$enkrip = password_hash($password, PASSWORD_DEFAULT);
$hasil_pengguna = mysqli_query($koneksi, "UPDATE pengguna SET Password = '$enkrip' WHERE Username = '$username'");
if(!$hasil){
echo "<script>alert('Gagal update data pegawai');window.location.href='halaman_utama.php?page=ubah_pegawai&username=".$username."'</script>";
}else{
echo "<script>alert('Berhasil update data pegawai');window.location.href='../logout.php';</script>";
}
}
}
}
if (isset($_POST['tombol_delete'])) {
echo '<center>
<form action="" method="post">
<h3>Konfirmasi Penghapusan</h3>
<p>Masukkan password Anda untuk menghapus akun:</p><br>
<input type="password" name="pass" required>
<br><br>
<button type="submit" name="delete_akun" class="btn btn-danger">Hapus Data Saya</button> |
<button onclick=window.location.href="halaman_utama.php?page=ubah_pegawai&username='.$_COOKIE["username"].'" class="btn btn-secondary">Batal</button>
</form>
</center>
';
}elseif(isset($_POST['delete_akun'])){
$pass = $_POST['pass'];
$pass_database = mysqli_fetch_assoc(mysqli_query($koneksi, "SELECT Password FROM pengguna WHERE Username = '$username'"))['Password'];
if(password_verify($pass, $pass_database)){
$delete_pengguna = mysqli_query($koneksi, "DELETE FROM pengguna WHERE Username = '$username'");
$delete_pegawai = mysqli_query($koneksi, "DELETE FROM pegawai WHERE Username = '$username'");
if(!$delete_pengguna){
echo "<script>alert('gagal menghapus data pegawai');window.location.href='halaman_utama.php?page=ubah_pegawai&username=".$username."'</script>";
}else{
echo "<script>alert('berhasil menghapus data');window.location.href='../logout.php';</script>";
}
}else{
echo "<script>alert('Password Salah');window.location.href='halaman_utama.php?page=ubah_pegawai&username=".$username."'</script>";
}
}
else {
?>
<center>
@ -48,8 +100,8 @@ if (isset($_GET['delete_confirm'])) {
</tr>
<tr>
<td></td>
<td><button onclick="window.location.href='halaman_utama.php?page=pegawai&delete_confirm=true';">
Delete</button> | <input type="submit" name="tombol_ubah" value="Update"></td>
<td><input type="submit" name="tombol_delete" value="Delete">
| <input type="submit" name="tombol_ubah" value="Update"></td>
</tr>
</table>
</form><br>