Advertisement
jfrye2007

houses.php

Jul 26th, 2016
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.52 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.  
  157.  
  158.  
  159. <form method="post" action="house.php">
  160. <table border="0" cellspacing="1" cellpadding="4" width="100%">
  161. <tbody>
  162. <tr bgcolor="#800000">
  163. <td colspan="4" class="white">
  164. <b><font color="F5F5DC">House Search</b>
  165. </td>
  166. </tr>
  167. <tr bgcolor="F5F5DC">
  168. <td width="33%">
  169. <b><font color="black">Town</b>
  170. </td>
  171. <td width="33%">
  172. <b><font color="black">Status</b>
  173. </td>
  174. <td width="33%">
  175. <b><font color="black">Order</b>
  176. </td>
  177. </tr>
  178. <tr bgcolor="F5F5DC">
  179. <td valign="top" rowspan="2">
  180. <input type="radio" name="town" value="Thralkeld"><font color="black"> Thralkeld <br>
  181. <input type="radio" name="town" value="Kilerth"><font color="black"> Kilerth <br>
  182. </td>
  183. <td valign="top">
  184. <input type="radio" name="state" value checked><font color="black"> all states <br>
  185. <input type="radio" name="state" value="auctioned"><font color="black"> auctioned <br>
  186. <input type="radio" name="state" value="rented"><font color="black"> rented <br>
  187. </td>
  188. <td valign="top" rowspan="2">
  189. <input type="radio" name="order" value checked><font color="black"> by name <br>
  190. <input type="radio" name="order" value="size"><font color="black"> by size <br>
  191. <input type="radio" name="order" value="rent"><font color="black"> by rent <br>
  192. <input type="radio" name="order" value="bid"><font color="black"> by bid <br>
  193. <input type="radio" name="order" value="end"><font color="black"> by auction end <br>
  194. </td>
  195. </tr>
  196. <tr bgcolor="F5F5DC">
  197. <td valign="top">
  198. <input type="radio" name="type" value="houses" checked><font color="black"> houses and flats <br>
  199. <input type="radio" name="type" value="guildhalls"><font color="black"> guildhalls <br>
  200. </td>
  201. </tr>
  202. </tbody>
  203. </table>
  204. <br>
  205. <center>
  206. <table border="0" cellspacing="0" cellpadding="0"></table>
  207. <tbody>
  208. <tr>
  209. <td>
  210. <input type="image" name="Submit" alt="Submit" src="layout/images/buttons/submit.png">
  211. </td>
  212. </tr>
  213. </tbody>
  214. </table>
  215.  
  216. </center>
  217. </form>
  218. <?php
  219. if(!in_array($order, $order_allowed))
  220. $order = 'id';
  221.  
  222. if(!in_array($type, $type_allowed))
  223. $type = 'desc';
  224.  
  225. // Create or fetch data from cache
  226. $cache = new Cache('engine/cache/houses/houses-' . $order . '-' . $type);
  227. $houses = array();
  228. if ($cache->hasExpired()) {
  229. $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};");
  230. if ($houses !== false) {
  231. // Fetch player names
  232. $playerlist = array();
  233.  
  234. foreach ($houses as $h)
  235. if ($h['owner'] > 0)
  236. $playerlist[] = $h['owner'];
  237.  
  238. if (!empty($playerlist)) {
  239. $ids = join(',', $playerlist);
  240. $tmpPlayers = mysql_select_multi("SELECT `id`, `name` FROM players WHERE `id` IN ($ids);");
  241.  
  242. // Sort $tmpPlayers by player id
  243. $tmpById = array();
  244. foreach ($tmpPlayers as $p)
  245. $tmpById[$p['id']] = $p['name'];
  246.  
  247. for ($i = 0; $i < count($houses); $i++)
  248. if ($houses[$i]['owner'] > 0)
  249. $houses[$i]['ownername'] = $tmpById[$houses[$i]['owner']];
  250. }
  251.  
  252. $cache->setContent($houses);
  253. $cache->save();
  254. }
  255. } else
  256. $houses = $cache->load();
  257.  
  258. if ($houses !== false || !empty($houses)) {
  259. // Intialize stuff
  260. //data_dump($houses, false, "House data");
  261. ?>
  262.  
  263. <?php
  264. foreach ($houses as $house) {
  265. if ($house['town_id'] == $townid) {
  266. ?>
  267. <tr width="143px" height="26px" bgcolor="#F5F5DC" border="0" cellspacing="1" cellpadding="2">
  268. <td><?php echo "<font color='#505050'>". $house['name'] ."</a>"; ?></td>
  269. <td><?php echo "<font color='#505050'>". $house['size']; ?> sqm</td>
  270. <td><?php echo "<font color='#505050'>". $house['rent']; ?> gold</td>
  271.  
  272. <?php
  273. // Status:
  274. if ($house['owner'] != 0)
  275. echo "<td><font color='#505050'>Rented</td>";
  276. else
  277. echo ($house['highest_bidder'] == 0 ? '<td><font color="#505050">auctioned (no bit yet)</td>' : '<td><font color="#505050">auctioned (<?php echo <td>'. $house['last_bid'] .'gp; '.($house['bid_end'] > time()).' day(s) left)</td></td>');
  278. ?>
  279.  
  280. <?php echo '<td width="115px" height="24px" bgcolor="F5F5DC"><a href="house.php?id='. $house['id'] .'"><img align="center" src="layout/images/buttons/view.gif"></a></td>'; ?>
  281. </tr>
  282. <?php
  283. }
  284. }
  285. ?>
  286. </table>
  287. <?php
  288. } else
  289. echo "<h1>Failed to fetch data from sql->houses table.</h1><p>Is the table empty?</p>";
  290. } // End TFS 1.0 logic
  291. }
  292. include 'layout/overall/footer.php'; ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement