<?php
include("admin/connection.php");
function path()
{
    echo 'https://nmadvertiser.com/';
}

// 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://nmadvertiser.com/'; // 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);

?>
<!-- header -->
<?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'] : 'NM Advertiser Pvt. Ltd.'; ?></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">

    <!-- Mobile Specific Metas -->
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

    <!-- Favicons - Place favicon.ico in the root directory -->
    <link rel="icon" type="image/png" sizes="16x16" href="<?php path() ?>/assets/img/logo/fav.jpg">
    <link rel="manifest" href="<?php path() ?>/assets/img/favicons/manifest.json">
    <meta name="msapplication-TileColor" content="#ffffff">
    <meta name="msapplication-TileImage" content="<?php path() ?>/assets/img/favicons/ms-icon-144x144.png">
    <meta name="theme-color" content="#ffffff">

    <!--==============================
	  Google Fonts
	============================== -->
    <link rel="preconnect" href="https://fonts.googleapis.com/">
    <link
        href="https://fonts.googleapis.com/css2?family=Barlow:wght@400;500;600;700;800&amp;family=Roboto:wght@400;500;700;900&amp;display=swap"
        rel="stylesheet">

    <!--==============================
	    All CSS File
	============================== -->
    <!-- Bootstrap -->
    <link rel="stylesheet" href="<?php path() ?>/assets/css/bootstrap.min.css">
    <!-- Fontawesome Icon -->
    <link rel="stylesheet" href="<?php path() ?>/assets/css/fontawesome.min.css">
    <!-- Magnific Popup -->
    <link rel="stylesheet" href="<?php path() ?>/assets/css/magnific-popup.min.css">
    <!-- Slick Slider -->
    <link rel="stylesheet" href="<?php path() ?>/assets/css/slick.min.css">
    <!-- Theme Custom CSS -->
    <link rel="stylesheet" href="<?php path() ?>/assets/css/style.css">

</head>


<body>


    <!--==============================
Mobile Menu
============================== -->
    <div class="as-menu-wrapper">
        <div class="as-menu-area text-center">
            <button class="as-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="logo"></a>
            </div>
            <div class="as-mobile-menu">
                <ul>
                    <li>
                        <a href="<?php path() ?>index.php">Home</a>
                    </li>
                    <li>
                        <a href="<?php path() ?>about.php">About</a>
                    </li>
                    <?php
                    $ser = mysqli_query($con, "SELECT * FROM `upvc_door`");
                    if (mysqli_num_rows($ser) > 0) {
                    ?>
                        <li class="menu-item-has-children">
                            <a href="#">Services</a>
                            <ul class="sub-menu">
                                <?php while ($rowd = mysqli_fetch_array($ser)) {
                                    $title = $rowd['title'];
                                    $slug = $rowd['slug'];
                                ?>
                                    <li>
                                        <a href="<?php path(); ?>service-details.php?slug=<?php echo htmlspecialchars($slug); ?>">
                                            <?php echo htmlspecialchars($title); ?>
                                        </a>
                                    </li>

                                <?php } ?>
                            </ul>
                        </li>
                    <?php
                    } ?>

                    <?php
                    // Get all top categories
                    $top = mysqli_query($con, "SELECT * FROM `tbl_top_category`");
                    if (mysqli_num_rows($top) > 0) {
                    ?>

                        <li class="menu-item-has-children">
                            <a href="#">Signages Pic</a>
                            <ul class="sub-menu">
                                <?php while ($rows = mysqli_fetch_array($top)) {
                                    $cat_name = $rows['cat_name'];
                                    $slug = $rows['slug'];
                                ?>


                                    <a href="<?php path(); ?>signages-pic.php?slug=<?php echo htmlspecialchars($slug); ?>">
                                        <?php echo htmlspecialchars($cat_name); ?>
                                    </a>
                                <?php } ?>
                            </ul>
                        </li>
                    <?php } ?>
                    <li>
                        <a href="<?php path() ?>infrastructure.php">Infrastructure</a>
                    </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">Contant</a>
                    </li>

                </ul>
            </div>
        </div>
    </div>

    <!--==============================
Header Area
==============================-->
    <header class="as-header header-layout2">
        <div class="navbar-top">
            <div class="container-fluid">
                <div class="row">
                    <div class="col-xxl-7 col-lg-6 text-lg-start text-center">
                        <div class="header-links d-lg-inline-block d-none">
                            <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-xxl-5 col-lg-6 align-self-center text-lg-end text-center">
                        <div class="header-links">
                            <ul>

                                <li>
                                    <div class="header-social">
                                        <a href="https://www.facebook.com/"><i class="fab fa-facebook-f"></i></a>
                                        <a href="https://www.twitter.com/"><i class="fa-brands fa-instagram"></i></a>
                                        <a href="https://www.twitter.com/"><i class="fab fa-twitter"></i></a>
                                        <a href="https://www.linkedin.com/"><i class="fab fa-linkedin-in"></i></a>
                                        
                                    </div>
                                </li>
                                |
                                <li>
                                    <a href="">Download Brochure</a>
                                    <i class="fas fa-arrow-right ms-1"></i>
                                </li>
                            </ul>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="sticky-wrapper">
            <!-- Main Menu Area -->
            <div class="menu-area">
                <div class="logo-bg-shape"></div>
                <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="logo"></a>
                            </div>
                        </div>
                        <div class="col-auto">
                            <div class="menu-area">
                                <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</a>
                                        </li>
                                        <?php
                                        $ser = mysqli_query($con, "SELECT * FROM `upvc_door`");
                                        if (mysqli_num_rows($ser) > 0) {
                                        ?>
                                            <li class="menu-item-has-children">
                                                <a href="#">Services</a>
                                                <ul class="sub-menu">
                                                    <?php while ($rowd = mysqli_fetch_array($ser)) {
                                                        $title = $rowd['title'];
                                                        $slug = $rowd['slug'];
                                                    ?>
                                                        <li>
                                                            <a href="<?php path(); ?>service-details.php?slug=<?php echo htmlspecialchars($slug); ?>">
                                                                <?php echo htmlspecialchars($title); ?>
                                                            </a>
                                                        </li>

                                                    <?php } ?>
                                                </ul>
                                            </li>
                                        <?php
                                        } ?>
                                        <?php
                                        // Get all top categories
                                        $top = mysqli_query($con, "SELECT * FROM `tbl_top_category`");
                                        if (mysqli_num_rows($top) > 0) {
                                        ?>

                                            <li class="menu-item-has-children">
                                                <a href="#">Signages Pic</a>
                                                <ul class="sub-menu">
                                                    <?php while ($rows = mysqli_fetch_array($top)) {
                                                        $cat_name = $rows['cat_name'];
                                                        $slug = $rows['slug'];
                                                    ?>


                                                        <a href="<?php path(); ?>signages-pic.php?slug=<?php echo htmlspecialchars($slug); ?>">
                                                            <?php echo htmlspecialchars($cat_name); ?>
                                                        </a>
                                                    <?php } ?>
                                                </ul>
                                            </li>
                                        <?php } ?>
                                        <li>
                                            <a href="<?php path() ?>infrastructure.php">Infrastructure</a>
                                        </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">Contant</a>
                                        </li>
                                    </ul>

                                </nav>
                                <button type="button" class="as-menu-toggle d-inline-block d-lg-none"><i
                                        class="far fa-bars"></i></button>
                            </div>
                        </div>

                    </div>
                </div>
            </div>
        </div>
    </header>