353 lines
16 KiB
PHP
353 lines
16 KiB
PHP
<?php
|
|
session_start();
|
|
include '../config/database.php';
|
|
|
|
if (!isset($_SESSION['loggedin']) || $_SESSION['loggedin'] !== true) {
|
|
header('Location: ../auth/login.php');
|
|
exit;
|
|
}
|
|
|
|
// Ambil data profil
|
|
$query = "SELECT * FROM profil LIMIT 1";
|
|
$result = $conn->query($query);
|
|
$profil_masjid = $result->fetch_assoc();
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|
|
|
// Data profil
|
|
$profil_nama = $_POST['profil_nama'] ?? '';
|
|
$profil_alamat = $_POST['profil_alamat'] ?? '';
|
|
$profil_alamatlengkap = $_POST['profil_alamatlengkap'] ?? '';
|
|
$profil_maps = $_POST['profil_maps'] ?? '';
|
|
$profil_desmasjid = $_POST['profil_desmasjid'] ?? '';
|
|
$profil_rekening = $_POST['profil_rekening'] ?? '';
|
|
$profil_dompet = $_POST['profil_dompet'] ?? '';
|
|
$profil_nohp = $_POST['profil_nohp'] ?? '';
|
|
$profil_facebook = $_POST['profil_facebook'] ?? '';
|
|
$profil_instagram = $_POST['profil_instagram'] ?? '';
|
|
|
|
// Menyaring inputan untuk mengambil URL embed Google Maps
|
|
$profil_maps = extractMapUrl($profil_maps);
|
|
|
|
$errors = [];
|
|
|
|
if (empty($profil_nama) || empty($profil_alamat) || empty($profil_alamatlengkap) ||
|
|
empty($profil_maps) || empty($profil_desmasjid) || empty($profil_rekening) ||
|
|
empty($profil_dompet) || empty($profil_nohp)) {
|
|
$errors[] = "Semua kolom wajib diisi!";
|
|
}
|
|
|
|
if (!empty($errors)) {
|
|
echo '<div class="alert alert-danger">'. implode("<br>", $errors) .'</div>';
|
|
} else {
|
|
// Proses upload & simpan data
|
|
}
|
|
|
|
|
|
// Direktori upload
|
|
$dir_cover = "../assets/img/gambarcover/";
|
|
$dir_struktur = "../assets/img/gambarstruktur/";
|
|
$dir_donasi = "../assets/img/gambardonasi/";
|
|
|
|
if (!is_dir($dir_cover)) mkdir($dir_cover, 0777, true);
|
|
if (!is_dir($dir_struktur)) mkdir($dir_struktur, 0777, true);
|
|
if (!is_dir($dir_donasi)) mkdir($dir_donasi, 0777, true);
|
|
|
|
function uploadFile($file, $oldFile, $directory) {
|
|
if (!empty($file['name']) && $file['error'] == 0) {
|
|
$ext = strtolower(pathinfo($file['name'], PATHINFO_EXTENSION));
|
|
$allowed_exts = ['jpg', 'jpeg', 'png', 'webp', 'gif'];
|
|
|
|
if (!in_array($ext, $allowed_exts)) {
|
|
die("Error: Format file tidak diperbolehkan!");
|
|
}
|
|
|
|
$newFileName = uniqid('img_', true) . '.' . $ext;
|
|
$filePath = $directory . $newFileName;
|
|
|
|
if (move_uploaded_file($file['tmp_name'], $filePath)) {
|
|
// Hapus gambar lama jika ada
|
|
if (!empty($oldFile) && file_exists($directory . $oldFile)) {
|
|
unlink($directory . $oldFile);
|
|
}
|
|
return $newFileName;
|
|
} else {
|
|
die("Error: Gagal memindahkan file!");
|
|
}
|
|
}
|
|
return $oldFile;
|
|
}
|
|
|
|
// Upload gambar cover, struktur, donasi
|
|
$profil_gambarcover = uploadFile($_FILES['profil_gambarcover'], $profil_masjid['profil_gambarcover'] ?? '', $dir_cover);
|
|
$profil_gambarstruktur = uploadFile($_FILES['profil_gambarstruktur'], $profil_masjid['profil_gambarstruktur'] ?? '', $dir_struktur);
|
|
$profil_gambardonasi = uploadFile($_FILES['profil_gambardonasi'], $profil_masjid['profil_gambardonasi'] ?? '', $dir_donasi);
|
|
|
|
// **PERBAIKAN QUERY SQL**
|
|
$query = "UPDATE profil SET
|
|
profil_nama = ?,
|
|
profil_alamat = ?,
|
|
profil_alamatlengkap = ?,
|
|
profil_maps = ?,
|
|
profil_desmasjid = ?,
|
|
profil_rekening = ?,
|
|
profil_dompet = ?,
|
|
profil_nohp = ?,
|
|
profil_facebook = ?,
|
|
profil_instagram = ?,
|
|
profil_gambarcover = ?,
|
|
profil_gambarstruktur = ?,
|
|
profil_gambardonasi = ?
|
|
LIMIT 1"; // ✅ Koma dihilangkan setelah kolom terakhir
|
|
|
|
$stmt = $conn->prepare($query);
|
|
|
|
// **PERBAIKAN BIND PARAM**
|
|
$stmt->bind_param("sssssssssssss",
|
|
$profil_nama, $profil_alamat, $profil_alamatlengkap, $profil_maps,
|
|
$profil_desmasjid, $profil_rekening,
|
|
$profil_dompet, $profil_nohp, $profil_facebook, $profil_instagram,
|
|
$profil_gambarcover, $profil_gambarstruktur, $profil_gambardonasi
|
|
);
|
|
|
|
if ($stmt->execute()) {
|
|
$_SESSION['success'] = "Data berhasil diperbarui!";
|
|
header('Location: kelolaprofilmasjid.php');
|
|
exit;
|
|
} else {
|
|
echo "Error saat menyimpan data: " . $stmt->error;
|
|
}
|
|
}
|
|
|
|
function extractMapUrl($input) {
|
|
// Cek jika input adalah <iframe>
|
|
if (strpos($input, '<iframe') !== false) {
|
|
// Menggunakan regex untuk mengekstrak URL dari src attribute
|
|
preg_match('/src="([^"]+)"/', $input, $matches);
|
|
if (!empty($matches[1])) {
|
|
return $matches[1]; // Kembalikan URL dari <iframe>
|
|
}
|
|
}
|
|
|
|
// Jika input bukan <iframe>, asumsikan itu URL biasa
|
|
return $input; // Langsung kembalikan inputan
|
|
}
|
|
|
|
mysqli_close($conn);
|
|
?>
|
|
|
|
|
|
<!DOCTYPE html>
|
|
<html lang="en">
|
|
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<meta content="width=device-width, initial-scale=1.0" name="viewport">
|
|
|
|
<title>Kelola Profil - Masjid-E</title>
|
|
<meta content="" name="description">
|
|
<meta content="" name="keywords">
|
|
|
|
<!-- Favicons -->
|
|
<link href="../assets/img/favicon.png" rel="icon">
|
|
<link href="../assets/img/apple-touch-icon.png" rel="apple-touch-icon">
|
|
|
|
<!-- Google Fonts -->
|
|
<link href="https://fonts.gstatic.com" rel="preconnect">
|
|
<link href="https://fonts.googleapis.com/css?family=Open+Sans:300,300i,400,400i,600,600i,700,700i|Nunito:300,300i,400,400i,600,600i,700,700i|Poppins:300,300i,400,400i,500,500i,600,600i,700,700" rel="stylesheet">
|
|
<!-- Vendor CSS Files -->
|
|
<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/boxicons/css/boxicons.min.css" rel="stylesheet">
|
|
<link href="../assets/vendor/quill/quill.snow.css" rel="stylesheet">
|
|
<link href="../assets/vendor/quill/quill.bubble.css" rel="stylesheet">
|
|
<link href="../assets/vendor/remixicon/remixicon.css" rel="stylesheet">
|
|
<link href="../assets/vendor/simple-datatables/style.css" rel="stylesheet">
|
|
|
|
<!-- Template Main CSS File -->
|
|
<link href="../assets/css/admin.css" rel="stylesheet">
|
|
<!-- Tambahkan di head -->
|
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
|
|
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
|
|
|
|
|
|
<!-- Lightbox2 CSS -->
|
|
<link href="https://cdnjs.cloudflare.com/ajax/libs/lightbox2/2.11.3/css/lightbox.min.css" rel="stylesheet">
|
|
|
|
<!-- Add jQuery -->
|
|
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
|
|
<!-- Include admin.js -->
|
|
<script src="../assets/js/admin.js"></script>
|
|
</head>
|
|
|
|
<body>
|
|
|
|
<?php
|
|
include '../forms/section/header.php';
|
|
include '../forms/section/sidebar.php';
|
|
?>
|
|
|
|
<main id="main" class="main">
|
|
<div class="pagetitle">
|
|
<h1>Kelola Profil Masjid</h1>
|
|
<nav>
|
|
<ol class="breadcrumb">
|
|
<li class="breadcrumb-item"><a href="dashboard.php">Home</a></li>
|
|
<li class="breadcrumb-item active">Kelola Profil Masjid</li>
|
|
</ol>
|
|
</nav>
|
|
</div>
|
|
|
|
<section class="section">
|
|
<div class="row">
|
|
<div class="col-lg-12">
|
|
<div class="card">
|
|
<div class="card-body">
|
|
<h5 class="card-title">Profil Masjid</h5>
|
|
<?php if (isset($_SESSION['success'])): ?>
|
|
<div class="alert alert-success alert-dismissible fade show" role="alert">
|
|
<?= $_SESSION['success']; ?>
|
|
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
|
|
</div>
|
|
<?php unset($_SESSION['success']); ?>
|
|
<?php endif; ?>
|
|
<form method="POST" action="kelolaprofilmasjid.php" enctype="multipart/form-data">
|
|
<div class="mb-3">
|
|
<label for="profil_nama" class="form-label">Nama Masjid</label>
|
|
<input type="text" class="form-control" id="profil_nama" name="profil_nama" value="<?php echo htmlspecialchars($profil_masjid['profil_nama']); ?>" required>
|
|
<div class="form-text">Isikan Nama Masjid, Contoh: Masjid Al-Aqsa.</div>
|
|
</div>
|
|
<div class="mb-3">
|
|
<label for="profil_alamat" class="form-label">Alamat Masjid</label>
|
|
<input type="text" class="form-control" id="profil_alamat" name="profil_alamat" value="<?php echo htmlspecialchars($profil_masjid['profil_alamat']); ?>" required>
|
|
<div class="form-text">Isikan alamat jalan atau lokasi singkat Masjid, Contoh: Tembarak - Kertosono - Nganjuk.</div>
|
|
</div>
|
|
<div class="mb-3">
|
|
<label for="profil_gambarcover" class="form-label">Gambar Cover</label>
|
|
<input type="file" class="form-control" id="profil_gambarcover" name="profil_gambarcover"
|
|
onchange="updateFileName(this, 'profil_gambarcover_label', 'profil_gambarcover_preview')">
|
|
<div class="form-text">Upload gambar tampilan depan Masjid, Format: JPG, PNG, WebP.</div>
|
|
<label id="profil_gambarcover_label" class="form-text">
|
|
<?php echo !empty($profil_masjid['profil_gambarcover']) ? htmlspecialchars($profil_masjid['profil_gambarcover']) : "Pilih gambar"; ?>
|
|
</label>
|
|
</br>
|
|
<img id="profil_gambarcover_preview"
|
|
src="<?php echo !empty($profil_masjid['profil_gambarcover']) ? "../assets/img/gambarcover/" . htmlspecialchars($profil_masjid['profil_gambarcover']) : ''; ?>"
|
|
alt="Gambar Cover" width="100" class="mt-2"
|
|
style="<?php echo empty($profil_masjid['profil_gambarcover']) ? 'display:none;' : ''; ?>">
|
|
</div>
|
|
<div class="mb-3">
|
|
<label for="profil_desmasjid" class="form-label">Deskripsi Profil Masjid</label>
|
|
<textarea class="form-control" id="profil_desmasjid" name="profil_desmasjid" rows="4" required><?php echo htmlspecialchars($profil_masjid['profil_desmasjid']); ?></textarea>
|
|
<div class="form-text">Tuliskan deskripsi singkat mengenai sejarah atau aktivitas Masjid.</div>
|
|
</div>
|
|
<div class="mb-3">
|
|
<label for="profil_gambarstruktur" class="form-label">Gambar Struktur</label>
|
|
<input type="file" class="form-control" id="profil_gambarstruktur" name="profil_gambarstruktur"
|
|
onchange="updateFileName(this, 'profil_gambarstruktur_label', 'profil_gambarstruktur_preview')">
|
|
<div class="form-text">Upload struktur organisasi atau kepengurusan Masjid, Format: JPG, PNG, WebP.</div>
|
|
<label id="profil_gambarstruktur_label" class="form-text">
|
|
<?php echo !empty($profil_masjid['profil_gambarstruktur']) ? htmlspecialchars($profil_masjid['profil_gambarstruktur']) : "Pilih gambar"; ?>
|
|
</label>
|
|
</br>
|
|
<img id="profil_gambarstruktur_preview"
|
|
src="<?php echo !empty($profil_masjid['profil_gambarstruktur']) ? "../assets/img/gambarstruktur/" . htmlspecialchars($profil_masjid['profil_gambarstruktur']) : ''; ?>"
|
|
alt="Gambar Struktur" width="100" class="mt-2"
|
|
style="<?php echo empty($profil_masjid['profil_gambarstruktur']) ? 'display:none;' : ''; ?>">
|
|
</div>
|
|
<div class="mb-3">
|
|
<label for="profil_gambardonasi" class="form-label">Gambar Donasi</label>
|
|
<input type="file" class="form-control" id="profil_gambardonasi" name="profil_gambardonasi"
|
|
onchange="updateFileName(this, 'profil_gambardonasi_label', 'profil_gambardonasi_preview')">
|
|
<div class="form-text">Upload gambar atau banner QRIS informasi donasi Masjid, Format: JPG, PNG, WebP.</div>
|
|
<label id="profil_gambardonasi_label" class="form-text">
|
|
<?php echo !empty($profil_masjid['profil_gambardonasi']) ? htmlspecialchars($profil_masjid['profil_gambardonasi']) : "Pilih gambar"; ?>
|
|
</label>
|
|
</br>
|
|
<img id="profil_gambardonasi_preview"
|
|
src="<?php echo !empty($profil_masjid['profil_gambardonasi']) ? "../assets/img/gambardonasi/" . htmlspecialchars($profil_masjid['profil_gambardonasi']) : ''; ?>"
|
|
alt="Gambar Donasi" width="100" class="mt-2"
|
|
style="<?php echo empty($profil_masjid['profil_gambardonasi']) ? 'display:none;' : ''; ?>">
|
|
</div>
|
|
<div class="mb-3">
|
|
<label for="profil_rekening" class="form-label">Nomor Rekening</label>
|
|
<input type="text" class="form-control" id="profil_rekening" name="profil_rekening" value="<?php echo htmlspecialchars($profil_masjid['profil_rekening']); ?>" required>
|
|
<div class="form-text">Masukkan nomor rekening bank, Contoh: BCA. 123-456-7890 a/n Masjid Al-Aqsa</div>
|
|
</div>
|
|
<div class="mb-3">
|
|
<label for="profil_dompet" class="form-label">Nomor Dompet Digital</label>
|
|
<input type="text" class="form-control" id="profil_dompet" name="profil_dompet" value="<?php echo htmlspecialchars($profil_masjid['profil_dompet']); ?>" required>
|
|
<div class="form-text">Masukkan nomor dompet digital (DANA, OVO, GoPay), Contoh: 081234567890 a/n Masjid Al-Aqsa</div>
|
|
</div>
|
|
<div class="mb-3">
|
|
<label for="profil_alamatlengkap" class="form-label">Alamat Lengkap</label>
|
|
<textarea class="form-control" id="profil_alamatlengkap" name="profil_alamatlengkap" rows="3" required><?php echo htmlspecialchars($profil_masjid['profil_alamatlengkap']); ?></textarea>
|
|
<div class="form-text">Isikan alamat lengkap beserta RT/RW, Kelurahan, Kecamatan, Kota/Kabupaten.</div>
|
|
</div>
|
|
<div class="mb-3">
|
|
<label for="profil_maps" class="form-label">Link Google Maps</label>
|
|
<input type="text" class="form-control" id="profil_maps" name="profil_maps"
|
|
value="<?php echo htmlspecialchars($profil_masjid['profil_maps']); ?>" required>
|
|
<div class="form-text">Tempelkan kode embed iframe lokasi Masjid di Google Maps.</div>
|
|
</div>
|
|
<div class="mb-3">
|
|
<label for="profil_nohp" class="form-label">Nomor WhatsApp</label>
|
|
<input type="text" class="form-control" id="profil_nohp" name="profil_nohp" value="<?php echo htmlspecialchars($profil_masjid['profil_nohp']); ?>" required>
|
|
<div class="form-text">Isikan nomor WhatsApp dengan format (6281234567890.) tanpa tanda +</div>
|
|
</div>
|
|
<div class="mb-3">
|
|
<label for="profil_facebook" class="form-label">Facebook</label>
|
|
<input type="text" class="form-control" id="profil_facebook" name="profil_facebook" value="<?php echo htmlspecialchars($profil_masjid['profil_facebook']); ?>" required>
|
|
<div class="form-text">Masukkan tautan profil atau halaman Facebook resmi Masjid.</div>
|
|
</div>
|
|
<div class="mb-3">
|
|
<label for="profil_instagram" class="form-label">Instagram</label>
|
|
<input type="text" class="form-control" id="profil_instagram" name="profil_instagram" value="<?php echo htmlspecialchars($profil_masjid['profil_instagram']); ?>" required>
|
|
<div class="form-text">Masukkan tautan profil Instagram resmi Masjid.</div>
|
|
</div>
|
|
<button type="submit" class="btn btn-primary">Simpan Perubahan</button>
|
|
<?php if (!empty($errors)): ?>
|
|
<div class="alert alert-danger mt-3">
|
|
<?php foreach ($errors as $error): ?>
|
|
<div><?php echo htmlspecialchars($error); ?></div>
|
|
<?php endforeach; ?>
|
|
</div>
|
|
<?php endif; ?>
|
|
|
|
</form>
|
|
<!-- End Form -->
|
|
|
|
</div>
|
|
</div>
|
|
|
|
</div>
|
|
</div>
|
|
</section>
|
|
|
|
</main><!-- End #main -->
|
|
|
|
<script src="../assets/vendor/bootstrap/js/bootstrap.bundle.min.js"></script>
|
|
<script>
|
|
function updateFileName(input, labelId, imgPreviewId) {
|
|
var label = document.getElementById(labelId);
|
|
var imgPreview = document.getElementById(imgPreviewId);
|
|
|
|
if (input.files && input.files[0]) {
|
|
label.innerText = input.files[0].name; // Menampilkan nama file
|
|
var reader = new FileReader();
|
|
reader.onload = function (e) {
|
|
imgPreview.src = e.target.result; // Menampilkan gambar yang baru dipilih
|
|
imgPreview.style.display = 'block';
|
|
}
|
|
reader.readAsDataURL(input.files[0]);
|
|
}
|
|
}
|
|
</script>
|
|
|
|
|
|
<!-- ======= Footer ======= -->
|
|
<?php include('../forms/section/footer.php'); ?>
|
|
<!-- End Footer -->
|
|
|
|
</body>
|
|
</html>
|