<?php
echo 'here';
$optres['js'][] = $path . 'amodules/search_adv/js/search_adv.js';
//$homepage_url = "/";
$server_host = $_SERVER['HTTP_HOST'];
if(str_replace("www.", "", $server_host) != str_replace("www.", "", $real_domainname)) {
    if(isset($partner_site) && $partner_site != "") {
        $server_host .= "/$partner_site";
    }
    else {
        $server_host .= "/$real_addonname";
        $homepage_url = "/$real_addonname/";
    }
}
else {
    $homepage_url = $protocol . $server_host . '/';
}
//echo '<pre>', var_export($_POST, true), '</pre>';
$catdom_id = $domain_id;
$start = "";
if(isset($_REQUEST['search'])) {
    $search = $_REQUEST['search'];
	foreach ($_REQUEST as $k=>$v) {
		if(!is_array($_REQUEST[$k])) {
			${$k} = mysql_real_escape_string($_REQUEST[$k]);
		}
		else {
			${$k} = array_map('mysql_real_escape_string', $_REQUEST[$k]);
		}
	}

    if(isset($search['catdom_id']) && intval($search['catdom_id']) > 0) {
        $catdom_id = intval($search['catdom_id']);
    }
}
else {
    $search = array(
        'now' => 'yes'
    );
}
if(isset($seri) && strlen($seri)>0){
	$search = (!is_array($search)) ? unserialize(base64_decode($search)) : $search;

    if(isset($search['catdom_id']) && intval($search['catdom_id']) > 0) {
        $catdom_id = intval($search['catdom_id']);
    }

	/*$catdom_ids = base64_decode($catdom_ids);
	$catdom_ids = unserialize($catdom_ids);
	$filter_ids = base64_decode($filter_ids);
	$filter_ids = unserialize($filter_ids);*/
}
if(isset($search['now']) && $search['now']=="yes"){
	
	$is_hotel = false;
	if(str_replace('www.', '', $ultra_domainname) == "cyprus-hotel.com") {
		$is_hotel = true;
	}
	
	// Get domain category
	$q = "select * from wb_categories_domains where wb_domainname='".(str_replace("www.", "", $ultra_domainname))."';";
	//echo $q;
	$r = @mysql_query($q);
	if($r && mysql_num_rows($r) == 1) {
		$row = mysql_fetch_assoc($r);
		$wb_uid = $row['wb_uid'];
	}
	
	
	// Get the searched catdom
	$catdom_id_adv = $domain_id;
	if(isset($search['catdom_id']) && intval($search['catdom_id']) > 0) {
		$catdom_id_adv = intval($search['catdom_id']);
	}
	
	// Get town friendly url
	$town_friendly_url = "";
	if($catdom_id_adv != $domain_id) {
		$q = "select * from domaincategories where catdom_id='$catdom_id_adv';";
		$r = @mysql_query($q);
		if($r && mysql_num_rows($r) > 0) {
			$row = mysql_fetch_assoc($r);
			$town_friendly_url = trim($row['friendly_url']) . "/";
		}
	}
	
	
	if (isset($start) && strlen($start) < 1 ){
		$start = 0;
	}
	$range = 10;
	$catdom_idx = sprintf("%04.0f", $catdom_id);
	$query = "SELECT * FROM advertisment WHERE active='yes' ";

	if(isset($search['keyword']) && $search['keyword']<>""){
		$query .=" AND (short_title_en LIKE '%{$search['keyword']}%' OR title_el LIKE '%{$search['keyword']}%' OR title_tr LIKE '%{$search['keyword']}%' OR description_en LIKE '%{$search['keyword']}%' OR description_el LIKE '%{$search['keyword']}%' OR description_tr LIKE '%{$search['keyword']}%' OR  email like '{$search['keyword']}' OR tel like '{$search['keyword']}' OR website LIKE '%{$search['keyword']}%' OR StreetName LIKE '%{$search['keyword']}%'  OR BuildingName LIKE '%{$search['keyword']}%' OR tel2 like '%{$search['keyword']}%' OR mobile like '%{$search['keyword']}%' OR mobile2 like '%{$search['keyword']}%' OR fax like '%{$search['keyword']}%' OR ContactPerson LIKE '%{$search['keyword']}%' OR Directors LIKE '%{$search['keyword']}%' OR Country LIKE '%{$search['keyword']}%' OR MemberOf LIKE '%{$search['keyword']}%' OR WebSiteTitle LIKE '%{$search['keyword']}%')";
	}
	if($domain_id != 611){
		if($domain_id<>"" && $domain_id>0){
			// echo $domain_id;
			$query .=" AND";
			if(isset($catdom_ids) && is_array($catdom_ids) && count($catdom_ids)>0){
				$query .=" (";
				while (list($key, $val) = each($catdom_ids)) {
					if($val>0){
						$countval++;
						if($countval>1 && isset($search['andor'])){
							$query .=" {$search['andor']} ";
						}
						$catdom_idx=sprintf("%04.0f", $val);
						$query .="catdom_id LIKE '%$catdom_idx%'";
					}
				}
				$query .=") ";
			}
			elseif(isset($search["catdom_id"]) && $search["catdom_id"]<>""){
				$catdom_idx2=sprintf("%04.0f", $search["catdom_id"]);
				$query .=" catdom_id LIKE '%$catdom_idx2%'";
			}
			else{
				$domain_idx2=sprintf("%04.0f", $domain_id);
				$query .=" (catdom_id LIKE '%$domain_idx2%'";
				$result_sub = mysql_query ("SELECT * FROM  domaincategories WHERE parent_id='$domain_id'");
				if (mysql_num_rows($result_sub) <> 0){			  
					while($line_sub = mysql_fetch_array($result_sub)){ 
						$domain_idx2=sprintf("%04.0f", $line_sub["catdom_id"]);
						$query .=" OR catdom_id LIKE '%$domain_idx2%'";
					}
				}
				$query .=")";
			}
		}
	}			  
	if(isset($filter_ids) && is_array($filter_ids) && count($filter_ids)>0){
		$where_filters = array();
		while (list($key, $val) = each($filter_ids)) {
			if($val>0){
				$filter_idx=sprintf("%04.0f", $val);
				$where_filters [] ="filter_id LIKE '%$filter_idx%'";
			}
		}
		if(count($where_filters) > 0) {
			$where_filters_str = implode(" OR ", $where_filters);
			$query .= " AND ($where_filters_str)";
		}
	}
	//			  if($catdom_idS<>"" && $catdom_idS=="0"){$query .=" AND (catdom_id='' OR catdom_id=0)";}
	if(isset($date_before) && $date_before<>""){
		$query .=" AND added_on >= '$date_before'";
	}
	if(isset($date_after) && $date_after<>""){
		$query .=" AND added_on <= '$date_after'";
	}
	//echo $query;
	$result = @mysql_query ($query);
	
	if ($result && mysql_num_rows($result) > 0){ 
		$NumberOfFields = mysql_num_rows($result);
		
		/*
		if($domain_id == 611){
			$query .= " ORDER BY short_title_en ASC LIMIT $start, $range";
			
			echo $query;
			
			$result = @mysql_query($query);
		}
		*/		
		?>
		<section class="search-results">
			<header>
					<?php
					$search_title = stripslashes(trim($line_catdom_id["title_en"])) . ' Search';
					if(isset($filter_ids) && is_array($filter_ids) && count($filter_ids) > 0) {
						$qf = "select * from filters where filter_id in (".implode(",", $filter_ids).");";
						$rf = @mysql_query($qf);
						if($rf && mysql_num_rows($rf) > 0) {
							$rf_cnt = 0;
							while ($rowf = mysql_fetch_assoc($rf)) {
								if($rf_cnt == 0) {
									$search_title .= " " . stripslashes($rowf['title_en']);
								}
								else {
									$search_title .= ", " . stripslashes($rowf['title_en']);
								}
								$rf_cnt ++;
							}
						}
					}
					
					$webpage_title_en = $search_title;
					$meta['description'] = $search_title. '. ';
					?>
				
					<h1><?php echo $search_title;?></h1>
			</header>
			<div class="content-body">
                <?php
                require_once(dirname(__FILE__) . "/../advanced_search/advanced_search.php");

                ?>
				<div>
					<?php 
					$count=0;
					$results = array();
					while($line = mysql_fetch_assoc($result)){
						
						$authorized_advert = true;
						$category_advert = false;
						// Check if advert belongs to this category
						/*
						if(isset($wb_uid) && strlen($wb_uid) == 16) {
							$q = "select * from wb_categories_adverts where wb_uid='$wb_uid' and wb_advert_uid='{$line['adv_code']}';";
							if(isset($_REQUEST['debug'])) echo "<br/>$q";
							$r = @mysql_query($q);
							if($r && mysql_num_rows($r) == 1) {
								$row = mysql_fetch_assoc($r);
								$wb_status = intval($row['wb_status']);
								
								if($wb_status == 1) $authorized_advert = true;
							}
						}
						*/
											
						if($domain_id != 611){
							if($authorized_advert) {
								$results[$count] = array();
								$results[$count]["order"]=0;
								$results[$count]["categ_order"]=0;
								$results[$count]["title_en"] = stripslashes($line["short_title_en"]);
								$results[$count]["advertisment_id"] = $line["advertisment_id"];
								$results[$count]["town_locations"] = array();
								
								$query_categtop = "SELECT * FROM domain_advertisment WHERE catdom_id='$catdom_id_adv' AND advertisment_id='{$line['advertisment_id']}'";
								//echo "<br/>" . $query_categtop;
								$result_categtop= mysql_query($query_categtop) or die(mysql_error());
								if($result_categtop && mysql_num_rows($result_categtop)>0){
									$line_categ_top = mysql_fetch_assoc($result_categtop);
									if($line_categ_top["category_top"]=="yes"){
										$results[$count]["order"] = 10;
										$results[$count]["categ_order"] = $line_categ_top["category_top_order_seq"];
									}
									elseif($line_categ_top["active"]=="yes"){
										$results[$count]["order"] = 8;
										$results[$count]["categ_order"] = $line_categ_top["order_seq"];
									}
									
									$params = $line_categ_top['params'];
									if($params != "") {
										$params = unserialize(base64_decode($params));
										if(is_array($params) && count($params) > 0) {
											$results[$count]["town_locations"] = $params;
										}
										
										//echo '<pre>', var_export($params, true), '</pre>';
									}
									
								}
								else {
									$result_sub = mysql_query ("SELECT * FROM  domaincategories WHERE parent_id='$domain_id'");
									if (mysql_num_rows($result_sub) > 0){			  
										$query_categtop = "SELECT * FROM domain_advertisment WHERE advertisment_id='{$line['advertisment_id']}' AND (";
										$sub = 0;
										while($line_sub = mysql_fetch_array($result_sub)){ 
											$query_categtop .=" catdom_id = '{$line_sub['catdom_id']}' ";
											$sub++;
											if($sub<mysql_num_rows($result_sub)){
												$query_categtop .= " OR ";
											}
										}
										$query_categtop .=")";
									}
									//echo $query_categtop;
									//echo "<br>";
									$result_categtop= mysql_query($query_categtop) or die(mysql_error());
									if(mysql_num_rows($result_categtop)>0){
										$line_categ_top=mysql_fetch_assoc($result_categtop);
										if($line_categ_top["category_top"]=="yes"){
											$results[$count]["order"]=6;
											$results[$count]["categ_order"]=$line_categ_top["category_top_order_seq"];
										}
										elseif($line_categ_top["active"]=="yes"){
											$results[$count]["order"]=4;
											$results[$count]["categ_order"]=$line_categ_top["order_seq"];
										}
										
										$params = $line_categ_top['params'];
										if($params != "") {
											$params = unserialize(base64_decode($params));
											if(is_array($params) && count($params) > 0) {
												$results[$count]["town_locations"] = $params;
											}
										}
									}
									
									
								}
								
								$count++;
							}
						}
						else {
							/*
							$i=0;
							while($line = mysql_fetch_array($result)){ 
								$advertisment_id[$i] = $line['advertisment_id'];
								$i++;
							}
							*/
							
							$results[$count] = array();
							$results[$count]["order"]=0;
							$results[$count]["categ_order"]=0;
							$results[$count]["title_en"] = stripslashes($line["short_title_en"]);
							$results[$count]["advertisment_id"] = $line["advertisment_id"];
							$results[$count]["town_locations"] = array();
							
							$query_categtop = "SELECT * FROM domain_advertisment WHERE category_top='yes' AND advertisment_id='{$line['advertisment_id']}'";
							$result_categtop= mysql_query($query_categtop) or die(mysql_error());
							if(mysql_num_rows($result_categtop)>0){
								$results[$count]["order"] = 10;
								$results[$count]["categ_order"] = 10;
							}
							else {
								$query_categtop = "SELECT * FROM domain_advertisment WHERE active='yes' AND advertisment_id='{$line['advertisment_id']}'";
								$result_categtop= mysql_query($query_categtop) or die(mysql_error());
								if(mysql_num_rows($result_categtop)>0){
									$results[$count]["order"] = 8;
									$results[$count]["categ_order"] = 8;
								}
							}
							$count++;
								
						}
						
					}
							
					$NumberOfFields = $count;
					$order = array();
					$categ_order = array();
					$title_en = array();
					$advertisment_id = array();
					$town_locations = array();
					foreach ($results as $key => $row) {
						$order[$key]  = $row['order'];
						$categ_order[$key]  = $row['categ_order'];
						$title_en[$key] = $row['title_en'];
						$advertisment_id[$key] = $row['advertisment_id'];
						
					}
			
					array_multisort($order, SORT_DESC, $categ_order, SORT_DESC, $title_en, SORT_ASC, SORT_STRING, $results);
					$i=0;
					foreach ($results as $key => $row) {
						$order[$i]  = $row['order'];
						$categ_order[$i]  = $row['categ_order'];
						$title_en[$i] = $row['title_en'];
						$advertisment_id[$i] = $row['advertisment_id'];
						$town_locations[$i] = $row["town_locations"];
						$i++;
					}
							
					
					//echo "<hr>";
					if($NumberOfFields>$start+$range){
						$end=$start+$range;
					}
					else{
						$end=$NumberOfFields;
					}
		
					$meta_keywords = array();
					$meta_strip_array = array(
						"cyprus", "limassol", "paphos", "larnaca", "famagusta", "ayia napa"
					);
					$meta_keywords [] = trim(str_ireplace($meta_strip_array, '', stripslashes(trim($line_catdom_id["title_en"]))));
					//$_REQUEST['debugx'] = 1;
					
					$click_count_paths = array();
					
					for($i=$start;$i<$end;$i++){
						$paying_advert = false;
						$use_town_dir = false;
						$query = "SELECT * FROM advertisment WHERE advertisment_id='{$advertisment_id[$i]}'";
						$result=mysql_query($query);
						if(mysql_num_rows($result)>0){
							$line = mysql_fetch_assoc($result);

                            $show_website = intval($line['show_website']);
							// Check if it is a paying advert
							$qp = "select * from domain_advertisment where advertisment_id='{$advertisment_id[$i]}' and catdom_id='$catdom_id_adv' and (category_top='yes' or active='yes');";
							$rp = @mysql_query($q);
							if($rp && mysql_num_rows($rp) > 0) {
								$paying_advert = true;
							}
							
							
							$advert_active = ($line['active'] == "yes") ? true : false;
							
							$shortNameURL = $line["title_tr"];
							$shortNameALT = str_replace('"','',$line["short_title_en"]);

                            $thumbshot = trim($line['image']);
                            $thumbshot_file = dirname(__FILE__) . "/../images/advertisments/advert_images/" . trim($line['image']);
                            $thumbshot_url = $protocol . $_SERVER['HTTP_HOST'] . "/images/advertisments/advert_images/" . trim($line['image']);
                            $has_thumbshot = ($thumbshot != "" && file_exists($thumbshot_file));

							$meta_keywords [] = $line["short_title_en"];
							
							if($i == $start) {
								$meta['description'] .= $line["short_title_en"];
							}
							else {
								$meta['description'] .= ', ' . $line["short_title_en"];
							}
							
							$rec_locations = array();

							$location = array();
							$q = "select * from advertisment_locations where advertisment_id='{$advertisment_id[$i]}' and active='1' order by main_location asc;";
							$r = @mysql_query($q);
							if($r && mysql_num_rows($r)>0) {
								while($row = mysql_fetch_assoc($r)) {
									if(isset($town_locations[$i]['locations'])) {
										if(in_array($row['location_id'], $town_locations[$i]['locations'])) {
											$rec_locations [] = $row;
											
											if(isset($_REQUEST['debugx'])) {
												echo '<br/>' . $row['location_id'] . ' is in ' . var_export($town_locations[$i]['locations'], true);
											}
											
										}
										else {
											if(isset($_REQUEST['debugx'])) {
												echo '<br/>' . $row['location_id'] . ' not in ' . var_export($town_locations[$i]['locations'], true);
											}
										}
									}
									if($row['main_location'] == 1 && count($location) == 0) $location = $row;
								}
							}
							
							if(count($rec_locations) > 0) {
								if(count($rec_locations) > 1 && count($location) == 0) $location = $rec_locations[0];
								if(count($rec_locations) == 1) $location = $rec_locations[0];
								if(count($town_locations[$i]) > 0)$use_town_dir = true;
							}
							
							//echo '<pre>', var_export($rec_locations, true), '</pre>';
							//echo '<pre>', var_export($location, true), '</pre>';
							
							
							if($use_town_dir) {
								$shortNameURL = $town_friendly_url . $shortNameURL;
							}
							
							$click_link_id = 'adv_' . $line['advertisment_id'];
							$click_count_paths [$click_link_id] = 'click_count.php?link=' .'' . '&amp;type=www&amp;id=' . $line['advertisment_id'] . '&amp;domain=' . $line_domain["domainname"] .'&amp;domain_id=' . $domain_id. '&amp;click_from=s&amp;cc=1';
							
							
							?>
							<div class="box box-primary box-compact">
								<?php
								if($paying_advert) {
									mysql_query("UPDATE advertisment SET views=views+1 WHERE advertisment_id='{$line['advertisment_id']}'") or die (mysql_error());
									count_views('adverts_stats_views', 'advertisment_id', $line['advertisment_id'], $domain_id, '', 's');
								}
                                ?>
                                <div class="box-header with-border">
                                    <h2><?php echo trim(stripslashes($line["short_title_en"]));?></h2>
                                </div>
                                <div class="box-body">
                                    <div class="row no-margin">
                                        <div class="col-md-3 text-center search-result-logo">
                                            <?php
                                            if(trim($line['website']) != "" && $show_website == 1){
                                                $website_link = (strpos(trim($line['website']), 'http') === false)  ? "http://" . trim($line['website']) : trim($line['website']);
                                                if($advert_active) {
                                                    if($is_hotel) {
                                                        ?>
                                                        <span class="click-link flimg" rel="<?php echo $click_link_id;?>" extra_class="flimg">
                                                            <img src="http://images.thumbshots.com/image.aspx?cid=wAQzqmGmx3A%3d&v=1&w=120&amp;h=90&amp;url=<?php echo urlencode($website_link); ?>" class="" alt="<?php echo stripslashes($line['short_title_en']); ?>" />
                                                        </span>
                                                        <?php
                                                    }
                                                    else {
                                                        ?>
                                                        <a class="flimg" href="click_count.php?link=<?php echo '';?>&amp;type=www&amp;id=<?php echo $line['advertisment_id'];?>&amp;domain=<?php echo $line_domain["domainname"];?>&amp;domain_id=<?php echo $domain_id;?>&amp;click_from=s" target="_blank">
                                                            <img src="http://images.thumbshots.com/image.aspx?cid=wAQzqmGmx3A%3d&v=1&w=120&amp;h=90&amp;url=<?php echo urlencode($website_link); ?>"  class="" alt="<?php echo trim(stripslashes($line['short_title_en'])); ?>"/>
                                                        </a>
                                                        <?php
                                                    }
                                                }
                                                else {
                                                    ?>
                                                    <img src="http://images.thumbshots.com/image.aspx?cid=wAQzqmGmx3A%3d&v=1&w=120&amp;h=90&amp;url=<?php echo urlencode($website_link); ?>"  class="" alt="<?php echo trim(stripslashes($line['short_title_en'])); ?>"/>
                                                    <?php
                                                }
                                            }
                                            ?>
                                        </div>
                                        <div class="col-md-7 search-result-data">
                                            <table>
                                                <tr>
                                                    <td class="th">phone:</td>
                                                    <td>
                                                        <?php
                                                        if(isset($location['tel1']) && trim($location['tel1']) != ""){
                                                            echo '+357 / ' . number_format(floatval(str_replace(array('00357', '+357'), '', $location['tel1'])), 0, '', '-');
                                                        }
                                                        else {
                                                            echo 'n/a';
                                                        }
                                                        ?>
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td class="th">email:</td>
                                                    <td>
                                                        <?php
                                                        if(isset($location['email']) && trim($location['email']) != ""){
                                                            ?>
                                                            <a href="javascript:;" class="mailto" rel="<?php echo str_replace('@', '[ at ]', $location['email']); ?>"><?php echo str_replace('@', '[ at ]', $location['email']); ?></a>
                                                            <?php
                                                        }
                                                        else {
                                                            echo 'n/a';
                                                        }
                                                        ?>
                                                    </td>
                                                </tr>
                                                <?php
                                                if($show_website == 1) {
                                                ?>
                                                <tr>
                                                    <td class="th">website:</td>
                                                    <td>
                                                        <?php
                                                        if(trim($line['website']) != ""){
                                                            if($advert_active && $paying_advert) {
                                                                if($is_hotel) {
                                                                    ?>
                                                                    <span class="click-link" rel="<?php echo $click_link_id;?>"><?php echo '';?></span>
                                                                    <?php
                                                                }
                                                                else {
                                                                    ?>
                                                                    <a href="click_count.php?link=<?php echo '';?>&amp;type=www&amp;id=<?php echo $line['advertisment_id'];?>&amp;domain=<?php echo $line_domain["domainname"];?>&amp;domain_id=<?php echo $domain_id;?>&amp;catdom_id=<?php echo $catdom_id_adv;?>&amp;click_from=s" class="click-count" target="_blank"><?php echo $line["website"];?></a>
                                                                    <?php
                                                                }
                                                            }
                                                            else {
                                                                echo $line["website"];
                                                            }
                                                        }
                                                        else {
                                                            echo 'n/a';
                                                        }
                                                        ?>
                                                    </td>
                                                </tr>
                                                <?php
                                                }
                                                ?>
                                            </table>
                                        </div>
                                    </div>
                                </div>
                                <div class="box-footer">
                                    <?php
                                    if(isset($_SESSION['user_id'])) {
                                        echo '<a href="../admin/advert_manager.php?advert_action=advert_edit_main&amp;advertisment_id=' . $line['advertisment_id'] . '" target="_blank">Edit</a> | ';
                                    }
                                    if($paying_advert && !$is_hotel) {
                                        ?>
                                        More about <a href="<?php echo $shortNameURL;?>" link="click_count.php?link=<?php echo '';?>&amp;type=adv&amp;id=<?php echo $line['advertisment_id'];?>&amp;domain=<?php echo $line_domain["domainname"];?>&amp;domain_id=<?php echo $domain_id;?>&amp;catdom_id=<?php echo $catdom_id_adv;?>&amp;click_from=s&amp;cc=1" class="small10 adv_linkage"><strong><?php echo stripslashes($line["short_title_en"]);?></strong> <i class="fa fa-arrow-circle-right fa-lg pull-right"></i></a>
                                        <?php
                                    }
                                    else {
                                        ?>
                                        More about <a href="<?php echo $shortNameURL;?>" class="small10" target="_blank"><strong><?php echo stripslashes($line["short_title_en"]);?></strong> <i class="fa fa-arrow-circle-right fa-lg pull-right"></i></a>
                                        <?php
                                    }
                                    ?>
                                </div>

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

            <div class="search-results-pagination text-left">
                <div class="search-results-num">
                    <?php
                    $end = $NumberOfFields;
                    if($NumberOfFields > $start + $range) $end = $start + $range;
                    echo "Results <b>", ($start + 1), " - ", $end, "</b> out of <b>", $NumberOfFields, "</b>";
                    ?>
                </div>
                <nav>
                    <ul class="pagination">

                        <?php
                        $startmsg = '';
                        $endmsg = '';
                        $pagesrange = 2;
                        $pages = $NumberOfFields/$range;
                        $search = base64_encode(serialize($search));
                        if(($start/$range)<=$pagesrange){
                            $startrange=0;
                        }
                        else{
                            $startrange=$start/$range-$pagesrange;
                            $prev=$start-$range;
                            $startmsg = '<li><a href="'.$homepage_url . '?start='.$prev.'&amp;search='.$search.'&amp;seri=111&amp;module_page=search" aria-label="Previous"><span aria-hidden="true">&laquo;</span></a></li>  <li><a href="'.$homepage_url  . '?start=&amp;search='.$search.'&amp;seri=111&amp;module_page=search">1</a></li><li><a href="#">...</a></li>';
                        }
                        if(($startrange+(2*$pagesrange)+1)>=$pages){
                            $endrange=$pages;
                        }
                        else{
                            $endrange=$startrange+(2*$pagesrange)+1;
                            $nex=$start+$range;$endpage=ceil($pages);
                            $end=floor($pages)*$range;
                            $endmsg =  '<li><a href="#">...</a></li>  <li><a href="'.$homepage_url .'?start=$end&amp;search=$search&amp;seri=111&amp;module_page=search">'.$endpage . '</a></li> <li><a href="'.$homepage_url . '?start=' . $nex . '&amp;search=' . $search . '&amp;seri=111&amp;module_page=search" aria-label="Next"><span aria-hidden="true">&raquo;</span></a>';
                        }
                        echo $startmsg;
                        for ($noofpage = $startrange; $noofpage < $endrange; $noofpage++) {
                        if ($start != $noofpage*$range){
                        /*Modification by Theodosis */
                        if ($search == 'YToyOntzOjc6ImtleXdvcmQiO3M6MDoiIjtzOjM6Im5vdyI7czozOiJ5ZXMiO30='){
                        ?>
                        <li><a href="cyprus<?php if ($noofpage > 0) echo $noofpage * $range; ?>">
                                <?php
                                }
                                else {
                                ?>
                                <li><a href="<?php echo $homepage_url ; ?>?start=<?php echo $noofpage * $range; ?>&amp;search=<?php echo $search; ?>&amp;seri=111&amp;module_page=search">
                                        <?php
                                        }
                                        echo ($noofpage+1) . '</a></li>';
                                        }
                                        else {
                                            echo '<li class="active"><a href="#">' . ($noofpage+1) . '</a></li>';
                                        }
                                        }
                                        echo $endmsg;
                                        ?>


                    </ul>
                </nav>
            </div>
		</section>

		<?php
		
		if(isset($meta_keywords) && count($meta_keywords) > 0) {
			$meta['keywords'] = implode(", ", $meta_keywords) . ", " . $meta['keywords'];
		}
		
		if($start > 0) {
			$webpage_title_en .= " | Page " . ($start/10 + 1);
		}

        ?>
        <script type="text/javascript">
            var click_count_paths = <?php echo json_encode($click_count_paths);?>;
        </script>
        <?php

	}
	else{
		?>
		<div class="alert alert-danger">
            <p>There are no listings in database with these criteria.</p>
        </div>
		<?php 
	}
}
?>
