mirror of
https://github.com/Znote/ZnoteAAC.git
synced 2025-04-30 11:19:22 +02:00
Merge pull request #52 from Kuzirashi/master
Added sorting to Houses. Fixed bugs.
This commit is contained in:
commit
cb1c7546ef
14
house.php
14
house.php
@ -14,9 +14,9 @@ if ($house !== false && $config['TFSVersion'] === 'TFS_10') {
|
|||||||
|
|
||||||
//////////////////////
|
//////////////////////
|
||||||
// Bid on house logic
|
// Bid on house logic
|
||||||
$bid_char = getValue($_POST['char']);
|
$bid_char = &$_POST['char'];
|
||||||
$bid_amount = getValue($_POST['amount']);
|
$bid_amount = &$_POST['amount'];
|
||||||
if ($bid_amount !== false && $bid_char !== false) {
|
if ($bid_amount && $bid_char) {
|
||||||
$bid_char = (int)$bid_char;
|
$bid_char = (int)$bid_char;
|
||||||
$bid_amount = (int)$bid_amount;
|
$bid_amount = (int)$bid_amount;
|
||||||
$player = mysql_select_single("SELECT `id`, `account_id`, `name`, `level`, `balance` FROM `players` WHERE `id`='$bid_char' LIMIT 1;");
|
$player = mysql_select_single("SELECT `id`, `account_id`, `name`, `level`, `balance` FROM `players` WHERE `id`='$bid_char' LIMIT 1;");
|
||||||
@ -86,10 +86,14 @@ if ($house !== false && $config['TFSVersion'] === 'TFS_10') {
|
|||||||
?>
|
?>
|
||||||
<h1>House: <?php echo $house['name']; ?></h1>
|
<h1>House: <?php echo $house['name']; ?></h1>
|
||||||
<ul>
|
<ul>
|
||||||
<li><b>Town</b>: <?php echo "<a href='houses.php?id=". $house['town_id'] ."'>". $config['towns'][$house['town_id']] ."</a>"; ?></li>
|
<li><b>Town</b>:
|
||||||
|
<?php
|
||||||
|
$town_name = &$config['towns'][$house['town_id']];
|
||||||
|
echo "<a href='houses.php?id=". $house['town_id'] ."'>". ($town_name ? $town_name : 'Specify town id ' . $house['town_id'] . ' name in config.php first.') ."</a>";
|
||||||
|
?></li>
|
||||||
<li><b>Size</b>: <?php echo $house['size']; ?></li>
|
<li><b>Size</b>: <?php echo $house['size']; ?></li>
|
||||||
<li><b>Beds</b>: <?php echo $house['beds']; ?></li>
|
<li><b>Beds</b>: <?php echo $house['beds']; ?></li>
|
||||||
<li><b>owner</b>: <?php
|
<li><b>Owner</b>: <?php
|
||||||
if ($house['owner'] > 0) echo "<a href='characterprofile.php?name=". $house['ownername'] ."' target='_BLANK'>". $house['ownername'] ."</a>";
|
if ($house['owner'] > 0) echo "<a href='characterprofile.php?name=". $house['ownername'] ."' target='_BLANK'>". $house['ownername'] ."</a>";
|
||||||
else echo "Available for auction.";
|
else echo "Available for auction.";
|
||||||
?></li>
|
?></li>
|
||||||
|
118
houses.php
118
houses.php
@ -1,10 +1,11 @@
|
|||||||
<?php require_once 'engine/init.php'; include 'layout/overall/header.php';
|
<?php
|
||||||
if ($config['log_ip']) {
|
require_once 'engine/init.php';
|
||||||
znote_visitor_insert_detailed_data(3);
|
include 'layout/overall/header.php';
|
||||||
}
|
|
||||||
if (empty($_POST) === false && $config['TFSVersion'] === 'TFS_03') {
|
|
||||||
|
|
||||||
#if ($_POST['token'] == $_SESSION['token']) {
|
if ($config['log_ip'])
|
||||||
|
znote_visitor_insert_detailed_data(3);
|
||||||
|
|
||||||
|
if (empty($_POST) === false && $config['TFSVersion'] === 'TFS_03') {
|
||||||
|
|
||||||
/* Token used for cross site scripting security */
|
/* Token used for cross site scripting security */
|
||||||
if (isset($_POST['token']) && Token::isValid($_POST['token'])) {
|
if (isset($_POST['token']) && Token::isValid($_POST['token'])) {
|
||||||
@ -47,20 +48,19 @@ if (empty($_POST) === false && $config['TFSVersion'] === 'TFS_03') {
|
|||||||
</tr>
|
</tr>
|
||||||
<?php
|
<?php
|
||||||
foreach ($array as $value) {
|
foreach ($array as $value) {
|
||||||
// start foreach
|
|
||||||
echo '<tr>';
|
echo '<tr>';
|
||||||
echo "<td>". $value['name'] ."</td>";
|
echo "<td>". $value['name'] ."</td>";
|
||||||
echo "<td>". $value['size'] ."</td>";
|
echo "<td>". $value['size'] ."</td>";
|
||||||
echo "<td>". $value['doors'] ."</td>";
|
echo "<td>". $value['doors'] ."</td>";
|
||||||
echo "<td>". $value['beds'] ."</td>";
|
echo "<td>". $value['beds'] ."</td>";
|
||||||
echo "<td>". $value['price'] ."</td>";
|
echo "<td>". $value['price'] ."</td>";
|
||||||
if ($value['owner'] == 0) echo "<td>None</td>";
|
if ($value['owner'] == 0)
|
||||||
|
echo "<td>None</td>";
|
||||||
else {
|
else {
|
||||||
$data = user_character_data($value['owner'], 'name');
|
$data = user_character_data($value['owner'], 'name');
|
||||||
echo '<td><a href="characterprofile.php?name='. $data['name'] .'">'. $data['name'] .'</a></td>';
|
echo '<td><a href="characterprofile.php?name='. $data['name'] .'">'. $data['name'] .'</a></td>';
|
||||||
}
|
}
|
||||||
echo '</tr>';
|
echo '</tr>';
|
||||||
// end foreach
|
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
</table>
|
</table>
|
||||||
@ -76,8 +76,10 @@ if (empty($_POST) === false && $config['TFSVersion'] === 'TFS_03') {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (empty($_POST) === true && $config['TFSVersion'] === 'TFS_03') {
|
if (empty($_POST) === true && $config['TFSVersion'] === 'TFS_03') {
|
||||||
if ($config['allowSubPages']) header('Location: sub.php?page=houses');
|
if ($config['allowSubPages'])
|
||||||
else echo 'Sub page system disabled.';
|
header('Location: sub.php?page=houses');
|
||||||
|
else
|
||||||
|
echo 'Sub page system disabled.';
|
||||||
} else if ($config['TFSVersion'] === 'TFS_02') {
|
} else if ($config['TFSVersion'] === 'TFS_02') {
|
||||||
$house = $config['house'];
|
$house = $config['house'];
|
||||||
if (!is_file($house['house_file'])) {
|
if (!is_file($house['house_file'])) {
|
||||||
@ -92,9 +94,8 @@ if (empty($_POST) === false && $config['TFSVersion'] === 'TFS_03') {
|
|||||||
|
|
||||||
$cache->setContent($house_query);
|
$cache->setContent($house_query);
|
||||||
$cache->save();
|
$cache->save();
|
||||||
} else {
|
} else
|
||||||
$house_query = $cache->load();
|
$house_query = $cache->load();
|
||||||
}
|
|
||||||
|
|
||||||
$sqmPrice = $house['price_sqm'];
|
$sqmPrice = $house['price_sqm'];
|
||||||
$house_load = simplexml_load_file($house['house_file']);
|
$house_load = simplexml_load_file($house['house_file']);
|
||||||
@ -106,14 +107,15 @@ if (empty($_POST) === false && $config['TFSVersion'] === 'TFS_03') {
|
|||||||
<td><b>House</b></td>
|
<td><b>House</b></td>
|
||||||
<td><b>Location</b></td>
|
<td><b>Location</b></td>
|
||||||
<td><b>Owner</b></td>
|
<td><b>Owner</b></td>
|
||||||
<td><b>Size</b></td><td><b>Rent</b></td>
|
<td><b>Size</b></td>
|
||||||
|
<td><b>Rent</b></td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|
||||||
<?php
|
<?php
|
||||||
//execute code.
|
//execute code.
|
||||||
foreach($house_query as $row) {
|
foreach($house_query as $row)
|
||||||
$house_info[(int)$row['id']] = '<a href="characterprofile.php?name='. $row['name'] .'">'. $row['name'] .'</a>';
|
$house_info[(int)$row['id']] = '<a href="characterprofile.php?name='. $row['name'] .'">'. $row['name'] .'</a>';
|
||||||
}
|
|
||||||
foreach ($house_load as $house_fetch){
|
foreach ($house_load as $house_fetch){
|
||||||
$house_price = (int)$house_fetch['size'] * $sqmPrice;
|
$house_price = (int)$house_fetch['size'] * $sqmPrice;
|
||||||
?>
|
?>
|
||||||
@ -142,52 +144,80 @@ if (empty($_POST) === false && $config['TFSVersion'] === 'TFS_03') {
|
|||||||
} else echo '<p><font color="red">Something is wrong with the cache.</font></p>';
|
} else echo '<p><font color="red">Something is wrong with the cache.</font></p>';
|
||||||
} else if ($config['TFSVersion'] === 'TFS_10') {
|
} else if ($config['TFSVersion'] === 'TFS_10') {
|
||||||
// Fetch values
|
// Fetch values
|
||||||
$townid = (getValue($_GET['id']) !== false) ? (int)$_GET['id'] : $config['houseConfig']['HouseListDefaultTown'];
|
$querystring_id = &$_GET['id'];
|
||||||
|
$townid = ($querystring_id) ? (int)$_GET['id'] : $config['houseConfig']['HouseListDefaultTown'];
|
||||||
$towns = $config['towns'];
|
$towns = $config['towns'];
|
||||||
|
|
||||||
|
$order = &$_GET['order'];
|
||||||
|
$type = &$_GET['type'];
|
||||||
|
|
||||||
// Create Search house box
|
// Create Search house box
|
||||||
?>
|
?>
|
||||||
<form action="" method="get">
|
<form action="" method="get" style="width: 648px">
|
||||||
<b>Select town:</b>
|
<b>Select town:</b>
|
||||||
<select name="id">
|
<select name="id">
|
||||||
<?php
|
<?php
|
||||||
foreach ($towns as $id => $name) {
|
foreach ($towns as $id => $name)
|
||||||
if ($id != $townid) echo '<option value="'. $id .'">'. $name .'</option>';
|
echo '<option value="'. $id .'"' . ($townid != $id ?: ' selected') . '>'. $name .'</option>';
|
||||||
else echo '<option value="'. $id .'" selected>'. $name .'</option>';
|
|
||||||
}
|
|
||||||
?>
|
?>
|
||||||
</select>
|
</select>
|
||||||
<input type="submit" value="Fetch houses">
|
<b style="padding-left: 8px;">Order:</b>
|
||||||
|
<select name="order">
|
||||||
|
<?php
|
||||||
|
$order_allowed = array('id', 'name', 'size', 'beds', 'rent', 'owner');
|
||||||
|
foreach($order_allowed as $o)
|
||||||
|
echo '<option value="' . $o . '"' . ($o != $order ?: ' selected') . '>' . ucfirst($o) . '</option>';
|
||||||
|
?>
|
||||||
|
</select>
|
||||||
|
<select name="type">
|
||||||
|
<?php
|
||||||
|
$type_allowed = array('desc', 'asc');
|
||||||
|
foreach($type_allowed as $t)
|
||||||
|
echo '<option value="' . $t . '"' . ($t != $type ?: ' selected') . '>' . ($t == 'desc' ? 'Descending' : 'Ascending') .'</option>';
|
||||||
|
?>
|
||||||
|
</select>
|
||||||
|
<input type="submit" value="Fetch houses" style="margin-left: 8px;"/>
|
||||||
</form>
|
</form>
|
||||||
<?php
|
<?php
|
||||||
|
if(!in_array($order, $order_allowed))
|
||||||
|
$order = 'id';
|
||||||
|
|
||||||
|
if(!in_array($type, $type_allowed))
|
||||||
|
$type = 'desc';
|
||||||
|
|
||||||
// Create or fetch data from cache
|
// Create or fetch data from cache
|
||||||
$cache = new Cache('engine/cache/houses');
|
$cache = new Cache('engine/cache/houses/houses-' . $order . '-' . $type);
|
||||||
$houses = array();
|
$houses = array();
|
||||||
if ($cache->hasExpired()) {
|
if ($cache->hasExpired()) {
|
||||||
$houses = mysql_select_multi("SELECT `id`, `owner`, `paid`, `warnings`, `name`, `rent`, `town_id`, `size`, `beds`, `bid`, `bid_end`, `last_bid`, `highest_bidder` FROM `houses`;");
|
$houses = mysql_select_multi("SELECT `id`, `owner`, `paid`, `warnings`, `name`, `rent`, `town_id`, `size`, `beds`, `bid`, `bid_end`, `last_bid`, `highest_bidder` FROM `houses` ORDER BY {$order} {$type};");
|
||||||
|
|
||||||
if ($houses !== false) {
|
if ($houses !== false) {
|
||||||
// Fetch player names
|
// Fetch player names
|
||||||
$playerlist = array();
|
$playerlist = array();
|
||||||
foreach ($houses as $h) if ($h['owner'] > 0) $playerlist[] = $h['owner'];
|
|
||||||
|
foreach ($houses as $h)
|
||||||
|
if ($h['owner'] > 0)
|
||||||
|
$playerlist[] = $h['owner'];
|
||||||
|
|
||||||
if (!empty($playerlist)) {
|
if (!empty($playerlist)) {
|
||||||
$ids = join(',',$playerlist);
|
$ids = join(',', $playerlist);
|
||||||
$tmpPlayers = mysql_select_multi("SELECT `id`, `name` FROM players WHERE `id` IN ($ids);");
|
$tmpPlayers = mysql_select_multi("SELECT `id`, `name` FROM players WHERE `id` IN ($ids);");
|
||||||
|
|
||||||
// Sort $tmpPlayers by player id
|
// Sort $tmpPlayers by player id
|
||||||
$tmpById = array();
|
$tmpById = array();
|
||||||
foreach ($tmpPlayers as $p) $tmpById[$p['id']] = $p['name'];
|
foreach ($tmpPlayers as $p)
|
||||||
for ($i = 0; $i < count($houses); $i++) {
|
$tmpById[$p['id']] = $p['name'];
|
||||||
if ($houses[$i]['owner'] > 0) $houses[$i]['ownername'] = $tmpById[$houses[$i]['owner']];
|
|
||||||
}
|
for ($i = 0; $i < count($houses); $i++)
|
||||||
|
if ($houses[$i]['owner'] > 0)
|
||||||
|
$houses[$i]['ownername'] = $tmpById[$houses[$i]['owner']];
|
||||||
}
|
}
|
||||||
|
|
||||||
$cache->setContent($houses);
|
$cache->setContent($houses);
|
||||||
$cache->save();
|
$cache->save();
|
||||||
}
|
}
|
||||||
} else {
|
} else
|
||||||
$houses = $cache->load();
|
$houses = $cache->load();
|
||||||
}
|
|
||||||
if ($houses !== false || !empty($houses)) {
|
if ($houses !== false || !empty($houses)) {
|
||||||
// Intialize stuff
|
// Intialize stuff
|
||||||
//data_dump($houses, false, "House data");
|
//data_dump($houses, false, "House data");
|
||||||
@ -212,25 +242,25 @@ if (empty($_POST) === false && $config['TFSVersion'] === 'TFS_03') {
|
|||||||
<td><?php echo $house['rent']; ?></td>
|
<td><?php echo $house['rent']; ?></td>
|
||||||
<?php
|
<?php
|
||||||
// Status:
|
// Status:
|
||||||
if ($house['owner'] != 0) {
|
if ($house['owner'] != 0)
|
||||||
echo "<td><a href='characterprofile.php?name=". $house['ownername'] ."' target='_BLANK'>". $house['ownername'] ."</a></td>";
|
echo "<td><a href='characterprofile.php?name=". $house['ownername'] ."' target='_BLANK'>". $house['ownername'] ."</a></td>";
|
||||||
} else {
|
else
|
||||||
if ($house['highest_bidder'] == 0) {
|
echo ($house['highest_bidder'] == 0 ? '<td>None</td>' : '<td><b>Selling</b></td>');
|
||||||
echo "<td>None</td>";
|
|
||||||
} else {
|
|
||||||
echo "<td><b>Selling</b></td>";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
?>
|
?>
|
||||||
<td><?php echo $towns[$house['town_id']]; ?></td>
|
<td><?php
|
||||||
|
$town_name = &$towns[$house['town_id']];
|
||||||
|
echo ($town_name ? $town_name : 'Specify town id ' . $house['town_id'] . ' name in config.php first.');
|
||||||
|
?></td>
|
||||||
</tr>
|
</tr>
|
||||||
<?php
|
<?php
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
<?php
|
<?php
|
||||||
} else echo "<h1>Failed to fetch data from sql->houses table.</h1><p>Is the table empty?</p>";
|
} else
|
||||||
|
echo "<h1>Failed to fetch data from sql->houses table.</h1><p>Is the table empty?</p>";
|
||||||
} // End TFS 1.0 logic
|
} // End TFS 1.0 logic
|
||||||
}
|
}
|
||||||
include 'layout/overall/footer.php'; ?>
|
include 'layout/overall/footer.php'; ?>
|
Loading…
x
Reference in New Issue
Block a user