148 lines
6.6 KiB
PHP
148 lines
6.6 KiB
PHP
<?php
|
||
session_start();
|
||
if (empty($_SESSION['uid'])) {
|
||
header("Location: index.php");
|
||
exit;
|
||
}
|
||
|
||
require_once 'functions.php';
|
||
$user = $user ?? [];
|
||
if ($user->room != 27) {
|
||
header("Location: main.php");
|
||
exit;
|
||
}
|
||
if ($user->battle) {
|
||
header('location: fbattle.php');
|
||
exit;
|
||
}
|
||
$changeReceiver = $_GET['change'] ?? 0;
|
||
if ($changeReceiver) {
|
||
unset($_SESSION['receiverName']);
|
||
}
|
||
$razdelId = $_GET['razdel'] ?? 0;
|
||
$_SESSION['receiverName'] = $_POST['receiverName'] ?? '';
|
||
$receiverId = null;
|
||
$queryItems = null;
|
||
|
||
if ($_SESSION['receiverName']) {
|
||
$receiver = db::c()->query('SELECT `id`, `level`, `login` FROM `users` WHERE `login` = "?s"', $_SESSION['receiverName'])->fetch_assoc();
|
||
if (!$receiver['id']) {
|
||
err('Персонажа не существует!');
|
||
unset($_SESSION['receiverName']);
|
||
} elseif ($receiver['level'] < 4) {
|
||
err('Персонажей ниже 4-го уровня не обслуживаем!');
|
||
unset($_SESSION['receiverName']);
|
||
} else {
|
||
$receiverId = $receiver['id'];
|
||
$submit = $_POST['action'] ?? 0;
|
||
$sendItemId = $_POST['item_id'] ?? 0;
|
||
$telegraphText = $_POST['message'] ?? 0;
|
||
|
||
if ($submit == 'sendMessage' && $telegraphText && $user->money) {
|
||
|
||
if ($telegraphText) {
|
||
$user->money -= 1;
|
||
Bank::setWalletMoney($user->money, $user->id);
|
||
db::c()->query('INSERT INTO `telegraph` (`receiver`,`text`) VALUES (?i,"?s")', $receiverId, $telegraphText);
|
||
$statusMessage = 'Сообщение отправлено.';
|
||
} else {
|
||
$statusMessage = 'Сообщение было оставлено пустым!';
|
||
}
|
||
}
|
||
|
||
if ($submit == 'sendItem' && $sendItemId && $user->money) {
|
||
$res = db::c()->query('SELECT `id`,`name` FROM `inventory` WHERE `owner` = ?i AND `id` = ?i AND `dressed` = 0 AND `setsale` = 0 AND `present` = "?s" AND `artefact` = 0', $_SESSION['uid'], $sendItemId, null)->fetch_assoc();
|
||
if (!$res['id']) {
|
||
$statusMessage = "Предмет не найден в рюкзаке.";
|
||
} else {
|
||
$user->money -= 1;
|
||
Bank::setWalletMoney($user->money, $user->id);
|
||
db::c()->query('UPDATE `inventory` SET `owner` = ?i WHERE `id`= ?i AND `owner`= ?i', $receiverId, $sendItemId, $_SESSION['uid']);
|
||
//TODO: Добавить логи и статистику.
|
||
$statusMessage = 'Предмет "' . $res['name'] . '" передан персонажу ' . $receiverId;
|
||
db::c()->query('INSERT INTO `telegraph` (`receiver`,`text`) VALUES (?i,"?s")', $receiverId, 'Почтовый перевод: ' . $res['name'] . ' от персонажа ' . $user['login'] . '.');
|
||
}
|
||
}
|
||
$queryItems = db::c()->query('SELECT `inventory`.*,
|
||
`magic`.`name` AS `magic_name`,
|
||
`magic`.`chanse` AS `magic_chanse`,
|
||
`magic`.`time` AS `magic_time`,
|
||
`magic`.`file` AS `magic_file`,
|
||
`magic`.`targeted` AS `magic_targeted`,
|
||
`magic`.`needcharge` AS `magic_needcharge`,
|
||
`magic`.`img` AS `magic_img` FROM `inventory` LEFT JOIN `magic` ON `magic` = `magic`.`id` WHERE `owner` = ?i AND `dressed` = 0 AND `setsale` = 0 AND `present` = "?s" AND `artefact` = 0 ORDER BY `update` DESC', $_SESSION['uid'], null);
|
||
$iteminfo = [];
|
||
while ($row = $queryItems->fetch_assoc()) {
|
||
$iteminfo[] = new InventoryItem($row);
|
||
}
|
||
}
|
||
}
|
||
?>
|
||
<!DOCTYPE html>
|
||
<html>
|
||
<head>
|
||
<meta charset="utf-8">
|
||
<link href="css/main.css" rel="stylesheet"/>
|
||
<script src="js/main.js"></script>
|
||
</head>
|
||
<body>
|
||
<div style="float: right">
|
||
<button onclick="hrefToFrame('city.php?cp')">Вернуться</button>
|
||
</div>
|
||
<h1>Почта</h1>
|
||
<div style="text-align: center;"><?php if (isset($statusMessage)) err($statusMessage); ?></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>
|
||
<td valign=top align=right>
|
||
<table class="zebra" WIDTH=100%" cellspacing="1" cellpadding="2">
|
||
<th colspan="2">Передача предметов</th>
|
||
<?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>
|
||
<td bgcolor='#d3d3d3'>
|
||
<?php $ii->printInfo(); ?>
|
||
</td>
|
||
</tr>
|
||
<?php endforeach; ?>
|
||
<?php if (empty($queryItems->getNumRows())): ?>
|
||
<tr>
|
||
<td align=center bgcolor=#C7C7C7>Нечего передавать...</td>
|
||
</tr>
|
||
<?php endif ?>
|
||
</table>
|
||
</td>
|
||
</tr>
|
||
</table>
|
||
<?php else: ?>
|
||
<form method="post">
|
||
<input name='receiverName' placeholder="Логин получателя"> <input type=submit value='Применить'>
|
||
</form>
|
||
<?php endif ?>
|
||
</BODY>
|
||
</HTML>
|