battles/repair.php

189 lines
9.3 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
session_start();
require_once("functions.php");
$d = db::c()->query('SELECT SUM(`massa`) FROM `inventory` WHERE `dressed` = 0 AND `owner` = ?i', $_SESSION['uid'])->fetch_assoc();
define('GRAV_LIMIT', 32);
define('GRAV_COST', 30);
define('REPAIR_STATUS', [
'OK_GRAV_ADDED' => 'Гравировка добавлена!',
'OK_GRAV_REMOVED' => 'Гравировка удалена!',
'OK_REPAIRED' => 'Предмет отремонтирован!',
'ERROR_SIZE_LIMIT' => 'Превышен лимит в ' . GRAV_LIMIT . ' символа!',
'ERROR_NO_MONEY' => 'Недостаточно денег!',
]);
$gravirovkaText = $_POST['gravirovka_text'] ?? null;
$itemId = $_POST['itemId'] ?? null;
$gravirovkaRemove = $_POST['gravirovka_remove'] ?? null;
$action = $_POST['action'] ?? null;
$goto = $_POST['goto'] ?? null;
// Гравировка 30 кред. Максимум 32 символа.
if ($gravirovkaText && $itemId) {
if ($user->money >= GRAV_COST) {
if (iconv_strlen($gravirovkaText) <= GRAV_LIMIT) {
db::c()->query('UPDATE `inventory` SET `text` = "?s" WHERE `dressed` = 0 AND `setsale` = 0 AND `owner` = ?i AND `id` = ?i', $gravirovkaText, $_SESSION['uid'], $itemId);
$user->money -= GRAV_COST;
Bank::setWalletMoney($user->money, $user->id);
$status = REPAIR_STATUS['OK_GRAV_ADDED'];
} else {
$status = REPAIR_STATUS['ERROR_SIZE_LIMIT'];
}
} else {
$status = REPAIR_STATUS['ERROR_NO_MONEY'];
}
}
// Снять гравировку.
if ($gravirovkaRemove) {
if ($user->money >= GRAV_COST) {
db::c()->query('UPDATE `inventory` SET `text` = ?n WHERE `dressed` = 0 AND `setsale` = 0 AND `id` = ?i AND `owner` = ?i', null, $gravirovkaRemove, $_SESSION['uid']);
$user->money -= GRAV_COST;
Bank::setWalletMoney($user->money, $user->id);
$status = REPAIR_STATUS['OK_GRAV_REMOVED'];
} else {
$status = REPAIR_STATUS['ERROR_NO_MONEY'];
}
}
// Ремонт 0,5 кред за единицу.
if ($action == 'repair' && $itemId) {
$q = db::c()->query('SELECT `name`, `duration` FROM `inventory` WHERE id = ?i', $itemId)->fetch_assoc();
if ($user->money > ceil($q['duration'] / 2)) {
db::c()->query('UPDATE `inventory` SET `maxdur` = `maxdur` - 1, `duration` = 0 WHERE `dressed` = 0 AND `setsale` = 0 AND `id` = ?i AND `owner` = ?i', $itemId, $_SESSION['uid']);
$user->money -= ceil($q['duration'] / 2);
Bank::setWalletMoney($user->money, $user->id);
addToDelo('Отремонтирован предмет «' . $q['name'] . '» id:(' . $itemId . ') за ' . ceil($q['duration'] / 2) . ' кр.');
$status = REPAIR_STATUS['OK_REPAIRED'];
} else {
$status = REPAIR_STATUS['ERROR_NO_MONEY'];
}
}
if ($goto == 'remont') {
$remont_query = db::c()->query('SELECT `id`,`name`,`img`,`duration`,`maxdur` FROM `inventory` WHERE `type` < 12 AND `dressed` = 0 AND `isrep` = 1 AND `setsale` = 0 AND `duration` > 0 AND `owner` = ?i ORDER BY `update` DESC', $_SESSION['uid']);
}
if ($goto == 'gravirovka') {
$gravirovka_query = db::c()->query('SELECT `id`,`name`,`img`,`text` FROM `inventory` WHERE `owner` = ?i AND `dressed` = 0 AND `type` = 3 AND `name` NOT LIKE "?S" AND `setsale` = 0 OR `text` <> "?s" AND `owner` = ?i AND `dressed` = 0 AND `setsale` = 0 ORDER by `update` DESC', $_SESSION['uid'], '%Букет%', '', $_SESSION['uid']);
}
\Battles\Template::header('Кузня');
?>
<link href="css/secondary.css" rel="stylesheet"/>
<script src="js/main.js"></script>
<h1>Ремонтная мастерская</h1>
<a href=# onclick=hrefToFrame('city.php?cp')> ← выйти из мастерской</a><br>
<div class="appblock appblock-main">
<span class="legend">Информация</span>
<span class="wrap">Кредиты<span class="num"><?= $user['money'] ?></span></span>
<span class="wrap">Масса вещей<span class="num"><?= getItemsMassaInfo() ?></span></span>
</div>
<div class="appblock">
<span class="legend">Зал ремонта</span>
<form method="post">
<input type="hidden" name="goto" value="remont">
<input type="submit" value="Войти">
</form>
<span class="wrap">Починка поврежденных предметов. В процессе ремонта состояние предмета
уменьшится на единицу!</span>
</div>
<div class="appblock">
<span class="legend">Зал гравировки</span>
<form method="post">
<input type="hidden" name="goto" value="gravirovka">
<input type="submit" value="Войти" disabled>
</form>
<span class="wrap">Нанесение надписей на оружие и удаление надписей из любого обмундирования.
Максимум 32 символа!</span>
</div>
<div style="clear: both;">
<?php if (isset($status)): ?>
<span class="wrap"><?= $status ?></span>
<?php endif; ?>
</div>
<?php if ($goto == 'remont'):
while ($row = $remont_query->fetch_assoc()): ?>
<div class="appblock">
<span class="legend"><?= $row['name'] ?></span>
<span class="wrap">Состояние предмета<span class="num"><?= $row['duration'] ?>/<?= $row['maxdur'] ?></span></span>
<span class="wrap">Стоимость услуги<span class="num"><?= ceil($row['duration'] / 2) ?></span></span>
<div style="text-align: center">
<img src="i/sh/<?= $row['img'] ?>">
<form method="post">
<input type="hidden" name="itemId" value="<?= $row['id'] ?>">
<input type="hidden" name="action" value="repair">
<input type="submit" value="Ремонт">
</form>
</div>
</div>
<?php endwhile; endif; ?>
<?php if ($goto == 'gravirovka'):
while ($row = $gravirovka_query->fetch_assoc()): ?>
<div class="appblock">
<span class="legend"><?= $row['name'] ?></span>
<span class="wrap">Стоимость услуги<span class="num">30</span></span>
<div style="text-align: center">
<?php if (empty($row['text'])): ?>
<form method="post" id="gravirovka">
<input maxlength="32" placeholder="Текст гравировки" name="gravirovka_text">
<br><img src="i/sh/<?= $row['img'] ?>"><br>
<input type="hidden" name="itemId" value="<?= $row['id'] ?>">
<input type="submit" value="Добавить надпись">
</form>
<?php else: ?>
<form method="post" id="gravirovka">
<input value="<?= $row['text'] ?>" readonly title>
<br><img src="i/sh/<?= $row['img'] ?>"><br>
<input type="hidden" name="gravirovka_remove" value="<?= $row['id'] ?>">
<input type="submit" value="Удалить надпись">
</form>
<?php endif; ?>
</div>
</div>
<?php endwhile; endif; ?>
<?php
if ($goto == 'modding') {
$data = mysql_query("SELECT * FROM `inventory` WHERE `type` < 12 AND `type` != 3 AND `owner` = '{$_SESSION['uid']}' AND `dressed` = 0 AND `name` NOT LIKE '% (мф)%' AND `name` NOT LIKE '%Букет%' AND `setsale`=0 ORDER by `update` DESC; ");
while ($row = mysql_fetch_array($data)) {
?>
<TR bgcolor=<?= $color ?>>
<TD align=center><IMG SRC="i/sh/<?= $row['img'] ?>" BORDER=0>";
<BR>
<small>
<A HREF="?razdel=3&mf=<?= $row['id'] ?>"
onClick="if(!confirm('Вы действительно хотите модифицировать эту вещь?')){ return false;}">Модифицировать
за <?= $row['cost'] ?> кр.</A><BR>
</small>
</TD>
<TD valign=top><?php #showitem($row) ?></TD>
</TR>
<?php
}
}
if ($goto == 'podgon') {
$data = mysql_query("SELECT * FROM `inventory` WHERE `type` < 12 AND `type` != 3 AND `owner` = '{$user['id']}' AND `dressed` = 0 AND `modif`='1' AND `podgon`<'5' AND `name` NOT LIKE '%Букет%' AND `setsale`=0 ORDER by `update` DESC; ");
while ($row = mysql_fetch_array($data)) {
?>
<TR bgcolor=<?= $color ?>>
<TD align=center><IMG SRC="i/sh/<?= $row['img'] ?>" BORDER=0>";
<BR>
<small>
<?
if ($row['point'] > 0) {
$babki = round(($row['point'] / 2), 0);
$cost_t = 'Реп';
} else {
$babki = round(($row['cost'] / 2), 0);
$cost_t = 'Кр';
}
?>
<A HREF="?razdel=4&podgon=<?= $row['id'] ?>"
onclick="if(!confirm('Вы действительно хотите подогнать эту вещь?')){ return false;}">Подогнать
за <?= $babki ?> <?= $cost_t ?>.</A><BR>
</small>
</TD>
<TD valign=top><?php #showitem($row) ?></TD>
</TR>
<?php
}
}
?>
</TABLE>