2018-01-28 16:40:49 +00:00
< ? php
2021-01-27 13:53:39 +00:00
use Battles\Bank ;
use Battles\GameLogs ;
use Battles\InventoryItem ;
use Battles\Nick ;
use Battles\Template ;
use Battles\User ;
2018-06-23 19:32:33 +00:00
session_start ();
2019-01-16 16:35:00 +00:00
require_once 'functions.php' ;
2021-01-27 13:53:39 +00:00
$user = $user ? ? new User ( $_SESSION [ 'uid' ]);
2020-10-27 16:53:35 +00:00
if ( $_GET [ 'change' ] ? ? 0 ) {
2020-09-29 22:39:06 +00:00
unset ( $_SESSION [ 'receiverName' ]);
}
$_SESSION [ 'receiverName' ] = $_POST [ 'receiverName' ] ? ? '' ;
2018-06-23 23:12:30 +00:00
$receiverId = null ;
$queryItems = null ;
2020-10-27 16:53:35 +00:00
$statusMessage = null ;
2018-01-28 16:40:49 +00:00
2018-06-24 10:18:49 +00:00
if ( $_SESSION [ 'receiverName' ]) {
$receiver = db :: c () -> query ( 'SELECT `id`, `level`, `login` FROM `users` WHERE `login` = "?s"' , $_SESSION [ 'receiverName' ]) -> fetch_assoc ();
2018-06-24 15:38:19 +00:00
if ( ! $receiver [ 'id' ]) {
2020-10-27 16:53:35 +00:00
$statusMessage = 'Персонажа не существует!' ;
2018-06-24 15:38:19 +00:00
unset ( $_SESSION [ 'receiverName' ]);
} else {
2018-06-23 23:12:30 +00:00
$receiverId = $receiver [ 'id' ];
2020-09-29 22:39:06 +00:00
$submit = $_POST [ 'action' ] ? ? 0 ;
$sendItemId = $_POST [ 'item_id' ] ? ? 0 ;
$telegraphText = $_POST [ 'message' ] ? ? 0 ;
2018-06-24 11:34:43 +00:00
2020-09-29 22:39:06 +00:00
if ( $submit == 'sendMessage' && $telegraphText && $user -> money ) {
2018-06-23 23:12:30 +00:00
if ( $telegraphText ) {
2020-09-29 22:39:06 +00:00
$user -> money -= 1 ;
Bank :: setWalletMoney ( $user -> money , $user -> id );
2018-06-23 23:12:30 +00:00
db :: c () -> query ( 'INSERT INTO `telegraph` (`receiver`,`text`) VALUES (?i,"?s")' , $receiverId , $telegraphText );
$statusMessage = 'Сообщение отправлено.' ;
2020-09-29 22:39:06 +00:00
} else {
$statusMessage = 'Сообщение было оставлено пустым!' ;
}
2018-06-24 15:58:15 +00:00
}
2018-06-24 15:38:19 +00:00
2020-09-29 22:39:06 +00:00
if ( $submit == 'sendItem' && $sendItemId && $user -> money ) {
2020-10-27 16:53:35 +00:00
$res = db :: c () -> query ( 'SELECT name FROM inventory WHERE owner_id = ?i AND item_id = ?i AND dressed_slot = 0 AND on_sale = 0' , $user -> id , $sendItemId ) -> fetch_assoc ();
if ( ! $res ) {
2018-06-24 15:38:19 +00:00
$statusMessage = " Предмет не найден в рюкзаке. " ;
2018-06-23 23:12:30 +00:00
} else {
2020-09-29 22:39:06 +00:00
$user -> money -= 1 ;
Bank :: setWalletMoney ( $user -> money , $user -> id );
2020-10-27 16:53:35 +00:00
db :: c () -> query ( 'UPDATE `inventory` SET owner_id = ?i WHERE item_id= ?i AND owner_id = ?i' , $receiverId , $sendItemId , $_SESSION [ 'uid' ]);
2021-01-27 13:53:39 +00:00
$statusMessage = 'Предмет "' . $res [ 'name' ] . '" передан персонажу ' . Nick :: id ( $receiverId ) -> short ( 1 );
$receiverLogMessage = 'Получен предмет "' . $res [ 'name' ] . '" от персонажа ' . Nick :: id ( $_SESSION [ 'uid' ]) -> short ( 1 );
2019-01-16 16:26:16 +00:00
db :: c () -> query ( 'INSERT INTO `telegraph` (`receiver`,`text`) VALUES (?i,"?s")' , $receiverId , 'Почтовый перевод: ' . $res [ 'name' ] . ' от персонажа ' . $user [ 'login' ] . '.' );
2021-01-27 13:53:39 +00:00
// Пишем в лог отправителю.
GameLogs :: addUserLog ( $_SESSION [ 'uid' ], $statusMessage , 'почта' );
// Пишем в лог получателю.
GameLogs :: addUserLog ( $receiverId , $receiverLogMessage , 'почта' );
2018-06-23 19:32:33 +00:00
}
}
2020-10-27 16:53:35 +00:00
$queryItems = db :: c () -> query ( 'SELECT * FROM inventory WHERE dressed_slot = 0 AND on_sale = 0 AND owner_id = ?i' , $user -> id );
2019-01-16 16:26:16 +00:00
while ( $row = $queryItems -> fetch_assoc ()) {
2021-01-27 13:53:39 +00:00
$iteminfo [] = new InventoryItem ( $row );
2019-01-16 16:26:16 +00:00
}
2018-06-23 19:32:33 +00:00
}
2018-06-24 15:38:19 +00:00
}
2021-01-27 13:53:39 +00:00
Template :: header ( 'Почта' );
2018-01-28 16:40:49 +00:00
?>
2021-01-27 13:53:39 +00:00
< 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 >
2020-10-27 16:53:35 +00:00
< ? php if ( $_SESSION [ 'receiverName' ] ? ? '' ) : ?>
2020-08-27 12:17:02 +00:00
Получатель : < ? = Nick :: id ( $receiverId ) -> full () ?>
2018-06-23 23:12:30 +00:00
< a href = " ?change " > Сменить </ a >
< table width = 100 %>
< tr >
< td valign = top align = left width = 30 %>
< form METHOD = POST >
2018-06-23 19:32:33 +00:00
< fieldset >
2018-01-28 16:40:49 +00:00
< legend >< b > Телеграф </ b ></ legend >
2018-06-23 19:32:33 +00:00
Вы можете отправить короткое сообщение любому персонажу , даже если он находится в offline или
другом городе .< br />
2018-06-23 20:14:33 +00:00
Услуга платная : < b > 1 кр .</ b > < br />
2018-06-23 23:12:30 +00:00
< input type = " text " name = " message " id = " message " size = " 52 "
placeholder = " Сообщение: (Максимум 100 символов) " >
< input type = " hidden " name = " action " value = " telegraph " >
2018-06-24 11:34:43 +00:00
< input type = " submit " value = " Отправить " >
2018-06-23 19:32:33 +00:00
</ fieldset >
2018-06-23 23:12:30 +00:00
</ form >
< td valign = top align = right >
2019-01-16 16:35:00 +00:00
< table class = " zebra " WIDTH = 100 % " cellspacing= " 1 " cellpadding= " 2 " >
2021-01-27 13:53:39 +00:00
< th colspan = " 2 " > Передача предметов
< ? php foreach ( $iteminfo as $ii ) : ?>
2018-06-23 23:12:30 +00:00
< tr >
2019-01-16 16:26:16 +00:00
< td bgcolor = '#d3d3d3' >
< ? php $ii -> printImage (); ?>
2018-06-24 15:38:19 +00:00
< form method = " post " >
< input type = " hidden " name = " action " value = " sendItem " >
2019-01-16 16:26:16 +00:00
< input type = " hidden " name = " item_id " value = " <?= $ii->getId () ?> " >
2018-06-24 15:38:19 +00:00
< input type = " submit " value = " Передать за 1кр . " >
</ form >
2019-01-16 16:26:16 +00:00
< td bgcolor = '#d3d3d3' >
< ? php $ii -> printInfo (); ?>
2021-01-27 13:53:39 +00:00
< ? php endforeach ; ?>
< ? php if ( empty ( $queryItems -> getNumRows ())) : ?>
2018-06-23 23:12:30 +00:00
< tr >
2021-01-27 13:53:39 +00:00
< td align = center bgcolor = #C7C7C7>Нечего передавать...
2018-06-23 23:12:30 +00:00
< ? php endif ?>
</ table >
</ table >
< ? php else : ?>
< form method = " post " >
< input name = 'receiverName' placeholder = " Логин получателя " > < input type = submit value = 'Применить' >
</ form >
2020-10-27 16:53:35 +00:00
< ? php endif ?>