<?php include_once("include/main.inc.php");


 $filename = basename($_SERVER['REQUEST_URI']);  
$filename = str_replace(".htm", "", $filename);

// Extract product ID
$parts = explode("-", $filename);
$product_id = end($parts);


   $sql_latest = mysqli_query($dbconn, "select * from product_tbl where product_id='$product_id'");
   $res_latest = mysqli_fetch_array($sql_latest);

   $admin_sql = mysqli_query($GLOBALS['dbconn'], "select * from admin_details");
   $admin_res = mysqli_fetch_array($admin_sql);

   $productdisplay = $res_latest['product_title'];
   $page_metatitle =  $productdisplay . ' in '. 'Delhi';
   $page_metadesc = $productdisplay . ' in '. 'Delhi';
   $page_metakey = $productdisplay . ' in '. 'Delhi';
   $product_image =  explode(',', $res_latest['product_image']);

   $product_id=$res_latest['product_id'];
   $productbig_img = $product_image[0];
   $prod_img = getImage($productbig_img, 500, 500, $res_latest['product_title'], "/uploaded-files/product-images/");

   
   // Product Category IDs (main category)
$productCatIds = explode(',', $res_latest['product_cat']);

// Product Sub Category IDs
$productSubCatIds = explode(',', $res_latest['prodcut_subcat']);

// Merge both arrays
$prodIds = array_merge($productCatIds, $productSubCatIds);

// Remove duplicate IDs (optional)
$prodIds = array_unique($prodIds);

if (!empty($productSubCatIds[0]) && $productSubCatIds[0] != "") {
    $primaryCat = $productSubCatIds[0];
} elseif (!empty($productCatIds[0]) && $productCatIds[0] != "") {
    $primaryCat = $productCatIds[0];
} else {
    $primaryCat = 0;  // fallback
}

$categoryIds = $primaryCat;


$cat_sql1="SELECT * FROM category_tbl WHERE catID='$primaryCat'";
$cat_qry1=mysqli_query($dbconn,$cat_sql1);
$cat_res=mysqli_fetch_array($cat_qry1);

// Parent Level 1
$parent = $cat_res['parentID'];
$cat_sql2="SELECT * FROM category_tbl WHERE catID='$parent'";
$cat_qry2=mysqli_query($dbconn,$cat_sql2);
$cat_res2=mysqli_fetch_array($cat_qry2);
$num2 = mysqli_num_rows($cat_qry2);

// Parent Level 2
$mparent = $cat_res2['parentID'];
$cat_sql3="SELECT * FROM category_tbl WHERE catID='$mparent'";
$cat_qry3=mysqli_query($dbconn,$cat_sql3);
$cat_res3=mysqli_fetch_array($cat_qry3);
$num3 = mysqli_num_rows($cat_qry3);

// Parent Level 3
$mmparent = $cat_res3['parentID'];
$cat_sql4="SELECT * FROM category_tbl WHERE catID='$mmparent'";
$cat_qry4=mysqli_query($dbconn,$cat_sql4);
$cat_res4=mysqli_fetch_array($cat_qry4);
$num4 = mysqli_num_rows($cat_qry4);

$mobile = $admin_res['mobile'];
$city = $admin_res['city'];
$state = $admin_res['state'];
$country = $admin_res['country'];
$companyName = $admin_res['companyName'];
$address = $admin_res['address'];

$alt = explode(',', $page_metatitle);
   $alt_tags = $productdisplay . ' Manufacturers, Suppliers, Exporters in '. 'Delhi';   
   

   ?>


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

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <?php include "app_top.php"; ?>
</head>

<body>
    <?php include "app_header.php"; ?>

    <div class="heading_banner" style="background-image: url(<?= site_url; ?>/designer/images/about-banner.jpg)">
        <div class="container">
            <div class="row">
                <div class="col-xxl-12 col-xl-12 col-lg-12 col-md-12 col-sm-12 col-12 text-center">
                    <h1 class="cat_title"><?= $productdisplay; ?></h1>
                    <div class="clearfix"></div>
                </div>
            </div>
        </div>
    </div>

    <div class="inner_breadcrumb hidden_xs">
        <div class="container">
            <div class="row">
                <div class="col-xxl-12 col-xl-12 col-lg-12 col-md-12 col-sm-12 col-12">
                    <ul class="breadcrumb">
                       <li><a href="<?= site_url; ?>" title="Home">Home</a></li>
                        <?php if ($num4 > 0) { ?>
                        <li><a href="<?= site_url; ?>/<?= getValidFileName($cat_res4['catName']); ?>.htm"
                                title="<?php echo $cat_res4['catName']; ?>"><?php echo $cat_res4['catName']; ?></a></li>
                        <?php } ?>
                        <?php if ($num3 > 0) { ?>
                        <li><a href="<?= site_url; ?>/<?= getValidFileName($cat_res3['catName']); ?>.htm"
                                title="<?php echo $cat_res3['catName']; ?>"><?php echo $cat_res3['catName']; ?></a></li>
                        <?php  } ?>
                        <?php if ($num2 > 0) { ?>
                        <li><a href="<?= site_url; ?>/<?= getValidFileName($cat_res2['catName']); ?>.htm"
                                title="<?php echo $cat_res2['catName']; ?>"><?php echo $cat_res2['catName']; ?></a></li>
                        <?php  } ?>
                        <li><a href="<?= site_url; ?>/<?= getValidFileName($cat_res['catName']); ?>.htm"
                                title="<?php echo $cat_res['catName']; ?>"><?php echo $cat_res['catName']; ?></a></li>
                            <li class="active"><?php echo $res_latest['product_title']; ?></li>
                    </ul>
                </div>
            </div>
        </div>
    </div>


    <section class="about_page">
        <div class="container">
            <!-- <h1 class="detailsTitle">Product Details</h1> -->
            <div class="clearfix"></div>
            <div class="row">
                <div class="col-xxl-9 col-xl-9 col-lg-9 col-md-9 col-sm-12 col-12">
                    <div class="productFullDetails">
                        <div class="detailSlider">

                                <?php 
                                $totalImages = count($product_image);
                                ?>
                            <!-- Main Slider -->
                            <div class="swiper main-slider <?php if($totalImages <= 1){ echo 'no-slider'; } ?>">
                                 
                                <div class="swiper-wrapper">
                                         <?php foreach($product_image as $pro_imag_vals){ ?>
                                    <div class="swiper-slide"><img src="<?= site_url; ?>/uploaded-files/product-images/<?= $pro_imag_vals; ?>" 
                                    alt="<?=$alt_tags;?>" 
                                    title="<?=$alt_tags;?>">
                                </div>
                                  <?php } ?>

                                    

                                </div>


                                <!-- <div class="swiper-button-next"></div>
                            <div class="swiper-button-prev"></div> -->
                            </div>

                             <?php if($totalImages > 1){ ?>
                            <!-- Thumbnail Slider -->
                            <div class="swiper thumb-slider">
                                
                                <div class="swiper-wrapper">

                               <?php foreach($product_image as $pro_imag_vals){ ?>

                                    <div class="swiper-slide"><img src="<?= site_url; ?>/uploaded-files/product-images/<?= $pro_imag_vals; ?>"
                                    alt="<?=$alt_tags;?>" 
                                    title="<?=$alt_tags;?>">
                                
                                </div>

                                 <?php } ?>


                                </div>
                            </div>
                           <?php } ?>

                        </div>

                        <h2><?= $productdisplay; ?></h2>
                        
                        <?= html_entity_decode($res_latest['product_specfi']); ?>
                        <?= html_entity_decode($res_latest['product_specfi1']); ?>                    


                        <a class="readMore" href="javascript:void(0);" data-bs-toggle="modal" data-bs-target="#productID" title="Get Best Quote">
                                                        Get Best Quote <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" viewBox="0 0 16 16">
                                                            <path d="M.05 3.555A2 2 0 0 1 2 2h12a2 2 0 0 1 1.95 1.555L8 8.414.05 3.555ZM0 4.697v7.104l5.803-3.558L0 4.697ZM6.761 8.83l-6.57 4.027A2 2 0 0 0 2 14h12a2 2 0 0 0 1.808-1.144l-6.57-4.027L8 9.586l-1.239-.757Zm3.436-.586L16 11.801V4.697l-5.803 3.546Z"></path>
                           </svg></a>

                    </div>
                </div>

                <div class="col-xxl-3 col-xl-3 col-lg-3 col-md-3 col-sm-12 col-12">
                    <div class="rightSideBar">
                        <div class="rightSideBarTitle">Cable Tray</div>
                        <ul>
                            <li><a href="<?= site_url; ?>/galvanized-perforated-cable-tray.htm" title="Galvanized Perforated Cable Tray">Galvanized Perforated Cable Tray</a></li>
                            <li><a href="<?= site_url; ?>/channel-type-cable-tray.htm" title="Channel Type Cable Tray">Channel Type Cable Tray</a></li>
                            <li><a href="<?= site_url; ?>/galvanized-cable-tray.htm" title="Galvanized Cable Tray">Galvanized Cable Tray</a></li>
                            <li><a href="<?= site_url; ?>/mild-steel-cable-tray.htm" title="Mild Steel Cable Tray">Mild Steel Cable Tray</a></li>
                            <li><a href="<?= site_url; ?>/ladder-cable-trays.htm" title="Ladder Cable Trays">Ladder Cable Trays</a></li>
                            <li><a href="<?= site_url; ?>/raceway-cable-tray.htm" title="Raceway Cable Tray">Raceway Cable Tray</a></li>
                            <li><a href="<?= site_url; ?>/slotted-channel.htm" title="Slotted Channel">Slotted Channel</a></li>
                            <li><a href="<?= site_url; ?>/gi-earthing-strip.htm" title="Gi Earthing Strip">Gi Earthing Strip</a></li>
                            <li><a href="<?= site_url; ?>/solar-rooftop-walkways.htm" title="Solar Rooftop Walkways">Solar Rooftop Walkways</a></li>
                            <li><a href="<?= site_url; ?>/perforated-cable-trays.htm" title="Perforated Cable Trays">Perforated Cable Trays</a></li>
                            <li><a href="<?= site_url; ?>/cable-tray-fittings.htm" title="Cable Tray Fittings">Cable Tray Fittings</a></li>
                            <li><a href="<?= site_url; ?>/raceway-junction-box.htm" title="Raceway Junction Box">Raceway Junction Box</a></li>
                        </ul>
                    </div>
                </div>
            </div>
        </div>
    </section>

    <?php include "app_faq.php"; ?>
    <?php include "app_clients.php"; ?>
    <?php include "app_footer.php"; ?>
    <?php include "app_bottom.php"; ?>
    <script>
        // Initialize thumbnail swiper
        var thumbSwiper = new Swiper(".thumb-slider", {
            spaceBetween: 10,
            slidesPerView: 8,
            freeMode: true,
            watchSlidesProgress: true,
        });

        // Initialize main swiper
        var mainSwiper = new Swiper(".main-slider", {
            spaceBetween: 10,
            loop: true,
            autoplay: {
                delay: 3000,
                disableOnInteraction: false,
            },
            navigation: false,
            navigation: {
                nextEl: ".swiper-button-next",
                prevEl: ".swiper-button-prev",
            },
            thumbs: {
                swiper: thumbSwiper,
            },
        });
    </script>

</body>

</html>