350 lines
21 KiB
PHP
350 lines
21 KiB
PHP
<?php
|
||
session_start();
|
||
if ($_SESSION['uid'] == null) header("Location: index.php");
|
||
include "config.php";
|
||
include "functions.php";
|
||
|
||
if ($user['room'] != 50) {
|
||
header("Location: main.php");
|
||
die();
|
||
}
|
||
|
||
$itemWeight = db::c()->query('SELECT sum(`massa`) AS `m` FROM `inventory` WHERE `owner` = ?i AND `dressed` = 0 AND `setsale` = 0', $user['id'])->fetch_assoc();
|
||
if ($user['battle'] != 0) {
|
||
header('location: fbattle.php');
|
||
die();
|
||
}
|
||
|
||
$bank = db::c()->query('SELECT `ekr` FROM `bank` WHERE `id`=?i', $_SESSION['uid'])->fetch_assoc();
|
||
|
||
if (isset($_GET['set']) OR isset($_POST['set'])) {
|
||
|
||
$set = empty($_GET['set']) ?: $_GET['set'];
|
||
$set = empty($_POST['set']) ?: $_POST['set'];
|
||
|
||
$count = isset($_POST['count']) && is_numeric($_POST['count']) ? $_POST['count'] : 0;
|
||
|
||
if ($count < 1) {
|
||
$count = 0;
|
||
$count_ok = 0;
|
||
} else $count_ok = 1;
|
||
|
||
$dress = db::c()->query('SELECT * FROM `ashop` WHERE `id`=?i', $set)->fetch_assoc();
|
||
if ($count_ok == 0) {
|
||
err('Неправильно введено количество.');
|
||
} elseif (($dress['massa'] * $_POST['count'] + $itemWeight['m']) > (get_meshok())) {
|
||
err('Недостаточно места в рюкзаке.');
|
||
} elseif ($count_ok == 1 && ($bank['ekr'] >= ($dress['ecost'] * $_POST['count'])) && ($dress['count'] >= $_POST['count'])) {
|
||
for ($k = 1; $k <= $_POST['count']; $k++) {
|
||
$goden = '';
|
||
if (isset($dress['goden'])) $goden = $dress['goden'] * 24 * 60 * 60 + time(); // Ну вот нахуя?
|
||
db::c()->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`,
|
||
`artefact`, `koll`
|
||
)
|
||
VALUES (?i,?i,"?s",?i,?i,"?s","?s",?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i)
|
||
', $dress['id'], $_SESSION['uid'], $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['bron3'], $dress['bron2'], $dress['bron4'], $dress['maxu'], $dress['minu'], $dress['magic'],
|
||
$dress['nlevel'], $dress['nalign'], $goden, $dress['goden'], $dress['razdel'], $dress['artefact'], $dress['koll']);
|
||
|
||
db::c()->query('UPDATE `ashop` SET `count` = `count`- ?i WHERE `id` = ?i', $_POST['count'], $set);
|
||
$invdb = db::c()->query('SELECT `id` FROM `inventory` WHERE `name` = "?s" ORDER BY `id` DESC LIMIT ?i', $dress['name'], $_POST['count']);
|
||
if ($_POST['count'] == 1) {
|
||
$dressinv = $invdb->fetch_assoc();
|
||
$dressid = "cap" . $dressinv['id'];
|
||
$dresscount = " ";
|
||
} else {
|
||
$dressid = "";
|
||
while ($dressinv = $invdb->fetch_assoc()) {
|
||
$dressid .= "cap" . $dressinv['id'] . ",";
|
||
}
|
||
$dresscount = "(x" . $_POST['count'] . ") ";
|
||
}
|
||
$allcost = $_POST['count'] * $dress['ecost'];
|
||
$deloText = $user['login'] . " купил товар: " . $dress['name'] . $dresscount . "id:(" . $dressid . ") [0/" . $dress['maxdur'] . "] за " . $allcost . " екр.";
|
||
db::c()->query('INSERT INTO `delo` (`author` ,`pers`, `text`, `type`, `date`) VALUES (?i, ?i, "?s", ?i, "?s")', 0, $user['id'], $deloText, 1, time());
|
||
err('Вы купили ' . $_POST['count'] . ' шт. "' . $dress['name'] . '.');
|
||
db::c()->query('UPDATE `bank` SET `ekr` = `ekr` - ?i WHERE `id` = ?i', $allcost, $_SESSION['uid']);
|
||
$bank['ekr'] -= $allcost;
|
||
}
|
||
} else {
|
||
err('Недостаточно денег или нет вещей в наличии.');
|
||
}
|
||
}
|
||
$shopCategory = '';
|
||
if ($_REQUEST['compare'] && !$_REQUEST['common'] && !$_REQUEST['present']) {
|
||
$shopCategory = "Составление подарочного букета";
|
||
} else {
|
||
switch ($_GET['otdel']) {
|
||
default:
|
||
$shopCategory = "Кастеты и ножи";
|
||
$_GET['otdel'] = 1;
|
||
break;
|
||
case 1:
|
||
$shopCategory = "Кастеты и ножи";
|
||
break;
|
||
case 11:
|
||
$shopCategory = "Топоры";
|
||
break;
|
||
case 12:
|
||
$shopCategory = "Дубины и булавы";
|
||
break;
|
||
case 13:
|
||
$shopCategory = "Мечи";
|
||
break;
|
||
case 14:
|
||
$shopCategory = "Луки и арбалеты";
|
||
break;
|
||
case 2:
|
||
$shopCategory = "Сапоги";
|
||
break;
|
||
case 21:
|
||
$shopCategory = "Перчатки";
|
||
break;
|
||
case 22:
|
||
$shopCategory = "Легкая броня";
|
||
break;
|
||
case 23:
|
||
$shopCategory = "Тяжелая броня";
|
||
break;
|
||
case 24:
|
||
$shopCategory = "Шлемы";
|
||
break;
|
||
case 3:
|
||
$shopCategory = "Щиты";
|
||
break;
|
||
case 4:
|
||
$shopCategory = "Серьги";
|
||
break;
|
||
case 41:
|
||
$shopCategory = "Ожерелья";
|
||
break;
|
||
case 42:
|
||
$shopCategory = "Кольца";
|
||
break;
|
||
case 5:
|
||
$shopCategory = "Заклинания: нейтральные";
|
||
break;
|
||
case 51:
|
||
$shopCategory = "Заклинания: боевые и защитные";
|
||
break;
|
||
case 6:
|
||
$shopCategory = "Амуниция";
|
||
break;
|
||
case 7:
|
||
$shopCategory = "Букеты";
|
||
break;
|
||
}
|
||
}
|
||
|
||
?>
|
||
<!DOCTYPE html>
|
||
<html>
|
||
<head>
|
||
<meta charset="utf-8">
|
||
<link href="css/main.css" rel="stylesheet"/>
|
||
<script language="JavaScript">
|
||
function AddCount(name, txt) {
|
||
document.all("hint3").innerHTML = '<form method=post style="margin:0; padding:0;"><table border=0 width=100% cellspacing=1 cellpadding=0 bgcolor="#CCC3AA"><tr><td align=center><B>Купить неск. штук</td><td width=20 align=right valign=top style="cursor: hand" onclick="closehint3();"><b>x</td></tr><tr><td colspan=2>' +
|
||
'<table border=0 width=100% cellspacing=0 cellpadding=0 bgcolor="#FFF6DD"><tr><input type="hidden" name="set" value="' + name + '"><td colspan=2 align=center><b><i>' + txt + '</td></tr><tr><td width=80% align=right>' +
|
||
'Количество (шт.) <input type="text" name="count" size=4 ></td><td width=20%> <input type="submit" value=" »» ">' +
|
||
'</td></tr></table></td></tr></table></form>';
|
||
document.all("hint3").style.visibility = "visible";
|
||
document.all("hint3").style.left = 100;
|
||
document.all("hint3").style.top = 100;
|
||
document.all("count").focus();
|
||
}
|
||
|
||
// Закрывает окно
|
||
function closehint3() {
|
||
document.all("hint3").style.visibility = "hidden";
|
||
}
|
||
|
||
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">
|
||
<tr>
|
||
<td>
|
||
<h3><?=$shopCategory?></h3>
|
||
</td>
|
||
</tr>
|
||
<tr>
|
||
<td><!--Рюкзак-->
|
||
<table border=0 width=100% cellspacing="1" cellpadding="2" bgcolor="#A5A5A5">
|
||
<?php
|
||
if ($_REQUEST['present']) {
|
||
if ($_POST['to_login'] && $_POST['flower']) {
|
||
$to = db::c()->query('SELECT `id`,`login`,`room` FROM `users` WHERE `login` = ?i', $_POST['to_login'])->fetch_assoc();
|
||
if ($_POST['to_login'] == $user['login']) {
|
||
err('Очень щедро - дарить что-то самому себе! ;)');
|
||
} elseif ($to['room'] > 500 && $to['room'] < 561) {
|
||
err('Персонаж в данный момент участвует в турнире в Башне Смерти. Попробуйте позже.');
|
||
} else {
|
||
if ($_POST['from'] == 1) {
|
||
$from = 'Аноним';
|
||
} elseif ($_POST['from'] == 2 && $user['klan']) {
|
||
$from = ' клана ' . $user['klan'];
|
||
} else {
|
||
$from = $user['login'];
|
||
}
|
||
|
||
db::c()->query('UPDATE `inventory` SET `owner` = ?i, `present` = "?s", `letter` = "?s" WHERE `present` = "?s" AND `id` = "?s" AND `owner` = ?i AND `dressed` = 0 AND `setsale` = 0', $to['id'], $from, $_POST['podarok2'], null, $_POST['flower'], $_SESSION['uid']);
|
||
$res = db::c()->query('SELECT `id`,`name`,`duration`,`maxdur` FROM `inventory` WHERE `id` = ?i', $_POST['flower'])->fetch_assoc();
|
||
$deloTextSender = "Подарен предмет \"" . $res['name'] . "\" id:(cap" . $res['id'] . ") [" . $res['duration'] . "/" . $res['maxdur'] . "] от \"" . $user['login'] . "\" к \"" . $to['login'] . "\"";
|
||
$deloTextReceiver = "Подарен предмет \"" . $res['name'] . "\" id:(cap" . $res['id'] . ") [" . $res['duration'] . "/" . $res['maxdur'] . "] от \"" . $user['login'] . "\" к \"" . $to['login'] . "\"";
|
||
db::c()->query('INSERT INTO `delo`(`author`,`pers`,`text`,`type`,`date`) VALUES (0,?i,"?s",1,?i)', $_SESSION['uid'], $deloTextSender, time());
|
||
db::c()->query('INSERT INTO `delo`(`author`,`pers`,`text`,`type`,`date`) VALUES (0,?i,"?s",1,?i)', $to['id'], $deloTextReceiver, time());
|
||
|
||
$telegraphText = "Вам пришёл подарок \"" . $res['name'] . "\" от " . $from . "!";
|
||
db::c()->query('INSERT INTO `telegraph` (receiver, text) VALUES (?i,"?s")', $to['id'], $telegraphText)->fetch_assoc();
|
||
|
||
err('Подарок удачно доставлен к ' . $_POST['to_login']);
|
||
}
|
||
}
|
||
?>
|
||
<!-- Подарить подарок -->
|
||
<table cellspacing=0 cellpadding=0 width=100% bgcolor=#e0e0e2>
|
||
<td>
|
||
<form method="post">
|
||
<input type=hidden name=present value=1>
|
||
Вы можете сделать подарок дорогому человеку. Ваш подарок будет
|
||
отображаться в информации о персонаже.
|
||
<ol>
|
||
<li>Укажите логин персонажа, которому хотите сделать подарок<br>
|
||
<input type=text name=to_login value="" placeholder="Логин">
|
||
<li><input type=text name=podarok2 value="" maxlength=60 size=50
|
||
placeholder="Цель подарка.">
|
||
<li><textarea name=txt rows=6 cols=80
|
||
placeholder="Текст сопроводительной записки (в информации о персонаже не отображается)"></textarea>
|
||
<li>Выберите, от чьего имени подарок:<br>
|
||
<label><input type=radio name=from value=0
|
||
checked> <?= nick::id($user['id'])->full() ?>
|
||
</label><br>
|
||
<label><input type=radio name=from value=1> анонимно</label><br>
|
||
<label><input type=radio name=from value=2> от имени
|
||
клана</label><br>
|
||
<li>Нажмите кнопку <b>Подарить</b> под предметом, который хотите
|
||
преподнести в подарок:<br>
|
||
</ol>
|
||
<input type="hidden" name="flower" id="flower" value="">
|
||
<table class="zebra" width=100% cellspacing="1" cellpadding="2"
|
||
bgcolor="#A5A5A5">
|
||
<?php
|
||
$data = db::c()->query('SELECT `id`,`img` FROM `inventory` WHERE `owner`= ?i
|
||
AND `dressed` = 0
|
||
AND (
|
||
`name` LIKE "?S" OR `name` LIKE "?S" OR `name` LIKE "?S" OR `name` LIKE "?S" OR `name` LIKE "?S" OR
|
||
`name` LIKE "?S" OR `name` LIKE "?S" OR `name` LIKE "?S"
|
||
)
|
||
AND `setsale` = 0 AND `present` = "?s"
|
||
ORDER BY `id` DESC', $_SESSION['uid'], '%Букет%', '%Сувенир%', '%Подарок%', '%Валентинка%', '%Открытка%', 'Ель%', '%Медаль%', '%Статуэтка%', null);
|
||
while ($row = $data->fetch_assoc()) {
|
||
if (!in_array($row['id'], array_keys($_SESSION['flowers']))) {
|
||
$row['count'] = 1;
|
||
?>
|
||
<tr>
|
||
<td align=center style='width:150px'>
|
||
<img src="i/sh/<?= $row['img'] ?>">
|
||
<br><input type=submit
|
||
onClick="document.all['flower'].value="<?= $row['id']; ?>
|
||
value="Подарить">
|
||
</td>
|
||
<td valign=top>
|
||
<?php showitem($row); ?>
|
||
</td>
|
||
</tr>
|
||
<?php
|
||
}
|
||
}
|
||
?>
|
||
</form>
|
||
</td>
|
||
</table>
|
||
<?
|
||
} else {
|
||
$data = db::c()->query('SELECT `id`,`img`,`name` FROM `ashop` WHERE `count` > 0 AND `razdel` = "?s" AND `ecost` > 0 ORDER BY `ecost` ASC', $_GET['otdel']);
|
||
while ($row = $data->fetch_assoc()) {
|
||
?>
|
||
<tr>
|
||
<td align=center style='width:150px'><img src="i/sh/<?= $row['img'] ?>"
|
||
border=0>
|
||
<br/>
|
||
<a href="ashop.php?otdel=<?= $_GET['otdel'] ?>&set=<?= $row['id'] ?>&sid=">купить</A>
|
||
<img src="i/up.gif" width=11 height=11 border=0 alt="Купить несколько штук"
|
||
style="cursor:hand"
|
||
onClick="AddCount("<?= $row['id'] ?>", "<?= $row['name'] ?>")">
|
||
</td>
|
||
<td valign=top>
|
||
<?php showitem($row); ?>
|
||
</td>
|
||
</tr>
|
||
<?php
|
||
}
|
||
}
|
||
?>
|
||
</table>
|
||
</td>
|
||
</tr>
|
||
</table>
|
||
</td>
|
||
<td valign=top width=280>
|
||
<b>Масса всех ваших вещей: <?= getItemsMassaInfo() ?>
|
||
<br>У вас в наличии: <span style="color: #339900;"><?= $bank['ekr'] ?></span> екр.</b>
|
||
<hr/>
|
||
<a href=upgrade_items.php>Улучшение Артефактов</a>
|
||
<hr>
|
||
|
||
<div style="background-color: #d2d0d0;padding: 1px; text-align: center; font-weight: bold;">
|
||
Отделы магазина
|
||
</div>
|
||
<dl>
|
||
<dt><b>Оружие:</b></dt>
|
||
<dd><a href="ashop.php?otdel=1&rnd=<?= mt_rand() ?>">кастеты,ножи</a></dd>
|
||
<dd><a href="ashop.php?otdel=11&rnd=<?= mt_rand() ?>">топоры</a></dd>
|
||
<dd><a href="ashop.php?otdel=12&rnd=<?= mt_rand() ?>">дубины,булавы</a></dd>
|
||
<dd><a href="ashop.php?otdel=13&rnd=<?= mt_rand() ?>">мечи</a></dd>
|
||
<dt><b>Одежда:</b></dt>
|
||
<dd><a href="ashop.php?otdel=24&rnd=<?= mt_rand() ?>">шлемы</a></dd>
|
||
<dd><a href="ashop.php?otdel=23&rnd=<?= mt_rand() ?>">тяжелая броня</a></dd>
|
||
<dd><a href="ashop.php?otdel=22&rnd=<?= mt_rand() ?>">легкая броня</a></dd>
|
||
<dd><a href="ashop.php?otdel=3&rnd=<?= mt_rand() ?>">щиты</a></dd>
|
||
<dd><a href="ashop.php?otdel=21&rnd=<?= mt_rand() ?>">перчатки</a></dd>
|
||
<dd><a href="ashop.php?otdel=2&rnd=<?= mt_rand() ?>">сапоги</a></dd>
|
||
<dt><b>Ювелирные товары:</b></dt>
|
||
<dd><a href="ashop.php?otdel=4&rnd=<?= mt_rand() ?>">серьги</a></dd>
|
||
<dd><a href="ashop.php?otdel=41&rnd=<?= mt_rand() ?>">ожерелья</a></dd>
|
||
<dd><a href="ashop.php?otdel=42&rnd=<?= mt_rand() ?>">кольца</a></dd>
|
||
<dt><b>Магия:</b></dt>
|
||
<dd><a href="ashop.php?otdel=51&rnd=<?= mt_rand() ?>">боевые</a></dd>
|
||
<dd><a href="ashop.php?otdel=5&rnd=<?= mt_rand() ?>">разные</a></dd>
|
||
<dt><b>Разное:</b></dt>
|
||
<dd><a href="ashop.php?otdel=6&rnd=<?= mt_rand() ?>">амуниция</a></dd>
|
||
<dd><a href="ashop.php?otdel=7rnd=<?= mt_rand() ?>">букеты</a></dd>
|
||
</dl>
|
||
<div id="hint3" class="ahint"></div>
|
||
</td>
|
||
</tr>
|
||
</table>
|
||
</body>
|
||
</html>
|