:: **Zploit** v1.0 | Current Path: **/home/kreativepixelz/tdrbazaar.com/crm/**
:: Editing File: blog_edit.php
<?php include "db.php"; ini_set('display_errors', 0); ini_set('display_startup_errors', 0); $success_message = ''; $error_message = ''; // Get Blog ID for Editing $blog_id = intval($_GET['id'] ?? 0); if ($blog_id <= 0) { header("Location: blog_list.php"); exit(); } // Fetch existing blog record $fetch_q = mysqli_query($conn, "SELECT * FROM blogs WHERE id = $blog_id"); if (mysqli_num_rows($fetch_q) === 0) { header("Location: blog_list.php"); exit(); } $blog = mysqli_fetch_assoc($fetch_q); // Handle Form Submission for Update if ($_SERVER['REQUEST_METHOD'] === 'POST') { $name = mysqli_real_escape_string($conn, $_POST['name'] ?? ''); $url = mysqli_real_escape_string($conn, $_POST['url'] ?? ''); $author_name = mysqli_real_escape_string($conn, $_POST['author_name'] ?? ''); $blog_date = !empty($_POST['blog_date']) ? $_POST['blog_date'] : NULL; $display_order = intval($_POST['display_order'] ?? 0); $status = mysqli_real_escape_string($conn, $_POST['status'] ?? 'Active'); $meta_keyword = mysqli_real_escape_string($conn, $_POST['meta_keyword'] ?? ''); $meta_description = mysqli_real_escape_string($conn, $_POST['meta_description'] ?? ''); $description = mysqli_real_escape_string($conn, $_POST['description'] ?? ''); $image_name = $blog['image']; // Keep existing image by default // Handle Image Upload if a new file is provided if (isset($_FILES['image']) && $_FILES['image']['error'] === UPLOAD_ERR_OK) { $file_tmp = $_FILES['image']['tmp_name']; $file_name = $_FILES['image']['name']; $file_ext = strtolower(pathinfo($file_name, PATHINFO_EXTENSION)); $allowed_ext = ['jpg', 'jpeg', 'png', 'webp']; if (in_array($file_ext, $allowed_ext)) { $slug_name = strtolower(trim(preg_replace('/[^A-Za-z0-9-]+/', '-', $name))); $image_name = $slug_name . '-' . rand(1000, 9999) . '.' . $file_ext; $upload_dir = '../logo/blog/'; if (!is_dir($upload_dir)) { mkdir($upload_dir, 0777, true); } // Delete old image if exists if (!empty($blog['image']) && file_exists($upload_dir . $blog['image'])) { @unlink($upload_dir . $blog['image']); } move_uploaded_file($file_tmp, $upload_dir . $image_name); } } // Update Query $update_sql = "UPDATE blogs SET name = '$name', url = '$url', image = " . ($image_name ? "'$image_name'" : "NULL") . ", description = '$description', meta_keyword = '$meta_keyword', meta_description = '$meta_description', author_name = '$author_name', blog_date = " . ($blog_date ? "'$blog_date'" : "NULL") . ", display_order = '$display_order', status = '$status', updated_at = NOW() WHERE id = $blog_id"; if (mysqli_query($conn, $update_sql)) { header("Location: blogs_list.php?msg=updated_successfully"); exit(); } else { $error_message = "Error updating blog: " . mysqli_error($conn); } } include "header.php"; ?> <!-- Include CKEditor for Rich Text Box --> <script src="https://cdn.jsdelivr.net/npm/ckeditor@4.22.1/ckeditor.js"></script> <style> input[type="text"], input[type="number"], input[type="date"], input[type="file"] { height: 40px; padding: 0 12px; box-sizing: border-box; } </style> <div class="page-wrapper"> <div class="content pb-0"> <!-- Page Header & Breadcrumbs --> <div class="d-flex align-items-center justify-content-between gap-2 mb-4 flex-wrap"> <div> <h4 class="mb-1">Edit Blog</h4> <nav aria-label="breadcrumb"> <ol class="breadcrumb mb-0 p-0"> <li class="breadcrumb-item"><a href="dashboard.php">Home</a></li> <li class="breadcrumb-item"><a href="blogs_list.php">Manage Blogs</a></li> <li class="breadcrumb-item active" aria-current="page">Edit Blog</li> </ol> </nav> </div> <div> <a href="blog_list.php" class="btn btn-sm btn-outline-secondary"><i class="ti ti-arrow-left me-1"></i>Back to List</a> </div> </div> <?php if (!empty($error_message)) { ?> <div class="alert alert-danger alert-dismissible fade show" role="alert"> <?php echo $error_message; ?> <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button> </div> <?php } ?> <!-- Start Row Form Card --> <div class="row"> <div class="col-xl-12"> <div class="card border-0 shadow-sm"> <div class="card-header bg-light"> <h5 class="card-title mb-0 text-primary"><i class="ti ti-edit me-2"></i>Edit Blog Matrix</h5> </div> <div class="card-body"> <form action="" method="POST" enctype="multipart/form-data" class="needs-validation" novalidate> <div class="row g-3"> <!-- Blog Name & URL --> <div class="col-md-6"> <label class="form-label small fw-bold">Blog Title / Name *</label> <input type="text" name="name" class="form-control form-control-sm" value="<?php echo htmlspecialchars($blog['name']); ?>" required> </div> <div class="col-md-6"> <label class="form-label small fw-bold">URL Slug *</label> <input type="text" name="url" class="form-control form-control-sm" value="<?php echo htmlspecialchars($blog['url']); ?>" required> </div> <!-- Author Name & Blog Date --> <div class="col-md-6"> <label class="form-label small fw-bold">Author Name</label> <input type="text" name="author_name" class="form-control form-control-sm" value="<?php echo htmlspecialchars($blog['author_name']); ?>"> </div> <div class="col-md-6"> <label class="form-label small fw-bold">Blog Date</label> <input type="date" name="blog_date" class="form-control form-control-sm" value="<?php echo htmlspecialchars($blog['blog_date']); ?>"> </div> <!-- Image Upload & Display Order --> <div class="col-md-6"> <label class="form-label small fw-bold">Blog Image</label> <input type="file" name="image" class="form-control form-control-sm mb-1"> <?php if(!empty($blog['image'])) { ?> <div class="small text-muted">Current: <a href="../logo/blog/<?php echo $blog['image']; ?>" target="_blank"><?php echo $blog['image']; ?></a></div> <?php } ?> </div> <!-- <div class="col-md-6"> <label class="form-label small fw-bold">Display Order</label> <input type="number" name="display_order" class="form-control form-control-sm" value="<?php echo intval($blog['display_order']); ?>"> </div> --> <!-- Status Selection --> <div class="col-md-6"> <label class="form-label small fw-bold">Status</label> <select name="status" class="form-select form-select-sm"> <option value="Active" <?php echo ($blog['status'] == 'Active') ? 'selected' : ''; ?>>Active</option> <option value="Inactive" <?php echo ($blog['status'] == 'Inactive') ? 'selected' : ''; ?>>Inactive</option> </select> </div> <!-- Meta Keywords --> <div class="col-12"> <label class="form-label small fw-bold">Meta Keywords</label> <textarea name="meta_keyword" class="form-control form-control-sm" rows="2"><?php echo htmlspecialchars($blog['meta_keyword']); ?></textarea> </div> <!-- Meta Description --> <div class="col-12"> <label class="form-label small fw-bold">Meta Description</label> <textarea name="meta_description" class="form-control form-control-sm" rows="2"><?php echo htmlspecialchars($blog['meta_description']); ?></textarea> </div> <!-- Description Box (Rich Text Editor Enabled) --> <div class="col-12"> <label class="form-label small fw-bold">Description (Rich Text)</label> <textarea name="description" id="editor" class="form-control form-control-sm" rows="6"><?php echo htmlspecialchars($blog['description']); ?></textarea> </div> </div> <!-- Action Buttons --> <div class="mt-4 pt-3 border-top text-end"> <a href="blogs_list.php" class="btn btn-sm btn-outline-secondary me-2">Cancel</a> <button type="submit" class="btn btn-sm btn-primary px-4"><i class="ti ti-device-floppy me-1"></i>Update Blog Record</button> </div> </form> </div> <!-- end card-body --> </div> <!-- end card --> </div> <!-- end col --> </div> <!-- end row --> </div> <!-- End Content --> <?php include "footer-heading.php"; ?> </div> <script> // Initialize CKEditor on description field // CKEDITOR.replace('editor'); </script> <script src="https://code.jquery.com/jquery-3.7.1.min.js"></script> <!-- Include CKEditor for Rich Text Box --> <script src="https://cdn.jsdelivr.net/npm/ckeditor@4.22.1/ckeditor.js"></script> <script> // Initialize CKEditor on description field //CKEDITOR.replace('editor'); </script> <!-- 2. Bootstrap JS (if needed for your theme) --> <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script> <!-- 3. Summernote CSS & JS CDN --> <link href="https://cdn.jsdelivr.net/npm/summernote@0.8.20/dist/summernote-lite.min.css" rel="stylesheet"> <script src="https://cdn.jsdelivr.net/npm/summernote@0.8.20/dist/summernote-lite.min.js"></script> <script> jQuery(document).ready(function($) { jQuery('#editor').summernote({ placeholder: 'Write comprehensive blog text here...', tabsize: 2, height: 250, toolbar: [ ['style', ['style']], ['font', ['bold', 'underline', 'clear']], ['color', ['color']], ['para', ['ul', 'ol', 'paragraph']], ['table', ['table']], ['insert', ['link', 'picture', 'video']], ['view', ['fullscreen', 'codeview', 'help']] ] }); }); </script> <?php include "footer.php"; ?> <?php ob_end_flush(); ?>