battles/shop.php
2018-06-23 13:21:25 +03:00

338 lines
19 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
ob_start();
session_start();
if (!isset($_SESSION['uid'])) {
header("Location: index.php");
}
include("config.php");
include("functions.php");
if ($user['room'] != 22) {
header("Location: main.php");
die();
}
if ($user['battle'] != 0) {
header('location: fbattle.php');
die();
}
if ($_GET['sed']) {
$dress = mysql_fetch_array(mysql_query("SELECT `id`, `name`, `cost`, `type`, `duration`, `maxdur`, `goden`, `dategoden`, `koll` FROM `inventory` WHERE `dressed` = 0 AND `id` = '" . (int)$_GET['sed'] . "' AND `owner` = '{$user['id']}' LIMIT 1"));
$price = $dress['cost'] * 1;
$kols = '';
if ($dress['koll']) {
$price *= $dress['koll'];
$kols = '(x' . $dress['koll'] . ')';
}
destructitem($dress['id']);
if ($dress['type'] == 12) {
$allcost = round($price * (1 - $dress['duration'] / $dress['maxdur']), 2);
} else {
$allcost = round($price - $dress['duration'] * ($dress['cost'] / ($dress['maxdur'] * 10)), 2);
}
if ($dress['goden'] != 0) {
$goden_max = $dress['goden'] * 24 * 60;
$goden_left = ($dress['dategoden'] - time()) / 60;
$per = $goden_left / $goden_max;
$allcost = round(($allcost * $per), 2);
}
$user['money'] += $allcost;
mysql_query("UPDATE `users` SET `money` = '" . $user['money'] . "' WHERE `id` = {$user['id']} LIMIT 1");
mysql_query("INSERT INTO `delo` (`author`, `pers`, `text`, `type`, `date`) VALUES ('0', '{$user['id']}', '\"" . $user['login'] . "\" продал в магазин товар : \"" . $dress['name'] . "\" $kols id:(cap" . $dress['id'] . ") [" . $dress['duration'] . "/" . $dress['maxdur'] . "] за " . $allcost . " кр. ', '1', '" . time() . "')");
echo "<font color=red><b>Вы продали \"{$dress['name']}\" $kols за " . $allcost . " кр.</b></font>";
}
if (($_GET['set'] || $_POST['set'])) {
if ($_GET['set']) {
$set = $_GET['set'];
}
if ($_POST['set']) {
$set = $_POST['set'];
}
if (!$_GET['count']) {
$_GET['count'] = 1;
}
if (!is_numeric($_GET['count']) || $_GET['count'] != ((int)$_GET['count'])) {
$_GET['count'] = 0;
$count_ok = 0;
} elseif ($_GET['count'] < 1) {
$_GET['count'] = 0;
$count_ok = 0;
} else {
$count_ok = 1;
}
$dress = mysql_fetch_array(mysql_query("SELECT * FROM `shop` WHERE `id` = '" . (int)$set . "' LIMIT 1"));
if ($count_ok == 0) {
echo "<font color=red><b>Неправильно введено количество</b></font>";
} elseif (($dress['massa'] * $_GET['count'] + $d[0]) > (get_meshok())) {
echo "<font color=red><b>Недостаточно места в рюкзаке.</b></font>";
} elseif ($count_ok == 1 && ($user['money'] >= ($dress['cost'] * $_GET['count'])) && ($dress['count'] >= $_GET['count'])) {
for ($k = 1; $k <= $_GET['count']; $k++) {
if (mysql_query("INSERT INTO `inventory` (`prototype`,`owner`,`name`,`type`,`massa`,`cost`,`img`,`maxdur`,`isrep`,`gsila`,`glovk`,`ginta`,`gintel`,`ghp`,`gnoj`,`gtopor`,`gdubina`,`gmech`,`gfire`,`gwater`,`gair`,`gearth`,`glight`,`ggray`,`gdark`,`needident`,`nsila`,`nlovk`,`ninta`,`nintel`,`nmudra`,`nvinos`,`nnoj`,`ntopor`,`ndubina`,`nmech`,`nfire`,`nwater`,`nair`,`nearth`,`nlight`,`ngray`,`ndark`,`mfkrit`,`mfakrit`,`mfuvorot`,`mfauvorot`,`bron1`,`bron2`,`bron3`,`bron4`,`maxu`,`minu`,`magic`,`nlevel`,`nalign`,`dategoden`,`goden`,`otdel`,`gmp`,`gmeshok`,`encicl`,`artefact`,`koll`) VALUES ('{$dress['id']}','{$user['id']}','{$dress['name']}','{$dress['type']}',{$dress['massa']},{$dress['cost']},'{$dress['img']}',{$dress['maxdur']},{$dress['isrep']},'{$dress['gsila']}','{$dress['glovk']}','{$dress['ginta']}','{$dress['gintel']}','{$dress['ghp']}','{$dress['gnoj']}','{$dress['gtopor']}','{$dress['gdubina']}','{$dress['gmech']}','{$dress['gfire']}','{$dress['gwater']}','{$dress['gair']}','{$dress['gearth']}','{$dress['glight']}','{$dress['ggray']}','{$dress['gdark']}','{$dress['needident']}','{$dress['nsila']}','{$dress['nlovk']}','{$dress['ninta']}','{$dress['nintel']}','{$dress['nmudra']}','{$dress['nvinos']}','{$dress['nnoj']}','{$dress['ntopor']}','{$dress['ndubina']}','{$dress['nmech']}','{$dress['nfire']}','{$dress['nwater']}','{$dress['nair']}','{$dress['nearth']}','{$dress['nlight']}','{$dress['ngray']}','{$dress['ndark']}','{$dress['mfkrit']}','{$dress['mfakrit']}','{$dress['mfuvorot']}','{$dress['mfauvorot']}','{$dress['bron1']}','{$dress['bron2']}','{$dress['bron3']}','{$dress['bron4']}','{$dress['maxu']}','{$dress['minu']}','{$dress['magic']}','{$dress['nlevel']}','{$dress['nalign']}','" . (($dress['goden']) ? ($dress['goden'] * 24 * 60 * 60 + time()) : "") . "','{$dress['goden']}','{$dress['razdel']}','{$dress['gmp']}','{$dress['gmeshok']}','{$dress['encicl']}','{$dress['artefact']}','{$dress[koll]}')")) {
$good = 1;
} else {
$good = 0;
}
}
if ($good) {
mysql_query("UPDATE `shop` SET `count` = (`count`-'" . (int)$_GET['count'] . "') WHERE `id` = '{$set}' LIMIT 1");
echo "<font color=red><b>Вы купили {$_GET['count']} шт. \"{$dress['name']}\".</b></font>";
$user['money'] -= (int)$_GET['count'] * $dress['cost'];
mysql_query("UPDATE `users` set `money` = '" . $user['money'] . "' WHERE `id` = {$user['id']} LIMIT 1");
$limit = (int)$_GET['count'];
$invdb = mysql_query("SELECT `id` FROM `inventory` WHERE `name` = '" . $dress['name'] . "' ORDER BY `id` DESC LIMIT " . $limit . "");
if ($limit == 1) {
$dressinv = mysql_fetch_array($invdb);
$dressid = "cap" . $dressinv['id'];
$dresscount = " ";
} else {
$dressid = "";
while ($dressinv = mysql_fetch_array($invdb)) {
$dressid .= "cap" . $dressinv['id'] . ",";
}
$dresscount = "(x" . $_GET['count'] . ") ";
}
$allcost = (int)$_GET['count'] * $dress['cost'];
mysql_query("INSERT INTO `delo` (`author`, `pers`, `text`, `type`, `date`) VALUES ('0', '{$user['id']}', '\"" . $user['login'] . "\" купил товар : \"" . $dress['name'] . "\" " . $dresscount . " id:(" . $dressid . ") [0/" . $dress['maxdur'] . "] за " . $allcost . " кр.', '1', '" . time() . "')");
}
} else {
echo "<font color=red><b>Недостаточно денег или нет вещей в наличии.</b></font>";
}
}
$itemWeight = db::c()->query('SELECT sum(`massa`) AS `m` FROM `inventory` WHERE `owner` = ?i AND `dressed` = 0 AND `setsale` = 0', $user['id'])->fetch_assoc();
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<link href="css/main.css" rel="stylesheet"/>
<script src="js/jquery-1.7.2.min.js"></script>
<script src="js/jquery.simplemodal.js"></script>
<script src="js/jquery.ui.js?100"></script>
<script src="js/mi.js"></script>
<link rel="stylesheet" href="css/bkstyle.css?101"/>
<link rel="stylesheet" href="css/mi.css"/>
<style>
.row {
font-family: Tahoma, sans-serif;
font-size: 13px;
}
</style>
<script>
function addCountItems(name, txt) {
new miDialog({title: 'Купить неск. штук'}, {byu: 1}, function () {
document.location = '/shop.php?' + $.param(this.data);
},
$('<div style="text-align: center;"><b>' + txt + '</b></div>').append(miDialog._oneInput({
name: 'count',
onkeyup: 'return proverka(this);',
onchange: 'return proverka(this);'
}), miDialog._hiddenInput({name: 'set', value: name})), {width: 250});
}
function proverka(input) {
input.value = input.value.replace(/[^\d]/g, '');
}
function leave() {
top.frames['main'].location = 'city.php?cp'
}
</script>
</head>
<body>
<h1>Государственный магазин</h1>
<a href=# onclick=leave()> ← выйти на Центральную площадь</a>
<TABLE border=0 width=100% cellspacing="0" cellpadding="4">
<TR>
<TD valign=top align=left>
<!--Магазин-->
<TABLE border=0 width=100% cellspacing="0" cellpadding="0" bgcolor="#A5A5A5">
<TR>
<TD align=center>Отдел "<?php
if ($_POST['sale']) {
echo "Скупка";
} else
switch ($_GET['otdel']) {
default:
echo "Оружие: кастеты,ножи";
$_GET['otdel'] = 1;
break;
case 1:
echo "Оружие: кастеты,ножи";
break;
case 11:
echo "Оружие: топоры";
break;
case 12:
echo "Оружие: дубины,булавы";
break;
case 13:
echo "Оружие: мечи";
break;
case 14:
echo "Оружие: луки и арбалеты";
break;
case 2:
echo "Одежда: сапоги";
break;
case 21:
echo "Одежда: перчатки";
break;
case 22:
echo "Одежда: легкая броня";
break;
case 23:
echo "Одежда: тяжелая броня";
break;
case 24:
echo "Одежда: шлемы";
break;
case 3:
echo "Щиты";
break;
case 4:
echo "Ювелирные товары: серьги";
break;
case 41:
echo "Ювелирные товары: ожерелья";
break;
case 42:
echo "Ювелирные товары: кольца";
break;
case 5:
echo "Заклинания: нейтральные";
break;
case 51:
echo "Заклинания: боевые и защитные";
break;
case 6:
echo "Амуниция";
break;
case 52:
echo "Руны";
break;
}
?>"
</TD>
</TR>
<TR>
<TD>
<TABLE BORDER=0 WIDTH=100% CELLSPACING="1" CELLPADDING="2" BGCOLOR="#A5A5A5">
<?php
if ($_REQUEST['sale']) {
$data = mysql_query("SELECT * FROM `inventory` WHERE `owner` = '{$user['id']}' AND `dressed` = 0 AND `setsale` = 0 AND `cost` > 0 AND `present` = '' AND `tradesale` = 0 AND `podzem` = 0 ORDER BY `update` DESC");
while ($row = mysql_fetch_array($data)) {
$row['count'] = 1;
if ($i == 0) {
$i = 1;
$color = '#C7C7C7';
} else {
$i = 0;
$color = '#D5D5D5';
}
echo "<tr bgcolor={$color}><td align=center style='width: 150px;'><img src=\"i/sh/{$row['img']}\" border=0 />";
$price = $row['cost'] * 1;
if ($data['koll']) {
$price *= $data['koll'];
}
if ($row['type'] == 12) {
$allcost = round($price * (1 - $row['duration'] / $row['maxdur']), 2);
} else {
$allcost = round($price - $row['duration'] * ($row['cost'] / ($row['maxdur'] * 10)), 2);
}
if ($row['goden'] != 0) {
$goden_max = $row['goden'] * 24 * 60;
$goden_left = ($row['dategoden'] - time()) / 60;
$per = $goden_left / $goden_max;
$allcost = round(($allcost * $per), 2);
}
?>
<br/><a href="shop.php?sed=<?= $row['id'] ?>&sid=&sale=1">продать
за <?= $allcost ?></a>
</td>
<?php
echo "<td valign=top class=\"row\">";
showitem($row);
echo "</TD></TR>";
}
} else {
if (!isset($_SESSION['type_sort'])) {
$_SESSION['type_sort'] = 1;
$where = '';
} elseif ($_SESSION['type_sort'] == 1) {
$where = '';
} elseif ($_SESSION['type_sort'] == 2) {
$where = ' AND `nlevel` = "' . $user['level'] . '"';
}
$arr_sort = array(11, 13, 12); #$item
$data = mysql_query("SELECT `id`, `img`, `name` FROM `shop` WHERE `count` > 0 AND `razdel` = '{$_GET['otdel']}' $where ORDER by `nlevel` ASC, `id` ASC");
while ($row = mysql_fetch_array($data)) {
if ($i == 0) {
$i = 1;
$color = '#C7C7C7';
} else {
$i = 0;
$color = '#D5D5D5';
}
echo "<TR bgcolor={$color}><TD align=center style='width:150px'><IMG SRC=\"i/sh/{$row['img']}\" BORDER=0>";
?>
<BR>
<A HREF="shop.php?otdel=<?= $_GET['otdel'] ?>&set=<?= $row['id'] ?>&sid=<? echo rand(10000, 1000000); ?>">купить</A>
<IMG SRC="i/up.gif" WIDTH=11 HEIGHT=11 BORDER=0 ALT="Купить несколько штук"
style="cursor:hand"
onclick="addCountItems('<?= $row['id'] ?>', '<?= $row['name'] ?>')"></TD>
<?php
echo "<TD valign=top>";
echo show_shop_items($row['id']);
//showitem ($row);
echo "</TD></TR>";
}
}
?>
</TABLE>
</TD>
</TR>
</TABLE>
</TD>
<TD valign=top width=280>
<B>Масса всех ваших вещей: <?= $itemWeight['m'] ?>/<?= get_meshok() ?>
<BR>У вас в наличии: <span style="color: #339900;"><?= $user['money'] ?></span> кр.</B>
<hr>
<INPUT TYPE="submit" value="Продать вещи" name="sale"><BR><br/>
<dl>
<dt><b>Оружие:</b></dt>
<dd><a href="shop.php?otdel=1&rnd=<?= mt_rand() ?>">кастеты,ножи</a></dd>
<dd><a href="shop.php?otdel=11&rnd=<?= mt_rand() ?>">топоры</a></dd>
<dd><a href="shop.php?otdel=12&rnd=<?= mt_rand() ?>">дубины,булавы</a></dd>
<dd><a href="shop.php?otdel=13&rnd=<?= mt_rand() ?>">мечи</a></dd>
<dt><b>Одежда:</b></dt>
<dd><a href="shop.php?otdel=24&rnd=<?= mt_rand() ?>">шлемы</a></dd>
<dd><a href="shop.php?otdel=23&rnd=<?= mt_rand() ?>">тяжелая броня</a></dd>
<dd><a href="shop.php?otdel=22&rnd=<?= mt_rand() ?>">легкая броня</a></dd>
<dd><a href="shop.php?otdel=3&rnd=<?= mt_rand() ?>">щиты</a></dd>
<dd><a href="shop.php?otdel=21&rnd=<?= mt_rand() ?>">перчатки</a></dd>
<dd><a href="shop.php?otdel=2&rnd=<?= mt_rand() ?>">сапоги</a></dd>
<dt><b>Ювелирные товары:</b></dt>
<dd><a href="shop.php?otdel=4&rnd=<?= mt_rand() ?>">серьги</a></dd>
<dd><a href="shop.php?otdel=41&rnd=<?= mt_rand() ?>">ожерелья</a></dd>
<dd><a href="shop.php?otdel=42&rnd=<?= mt_rand() ?>">кольца</a></dd>
<dt><b>Магия:</b></dt>
<dd><a href="shop.php?otdel=51&rnd=<?= mt_rand() ?>">боевые</a></dd>
<dd><a href="shop.php?otdel=5&rnd=<?= mt_rand() ?>">разные</a></dd>
<dt><b>Разное:</b></dt>
<dd><a href="shop.php?otdel=6&rnd=<?= mt_rand() ?>">амуниция</a></dd>
</dl>
<div id="hint3" class="ahint"></div>
</TD>
</TR>
</TABLE>
</BODY>
</HTML>