🤩 File Manager - Mr.X
PHP:
8.3.33
Server:
Apache
OS:
Linux 5.14.0-611.49.1.el9_7.x86_64
User:
websparkit
Navigate
Upload:
Upload
New File
New Folder
Editing:services.php
<?php /** * ARCHI-TECH Admin Services CRUD Manager */ require_once __DIR__ . '/../includes/db.php'; require_once __DIR__ . '/../includes/functions.php'; check_admin_auth(); $action = isset($_GET['action']) ? $_GET['action'] : 'list'; $id = isset($_GET['id']) ? intval($_GET['id']) : 0; $success_msg = ''; $error_msg = ''; // Success Notice Handling if (isset($_GET['success'])) { if ($_GET['success'] === 'added') $success_msg = "New service successfully created."; if ($_GET['success'] === 'updated') $success_msg = "Service details successfully updated."; if ($_GET['success'] === 'deleted') $success_msg = "Service successfully deleted."; } // Delete Service logic if (isset($_GET['delete'])) { $delete_id = intval($_GET['delete']); try { $stmt = $pdo->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'; ?> <div class="d-flex justify-content-between flex-wrap flex-md-nowrap align-items-center pt-3 pb-2 mb-4 border-bottom border-secondary"> <h1 class="h2 text-white text-uppercase" style="letter-spacing: -0.01em; font-family: 'Syne', sans-serif;">Manage Services</h1> <div class="btn-toolbar mb-2 mb-md-0"> <?php if ($action === 'list'): ?> <a href="<?= BASE_URL ?>admin/services.php?action=add" class="btn btn-gold btn-sm py-2 px-3"><i class="bi bi-plus-circle me-2"></i>Add New Service</a> <?php else: ?> <a href="<?= BASE_URL ?>admin/services.php" class="btn btn-outline-light btn-sm py-2 px-3"><i class="bi bi-arrow-left me-2"></i>Back to List</a> <?php endif; ?> </div> </div> <!-- Alert Notices --> <?php if (!empty($success_msg)): ?> <div class="alert alert-success border-0 bg-success text-white mb-4"> <i class="bi bi-check-circle-fill me-2"></i><?= sanitize_input($success_msg) ?> </div> <?php endif; ?> <?php if (!empty($error_msg)): ?> <div class="alert alert-danger border-0 bg-danger text-white mb-4"> <i class="bi bi-exclamation-triangle-fill me-2"></i><?= sanitize_input($error_msg) ?> </div> <?php endif; ?> <?php if ($action === 'list'): ?> <!-- SERVICES LISTING TABLE --> <div class="glass-card p-4"> <div class="table-responsive"> <table class="table table-dark table-striped table-hover align-middle border-secondary table-dark-custom"> <thead> <tr> <th scope="col" style="width: 5%; text-align: center;">Icon</th> <th scope="col" style="width: 25%;">Title</th> <th scope="col" style="width: 20%;">Category</th> <th scope="col" style="width: 35%;">Description</th> <th scope="col" style="width: 15%; text-align: center;">Actions</th> </tr> </thead> <tbody> <?php if (!empty($all_services)): ?> <?php foreach ($all_services as $srv): ?> <tr> <td align="center" class="text-accent-color fs-4"><i class="bi <?= sanitize_input($srv['icon']) ?>"></i></td> <td><strong><?= sanitize_input($srv['title']) ?></strong></td> <td><span class="badge" style="background-color: var(--light-accent-color); color: var(--accent-color);"><?= sanitize_input($srv['category']) ?></span></td> <td class="small text-white-50"><?= sanitize_input(substr($srv['description'], 0, 80)) ?><?= strlen($srv['description']) > 80 ? '...' : '' ?></td> <td align="center"> <a href="<?= BASE_URL ?>admin/services.php?action=edit&id=<?= $srv['id'] ?>" class="btn btn-outline-light btn-sm me-2" title="Edit"><i class="bi bi-pencil"></i></a> <a href="<?= BASE_URL ?>admin/services.php?delete=<?= $srv['id'] ?>" class="btn btn-outline-danger btn-sm" title="Delete" onclick="return confirm('Are you sure you want to delete this service?')"><i class="bi bi-trash"></i></a> </td> </tr> <?php endforeach; ?> <?php else: ?> <tr> <td colspan="5" class="text-center text-muted py-4">No services currently registered in the system.</td> </tr> <?php endif; ?> </tbody> </table> </div> </div> <?php elseif ($action === 'add' || $action === 'edit'): ?> <!-- ADD / EDIT SERVICE FORM --> <div class="row justify-content-center"> <div class="col-lg-8"> <div class="glass-card"> <h3 class="h5 text-white text-uppercase mb-4" style="letter-spacing: 0.05em;"> <?= ($action === 'add') ? '<i class="bi bi-plus-circle text-accent-color me-2"></i>Add Service' : '<i class="bi bi-pencil-square text-accent-color me-2"></i>Edit Service' ?> </h3> <form action="<?= BASE_URL ?>admin/services.php?action=<?= $action ?><?= ($action === 'edit') ? '&id=' . $id : '' ?>" method="POST"> <div class="mb-3"> <label for="title" class="form-label text-uppercase small text-muted fw-bold">Service Title</label> <input type="text" class="form-control form-dark-control" id="title" name="title" required value="<?= sanitize_input($edit_data['title']) ?>" placeholder="eg: Architectural Design"> </div> <div class="mb-3"> <label for="category" class="form-label text-uppercase small text-muted fw-bold">Service Category</label> <select class="form-select form-dark-control" id="category" name="category" required> <option value="">-- Select Category --</option> <option value="Architecture & Planning" <?= ($edit_data['category'] === 'Architecture & Planning') ? 'selected' : '' ?>>Architecture & Planning</option> <option value="Landscape Design" <?= ($edit_data['category'] === 'Landscape Design') ? 'selected' : '' ?>>Landscape Design</option> <option value="Interior Design" <?= ($edit_data['category'] === 'Interior Design') ? 'selected' : '' ?>>Interior Design</option> <option value="Construction Services" <?= ($edit_data['category'] === 'Construction Services') ? 'selected' : '' ?>>Construction Services</option> <option value="CAD & 3D Visualization" <?= ($edit_data['category'] === 'CAD & 3D Visualization') ? 'selected' : '' ?>>CAD & 3D Visualization</option> <option value="Engineering Consultancy" <?= ($edit_data['category'] === 'Engineering Consultancy') ? 'selected' : '' ?>>Engineering Consultancy</option> <option value="Urban Green Solutions" <?= ($edit_data['category'] === 'Urban Green Solutions') ? 'selected' : '' ?>>Urban Green Solutions</option> <option value="Project Management" <?= ($edit_data['category'] === 'Project Management') ? 'selected' : '' ?>>Project Management</option> <option value="Specialized Services" <?= ($edit_data['category'] === 'Specialized Services') ? 'selected' : '' ?>>Specialized Services</option> </select> </div> <div class="mb-3"> <label for="icon" class="form-label text-uppercase small text-muted fw-bold">Bootstrap Icon Class (optional)</label> <div class="input-group"> <span class="input-group-text bg-dark border-secondary text-accent-color"><i class="bi bi-code"></i></span> <input type="text" class="form-control form-dark-control" id="icon" name="icon" value="<?= sanitize_input($edit_data['icon']) ?>" placeholder="eg: bi-vector-pen (see Bootstrap icons listing)"> </div> <small class="text-muted">Defaults to bi-house if left blank.</small> </div> <div class="mb-4"> <label for="description" class="form-label text-uppercase small text-muted fw-bold">Service Description</label> <textarea class="form-control form-dark-control" id="description" name="description" rows="5" required placeholder="Write a detailed description explaining the workflows, scope, and target deliveries for this service..."><?= sanitize_input($edit_data['description']) ?></textarea> </div> <div class="text-end pt-3"> <a href="<?= BASE_URL ?>admin/services.php" class="btn btn-outline-light me-2">Cancel</a> <button type="submit" name="submit_service" class="btn-gold-filled px-4">Save Service</button> </div> </form> </div> </div> </div> <?php endif; ?> <?php require_once __DIR__ . '/footer.php'; ?>
Save Changes
Cancel
Create New File
Create New Folder