forked from Znote/ZnoteAAC
-
Notifications
You must be signed in to change notification settings - Fork 0
/
houses.php
266 lines (243 loc) · 8.01 KB
/
houses.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
<?php
require_once 'engine/init.php';
include 'layout/overall/header.php';
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 */
if (isset($_POST['token']) && Token::isValid($_POST['token'])) {
$townid = (int)$_POST['selected'];
$cache = new Cache('engine/cache/houses');
$array = array();
if ($cache->hasExpired()) {
$tmp = fetchAllHouses_03();
$cache->setContent($tmp);
$cache->save();
foreach ($tmp as $t) {
if ($t['town'] == $townid) $array[] = $t;
}
$array = isset($array) ? $array : false;
} else {
$tmp = $cache->load();
foreach ($tmp as $t) {
if ($t['town'] == $townid) $array[] = $t;
}
$array = isset($array) ? $array : false;
}
// Design and present the list
if ($array) {
?>
<h2>
<?php echo ucfirst(town_id_to_name($townid)); ?> house list.
</h2>
<table id="housesTable" class="table table-striped">
<tr class="yellow">
<th>Name:</th>
<th>Size:</th>
<th>Doors:</th>
<th>Beds:</th>
<th>Price:</th>
<th>Owner:</th>
</tr>
<?php
foreach ($array as $value) {
echo '<tr>';
echo "<td>". $value['name'] ."</td>";
echo "<td>". $value['size'] ."</td>";
echo "<td>". $value['doors'] ."</td>";
echo "<td>". $value['beds'] ."</td>";
echo "<td>". $value['price'] ."</td>";
if ($value['owner'] == 0)
echo "<td>None</td>";
else {
$data = user_character_data($value['owner'], 'name');
echo '<td><a href="characterprofile.php?name='. $data['name'] .'">'. $data['name'] .'</a></td>';
}
echo '</tr>';
}
?>
</table>
<?php
} else {
echo 'Empty list, it appears no houses are listed in this town.';
}
//Done.
} else {
echo 'Token appears to be incorrect.<br><br>';
//Token::debug($_POST['token']);
echo 'Please clear your web cache/cookies <b>OR</b> use another web browser<br>';
}
} else {
if (empty($_POST) === true && $config['TFSVersion'] === 'TFS_03') {
if ($config['allowSubPages'])
header('Location: sub.php?page=houses');
else
echo 'Sub page system disabled.';
} else if ($config['TFSVersion'] === 'TFS_02') {
$house = $config['house'];
if (!is_file($house['house_file'])) {
echo("<h3>House file not found</h3><p>FAILED TO LOCATE/READ FILE AT:<br><font color='red'>". $house['house_file'] ."</font><br><br>LINUX users: Make sure www-data have read access to file.<br>WINDOWS users: Learn to write correct file path.</p>");
exit();
}
// Load and cache SQL house data:
$cache = new Cache('engine/cache/houses/sqldata');
if ($cache->hasExpired()) {
$house_query = mysql_select_multi('SELECT `players`.`name`, `houses`.`id` FROM `players`, `houses` WHERE `houses`.`owner` = `players`.`id`;');
$cache->setContent($house_query);
$cache->save();
} else
$house_query = $cache->load();
$sqmPrice = $house['price_sqm'];
$house_load = simplexml_load_file($house['house_file']);
if ($house_query !== false && $house_load !== false) {
?>
<h2>House list</h2>
<table>
<tr class="yellow">
<td><b>House</b></td>
<td><b>Location</b></td>
<td><b>Owner</b></td>
<td><b>Size</b></td>
<td><b>Rent</b></td>
</tr>
<?php
//execute code.
foreach($house_query as $row)
$house_info[(int)$row['id']] = '<a href="characterprofile.php?name='. $row['name'] .'">'. $row['name'] .'</a>';
foreach ($house_load as $house_fetch){
$house_price = (int)$house_fetch['size'] * $sqmPrice;
?>
<tr>
<td><?php echo htmlspecialchars($house_fetch['name']); ?></td>
<td>
<?php
if (isset($config['towns'][(int)$house_fetch['townid']])) echo htmlspecialchars($config['towns'][(int)$house_fetch['townid']]);
else echo '(Missing town)';
?>
</td>
<td>
<?php
if (isset($house_info[(int)$house_fetch['houseid']])) echo $house_info[(int)$house_fetch['houseid']];
else echo 'None [Available]';
?>
</td>
<td><?php echo $house_fetch['size']; ?></td>
<td><?php echo $house_price; ?></td>
</tr>
<?php
}
?>
</table>
<?php
} else echo '<p><font color="red">Something is wrong with the cache.</font></p>';
} else if ($config['TFSVersion'] === 'TFS_10') {
// Fetch values
$querystring_id = &$_GET['id'];
$townid = ($querystring_id) ? (int)$_GET['id'] : $config['houseConfig']['HouseListDefaultTown'];
$towns = $config['towns'];
$order = &$_GET['order'];
$type = &$_GET['type'];
// Create Search house box
?>
<form action="" method="get" style="width: 648px">
<b>Select town:</b>
<select name="id">
<?php
foreach ($towns as $id => $name)
echo '<option value="'. $id .'"' . ($townid != $id ?: ' selected') . '>'. $name .'</option>';
?>
</select>
<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>
<?php
if(!in_array($order, $order_allowed))
$order = 'id';
if(!in_array($type, $type_allowed))
$type = 'desc';
// Create or fetch data from cache
$cache = new Cache('engine/cache/houses/houses-' . $order . '-' . $type);
$houses = array();
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` ORDER BY {$order} {$type};");
if ($houses !== false) {
// Fetch player names
$playerlist = array();
foreach ($houses as $h)
if ($h['owner'] > 0)
$playerlist[] = $h['owner'];
if (!empty($playerlist)) {
$ids = join(',', $playerlist);
$tmpPlayers = mysql_select_multi("SELECT `id`, `name` FROM players WHERE `id` IN ($ids);");
// Sort $tmpPlayers by player id
$tmpById = array();
foreach ($tmpPlayers as $p)
$tmpById[$p['id']] = $p['name'];
for ($i = 0; $i < count($houses); $i++)
if ($houses[$i]['owner'] > 0)
$houses[$i]['ownername'] = $tmpById[$houses[$i]['owner']];
}
$cache->setContent($houses);
$cache->save();
}
} else
$houses = $cache->load();
if ($houses !== false || !empty($houses)) {
// Intialize stuff
//data_dump($houses, false, "House data");
?>
<table id="housetable">
<tr class="yellow">
<th>Name</th>
<th>Size</th>
<th>Beds</th>
<th>Rent</th>
<th>Owner</th>
<th>Town</th>
</tr>
<?php
foreach ($houses as $house) {
if ($house['town_id'] == $townid) {
?>
<tr>
<td><?php echo "<a href='house.php?id=". $house['id'] ."'>". $house['name'] ."</a>"; ?></td>
<td><?php echo $house['size']; ?></td>
<td><?php echo $house['beds']; ?></td>
<td><?php echo $house['rent']; ?></td>
<?php
// Status:
if ($house['owner'] != 0)
echo "<td><a href='characterprofile.php?name=". $house['ownername'] ."' target='_BLANK'>". $house['ownername'] ."</a></td>";
else
echo ($house['highest_bidder'] == 0 ? '<td>None</td>' : '<td><b>Selling</b></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>
<?php
}
}
?>
</table>
<?php
} else
echo "<h1>Failed to fetch data from sql->houses table.</h1><p>Is the table empty?</p>";
} // End TFS 1.0 logic
}
include 'layout/overall/footer.php'; ?>