<?php
include("admin/connection.php");
function path()
{
    echo 'https://starfieldsystem.wedigitalindia.in/';
}
// meta tag
ini_set('display_errors', '1');
ini_set('display_startup_errors', '1');
error_reporting(E_ALL);

$actual_link = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
// echo $actual_link;exit;
$host = $_SERVER['HTTP_HOST'];
$currentURL = $_SERVER['REQUEST_URI'];


if (strpos($currentURL, 'index') !== false) {
    $redirectURL = 'https://starfieldsystem.wedigitalindia.in/'; // Change this URL to your desired destination
    header('Location: ' . $redirectURL);
    // exit;
}

$query = "SELECT * FROM meta_tag WHERE url='$actual_link'  ";
$meta_all = mysqli_query($con, $query);
$metaRow = mysqli_fetch_array($meta_all);

?>
<?php
$query = "SELECT * FROM `header` LIMIT 1";
$sql = mysqli_query($con, $query);
$row = mysqli_fetch_assoc($sql);
?>
<!doctype html>
<html class="no-js" lang="zxx">

<head>
    <meta charset="utf-8">
    <meta http-equiv="x-ua-compatible" content="ie=edge">
    <title><?php echo isset($metaRow['meta_title']) ? $metaRow['meta_title'] : 'Star Filed System'; ?></title>
    <meta name="author" content="themeholy">
    <meta name="description" content="<?php echo isset($metaRow['description']) ? htmlspecialchars(strip_tags($metaRow['description'])) : 'Default site description.'; ?>">
    <meta name="keywords" content="<?php echo isset($metaRow['meta_key']) ? $metaRow['meta_key'] : 'Default, Keywords'; ?>">
    <meta name="robots" content="INDEX,FOLLOW">
    <meta name="viewport" content="width=device-width,initial-scale=1,shrink-to-fit=no">
    <link rel="icon" type="image/x-icon" href="<?php path() ?>/assets/img/favicons/fav.png">
    <link rel="manifest" href="<?php path() ?>/assets/img/favicons/manifest.json">
    <link rel="preconnect" href="<?php path() ?>/https://fonts.googleapis.com/">
    <link rel="preconnect" href="<?php path() ?>/https://fonts.gstatic.com/" crossorigin>
    <link
        href="https://fonts.googleapis.com/css2?family=Exo:wght@300;400;500;600;700;800;900&amp;family=Public+Sans:wght@100;200;300;400;500;600;700&amp;display=swap"
        rel="stylesheet">
        <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.2/css/all.min.css">
    <link rel="stylesheet" href="<?php path() ?>/assets/css/app.min.css">
    <link rel="stylesheet" href="<?php path() ?>/assets/css/fontawesome.min.css">
    <link rel="stylesheet" href="<?php path() ?>/assets/css/style.css">
</head>

<body>

    <div class="th-menu-wrapper">
        <div class="th-menu-area text-center"><button class="th-menu-toggle"><i class="fal fa-times"></i></button>
            <div class="mobile-logo"><a href="<?php path() ?>/index.php"><img src="<?php path(); ?>/admin/assets/images/slider/<?php echo $row['logo']; ?>" alt="Konta"></a></div>
            <div class="th-mobile-menu">
                <ul>
                    <li><a href="<?php path() ?>/index.php">Home</a></li>
                    <li><a href="<?php path() ?>/about.php">About Us</a></li>

                    <?php
                    // Get all top categories
                    $topQuery = "SELECT * FROM tbl_top_category ORDER BY cat_name DESC";
                    $topResult = mysqli_query($con, $topQuery);
                    ?>

                    <li class="menu-item-has-children"><a href="javascript:;">Our Product</a>
                        <ul class="sub-menu">
                            <?php while ($topRow = mysqli_fetch_assoc($topResult)) {
                                $topCatId = $topRow['id'];

                                // Get mid categories for this top category
                                $midQuery = "SELECT * FROM mid_category WHERE id='$topCatId' ORDER BY title DESC";
                                $midResult = mysqli_query($con, $midQuery);

                            ?>
                                <li class="menu-item-has-children">
                                    <a href="#"><?php echo htmlspecialchars($topRow['cat_name']); ?></a>
                                    <?php
                                    if (mysqli_num_rows($midResult) > 0) { ?>
                                        <ul class="sub-menu">
                                            <?php while ($midRow = mysqli_fetch_assoc($midResult)) { ?>
                                                <li>
                                                    <a href="service-details.php?slug=<?php echo htmlspecialchars($midRow['slug']); ?>">
                                                        <?php echo htmlspecialchars($midRow['title']); ?>
                                                    </a>
                                                </li>
                                            <?php } ?>
                                        </ul>
                                <?php }
                                } ?>
                                </li>

                        </ul>
                    </li>
                    <li><a href="Application.php">Application Area</a></li>
                    <li class="menu-item-has-children"><a href="#">Knowledge Centre</a>
                        <ul class="sub-menu">
                            <li><a href="knowledge.php#Technologies">FAQ About Star Filed System </a></li>
                            <li><a href="knowledge.php#Coating">Concept of Powder Coating </a></li>
                            <li><a href="knowledge.php#Benefits">Benefits of Powder Coating</a></li>
                            <li><a href="knowledge.php#Advantages">Advantages Of Powder Coating </a></li>
                            <li><a href="knowledge.php#Plant">Tentative Cost of Powder Coating Plant </a></li>
                            <li><a href="knowledge.php#Process">Pre-Treatment before Powder Coating Process </a></li>
                            <li><a href="knowledge.php#Parts">Parts of Powder Coating Plant </a></li>
                        </ul>
                    </li>
                    <li class="menu-item-has-children"><a href="#">Gallery</a>
                        <ul class="sub-menu">
                            <li><a href="<?php path() ?>/gallery.php">Images</a></li>
                            <li><a href="<?php path() ?>/video.php">Video</a></li>
                        </ul>
                    </li>

                    <li><a href="<?php path() ?>/blog.php">Blog</a></li>
                    <li><a href="<?php path() ?>/contact.php">Contact Us</a></li>

                </ul>
            </div>
        </div>
    </div>
    <div class="popup-search-box d-none d-lg-block">
        <button class="searchClose"><i class="fal fa-times"></i></button>
        <form action="#"><input type="text" placeholder="What are you looking for?">
            <button type="submit"><i class="fal fa-search"></i></button>
        </form>
    </div>

    <header class="th-header header-layout11">
        <div class="header-top">
            <div class="container-fluid">
                <div class="row justify-content-center justify-content-md-between align-items-center gy-2">
                    <div class="col-auto d-none d-md-block">
                        <div class="header-links">
                            <ul>
                                <?php
                                $fullPhone = $row['phone'] ?? '';
                                $firstPhoneOnly = explode(',', $fullPhone)[0];
                                $cleanTel = preg_replace('/\D/', '', $firstPhoneOnly);
                                ?>

                                <li>
                                    <i class="far fa-phone"></i>
                                    <a href="tel:+91<?php echo $cleanTel; ?>">
                                        <?php echo htmlspecialchars(trim($firstPhoneOnly)); ?>
                                    </a>
                                </li>

                                <?php

                                $fullEmail = $row['email'] ?? '';
                                $firstEmailOnly = explode('<br', $fullEmail)[0];
                                $firstEmailOnly = explode(',', $firstEmailOnly)[0];
                                $firstEmailOnly = trim(strip_tags($firstEmailOnly));
                                ?>
                                <li>
                                    <i class="far fa-envelope"></i>
                                    <a href="mailto:<?php echo htmlspecialchars($firstEmailOnly); ?>">
                                        <?php echo htmlspecialchars($firstEmailOnly); ?>
                                    </a>
                                </li>
                            </ul>
                        </div>
                    </div>
                    <div class="col-auto" style="text-align: center;">
                        <div class="header-links">
                            <ul>

                                <li>
                                    <div class="header-social">
                                        <span class="social-title">Follow Us:</span> 
                                        <a href="https://www.facebook.com/"><i class="fab fa-facebook-f"></i></a>
                                         <a href="https://www.facebook.com/"><i class="fa-brands fa-instagram"></i></a>
                                        <a href="https://www.twitter.com/"><i class="fa-brands fa-x-twitter"></i></a>
                                        <a href="https://www.linkedin.com/"><i class="fab fa-linkedin-in"></i></a>
                                        <a href="https://www.whatsapp.com/"><i class="fa-brands fa-youtube"></i></a>
                                        <a href="assets/img/favicons/Catalog-Design.pdf" class="download th-btn" download>
                                            Download Brochure <i class="fas fa-arrow-right ms-1"></i></a>
                                    </div>
                                </li>
                            </ul>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="sticky-wrapper">
            <div class="sticky-active">
                <div class="menu-area" data-bg-src="">
                    <div class="container-fluid">
                        <div class="row align-items-center justify-content-between">
                            <div class="col-auto">
                                <div class="header-logo"><a href="<?php path(); ?>/index.php">
                                        <img src="<?php path(); ?>/admin/assets/images/slider/<?php echo $row['logo']; ?>"
                                            alt="Konta"></a></div>
                            </div>
                            <div class="col-auto">
                                <div class="row align-items-center">
                                    <div class="col-auto">
                                        <nav class="main-menu d-none d-lg-inline-block">
                                            <ul>
                                                <li><a href="<?php path() ?>/index.php">Home</a></li>
                                                <li><a href="<?php path() ?>/about.php">About Us</a></li>
                                                <?php
                                                // Get all top categories
                                                $topQuery = "SELECT * FROM tbl_top_category ORDER BY cat_name DESC";
                                                $topResult = mysqli_query($con, $topQuery);
                                                ?>

                                                <li class="menu-item-has-children"><a href="javascript:;">Our Product</a>
                                                    <ul class="sub-menu">
                                                        <?php while ($topRow = mysqli_fetch_assoc($topResult)) {
                                                            $topCatId = $topRow['id'];

                                                            // Get mid categories for this top category
                                                            $midQuery = "SELECT * FROM mid_category WHERE id='$topCatId' ORDER BY title DESC";
                                                            $midResult = mysqli_query($con, $midQuery);

                                                        ?>
                                                            <li class="menu-item-has-children">
                                                                <a href="#"><?php echo htmlspecialchars($topRow['cat_name']); ?></a>
                                                                <?php
                                                                if (mysqli_num_rows($midResult) > 0) { ?>
                                                                    <ul class="sub-menu">
                                                                        <?php while ($midRow = mysqli_fetch_assoc($midResult)) { ?>
                                                                            <li>
                                                                                <a href="service-details.php?slug=<?php echo htmlspecialchars($midRow['slug']); ?>">
                                                                                    <?php echo htmlspecialchars($midRow['title']); ?>
                                                                                </a>
                                                                            </li>
                                                                        <?php } ?>
                                                                    </ul>
                                                            <?php }
                                                            } ?>
                                                            </li>

                                                    </ul>
                                                </li>


                                                <li><a href="Application.php">Application Area</a></li>
                                                <li class="menu-item-has-children"><a href="#">Knowledge Centre</a>
                                                    <ul class="sub-menu">
                                                        <li><a href="knowledge.php#Technologies">FAQ About Star Filed System</a></li>
                                                        <li><a href="knowledge.php#Coating">Concept of Powder Coating </a></li>
                                                        <li><a href="knowledge.php#Benefits">Benefits of Powder Coating</a></li>
                                                        <li><a href="knowledge.php#Advantages">Advantages Of Powder Coating </a></li>
                                                        <li><a href="knowledge.php#Plant">Tentative Cost of Powder Coating Plant </a></li>
                                                        <li><a href="knowledge.php#Process">Pre-Treatment before Powder Coating Process </a></li>

                                                        <li><a href="knowledge.php#Parts">Parts of Powder Coating Plant </a></li>
                                                    </ul>
                                                </li>
                                                <li class="menu-item-has-children"><a href="#">Gallery</a>
                                                    <ul class="sub-menu">
                                                        <li><a href="<?php path() ?>/gallery.php">Images</a></li>
                                                        <li><a href="<?php path() ?>/video.php">Video</a></li>
                                                    </ul>
                                                </li>
                                                <!--<li><a href="video.php">Video</a></li> -->

                                                <li><a href="<?php path() ?>/blog.php">Blog</a></li>
                                                <li><a href="<?php path() ?>/contact.php">Contact Us</a></li>

                                            </ul>
                                        </nav><button type="button" class="th-menu-toggle d-inline-block d-lg-none"><i
                                                class="far fa-bars"></i></button>
                                    </div>


                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="logo-shape"></div>
                </div>
            </div>
        </div>
    </header>