:: **Zploit** v1.0 | Current Path: **/home/kreativepixelz/tdrbazaar.com/crm/**
:: Editing File: blog_add.php
<?php // Initialize session and database connection if not already included //if (session_status() === PHP_SESSION_NONE) { // session_start(); //} include "db.php"; // Adjust to your actual DB connection file if named differently ini_set('display_errors', 0); ini_set('display_startup_errors', 0); //error_reporting(E_ALL); // Handle Form Submission logic $success_message = ''; $error_message = ''; if ($_SERVER['REQUEST_METHOD'] === 'POST') { // Sanitize and capture inputs based on blogs table schema $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'] ?? ''); // Rich text content // Handle Image Upload // Handle Image Upload & Dynamic Name Generation based on Blog Title $image_name = ''; 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)) { // Convert blog title to a clean slug/file-name format (e.g., "My First Blog!" becomes "my-first-blog") $slug_name = strtolower(trim(preg_replace('/[^A-Za-z0-9-]+/', '-', $name))); // Generate final image name using the blog title slug + unique random suffix + extension $image_name = $slug_name . '-' . rand(1000, 9999) . '.' . $file_ext; // Specified upload directory $upload_dir = '../logo/blog/'; if (!is_dir($upload_dir)) { mkdir($upload_dir, 0777, true); } // Move uploaded file to destination move_uploaded_file($file_tmp, $upload_dir . $image_name); } } // Insert Query for blogs table $insert_sql = "INSERT INTO blogs ( name, url, image, description, meta_keyword, meta_description, author_name, blog_date, display_order, status, created_at, updated_at ) VALUES ( '$name', '$url', " . ($image_name ? "'$image_name'" : "NULL") . ", '$description', '$meta_keyword', '$meta_description', '$author_name', " . ($blog_date ? "'$blog_date'" : "NULL") . ", '$display_order', '$status', NOW(), NOW() )"; if (mysqli_query($conn, $insert_sql)) { header("Location: blogs_list.php?msg=created_successfully"); exit(); } else { $error_message = "Error recording blog: " . mysqli_error($conn); } } include "header.php"; ?> <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">Add New 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">Add 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-news me-2"></i>Blog Information 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" placeholder="Enter blog title" 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" placeholder="e.g. medical-equipment-trends" 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" placeholder="Enter 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"> </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"> </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="0"> </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" selected>Active</option> <option value="Inactive">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" placeholder="Comma separated keywords"></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" placeholder="Brief search engine snippet"></textarea> </div> <!-- Description Box (Rich Text Editor Enabled) --> <div class="col-12"> <label class="form-label small fw-bold">Description</label> <textarea name="description" id="editor" class="form-control form-control-sm" rows="6" placeholder="Write comprehensive blog text here..."></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>Save 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> <?php include "footer.php"; ?> <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 ob_end_flush(); ?>