🤩 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:product.php
<?php require_once __DIR__ . '/../includes/config.php'; require_once __DIR__ . '/../includes/db.php'; require_once __DIR__ . '/../includes/functions.php'; $page = 'product'; $slug = $_GET['slug'] ?? ''; $product = get_product($slug); if (!$product) { header('Location: ' . SITE_URL . 'pages/shop.php'); exit; } // Increment views $db->prepare("UPDATE products SET views = views + 1 WHERE id = ?")->execute([$product['id']]); $page_title = $product['name']; $product_images = get_product_images($product['id']); $product_variations = get_product_variations($product['id']); $product_reviews = get_product_reviews($product['id']); $avg_rating = get_average_rating($product['id']); $rating = round($avg_rating['avg_rating'] ?? 0); $related_products = get_related_products($product['id'], $product['category_id']); require_once '../includes/header.php'; require_once '../includes/navbar.php'; ?> <main> <!-- Breadcrumb --> <section style="background: var(--light-marble); padding: 20px 0;"> <div class="container"> <nav aria-label="breadcrumb"> <ol class="breadcrumb mb-0"> <li class="breadcrumb-item"><a href="<?= SITE_URL ?>">Home</a></li> <li class="breadcrumb-item"><a href="<?= SITE_URL ?>pages/shop.php">Shop</a></li> <li class="breadcrumb-item"><a href="<?= SITE_URL ?>pages/category.php?slug=<?= $product['category_slug'] ?>"><?= htmlspecialchars($product['category_name']) ?></a></li> <li class="breadcrumb-item active"><?= htmlspecialchars($product['name']) ?></li> </ol> </nav> </div> </section> <!-- Product Detail Section --> <section class="product-detail-section" style="padding: 60px 0;"> <div class="container"> <div class="row g-4"> <!-- Product Images --> <div class="col-lg-6"> <div class="product-gallery" style="background: var(--white); border-radius: 16px; padding: 20px; box-shadow: var(--shadow-sm);"> <div class="gallery-main" style="margin-bottom: 15px; border-radius: 12px; overflow: hidden; position: relative;"> <?php $main_image = $product['thumbnail'] ?: ($product_images[0]['image'] ?? ''); $main_image_url = SITE_URL . 'assets/images/no-image.jpg'; if ($main_image) { $candidate = UPLOADS_PATH . 'products/' . $main_image; if (file_exists($candidate)) { $main_image_url = UPLOADS_URL . 'products/' . $main_image; } } ?> <img src="<?= function_exists('img_url') ? img_url($main_image_url) : $main_image_url ?>" alt="<?= htmlspecialchars($product['name']) ?>" class="product-zoom img-fluid" style="width: 100%; cursor: crosshair; transition: transform 0.3s ease;" onerror="this.onerror=null;this.src='<?= SITE_URL ?>assets/images/no-image.jpg';"> <div class="product-badges" style="position: absolute; top: 20px; left: 20px; z-index: 3;"> <?php if ($product['new_arrival']): ?> <span class="product-badge new">New</span> <?php endif; ?> <?php if ($product['sale_price'] > 0 && $product['sale_price'] < $product['regular_price']): ?> <?php $discount = round((($product['regular_price'] - $product['sale_price']) / $product['regular_price']) * 100); ?> <span class="product-badge sale">-<?= $discount ?>%</span> <?php endif; ?> </div> </div> <div class="gallery-thumbs" style="display: flex; gap: 10px; overflow-x: auto;"> <div class="gallery-thumb active" style="width: 80px; height: 80px; border: 2px solid var(--primary-rose-gold); border-radius: 8px; overflow: hidden; flex-shrink: 0;"> <img src="<?= function_exists('img_url') ? img_url($main_image_url) : $main_image_url ?>" alt="" style="width: 100%; height: 100%; object-fit: cover; cursor: pointer;" onerror="this.onerror=null;this.src='<?= SITE_URL ?>assets/images/no-image.jpg';"> </div> <?php foreach ($product_images as $img): ?> <div class="gallery-thumb" style="width: 80px; height: 80px; border: 2px solid transparent; border-radius: 8px; overflow: hidden; flex-shrink: 0;"> <?php $gthumb_url = file_exists(UPLOADS_PATH . 'products/' . $img['image']) ? UPLOADS_URL . 'products/' . $img['image'] : (SITE_URL . 'assets/images/no-image.jpg'); ?> <img src="<?= function_exists('img_url') ? img_url($gthumb_url) : $gthumb_url ?>" alt="" style="width: 100%; height: 100%; object-fit: cover; cursor: pointer;" onerror="this.onerror=null;this.src='<?= SITE_URL ?>assets/images/no-image.jpg';"> </div> <?php endforeach; ?> </div> </div> </div> <!-- Product Info --> <div class="col-lg-6"> <div class="product-details"> <div class="product-category" style="color: var(--primary-rose-gold); font-size: 0.85rem; text-transform: uppercase; letter-spacing: 2px; margin-bottom: 10px;"> <a href="<?= SITE_URL ?>pages/category.php?slug=<?= $product['category_slug'] ?>" style="color: var(--primary-rose-gold); text-decoration: none;"> <?= htmlspecialchars($product['category_name']) ?> </a> <?php if ($product['subcategory_name']): ?> / <?= htmlspecialchars($product['subcategory_name']) ?> <?php endif; ?> </div> <h1 style="font-size: 2.2rem; margin-bottom: 15px;"><?= htmlspecialchars($product['name']) ?></h1> <?php if ($product['brand_name']): ?> <p style="margin-bottom: 15px; color: var(--gray-600);"> <strong>Brand:</strong> <a href="<?= SITE_URL ?>pages/shop.php?brand=<?= $product['brand_slug'] ?>" style="color: var(--primary-rose-gold);"> <?= htmlspecialchars($product['brand_name']) ?> </a> </p> <?php endif; ?> <div class="product-rating" style="display: flex; align-items: center; gap: 10px; margin-bottom: 20px;"> <div class="stars" style="color: #ffc107;"> <?php for ($i = 1; $i <= 5; $i++): ?> <i class="fa<?= $i <= $rating ? 's' : 'r' ?> fa-star"></i> <?php endfor; ?> </div> <span style="color: var(--gray-600);">(<?= $avg_rating['total_reviews'] ?? 0 ?> reviews)</span> </div> <div class="product-price" style="margin-bottom: 25px; padding-bottom: 25px; border-bottom: 1px solid var(--gray-200);"> <?php if ($product['sale_price'] > 0 && $product['sale_price'] < $product['regular_price']): ?> <span style="font-size: 2rem; font-weight: 700; color: var(--primary-rose-gold);"><?= format_currency($product['sale_price']) ?></span> <span style="font-size: 1.2rem; color: var(--gray-500); text-decoration: line-through; margin-left: 10px;"><?= format_currency($product['regular_price']) ?></span> <span style="background: #fff0f0; color: var(--danger); padding: 4px 10px; border-radius: 20px; font-size: 0.85rem; font-weight: 600; margin-left: 10px;">Save <?= format_currency($product['regular_price'] - $product['sale_price']) ?></span> <?php else: ?> <span style="font-size: 2rem; font-weight: 700; color: var(--primary-rose-gold);"><?= format_currency($product['regular_price']) ?></span> <?php endif; ?> </div> <div class="product-short-desc" style="color: var(--gray-700); margin-bottom: 25px; line-height: 1.8;"> <?= nl2br(htmlspecialchars($product['short_description'] ?? '')) ?> </div> <div class="product-stock" style="margin-bottom: 20px;"> <?php if ($product['stock_status'] == 'in_stock' && $product['stock_quantity'] > 0): ?> <span style="color: var(--success);"><i class="fas fa-check-circle"></i> In Stock</span> <?php if ($product['stock_quantity'] < 10): ?> <span style="color: var(--warning); margin-left: 15px;"><i class="fas fa-exclamation-triangle"></i> Only <?= $product['stock_quantity'] ?> left</span> <?php endif; ?> <?php elseif ($product['stock_status'] == 'pre_order'): ?> <span style="color: var(--info);"><i class="fas fa-clock"></i> Pre-Order Available</span> <?php else: ?> <span style="color: var(--danger);"><i class="fas fa-times-circle"></i> Out of Stock</span> <?php endif; ?> </div> <div class="product-variations" style="margin-bottom: 25px;"> <?php $types = []; foreach ($product_variations as $v) { $types[$v['type']][] = $v; } foreach ($types as $type => $variations): ?> <div class="variation-group" style="margin-bottom: 15px;"> <label style="font-weight: 600; margin-bottom: 8px; display: block;"><?= htmlspecialchars(ucfirst($type)) ?>:</label> <div style="display: flex; gap: 8px; flex-wrap: wrap;"> <?php foreach ($variations as $v): ?> <label style="cursor: pointer; padding: 8px 16px; border: 2px solid var(--gray-200); border-radius: 25px; transition: var(--transition); font-size: 0.9rem;"> <input type="radio" name="variation_<?= $type ?>" value="<?= htmlspecialchars($v['value']) ?>" style="display: none;"> <?= htmlspecialchars($v['value']) ?> </label> <?php endforeach; ?> </div> </div> <?php endforeach; ?> </div> <div class="product-actions" style="margin-bottom: 25px;"> <form class="add-to-cart-form" style="display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 15px;"> <div class="qty-wrapper"> <button type="button" class="qty-btn qty-minus">−</button> <input type="number" name="quantity" value="1" min="1" max="<?= $product['stock_quantity'] ?: 999 ?>" class="qty-input"> <button type="button" class="qty-btn qty-plus">+</button> </div> <?php if ($product['stock_status'] != 'out_of_stock'): ?> <button type="button" class="add-to-cart-btn btn-luxury" data-product-id="<?= $product['id'] ?>" style="flex: 1; min-width: 200px;"> <i class="fas fa-shopping-bag"></i> Add to Cart </button> <?php else: ?> <button type="button" class="btn-luxury" disabled style="flex: 1; min-width: 200px; opacity: 0.5; cursor: not-allowed;"> <i class="fas fa-times"></i> Out of Stock </button> <?php endif; ?> </form> <div style="display: flex; gap: 10px; flex-wrap: wrap;"> <button class="wishlist-btn btn-outline-luxury" data-product-id="<?= $product['id'] ?>" style="border-color: var(--primary-rose-gold); color: var(--primary-rose-gold);"> <i class="far fa-heart"></i> Add to Wishlist </button> </div> </div> <div class="product-meta" style="border-top: 1px solid var(--gray-200); padding-top: 20px;"> <p style="margin-bottom: 8px; color: var(--gray-600); font-size: 0.9rem;"> <strong>SKU:</strong> <?= htmlspecialchars($product['sku'] ?? 'N/A') ?> </p> <p style="margin-bottom: 8px; color: var(--gray-600); font-size: 0.9rem;"> <strong>Category:</strong> <?= htmlspecialchars($product['category_name']) ?> </p> <?php if ($product['tags']): ?> <p style="margin-bottom: 0; color: var(--gray-600); font-size: 0.9rem;"> <strong>Tags:</strong> <?php foreach (explode(',', $product['tags']) as $tag): ?> <a href="<?= SITE_URL ?>pages/shop.php?search=<?= urlencode(trim($tag)) ?>" style="color: var(--primary-rose-gold); margin-right: 5px;">#<?= trim($tag) ?></a> <?php endforeach; ?> </p> <?php endif; ?> </div> </div> </div> </div> <!-- Product Tabs --> <div class="product-tabs" style="margin-top: 60px;"> <ul class="nav nav-tabs" style="border-bottom: 2px solid var(--gray-200);" id="productTabs"> <li class="nav-item"> <button class="nav-link active tab-btn" data-target="#description" style="border: none; padding: 15px 30px; font-weight: 600; color: var(--dark-text); position: relative;"> Description </button> </li> <li class="nav-item"> <button class="nav-link tab-btn" data-target="#specifications" style="border: none; padding: 15px 30px; font-weight: 600; color: var(--dark-text);"> Specifications </button> </li> <li class="nav-item"> <button class="nav-link tab-btn" data-target="#reviews" style="border: none; padding: 15px 30px; font-weight: 600; color: var(--dark-text);"> Reviews (<?= $avg_rating['total_reviews'] ?? 0 ?>) </button> </li> </ul> <div class="tab-contents" style="background: var(--white); padding: 40px; border-radius: 0 0 16px 16px; box-shadow: var(--shadow-sm);"> <div id="description" class="tab-content active"> <div style="line-height: 1.8; color: var(--gray-700);"> <?= nl2br(htmlspecialchars($product['description'] ?? 'No description available.')) ?> </div> </div> <div id="specifications" class="tab-content" style="display: none;"> <?php if ($product['specifications']): $specs = json_decode($product['specifications'], true); if ($specs && is_array($specs)): ?> <table class="table" style="margin: 0;"> <tbody> <?php foreach ($specs as $key => $value): ?> <tr> <th style="width: 30%; padding: 12px; background: var(--light-marble);"><?= htmlspecialchars($key) ?></th> <td style="padding: 12px;"><?= htmlspecialchars($value) ?></td> </tr> <?php endforeach; ?> </tbody> </table> <?php else: ?> <p class="text-muted">No specifications available.</p> <?php endif; else: ?> <p class="text-muted">No specifications available.</p> <?php endif; ?> </div> <div id="reviews" class="tab-content" style="display: none;"> <?php if (count($product_reviews) > 0): ?> <?php foreach ($product_reviews as $review): ?> <div class="review-item" style="padding: 20px 0; border-bottom: 1px solid var(--gray-200);"> <div style="display: flex; gap: 15px; align-items: flex-start;"> <div class="testimonial-avatar" style="background: var(--gradient-rose); color: var(--white); width: 50px; height: 50px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-weight: 600;"> <?= strtoupper(substr($review['user_name'] ?? $review['name'], 0, 1)) ?> </div> <div style="flex: 1;"> <div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px;"> <div> <strong><?= htmlspecialchars($review['user_name'] ?? $review['name']) ?></strong> <div class="stars" style="color: #ffc107; font-size: 0.85rem; margin-top: 3px;"> <?php for ($i = 1; $i <= 5; $i++): ?> <i class="fa<?= $i <= $review['rating'] ? 's' : 'r' ?> fa-star"></i> <?php endfor; ?> </div> </div> <small class="text-muted"><?= date('M d, Y', strtotime($review['created_at'])) ?></small> </div> <?php if ($review['title']): ?> <h6 style="margin-bottom: 5px;"><?= htmlspecialchars($review['title']) ?></h6> <?php endif; ?> <p style="margin: 0; color: var(--gray-700);"><?= nl2br(htmlspecialchars($review['review'])) ?></p> </div> </div> </div> <?php endforeach; ?> <?php else: ?> <p class="text-muted">No reviews yet. Be the first to review this product!</p> <?php endif; ?> <?php if (is_logged_in()): ?> <div class="review-form" style="margin-top: 30px; padding-top: 30px; border-top: 1px solid var(--gray-200);"> <h4 style="margin-bottom: 20px;">Write a Review</h4> <form action="<?= SITE_URL ?>pages/submit-review.php" method="POST"> <input type="hidden" name="product_id" value="<?= $product['id'] ?>"> <?= csrf_field() ?> <div class="row g-3"> <div class="col-md-12"> <label class="form-label">Your Rating *</label> <div class="rating-input" style="display: flex; gap: 5px; font-size: 1.5rem; color: #ffc107;"> <?php for ($i = 1; $i <= 5; $i++): ?> <i class="far fa-star" data-rating="<?= $i ?>" style="cursor: pointer;"></i> <?php endfor; ?> <input type="hidden" name="rating" id="rating-input" required> </div> </div> <div class="col-md-12"> <label class="form-label">Review Title</label> <input type="text" name="title" class="form-control" placeholder="Summarize your review" style="border-radius: 25px; padding: 10px 20px;"> </div> <div class="col-md-12"> <label class="form-label">Your Review *</label> <textarea name="review" class="form-control" rows="4" required placeholder="Share your thoughts about this product..." style="border-radius: 15px; padding: 15px 20px;"></textarea> </div> <div class="col-md-12"> <button type="submit" class="btn-luxury">Submit Review</button> </div> </div> </form> </div> <?php endif; ?> </div> </div> </div> <!-- Related Products --> <?php if (count($related_products) > 0): ?> <div class="related-products" style="margin-top: 60px;"> <div class="section-title" style="text-align: left; margin-bottom: 30px;"> <h2 class="section-heading">Related <span style="color: var(--primary-rose-gold);">Products</span></h2> </div> <div class="product-grid"> <?php foreach ($related_products as $product): ?> <?php include '../includes/product-card.php'; ?> <?php endforeach; ?> </div> </div> <?php endif; ?> </div> </section> <script> // Rating stars interaction document.querySelectorAll('.rating-input .fa-star').forEach(function(star) { star.addEventListener('click', function() { const rating = this.dataset.rating; document.getElementById('rating-input').value = rating; document.querySelectorAll('.rating-input .fa-star').forEach(function(s, index) { if (index < rating) { s.classList.remove('far'); s.classList.add('fas'); } else { s.classList.remove('fas'); s.classList.add('far'); } }); }); }); // Variation selection document.querySelectorAll('.variation-group label').forEach(function(label) { label.addEventListener('click', function() { this.closest('.variation-group').querySelectorAll('label').forEach(function(l) { l.style.borderColor = 'var(--gray-200)'; l.style.background = 'transparent'; }); this.style.borderColor = 'var(--primary-rose-gold)'; this.style.background = 'var(--soft-pink)'; }); }); </script> </main> <?php require_once '../includes/footer.php'; ?>
Save Changes
Cancel
Create New File
Create New Folder