Замена define на const. Отказ от дублирующих инициализаций переменных $user $db и вызовов классов User и DBPDO из-за ошибочно настроенной IDE.

This commit is contained in:
lopar
2021-08-23 21:51:34 +03:00
parent c3cfc4ff22
commit 49c2e7c6d6
24 changed files with 90 additions and 167 deletions

View File

@@ -3,11 +3,9 @@
use Battles\GameLogs;
use Battles\ShopItem;
use Battles\Template;
use Battles\User;
session_start();
require_once 'functions.php';
$user = $user ?? new User($_SESSION['uid']);
$get = urldecode(filter_input(INPUT_SERVER, 'QUERY_STRING'));
$putItemCost = (int)filter_input(INPUT_POST, 'cost', FILTER_VALIDATE_INT, ['options' => ['min_range' => 1]]);
$putItemId = (int)filter_input(INPUT_POST, 'putId', FILTER_VALIDATE_INT, ['options' => ['min_range' => 1]]);
@@ -15,6 +13,8 @@ $returningItemId = (int)filter_input(INPUT_GET, 'back', FILTER_VALIDATE_INT, ['o
$byingItemId = (int)filter_input(INPUT_GET, 'set', FILTER_VALIDATE_INT, ['options' => ['min_range' => 1]]);
if ($putItemId) {
$query = 'select name from inventory where dressed_slot = 0 and owner_id = ? and item_id = ?';
\Battles\Database\DBPDO::INIT()->ofetch($query, [$_SESSION['uid'], $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();
if (empty($putItemCost)) {
$putItemCost = $dress['cost'];
@@ -75,60 +75,30 @@ if ($byingItemId) {
$classPrintControlName = "marketbuy";
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']);
$search = $_SESSION['uid'];
$query = 'select * from inventory where on_sale = 0 and dressed_slot = 0 and present is null and owner_id = ? order by name';
$classPrintControlName = "marketput";
} elseif ($get === 'unsale') {
$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']);
$search = $_SESSION['uid'];
$query = 'select * from inventory where on_sale > 0 and dressed_slot = 0 and owner_id = ? order by name';
$classPrintControlName = "marketgetback";
} else if (!empty($_POST['search'])) {
$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 `inventory`.`name` LIKE "%?S%" AND `setsale` > 0 ORDER BY `setsale` ASC', $_POST['search']);
$search = "%{$_POST['search']}%";
$query = 'select * from inventory where on_sale > 0 and dressed_slot = 0 and name like ? order by item_id';
} else {
$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');
$query = 'select * from inventory where on_sale > 0 and dressed_slot = 0 order by name';
}
if (isset($search)) {
$data = \Battles\Database\DBPDO::INIT()->ofetchAll($query, $search);
unset($search);
} else {
$data = \Battles\Database\DBPDO::INIT()->ofetchAll($query);
}
$iteminfo = [];
while ($row = $data->fetch_assoc()) {
$iteminfo[] = new ShopItem($row);
foreach ($data as $itemObject) {
$iteminfo[] = new ShopItem($itemObject, 'buymarket');
}
Template::header('Рынок');
@@ -137,12 +107,12 @@ Template::header('Рынок');
<h1>Рынок</h1>
<a href=# onclick=hrefToFrame('city.php?cp')> ← выйти на Центральную площадь</a>
<div><?php if (!empty($status)) err($status); ?></div>
<TABLE width=100% cellspacing="0" cellpadding="4">
<TR>
<TD valign=top align=left>
<TABLE class="zebra" width=100%>
<TR>
<TH>
<table width=100% cellspacing="0" cellpadding="4">
<tr>
<td valign=top align=left>
<table class="zebra" width=100%>
<tr>
<th>
<?php if ($get === 'sale'): ?>
Выставить товар на продажу.
<br>Комиссия за услуги магазина составляет 10% от цены, по которой вы предлагаете предмет.
@@ -154,9 +124,9 @@ Template::header('Рынок');
<input name="search"> <input type="submit" value="Искать товар">
</form>
<?php endif; ?>
<TR>
<TD><!--Рюкзак-->
<TABLE WIDTH=100%>
<tr>
<td><!--Рюкзак-->
<table width=100%>
<?php
foreach ($iteminfo as $ii) {
echo "<tr><td style='width: 150px; text-align: center;'>";
@@ -168,8 +138,8 @@ Template::header('Рынок');
echo "</td></tr>";
}
?>
</TABLE>
</TABLE>
</table>
</table>
<TD valign=top width=280>
<div style="margin-left:15px; margin-top: 10px;">
<b>Масса всех ваших вещей: <?= getItemsMassaInfo() ?>
@@ -184,4 +154,4 @@ Template::header('Рынок');
<br>
<button onclick="hrefToFrame('city.php?cp=1')">Вернуться</button>
</div>
</TABLE>
</table>