<?php

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

@extract($_REQUEST);



if (preg_match('webpulse\.co$/', $_SERVER['HTTP_HOST'], $match)) {

  $match1 = $match[1];

  $vanity_url = 'http://' . $_SERVER['HTTP_HOST'];

}

$actual_link = "https://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";

$ee = explode('/', $actual_link);

$loc_url = $ee[3];

$cat_url = $_REQUEST['pid'];

$cats = ucwords(str_replace("-", " ", $_REQUEST['pid']));

$cat_s = "select catName, catID from category_tbl where catName='$cats' or catUrl='$cat_url'";

$cat_q = mysqli_query($GLOBALS['dbconn'], $cat_s);



if (mysqli_num_rows($cat_q) > 0) {

} else {

  header("Location: " . site_url);

  exit;

}

$num = mysqli_num_rows($cat_q);

$cat_r = mysqli_fetch_array($cat_q);

$category_id = $cat_r['catID'];

$hover = $category_id;

$catn = $cat_r['catName'];

$cat_sql = "select catImage, catName, displayName, catDesc, catID, catDesc1, parentID,catUrl,alt, title from category_tbl where parentID='$category_id' and status='Y'";

$cat_qry = mysqli_query($GLOBALS['dbconn'], $cat_sql);

$cccnum = mysqli_num_rows($cat_qry);

$cat_sql1 = "select catName, displayName, catID, parentID,catImage,catDesc1,catBanner,keyword1,keyword2,keyword3,catHeading1, catHeading2,alt,pageTitle,pageKeywords,pageDescription,multi_image,catDesc2 from category_tbl where catID='$category_id'";

$cat_qry1 = mysqli_query($GLOBALS['dbconn'], $cat_sql1);

$cat_res = mysqli_fetch_array($cat_qry1);

$pageTitles = $cat_res['catName'];

$disTitles = $cat_res['displayName'];



$parent = $cat_res['parentID'];

$cat_sql2 = "select catName, displayName, catID, parentID from category_tbl where catID='$parent'";

$cat_qry2 = mysqli_query($GLOBALS['dbconn'], $cat_sql2);

$num2 = mysqli_num_rows($cat_qry2);

$cat_res2 = mysqli_fetch_array($cat_qry2);

$mparent = $cat_res2['parentID'];

$cat_sql3 = "select catName, displayName, catID, parentID from category_tbl where catID='$mparent'";

$cat_qry3 = mysqli_query($GLOBALS['dbconn'], $cat_sql3);

$num3 = mysqli_num_rows($cat_qry3);

$cat_res3 = mysqli_fetch_array($cat_qry3);

$mmparent = $cat_res3['parentID'];

$cat_sql4 = "select catName, displayName, catID, parentID from category_tbl where catID='$mmparent'";

$cat_qry4 = mysqli_query($GLOBALS['dbconn'], $cat_sql4);

$num4 = mysqli_num_rows($cat_qry4);

$cat_res4 = mysqli_fetch_array($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'];

$multi_image = explode(',', $cat_res['multi_image']);



if ($cat_res['catImage'] != '') {

  $imglink = getImage($cat_res[catImage], 500, 500, $cat_res[catName], "/uploaded-files/category/images/");

} else {

  $imglink = getImage("noimage (10).jpg", 500, 500, "noimage", "/uploaded-files/category/images/");

}

$loc_sql = mysqli_query($GLOBALS['dbconn'], "select locationID,locationName,loc_url from location_tbl where loc_url='$loc_url' and status='Y'");

$location = mysqli_fetch_array($loc_sql);

$locationName = $location['locationName'];

$location_id = $location['locationID'];

$category_sub_general = mysqli_query($dbconn, "select location_ids,meta_title,meta_keyword,meta_description,description,short_description,subheadingtwo,description2 from location_content_tbl where category_id='$category_id' AND location_id='0'");

$content_count = mysqli_num_rows($category_sub_general);

if ($content_count > 0) {

  while ($categorysubdomain = mysqli_fetch_array($category_sub_general)) {

    $locati = explode(",", $categorysubdomain['location_ids']);

    if (in_array($location_id, $locati)) {

      if ($categorysubdomain['meta_title'] != '') {

        $page_metatitle1 = $categorysubdomain['meta_title'];

      }

      if ($categorysubdomain['meta_keyword'] != '') {

        $page_metakey1 = $categorysubdomain['meta_keyword'];

      }

      if ($categorysubdomain['meta_description']) {

        $page_metadesc1 = $categorysubdomain['meta_description'];

      }

      $page_desc = $categorysubdomain['description'];

      $page_desc2 = $categorysubdomain['description2'];

    }

  }

  //    specific location content

}



if ($cat_res['keyword1'] != '' && $cat_res['keyword2'] != '' && $cat_res['keyword3'] != '') {

  $m_title = "hotkeyword1 Services in location, hotkeyword2 Suppliers, Exporters in location";

  $page_metatitle = str_replace('hotkeyword1', $cat_res[keyword1], str_replace('hotkeyword2', $cat_res[keyword2], str_replace('location', $locationName, $m_title)));

  $m_keyword = "hotkeyword1 in location, hotkeyword2 in location, hotkeyword1 Services in location, hotkeyword2 Services in location, hotkeyword1 Suppliers in location, hotkeyword2 Suppliers in location, hotkeyword1 Exporters in location, hotkeyword2 Exporters in location";

  $page_metakey = str_replace('hotkeyword1', $cat_res[keyword1], str_replace('hotkeyword2', $cat_res[keyword2], str_replace('hotkeyword3', $cat_res[keyword3], str_replace('location', $locationName, $m_keyword))));

  $meta_des = "companyName leading hotkeyword1 Services in location, Since . Premium Quality hotkeyword2 Suppliers Exporters in location, Get latest factory price for hotkeyword3. ✓Fast Delivery ✓Good Price ✓Premium Quality";

  $page_metadesc = str_replace('hotkeyword1', $cat_res[keyword1], str_replace('hotkeyword2', $cat_res[keyword2], str_replace('hotkeyword3', $cat_res[keyword3], str_replace('companyName', $admin_res['companyName'], str_replace('phone', $admin_res['mobile_meta'], str_replace('location', $locationName, $meta_des))))));

} else if ($cat_res['keyword1'] != '' && $cat_res['keyword2'] != '') {

  $m_title = "hotkeyword1 Services in location, hotkeyword2 Suppliers Exporters in location";

  $page_metatitle = str_replace('hotkeyword1', $cat_res[keyword1], str_replace('hotkeyword2', $cat_res[keyword2], str_replace('location', $locationName, $m_title)));

  $m_keyword = "hotkeyword1 in location, hotkeyword2 in location, hotkeyword1 Services in location, hotkeyword2 Services in location, hotkeyword1 Suppliers in location, hotkeyword2 Suppliers in location";

  $page_metakey = str_replace('hotkeyword1', $cat_res[keyword1], str_replace('hotkeyword2', $cat_res[keyword2], str_replace('location', $locationName, $m_keyword)));

  $meta_des = "companyName leading hotkeyword1 Services in location, since . Premium Quality hotkeyword2 Suppliers, Exporters in location, Get latest factory price for hotkeyword1. ✓Fast Delivery ✓Good Price";

  $page_metadesc = str_replace('hotkeyword1', $cat_res[keyword1], str_replace('hotkeyword2', $cat_res[keyword2], str_replace('companyName', $admin_res[companyName], str_replace('phone', $admin_res['mobile_meta'], str_replace('location', $locationName, $meta_des)))));

} else if ($cat_res['keyword1'] != '') {

  $m_title = "hotkeyword1 Services in location, hotkeyword1 Suppliers Exporters in location";

  $page_metatitle = str_replace('hotkeyword1', $cat_res[keyword1], str_replace('location', $locationName, $m_title));

  $m_keyword = "hotkeyword1 in location, hotkeyword1 Services in location, hotkeyword1 Suppliers in location, hotkeyword1 Exporters in location";

  $page_metakey = str_replace('hotkeyword1', $cat_res[keyword1], str_replace('location', $locationName, $m_keyword));

  $meta_des = "companyName leading hotkeyword1 Services in location, Since . Premium Quality hotkeyword1 Suppliers Exporters in locationh, Get latest factory price for hotkeyword1. ✓Fast Delivery ✓Good Price ✓Premium Quality";

  $page_metadesc = str_replace('hotkeyword1', $cat_res[keyword1], str_replace('companyName', $admin_res[companyName], str_replace('phone', $admin_res['mobile_meta'], str_replace('location', $locationName, $meta_des))));

}

else {

  $page_metatitle = $page_metatitle1;

  $page_metakey = $page_metakey1;

  $page_metadesc = $page_metadesc1;

}

$page_desc = str_replace('countryname', $locationName, $page_desc);

$page_desc = str_replace('catname', $pid, $page_desc);

$page_desc = str_replace('{location}', $locationName, $page_desc);

$page_desc = str_ireplace('{companyName}', $admin_res['companyName'], $page_desc);

// for second description

$page_desc2 = str_replace('countryname', $locationName, $page_desc2);

$page_desc2 = str_replace('catname', $pid, $page_desc2);

$page_desc2 = str_replace('{location}', $locationName, $page_desc2);

$page_desc2 = str_ireplace('{companyName}', $admin_res['companyName'], $page_desc2);

// meta keywords

$page_metatitle = str_replace('countryname', $locationName, $page_metatitle);

$page_metatitle = str_replace('catname', $pid, $page_metatitle);

$page_metatitle = str_replace('{location}', $locationName, $page_metatitle);

$page_metakey = str_replace('countryname', $locationName, $page_metakey);

$page_metakey = str_replace('catname', $pid, $page_metakey);

$page_metakey = str_replace('{location}', $locationName, $page_metakey);

$page_metadesc = str_replace('countryname', $locationName, $page_metadesc);

$page_metadesc = str_replace('catname', $pid, $page_metadesc);

$page_metadesc = str_replace('{location}', $locationName, $page_metadesc);

// if location not checked in admin

$category_sub_uncheck_loc = mysqli_query($GLOBALS['dbconn'], "select description,subheadingtwo,meta_title,meta_keyword,meta_description,short_description,description2 from location_content_tbl where category_id='$category_id' AND location_id='0'");

$category_sub_uncheck_res = mysqli_fetch_array($category_sub_uncheck_loc);



// For metatitle 1 (uncheck location)

$page_metatitle = $category_sub_uncheck_res['meta_title'];

$page_metatitle= str_replace('{location}', $locationName,  $page_metatitle);

$page_metatitle= str_ireplace('{companyName}', $admin_res['companyName'], $page_metatitle);



// For metadescription 1 (uncheck location)

$page_metadesc = $category_sub_uncheck_res['meta_description'];

$page_metadesc= str_replace('{location}', $locationName,  $page_metadesc);

$page_metadesc= str_ireplace('{companyName}', $admin_res['companyName'], $page_metadesc);





// For metakeyword 1 (uncheck location)

$page_metakey = $category_sub_uncheck_res['meta_keyword'];

$page_metakey= str_replace('{location}', $locationName,  $page_metakey);

$page_metakey= str_ireplace('{companyName}', $admin_res['companyName'], $page_metakey);





// For description 1 (uncheck location)

$page_descUncheck = $category_sub_uncheck_res['description'];

$page_descUncheck = str_replace('{location}', $locationName,  $page_descUncheck);

$page_descUncheck = str_ireplace('{companyName}', $admin_res['companyName'], $page_descUncheck);

// For description 2 (uncheck location)

$page_desc2Uncheck = $category_sub_uncheck_res['description'];

$page_desc2Uncheck = str_replace('{location}', $locationName,  $page_desc2Uncheck);

$page_desc2Uncheck = str_ireplace('{companyName}', $admin_res['companyName'], $page_desc2Uncheck);

$page_desc = $page_desc != '' ? $page_desc : $page_descUncheck;

$page_desc2 = $page_desc2 != '' ? $page_desc2 : $page_desc2Uncheck;







// if ($cat_res['catHeading1'] != '') {

//   $heading1 = $cat_res['catHeading1'] . ' Services in ' . $locationName;

// } else {

//   $heading1 = $disTitles . ' Services in ' . $locationName;

// }



if ($cat_res['catHeading1'] != '') {

    $heading1 = $cat_res['catHeading1'] . ' in ' . $locationName;

} else {

    // Join array into a string

    $heading1 = explode(',', $page_metatitle)[0];

}



if ($cat_res['catHeading2'] != '') {

  $heading2 = $cat_res['catHeading2'] . ' in ' . $locationName;

} else {

  $heading2 = $disTitles . ' in ' . $locationName;

}



// if ($cat_res['alt'] != '') {

//   $alttag = $cat_res['alt'] . ' Services in ' . $locationName;

// } else {

//   $alttag = $disTitles . ' Services in ' . $locationName;

// }



if ($cat_res['alttag'] != '') {

    $alttag = $cat_res['alttag'] . ' in ' . $locationName;

} else {

    if ($cat_res['catID'] == '8') {

        $alttag = $cat_res['displayName'] . ' in ' . $locationName;

    } else {

        $alttag = explode(',', $page_metatitle)[0];

    }

}





if (mysqli_num_rows($loc_sql) > 0) {

} else {

  header("Location: " . site_url);

  exit;

}

?>

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

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

<body>
    <?php include 'apps/app_header_sub.php'; ?>

    <div class="heading_banner" style="background-image: url(<?=site_url;?>/assets/images/category-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"><?= $heading1; ?></h1>
                    <div class="clearfix"></div>
                    <!-- <div class="cat_title2">Explore the Science of Compatibility</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($loc_url); ?>/<?= getValidFileName($cat_res4['catName']); ?>.htm"
                                    title="<?php echo $cat_res4['displayName']; ?> "><?php echo $cat_res4['displayName']; ?></a>
                            </li>
                        <?php } ?>
                        <?php if ($num3 > 0) { ?>
                            <li><a href="<?= site_url; ?>/<?= getValidFileName($loc_url); ?>/<?= getValidFileName($cat_res3['catName']); ?>.htm"
                                    title="<?php echo $cat_res3['displayName']; ?>"><?php echo $cat_res3['displayName']; ?></a>
                            </li>
                        <?php } ?>
                        <?php if ($num2 > 0) { ?>
                            <li><a href="<?= site_url; ?>/<?= getValidFileName($loc_url); ?>/<?= getValidFileName($cat_res2['catName']); ?>.htm"
                                    title="<?php echo $cat_res2['displayName']; ?>"><?php echo $cat_res2['displayName']; ?></a>
                            </li>
                        <?php } ?>
                        <li class="active"><?php echo $cat_res['catName']; ?></li>
                    </ul>
                </div>
            </div>
        </div>
    </div>

    <div class="category_page">
        <div class="container">
            <!-- <h2 class="title_1"><?= $heading2; ?></h2> -->
            <div class="clearfix"></div>
            <div class="row">
                <div class="col-xxl-12 col-xl-12 col-lg-12 col-md-12 col-sm-12 col-12">
                    <div class="wps_right">
                        <div class="product_right_image">
                            <div data-bs-toggle="modal" data-bs-target="#productID" onclick="$('.catID').val('<?php echo $cat_res['catID']; ?>');
                                     $('.catName').html('<?php echo $cat_res['catName']; ?>'); $('.catImg').attr('src','<?= $imglink; ?>');  $('.catImg').attr('alt','<?= $alttag; ?>'); $('.catImg').attr('title','<?= $alttag; ?>');" title="Consult With Astrologer">
                                <div class="detail_image">
                                    <img class="img-responsive" src="<?= $imglink; ?>" alt="<?= $alttag; ?>" title="<?= $alttag; ?>">
                                </div>
                                <span class="mainBtn3">
                                    <span>
                                        <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> Consult with Astrologer
                                    </span>
                        </span>
                            </div>

                        </div>
                        <?php echo html_entity_decode($page_desc); ?>

                        <div class="clearfix"></div>

                        <div class="you_may">All Astrology Services</div>
                        <div class="allListing">

                        <?php
                                if (mysqli_num_rows($cat_qry) > 0) {
                                    $subcat_sql = $cat_qry;
                                } else {
                                    $sqlsub2 = mysqli_query($GLOBALS['dbconn'], "select catImage, catName, displayName, catDesc, catID, catDesc1, alt, title, parentID from category_tbl where parentID ='$parent' and status='Y' and catID!='$category_id' order by catOrder Asc");
                                    if (mysqli_num_rows($sqlsub2) > 1) {
                                        $subcat_sql = $sqlsub2;
                                    } else {
                                        $subcat_sql = mysqli_query($GLOBALS['dbconn'], "select catImage, catName, displayName,catDesc, catID, alt, title, catDesc1, parentID from category_tbl  where parentID ='0' and status='Y' and catID!='$category_id' order by catOrder Asc");
                                    }
                                }
                                while ($sub_res = mysqli_fetch_array($subcat_sql)) {
                                    if ($sub_res['catImage'] != '') {
                                        $img_link = getImage($sub_res[catImage], 415, 415, $sub_res[catName], "/uploaded-files/category/images/");
                                        $img_link1 = getImage($sub_res[catImage], 415, 415, $sub_res[catName], "/uploaded-files/category/images/");
                                    } else {
                                        $img_link = getImage("noimage (10).jpg",  415, 415, "noimage", "/uploaded-files/category/images/");
                                        $img_link1 = getImage("noimage (10).jpg", 415, 415, "noimage", "/uploaded-files/category/images/");
                                    }
                                    $caturls1 = !empty($sub_res['catUrl']) ? $sub_res['catUrl'] : $sub_res['catName'];

                                    $sub_desc = $sub_res['catDesc'];
            
            
            
                                    $catIdss = $sub_res['catID'];
            
                                                $sql_content = mysqli_query($GLOBALS['dbconn'], "select subheadingtwo,short_description,meta_title,meta_keyword,meta_description from location_content_tbl where category_id ='$catIdss'");
            
                                                $res_content = mysqli_fetch_array($sql_content);
            
                                                $subcontent_descc = html_entity_decode($res_content['short_description']);
            
                                                $subcontent_desccc = str_replace('{location}', $locationName, $subcontent_descc);
            
                                                $subcontent_descccc = str_replace('catname', $res_cat['catName'], $subcontent_desccc);
            
                                                $subcontent_descccc = str_ireplace('{companyName}', $admin_res['companyName'], $subcontent_descccc);
            
            
            
                                                if ($sub_res['alt'] != '') {
            
                                                    $alttag1 = $sub_res['alt'] . ' in ' . $locationName;
            
                                                } else {
            
                                                    if ($sub_res['catID'] == '8') {
            
                                                        $alttag1 = $sub_res['displayName'] . ' in ' . $locationName;
            
                                                    } else {
            
                                                        $alttag1 = $sub_res['displayName'] . ' in ' . $locationName;
            
                                                    }
            
                                                }

                                   


                                ?>

                            <div class="product_listing">
                                <div class="row">
                                    <div class="col-xxl-4 col-xl-4 col-lg-4 col-md-4 col-sm-5 col-12">
                                        <div class="product">
                                            <a href="<?= site_url; ?>/<?= getValidFileName($loc_url); ?>/<?= getValidFileName($caturls1); ?>.htm" title="<?= $alttag1; ?>">
                                                <div class="image1">
                                                    <img src="<?= $img_link; ?>" alt="<?= $alttag1; ?>"
                                                    title="<?= $alttag1; ?>">
                                                </div>
                                            </a>
                                        </div>
                                    </div>
                                    <div class="col-xxl-8 col-xl-8 col-lg-8 col-md-8 col-sm-7 col-12">
                                        <div class="right-content">
                                            <h4 class="titleH3_1"><a href="<?= site_url; ?>/<?= getValidFileName($loc_url); ?>/<?= getValidFileName($caturls1); ?>.htm" title="<?= $alttag1; ?>"><?= $sub_res['displayName']; ?> in <?=$locationName;?></a></h4>
                                            <div class="blue-line1"></div>
                                            <div class="more_info">
                                                <p><?= $subcontent_descccc; ?></p>

                                            </div>

                                            <div class="buttons">
                                                <button type="button" class="mainBtn3" data-bs-toggle="modal" data-bs-target="#productID" onclick="$('.catID').val('<?php echo $sub_res['catID']; ?>');$('.catName').html('<?php echo $sub_res['catName']; ?>');$('.catImg').attr('src','<?= $img_link1; ?>'); $('.catImg').attr('alt','<?= $sub_res['displayName']; ?> in <?= $locationName; ?>'); $('.catImg').attr('title','<?= $sub_res['displayName']; ?> in <?= $locationName; ?>');" title="Consult With Astrologer">
                                                    <span>
                                                        <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" />
                                                        </svg> Consult with Astrologer</span>
                                                </button>

                                                <a href="<?= site_url; ?>/<?= getValidFileName($loc_url); ?>/<?= getValidFileName($caturls1); ?>.htm" class="mainBtn4" title="Read More">
                                                    <span> Read More <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" viewBox="0 0 16 16">
                                                            <path fill-rule="evenodd" d="M4.646 1.646a.5.5 0 0 1 .708 0l6 6a.5.5 0 0 1 0 .708l-6 6a.5.5 0 0 1-.708-.708L10.293 8 4.646 2.354a.5.5 0 0 1 0-.708z"></path>
                                                        </svg></span>
                                                </a>
                                            </div>

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

  <?php include "apps/app_testimonials.php"; ?>
    <?php include 'apps/app_footer_sub.php'; ?>
    <?php include 'apps/app_bottom.php'; ?>
</body>

</html>