collectSearchRequestParams(); if( isset( $_REQUEST['ID'] ) and (int)$_REQUEST['ID'] ) $aRequestParams['ID'] = (int)$_REQUEST['ID']; if( isset( $_REQUEST['NickName'] ) and trim( $_REQUEST['NickName'] ) ) $aRequestParams['NickName'] = trim( process_pass_data( $_REQUEST['NickName'] ) ); if( isset( $_REQUEST['Tags'] ) and trim( $_REQUEST['Tags'] ) ) $aRequestParams['Tags'] = trim( process_pass_data( $_REQUEST['Tags'] ) ); if( isset( $_REQUEST['distance'] ) and (int)$_REQUEST['distance'] ) $aRequestParams['distance'] = (int)$_REQUEST['distance']; // start page generation ob_start(); $bShowForms = false; //echoDbg($aRequestParams); if( !empty( $aRequestParams ) or $_REQUEST['online_only'] ) PageCodeSearchResult( $aRequestParams ); else { PageCodeSearchForm(); $bShowForms = true; } $_ni = $_page['name_index']; $_page_cont[$_ni]['page_main_code'] = ob_get_clean(); $_page_cont[$_ni]['search_by_id'] = $bShowForms ? PageCodeSearchByID() : ''; $_page_cont[$_ni]['search_by_nick'] = $bShowForms ? PageCodeSearchByNick() : ''; $_page_cont[$_ni]['search_by_tag'] = $bShowForms ? PageCodeSearchByTag() : ''; PageCode(); function PageCodeSearchForm() { global $oPF; global $sPageHeader; global $sSearchMode; ob_start(); ?>
aBlocks as $aBlock ) { ?>
: $sValue ) { ?>
 {$sLivingWithinC}   {$sFromZipC} 
EOF; echo $sRet; break; } break; } ?>



`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], //add id $oPF -> aCache[100][0]['Items'][2], //add nickname $oPF -> aCache[100][0]['Items'][38] //add tags ) ); //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 'Keyword': 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 '
' . _t("_NO_RESULTS") . '
'; } 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 = '
' . _t( '_Showing results:', $iFromResults, $iToResults, $iCountProfiles ) . '
'; echo $sPagination; echo $sShowingResults; //output search results $sTemplSearch = file_get_contents( BX_DIRECTORY_PATH_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; } } function genSearchPagination( $iTotalPages, $iCurrentPage, $iResultsPerPage ) { $aGetParams = $_GET; unset( $aGetParams['page'] ); unset( $aGetParams['res_per_page'] ); $sRequestString = collectRequestString( $aGetParams ); $sRequestString = $_SERVER['PHP_SELF'] . '?' . substr( $sRequestString, 1 ); $sPaginTmpl = $sRequestString . '&res_per_page=' . $iResultsPerPage . '&page={page}'; $sResPerPageTmpl = $sRequestString . '&res_per_page={res_per_page}'; $sPagination = genResPerPage( array(10,20,50,100), $iResultsPerPage, $sResPerPageTmpl ); $sPagination .= genPagination( $iTotalPages, $iCurrentPage, $sPaginTmpl ); return $sPagination; } function collectRequestString( $aGetParams, $sKeyPref = '', $sKeyPostf = '' ) { if( !is_array( $aGetParams ) ) return ''; $sRet = ''; foreach( $aGetParams as $sKey => $sValue ) { if( $sValue === '' ) continue; if( !is_array($sValue) ) { $sRet .= '&' . urlencode( $sKeyPref . $sKey . $sKeyPostf ) . '=' . urlencode( process_pass_data( $sValue ) ); } else { $sRet .= collectRequestString( $sValue, "{$sKeyPref}{$sKey}{$sKeyPostf}[", "]" ); //recursive call } } return $sRet; }