File Manager
Editing: allproducts.php
<?php require_once 'security.php'; require_once 'functions.php'; $host = "127.0.0.1:3306"; $username = "u404542307_dacotywebsites"; $password = "daCotywebs1te5"; $database = "u404542307_eizon"; try { // Establish database connection $pdo = new PDO("mysql:host=$host;dbname=$database", $username, $password); $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); } catch (PDOException $e) { die("Could not connect to the database: " . $e->getMessage()); } // Sanitize inputs $category = isset($_GET['category']) ? str_replace('-', ' ', htmlspecialchars($_GET['category'])) : ''; $highlight = isset($_GET['highlight']) ? intval($_GET['highlight']) : null; $region = isset($_GET['region']) ? str_replace('-', ' ', htmlspecialchars($_GET['region'])) : ''; $searchTerm = isset($_GET['search']) ? htmlspecialchars($_GET['search']) : ''; // Capture the search term // Define the base query to search for the product and related ones $sql = "SELECT * FROM cards WHERE 1=1"; // If a search term is provided, search the product by name if ($searchTerm) { $sql .= " AND name LIKE :searchTerm"; } // If category and region are provided, apply them as filters if ($category) { $sql .= " AND category = :category"; } if ($region) { $sql .= " AND region = :region"; } // Fetch the category of the highlighted product (if it exists) $highlightCategory = null; if ($highlight) { $highlightCategoryQuery = "SELECT category FROM cards WHERE card_id = :highlight"; $highlightCategoryStmt = $pdo->prepare($highlightCategoryQuery); $highlightCategoryStmt->execute(['highlight' => $highlight]); $highlightCategory = $highlightCategoryStmt->fetchColumn(); } // If we found the highlighted product's category, filter by it if ($highlightCategory) { $sql .= " AND category = :highlightCategory"; } // Prioritize the highlighted product, and then pick the rest randomly within the same category $sql .= " ORDER BY (card_id = :highlight) DESC, RAND()"; // Prepare the query and bind the parameters conditionally $stmt = $pdo->prepare($sql); $params = ['highlight' => $highlight]; if ($searchTerm) { $params['searchTerm'] = "%" . $searchTerm . "%"; // Search term with wildcards } if ($category) { $params['category'] = $category; } if ($region) { $params['region'] = $region; } if ($highlightCategory) { $params['highlightCategory'] = $highlightCategory; } // Execute the query with the prepared parameters $stmt->execute($params); $products = $stmt->fetchAll(PDO::FETCH_ASSOC); // Fetch regions for the dropdown $regions = []; $regionStmt = $pdo->query("SELECT DISTINCT region FROM cards ORDER BY region ASC"); while ($row = $regionStmt->fetch(PDO::FETCH_ASSOC)) { $regions[] = $row['region']; } // Fetch categories for the listing $categories = []; $categoryStmt = $pdo->query("SELECT DISTINCT category FROM cards ORDER BY category ASC"); while ($row = $categoryStmt->fetch(PDO::FETCH_ASSOC)) { $categories[] = $row['category']; } // Check if this is an AJAX request if (!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) === 'xmlhttprequest') { foreach ($products as $product) { $countryCode = $product['country_code']; $phoneNumber = $product['contacts']; $fullPhoneNumber = $countryCode . $phoneNumber; if (!preg_match('/^\+\d{6,15}$/', $fullPhoneNumber)) { echo "<p>Invalid or missing phone number for product: " . htmlspecialchars($product['name']) . "</p>"; continue; } ?> <div class="generalcard"> <div class="card <?= $product['card_id'] === $highlight ? 'highlight' : '' ?>"> <div class="card-inner"> <div class="card-front"> <div class="slideshow"> <img src="/<?= htmlspecialchars($product['image1']) ?>" alt="<?= htmlspecialchars($product['name']) ?>"> <img src="/<?= htmlspecialchars($product['image2']) ?>" alt="<?= htmlspecialchars($product['name']) ?>"> <img src="/<?= htmlspecialchars($product['image3']) ?>" alt="<?= htmlspecialchars($product['name']) ?>"> </div> </div> <div class="card-back"> <h3 class="namekit"><?= htmlspecialchars($product['name']) ?></h3> <p class="over"><?= htmlspecialchars($product['description']) ?></p> <p><?= htmlspecialchars($product['region']) ?></p> <p><?= htmlspecialchars($product['state']) ?></p> <button onclick="window.location.href='https://wa.me/<?= htmlspecialchars($fullPhoneNumber) ?>?text=Habari%20I%20am%20interested%20in%20your%20product%20on%20eizononline.com%20<?= urlencode($product['name']) ?>';"> Contact Seller </button> </div> </div> </div> <div class="pricetag"> <p><?= htmlspecialchars(number_format($product['price'], 2)) ?> Tsh</p> </div> </div> <?php } exit; } ?> <!DOCTYPE html> <html lang="en"> <head> <!-- Google tag (gtag.js) --> <script async defer src="https://www.googletagmanager.com/gtag/js?id=G-Z6RR2PMZW4"></script> <script defer> window.dataLayer = window.dataLayer || []; function gtag(){dataLayer.push(arguments);} gtag('js', new Date()); gtag('config', 'G-Z6RR2PMZW4'); </script> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>All Products</title> <meta name="description" content="Browse a diverse collection of products on eizon. Find top deals in your region, explore categories, and connect directly with sellers. Shop smarter, faster, and closer to home today!"> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.2/css/all.min.css" media="print" onload="this.media='all'"> <link rel="stylesheet" href="/e-commerce.css"> <link rel="icon" href="/favicon.ico" type="image/x-icon"> <link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon.png"> <link rel="icon" type="image/png" sizes="32x32" href="/favicon-32x32.png"> <link rel="icon" type="image/png" sizes="16x16" href="/favicon-16x16.png"> <link rel="manifest" href="/site.webmanifest"> <link rel="manifest" href="/manifest.json"> <script> function highlightProduct(productId) { fetch("allproducts.php?highlight=" + productId, { headers: { 'X-Requested-With': 'XMLHttpRequest' } }) .then(response => response.text()) .then(html => { document.getElementById("products").innerHTML = html; }); } </script> <style>.namekit,.locationkit{display:-webkit-box;-webkit-box-orient:vertical;overflow:hidden;text-overflow:ellipsis;white-space:normal}.namekit{-webkit-line-clamp:1}.locationkit{-webkit-line-clamp:1}.overlay-content a{display:flex;align-items:center;gap:10px;padding:5px 7px}.categories{display:flex;overflow-x:auto;white-space:nowrap;padding:10px;background:#f9f9f9;border:1px solid #ddd;scroll-behavior:smooth;-ms-overflow-style:none;scrollbar-width:none}::-webkit-scrollbar{display:none}.categories a{display:inline-flex;align-items:center;padding:10px 15px;margin-right:10px;text-decoration:none;color:#40e350;background:#fff;border:1px solid #ddd;border-radius:5px;transition:background .3s ease}.categories a:hover{background:#f0f0f0}.categories a.active{background:#40e350;color:#fff;border-color:#40e350}.categories a i{margin-right:8px;font-size:18px}</style> </head> <body> <nav> <div class="topro"> <div class="title">e!zon</div> <input type="text" id="search" placeholder="Search anything..."> <div class="nav"> <span class="open-btn" onclick="openNav()">☰</span> </div> </div> <div id="myNav" class="overlay"> <a href="javascript:void(0)" class="close-btn" onclick="closeNav()">×</a> <div class="overlay-content"> <!-- My Account --> <a href="/dashboard"> <i class="fas fa-user"></i> My Account </a> <!-- Home --> <a href="/home"> <i class="fas fa-home"></i> Home </a> <!-- Categories --> <div class="categs"> <h4> Categories</h4> <a href="/products"> <i class="fas fa-list"></i> All Categories </a> <a href="/products/Electronics"> <i class="fas fa-laptop"></i> Electronics </a> <a href="/products/Fashion-and-Beauty"> <i class="fas fa-tshirt"></i> Fashion & Beauty </a> <a href="/products/Home-Accessories"> <i class="fas fa-couch"></i> Home Accessories </a> <a href="/products/Decorations"> <i class="fas fa-palette"></i> Decorations </a> <a href="/products/Food-and-Nutrition"> <i class="fas fa-utensils"></i> Food & Nutrition </a> <a href="/products/Services"> <i class="fas fa-tools"></i> Services </a> <a href="/products/transport"> <i class="fas fa-truck"></i> Transport </a> <a href="/products/Other"> <i class="fas fa-ellipsis-h"></i> Other </a> </div> <!-- Request a Product --> <a href="/add_request"> <i class="fas fa-plus-circle"></i> Request a Product </a> <!-- About Us --> <a href="/about-us"> <i class="fas fa-info-circle"></i> About Us </a> <!-- Sell on EIZON --> <button style="background-color: orange;border: none;border-radius: 5px;padding: 9px 4px;"> <a href="/sell"> SELL ON EIZON NOW </a> </button> <!-- Login --> <a href="/login"> <i class="fas fa-sign-in-alt"></i> LOGIN </a> </div> </nav> <div class="categories"> <a href="/products"><i class="fas fa-th-list"></i>All Categories</a> <a href="/products/Electronics"><i class="fas fa-laptop"></i>Electronics</a> <a href="/products/Fashion-and-Beauty"><i class="fas fa-tshirt"></i>Fashion & Beauty</a> <a href="/products/Home-Accessories"><i class="fas fa-couch"></i>Home Accessories</a> <a href="/products/Decorations"><i class="fas fa-paint-brush"></i>Decorations</a> <a href="/products/Food-and-Nutrition"><i class="fas fa-utensils"></i>Food & Nutrition</a> <a href="/products/Services"><i class="fas fa-concierge-bell"></i>Services</a> <a href="/products/transport"><i class="fas fa-bus"></i>Transport</a> <a href="/products/Other"><i class="fas fa-ellipsis-h"></i>Other</a> </div> <div style="height:1svh;"><div id="result" class="search-result"></div></div> <div class="filter"> <div class="categories-section"> <button class="dropdown-btn">Categories</button> <div class="dropdown-content"> <a href="/products">All Categories</a> <a href="/products/Electronics">Electronics</a> <a href="/products/Fashion-and-Beauty">Fashion & Beauty</a> <a href="/products/Home-Accessories">Home Accessories</a> <a href="/products/Decorations">Decorations</a> <a href="/products/Food-and-Nutrition">Food & Nutrition</a> <a href="/products/Services">Services</a> <a href="/products/transport">transport</a> <a href="/products/Other">Other</a> </div> </div> <div class="region-filter"> <button class="region-btn" type="button">Filter by location</button> <div class="region-dropdown" style="display: none;"> <a href="/products">All Regions</a> <?php foreach ($regions as $regionOption): ?> <a href="/regions/<?= str_replace(' ', '-', $regionOption) ?>" class="<?= $region == $regionOption ? 'active' : '' ?>"> <?= htmlspecialchars($regionOption) ?> </a> <?php endforeach; ?> </div> </div> </div> <div class="products" id="products"> <?php foreach ($products as $product): ?> <?php // Combine country_code and contacts $countryCode = $product['country_code']; // Fetch country code from the database $phoneNumber = $product['contacts']; // Fetch phone number from the database // Format the full phone number $fullPhoneNumber = $countryCode . $phoneNumber; ?> <div class="generalcard"> <div class="card <?= $product['card_id'] === $highlight ? 'highlight' : '' ?>"> <div class="card-inner"> <div class="card-front"> <div class="slideshow"> <img src="/<?= htmlspecialchars($product['image1']) ?>" alt="<?= htmlspecialchars($product['name']) ?>"> <img src="/<?= htmlspecialchars($product['image2']) ?>" alt="<?= htmlspecialchars($product['name']) ?>"> <img src="/<?= htmlspecialchars($product['image3']) ?>" alt="<?= htmlspecialchars($product['name']) ?>"> </div> </div> <div class="card-back"> <h3 class="namekit"><?= htmlspecialchars($product['name']) ?></h3> <p class="over"><?= htmlspecialchars($product['description']) ?></p> <p class="locationkit"><?= htmlspecialchars($product['region']) ?></p> <p><?= htmlspecialchars($product['state']) ?></p> <button onclick="window.location.href='https://wa.me/<?= htmlspecialchars($fullPhoneNumber) ?>?text=Habari!%20I%20am%20interested%20in%20your%20product%20<?= urlencode($product['name']) ?>%20on%20eizon%20:%20<?= urlencode('https://www.eizononline.com/product.php?card_id=' . $product['card_id']) ?>';"> Contact Seller </button> <p> <a href="/product.php?card_id=<?= htmlspecialchars($product['card_id']) ?>">More Details</a> </p> </div> </div> </div> <div class="pricetag"> <p><?= htmlspecialchars(number_format($product['price'], 2)) ?> Tsh</p> </div> </div> <?php endforeach; ?> </div> <?php include 'footer.php'; ?> <script> function openNav() { document.getElementById("myNav").style.width = "250px"; } function closeNav() { document.getElementById("myNav").style.width = "0"; } // Close the navigation menu when clicking outside of it document.addEventListener("click", function (event) { const nav = document.getElementById("myNav"); const openButton = document.querySelector(".open-btn"); // Assuming you have a button to open the nav // Check if the click is outside the nav and not on the open button if (!nav.contains(event.target) && !openButton.contains(event.target)) { closeNav(); } }); </script> <script src="/e-commerce.js" defer></script> <script defer> const dropdownButton = document.querySelector(".dropdown-btn"), dropdownContent = document.querySelector(".dropdown-content"), dropdownLinks = document.querySelectorAll(".dropdown-content a"); dropdownButton.addEventListener("click", function() { dropdownContent.style.display = dropdownContent.style.display === "block" ? "none" : "block"; }); dropdownLinks.forEach(link => { link.addEventListener("click", function() { dropdownContent.style.display = "none"; }); }); document.addEventListener("click", function(event) { if (!dropdownButton.contains(event.target) && !dropdownContent.contains(event.target)) { dropdownContent.style.display = "none"; } }); document.addEventListener("DOMContentLoaded", () => { let regionButton = document.querySelector(".region-btn"), regionDropdown = document.querySelector(".region-dropdown"); regionButton.addEventListener("click", () => { let isVisible = regionDropdown.style.display === "block"; regionDropdown.style.display = isVisible ? "none" : "block"; }); document.addEventListener("click", event => { if (!regionButton.contains(event.target) && !regionDropdown.contains(event.target)) { regionDropdown.style.display = "none"; } }); }); </script> <script defer> document.addEventListener('DOMContentLoaded', function () { const categoryLinks = document.querySelectorAll('.categories a'); const categoriesContainer = document.querySelector('.categories'); // Function to highlight the active category and ensure it's in view function setActiveCategory() { const currentUrl = window.location.pathname; categoryLinks.forEach(link => { if (link.getAttribute('href') === currentUrl) { // Remove 'active' class from all links categoryLinks.forEach(link => link.classList.remove('active')); // Add 'active' class to the current link link.classList.add('active'); // Scroll the active category into view link.scrollIntoView({ behavior: 'smooth', // Smooth scrolling block: 'nearest', // Align to the nearest edge inline: 'center' // Center the active category horizontally }); } }); } // Set the active category on page load setActiveCategory(); // Update the active category on link click categoryLinks.forEach(link => { link.addEventListener('click', function (e) { // Remove 'active' class from all links categoryLinks.forEach(link => link.classList.remove('active')); // Add 'active' class to the clicked link this.classList.add('active'); // Scroll the clicked category into view this.scrollIntoView({ behavior: 'smooth', block: 'nearest', inline: 'center' }); }); }); }); </script> </body> </html>
💾 Save
⬅ Back