From: <rav...@us...> - 2011-12-26 23:17:32
|
Revision: 7914 http://planeshift.svn.sourceforge.net/planeshift/?rev=7914&view=rev Author: ravna-ps Date: 2011-12-26 23:17:26 +0000 (Mon, 26 Dec 2011) Log Message: ----------- Added functionality to create tribes. Added functionality to delete tribes along with all associated sc_tribe_* and tribe_members data. Modified Paths: -------------- www/webconsole-new/tribes/listtribes.php Modified: www/webconsole-new/tribes/listtribes.php =================================================================== --- www/webconsole-new/tribes/listtribes.php 2011-12-26 09:33:06 UTC (rev 7913) +++ www/webconsole-new/tribes/listtribes.php 2011-12-26 23:17:26 UTC (rev 7914) @@ -56,12 +56,48 @@ echo '<p><input type="hidden" name="id" value="'.$row['id'].'" />'; echo '<input type="submit" name="commit" value="Edit" /></p>'; echo '</form>'; - + if (checkaccess('npcs', 'delete')) + { + echo '<form action="./index.php?do=edittribes" method="post">'; + echo '<div><input type="hidden" name="id" value="'.$row['id'].'" />'; + echo '<input type="submit" name="commit" value="Delete" /></div>'; + echo '</form>'; + } echo '</td>'; } echo '</tr>'; } echo '</table>'; + if (checkaccess('npcs', 'create')) + { + echo '<br /><hr />'; + echo '<p>Create New Tribe: </p>'; + echo '<form action="./index.php?do=edittribes" method="post">'; + echo '<table border="1">'; + echo '<tr><th>Field</th><th>Value</th></tr>'; + echo '<tr><td>Name</td><td><input type="text" name="name" /></td></tr>'; + $sectors = PrepSelect('sectorid'); + echo '<tr><td>Home Sector</td><td>'.DrawSelectBox('sectorid', $sectors, 'home_sector_id', '').'</td></tr>'; + echo '<tr><td>Home X</td><td><input type="text" name="home_x" /></td></tr>'; + echo '<tr><td>Home Y</td><td><input type="text" name="home_y" /></td></tr>'; + echo '<tr><td>Home Z</td><td><input type="text" name="home_z" /></td></tr>'; + echo '<tr><td>Home Radius</td><td><input type="text" name="home_radius" /></td></tr>'; + echo '<tr><td>Max Size</td><td><input type="text" name="max_size" /></td></tr>'; + echo '<tr><td>Resource Name</td><td><input type="text" name="wealth_resource_name" /></td></tr>'; + echo '<tr><td>Resource Nick</td><td><input type="text" name="wealth_resource_nick" /></td></tr>'; + echo '<tr><td>Resource Area</td><td><input type="text" name="wealth_resource_area" /></td></tr>'; + echo '<tr><td>Gather Need</td><td><input type="text" name="wealth_gather_need" /></td></tr>'; + echo '<tr><td>Resource Growth</td><td><input type="text" name="wealth_resource_growth" /></td></tr>'; + echo '<tr><td>Resource Growth Active</td><td><input type="text" name="wealth_resource_growth_active" /></td></tr>'; + echo '<tr><td>Resource Growth Active Limit</td><td><input type="text" name="wealth_resource_growth_active_limit" /></td></tr>'; + echo '<tr><td>Reproduction Cost</td><td><input type="text" name="reproduction_cost" /></td></tr>'; + echo '<tr><td>NPC Idle Behavior</td><td><input type="text" name="npc_idle_behavior" /></td></tr>'; + $tribe_recipe = PrepSelect('tribe_recipe'); + echo '<tr><td>Tribal Recipe</td><td>'.DrawSelectBox('tribe_recipe', $tribe_recipe, 'tribal_recipe', '').'</td></tr>'; + echo '<tr><td colspan="2"><input type="submit" name="commit" value="Create Tribe" /></td></tr>'; + echo '</table>'; + echo '</form>'; + } } else { @@ -82,10 +118,95 @@ return; } - if ($_POST['commit'] == 'Edit') + if ($_POST['commit'] == 'Create Tribe') { + if (!checkaccess('npcs', 'create')) + { + echo '<p class="error">You are not authorized to use these functions</p>'; + return; + } + $name = mysql_real_escape_string($_POST['name']); + $home_sector_id = mysql_real_escape_string($_POST['home_sector_id']); + $home_x = mysql_real_escape_string($_POST['home_x']); + $home_y = mysql_real_escape_string($_POST['home_y']); + $home_z = mysql_real_escape_string($_POST['home_z']); + $home_radius = mysql_real_escape_string($_POST['home_radius']); + $max_size = mysql_real_escape_string($_POST['max_size']); + $wealth_resource_name = mysql_real_escape_string($_POST['wealth_resource_name']); + $wealth_resource_nick = mysql_real_escape_string($_POST['wealth_resource_nick']); + $wealth_resource_area = mysql_real_escape_string($_POST['wealth_resource_area']); + $wealth_gather_need = mysql_real_escape_string($_POST['wealth_gather_need']); + $wealth_resource_growth = mysql_real_escape_string($_POST['wealth_resource_growth']); + $wealth_resource_growth_active = mysql_real_escape_string($_POST['wealth_resource_growth_active']); + $wealth_resource_growth_active_limit = mysql_real_escape_string($_POST['wealth_resource_growth_active_limit']); + $reproduction_cost = mysql_real_escape_string($_POST['reproduction_cost']); + $npc_idle_behavior = mysql_real_escape_string($_POST['npc_idle_behavior']); + $tribal_recipe = mysql_real_escape_string($_POST['tribal_recipe']); + $query = "INSERT INTO tribes SET name='$name', home_sector_id='$home_sector_id', home_x='$home_x', home_y='$home_y', home_z='$home_z', home_radius='$home_radius', max_size='$max_size', wealth_resource_name='$wealth_resource_name', wealth_resource_nick='$wealth_resource_nick', wealth_resource_area='$wealth_resource_area', wealth_gather_need='$wealth_gather_need', wealth_resource_growth='$wealth_resource_growth', wealth_resource_growth_active='$wealth_resource_growth_active', wealth_resource_growth_active_limit='$wealth_resource_growth_active_limit', reproduction_cost='$reproduction_cost', npc_idle_behavior='$npc_idle_behavior', tribal_recipe='$tribal_recipe'"; + mysql_query2($query); + echo '<p class="error">Tribe Successfully Created</p>'; + unset($_POST); + listtribes(); + return; + } + else if ($_POST['commit'] == 'Delete') + { + if (!checkaccess('npcs', 'delete')) + { + echo '<p class="error">You are not authorized to use these functions</p>'; + return; + } if (!isset($_POST['id']) || !is_numeric($_POST['id'])) { + echo '<p class="error">Invalid ID, cannot delete.</p>'; + return; + } + $id = mysql_real_escape_string($_POST['id']); + $query = "SELECT name FROM tribes WHERE id='$id'"; + $result = mysql_query2($query); + $row = mysql_fetch_array($result); + echo '<p>You are about to delete the tribe named '.$row['name'].' id('.$id.') and *all* associated assets, knowledge, memories, resources and members.<br />'; + echo 'This action is permanent and can not be undone.</p>'; + echo '<form action="./index.php?do=edittribes" method="post">'; + echo '<p><input type="hidden" name="id" value="'.$id.'" /><input type="submit" name="commit" value="Confirm Delete" /></p>'; + echo '</form>'; + } + else if ($_POST['commit'] == 'Confirm Delete') + { + if (!checkaccess('npcs', 'delete')) + { + echo '<p class="error">You are not authorized to use these functions</p>'; + return; + } + if (!isset($_POST['id']) || !is_numeric($_POST['id'])) + { + echo '<p class="error">Invalid ID, cannot delete.</p>'; + return; + } + + $id = mysql_real_escape_string($_POST['id']); + $query = "DELETE FROM sc_tribe_assets WHERE tribe_id='$id'"; + mysql_query2($query); + $query = "DELETE FROM sc_tribe_knowledge WHERE tribe_id='$id'"; + mysql_query2($query); + $query = "DELETE FROM sc_tribe_memories WHERE tribe_id='$id'"; + mysql_query2($query); + $query = "DELETE FROM sc_tribe_resources WHERE tribe_id='$id'"; + mysql_query2($query); + $query = "DELETE FROM tribe_members WHERE tribe_id='$id'"; + mysql_query2($query); + + $query = "DELETE FROM tribes WHERE id='$id' LIMIT 1"; + mysql_query2($query); + echo '<p class="error">Tribe With ID '.$id.' And All Associated Data Successfully Deleted</p>'; + unset($_POST); + listtribes(); + return; + } + else if ($_POST['commit'] == 'Edit') + { + if (!isset($_POST['id']) || !is_numeric($_POST['id'])) + { echo '<p class="error">Invalid ID, cannot edit.</p>'; return; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |