battles/shop.php

160 lines
6.0 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
use Battles\Bank;
use Battles\Database\DBPDO;
use Battles\GameLogs;
use Battles\Item;
use Battles\ShopItem;
use Battles\Template;
use Battles\User;
ob_start();
session_start();
require_once 'functions.php';
$user = $user ?? new User($_SESSION['uid']);
$db = new DBPDO();
$saleItems = false;
$shopCategoryType = $_POST['sale'] ?? '';
$shopCategoryTypeNumber = $_GET['otdel'] ?? 0;
$status = null;
if (!empty($_POST['sellshop'])) {
$status = ShopItem::sellItem($_POST['itemId'], $user, 1);
}
if (!empty($_POST['buyshop'])) {
$status = ShopItem::buyItem($_POST['itemId'], $user);
}
$bank = new Bank($user->getId());
switch ($shopCategoryTypeNumber) {
default:
$shopCategoryType = "Все товары";
break;
case Item::ITEM_TYPE_HELMET:
$shopCategoryType = "Шлемы";
break;
case Item::ITEM_TYPE_ARMOR:
$shopCategoryType = "Броня";
break;
case Item::ITEM_TYPE_LEGS:
$shopCategoryType = "Поножи";
break;
case Item::ITEM_TYPE_BOOTS:
$shopCategoryType = "Сапоги";
break;
case Item::ITEM_TYPE_GLOVES:
$shopCategoryType = "Перчатки";
break;
case Item::ITEM_TYPE_WEAPON:
$shopCategoryType = "Оружие";
break;
case Item::ITEM_TYPE_SHIELD:
$shopCategoryType = "Щиты";
break;
case Item::ITEM_TYPE_BELT:
$shopCategoryType = "Пояса";
break;
case Item::ITEM_TYPE_RING:
$shopCategoryType = "Кольца";
break;
case Item::ITEM_TYPE_AMULET:
$shopCategoryType = "Амулеты";
break;
case Item::ITEM_TYPE_CONSUMABLE:
$shopCategoryType = "Расходники";
break;
case Item::ITEM_TYPE_OTHER:
$shopCategoryType = "Разное";
break;
case 'sale':
$shopCategoryType = "Предметы в инвентаре";
$saleItems = true;
break;
}
// MUST BE ARRAY!
$iteminfo = [];
if (!$saleItems) {
$shopItems = $db->ofetchAll("select * from items inner join trade_offers on id = shop_item_id where shop_id = 1 and shop_item_quantity !=0");
foreach ($shopItems as $shopItemObject) {
$iteminfo[] = new ShopItem($shopItemObject, 'buyshop');
}
} else {
$inventoryItems = $db->ofetchall("select * from inventory where on_sale = 0 and dressed_slot = 0 and durability > 0 and owner_id = ?", $user->getId());
foreach ($inventoryItems as $inventoryItemObject) {
$iteminfo[] = new ShopItem($inventoryItemObject, 'sellshop');
}
}
Template::header('Магазин');
?>
<script src="js/main.js"></script>
<style>
a.waretype {
margin: 2px 16px;
padding: 6px;
border: 1px silver solid;
border-radius: 4px;
background-color: #ccc;
display: block;
}
a.sell {
background-color: #cdc;
}
a.alltypes {
background-color: #ccd;
}
.status {
color:darkgreen;
background:#afa;
}
</style>
<h1>Государственный магазин</h1>
<a href=# onclick=hrefToFrame('city.php?cp')> ← выйти на Центральную площадь</a>
<div class="status"><?= $status ?></div>
<table style="width: 100%; border-collapse: collapse; border-spacing: 0; padding: 4px;">
<tr>
<td style="vertical-align: top; text-align: left;">
<h3><?= $shopCategoryType ?></h3>
<?php if ($saleItems): ?>
<div style="text-align: center;">Вы можете продать ваши предметы за сущие копейки.</div>
<?php endif; ?>
<!--Магазин-->
<table class="zebra" style="width: 100%; border-collapse: separate; border-spacing: 1px; padding: 2px;">
<?php
foreach ($iteminfo as $ii) {
if ($ii->getItemType() != $shopCategoryTypeNumber && $shopCategoryTypeNumber != 'sale') {
continue;
}
echo "<tr><td style='width: 150px; text-align: center; padding: 5px;'>";
echo $ii->printImage();
$ii->printControls();
echo "<td style='vertical-align: top; padding: 5px;'>";
$ii->printInfo();
}
?>
</table>
<td style="width: 280px; vertical-align: top;">
<strong>
Масса всех ваших вещей: <?= getItemsMassaInfo() ?> <br>
У вас в банке: <span style="color: darkgreen;"><?= $bank->getMoney() ?></span> банкнот.
</strong>
<hr>
<div style="text-align: center; font-weight: bold;">Отделы магазина</div>
<a class="waretype" href="?otdel=6&rnd=<?= mt_rand() ?>">Оружие</a>
<a class="waretype" href="?otdel=1&rnd=<?= mt_rand() ?>">Шлемы</a>
<a class="waretype" href="?otdel=2&rnd=<?= mt_rand() ?>">Броня</a>
<a class="waretype" href="?otdel=3&rnd=<?= mt_rand() ?>">Поножи</a>
<a class="waretype" href="?otdel=4&rnd=<?= mt_rand() ?>">Сапоги</a>
<a class="waretype" href="?otdel=5&rnd=<?= mt_rand() ?>">Перчатки</a>
<a class="waretype" href="?otdel=7&rnd=<?= mt_rand() ?>">Щиты</a>
<a class="waretype" href="?otdel=8&rnd=<?= mt_rand() ?>">Пояса</a>
<a class="waretype" href="?otdel=9&rnd=<?= mt_rand() ?>">Кольца</a>
<a class="waretype" href="?otdel=10&rnd=<?= mt_rand() ?>">Амулеты</a>
<a class="waretype" href="?otdel=20&rnd=<?= mt_rand() ?>">Расходники</a>
<a class="waretype" href="?otdel=50&rnd=<?= mt_rand() ?>">Разное</a>
<a class="waretype alltypes" href="?rnd=<?= mt_rand() ?>">Все товары</a>
<a class="waretype sell" href="?otdel=sale&rnd=<?= mt_rand() ?>">Продать вещи</a>
<div id="hint3" class="ahint"></div>
</table>