Devco1
Home
Console
Upload
New File
New Folder
Tools
Info
About
/
home
/
wifiyecu
/
www
/
Filename :
product.php
back
Copy
<?php include 'includes/config.php'; ?> <?php if (!isset($_GET['id']) || !is_numeric($_GET['id'])) { header('Location: index.php'); exit; } $product_id = intval($_GET['id']); try { // الحصول على بيانات المنتج $stmt = $pdo->prepare("SELECT * FROM products WHERE id = ?"); $stmt->execute([$product_id]); $product = $stmt->fetch(); if (!$product) { header('Location: index.php'); exit; } // الحصول على صور المنتج $images_stmt = $pdo->prepare("SELECT * FROM product_images WHERE product_id = ? ORDER BY is_main DESC"); $images_stmt->execute([$product_id]); $images = $images_stmt->fetchAll(); // الحصول على الألوان المتاحة $colors_stmt = $pdo->prepare("SELECT * FROM colors WHERE product_id = ?"); $colors_stmt->execute([$product_id]); $colors = $colors_stmt->fetchAll(); // الحصول على التقييمات $reviews_stmt = $pdo->prepare(" SELECT *, (SELECT COUNT(*) FROM reviews r2 WHERE r2.product_id = r.product_id) as total_reviews, (SELECT AVG(rating) FROM reviews r3 WHERE r3.product_id = r.product_id) as avg_rating FROM reviews r WHERE product_id = ? ORDER BY created_at DESC LIMIT 10 "); $reviews_stmt->execute([$product_id]); $reviews = $reviews_stmt->fetchAll(); $avg_rating = $reviews[0]['avg_rating'] ?? 0; $total_reviews = $reviews[0]['total_reviews'] ?? 0; } catch (PDOException $e) { die("خطأ في قاعدة البيانات: " . $e->getMessage()); } ?> <?php include 'includes/header.php'; ?> <div class="row"> <!-- معرض الصور --> <div class="col-md-6"> <div class="product-gallery"> <div class="main-image mb-3"> <img src="<?php echo $images[0]['image_url'] ?? 'images/placeholder.jpg'; ?>" class="img-fluid rounded" alt="<?php echo htmlspecialchars($product['name']); ?>" id="mainImage"> </div> <?php if (count($images) > 1): ?> <div class="thumbnail-images"> <div class="row g-2"> <?php foreach ($images as $image): ?> <div class="col-3"> <img src="<?php echo $image['image_url']; ?>" class="img-thumbnail thumbnail <?php echo $image['is_main'] ? 'active' : ''; ?>" alt="Thumbnail" data-image="<?php echo $image['image_url']; ?>" style="cursor: pointer; height: 80px; object-fit: cover;"> </div> <?php endforeach; ?> </div> </div> <?php endif; ?> </div> </div> <!-- معلومات المنتج --> <div class="col-md-6"> <h1 class="mb-3"><?php echo htmlspecialchars($product['name']); ?></h1> <!-- التقييم --> <div class="rating-section mb-3"> <div class="d-flex align-items-center"> <div class="stars me-2"> <?php $full_stars = floor($avg_rating); $half_star = ($avg_rating - $full_stars) >= 0.5; $empty_stars = 5 - $full_stars - ($half_star ? 1 : 0); echo str_repeat('<i class="fas fa-star text-warning"></i>', $full_stars); if ($half_star) { echo '<i class="fas fa-star-half-alt text-warning"></i>'; } echo str_repeat('<i class="far fa-star text-warning"></i>', $empty_stars); ?> </div> <span class="text-muted">(<?php echo number_format($avg_rating, 1); ?> | <?php echo $total_reviews; ?> تقييم)</span> </div> </div> <!-- السعر --> <div class="price-section mb-3"> <?php if ($product['old_price'] && $product['old_price'] > $product['price']): ?> <div class="d-flex align-items-center"> <span class="h3 text-primary me-3">$<?php echo $product['price']; ?></span> <span class="text-muted text-decoration-line-through">$<?php echo $product['old_price']; ?></span> <span class="badge bg-danger ms-2"> وفر <?php echo round((($product['old_price'] - $product['price']) / $product['old_price']) * 100); ?>% </span> </div> <?php else: ?> <span class="h3 text-primary">$<?php echo $product['price']; ?></span> <?php endif; ?> </div> <!-- الألوان --> <?php if (!empty($colors)): ?> <div class="color-selection mb-4"> <h5>اختر اللون:</h5> <div class="color-options d-flex gap-2"> <?php foreach ($colors as $color): ?> <div class="color-option rounded border" style="width: 40px; height: 40px; background-color: <?php echo $color['color_code']; ?>; cursor: pointer;" data-color-id="<?php echo $color['id']; ?>" title="<?php echo htmlspecialchars($color['color_name']); ?>"> </div> <?php endforeach; ?> </div> </div> <?php endif; ?> <!-- إضافة إلى السلة --> <div class="add-to-cart-section mb-4"> <div class="row g-3 align-items-center"> <div class="col-auto"> <label for="quantity" class="col-form-label">الكمية:</label> </div> <div class="col-auto"> <div class="input-group" style="width: 120px;"> <button class="btn btn-outline-secondary" type="button" id="decreaseQty">-</button> <input type="number" class="form-control text-center" id="quantity" value="1" min="1" max="<?php echo $product['stock_quantity']; ?>"> <button class="btn btn-outline-secondary" type="button" id="increaseQty">+</button> </div> </div> <div class="col"> <button class="btn btn-primary btn-lg w-100 add-to-cart" data-product-id="<?php echo $product['id']; ?>" id="addToCartBtn"> <i class="fas fa-cart-plus"></i> إضافة إلى السلة </button> </div> </div> </div> <!-- معلومات المخزون --> <div class="stock-info mb-4"> <div class="d-flex align-items-center"> <i class="fas fa-box me-2 <?php echo $product['stock_quantity'] > 10 ? 'text-success' : 'text-warning'; ?>"></i> <span class="<?php echo $product['stock_quantity'] > 10 ? 'text-success' : 'text-warning'; ?>"> <?php if ($product['stock_quantity'] > 10): ?> متوفر في المخزون <?php elseif ($product['stock_quantity'] > 0): ?> فقط <?php echo $product['stock_quantity']; ?> وحدة متبقية <?php else: ?> غير متوفر <?php endif; ?> </span> </div> </div> </div> </div> <!-- تفاصيل المنتج --> <div class="row mt-5"> <div class="col-12"> <div class="card"> <div class="card-header"> <h4 class="mb-0">المواصفات والتفاصيل</h4> </div> <div class="card-body"> <div class="product-description"> <?php echo nl2br(htmlspecialchars($product['description'])); ?> </div> </div> </div> </div> </div> <!-- التقييمات --> <?php if (!empty($reviews)): ?> <div class="row mt-5"> <div class="col-12"> <div class="card"> <div class="card-header"> <h4 class="mb-0">تقييمات العملاء (<?php echo $total_reviews; ?>)</h4> </div> <div class="card-body"> <?php foreach ($reviews as $review): ?> <div class="review-item border-bottom pb-3 mb-3"> <div class="d-flex justify-content-between align-items-start mb-2"> <div> <strong><?php echo htmlspecialchars($review['user_name']); ?></strong> <div class="stars"> <?php echo str_repeat('<i class="fas fa-star text-warning"></i>', $review['rating']); echo str_repeat('<i class="far fa-star text-warning"></i>', 5 - $review['rating']); ?> </div> </div> <small class="text-muted"><?php echo date('Y-m-d', strtotime($review['created_at'])); ?></small> </div> <p class="mb-0"><?php echo htmlspecialchars($review['comment']); ?></p> </div> <?php endforeach; ?> </div> </div> </div> </div> <?php endif; ?> <script> document.addEventListener('DOMContentLoaded', function() { // معرض الصور const thumbnails = document.querySelectorAll('.thumbnail'); const mainImage = document.getElementById('mainImage'); thumbnails.forEach(thumb => { thumb.addEventListener('click', function() { const newImage = this.getAttribute('data-image'); mainImage.src = newImage; thumbnails.forEach(t => t.classList.remove('active')); this.classList.add('active'); }); }); // التحكم في الكمية const quantityInput = document.getElementById('quantity'); const decreaseBtn = document.getElementById('decreaseQty'); const increaseBtn = document.getElementById('increaseQty'); decreaseBtn.addEventListener('click', function() { let currentValue = parseInt(quantityInput.value); if (currentValue > 1) { quantityInput.value = currentValue - 1; } }); increaseBtn.addEventListener('click', function() { let currentValue = parseInt(quantityInput.value); let maxValue = parseInt(quantityInput.getAttribute('max')); if (currentValue < maxValue) { quantityInput.value = currentValue + 1; } }); }); </script> <?php include 'includes/footer.php'; ?>