127 lines
5.2 KiB
PHP
127 lines
5.2 KiB
PHP
<?php
|
|
session_start();
|
|
// Cek apakah pengguna sudah login
|
|
if (!isset($_SESSION['admin_id'])) {
|
|
header('Location: auth/login.php');
|
|
exit;
|
|
}
|
|
|
|
// Include file koneksi ke database
|
|
include '../config/database.php';
|
|
|
|
// Ambil data admin berdasarkan session
|
|
$admin_id = $_SESSION['admin_id'];
|
|
$query = "SELECT admin_username, admin_nama, admin_nohp, admin_email FROM admin WHERE admin_id = ?";
|
|
$stmt = $conn->prepare($query);
|
|
$stmt->bind_param("i", $admin_id);
|
|
$stmt->execute();
|
|
$result = $stmt->get_result();
|
|
$admin_data = $result->fetch_assoc();
|
|
|
|
// Mengupdate data admin jika form di-submit
|
|
if ($_SERVER["REQUEST_METHOD"] == "POST") {
|
|
$username = $_POST['admin_username'];
|
|
$nama = $_POST['admin_nama'];
|
|
$nohp = $_POST['admin_nohp'];
|
|
$email = $_POST['admin_email'];
|
|
|
|
$update_query = "UPDATE admin SET admin_username = ?, admin_nama = ?, admin_nohp = ?, admin_email = ? WHERE admin_id = ?";
|
|
$update_stmt = $conn->prepare($update_query);
|
|
$update_stmt->bind_param("ssssi", $username, $nama, $nohp, $email, $admin_id);
|
|
|
|
if ($update_stmt->execute()) {
|
|
echo "<script>alert('Profil berhasil diperbarui!'); window.location.href = 'dashboard.php';</script>";
|
|
} else {
|
|
echo "<script>alert('Terjadi kesalahan saat memperbarui profil.');</script>";
|
|
}
|
|
}
|
|
|
|
mysqli_close($conn);
|
|
?>
|
|
|
|
<!DOCTYPE html>
|
|
<html lang="en">
|
|
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Ubah Profil Admin - Masjid-E</title>
|
|
<link href="../assets/img/favicon.png" rel="icon">
|
|
<link href="../assets/img/apple-touch-icon.png" rel="apple-touch-icon">
|
|
|
|
<!-- Fonts & CSS -->
|
|
<link href="https://fonts.googleapis.com/css?family=Open+Sans|Nunito|Poppins" rel="stylesheet">
|
|
<link href="../assets/vendor/bootstrap/css/bootstrap.min.css" rel="stylesheet">
|
|
<link href="../assets/vendor/bootstrap-icons/bootstrap-icons.css" rel="stylesheet">
|
|
<link href="../assets/vendor/simple-datatables/style.css" rel="stylesheet">
|
|
<link href="../assets/css/admin.css" rel="stylesheet">
|
|
</head>
|
|
|
|
<body>
|
|
|
|
<?php
|
|
include '../forms/section/header.php';
|
|
include '../forms/section/sidebar.php';
|
|
?>
|
|
|
|
<main id="main" class="main">
|
|
<div class="pagetitle">
|
|
<h1>Ubah Profil Admin</h1>
|
|
<nav>
|
|
<ol class="breadcrumb">
|
|
<li class="breadcrumb-item"><a href="dashboard.php">Home</a></li>
|
|
<li class="breadcrumb-item active">Ubah Profil Admin</li>
|
|
</ol>
|
|
</nav>
|
|
</div><!-- End Page Title -->
|
|
|
|
<section class="section">
|
|
<div class="row">
|
|
<div class="col-lg-8 offset-lg-2">
|
|
<div class="card">
|
|
<div class="card-body">
|
|
<h5 class="card-title">Form Ubah Profil</h5>
|
|
|
|
<!-- Form Ubah Profil Admin -->
|
|
<form action="ubahprofiladmin.php" method="post">
|
|
<div class="mb-3">
|
|
<label for="admin_username" class="form-label">Username</label>
|
|
<input type="text" class="form-control" id="admin_username" name="admin_username" value="<?php echo htmlspecialchars($admin_data['admin_username']); ?>" required>
|
|
</div>
|
|
<div class="mb-3">
|
|
<label for="admin_nama" class="form-label">Nama Lengkap</label>
|
|
<input type="text" class="form-control" id="admin_nama" name="admin_nama" value="<?php echo htmlspecialchars($admin_data['admin_nama']); ?>" required>
|
|
</div>
|
|
<div class="mb-3">
|
|
<label for="admin_nohp" class="form-label">Nomor HP</label>
|
|
<input type="text" class="form-control" id="admin_nohp" name="admin_nohp"
|
|
value="<?php echo htmlspecialchars($admin_data['admin_nohp']); ?>"
|
|
required pattern="^08[0-9]{8,11}$" minlength="10" maxlength="13"
|
|
title="Nomor HP harus diawali dengan 08 dan terdiri dari 10 hingga 13 digit angka.">
|
|
</div>
|
|
<div class="mb-3">
|
|
<label for="admin_email" class="form-label">Email</label>
|
|
<input type="email" class="form-control" id="admin_email" name="admin_email" value="<?php echo htmlspecialchars($admin_data['admin_email']); ?>" required>
|
|
</div>
|
|
<button type="submit" class="btn btn-primary">Simpan Perubahan</button>
|
|
</form><!-- End Form Ubah Profil Admin -->
|
|
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</section>
|
|
|
|
</main><!-- End #main -->
|
|
|
|
<?php include '../forms/section/footer.php'; ?>
|
|
|
|
<script src="../assets/vendor/bootstrap/js/bootstrap.bundle.min.js"></script>
|
|
<!-- Vendor JS Files -->
|
|
<script src="../assets/vendor/bootstrap/js/bootstrap.bundle.min.js"></script>
|
|
<script src="../assets/vendor/simple-datatables/simple-datatables.js"></script>
|
|
<script src="../assets/js/main.js"></script>
|
|
</body>
|
|
|
|
</html>
|