00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00023 class Search
00024 {
00025 var $oDB;
00026 var $oUser;
00027
00032 function Search ( &$oDB, &$oUser )
00033 {
00034 $this->oDB =& $oDB;
00035 $this->oUser =& $oUser;
00036 }
00037
00038 function doSearch ( $strName = '', $strGuild = '', $intGuild = 0, $intX = 0, $intY = 0, $intRadius = 0, $strOrder = '' )
00039 {
00040
00041 switch ( $strOrder )
00042 {
00043 case 'position':
00044 $strOrderBy = '`x`, `y`';
00045 break;
00046 case 'guild':
00047 $strOrderBy = 'g.`tag`, p.name';
00048 break;
00049 case 'town':
00050 $strOrderBy = 't.name';
00051 break;
00052 default:
00053 $strOrderBy = 'p.`name`';
00054 }
00055
00056
00057 $strFilter = '';
00058 if ( $strName != '' )
00059 {
00060 $strFilter .= " AND UPPER(`p`.`name`) LIKE UPPER('%$strName%')";
00061 }
00062
00063 if ( $strGuild != '' )
00064 {
00065 $strFilter .= " AND UPPER(`g`.`tag`) LIKE UPPER('%$strGuild%')";
00066 }
00067
00068 if ( $intX > 0 )
00069 {
00070 $strFilter .= " AND t.`x` BETWEEN ".($intX-$intRadius)." AND ".($intX+$intRadius);
00071 }
00072
00073 if ( $intY > 0 )
00074 {
00075 $strFilter .= " AND t.`y` BETWEEN ".($intY-$intRadius)." AND ".($intY+$intRadius);
00076 }
00077
00078 if ( $intGuild > 0 && $strFilter == '' )
00079 {
00080 $strFilter = ' AND `p`.`guild_id`='.$intGuild;
00081 }
00082
00083 if ( $this->oUser->intLimitView > 0 )
00084 {
00085
00086 $strFilter .= ' AND t.x BETWEEN '.( $this->oUser->intHomeX - $this->oUser->intLimitView).' AND '.($this->oUser->intHomeX + $this->oUser->intLimitView);
00087 $strFilter .= ' AND t.y BETWEEN '.( $this->oUser->intHomeY - $this->oUser->intLimitView).' AND '.($this->oUser->intHomeY + $this->oUser->intLimitView);
00088 }
00089
00090 $sqlResult = $this->oDB->query("SELECT p.`name`, t.`name` AS `townname`, g.`tag` AS `guild_tag`, t.`x`, t.`y`, p.`guild_id`, m.building ".
00091 "FROM `".$this->oDB->tblTown."` t ".
00092 "LEFT JOIN `".$this->oDB->tblMapData."` m ON (t.x=m.x AND t.y=m.y) ".
00093 "LEFT JOIN `".$this->oDB->tblPlayer."` p ON (t.`player_id`=p.`player_id`) ".
00094 "LEFT JOIN `".$this->oDB->tblGuild."` g ON (p.`guild_id`=g.`guild_id`) ".
00095 "WHERE t.`town_id`>0 AND m.`building` > '-10' ".$strFilter." ".
00096 "ORDER BY $strOrderBy;");
00097
00098 $aResult = array();
00099 while ( $aRow = $this->oDB->fetch_assoc ($sqlResult) )
00100 {
00101 if ( !isset ( $aRow['guild_tag'] ) ) $aRow['guild_tag'] = '';
00102 if ( !isset ( $aRow['guild_id'] ) ) $aRow['guild_id'] = 0;
00103 $aRow['prefix'] = ( $aRow['building'] == -2 ) ? '~' : '';
00104 $aResult[] = $aRow;
00105 }
00106 return $aResult;
00107 }
00108 }