prepare("DELETE FROM services WHERE id = :id"); $stmt->execute(['id' => $delete_id]); header("Location: " . BASE_URL . "admin/services.php?success=deleted"); exit(); } catch (PDOException $e) { $error_msg = "Failed to delete service: " . $e->getMessage(); } } // Add/Edit Submission logic if (isset($_POST['submit_service'])) { $title = trim($_POST['title']); $category = trim($_POST['category']); $description = trim($_POST['description']); $icon = trim($_POST['icon']); if (empty($icon)) $icon = 'bi-house'; if (empty($title) || empty($category) || empty($description)) { $error_msg = "All inputs (Title, Category, Description) are required."; } else { try { if ($action === 'add') { $stmt = $pdo->prepare("INSERT INTO services (title, category, description, icon) VALUES (:title, :category, :description, :icon)"); $stmt->execute([ 'title' => $title, 'category' => $category, 'description' => $description, 'icon' => $icon ]); header("Location: " . BASE_URL . "admin/services.php?success=added"); exit(); } elseif ($action === 'edit') { $stmt = $pdo->prepare("UPDATE services SET title = :title, category = :category, description = :description, icon = :icon WHERE id = :id"); $stmt->execute([ 'title' => $title, 'category' => $category, 'description' => $description, 'icon' => $icon, 'id' => $id ]); header("Location: " . BASE_URL . "admin/services.php?success=updated"); exit(); } } catch (PDOException $e) { $error_msg = "Error updating database: " . $e->getMessage(); } } } // Pre-fill Edit form details $edit_data = ['title' => '', 'category' => '', 'description' => '', 'icon' => '']; if ($action === 'edit' && $id > 0) { try { $stmt = $pdo->prepare("SELECT * FROM services WHERE id = :id"); $stmt->execute(['id' => $id]); $edit_data = $stmt->fetch(); if (!$edit_data) { header("Location: " . BASE_URL . "admin/services.php"); exit(); } } catch (PDOException $e) { $error_msg = "Error loading service: " . $e->getMessage(); } } // Fetch all services for lists $all_services = []; try { $stmt = $pdo->query("SELECT * FROM services ORDER BY category ASC, title ASC"); $all_services = $stmt->fetchAll(); } catch (PDOException $e) { // offline mock } require_once __DIR__ . '/header.php'; require_once __DIR__ . '/navbar.php'; ?>

Manage Services

Add New Service Back to List
Icon Title Category Description Actions
80 ? '...' : '' ?>
No services currently registered in the system.

Add Service' : 'Edit Service' ?>

Defaults to bi-house if left blank.
Cancel