<?php 
/********
Hotels | WC3DFD06FC494314 | Done
*******/
?><?php
mb_internal_encoding("UTF-8");
$line = mysql_fetch_assoc($result);
$use_town_dir = false;
$current_advertisment_id = intval($line['advertisment_id']);
$adv_code = $line['adv_code'];
$has_thumbshot = false;

/******************************************************************************************************/

if(isset($hotel_rates[$adv_code])) {
	$from_price = 0;
	$min_price = 0;
	$rates = array();

	foreach ($hotel_rates[$adv_code] as $rate_index=>$rate) {
		if(floatval($rate) > 1) {
			if($min_price == 0) $min_price = $rate;
			if($rate < $min_price) $min_price = $rate;
		}
		
		$from_price += $rate;
	}
	
	$from_price = round($from_price/count($hotel_rates[$adv_code]), 2) . ' (*)';
	
}
else {
	
	//if(!isset($_SESSION['hotel_search']['checkin'])) {
		// Get Hotel prices
        $has_price = false;
        $price_from = 0;
        $price_to = 0;
		$from_price = 0;
		$min_price = 0;
		$rates = array();
		$q = "select a.* from hotel_affiliates_adverts a, hotel_affiliates r where a.adv_code='$adv_code' and a.aff_code=r.aff_code and r.aff_status='1' and a.aff_code='BOOKING000000002' and a.aff_hotel_status='1' order by a.low_rate asc;";
		
		$r = @mysql_query($q);
		if($r && mysql_num_rows($r) > 0) {
			while ($row = mysql_fetch_assoc($r)) {
				$rates[$row['aff_code']] = array(
					"low_rate"	=> $row['low_rate'],
					"hight_rate"	=> $row['high_rate']
				);

                if(floatval($row['low_rate']) > 0) {
                    if (floatval($row['low_rate']) < $price_from || $price_from == 0) {
                        $price_from = floatval($row['low_rate']);
                        $has_price = true;
                    }
                }

                if(floatval($row['high_rate']) > $price_to) {
                    $price_to = floatval($row['high_rate']);
                    $has_price = true;
                }

				/*if(floatval($row['low_rate'])>1) {
					if($min_price == 0 && floatval($row['low_rate']) > 1 ) {
						$min_price = floatval($row['low_rate']);
					}
					if(floatval($row['low_rate']) < $min_price) $min_price = floatval($row['low_rate']);
				}
				$from_price += floatval($row['low_rate']);*/
			}
			
			//$from_price = number_format($from_price/count($rates), 2, ".", '');
			//echo '<br/>', $from_price;
			//echo '<br/>', '<pre>', var_export($rates, true), '</pre>';
		}
	//}
	//else {
	//	$from_price = "TBD";
	//}
}
/******************************************************************************************************/



// Get Advert Sub-Category
$q = "SELECT m.fm_uid, m.title FROM wb_filters_mains m, `wb_filters_adverts_categs` a where m.wb_uid='$wb_uid' and m.fm_uid=a.fm_uid and m.wb_uid=a.wb_uid and a.adv_code='$adv_code'";
$r = @mysql_query($q);
if($r && mysql_num_rows($r) == 1) {
	$row = mysql_fetch_assoc($r) ;
	$res_fm_uid = $row['fm_uid'];
	$res_fm_title = stripslashes($row['title']);
}

// Get ratings and category
$star_rating = '';
$q = "SELECT a.f_value, e.e_label_display, e.e_db  FROM wb_filters_adverts a, wb_filters_elems e where a.adv_code='$adv_code' and a.wb_uid='$wb_uid' and e.fm_uid='$res_fm_uid' and a.fe_uid=e.fe_uid and e.e_name='star_rating'";
$r = mysql_query($q) or die("<strong>$q</strong>".mysql_error());
if($r && mysql_num_rows($r) >0) {
	$row = mysql_fetch_assoc($r);
	$f_value = $row['f_value'];
	$e_label_display = stripslashes($row['e_label_display']);
	$e_db = unserialize(base64_decode($row['e_db']));
	//echo '<pre>', var_export($row, true), '</pre>';
	
	$star_rating = 0;
	$star_rating_text = "";
	$star_cnt = 5;
	foreach ($e_db as $star_value=>$star_text) {
		if($f_value == $star_value) {
			$star_rating = $star_cnt;
			$star_rating_text = stripslashes($star_text);
		}
		$star_cnt--;
	}
	//echo '<pre>', var_export($e_db, true), '</pre>';
	
}

// Get Class
$class_vars = array(
	"'apt_class'", "'class'"
);
$apt_class = '';
$q = "SELECT a.f_value, e.e_label_display, e.e_db  FROM wb_filters_adverts a, wb_filters_elems e where a.adv_code='$adv_code' and e.wb_uid='$wb_uid' and e.fm_uid='$res_fm_uid' and a.fe_uid=e.fe_uid and e.e_name in (".implode(",", $class_vars).")";
//echo "<br/>$q";
$r = mysql_query($q) or die("<strong>$q</strong>".mysql_error());
if($r && mysql_num_rows($r) >0) {
	$row = mysql_fetch_assoc($r);
	$f_value = $row['f_value'];
	$e_label_display = stripslashes($row['e_label_display']);
	$e_db = unserialize(base64_decode($row['e_db']));
	//echo '<pre>', var_export($row, true), '</pre>';
	
	foreach ($e_db as $class_value=>$class_text) {
		if($f_value == $class_value) {
			$apt_class = stripslashes($class_text);
		}
	}
	//echo '<pre>', var_export($e_db, true), '</pre>';
	
}


// Check if it is a paying advert
$paying_advert = 0;
$qp = "select * from domain_advertisment where advertisment_id='$current_advertisment_id' and catdom_id IN (".implode(",", $catdoms).") and (category_top='yes' or active='yes');";
$rp = @mysql_query($qp);
if($rp && mysql_num_rows($rp) > 0) {
	$paying_advert = 1;
}

// Get Gallery image
$th_filename = "";
$th_file_path = "";
$th_path = "";
$qts = "SELECT `filename`,`iwt`,`iht` FROM `advertisment_gallery` WHERE adv_code='$adv_code' order by pos asc limit 0,1";
//echo $qts;
$rts = @mysql_query($qts);
if($rts && mysql_num_rows($rts) == 1) {
	$rowts = mysql_fetch_assoc($rts);

    $orig_image = '';
	$th_filename = $rowts['filename'];
	$th_w = $rowts['iwt'];
	$th_h = $rowts['iht'];
	$th_file_path = dirname(__FILE__) . "/../../../images/advertisments/gallery/$current_advertisment_id/thumbs/$th_filename";
	if(file_exists($th_file_path)) {
		$th_path = $path . "images/advertisments/gallery/$current_advertisment_id/thumbs/$th_filename";
        $orig_image = $path . "images/advertisments/gallery/$current_advertisment_id/$th_filename";
	}
	
}

$website = trim($line['website']);
$show_website = intval($line['show_website']);
$wb_protocol = "http://";
if(strpos($website, "https://") !== false) $wb_protocol = "https://";
$website = str_replace("$wb_protocol", "", $website);
if($website != "") {
	$website = $wb_protocol . $website;
}

$advert_active = ($line['active'] == "yes") ? true : false;

$shortNameURL = $line["title_tr"];
$shortNameALT = str_replace('"','',$line["short_title_en"]);

// Get description from either desc or versions's desc
if(trim($line['abstract_en']) != "") {
	if(mb_strlen(strip_html_tags(stripslashes($line['abstract_en'])), 'UTF-8') > 340) {
		$result_description = trim(mb_substr(strip_html_tags(stripslashes($line['abstract_en'])), 0, 340)) . ' ..';
	}
	else {
		$result_description = trim(strip_html_tags(stripslashes($line['abstract_en'])));
	}
}
else {
	if(mb_strlen(strip_html_tags(stripslashes($line['description_en'])), 'UTF-8') > 340) {
		$result_description = trim(mb_substr(strip_html_tags(stripslashes($line['description_en'])), 0, 340)) . ' ..';
	}
	else {
		$result_description = trim(strip_html_tags(stripslashes($line['description_en'])));
	}
}


$qv = "select * from advertisment_versions where advertisment_id='$current_advertisment_id' and domainname='$ultra_domainname';";
if(isset($_REQUEST['debugv'])) {
	echo "<br/>$qv";
}
$rv = @mysql_query($qv);
if($rv && mysql_num_rows($rv) == 1) {
	$rowv = mysql_fetch_assoc($rv);
	$abstract_en = trim($rowv['abstract_en']);
	if($abstract_en != "") {
		if(mb_strlen(strip_html_tags(stripslashes($rowv['abstract_en'])), 'UTF-8') > 340) {
			$result_description = trim(mb_substr(strip_html_tags(stripslashes($rowv['abstract_en'])), 0, 340)) . ' ..';
		}
		else {
			$result_description = trim(strip_html_tags(stripslashes($rowv['abstract_en'])));
		}
	}
	else {
		if(mb_strlen(strip_html_tags(stripslashes($rowv['description_en'])), 'UTF-8') > 340) {
			$result_description = trim(mb_substr(strip_html_tags(stripslashes($rowv['description_en'])), 0, 340)) . ' ..';
		}
		else {
			$result_description = trim(strip_html_tags(stripslashes($rowv['description_en'])));
		}
	}
}

// Map Coordinates
$llz = '';
$rec_locations = array();
$location = array();
$q = "select * from advertisment_locations where adv_code='$adv_code' and main_location='1' and active='1';";
$r = @mysql_query($q);
if($r && mysql_num_rows($r)>0) {
	$row = mysql_fetch_assoc($r);
	$lat = $row['lat'];
	$lng = $row['lng'];
	$zoom = $row['zoom'];
	$city = stripslashes($row['city']);
	$district = stripslashes($row['district']);
	$location_id = intval($row['location_id']);
	
	$llz = "$lat|$lng|$zoom";
	$llz_id = $location_id;
	
	$map_w = 120;
	$map_h = 90;
	$zoom = 15;
	$google_map_url = 'https://maps.google.com/maps/api/staticmap?maptype=map&' . ('center=' . $lat . ',' . $lng .'&zoom='.$zoom.'&size='.$map_w.'x'.$map_h.'&markers=%7C'.$lat . ',' . $lng.'&sensor=false');
}




if(isset($_REQUEST['rel_page'])) { 
	$meta_keywords [] = $line["short_title_en"];
	
	if(isset($advert_num) && $advert_num == $start) {
		//$meta['description'] = $line["short_title_en"];
	}
	else {
		//$meta['description'] .= ', ' . $line["short_title_en"];
	}
}

$box_class = "wb-box-result";
if($categ_order[$advert_num] == 10) $box_class = "wb-box-result featured_1";
if($categ_order[$advert_num] == 8) $box_class = "wb-box-result featured_2";
if($categ_order[$advert_num] == 6) $box_class = "wb-box-result featured_3";

$click_link_id = 'adv_' . $line['advertisment_id'];
if($is_hotel) {
	if($paying_advert) {
		if($advert_active) {
			$click_count_paths [$click_link_id] = 'click_count.php?link=' .$line["website"] . '&amp;type=www&amp;id=' . $line['advertisment_id'] . '&amp;domain=' . $line_domain["domainname"] .'&amp;domain_id=' . $domain_id. '&amp;click_from=s';
		}
		else {
			$click_count_paths [$click_link_id] = 'click_count.php?link=' .$line["website"] . '&amp;type=www&amp;id=' . $line['advertisment_id'] . '&amp;domain=' . $line_domain["domainname"] .'&amp;domain_id=' . $domain_id. '&amp;click_from=s';
		}
	}
	else {
		$click_count_paths [$click_link_id] = 'click_count.php?link=' .$line["website"] . '&amp;type=www&amp;id=' . $line['advertisment_id'] . '&amp;domain=' . $line_domain["domainname"] .'&amp;domain_id=' . $domain_id. '&amp;click_from=s';
	}
}
else {
	$click_count_paths [$click_link_id] = 'click_count.php?link=' .$line["website"] . '&amp;type=www&amp;id=' . $line['advertisment_id'] . '&amp;domain=' . $line_domain["domainname"] .'&amp;domain_id=' . $domain_id. '&amp;click_from=s';
}

//$result_description .= ' <span class="see-more" rel="' . 'http://' . $microdata_host . '/' .  $shortNameURL. '" extra_class="see-more"></span>';

/*itemprop="itemListElement" itemscope itemtype="http://schema.org/ListItem"*/
?>
<div class="<?php echo $box_class;?>">
	<?php
	if(!isset($_SESSION['user_id']) && $paying_advert) {
		mysql_query("UPDATE advertisment SET views=views+1 WHERE advertisment_id='{$line['advertisment_id']}'") or die (mysql_error());
		
		$ipfrom = (isset($catdom_id) && intval($catdom_id) != $domain_id) ? $catdom_id : $domain_id; 
		
		count_views('adverts_stats_views', 'advertisment_id', $line['advertisment_id'], $domain_id, $ipfrom, 's');
		
		$_adverts_views [] = array(
			"adv_code"				=> $line['adv_code'],
			"advertisment_id"		=> $line['advertisment_id'],
			"domain_id"				=> $domain_id,
			"catdom_id"				=> $ipfrom,
			"domainname"			=> $ultra_domainname,
			"date_short"			=> date("Y-m-d"),
			"date_long"				=> date("Y-m-d H:i:s"),
			"views"					=> 1,
			"view_from"				=> 's'
		);
		
	}
	
	$advert_image = '';
	if(isset($th_path) && $th_path != "" && file_exists($th_file_path)) {
		//$advert_image = $th_path;
		$advert_image = $orig_image;
	}

    //echo '<pre>', var_export($microdata['adverts']), '</pre>';

    ?>
    <!--<meta itemprop="position" content="<?/*=$advert_num;*/?>"/>-->
    <div class="box box-info" itemscope itemtype="http://schema.org/Hotel">
        <div class="box-header with-border">
            <?php
            if($is_hotel) {
                echo '<h2>';
                if($use_town_dir) {
                    $shortNameURL = $town_friendly_url . $shortNameURL;
                }
                ?>
                <a itemprop="url" content="<?php echo $protocol . $microdata_host . '/' .  $shortNameURL;?>" href="<?php echo $protocol . $microdata_host . '/' .  $shortNameURL;?>"
                   target="_blank"
                   class="h2-result-link"
                    >
                    <span itemprop="name"><?php echo stripslashes($line["short_title_en"]);?></span>
                </a>
                <br class="wb-nl"/>
                <?php

                if(isset($star_rating) && intval($star_rating) > 0) {
                    echo '<span class="hotel-stars stars-'.$star_rating.'" title="'.$star_rating_text.'"  itemprop="starRating" itemscope itemtype="http://schema.org/Rating"><meta itemprop="ratingValue" content="'.$star_rating.'">'.$star_rating_text.'</span>';
                }

                if(isset($apt_class) && trim($apt_class) != "") {
                    echo '<span class="hotel-class" title="'.$apt_class.'">'.stripslashes($apt_class).'</span>';
                }

                if($paying_advert == true) {
                    echo '<span class="featured-result"><i class="fa fa-bookmark fa-2x"></i></span>';
                }

                echo '</h2>';



            }
            else {
                ?>
                <h2><?php echo stripslashes($line["short_title_en"]);?></h2>
                <?php
            }
            ?>
        </div>
        <div class="box-body">

            <div class="row result-links">

                <div class="col-sm-2 col-xs-5 result-action">
                    <?php
                    if($website != "" && $show_website == 1){
                        if($paying_advert) {
                            echo '<a class="" href="' . 'click_count.php?link=' .$line["website"] . '&amp;type=www&amp;id=' . $line['advertisment_id'] . '&amp;domain=' . $line_domain["domainname"] .'&amp;domain_id=' . $domain_id. '&amp;click_from=s' . '" rel="nofollow" class="result-click-link" target="_blank"><i class="fa fa-globe"></i> Website</a>';
                        }
                        else {
                            ?>
                            <a class="" href="<?php echo $website;?>" target="_blank" rel="nofollow" class="result-click-link" title="<?php echo stripslashes($line['short_title_en']);?>"><i class="fa fa-globe"></i> Website</a>
                            <?php
                        }
                    }
                    else {
                        echo '&nbsp;';
                    }
                    ?>
                </div>
                <div class="col-sm-5 col-xs-5 result-action">
                    <a class="wb-map-link map-link" data-rel="<?php echo $llz_id;?>"><i class="fa fa-map-marker"></i> View Map
                        <span itemprop="address" itemscope itemtype="http://schema.org/PostalAddress">

                            <?php
                            if(strtolower($city) == strtolower($district)) {
                                ?>
                                <meta itemprop="addressLocality" content="<?=$city;?>">
                                <meta itemprop="addressRegion" content="<?= $district; ?>">
                                <?
                            }
                            else {
                                ?>
                                <meta itemprop="addressLocality" content="<?=$city;?>">
                                <meta itemprop="addressRegion" content="<?= $district; ?>">
                                <?
                            }
                            ?>
                            <meta itemprop="addressCountry" content="CY">
                        </span>
                    </a>
                </div>
                <!--<a class="btn wb-result-type" title="<?php /*echo $res_fm_title;*/?> in <?php /*echo $city;*/?>"><?php /*echo $res_fm_title;*/?> in <?php /*echo $city;*/?></a>-->

                <div class="col-sm-3 result-action">
                    <?php
                    /**************************************************************************************/
                    if( !$has_price) {
                        ?>
                            <a href="<?php echo $protocol . $microdata_host . '/' .  $shortNameURL;?>" class="aff_rate_find" target="_blank">
                                <span class="aff_rate" itemprop="priceRange">Check Availability</span>
                            </a>
                        <?php
                    }
                    else {
                        if(!isset($show_disclaimer) || !isset($show_disclaimer['*'])) {
                            $show_disclaimer = array(
                                '*' => 'Prices displayed are based on the rates obtained from our network of booking partners. We do not guarantee any specific rates or prices. These rates are estimates therefore check with the specific booking site for the exact amount, currency and fees.'
                            );
                        }
                        ?>
                            <a href="<?php echo $protocol . $microdata_host . '/' .  $shortNameURL;?>" class="aff_rate_check" target="_blank">
                                <?php
                                if($price_from > 0) {
                                    $range_text = 'From';
                                    if($price_to > 0) $range_text = "Between";
                                    ?>
                                    <?=$range_text?>
                                    <span class="aff_rate" itemprop="priceRange">
                                        &euro; <?php echo number_format($price_from, 0);?>
                                        <?php
                                        if($price_to > 0) {
                                            ?>
                                            - &euro; <?php echo number_format($price_to, 0);?>
                                            <?php
                                        }
                                        ?>
                                    </span>*
                                    <?php


                                }
                                elseif($price_to > 0) {
                                    $range_text = 'Up to';
                                    ?>
                                    <?=$range_text; ?>
                                    <span class="aff_rate" itemprop="priceRange">
                                        &euro; <?php echo number_format($price_to, 0);?>

                                    </span>*
                                    <?php
                                }
                                ?>

                            </a>
                        <?php
                    }
                    /****************************************************************************************/
                    ?>
                </div>
            </div>
            <div class="result-body row">

                <div class="col-sm-3">
                    <div class="image-holder">
                        <div class="image-container" itemprop="image" itemscope="" itemtype="http://schema.org/ImageObject">
                            <a target="_blank" href="<?php echo $protocol . $microdata_host . '/' .  $shortNameURL;?>"  class="event-image-link">
                                <img itemprop="url" src="<?php echo $advert_image; ?>" class="event-image" alt="<?php echo stripslashes($line['short_title_en']); ?>" />
                            </a>
                        </div>
                    </div>
                </div>

                <div class="col-sm-7">
                    <?php
                    if(isset($_REQUEST['debug1'])) {
                        echo "<strong>".$categ_order[$advert_num]."</strong>";
                    }
                    if(isset($_REQUEST['debugx'])) {
                        echo '<pre>', var_export($rec_locations, true), '</pre>';
                        echo '<pre>', var_export($wb_locations, true), '</pre>';
                    }

                    ?>
                    <p class="result-description" itemprop="description">
                        <?php
                        echo $result_description;
                        ?>
                    </p>

                    <div class="result-map">
                        <?php
                        /*
                        //echo '<img src="', $google_map_url,'" alt="' . stripslashes($line["short_title_en"]) . '" border="0" class="result-map-img wb-map-link" width="'.$map_w.'" height="'.$map_h.'" rel="' . $llz_id . '">';
                        if(isset($th_path) && $th_path != "") {
                            echo '<a href="http://' . $microdata_host . '/' .  $shortNameURL.'" target="_blank">';
                            echo '<img src="', $th_path,'" alt="" border="0" class="result-map-img" width="'.$map_w.'" height="'.$map_h.'">';
                            echo '</a>';
                        }
                        */
                        ?>
                    </div>
                </div>
            </div>
            <p><?php
                if($is_hotel) {
                    echo '';
                    if(isset($_SESSION['user_id'])) {
                        echo '<a href="../admin/advert_manager.php?advert_action=advert_edit_main&advertisment_id=',$line['advertisment_id'],'" target="_blank">Edit</a>';
                    }
                }
                else {
                    if($use_town_dir) {
                        $shortNameURL = $town_friendly_url . $shortNameURL;
                    }

                    if($paying_advert && $advert_active) {
                        ?>
                        <a href="<?php echo $protocol . $microdata_host . '/' .  $shortNameURL;?>" target="_blank">More about <?php echo stripslashes($line["short_title_en"]);?></a>
                        <?php
                    }
                    else {
                        ?>
                        <a href="<?php echo $protocol . $microdata_host . '/' .  $shortNameURL;?>" target="_blank" class="small10" >More about <?php echo stripslashes($line["short_title_en"]);?></a>
                        <?php
                    }
                }
                ?></p>
        </div>
    </div>

	
</div>
<div style="clear: both;"></div>
<?php
?>