/**
  * @see IDX_Panel::getOptions()
  */
 public function getOptions()
 {
     $idx = Util_IDX::getIdx();
     $db_idx = Util_IDX::getDatabase();
     $query = "SELECT DISTINCT `" . $idx->field($this->field) . "` AS `value` FROM `" . $idx->getTable() . "`" . (!empty($extra) ? ' WHERE ' . $extra : '') . " ORDER BY `" . $idx->field($this->field) . "` DESC LIMIT 20;";
     if ($result = $db_idx->query($query)) {
         while ($option = $db_idx->fetchArray($result)) {
             $options[] = $option['value'];
         }
     } else {
         return false;
     }
     if (!empty($options)) {
         $post = array();
         $confirmed = array();
         foreach ($options as $val) {
             $pre = explode(',', $val);
             //confirm and add to array
             foreach ($pre as $opt) {
                 $opt = preg_replace('/(^\\s+)|(\\s{2,})|(\\s+$)|(\\n)|(\\r)/', ' ', $opt);
                 //trim and remove exessive spacing
                 if (!in_array_nocase($opt, $confirmed) && !empty($opt)) {
                     if (!empty($filter)) {
                         if (preg_match($filter, $opt)) {
                             $confirmed[] = $opt;
                         }
                     } else {
                         $confirmed[] = $opt;
                     }
                 }
             }
         }
         //sort them
         if (!empty($confirmed)) {
             asort($confirmed);
             foreach ($confirmed as $opt) {
                 $post[] = array('value' => $opt, 'title' => ucwords(strtolower($opt)));
             }
         }
         $this->options = $post;
     } else {
         return false;
     }
     return $this->options;
 }
/**
* REWMOD 01/31/2013 Eric B *456848651351*  Reduces comma seperated options into array of single options 
* useful for making select lists from fields were most rows have multiple options
* Can provide DB column to be pulled, or array of items to be reduced
* 
* @global $idx, $db_idx;
* @param {String} (conditional) $field column name to pull options from
* @param {String} (optional) $extra extra where statement for pulling options
* @param {String} (optional) $filter regex to match values. any non matches are filtered out
* @param {String} (optional) $delimiter string delimiter for options, predefined as ", "
* @param {Array}  (conditional) $options existing array of options to be limited
* 
* @return {Array|Bool} Array of options on success, False on failure
* 
*/
function reducedOptions($field = null, $extra = null, $filter = null, $delimiter = ', ', $options = array())
{
    //trying to get away from globals since 4.3
    if (class_exists('Util_IDX')) {
        $idx = Util_IDX::getIdx();
        $db_idx = Util_IDX::getDatabase();
    } else {
        global $idx, $db_idx;
    }
    if (empty($options) && !empty($field)) {
        $query = "SELECT DISTINCT `" . $idx->field($field) . "` FROM `" . $idx->getTable() . "`" . (!empty($extra) ? ' WHERE ' . $extra : '') . " ORDER BY `" . $idx->field($field) . "` DESC LIMIT 20;";
        if ($result = $db_idx->query($query)) {
            while ($option = $db_idx->fetchArray($result)) {
                $options[] = $option[$field];
            }
        } else {
            return false;
        }
    }
    if (!empty($options)) {
        $post = array();
        $confirmed = array();
        foreach ($options as $val) {
            $pre = explode($delimiter, $val);
            //confirm and add to array
            foreach ($pre as $opt) {
                $opt = preg_replace('/(^\\s+)|(\\s{2,})|(\\s+$)|(\\n)|(\\r)/', ' ', $opt);
                //trim and remove exessive spacing
                if (!in_array_nocase($opt, $confirmed) && !empty($opt)) {
                    if (!empty($filter)) {
                        if (preg_match($filter, $opt)) {
                            $confirmed[] = $opt;
                        }
                    } else {
                        $confirmed[] = $opt;
                    }
                }
            }
        }
        //sort them
        if (!empty($confirmed)) {
            asort($confirmed);
            foreach ($confirmed as $opt) {
                $post[] = array('value' => $opt, 'title' => ucwords(strtolower($opt)));
            }
        }
        return $post;
    } else {
        return false;
    }
}
 // Set $_REQUEST Criteria
 $criteria = is_array($criteria) ? $criteria : array();
 $_REQUEST = search_criteria($idx, $criteria);
 // Page Limit
 $criteria['page_limit'] = !empty($criteria['page_limit']) && $criteria['page_limit'] > 0 ? $criteria['page_limit'] : 5;
 // Price Range Links
 $criteria['price_ranges'] = isset($criteria['price_ranges']) ? $criteria['price_ranges'] : 'true';
 // Default View
 $criteria['view'] = isset($criteria['view']) ? $criteria['view'] : 'grid';
 // Select IDX
 if (!empty($criteria['feed'])) {
     Util_IDX::switchFeed($criteria['feed']);
 }
 // IDX objects
 $idx = Util_IDX::getIdx();
 $db_idx = Util_IDX::getDatabase();
 // Order / Sort
 list($criteria['sort'], $criteria['order']) = explode('-', $criteria['sort_by']);
 $criteria['order'] = isset($_REQUEST['order']) ? $_REQUEST['order'] : $criteria['order'];
 $criteria['sort'] = isset($_REQUEST['sort']) ? $_REQUEST['sort'] : $criteria['sort'];
 // Snippet Panels (Legacy Hack)
 $builder_panels = $criteria['panels'];
 // IDX Builder
 $builder = new IDX_Builder(array('map' => true, 'mode' => 'snippet', 'panels' => $criteria['panels']));
 // Slugify Snippet Name
 $page->writeJS("\$('#snippet_id').slugify();");
 // Pages using this Snippet
 $snippet['pages'] = array();
 // Check Homepage
 $query = "SELECT `agent` FROM `" . TABLE_SETTINGS . "` WHERE `agent` = '" . $agent_id . "' AND `category_html` LIKE '%#" . mysql_real_escape_string($snippet['name']) . "#%';";
 if ($result = mysql_query($query)) {
 /**
  * Check Field Values
  * @param string $field IDX Field Name
  * @return boolean
  * @TODO Move this to IDX_Feed
  */
 public static function checkField($field)
 {
     // IDX Feed
     $idx = Util_IDX::getIdx();
     $db_idx = Util_IDX::getDatabase();
     // IDX Field
     $field = $idx->field($field);
     // Require Field
     if (empty($field)) {
         return false;
     }
     // Cache Key
     $index = __METHOD__ . ':' . $idx->getName() . ':' . $db_idx->db() . ':' . $idx->getTable() . ':' . $field;
     // Is Cached (Server-Wide)
     $cache = static::$useCache && !static::$reCache ? Cache::getCache($index, true) : null;
     if (!is_null($cache)) {
         $check = $cache;
         // Not Cached
     } else {
         // Check for Values
         $check = $db_idx->fetchQuery("SELECT SQL_CACHE `" . $field . "` FROM `" . $idx->getTable() . "` WHERE `" . $field . "` IS NOT NULL AND `" . $field . "` != '' LIMIT 1;");
         // Return Boolean
         $check = !empty($check);
         // Save Cache (Server-Wide)
         if (static::$useCache || static::$reCache) {
             Cache::setCache($index, $check, true);
         }
     }
     // Return Check
     return $check;
 }
if (!empty($search_order) && !empty($search_sort) && !is_null($idx->field($search_order))) {
    $sort_col = $idx->field($search_order) ? $idx->field($search_order) : false;
    if (!empty($sort_col)) {
        $sql_order = " ORDER BY `" . $sort_col . '` ' . $search_sort;
    }
}
// Order by ID
$sql_order .= !empty($sql_order) ? ", `t1`.`id` ASC" : " ORDER BY `t1`.`" . $idx->field('AddressZipCode') . "` ASC";
// Create Search Query
$search_query = "SELECT SQL_CACHE " . $idx->selectColumns("`t1`.") . " FROM `" . $idx->getTable() . "` `t1`" . (!empty($search_where) ? ' WHERE ' . $search_where : '') . $sql_order;
// Execute Search Query
$search_results = $db_idx->query($search_query);
// Search Results
$results = array();
// Map Markers
$markers = array();
// Listing Results Found
if (!empty($search_results_count['total'])) {
    // Process Search Results
    while ($search_result = $db_idx->fetchArray($search_results)) {
        // Parse Listing
        $result = Util_IDX::parseListing($idx, $db_idx, $search_result);
        // Add to Collection
        $results[] = $result;
    }
    // Free Result
    if ($search_results) {
        $search_results->close();
    }
}
$_REQUEST = $oldRequest;
?>
">
	<input type="hidden" name="map[zoom]" value="<?php 
echo htmlspecialchars($_REQUEST['map']['zoom']);
?>
">
	<input type="hidden" name="map[latitude]" value="<?php 
echo htmlspecialchars($_REQUEST['map']['latitude']);
?>
">
	<input type="hidden" name="map[longitude]" value="<?php 
echo htmlspecialchars($_REQUEST['map']['longitude']);
?>
">
	<input type="hidden" name="idx" value="<?php 
echo Util_IDX::getIdx()->getLink();
?>
">
	<input type="hidden" name="map[radius]" value="<?php 
echo htmlspecialchars($_REQUEST['map']['radius']);
?>
">
	<input type="hidden" name="map[polygon]" value="<?php 
echo htmlspecialchars($_REQUEST['map']['polygon']);
?>
">
	<input type="hidden" name="map[ne]" value="<?php 
echo htmlspecialchars($_REQUEST['map']['ne']);
?>
">
	<input type="hidden" name="map[sw]" value="<?php 
<?php

// Load Module's Default Javascript
$javascript = $this->locateFile('module.js.php', __FILE__);
if (!empty($javascript)) {
    require_once $javascript;
}
?>
/* <script> */
(function () {

	'use strict';

    // global variables
    <?php 
$idx = Util_IDX::getIdx();
$tagNames = collab_tag_names($idx);
?>
    var tagNames = <?php 
echo json_encode($tagNames);
?>
, $collab_form = $('.idx-search-bar'), subtypeRequest = false, collab_request_limit = true, $map = $('#listings-map');
    
    // Update map values on submit
    $collab_form.bind('submit', function () {
    	
    	// Update map information fields
    	var center = $map.Map('getCenter'),
		zoom = $map.Map('getZoom'),
		bounds = $map.Map('getBounds'),
		polygons = $map.Map('getPolygons'),
 /**
  * @see IDX_Panel::fetchOptions()
  */
 public static function fetchOptions($field, $where = NULL, $order = NULL)
 {
     // IDX Feed
     $idx = Util_IDX::getIdx();
     $db_idx = Util_IDX::getDatabase();
     // Filter Sub-Type By Type
     $types = $_REQUEST['search_type'];
     $types = is_array($types) ? Format::trim($types) : Format::trim(explode(',', $types));
     $types = array_filter($types);
     // Filter Options
     $where = is_null($where) ? '' : $where . ' AND ';
     $type = $idx->field('ListingType');
     if (!empty($types) && !empty($type)) {
         $types = array_map(array(&$db_idx, 'cleanInput'), $types);
         $where = "`" . $type . "` = '" . implode("' OR `" . $type . "` = '", $types) . "'";
     }
     // Order by # of Records
     $field = $idx->field($field);
     $order = is_null($order) ? '' : $order . ',';
     $order .= "COUNT(`" . $field . "`) DESC";
     // Fetch Options
     return parent::fetchOptions($field, $where, $order);
 }