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

// 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";
$rts = @mysql_query($qts);
if($rts && mysql_num_rows($rts) == 1) {
	$rowts = mysql_fetch_assoc($rts);
	
	$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";
	}
	//echo "<br/>$th_path";
}

$website = fix_url(trim($line['website']));

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

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



// Map Coordinates
$llz = '';
$rec_locations = array();
$location = array();
$q = "select * from advertisment_locations where advertisment_id='$current_advertisment_id' 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']);
	$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');
}




$box_class = "wb-info-window";

$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&cc=1';
		}
		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&cc=1';
}

?>
<div class="<?php echo $box_class;?>">
	<div class="wb-info-window-close" onclick="javascript:info_bubble.close();"><span style="margin:0;" class="ui-icon ui-icon-closethick"></span></div>
	<?php
	$advert_image = $screenshot_url . 'w=120&amp;h=90&amp;url=' . urlencode($website);
	if(isset($th_path) && $th_path != "" && file_exists($th_file_path)) {
		$advert_image = $th_path;
	}
	
	if($is_hotel) {
		echo '<h2>';
		?>
		<a href="<?php echo $protocol . $microdata_host . '/' .  $shortNameURL;?>" target="_blank" class="h2-result-link"><?php echo stripslashes($line["short_title_en"]);?></a>
		<?php
		
		echo '</h2>';
		
		if(isset($star_rating) && intval($star_rating) > 0) {
			echo '<span class="hotel-stars stars-'.$star_rating.'" title="'.$star_rating_text.'">'.$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">Featured</span>';
		}
	}
	else {
		?>
		<h2><?php echo stripslashes($line["short_title_en"]);?></h2>
		<?php
	}
	
	?>
	
	<div class="result-body">
	<?php
	
	if($website != ""){
		if($advert_active) {
			if($paying_advert) {
				if($is_hotel) {
					?>
					<span class="click-link flimg" rel="<?php echo $click_link_id;?>" extra_class="flimg">
					<img src="<?php echo $advert_image; ?>" width="120" height="90" border="0" alt="<?php echo stripslashes($line['short_title_en']); ?>" />
					</span>
					<?php
				}
				else {
					?>
					<a class="flimg" href="click_count.php?link=<?php echo $line["website"];?>&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&amp;cc=1" target="_blank">
						<img src="<?php echo $advert_image; ?>" width="120" height="90" border="0" alt="<?php echo stripslashes($line['short_title_en']); ?>" />
					</a>
					<?php 
				}
			}
			else {
				if($is_hotel) {
					?>
					<span class="click-link flimg" rel="<?php echo $click_link_id;?>" extra_class="flimg">
						<img src="<?php echo $advert_image; ?>" width="120" height="90" border="0" alt="<?php echo stripslashes($line['short_title_en']); ?>" />
					</span>
					<?php 
				}
				else {
					?>
					<span class="flimg">
					<img src="<?php echo $advert_image; ?>" width="120" height="90" border="0" alt="<?php echo stripslashes($line['short_title_en']); ?>" />
					</span>
					<?php 
				}
			}
		}
		else {
			if($is_hotel) {
				?>
				<span class="click-link flimg" rel="<?php echo $click_link_id;?>" extra_class="flimg">
				<img src="<?php echo $advert_image; ?>" width="120" height="90" border="0" alt="<?php echo stripslashes($line['short_title_en']); ?>" />
				</span>
				<?php 
			}
			else {
				?>
				<span class="flimg">
				<img src="<?php echo $advert_image; ?>" width="120" height="90" border="0" alt="<?php echo stripslashes($line['short_title_en']); ?>" />
				</span>
				<?php 
			}
		}
	}
	
	?>
	<div class="result-links">
		<?php
		if($website != ""){
			?>
			<span style="float: left; margin: 3px 0px 0 0;" class="ui-icon ui-icon-extlink"></span>
			<span class="click-link" rel="<?php echo $click_link_id;?>" extra_class="result-click-link">Visit Website</span><br/>
			<?php
		}
		?>
		<span class="wb-result-type"><?php echo $res_fm_title;?> in <?php echo $city;?></span>
	</div>
	<div class="result-more-button">
		<a href="<?php echo $protocol . $microdata_host . '/' .  $shortNameURL;?>" target="_blank" class="wb-info-window-button">See Details</a>
	</div>
	<div style="clear: both;"></div>
	</div>
</div>
<div style="clear: both;"></div>
<script>
	var tmp_click_links = <?php echo json_encode($click_count_paths);?>;
</script>