Guest User

staff_mine.php

a guest
Jan 31st, 2017
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 23.69 KB | None | 0 0
  1. <?php
  2. require('sglobals.php');
  3. echo "<h2>Mining</h2><hr />";
  4. if (!isset($_GET['action']))
  5. {
  6. $_GET['action'] = '';
  7. }
  8. switch ($_GET['action'])
  9. {
  10. case 'addmine':
  11. addmine();
  12. break;
  13. case 'editmine':
  14. editmine();
  15. break;
  16. case 'delmine':
  17. delmine();
  18. break;
  19. default:
  20. echo '404'; die($h->endpage());
  21. break;
  22. }
  23. function addmine()
  24. {
  25. global $db,$ir,$userid;
  26. if (isset($_POST['level']) && (!empty($_POST['level'])))
  27. {
  28. var_dump($_POST);
  29. $level=(isset($_POST['level']) && is_numeric($_POST['level'])) ? abs(intval($_POST['level'])) : '';
  30. $power=(isset($_POST['power']) && is_numeric($_POST['power'])) ? abs(intval($_POST['power'])) : '';
  31. $iq=(isset($_POST['iq']) && is_numeric($_POST['iq'])) ? abs(intval($_POST['iq'])) : '';
  32. $pick=(isset($_POST['pick']) && is_numeric($_POST['pick'])) ? abs(intval($_POST['pick'])) : '';
  33. $city=(isset($_POST['city']) && is_numeric($_POST['city'])) ? abs(intval($_POST['city'])) : '';
  34. $cflakes=(isset($_POST['cflakes']) && is_numeric($_POST['cflakes'])) ? abs(intval($_POST['cflakes'])) : '';
  35. $cflakesmin=(isset($_POST['cflakemin']) && is_numeric($_POST['cflakemin'])) ? abs(intval($_POST['cflakemin'])) : '';
  36. $cflakesmax=(isset($_POST['cflakemax']) && is_numeric($_POST['cflakemax'])) ? abs(intval($_POST['cflakemax'])) : '';
  37. $sflakes=(isset($_POST['sflakes']) && is_numeric($_POST['sflakes'])) ? abs(intval($_POST['sflakes'])) : '';
  38. $sflakesmin=(isset($_POST['sflakemin']) && is_numeric($_POST['sflakemin'])) ? abs(intval($_POST['sflakemin'])) : '';
  39. $sflakesmax=(isset($_POST['sflakemax']) && is_numeric($_POST['sflakemax'])) ? abs(intval($_POST['sflakemax'])) : '';
  40. $gflakes=(isset($_POST['gflakes']) && is_numeric($_POST['gflakes'])) ? abs(intval($_POST['gflakes'])) : '';
  41. $gflakesmin=(isset($_POST['gflakemin']) && is_numeric($_POST['gflakemin'])) ? abs(intval($_POST['gflakemin'])) : '';
  42. $gflakesmax=(isset($_POST['gflakemax']) && is_numeric($_POST['gflakemax'])) ? abs(intval($_POST['gflakemax'])) : '';
  43. $gem=(isset($_POST['gem']) && is_numeric($_POST['gem'])) ? abs(intval($_POST['gem'])) : '';
  44. if (empty($level) || empty($iq) || empty($pick) || empty($city) || empty($cflakes)
  45. || empty($cflakesmin) || empty($cflakesmax) || empty($gflakes) || empty($gflakesmin)
  46. || empty($gflakesmax) || empty($sflakesmin) || empty($sflakesmax) || empty($sflakes) || empty($gem) || empty($power))
  47. {
  48. echo "None of the inputs in the form can be empty.";
  49. }
  50. elseif ($level < 1)
  51. {
  52. echo "You need the level to be greater than 0.";
  53. }
  54. elseif ($cflakesmin == 0 || $cflakesmax == 0 || $gflakesmin == 0 ||
  55. $gflakesmax == 0 || $sflakesmin == 0 || $sflakesmax == 0)
  56. {
  57. echo "You cannot specify a minimum or maximum output of zero.";
  58. }
  59. elseif ($cflakesmin >= $cflakesmax || $sflakesmin >= $sflakesmax || $gflakesmin >= $gflakesmax)
  60. {
  61. echo "The minimum output cannot be equal to or larger than the output.";
  62. }
  63. else
  64. {
  65. $CitySQL=($db->query("SELECT `cityname` FROM `cities` WHERE `cityid` = {$city}"));
  66. $PickSQL=($db->query("SELECT `itmname` FROM `items` WHERE `itmid` = {$pick}"));
  67. $CFSQL=($db->query("SELECT `itmname` FROM `items` WHERE `itmid` = {$cflakes}"));
  68. $SFSQL=($db->query("SELECT `itmname` FROM `items` WHERE `itmid` = {$sflakes}"));
  69. $GFSQL=($db->query("SELECT `itmname` FROM `items` WHERE `itmid` = {$gflakes}"));
  70. $GemSQL=($db->query("SELECT `itmname` FROM `items` WHERE `itmid` = {$gem}"));
  71.  
  72. if ($db->num_rows($CitySQL) == 0)
  73. {
  74. echo "The city you specified appears to not exist.";
  75. }
  76. elseif ($db->num_rows($PickSQL) == 0)
  77. {
  78. echo "The pickaxe you chose appears to not exist as an in-game item.";
  79. }
  80. elseif ($db->num_rows($CFSQL) == 0)
  81. {
  82. echo "The item you chose for Output #1 appears to not exist as an in-game item.";
  83. }
  84. elseif ($db->num_rows($SFSQL) == 0)
  85. {
  86. echo "The item you chose for Output #2 appears to not exist as an in-game item.";
  87. }
  88. elseif ($db->num_rows($GFSQL) == 0)
  89. {
  90. echo "The item you chose for Output #3 appears to not exist as an in-game item.";
  91. }
  92. elseif ($db->num_rows($GemSQL) == 0)
  93. {
  94. echo "The item you chose as the mine's gem does not exist in-game.";
  95. }
  96. else
  97. {
  98. $db->query("INSERT INTO `tmg_mines_data`
  99. (`mine_id`, `mine_location`, `mine_level`,
  100. `mine_copper_min`, `mine_copper_max`,
  101. `mine_silver_min`, `mine_silver_max`,
  102. `mine_gold_min`, `mine_gold_max`,
  103. `mine_pickaxe`, `mine_iq`,
  104. `mine_power_use`, `mine_copper_item`,
  105. `mine_silver_item`, `mine_gold_item`,
  106. `mine_gem_item`)
  107. VALUES
  108. (NULL, '{$city}', '{$level}', '{$cflakesmin}',
  109. '{$cflakesmax}', '{$sflakesmin}', '{$sflakesmax}',
  110. '{$gflakesmin}', '{$gflakesmax}', '{$pick}', '{$iq}',
  111. '{$power}', '{$cflakes}', '{$sflakes}', '{$gflakes}',
  112. '{$gem}');");
  113. echo "The mine has been created successfully.";
  114. $citynamelog=$db->fetch_single($CitySQL);
  115. stafflog_add("Added a a mine in {$citynamelog}.");
  116. }
  117.  
  118. }
  119. }
  120. else
  121. {
  122. echo "Use this form to add a mine into the game. The mine's name will
  123. be named after the city its placed in. If you have a specific naming
  124. scheme, you'll likely want to edit the code to allow it.<br />
  125. <table border='1' padding='1' width='100%'>
  126. <form method='post'>
  127. <tr>
  128. <th>
  129. Mine's Location
  130. </th>
  131. <td>
  132. " . location_dropdown(NULL, "city") . "
  133. </td>
  134. </tr>
  135. <tr>
  136. <th>
  137. Minimum Mining Level
  138. </th>
  139. <td>
  140. <input type='number' name='level' min='1' required='1'>
  141. </td>
  142. </tr>
  143. <tr>
  144. <th>
  145. Minimum IQ Required
  146. </th>
  147. <td>
  148. <input type='number' name='iq' min='1' required='1'>
  149. </td>
  150. </tr>
  151. <tr>
  152. <th>
  153. Power Exhaustion Per Attempt
  154. </th>
  155. <td>
  156. <input type='number' name='power' min='1' required='1'>
  157. </td>
  158. </tr>
  159. <tr>
  160. <th>
  161. Required Pickaxe
  162. </th>
  163. <td>
  164. " . item_dropdown(NULL, "pick") . "
  165. </td>
  166. </tr>
  167. <tr>
  168. <th>
  169. Output #1
  170. </th>
  171. <td>
  172. " . item_dropdown(NULL, "cflakes") . "
  173. </td>
  174. </tr>
  175. <tr>
  176. <th>
  177. Output #2
  178. </th>
  179. <td>
  180. " . item_dropdown(NULL, "sflakes") . "
  181. </td>
  182. </tr>
  183. <tr>
  184. <th>
  185. Output #3
  186. </th>
  187. <td>
  188. " . item_dropdown(NULL, "gflakes") . "
  189. </td>
  190. </tr>
  191. <tr>
  192. <th>
  193. Gem Item
  194. </th>
  195. <td>
  196. " . item_dropdown(NULL, "gem") . "
  197. </td>
  198. </tr>
  199. <tr>
  200. <th>
  201. Output #1's Minimum Output
  202. </th>
  203. <td>
  204. <input type='number' name='cflakemin' min='1' required='1'>
  205. </td>
  206. </tr>
  207. <tr>
  208. <th>
  209. Output #1's Maximum Output
  210. </th>
  211. <td>
  212. <input type='number' name='cflakemax' min='2' required='1'>
  213. </td>
  214. </tr>
  215. <tr>
  216. <th>
  217. Output #2's Minimum Output
  218. </th>
  219. <td>
  220. <input type='number' name='sflakemin' min='1' required='1'>
  221. </td>
  222. </tr>
  223. <tr>
  224. <th>
  225. Output #2's Maximum Output
  226. </th>
  227. <td>
  228. <input type='number' name='sflakemax' min='2' required='1'>
  229. </td>
  230. </tr>
  231. <tr>
  232. <th>
  233. Output #3's Minimum Output
  234. </th>
  235. <td>
  236. <input type='number' name='gflakemin' min='1' required='1'>
  237. </td>
  238. </tr>
  239. <tr>
  240. <th>
  241. Output #3's Maximum Output
  242. </th>
  243. <td>
  244. <input type='number' name='gflakemax' min='2' required='1'>
  245. </td>
  246. </tr>
  247. <tr>
  248. <td colspan='2'>
  249. <center><input type='submit' value='Add Mine'></center>
  250. </td>
  251. </tr>
  252. </form>
  253. </table>";
  254. }
  255. }
  256. function editmine()
  257. {
  258. if (!isset($_POST['step']))
  259. {
  260. $_POST['step'] = 0;
  261. }
  262. global $db,$ir,$userid;
  263. if (isset($_POST['level']) && (!empty($_POST['level'])) && $_POST['step'] == 2)
  264. {
  265. $mine=(isset($_POST['mineid']) && is_numeric($_POST['mineid'])) ? abs(intval($_POST['mineid'])) : '';
  266. $level=(isset($_POST['level']) && is_numeric($_POST['level'])) ? abs(intval($_POST['level'])) : '';
  267. $power=(isset($_POST['power']) && is_numeric($_POST['power'])) ? abs(intval($_POST['power'])) : '';
  268. $iq=(isset($_POST['iq']) && is_numeric($_POST['iq'])) ? abs(intval($_POST['iq'])) : '';
  269. $pick=(isset($_POST['pick']) && is_numeric($_POST['pick'])) ? abs(intval($_POST['pick'])) : '';
  270. $city=(isset($_POST['city']) && is_numeric($_POST['city'])) ? abs(intval($_POST['city'])) : '';
  271. $cflakes=(isset($_POST['cflakes']) && is_numeric($_POST['cflakes'])) ? abs(intval($_POST['cflakes'])) : '';
  272. $cflakesmin=(isset($_POST['cflakemin']) && is_numeric($_POST['cflakemin'])) ? abs(intval($_POST['cflakemin'])) : '';
  273. $cflakesmax=(isset($_POST['cflakemax']) && is_numeric($_POST['cflakemax'])) ? abs(intval($_POST['cflakemax'])) : '';
  274. $sflakes=(isset($_POST['sflakes']) && is_numeric($_POST['sflakes'])) ? abs(intval($_POST['sflakes'])) : '';
  275. $sflakesmin=(isset($_POST['sflakemin']) && is_numeric($_POST['sflakemin'])) ? abs(intval($_POST['sflakemin'])) : '';
  276. $sflakesmax=(isset($_POST['sflakemax']) && is_numeric($_POST['sflakemax'])) ? abs(intval($_POST['sflakemax'])) : '';
  277. $gflakes=(isset($_POST['gflakes']) && is_numeric($_POST['gflakes'])) ? abs(intval($_POST['gflakes'])) : '';
  278. $gflakesmin=(isset($_POST['gflakemin']) && is_numeric($_POST['gflakemin'])) ? abs(intval($_POST['gflakemin'])) : '';
  279. $gflakesmax=(isset($_POST['gflakemax']) && is_numeric($_POST['gflakemax'])) ? abs(intval($_POST['gflakemax'])) : '';
  280. $gem=(isset($_POST['gem']) && is_numeric($_POST['gem'])) ? abs(intval($_POST['gem'])) : '';
  281. if (empty($level) || empty($iq) || empty($pick) || empty($city) || empty($cflakes)
  282. || empty($cflakesmin) || empty($cflakesmax) || empty($gflakes) || empty($gflakesmin)
  283. || empty($gflakesmax) || empty($sflakesmin) || empty($sflakesmax) || empty($sflakes)
  284. || empty($gem) || empty($power) || empty($mine))
  285. {
  286. echo "None of the inputs in the form can be empty.";
  287. }
  288. elseif ($level < 1)
  289. {
  290. echo "You need the level to be greater than 0.";
  291. }
  292. elseif ($cflakesmin == 0 || $cflakesmax == 0 || $gflakesmin == 0 ||
  293. $gflakesmax == 0 || $sflakesmin == 0 || $sflakesmax == 0)
  294. {
  295. echo "You cannot specify a minimum or maximum output of zero.";
  296. }
  297. elseif ($cflakesmin >= $cflakesmax || $sflakesmin >= $sflakesmax || $gflakesmin >= $gflakesmax)
  298. {
  299. echo "The minimum output cannot be equal to or larger than the output.";
  300. }
  301. else
  302. {
  303. $CitySQL=($db->query("SELECT `cityname` FROM `cities` WHERE `cityid` = {$city}"));
  304. $PickSQL=($db->query("SELECT `itmname` FROM `items` WHERE `itmid` = {$pick}"));
  305. $CFSQL=($db->query("SELECT `itmname` FROM `items` WHERE `itmid` = {$cflakes}"));
  306. $SFSQL=($db->query("SELECT `itmname` FROM `items` WHERE `itmid` = {$sflakes}"));
  307. $GFSQL=($db->query("SELECT `itmname` FROM `items` WHERE `itmid` = {$gflakes}"));
  308. $GemSQL=($db->query("SELECT `itmname` FROM `items` WHERE `itmid` = {$gem}"));
  309.  
  310. if ($db->num_rows($CitySQL) == 0)
  311. {
  312. echo "The city you specified appears to not exist.";
  313. }
  314. elseif ($db->num_rows($PickSQL) == 0)
  315. {
  316. echo "The pickaxe you chose appears to not exist as an in-game item.";
  317. }
  318. elseif ($db->num_rows($CFSQL) == 0)
  319. {
  320. echo "The item you chose for Output #1 appears to not exist as an in-game item.";
  321. }
  322. elseif ($db->num_rows($SFSQL) == 0)
  323. {
  324. echo "The item you chose for Output #2 appears to not exist as an in-game item.";
  325. }
  326. elseif ($db->num_rows($GFSQL) == 0)
  327. {
  328. echo "The item you chose for Output #3 appears to not exist as an in-game item.";
  329. }
  330. elseif ($db->num_rows($GemSQL) == 0)
  331. {
  332. echo "The item you chose as the mine's gem does not exist in-game.";
  333. }
  334. else
  335. {
  336. $db->query("UPDATE `tmg_mines_data` SET `mine_location` = '{$city}', `mine_level` = '{$level}',
  337. `mine_copper_item` = '{$cflakes}', `mine_copper_max` = '{$cflakesmax}', `mine_copper_min` = '{$cflakesmin}',
  338. `mine_silver_item` = '{$sflakes}', `mine_silver_max` = '{$sflakesmax}', `mine_silver_min` = '{$sflakesmin}',
  339. `mine_gold_item` = '{$gflakes}', `mine_gold_max` = '{$gflakesmax}', `mine_gold_min` = '{$gflakesmin}',
  340. `mine_pickaxe` = '{$pick}', `mine_iq` = '{$iq}', `mine_gem_item` = '{$gem}', `mine_power_use` = '{$power}'
  341. WHERE `mine_id` = {$mine}");
  342. echo "The mine has been updated.";
  343. stafflog_add("Edited a mine.");
  344. }
  345.  
  346. }
  347. }
  348. elseif ($_POST['step'] == 1)
  349. {
  350. $mine=(isset($_POST['mine']) && is_numeric($_POST['mine'])) ? abs(intval($_POST['mine'])) : '';
  351. if ($db->num_rows($db->query("SELECT * FROM `tmg_mines_data` WHERE `mine_id` = {$mine}")) == 0)
  352. {
  353. echo "The mine you selected does not exist.";
  354. }
  355. else
  356. {
  357. $mi=$db->fetch_row($db->query("SELECT * FROM `tmg_mines_data` WHERE `mine_id` = {$mine}"));
  358. echo "Editing an existing mine...<br />
  359. <table border='1' padding='1' width='100%'>
  360. <form method='post'>
  361. <input type='hidden' value='2' name='step'>
  362. <input type='hidden' value='{$mine}' name='mineid'>
  363. <tr>
  364. <th>
  365. Mine's Location
  366. </th>
  367. <td>
  368. " . location_dropdown(NULL, "city", $mi['mine_location']) . "
  369. </td>
  370. </tr>
  371. <tr>
  372. <th>
  373. Minimum Mining Level
  374. </th>
  375. <td>
  376. <input type='number' name='level' min='1' value='{$mi['mine_level']}' required='1'>
  377. </td>
  378. </tr>
  379. <tr>
  380. <th>
  381. Minimum IQ Required
  382. </th>
  383. <td>
  384. <input type='number' name='iq' min='1' value='{$mi['mine_iq']}' required='1'>
  385. </td>
  386. </tr>
  387. <tr>
  388. <th>
  389. Power Exhaustion Per Attempt
  390. </th>
  391. <td>
  392. <input type='number' name='power' min='1' value='{$mi['mine_power_use']}' required='1'>
  393. </td>
  394. </tr>
  395. <tr>
  396. <th>
  397. Required Pickaxe
  398. </th>
  399. <td>
  400. " . item_dropdown(NULL, "pick", $mi['mine_pickaxe']) . "
  401. </td>
  402. </tr>
  403. <tr>
  404. <th>
  405. Output #1
  406. </th>
  407. <td>
  408. " . item_dropdown(NULL, "cflakes", $mi['mine_copper_item']) . "
  409. </td>
  410. </tr>
  411. <tr>
  412. <th>
  413. Output #2
  414. </th>
  415. <td>
  416. " . item_dropdown(NULL, "sflakes", $mi['mine_silver_item']) . "
  417. </td>
  418. </tr>
  419. <tr>
  420. <th>
  421. Output #3
  422. </th>
  423. <td>
  424. " . item_dropdown(NULL, "gflakes", $mi['mine_gold_item']) . "
  425. </td>
  426. </tr>
  427. <tr>
  428. <th>
  429. Gem Item
  430. </th>
  431. <td>
  432. " . item_dropdown(NULL, "gem", $mi['mine_gem_item']) . "
  433. </td>
  434. </tr>
  435. <tr>
  436. <th>
  437. Output #1's Minimum Output
  438. </th>
  439. <td>
  440. <input type='number' name='cflakemin' value='{$mi['mine_copper_min']}' min='1' required='1'>
  441. </td>
  442. </tr>
  443. <tr>
  444. <th>
  445. Output #1's Maximum Output
  446. </th>
  447. <td>
  448. <input type='number' name='cflakemax' value='{$mi['mine_copper_max']}' min='2' required='1'>
  449. </td>
  450. </tr>
  451. <tr>
  452. <th>
  453. Output #2's Minimum Output
  454. </th>
  455. <td>
  456. <input type='number' name='sflakemin' value='{$mi['mine_silver_min']}' min='1' required='1'>
  457. </td>
  458. </tr>
  459. <tr>
  460. <th>
  461. Output #2's Maximum Output
  462. </th>
  463. <td>
  464. <input type='number' name='sflakemax' value='{$mi['mine_silver_max']}' min='2' required='1'>
  465. </td>
  466. </tr>
  467. <tr>
  468. <th>
  469. Output #3's Minimum Output
  470. </th>
  471. <td>
  472. <input type='number' name='gflakemin' value='{$mi['mine_gold_min']}' min='1' required='1'>
  473. </td>
  474. </tr>
  475. <tr>
  476. <th>
  477. Output #3's Maximum Output
  478. </th>
  479. <td>
  480. <input type='number' name='gflakemax' value='{$mi['mine_gold_max']}' min='2' required='1'>
  481. </td>
  482. </tr>
  483. <tr>
  484. <td colspan='2'>
  485. <center><input type='submit' value='Edit Mine'></center>
  486. </td>
  487. </tr>
  488. </form>
  489. </table>";
  490. }
  491. }
  492. else
  493. {
  494. echo "Select a mine to edit<br />
  495. <form method='post'>
  496. <input type='hidden' name='step' value='1'>
  497. " . mines_dropdown(NULL, "mine") . "<br />
  498. <input type='submit' value='Edit Mine'>
  499. ";
  500. }
  501. }
  502. function delmine()
  503. {
  504. global $db;
  505. if (isset($_POST['mine']))
  506. {
  507. $mine=(isset($_POST['mine']) && is_numeric($_POST['mine'])) ? abs(intval($_POST['mine'])) : '';
  508. if ($db->num_rows($db->query("SELECT * FROM `tmg_mines_data` WHERE `mine_id` = {$mine}")) == 0)
  509. {
  510. echo "The mine does not exist, or has been already deleted.";
  511. }
  512. else
  513. {
  514. $db->query("DELETE FROM `tmg_mines_data` WHERE `mine_id` = {$mine}");
  515. echo "The mine has been deleted successfully.";
  516. stafflog_add("Deleted a mine");
  517. }
  518. }
  519. else
  520. {
  521. echo "Select a mine to delete.<br />
  522. <form method='post'>
  523. <input type='hidden' name='step' value='1'>
  524. " . mines_dropdown(NULL, "mine") . "<br />
  525. <input type='submit' value='Delete Mine (No verification, be 100% sure)'>
  526. ";
  527. }
  528. }
  529. function mines_dropdown($connection, $ddname = "mine", $selected = -1)
  530. {
  531. global $db;
  532. $ret = "<select name='$ddname' type='dropdown'>";
  533. $q =
  534. $db->query(
  535. "SELECT `mine_id`, `mine_location`, `mine_level`
  536. FROM `tmg_mines_data`
  537. ORDER BY `mine_level` ASC");
  538. if ($selected == -1)
  539. {
  540. $first = 0;
  541. }
  542. else
  543. {
  544. $first = 1;
  545. }
  546. while ($r = $db->fetch_row($q))
  547. {
  548. $CityName=$db->fetch_single($db->query("SELECT `cityname` FROM `cities` WHERE `cityid` = {$r['mine_location']}"));
  549. $ret .= "\n<option value='{$r['mine_id']}'";
  550. if ($selected == $r['mine_id'] || $first == 0)
  551. {
  552. $ret .= " selected='selected'";
  553. $first = 1;
  554. }
  555. $ret .= ">{$CityName} - Level {$r['mine_level']}</option>";
  556. }
  557. $db->free_result($q);
  558. $ret .= "\n</select>";
  559. return $ret;
  560. }
  561. $h->endpage();
Add Comment
Please, Sign In to add comment