<?
include 'config.php';
include 'func.php';
head();
ban();
aut();

echo head . 'Корсары' . div . katalog;
####################Запись онлайна##################
mysql_query("UPDATE `profile` SET `online` = 'korsar_a' WHERE `id` = '".$id_session."'");
####################################################
If (!isset($_GET['mod']) || !preg_match("!^[a-zA-Z0-9_]+$!i",$_GET['mod'])) $mod=false; else $mod=$_GET['mod'];

switch ($mod) {


case 'city_add':

If (!isset($_GET['id']) || !preg_match("!^[0-9]+$!i",$_GET['id'])) $id=false; else $id=$_GET['id'];

if ( $id != false) $city_info = mysql_fetch_array ( mysql_query ("SELECT * FROM korsar_city WHERE id='" . $id . "'"));

If (!isset($_POST['ok']) || !preg_match("!^[a-zA-Z0-9_]+$!i",$_POST['ok'])) $ok=false; else $ok=$_POST['ok'];
if ( $ok == 'ok' ) {

If (!isset($_POST['id']) || !preg_match("!^[0-9]+$!i",$_POST['id'])) $id=false; else $id=$_POST['id'];

if ( $id != false ) {

mysql_query( "UPDATE `korsar_city` SET `name` = '$_POST[name]', `distance` = '$_POST[distance]', `sale_tree` = '$_POST[sale_tree]', `purchase_tree` = '$_POST[purchase_tree]', `sale_wood` = '$_POST[sale_wood]', `purchase_wood` = '$_POST[purchase_wood]', `sale_iron` = '$_POST[sale_iron]', `purchase_iron` = '$_POST[purchase_iron]', `sale_fabric` = '$_POST[sale_fabric]', `purchase_fabric` = '$_POST[purchase_fabric]', `sale_silver` = '$_POST[sale_silver]', `purchase_silver` = '$_POST[purchase_silver]', `sale_charcoal` = '$_POST[sale_charcoal]', `purchase_charcoal` = '$_POST[purchase_charcoal]' WHERE `id` = '$id'");
echo '<b>Форт отредактирован</b><br/>';

} else {

mysql_query( "INSERT INTO `korsar_city` SET `name` = '$_POST[name]', `distance` = '$_POST[distance]', `sale_tree` = '$_POST[sale_tree]', `purchase_tree` = '$_POST[purchase_tree]', `sale_wood` = '$_POST[sale_wood]', `purchase_wood` = '$_POST[purchase_wood]', `sale_iron` = '$_POST[sale_iron]', `purchase_iron` = '$_POST[purchase_iron]', `sale_fabric` = '$_POST[sale_fabric]', `purchase_fabric` = '$_POST[purchase_fabric]', `sale_silver` = '$_POST[sale_silver]', `purchase_silver` = '$_POST[purchase_silver]', `sale_charcoal` = '$_POST[sale_charcoal]', `purchase_charcoal` = '$_POST[purchase_charcoal]'");
echo '<b>Форт добавлен</b><br/>';
}

} 
echo "
<form action='?mod=city_add' method='post'>
<b>Название:</b> <br />
<input type='text' name='name' value='$city_info[name]' maxlength='30' /> <br />

<b>Растояние от начала:</b> <br />
<input type='text' name='distance' value='$city_info[distance]' maxlength='30' /> <br />

<b>Дерево</b> <br />
<small>Продажа</small> <br />
<input type='text' name='sale_tree' value='$city_info[sale_tree]' maxlength='30' /> <br />
<small>Покупка</small> <br />
<input type='text' name='purchase_tree' value='$city_info[purchase_tree]' maxlength='30' /> <br />

<b>Еда</b> <br />
<small>Продажа</small> <br />
<input type='text' name='sale_wood' value='$city_info[sale_wood]' maxlength='30' /> <br />
<small>Покупка</small> <br />
<input type='text' name='purchase_wood' value='$city_info[purchase_wood]' maxlength='30' /> <br />

<b>Железо</b> <br />
<small>Продажа</small> <br />
<input type='text' name='sale_iron' value='$city_info[sale_iron]' maxlength='30' /> <br />
<small>Покупка</small> <br />
<input type='text' name='purchase_iron' value='$city_info[purchase_iron]' maxlength='30' /> <br />

<b>Уголь</b> <br />
<small>Продажа</small> <br />
<input type='text' name='sale_fabric' value='$city_info[sale_fabric]' maxlength='30' /> <br />
<small>Покупка</small> <br />
<input type='text' name='purchase_fabric' value='$city_info[purchase_fabric]' maxlength='30' /> <br />

<b>Ткань</b> <br />
<small>Продажа</small> <br />
<input type='text' name='sale_silver' value='$city_info[sale_silver]' maxlength='30' /> <br />
<small>Покупка</small> <br />
<input type='text' name='purchase_silver' value='$city_info[purchase_silver]' maxlength='30' /> <br />

<b>Серебро</b> <br />
<small>Продажа</small> <br />
<input type='text' name='sale_charcoal' value='$city_info[sale_charcoal]' maxlength='30' /> <br />
<small>Покупка</small> <br />
<input type='text' name='purchase_charcoal' value='$city_info[purchase_charcoal]' maxlength='30' /> <br />

<input type='hidden' name='ok' value='ok' />
<input type='hidden' name='id' value='$id' />

<input type='submit' value='Добавить' /></form>     
<br /> <a href='?mod=city'>Назад</a> <br />";
break;

case 'city':

If (!isset($_GET['id']) || !preg_match("!^[0-9]+$!i",$_GET['id'])) $id=false; else $id=$_GET['id'];

if ( $id != false ) {
mysql_query( "DELETE FROM `korsar_city` WHERE `id` = '$id'" ); 
echo "<b>Форт пот ID $id удален</b> <br />";
}

echo "<a href='?mod=city_add'>Добавить форт</a> <br /> <br /><b>Список фортов:</b> <br />";
$city = mysql_query("SELECT * FROM `korsar_city`");
while ( $city_info = mysql_fetch_array ( $city ) ) 
{
echo "".win2utf($city_info[name])." <b>[</b><a href='?mod=city&id=$city_info[id]'>del</a> <b>/</b> <a href='?mod=city_add&id=$city_info[id]'>red</a><b>]</b> <br />";
}
echo "<br /><a href='?'>Назад</a>";

break;

case 'ship_add':

If (!isset($_GET['id']) || !preg_match("!^[0-9]+$!i",$_GET['id'])) $id=false; else $id=$_GET['id'];

if ( $id != false) $ship_info = mysql_fetch_array ( mysql_query ("SELECT * FROM korsar_ship WHERE id='" . $id . "'"));

If (!isset($_POST['ok']) || !preg_match("!^[a-zA-Z0-9_]+$!i",$_POST['ok'])) $ok=false; else $ok=$_POST['ok'];
if ( $ok == 'ok' ) {

If (!isset($_POST['id']) || !preg_match("!^[0-9]+$!i",$_POST['id'])) $id=false; else $id=$_POST['id'];

if ( $id != false ) {

mysql_query( "UPDATE `korsar_ship` SET `name` = '$_POST[name]', `scrin` = '$_POST[scrin]', `number_of_guns` = '$_POST[number_of_guns]', `strength` = '$_POST[strength]', `capacity` = '$_POST[capacity]', `speed` = '$_POST[speed]', `cost` = '$_POST[cost]', `lvl` = '$_POST[lvl]' WHERE `id` = '$id'");
echo '<b>Корабль изменен</b> <br />';

} else {

mysql_query( "INSERT INTO `korsar_ship` SET `name` = '$_POST[name]', `scrin` = '$_POST[scrin]', `number_of_guns` = '$_POST[number_of_guns]', `strength` = '$_POST[strength]', `capacity` = '$_POST[capacity]', `speed` = '$_POST[speed]', `cost` = '$_POST[cost]', `lvl` = '$_POST[lvl]'");
echo "<b>Корабль добавлен</b> <br  />";

}
}
 
echo "

<form action='?mod=ship_add' method='post'>

Название: <br />
<input type='text' name='name' value='$ship_info[name]' maxlength='30' /> <br />
Скрин: <br />
<input type='text' name='scrin' value='$ship_info[scrin]' maxlength='30' /> <br />
Колличество орудий: <br />
<input type='text' name='number_of_guns' value='$ship_info[number_of_guns]' maxlength='30' /> <br />
Прочность: <br />
<input type='text' name='strength' value='$ship_info[strength]' maxlength='30' /> <br />
Вместимость: <br />
<input type='text' name='capacity' value='$ship_info[capacity]' maxlength='30' /> <br />
Скорость: <br />
<input type='text' name='speed' value='$ship_info[speed]' maxlength='30' /> <br />
Стоимость: <br />
<input type='text' name='cost' value='$ship_info[cost]' maxlength='30' /> <br />
Ранг: <br />
<input type='text' name='lvl' value='$ship_info[lvl]' maxlength='30' /> <br />

<input type='hidden' name='ok' value='ok' />
<input type='hidden' name='id' value='$id' />

<input type='submit' value='Добавить'/></form>     
 <br /><a href='?mod=ship'>Назад</a> <br />

";

break;

case 'ship':

If (!isset($_GET['id']) || !preg_match("!^[0-9]+$!i",$_GET['id'])) $id=false; else $id=$_GET['id'];

if ( $id != false ) {
mysql_query( "DELETE FROM `korsar_ship` WHERE id = '$id'" ); 
echo "<b>Корабль пот ID $id удален</b> <br />";
}

echo "<a href='?mod=ship_add'>Добавить корабль</a> <br /> <br /><b>Список кораблей:</b> <br />";
$ship = mysql_query("SELECT * FROM `korsar_ship`");
while ( $ship_info = mysql_fetch_array ( $ship ) ) 
{
echo "".win2utf($ship_info[name])." <b>[</b><a href='?mod=ship&id=$ship_info[id]'>del</a> <b>/</b> <a href='?mod=ship_add&id=$ship_info[id]'>red</a><b>]</b> <br />";
}
echo " <br /><a href='?'>Назад</a> <br />";

break;

case 'settings':

If (!isset($_POST['ok']) || !preg_match("!^[a-zA-Z0-9_]+$!i",$_POST['ok'])) $ok=false; else $ok=$_POST['ok'];
if ( $ok == 'ok' ) {
mysql_query( "UPDATE `korsar_settings` SET `initial_gold` = '$_POST[initial_gold]', `maps_gold` = '$_POST[maps_gold]', `treasures_time` = '$_POST[treasures_time]', `fishing_time` = '$_POST[fishing_time]', `pirate_time` = '$_POST[pirate_time]', `karma_time` = '$_POST[karma_time]', `attack_time` = '$_POST[attack_time]', `bank` = '$_POST[bank]', `gun_gold` = '$_POST[gun_gold]' WHERE `id` = '1'");
echo '<b>Настройки изменены</b> <br />';
}

$settings = mysql_fetch_array ( mysql_query ("SELECT * FROM korsar_settings LIMIT 1"));

echo "

<form action='?mod=settings' method='post'>

Кол начального золота: <br />
<input type='text' name='initial_gold' value='$settings[initial_gold]' maxlength='30' /> <br />
Стоимость карты сокровищь: <br />
<input type='text' name='maps_gold' value='$settings[maps_gold]'' maxlength='30' /> <br />
Время поиска сокровищ [в минутах]: <br />
<input type='text' name='treasures_time' value='$settings[treasures_time]' maxlength='30' /> <br />
Время рыбалки [в минутах]: <br />
<input type='text' name='fishing_time' value='$settings[fishing_time]' maxlength='30' /> <br />
Время перерыва между пиратством [в часах]: <br />
<input type='text' name='pirate_time' value='$settings[pirate_time]' maxlength='30' /> <br />
Время минимальной кармы [в часах]: <br />
<input type='text' name='karma_time' value='$settings[karma_time]' maxlength='30' /> <br />
Время отдыха после обороны [в часах]: <br />
<input type='text' name='attack_time' value='$settings[attack_time]' maxlength='30' /> <br />
Процент в банке: <br />
<input type='text' name='bank' value='$settings[bank]' maxlength='30' /> <br />
Стоимость орудия: <br />
<input type='text' name='gun_gold' value='$settings[gun_gold]' maxlength='30' /> <br />

<input type='hidden' name='ok' value='ok' />

<input type='submit' value='Изменить' /></form>     
 <br /><a href='?'>Назад</a> <br />

";
break;


default :
echo "
<a href='?mod=city'>Управление фортами</a> <br />
<a href='?mod=ship'>Управление кораблями</a> <br />
<a href='?mod=settings'>Общие настройки</a> <br />
<a href='/korsar.php'>В игру</a>";
break;

}


navig();
foot();
?>