battles/post.php

124 lines
6.2 KiB
PHP
Raw Permalink 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\Database\Db;
use Battles\GameLogs;
use Battles\InventoryItem;
use Battles\Nick;
use Battles\Template;
use Battles\User;
require_once 'functions.php';
if ($_GET['change'] ?? 0) {
unset($_SESSION['receiverName']);
}
$_SESSION['receiverName'] = $_POST['receiverName'] ?? '';
$receiverId = null;
$queryItems = null;
$statusMessage = null;
if ($_SESSION['receiverName']) {
$receiver = db::c()->query('SELECT `id`, `level`, `login` FROM `users` WHERE `login` = "?s"', $_SESSION['receiverName'])->fetch_assoc();
if (!$receiver['id']) {
$statusMessage = 'Персонажа не существует!';
unset($_SESSION['receiverName']);
} else {
$receiverId = $receiver['id'];
$submit = $_POST['action'] ?? 0;
$sendItemId = $_POST['item_id'] ?? 0;
$telegraphText = $_POST['message'] ?? 0;
if ($submit == 'sendMessage' && User::getInstance()->money()->get()) {
if ($telegraphText) {
if (User::getInstance()->money()->spend(1)) {
db::c()->query('INSERT INTO `telegraph` (`receiver`,`text`) VALUES (?i,"?s")', $receiverId, $telegraphText);
$statusMessage = 'Сообщение отправлено.';
} else {
$statusMessage = 'Недостаточно денег.';
}
} else {
$statusMessage = 'Сообщение было оставлено пустым!';
}
}
if ($submit == 'sendItem' && $sendItemId && User::getInstance()->money()->get()) {
$itemName = Db::getInstance()->fetchColumn('select name from inventory where owner_id = ? and item_id = ? and dressed_slot = 0 and on_sale = 0', [User::getInstance()->getId(), $sendItemId]);
if (!$itemName) {
$statusMessage = "Предмет не найден в рюкзаке.";
} else {
if (User::getInstance()->money()->spend(1)) {
db::c()->query('UPDATE `inventory` SET owner_id = ?i WHERE item_id= ?i AND owner_id = ?i', $receiverId, $sendItemId, $_SESSION['uid']);
$statusMessage = 'Предмет "' . $itemName . '" передан персонажу ' . User::getInstance($receiverId)->getLogin();
$receiverLogMessage = 'Получен предмет "' . $itemName . '" от персонажа ' . User::getInstance()->getLogin();
db::c()->query('INSERT INTO `telegraph` (`receiver`,`text`) VALUES (?i,"?s")', $receiverId, 'Почтовый перевод: ' . $itemName . ' от персонажа ' . $user['login'] . '.');
// Пишем в лог отправителю.
GameLogs::addUserLog($_SESSION['uid'], $statusMessage, 'почта');
// Пишем в лог получателю.
GameLogs::addUserLog($receiverId, $receiverLogMessage, 'почта');
} else {
$statusMessage = 'Недостаточно денег.';
}
}
}
$queryItems = db::c()->query('SELECT * FROM inventory WHERE dressed_slot = 0 AND on_sale = 0 AND owner_id = ?i', User::getInstance()->getId());
while ($row = $queryItems->fetch_assoc()) {
$iteminfo[] = new InventoryItem($row);
}
}
}
Template::header('Почта');
?>
<div style="float: right">
<button onclick="top.frames['gameframe'].location = 'city.php?cp'">Вернуться</button>
</div>
<h1>Почта</h1>
<div style="text-align: center;"><span class="error"><?= $statusMessage ?></span></div>
<legend>Услуги почты платные: 1 кредит.</legend>
<?php if ($_SESSION['receiverName'] ?? ''): ?>
Получатель: <?= Nick::id($receiverId)->full() ?>
<a href="?change">Сменить</a>
<table width=100%>
<tr>
<td valign=top align=left width=30%>
<form METHOD=POST>
<fieldset>
<legend><b>Телеграф</b></legend>
Вы можете отправить короткое сообщение любому персонажу, даже если он находится в offline или
другом городе.<br/>
Услуга платная: <b>1 кр.</b> <br/>
<input type="text" name="message" id="message" size="52"
placeholder="Сообщение: (Максимум 100 символов)">
<input type="hidden" name="action" value="telegraph">
<input type="submit" value="Отправить">
</fieldset>
</form>
<td valign=top align=right>
<table class="zebra" WIDTH=100%" cellspacing="1" cellpadding="2">
<th colspan="2">Передача предметов
<?php foreach ($iteminfo
as $ii): ?>
<tr>
<td bgcolor='#d3d3d3'>
<?php $ii->printImage(); ?>
<form method="post">
<input type="hidden" name="action" value="sendItem">
<input type="hidden" name="item_id" value="<?= $ii->getId() ?>">
<input type="submit" value="Передать за 1кр.">
</form>
<td bgcolor='#d3d3d3'>
<?php $ii->printInfo(); ?>
<?php endforeach; ?>
<?php if (empty($queryItems->getNumRows())): ?>
<tr>
<td align=center bgcolor=#C7C7C7>Нечего передавать...
<?php endif ?>
</table>
</table>
<?php else: ?>
<form method="post">
<input name='receiverName' placeholder="Логин получателя"> <input type=submit value='Применить'>
</form>
<?php endif ?>