houses.php

main 163 lines · 4.4 KB Raw
Alex Alex Commit Initial commit 01/10/2026 09:20
1<?php
2require_once 'engine/init.php';
3
4$themeHousesPage = function_exists('theme_file') ? theme_file('pages/houses.php') : null;
5if ($themeHousesPage !== null) {
6 include $themeHousesPage;
7 exit;
8}
9
10theme_open();
11
12if ($config['log_ip'])
13 znote_visitor_insert_detailed_data(3);
14
15// Fetch values
16$querystring_id = &$_GET['id'];
17$townid = ($querystring_id) ? (int)$_GET['id'] : $config['houseConfig']['HouseListDefaultTown'];
18$towns = $config['towns'];
19
20$order = &$_GET['order'];
21$type = &$_GET['type'];
22
23// Create Search house box
24?>
25<form action="" method="get" class="houselist">
26 <table>
27 <tr>
28 <td><?= t('common.town') ?></td>
29 <td><?= t('houses.order') ?></td>
30 <td><?= t('houses.sort') ?></td>
31 </tr>
32 <tr>
33 <td>
34 <select name="id">
35 <?php
36 foreach ($towns as $id => $name)
37 echo '<option value="'. $id .'"' . ($townid != $id ?: ' selected') . '>'. $name .'</option>';
38 ?>
39 </select>
40 </td>
41 <td>
42 <select name="order">
43 <?php
44 $order_allowed = array('id', 'name', 'size', 'beds', 'rent', 'owner');
45 $order_labels = array('id' => 'ID', 'name' => t('common.name'), 'size' => t('house.size'), 'beds' => t('house.beds'), 'rent' => t('house.rent'), 'owner' => t('house.owner'));
46 foreach($order_allowed as $o)
47 echo '<option value="' . $o . '"' . ($o != $order ?: ' selected') . '>' . htmlspecialchars($order_labels[$o], ENT_QUOTES, 'UTF-8') . '</option>';
48 ?>
49 </select>
50 </td>
51 <td>
52 <select name="type">
53 <?php
54 $type_allowed = array('desc', 'asc');
55 foreach($type_allowed as $t)
56 echo '<option value="' . $t . '"' . ($t != $type ?: ' selected') . '>' . ($t == 'desc' ? t('houses.descending') : t('houses.ascending')) .'</option>';
57 ?>
58 </select>
59 </td>
60 </tr>
61 <tr>
62 <td colspan="3">
63 <input type="submit" value="<?= t('houses.fetch') ?>"/>
64 </td>
65 </tr>
66 </table>
67</form>
68<?php
69if(!in_array($order, $order_allowed))
70 $order = 'id';
71
72if(!in_array($type, $type_allowed))
73 $type = 'desc';
74
75// Create or fetch data from cache
76$cache = new Cache('engine/cache/houses/houses-' . $order . '-' . $type);
77$houses = array();
78
79if ($cache->hasExpired()) {
80
81 $houses = db()->fetchAll("
82 SELECT
83 `id`, `owner`, `paid`, `warnings`, `name`, `rent`, `town_id`,
84 `size`, `beds`, " . houseSelect(array('bid','bid_end','last_bid','highest_bidder')) . "
85 FROM `houses`
86 ORDER BY {$order} {$type};
87 ");
88
89 if ($houses !== false) {
90 // Fetch player names
91 $playerlist = array();
92
93 foreach ($houses as $h)
94 if ($h['owner'] > 0)
95 $playerlist[] = (int)$h['owner'];
96
97 if (!empty($playerlist)) {
98 $placeholders = implode(',', array_fill(0, count($playerlist), '?'));
99 $tmpPlayers = db()->fetchAll("SELECT `id`, `name` FROM players WHERE `id` IN ($placeholders);", $playerlist);
100
101 // Sort $tmpPlayers by player id
102 $tmpById = array();
103 foreach ($tmpPlayers as $p)
104 $tmpById[$p['id']] = $p['name'];
105
106 for ($i = 0; $i < count($houses); $i++)
107 if ($houses[$i]['owner'] > 0)
108 $houses[$i]['ownername'] = $tmpById[$houses[$i]['owner']];
109 }
110
111 $cache->setContent($houses);
112 $cache->save();
113 }
114} else
115 $houses = $cache->load();
116
117if ($houses !== false || !empty($houses)) {
118 // Intialize stuff
119 //data_dump($houses, false, "House data");
120 ?>
121 <table id="housetable">
122 <tr class="yellow">
123 <th><?= t('common.name') ?></th>
124 <th><?= t('house.size') ?></th>
125 <th><?= t('house.beds') ?></th>
126 <th><?= t('house.rent') ?></th>
127 <th><?= t('house.owner') ?></th>
128 <th><?= t('common.town') ?></th>
129 </tr>
130 <?php
131 foreach ($houses as $house) {
132 if ($house['town_id'] == $townid) {
133 ?>
134 <tr>
135 <td><?php echo "<a href='house.php?id=". $house['id'] ."'>". $house['name'] ."</a>"; ?></td>
136 <td><?php echo $house['size']; ?></td>
137 <td><?php echo $house['beds']; ?></td>
138 <td><?php echo $house['rent']; ?></td>
139 <?php
140 // Status:
141 if ($house['owner'] != 0)
142 echo "<td><a href='characterprofile.php?name=". $house['ownername'] ."' target='_BLANK'>". $house['ownername'] ."</a></td>";
143 else
144 echo ($house['highest_bidder'] == 0 ? '<td>None</td>' : '<td><b>Selling</b></td>');
145 ?>
146 <td><?php
147 $town_name = &$towns[$house['town_id']];
148 echo ($town_name ? $town_name : 'Specify town id ' . $house['town_id'] . ' name in config.php first.');
149 ?></td>
150 </tr>
151 <?php
152 }
153 }
154 ?>
155 </table>
156
157 <?php
158} else {
159 echo "<h1>". t('houses.fetch_failed') ."</h1><p>". t('houses.empty') ."</p>";
160}
161
162theme_close(); ?>
163
Top