Files
legacy-server/database/getMarketplaceIcons.php
2025-08-27 21:56:58 -07:00

50 lines
1.5 KiB
PHP

<?php
require __DIR__ . '/../incl/util.php';
setPlainHeader();
checkClientDatabaseVersion();
$conn = newConnection();
$post = getPostData();
$priceRangeEnabled = (bool)$post['priceRangeEnabled'] ?? false;
$priceRangeMin = (int)$post['priceRangeMin'] ?? 10;
$priceRangeMax = (int)$post['priceRangeMax'] ?? 250;
$searchForEnabled = (bool)$post['searchForEnabled'] ?? false;
$searchForValue = (string)$post['searchForValue'] ?? '';
$where = ["u.banned = 0", "(c.state = 1 OR c.state = 2)"];
$params = [];
$types = "";
if ($priceRangeEnabled) {
$where[] = "c.price BETWEEN ? AND ?";
$params[] = $priceRangeMin;
$params[] = $priceRangeMax;
$types .= "ii";
}
if ($searchForEnabled && $searchForValue !== '') {
$where[] = "FROM_BASE64(c.name) LIKE ?";
$params[] = "%$searchForValue%";
$types .= "s";
}
$sql = "
SELECT c.data, u.username, u.id, c.price, c.name, c.uuid, c.state
FROM marketplaceicons c
JOIN users u ON c.userId = u.id
WHERE " . implode(" AND ", $where) . "
ORDER BY c.id ASC
";
$stmt = $conn->prepare($sql);
if (!empty($params)) {
$stmt->bind_param($types, ...$params);
}
$stmt->execute();
$result = $stmt->get_result();
echo encrypt(json_encode(array_map(fn($row) => ['username' => $row['username'], 'userid' => $row['id'], 'data' => $row['data'], 'uuid' => $row['uuid'], 'price' => (int)$row['state'] == 2 ? 100000000 : $row['price'], 'name' => base64_decode($row['name'])], $result->fetch_all(MYSQLI_ASSOC))));
$conn->close();