<?php
include ('inc/base.php');
include ('inc/functions.php');
include ('inc/user.php');
$title = 'Магазин';
include ('inc/header.php');
if(!$user) {
header('location: /');
exit();
}
echo '<table class="center" width="100%"><tr><td style="width: 33%"><a href="?weapon" class="mini-link">оружие</a></td><td style="width: 33%"><a href="?bullets" class="mini-link">патроны</a></td><td style="width: 33%"><a href="?first" class="mini-link">аптечки</a></td></tr></table><div class="new-line"></div>';
if(isset($_GET['weapon'])) {
if(isset($_GET['buy'])) {
$id = text(num($_GET['buy']));
if(mysql_result(mysql_query('SELECT COUNT(*) FROM `weapon` WHERE `id` = \''.$id.'\''),0) == 0) {
echo '<div class="main center">Оружие не найдено!</div>';
echo '<a href="?weapon" class="link center">Продолжить</a>';
include ('inc/footer.php');
exit();
}
$weapon = mysql_fetch_array(mysql_query('SELECT * FROM `weapon` WHERE `id` = "'.$id.'" LIMIT 1'));
mysql_free_result($weapon);
if($user['cash'] < $weapon['cost']) {
echo '<div class="main center">Не хватает '.($weapon['cost']- $user['cash']).' рублей!</div>';
echo '<a href="?weapon" class="link center">Продолжить</a>';
include ('inc/footer.php');
exit();
}
mysql_query('INSERT INTO `acc_weapon` (`name`, `damage`, `img`, `user`, `accuracy`, `consumption`) VALUEs ("'.$weapon['name'].'", "'.$weapon['damage'].'", "'.$weapon['img'].'", "'.$user['id'].'", "'.$weapon['accuracy'].'", "'.$weapon['consumption'].'")');
mysql_query("update `accounts` set `cash` = `cash` - '".$weapon['cost']."' where `id` = '".$user['id']."'");
echo '<div class="main center">Оружие куплено!</div>';
echo '<a href="/act.php?weapon" class="link center">Продолжить</a>';
include ('inc/footer.php');
exit();
}
$max = text(num($_GET['max']));
$k_post = mysql_result(mysql_query("SELECT COUNT(*) FROM `weapon`"),0);
mysql_free_result($k_post);
if($max and $max >= '11') {
$sql = mysql_query("SELECT * FROM `weapon` ORDER BY `id` ASC LIMIT 0, $max");
}else{
$sql = mysql_query("SELECT * FROM `weapon` ORDER BY `id` ASC LIMIT 0, 10");
}
while($weapon = mysql_fetch_assoc($sql)) {
echo '<div class="main"><img src="'.$weapon['img'].'"></div><div class="main"><small>'.$weapon['text'].'</small></div><div class="main"><img src="/style/src/info.png"> Название: <span style="float: right">'.$weapon['name'].'</span><br><img src="/style/src/accuracy.png"> Точность: <span style="float: right">'.$weapon['accuracy'].'%</span><br><img src="/style/src/bullets.png" height="20"> Расход: <span style="float: right">'.$weapon['consumption'].' шт.</span><br><img src="/style/src/damage.png"> Урон: <span style="float: right">'.$weapon['damage'].'</span></div><a href="?weapon&buy='.$weapon['id'].'" class="link center">Купить за '.$weapon['cost'].' <img src="/style/src/cash.png" height="14"></a><div class="new-line"></div>';
mysql_free_result($weapon);
}
if($k_post > '10' and !$max) {
echo '<div class="new-line"></div><a href="?weapon&max='.$k_post.'" class="link center">Показать всё</a>';
}
if($k_post > '10' and $max) {
echo '<div class="new-line"></div><a href="?weapon" class="link center">Скрыть все</a>';
}
if($k_post < '1') {
echo '<div class="main center">Оружия нет!</div>';
}
}
if(isset($_GET['first'])) {
if($_GET['buy'] == 'first1') {
if($user['cash'] < '5000') {
echo '<div class="main center">Не хватает '.(5000- $user['cash']).' рублей!</div>';
echo '<a href="?first" class="link center">Продолжить</a>';
include ('inc/footer.php');
exit();
}
mysql_query("update `accounts` set `cash` = `cash` - '5000', `first` = `first` + '1' where `id` = '".$user['id']."'");
echo '<div class="main center">Аптечки куплены!</div>';
echo '<a href="?" class="link center">Продолжить</a>';
include ('inc/footer.php');
exit();
}
if($_GET['buy'] == 'first2') {
if($user['cash'] < '45000') {
echo '<div class="main center">Не хватает '.(45000- $user['cash']).' рублей!</div>';
echo '<a href="?first" class="link center">Продолжить</a>';
include ('inc/footer.php');
exit();
}
mysql_query("update `accounts` set `cash` = `cash` - '45000', `first` = `first` + '10' where `id` = '".$user['id']."'");
echo '<div class="main center">Аптечки куплены!</div>';
echo '<a href="?" class="link center">Продолжить</a>';
include ('inc/footer.php');
exit();
}
echo '<div class="main center"><div class="new-line"><font color="#953535">Аптечка</font></div><small>при использовании прибавляет 10000 жизней</small></div><a href="?first&buy=first1" class="link center">Купить 1 за 5000 <img src="/style/src/cash.png" height="14"></a><a href="?first&buy=first2" class="link center">Купить 10 за 45000 <img src="/style/src/cash.png" height="14"></a>';
}
if(isset($_GET['bullets'])) {
if($_GET['bullets'] == '10') {
if($user['cash'] < '10') {
echo '<div class="main center">Не хватает '.(10- $user['cash']).' рублей!</div>';
echo '<a href="?bullets" class="link center">Продолжить</a>';
include ('inc/footer.php');
exit();
}
mysql_query("update `accounts` set `bullets` = `bullets` + '10', `cash` = `cash` - '10' where `id` = '".$user['id']."'");
echo '<div class="main center">Патроны куплены!</div>';
echo '<a href="?bullets" class="link center">Продолжить</a>';
include ('inc/footer.php');
exit();
}
if($_GET['bullets'] == '50') {
if($user['cash'] < '50') {
echo '<div class="main center">Не хватает '.(50- $user['cash']).' рублей!</div>';
echo '<a href="?bullets" class="link center">Продолжить</a>';
include ('inc/footer.php');
exit();
}
mysql_query("update `accounts` set `bullets` = `bullets` + '50', `cash` = `cash` - '50' where `id` = '".$user['id']."'");
echo '<div class="main center">Патроны куплены!</div>';
echo '<a href="?bullets" class="link center">Продолжить</a>';
include ('inc/footer.php');
exit();
}
if($_GET['bullets'] == '100') {
if($user['cash'] < '100') {
echo '<div class="main center">Не хватает '.(100- $user['cash']).' рублей!</div>';
echo '<a href="?bullets" class="link center">Продолжить</a>';
include ('inc/footer.php');
exit();
}
mysql_query("update `accounts` set `bullets` = `bullets` + '100', `cash` = `cash` - '100' where `id` = '".$user['id']."'");
echo '<div class="main center">Патроны куплены!</div>';
echo '<a href="?bullets" class="link center">Продолжить</a>';
include ('inc/footer.php');
exit();
}
if($_GET['bullets'] == '1000') {
if($user['cash'] < '1000') {
echo '<div class="main center">Не хватает '.(1000- $user['cash']).' рублей!</div>';
echo '<a href="?bullets" class="link center">Продолжить</a>';
include ('inc/footer.php');
exit();
}
mysql_query("update `accounts` set `bullets` = `bullets` + '1000', `cash` = `cash` - '1000' where `id` = '".$user['id']."'");
echo '<div class="main center">Патроны куплены!</div>';
echo '<a href="?bullets" class="link center">Продолжить</a>';
include ('inc/footer.php');
exit();
}
echo '<div class="main center"><div class="new-line"><font color="#606030">Патроны</font></div><small>используются для нанесения урона</small></div><a href="?bullets&bullets=10" class="link center">Купить 10 <img src="/style/src/bullets.png" height="14"> за 10 <img src="/style/src/cash.png" height="14"></a><a href="?bullets&bullets=50" class="link center">Купить 50 <img src="/style/src/bullets.png" height="14"> за 50 <img src="/style/src/cash.png" height="14"></a><a href="?bullets&bullets=100" class="link center">Купить 100 <img src="/style/src/bullets.png" height="14"> за 100 <img src="/style/src/cash.png" height="14"></a><a href="?bullets&bullets=1000" class="link center">Купить 1000 <img src="/style/src/bullets.png" height="14"> за 1000 <img src="/style/src/cash.png" height="14"></a>';
}
if(!isset($_GET['bullets']) and !isset($_GET['weapon']) and !isset($_GET['first'])) {
echo '<div class="main center">Ничего не выбрано!</div>';
}
include ('inc/footer.php');
?>