2018-01-28 16:40:49 +00:00
< ? php
2019-01-18 19:56:07 +00:00
session_start ();
2020-09-29 22:39:06 +00:00
if ( ! $_SESSION [ 'uid' ]) {
header ( " Location: index.php " );
exit ;
}
2019-01-18 19:56:07 +00:00
require_once 'functions.php' ;
2020-09-29 22:39:06 +00:00
$user = $user ? ? 0 ;
2018-01-28 16:40:49 +00:00
2020-09-29 22:39:06 +00:00
if ( $user -> level < 1 ) {
2019-01-18 19:56:07 +00:00
header ( " Location: main.php " );
2020-09-29 22:39:06 +00:00
exit ;
2018-01-28 16:40:49 +00:00
}
2020-09-29 22:39:06 +00:00
if ( $user -> room != 25 ) {
2019-01-18 19:56:07 +00:00
header ( " Location: main.php " );
2020-09-29 22:39:06 +00:00
exit ;
2019-01-18 19:56:07 +00:00
}
2020-09-29 22:39:06 +00:00
if ( $user -> battle ) {
2019-01-18 19:56:07 +00:00
header ( 'location: fbattle.php' );
2020-09-29 22:39:06 +00:00
exit ;
2018-01-28 16:40:49 +00:00
}
2019-01-18 19:56:07 +00:00
$get = urldecode ( filter_input ( INPUT_SERVER , 'QUERY_STRING' ));
2018-01-28 16:40:49 +00:00
2019-02-15 22:02:42 +00:00
$putItemCost = ( int ) filter_input ( INPUT_POST , 'cost' , FILTER_VALIDATE_INT , [ 'options' => [ 'min_range' => 1 ]]);
2019-02-15 20:18:02 +00:00
$putItemId = ( int ) filter_input ( INPUT_POST , 'putId' , FILTER_VALIDATE_INT , [ 'options' => [ 'min_range' => 1 ]]);
2019-02-15 14:39:46 +00:00
$returningItemId = ( int ) filter_input ( INPUT_GET , 'back' , FILTER_VALIDATE_INT , [ 'options' => [ 'min_range' => 1 ]]);
2019-02-15 17:23:43 +00:00
$byingItemId = ( int ) filter_input ( INPUT_GET , 'set' , FILTER_VALIDATE_INT , [ 'options' => [ 'min_range' => 1 ]]);
2019-02-13 13:28:06 +00:00
2019-02-15 20:18:02 +00:00
if ( $putItemId ) {
$dress = db :: c () -> query ( 'SELECT `name`,`duration`,`maxdur`,`cost` FROM `inventory` WHERE `dressed` = 0 AND `id` = ?i AND `owner` = ?i' , $putItemId , $_SESSION [ 'uid' ]) -> fetch_assoc ();
2020-09-30 14:33:23 +00:00
if ( empty ( $putItemCost )) {
$putItemCost = $dress [ 'cost' ];
}
2019-02-15 22:02:42 +00:00
$commission = ceil ( $putItemCost / 10 ); # 10% от суммы с округлением вверх.
2019-02-13 12:57:28 +00:00
if ( $user [ 'money' ] > $commission ) {
2019-02-15 20:18:02 +00:00
2019-02-13 12:57:28 +00:00
if ( db :: c () -> getAffectedRows ()) {
2019-02-15 22:02:42 +00:00
$deloText = " { $user [ 'login' ] } выставил товар: « { $dress [ 'name' ] } » id:( { $putItemId } ) [ { $dress [ 'duration' ] } / { $dress [ 'maxdur' ] } ] на продажу в комиссионку за { $putItemCost } кр. " ;
2019-02-13 12:57:28 +00:00
addToDelo ( $deloText );
2019-02-15 22:02:42 +00:00
db :: c () -> query ( 'UPDATE `inventory` SET `setsale` = ?i WHERE `id` = ?i' , $putItemCost , $putItemId );
2019-02-13 12:57:28 +00:00
db :: c () -> query ( 'UPDATE `users` SET `money` = `money` - ?i WHERE `id` = ?i' , $commission , $_SESSION [ 'uid' ]);
2019-02-15 22:02:42 +00:00
$status = " Вы сдали в магазин « { $dress [ 'name' ] } » за { $putItemCost } кр. Вычтено за услуги магазина: { $commission } кр. " ;
2020-09-30 14:33:23 +00:00
} else {
$status = " Предмет не найден в инвентаре! " ;
}
} else {
$status = " У вас не хватает " . $commission - $user [ 'money' ] . " кр. чтобы оплатить комиссию! " ;
}
2019-02-13 12:57:28 +00:00
}
2019-02-13 13:28:06 +00:00
if ( $returningItemId ) {
$dress = db :: c () -> query ( 'SELECT `name`,`duration`,`maxdur` FROM `inventory` WHERE `dressed` = 0 AND `setsale` > 0 AND `id` = ?i AND `owner` = ?i' , $returningItemId , $_SESSION [ 'uid' ]) -> fetch_assoc ();
if ( db :: c () -> getAffectedRows ()) {
$deloText = " { $user [ 'login' ] } забрал свой товар: « { $dress [ 'name' ] } » id:( { $returningItemId } ) [ { $dress [ 'duration' ] } / { $dress [ 'maxdur' ] } ] из комиссионки. " ;
addToDelo ( $deloText );
db :: c () -> query ( 'UPDATE `inventory` SET `setsale` = 0 WHERE `id` = ?i' , $returningItemId );
$status = " Вы забрали из магазина ваш « { $dress [ 'name' ] } ». " ;
2020-09-30 14:33:23 +00:00
} else {
$status = " Предмет не найден на полках магазина! " ;
}
2018-01-28 16:40:49 +00:00
}
2019-02-15 17:23:43 +00:00
if ( $byingItemId ) {
2019-02-15 22:02:42 +00:00
$dress = db :: c () -> query ( 'SELECT `name`,`owner`,`duration`,`maxdur`,`setsale` FROM `inventory` WHERE `dressed` = 0 AND `setsale` > 0 AND `id` = ?i' , $byingItemId ) -> fetch_assoc ();
$seller = db :: c () -> query ( 'SELECT `login` FROM `users` WHERE `id` =?i' , $dress [ 'owner' ]) -> fetch_assoc ();
2019-02-15 15:25:53 +00:00
2019-02-15 22:02:42 +00:00
if ( $dress [ 'setsale' ]) {
if ( $user [ 'money' ] >= $dress [ 'setsale' ]) {
db :: c () -> query ( 'UPDATE `inventory` SET `setsale` = 0, `owner` = ?i WHERE `id` = ?i' , $_SESSION [ 'uid' ], $byingItemId );
db :: c () -> query ( 'UPDATE `users` set `money` = `money` - ?i WHERE `id` = ?i' , $dress [ 'setsale' ], $_SESSION [ 'uid' ]);
db :: c () -> query ( 'UPDATE `users` set `money` = `money` + ?i WHERE `id` = ?i' , $dress [ 'setsale' ], $dress [ 'owner' ]);
$status = " Вы купили « { $dress [ 'name' ] } » за { $dress [ 'setsale' ] } кр. " ;
$deloText = " { $user [ 'login' ] } купил на рынке товар: « { $dress [ 'name' ] } » id:( { $byingItemId } ) [ { $dress [ 'duration' ] } / { $dress [ 'maxdur' ] } ] у { $seller [ 'login' ] } за { $dress [ 'setsale' ] } кр. " ;
addToDelo ( $deloText );
2019-02-15 22:09:02 +00:00
$deloText = " { $seller [ 'login' ] } продал на рынке товар: « { $dress [ 'name' ] } » id:( { $byingItemId } ) [ { $dress [ 'duration' ] } / { $dress [ 'maxdur' ] } ] персонажу { $user [ 'login' ] } за { $dress [ 'setsale' ] } кр. " ;
2019-02-15 22:02:42 +00:00
addToDelo ( $deloText , $dress [ 'owner' ]);
$user [ 'money' ] = $user [ 'money' ] - $dress [ 'setsale' ];
2020-09-30 14:33:23 +00:00
telegraph ( $dress [ 'owner' ], " Предмет « { $dress [ 'name' ] } » продан на рынке за { $dress [ 'setsale' ] } кр. " );
} else {
$status = " Недостаточно средств! " ;
}
} else {
$status = " Предмет не найден на полках магазина! " ;
}
2018-01-28 16:40:49 +00:00
}
2019-02-15 18:25:31 +00:00
$classPrintControlName = " marketbuy " ;
2019-02-15 14:11:58 +00:00
if ( $get === 'sale' ) {
$data = 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` ,
0 AS `maxdur`
FROM `inventory` LEFT JOIN `magic` ON `magic` = `magic` . `id` WHERE `setsale` = 0 AND `dressed` = 0 AND `present` = " ?s " AND `owner` = ? i ORDER BY `update` DESC ', ' ', $_SESSION[' uid ' ]);
2019-02-15 18:25:31 +00:00
$classPrintControlName = " marketput " ;
2019-02-15 18:31:56 +00:00
} elseif ( $get === 'unsale' ) {
2019-02-15 12:16:40 +00:00
$data = 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` ,
0 AS `maxdur`
FROM `inventory` LEFT JOIN `magic` ON `magic` = `magic` . `id` WHERE `setsale` > 0 AND `dressed` = 0 AND `owner` = ? i ORDER BY `update` DESC ', $_SESSION[' uid ' ]);
2019-02-15 18:25:31 +00:00
$classPrintControlName = " marketgetback " ;
2019-02-15 18:31:56 +00:00
} else if ( ! empty ( $_POST [ 'search' ])) {
2019-02-15 16:39:47 +00:00
$data = 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` ,
0 AS `maxdur`
2019-02-15 18:21:05 +00:00
FROM `inventory` LEFT JOIN `magic` ON `magic` = `magic` . `id` WHERE `dressed` = 0 AND `inventory` . `name` LIKE " %?S% " AND `setsale` > 0 ORDER BY `setsale` ASC ', $_POST[' search ' ]);
2019-02-15 18:31:56 +00:00
} else {
2019-02-15 18:21:05 +00:00
$data = 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` ,
0 AS `maxdur`
FROM `inventory` LEFT JOIN `magic` ON `magic` = `magic` . `id` WHERE `dressed` = 0 AND `setsale` > 0 ORDER BY `setsale` ASC ' );
}
$iteminfo = [];
while ( $row = $data -> fetch_assoc ()) {
2020-10-28 20:21:08 +00:00
$iteminfo [] = new \Battles\ShopItem ( $row );
2019-02-15 16:39:47 +00:00
}
2020-10-28 20:21:08 +00:00
\Battles\Template :: header ( 'Рынок' );
2018-01-28 16:40:49 +00:00
?>
2020-09-30 14:33:23 +00:00
< script src = " js/main.js " ></ script >
2019-02-15 17:23:43 +00:00
< h1 > Рынок </ h1 >
< a href = # onclick=hrefToFrame('city.php?cp')> ← выйти на Центральную площадь</a>
< div >< ? php if ( ! empty ( $status )) err ( $status ); ?> </div>
2019-01-18 19:56:07 +00:00
< TABLE width = 100 % cellspacing = " 0 " cellpadding = " 4 " >
< TR >
< TD valign = top align = left >
2019-02-15 19:07:02 +00:00
< TABLE class = " zebra " width = 100 %>
2019-01-18 19:56:07 +00:00
< TR >
2019-02-15 15:36:07 +00:00
< TH >
2019-02-15 20:18:02 +00:00
< ? php if ( $get === 'sale' ) : ?>
Выставить товар на продажу .
< br > Комиссия за услуги магазина составляет 10 % от цены , по которой вы предлагаете предмет .
< ? php elseif ( $get === 'unsale' ) : ?>
Забрать свой товар .
< ? php else : ?>
Список товаров .< br >
< form method = " post " >
< input name = " search " > < input type = " submit " value = " Искать товар " >
</ form >
< ? php endif ; ?>
2019-02-15 15:36:07 +00:00
</ TH >
2019-01-18 19:56:07 +00:00
</ TR >
< TR >
< TD ><!-- Рюкзак -->
2019-02-15 19:07:02 +00:00
< TABLE WIDTH = 100 %>
2019-01-18 19:56:07 +00:00
< ? php
2019-02-15 18:31:56 +00:00
foreach ( $iteminfo as $ii ) {
echo " <tr><td style='width: 150px; text-align: center;'> " ;
$ii -> printImage ();
$ii -> printControls ( $classPrintControlName );
echo " </td> " ;
echo " <td style='vertical-align: top;'> " ;
$ii -> printInfo ();
echo " </td></tr> " ;
}
2019-01-18 19:56:07 +00:00
?>
</ TABLE >
</ TD >
</ TR >
</ TABLE >
</ TD >
< TD valign = top width = 280 >
2019-02-15 17:43:18 +00:00
< div style = " margin-left:15px; margin-top: 10px; " >
< b > М а с с а всех ваших вещей : < ? = getItemsMassaInfo () ?>
< br > У вас в наличии : < span style = " color: darkgreen; " >< ? = $user [ 'money' ] ?> </span> кр.</b>
2019-01-18 19:56:07 +00:00
< hr >
2019-02-15 18:31:56 +00:00
< br >
< button onclick = " hrefToFrame('?show') " > Осмотреть товары </ button >
< br >
< button onclick = " hrefToFrame('?sale') " > Сдать вещи в магазин </ button >
< br >
< button onclick = " hrefToFrame('?unsale') " > Забрать вещи из магазина </ button >
< br >
< button onclick = " hrefToFrame('city.php?cp=1') " > Вернуться </ button >
2019-01-18 19:56:07 +00:00
</ div >
</ TD >
</ TR >
2020-09-30 14:33:23 +00:00
</ TABLE >