<?php
$module_css_path = ($line_domain['theme'] != "" && $line_domain['theme'] != "default") ? ($path . ('assets/themes/' . $line_domain['theme'] . '/')) : $path;

$optres['js'][] = $path . "js/jquery.blockUI.js";
if(isset($wb_search_params)) {
	
}
else {
	$wb_search_params = array(
		"dcode"		=> '',
		"lcode"		=> ''
	);
}
if(isset($module_params) && isset($module_params['wb_search_map_type']) && $module_params['wb_search_map_type'] == "standalone") {
	
	//echo '<pre>', var_export($module_params, true), '</pre>';
	
	
	$map_title = '';
	if(isset($module_params['module_page_title'])) {
		$map_title = trim($module_params['module_page_title']);
	}
	
	// Get All Main Categories
	$wb_mains = array();
	$wb_mains_adverts = array();
	$q = "SELECT * FROM `wb_filters_mains` where wb_uid='$wb_uid' and active='1' order by pos asc;";
	$r = @mysql_query($q);
	if($r && mysql_num_rows($r) > 0) {
		while ($row = mysql_fetch_assoc($r)) {
			$wb_mains [$row['fm_uid']] = array_map('stripslashes', $row);
		}
	}
	
	
	$json_locations = array();
	$ql = "SELECT a.short_title_en, l.adv_code, l.lat, l.lng, w.fm_uid
		FROM advertisment a, wb_categories_adverts c, advertisment_locations l, wb_filters_adverts_categs w
		WHERE a.adv_code = c.wb_advert_uid
		AND c.wb_uid = '$wb_uid'
		AND c.wb_status = '1'
		AND l.adv_code = a.adv_code
		AND w.adv_code = a.adv_code
		AND l.main_location = '1'
		GROUP BY l.adv_code";
	
	if(isset($_REQUEST['debugmap'])) echo "<br/>", $ql, "<br/>";
	$rl = @mysql_query($ql);
	if($rl && mysql_num_rows($rl) > 0) {
		while ($rowl = mysql_fetch_assoc($rl)) {
		
			if(abs($rowl['lat']) - 0 > 0) {
			
				$json_locations [] = array(
					"lat"		=> $rowl['lat'],
					"lng"		=> $rowl['lng'],
					"adv_code"	=> $rowl['adv_code'],
					"title"		=> htmlentities(stripslashes($rowl['short_title_en'])),
					"fm_uid"	=> $rowl['fm_uid'],
					"fm_name"	=> isset($wb_mains[$rowl['fm_uid']]) ? htmlentities($wb_mains[$rowl['fm_uid']]['title']) : ''
				);
			}
			else {
				if(isset($_REQUEST['debugmap'])) echo "<br/>" . $rowl['adv_code'] . " : lat=[" . $rowl['lat'] . "] -> [" . abs($rowl['lat']) . "]";
			}
		}
		
	}
	
	if(count($json_locations) > 0) {
		require_once(dirname(__FILE__) . "/wb_search_map_default.php");
		
		//require_once(dirname(__FILE__) . "/wb_search_map_js.php");
        $optres['js'][] = $path . "amodules/wb_search_map/js/markerclusterer.js";
        $optres['css'][] = $path . "assets/plugins/snazzy/snazzy-info-window.css";
        $optres['css'][] = $path . "assets/plugins/snazzy/snazzy-custom.css";
        $optres['css'][] = $path . "assets/css/bootstrap-dialog.min.css";
        $optres['js'][] = $path . "assets/js/bootstrap-dialog.min.js";
        $optres['js'][] = $path . 'amodules/wb_search_map/js/loader.js';
	}
	
}
else {
	require_once(dirname(__FILE__) . "/wb_search_map_default.php");
    $optres['js'][] = $path . "amodules/wb_search_map/js/markerclusterer.js";
    $optres['css'][] = $path . "assets/plugins/snazzy/snazzy-info-window.css";
    $optres['css'][] = $path . "assets/plugins/snazzy/snazzy-custom.css";
    $optres['css'][] = $path . "assets/css/bootstrap-dialog.min.css";
    $optres['js'][] = $path . "assets/js/bootstrap-dialog.min.js";
    $optres['js'][] = $path . 'amodules/wb_search_map/js/loader.js';
}
?>
<script>
    window.wb_search_map_init = '<?=$path;?>amodules/wb_search_map/js/wb_search_map.js';
    //console.log(window.wb_search_map_init);
</script>
