🤩 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:testimonials.php
<?php /** * ARCHI-TECH Admin Testimonials 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 testimonial successfully created."; if ($_GET['success'] === 'updated') $success_msg = "Testimonial successfully updated."; if ($_GET['success'] === 'deleted') $success_msg = "Testimonial successfully deleted."; } // Delete testimonial logic if (isset($_GET['delete'])) { $delete_id = intval($_GET['delete']); try { $stmt = $pdo->prepare("DELETE FROM testimonials WHERE id = :id"); $stmt->execute(['id' => $delete_id]); header("Location: " . BASE_URL . "admin/testimonials.php?success=deleted"); exit(); } catch (PDOException $e) { $error_msg = "Failed to delete testimonial: " . $e->getMessage(); } } // Add/Edit Form submit logic if (isset($_POST['submit_testimonial'])) { $client_name = trim($_POST['client_name']); $designation = trim($_POST['designation']); $comment = trim($_POST['comment']); $rating = intval($_POST['rating']); if (empty($client_name) || empty($comment)) { $error_msg = "Client Name and Comment are required fields."; } else { try { if ($action === 'add') { $stmt = $pdo->prepare("INSERT INTO testimonials (client_name, designation, comment, rating) VALUES (:client_name, :designation, :comment, :rating)"); $stmt->execute([ 'client_name' => $client_name, 'designation' => $designation, 'comment' => $comment, 'rating' => $rating ]); header("Location: " . BASE_URL . "admin/testimonials.php?success=added"); exit(); } elseif ($action === 'edit') { $stmt = $pdo->prepare("UPDATE testimonials SET client_name = :client_name, designation = :designation, comment = :comment, rating = :rating WHERE id = :id"); $stmt->execute([ 'client_name' => $client_name, 'designation' => $designation, 'comment' => $comment, 'rating' => $rating, 'id' => $id ]); header("Location: " . BASE_URL . "admin/testimonials.php?success=updated"); exit(); } } catch (PDOException $e) { $error_msg = "Database error: " . $e->getMessage(); } } } // Edit Form preload details $edit_data = ['client_name' => '', 'designation' => '', 'comment' => '', 'rating' => 5]; if ($action === 'edit' && $id > 0) { try { $stmt = $pdo->prepare("SELECT * FROM testimonials WHERE id = :id"); $stmt->execute(['id' => $id]); $edit_data = $stmt->fetch(); if (!$edit_data) { header("Location: " . BASE_URL . "admin/testimonials.php"); exit(); } } catch (PDOException $e) { $error_msg = "Error loading testimonial: " . $e->getMessage(); } } // Fetch all testimonials $all_testimonials = []; try { $stmt = $pdo->query("SELECT * FROM testimonials ORDER BY id DESC"); $all_testimonials = $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 Testimonials</h1> <div class="btn-toolbar mb-2 mb-md-0"> <?php if ($action === 'list'): ?> <a href="<?= BASE_URL ?>admin/testimonials.php?action=add" class="btn btn-gold btn-sm py-2 px-3"><i class="bi bi-plus-circle me-2"></i>Add Testimonial</a> <?php else: ?> <a href="<?= BASE_URL ?>admin/testimonials.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 TESTIMONIALS 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: 25%;">Client Name</th> <th scope="col" style="width: 20%;">Designation / Firm</th> <th scope="col" style="width: 35%;">Comment</th> <th scope="col" style="width: 10%; text-align: center;">Rating</th> <th scope="col" style="width: 10%; text-align: center;">Actions</th> </tr> </thead> <tbody> <?php if (!empty($all_testimonials)): ?> <?php foreach ($all_testimonials as $t): ?> <tr> <td><strong><?= sanitize_input($t['client_name']) ?></strong></td> <td><span class="text-white-50"><?= sanitize_input($t['designation']) ?></span></td> <td class="small text-white-50">"<?= sanitize_input(substr($t['comment'], 0, 70)) ?><?= strlen($t['comment']) > 70 ? '...' : '' ?>"</td> <td align="center" class="text-accent-color small"> <?php for ($i = 0; $i < $t['rating']; $i++): ?> <i class="bi bi-star-fill"></i> <?php endfor; ?> </td> <td align="center"> <a href="<?= BASE_URL ?>admin/testimonials.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/testimonials.php?delete=<?= $t['id'] ?>" class="btn btn-outline-danger btn-sm" title="Delete" onclick="return confirm('Delete this testimonial?')"><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 reviews recorded.</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 Testimonial' : '<i class="bi bi-pencil-square text-accent-color me-2"></i>Edit Testimonial Details' ?> </h3> <form action="<?= BASE_URL ?>admin/testimonials.php?action=<?= $action ?><?= ($action === 'edit') ? '&id=' . $id : '' ?>" method="POST"> <div class="row"> <div class="col-md-6 mb-3"> <label for="client_name" class="form-label text-uppercase small text-muted fw-bold">Client Name <span class="text-accent-color">*</span></label> <input type="text" class="form-control form-dark-control" id="client_name" name="client_name" required value="<?= sanitize_input($edit_data['client_name']) ?>" placeholder="eg: Dilan Perera"> </div> <div class="col-md-6 mb-3"> <label for="designation" class="form-label text-uppercase small text-muted fw-bold">Designation / Company</label> <input type="text" class="form-control form-dark-control" id="designation" name="designation" value="<?= sanitize_input($edit_data['designation']) ?>" placeholder="eg: CEO, Zenith Holdings"> </div> </div> <div class="mb-3"> <label for="rating" class="form-label text-uppercase small text-muted fw-bold">Star Rating (1 - 5)</label> <select class="form-select form-dark-control" id="rating" name="rating"> <option value="5" <?= (intval($edit_data['rating']) === 5) ? 'selected' : '' ?>>5 Stars (Excellent)</option> <option value="4" <?= (intval($edit_data['rating']) === 4) ? 'selected' : '' ?>>4 Stars (Very Good)</option> <option value="3" <?= (intval($edit_data['rating']) === 3) ? 'selected' : '' ?>>3 Stars (Average)</option> <option value="2" <?= (intval($edit_data['rating']) === 2) ? 'selected' : '' ?>>2 Stars (Below Average)</option> <option value="1" <?= (intval($edit_data['rating']) === 1) ? 'selected' : '' ?>>1 Star (Poor)</option> </select> </div> <div class="mb-4"> <label for="comment" class="form-label text-uppercase small text-muted fw-bold">Client Quote</label> <textarea class="form-control form-dark-control" id="comment" name="comment" rows="5" required placeholder="Write what the client said about your layouts, construction efficiency, timelines or communication skills..."><?= sanitize_input($edit_data['comment']) ?></textarea> </div> <div class="text-end pt-3"> <a href="<?= BASE_URL ?>admin/testimonials.php" class="btn btn-outline-light me-2">Cancel</a> <button type="submit" name="submit_testimonial" class="btn-gold-filled px-4">Save Testimonial</button> </div> </form> </div> </div> </div> <?php endif; ?> <?php require_once __DIR__ . '/footer.php'; ?>
Save Changes
Cancel
Create New File
Create New Folder