00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00028 class TownInfo
00029 {
00030 var $oDB;
00031 var $oLog;
00032
00039 function TownInfo( &$oDB, &$oLog )
00040 {
00041 $this->oDB =& $oDB;
00042 $this->oLog =& $oLog;
00043 }
00044
00057 function add( $x, $y, $strName='', $intPlayer=1, $strInfos='', $intTownhall=0, $intSight=0 )
00058 {
00059 $this->oDB->query( "INSERT INTO `".$this->oDB->tblTown."` SET `x`='$x', `y`='$y', `name`='$strName', `player_id`='$intPlayer', `townhall`='$intTownhall', `sight`='$intSight', `infos`='$strInfos'".$GLOBALS['strUpdateString'].$GLOBALS['strCreatedString'].";" );
00060 return $this->oDB->insert_id();
00061 }
00062
00070 function get( $x, $y )
00071 {
00072 $sqlResult = $this->oDB->query( "SELECT town_id, name, last_update FROM ".$this->oDB->tblTown." WHERE x='$x' AND y='$y';" );
00073 if( $this->oDB->num_rows( $sqlResult ) != 1 )
00074 {
00075 return false;
00076 }
00077 return $this->oDB->fetch_assoc( $sqlResult );
00078 }
00079
00085 function getById( $intTownId = 0 )
00086 {
00087 $aInfo = $this->oDB->query_first("SELECT `t`.*, `p`.`name` AS `owner`, `p`.`player_id` AS `ownerid`, `u`.`name` AS username, `u2`.`name` AS username2
00088 FROM `".$this->oDB->tblTown."` t
00089 LEFT JOIN `".$this->oDB->tblPlayer."` p ON (`t`.`player_id`=`p`.`player_id`)
00090 LEFT JOIN `".$this->oDB->tblUser."` u ON (`t`.`last_update_by`=`u`.`user_id`)
00091 LEFT JOIN `".$this->oDB->tblUser."` u2 ON (`t`.`created_by`=`u2`.`user_id`)
00092 WHERE `t`.`town_id`='$intTownId';");
00093
00094 if ( $aInfo['town_id'] != $intTownId )
00095 {
00096 return false;
00097 }
00098 return $aInfo;
00099 }
00100
00108 function getTowns( $intPlayerId, $intNoTown = 0 )
00109 {
00110 $aResult = array();
00111 $this->oDB->query("SELECT `name`, `town_id`, `t`.`x`, `t`.`y` FROM `".$this->oDB->tblTown."` t LEFT JOIN `".$this->oDB->tblMapData."` m USING (x,y) WHERE m.`building` > '-10' AND `player_id`='$intPlayerId' AND `town_id`!='$intNoTown';");
00112 while ( $aRow = $this->oDB->fetch_assoc() )
00113 {
00114 $aResult[] = $aRow;
00115 }
00116 return $aResult;
00117 }
00118
00130 function set( $intTownId, $strName, $intPlayer=-1, $intSight=-1, $intTownhall=-1, $strInfos=-1, $booPrepend = false )
00131 {
00132 $strQuery = "UPDATE `".$this->oDB->tblTown."` SET `name`='$strName'";
00133 if( $intPlayer !== -1 )
00134 {
00135 $strQuery .= ", `player_id`='$intPlayer'";
00136 }
00137 if( $intSight !== -1 )
00138 {
00139 $strQuery .= ", `sight`='$intSight'";
00140 }
00141 if( $intTownhall !== -1 )
00142 {
00143 $strQuery .= ", `townhall`='$intTownhall'";
00144 }
00145 if( $strInfos !== -1 )
00146 {
00147 $strQuery .= ($booPrepend) ? ", infos=CONCAT('$strInfos', `infos`)" : ", infos='$strInfos'";
00148 }
00149
00150 $strQuery .= $GLOBALS['strUpdateString']." WHERE `town_id`='$intTownId' LIMIT 1;";
00151 $this->oDB->query( $strQuery );
00152 $this->oLog->write( "Stadtinfo gesichert für: " . $strName . " (id=" . $intTownId. ")", 5);
00153 }
00154
00162 function delete( $intTown, $x, $y )
00163 {
00164 $this->oDB->query( "DELETE FROM `".$this->oDB->tblTown."` WHERE `town_id`='".$intTown."';" );
00165 $this->oDB->query("UPDATE `".$this->oDB->tblMapData."` SET `building`=NULL".$GLOBALS['strUpdateString']." WHERE `x`='$x' AND `y`='$y';" );
00166 }
00167 }