🤩 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:team.php
<?php /** * ARCHI-TECH Admin Team 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 = ''; // Helper to upload team member portrait function handle_team_upload($file) { if (!isset($file) || $file['error'] !== UPLOAD_ERR_OK) { return null; } $allowed = ['image/jpeg', 'image/png', 'image/webp', 'image/jpg']; if (!in_array($file['type'], $allowed)) { return null; } $ext = pathinfo($file['name'], PATHINFO_EXTENSION); $new_name = 'team_' . bin2hex(random_bytes(4)) . '.' . $ext; $destination = __DIR__ . '/../assets/images/' . $new_name; if (move_uploaded_file($file['tmp_name'], $destination)) { return 'assets/images/' . $new_name; } return null; } // Notice Alert Actions if (isset($_GET['success'])) { if ($_GET['success'] === 'added') $success_msg = "Team member successfully created."; if ($_GET['success'] === 'updated') $success_msg = "Team member details successfully updated."; if ($_GET['success'] === 'deleted') $success_msg = "Team member successfully deleted."; } // Delete Team Member logic if (isset($_GET['delete'])) { $delete_id = intval($_GET['delete']); try { $stmt_img = $pdo->prepare("SELECT image_path FROM team_members WHERE id = :id"); $stmt_img->execute(['id' => $delete_id]); $row = $stmt_img->fetch(); if ($row && !empty($row['image_path']) && file_exists(__DIR__ . '/../' . $row['image_path'])) { // Keep sample images safe, only delete custom ones if (strpos($row['image_path'], 'team-') === false) { @unlink(__DIR__ . '/../' . $row['image_path']); } } $stmt = $pdo->prepare("DELETE FROM team_members WHERE id = :id"); $stmt->execute(['id' => $delete_id]); header("Location: " . BASE_URL . "admin/team.php?success=deleted"); exit(); } catch (PDOException $e) { $error_msg = "Failed to delete team member: " . $e->getMessage(); } } // Handle Form Submission if (isset($_POST['submit_team'])) { $name = trim($_POST['name']); $role = trim($_POST['role']); $bio = trim($_POST['bio']); if (empty($name) || empty($role)) { $error_msg = "Name and Designation are required fields."; } else { try { if ($action === 'add') { $img_path = handle_team_upload($_FILES['image']); if (!$img_path) $img_path = 'assets/images/team-1.jpg'; // fallback default $stmt = $pdo->prepare("INSERT INTO team_members (name, role, image_path, bio) VALUES (:name, :role, :image_path, :bio)"); $stmt->execute([ 'name' => $name, 'role' => $role, 'image_path' => $img_path, 'bio' => $bio ]); header("Location: " . BASE_URL . "admin/team.php?success=added"); exit(); } elseif ($action === 'edit') { $stmt_orig = $pdo->prepare("SELECT image_path FROM team_members WHERE id = :id"); $stmt_orig->execute(['id' => $id]); $orig_path = $stmt_orig->fetchColumn(); $new_path = handle_team_upload($_FILES['image']); if ($new_path) { if (!empty($orig_path) && file_exists(__DIR__ . '/../' . $orig_path) && strpos($orig_path, 'team-') === false) { @unlink(__DIR__ . '/../' . $orig_path); } $orig_path = $new_path; } $stmt = $pdo->prepare("UPDATE team_members SET name = :name, role = :role, image_path = :image_path, bio = :bio WHERE id = :id"); $stmt->execute([ 'name' => $name, 'role' => $role, 'image_path' => $orig_path, 'bio' => $bio, 'id' => $id ]); header("Location: " . BASE_URL . "admin/team.php?success=updated"); exit(); } } catch (PDOException $e) { $error_msg = "Error updating database: " . $e->getMessage(); } } } // Edit Mode detail pre-filler $edit_data = ['name' => '', 'role' => '', 'image_path' => '', 'bio' => '']; if ($action === 'edit' && $id > 0) { try { $stmt = $pdo->prepare("SELECT * FROM team_members WHERE id = :id"); $stmt->execute(['id' => $id]); $edit_data = $stmt->fetch(); if (!$edit_data) { header("Location: " . BASE_URL . "admin/team.php"); exit(); } } catch (PDOException $e) { $error_msg = "Error loading database row: " . $e->getMessage(); } } // Load all team members $all_team = []; try { $stmt = $pdo->query("SELECT * FROM team_members ORDER BY id ASC"); $all_team = $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 Team</h1> <div class="btn-toolbar mb-2 mb-md-0"> <?php if ($action === 'list'): ?> <a href="<?= BASE_URL ?>admin/team.php?action=add" class="btn btn-gold btn-sm py-2 px-3"><i class="bi bi-plus-circle me-2"></i>Add Team Member</a> <?php else: ?> <a href="<?= BASE_URL ?>admin/team.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> <!-- Notice Alerts --> <?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'): ?> <!-- LIST ALL TEAM 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: 10%; text-align: center;">Portrait</th> <th scope="col" style="width: 25%;">Full Name</th> <th scope="col" style="width: 20%;">Designation / Role</th> <th scope="col" style="width: 35%;">Biography</th> <th scope="col" style="width: 10%; text-align: center;">Actions</th> </tr> </thead> <tbody> <?php if (!empty($all_team)): ?> <?php foreach ($all_team as $t): ?> <tr> <td align="center"> <img src="<?= BASE_URL . sanitize_input($t['image_path']) ?>" class="rounded-circle border border-secondary" style="width: 50px; height: 50px; object-fit: cover;" alt="Team portrait"> </td> <td><strong><?= sanitize_input($t['name']) ?></strong></td> <td><span class="badge" style="background-color: var(--light-accent-color); color: var(--accent-color);"><?= sanitize_input($t['role']) ?></span></td> <td class="small text-white-50"><?= sanitize_input(substr($t['bio'], 0, 80)) ?><?= strlen($t['bio']) > 80 ? '...' : '' ?></td> <td align="center"> <a href="<?= BASE_URL ?>admin/team.php?action=edit&id=<?= $t['id'] ?>" class="btn btn-outline-light btn-sm me-2" title="Edit"><i class="bi bi-pencil"></i></a> <a href="<?= BASE_URL ?>admin/team.php?delete=<?= $t['id'] ?>" class="btn btn-outline-danger btn-sm" title="Delete" onclick="return confirm('Delete this team member?')"><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 team members registered.</td> </tr> <?php endif; ?> </tbody> </table> </div> </div> <?php elseif ($action === 'add' || $action === 'edit'): ?> <!-- ADD / EDIT 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 Member' : '<i class="bi bi-pencil-square text-accent-color me-2"></i>Edit Member Details' ?> </h3> <form action="<?= BASE_URL ?>admin/team.php?action=<?= $action ?><?= ($action === 'edit') ? '&id=' . $id : '' ?>" method="POST" enctype="multipart/form-data"> <div class="row"> <div class="col-md-6 mb-3"> <label for="name" class="form-label text-uppercase small text-muted fw-bold">Full Name <span class="text-accent-color">*</span></label> <input type="text" class="form-control form-dark-control" id="name" name="name" required value="<?= sanitize_input($edit_data['name']) ?>" placeholder="eg: Archt. Kusal De Silva"> </div> <div class="col-md-6 mb-3"> <label for="role" class="form-label text-uppercase small text-muted fw-bold">Designation / Role <span class="text-accent-color">*</span></label> <input type="text" class="form-control form-dark-control" id="role" name="role" required value="<?= sanitize_input($edit_data['role']) ?>" placeholder="eg: Principal Architect & Founder"> </div> </div> <div class="mb-4"> <label for="image" class="form-label text-uppercase small text-muted fw-bold">Select Portrait Image File</label> <input type="file" class="form-control form-dark-control" id="image" name="image"> <?php if (!empty($edit_data['image_path'])): ?> <small class="text-accent-color d-block mt-2">Active file: <?= basename($edit_data['image_path']) ?></small> <?php endif; ?> </div> <div class="mb-4"> <label for="bio" class="form-label text-uppercase small text-muted fw-bold">Biography & Credentials Summary</label> <textarea class="form-control form-dark-control" id="bio" name="bio" rows="6" placeholder="Write academic degrees, specialization details, and work experience parameters..."><?= sanitize_input($edit_data['bio']) ?></textarea> </div> <div class="text-end pt-3"> <a href="<?= BASE_URL ?>admin/team.php" class="btn btn-outline-light me-2">Cancel</a> <button type="submit" name="submit_team" class="btn-gold-filled px-4">Save Member</button> </div> </form> </div> </div> </div> <?php endif; ?> <?php require_once __DIR__ . '/footer.php'; ?>
Save Changes
Cancel
Create New File
Create New Folder