336 lines
19 KiB
PHP
336 lines
19 KiB
PHP
<?php
|
||
session_start();
|
||
if ($_SESSION['uid'] == null) header("Location: index.php");
|
||
require_once 'functions.php';
|
||
|
||
if ($user['level'] < 1) {
|
||
header("Location: main.php");
|
||
die();
|
||
}
|
||
if ($user['room'] != 25) {
|
||
header("Location: main.php");
|
||
die();
|
||
}
|
||
if ($user['battle'] != 0) {
|
||
header('location: fbattle.php');
|
||
die();
|
||
}
|
||
|
||
$get = urldecode(filter_input(INPUT_SERVER, 'QUERY_STRING'));
|
||
|
||
if (isset($_GET['kredit'])) $itemCost = checkIntInRange($_GET['kredit']);
|
||
if (isset($_GET['n'])) $itemId = checkIntInRange($_GET['n']);
|
||
if (isset($_GET['back'])) $returningItemId = checkIntInRange($_GET['back']);
|
||
|
||
if ($itemCost && $itemId) {
|
||
$commission = ceil($itemCost / 10); # 10% от суммы с округлением вверх.
|
||
if ($user['money'] > $commission) {
|
||
$dress = db::c()->query('SELECT `name`,`duration`,`maxdur` FROM `inventory` WHERE `dressed` = 0 AND `id` = ?i AND `owner` = ?i', $itemId, $_SESSION['uid'])->fetch_assoc();
|
||
if (db::c()->getAffectedRows()) {
|
||
$deloText = "{$user['login']} выставил товар: «{$dress['name']}» id:({$itemId}) [{$dress['duration']}/{$dress['maxdur']}] на продажу в комиссионку за {$itemCost} кр. ";
|
||
addToDelo($deloText);
|
||
db::c()->query('UPDATE `inventory` SET `setsale` = ?i WHERE `id` = ?i', $itemCost, $itemId);
|
||
db::c()->query('UPDATE `users` SET `money` = `money` - ?i WHERE `id` = ?i', $commission, $_SESSION['uid']);
|
||
$status = "Вы сдали в магазин «{$dress['name']}» за {$itemCost} кр. Вычтено за услуги магазина: {$commission} кр.";
|
||
} else $status = "Предмет не найден в инвентаре!";
|
||
} else $status = "У вас не хватает " . $commission - $user['money'] . " кр. чтобы оплатить комиссию!";
|
||
}
|
||
|
||
if ($returningItemId) {
|
||
$dress = db::c()->query('SELECT `name`,`duration`,`maxdur` FROM `inventory` WHERE `dressed` = 0 AND `setsale` > 0 AND `id` = ?i AND `owner` = ?i', $returningItemId, $_SESSION['uid'])->fetch_assoc();
|
||
if (db::c()->getAffectedRows()) {
|
||
$deloText = "{$user['login']} забрал свой товар: «{$dress['name']}» id:({$returningItemId}) [{$dress['duration']}/{$dress['maxdur']}] из комиссионки.";
|
||
addToDelo($deloText);
|
||
db::c()->query('UPDATE `inventory` SET `setsale` = 0 WHERE `id` = ?i', $returningItemId);
|
||
$status = "Вы забрали из магазина ваш «{$dress['name']}».";
|
||
} else $status = "Предмет не найден на полках магазина!";
|
||
}
|
||
|
||
|
||
if ($_GET['set']) {
|
||
|
||
if (!$_POST['count'] || !is_numeric($_POST['count']) || $_POST['count'] <= 0) {
|
||
$_POST['count'] = 1;
|
||
}
|
||
if (is_numeric($set) && $set > 0) {
|
||
$dress = mysql_fetch_array(mysql_query("SELECT * FROM `inventory` WHERE `dressed`=0 AND `id` = '{$set}' and `owner`!='" . $user['id'] . "' AND `setsale` > 0"));
|
||
$userfrom = mysql_fetch_array(mysql_query("SELECT `login`,`id` FROM `users` WHERE `id` = '" . $dress['owner'] . "' LIMIT 1;"));
|
||
$d = mysql_fetch_array(mysql_query("SELECT sum(`massa`) FROM `inventory` WHERE `owner` = '{$_SESSION['uid']}' AND `dressed` = 0 AND `setsale` = 0 ; "));
|
||
if ($userfrom['id'] && $dress['id']) {
|
||
if (($dress['massa'] + $d[0]) > (get_meshok())) {
|
||
echo "<font color=red><b>Недостаточно места в рюкзаке.</b></font>";
|
||
} elseif ($user['money'] >= $dress['setsale']) {
|
||
if (mysql_query("UPDATE `inventory` SET `owner` = '{$user['id']}', `setsale` = 0 WHERE `id` = '{$set}' AND `setsale` > '0' LIMIT 1;")) {
|
||
$good = 1;
|
||
} else {
|
||
$good = 0;
|
||
}
|
||
|
||
if ($good) {
|
||
//mysql_query("UPDATE `shop` SET `count`=`count`-{$_POST['count']} WHERE `id` = '{$set}' LIMIT 1;");
|
||
echo "<font color=red><b>Вы купили \"" . $dress['name'] . "\".</b></font>";
|
||
$moneyto = round($dress['setsale'] * 0.90, 2);
|
||
$komiss = round($dress['setsale'] * 0.10, 2);
|
||
mysql_query("UPDATE `users` set `money` = `money`- '" . $dress['setsale'] . "' WHERE id = {$_SESSION['uid']}");
|
||
mysql_query("UPDATE `users` set `money` = `money`+ '" . $moneyto . "' WHERE id = {$userfrom['id']}");
|
||
mysql_query("INSERT INTO `delo` (`id` , `author` ,`pers`, `text`, `type`, `date`) VALUES ('','0','{$_SESSION['uid']}','\"" . $user['login'] . "\" купил товар: \"" . $dress['name'] . "\" id:(cap" . $dress['id'] . ") [" . $dress['duration'] . "/" . $dress['maxdur'] . "] от \"" . $userfrom['login'] . "\" за " . $dress['setsale'] . " кр. в комиссионке ',5,'" . time() . "');");
|
||
mysql_query("INSERT INTO `delo` (`id` , `author` ,`pers`, `text`, `type`, `date`) VALUES ('','0','{$userfrom['id']}','\"" . $user['login'] . "\" купил товар: \"" . $dress['name'] . "\" id:(cap" . $dress['id'] . ") [" . $dress['duration'] . "/" . $dress['maxdur'] . "] от \"" . $userfrom['login'] . "\" за " . $dress['setsale'] . " кр. в комиссионке ',5,'" . time() . "');");
|
||
mysql_query("INSERT INTO `delo` (`id` , `author` ,`pers`, `text`, `type`, `date`) VALUES ('','0','{$_SESSION['uid']}','\"" . $user['login'] . "\" купил товар: \"" . $dress['name'] . "\" id:(cap" . $dress['id'] . ") [" . $dress['duration'] . "/" . $dress['maxdur'] . "] за " . $dress['setsale'] . " кр. в комиссионке ',1,'" . time() . "');");
|
||
mysql_query("INSERT INTO `delo` (`id` , `author` ,`pers`, `text`, `type`, `date`) VALUES ('','0','{$userfrom['id']}','\"" . $userfrom['login'] . "\" получил " . $moneyto . " кр. за продажу товара: \"" . $dress['name'] . "\" id:(cap" . $dress['id'] . ") [" . $dress['duration'] . "/" . $dress['maxdur'] . "] через комиссионку ',1,'" . time() . "');");
|
||
$user['money'] = $user['money'] - $dress['setsale'];
|
||
$us = mysql_fetch_array(mysql_query("select `id` from `online` WHERE `date` >= " . (time() - 60) . " AND `id` = '{$userfrom['id']}' LIMIT 1;"));
|
||
if ($us[0]) {
|
||
addchp('<font color=red>Внимание!</font> Успешно продан предмет "' . $dress['name'] . '" за ' . $dress['setsale'] . ' кр. Комиссия составила ' . $komiss . ' кр. Вам перечислено от комиссионного магазина ' . $moneyto . ' кр. ', '{[]}' . $userfrom['login'] . '{[]}');
|
||
} else {
|
||
// если в офе
|
||
mysql_query("INSERT INTO `telegraph` (`receiver`,`date`,`text`) values ('" . $userfrom['id'] . "','','" . '<font color=red>Внимание!</font> Успешно продан предмет "' . $dress['name'] . '" за ' . $dress['setsale'] . ' кр. Комиссия составила ' . $komiss . ' кр. Вам перечислено от комиссионного магазина ' . $moneyto . ' кр. ' . "');");
|
||
}
|
||
}
|
||
} else {
|
||
echo "<font color=red><b>Недостаточно денег или нет вещей в наличии.</b></font>";
|
||
}
|
||
} else {
|
||
echo "<font color=red><b>Вещь не найдена в магазине</b></font>";
|
||
}
|
||
} else {
|
||
echo "<font color=red><b>Не надо так делать</b></font>";
|
||
}
|
||
}
|
||
|
||
if ($get === 'sale') {
|
||
$data = db::c()->query('SELECT `inventory`.*,
|
||
`magic`.`name` AS `magic_name`,
|
||
`magic`.`chanse` AS `magic_chanse`,
|
||
`magic`.`time` AS `magic_time`,
|
||
`magic`.`file` AS `magic_file`,
|
||
`magic`.`targeted` AS `magic_targeted`,
|
||
`magic`.`needcharge` AS `magic_needcharge`,
|
||
`magic`.`img` AS `magic_img`,
|
||
0 AS `maxdur`
|
||
|
||
FROM `inventory` LEFT JOIN `magic` ON `magic` = `magic`.`id` WHERE `setsale` = 0 AND `dressed` = 0 AND `present` = "?s" AND `owner` = ?i ORDER BY `update` DESC ', '', $_SESSION['uid']);
|
||
$iteminfo = [];
|
||
while ($row = $data->fetch_assoc()) {
|
||
$iteminfo[] = new ShopItem($row);
|
||
}
|
||
}
|
||
|
||
if ($get === 'unsale') {
|
||
$data = db::c()->query('SELECT `inventory`.*,
|
||
`magic`.`name` AS `magic_name`,
|
||
`magic`.`chanse` AS `magic_chanse`,
|
||
`magic`.`time` AS `magic_time`,
|
||
`magic`.`file` AS `magic_file`,
|
||
`magic`.`targeted` AS `magic_targeted`,
|
||
`magic`.`needcharge` AS `magic_needcharge`,
|
||
`magic`.`img` AS `magic_img`,
|
||
0 AS `maxdur`
|
||
|
||
FROM `inventory` LEFT JOIN `magic` ON `magic` = `magic`.`id` WHERE `setsale` > 0 AND `dressed` = 0 AND `owner` = ?i ORDER BY `update` DESC', $_SESSION['uid']);
|
||
$iteminfo = [];
|
||
while ($row = $data->fetch_assoc()) {
|
||
$iteminfo[] = new ShopItem($row);
|
||
}
|
||
}
|
||
|
||
$shopCategoryTypeNumber = empty($_GET['otdel']) ?: $_GET['otdel'];
|
||
switch ($shopCategoryTypeNumber) {
|
||
default:
|
||
$shopCategoryType = "Предметы в инвентаре";
|
||
$saleItems = true;
|
||
break;
|
||
case 1:
|
||
$shopCategoryType = "Кинжалы";
|
||
break;
|
||
case 11:
|
||
$shopCategoryType = "Топоры";
|
||
break;
|
||
case 12:
|
||
$shopCategoryType = "Дубины";
|
||
break;
|
||
case 13:
|
||
$shopCategoryType = "Мечи";
|
||
break;
|
||
case 2:
|
||
$shopCategoryType = "Сапоги";
|
||
break;
|
||
case 21:
|
||
$shopCategoryType = "Перчатки";
|
||
break;
|
||
case 22:
|
||
$shopCategoryType = "Легкая броня";
|
||
break;
|
||
case 23:
|
||
$shopCategoryType = "Тяжелая броня";
|
||
break;
|
||
case 24:
|
||
$shopCategoryType = "Шлемы";
|
||
break;
|
||
case 3:
|
||
$shopCategoryType = "Щиты";
|
||
break;
|
||
case 4:
|
||
$shopCategoryType = "Серьги";
|
||
break;
|
||
case 41:
|
||
$shopCategoryType = "Ожерелья";
|
||
break;
|
||
case 42:
|
||
$shopCategoryType = "Кольца";
|
||
break;
|
||
case 5:
|
||
$shopCategoryType = "Заклинания: нейтральные";
|
||
break;
|
||
case 51:
|
||
$shopCategoryType = "Заклинания: боевые и защитные";
|
||
break;
|
||
case 6:
|
||
$shopCategoryType = "Амуниция";
|
||
break;
|
||
}
|
||
?>
|
||
<HTML>
|
||
<HEAD>
|
||
<link rel=stylesheet href="css/main.css">
|
||
<script src="js/main.js"></script>
|
||
<meta charset="utf-8">
|
||
<SCRIPT LANGUAGE="JavaScript">
|
||
function sale(name, txt, n, kr) {
|
||
var s = prompt("Сдать в магазин \"" + txt + "\". Укажите цену:", kr);
|
||
if ((s != null) && (s !== '')) {
|
||
location.href = "?sale=" + name + "&kredit=" + s + "&n=" + n;
|
||
}
|
||
}
|
||
</SCRIPT>
|
||
</HEAD>
|
||
<body>
|
||
<div style="float: right;">
|
||
<button onclick="hrefToFrame('?sale')">Сдать вещи в магазин</button>
|
||
<button onclick="hrefToFrame('?unsale')">Забрать вещи из магазина</button>
|
||
<button onclick="hrefToFrame('city.php?cp=1')">Вернуться</button>
|
||
</div>
|
||
<TABLE width=100% cellspacing="0" cellpadding="4">
|
||
<TR>
|
||
<TD valign=top align=left>
|
||
<!--Комиссионный Магазин-->
|
||
<TABLE width=100% cellspacing="0" cellpadding="0" bgcolor="#A5A5A5">
|
||
<TR>
|
||
<TD align=center>
|
||
<B>Отдел "<?php
|
||
if ($get === 'sale') echo "Сдать вещи";
|
||
elseif ($get === 'unsale') echo "Забрать вещи";
|
||
else echo $shopCategoryType; ?>"</B>
|
||
</TD>
|
||
</TR>
|
||
<TR>
|
||
<TD><!--Рюкзак-->
|
||
<TABLE BORDER=0 WIDTH=100% CELLSPACING="1" CELLPADDING="2" BGCOLOR="#A5A5A5">
|
||
<?php
|
||
if ($_REQUEST['max']) {
|
||
$data = db::c()->query('SELECT * FROM `inventory` WHERE `dressed` = 0 AND `name` LIKE "?S" AND `setsale` > 0 ORDER BY `setsale` ASC', $_REQUEST['max'] . '%');
|
||
|
||
while ($row = $data->fetch_assoc()) {
|
||
$row['cost'] = $row['setsale'];
|
||
?>
|
||
|
||
<TR>
|
||
<TD align=center style="width:150px"><IMG SRC="i/sh/<?= $row['img'] ?>">
|
||
<BR> <A HREF="?otdel=<?= $_GET['otdel'] ?>&set=<?= $row['id'] ?>&sid=">купить</A>
|
||
</TD>
|
||
<TD valign=top>
|
||
<?php showitem($row); ?>
|
||
</TD>
|
||
</TR>
|
||
<?php
|
||
}
|
||
} elseif ($get === 'sale') {
|
||
echo "<TR bgcolor=#C7C7C7><th colspan=2>Комиссия за услуги магазина составляет 10% от цены, по которой вы предлагаете предмет.</th></TR>";
|
||
|
||
foreach ($iteminfo as $ii) {
|
||
echo "<tr><td style='width: 150px; text-align: center;'>";
|
||
$ii->printImage(); ?>
|
||
<br><button onclick="sale(1, '<?= $iteminfo['name'] ?>', '<?= $iteminfo['id'] ?>', '<?= $iteminfo['cost'] ?>')">Cдать в магазин</button>
|
||
<?php
|
||
echo "</td>";
|
||
echo "<td style='vertical-align: top;'>";
|
||
$ii->printInfo();
|
||
echo "</td></tr>";
|
||
}
|
||
|
||
} elseif ($get === 'unsale') {
|
||
|
||
foreach ($iteminfo as $ii) {
|
||
echo "<tr><td style='width: 150px; text-align: center;'>";
|
||
$ii->printImage();
|
||
$ii->printControls('marketgetback');
|
||
echo "</td>";
|
||
echo "<td style='vertical-align: top;'>";
|
||
$ii->printInfo();
|
||
echo "</td></tr>";
|
||
}
|
||
|
||
} else {
|
||
$data = db::c()->query('SELECT DISTINCT `img`, `name`, `nalign`, `massa` FROM `inventory` WHERE `dressed` = 0 AND `setsale` > 0 AND `present` = "?s" AND `otdel` = "?s" GROUP BY `img` ORDER BY `cost` ASC', '', $_GET['otdel']);
|
||
$replacements = ['+1','+2','+3','+4','+5',' (мф)'];
|
||
while ($row = $data->fetch_assoc()) {
|
||
$item_name = str_replace($replacements, '', $row['name']);
|
||
$item = db::c()->query('SELECT COUNT(`id`), MIN(`duration`), MIN(`maxdur`), MAX(`duration`), MAX(`maxdur`), MIN(`setsale`), MAX(`setsale`) FROM `inventory` WHERE `dressed` = 0 AND `setsale` > 0 AND `present` = "?s" AND `name` LIKE "?S"', '', $item_name.'%')->fetch_assoc();
|
||
?>
|
||
<TR>
|
||
<TD align=center>
|
||
<IMG SRC="i/sh/<?= $row['img'] ?>" ALT="">
|
||
<BR><A HREF="?max=<?= $item_name ?>">подробнее</A>
|
||
</TD>
|
||
<TD valign=top>
|
||
<?= $item_name ?> <img src="i/align_<?= $row['nalign'] ?>.gif">
|
||
(Масса: <?= $row['massa'] ?>) <BR>
|
||
<b>Цена: <?= round($item[5], 2) ?> - <?= round($item[6], 2) ?> кр.</b>
|
||
<small>(количество: <?= $item[0] ?>)</small>
|
||
<BR>Долговечность: <?= $item[1] ?>-<?= $item[2] ?>/<?= $item[3] ?> -<?= $item[4] ?><BR>
|
||
</TD>
|
||
</TR>
|
||
<?
|
||
}
|
||
}
|
||
?>
|
||
</TABLE>
|
||
</TD>
|
||
</TR>
|
||
</TABLE>
|
||
</TD>
|
||
<TD valign=top width=280>
|
||
<div style="MARGIN-LEFT:15px; MARGIN-TOP: 10px;">
|
||
<B>Масса всех ваших вещей: <?= getItemsMassaInfo() ?>
|
||
<BR>У вас в наличии: <span style="color: darkgreen;"><?= $user['money'] ?></span> кр.</B>
|
||
<hr>
|
||
<div style="text-align: center; font-weight: bold;">Отделы магазина</div>
|
||
<dl>
|
||
<dt><b>Оружие:</b></dt>
|
||
<dd><a href="?otdel=1&rnd=<?= mt_rand() ?>">кинжалы</a></dd>
|
||
<dd><a href="?otdel=11&rnd=<?= mt_rand() ?>">топоры</a></dd>
|
||
<dd><a href="?otdel=12&rnd=<?= mt_rand() ?>">дубины</a></dd>
|
||
<dd><a href="?otdel=13&rnd=<?= mt_rand() ?>">мечи</a></dd>
|
||
<dt><b>Одежда:</b></dt>
|
||
<dd><a href="?otdel=24&rnd=<?= mt_rand() ?>">шлемы</a></dd>
|
||
<dd><a href="?otdel=23&rnd=<?= mt_rand() ?>">тяжелая броня</a></dd>
|
||
<dd><a href="?otdel=22&rnd=<?= mt_rand() ?>">легкая броня</a></dd>
|
||
<dd><a href="?otdel=3&rnd=<?= mt_rand() ?>">щиты</a></dd>
|
||
<dd><a href="?otdel=21&rnd=<?= mt_rand() ?>">перчатки</a></dd>
|
||
<dd><a href="?otdel=2&rnd=<?= mt_rand() ?>">сапоги</a></dd>
|
||
<dt><b>Ювелирные товары:</b></dt>
|
||
<dd><a href="?otdel=4&rnd=<?= mt_rand() ?>">серьги</a></dd>
|
||
<dd><a href="?otdel=41&rnd=<?= mt_rand() ?>">ожерелья</a></dd>
|
||
<dd><a href="?otdel=42&rnd=<?= mt_rand() ?>">кольца</a></dd>
|
||
<dt><b>Магия:</b></dt>
|
||
<dd><a href="?otdel=51&rnd=<?= mt_rand() ?>">боевые</a></dd>
|
||
<dd><a href="?otdel=5&rnd=<?= mt_rand() ?>">разные</a></dd>
|
||
<dt><b>Разное:</b></dt>
|
||
<dd><a href="?otdel=6&rnd=<?= mt_rand() ?>">амуниция</a></dd>
|
||
</dl>
|
||
</div>
|
||
<div id="hint3" class="ahint"></div>
|
||
</TD>
|
||
</TR>
|
||
</TABLE>
|
||
</BODY>
|
||
</HTML>
|