<?
# Автор движка: InstalScript
# vk.com/k.karamin  - Я Вк
# bymas.ru/id3741  - Я на бумасе
# Специально для обитателей bymas.ru
# Ток на бумасе можно найти моды для данного движка
require_once($_SERVER['DOCUMENT_ROOT']."/instalscript/game/inc/function.php");
head("Покупка танка",$uid); # Голова
echo logs();logn();

switch($is['1']){
default:
echo "
<div class='trnt-block'>
<div class='wrap1'><div class='wrap2'><div class='wrap3'><div class='wrap4'><div class='wrap5'><div class='wrap6'><div class='wrap7'><div class='wrap8'>
<div class='wrap-content'>";

echo "<form method = 'post' action = '/newstore/search/'>";
echo "<table>";
echo "
<td>
<select name='country' style = '
    border-radius: 4px;
    border: 1px solid rgb(255, 220, 32);
    width: 100%;
    height: 36px;
    background: #000;
    color: #fff;'
>
<option value='usa'>США</option>
<option value='ussr'>СССР</option>
<option value='china'>КИТАЙ</option>
<option value='japan'>ЯПОНИЯ</option>
<option value='france'>ФРАНЦИЯ</option>
<option value='germany'>ГЕРМАНИЯ</option>
<option value='britain'>ВЕЛИКОБРИТАНИЯ</option>
</select>
</td>
";
echo "<td>
<select name='type' style = '
    border-radius: 4px;
    border: 1px solid rgb(255, 220, 32);
    width: 100%;
    height: 36px;
    background: #000;
    color: #fff;'>
<option value='easy'>Легкие</option>
<option value='normal'>Средние</option>
<option value='hard'>Тяжелые</option>";

# <option value='sau'>САУ</option>
# <option value='pt-sau'>ПТ-САУ</option>

echo "</select></td>";
echo "</table>";
echo "<input type = 'submit'
style = '
background: black;
color: white;
border: 1px solid rgb(255, 220, 32);
border-radius: 4px;
width: 100%;
height: 39px;
'value = 'Поиск' >";
echo "</form>";


echo "</div>
</div></div></div></div></div></div></div></div>
</div>
";
break;
case'search':
echo $_POST['country']."</br>".$_POST['type'];
if(
$_POST['country']!= 'usa' &&
$_POST['country']!= 'ussr' &&
$_POST['country']!= 'china' &&
$_POST['country']!= 'japan' &&
$_POST['country']!= 'france' &&
$_POST['country']!= 'germany' &&
$_POST['country']!= 'britain' or
$_POST['type']!= 'easy' &&
$_POST['type']!= 'normal' &&
$_POST['type']!= 'hard'
){
logi("Подменна даных");
header("Location:".$_SERVER['HTTP_REFERER']."");
exit();
}else{
$_SESSION['country_stnk'] = check($_POST['country']);
$_SESSION['type_stnk'] = check($_POST['type']);
}
header("Location:/newstore/list/");
exit();
break;
case'list':
$country = check($_SESSION['country_stnk']);
$type = check($_SESSION['type_stnk']);

if($country == null or $type == null){
header("Location:/newstore/");
exit();
}

$count = mysql_result(mysql_query("SELECT COUNT(*) FROM  `tank` WHERE `type` = '".$type."' AND `country` = '".$country."' "),0);

if($count == '0'){
echo "Танков по данному запросу нет";
}else{

$str = '5'; # кол-во записей для вывода
$url = "/newstore/list"; # ссылка
$num = abs($is['2']); # текущая страница
$result = $count; # подсчёт

$tnk_q = mysql_query("SELECT * FROM `tank` WHERE `type` = '".$type."' AND `country` = '".$country."' ORDER BY `id` ASC LIMIT ".page($num,$str,$result).",$str ");

while($tnk = mysql_fetch_assoc($tnk_q)){
echo "<a class='simple-but border mb1' href = '/newstore/inf/".$tnk['id']."/'><span><span style = 'text-align: left;'>".$tnk['name']."</span></span></a>";
}
ppage($url,$num,$str,$result);
}


echo "<div class='bot'><a class='simple-but border mb2' href = '/newstore/'><span><span>Вернуться к поиску</span></span></a></div>";

echo "
</div>
</div></div></div></div></div></div></div></div>
</div>";




break;
case'inf':
$tnk = mysql_fetch_assoc(mysql_query("SELECT * FROM `tank` WHERE `id` = '".abs($is['2'])."' "));
if($tnk == null){
logi("Нечего ненайдено");
header("Location:/newstore/");
exit();
}


echo "

<div class='trnt-block'>
<div class='wrap1'><div class='wrap2'><div class='wrap3'><div class='wrap4'><div class='wrap5'><div class='wrap6'><div class='wrap7'><div class='wrap8'>
<div class='wrap-content'>";

if($user['rules'] == '10'){
if($is['3'] != 'edit'){
echo "<a class='simple-but border mb2' href = '/newstore/inf/".$tnk['id']."/edit/'><span><span>Изменить</span></span></a>";
}else{
echo "<a class='simple-but border mb2' href = '/newstore/inf/".$tnk['id']."/'><span><span>Скрыть админку</span></span></a>";
}

if($is['3'] == 'editgo'){

if(isset($_POST['name'])){
$name = check($_POST['name']);
mysql_query("UPDATE `tank` SET `name` = '".$name."' WHERE `id` = '".abs($tnk['id'])."' ")or die(mysql_error());
}
elseif(isset($_POST['level'])){
$level = check($_POST['level']);
if($level != 'I' && $level != 'II' && $level != 'III' && $level != 'IV' && $level != 'V' && $level != 'VI' && $level != 'VII' && $level != 'VIII' && $level != 'IX' && $level != 'X'){$level = 'I';}
mysql_query("UPDATE `tank` SET `level` = '".$level."' WHERE `id` = '".abs($tnk['id'])."' ")or die(mysql_error());
}
elseif(isset($_POST['type'])){
$type = check($_POST['type']);
if($type != 'easy' && $type != 'normal' && $type != 'hard' && $type != 'pt-sau' && $type != 'sau'){$type = 'easy';}
mysql_query("UPDATE `tank` SET `type` = '".$type."' WHERE `id` = '".abs($tnk['id'])."' ")or die(mysql_error());
}
elseif(isset($_POST['country'])){
$country = check($_POST['country']);
if($country != 'usa' && $country != 'ussr' && $country != 'china' && $country != 'japan' && $country != 'france' && $country != 'germany' && $country != 'britain' ){$country = 'ussr';}
mysql_query("UPDATE `tank` SET `country` = '".$country."' WHERE `id` = '".abs($tnk['id'])."' ")or die(mysql_error());
}
elseif(isset($_POST['ha']) or isset($_POST['hb']) or isset($_POST['ho']) or isset($_POST['hc'])){
$ha = abs($_POST['ha']);
$hb = abs($_POST['hb']);
$ho = abs($_POST['ho']);
$hc = abs($_POST['hc']);
mysql_query("UPDATE `tank` SET `ha` = '".$ha."',`hb` = '".$hb."',`ho` = '".$ho."',`hc` = '".$hc."' WHERE `id` = '".abs($tnk['id'])."' ")or die(mysql_error());
}
elseif(isset($_POST['img'])){
$img = check($_POST['img']);
mysql_query("UPDATE `tank` SET `img` = '".$img."' WHERE `id` = '".abs($tnk['id'])."' ")or die(mysql_error());
}
elseif(isset($_POST['gold']) or isset($_POST['silver'])){
$gold = abs($_POST['gold']);
$silver = abs($_POST['silver']);
mysql_query("UPDATE `tank` SET `gold` = '".$gold."',`silver` = '".$silver."' WHERE `id` = '".abs($tnk['id'])."' ")or die(mysql_error());
}


header("Location:/newstore/inf/".$tnk['id']."/edit/");
exit();
}

}

echo "
<table>
<tbody><tr>
<td class='small white bold sh_b w100'>";
echo "Название:<span class='green2'>".$tnk['name']."</span>";
if($user['rules'] == '10' && $is['3'] == 'edit'){
echo "
<form action = '/newstore/inf/".$tnk['id']."/editgo/' method = 'post'>
<input name = 'name' type = 'text' value = '".$tnk['name']."'>
<input type = 'submit' value = 'Изменить название'>
</form>
";
}else{echo "<br>";}
echo "Уровень <span class='green2'>".$tnk['level']."</span>";
if($user['rules'] == '10' && $is['3'] == 'edit'){
echo "
<form action = '/newstore/inf/".$tnk['id']."/editgo/' method = 'post'>
<select name = 'level'>
<option value = '".$tnk['level']."'>>".$tnk['level']."<</option>
<option value = 'I'>I</option>
<option value = 'II'>II</option>
<option value = 'III'>III</option>
<option value = 'IV'>IV</option>
<option value = 'V'>V</option>
<option value = 'VI'>VI</option>
<option value = 'VII'>VII</option>
<option value = 'VIII'>VIII</option>
<option value = 'IX'>IX</option>
<option value = 'X'>X</option>
</select>
<input type = 'submit' value = 'Изменить уровень'>
</form>
";
}else{echo "<br>";}
echo "Тип <span class='green2'>".ttype($tnk['type'])."</span>";
if($user['rules'] == '10' && $is['3'] == 'edit'){
echo "
<form action = '/newstore/inf/".$tnk['id']."/editgo/' method = 'post'>
<select name = 'type'>";
echo "<option value = '".$tnk['type']."'>>".ttype($tnk['type'])."<</option>";
echo "<option value = 'easy'>Лёгкий</option>
<option value = 'normal'>Средний</option>
<option value = 'hard'>Тяжёлый</option>";

# echo "
# <option value = 'pt-sau'>ПТ-САУ</option>
# <option value = 'sau'>САУ</option>
# ";

echo "</select>
<input type = 'submit' value = 'Изменить тип'>
</form>
";
}else{echo "<br>";}
echo "Страна <span class='green2'><img src = '".country($tnk['country'],'img')."'>".country($tnk['country'],'text')."</span>";
if($user['rules'] == '10' && $is['3'] == 'edit'){

echo "
<form action = '/newstore/inf/".$tnk['id']."/editgo/' method = 'post'>
<select name = 'country'>
<option value = '".$tnk['country']."'>>".country($tnk['country'],'text')."<</option>
<option value='usa'>США</option>
<option value='ussr'>СССР</option>
<option value='china'>КИТАЙ</option>
<option value='japan'>ЯПОНИЯ</option>
<option value='france'>ФРАНЦИЯ</option>
<option value='germany'>ГЕРМАНИЯ</option>
<option value='britain'>ВЕЛИКОБРИТАНИЯ</option>
</select>
<input type = 'submit' value = 'Изменить страну'>
</form>
";
}else{echo "<br>";}

if($user['rules'] == '10' && $is['3'] == 'edit'){
echo "<form action = '/newstore/inf/".$tnk['id']."/editgo/' method = 'post'>";
}
echo "<img src = '/instalscript/images/icons/damage.jpg'>Урон <span class='green2'>".$tnk['ha']."</span>";
if($user['rules'] == '10' && $is['3'] == 'edit'){echo "<input name = 'ha' type = 'text' value = '".$tnk['ha']."'>";}
echo "<br>";
echo "<img src = '/instalscript/images/icons/armor.jpg'>Броня <span class='green2'>".$tnk['hb']."</span>";
if($user['rules'] == '10' && $is['3'] == 'edit'){echo "<input name = 'hb' type = 'text' value = '".$tnk['hb']."'>";}
echo "<br>";
echo "<img src = '/instalscript/images/icons/durability.jpg'>Прочность <span class='green2'>".$tnk['ho']."</span>";
if($user['rules'] == '10' && $is['3'] == 'edit'){echo "<input name = 'ho' type = 'text' value = '".$tnk['ho']."'>";}
echo "<br>";
echo "<img src = '/instalscript/images/icons/accuracy.jpg'>Точность <span class='green2'>".$tnk['hc']."</span>";
if($user['rules'] == '10' && $is['3'] == 'edit'){echo "<input name = 'hc' type = 'text' value = '".$tnk['hc']."'>";}
echo "<br>";
if($user['rules'] == '10' && $is['3'] == 'edit'){
echo "
<input type = 'submit' value = 'Изменить параметры'>
</form>
";
}
echo "</td>
</tr>
</tbody>
</table>";


echo "
<div class='cntr'>
<img class='tank-img' src='/tankimage_".$tnk['id']."_1.jpg'>
</div>";
if($user['rules'] == '10' && $is['3'] == 'edit'){
echo "<form action = '/newstore/inf/".$tnk['id']."/editgo/' method = 'post'>";
echo "<input name = 'img' type = 'text' value = '".$tnk['img']."'>";
echo "ФОРМАТ ТОЛЬКО PNG";
echo "<input type = 'submit' value = 'Изменить изображение'>";
echo "</form>";
echo "</br>";
}

echo "Цена:";
if($tnk['gold'] > '0'){echo "<span class='yellow1'><img class='ico vm' src='/instalscript/images/icons/gold.png' alt='Золото' title='Золото'> ".$tnk['gold']."</span>";}
if($tnk['silver'] > '0'){echo "<span class='yellow1'><img class='ico vm' src='/instalscript/images/icons/silver.png' alt='Серебро' title='Серебро'> ".$tnk['silver']."</span>";}
if($user['rules'] == '10' && $is['3'] == 'edit'){
echo "<form action = '/newstore/inf/".$tnk['id']."/editgo/' method = 'post'>";
echo "<br />Золото<input name = 'gold' type = 'text' value = '".$tnk['gold']."'>";
echo "<br />Серебро<input name = 'silver' type = 'text' value = '".$tnk['silver']."'>";
echo "<br /><input type = 'submit' value = 'Изменить цену'>";
echo "<br /></form>";
}

echo "</div>";

if($is['3'] == 'sale'){
if($tnk['gold'] > $user['gold'] or $tnk['silver'] > $user['silver']){
echo "Покупка невозможна</br>";
if($tnk['gold'] > $user['gold']){echo "Нехватает золота!<br />";}
if($tnk['silver'] > $user['silver']){echo "Нехватает серебра!<br />";}
}else{
echo "Вы действительно хотите приобрести данный танк?";

echo "</br>";
if($tnk['gold'] > $user['gold'] or $tnk['silver'] > $user['silver']){
if($tnk['gold'] > $user['gold']){echo "Нехватает золота!<br />";}
if($tnk['silver'] > $user['silver']){echo "Нехватает серебра!<br />";}
}else{
# - Обработка покупки танка - #
if($is['4'] == 'yes'){

if($tnk['silver'] <= $user['silver'] && $tnk['gold'] <= $user['gold']){
mysql_query("INSERT INTO `utank` SET
`uid` = '".$uid."',
`tid` = '".$tnk['id']."',
`act` = '0',
`ha` = '".$tnk['ha']."',
`hb` = '".$tnk['hb']."',
`hc` = '".$tnk['hc']."',
`ho` = '".$tnk['ho']."',
`cannon` = '1',
`tower` = '1',
`caterpillar` = '1',
`machinegun` = '1',
`rockets` = '1',
`frontalarmor` = '1',
`sidearmor` = '1',
`gun` = '1',
`frame` = '1',
`optronics` = '1',
`fragshield` = '1',
`upgrade` = '1',
`time` = '".(time())."'
")or die(mysql_error());
mysql_query("UPDATE `users` SET `gold` = `gold` - '".$tnk['gold']."',`silver` = `silver` - '".$tnk['silver']."' WHERE `id` = '".$uid."' ")or die(mysql_error());
header("Location:/angar/tank/");
exit();
}
}


}
# - Обработка покупки танка - #

echo "<div class='bot'><a class='simple-but border mb2' href = '/newstore/inf/".$tnk['id']."/sale/yes/'><span><span>Да</span></span></a></div>";
echo "<a class='simple-but border mb2' href = '/newstore/inf/".$tnk['id']."/'><span><span>Нет</span></span></a>";
}
}else{
echo "<div class='bot'><a class='simple-but border mb2' href = '/newstore/inf/".$tnk['id']."/sale/'><span><span>Купить</span></span></a></div>";
}

echo "
<a class='simple-but border mb2' href = '/newstore/list/'><span><span>Вернуться к списку</span></span></a>
<a class='simple-but border mb2' href = '/newstore/'><span><span>Вернуться к поиску</span></span></a>
";


echo "</div>
</div></div></div></div></div></div></div></div>
</div>
";
break;
}
foot($uid); # Ноги

?>