fix: 🧑💻 update pegawai dan hapus pegawai
This commit is contained in:
parent
0a5874276a
commit
8c8c53b417
@ -3,6 +3,7 @@ setcookie('username', '', time(), '/');
|
|||||||
setcookie('level_user', '', time(), '/');
|
setcookie('level_user', '', time(), '/');
|
||||||
setcookie('nama_lengkap', '', time(), '/');
|
setcookie('nama_lengkap', '', time(), '/');
|
||||||
setcookie('nis', '', time(), '/');
|
setcookie('nis', '', time(), '/');
|
||||||
|
setcookie('angkatan', '', time(), '/');
|
||||||
|
setcookie('status', '', time(), '/');
|
||||||
echo "<script>alert('Berhasil Logout');window.location.href='login.php'</script>";
|
echo "<script>alert('Berhasil Logout');window.location.href='login.php'</script>";
|
||||||
?>
|
?>
|
@ -1,22 +1,74 @@
|
|||||||
<?php
|
<?php
|
||||||
if(!isset($_COOKIE['username'])) {
|
if(!isset($_COOKIE['username'])) {
|
||||||
header("Location: ../login.php");
|
echo "<script>alert('anda belum login');window.location.href='../login.php'</script>";
|
||||||
exit;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$username = $_COOKIE['username'];
|
$username = $_COOKIE['username'];
|
||||||
$data_update = mysqli_fetch_assoc(mysqli_query($koneksi, "SELECT * FROM pegawai INNER JOIN pengguna USING(Username) WHERE Username = '$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">
|
if(isset($_POST['tombol_ubah'])){
|
||||||
<h3>Konfirmasi Penghapusan</h3>
|
$nama_lengkap = htmlspecialchars($_POST['nama_lengkap']);
|
||||||
<p>Masukkan password Anda untuk menghapus akun:</p>
|
$password = htmlspecialchars($_POST['password']);
|
||||||
<input type="password" name="delete_akun" required>
|
$konfirmasi_pass = htmlspecialchars($_POST['konfirmasi_pass']);
|
||||||
<br>
|
if($password == NULL){
|
||||||
<button type="submit" class="btn btn-danger">Hapus Data Saya</button>
|
if($password !== $konfirmasi_pass){
|
||||||
<a href="halaman_utama.php?page=pegawai" class="btn btn-secondary">Batal</a>
|
echo "<script>alert('password dengan konfirmasi password tidak sama');window.location.href='halaman_utama.php?page=ubah_pegawai&username=".$username."'</script>";
|
||||||
</form>';
|
}else{
|
||||||
} 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>
|
<center>
|
||||||
@ -48,8 +100,8 @@ if (isset($_GET['delete_confirm'])) {
|
|||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td></td>
|
<td></td>
|
||||||
<td><button onclick="window.location.href='halaman_utama.php?page=pegawai&delete_confirm=true';">
|
<td><input type="submit" name="tombol_delete" value="Delete">
|
||||||
Delete</button> | <input type="submit" name="tombol_ubah" value="Update"></td>
|
| <input type="submit" name="tombol_ubah" value="Update"></td>
|
||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
</form><br>
|
</form><br>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user