Exemplo n.º 1
0
 function serviceGetSqlParts($mixedCountry, $sZip, $sMetric, $iDistance, &$sJoin, &$aWhere)
 {
     if (!getParam('bx_zip_enabled')) {
         return false;
     }
     $sWhere = '';
     // check input fields
     $sZip = process_db_input(strtoupper(trim($sZip)), BX_TAGS_STRIP);
     $sMetric = process_db_input($sMetric, BX_TAGS_STRIP);
     $iDistance = (int) $iDistance;
     if (is_array($mixedCountry)) {
         $sCountry = process_db_input($mixedCountry[0], BX_TAGS_STRIP);
         // no reason to search by zipcode in different countries
     } else {
         $sCountry = process_db_input($mixedCountry, BX_TAGS_STRIP);
     }
     // check GB and CA zipcodes
     if ('CA' == $sCountry) {
         $sZip = substr($sZip, 0, 3);
     } elseif ('GB' == $sCountry) {
         $sZip = strlen($sZip) > 4 ? trim(substr($sZip, 0, -3)) : trim($sZip);
     }
     // search using google - Worls Maps module needs to be installed and configured
     if ('Google' == getParam('bx_zip_mode') && $this->_oDb->isModule('wmap')) {
         if ($sMetric == 'km') {
             $iDistance *= 0.62;
         }
         do {
             $sAddress = "{$sZip} " . str_replace('_', '', $GLOBALS['aPreValues']['Country'][$sCountry]['LKey']);
             if (200 != $this->_geocodeGoogle($sAddress, $fLat, $fLng, $sCountry)) {
                 $this->_setError(_t('_No zip codes found'));
                 break;
             }
             if (!class_exists('RadiusAssistant')) {
                 require_once BX_DIRECTORY_PATH_INC . 'RadiusAssistant.inc.php';
             }
             $zcdRadius = new RadiusAssistant($fLat, $fLng, $iDistance);
             $minLat = $zcdRadius->MinLatitude();
             $maxLat = $zcdRadius->MaxLatitude();
             $minLong = $zcdRadius->MinLongitude();
             $maxLong = $zcdRadius->MaxLongitude();
             $sWhere = " `Profiles`.`Country` = '{$sCountry}' AND `bx_wmap_locations`.`country` = '{$sCountry}' AND `bx_wmap_locations`.`failed` = 0 AND `bx_wmap_locations`.`lat` >= {$minLat} AND `bx_wmap_locations`.`lat` <= {$maxLat} AND `bx_wmap_locations`.`lng` >= {$minLong} AND `bx_wmap_locations`.`lng` <= {$maxLong} ";
             $sJoin .= " INNER JOIN `bx_wmap_locations` ON (`bx_wmap_locations`.`part` = 'profiles' AND  `bx_wmap_locations`.`id` = `Profiles`.`ID`) ";
         } while (0);
     } else {
         if ($sMetric != 'km') {
             $iDistance *= 1.61;
         }
         if ($iDistance > 30) {
             // free service don't allow to search more than 30 km
             $iDistance = 30;
         }
         do {
             $s = $this->_readFromUrl($this->_server . "/findNearbyPostalCodes?postalcode={$sZip}&country={$sCountry}&radius={$iDistance}&style={$this->_style}&maxRows={$this->_maxRows}&username="******" `Country` = '{$sCountry}' AND (";
                 foreach ($aZips as $s) {
                     $sWhere .= " UPPER(IF(LENGTH(`Profiles`.`zip`) > 4,TRIM(SUBSTRING(`Profiles`.`zip`,1,LENGTH(`Profiles`.`zip`)-3)),`Profiles`.`zip`)) = '{$s}' OR ";
                 }
                 $sWhere = substr($sWhere, 0, -4);
                 $sWhere .= ")";
             } elseif ('CA' == $sCountry) {
                 $sWhere = " `Country` = '{$sCountry}' AND (UPPER(SUBSTRING(`Profiles`.`zip`,1,3)) = '" . join("' OR UPPER(SUBSTRING(`Profiles`.`zip`,1,3)) = '", $aZips) . "') ";
             } else {
                 $sWhere = " `Country` = '{$sCountry}' AND (UPPER(`Profiles`.`zip`) = '" . join("' OR UPPER(`Profiles`.`zip`) = '", $aZips) . "') ";
             }
         } while (0);
     }
     if ($s = $this->getError()) {
         $aWhere[] = ' 0 ';
     } else {
         foreach ($aWhere as $k => $v) {
             if (preg_match('/`zip`/', $v) || preg_match('/`Country`/', $v)) {
                 unset($aWhere[$k]);
             }
         }
         $aWhere[] = $sWhere ? $sWhere : ' 0 ';
     }
     return true;
 }
Exemplo n.º 2
0
 function get_zip_codes_in_radious($ZIPCode, $radious, $radiusTo = '')
 {
     //var $resultZipCodes;
     //$result = mysql_fetch_array("SELECT Latitude,Longitude FROM xebura_ZIPCODES WHERE ZIPCode = '$ZIPCode'");
     $rs = $this->query("SELECT Latitude,Longitude FROM xebura_ZIPCODES WHERE ZIPCode = '{$ZIPCode}'");
     //echo '<br>ZIPCode ---> '.$ZIPCode;
     if ($this->getNumRows($rs) > 0) {
         $values = $this->fetchQueryArray($rs);
         $LAT = $values['Latitude'];
         $LON = $values['Longitude'];
         //echo '<br>Latitude ---> '.$LAT;
         //echo '<br>Longitude---> '.$LON;
         //$myrow = mysql_fetch_array($result);
         //$Latitude = $myrow["Latitude"];
         //$Longitude = $myrow["Longitude"];
         //echo '<br>L1 ---> '.$myrow[0];
         if (!empty($radiusTo)) {
             $zcdRadius = new RadiusAssistant($LAT, $LON, $radiusTo);
         } else {
             $zcdRadius = new RadiusAssistant($LAT, $LON, $radious);
         }
         $minLat = $zcdRadius->MinLatitude();
         $maxLat = $zcdRadius->MaxLatitude();
         $minLong = $zcdRadius->MinLongitude();
         $maxLong = $zcdRadius->MaxLongitude();
         //mySQL Query
         $sql = "SELECT * FROM xebura_ZIPCODES WHERE\r\n\t\t\t\t\t\tLatitude >= {$minLat}\r\n\t\t\t\t\t\tAND Latitude <= {$maxLat}\r\n\t\t\t\t\t\tAND Longitude >= {$minLong}\r\n\t\t\t\t\t\tAND Longitude <= {$maxLong}";
         //echo '<br>Final query---> '.$sql;
         $rs1 = $this->query($sql);
         $totalZipsFound = $this->getNumRows($rs1);
         $cnt = 0;
         //echo '<br>Number of rows---> '.$this->getNumRows($rs1);
         //if($this->getNumRows($rs1) > 0)
         //{
         //	$values = $this->fetchQueryArray($rs);
         //}
         $distance_radious_arr = array();
         $zcdDistance = new DistanceAssistant();
         $flag = false;
         while ($myrow = mysql_fetch_array($rs1)) {
             $Distance = $zcdDistance->Calculate($LAT, $LON, $myrow["Latitude"], $myrow["Longitude"]);
             if (empty($radiusTo)) {
                 if ($Distance <= $radious) {
                     //this ZIP Code is within $Miles of $ZIPCode
                     //Display appropriate information to the user...
                     //printf ("%s - %s<br>\n", $myrow["City"], $Distance);
                     if ($flag) {
                         $resultZipCodes .= ',';
                     }
                     $resultZipCodes .= $myrow["ZIPCode"];
                     $distance_radious_arr[$myrow["ZIPCode"]] = $Distance;
                     $flag = true;
                 }
             } else {
                 if (doubleval($Distance) >= doubleval($radious) and doubleval($Distance) <= doubleval($radiusTo)) {
                     //this ZIP Code is within $Miles of $ZIPCode
                     //Display appropriate information to the user...
                     //printf ("%s - %s<br>\n", $myrow["City"], $Distance);
                     if ($flag) {
                         $resultZipCodes .= ',';
                     }
                     $resultZipCodes .= $myrow["ZIPCode"];
                     $distance_radious_arr[$myrow["ZIPCode"]] = $Distance;
                     $flag = true;
                 }
             }
         }
         //echo '<br>resultZipCodes---> '.$resultZipCodes;
     }
     if (!empty($distance_radious_arr) and is_array($distance_radious_arr)) {
         $resultZipCodes = '';
         asort($distance_radious_arr);
         foreach ($distance_radious_arr as $key => $value) {
             $resultZipCodes .= $key . ",";
         }
     }
     /*echo '<pre>';
     		print_r($distance_radious_arr);
     		echo '</pre>';
     		echo $resultZipCodes;*/
     return trim($resultZipCodes, ',');
     //return '544';
 }
    $total_query .= "AND ( `Tags`.`Tag` = '" . implode("' OR `Tags`.`Tag` = '", $aTags) . "' ) ";
    if ($photos_only || $gallery_view) {
        $total_query .= "AND Picture = '1' ";
    }
} else {
    if ($zip) {
        $zip = process_db_input(strtoupper(str_replace(' ', '', $zip)), 1);
        $z_arr = db_arr("SELECT `Latitude`, `Longitude` FROM `ZIPCodes` WHERE REPLACE(`ZIPCode`,' ','') = '{$zip}'");
        if ($z_arr) {
            // ZIP code exists
            $miles2km = 0.7;
            // miles/kilometers ratio
            $Miles = $metric == "km" ? $distance * $miles2km : $distance;
            $Latitude = $z_arr["Latitude"];
            $Longitude = $z_arr["Longitude"];
            $zcdRadius = new RadiusAssistant($Latitude, $Longitude, $Miles);
            $minLat = $zcdRadius->MinLatitude();
            $maxLat = $zcdRadius->MaxLatitude();
            $minLong = $zcdRadius->MinLongitude();
            $maxLong = $zcdRadius->MaxLongitude();
            $total_query = "LEFT JOIN `ZIPCodes` ON UPPER( REPLACE(`Profiles`.`zip`, ' ', '') ) = REPLACE(`ZIPCodes`.`ZIPCode`,' ', '')\r\n\t\t\t\t\t\t\t\tWHERE `ZIPCodes`.`ZIPCode` IS NOT NULL AND `ZIPCodes`.`Latitude` >= {$minLat} AND `ZIPCodes`.`Latitude` <= {$maxLat} AND `ZIPCodes`.`Longitude` >= {$minLong} AND `ZIPCodes`.`Longitude` <= {$maxLong} ";
        } else {
            // ZIP code doesn't exist
            $total_query = "WHERE 0 ";
        }
    } else {
        $total_query = "WHERE 1 ";
    }
    $total_query .= "AND `Profiles`.`Status` = 'Active' ";
    if ($photos_only || $gallery_view) {
        $total_query .= "AND `Profiles`.`Picture` = '1' ";
Exemplo n.º 4
0
function PageCodeSearchResult($aParams)
{
    global $oPF;
    global $dir;
    global $tmpl;
    global $bEnZipSearch;
    $sQuery = 'SELECT DISTINCT IF( `Profiles`.`Couple`=0, `Profiles`.`ID`, IF( `Profiles`.`Couple`>`Profiles`.`ID`, `Profiles`.`ID`, `Profiles`.`Couple` ) ) AS `ID` FROM `Profiles` ';
    $sJoin = '';
    $aWhere = array();
    $aMyBlocks = $oPF->aBlocks;
    $aMyBlocks['addSpecial'] = array('Items' => array($oPF->aCache[100][0]['Items'][1], $oPF->aCache[100][0]['Items'][2], $oPF->aCache[100][0]['Items'][38]));
    //collect where request array
    foreach ($aMyBlocks as $iBlockID => $aBlock) {
        foreach ($aBlock['Items'] as $aItem) {
            if (!isset($aParams[$aItem['Name']])) {
                continue;
            }
            if ($iBlockID != 'addSpecial' and ($aItem['Name'] == 'ID' or $aItem['Name'] == 'NickName' or $aItem['Name'] == 'Tags')) {
                continue;
            }
            // skip collecting id, nick and tags for regular blocks, only in special
            $sItemName = $aItem['Name'];
            $mValue = $aParams[$sItemName];
            switch ($aItem['Type']) {
                case 'text':
                case 'area':
                    if ($sItemName == 'Tags') {
                        $sJoin .= " INNER JOIN `Tags` ON (`Tags`.`Type` = 'profile' AND `Tags`.`ID` = `Profiles`.`ID`) ";
                        $aWhere[] = "`Tags`.`Tag` = '" . addslashes($mValue) . "'";
                    } else {
                        $aWhere[] = "`Profiles`.`{$sItemName}` LIKE '%" . addslashes($mValue) . "%'";
                    }
                    break;
                case 'num':
                    $aWhere[] = "`Profiles`.`{$sItemName}` >= {$mValue[0]} AND `Profiles`.`{$sItemName}` <= {$mValue[1]}";
                    break;
                case 'date':
                    $iMin = floor($mValue[0] * 365.25);
                    //for leap years
                    $iMax = floor($mValue[1] * 365.25);
                    $aWhere[] = "DATEDIFF( NOW(), `Profiles`.`{$sItemName}` ) >= {$iMin} AND DATEDIFF( NOW(), `Profiles`.`{$sItemName}` ) <= {$iMax}";
                    //$aWhere[] = "DATE_ADD( `$sItemName`, INTERVAL {$mValue[0]} YEAR ) <= NOW() AND DATE_ADD( `$sItemName`, INTERVAL {$mValue[1]} YEAR ) >= NOW()"; //is it correct statement?
                    break;
                case 'select_one':
                    $sValue = implode(',', $mValue);
                    $aWhere[] = "FIND_IN_SET( `Profiles`.`{$sItemName}`, '" . addslashes($sValue) . "' )";
                    break;
                case 'select_set':
                    $aSet = array();
                    foreach ($mValue as $sValue) {
                        $sValue = addslashes($sValue);
                        $aSet[] = "FIND_IN_SET( '{$sValue}', `Profiles`.`{$sItemName}` )";
                    }
                    $aWhere[] = '( ' . implode(' OR ', $aSet) . ' )';
                    break;
                case 'range':
                    //impl
                    break;
                case 'bool':
                    $aWhere[] = "`Profiles`.`{$sItemName}'";
                    break;
                case 'system':
                    switch ($aItem['Name']) {
                        case 'Couple':
                            if ($mValue == '-1') {
                            } elseif ($mValue) {
                                $aWhere[] = "`Profiles`.`Couple` > `Profiles`.`ID`";
                            } else {
                                $aWhere[] = "`Profiles`.`Couple` = 0";
                            }
                            break;
                        case 'Location':
                            $aFields = explode("\n", $aItem['Extra']);
                            $aKeyw = array();
                            $sValue = addslashes($mValue);
                            foreach ($aFields as $sField) {
                                $aKeyw[] = "`Profiles`.`{$sField}` LIKE '%{$sValue}%'";
                            }
                            $aWhere[] = '( ' . implode(' OR ', $aKeyw) . ')';
                            break;
                        case 'ID':
                            $aWhere[] = "`ID` = {$mValue}";
                            break;
                    }
                    break;
            }
        }
    }
    if ($bEnZipSearch && $aParams['distance'] > 0) {
        $sZip = htmlspecialchars_adv($_REQUEST['zip']);
        $iDistance = (int) $aParams['distance'];
        $sMetric = htmlspecialchars_adv($_REQUEST['metric']);
        $zip = process_db_input(strtoupper(str_replace(' ', '', $zip)), 1);
        $aZipInfo = db_arr("SELECT `Latitude`, `Longitude` FROM `ZIPCodes` WHERE REPLACE(`ZIPCode`,' ','') = '{$sZip}'");
        //echoDbg($aZipInfo);
        if ($aZipInfo) {
            // ZIP code exists
            $miles2km = 0.7;
            // miles/kilometers ratio
            $Miles = $sMetric == "km" ? $iDistance * $miles2km : $iDistance;
            $Latitude = $aZipInfo["Latitude"];
            $Longitude = $aZipInfo["Longitude"];
            $zcdRadius = new RadiusAssistant($Latitude, $Longitude, $Miles);
            //echoDbg($zcdRadius);
            $minLat = $zcdRadius->MinLatitude();
            $maxLat = $zcdRadius->MaxLatitude();
            $minLong = $zcdRadius->MinLongitude();
            $maxLong = $zcdRadius->MaxLongitude();
            $sJoin .= " LEFT JOIN `ZIPCodes` ON UPPER( REPLACE(`Profiles`.`zip`, ' ', '') ) = REPLACE(`ZIPCodes`.`ZIPCode`,' ', '') ";
            $aWhere[] = "`ZIPCodes`.`ZIPCode` IS NOT NULL AND `ZIPCodes`.`Latitude` >= {$minLat} AND `ZIPCodes`.`Latitude` <= {$maxLat} AND `ZIPCodes`.`Longitude` >= {$minLong} AND `ZIPCodes`.`Longitude` <= {$maxLong} ";
        }
    }
    // collect query string
    $aWhere[] = "`Profiles`.`Status` = 'Active'";
    // add online only
    if ($_REQUEST['online_only']) {
        $iOnlineTime = getParam('member_online_time');
        $aWhere[] = "DATE_ADD( `DateLastNav`, INTERVAL {$iOnlineTime} MINUTE ) >= NOW()";
    }
    if ($_REQUEST['photos_only']) {
        $aWhere[] = "`Profiles`.`PrimPhoto`";
    }
    $aWhere[] = "(`Profiles`.`Couple`='0' OR `Profiles`.`Couple`>`Profiles`.`ID`)";
    $sWhere = ' WHERE ' . implode(' AND ', $aWhere);
    //collect the whole query string
    $sQuery = $sQuery . $sJoin . $sWhere;
    //echo $sQuery;
    //make search
    $rProfiles = db_res($sQuery);
    $aProfiles = array();
    while ($aProfile = mysql_fetch_assoc($rProfiles)) {
        $aProfiles[] = $aProfile['ID'];
    }
    $iCountProfiles = count($aProfiles);
    if (!$iCountProfiles) {
        echo '<div class="no_result"><div>' . _t("_NO_RESULTS") . '</div></div>';
    } else {
        //collect pagination
        $iCurrentPage = isset($_GET['page']) ? (int) $_GET['page'] : 1;
        $iResultsPerPage = isset($_GET['res_per_page']) ? (int) $_GET['res_per_page'] : 10;
        if ($iCurrentPage < 1) {
            $iCurrentPage = 1;
        }
        if ($iResultsPerPage < 1) {
            $iResultsPerPage = 10;
        }
        $iTotalPages = ceil($iCountProfiles / $iResultsPerPage);
        if ($iTotalPages > 1) {
            if ($iCurrentPage > $iTotalPages) {
                $iCurrentPage = $iTotalPages;
            }
            $aOutputProfiles = array_slice($aProfiles, ($iCurrentPage - 1) * $iResultsPerPage, $iResultsPerPage);
            $iCountOutputProfiles = count($aOutputProfiles);
            $iFromResults = ($iCurrentPage - 1) * $iResultsPerPage + 1;
            $sPagination = genSearchPagination($iTotalPages, $iCurrentPage, $iResultsPerPage);
        } else {
            $iFromResults = 1;
            $aOutputProfiles = $aProfiles;
            $iCountOutputProfiles = $iCountProfiles;
            $sPagination = '';
        }
        $iToResults = $iFromResults - 1 + $iCountOutputProfiles;
        $sShowingResults = '<div class="showingResults">' . _t('_Showing results:', $iFromResults, $iToResults, $iCountProfiles) . '</div>';
        echo $sPagination;
        echo $sShowingResults;
        //output search results
        $sTemplSearch = file_get_contents("{$dir['root']}templates/tmpl_{$tmpl}/searchrow.html");
        foreach ($aOutputProfiles as $iProfID) {
            $aProfileInfo = getProfileInfo($iProfID);
            if ($aProfileInfo['Couple'] > 0) {
                $aProfileInfoC = getProfileInfo($aProfileInfo['Couple']);
                echo PrintSearhResult($aProfileInfo, $sTemplSearch, 1, true, $aProfileInfoC);
            } else {
                echo PrintSearhResult($aProfileInfo, $sTemplSearch);
            }
        }
        echo $sShowingResults;
        echo $sPagination;
    }
}
Exemplo n.º 5
0
 function GenSqlConditions(&$aSearchBlocks, &$aRequestParams, $aFilterSortSettings = array())
 {
     $aWhere = array();
     $sJoin = '';
     $sPossibleOrder = '';
     // --- cut 1
     //collect where request array
     foreach ($aSearchBlocks as $iBlockID => $aBlock) {
         foreach ($aBlock['Items'] as $aItem) {
             if (!isset($aRequestParams[$aItem['Name']])) {
                 continue;
             }
             $sItemName = $aItem['Name'];
             $mValue = $aRequestParams[$sItemName];
             switch ($aItem['Type']) {
                 case 'text':
                 case 'area':
                     if ($sItemName == 'Tags') {
                         $sJoin .= " INNER JOIN `sys_tags` ON (`sys_tags`.`Type` = 'profile' AND `sys_tags`.`ObjID` = `Profiles`.`ID`) ";
                         $aWhere[] = "`sys_tags`.`Tag` = '" . process_db_input($mValue, BX_TAGS_STRIP) . "'";
                     } else {
                         $aWhere[] = "`Profiles`.`{$sItemName}` LIKE '%" . process_db_input($mValue, BX_TAGS_STRIP) . "%'";
                     }
                     break;
                 case 'num':
                     $mValue[0] = (int) $mValue[0];
                     $mValue[1] = (int) $mValue[1];
                     $aWhere[] = "`Profiles`.`{$sItemName}` >= {$mValue[0]} AND `Profiles`.`{$sItemName}` <= {$mValue[1]}";
                     break;
                 case 'date':
                     $iMin = floor($mValue[0] * 365.25);
                     //for leap years
                     $iMax = floor($mValue[1] * 365.25);
                     $aWhere[] = "DATEDIFF( NOW(), `Profiles`.`{$sItemName}` ) >= {$iMin} AND DATEDIFF( NOW(), `Profiles`.`{$sItemName}` ) <= {$iMax}";
                     // TODO: optimize it, move static sql part to the right part and leave db field only in the left part
                     //$aWhere[] = "DATE_ADD( `$sItemName`, INTERVAL {$mValue[0]} YEAR ) <= NOW() AND DATE_ADD( `$sItemName`, INTERVAL {$mValue[1]} YEAR ) >= NOW()"; //is it correct statement?
                     break;
                 case 'select_one':
                     if (is_array($mValue)) {
                         $sValue = implode(',', $mValue);
                         $aWhere[] = "FIND_IN_SET( `Profiles`.`{$sItemName}`, '" . process_db_input($sValue, BX_TAGS_STRIP) . "' )";
                     } else {
                         $aWhere[] = "`Profiles`.`{$sItemName}` = '" . process_db_input($mValue, BX_TAGS_STRIP) . "'";
                     }
                     break;
                 case 'select_set':
                     $aSet = array();
                     $aMyValues = is_array($mValue) ? $mValue : array($mValue);
                     foreach ($aMyValues as $sValue) {
                         $sValue = process_db_input($sValue, BX_TAGS_STRIP);
                         $aSet[] = "FIND_IN_SET( '{$sValue}', `Profiles`.`{$sItemName}` )";
                     }
                     $aWhere[] = '( ' . implode(' OR ', $aSet) . ' )';
                     break;
                 case 'range':
                     //impl
                     break;
                 case 'bool':
                     $aWhere[] = "`Profiles`.`{$sItemName}'";
                     break;
                 case 'system':
                     switch ($aItem['Name']) {
                         case 'Couple':
                             if ($mValue == '-1') {
                             } elseif ($mValue) {
                                 $aWhere[] = "`Profiles`.`Couple` > `Profiles`.`ID`";
                             } else {
                                 $aWhere[] = "`Profiles`.`Couple` = 0";
                             }
                             break;
                         case 'Keyword':
                         case 'Location':
                             $aFields = explode("\n", $aItem['Extra']);
                             $aKeyw = array();
                             $sValue = process_db_input($mValue, BX_TAGS_STRIP);
                             foreach ($aFields as $sField) {
                                 $aKeyw[] = "`Profiles`.`{$sField}` LIKE '%{$sValue}%'";
                             }
                             $aWhere[] = '( ' . implode(' OR ', $aKeyw) . ')';
                             break;
                         case 'ID':
                             $aWhere[] = "`ID` = {$mValue}";
                             break;
                     }
                     break;
             }
         }
     }
     // --- cut 2
     $bEnZipSearch = getParam("enable_zip_loc") == "on" ? 1 : 0;
     if ($bEnZipSearch) {
         require_once BX_DIRECTORY_PATH_INC . 'RadiusAssistant.inc.php';
     }
     if ($bEnZipSearch && $aRequestParams['distance'] > 0) {
         $sZip = process_db_input($_REQUEST['zip'], BX_TAGS_STRIP);
         $iDistance = (int) $aRequestParams['distance'];
         $sMetric = htmlspecialchars_adv($_REQUEST['metric'], BX_TAGS_STRIP);
         $zip = process_db_input(strtoupper(str_replace(' ', '', $zip)), BX_TAGS_STRIP);
         $aZipInfo = db_arr("SELECT `Latitude`, `Longitude` FROM `sys_zip_codes` WHERE REPLACE(`ZIPCode`,' ','') = '{$sZip}'");
         //echoDbg($aZipInfo);
         if ($aZipInfo) {
             // ZIP code exists
             $miles2km = 0.7;
             // miles/kilometers ratio
             $Miles = $sMetric == "km" ? $iDistance * $miles2km : $iDistance;
             $Latitude = $aZipInfo["Latitude"];
             $Longitude = $aZipInfo["Longitude"];
             $zcdRadius = new RadiusAssistant($Latitude, $Longitude, $Miles);
             //echoDbg($zcdRadius);
             $minLat = $zcdRadius->MinLatitude();
             $maxLat = $zcdRadius->MaxLatitude();
             $minLong = $zcdRadius->MinLongitude();
             $maxLong = $zcdRadius->MaxLongitude();
             $sJoin .= " LEFT JOIN `sys_zip_codes` ON UPPER( REPLACE(`Profiles`.`zip`, ' ', '') ) = REPLACE(`sys_zip_codes`.`ZIPCode`,' ', '') ";
             $aWhere[] = "`sys_zip_codes`.`ZIPCode` IS NOT NULL AND `sys_zip_codes`.`Latitude` >= {$minLat} AND `sys_zip_codes`.`Latitude` <= {$maxLat} AND `sys_zip_codes`.`Longitude` >= {$minLong} AND `sys_zip_codes`.`Longitude` <= {$maxLong} ";
         }
     }
     // --- cut 3
     // collect query string
     $aWhere[] = "`Profiles`.`Status` = 'Active'";
     // add online only
     if ($_REQUEST['online_only']) {
         $iOnlineTime = getParam('member_online_time');
         $aWhere[] = "`DateLastNav` >= DATE_SUB(NOW(), INTERVAL {$iOnlineTime} MINUTE)";
     }
     // --- cut 4
     $sPossibleOrder = '';
     switch ($_REQUEST['show']) {
         case 'featured':
             $aWhere[] = "`Profiles`.`Featured` = '1'";
             break;
         case 'birthdays':
             $aWhere[] = "MONTH(`DateOfBirth`) = MONTH(CURDATE()) AND DAY(`DateOfBirth`) = DAY(CURDATE())";
             break;
         case 'top_rated':
             $sPossibleOrder = ' ORDER BY `Profiles`.`Rate` DESC';
             break;
         case 'popular':
             $sPossibleOrder = ' ORDER BY `Profiles`.`Views` DESC';
             break;
         case 'moderators':
             $sJoin .= " INNER JOIN `" . DB_PREFIX . "ChatProfiles` ON `Profiles`.`ID`= `" . DB_PREFIX . "ChatProfiles`.`ID` ";
             $aWhere[] = "`" . DB_PREFIX . "ChatProfiles`.`Type`='moder'";
             break;
     }
     switch ($aFilterSortSettings['sort']) {
         case 'activity':
             $sPossibleOrder = ' ORDER BY `Profiles`.`DateLastNav` DESC';
             break;
         case 'date_reg':
             $sPossibleOrder = ' ORDER BY `Profiles`.`DateReg` DESC';
             break;
         default:
             break;
     }
     // --- cut 5
     if ($_REQUEST['photos_only']) {
         $aWhere[] = "`Profiles`.`Avatar`";
     }
     $aWhere[] = "(`Profiles`.`Couple`='0' OR `Profiles`.`Couple`>`Profiles`.`ID`)";
     return array($aWhere, $sJoin, $sPossibleOrder);
 }