BLACKSITE
:
216.73.216.62
:
147.93.18.13 / vinyasaweddings.com
:
Linux srv667811 6.8.0-134-generic #134-Ubuntu SMP PREEMPT_DYNAMIC Fri Jun 26 18:43:11 UTC 2026 x86_64
:
/
var
/
www
/
kds
/
views
/
admin
/
Upload File:
files >> /var/www/kds/views/admin/testimonial-add.php
<?php include 'views/admin/layout/header.php'; ?> <?php include 'views/admin/layout/Sidebar.php'; ?> <?php require_once __DIR__ . '/../../db.php'; $successMessage = ''; $errorMessage = ''; $editing = false; $testimonial = [ 'name' => '', 'location' => '', 'rating' => '', 'image' => '', 'details' => '', 'status' => 'active', ]; // Check if editing if (isset($_GET['edit']) && is_numeric($_GET['edit'])) { $editing = true; $id = (int) $_GET['edit']; $stmt = $db->prepare("SELECT * FROM testimonials WHERE id = ?"); $stmt->execute([$id]); $testimonial = $stmt->fetch(PDO::FETCH_ASSOC); if (!$testimonial) { $errorMessage = "Testimonial not found."; $editing = false; } } if ($_SERVER['REQUEST_METHOD'] === 'POST') { $name = $_POST['name'] ?? ''; $location = $_POST['location'] ?? ''; $rating = $_POST['rating'] ?? ''; $details = $_POST['details'] ?? ''; $status = 'active'; $existingImage = $_POST['existing_image'] ?? ''; // Validation if (empty($name) || empty($location) || empty($rating) || empty($details)) { $errorMessage = "All fields except image are required."; } else { $uploadDir = 'uploads/testimonials/'; if (!is_dir($uploadDir)) mkdir($uploadDir, 0755, true); $fileName = $existingImage; if (isset($_FILES['image']) && $_FILES['image']['tmp_name']) { $fileTmp = $_FILES['image']['tmp_name']; $fileName = time() . '_' . basename($_FILES['image']['name']); $targetFile = $uploadDir . $fileName; if (!move_uploaded_file($fileTmp, $targetFile)) { $errorMessage = "Image upload failed."; } } if (!$errorMessage) { if ($editing) { $stmt = $db->prepare("UPDATE testimonials SET name=?, location=?, rating=?, image=?, details=?, status=? WHERE id=?"); $stmt->execute([$name, $location, $rating, $fileName, $details, $status, $id]); $successMessage = "Testimonial updated successfully."; } else { $stmt = $db->prepare("INSERT INTO testimonials (name, location, rating, image, details, status, created_at) VALUES (?, ?, ?, ?, ?, ?, NOW())"); $stmt->execute([$name, $location, $rating, $fileName, $details, $status]); $successMessage = "Testimonial added successfully."; } echo "<script>location.href=window.location.href;</script>"; exit; } } } ?> <main class="main-content"> <div class="container-fluid px-4"> <div class="d-flex justify-content-between align-items-center mb-4"> <h2 class="mb-4"><?= $editing ? 'Edit' : 'Add' ?> Testimonial</h2> </div> <?php if ($successMessage): ?> <div class="alert alert-success"><?= $successMessage ?></div> <?php elseif ($errorMessage): ?> <div class="alert alert-danger"><?= $errorMessage ?></div> <?php endif; ?> <div class="card shadow-sm"> <div class="card-body"> <form method="POST" enctype="multipart/form-data"> <input type="hidden" name="existing_image" value="<?= htmlspecialchars($testimonial['image'] ?? '') ?>"> <div class="row"> <div class="col-md-6 mb-3"> <label class="form-label">Name</label> <input type="text" name="name" class="form-control" value="<?= htmlspecialchars($testimonial['name'] ?? '') ?>" required> </div> <div class="col-md-6 mb-3"> <label class="form-label">Location</label> <input type="text" name="location" class="form-control" value="<?= htmlspecialchars($testimonial['location'] ?? '') ?>" required> </div> <div class="col-md-6 mb-3"> <label class="form-label">Rating</label> <select name="rating" class="form-select" required> <option value="">Select Rating</option> <?php for ($i = 1; $i <= 5; $i++): ?> <option value="<?= $i ?>" <?= ($testimonial['rating'] == $i) ? 'selected' : '' ?>><?= $i ?> </option> <?php endfor; ?> </select> </div> <div class="col-md-6 mb-3"> <label class="form-label">Upload Image</label> <input type="file" name="image" class="form-control" accept="image/*"> <?php if ($testimonial['image']): ?> <div class="mt-2"> <img src="<?= BASE_URL ?>/uploads/testimonials/<?= htmlspecialchars($testimonial['image']) ?>" alt="Image" style="height: 80px; border-radius: 5px;"> </div> <?php endif; ?> </div> <div class="col-12 mb-3"> <label class="form-label">Details</label> <textarea name="details" class="form-control" rows="4" required><?= htmlspecialchars($testimonial['details'] ?? '') ?></textarea> </div> <div class="col-12"> <button type="submit" class="btn btn-primary"><?= $editing ? 'Update' : 'Submit' ?> Testimonial</button> </div> </div> </form> </div> </div> </div> </main> <script> setTimeout(() => { const alert = document.querySelector('.fade-alert'); if (alert) { alert.style.transition = 'opacity 0.5s'; alert.style.opacity = 0; setTimeout(() => alert.remove(), 500); } }, 2000); </script> <?php include 'views/admin/layout/footer.php'; ?>