battles/admin/edit_user.php
Igor Barkov (iwork) 3502904656 Рефакторинг, очистка, работа над ошибками, связанными с базой, отказ от глобальной переменной $user во многих файлах.
Singleton в некоторых местах вместо решения #42.
Новые шаги для решения #16 и #52.
Closes #42.
Closes #32.
Closes #31.
2022-01-27 01:15:33 +02:00

95 lines
3.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
/**
* Copyright (c) 2018.
* Author: Igor Barkov <lopar.4ever@gmail.com>
* Project name: Battles-Game
*/
use Battles\Database\Db;
use Battles\DressedItems;
use Battles\Template;
use Battles\User;
require_once "../functions.php";
if (!User::getInstance()->getAdmin()) {
header("HTTP/1.0 404 Not Found");
exit;
}
$player = $_POST['player'] ?? null;
$undress_char = $_POST['undress_char'] ?? null;
$end = $_POST['end'] ?? null;
$del = $_POST['del'] ?? null;
if ($player) {
$row = Db::getInstance()->ofetch('select id, login from users where id = ? or login = ?', [$player, $player]);
$_SESSION['player_id'] = $row->id;
$_SESSION['player_name'] = $row->login;
unset($row);
}
if ($undress_char) {
DressedItems::undressAllItems($_SESSION['player_id']);
}
if ($end) {
unset($_SESSION['player_id']);
unset($_SESSION['player_name']);
}
if (isset($_SESSION['player_id'])) {
$inv = db::c()->query('SELECT item_id, name, image FROM inventory WHERE owner = ?i ORDER BY id DESC', $_SESSION['player_id']);
}
if ($del) {
$itemdel = db::c()->query('SELECT item_type, dressed_slot FROM inventory WHERE id=?i', $del)->fetch_assoc();
if ($itemdel['dressed_slot'] == 1) {
$item = new DressedItems($del);
$item->undressItem($itemdel['item_type']);
if ($itemdel['item_type'] == 5) {
$item->undressItem(6);
$item->undressItem(7);
}
}
Db::getInstance()->execute('delete from inventory where id = ?', $del);
}
Template::header('ᐰdminка инвентаря');
?>
<h1>Администрирование инвентаря <?php if (isset($_SESSION['player_name'])) echo $_SESSION['player_name']; ?></h1>
<table class='adm'>
<tr>
<th>ID</th>
<th>Название</th>
<th>Количество</th>
<th>Картинка</th>
<th></th>
</tr>
<?php if (empty($_SESSION['player_id'])): ?>
<tr>
<th colspan="5">
<form method="post">
<input placeholder="Логин или ID" name="player">
<input type="submit">
</form>
</th>
</tr>
<?php else: while ($row = $inv->fetch_assoc()): ?>
<tr>
<td><?= $row['id'] ?></td>
<td><?= $row['name'] ?></td>
<td><?= $row['koll'] ?></td>
<td><img src='/i/sh/<?= $row['img'] ?>'></td>
<td>
<form method='post'>
<input name='del' type='hidden' value='<?= $row['id'] ?>'>
<input name='ok' type='submit' value='Удалить'>
</form>
</td>
</tr>
<?php endwhile; ?>
<th colspan='6'>
<form method='post'>
<input name='undress_char' type='submit' value='Стриптиз'>
</form>
<form method="post">
<input name='end' type='submit' value='Выйти'>
</form>
</th>
<?php endif; ?>
</table>