2018-01-28 16:40:49 +00:00
< ? php
ob_start ();
session_start ();
2018-12-12 19:55:33 +00:00
if ( $_SESSION [ 'uid' ] == null ) header ( " Location: index.php " );
require_once ( " functions.php " );
2018-01-28 16:40:49 +00:00
2018-06-22 23:00:48 +00:00
if ( $user [ 'room' ] != 22 ) {
header ( " Location: main.php " );
die ();
2018-01-28 16:40:49 +00:00
}
2018-06-22 23:00:48 +00:00
if ( $user [ 'battle' ] != 0 ) {
header ( 'location: fbattle.php' );
die ();
2018-01-28 16:40:49 +00:00
}
2018-06-23 18:08:07 +00:00
$saleItems = false ;
2018-01-28 16:40:49 +00:00
2019-01-14 20:28:47 +00:00
if ( false == $saleItems ) {
$shopItems = db :: c () -> query ( ' SELECT `shop` .* ,
`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 `shop` LEFT JOIN `magic` ON `magic` = `magic` . `id` WHERE `count` > 0 AND `cost` > 0 AND `razdel` = ? i ORDER by `nlevel` ASC , `id` ASC ' , $shopCategoryTypeNumber );
$iteminfo = [];
while ( $row = $shopItems -> fetch_assoc ()) {
$iteminfo [] = new ShopItem ( $row );
2018-01-28 16:40:49 +00:00
}
2019-01-14 20:28:47 +00:00
} else {
$inventoryItems = 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 `dressed` = 0 AND `setsale` = 0 AND `cost` > 0 AND `present` = " ?n " AND `tradesale` = 0 AND `podzem` = 0 AND `goden` = 0 AND `owner` = ? i ORDER BY `update` DESC ', $_SESSION[' uid ' ], null );
$iteminfo = [];
while ( $row = $inventoryItems -> fetch_assoc ()) {
$iteminfo [] = new ShopItem ( $row );
2018-01-28 16:40:49 +00:00
}
2019-01-14 20:28:47 +00:00
}
$sellItemId = filter_input ( INPUT_GET , 'sell' );
if ( $sellItemId ) {
$dress = db :: c () -> query ( 'SELECT `id`, `name`, `cost`, `koll` FROM `inventory` WHERE `dressed` = 0 AND `id` = ?i AND `owner` = ?i' , $sellItemId , $user [ 'id' ]) -> fetch_assoc ();
$kols = '' ;
if ( $dress [ 'koll' ]) {
$dress [ 'cost' ] *= $dress [ 'koll' ];
$kols = " (x { $dress [ 'koll' ] } ) " ;
2018-06-22 23:00:48 +00:00
}
2019-01-14 20:28:47 +00:00
$allcost = mt_rand ( 0 , $dress [ 'cost' ] / 2 );
#destructitem($dress['id']);
db :: c () -> query ( 'DELETE FROM `inventory` WHERE `id` = ?i' , $dress [ 'id' ]);
db :: c () -> query ( 'UPDATE `users` SET `money` = ?i WHERE `id` = ?i' , $allcost , $_SESSION [ 'uid' ]);
$status = " Вы продали « { $dress [ 'name' ] } » $kols за " . $allcost . " кр. " ;
$deloText = " { $user [ 'login' ] } продал товар « { $dress [ 'name' ] } » { $kols } id:( { $dress [ 'id' ] } ) в магазине за { $allcost } кр. " ;
addToDelo ( $deloText );
2018-01-28 16:40:49 +00:00
}
2019-01-12 21:35:48 +00:00
if ( ! empty ( $_GET [ 'buy' ])) {
2018-01-28 16:40:49 +00:00
2019-01-14 17:19:11 +00:00
$dress = db :: c () -> query ( 'SELECT * FROM `shop` WHERE `id`=?i' , $_GET [ 'buy' ]) -> fetch_assoc ();
2019-01-14 17:40:14 +00:00
$itemWeight = db :: c () -> query ( 'SELECT sum(`massa`) AS `m` FROM `inventory` WHERE `owner` = ?i AND `setsale` = 0' , $_SESSION [ 'uid' ]) -> fetch_assoc ();
2018-06-23 16:22:20 +00:00
2019-01-14 17:40:14 +00:00
if (( $dress [ 'massa' ] + $itemWeight [ 'm' ]) > ( get_meshok ())) $status = 'Недостаточно места в рюкзаке.' ;
elseif ( $user [ 'money' ] >= $dress [ 'cost' ] AND ( $dress [ 'count' ] > 0 OR $dress [ 'count' ] == - 1 )) {
2018-06-23 12:44:38 +00:00
$newItem = [
'prototype' => $dress [ 'id' ],
'owner' => $user [ 'id' ],
'name' => $dress [ 'name' ], //s
'type' => $dress [ 'type' ],
'massa' => $dress [ 'massa' ],
'cost' => $dress [ 'cost' ],
'img' => $dress [ 'img' ], //s
'maxdur' => $dress [ 'maxdur' ],
'isrep' => $dress [ 'isrep' ],
'gsila' => $dress [ 'gsila' ],
'glovk' => $dress [ 'glovk' ],
'ginta' => $dress [ 'ginta' ],
'gintel' => $dress [ 'gintel' ],
'ghp' => $dress [ 'ghp' ],
'gnoj' => $dress [ 'gnoj' ],
'gtopor' => $dress [ 'gtopor' ],
'gdubina' => $dress [ 'gdubina' ],
'gmech' => $dress [ 'gmech' ],
'gfire' => $dress [ 'gfire' ],
'gwater' => $dress [ 'gwater' ],
'gair' => $dress [ 'gair' ],
'gearth' => $dress [ 'gearth' ],
'glight' => $dress [ 'glight' ],
'ggray' => $dress [ 'ggray' ],
'gdark' => $dress [ 'gdark' ],
'needident' => $dress [ 'needident' ],
'nsila' => $dress [ 'nsila' ],
'nlovk' => $dress [ 'nlovk' ],
'ninta' => $dress [ 'ninta' ],
'nintel' => $dress [ 'nintel' ],
'nmudra' => $dress [ 'nmudra' ],
'nvinos' => $dress [ 'nvinos' ],
'nnoj' => $dress [ 'nnoj' ],
'ntopor' => $dress [ 'ntopor' ],
'ndubina' => $dress [ 'ndubina' ],
'nmech' => $dress [ 'nmech' ],
'bron1' => $dress [ 'bron1' ],
'bron2' => $dress [ 'bron2' ],
'bron3' => $dress [ 'bron3' ],
'bron4' => $dress [ 'bron4' ],
'minu' => $dress [ 'minu' ],
'maxu' => $dress [ 'maxu' ],
'magic' => $dress [ 'magic' ],
'nlevel' => $dress [ 'nlevel' ],
'nalign' => $dress [ 'nalign' ],
'dategoden' => $dress [ 'dategoden' ],
'goden' => $dress [ 'goden' ],
'gmp' => $dress [ 'gmp' ],
'artefact' => $dress [ 'artefact' ],
'koll' => $dress [ 'koll' ]
];
2018-06-22 23:00:48 +00:00
2019-01-14 17:48:36 +00:00
db :: c () -> query ( 'INSERT INTO `inventory` SET ?A[?i,?i,"?s",?i,?i,?i,"?s",?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i]' , $newItem );
2019-01-14 17:40:14 +00:00
$inventoryItemId = db :: c () -> getLastInsertId ();
if ( $dress [ 'count' ] != - 1 ) db :: c () -> query ( 'UPDATE `shop` SET `count` = `count` - 1 WHERE `id` = ?i' , $_GET [ 'buy' ]);
$status = " Вы купили \" { $dress [ 'name' ] } \" . " ;
db :: c () -> query ( 'UPDATE `users` set `money` = ?i WHERE `id` = ?i' , $dress [ 'cost' ], $_SESSION [ 'uid' ]);
2019-01-14 17:48:36 +00:00
$deloText = " { $user [ 'login' ] } купил товар « { $dress [ 'name' ] } » id:( { $inventoryItemId } ) в магазине за { $dress [ 'cost' ] } кр. " ;
addToDelo ( $deloText );
2019-01-14 17:05:15 +00:00
2018-06-22 23:00:48 +00:00
} else {
2019-01-14 17:40:14 +00:00
$status = " Недостаточно денег или нет вещей в наличии. " ;
2018-01-28 16:40:49 +00:00
}
}
2019-01-14 17:40:14 +00:00
2018-06-23 17:48:10 +00:00
$shopCategoryType = empty ( $_POST [ 'sale' ]) ? : $_POST [ 'sale' ];
$shopCategoryTypeNumber = empty ( $_GET [ 'otdel' ]) ? : $_GET [ 'otdel' ];
switch ( $shopCategoryTypeNumber ) {
2018-06-23 12:44:38 +00:00
default :
2018-06-23 18:26:38 +00:00
$shopCategoryType = " Предметы в инвентаре " ;
2018-06-23 18:08:07 +00:00
$saleItems = true ;
2018-06-23 12:44:38 +00:00
break ;
case 1 :
2018-06-23 17:48:10 +00:00
$shopCategoryType = " Кастеты и ножи " ;
2018-06-23 12:44:38 +00:00
break ;
case 11 :
2018-06-23 17:48:10 +00:00
$shopCategoryType = " Топоры " ;
2018-06-23 12:44:38 +00:00
break ;
case 12 :
2018-06-23 17:48:10 +00:00
$shopCategoryType = " Дубины и булавы " ;
2018-06-23 12:44:38 +00:00
break ;
case 13 :
2018-06-23 17:48:10 +00:00
$shopCategoryType = " Мечи " ;
2018-06-23 12:44:38 +00:00
break ;
case 2 :
2018-06-23 17:48:10 +00:00
$shopCategoryType = " Сапоги " ;
2018-06-23 12:44:38 +00:00
break ;
case 21 :
2018-06-23 17:48:10 +00:00
$shopCategoryType = " Перчатки " ;
2018-06-23 12:44:38 +00:00
break ;
case 22 :
2018-06-23 17:48:10 +00:00
$shopCategoryType = " Легкая броня " ;
2018-06-23 12:44:38 +00:00
break ;
case 23 :
2018-06-23 17:48:10 +00:00
$shopCategoryType = " Тяжелая броня " ;
2018-06-23 12:44:38 +00:00
break ;
case 24 :
2018-06-23 17:48:10 +00:00
$shopCategoryType = " Шлемы " ;
2018-06-23 12:44:38 +00:00
break ;
case 3 :
2018-06-23 17:48:10 +00:00
$shopCategoryType = " Щиты " ;
2018-06-23 12:44:38 +00:00
break ;
case 4 :
2018-06-23 17:48:10 +00:00
$shopCategoryType = " Серьги " ;
2018-06-23 12:44:38 +00:00
break ;
case 41 :
2018-06-23 17:48:10 +00:00
$shopCategoryType = " Ожерелья " ;
2018-06-23 12:44:38 +00:00
break ;
case 42 :
2018-06-23 17:48:10 +00:00
$shopCategoryType = " Кольца " ;
2018-06-23 12:44:38 +00:00
break ;
case 5 :
2018-06-23 17:48:10 +00:00
$shopCategoryType = " Заклинания: нейтральные " ;
2018-06-23 12:44:38 +00:00
break ;
case 51 :
2018-06-23 17:48:10 +00:00
$shopCategoryType = " Заклинания: боевые и защитные " ;
2018-06-23 12:44:38 +00:00
break ;
case 6 :
2018-06-23 17:48:10 +00:00
$shopCategoryType = " Амуниция " ;
2018-06-23 12:44:38 +00:00
break ;
case 52 :
2018-06-23 17:48:10 +00:00
$shopCategoryType = " Руны " ;
2018-06-23 12:44:38 +00:00
break ;
}
2018-01-28 16:40:49 +00:00
?>
2018-06-22 23:00:48 +00:00
<! DOCTYPE html >
< html >
< head >
< meta charset = " utf-8 " >
< link href = " css/main.css " rel = " stylesheet " />
< script src = " js/jquery-1.7.2.min.js " ></ script >
< script src = " js/jquery.simplemodal.js " ></ script >
< script src = " js/jquery.ui.js?100 " ></ script >
< script src = " js/mi.js " ></ script >
< link rel = " stylesheet " href = " css/bkstyle.css?101 " />
< link rel = " stylesheet " href = " css/mi.css " />
< style >
. row {
font - family : Tahoma , sans - serif ;
font - size : 13 px ;
}
</ style >
< script >
function leave () {
top . frames [ 'main' ] . location = 'city.php?cp'
}
</ script >
</ head >
< body >
< h1 > Государственный магазин </ h1 >
< a href = # onclick=leave()> ← выйти на Центральную площадь</a>
2019-01-14 17:40:14 +00:00
< div >< ? php if ( ! empty ( $status )) err ( $status ); ?> </div>
2018-06-23 17:14:10 +00:00
< TABLE width = 100 % cellspacing = " 0 " cellpadding = " 4 " >
2018-06-22 23:00:48 +00:00
< TR >
< TD valign = top align = left >
<!-- Магазин -->
< TABLE border = 0 width = 100 % cellspacing = " 0 " cellpadding = " 0 " bgcolor = " #A5A5A5 " >
< TR >
2018-06-23 12:44:38 +00:00
< TD align = center >
2018-06-23 17:48:10 +00:00
< h3 >< ? = $shopCategoryType ?> </h3>
2018-12-12 21:18:14 +00:00
< ? php if ( $saleItems ) : ?>
2019-01-14 20:28:47 +00:00
Вы можете продать ваши предметы за сущие копейки .
2018-12-12 21:18:14 +00:00
< ? php endif ; ?>
2018-06-22 23:00:48 +00:00
</ TD >
</ TR >
< TR >
< TD >
2018-06-23 17:14:10 +00:00
< TABLE class = " zebra " WIDTH = 100 % CELLSPACING = " 1 " CELLPADDING = " 2 " BGCOLOR = " #A5A5A5 " >
2018-06-22 23:00:48 +00:00
< ? php
2018-12-12 19:55:33 +00:00
if ( $saleItems == true ) {
2019-01-14 20:28:47 +00:00
2019-01-14 20:33:32 +00:00
foreach ( $iteminfo as $ii ) {
echo " <tr><td style='width: 150px; text-align: center;'> " ;
$ii -> printImage ();
$ii -> printControls ( true );
echo " </td> " ;
echo " <td style='vertical-align: top;'> " ;
$ii -> printInfo ();
echo " </td></tr> " ;
2018-06-22 23:00:48 +00:00
}
2019-01-14 20:33:32 +00:00
2018-06-22 23:00:48 +00:00
} else {
2019-01-14 17:05:15 +00:00
foreach ( $iteminfo as $ii ) {
echo " <tr><td style='width: 150px; text-align: center;'> " ;
$ii -> printImage ();
$ii -> printControls ();
echo " </td> " ;
echo " <td style='vertical-align: top;'> " ;
$ii -> printInfo ();
echo " </td></tr> " ;
}
2018-06-22 23:00:48 +00:00
}
?>
</ TABLE >
</ TD >
</ TR >
</ TABLE >
</ TD >
< TD valign = top width = 280 >
2018-12-12 20:21:47 +00:00
< B > М а с с а всех ваших вещей : < ? = getItemsMassaInfo () ?>
< BR > У вас в наличии : < span style = " color: darkgreen; " >< ? = $user [ 'money' ] ?> </span> кр.</B>
2018-06-22 23:00:48 +00:00
< hr >
2018-06-23 18:26:38 +00:00
< a href = " shop.php?otdel=sale&rnd=<?= mt_rand() ?> " > Продать вещи </ a >
2018-06-22 23:00:48 +00:00
< dl >
< dt >< b > Оружие :</ b ></ dt >
< dd >< a href = " shop.php?otdel=1&rnd=<?= mt_rand() ?> " > кастеты , ножи </ a ></ dd >
< dd >< a href = " shop.php?otdel=11&rnd=<?= mt_rand() ?> " > топоры </ a ></ dd >
< dd >< a href = " shop.php?otdel=12&rnd=<?= mt_rand() ?> " > дубины , булавы </ a ></ dd >
< dd >< a href = " shop.php?otdel=13&rnd=<?= mt_rand() ?> " > мечи </ a ></ dd >
< dt >< b > Одежда :</ b ></ dt >
< dd >< a href = " shop.php?otdel=24&rnd=<?= mt_rand() ?> " > шлемы </ a ></ dd >
< dd >< a href = " shop.php?otdel=23&rnd=<?= mt_rand() ?> " > тяжелая броня </ a ></ dd >
< dd >< a href = " shop.php?otdel=22&rnd=<?= mt_rand() ?> " > легкая броня </ a ></ dd >
< dd >< a href = " shop.php?otdel=3&rnd=<?= mt_rand() ?> " > щиты </ a ></ dd >
< dd >< a href = " shop.php?otdel=21&rnd=<?= mt_rand() ?> " > перчатки </ a ></ dd >
< dd >< a href = " shop.php?otdel=2&rnd=<?= mt_rand() ?> " > сапоги </ a ></ dd >
< dt >< b > Ювелирные товары :</ b ></ dt >
< dd >< a href = " shop.php?otdel=4&rnd=<?= mt_rand() ?> " > серьги </ a ></ dd >
< dd >< a href = " shop.php?otdel=41&rnd=<?= mt_rand() ?> " > ожерелья </ a ></ dd >
< dd >< a href = " shop.php?otdel=42&rnd=<?= mt_rand() ?> " > кольца </ a ></ dd >
< dt >< b > Магия :</ b ></ dt >
< dd >< a href = " shop.php?otdel=51&rnd=<?= mt_rand() ?> " > боевые </ a ></ dd >
< dd >< a href = " shop.php?otdel=5&rnd=<?= mt_rand() ?> " > разные </ a ></ dd >
< dt >< b > Разное :</ b ></ dt >
< dd >< a href = " shop.php?otdel=6&rnd=<?= mt_rand() ?> " > амуниция </ a ></ dd >
2018-06-23 17:48:10 +00:00
< dd >< a href = " shop.php?otdel=52&rnd=<?= mt_rand() ?> " > руны </ a ></ dd >
2018-06-22 23:00:48 +00:00
</ dl >
< div id = " hint3 " class = " ahint " ></ div >
</ TD >
</ TR >
2018-01-28 16:40:49 +00:00
</ TABLE >
</ BODY >
</ HTML >