Exemplo n.º 1
0
    function cp_refine_search_builder($results)
    {
        global $wpdb, $cp_options;
        $cp_min_price = str_replace(',', '', $wpdb->get_var("SELECT min( CAST( m.meta_value AS UNSIGNED ) ) FROM {$wpdb->postmeta} m INNER JOIN {$wpdb->posts} p ON m.post_id = p.ID WHERE m.meta_key = 'cp_price' AND p.post_status = 'publish'"));
        $cp_max_price = str_replace(',', '', $wpdb->get_var("SELECT max( CAST( m.meta_value AS UNSIGNED ) ) FROM {$wpdb->postmeta} m INNER JOIN {$wpdb->posts} p ON m.post_id = p.ID WHERE m.meta_key = 'cp_price' AND p.post_status = 'publish'"));
        $show_precise = $cp_max_price > 1000 ? true : false;
        $locarray = array();
        ?>
	<script type="text/javascript">
	// <![CDATA[
	// toggles the refine search field values
	jQuery(document).ready(function() {
		jQuery('div.handle').click(function() {
			jQuery(this).next('div.element').animate({
				height: ['toggle', 'swing'],
				opacity: 'toggle' }, 200
			);

			jQuery(this).toggleClass('close', 'open');
			return false;
		});
		<?php 
        foreach ($_GET as $field => $val) {
            ?>
			jQuery('.<?php 
            echo esc_js($field);
            ?>
 div.handle').toggleClass('close', 'open');
			jQuery('.<?php 
            echo esc_js($field);
            ?>
 div.element').show();
		<?php 
        }
        ?>

	});
	// ]]>
	</script>

	<div id="refine_widget" class="shadowblock_out">

		<div class="shadowblock">

			<h2 class="dotted"><?php 
        _e('Refine Results', APP_TD);
        ?>
</h2>

			<ul class="refine">

				<form action="<?php 
        echo home_url('/');
        ?>
" method="get" name="refine-search">
				<?php 
        if (!is_tax(APP_TAX_CAT)) {
            ?>
					<input type="hidden" name="s" value="<?php 
            echo esc_attr(cp_get_search_term());
            ?>
" />
					<input type="hidden" name="scat" value="<?php 
            echo esc_attr(cp_get_search_catid());
            ?>
" />
				<?php 
        } else {
            ?>
					<input type="hidden" name="<?php 
            echo esc_attr(get_query_var('taxonomy'));
            ?>
" value="<?php 
            echo esc_attr(get_query_var('term'));
            ?>
" />
				<?php 
        }
        ?>

					<?php 
        // grab the price and location fields first and put into a separate array
        // then remove them from the results array so they don't print out again
        foreach ($results as $key => $value) {
            switch ($value->field_name) {
                case 'cp_city':
                    $locarray[0] = $results[$key];
                    unset($results[$key]);
                    break;
                case 'cp_zipcode':
                    $locarray[1] = $results[$key];
                    unset($results[$key]);
                    break;
                case 'cp_price':
                    $locarray[2] = $results[$key];
                    unset($results[$key]);
                    break;
            }
        }
        // sort array by key so we get the city/zip code first
        ksort($locarray);
        // both zip code and city have been checked
        if (array_key_exists(0, $locarray) && array_key_exists(1, $locarray)) {
            $flabel = sprintf(__('%1$s or %2$s', APP_TD), $locarray[0]->field_label, $locarray[1]->field_label);
            $fname = 'cp_city_zipcode';
        } elseif (array_key_exists(0, $locarray)) {
            // must be the city only
            $flabel = $locarray[0]->field_label;
            $fname = 'cp_city_zipcode';
        } elseif (array_key_exists(1, $locarray)) {
            // must be the zip code only
            $flabel = $locarray[1]->field_label;
            $fname = 'cp_city_zipcode';
        }
        $distance_unit = 'mi' == $cp_options->distance_unit ? __('miles', APP_TD) : __('kilometers', APP_TD);
        // show the city/zip code field and radius slider bar
        if (array_key_exists(0, $locarray) || array_key_exists(1, $locarray)) {
            ?>
						<script type="text/javascript">
						// <![CDATA[
							jQuery(document).ready(function() {
								jQuery('#dist-slider').slider( {
									range: 'min',
									min: 0,
									max: 100,
									value: <?php 
            echo esc_js(isset($_GET['distance']) ? intval($_GET['distance']) : '50');
            ?>
,
									step: 5,
									slide: function(event, ui) {
										jQuery('#distance').val(ui.value + ' <?php 
            echo esc_js($distance_unit);
            ?>
');
									}
								});
								jQuery('#distance').val(jQuery('#dist-slider').slider('value') + ' <?php 
            echo esc_js($distance_unit);
            ?>
');
							});
						// ]]>
						</script>

						<li class="distance">
							<label class="title"><?php 
            echo $flabel;
            ?>
</label>
							<input name="<?php 
            echo esc_attr($fname);
            ?>
" id="<?php 
            echo esc_attr($fname);
            ?>
" type="text" minlength="2" value="<?php 
            if (isset($_GET[$fname])) {
                echo esc_attr($_GET[$fname]);
            }
            ?>
" class="text" />
							<div class="clr"></div>
							<label for="distance" class="title"><?php 
            _e('Radius', APP_TD);
            ?>
:</label>
							<input type="text" id="distance" name="distance" />
							<div id="dist-slider"></div>
						</li>

					<?php 
        }
        // now loop through the other special fields
        foreach ($locarray as $value) {
            // show the price field range slider
            if ($value->field_name == 'cp_price') {
                $curr_symbol = $cp_options->curr_symbol;
                if (isset($_GET['amount'])) {
                    $amount = explode(' - ', $_GET['amount']);
                } else {
                    if (isset($_GET['price_min']) && isset($_GET['price_max'])) {
                        $amount = array($_GET['price_min'], $_GET['price_max']);
                    }
                }
                $amount[0] = empty($amount[0]) ? $cp_min_price : $amount[0];
                $amount[1] = empty($amount[1]) ? $cp_max_price : $amount[1];
                $amount[0] = str_replace(array(',', $curr_symbol, ' '), '', $amount[0]);
                $amount[1] = str_replace(array(',', $curr_symbol, ' '), '', $amount[1]);
                if ($cp_options->refine_price_slider) {
                    ?>

							<script type="text/javascript">
							// <![CDATA[
								jQuery(document).ready(function() {

									jQuery("#precise_price").click(function() {
										precise_price = ( jQuery(this).is(":checked") ) ? true : false;
										cp_show_price_slider(<?php 
                    echo esc_js(intval($cp_min_price));
                    ?>
, <?php 
                    echo esc_js(intval($cp_max_price));
                    ?>
, <?php 
                    echo esc_js(intval($amount[0]));
                    ?>
, <?php 
                    echo esc_js(intval($amount[1]));
                    ?>
, precise_price);
									});
									precise_price = ( jQuery("#precise_price").is(":checked") ) ? true : false;
									cp_show_price_slider(<?php 
                    echo esc_js(intval($cp_min_price));
                    ?>
, <?php 
                    echo esc_js(intval($cp_max_price));
                    ?>
, <?php 
                    echo esc_js(intval($amount[0]));
                    ?>
, <?php 
                    echo esc_js(intval($amount[1]));
                    ?>
, precise_price);

								});
							// ]]>
							</script>

							<li class="amount">
								<label class="title"><?php 
                    echo esc_html(translate($value->field_label, APP_TD));
                    ?>
:</label>
								<input type="text" id="amount" name="amount" />
								<div id="slider-range"></div>
								<?php 
                    if ($show_precise) {
                        ?>
									<label class="title"><?php 
                        echo esc_html(__('Precise price', APP_TD));
                        ?>
:</label><input type="checkbox" id="precise_price" name="precise_price" <?php 
                        checked(isset($_GET['precise_price']));
                        ?>
 />
								<?php 
                    }
                    ?>
							</li>
							<?php 
                } else {
                    ?>
							<li class="price_min_max">
								<label class="title"><?php 
                    echo esc_html(translate($value->field_label, APP_TD));
                    ?>
 (<?php 
                    echo $cp_options->curr_symbol;
                    ?>
)</label>
								<input type="text" class="text" id="price_min" name="price_min" placeholder="<?php 
                    _e('from', APP_TD);
                    ?>
" value="<?php 
                    if (isset($_GET['price_min'])) {
                        echo esc_attr($_GET['price_min']);
                    }
                    ?>
" /> &ndash;
								<input type="text" class="text" id="price_max" name="price_max" placeholder="<?php 
                    _e('to', APP_TD);
                    ?>
" value="<?php 
                    if (isset($_GET['price_max'])) {
                        echo esc_attr($_GET['price_max']);
                    }
                    ?>
" />
							</li>
							<?php 
                }
            }
        }
        foreach ($results as $key => $result) {
            if (in_array($result->field_type, array('radio', 'checkbox', 'drop-down', 'text box', 'text area'))) {
                echo cp_refine_fields($result->field_label, $result->field_name, $result->field_values, $result->field_type);
            }
        }
        ?>
					<div class="pad10"></div>
					<button class="obtn btn_orange" type="submit" tabindex="1" id="go" value="Go" name="sa"><?php 
        _e('Refine Results &rsaquo;&rsaquo;', APP_TD);
        ?>
</button>

					<input type="hidden" name="refine_search" value="yes" />

				</form>

			</ul>

			<div class="clr"></div>

		</div>

	</div>

<?php 
    }
Exemplo n.º 2
0
    function cp_refine_search_builder($results)
    {
        global $wpdb;
        $cp_min_price = str_replace(',', '', $wpdb->get_var("SELECT min( CAST( meta_value AS UNSIGNED ) ) FROM {$wpdb->postmeta} WHERE meta_key = 'cp_price'"));
        $cp_max_price = str_replace(',', '', $wpdb->get_var("SELECT max( CAST( meta_value AS UNSIGNED ) ) FROM {$wpdb->postmeta} WHERE meta_key = 'cp_price'"));
        $thousands = $cp_max_price > 1000 ? true : false;
        $locarray = array();
        ?>
	<script type="text/javascript">
	// <![CDATA[
	// toggles the refine search field values
	jQuery(document).ready(function() {
		jQuery('div.handle').click(function() {
			jQuery(this).next('div.element').animate({
				height: ['toggle', 'swing'],
				opacity: 'toggle' }, 200
			);

			jQuery(this).toggleClass('close', 'open');
			return false;
		});
		<?php 
        foreach ($_GET as $field => $val) {
            ?>
			jQuery('.<?php 
            echo esc_js($field);
            ?>
 div.handle').toggleClass('close', 'open');
			jQuery('.<?php 
            echo esc_js($field);
            ?>
 div.element').show();
		<?php 
        }
        ?>

	});
	// ]]>
	</script>

	<div class="shadowblock_out">

		<div class="shadowblock">

			<h2 class="dotted"><?php 
        _e('Refine Results', APP_TD);
        ?>
</h2>

			<ul class="refine">

				<form action="<?php 
        if (is_tax(APP_TAX_CAT)) {
            echo get_term_link(get_query_var('term'), get_query_var('taxonomy'));
        } else {
            bloginfo('wpurl');
        }
        ?>
" method="get" name="refine-search">
				<?php 
        if (!is_tax(APP_TAX_CAT)) {
            ?>
					<input type="hidden" name="s" value="<?php 
            echo esc_attr(cp_get_search_term());
            ?>
" />
					<input type="hidden" name="scat" value="<?php 
            echo esc_attr(cp_get_search_catid());
            ?>
" />
				<?php 
        }
        ?>

					<?php 
        // grab the price and location fields first and put into a separate array
        // then remove them from the results array so they don't print out again
        foreach ($results as $key => $value) {
            switch ($value->field_name) {
                case 'cp_city':
                    $locarray[0] = $results[$key];
                    unset($results[$key]);
                    break;
                case 'cp_zipcode':
                    $locarray[1] = $results[$key];
                    unset($results[$key]);
                    break;
                case 'cp_price':
                    $locarray[2] = $results[$key];
                    unset($results[$key]);
                    break;
                case 'cp_country':
                    $locarray[3] = $results[$key];
                    unset($results[$key]);
                    break;
                case 'cp_region':
                    $locarray[4] = $results[$key];
                    unset($results[$key]);
                    break;
            }
        }
        // sort array by key so we get the city/zip code first
        ksort($locarray);
        // echo '<pre>';
        // print_r($locarray);
        // echo '</pre><br/><br/>';
        // both zip code and city have been checked
        if (array_key_exists(0, $locarray) && array_key_exists(1, $locarray)) {
            $flabel = sprintf(__('%s or %s', APP_TD), $locarray[0]->field_label, $locarray[1]->field_label);
            $fname = 'cp_city_zipcode';
        } elseif (array_key_exists(0, $locarray)) {
            // must be the city only
            $flabel = $locarray[0]->field_label;
            $fname = 'cp_city_zipcode';
        } elseif (array_key_exists(1, $locarray)) {
            // must be the zip code only
            $flabel = $locarray[1]->field_label;
            $fname = 'cp_city_zipcode';
        }
        $distance_unit = 'mi' == get_option('cp_distance_unit', 'mi') ? __('miles', APP_TD) : __('kilometers', APP_TD);
        // show the city/zip code field and radius slider bar
        if (array_key_exists(0, $locarray) || array_key_exists(1, $locarray)) {
            ?>
						<script type="text/javascript">
						// <![CDATA[
							jQuery(document).ready(function() {
								jQuery('#dist-slider').slider( {
									range: 'min',
									min: 0,
									max: 100,
									value: <?php 
            echo esc_js(isset($_GET['distance']) ? intval($_GET['distance']) : '50');
            ?>
,
									step: 5,
									slide: function(event, ui) {
										jQuery('#distance').val(ui.value + ' <?php 
            echo esc_js($distance_unit);
            ?>
');
									}
								});
								jQuery('#distance').val(jQuery('#dist-slider').slider('value') + ' <?php 
            echo esc_js($distance_unit);
            ?>
');
							});
						// ]]>
						</script>

						<li class="distance">
							<label class="title"><?php 
            echo $flabel;
            ?>
</label>
							<input name="<?php 
            echo esc_attr($fname);
            ?>
" id="<?php 
            echo esc_attr($fname);
            ?>
" type="text" minlength="2" value="<?php 
            if (isset($_GET[$fname])) {
                echo esc_attr($_GET[$fname]);
            }
            ?>
" class="text" />
							<div class="clr"></div>
							<label for="distance" class="title"><?php 
            _e('Radius', APP_TD);
            ?>
:</label>
							<input type="text" id="distance" name="distance" />
							<div id="dist-slider"></div>
						</li>

					<?php 
        }
        // now loop through the other special fields
        foreach ($locarray as $value) {
            // show the price field range slider
            if ($value->field_name == 'cp_price') {
                $curr_symbol = get_option('cp_curr_symbol', '$');
                $cp_curr_symbol_pos = get_option('cp_curr_symbol_pos', 'left');
                if (isset($_GET['amount'])) {
                    $amount = explode(' - ', $_GET['amount']);
                }
                $amount[0] = empty($amount[0]) ? $cp_min_price : $amount[0];
                $amount[1] = empty($amount[1]) ? $cp_max_price : $amount[1];
                $amount[0] = str_replace(array(',', $curr_symbol, ' '), '', $amount[0]);
                $amount[1] = str_replace(array(',', $curr_symbol, ' '), '', $amount[1]);
                ?>

							<script type="text/javascript">
							// <![CDATA[
								jQuery(document).ready(function() {
									function cp_show_price_slider(min_price, max_price, min_value, max_value, thousands) {
										min_value = ( (thousands && min_value <= 1000) ? 1000 : ( (!thousands && min_value >= 1000) ? 0 : min_value ) );
										max_value = ( (thousands && max_value <= 1000) ? max_price : ( (!thousands && max_value >= 1000) ? 1000 : max_value ) );

										jQuery('#slider-range').slider( {
										  range: true,
										  min: ( (thousands) ? 1000 : min_price ),
										  max: ( (thousands) ? max_price : 1000 ),
										  step: 1,
										  values: [ min_value, max_value ],
										  slide: function(event, ui) {
												<?php 
                switch ($cp_curr_symbol_pos) {
                    case 'left':
                        ?>
jQuery('#amount').val('<?php 
                        echo $curr_symbol;
                        ?>
' + ui.values[0] + ' - <?php 
                        echo $curr_symbol;
                        ?>
' + ui.values[1]);<?php 
                        break;
                    case 'left_space':
                        ?>
jQuery('#amount').val('<?php 
                        echo $curr_symbol;
                        ?>
 ' + ui.values[0] + ' - <?php 
                        echo $curr_symbol;
                        ?>
 ' + ui.values[1]);<?php 
                        break;
                    case 'right':
                        ?>
jQuery('#amount').val(ui.values[0] + '<?php 
                        echo $curr_symbol;
                        ?>
 - ' + ui.values[1] + '<?php 
                        echo $curr_symbol;
                        ?>
' );<?php 
                        break;
                    case 'right_space':
                        ?>
jQuery('#amount').val(ui.values[0] + ' <?php 
                        echo $curr_symbol;
                        ?>
 - ' + ui.values[1] + ' <?php 
                        echo $curr_symbol;
                        ?>
' );<?php 
                        break;
                }
                ?>
										  }
										});

										<?php 
                switch ($cp_curr_symbol_pos) {
                    case 'left':
                        ?>
jQuery('#amount').val('<?php 
                        echo $curr_symbol;
                        ?>
' + jQuery('#slider-range').slider('values', 0) + ' - <?php 
                        echo $curr_symbol;
                        ?>
' + jQuery('#slider-range').slider('values', 1));<?php 
                        break;
                    case 'left_space':
                        ?>
jQuery('#amount').val('<?php 
                        echo $curr_symbol;
                        ?>
 ' + jQuery('#slider-range').slider('values', 0) + ' - <?php 
                        echo $curr_symbol;
                        ?>
 ' + jQuery('#slider-range').slider('values', 1));<?php 
                        break;
                    case 'right':
                        ?>
jQuery('#amount').val(jQuery('#slider-range').slider('values', 0) + '<?php 
                        echo $curr_symbol;
                        ?>
 - ' + jQuery('#slider-range').slider('values', 1) + '<?php 
                        echo $curr_symbol;
                        ?>
');<?php 
                        break;
                    case 'right_space':
                        ?>
jQuery('#amount').val(jQuery('#slider-range').slider('values', 0) + ' <?php 
                        echo $curr_symbol;
                        ?>
 - ' + jQuery('#slider-range').slider('values', 1) + ' <?php 
                        echo $curr_symbol;
                        ?>
');<?php 
                        break;
                }
                ?>

									};

									jQuery("#thousands").click(function() {
										thousands = ( jQuery(this).is(":checked") ) ? true : false;
										cp_show_price_slider(<?php 
                echo esc_js(intval($cp_min_price));
                ?>
, <?php 
                echo esc_js(intval($cp_max_price));
                ?>
, <?php 
                echo esc_js(intval($amount[0]));
                ?>
, <?php 
                echo esc_js(intval($amount[1]));
                ?>
, thousands);
									});
									thousands = ( jQuery("#thousands").is(":checked") ) ? true : false;
									cp_show_price_slider(<?php 
                echo esc_js(intval($cp_min_price));
                ?>
, <?php 
                echo esc_js(intval($cp_max_price));
                ?>
, <?php 
                echo esc_js(intval($amount[0]));
                ?>
, <?php 
                echo esc_js(intval($amount[1]));
                ?>
, thousands);

								});
							// ]]>
							</script>

							<li class="amount">
								<label class="title"><?php 
                echo esc_html(translate($value->field_label, APP_TD));
                ?>
:</label>
								<input type="text" id="amount" name="amount" />
								<div id="slider-range"></div>
								<?php 
                if ($thousands) {
                    ?>
									<label class="title"><?php 
                    echo esc_html(__('Show Thousands', APP_TD));
                    ?>
:</label><input type="checkbox" id="thousands" name="thousands" <?php 
                    checked(isset($_GET['thousands']));
                    ?>
 />
								<?php 
                }
                ?>
							</li>
							<?php 
            }
            if ('cp_region' == $value->field_name || 'cp_country' == $value->field_name) {
                echo cp_refine_fields($value->field_label, $value->field_name, $value->field_values);
            }
            // show the state values
            // uncomment to include states
            // if ( $value->field_name == 'cp_state' )
            // echo cp_refine_fields( $value->field_label, $value->field_name, $value->field_values );
        }
        // echo '<pre>';
        // print_r($results);
        // echo'</pre>';
        foreach ($results as $key => $result) {
            switch ($result->field_type) {
                // case 'text box':
                case 'radio':
                case 'checkbox':
                case 'drop-down':
                    echo cp_refine_fields($result->field_label, $result->field_name, $result->field_values);
                    break;
            }
            ?>

					<?php 
        }
        ?>
					<div class="pad10"></div>
					<button class="obtn btn_orange" type="submit" tabindex="1" id="go" value="Go" name="sa"><?php 
        _e('Refine Results &rsaquo;&rsaquo;', APP_TD);
        ?>
</button>
          
          <input type="hidden" name="refine_search" value="yes" />
          
				</form>

			</ul>

			<div class="clr"></div>

		</div>

	</div>

	<?php 
    }
Exemplo n.º 3
0
    function cp_refine_search_builder($results, $catid)
    {
        global $wpdb;
        $cp_min_price = str_replace(',', '', $wpdb->get_var("SELECT min( CAST( meta_value AS UNSIGNED ) ) FROM {$wpdb->term_relationships},{$wpdb->postmeta} WHERE object_id=post_id AND meta_key = 'cp_price' And term_taxonomy_id = {$catid};"));
        $cp_max_price = str_replace(',', '', $wpdb->get_var("SELECT max( CAST( meta_value AS UNSIGNED ) ) FROM {$wpdb->term_relationships},{$wpdb->postmeta} WHERE object_id=post_id AND meta_key = 'cp_price' And term_taxonomy_id = {$catid};"));
        if (!$cp_max_price) {
            $cp_max_price = 0;
            $cp_min_price = 0;
        }
        $subcats = get_term_children($catid, 'ad_cat');
        if (count($subcats) > 0) {
            $counter = count($subcats) - '1';
            while ($counter >= 0) {
                $cat_max_price = str_replace(',', '', $wpdb->get_var("SELECT max( CAST( meta_value AS UNSIGNED ) ) FROM {$wpdb->term_relationships},{$wpdb->postmeta} WHERE object_id=post_id AND meta_key = 'cp_price' And term_taxonomy_id = {$subcats[$counter]};"));
                if ($cat_max_price > $cp_max_price && $cat_max_price) {
                    $cp_max_price = $cat_max_price;
                }
                $cat_min_price = str_replace(',', '', $wpdb->get_var("SELECT min( CAST( meta_value AS UNSIGNED ) ) FROM {$wpdb->term_relationships},{$wpdb->postmeta} WHERE object_id=post_id AND meta_key = 'cp_price' And term_taxonomy_id = {$subcats[$counter]};"));
                if ($cat_min_price) {
                    if ($cp_min_price == 0) {
                        $cp_min_price = $cat_min_price;
                    } else {
                        if ($cp_min_price > $cat_min_price) {
                            $cp_min_price = $cat_min_price;
                        }
                    }
                }
                $counter--;
            }
        }
        $locarray = array();
        ?>
	<script type="text/javascript">
	// <![CDATA[
	// toggles the refine search field values
	jQuery(document).ready(function($) {
		$('div.handle').click(function() {
			$(this).next('div.element').animate({
				height: ['toggle', 'swing'],
				opacity: 'toggle' }, 200
			);

			$(this).toggleClass('close', 'open');
			return false;
		});
		<?php 
        foreach ($_POST as $field => $val) {
            ?>
		$('.<?php 
            echo $field;
            ?>
 div.handle').toggleClass('close', 'open');
		$('.<?php 
            echo $field;
            ?>
 div.element').show();
		<?php 
        }
        ?>

	});
	// ]]>
	</script>

	<div class="shadowblock_out">

		<div class="shadowblock">

			<h2 class="dotted"><?php 
        _e('Refine Results', 'appthemes');
        ?>
</h2>

			<ul class="refine">

				<form method="post" name="refine-search">

					<?php 
        // grab the price and location fields first and put into a separate array
        // then remove them from the results array so they don't print out again
        foreach ($results as $key => $value) {
            switch ($value->field_name) {
                case 'cp_city':
                    $locarray[0] = $results[$key];
                    unset($results[$key]);
                    break;
                case 'cp_zipcode':
                    $locarray[1] = $results[$key];
                    unset($results[$key]);
                    break;
                case 'cp_price':
                    $locarray[2] = $results[$key];
                    unset($results[$key]);
                    break;
                case 'cp_country':
                    $locarray[3] = $results[$key];
                    unset($results[$key]);
                    break;
                case 'cp_region':
                    $locarray[4] = $results[$key];
                    unset($results[$key]);
                    break;
            }
        }
        // sort array by key so we get the city/zip code first
        ksort($locarray);
        // echo '<pre>';
        // print_r($locarray);
        // echo '</pre><br/><br/>';
        // both zip code and city have been checked
        if (array_key_exists(0, $locarray) && array_key_exists(1, $locarray)) {
            $flabel = sprintf(__("%s or %s", 'appthemes'), $locarray[0]->field_label, $locarray[1]->field_label);
            $fname = 'cp_city_zipcode';
        } elseif (array_key_exists(0, $locarray)) {
            // must be the city only
            $flabel = $locarray[0]->field_label;
            $fname = 'cp_city_zipcode';
        } elseif (array_key_exists(1, $locarray)) {
            // must be the zip code only
            $flabel = $locarray[1]->field_label;
            $fname = 'cp_city_zipcode';
        }
        $distance_unit = 'mi' == get_option('cp_distance_unit', 'mi') ? 'miles' : 'kilometers';
        // show the city/zip code field and radius slider bar
        if (array_key_exists(0, $locarray) || array_key_exists(1, $locarray)) {
            ?>
						<script type="text/javascript">
						// <![CDATA[
							jQuery(document).ready(function($) {
								$('#dist-slider').slider( {
									range: 'min',
									min: 0,
									max: 100,
									value: <?php 
            echo esc_js(isset($_POST['distance']) ? intval($_POST['distance']) : '50');
            ?>
,
									step: 5,
									slide: function(event, ui) {
										$('#distance').val(ui.value + ' <?php 
            _e($distance_unit, 'appthemes');
            ?>
');
									}
								});
								$('#distance').val($('#dist-slider').slider('value') + '  <?php 
            _e($distance_unit, 'appthemes');
            ?>
');
							});
						// ]]>
						</script>

						<li class="distance">
							<label class="title"><?php 
            echo $flabel;
            ?>
</label>
							<input name="<?php 
            echo esc_attr($fname);
            ?>
" id="<?php 
            echo esc_attr($fname);
            ?>
" type="text" minlength="2" value="<?php 
            if (isset($_POST[$fname])) {
                echo esc_attr($_POST[$fname]);
            }
            ?>
" class="text" />
							<div class="clr"></div>
							<label for="distance" class="title"><?php 
            _e('Radius', 'appthemes');
            ?>
:</label>
							<input type="text" id="distance" name="distance" />
							<div id="dist-slider"></div>
						</li>

					<?php 
        }
        // now loop through the other special fields
        foreach ($locarray as $value) {
            // show the price field range slider
            if ($value->field_name == 'cp_price') {
                $curr_symbol = get_option('cp_curr_symbol', '$');
                $cp_curr_symbol_pos = get_option('cp_curr_symbol_pos', 'left');
                if (isset($_POST['amount'])) {
                    $amount = explode(' - ', $_POST['amount']);
                }
                $amount[0] = empty($amount[0]) ? $cp_min_price : $amount[0];
                $amount[1] = empty($amount[1]) ? $cp_max_price : $amount[1];
                $amount[0] = str_replace(array(',', $curr_symbol, ' '), '', $amount[0]);
                $amount[1] = str_replace(array(',', $curr_symbol, ' '), '', $amount[1]);
                ?>

							<script type="text/javascript">
							// <![CDATA[
								jQuery(document).ready(function($) {
									$('#slider-range').slider( {
									  range: true,
									  min: <?php 
                echo esc_js(intval($cp_min_price));
                ?>
,
									  max: <?php 
                echo esc_js(intval($cp_max_price));
                ?>
,
									  step: 1,
									  values: [ <?php 
                echo esc_js("{$amount[0]}, {$amount[1]}");
                ?>
 ],
									  slide: function(event, ui) {
										<?php 
                switch ($cp_curr_symbol_pos) {
                    case 'left':
                        ?>
$('#amount').val('<?php 
                        echo $curr_symbol;
                        ?>
' + ui.values[0] + ' - <?php 
                        echo $curr_symbol;
                        ?>
' + ui.values[1]);<?php 
                        break;
                    case 'left_space':
                        ?>
$('#amount').val('<?php 
                        echo $curr_symbol;
                        ?>
 ' + ui.values[0] + ' - <?php 
                        echo $curr_symbol;
                        ?>
 ' + ui.values[1]);<?php 
                        break;
                    case 'right':
                        ?>
$('#amount').val(ui.values[0] + '<?php 
                        echo $curr_symbol;
                        ?>
 - ' + ui.values[1] + '<?php 
                        echo $curr_symbol;
                        ?>
' );<?php 
                        break;
                    case 'right_space':
                        ?>
$('#amount').val(ui.values[0] + ' <?php 
                        echo $curr_symbol;
                        ?>
 - ' + ui.values[1] + ' <?php 
                        echo $curr_symbol;
                        ?>
' );<?php 
                        break;
                }
                ?>
									  }
									});
									<?php 
                switch ($cp_curr_symbol_pos) {
                    case 'left':
                        ?>
$('#amount').val('<?php 
                        echo $curr_symbol;
                        ?>
' + $('#slider-range').slider('values', 0) + ' - <?php 
                        echo $curr_symbol;
                        ?>
' + $('#slider-range').slider('values', 1));<?php 
                        break;
                    case 'left_space':
                        ?>
$('#amount').val('<?php 
                        echo $curr_symbol;
                        ?>
 ' + $('#slider-range').slider('values', 0) + ' - <?php 
                        echo $curr_symbol;
                        ?>
 ' + $('#slider-range').slider('values', 1));<?php 
                        break;
                    case 'right':
                        ?>
$('#amount').val($('#slider-range').slider('values', 0) + '<?php 
                        echo $curr_symbol;
                        ?>
 - ' + $('#slider-range').slider('values', 1) + '<?php 
                        echo $curr_symbol;
                        ?>
');<?php 
                        break;
                    case 'right_space':
                        ?>
$('#amount').val($('#slider-range').slider('values', 0) + ' <?php 
                        echo $curr_symbol;
                        ?>
 - ' + $('#slider-range').slider('values', 1) + ' <?php 
                        echo $curr_symbol;
                        ?>
');<?php 
                        break;
                }
                ?>

								});
							// ]]>
							</script>

							<li class="amount">
								<label class="title"><?php 
                echo $value->field_label;
                ?>
:</label>
								<input type="text" id="amount" name="amount" />
								<div id="slider-range"></div>
							</li>
							<?php 
            }
            if ('cp_region' == $value->field_name || 'cp_country' == $value->field_name) {
                echo cp_refine_fields($value->field_label, $value->field_name, $value->field_values);
            }
            // show the state values
            // uncomment to include states
            // if ( $value->field_name == 'cp_state' )
            // echo cp_refine_fields( $value->field_label, $value->field_name, $value->field_values );
        }
        // echo '<pre>';
        // print_r($results);
        // echo'</pre>';
        foreach ($results as $key => $result) {
            switch ($result->field_type) {
                // case 'text box':
                case 'radio':
                case 'checkbox':
                case 'drop-down':
                    echo cp_refine_fields($result->field_label, $result->field_name, $result->field_values);
                    break;
            }
            ?>

					<?php 
        }
        ?>
					<div class="pad10"></div>
					<button class="obtn btn_orange" type="submit" tabindex="1" id="go" value="Go" name="sa"><?php 
        _e('Refine Results &rsaquo;&rsaquo;', 'appthemes');
        ?>
</button>
          
          <input type="hidden" name="refine_search" value="yes" />
          
				</form>

			</ul>

			<div class="clr"></div>

		</div>

	</div>

	<?php 
    }