 <?php
include 'db.php';

$slug = isset($_GET['slug']) ? trim($_GET['slug']) : '';
$slugEsc = mysqli_real_escape_string($conn, $slug);

if (empty($slug)) {
    die("Invalid product.");
}

/*
|--------------------------------------------------------------------------
| FETCH PRODUCT
|--------------------------------------------------------------------------
*/
$sqlProduct = "SELECT * FROM products WHERE slug = '$slugEsc' AND status = 1 LIMIT 1";
$resultProduct = mysqli_query($conn, $sqlProduct);

if (!$resultProduct || mysqli_num_rows($resultProduct) == 0) {
    die("Product not found.");
}

$product = mysqli_fetch_assoc($resultProduct);

/*
|--------------------------------------------------------------------------
| PRODUCT VALUES
|--------------------------------------------------------------------------
*/
$productId         = (int)$product['id'];
$productName       = htmlspecialchars($product['product_name']);
$productSlug       = urlencode($product['slug']);
$productCategory   = htmlspecialchars($product['category']);
$productPrice      = number_format((float)$product['price'], 2);
$productOldPrice   = (!empty($product['old_price']) && $product['old_price'] > $product['price']) ? number_format((float)$product['old_price'], 2) : '';
$productRating     = (int)$product['rating'];
$productBadge      = !empty($product['badge']) ? htmlspecialchars($product['badge']) : '';
$productBadgeText  = !empty($product['badge_text']) ? htmlspecialchars($product['badge_text']) : '';
$productDesc       = !empty($product['full_description']) ? nl2br(htmlspecialchars($product['full_description'])) : nl2br(htmlspecialchars($product['short_description']));
$productShortSpecs = !empty($product['short_specs']) ? nl2br(htmlspecialchars($product['short_specs'])) : '';
$productSpecs      = !empty($product['specifications']) ? nl2br(htmlspecialchars($product['specifications'])) : '';
$productSku        = !empty($product['sku']) ? htmlspecialchars($product['sku']) : 'N/A';
$productBrand      = !empty($product['brand']) ? htmlspecialchars($product['brand']) : 'Gnosis Geomatics';
$productModel      = !empty($product['model']) ? htmlspecialchars($product['model']) : 'N/A';
$productStock      = !empty($product['stock_status']) ? htmlspecialchars($product['stock_status']) : 'Available on Request';

$images = [];
if (!empty($product['image1'])) $images[] = $product['image1'];
if (!empty($product['image2'])) $images[] = $product['image2'];
if (!empty($product['image3'])) $images[] = $product['image3'];
if (!empty($product['image4'])) $images[] = $product['image4'];
if (!empty($product['image5'])) $images[] = $product['image5'];

if (empty($images)) {
    $images[] = 'assets/images/placeholder.jpg';
}

$tags = [];
if (!empty($product['tag1'])) $tags[] = $product['tag1'];
if (!empty($product['tag2'])) $tags[] = $product['tag2'];
if (!empty($product['tag3'])) $tags[] = $product['tag3'];

/*
|--------------------------------------------------------------------------
| PREVIOUS / NEXT PRODUCT
|--------------------------------------------------------------------------
*/
$prevProduct = null;
$nextProduct = null;

$sqlPrev = "SELECT id, product_name, slug, image1 FROM products 
            WHERE id < $productId AND status = 1 
            ORDER BY id DESC LIMIT 1";
$resultPrev = mysqli_query($conn, $sqlPrev);
if ($resultPrev && mysqli_num_rows($resultPrev) > 0) {
    $prevProduct = mysqli_fetch_assoc($resultPrev);
}

$sqlNext = "SELECT id, product_name, slug, image1 FROM products 
            WHERE id > $productId AND status = 1 
            ORDER BY id ASC LIMIT 1";
$resultNext = mysqli_query($conn, $sqlNext);
if ($resultNext && mysqli_num_rows($resultNext) > 0) {
    $nextProduct = mysqli_fetch_assoc($resultNext);
}

/*
|--------------------------------------------------------------------------
| RELATED PRODUCTS
|--------------------------------------------------------------------------
*/
$relatedProducts = [];
$sqlRelated = "SELECT * FROM products 
               WHERE category = '" . mysqli_real_escape_string($conn, $product['category']) . "' 
               AND id != $productId 
               AND status = 1
               ORDER BY id DESC 
               LIMIT 8";
$resultRelated = mysqli_query($conn, $sqlRelated);

if ($resultRelated && mysqli_num_rows($resultRelated) > 0) {
    while ($row = mysqli_fetch_assoc($resultRelated)) {
        $relatedProducts[] = $row;
    }
}
?>

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
        <title>Gnosis Geomatics | Survey Equipment, GNSS, Total Station & Geomatics Services</title>

<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta http-equiv="X-UA-Compatible" content="IE=edge">

<meta name="robots" content="index, follow">
<meta name="author" content="Gnosis Geomatics">
<meta name="keywords" content="Gnosis Geomatics, survey equipment Nigeria, land surveying equipment, geomatics equipment, GNSS RTK, Total Station, survey drone, level instrument, hand held GPS, surveying tools, surveying equipment sales, survey equipment repairs, surveying services, geomatics consultation, GPS devices Nigeria, survey accessories">
<meta name="description" content="Gnosis Geomatics is a leading provider of land surveying and geomatics equipment in Nigeria. We specialize in GNSS RTK, Total Stations, drones, level instruments, hand held GPS devices, surveying tools, equipment repairs, surveying services, and professional consultation.">

<link rel="canonical" href="https://gnosisgeo.com/">

<!-- Open Graph -->
<meta property="og:type" content="website">
<meta property="og:site_name" content="Gnosis Geomatics">
<meta property="og:title" content="Gnosis Geomatics | Survey Equipment, GNSS, Total Station & Geomatics Services">
<meta property="og:description" content="Leading provider of land surveying and geomatics equipment in Nigeria. Explore GNSS RTK, Total Stations, drones, GPS devices, repairs, surveying services, and expert consultation.">
<meta property="og:url" content="https://gnosisgeo.com/">
<meta property="og:image" content="https://gnosisgeo.com/assets/images/logo.png">
<meta property="og:image:secure_url" content="https://gnosisgeo.com/assets/images/logo.png">
<meta property="og:image:width" content="1200">
<meta property="og:image:height" content="630">
<meta property="og:image:alt" content="Gnosis Geomatics Survey Equipment and Services">

<!-- Twitter Card -->
<meta name="twitter:card" content="summary_large_image">
<meta name="twitter:title" content="Gnosis Geomatics | Survey Equipment, GNSS, Total Station & Geomatics Services">
<meta name="twitter:description" content="Leading provider of land surveying and geomatics equipment in Nigeria. GNSS RTK, Total Stations, drones, GPS devices, repairs, surveying services, and consultation.">
<meta name="twitter:image" content="https://gnosisgeo.com/assets/images/logo.png">
<meta name="twitter:image:alt" content="Gnosis Geomatics Survey Equipment and Services">
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"></script>
<!-- Optional Theme Color -->
<meta name="theme-color" content="#2A95CB">

    <!-- Favicon -->
    <link rel="icon" type="image/x-icon" href="assets/images/icons/favicon.png">

    <script>
        WebFontConfig = {
            google: {
                families: ['Open+Sans:300,400,600,700,800', 'Poppins:300,400,500,600,700', 'Shadows+Into+Light:400']
            }
        };
        (function(d) {
            var wf = d.createElement('script'),
                s = d.scripts[0];
            wf.src = 'assets/js/webfont.js';
            wf.async = true;
            s.parentNode.insertBefore(wf, s);
        })(document);
    </script>

    <!-- Plugins CSS File -->
    <link rel="stylesheet" href="assets/css/bootstrap.min.css">

    <!-- Main CSS File -->
    <link rel="stylesheet" href="assets/css/style.min.css">
    <link rel="stylesheet" type="text/css" href="assets/vendor/fontawesome-free/css/all.min.css">
    
    <style>
        .product-single-image,
        .prod-thumbnail img,
        .product-default figure img {
            object-fit: cover;
        }

        .product-single-image {
            width: 100%;
            height: 468px;
        }

        .prod-thumbnail img {
            width: 110px;
            height: 110px;
            border-radius: 6px;
        }

        .product-default figure img {
            width: 100%;
            height: 280px;
        }

        .single-info-list li {
            margin-bottom: 8px;
        }

        .stock-badge {
            display: inline-block;
            padding: 6px 12px;
            border-radius: 20px;
            background: #eef7fc;
            color: #2A95CB;
            font-weight: 600;
            font-size: 13px;
            margin-bottom: 15px;
        }

        .product-single-details .btn {
            min-height: 46px;
        }

        .product-inquiry-note {
            font-size: 13px;
            color: #666;
            margin-top: 10px;
        }

        .product-desc p:last-child {
            margin-bottom: 0;
        }

        .product-single-tabs .tab-pane {
            padding-top: 20px;
        }

        .spec-table th {
            width: 220px;
            white-space: nowrap;
        }
    </style>
</head>

<body>
    <div class="page-wrapper">
   <?php include("header.php"); ?>

        <main class="main">
            
            
        

<div class="container">
    <nav aria-label="breadcrumb" class="breadcrumb-nav">
        <ol class="breadcrumb">
            <li class="breadcrumb-item"><a href="index.php"><i class="icon-home"></i></a></li>
            <li class="breadcrumb-item"><a href="shop.php">Products</a></li>
            <li class="breadcrumb-item"><a href="category.php?category=<?php echo urlencode($product['category']); ?>"><?php echo $productCategory; ?></a></li>
            <li class="breadcrumb-item active" aria-current="page"><?php echo $productName; ?></li>
        </ol>
    </nav>

    <div class="product-single-container product-single-default">
        <div class="row">
            <div class="col-lg-5 col-md-6 product-single-gallery">
                <div class="product-slider-container">
                    <?php if (!empty($productBadge) && !empty($productBadgeText)) : ?>
                        <div class="label-group">
                            <div class="product-label <?php echo $productBadge; ?>">
                                <?php echo $productBadgeText; ?>
                            </div>
                        </div>
                    <?php endif; ?>

                    <div class="product-single-carousel owl-carousel owl-theme show-nav-hover">
                        <?php foreach ($images as $img) : ?>
                            <div class="product-item">
                                <img class="product-single-image"
                                     src="<?php echo htmlspecialchars($img); ?>"
                                     data-zoom-image="<?php echo htmlspecialchars($img); ?>"
                                     width="468" height="468"
                                     alt="<?php echo $productName; ?>" />
                            </div>
                        <?php endforeach; ?>
                    </div>
                    <span class="prod-full-screen">
                        <i class="icon-plus"></i>
                    </span>
                </div>

                <div class="prod-thumbnail owl-dots">
                    <?php foreach ($images as $img) : ?>
                        <div class="owl-dot">
                            <img src="<?php echo htmlspecialchars($img); ?>" width="110" height="110" alt="<?php echo $productName; ?>" />
                        </div>
                    <?php endforeach; ?>
                </div>
            </div>

            <div class="col-lg-7 col-md-6 product-single-details">
                <h1 class="product-title"><?php echo $productName; ?></h1>

                <div class="product-nav">
                    <div class="product-prev">
                        <?php if ($prevProduct) : ?>
                            <a href="product.php?slug=<?php echo urlencode($prevProduct['slug']); ?>">
                                <span class="product-link"></span>
                                <span class="product-popup">
                                    <span class="box-content">
                                        <img alt="product" width="150" height="150"
                                             src="<?php echo htmlspecialchars(!empty($prevProduct['image1']) ? $prevProduct['image1'] : 'assets/images/placeholder.jpg'); ?>"
                                             style="padding-top: 0px;">
                                        <span><?php echo htmlspecialchars($prevProduct['product_name']); ?></span>
                                    </span>
                                </span>
                            </a>
                        <?php endif; ?>
                    </div>

                    <div class="product-next">
                        <?php if ($nextProduct) : ?>
                            <a href="product.php?slug=<?php echo urlencode($nextProduct['slug']); ?>">
                                <span class="product-link"></span>
                                <span class="product-popup">
                                    <span class="box-content">
                                        <img alt="product" width="150" height="150"
                                             src="<?php echo htmlspecialchars(!empty($nextProduct['image1']) ? $nextProduct['image1'] : 'assets/images/placeholder.jpg'); ?>"
                                             style="padding-top: 0px;">
                                        <span><?php echo htmlspecialchars($nextProduct['product_name']); ?></span>
                                    </span>
                                </span>
                            </a>
                        <?php endif; ?>
                    </div>
                </div>

                <div class="ratings-container">
                    <div class="product-ratings">
                        <span class="ratings" style="width:<?php echo $productRating; ?>%"></span>
                        <span class="tooltiptext tooltip-top"></span>
                    </div>
                </div>

                <hr class="short-divider">

                <div class="stock-badge"><?php echo $productStock; ?></div>

                <div class="price-box">
                    <?php if (!empty($productOldPrice)) : ?>
                        <span class="old-price">₦<?php echo $productOldPrice; ?></span>
                    <?php endif; ?>
                    <span class="new-price">₦<?php echo $productPrice; ?></span>
                </div>

                <div class="product-desc">
                    <p><?php echo $productShortSpecs; ?></p>
                </div>

                <ul class="single-info-list">
                    <li>SKU: <strong><?php echo $productSku; ?></strong></li>
                    <li>BRAND: <strong><?php echo $productBrand; ?></strong></li>
                    <li>MODEL: <strong><?php echo $productModel; ?></strong></li>
                    <li>CATEGORY: <strong><a href="category.php?category=<?php echo urlencode($product['category']); ?>" class="product-category"><?php echo $productCategory; ?></a></strong></li>
                    <?php if (!empty($tags)) : ?>
                        <li>
                            TAGS:
                            <?php foreach ($tags as $index => $tag) : ?>
                                <strong><a href="category.php?category=<?php echo urlencode($product['category']); ?>" class="product-category"><?php echo htmlspecialchars($tag); ?></a></strong><?php echo $index < count($tags)-1 ? ',' : ''; ?>
                            <?php endforeach; ?>
                        </li>
                    <?php endif; ?>
                </ul>

                <div class="product-action">
    <button type="button" class="btn btn-dark mr-2" data-bs-toggle="modal" data-bs-target="#productInquiryModal">
        Make Inquiry
    </button>

    <a href="category.php?category=<?php echo urlencode($product['category']); ?>" class="btn btn-gray">
        Browse Category
    </a>
</div>

                <div class="product-inquiry-note">
                    Need pricing, availability, repairs, setup support, or product guidance? Contact Gnosis Geomatics directly for fast assistance.
                </div>

                <hr class="divider mb-0 mt-4">

                <div class="product-single-share mb-3 mt-3">
                    <label class="sr-only">Share:</label>

                    <div class="social-icons mr-2">
                        <a href="https://www.facebook.com/sharer/sharer.php?u=<?php echo urlencode('https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']); ?>" class="social-icon social-facebook icon-facebook" target="_blank" title="Facebook"></a>
                        <a href="https://twitter.com/intent/tweet?url=<?php echo urlencode('https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']); ?>&text=<?php echo urlencode($product['product_name']); ?>" class="social-icon social-twitter icon-twitter" target="_blank" title="Twitter"></a>
                        <a href="https://www.linkedin.com/sharing/share-offsite/?url=<?php echo urlencode('https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']); ?>" class="social-icon social-linkedin fab fa-linkedin-in" target="_blank" title="Linkedin"></a>
                        <a href="mailto:?subject=<?php echo rawurlencode($product['product_name']); ?>&body=<?php echo rawurlencode('Check out this product: https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']); ?>" class="social-icon social-mail icon-mail-alt" target="_blank" title="Mail"></a>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <div class="product-single-tabs">
        <ul class="nav nav-tabs" role="tablist">
            <li class="nav-item">
                <a class="nav-link active" id="product-tab-desc" data-toggle="tab" href="#product-desc-content" role="tab" aria-controls="product-desc-content" aria-selected="true">Description</a>
            </li>

            <li class="nav-item">
                <a class="nav-link" id="product-tab-specs" data-toggle="tab" href="#product-specs-content" role="tab" aria-controls="product-specs-content" aria-selected="false">Specifications</a>
            </li>
        </ul>

        <div class="tab-content">
            <div class="tab-pane fade show active" id="product-desc-content" role="tabpanel" aria-labelledby="product-tab-desc">
                <div class="product-desc-content">
                    <p><?php echo $productDesc; ?></p>
                </div>
            </div>

            <div class="tab-pane fade" id="product-specs-content" role="tabpanel" aria-labelledby="product-tab-specs">
                <table class="table table-striped mt-2 spec-table">
                    <tbody>
                        <tr>
                            <th>Product Name</th>
                            <td><?php echo $productName; ?></td>
                        </tr>
                        <tr>
                            <th>Brand</th>
                            <td><?php echo $productBrand; ?></td>
                        </tr>
                        <tr>
                            <th>Model</th>
                            <td><?php echo $productModel; ?></td>
                        </tr>
                        <tr>
                            <th>Category</th>
                            <td><?php echo $productCategory; ?></td>
                        </tr>
                        <tr>
                            <th>Stock Status</th>
                            <td><?php echo $productStock; ?></td>
                        </tr>
                        <tr>
                            <th>Specifications</th>
                            <td><?php echo $productSpecs; ?></td>
                        </tr>
                    </tbody>
                </table>
            </div>
        </div>
    </div>

    <?php if (!empty($relatedProducts)) : ?>
        <div class="products-section pt-0">
            <h2 class="section-title">Related Products</h2>

            <div class="products-slider owl-carousel owl-theme dots-top dots-small">
                <?php foreach ($relatedProducts as $related) : ?>
                    <?php
                        $rImage1 = !empty($related['image1']) ? htmlspecialchars($related['image1']) : 'assets/images/placeholder.jpg';
                        $rImage2 = !empty($related['image2']) ? htmlspecialchars($related['image2']) : $rImage1;
                        $rName = htmlspecialchars($related['product_name']);
                        $rSlug = urlencode($related['slug']);
                        $rCategory = htmlspecialchars($related['category']);
                        $rPrice = number_format((float)$related['price'], 2);
                        $rOldPrice = (!empty($related['old_price']) && $related['old_price'] > $related['price']) ? number_format((float)$related['old_price'], 2) : '';
                        $rRating = (int)$related['rating'];
                    ?>
                    <div class="product-default">
                        <figure>
                            <a href="product.php?slug=<?php echo $rSlug; ?>">
                                <img src="<?php echo $rImage1; ?>" width="280" height="280" alt="<?php echo $rName; ?>">
                                <img src="<?php echo $rImage2; ?>" width="280" height="280" alt="<?php echo $rName; ?>">
                            </a>
                            <?php if (!empty($related['badge']) && !empty($related['badge_text'])) : ?>
                                <div class="label-group">
                                    <div class="product-label <?php echo htmlspecialchars($related['badge']); ?>">
                                        <?php echo htmlspecialchars($related['badge_text']); ?>
                                    </div>
                                </div>
                            <?php endif; ?>
                        </figure>

                        <div class="product-details">
                            <div class="category-list">
                                <a href="category.php?category=<?php echo urlencode($related['category']); ?>" class="product-category"><?php echo $rCategory; ?></a>
                            </div>

                            <h3 class="product-title">
                                <a href="product.php?slug=<?php echo $rSlug; ?>"><?php echo $rName; ?></a>
                            </h3>

                            <div class="ratings-container">
                                <div class="product-ratings">
                                    <span class="ratings" style="width:<?php echo $rRating; ?>%"></span>
                                    <span class="tooltiptext tooltip-top"></span>
                                </div>
                            </div>

                            <div class="price-box">
                                <?php if (!empty($rOldPrice)) : ?>
                                    <del class="old-price">₦<?php echo $rOldPrice; ?></del>
                                <?php endif; ?>
                                <span class="product-price">₦<?php echo $rPrice; ?></span>
                            </div>

                            <div class="product-action">
                                <a href="product.php?slug=<?php echo $rSlug; ?>" class="btn-icon btn-add-cart">
                                    <i class="fa fa-arrow-right"></i><span>VIEW DETAILS</span>
                                </a>
                            </div>
                        </div>
                    </div>
                <?php endforeach; ?>
            </div>
        </div>
    <?php endif; ?>
</div>

 
 
 
 
 
       <?php include("footer.php"); ?>
        
    </div>
   

    <div class="loading-overlay">
        <div class="bounce-loader">
            <div class="bounce1"></div>
            <div class="bounce2"></div>
            <div class="bounce3"></div>
        </div>
    </div>

    <div class="mobile-menu-overlay"></div>
    

 
   <?php include("mobile.php"); ?>

   <?php include("sticker.php"); ?>

 
    <a id="scroll-top" href="#top" title="Top" role="button"><i class="icon-angle-up"></i></a>

   <script src="assets/js/jquery.min.js"></script>
    <script src="assets/js/bootstrap.bundle.min.js"></script>
    <script src="assets/js/optional/isotope.pkgd.min.js"></script>
    <script src="assets/js/plugins.min.js"></script>
    <script src="assets/js/jquery.appear.min.js"></script>

   
    <script src="assets/js/main.min.js"></script>
    <div class="modal fade" id="productInquiryModal" tabindex="-1">
    <div class="modal-dialog">
        <div class="modal-content">
            <form action="product-inquiry-process.php" method="POST">
                <div class="modal-header">
                    <h5 class="modal-title">Product Inquiry</h5>
                    <button type="button" class="btn-close" data-bs-dismiss="modal"></button>
                </div>

                <div class="modal-body">
                    <input type="hidden" name="product_id" value="<?php echo (int)$product['id']; ?>">
                    <input type="hidden" name="product_name" value="<?php echo htmlspecialchars($product['product_name']); ?>">

                    <div class="mb-3">
                        <label>Your Name</label>
                        <input type="text" class="form-control" name="customer_name" required>
                    </div>

                    <div class="mb-3">
                        <label>Your Email</label>
                        <input type="email" class="form-control" name="customer_email" required>
                    </div>

                    <div class="mb-3">
                        <label>Your Phone</label>
                        <input type="text" class="form-control" name="customer_phone">
                    </div>

                    <div class="mb-3">
                        <label>Message</label>
                        <textarea class="form-control" name="message" rows="4" required>I am interested in <?php echo htmlspecialchars($product['product_name']); ?>. Please share availability and pricing.</textarea>
                    </div>
                </div>

                <div class="modal-footer">
                    <button class="btn btn-dark">Send Inquiry</button>
                </div>
            </form>
        </div>
    </div>
</div>
</body>

</html>