:: **Zploit** v1.0 | Current Path: **/home/kreativepixelz/public_html/crm/**
:: Editing File: vcard_testimonial_edit.php
<?php ob_start(); include 'header.php'; $page_title = "Edit VCard Testimonial"; $page_parent = "VCards"; $page_parent_link = "vcard_testimonial_list.php"; include 'breadcrumb.php'; include 'menu.php'; $message = ""; /* ✅ Validate ID */ if (!isset($_GET['id']) || !is_numeric($_GET['id'])) { header("Location: vcard_testimonial_list.php?msg=Invalid Testimonial ID"); exit; } $id = intval($_GET['id']); /* ✅ Fetch testimonial */ $q = mysqli_query($conn, "SELECT * FROM vcard_testimonials WHERE id='$id'"); if (mysqli_num_rows($q) == 0) { header("Location: vcard_testimonial_list.php?msg=Testimonial Not Found"); exit; } $row = mysqli_fetch_assoc($q); /* ✅ Fetch card_slug (IMPORTANT) */ $vcard_q = mysqli_query( $conn, "SELECT card_slug FROM vcards WHERE id='{$row['vcard_id']}'" ); $vcard = mysqli_fetch_assoc($vcard_q); $slug = $vcard['card_slug']; $base_dir = "uploads/vcard/" . $slug . "/testimonial/"; /* Ensure folder exists */ if (!is_dir($base_dir)) { mkdir($base_dir, 0777, true); } /* ✅ Handle Update */ if ($_SERVER['REQUEST_METHOD'] === 'POST') { $vcard_id = intval($_POST['vcard_id']); $client_name = mysqli_real_escape_string($conn, $_POST['client_name']); $msg = mysqli_real_escape_string($conn, $_POST['message']); $status = intval($_POST['status']); if ($vcard_id == 0 || $client_name == '') { $message = "VCard and Client Name are required."; } /* Get NEW card_slug if VCard changed */ if ($message == '') { $vcard_q = mysqli_query( $conn, "SELECT card_slug FROM vcards WHERE id='$vcard_id'" ); $vcard = mysqli_fetch_assoc($vcard_q); if (!$vcard) { $message = "Invalid VCard selected."; } else { $slug = $vcard['card_slug']; $base_dir = "uploads/vcard/" . $slug . "/testimonial/"; if (!is_dir($base_dir)) { mkdir($base_dir, 0777, true); } } } /* Image handling */ $client_image = $row['client_image']; $allowed_ext = ['jpg','jpeg','png','webp']; if ($message == '' && !empty($_FILES['client_image']['name'])) { $ext = strtolower(pathinfo($_FILES['client_image']['name'], PATHINFO_EXTENSION)); if (!in_array($ext, $allowed_ext)) { $message = "Only JPG, PNG, WEBP images allowed."; } else { /* delete old image */ if ($client_image && file_exists($base_dir . $client_image)) { unlink($base_dir . $client_image); } $client_image = time() . '_' . rand(100,999) . '.' . $ext; move_uploaded_file( $_FILES['client_image']['tmp_name'], $base_dir . $client_image ); } } /* ✅ Update DB */ if ($message == '') { $sql = "UPDATE vcard_testimonials SET vcard_id = '$vcard_id', client_name = '$client_name', message = '$msg', client_image = '$client_image', status = '$status', updated_at = NOW() WHERE id = '$id'"; if (mysqli_query($conn, $sql)) { header("Location: vcard_testimonial_list.php?msg=Testimonial updated successfully"); exit; } else { $message = "Database Error: " . mysqli_error($conn); } } } ?> <!-- ✅ Page Body --> <div class="page-body"> <div class="container-fluid"> <div class="row"> <div class="col-sm-12"> <div class="card"> <div class="card-header pb-0 card-no-border"> <h2>Edit VCard Testimonial</h2> </div> <div class="card-body"> <?php if ($message): ?> <div class="alert alert-danger"><?= htmlspecialchars($message); ?></div> <?php endif; ?> <form method="POST" enctype="multipart/form-data"> <div class="row"> <div class="col-md-6"> <label class="form-label">Select VCard *</label> <select name="vcard_id" class="form-control" required> <?php $vcards = mysqli_query($conn, "SELECT id, full_name FROM vcards WHERE status=1"); while ($v = mysqli_fetch_assoc($vcards)) { $sel = ($v['id'] == $row['vcard_id']) ? 'selected' : ''; echo "<option value='{$v['id']}' $sel>" . htmlspecialchars($v['full_name']) . "</option>"; } ?> </select> </div> <div class="col-md-6"> <label class="form-label">Client Name *</label> <input type="text" name="client_name" class="form-control" value="<?= htmlspecialchars($row['client_name']); ?>" required> </div> <div class="col-md-12 mt-3"> <label class="form-label">Message</label> <textarea name="message" class="form-control" rows="4"><?= htmlspecialchars($row['message']); ?></textarea> </div> <div class="col-md-6 mt-3"> <label class="form-label">Client Image</label> <input type="file" name="client_image" class="form-control"> <?php if ($row['client_image']) : ?> <br> <img src="<?= htmlspecialchars($base_dir . $row['client_image']); ?>" height="60" style="border-radius:5px;"> <?php endif; ?> </div> <div class="col-md-6 mt-3"> <label class="form-label">Status</label> <select name="status" class="form-control"> <option value="1" <?= ($row['status']==1)?'selected':''; ?>>Active</option> <option value="0" <?= ($row['status']==0)?'selected':''; ?>>Inactive</option> </select> </div> </div> <br> <div class="text-start"> <button type="submit" class="btn btn-success">Update Testimonial</button> <a href="vcard_testimonial_list.php" class="btn btn-secondary">Cancel</a> </div> </form> </div> </div> </div> </div> </div> </div> <?php include 'footer.php'; ob_end_flush(); ?>