PageRenderTime 108ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/crop_finder.php

https://github.com/caponelpalo/Travianx
PHP | 359 lines | 278 code | 74 blank | 7 comment | 41 complexity | debabc4a239589f1fd2bfed4966ab76a MD5 | raw file
  1. <?php
  2. /*-------------------------------------------------------*\
  3. | ********* DO NOT REMOVE THIS COPYRIGHT NOTICE ********* |
  4. +---------------------------------------------------------+
  5. | Developed by: Manni < manuel_mannhardt@web.de > |
  6. | Dzoki < dzoki.travian@gmail.com > |
  7. | Copyright: TravianX Project All rights reserved |
  8. \*-------------------------------------------------------*/
  9. include ("GameEngine/Village.php");
  10. if($session->plus == 0) {
  11. header("Location: plus.php?id=3");
  12. }
  13. if($_POST['type'] == 15) {
  14. header("Location: ".$_SERVER['PHP_SELF']."?s=1&x=" . $_POST['x'] . '&y=' . $_POST['y']);
  15. } elseif($_POST['type'] == 9) {
  16. header("Location: ".$_SERVER['PHP_SELF']."?s=2&x=" . $_POST['x'] . '&y=' . $_POST['y']);
  17. } elseif($_POST['type'] == 'both') {
  18. header("Location: ".$_SERVER['PHP_SELF']."?s=3&x=" . $_POST['x'] . '&y=' . $_POST['y']);
  19. }
  20. ?>
  21. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  22. <html>
  23. <head>
  24. <title><?php
  25. echo SERVER_NAME
  26. ?> - Crop Finder</title>
  27. <link REL="shortcut icon" HREF="favicon.ico"/>
  28. <meta http-equiv="cache-control" content="max-age=0" />
  29. <meta http-equiv="pragma" content="no-cache" />
  30. <meta http-equiv="expires" content="0" />
  31. <meta http-equiv="imagetoolbar" content="no" />
  32. <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
  33. <script src="mt-full.js?0faaa" type="text/javascript"></script>
  34. <script src="unx.js?0faaa" type="text/javascript"></script>
  35. <script src="new.js?0faaa" type="text/javascript"></script>
  36. <link href="<?php
  37. echo GP_LOCATE;
  38. ?>lang/en/lang.css?f4b7c" rel="stylesheet" type="text/css" />
  39. <link href="<?php
  40. echo GP_LOCATE;
  41. ?>lang/en/compact.css?f4b7c" rel="stylesheet" type="text/css" />
  42. <?php
  43. if($session->gpack == null || GP_ENABLE == false) {
  44. echo "
  45. <link href='".GP_LOCATE."travian.css?e21d2' rel='stylesheet' type='text/css' />
  46. <link href='".GP_LOCATE."lang/en/lang.css?e21d2' rel='stylesheet' type='text/css' />";
  47. }
  48. else {
  49. echo "
  50. <link href='".$session->gpack."travian.css?e21d2' rel='stylesheet' type='text/css' />
  51. <link href='".$session->gpack."lang/en/lang.css?e21d2' rel='stylesheet' type='text/css' />";
  52. }
  53. ?>
  54. <script type="text/javascript">
  55. window.addEvent('domready', start);
  56. </script>
  57. </head>
  58. <body class="v35 ie ie8">
  59. <div class="wrapper">
  60. <img style="filter:chroma();" src="img/x.gif" id="msfilter" alt="" />
  61. <div id="dynamic_header">
  62. </div>
  63. <?php
  64. include ("Templates/header.tpl");
  65. ?>
  66. <div id="mid">
  67. <?php
  68. include ("Templates/menu.tpl");
  69. if(is_numeric($_GET['x']) AND is_numeric($_GET['y'])) {
  70. $coor2['x'] = $_GET['x'];
  71. $coor2['y'] = $_GET['y'];
  72. } else {
  73. $wref2 = $village->wid;
  74. $coor2 = $database->getCoor($wref2);
  75. }
  76. ?>
  77. <div id="content" class="player">
  78. <h1>Crop Finder</h1>
  79. <center>
  80. <img width="200" src="gpack/travian_default/img/g/f6.jpg" />
  81. <img width="200" src="gpack/travian_default/img/g/f1.jpg" />
  82. </center>
  83. <br /><br />
  84. <form action="<?php echo $_SERVER['PHP_SELF']; ?>?s" method="post">
  85. <table>
  86. <tr>
  87. <td width="100">Search for:</td>
  88. <td width="250">
  89. <input type="radio" class="radio" name="type" value="15" <?php if($_GET['s'] == 1) { print 'checked="checked"'; } ?> /> 15 crop
  90. <input type="radio" class="radio" name="type" value="9" <?php if($_GET['s'] == 2) { print 'checked="checked"'; } ?> /> 9 crop
  91. <input type="radio" class="radio" name="type" value="both" <?php if($_GET['s'] == 3) { print 'checked="checked"'; } ?> /> both<br />
  92. </td>
  93. </tr>
  94. <tr>
  95. <td>Startposition:</td>
  96. <td>x: <input type="text" name="x" value="<?php print $coor2['x']; ?>" size="3" /> y: <input type="text" name="y" value="<?php print $coor2['y']; ?>" size="3" />
  97. </tr>
  98. <tr>
  99. <td colspan="2"><input type="submit" name="submit" value="Search"></td>
  100. </tr>
  101. </table>
  102. </form>
  103. <?php
  104. define('PREFIX', TB_PREFIX);
  105. $type15 = mysql_query("SELECT id,x,y,occupied FROM ".PREFIX."wdata WHERE fieldtype = 6");
  106. $type9 = mysql_query("SELECT id,x,y,occupied FROM ".PREFIX."wdata WHERE fieldtype = 1");
  107. $type_both = mysql_query("SELECT id,x,y,occupied,fieldtype FROM ".PREFIX."wdata WHERE fieldtype = 1 OR fieldtype = 6");
  108. if(is_numeric($_GET['x']) AND is_numeric($_GET['y'])) {
  109. $coor['x'] = $_GET['x'];
  110. $coor['y'] = $_GET['y'];
  111. } else {
  112. $wref = $village->wid;
  113. $coor = $database->getCoor($wref);
  114. }
  115. function getDistance($coorx1, $coory1, $coorx2, $coory2) {
  116. $max = WORLD_MAX * WORLD_MAX;
  117. $x1 = intval($coorx1);
  118. $y1 = intval($coory1);
  119. $x2 = intval($coorx2);
  120. $y2 = intval($coory2);
  121. $distanceX = min(abs($x2 - $x1), abs($max - abs($x2 - $x1)));
  122. $distanceY = min(abs($y2 - $y1), abs($max - abs($y2 - $y1)));
  123. $dist = sqrt(pow($distanceX, 2) + pow($distanceY, 2));
  124. return round($dist, 1);
  125. }
  126. if($_GET['s'] == 1) {
  127. ?>
  128. <table id="member">
  129. <thead>
  130. <tr>
  131. <th colspan='5'>Crop Finder - 15c</th>
  132. </tr>
  133. <tr>
  134. <td>Type</td>
  135. <td>Coordinates</td>
  136. <td>Owner</td>
  137. <td>Occupied</td>
  138. <td>Distance</td>
  139. </tr>
  140. </thead><tbody>
  141. </td></tr><br>
  142. <?php
  143. while($row = mysql_fetch_array($type15)) {
  144. $dist = getDistance($coor['x'], $coor['y'], $row['x'], $row['y']);
  145. $rows[$dist] = $row;
  146. }
  147. ksort($rows);
  148. foreach($rows as $dist => $row) {
  149. echo "<tr>";
  150. echo "<td>15c</td>";
  151. if($row['occupied'] == 0) {
  152. echo "<td>(".$row['x']."|".$row['y'].")</td>";
  153. echo "<td>-</td>";
  154. echo "<td><b><font color=\"green\">Unoccupied</b></font></td>";
  155. } else {
  156. echo "<td><a href=\"karte.php?d=".$row['id']."&c=".$generator->getMapCheck($row['id'])."\">".$database->getVillageField($row['id'], "name")." (".$row['x']."|".$row['y'].")</a></td>";
  157. echo "<td><a href=\"spieler.php?uid=".$database->getVillageField($row['id'], "owner")."\">".$database->getUserField($database->getVillageField($row['id'], "owner"), "username", 0)."</a></td>";
  158. echo "<td><b><font color=\"red\">Occupied</b></font></td>";
  159. }
  160. echo "<td><center>".getDistance($coor['x'], $coor['y'], $row['x'], $row['y'])."</center></td>";
  161. }
  162. ?>
  163. </tbody></table>
  164. <?php
  165. }
  166. else if($_GET['s'] == 2) {
  167. ?>
  168. <table id="member">
  169. <thead>
  170. <tr>
  171. <th colspan='5'>Crop Finder - 9c</th>
  172. </tr>
  173. <tr>
  174. <td>Type</td>
  175. <td>Coordinates</td>
  176. <td>Owner</td>
  177. <td>Occupied</td>
  178. <td>Distance</td>
  179. </tr>
  180. </thead><tbody>
  181. </td></tr><br>
  182. <?php
  183. unset($rows);
  184. while($row = mysql_fetch_array($type9)) {
  185. $dist = getDistance($coor['x'], $coor['y'], $row['x'], $row['y']);
  186. $rows[$dist] = $row;
  187. }
  188. ksort($rows);
  189. foreach($rows as $dist => $row) {
  190. echo "<tr>";
  191. echo "<td>9c</td>";
  192. if($row['occupied'] == 0) {
  193. echo "<td>(".$row['x']."|".$row['y'].")</td>";
  194. echo "<td>-</td>";
  195. echo "<td><b><font color=\"green\">Unoccupied</b></font></td>";
  196. } else {
  197. echo "<td><a href=\"karte.php?d=".$row['id']."&c=".$generator->getMapCheck($row['id'])."\">".$database->getVillageField($row['id'], "name")." (".$row['x']."|".$row['y'].")</a></td>";
  198. echo "<td><a href=\"spieler.php?uid=".$database->getVillageField($row['id'], "owner")."\">".$database->getUserField($database->getVillageField($row['id'], "owner"), "username", 0)."</a></td>";
  199. echo "<td><b><font color=\"red\">Occupied</b></font></td>";
  200. }
  201. echo "<td><center>".getDistance($coor['x'], $coor['y'], $row['x'], $row['y'])."</center></td>";
  202. }
  203. ?>
  204. </tbody></table>
  205. <?php
  206. }
  207. else if($_GET['s'] == 3) {
  208. ?>
  209. <table id="member">
  210. <thead>
  211. <tr>
  212. <th colspan='5'>Crop Finder - 9c and 15c</th>
  213. </tr>
  214. <tr>
  215. <td>Type</td>
  216. <td>Coordinates</td>
  217. <td>Owner</td>
  218. <td>Occupied</td>
  219. <td>Distance</td>
  220. </tr>
  221. </thead><tbody>
  222. </td></tr><br>
  223. <?php
  224. unset($rows);
  225. while($row = mysql_fetch_array($type_both)) {
  226. $dist = getDistance($coor['x'], $coor['y'], $row['x'], $row['y']);
  227. $rows[$dist] = $row;
  228. }
  229. ksort($rows);
  230. foreach($rows as $dist => $row) {
  231. if($row['fieldtype'] == 1) {
  232. $field = '9c';
  233. } elseif($row['fieldtype'] == 6) {
  234. $field = '15c';
  235. }
  236. echo "<tr>";
  237. echo "<td>" . $field . "</td>";
  238. if($row['occupied'] == 0) {
  239. echo "<td>(".$row['x']."|".$row['y'].")</td>";
  240. echo "<td>-</td>";
  241. echo "<td><b><font color=\"green\">Unoccupied</b></font></td>";
  242. } else {
  243. echo "<td><a href=\"karte.php?d=".$row['id']."&c=".$generator->getMapCheck($row['id'])."\">".$database->getVillageField($row['id'], "name")." (".$row['x']."|".$row['y'].")</a></td>";
  244. echo "<td><a href=\"spieler.php?uid=".$database->getVillageField($row['id'], "owner")."\">".$database->getUserField($database->getVillageField($row['id'], "owner"), "username", 0)."</a></td>";
  245. echo "<td><b><font color=\"red\">Occupied</b></font></td>";
  246. }
  247. echo "<td><center>".getDistance($coor['x'], $coor['y'], $row['x'], $row['y'])."</center></td>";
  248. }
  249. ?>
  250. </tbody></table>
  251. <?php
  252. }
  253. ?>
  254. </div>
  255. <div id="side_info">
  256. <?php
  257. include ("Templates/quest.tpl");
  258. include ("Templates/news.tpl");
  259. include ("Templates/multivillage.tpl");
  260. include ("Templates/links.tpl");
  261. ?>
  262. </div>
  263. <div class="clear"></div>
  264. </div>
  265. <div class="footer-stopper"></div>
  266. <div class="clear"></div>
  267. <?php
  268. include ("Templates/footer.tpl");
  269. include ("Templates/res.tpl");
  270. ?>
  271. <div id="stime">
  272. <div id="ltime">
  273. <div id="ltimeWrap">
  274. Calculated in <b><?php
  275. echo round(($generator->pageLoadTimeEnd() - $start) * 1000);
  276. ?></b> ms
  277. <br />Server time: <span id="tp1" class="b"><?php
  278. echo date('H:i:s');
  279. ?></span>
  280. </div>
  281. </div>
  282. </div>
  283. <div id="ce"></div>
  284. </body>
  285. </html>