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

$optres['js'][] = $path . "assets/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_type']) && $module_params['wb_search_type'] == "standalone") {
	if(isset($_REQUEST['debugwb'])) {
		echo '<br/>standalone = ', var_export($module_params, true);	
	}
	//echo '<>', var_export($module_params, true), '<>';
	//require_once(dirname(__FILE__) . "/wb_search_init.php");
	if(isset($module_params) && count($module_params) > 0) {
		$wb_srch_dcode = trim($module_params['dcode']);
		$wb_srch_lcode = trim($module_params['lcode']);
		$wb_srch_fm_uid = trim($module_params['fm_uid']);
		$wb_srch_selected_fm_uid = trim($module_params['module_selected_fm_uid']);
		$wb_search_form_title = stripslashes(trim($module_params['wb_search_form_title']));
		$wb_search_post_url = trim($module_params['wb_search_post_url']) != '' ? trim($module_params['wb_search_post_url']) : '';
	}
	
	if(!isset($wb_uid)) {

		$q = "select wb.* from wb_categories_domains wb where wb.wb_domainname='$wb_domainname';";
		$r = mysql_query($q) or die("<strong>$q</strong>".mysql_error());
		if($r && mysql_num_rows($r) > 0) {
			$row = mysql_fetch_assoc($r);
			$wb_uid = $row['wb_uid'];
		}
			
	}
	
	// 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);
		}
	}
	
	// Get Main Categories
	$wb_filters_mains = array();
	$q = "select * from wb_filters_mains where wb_uid='$wb_uid' order by pos asc;";
	$r = @mysql_query($q);
	if($r && mysql_num_rows($r) > 0) {
		$fm_selected = (isset($fm_uid) && $fm_uid != "") ? $fm_uid : '';
		$fm_cnt = 1;
		while ($row = mysql_fetch_assoc($r)) {
			
			if($fm_cnt == 1 && $fm_selected == "") {
				//$fm_selected = $row['fm_uid'];
				//$fm_uid = $row['fm_uid'];
			}
			
			$wb_filters_mains [$row['fm_uid']] = array(
				"title"		=> trim(stripslashes($row['title'])),
				"results"	=> 0,
				"selected"	=> ($row['fm_uid'] == $fm_selected) ? 1 : 0
			);
			
			$fm_cnt ++;
		}
	}
	
	
	
	//$wb_srch_fm_uid = '';
	$wb_search_params['wb_adverts'] = array();
	
	// Get All visible Adverts by wb_uid
	$wb_uid_adverts = array();
	//$q = "select a.wb_advert_uid, f.fm_uid from wb_categories_adverts a, wb_filters_adverts f where a.wb_uid='$wb_uid' and a.wb_status='1' and a.wb_advert_uid=f.adv_code group by a.wb_advert_uid;";
	
	// Changed: dont care of filters as there might be categories which do not have filters
	$q = "select a.wb_advert_uid, f.fm_uid from wb_categories_adverts a, wb_filters_adverts_categs f where a.wb_uid='$wb_uid' and a.wb_status='1' and a.wb_advert_uid=f.adv_code and f.wb_uid='$wb_uid' group by a.wb_advert_uid;";
	$r = @mysql_query($q);
	if($r && mysql_num_rows($r) > 0) {
		while ($row = mysql_fetch_assoc($r)) {
			$wb_search_params['wb_adverts'][] = $row['wb_advert_uid'];
			if(isset($wb_filters_mains [$row['fm_uid']])) {
				$wb_filters_mains [$row['fm_uid']]['results'] += 1;
			}
		}
	}
	
	if($wb_search_post_url != "") {
		include(dirname(__FILE__) . "/wb_search_top_default.php");
		
		echo '<br/>';
	}
}
else {
	include(dirname(__FILE__) . "/wb_search_top_default.php");
}
?>