:: **Zploit** v1.0 | Current Path: **/home/kreativepixelz/www/kreativecrm/**
:: Editing File: quotation_edit.php
<?php ob_start(); include 'header.php'; $page_title = "Add Quotation"; $page_parent = "Quotations"; $page_parent_link = "quotation.php"; include 'breadcrumb.php'; include 'menu.php'; // ✅ Page setup $page_title = "Edit Quotation"; $page_parent = "Quotation"; $page_parent_link = "quotation_list.php"; $message = ""; $quotation = null; // default // ✅ Validate and fetch quotation data if (isset($_GET['id']) && is_numeric($_GET['id'])) { $q_id = intval($_GET['id']); $query = "SELECT * FROM qutation WHERE id = $q_id"; $result = mysqli_query($conn, $query); if ($result && mysqli_num_rows($result) > 0) { $quotation = mysqli_fetch_assoc($result); } else { $message = "Quotation not found."; } } else { $message = "Invalid Quotation ID."; } // ✅ Handle form submission if ($_SERVER['REQUEST_METHOD'] === 'POST' && $quotation) { $name = mysqli_real_escape_string($conn, $_POST['name']); $pdf_path = $quotation['pdf_path']; // default to old path // ✅ Handle file upload if new file is selected if (!empty($_FILES['pdf_file']['name'])) { $target_dir = "uploads/quotation/"; if (!is_dir($target_dir)) { mkdir($target_dir, 0777, true); } $file_name = basename($_FILES['pdf_file']['name']); $file_ext = strtolower(pathinfo($file_name, PATHINFO_EXTENSION)); if ($file_ext === 'pdf') { $new_file_name = time() . "_" . preg_replace("/[^a-zA-Z0-9_\.-]/", "_", $file_name); $target_file = $target_dir . $new_file_name; if (move_uploaded_file($_FILES['pdf_file']['tmp_name'], $target_file)) { $pdf_path = $new_file_name; // Optional: delete old file $old_file = "uploads/quotation/" . $quotation['pdf_path']; if (!empty($quotation['pdf_path']) && file_exists($old_file)) { unlink($old_file); } } else { $message = "Error uploading new PDF file."; } } else { $message = "Only PDF files are allowed."; } } // ✅ Update in database if no error if (empty($message)) { $sql = "UPDATE qutation SET name = '$name', pdf_path = '$new_file_name', updated_at = NOW() WHERE id = $q_id"; if (mysqli_query($conn, $sql)) { header("Location: quotation.php?msg=Quotation updated successfully"); exit; } else { $message = "Error updating quotation: " . 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 Quotation</h2> </div> <div class="card-body"> <?php if ($message): ?> <div class="alert alert-warning"><?= htmlspecialchars($message); ?></div> <?php endif; ?> <?php if ($quotation): ?> <form method="POST" enctype="multipart/form-data"> <input type="hidden" name="id" class="form-control" value="<?= htmlspecialchars($quotation['id']); ?>" > <div class="row"> <div class="col-md-6"> <label class="form-label">Quotation Name</label> <input type="text" name="name" class="form-control" value="<?= htmlspecialchars($quotation['name']); ?>" required> </div> <div class="col-md-6"> <label class="form-label">Upload New PDF</label> <input type="file" name="pdf_file" class="form-control" accept=".pdf"> </div> <?php // ✅ Display current PDF if exists if (!empty($quotation['pdf_path'])) { $pdf_path = "uploads/quotations/" . $quotation['pdf_path']; $base_url = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://{$_SERVER['HTTP_HOST']}" . dirname($_SERVER['SCRIPT_NAME']) . "/"; $full_pdf_url = $base_url . $pdf_path; ?> <div class="col-md-6 mt-3"> <label class="form-label">Current PDF:</label><br> <a href="<?= $full_pdf_url; ?>" target="_blank" class="btn btn-primary btn-sm"> View PDF </a> </div> <?php } ?> </div> <br> <div class="text-start"> <button type="submit" class="btn btn-success">Update Quotation</button> <a href="quotation.php" class="btn btn-secondary">Cancel</a> </div> </form> <?php endif; ?> </div> </div> </div> </div> </div> </div> <?php include 'footer.php'; ob_end_flush(); ?>