Advertisement
Guest User

Untitled

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