Hackfut Security File Manager
Current Path:
/home/u126195517/domains/foodstamping.in/public_html/admin
home
/
u126195517
/
domains
/
foodstamping.in
/
public_html
/
admin
/
📁
..
📁
assets
📄
categories.php
(15.94 KB)
📄
get-product.php
(604 B)
📄
index.php
(7.83 KB)
📄
login.php
(4.52 KB)
📄
logout.php
(557 B)
📄
orders.php
(10.34 KB)
📄
product-action.php
(2.63 KB)
📄
product-images.php
(14.15 KB)
📄
product-save.php
(6.86 KB)
📄
product-specifications.php
(11.11 KB)
📄
products.php
(48.18 KB)
📄
reviews.php
(12.46 KB)
📄
specifications.php
(14.72 KB)
Editing: products.php
<?php session_start(); require_once '../config/database.php'; require_once '../models/Product.php'; if(!isset($_SESSION['admin_id'])) { header("Location: login.php"); exit(); } $database = new Database(); $db = $database->getConnection(); // Handle product actions if(isset($_POST['action'])) { $action = $_POST['action']; switch($action) { case 'toggle_status': $id = $_POST['product_id']; $status = $_POST['status']; $query = "UPDATE products SET status = :status WHERE id = :id"; $stmt = $db->prepare($query); $stmt->bindParam(':status', $status); $stmt->bindParam(':id', $id); if($stmt->execute()) { echo json_encode(['success' => true]); } else { echo json_encode(['success' => false]); } exit(); break; case 'toggle_featured': $id = $_POST['product_id']; $featured = $_POST['featured']; $query = "UPDATE products SET featured = :featured WHERE id = :id"; $stmt = $db->prepare($query); $stmt->bindParam(':featured', $featured); $stmt->bindParam(':id', $id); if($stmt->execute()) { echo json_encode(['success' => true]); } else { echo json_encode(['success' => false]); } exit(); break; case 'delete': $id = $_POST['product_id']; $query = "UPDATE products SET status = 0 WHERE id = :id"; $stmt = $db->prepare($query); $stmt->bindParam(':id', $id); if($stmt->execute()) { $_SESSION['message'] = "Product deleted successfully!"; $_SESSION['message_type'] = "success"; } header("Location: products.php"); exit(); break; case 'bulk_delete': $ids = $_POST['product_ids']; $placeholders = str_repeat('?,', count($ids) - 1) . '?'; $query = "UPDATE products SET status = 0 WHERE id IN ($placeholders)"; $stmt = $db->prepare($query); if($stmt->execute($ids)) { echo json_encode(['success' => true, 'message' => 'Products deleted successfully']); } else { echo json_encode(['success' => false]); } exit(); break; } } // Get filter parameters $category_filter = isset($_GET['category']) ? $_GET['category'] : ''; $status_filter = isset($_GET['status']) ? $_GET['status'] : ''; $stock_filter = isset($_GET['stock']) ? $_GET['stock'] : ''; $search = isset($_GET['search']) ? $_GET['search'] : ''; // Build query with filters $query = "SELECT p.*, c.name as category_name, (SELECT COUNT(*) FROM product_images WHERE product_id = p.id) as image_count, (SELECT COUNT(*) FROM product_specifications WHERE product_id = p.id) as spec_count FROM products p LEFT JOIN categories c ON p.category_id = c.id WHERE 1=1"; $params = []; if($category_filter) { $query .= " AND p.category_id = :category"; $params[':category'] = $category_filter; } if($status_filter !== '') { $query .= " AND p.status = :status"; $params[':status'] = $status_filter; } if($stock_filter == 'out') { $query .= " AND p.stock_quantity = 0"; } elseif($stock_filter == 'low') { $query .= " AND p.stock_quantity > 0 AND p.stock_quantity < 10"; } if($search) { $query .= " AND (p.name LIKE :search OR p.description LIKE :search)"; $params[':search'] = "%$search%"; } $query .= " ORDER BY p.created_at DESC"; $stmt = $db->prepare($query); foreach($params as $key => $value) { $stmt->bindValue($key, $value); } $stmt->execute(); $products = $stmt->fetchAll(PDO::FETCH_ASSOC); // Get categories for filter $cat_query = "SELECT * FROM categories WHERE status = 1 ORDER BY name"; $cat_stmt = $db->prepare($cat_query); $cat_stmt->execute(); $categories = $cat_stmt->fetchAll(PDO::FETCH_ASSOC); // Get statistics $stats_query = "SELECT COUNT(*) as total, SUM(CASE WHEN status = 1 THEN 1 ELSE 0 END) as active, SUM(CASE WHEN stock_quantity = 0 THEN 1 ELSE 0 END) as out_of_stock, SUM(CASE WHEN stock_quantity > 0 AND stock_quantity < 10 THEN 1 ELSE 0 END) as low_stock, SUM(CASE WHEN featured = 1 THEN 1 ELSE 0 END) as featured FROM products"; $stats_stmt = $db->prepare($stats_query); $stats_stmt->execute(); $stats = $stats_stmt->fetch(PDO::FETCH_ASSOC); ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Manage Products - Admin Panel</title> <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet"> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css"> <link rel="stylesheet" href="https://cdn.datatables.net/1.11.5/css/dataTables.bootstrap5.min.css"> <script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script> <style> .sidebar { min-height: 100vh; background: #343a40; } .sidebar .nav-link { color: #fff; padding: 15px 20px; } .sidebar .nav-link:hover { background: #495057; } .sidebar .nav-link.active { background: #007bff; } .stat-card { border-radius: 10px; padding: 15px; margin-bottom: 20px; color: white; } .product-thumb { width: 50px; height: 50px; object-fit: cover; border-radius: 5px; cursor: pointer; } .badge-stock { font-size: 11px; } .action-buttons .btn { padding: 5px 10px; margin: 0 2px; } .filter-section { background: #f8f9fa; padding: 15px; border-radius: 10px; margin-bottom: 20px; } .bulk-actions { display: none; padding: 10px; background: #e9ecef; border-radius: 5px; margin-bottom: 10px; } .featured-star { color: gold; cursor: pointer; } .switch { position: relative; display: inline-block; width: 50px; height: 24px; } .switch input { opacity: 0; width: 0; height: 0; } .slider { position: absolute; cursor: pointer; top: 0; left: 0; right: 0; bottom: 0; background-color: #ccc; transition: .4s; border-radius: 24px; } .slider:before { position: absolute; content: ""; height: 16px; width: 16px; left: 4px; bottom: 4px; background-color: white; transition: .4s; border-radius: 50%; } input:checked + .slider { background-color: #2196F3; } input:checked + .slider:before { transform: translateX(26px); } </style> </head> <body> <div class="container-fluid"> <div class="row"> <!-- Sidebar --> <nav class="col-md-2 d-md-block sidebar"> <div class="position-sticky"> <h4 class="text-white p-3">Admin Panel</h4> <ul class="nav flex-column"> <li class="nav-item"> <a class="nav-link" href="index.php"> <i class="fas fa-tachometer-alt"></i> Dashboard </a> </li> <li class="nav-item"> <a class="nav-link active" href="products.php"> <i class="fas fa-box"></i> Products </a> </li> <li class="nav-item"> <a class="nav-link" href="categories.php"> <i class="fas fa-tags"></i> Categories </a> </li> <li class="nav-item"> <a class="nav-link" href="orders.php"> <i class="fas fa-shopping-cart"></i> Orders </a> </li> <li class="nav-item"> <a class="nav-link" href="reviews.php"> <i class="fas fa-star"></i> Reviews </a> </li> <li class="nav-item"> <a class="nav-link" href="specifications.php"> <i class="fas fa-list"></i> Specifications </a> </li> <li class="nav-item"> <a class="nav-link" href="logout.php"> <i class="fas fa-sign-out-alt"></i> Logout </a> </li> </ul> </div> </nav> <!-- Main Content --> <main class="col-md-10 ms-sm-auto px-md-4"> <div class="d-flex justify-content-between flex-wrap flex-md-nowrap align-items-center pt-3 pb-2 mb-3 border-bottom"> <h1 class="h2">Manage Products</h1> <div class="btn-toolbar mb-2 mb-md-0"> <div class="btn-group me-2"> <button type="button" class="btn btn-sm btn-outline-secondary" onclick="exportProducts()"> <i class="fas fa-download"></i> Export </button> <button type="button" class="btn btn-sm btn-outline-secondary" data-bs-toggle="modal" data-bs-target="#importModal"> <i class="fas fa-upload"></i> Import </button> </div> <button type="button" class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#addProductModal"> <i class="fas fa-plus"></i> Add New Product </button> </div> </div> <!-- Statistics Cards --> <div class="row mb-4"> <div class="col-md-2"> <div class="stat-card bg-primary"> <h6>Total Products</h6> <h3><?php echo $stats['total']; ?></h3> </div> </div> <div class="col-md-2"> <div class="stat-card bg-success"> <h6>Active</h6> <h3><?php echo $stats['active']; ?></h3> </div> </div> <div class="col-md-2"> <div class="stat-card bg-danger"> <h6>Out of Stock</h6> <h3><?php echo $stats['out_of_stock']; ?></h3> </div> </div> <div class="col-md-2"> <div class="stat-card bg-warning"> <h6>Low Stock</h6> <h3><?php echo $stats['low_stock']; ?></h3> </div> </div> <div class="col-md-2"> <div class="stat-card bg-info"> <h6>Featured</h6> <h3><?php echo $stats['featured']; ?></h3> </div> </div> </div> <?php if(isset($_SESSION['message'])): ?> <div class="alert alert-<?php echo $_SESSION['message_type']; ?> alert-dismissible fade show" role="alert"> <?php echo $_SESSION['message']; unset($_SESSION['message']); unset($_SESSION['message_type']); ?> <button type="button" class="btn-close" data-bs-dismiss="alert"></button> </div> <?php endif; ?> <!-- Filters --> <div class="filter-section"> <form method="GET" class="row g-3"> <div class="col-md-3"> <input type="text" class="form-control" name="search" placeholder="Search products..." value="<?php echo htmlspecialchars($search); ?>"> </div> <div class="col-md-2"> <select class="form-select" name="category"> <option value="">All Categories</option> <?php foreach($categories as $cat): ?> <option value="<?php echo $cat['id']; ?>" <?php echo $category_filter == $cat['id'] ? 'selected' : ''; ?>> <?php echo htmlspecialchars($cat['name']); ?> </option> <?php endforeach; ?> </select> </div> <div class="col-md-2"> <select class="form-select" name="status"> <option value="">All Status</option> <option value="1" <?php echo $status_filter === '1' ? 'selected' : ''; ?>>Active</option> <option value="0" <?php echo $status_filter === '0' ? 'selected' : ''; ?>>Inactive</option> </select> </div> <div class="col-md-2"> <select class="form-select" name="stock"> <option value="">All Stock</option> <option value="out" <?php echo $stock_filter == 'out' ? 'selected' : ''; ?>>Out of Stock</option> <option value="low" <?php echo $stock_filter == 'low' ? 'selected' : ''; ?>>Low Stock</option> </select> </div> <div class="col-md-2"> <button type="submit" class="btn btn-primary w-100"> <i class="fas fa-filter"></i> Filter </button> </div> <div class="col-md-1"> <a href="products.php" class="btn btn-secondary w-100"> <i class="fas fa-redo"></i> Reset </a> </div> </form> </div> <!-- Bulk Actions --> <div class="bulk-actions" id="bulkActions"> <div class="d-flex justify-content-between align-items-center"> <div> <span id="selectedCount">0</span> products selected </div> <div> <button class="btn btn-sm btn-danger" onclick="bulkDelete()"> <i class="fas fa-trash"></i> Delete Selected </button> <button class="btn btn-sm btn-warning" onclick="bulkUpdateStock()"> <i class="fas fa-boxes"></i> Update Stock </button> <button class="btn btn-sm btn-info" onclick="bulkUpdateCategory()"> <i class="fas fa-tags"></i> Change Category </button> </div> </div> </div> <!-- Products Table --> <div class="card"> <div class="card-body"> <div class="table-responsive"> <table id="productsTable" class="table table-hover"> <thead> <tr> <th> <input type="checkbox" id="selectAll" class="form-check-input"> </th> <th>ID</th> <th>Image</th> <th>Name</th> <th>Category</th> <th>Price</th> <th>Stock</th> <th>Rating</th> <th>Views</th> <th>Featured</th> <th>Status</th> <th>Actions</th> </tr> </thead> <tbody> <?php foreach($products as $product): ?> <?php $discount = 0; if($product['original_price'] > $product['price']) { $discount = round((($product['original_price'] - $product['price']) / $product['original_price']) * 100); } ?> <tr> <td> <input type="checkbox" class="form-check-input product-checkbox" value="<?php echo $product['id']; ?>"> </td> <td><?php echo $product['id']; ?></td> <td> <img src="../<?php echo $product['image_primary']; ?>" alt="<?php echo htmlspecialchars($product['name']); ?>" class="product-thumb" onclick="viewProduct(<?php echo $product['id']; ?>)" data-bs-toggle="tooltip" title="Click to view"> <?php if($product['image_count'] > 0): ?> <span class="badge bg-secondary badge-stock"> <?php echo $product['image_count']; ?> imgs </span> <?php endif; ?> </td> <td> <strong><?php echo htmlspecialchars($product['name']); ?></strong> <?php if($discount > 0): ?> <span class="badge bg-danger"><?php echo $discount; ?>% OFF</span> <?php endif; ?> <?php if($product['spec_count'] > 0): ?> <span class="badge bg-info badge-stock"> <?php echo $product['spec_count']; ?> specs </span> <?php endif; ?> </td> <td><?php echo htmlspecialchars($product['category_name'] ?: 'Uncategorized'); ?></td> <td> <strong>Rs. <?php echo number_format($product['price'], 2); ?></strong> <?php if($product['original_price'] > $product['price']): ?> <br><del class="text-muted">Rs. <?php echo number_format($product['original_price'], 2); ?></del> <?php endif; ?> </td> <td> <?php if($product['stock_quantity'] == 0): ?> <span class="badge bg-danger">Out of Stock</span> <?php elseif($product['stock_quantity'] < 10): ?> <span class="badge bg-warning"><?php echo $product['stock_quantity']; ?> (Low)</span> <?php else: ?> <span class="badge bg-success"><?php echo $product['stock_quantity']; ?></span> <?php endif; ?> </td> <td> <?php if($product['average_rating'] > 0): ?> <span class="text-warning"> <?php echo number_format($product['average_rating'], 1); ?> <i class="fas fa-star"></i> </span> <br> <small class="text-muted">(<?php echo $product['total_reviews']; ?>)</small> <?php else: ?> <span class="text-muted">No ratings</span> <?php endif; ?> </td> <td> <span class="badge bg-secondary"><?php echo $product['views']; ?></span> </td> <td> <i class="fas fa-star featured-star <?php echo $product['featured'] ? '' : 'text-muted'; ?>" onclick="toggleFeatured(<?php echo $product['id']; ?>, <?php echo $product['featured'] ? 0 : 1; ?>)" title="<?php echo $product['featured'] ? 'Remove from featured' : 'Add to featured'; ?>"></i> </td> <td> <label class="switch"> <input type="checkbox" <?php echo $product['status'] ? 'checked' : ''; ?> onchange="toggleStatus(<?php echo $product['id']; ?>, this.checked ? 1 : 0)"> <span class="slider"></span> </label> </td> <td> <div class="action-buttons"> <a href="../product-single.php?id=<?php echo $product['id']; ?>" target="_blank" class="btn btn-sm btn-success" data-bs-toggle="tooltip" title="View"> <i class="fas fa-eye"></i> </a> <button class="btn btn-sm btn-info" onclick="editProduct(<?php echo $product['id']; ?>)" data-bs-toggle="tooltip" title="Edit"> <i class="fas fa-edit"></i> </button> <button class="btn btn-sm btn-warning" onclick="manageImages(<?php echo $product['id']; ?>)" data-bs-toggle="tooltip" title="Images"> <i class="fas fa-images"></i> </button> <button class="btn btn-sm btn-primary" onclick="manageSpecs(<?php echo $product['id']; ?>)" data-bs-toggle="tooltip" title="Specifications"> <i class="fas fa-list"></i> </button> <button type="button" class="btn btn-danger btn-sm" onclick="deleteProduct(<?php echo $product['id']; ?>)"> <i class="fas fa-trash"></i> </button> </div> </td> </tr> <?php endforeach; ?> </tbody> </table> </div> </div> </div> </main> </div> </div> <!-- Add/Edit Product Modal --> <div class="modal fade" id="addProductModal" tabindex="-1"> <div class="modal-dialog modal-xl"> <div class="modal-content"> <div class="modal-header"> <h5 class="modal-title" id="modalTitle">Add New Product</h5> <button type="button" class="btn-close" data-bs-dismiss="modal"></button> </div> <form action="product-save.php" method="POST" enctype="multipart/form-data" id="productForm"> <input type="hidden" name="product_id" id="product_id"> <div class="modal-body"> <ul class="nav nav-tabs" id="productTabs" role="tablist"> <li class="nav-item"> <a class="nav-link active" data-bs-toggle="tab" href="#basic">Basic Info</a> </li> <li class="nav-item"> <a class="nav-link" data-bs-toggle="tab" href="#pricing">Pricing & Stock</a> </li> <li class="nav-item"> <a class="nav-link" data-bs-toggle="tab" href="#images">Images</a> </li> <li class="nav-item"> <a class="nav-link" data-bs-toggle="tab" href="#seo">SEO</a> </li> </ul> <div class="tab-content mt-3"> <!-- Basic Info Tab --> <div class="tab-pane fade show active" id="basic"> <div class="row"> <div class="col-md-6 mb-3"> <label for="name" class="form-label">Product Name *</label> <input type="text" class="form-control" id="name" name="name" required> </div> <div class="col-md-6 mb-3"> <label for="category_id" class="form-label">Category *</label> <select class="form-select" id="category_id" name="category_id" required> <option value="">Select Category</option> <?php foreach($categories as $cat): ?> <option value="<?php echo $cat['id']; ?>"> <?php echo htmlspecialchars($cat['name']); ?> </option> <?php endforeach; ?> </select> </div> <div class="col-md-12 mb-3"> <label for="short_description" class="form-label">Short Description</label> <input type="text" class="form-control" id="short_description" name="short_description" maxlength="200"> </div> <div class="col-md-12 mb-3"> <label for="description" class="form-label">Full Description</label> <textarea class="form-control" id="description" name="description" rows="4"></textarea> </div> <div class="col-md-12 mb-3"> <label for="highlights" class="form-label">Highlights (one per line)</label> <textarea class="form-control" id="highlights" name="highlights" rows="3" placeholder="Special offer Free shipping 1 year warranty"></textarea> </div> <div class="col-md-6"> <div class="form-check"> <input class="form-check-input" type="checkbox" id="featured" name="featured" value="1"> <label class="form-check-label" for="featured"> Featured Product </label> </div> </div> <div class="col-md-6"> <div class="form-check"> <input class="form-check-input" type="checkbox" id="status" name="status" value="1" checked> <label class="form-check-label" for="status"> Active </label> </div> </div> </div> </div> <!-- Pricing & Stock Tab --> <div class="tab-pane fade" id="pricing"> <div class="row"> <div class="col-md-4 mb-3"> <label for="price" class="form-label">Selling Price *</label> <div class="input-group"> <span class="input-group-text">Rs.</span> <input type="number" class="form-control" id="price" name="price" step="0.01" required> </div> </div> <div class="col-md-4 mb-3"> <label for="original_price" class="form-label">Original Price</label> <div class="input-group"> <span class="input-group-text">Rs.</span> <input type="number" class="form-control" id="original_price" name="original_price" step="0.01"> </div> </div> <div class="col-md-4 mb-3"> <label for="discount_calc" class="form-label">Discount</label> <div class="input-group"> <input type="text" class="form-control" id="discount_calc" readonly> <span class="input-group-text">%</span> </div> </div> <div class="col-md-6 mb-3"> <label for="stock_quantity" class="form-label">Stock Quantity *</label> <input type="number" class="form-control" id="stock_quantity" name="stock_quantity" required> </div> <div class="col-md-6 mb-3"> <label for="low_stock_alert" class="form-label">Low Stock Alert At</label> <input type="number" class="form-control" id="low_stock_alert" name="low_stock_alert" value="10"> </div> </div> </div> <!-- Images Tab --> <div class="tab-pane fade" id="images"> <div class="row"> <div class="col-md-6 mb-3"> <label for="image_primary" class="form-label">Primary Image *</label> <input type="file" class="form-control" id="image_primary" name="image_primary" accept="image/*"> <div id="primary_preview" class="mt-2"></div> </div> <div class="col-md-6 mb-3"> <label for="image_secondary" class="form-label">Secondary Image</label> <input type="file" class="form-control" id="image_secondary" name="image_secondary" accept="image/*"> <div id="secondary_preview" class="mt-2"></div> </div> <div class="col-md-12 mb-3"> <label for="gallery_images" class="form-label">Gallery Images</label> <input type="file" class="form-control" id="gallery_images" name="gallery_images[]" accept="image/*" multiple> <div id="gallery_preview" class="mt-2 d-flex flex-wrap"></div> </div> </div> </div> <!-- SEO Tab --> <div class="tab-pane fade" id="seo"> <div class="row"> <div class="col-md-12 mb-3"> <label for="slug" class="form-label">URL Slug</label> <input type="text" class="form-control" id="slug" name="slug"> <small class="text-muted">Leave empty to auto-generate from product name</small> </div> <div class="col-md-12 mb-3"> <label for="meta_title" class="form-label">Meta Title</label> <input type="text" class="form-control" id="meta_title" name="meta_title"> </div> <div class="col-md-12 mb-3"> <label for="meta_description" class="form-label">Meta Description</label> <textarea class="form-control" id="meta_description" name="meta_description" rows="3"></textarea> </div> <div class="col-md-12 mb-3"> <label for="meta_keywords" class="form-label">Meta Keywords</label> <input type="text" class="form-control" id="meta_keywords" name="meta_keywords" placeholder="keyword1, keyword2, keyword3"> </div> </div> </div> </div> </div> <div class="modal-footer"> <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Cancel</button> <button type="submit" name="action" value="save" class="btn btn-primary"> <i class="fas fa-save"></i> Save Product </button> </div> </form> </div> </div> </div> <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script> <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js"></script> <script src="https://cdn.datatables.net/1.11.5/js/jquery.dataTables.min.js"></script> <script src="https://cdn.datatables.net/1.11.5/js/dataTables.bootstrap5.min.js"></script> <script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script> <script> $(document).ready(function() { // Initialize DataTable $('#productsTable').DataTable({ pageLength: 25, order: [[1, 'desc']], columnDefs: [ { orderable: false, targets: [0, 2, -1] } ] }); // Initialize tooltips var tooltipTriggerList = [].slice.call(document.querySelectorAll('[data-bs-toggle="tooltip"]')) var tooltipList = tooltipTriggerList.map(function (tooltipTriggerEl) { return new bootstrap.Tooltip(tooltipTriggerEl) }); // Select all checkbox $('#selectAll').on('change', function() { $('.product-checkbox').prop('checked', this.checked); updateBulkActions(); }); // Individual checkbox $('.product-checkbox').on('change', function() { updateBulkActions(); }); // Calculate discount on price change $('#price, #original_price').on('input', function() { var price = parseFloat($('#price').val()) || 0; var original = parseFloat($('#original_price').val()) || 0; if(original > price && original > 0) { var discount = ((original - price) / original * 100).toFixed(1); $('#discount_calc').val(discount); } else { $('#discount_calc').val('0'); } }); // Image preview $('#image_primary').on('change', function() { previewImage(this, '#primary_preview'); }); $('#image_secondary').on('change', function() { previewImage(this, '#secondary_preview'); }); $('#gallery_images').on('change', function() { previewMultipleImages(this, '#gallery_preview'); }); }); function updateBulkActions() { var checkedCount = $('.product-checkbox:checked').length; if(checkedCount > 0) { $('#bulkActions').show(); $('#selectedCount').text(checkedCount); } else { $('#bulkActions').hide(); } } function toggleStatus(productId, status) { $.post('products.php', { action: 'toggle_status', product_id: productId, status: status }, function(response) { if(response.success) { Swal.fire({ icon: 'success', title: 'Status Updated', toast: true, position: 'top-end', showConfirmButton: false, timer: 2000 }); } }, 'json'); } function toggleFeatured(productId, featured) { $.post('products.php', { action: 'toggle_featured', product_id: productId, featured: featured }, function(response) { if(response.success) { location.reload(); } }, 'json'); } function editProduct(productId) { // Load product data via AJAX $.get('get-product.php', {id: productId}, function(product) { $('#modalTitle').text('Edit Product'); $('#product_id').val(product.id); $('#name').val(product.name); $('#category_id').val(product.category_id); $('#short_description').val(product.short_description); $('#description').val(product.description); $('#highlights').val(product.highlights); $('#price').val(product.price); $('#original_price').val(product.original_price); $('#stock_quantity').val(product.stock_quantity); $('#low_stock_alert').val(product.low_stock_alert); $('#slug').val(product.slug); $('#featured').prop('checked', product.featured == 1); $('#status').prop('checked', product.status == 1); // Update discount field var price = parseFloat(product.price) || 0; var original = parseFloat(product.original_price) || 0; $('#discount_calc').val(original > price && original > 0 ? ((original - price)/original*100).toFixed(1) : 0); // Show modal using Bootstrap 5 API var modalEl = document.getElementById('addProductModal'); var modal = new bootstrap.Modal(modalEl); modal.show(); }, 'json'); } function viewProduct(productId) { window.open('../product-single.php?id=' + productId, '_blank'); } function manageImages(productId) { window.location.href = 'product-images.php?id=' + productId; } function manageSpecs(productId) { window.location.href = 'product-specifications.php?id=' + productId; } function bulkDelete() { var selected = $('.product-checkbox:checked').map(function() { return $(this).val(); }).get(); Swal.fire({ title: 'Are you sure?', text: `You are about to delete ${selected.length} product(s)!`, icon: 'warning', showCancelButton: true, confirmButtonColor: '#d33', cancelButtonColor: '#3085d6', confirmButtonText: 'Yes, delete them!' }).then((result) => { if (result.isConfirmed) { $.post('products.php', { action: 'bulk_delete', product_ids: selected }, function(response) { if(response.success) { Swal.fire('Deleted!', response.message, 'success'); setTimeout(() => location.reload(), 1500); } }, 'json'); } }); } function previewImage(input, previewId) { if (input.files && input.files[0]) { var reader = new FileReader(); reader.onload = function(e) { $(previewId).html('<img src="' + e.target.result + '" style="max-width: 200px; max-height: 200px;">'); } reader.readAsDataURL(input.files[0]); } } function previewMultipleImages(input, previewId) { $(previewId).empty(); if (input.files) { for(var i = 0; i < input.files.length; i++) { var reader = new FileReader(); reader.onload = function(e) { $(previewId).append('<img src="' + e.target.result + '" style="max-width: 100px; max-height: 100px; margin: 5px;">'); } reader.readAsDataURL(input.files[i]); } } } function deleteProduct(productId) { Swal.fire({ title: "Are you sure?", text: "This product will be marked inactive (soft delete).", icon: "warning", showCancelButton: true, confirmButtonColor: "#d33", cancelButtonColor: "#3085d6", confirmButtonText: "Yes, delete it!", cancelButtonText: "Cancel" }).then((result) => { if (!result.isConfirmed) return; $.ajax({ url: 'product-action.php', method: 'POST', dataType: 'json', data: { action: 'delete', product_id: productId }, success: function(res) { if (res.success) { Swal.fire('Deleted!', res.message, 'success'); setTimeout(() => location.reload(), 1200); } else { Swal.fire('Error!', res.message, 'error'); } }, error: function(xhr) { console.error('Server raw response:', xhr.responseText); Swal.fire('Error!', 'Server error. Check console for details.', 'error'); } }); }); } function exportProducts() { window.location.href = 'export-products.php'; } </script> </body> </html>
Upload File
Create Folder