View file vobog-wmzo_ru/user/inv.php

File size: 5.03Kb
<?php
require_once ('../system/core.php');
auth();

$max_slots = 100;
$base_price = 100;

if (isset($_GET['upgrade'])) {
    if ($user['inv_limit'] < $max_slots) {
        $upgrade_cost = (($user['inv_limit'] - 15) / 5 + 1) * $base_price;
        $res = db_query("UPDATE `users` SET `gold` = `gold` - ?, `inv_limit` = `inv_limit` + 5 WHERE `id` = ? AND `gold` >= ?", [$upgrade_cost, $myID, $upgrade_cost]);
        if ($res->rowCount()) set_msg("Рюкзак расширен!");
        else set_msg("Недостаточно золота!", "error");
    }
    header("Location: inv.php"); exit;
}

if (isset($_POST['sell_batch']) && !empty($_POST['items'])) {
    $ids = array_map('intval', $_POST['items']);
    $placeholders = implode(',', array_fill(0, count($ids), '?'));
    $items = db_query("SELECT SUM(it.price) as total_price FROM `inventory` i JOIN `items` it ON i.item_id = it.id WHERE i.id IN ($placeholders) AND i.user_id = ? AND i.equiped = '0'", array_merge($ids, [$myID]))->fetch();
    if ($items['total_price'] > 0) {
        $money = round($items['total_price'] / 2);
        db_query("UPDATE `users` SET `gold` = `gold` + ? WHERE `id` = ?", [$money, $myID]);
        db_query("DELETE FROM `inventory` WHERE id IN ($placeholders) AND user_id = ?", array_merge($ids, [$myID]));
        set_msg("Продано на сумму: " . $money . " золота!");
    }
    header("Location: inv.php"); exit;
}

$title = 'Рюкзак';
require_once ('../system/thead.php');
show_msg();

$per_page = 10;
$total_items = (int)db_query("SELECT COUNT(*) FROM `inventory` WHERE `user_id` = ? AND `equiped` = '0'", [$myID])->fetchColumn();
$total_pages = max(1, ceil($total_items / $per_page));
$page = isset($_GET['page']) ? max(1, min($total_pages, (int)$_GET['page'])) : 1;
$start = ($page - 1) * $per_page;

echo '<div style="text-align:center; margin-bottom:10px;"><div class="head-new"><div class="b-new" style="display:inline-block; width:90%;">РЮКЗАК (' . $total_items . ' / ' . $user['inv_limit'] . ')</div></div></div>';

echo '<div class="msg-new" style="margin-bottom:10px;"><div class="wr4-new" style="padding:10px; display:flex; justify-content:center; gap:10px;">';
echo '<a href="/user/equip.php" class="bbtn-new" style="width:130px; text-decoration:none;"><span class="lbl-new" style="color:#fff; font-size:11px;">ЭКИПИРОВКА</span></a>';
if ($user['inv_limit'] < $max_slots) {
    $next_cost = (($user['inv_limit'] - 15) / 5 + 1) * $base_price;
    echo '<a href="?upgrade=1" class="bbtn-new" style="width:130px; text-decoration:none;"><span class="lbl-new" style="color:#e2b70b; font-size:11px;">+5 СЛОТОВ ('.$next_cost.' з.)</span></a>';
}
echo '</div></div>';

$items = db_query("SELECT i.id as inv_id, it.* FROM `inventory` i JOIN `items` it ON i.item_id = it.id WHERE i.user_id = ? AND i.equiped = '0' ORDER BY i.id DESC LIMIT $start, $per_page", [$myID])->fetchAll();

if (!$items) {
    echo '<div class="msg-new" style="text-align:center; padding:20px; color:#477193">Рюкзак пуст</div>';
} else {
    echo '<form method="post" action="?page='.$page.'">';
    $q_colors = [1 => '#fff', 2 => '#08aa00', 3 => '#49acfc', 4 => '#a335ee', 5 => '#ff8000'];
    foreach ($items as $item) {
        $color = $q_colors[$item['quality']] ?? '#fff';
        echo '<div class="msg-new" style="margin-bottom:2px"><div class="wr4-new" style="padding:8px; display:flex; align-items:center; gap:10px"><input type="checkbox" name="items[]" value="'.(int)$item['inv_id'].'"><div style="width:40px; height:40px; background:#000; border:1px solid #183543"><img src="/style/items/'.(int)$item['id'].'.png" style="width:100%"></div><div style="flex:1"><div style="color:'.$color.'; font-weight:bold; font-size:13px">'.out($item['name']).'</div><div style="color:#477193; font-size:11px">'.($item['str']?"Сила +$item[str] ":"").($item['def']?"Защ +$item[def] ":"").($item['hp']?"ХП +$item[hp]":"").'</div></div><div style="text-align:right"><a href="/user/equip.php?equip='.(int)$item['inv_id'].'" style="color:#08aa00; font-size:10px; text-decoration:none; font-weight:bold;">[ОДЕТЬ]</a><br><span style="color:#e2b70b; font-size:10px">'.n_f($item['price']/2).' з.</span></div></div></div>';
    }
    echo '<div style="margin:10px; text-align:center"><button type="submit" name="sell_batch" class="bbtn-new" style="border:none; cursor:pointer; width:220px; height:34px;"><span class="lbl-new" style="color:#ff4444; font-size:11px;">ПРОДАТЬ ВЫБРАННЫЕ</span></button></div></form>';
}

if ($total_pages > 1) {
    echo '<div style="display:flex; justify-content:center; gap:5px; margin:10px">';
    if ($page > 1) echo '<a href="?page='.($page-1).'" class="bbtn-new" style="width:40px; text-decoration:none"><span class="lbl-new">«</span></a>';
    echo '<div class="msg-new" style="padding:5px 15px; color:#e2b70b">'.$page.' / '.$total_pages.'</div>';
    if ($page < $total_pages) echo '<a href="?page='.($page+1).'" class="bbtn-new" style="width:40px; text-decoration:none"><span class="lbl-new">»</span></a>';
    echo '</div>';
}

require_once ('../system/tfoot.php');
?>