diff --git a/admin/order_detail.php b/admin/order_detail.php new file mode 100644 index 0000000..63fe1db --- /dev/null +++ b/admin/order_detail.php @@ -0,0 +1,94 @@ +prepare('SELECT * FROM orders WHERE id = ?'); +$stmt->execute([$order_id]); +$order = $stmt->fetch(PDO::FETCH_ASSOC); + +if (!$order) { + die('Order not found.'); +} + +// Fetch order items +$stmt = $pdo->prepare('SELECT oi.quantity, oi.price, p.name FROM order_items oi JOIN products p ON oi.product_id = p.id WHERE oi.order_id = ?'); +$stmt->execute([$order_id]); +$items = $stmt->fetchAll(PDO::FETCH_ASSOC); +?> + +
+
+ + +
+
+

Detail Pesanan #

+ Kembali ke Daftar Pesanan +
+ +
+
+

Informasi Pelanggan

+

Nama:

+

Email:

+
+
+

Informasi Pesanan

+

Total: Rp

+

Status:

+

Tanggal:

+ +
+ +
+ + +
+
+
+
+ +

Item Pesanan

+
+ + + + + + + + + + + + + + + + + + + +
ProdukJumlahHargaSubtotal
Rp Rp
+
+ +
+
+
+ + diff --git a/admin/order_update_status.php b/admin/order_update_status.php new file mode 100644 index 0000000..b5b8440 --- /dev/null +++ b/admin/order_update_status.php @@ -0,0 +1,31 @@ +prepare('UPDATE orders SET status = ? WHERE id = ?'); + $stmt->execute([$status, $order_id]); + + // Redirect back to the order detail page with a success message + header('Location: order_detail.php?id=' . $order_id . '&status=updated'); + exit; + } catch (PDOException $e) { + // On error, redirect with an error message + header('Location: order_detail.php?id=' . $order_id . '&status=error'); + exit; + } +} + +// If not a POST request, just redirect to the main orders page +header('Location: orders.php'); +exit; +?> \ No newline at end of file diff --git a/admin/orders.php b/admin/orders.php new file mode 100644 index 0000000..e91c533 --- /dev/null +++ b/admin/orders.php @@ -0,0 +1,61 @@ +query('SELECT id, customer_name, total_amount, status, created_at FROM orders ORDER BY created_at DESC'); + $orders = $stmt->fetchAll(PDO::FETCH_ASSOC); +} catch (PDOException $e) { + die("Could not connect to the database: " . $e->getMessage()); +} +?> + +
+
+ + +
+
+

Manajemen Pesanan

+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
ID PesananNama PelangganTotalStatusTanggalAksi
Belum ada pesanan.
#Rp + Detail +
+
+
+
+
+ + \ No newline at end of file diff --git a/admin/partials/sidebar.php b/admin/partials/sidebar.php index 490d4f5..d9e44ee 100644 --- a/admin/partials/sidebar.php +++ b/admin/partials/sidebar.php @@ -10,16 +10,16 @@ $current_page = basename($_SERVER['REQUEST_URI']); Dashboard - + Manajemen User Manajemen Produk - + Manajemen Order - + Pengaturan diff --git a/admin/settings.php b/admin/settings.php new file mode 100644 index 0000000..1a304e9 --- /dev/null +++ b/admin/settings.php @@ -0,0 +1,73 @@ +prepare("UPDATE settings SET setting_value = :value WHERE setting_name = :name"); + $stmt->execute(['value' => $site_name, 'name' => 'site_name']); + $stmt->execute(['value' => $contact_email, 'name' => 'contact_email']); + $success_message = "Settings updated successfully!"; + } catch (PDOException $e) { + $error_message = "Error updating settings: " . $e->getMessage(); + } +} + +// Fetch current settings +$stmt = $pdo->query("SELECT * FROM settings"); +$settings = $stmt->fetchAll(PDO::FETCH_KEY_PAIR); + +$site_name = $settings['site_name'] ?? ''; +$contact_email = $settings['contact_email'] ?? ''; + +$page_title = "Settings"; +include 'partials/header.php'; +?> + +
+
+ + +
+
+

Settings

+
+ + + + + + + + +
+
+
General Settings
+
+
+ + +
+
+ + +
+ +
+
+
+ +
+
+
+ + diff --git a/admin/user_add.php b/admin/user_add.php new file mode 100644 index 0000000..bea7463 --- /dev/null +++ b/admin/user_add.php @@ -0,0 +1,54 @@ + + +
+ + +
+ +
+
+ + diff --git a/admin/user_create.php b/admin/user_create.php new file mode 100644 index 0000000..1fbd71b --- /dev/null +++ b/admin/user_create.php @@ -0,0 +1,53 @@ +prepare("INSERT INTO users (name, email, password, role) VALUES (:name, :email, :password, :role)"); + $stmt->execute([ + ':name' => $name, + ':email' => $email, + ':password' => $hashed_password, + ':role' => $role + ]); + + header("Location: users.php?status=success&message=" . urlencode('Pengguna baru berhasil ditambahkan.')); + exit; + + } catch (PDOException $e) { + $message = 'Gagal menambahkan pengguna.'; + // Check for duplicate email + if ($e->errorInfo[1] == 1062) { // 1062 is the MySQL error code for duplicate entry + $message = 'Email sudah terdaftar. Silakan gunakan email lain.'; + } + header("Location: users.php?status=danger&message=" . urlencode($message)); + exit; + } + +} else { + // Redirect if not a POST request + header('Location: user_add.php'); + exit; +} diff --git a/admin/user_delete.php b/admin/user_delete.php new file mode 100644 index 0000000..4e9b5ea --- /dev/null +++ b/admin/user_delete.php @@ -0,0 +1,34 @@ +prepare("DELETE FROM users WHERE id = :id"); + $stmt->execute(['id' => $user_id]); + + if ($stmt->rowCount() > 0) { + header("Location: users.php?status=success&message=" . urlencode('Pengguna berhasil dihapus.')); + } else { + header("Location: users.php?status=danger&message=" . urlencode('Pengguna tidak ditemukan atau sudah dihapus.')); + } + exit; + +} catch (PDOException $e) { + header("Location: users.php?status=danger&message=" . urlencode('Gagal menghapus pengguna.')); + exit; +} diff --git a/admin/user_edit.php b/admin/user_edit.php new file mode 100644 index 0000000..b4341af --- /dev/null +++ b/admin/user_edit.php @@ -0,0 +1,80 @@ +prepare("SELECT * FROM users WHERE id = :id"); + $stmt->execute(['id' => $user_id]); + $user = $stmt->fetch(); + + if (!$user) { + header("Location: users.php?status=danger&message=" . urlencode('Pengguna tidak ditemukan.')); + exit; + } +} catch (PDOException $e) { + header("Location: users.php?status=danger&message=" . urlencode('Gagal mengambil data pengguna.')); + exit; +} + +// Include header +include 'partials/header.php'; +?> + +
+ + +
+
+
+
+
+
+ +
+ + +
+
+ + +
+
+ + + Kosongkan jika tidak ingin mengubah password. +
+
+ + +
+ + Batal +
+
+
+
+
+
+
+ + diff --git a/admin/user_update.php b/admin/user_update.php new file mode 100644 index 0000000..3ca9300 --- /dev/null +++ b/admin/user_update.php @@ -0,0 +1,62 @@ + $id, + ':name' => $name, + ':email' => $email, + ':role' => $role + ]; + + // Handle password update + if (!empty($password)) { + $hashed_password = password_hash($password, PASSWORD_DEFAULT); + $sql .= ", password = :password"; + $params[':password'] = $hashed_password; + } + + $sql .= " WHERE id = :id"; + + // Update database + try { + $pdo = db(); + $stmt = $pdo->prepare($sql); + $stmt->execute($params); + + header("Location: users.php?status=success&message=" . urlencode('Data pengguna berhasil diperbarui.')); + exit; + + } catch (PDOException $e) { + $message = 'Gagal memperbarui data pengguna.'; + if ($e->errorInfo[1] == 1062) { + $message = 'Email sudah terdaftar. Silakan gunakan email lain.'; + } + header("Location: users.php?status=danger&message=" . urlencode($message)); + exit; + } + +} else { + header('Location: users.php'); + exit; +} diff --git a/admin/users.php b/admin/users.php new file mode 100644 index 0000000..b95581b --- /dev/null +++ b/admin/users.php @@ -0,0 +1,85 @@ +query("SELECT * FROM users ORDER BY created_at DESC"); + $users = $stmt->fetchAll(); +} catch (PDOException $e) { + $users = []; + $db_error = "Error fetching users: " . $e->getMessage(); +} + +// Include header +include 'partials/header.php'; +?> + +
+ + +
+ + + + + + +
+ + +
+
+ Tambah Pengguna +
+
+

Daftar Pengguna

+
+ + + + + + + + + + + + + + + + + $user) : ?> + + + + + + + + + + +
#NamaEmailPeranAksi
Belum ada pengguna.
+ Edit + Hapus +
+
+
+
+
+
+
+
+ + diff --git a/db/migration_orders.php b/db/migration_orders.php new file mode 100644 index 0000000..2d5a228 --- /dev/null +++ b/db/migration_orders.php @@ -0,0 +1,36 @@ +exec(" + CREATE TABLE IF NOT EXISTS `orders` ( + `id` INT AUTO_INCREMENT PRIMARY KEY, + `customer_name` VARCHAR(255) NOT NULL, + `customer_email` VARCHAR(255) NOT NULL, + `total_amount` DECIMAL(10, 2) NOT NULL, + `status` VARCHAR(50) NOT NULL DEFAULT 'Pending', + `created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP + ) + "); + + // Create order_items table + $pdo->exec(" + CREATE TABLE IF NOT EXISTS `order_items` ( + `id` INT AUTO_INCREMENT PRIMARY KEY, + `order_id` INT NOT NULL, + `product_id` INT NOT NULL, + `quantity` INT NOT NULL, + `price` DECIMAL(10, 2) NOT NULL, + FOREIGN KEY (`order_id`) REFERENCES `orders`(`id`) ON DELETE CASCADE, + FOREIGN KEY (`product_id`) REFERENCES `products`(`id`) ON DELETE RESTRICT + ) + "); + + echo "Tables 'orders' and 'order_items' created successfully." . PHP_EOL; + +} catch (PDOException $e) { + die("DB ERROR: " . $e->getMessage()); +} diff --git a/db/migration_settings.php b/db/migration_settings.php new file mode 100644 index 0000000..312dfc1 --- /dev/null +++ b/db/migration_settings.php @@ -0,0 +1,30 @@ +exec($sql); + + // Insert default settings if they don't exist + $defaults = [ + 'site_name' => 'My Awesome Site', + 'contact_email' => 'contact@example.com' + ]; + + $stmt = $pdo->prepare("INSERT INTO settings (setting_name, setting_value) VALUES (:name, :value) ON DUPLICATE KEY UPDATE setting_name=setting_name"); + + foreach ($defaults as $name => $value) { + $stmt->execute(['name' => $name, 'value' => $value]); + } + + echo "Table 'settings' created and default values inserted successfully." . PHP_EOL; +} catch (PDOException $e) { + die("DB ERROR: " . $e->getMessage()); +} diff --git a/db/migration_users.php b/db/migration_users.php new file mode 100644 index 0000000..2c06ac6 --- /dev/null +++ b/db/migration_users.php @@ -0,0 +1,18 @@ +exec($sql); + echo "Table 'users' created successfully." . PHP_EOL; +} catch (PDOException $e) { + die("DB ERROR: " . $e->getMessage()); +}