Masakan Nusantara
This commit is contained in:
parent
5336cb2bd9
commit
b2397c87b9
146
admin/kategori.php
Normal file
146
admin/kategori.php
Normal file
@ -0,0 +1,146 @@
|
||||
<?php
|
||||
require_once 'header.php';
|
||||
|
||||
$action = $_GET['action'] ?? 'tampil';
|
||||
$id = $_GET['id'] ?? null;
|
||||
|
||||
// Handle Delete
|
||||
if ($action === 'hapus' && $id) {
|
||||
// Check if category is used in menu
|
||||
$check = fetch_one("SELECT COUNT(*) as total FROM menu WHERE kategori_id = ?", [$id]);
|
||||
if ($check['total'] > 0) {
|
||||
header('Location: kategori.php?msg=Kategori tidak bisa dihapus karena masih digunakan di menu&type=danger');
|
||||
exit;
|
||||
}
|
||||
|
||||
$stmt = db()->prepare("DELETE FROM kategori_menu WHERE id = ?");
|
||||
$stmt->execute([$id]);
|
||||
header('Location: kategori.php?msg=Kategori berhasil dihapus');
|
||||
exit;
|
||||
}
|
||||
|
||||
// Handle Form Submit (Add/Edit)
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
$nama_kategori = $_POST['nama_kategori'];
|
||||
$deskripsi = $_POST['deskripsi'];
|
||||
$urutan = $_POST['urutan'] ?? 0;
|
||||
$status = isset($_POST['status']) ? 1 : 0;
|
||||
|
||||
// Simple slug generator
|
||||
$slug = strtolower(trim(preg_replace('/[^A-Za-z0-9-]+/', '-', $nama_kategori)));
|
||||
|
||||
if ($id) {
|
||||
// Edit
|
||||
$stmt = db()->prepare("UPDATE kategori_menu SET nama_kategori=?, slug=?, deskripsi=?, urutan=?, status=? WHERE id=?");
|
||||
$stmt->execute([$nama_kategori, $slug, $deskripsi, $urutan, $status, $id]);
|
||||
$msg = "Kategori berhasil diperbarui";
|
||||
} else {
|
||||
// Add
|
||||
$stmt = db()->prepare("INSERT INTO kategori_menu (nama_kategori, slug, deskripsi, urutan, status) VALUES (?, ?, ?, ?, ?)");
|
||||
$stmt->execute([$nama_kategori, $slug, $deskripsi, $urutan, $status]);
|
||||
$msg = "Kategori berhasil ditambahkan";
|
||||
}
|
||||
header('Location: kategori.php?msg=' . $msg);
|
||||
exit;
|
||||
}
|
||||
|
||||
// Fetch data for form
|
||||
$edit_data = null;
|
||||
if (($action === 'edit' || $action === 'tambah') && $id) {
|
||||
$edit_data = fetch_one("SELECT * FROM kategori_menu WHERE id = ?", [$id]);
|
||||
}
|
||||
|
||||
$kategori_list = fetch_all("SELECT * FROM kategori_menu ORDER BY urutan ASC, nama_kategori ASC");
|
||||
?>
|
||||
|
||||
<div class="d-flex justify-content-between flex-wrap flex-md-nowrap align-items-center pt-3 pb-2 mb-3 border-bottom">
|
||||
<h1 class="h2">Kelola Kategori</h1>
|
||||
<?php if ($action === 'tampil'): ?>
|
||||
<a href="kategori.php?action=tambah" class="btn btn-primary">Tambah Kategori Baru</a>
|
||||
<?php else: ?>
|
||||
<a href="kategori.php" class="btn btn-outline-secondary">Kembali ke Daftar</a>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
|
||||
<?php if (isset($_GET['msg'])): ?>
|
||||
<div class="alert alert-<?php echo $_GET['type'] ?? 'success'; ?>"><?php echo htmlspecialchars($_GET['msg']); ?></div>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if ($action === 'tambah' || $action === 'edit'): ?>
|
||||
<div class="card shadow-sm">
|
||||
<div class="card-body">
|
||||
<h5 class="card-title mb-4"><?php echo $id ? 'Edit Kategori' : 'Tambah Kategori Baru'; ?></h5>
|
||||
<form method="POST">
|
||||
<div class="row">
|
||||
<div class="col-md-6 mb-3">
|
||||
<label class="form-label">Nama Kategori</label>
|
||||
<input type="text" name="nama_kategori" class="form-control" value="<?php echo $edit_data['nama_kategori'] ?? ''; ?>" required>
|
||||
</div>
|
||||
<div class="col-md-3 mb-3">
|
||||
<label class="form-label">Urutan</label>
|
||||
<input type="number" name="urutan" class="form-control" value="<?php echo $edit_data['urutan'] ?? '0'; ?>">
|
||||
</div>
|
||||
<div class="col-md-3 mb-3 d-flex align-items-end">
|
||||
<div class="form-check mb-2">
|
||||
<input class="form-check-input" type="checkbox" name="status" id="status" <?php echo (!isset($edit_data['status']) || $edit_data['status']) ? 'checked' : ''; ?>>
|
||||
<label class="form-check-label" for="status">
|
||||
Aktif
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-12 mb-3">
|
||||
<label class="form-label">Deskripsi</label>
|
||||
<textarea name="deskripsi" class="form-control" rows="3"><?php echo $edit_data['deskripsi'] ?? ''; ?></textarea>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<button type="submit" class="btn btn-primary px-5">Simpan Kategori</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
<?php else: ?>
|
||||
<div class="card shadow-sm">
|
||||
<div class="card-body p-0">
|
||||
<div class="table-responsive">
|
||||
<table class="table table-hover mb-0">
|
||||
<thead class="table-light">
|
||||
<tr>
|
||||
<th>Urutan</th>
|
||||
<th>Nama Kategori</th>
|
||||
<th>Slug</th>
|
||||
<th>Status</th>
|
||||
<th>Aksi</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php foreach ($kategori_list as $row): ?>
|
||||
<tr>
|
||||
<td><?php echo $row['urutan']; ?></td>
|
||||
<td><?php echo htmlspecialchars($row['nama_kategori']); ?></td>
|
||||
<td><code><?php echo htmlspecialchars($row['slug']); ?></code></td>
|
||||
<td>
|
||||
<?php if ($row['status']): ?>
|
||||
<span class="badge bg-success">Aktif</span>
|
||||
<?php else: ?>
|
||||
<span class="badge bg-secondary">Non-aktif</span>
|
||||
<?php endif; ?>
|
||||
</td>
|
||||
<td>
|
||||
<a href="kategori.php?action=edit&id=<?php echo $row['id']; ?>" class="btn btn-sm btn-outline-info">Edit</a>
|
||||
<a href="kategori.php?action=hapus&id=<?php echo $row['id']; ?>" class="btn btn-sm btn-outline-danger" onclick="return confirm('Hapus kategori ini?')">Hapus</a>
|
||||
</td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
<?php if (empty($kategori_list)): ?>
|
||||
<tr>
|
||||
<td colspan="5" class="text-center py-4 text-muted">Belum ada kategori.</td>
|
||||
</tr>
|
||||
<?php endif; ?>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php require_once 'footer.php'; ?>
|
||||
199
admin/pesanan.php
Normal file
199
admin/pesanan.php
Normal file
@ -0,0 +1,199 @@
|
||||
<?php
|
||||
require_once 'header.php';
|
||||
|
||||
$action = $_GET['action'] ?? 'tampil';
|
||||
$id = $_GET['id'] ?? null;
|
||||
|
||||
// Handle Status Change
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['update_status'])) {
|
||||
$new_status = $_POST['status'];
|
||||
$stmt = db()->prepare("UPDATE pesanan SET status = ? WHERE id = ?");
|
||||
$stmt->execute([$new_status, $id]);
|
||||
header("Location: pesanan.php?action=detail&id=$id&msg=Status pesanan berhasil diperbarui");
|
||||
exit;
|
||||
}
|
||||
|
||||
// Handle Delete
|
||||
if ($action === 'hapus' && $id) {
|
||||
// Delete items first
|
||||
$stmt = db()->prepare("DELETE FROM pesanan_item WHERE pesanan_id = ?");
|
||||
$stmt->execute([$id]);
|
||||
|
||||
// Delete order
|
||||
$stmt = db()->prepare("DELETE FROM pesanan WHERE id = ?");
|
||||
$stmt->execute([$id]);
|
||||
|
||||
header('Location: pesanan.php?msg=Pesanan berhasil dihapus');
|
||||
exit;
|
||||
}
|
||||
|
||||
// Fetch Data
|
||||
if ($action === 'detail' && $id) {
|
||||
$order = fetch_one("SELECT * FROM pesanan WHERE id = ?", [$id]);
|
||||
$items = fetch_all("SELECT pi.*, m.nama_menu FROM pesanan_item pi JOIN menu m ON pi.menu_id = m.id WHERE pi.pesanan_id = ?", [$id]);
|
||||
}
|
||||
|
||||
$pesanan_list = fetch_all("SELECT * FROM pesanan ORDER BY id DESC");
|
||||
?>
|
||||
|
||||
<div class="d-flex justify-content-between flex-wrap flex-md-nowrap align-items-center pt-3 pb-2 mb-3 border-bottom">
|
||||
<h1 class="h2">Kelola Pesanan</h1>
|
||||
</div>
|
||||
|
||||
<?php if (isset($_GET['msg'])): ?>
|
||||
<div class="alert alert-success"><?php echo htmlspecialchars($_GET['msg']); ?></div>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if ($action === 'detail' && $order): ?>
|
||||
<div class="row">
|
||||
<div class="col-md-8">
|
||||
<div class="card shadow-sm mb-4">
|
||||
<div class="card-header bg-white">
|
||||
<h5 class="mb-0">Detail Pesanan #<?php echo $order['id']; ?></h5>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<table class="table table-bordered">
|
||||
<tr>
|
||||
<th width="30%">Nama Pelanggan</th>
|
||||
<td><?php echo htmlspecialchars($order['nama_pelanggan']); ?></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>WhatsApp</th>
|
||||
<td>
|
||||
<a href="https://wa.me/<?php echo $order['whatsapp']; ?>" target="_blank" class="text-decoration-none">
|
||||
<?php echo htmlspecialchars($order['whatsapp']); ?> <i class="fa fa-external-link small"></i>
|
||||
</a>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>Alamat Pengiriman</th>
|
||||
<td><?php echo nl2br(htmlspecialchars($order['alamat_pengiriman'])); ?></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>Tanggal Kirim</th>
|
||||
<td><?php echo date('d F Y', strtotime($order['tanggal_kirim'])); ?></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>Catatan</th>
|
||||
<td><?php echo nl2br(htmlspecialchars($order['catatan'] ?? '-')); ?></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>Waktu Pesan</th>
|
||||
<td><?php echo date('d/m/Y H:i', strtotime($order['created_at'])); ?></td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<h6 class="mt-4 mb-3">Item Pesanan</h6>
|
||||
<div class="table-responsive">
|
||||
<table class="table table-sm">
|
||||
<thead class="table-light">
|
||||
<tr>
|
||||
<th>Menu</th>
|
||||
<th class="text-center">Qty</th>
|
||||
<th class="text-end">Harga Satuan</th>
|
||||
<th class="text-end">Subtotal</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php foreach ($items as $item): ?>
|
||||
<tr>
|
||||
<td><?php echo htmlspecialchars($item['nama_menu']); ?></td>
|
||||
<td class="text-center"><?php echo $item['qty']; ?></td>
|
||||
<td class="text-end"><?php echo rupiah($item['harga_saat_pesan']); ?></td>
|
||||
<td class="text-end"><?php echo rupiah($item['qty'] * $item['harga_saat_pesan']); ?></td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
</tbody>
|
||||
<tfoot>
|
||||
<tr>
|
||||
<th colspan="3" class="text-end">Total</th>
|
||||
<th class="text-end h5"><?php echo rupiah($order['total_harga']); ?></th>
|
||||
</tr>
|
||||
</tfoot>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
<div class="card-footer bg-white">
|
||||
<a href="pesanan.php" class="btn btn-outline-secondary">Kembali</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-4">
|
||||
<div class="card shadow-sm">
|
||||
<div class="card-header bg-white">
|
||||
<h5 class="mb-0">Update Status</h5>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<form method="POST">
|
||||
<input type="hidden" name="update_status" value="1">
|
||||
<div class="mb-3">
|
||||
<label class="form-label">Status Saat Ini</label>
|
||||
<select name="status" class="form-select">
|
||||
<option value="Baru" <?php echo $order['status'] == 'Baru' ? 'selected' : ''; ?>>Baru</option>
|
||||
<option value="Proses" <?php echo $order['status'] == 'Proses' ? 'selected' : ''; ?>>Proses</option>
|
||||
<option value="Selesai" <?php echo $order['status'] == 'Selesai' ? 'selected' : ''; ?>>Selesai</option>
|
||||
<option value="Batal" <?php echo $order['status'] == 'Batal' ? 'selected' : ''; ?>>Batal</option>
|
||||
</select>
|
||||
</div>
|
||||
<button type="submit" class="btn btn-primary w-100">Update Status</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<?php else: ?>
|
||||
<div class="card shadow-sm">
|
||||
<div class="card-body p-0">
|
||||
<div class="table-responsive">
|
||||
<table class="table table-hover mb-0">
|
||||
<thead class="table-light">
|
||||
<tr>
|
||||
<th>ID</th>
|
||||
<th>Pelanggan</th>
|
||||
<th>WA</th>
|
||||
<th>Total</th>
|
||||
<th>Status</th>
|
||||
<th>Waktu</th>
|
||||
<th>Aksi</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php foreach ($pesanan_list as $row): ?>
|
||||
<tr>
|
||||
<td>#<?php echo $row['id']; ?></td>
|
||||
<td><?php echo htmlspecialchars($row['nama_pelanggan']); ?></td>
|
||||
<td><?php echo htmlspecialchars($row['whatsapp']); ?></td>
|
||||
<td><?php echo rupiah($row['total_harga']); ?></td>
|
||||
<td>
|
||||
<?php
|
||||
$badge = [
|
||||
'Baru' => 'bg-info',
|
||||
'Proses' => 'bg-warning',
|
||||
'Selesai' => 'bg-success',
|
||||
'Batal' => 'bg-danger'
|
||||
];
|
||||
?>
|
||||
<span class="badge <?php echo $badge[$row['status']] ?? 'bg-secondary'; ?>">
|
||||
<?php echo $row['status']; ?>
|
||||
</span>
|
||||
</td>
|
||||
<td class="small"><?php echo date('d/m/y H:i', strtotime($row['created_at'])); ?></td>
|
||||
<td>
|
||||
<a href="pesanan.php?action=detail&id=<?php echo $row['id']; ?>" class="btn btn-sm btn-outline-info">Detail</a>
|
||||
<a href="pesanan.php?action=hapus&id=<?php echo $row['id']; ?>" class="btn btn-sm btn-outline-danger" onclick="return confirm('Hapus pesanan ini?')">Hapus</a>
|
||||
</td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
<?php if (empty($pesanan_list)): ?>
|
||||
<tr>
|
||||
<td colspan="7" class="text-center py-4 text-muted">Belum ada pesanan.</td>
|
||||
</tr>
|
||||
<?php endif; ?>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php require_once 'footer.php'; ?>
|
||||
119
admin/profil.php
Normal file
119
admin/profil.php
Normal file
@ -0,0 +1,119 @@
|
||||
<?php
|
||||
require_once 'header.php';
|
||||
|
||||
// Fetch current profil
|
||||
$profil = fetch_one("SELECT * FROM profil_usaha LIMIT 1");
|
||||
|
||||
// Handle Form Submit
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
$nama_usaha = $_POST['nama_usaha'];
|
||||
$tagline = $_POST['tagline'];
|
||||
$deskripsi = $_POST['deskripsi'];
|
||||
$alamat = $_POST['alamat'];
|
||||
$whatsapp = $_POST['whatsapp'];
|
||||
$email = $_POST['email'];
|
||||
$instagram = $_POST['instagram'];
|
||||
|
||||
$logo = $profil['logo'] ?? '';
|
||||
|
||||
// Handle Logo Upload
|
||||
if (isset($_FILES['logo']) && $_FILES['logo']['error'] === UPLOAD_ERR_OK) {
|
||||
$tmp_name = $_FILES['logo']['tmp_name'];
|
||||
$name = basename($_FILES['logo']['name']);
|
||||
$ext = pathinfo($name, PATHINFO_EXTENSION);
|
||||
$new_name = 'logo_' . uniqid() . '.' . $ext;
|
||||
$target = "../assets/uploads/" . $new_name;
|
||||
|
||||
if (move_uploaded_file($tmp_name, $target)) {
|
||||
// Delete old logo if exists
|
||||
if ($logo && file_exists("../assets/uploads/" . $logo)) {
|
||||
unlink("../assets/uploads/" . $logo);
|
||||
}
|
||||
$logo = $new_name;
|
||||
}
|
||||
}
|
||||
|
||||
if ($profil) {
|
||||
// Update
|
||||
$stmt = db()->prepare("UPDATE profil_usaha SET nama_usaha=?, tagline=?, deskripsi=?, alamat=?, whatsapp=?, email=?, instagram=?, logo=? WHERE id=?");
|
||||
$stmt->execute([$nama_usaha, $tagline, $deskripsi, $alamat, $whatsapp, $email, $instagram, $logo, $profil['id']]);
|
||||
} else {
|
||||
// Insert
|
||||
$stmt = db()->prepare("INSERT INTO profil_usaha (nama_usaha, tagline, deskripsi, alamat, whatsapp, email, instagram, logo) VALUES (?, ?, ?, ?, ?, ?, ?, ?)");
|
||||
$stmt->execute([$nama_usaha, $tagline, $deskripsi, $alamat, $whatsapp, $email, $instagram, $logo]);
|
||||
}
|
||||
|
||||
header('Location: profil.php?msg=Profil usaha berhasil diperbarui');
|
||||
exit;
|
||||
}
|
||||
?>
|
||||
|
||||
<div class="d-flex justify-content-between flex-wrap flex-md-nowrap align-items-center pt-3 pb-2 mb-3 border-bottom">
|
||||
<h1 class="h2">Profil Usaha</h1>
|
||||
</div>
|
||||
|
||||
<?php if (isset($_GET['msg'])): ?>
|
||||
<div class="alert alert-success"><?php echo htmlspecialchars($_GET['msg']); ?></div>
|
||||
<?php endif; ?>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-md-8">
|
||||
<div class="card shadow-sm">
|
||||
<div class="card-body">
|
||||
<form method="POST" enctype="multipart/form-data">
|
||||
<div class="mb-3">
|
||||
<label class="form-label">Nama Usaha</label>
|
||||
<input type="text" name="nama_usaha" class="form-control" value="<?php echo $profil['nama_usaha'] ?? ''; ?>" required>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label class="form-label">Tagline</label>
|
||||
<input type="text" name="tagline" class="form-control" value="<?php echo $profil['tagline'] ?? ''; ?>">
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label class="form-label">Deskripsi Singkat</label>
|
||||
<textarea name="deskripsi" class="form-control" rows="3"><?php echo $profil['deskripsi'] ?? ''; ?></textarea>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label class="form-label">Alamat Lengkap</label>
|
||||
<textarea name="alamat" class="form-control" rows="2"><?php echo $profil['alamat'] ?? ''; ?></textarea>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-md-4 mb-3">
|
||||
<label class="form-label">WhatsApp</label>
|
||||
<input type="text" name="whatsapp" class="form-control" value="<?php echo $profil['whatsapp'] ?? ''; ?>">
|
||||
</div>
|
||||
<div class="col-md-4 mb-3">
|
||||
<label class="form-label">Email</label>
|
||||
<input type="email" name="email" class="form-control" value="<?php echo $profil['email'] ?? ''; ?>">
|
||||
</div>
|
||||
<div class="col-md-4 mb-3">
|
||||
<label class="form-label">Instagram</label>
|
||||
<input type="text" name="instagram" class="form-control" value="<?php echo $profil['instagram'] ?? ''; ?>">
|
||||
</div>
|
||||
</div>
|
||||
<div class="mb-4">
|
||||
<label class="form-label">Logo Usaha</label>
|
||||
<input type="file" name="logo" class="form-control">
|
||||
<?php if (isset($profil['logo']) && $profil['logo']): ?>
|
||||
<div class="mt-2">
|
||||
<img src="../assets/uploads/<?php echo $profil['logo']; ?>" width="120" class="img-thumbnail" alt="Logo">
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
<button type="submit" class="btn btn-primary px-5">Simpan Perubahan</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-4">
|
||||
<div class="card shadow-sm border-0 bg-light">
|
||||
<div class="card-body">
|
||||
<h5>Tips Profil</h5>
|
||||
<p class="small text-muted">Pastikan nomor WhatsApp diawali dengan 62 (contoh: 628123456789) agar fitur tombol pesan di halaman depan berfungsi dengan baik.</p>
|
||||
<p class="small text-muted">Logo yang diunggah sebaiknya memiliki latar belakang transparan (PNG) untuk tampilan terbaik di website.</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php require_once 'footer.php'; ?>
|
||||
Loading…
x
Reference in New Issue
Block a user