Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- require('sglobals.php');
- echo "<h2>Mining</h2><hr />";
- if (!isset($_GET['action']))
- {
- $_GET['action'] = '';
- }
- switch ($_GET['action'])
- {
- case 'addmine':
- addmine();
- break;
- case 'editmine':
- editmine();
- break;
- case 'delmine':
- delmine();
- break;
- default:
- echo '404'; die($h->endpage());
- break;
- }
- function addmine()
- {
- global $db,$ir,$userid;
- if (isset($_POST['level']) && (!empty($_POST['level'])))
- {
- var_dump($_POST);
- $level=(isset($_POST['level']) && is_numeric($_POST['level'])) ? abs(intval($_POST['level'])) : '';
- $power=(isset($_POST['power']) && is_numeric($_POST['power'])) ? abs(intval($_POST['power'])) : '';
- $iq=(isset($_POST['iq']) && is_numeric($_POST['iq'])) ? abs(intval($_POST['iq'])) : '';
- $pick=(isset($_POST['pick']) && is_numeric($_POST['pick'])) ? abs(intval($_POST['pick'])) : '';
- $city=(isset($_POST['city']) && is_numeric($_POST['city'])) ? abs(intval($_POST['city'])) : '';
- $cflakes=(isset($_POST['cflakes']) && is_numeric($_POST['cflakes'])) ? abs(intval($_POST['cflakes'])) : '';
- $cflakesmin=(isset($_POST['cflakemin']) && is_numeric($_POST['cflakemin'])) ? abs(intval($_POST['cflakemin'])) : '';
- $cflakesmax=(isset($_POST['cflakemax']) && is_numeric($_POST['cflakemax'])) ? abs(intval($_POST['cflakemax'])) : '';
- $sflakes=(isset($_POST['sflakes']) && is_numeric($_POST['sflakes'])) ? abs(intval($_POST['sflakes'])) : '';
- $sflakesmin=(isset($_POST['sflakemin']) && is_numeric($_POST['sflakemin'])) ? abs(intval($_POST['sflakemin'])) : '';
- $sflakesmax=(isset($_POST['sflakemax']) && is_numeric($_POST['sflakemax'])) ? abs(intval($_POST['sflakemax'])) : '';
- $gflakes=(isset($_POST['gflakes']) && is_numeric($_POST['gflakes'])) ? abs(intval($_POST['gflakes'])) : '';
- $gflakesmin=(isset($_POST['gflakemin']) && is_numeric($_POST['gflakemin'])) ? abs(intval($_POST['gflakemin'])) : '';
- $gflakesmax=(isset($_POST['gflakemax']) && is_numeric($_POST['gflakemax'])) ? abs(intval($_POST['gflakemax'])) : '';
- $gem=(isset($_POST['gem']) && is_numeric($_POST['gem'])) ? abs(intval($_POST['gem'])) : '';
- if (empty($level) || empty($iq) || empty($pick) || empty($city) || empty($cflakes)
- || empty($cflakesmin) || empty($cflakesmax) || empty($gflakes) || empty($gflakesmin)
- || empty($gflakesmax) || empty($sflakesmin) || empty($sflakesmax) || empty($sflakes) || empty($gem) || empty($power))
- {
- echo "None of the inputs in the form can be empty.";
- }
- elseif ($level < 1)
- {
- echo "You need the level to be greater than 0.";
- }
- elseif ($cflakesmin == 0 || $cflakesmax == 0 || $gflakesmin == 0 ||
- $gflakesmax == 0 || $sflakesmin == 0 || $sflakesmax == 0)
- {
- echo "You cannot specify a minimum or maximum output of zero.";
- }
- elseif ($cflakesmin >= $cflakesmax || $sflakesmin >= $sflakesmax || $gflakesmin >= $gflakesmax)
- {
- echo "The minimum output cannot be equal to or larger than the output.";
- }
- else
- {
- $CitySQL=($db->query("SELECT `cityname` FROM `cities` WHERE `cityid` = {$city}"));
- $PickSQL=($db->query("SELECT `itmname` FROM `items` WHERE `itmid` = {$pick}"));
- $CFSQL=($db->query("SELECT `itmname` FROM `items` WHERE `itmid` = {$cflakes}"));
- $SFSQL=($db->query("SELECT `itmname` FROM `items` WHERE `itmid` = {$sflakes}"));
- $GFSQL=($db->query("SELECT `itmname` FROM `items` WHERE `itmid` = {$gflakes}"));
- $GemSQL=($db->query("SELECT `itmname` FROM `items` WHERE `itmid` = {$gem}"));
- if ($db->num_rows($CitySQL) == 0)
- {
- echo "The city you specified appears to not exist.";
- }
- elseif ($db->num_rows($PickSQL) == 0)
- {
- echo "The pickaxe you chose appears to not exist as an in-game item.";
- }
- elseif ($db->num_rows($CFSQL) == 0)
- {
- echo "The item you chose for Output #1 appears to not exist as an in-game item.";
- }
- elseif ($db->num_rows($SFSQL) == 0)
- {
- echo "The item you chose for Output #2 appears to not exist as an in-game item.";
- }
- elseif ($db->num_rows($GFSQL) == 0)
- {
- echo "The item you chose for Output #3 appears to not exist as an in-game item.";
- }
- elseif ($db->num_rows($GemSQL) == 0)
- {
- echo "The item you chose as the mine's gem does not exist in-game.";
- }
- else
- {
- $db->query("INSERT INTO `tmg_mines_data`
- (`mine_id`, `mine_location`, `mine_level`,
- `mine_copper_min`, `mine_copper_max`,
- `mine_silver_min`, `mine_silver_max`,
- `mine_gold_min`, `mine_gold_max`,
- `mine_pickaxe`, `mine_iq`,
- `mine_power_use`, `mine_copper_item`,
- `mine_silver_item`, `mine_gold_item`,
- `mine_gem_item`)
- VALUES
- (NULL, '{$city}', '{$level}', '{$cflakesmin}',
- '{$cflakesmax}', '{$sflakesmin}', '{$sflakesmax}',
- '{$gflakesmin}', '{$gflakesmax}', '{$pick}', '{$iq}',
- '{$power}', '{$cflakes}', '{$sflakes}', '{$gflakes}',
- '{$gem}');");
- echo "The mine has been created successfully.";
- $citynamelog=$db->fetch_single($CitySQL);
- stafflog_add("Added a a mine in {$citynamelog}.");
- }
- }
- }
- else
- {
- echo "Use this form to add a mine into the game. The mine's name will
- be named after the city its placed in. If you have a specific naming
- scheme, you'll likely want to edit the code to allow it.<br />
- <table border='1' padding='1' width='100%'>
- <form method='post'>
- <tr>
- <th>
- Mine's Location
- </th>
- <td>
- " . location_dropdown(NULL, "city") . "
- </td>
- </tr>
- <tr>
- <th>
- Minimum Mining Level
- </th>
- <td>
- <input type='number' name='level' min='1' required='1'>
- </td>
- </tr>
- <tr>
- <th>
- Minimum IQ Required
- </th>
- <td>
- <input type='number' name='iq' min='1' required='1'>
- </td>
- </tr>
- <tr>
- <th>
- Power Exhaustion Per Attempt
- </th>
- <td>
- <input type='number' name='power' min='1' required='1'>
- </td>
- </tr>
- <tr>
- <th>
- Required Pickaxe
- </th>
- <td>
- " . item_dropdown(NULL, "pick") . "
- </td>
- </tr>
- <tr>
- <th>
- Output #1
- </th>
- <td>
- " . item_dropdown(NULL, "cflakes") . "
- </td>
- </tr>
- <tr>
- <th>
- Output #2
- </th>
- <td>
- " . item_dropdown(NULL, "sflakes") . "
- </td>
- </tr>
- <tr>
- <th>
- Output #3
- </th>
- <td>
- " . item_dropdown(NULL, "gflakes") . "
- </td>
- </tr>
- <tr>
- <th>
- Gem Item
- </th>
- <td>
- " . item_dropdown(NULL, "gem") . "
- </td>
- </tr>
- <tr>
- <th>
- Output #1's Minimum Output
- </th>
- <td>
- <input type='number' name='cflakemin' min='1' required='1'>
- </td>
- </tr>
- <tr>
- <th>
- Output #1's Maximum Output
- </th>
- <td>
- <input type='number' name='cflakemax' min='2' required='1'>
- </td>
- </tr>
- <tr>
- <th>
- Output #2's Minimum Output
- </th>
- <td>
- <input type='number' name='sflakemin' min='1' required='1'>
- </td>
- </tr>
- <tr>
- <th>
- Output #2's Maximum Output
- </th>
- <td>
- <input type='number' name='sflakemax' min='2' required='1'>
- </td>
- </tr>
- <tr>
- <th>
- Output #3's Minimum Output
- </th>
- <td>
- <input type='number' name='gflakemin' min='1' required='1'>
- </td>
- </tr>
- <tr>
- <th>
- Output #3's Maximum Output
- </th>
- <td>
- <input type='number' name='gflakemax' min='2' required='1'>
- </td>
- </tr>
- <tr>
- <td colspan='2'>
- <center><input type='submit' value='Add Mine'></center>
- </td>
- </tr>
- </form>
- </table>";
- }
- }
- function editmine()
- {
- if (!isset($_POST['step']))
- {
- $_POST['step'] = 0;
- }
- global $db,$ir,$userid;
- if (isset($_POST['level']) && (!empty($_POST['level'])) && $_POST['step'] == 2)
- {
- $mine=(isset($_POST['mineid']) && is_numeric($_POST['mineid'])) ? abs(intval($_POST['mineid'])) : '';
- $level=(isset($_POST['level']) && is_numeric($_POST['level'])) ? abs(intval($_POST['level'])) : '';
- $power=(isset($_POST['power']) && is_numeric($_POST['power'])) ? abs(intval($_POST['power'])) : '';
- $iq=(isset($_POST['iq']) && is_numeric($_POST['iq'])) ? abs(intval($_POST['iq'])) : '';
- $pick=(isset($_POST['pick']) && is_numeric($_POST['pick'])) ? abs(intval($_POST['pick'])) : '';
- $city=(isset($_POST['city']) && is_numeric($_POST['city'])) ? abs(intval($_POST['city'])) : '';
- $cflakes=(isset($_POST['cflakes']) && is_numeric($_POST['cflakes'])) ? abs(intval($_POST['cflakes'])) : '';
- $cflakesmin=(isset($_POST['cflakemin']) && is_numeric($_POST['cflakemin'])) ? abs(intval($_POST['cflakemin'])) : '';
- $cflakesmax=(isset($_POST['cflakemax']) && is_numeric($_POST['cflakemax'])) ? abs(intval($_POST['cflakemax'])) : '';
- $sflakes=(isset($_POST['sflakes']) && is_numeric($_POST['sflakes'])) ? abs(intval($_POST['sflakes'])) : '';
- $sflakesmin=(isset($_POST['sflakemin']) && is_numeric($_POST['sflakemin'])) ? abs(intval($_POST['sflakemin'])) : '';
- $sflakesmax=(isset($_POST['sflakemax']) && is_numeric($_POST['sflakemax'])) ? abs(intval($_POST['sflakemax'])) : '';
- $gflakes=(isset($_POST['gflakes']) && is_numeric($_POST['gflakes'])) ? abs(intval($_POST['gflakes'])) : '';
- $gflakesmin=(isset($_POST['gflakemin']) && is_numeric($_POST['gflakemin'])) ? abs(intval($_POST['gflakemin'])) : '';
- $gflakesmax=(isset($_POST['gflakemax']) && is_numeric($_POST['gflakemax'])) ? abs(intval($_POST['gflakemax'])) : '';
- $gem=(isset($_POST['gem']) && is_numeric($_POST['gem'])) ? abs(intval($_POST['gem'])) : '';
- if (empty($level) || empty($iq) || empty($pick) || empty($city) || empty($cflakes)
- || empty($cflakesmin) || empty($cflakesmax) || empty($gflakes) || empty($gflakesmin)
- || empty($gflakesmax) || empty($sflakesmin) || empty($sflakesmax) || empty($sflakes)
- || empty($gem) || empty($power) || empty($mine))
- {
- echo "None of the inputs in the form can be empty.";
- }
- elseif ($level < 1)
- {
- echo "You need the level to be greater than 0.";
- }
- elseif ($cflakesmin == 0 || $cflakesmax == 0 || $gflakesmin == 0 ||
- $gflakesmax == 0 || $sflakesmin == 0 || $sflakesmax == 0)
- {
- echo "You cannot specify a minimum or maximum output of zero.";
- }
- elseif ($cflakesmin >= $cflakesmax || $sflakesmin >= $sflakesmax || $gflakesmin >= $gflakesmax)
- {
- echo "The minimum output cannot be equal to or larger than the output.";
- }
- else
- {
- $CitySQL=($db->query("SELECT `cityname` FROM `cities` WHERE `cityid` = {$city}"));
- $PickSQL=($db->query("SELECT `itmname` FROM `items` WHERE `itmid` = {$pick}"));
- $CFSQL=($db->query("SELECT `itmname` FROM `items` WHERE `itmid` = {$cflakes}"));
- $SFSQL=($db->query("SELECT `itmname` FROM `items` WHERE `itmid` = {$sflakes}"));
- $GFSQL=($db->query("SELECT `itmname` FROM `items` WHERE `itmid` = {$gflakes}"));
- $GemSQL=($db->query("SELECT `itmname` FROM `items` WHERE `itmid` = {$gem}"));
- if ($db->num_rows($CitySQL) == 0)
- {
- echo "The city you specified appears to not exist.";
- }
- elseif ($db->num_rows($PickSQL) == 0)
- {
- echo "The pickaxe you chose appears to not exist as an in-game item.";
- }
- elseif ($db->num_rows($CFSQL) == 0)
- {
- echo "The item you chose for Output #1 appears to not exist as an in-game item.";
- }
- elseif ($db->num_rows($SFSQL) == 0)
- {
- echo "The item you chose for Output #2 appears to not exist as an in-game item.";
- }
- elseif ($db->num_rows($GFSQL) == 0)
- {
- echo "The item you chose for Output #3 appears to not exist as an in-game item.";
- }
- elseif ($db->num_rows($GemSQL) == 0)
- {
- echo "The item you chose as the mine's gem does not exist in-game.";
- }
- else
- {
- $db->query("UPDATE `tmg_mines_data` SET `mine_location` = '{$city}', `mine_level` = '{$level}',
- `mine_copper_item` = '{$cflakes}', `mine_copper_max` = '{$cflakesmax}', `mine_copper_min` = '{$cflakesmin}',
- `mine_silver_item` = '{$sflakes}', `mine_silver_max` = '{$sflakesmax}', `mine_silver_min` = '{$sflakesmin}',
- `mine_gold_item` = '{$gflakes}', `mine_gold_max` = '{$gflakesmax}', `mine_gold_min` = '{$gflakesmin}',
- `mine_pickaxe` = '{$pick}', `mine_iq` = '{$iq}', `mine_gem_item` = '{$gem}', `mine_power_use` = '{$power}'
- WHERE `mine_id` = {$mine}");
- echo "The mine has been updated.";
- stafflog_add("Edited a mine.");
- }
- }
- }
- elseif ($_POST['step'] == 1)
- {
- $mine=(isset($_POST['mine']) && is_numeric($_POST['mine'])) ? abs(intval($_POST['mine'])) : '';
- if ($db->num_rows($db->query("SELECT * FROM `tmg_mines_data` WHERE `mine_id` = {$mine}")) == 0)
- {
- echo "The mine you selected does not exist.";
- }
- else
- {
- $mi=$db->fetch_row($db->query("SELECT * FROM `tmg_mines_data` WHERE `mine_id` = {$mine}"));
- echo "Editing an existing mine...<br />
- <table border='1' padding='1' width='100%'>
- <form method='post'>
- <input type='hidden' value='2' name='step'>
- <input type='hidden' value='{$mine}' name='mineid'>
- <tr>
- <th>
- Mine's Location
- </th>
- <td>
- " . location_dropdown(NULL, "city", $mi['mine_location']) . "
- </td>
- </tr>
- <tr>
- <th>
- Minimum Mining Level
- </th>
- <td>
- <input type='number' name='level' min='1' value='{$mi['mine_level']}' required='1'>
- </td>
- </tr>
- <tr>
- <th>
- Minimum IQ Required
- </th>
- <td>
- <input type='number' name='iq' min='1' value='{$mi['mine_iq']}' required='1'>
- </td>
- </tr>
- <tr>
- <th>
- Power Exhaustion Per Attempt
- </th>
- <td>
- <input type='number' name='power' min='1' value='{$mi['mine_power_use']}' required='1'>
- </td>
- </tr>
- <tr>
- <th>
- Required Pickaxe
- </th>
- <td>
- " . item_dropdown(NULL, "pick", $mi['mine_pickaxe']) . "
- </td>
- </tr>
- <tr>
- <th>
- Output #1
- </th>
- <td>
- " . item_dropdown(NULL, "cflakes", $mi['mine_copper_item']) . "
- </td>
- </tr>
- <tr>
- <th>
- Output #2
- </th>
- <td>
- " . item_dropdown(NULL, "sflakes", $mi['mine_silver_item']) . "
- </td>
- </tr>
- <tr>
- <th>
- Output #3
- </th>
- <td>
- " . item_dropdown(NULL, "gflakes", $mi['mine_gold_item']) . "
- </td>
- </tr>
- <tr>
- <th>
- Gem Item
- </th>
- <td>
- " . item_dropdown(NULL, "gem", $mi['mine_gem_item']) . "
- </td>
- </tr>
- <tr>
- <th>
- Output #1's Minimum Output
- </th>
- <td>
- <input type='number' name='cflakemin' value='{$mi['mine_copper_min']}' min='1' required='1'>
- </td>
- </tr>
- <tr>
- <th>
- Output #1's Maximum Output
- </th>
- <td>
- <input type='number' name='cflakemax' value='{$mi['mine_copper_max']}' min='2' required='1'>
- </td>
- </tr>
- <tr>
- <th>
- Output #2's Minimum Output
- </th>
- <td>
- <input type='number' name='sflakemin' value='{$mi['mine_silver_min']}' min='1' required='1'>
- </td>
- </tr>
- <tr>
- <th>
- Output #2's Maximum Output
- </th>
- <td>
- <input type='number' name='sflakemax' value='{$mi['mine_silver_max']}' min='2' required='1'>
- </td>
- </tr>
- <tr>
- <th>
- Output #3's Minimum Output
- </th>
- <td>
- <input type='number' name='gflakemin' value='{$mi['mine_gold_min']}' min='1' required='1'>
- </td>
- </tr>
- <tr>
- <th>
- Output #3's Maximum Output
- </th>
- <td>
- <input type='number' name='gflakemax' value='{$mi['mine_gold_max']}' min='2' required='1'>
- </td>
- </tr>
- <tr>
- <td colspan='2'>
- <center><input type='submit' value='Edit Mine'></center>
- </td>
- </tr>
- </form>
- </table>";
- }
- }
- else
- {
- echo "Select a mine to edit<br />
- <form method='post'>
- <input type='hidden' name='step' value='1'>
- " . mines_dropdown(NULL, "mine") . "<br />
- <input type='submit' value='Edit Mine'>
- ";
- }
- }
- function delmine()
- {
- global $db;
- if (isset($_POST['mine']))
- {
- $mine=(isset($_POST['mine']) && is_numeric($_POST['mine'])) ? abs(intval($_POST['mine'])) : '';
- if ($db->num_rows($db->query("SELECT * FROM `tmg_mines_data` WHERE `mine_id` = {$mine}")) == 0)
- {
- echo "The mine does not exist, or has been already deleted.";
- }
- else
- {
- $db->query("DELETE FROM `tmg_mines_data` WHERE `mine_id` = {$mine}");
- echo "The mine has been deleted successfully.";
- stafflog_add("Deleted a mine");
- }
- }
- else
- {
- echo "Select a mine to delete.<br />
- <form method='post'>
- <input type='hidden' name='step' value='1'>
- " . mines_dropdown(NULL, "mine") . "<br />
- <input type='submit' value='Delete Mine (No verification, be 100% sure)'>
- ";
- }
- }
- function mines_dropdown($connection, $ddname = "mine", $selected = -1)
- {
- global $db;
- $ret = "<select name='$ddname' type='dropdown'>";
- $q =
- $db->query(
- "SELECT `mine_id`, `mine_location`, `mine_level`
- FROM `tmg_mines_data`
- ORDER BY `mine_level` ASC");
- if ($selected == -1)
- {
- $first = 0;
- }
- else
- {
- $first = 1;
- }
- while ($r = $db->fetch_row($q))
- {
- $CityName=$db->fetch_single($db->query("SELECT `cityname` FROM `cities` WHERE `cityid` = {$r['mine_location']}"));
- $ret .= "\n<option value='{$r['mine_id']}'";
- if ($selected == $r['mine_id'] || $first == 0)
- {
- $ret .= " selected='selected'";
- $first = 1;
- }
- $ret .= ">{$CityName} - Level {$r['mine_level']}</option>";
- }
- $db->free_result($q);
- $ret .= "\n</select>";
- return $ret;
- }
- $h->endpage();
Add Comment
Please, Sign In to add comment