2018-01-28 16:40:49 +00:00
< ? php
2018-06-23 19:32:33 +00:00
session_start ();
if ( $_SESSION [ 'uid' ] == null ) header ( " Location: index.php " );
include " config.php " ;
include " functions.php " ;
2018-01-28 16:40:49 +00:00
2018-06-23 19:32:33 +00:00
if ( $user [ 'room' ] != 27 ) {
header ( " Location: main.php " );
die ();
2018-01-28 16:40:49 +00:00
}
2018-06-23 19:32:33 +00:00
if ( $user [ 'battle' ] != 0 ) {
header ( 'location: fbattle.php' );
die ();
2018-01-28 16:40:49 +00:00
}
2018-06-24 15:38:19 +00:00
$changeReceiver = filter_input ( INPUT_GET , 'change' );
2018-06-24 10:18:49 +00:00
if ( $changeReceiver ) unset ( $_SESSION [ 'receiverName' ]);
2018-06-23 23:12:30 +00:00
$razdelId = filter_input ( INPUT_GET , 'razdel' );
2018-06-24 10:18:49 +00:00
$_SESSION [ 'receiverName' ] = filter_input ( INPUT_POST , 'receiverName' );
2018-06-23 23:12:30 +00:00
$receiverId = null ;
$queryItems = 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' ]) {
err ( 'Персонажа не существует!' );
unset ( $_SESSION [ 'receiverName' ]);
} elseif ( $receiver [ 'level' ] < 4 ) {
err ( 'Персонажей ниже 4-г о уровня не обслуживаем!' );
unset ( $_SESSION [ 'receiverName' ]);
} else {
2018-06-23 23:12:30 +00:00
$receiverId = $receiver [ 'id' ];
$submit = filter_input ( INPUT_POST , 'action' );
2018-06-24 15:38:19 +00:00
$sendItemId = filter_input ( INPUT_POST , 'item_id' );
2018-06-24 11:34:43 +00:00
$telegraphText = filter_input ( INPUT_POST , 'message' );
if ( $submit == 'sendMessage' && $telegraphText && $user [ 'money' ] >= 1 ) {
2018-06-23 23:12:30 +00:00
if ( $telegraphText ) {
db :: c () -> query ( 'UPDATE `users` SET `money` = `money` - 1 WHERE id=?i' , $user [ 'id' ]);
db :: c () -> query ( 'INSERT INTO `telegraph` (`receiver`,`text`) VALUES (?i,"?s")' , $receiverId , $telegraphText );
$statusMessage = 'Сообщение отправлено.' ;
2018-06-24 15:38:19 +00:00
} else $statusMessage = 'Сообщение было оставлено пустым!' ;
2018-06-24 15:58:15 +00:00
}
2018-06-24 15:38:19 +00:00
if ( $submit == 'sendItem' && $sendItemId && $user [ 'money' ] >= 1 ) {
$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 ();
2018-06-23 23:12:30 +00:00
if ( ! $res [ 'id' ]) {
2018-06-24 15:38:19 +00:00
$statusMessage = " Предмет не найден в рюкзаке. " ;
2018-06-23 23:12:30 +00:00
} else {
2018-06-24 15:38:19 +00:00
db :: c () -> query ( 'UPDATE `users` SET `money` = `money` - 1 WHERE id=?i' , $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' ] . '.' );
2018-06-23 19:32:33 +00:00
}
}
2018-06-23 23:12:30 +00:00
$queryItems = db :: c () -> query ( 'SELECT * FROM `inventory` WHERE `owner` = ?i AND `dressed` = 0 AND `setsale` = 0 AND `present` = "?s" AND `artefact` = 0 ORDER BY `update` DESC' , $_SESSION [ 'uid' ], null );
2018-06-23 19:32:33 +00:00
}
2018-06-24 15:38:19 +00:00
}
2018-01-28 16:40:49 +00:00
?>
2018-06-23 19:32:33 +00:00
<! DOCTYPE html >
< html >
< head >
< meta charset = " utf-8 " >
< link href = " css/main.css " rel = " stylesheet " />
< script >
function leave () {
top . frames [ 'main' ] . location = 'city.php?cp'
}
</ script >
</ head >
< body >
< h1 > Почта </ h1 >
< a href = # onclick=leave()> ← выйти на Центральную площадь</a>
2018-06-24 15:38:19 +00:00
< div style = " text-align: center; " >
< ? php if ( isset ( $statusMessage )) err ( $statusMessage ); ?>
</ div >
< legend > Услуги почты платные : 1 кредит .</ legend >
< ? php if ( $_SESSION [ 'receiverName' ]) : ?>
2018-06-24 10:21:18 +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 >
< td valign = top align = right >
< table class = " zebra " WIDTH = 100 % " >
2018-06-24 15:38:19 +00:00
< th colspan = " 2 " > Передача предметов </ th >
2018-06-23 23:12:30 +00:00
< ? php while ( $row = $queryItems -> fetch_assoc ()) : ?>
< tr >
< td align = center >
2018-06-24 15:38:19 +00:00
< img src = " i/sh/<?= $row['img'] ?> " >< br >
< form method = " post " >
< input type = " hidden " name = " action " value = " sendItem " >
< input type = " hidden " name = " item_id " value = " <?= $row['id'] ?> " >
< input type = " submit " value = " Передать за 1кр . " >
</ form >
2018-06-23 23:12:30 +00:00
</ td >
< td valign = top >
2018-06-24 20:03:57 +00:00
< ? php showitem ( $row , '' , '' , true ); ?>
2018-06-23 23:12:30 +00:00
</ td >
</ tr >
< ? php endwhile ?>
< ? php if ( $queryItems -> getNumRows () == 0 ) : ?>
< 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 ?>
2018-01-28 16:40:49 +00:00
</ BODY >
</ HTML >