<?php
$server_host = $_SERVER['HTTP_HOST'];
if(str_replace("www.", "", $server_host) != $real_domainname) {
	$server_host .= "/$real_addonname";
}

$microdata_domain = str_replace("www.", "", $ultra_domainname);
$microdata_host = $_SERVER['HTTP_HOST'];
if(str_replace('www.', '', $microdata_host) != str_replace('www.', '', $ultra_domainname)) $microdata_host .= "/" . $ultra_addonname;
$have_microdata = (isset($microdata_domains) && in_array($microdata_domain, $microdata_domains));

$show_bl_business = true;

$q = "select c.* from left_content c, module m where c.catdom_id='$domain_id' and c.module_id=m.module_id
	and m.url='bl_middle' and c.`type`='module' and c.location='middle' and c.module_active='yes' and c.module_params !=''
";
$r = @mysql_query($q);
if($r && mysql_num_rows($r) > 0) {
	$row = mysql_fetch_assoc($r);
	$bl_mp = unserialize(base64_decode($row['module_params']));
	$bl_categ_uids = array();
	if(isset($bl_mp['module_bl_categs']) && is_array($bl_mp['module_bl_categs'])) {
		$bl_categ_uids = array_keys($bl_mp['module_bl_categs']);
		$bl_categ_uids_str = "";
		$bl_title = (isset($bl_mp['module_bl_title'])) ? trim(stripslashes($bl_mp['module_bl_title'])) : '';
		$bl_description = (isset($bl_mp['module_bl_description'])) ? trim(stripslashes($bl_mp['module_bl_description'])) : '';
		if(count($bl_categ_uids) > 0) {
			$bl_temp = array();
			foreach ($bl_categ_uids as $i=>$t_uid) {
				$bl_temp [] = "'" . $t_uid . "'";
			}
			$bl_categ_uids_str = implode(",", $bl_temp);
		}
		else {
            if(isset($_REQUEST['debug'])) {
                echo '<br><pre>$bl_mp[module_bl_categs] = '.var_export($bl_mp['module_bl_categs'], true).'</pre>';
                echo '<br><pre>$bl_categ_uids = '.var_export($bl_categ_uids, true).'</pre>';
                echo '<br>' . $q;
            }
            else {

                $send404 = true;
                $show_bl_business = false;
            }

		}
	}
	else {
        if(isset($_REQUEST['debug'])) {
            echo '<br><pre>'.var_export($bl_mp, true).'</pre>';
            echo '<br>' . $q;
        }
        else {

            $send404 = true;
            $show_bl_business = false;
        }

	}
}
else {

	if(isset($_REQUEST['debug'])) {
        echo '<br>Must 404';
        echo '<br>' . $q;
    }
    else {

        $send404 = true;
        $show_bl_business = false;
    }
}


$optres['css'][] = $module_css_path . "amodules/bl_middle/css/bl_middle.css";
//$optres['js'][] = "$path" . "js/jquery-ui-1.8.23.custom.min.js";

if($show_bl_business) {
	ob_start();

	$bl_lang = "en";
	$is_canonical = false;
	$display_bl_content = true;
	require_once(dirname(__FILE__) . "/functions/bl_list_entries.php");
	if(isset($bl_categ) && $bl_categ != "") {

		//if($show_bl_adverts) include($modules_path. "adverts/adverts.php");
		$yp_limit = 50;

		if(in_array(str_replace('www.', '', $ultra_domainname), $special_domains) ) {
            $yp_limit = 9999999;
        }

		$bl_categ = trim($bl_categ);
		if(strpos($bl_categ, ",") !== false) {
			$tmp = explode(",", $bl_categ);
			$categ_furl = trim($tmp[0]);
			$yp_page = intval($tmp[1]);

            $is_canonical = true;

			if(isset($bl_alias_lang)) {
				$canonical_link = $protocol . $server_host . "/listings/$bl_alias_lang/" . urlencode($categ_furl);
			}
			else {
				$canonical_link = $protocol . $server_host . "/listings/" . urlencode($categ_furl);
			}
			if($yp_page > 1) {
				$canonical_link .= ",$yp_page";
			}
			
		}
		else {
			$is_canonical = true;
			$categ_furl = $bl_categ;
			$yp_page = 1;

            if(isset($bl_alias_lang)) {
                $canonical_link = $protocol . $server_host . "/listings/$bl_alias_lang/" . urlencode($categ_furl);
            }
            else {
                $canonical_link = $protocol . $server_host . "/listings/" . urlencode($categ_furl);
            }
		}

		/* furniture - noindex/follow*/
		/*if(str_replace('www.', '', $ultra_domainname) == "cyprusfurniture.com") {
			$meta_robots = "noindex, follow";
		}*/


		
		$is_alias = false;
		if(isset($bl_alias_lang)) {
			$is_alias = true;
			$bl_lang = $bl_alias_lang;
		}
		
		if(isset($categ_furl)) {
			if(!$is_alias) {
				$q = "select cy_admin_title_en, cy_description_en as cy_description, cy_keywords_en as cy_keywords, uid, cy_friendly_name_en from bl_categories where uid in ($bl_categ_uids_str) and cy_friendly_name_en='$categ_furl';";
			}
			else {
				$q = "select l.title as cy_admin_title_en, l.cy_description_en as cy_description, l.cy_keywords_en as cy_keywords, l.uid, l.district, l.location, c.cy_friendly_name_en as canonical from bl_categories_links l, bl_categories c where l.uid=c.uid and l.friendly_name='$categ_furl' and c.uid in ($bl_categ_uids_str);";
				
				$rt = @mysql_query($q);
				if(!$rt || mysql_num_rows($rt) <=0) {
					$q = "select l.alias_id, l.title as cy_admin_title_en, l.cy_description, l.cy_keywords, l.uid, l.district, l.location, c.cy_friendly_name_en as canonical from bl_categories_links_tr l, bl_categories c where l.uid=c.uid and l.friendly_name='$categ_furl' and c.uid in ($bl_categ_uids_str);";
				}
			}
			
			if(isset($_REQUEST['debug_bl'])) {
				echo $q;
			}
			
			$ask_real_categs = true;
			
			$r = @mysql_query($q);
			if($r && mysql_num_rows($r) > 0) {
				$row = mysql_fetch_assoc($r);
				$categ_uid = $row['uid'];
				$categ_title = stripslashes($row['cy_admin_title_en']);
				$_categ_title = $categ_title;
				if((isset($canonical_link) && $canonical_link != "") ) {
					$webpage_title_en = $_categ_title . ($yp_page > 1 ? ' | Page ' . $yp_page : '');
				}
				else {
					$webpage_title_en = $_categ_title;
				}

                $categ_keywords = $webpage_title_en;
				
				if($is_alias && isset($row['alias_id'])) {
					$alias_id = $row['alias_id'];
					$qa = "select * from bl_categories_links where id='$alias_id' and uid='$categ_uid' order by title asc, lang asc;";
					$ra = @mysql_query($qa);
					if($ra && mysql_num_rows($ra) == 1) {
						$rowa = mysql_fetch_assoc($ra);
						$pre_alias_title = $rowa["title"];

                        $categ_keywords = $pre_alias_title;
					}
					
					$meta['description'] = 'Listings of ' . $pre_alias_title . (($bl_lang !="" && $bl_lang !="en") ? ' in ' . ucfirst($dlc[$bl_lang]) : '');
				}
				else {
					$meta['description'] = 'Listings of ' . $_categ_title . (($bl_lang !="" && $bl_lang !="en") ? ' in ' . $dlc[$bl_lang] : '');
				}

                $breadcrumbs [] = [
                    "title" => $categ_keywords,
                    "link" => $canonical_link
                ];


				$meta['description'] .= ' | ' . $_categ_title;
				
				if(!$is_canonical && $yp_page > 0) {
					$meta['description'] .= ' - Page ' . $yp_page;
				}
				
				
				if(isset($_REQUEST['debugbl'])) {
					echo $q . '<br/>';
					echo '<pre>', var_export($row, true), '</pre>';
					echo '<pre>', var_export($meta, true), '</pre>';
				}
				
				$cy_description = trim(stripslashes($row['cy_description']));
				$cy_keywords = trim(stripslashes($row['cy_keywords']));
				$yp_canonical = '';
				if(isset($row['canonical'])) {
					$yp_canonical = trim($row['canonical']);
					//$canonical_link = $protocol . $server_host . "/listings/$yp_canonical";
				}
				
				$yp_district = isset($row['district']) ? trim($row['district']) : '';
				$yp_location = isset($row['location']) ? trim($row['location']) : '';
				
				?>
                    <header>
					    <h1><span lang="<?php echo $bl_lang; ?>" xml:lang="<?php echo $bl_lang; ?>"><?php echo $categ_title . '</span>' . (($yp_page > 1) ? ' | Page ' . $yp_page : '');?></h1>
                        <!--[/SocialShareButtons/]-->
                    </header>
					<div class="article-body cyprus">
						<?php



                        if($cy_keywords != "") {
                            if(!isset($meta) || !is_array($meta)) {
                                $meta = array();
                                $meta['keywords'] = $cy_keywords;
                            }
                            else {
                                $meta['keywords'] = $cy_keywords;
                            }
                        }
                        else {
                            $meta['keywords'] = $categ_keywords;
                        }
                        if($cy_description != "" && mb_strlen($cy_description, 'UTF-8') > 80) {
                            $meta_description = mb_substr($cy_description, 0, 150, 'UTF-8');
                            if(!isset($meta) || !is_array($meta)) {
                                $meta = array();
                                $meta['description'] = $meta_description;
                            }
                            else {
                                $meta['description'] = $meta_description;
                            }
                            ?>
                            <p class="bl-description" lang="<?php echo $bl_lang; ?>" xml:lang="<?php echo $bl_lang; ?>"><?php echo nl2br(htmlentities($cy_description, ENT_COMPAT, 'UTF-8'));?></p>
                            <?php
                        }

                        if($show_bl_adverts) {
							$hide_adverts_title = 1;
							include($modules_path. "adverts/adverts.php");
						}

						$yp_data_search = bl_list_entries($categ_uid, "$yp_district/$yp_location", $yp_page, $yp_limit, $bl_lang);
						$yp_total_records = $yp_data_search['total_records'];
						$yp_data = $yp_data_search['data'];
						$yp_data_tr = (isset($yp_data_search['data_tr']) && count($yp_data_search['data_tr']) > 0) ? $yp_data_search['data_tr'] : array(); 
						//echo '<pre>$yp_data_search = ',print_r($yp_data_search), '</pre>';
						if($yp_data && count($yp_data) > 0) {
                            ?>
                            <div class="box box-primary">
                            <?php
							foreach ($yp_data as $b_uid=>$b_data) {
								$locations = $b_data['locations'];
								$locations_tr = array();
								$num_locs = count($locations);
								
								if(isset($yp_data_tr[$b_uid]) && count($yp_data_tr[$b_uid]['locations']) > 0) {
									$locations_tr = $yp_data_tr[$b_uid]['locations'];
								}
								
								//echo '<pre>', var_export($locations_tr), '</pre>';
								
								?>

								<div class="row bl-list-row no-margin" <?php echo ($have_microdata) ? 'itemscope itemtype="' . $microdata_types[$microdata_domain]['adverts']['type'] . '"' : '';?>>
									
									
									<?php
									$td_locs = array(
										"district"	=> array(),
										"tel"		=> array(),
										"fax"		=> array()
									);
									$cnt = 0;
									foreach ($locations as $i=>$loc) {
										$have_loc_data = false;
										$l_tr = array();
										$location_id = $loc['id'];
										if(count($locations_tr) > 0) {
											foreach ($locations_tr as $tri=>$loc_tr) {
												if($loc_tr['location_id'] == $location_id) {
													$l_tr = $loc_tr;
													break;
												}
											}
										}
										
									
										$td_locs_tmp = array(
											"district"	=> (count($l_tr) > 0) ? $l_tr['district'] : $loc['district'],
											"tel"		=> "&nbsp;",
											"fax"		=> "&nbsp;"
										);
										
										$tels = array();
										if($loc['tel1'] != "") $tels [] = $loc['tel1'];
										if($loc['tel2'] != "") $tels [] = $loc['tel2'];
										
										$faxes = array();
										if($loc['fax1'] != "") $faxes [] = $loc['fax1'];
										if($loc['fax2'] != "") $faxes [] = $loc['fax2'];
										
										
										if(count($tels) > 0) {
											$have_loc_data = true;
											$td_locs_tmp['tel'] = implode(", ", $tels) . "";
										}
										
										if(count($faxes) > 0) {
											$have_loc_data = true;
											$td_locs_tmp['fax'] =  implode(", ", $faxes). "";
										}
										
										if($have_loc_data) {
											if(count($l_tr) > 0) {
												$td_locs ['district'][] = isset($loc['show_location']) ? $l_tr['location'] : $l_tr['district'];
											}
											else {
												$td_locs ['district'][] = isset($loc['show_location']) ? $loc['location'] : $td_locs_tmp['district'];
											}
											$td_locs ['tel'][] = $td_locs_tmp['tel'];
											$td_locs ['fax'][] = $td_locs_tmp['fax'];
										}
										
										
									}
									
									?>
                                    <div class="col-md-4 col-sm-3">
										<?php
										$microdata_url =  ($have_microdata) ? 'itemprop="url"' : '';
										$microdata_name =  ($have_microdata) ? 'itemprop="name"' : '';
										if(isset($yp_data_tr[$b_uid])) {
											$b_data = $yp_data_tr[$b_uid];
											$b_data['name'] = str_replace(".", ". ", $b_data['name']);
											echo '<a href="'. $protocol . $server_host.'/listings/name/'.$bl_lang.'/'.$b_data['friendly_name'].'" class="yp_link" '.$microdata_url.' target="_blank"><span '.$microdata_name.' lang="'.$bl_lang.'" xml:lang="'.$bl_lang.'">', $b_data['name'], '</span></a>';
										}
										else {
											$b_data['name'] = str_replace(".", ". ", $b_data['name']);
											echo '<a href="'. $protocol . $server_host.'/listings/name/'.$b_data['friendly_name'].'" class="yp_link" '.$microdata_url.'><span '.$microdata_name.'>', $b_data['name'], '</span></a>';
										}
										?>
									</div>
                                    <div class="col-md-6 col-sm-7">
											<?php
											$cnt = 1;
											for($i=0; $i<count($td_locs['district']); $i++) {
												?>
												<div class="row no-margin" <?php echo ($have_microdata) ? 'itemprop="address" itemscope itemtype="http://schema.org/PostalAddress"' : '';?>>
													<?php
                                                    foreach ($td_locs as $td_type=>$td_array) {
                                                        $yp_val = trim($td_array[$i]);
                                                        $yp_tmp = "&nbsp;";
                                                        $col_class = "col-sm-3 col-xs-3";

                                                        if($td_type == "district") {
                                                            $col_class = "col-sm-4 col-xs-4";
                                                            if($have_microdata) {
                                                                $yp_tmp = '<meta itemprop="addressCountry" content="CY">';
                                                                $yp_tmp .= '<span itemprop="addressRegion">';
                                                            }
                                                            //$yp_val = $yp_val;
                                                            $yp_tmp .= '<strong><i class="fa fa-map-marker" title="Telephone"></i> ' . $yp_val . '</strong>';
                                                            if($have_microdata) {
                                                                $yp_tmp .= '</span>';
                                                            }
                                                        }

                                                        if($td_type == "tel" && $yp_val != "&nbsp;") {
                                                            $col_class = "col-sm-3 col-xs-3";
                                                            $yp_tmp .= '<strong><i class="fa fa-phone" title="Telephone"></i> </strong>';
                                                            if($have_microdata) {
                                                                $yp_tmp = '<span itemprop="telephone">' . $yp_val;
                                                            }
                                                            else {
                                                                $yp_tmp .= $yp_val;
                                                            }
                                                            if($have_microdata) {
                                                                $yp_tmp .= '</span>';
                                                            }
                                                        }

                                                        if($td_type == "fax" && $yp_val !="&nbsp;") {
                                                            $col_class = "col-sm-3 col-xs-3";
                                                            $yp_tmp = '<strong><i class="fa fa-fax" title="Fax"></i> </strong>';
                                                            if($have_microdata) {
                                                                $yp_tmp = '<span itemprop="faxNumber">' . $yp_val;
                                                            }
                                                            else {
                                                                $yp_tmp .= $yp_val;
                                                            }
                                                            if($have_microdata) {
                                                                $yp_tmp .= '</span>';
                                                            }
                                                        }
                                                        ?>
                                                        <div class="<?=$col_class;?> no-padding"><?php echo $yp_tmp;?></div>
                                                        <?php
                                                    }
													?>
												</div>
												<?php
											}
											?>
									</div>
										
								</div>
								<?php
								
							}
							?>
                            </div>
							<?php
						}
						else {
							$send404 = true;
							$display_bl_content = false;
						}
						if($yp_total_records > $yp_limit) {
							$nrpages = intval(ceil($yp_total_records/$yp_limit));
							$yp_from = ($yp_page == 1) ? 0 : $yp_page * $yp_limit;
							$page = $yp_limit;
							
							$rel_url = $protocol . $server_host . '/listings/';
							if(isset($bl_alias_lang) && $bl_alias_lang != "") {
								$rel_url .= $bl_alias_lang . '/';
							}
							
							
							if($yp_page == 1 && $nrpages > 1) {
								$rel_next_page = $rel_url . urlencode($categ_furl) . ',2';
							}
							if($yp_page > 1 && $yp_page <= $nrpages) {
								if($yp_page == 2) {
									$rel_prev_page = $rel_url . urlencode($categ_furl);
								}
								else {
									$rel_prev_page = $rel_url . urlencode($categ_furl) . ',' . ($yp_page - 1);
								}
								
								if($yp_page <= $nrpages - 1) {
									$rel_next_page = $rel_url . urlencode($categ_furl) . ',' . ($yp_page + 1);
								}
								
							}
							
							if($yp_page > $nrpages || $yp_page <= 0) {
								
								
								
								$send404 = true;
								$display_bl_content = false;
							}
							
							?>
							<div class="search-results-pagination text-left">

									<?php
									$pages_to_show = 5;
									$prev_text = "&laquo;";
									$next_text = "&raquo;";
									
									$P = $yp_page;
									
									$plinks = array(
										"prev" => array(),
										"left" => array(),
										"middle" => array(),
										"right"	=> array(),
										"next"	=> array()
									);
									//echo '<pre>', print_r($plinks), '</pre>';
									$uri = $_SERVER['REQUEST_URI'];
									$comma_pos = strpos($uri, ",");
									if($comma_pos !== false) {
										$uri = mb_substr($uri, 0, $comma_pos, 'UTF-8');
									}
									
									//$link_url = $protocol . $server_host . $uri;
									//$link_url = $protocol . $_SERVER['HTTP_HOST'] . $uri;
									
									$link_url = $protocol . $server_host . '/listings/';
									if(isset($bl_alias_lang) && $bl_alias_lang != "") {
										$link_url .= $bl_alias_lang . '/';
									}
									
									$link_url .= urlencode($categ_furl);
									
									
									if($P + 2 > $pages_to_show) {
										for($i=2; $i>=1; $i--) {
											$cur_p = $P - $i;
											$cur_from = ($cur_p-1) * $page;
											$plink['left'][] = array(
												"href" 	=> $link_url . ",$cur_p",
												"rel"	=> $cur_from,
												"text"	=> $cur_p,
												"page"	=> $cur_p
											);
										}
										
										$cur_p = $P;
										$cur_from = ($cur_p-1) * $page;
										$plink['middle'][] = array(
												"href" 	=> $link_url . ",$cur_p",
												"rel"	=> $cur_from,
												"text"	=> $cur_p,
												"page"	=> $cur_p
											);
										if($nrpages > $P) {	
											
											for($i=1; $i<=($P+2 <= $nrpages ? 2 : $nrpages-$P); $i++) {
												$cur_p = $P + $i;
												$cur_from = ($cur_p-1) * $page;
												$plink['right'][] = array(
													"href" 	=> $link_url . ",$cur_p",
													"rel"	=> $cur_from,
													"text"	=> $cur_p,
													"page"	=> $cur_p
												);
											}
										}
									}
									else {
										for($i=1; $i<=($nrpages < 5 ? $nrpages : 5); $i++) {
											$cur_p = $i;
											$cur_from = 0;
											$plink['left'][] = array(
												"href" 	=> $link_url . ",$cur_p",
												"rel"	=> $cur_from,
												"text"	=> $cur_p,
												"page"	=> $cur_p
											);
										}
									}
									
									if($P>1) {
										$cur_p = $P - 1;
										$cur_from = ($cur_p-1) * $page;
										$plink['prev'][] = array(
											"href" 	=> $link_url . ",$cur_p",
											"rel"	=> $cur_from,
											"text"	=> '&laquo; ' . 'Prev',
											"page"	=> $cur_p
										);
									}
									
									if($nrpages > $P) {
										$cur_p = $P + 1;
										$cur_from = ($cur_p-1) * $page;
										$plink['next'][] = array(
											"href" 	=> $link_url . ",$cur_p",
											"rel"	=> $cur_from,
											"text"	=> 'Next' . ' &raquo;',
											"page"	=> $cur_p
										);
									}
									
									ob_start();
									?>
									<nav>
                                        <ul class="pagination">
									    <?php
										//echo '<textarea cols=80 rows=10><pre>', print_r($plink),'</pre></textarea>';
										//echo '<div id="ui-paginator" style="padding: 0px 3px;">';
										if(isset($plink['prev']) && count($plink['prev']) > 0) {
											$p_class = "pag_num lnext";
											$ld = $plink['prev'][0];
											echo '<li><a href="' . $ld['href'] . '" rel="'.$ld['rel'].'" class="'.$p_class.'">' . $ld['text'] . '</a></li>';
										}
										else {
											//echo '<li><span aria-hidden="true">' . $ld['text'] . '</span></li>';
										}
										
										$margins = array(
											"left" => array(),
											"right" => array(),
										);
										if($P>=5) {
											
											for($i=1; $i<=1; $i++) {
												$cur_p = $i;
												$cur_from = ($cur_p-1) * $page;
												$margins['left'][] = array(
													"href" 	=> $link_url . "," . $cur_p,
													"rel"	=> $cur_from,
													"text"	=> $cur_p,
													"page"	=> $cur_p
												);
											}
											
											foreach ($margins['left'] as $i=>$ld) {
												$p_class = "pag_num";
												echo '<li><a href="' . $ld['href'] . '" rel="'.$ld['rel'].'" class="'.$p_class.'">' . $ld['text'] . '</a></li>';
											}
											echo '<li><span> ... </span> </li>';
										}
										
										foreach ($plink as $pos_label => $pos) {
											foreach ($pos as $i=>$ld) {
												$p_class = "pag_num";
												if($pos_label != "prev" && $pos_label != "next") {
													if($ld['page'] == $P) {
														echo '<li class="active"><span class="current">' . $ld['text'] . '</span></li>';
													}
													else {
														echo '<li><a href="' . $ld['href'] . '" rel="'.$ld['rel'].'" class="'.$p_class.'">' . $ld['text'] . '</a></li>';
													}
												}
											}
										}
										
										if($P+3 < $nrpages) {
											
											for($i=1; $i<=1; $i++) {
												$cur_p = $nrpages;
												$cur_from = ($cur_p-1) * $page;
												$margins['right'][] = array(
													"href" 	=> $link_url . "," . $cur_p,
													"rel"	=> $cur_from,
													"text"	=> $cur_p,
													"page"	=> $cur_p
												);
											}
											echo '<li><a href="#"> ... </a> </li>';
											foreach ($margins['right'] as $i=>$ld) {
												$p_class = "pag_num";
												echo '<li><a href="' . $ld['href'] . '" rel="'.$ld['rel'].'" class="'.$p_class.'">' . $ld['text'] . '</a></li>';
											}
											
										}
										
										if(isset($plink['next']) && count($plink['next']) > 0) {
											$p_class = "pag_num lnext";
											$ld = $plink['next'][0];
											echo '<li><a href="' . $ld['href'] . '" rel="'.$ld['rel'].'" class="'.$p_class.'">' . $ld['text'] . '</a></li>';
										}
										else {
											//echo '<li><span aria-hidden="true" class="text-muted">&raquo;</span></li>';
										}
										//echo '</div>';
									?>
                                        </ul>
                                        </nav>
                                        <?php
									
									$pagination_code = ob_get_contents();
									ob_end_clean();
									echo $pagination_code;
						
									?>
								</div>
							<?php
						}
						
						?>
					</div>

				<?php
				//echo '<pre>', print_r($_SERVER), '</pre>';
			}
			else {
				if(isset($_REQUEST['debug_bl'])) {
					echo "<br>First else";
				}
				$send404 = true;
				$display_bl_content = false;
			}
		}
		else {
			$send404 = true;
			$display_bl_content = false;
		}
	}
	else {

		/* furniture - noindex/follow*/
		/*if(str_replace('www.', '', $ultra_domainname) == "cyprusfurniture.com") {
			$meta_robots = "noindex, follow";
		}*/

		$canonical_link = $protocol . $server_host . "/listings";

		$dir_module_id = $req_modules['bl_middle']['module_id'];
		$q = "select * from left_content where catdom_id='$domain_id' and module_id='$dir_module_id' and type='module' and location='middle';";
		if(isset($_REQUEST['debug_bl'])) {
			echo "<br>2) $q";
		}
		$r = @mysql_query($q);
		if($r && mysql_num_rows($r) > 0) {
			$row = mysql_fetch_assoc($r);
			$dir_params = trim($row['module_params']) != "" ? unserialize(base64_decode($row['module_params'])) : false;
			//print_r($dir_params);
			if($dir_params && isset($dir_params['module_bl_categs'])) {
				$module_bl_categs =  $dir_params['module_bl_categs'];
				$uids = array();
				foreach (array_keys($module_bl_categs) as $categ_uid) {
					$uids [] = "'" . $categ_uid . "'";
				}
				$uids_str = implode(",", $uids);
				
				$locations_links = array();

				
				$q = "select * from bl_categories where uid in ($uids_str) order by cy_admin_title_en";
				$r = @mysql_query($q);
				if($r && mysql_num_rows($r) > 0) {

                    if(isset($bl_title) && trim($bl_title) != "") {
                        $webpage_title_en = $bl_title;
                    }
                    else {
                        $webpage_title_en = $webpage_title_en . ' Listings';
                    }

                    if(isset($bl_description) && trim($bl_description) != "") {
                        $meta['description'] = $bl_description;
                    }
                    else {
                        $meta['description'] = "Extensive list of $webpage_title_en";
                    }

                    $meta['keywords'] = $webpage_title_en;
                    ?>
                    <header>
                        <h1><?php echo $webpage_title_en;?></h1>
                        <!--[/SocialShareButtons/]-->
                    </header>
                    <div class="article-body">
						<div class="list-group">
							<?php
							while ($row = mysql_fetch_assoc($r)) {
								$c_friendly_name = $row['cy_friendly_name_en'];
								$c_title = stripslashes($row['cy_admin_title_en']);
								$c_uid = $row['uid'];

								if(in_array(str_replace('www.', '', $ultra_domainname), $special_domains) ) {
                                    $c_title = str_replace("Cyprus ", "", $c_title);
                                }
								
								?>
								<div class="list-group-item">
                                    <a href="<?php echo $protocol . $server_host;?>/listings/<?php echo urlencode($c_friendly_name);?>" title="<?php echo $c_title;?>"><?php echo $c_title;?></a>
									<?php
									
									$qa = "select * from bl_categories_links where uid='$c_uid' order by title asc, lang asc;";
									if(isset($_REQUEST['debug'])) {
										echo "<br/>$qa";
									}
									$ra = @mysql_query($qa);
									if($ra && mysql_num_rows($ra)>0) {
										echo '<div class="list-group inner">';
										while ($rowa = mysql_fetch_assoc($ra)) {
											$al_id = $rowa['id'];
											$al_title = stripslashes($rowa['title']);
											$al_friendly_name = stripslashes($rowa['friendly_name']);
											$al_lang = $rowa['lang'];

											if(in_array(str_replace('www.', '', $ultra_domainname), $special_domains) ) {
                                                $al_title = str_replace("Cyprus ", "", $al_title);
                                            }

											if(trim($al_friendly_name) != "") {
												echo '<div class="list-group-item">';
												?>
												<i class="fa fa-list-ul"></i> <a href="<?php echo $protocol . $server_host;?>/listings/<?php echo $al_lang;?>/<?php echo urlencode($al_friendly_name);?>" title="<?php echo $al_title;?>"><?php echo $al_title;?></a>
												<?php
												$qaa = "select * from bl_categories_links_tr where alias_id='$al_id' order by title asc, lang asc;";
												if(isset($_REQUEST['debug'])) {
													echo "<br/>$qaa";
												}
												$raa = @mysql_query($qaa);
												if($raa && mysql_num_rows($raa)>0) {
													echo '<div class="list-group inner">';
													while ($rowaa = mysql_fetch_assoc($raa)) {
														$ala_title = stripslashes($rowaa['title']);
														$ala_friendly_name = stripslashes($rowaa['friendly_name']);
														$ala_lang = $rowaa['lang'];

														if(in_array(str_replace('www.', '', $ultra_domainname), $special_domains) ) {
                                                            $ala_title = str_replace("Cyprus ", "", $ala_title);
														}

														if(trim($ala_friendly_name) != "") {
															echo '<div class="list-group-item">';
															?>
                                                            <i class="fa fa-angle-double-right"></i> <a href="<?php echo $protocol . $server_host;?>/listings/<?php echo $ala_lang;?>/<?php echo urlencode($ala_friendly_name);?>"><?php echo $ala_title;?></a>
															<?php
															echo '</div>';
														}
													}
													echo '</div>';
												}
												?>
												
												<?php
												echo '</div>';
											}
										}
										echo '</div>';
									}
									?>
								</div>
								<?php
							}
							?>
						</div>
                        </div>

					<?php
				}
				else {
					$send404 = true;
					$display_bl_content = false;
				}
				
			}
			else {
				$send404 = true;
				$display_bl_content = false;
			}
			
		}
		else {
			$send404 = true;
			$display_bl_content = false;
		}
		if($show_bl_adverts) {
			$hide_adverts_title = 1;
			include($modules_path. "adverts/adverts.php");
		}
	}
	
	$bl_content = ob_get_contents();
	ob_end_clean();
}


if(!$show_bl_business || !$display_bl_content) {
	//echo dirname(__FILE__) . "/../404/404.php";
	require_once(dirname(__FILE__) . "/../404/404.php");
}
else {
    ?>
    <article class="article bl-middle-directory bl-middle  cyprus">
        <?=$bl_content;?>
    </article>

    <?php
}
if(isset($_REQUEST['debugbl'])) {
	echo '<pre>', var_export($meta, true), '</pre>';
}
?>