<?php
// This file is only for cyprus-hotel.com
if(!function_exists("getDataURI")) {
	function getDataURI($image,$mime='') {
		//$finfo = new finfo(FILEINFO_MIME_TYPE);
		$image_data = file_get_contents($image);
		//$mime = $finfo->buffer($image_data);
		
		$im = getimagesize($image);
		$mime = $im['mime'];
		return 'data:'.$mime.';base64,'.base64_encode($image_data);
	}
}
$remotehost = $_SERVER['REMOTE_ADDR'];
$date_now = date("Y-m-d", time());
$after1month  = date("Y-m-d",mktime(0, 0, 0, date("m")+1 ,date("d"), date("Y")));
$after3months  = date("Y-m-d",mktime(0, 0, 0, date("m")+3 ,date("d"), date("Y")));
if(isset($catdom_id) && intval($catdom_id)>0){
	$catdom_id_adv = $catdom_id;
}
else {
	$catdom_id_adv = $domain_id;
	$catdom_id = $domain_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']) . "/";
	}
}
*/


$domain_idx2 = sprintf("%04.0f", $catdom_id_adv);


$root_host = $_SERVER['HTTP_HOST'];
if(str_replace('www.', '', $root_host) != str_replace('www.', '', $ultra_domainname)) {
	$root_host .= "/$ultra_addonname";
}

$is_hotel = false;
if(str_replace('www.', '', $ultra_domainname) == "cyprus-hotel.com") {
	$is_hotel = true;
}


include($general_path . "queries.php");

$short_invoice_types = array(
	"999999"		=> array("short_name"=>"Complim.", "color"=>"#F02FFF"),
	"888888"		=> array("short_name"=>"Filler", "color"=>"#09AF00"),
	"777777"		=> array("short_name"=>"Featured", "color"=>"#FFD100"),
	"555555"		=> array("short_name"=>"Friends", "color"=>"#39424B"),
	"444444"		=> array("short_name"=>"Link Exch.", "color"=>"#800000")
);

$bind_types =  array(
	//"invoice"		=> "Payable",
	"t_upgrade"			=> "Temp.Upgrade",
	"t_complimentary"	=> "Temp.Complim",
	"t_filler"			=> "Temp.Filler"
);


$have_adverts_css = false;
//$css_filename = dirname(__FILE__) . "/css/adverts_" . $domain_id . "_" . $catdom_id_adv . ".css";
if(!is_dir($_SERVER['DOCUMENT_ROOT'] . "/all_cache/adverts/css")) {
	mkdir($_SERVER['DOCUMENT_ROOT'] . "/all_cache/adverts/css", 0755, true);
}
$css_filename = $_SERVER['DOCUMENT_ROOT'] . "/all_cache/adverts/css/adverts_" . $domain_id . "_" . $catdom_id_adv . ".css";
if(file_exists($css_filename)) {
	$have_adverts_css = true;
	if(filemtime($css_filename) < time() - 3600) $have_adverts_css = false;
	//echo '<br/>' . $css_filename . ' exists';
}
if(!$have_adverts_css || isset($_REQUEST['remove_cache'])) {
	$facss = fopen($css_filename, "wb");
	
	$no_image_advert = $_SERVER['DOCUMENT_ROOT'] . "/images/navigation/no_pic.gif";
	$css_line = ".logo-nopic {background-image:url(".getDataURI($no_image_advert).");}" . "\n";
	fwrite($facss, $css_line, strlen($css_line));
}

$have_featured = "no";
$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;

$result_categtop = mysql_query ($query_categtop) or die(mysql_error());
if (mysql_num_rows($result_categtop) > 0){
	$have_featured = "yes";

	$adverts = array();
	while($row_top = mysql_fetch_assoc($result_categtop)){
		$advertisment_id = $row_top['advertisment_id'];
		
		$adverts[$advertisment_id] = array(
			"adv_code"	=> $row_top['adv_code'],
			"advertisment_id"	=> $row_top['advertisment_id'],
			"member_id"	=> intval($row_top['member_id']),
			"website"	=> trim($row_top['website']),
			"show_website"	=> intval($row_top['show_website']),
			"invoice_no"	=> trim($row_top['invoice_no']),
			"bind_type"	=> trim($row_top['bind_type']),
			"active_from"	=> trim($row_top['active_from']),
			"active_to"	=> trim($row_top['active_to']),
			"short_title_en"	=> stripslashes($row_top['short_title_en']),
			"title_tr"	=> $row_top['title_tr'],
			"advertisment"	=> $row_top['advertisment'],
			"display_name" => str_replace('"','', stripslashes($row_top["short_title_en"])),
			"friendly_url" => $row_top["title_tr"],
			"advert_logo_file" => $_SERVER['DOCUMENT_ROOT'] . "/images/advertisments/" . $row_top['advertisment'],
			"advert_logo_url" => $protocol . $microdata_host . "/images/advertisments/" . $row_top['advertisment'],
			"advert_logo_class" => "logo-" . $advertisment_id
		);
		
		
		
	}
	
	
	if(!$have_adverts_css) {
		foreach ($adverts as $advertisment_id=>$a) {
			if(file_exists($a['advert_logo_file'])) {
				$css_line = "." . $a['advert_logo_class'] . "{background-image:url(".getDataURI($a['advert_logo_file']).");}" . "\n";
				fwrite($facss, $css_line, strlen($css_line));
			}
			else {
				$adverts[$advertisment_id]['advert_logo_class'] = "logo-nopic";
			}
		}
	}
	
	
	
	
	?>
	<div class="adverts-top row-fluid">
		<?php
		if($module_show_featured_title == 1) {
			?>
			<div class="adverts-top-title">
				<span><?php echo $recomented_value_en;?></span>
			</div>
			<?php
		}
		?>
		
		<div class="adverts-top-list">
			<?php
			$count_categtop = 1;
			$total_adverts = mysql_num_rows($result_categtop);
			$num_adverts = 1;
			//while($line_categtop = mysql_fetch_assoc($result_categtop)){
			foreach ($adverts as $advertisment_id=>$line_categtop) {
				$display_name = str_replace('"','',$line_categtop["short_title_en"]);
				$shortNameURL = $line_categtop["title_tr"];
				$shortNameALT = str_replace('"','',$line_categtop["short_title_en"]);
                $show_website = intval($line_categtop['show_website']);
				$adv_unit_salesview_class = "";
				if (isset($_SESSION['user_id'])){
					$adv_unit_salesview_class = "adv-unit-salesview";
				}
				?>
				<div class="span2 adv_unit adv-unit-top <?php echo $adv_unit_salesview_class;?>">
					<?php 
					if (!isset($_SESSION['user_id'])){
						mysql_query("UPDATE advertisment SET views=views+1 WHERE advertisment_id='{$line_categtop['advertisment_id']}'") or die (mysql_error());
						count_views('adverts_stats_views', 'advertisment_id', $line_categtop['advertisment_id'], $domain_id, $catdom_id_adv, 'top');
						
						$_adverts_views [] = array(
							"adv_code"				=> $line_categtop['adv_code'],
							"advertisment_id"		=> $line_categtop['advertisment_id'],
							"domain_id"				=> $domain_id,
							"catdom_id"				=> $catdom_id_adv,
							"domainname"			=> $ultra_domainname,
							"date_short"			=> date("Y-m-d"),
							"date_long"				=> date("Y-m-d H:i:s"),
							"views"					=> 1,
							"view_from"				=> 'topjs'
						);
						
					}
					
					// top = category top

					echo '<div class="advert_logo">';
                        if($show_website == 1) {
                            if($browser_type == "good") {
                                echo '<a href="click_count.php?link=' .$shortNameURL. '&amp;type=www&amp;id=' . $line_categtop['advertisment_id'] . '&amp;domain='.$domainname.'&amp;domain_id='.$domain_id.'&amp;click_from=top&amp;catdom_id='.$catdom_id_adv.'" target="_blank" title="' . $shortNameALT . '" rel="nofollow" class="'.$line_categtop['advert_logo_class'].' advert-logo"></a>';
                            }
                            else {
                                echo '<a href="click_count.php?link=' .$shortNameURL. '&amp;type=www&amp;id=' . $line_categtop['advertisment_id'] . '&amp;domain='.$domainname.'&amp;domain_id='.$domain_id.'&amp;click_from=top&amp;catdom_id='.$catdom_id_adv.'" target="_blank" rel="nofollow" class="advert-logo">';
                                    if($line_categtop['advertisment']<>""){
                                        ?><img src="<?php echo $path;?>images/advertisments/<?php echo $line_categtop["advertisment"];?>" width="85" height="74" border="0" alt="<?php echo $shortNameALT;?>"/><?php
                                    }
                                    else{
                                        ?><img src="<?php echo $path;?>images/navigation/no_pic.gif" width="85" height="74" border="0" alt="No picture"/><?php
                                    }
                                echo '</a>';
                            }
                        }
                        else {
                            if($line_categtop['advertisment']<>""){
                                ?><img src="<?php echo $path;?>images/advertisments/<?php echo $line_categtop["advertisment"];?>" width="85" height="74" border="0" alt="<?php echo $shortNameALT;?>"/><?php
                            }
                            else{
                                ?><img src="<?php echo $path;?>images/navigation/no_pic.gif" width="85" height="74" border="0" alt="No picture"/><?php
                            }
                        }
					echo '</div>';
					

					// Get the eventual rate
					$min_price = 0;
					$q_rates = "select a.* from hotel_affiliates_adverts a, hotel_affiliates r where a.aff_code=r.aff_code and r.aff_status='1' and a.adv_code='{$line_categtop['adv_code']}' and a.aff_hotel_status='1' order by a.low_rate asc;";
					
					$r_rates = @mysql_query($q_rates);
					if($r_rates && mysql_num_rows($r_rates) > 0) {
						while ($row_rates = mysql_fetch_assoc($r_rates)) {
							if($min_price == 0 && floatval($row_rates['low_rate']) > 0 ) {
								$min_price = floatval($row_rates['low_rate']);
							}
							if(floatval($row_rates['low_rate']) < $min_price) $min_price = floatval($row_rates['low_rate']);
						}
					}
					
					if($min_price > 0) {
						?>
						<div class="rate-bubble" onclick="show_page(<?php echo $advertisment_id;?>);">
							<span class="rate-bubble-text">From</span> &euro; <?php echo number_format($min_price, 0);?>
						</div>
						<?php
					}
					else {
						?>
						<div class="rate-bubble" onclick="show_page(<?php echo $advertisment_id;?>);">
							<span class="rate-bubble-text">Check Availability</span>
						</div>
						<?php
					}
					
					?>
					<a class="advert-js page-<?php echo $advertisment_id;?>" href="<?php echo $protocol . $microdata_host . '/' . $shortNameURL; ?>" title="<?php echo $shortNameALT;?>" target="_blank"><?php echo $shortNameALT;?></a>
					
					<?php 
					if (isset($_SESSION['user_id'])){
						
						$invoice_no = trim($line_categtop["invoice_no"]);
						$bind_type = trim($line_categtop["bind_type"]);
						$t_active_from = (trim($line_categtop["active_from"]) != "" && trim($line_categtop["active_from"]) != "0000-00-00") ? strtotime(trim($line_categtop["active_from"])) : "null";
						$t_active_to = (trim($line_categtop["active_to"]) != "" && trim($line_categtop["active_to"]) != "0000-00-00") ? strtotime(trim($line_categtop["active_to"])) : "null";
						$cur_timestamp = time();
						echo '<br/><a href="'. $protocol . $_SERVER['HTTP_HOST'] .'/admin/advert_manager.php?advert_action=advert_edit_main&advertisment_id=',$line_categtop['advertisment_id'],'" target="_blank">Edit</a>';
						echo '<div class="info-salesview">';
						if($invoice_no != "") {
							$inv_details = "";
							$qinv = "select i.details from advertisment_invoice i where i.adv_code='{$line_categtop["adv_code"]}' and i.in_use='1' and i.invoice='{$line_categtop["invoice_no"]}';";
							$rinv = mysql_query($qinv);
							if($rinv && mysql_num_rows($rinv)>0) {
								$rowinv = mysql_fetch_assoc($rinv);
								$inv_details = stripslashes($rowinv['details']);
							}
							
							if(array_key_exists($invoice_no, $short_invoice_types)) {
								echo '<span style="color:'.$short_invoice_types[$invoice_no]['color'].';">'.$short_invoice_types[$invoice_no]['short_name'].'</span>';
							}
							else {
								echo '<span style="color: #0000EE; font-weight: bold; text-decoration: none; ">'.$invoice_no.'</span>';
							}
							
							if($inv_details != "") {
								$inv_details = "Invoice Note ::: &raquo; " . $inv_details;
								?>
								<a href="javascript:;" class="tooltip_views" title="<?php echo $inv_details;?>"><img src="/images/class_info_red.gif" border="0" align="middle" alt="css-img"/></a>
								<?php
							}
							
						}
						else {
							echo '<span style="color:#ff0000;">[ <strong>NO_INVOICE</strong> ]</span>';
						}
						
						if($t_active_to != "null") {
							$active_from = $t_active_from != "null" ? date("d/m/Y", intval($t_active_from)) : 'Null';
							$active_to = $t_active_to != "null" ? date("d/m/Y", intval($t_active_to)) : 'Null';

							if($cur_timestamp > intval($t_active_to)) {
								echo '<br style="clear:both;"/><div style="color:#ff0000;" title="EXPIRED!!!">',$active_from, ' - ', $active_to,'</div>';
							}
							elseif(intval($t_active_to) < (strtotime("+2 month",$cur_timestamp))) {
								echo '<br style="clear:both;"/><div style="color:#0000EE;" title="EXPIRES IN LESS THAN 2 MONTHS!">',$active_from, ' - ', $active_to,'</div>';
							}
							else {
								echo '<br style="clear:both;"/><div style="color:#000000;" title="EXPIRES IN MORE THAN 2 MONTHS!">',$active_from, ' - ', $active_to,'</div>';
							}
						}
						else {
							$active_from = trim($t_active_from) != "null" ? date("d/m/Y", intval($t_active_from)) : 'Null';
							$active_to = trim($t_active_to) != "null" ? date("d/m/Y", intval($t_active_to)) : 'Null';
							echo '<br style="clear:both;"/><div style="color:#ff0000;" title="No Expiration Date">',$active_from, ' - ', $active_to,'</div>';
						}
						if($bind_type != "") {
							echo '<div style="clear: both; height: 16px; color:#ff0000; background-color: #FFE900;">',($bind_types[$bind_type]),'</div>';
						}
						
						
						if($line_categtop["member_id"]>0){
							$qha = "SELECT a.name, a.surname, a.user_id FROM auth a, members m WHERE m.member_id='{$line_categtop['member_id']}' AND a.user_id=m.salesman_id";
							$rha = @mysql_query($qha);
							if($rha && mysql_num_rows($rha) > 0) {
								$line_member = mysql_fetch_assoc($rha);
								echo '<div style="clear: both; height: 16px;">';
								echo '<strong>SP:</strong> ' . $line_member["name"] . ' ' . $line_member["surname"];
								echo '</div>';
							}
							else {
								echo '<div style="clear: both; height: 16px;">NO_SALESMAN</div>';
							}
						}
						else {
							echo '<div style="clear: both; height: 16px;">NO_CUSTOMER</div>';
						}
						echo '</div>';
					}
					?>
					</div>
				<?php 
				$count_categtop++;
				$num_adverts ++;
			}
			?>
		</div>
	</div>
	<?php 
}
?>
<?php //$query_adverts - loaded from ../general/queries.php

//if (isset($_SESSION['user_id'])){
//	echo $query_adverts;
//}

if(isset($_REQUEST['debugadv'])) {
	echo '<br/>' . $query_adverts;
}

$result_adverts = @mysql_query ($query_adverts);
if ($result_adverts && mysql_num_rows($result_adverts) > 0){
	$total_adverts = mysql_num_rows($result_adverts);
	$adverts = array();
	while($row_top = mysql_fetch_assoc($result_adverts)){

		//echo '<pre>', var_export($row_top, true),'</pre>';
		$advertisment_id = $row_top['advertisment_id'];

		$adverts[$advertisment_id] = array(
			"adv_code"	=> $row_top['adv_code'],
			"advertisment_id"	=> $row_top['advertisment_id'],
			"member_id"	=> intval($row_top['member_id']),
			"invoice_no"	=> trim($row_top['invoice_no']),
			"bind_type"	=> trim($row_top['bind_type']),
			"active_from"	=> trim($row_top['active_from']),
			"active_to"	=> trim($row_top['active_to']),
			"short_title_en"	=> stripslashes($row_top['short_title_en']),
			"title_tr"	=> $row_top['title_tr'],
			"advertisment"	=> $row_top['advertisment'],
			"display_name" => str_replace('"','', stripslashes($row_top["short_title_en"])),
			"friendly_url" => $row_top["title_tr"],
			"advert_logo_file" => $_SERVER['DOCUMENT_ROOT'] . "/images/advertisments/" . $row_top['advertisment'],
			"advert_logo_url" => $protocol . $microdata_host . "/images/advertisments/" . $row_top['advertisment'],
			"advert_logo_class" => "logo-" . $advertisment_id
		);



	}


	if(!$have_adverts_css) {
		foreach ($adverts as $advertisment_id=>$a) {
			$css_line = "." . $a['advert_logo_class'] . "{background-image:url(".getDataURI($a['advert_logo_file']).");}" . "\n";
			fwrite($facss, $css_line, strlen($css_line));
		}
	}


	?>
	<div class="adverts-top">
		<?php
		if($catdom_id_adv != $domain_id && $have_featured=="no" && $module_show_adv_title > 0) {
			?>
			<div class="adverts-top-title">
				<span><?php echo $recomented_value_en;?></span>
			</div>
			<?php
		}
		?>

		<div class="adverts-top-list">
			<?php
			$count_adverts=1;
			$num_adverts = 1;
			foreach ($adverts as $advertisment_id=>$line_adverts) {
				$use_town_dir = false;
				//Ioan modification
				$display_name = str_replace('"','',$line_adverts["short_title_en"]);
				$shortNameURL = $line_adverts["title_tr"];
				$shortNameALT = str_replace('"','',$line_adverts["short_title_en"]);
				$adv_unit_salesview_class = "";
				if (isset($_SESSION['user_id'])){
					$adv_unit_salesview_class = "adv-unit-salesview";
				}
				?>
				<div class="adv_unit adv-unit-top <?php echo $adv_unit_salesview_class;?>">
					<?php
					if (!isset($_SESSION['user_id'])){
						mysql_query("UPDATE advertisment SET views=views+1 WHERE advertisment_id='{$line_adverts['advertisment_id']}'") or die (mysql_error());
						count_views('adverts_stats_views', 'advertisment_id', $line_adverts['advertisment_id'], $domain_id, $catdom_id_adv, 'sel');

						$_adverts_views [] = array(
							"adv_code"				=> $line_adverts['adv_code'],
							"advertisment_id"		=> $line_adverts['advertisment_id'],
							"domain_id"				=> $domain_id,
							"catdom_id"				=> $catdom_id_adv,
							"domainname"			=> $ultra_domainname,
							"date_short"			=> date("Y-m-d"),
							"date_long"				=> date("Y-m-d H:i:s"),
							"views"					=> 1,
							"view_from"				=> 'seljs'
						);

					}

					// sel = selected adverts

					echo '<div class="advert_logo">';

						if($browser_type == "good") {
							echo '<a href="click_count.php?link=' .$shortNameURL. '&amp;type=www&amp;id=' . $line_adverts['advertisment_id'] . '&amp;domain='.$domainname.'&amp;domain_id='.$domain_id.'&amp;click_from=sel&amp;catdom_id='.$catdom_id_adv.'" target="_blank" rel="nofollow" title="'.$shortNameALT.'" class="'.$line_adverts['advert_logo_class'].' advert-logo"></a>';
						}
						else {
							echo '<a href="click_count.php?link=' .$shortNameURL. '&amp;type=www&amp;id=' . $line_adverts['advertisment_id'] . '&amp;domain='.$domainname.'&amp;domain_id='.$domain_id.'&amp;click_from=sel&amp;catdom_id='.$catdom_id_adv.'" target="_blank" rel="nofollow" class="advert-logo">';
								if($line_adverts['advertisment']<>""){
									?><img src="<?php echo $path;?>images/advertisments/<?php echo $line_adverts["advertisment"];?>" width="85" height="74" border="0" alt="<?php echo $shortNameALT;?>"/><?php
								}
								else{
									?><img src="<?php echo $path;?>images/navigation/no_pic.gif" width="85" height="74" border="0" alt="No picture"/><?php
								}
							echo '</a>';
						}
					echo '</div>';

					// Get the eventual rate
					$min_price = 0;
					$q_rates = "select a.* from hotel_affiliates_adverts a, hotel_affiliates r where a.aff_code=r.aff_code and r.aff_status='1' and a.adv_code='{$line_adverts['adv_code']}' and a.aff_hotel_status='1' order by a.low_rate asc;";

					$r_rates = @mysql_query($q_rates);
					if($r_rates && mysql_num_rows($r_rates) > 0) {
						while ($row_rates = mysql_fetch_assoc($r_rates)) {
							if($min_price == 0 && floatval($row_rates['low_rate']) > 0 ) {
								$min_price = floatval($row_rates['low_rate']);
							}
							if(floatval($row_rates['low_rate']) < $min_price) $min_price = floatval($row_rates['low_rate']);
						}
					}

					if($min_price > 0) {
						?>
						<div class="rate-bubble" onclick="show_page(<?php echo $advertisment_id;?>);">
							<span class="rate-bubble-text">From</span> &euro; <?php echo number_format($min_price, 0);?>
						</div>
						<?php
					}
					else {
						?>
						<div class="rate-bubble" onclick="show_page(<?php echo $advertisment_id;?>);">
							<span class="rate-bubble-text">Check Availability</span>
						</div>
						<?php
					}

					echo '<a class="advert-js page-'.$advertisment_id.'" ';
					echo ' href="' . $protocol . $microdata_host . '/' . $shortNameURL . '"';
					echo ' target="_blank" ';
					echo ' title="' . $shortNameALT . '">';
					echo $shortNameALT;
					echo '</a>';


					if (isset($_SESSION['user_id'])){
						$invoice_no = trim($line_adverts["invoice_no"]);
						$bind_type = trim($line_adverts["bind_type"]);
						$t_active_from = (trim($line_adverts["active_from"]) != "" && trim($line_adverts["active_from"]) != "0000-00-00") ? strtotime(trim($line_adverts["active_from"])) : "null";
						$t_active_to = (trim($line_adverts["active_to"]) != "" && trim($line_adverts["active_to"]) != "0000-00-00") ? strtotime(trim($line_adverts["active_to"])) : "null";
						$cur_timestamp = time();
						echo '<br/><a href="http://'. $_SERVER['HTTP_HOST'] .'/admin/advert_manager.php?advert_action=advert_edit_main&advertisment_id=',$line_adverts['advertisment_id'],'" target="_blank">Edit</a>';
						echo '<div class="info-salesview">';
						if($invoice_no != "") {
							$inv_details = "";
							$qinv = "select i.details from advertisment_invoice i where i.adv_code='{$line_adverts["adv_code"]}' and i.in_use='1' and i.invoice='{$line_adverts["invoice_no"]}';";
							$rinv = mysql_query($qinv);
							if($rinv && mysql_num_rows($rinv)>0) {
								$rowinv = mysql_fetch_assoc($rinv);
								$inv_details = stripslashes($rowinv['details']);
							}

							if(array_key_exists($invoice_no, $short_invoice_types)) {
								echo '<span style="color:'.$short_invoice_types[$invoice_no]['color'].';">'.$short_invoice_types[$invoice_no]['short_name'].'</span>';
							}
							else {
								echo '<span style="color: #0000EE; font-weight: bold; text-decoration: none; ">'.$invoice_no.'</span>';
							}

							if($inv_details != "") {
								$inv_details = "Invoice Note ::: &raquo; " . $inv_details;
								?>
								<a href="javascript:;" class="tooltip_views" title="<?php echo $inv_details;?>"><img src="/images/class_info_red.gif" border="0" align="middle" alt="css-img"/></a>
								<?php
							}

						}
						else {
							echo '<span style="color:#ff0000;">[ <strong>NO_INVOICE</strong> ]</span>';
						}

						if($t_active_to != "null") {
							$active_from = $t_active_from != "null" ? date("d/m/Y", intval($t_active_from)) : 'Null';
							$active_to = $t_active_to != "null" ? date("d/m/Y", intval($t_active_to)) : 'Null';

							if(intval($t_active_to) < $cur_timestamp) {
								echo '<br style="clear:both;"/><div style="color:#ff0000;" title="EXPIRED!!!">',$active_from, ' - ', $active_to,'</div>';
							}
							elseif(intval($t_active_to) > $cur_timestamp && intval($t_active_to) < (strtotime("+2 month",$cur_timestamp))) {
								echo '<br style="clear:both;"/><div style="color:#0000EE;" title="EXPIRES IN LESS THAN 2 MONTHS!">',$active_from, ' - ', $active_to,'</div>';
							}
							else {
								echo '<br style="clear:both;"/><div style="color:#000000;" title="EXPIRES IN MORE THAN 2 MONTHS!">',$active_from, ' - ', $active_to,'</div>';
							}
						}
						else {
							$active_from = trim($t_active_from) != "null" ? date("d/m/Y", intval($t_active_from)) : 'Null';
							$active_to = trim($t_active_to) != "null" ? date("d/m/Y", intval($t_active_to)) : 'Null';
							echo '<br style="clear:both;"/><div style="color:#ff0000;" title="No Expiration Date">',$active_from, ' - ', $active_to,'</div>';
						}
						if($bind_type != "") {
							echo '<div style="clear: both; height: 16px; color:#ff0000; background-color: #FFE900;">',($bind_types[$bind_type]),'</div>';
						}


						if($line_adverts["member_id"]>0){
							$qha = "SELECT a.name, a.surname, a.user_id FROM auth a, members m WHERE m.member_id='{$line_adverts['member_id']}' AND a.user_id=m.salesman_id";
							$rha = @mysql_query($qha);
							if($rha && mysql_num_rows($rha) > 0) {
								$line_member = mysql_fetch_assoc($rha);
								echo '<div style="clear: both; height: 16px;">';
								echo '<strong>SP:</strong> ' . $line_member["name"] . ' ' . $line_member["surname"];
								echo '</div>';
							}
							else {
								echo '<div style="clear: both; height: 16px;">NO_SALESMAN</div>';
							}
						}
						else {
							echo '<div style="clear: both; height: 16px;">NO_CUSTOMER</div>';
						}
						echo '</div>';
					}
				?>
				</div>
				<?php
				$count_adverts++;
				$num_adverts ++;
			}
			?>
		</div>
	</div>
	<?php
}

$curl_path = $protocol . $_SERVER['HTTP_HOST'] . "/curl.php";
if(str_replace('www.', '', $_SERVER['HTTP_HOST']) != str_replace('www.', '', $ultra_domainname)) {
	$curl_path = $protocol . $_SERVER['HTTP_HOST'] . "/$ultra_addonname/curl.php";
}

if(!$have_adverts_css) {
	fclose($facss);
}

$optres['css'][] = $css_filename;
if (isset($_SESSION['user_id'])){
    $optres['js'][] = $path . 'js/jquery.tooltip.min.js';
    $optres['js'][] = $path . 'amodules/adverts/js/adverts_js.js';

}