126 lines
5.6 KiB
PHP
126 lines
5.6 KiB
PHP
|
<?php
|
||
|
if (!defined('SVRJS_MOD_DIRECTORY')) die;
|
||
|
|
||
|
$pageTitle = "Pending mods";
|
||
|
$pageDescription = 'View pending SVR.JS mods.';
|
||
|
include 'header.php';
|
||
|
?>
|
||
|
<main class="content">
|
||
|
<h1>Pending mods</h1>
|
||
|
<?php
|
||
|
$countStatement = $connection->prepare('SELECT COUNT(mods_pending.id) AS count
|
||
|
FROM mods_pending
|
||
|
JOIN users ON users.id = mods_pending.user
|
||
|
WHERE users.id = ?
|
||
|
AND users.is_suspended = 0
|
||
|
AND users.is_deleted = 0
|
||
|
AND users.is_verified = 1;');
|
||
|
if (!$countStatement) {
|
||
|
echo "<p>An unexpected error occurred while fetching mods.</p>";
|
||
|
} else {
|
||
|
$countStatement->bind_param('i', $_SESSION['user']);
|
||
|
$countStatement->execute();
|
||
|
|
||
|
$countResult = $countStatement->get_result();
|
||
|
|
||
|
if (!$countResult) {
|
||
|
echo "<p>An unexpected error occurred while fetching mods.</p>";
|
||
|
$countStatement->close();
|
||
|
} else {
|
||
|
$countRow = $countResult->fetch_assoc();
|
||
|
$countStatement->close();
|
||
|
if (!$countRow) {
|
||
|
echo "<p>An unexpected error occurred while fetching mods.</p>";
|
||
|
} else {
|
||
|
$modCount = $countRow['count'];
|
||
|
$totalPages = ceil($modCount / PAGE_MODS);
|
||
|
$statement = $connection->prepare('SELECT
|
||
|
mods_pending.id AS id,
|
||
|
mods_pending.name AS name,
|
||
|
mods_pending.slug AS slug,
|
||
|
mods_pending.description AS description,
|
||
|
mods_pending.image_ext AS image_ext,
|
||
|
mods_pending.is_paid AS is_paid,
|
||
|
mods_pending.is_rejected AS is_rejected,
|
||
|
users.username AS user,
|
||
|
users.id AS user_id
|
||
|
FROM mods_pending
|
||
|
JOIN users ON users.id = mods_pending.user
|
||
|
WHERE users.id = ?
|
||
|
AND users.is_suspended = 0
|
||
|
AND users.is_deleted = 0
|
||
|
AND users.is_verified = 1
|
||
|
ORDER BY mods_pending.id DESC
|
||
|
LIMIT ?,?;');
|
||
|
if (!$statement) {
|
||
|
echo "<p>An unexpected error occurred while fetching mods.</p>";
|
||
|
} else {
|
||
|
$pageNumber = isset($_GET['page']) && filter_var($_GET['page'], FILTER_VALIDATE_INT) ? intval($_GET['page']) : 1;
|
||
|
$firstNumber = PAGE_MODS * ($pageNumber - 1);
|
||
|
$pageMods = PAGE_MODS;
|
||
|
$statement->bind_param('iii', $_SESSION['user'], $firstNumber, $pageMods);
|
||
|
$statement->execute();
|
||
|
|
||
|
$result = $statement->get_result();
|
||
|
|
||
|
if (!$result) {
|
||
|
echo "<p>An unexpected error occurred while fetching mods.</p>";
|
||
|
$statement->close();
|
||
|
} else {
|
||
|
$modsPresent = false;
|
||
|
while ($mod = $result->fetch_assoc()) {
|
||
|
if (!$modsPresent) {
|
||
|
echo '<div class="mods">';
|
||
|
}
|
||
|
$modsPresent = true;
|
||
|
echo '<div class="mods-mod-container">
|
||
|
<div class="mods-mod-card">
|
||
|
<img src="' . htmlspecialchars(APP_ROOT . 'img/' . (isset($mod['image_ext']) && $mod['image_ext'] ? 'mods_pending/' . urlencode(str_replace(['/', '\\'], '', $mod['slug'])) . '.' . urlencode(str_replace(['/', '\\'], '', $mod['image_ext'])) : 'mod-missing.png')) . '" alt="' . htmlspecialchars($mod['name']) . ' cover image">
|
||
|
<div class="mods-mod-card-contents">
|
||
|
<h2>' . htmlspecialchars($mod['name']) . '</h2>
|
||
|
<p>' . (isset($mod['description']) && $mod['description'] ? str_replace(["\r\n", "\n", "\r"], '<br/>', htmlspecialchars(shortenDescription($mod['description']))) : "<i>No description</i>") . '</p>
|
||
|
<div class="mods-mod-card-bottom">
|
||
|
<p class="mods-mod-card-publisher">' . (isset($_SESSION['user']) && $_SESSION['user'] == $mod['user_id'] ? '<a href="' . htmlspecialchars((URL_REWRITTEN ? APP_ROOT : APP_ROOT . APP_FILENAME . '/') . 'edit-mod/' . urlencode($mod['slug'])) . '">Edit mod</a> | <a href="' . htmlspecialchars((URL_REWRITTEN ? APP_ROOT : APP_ROOT . APP_FILENAME . '/') . 'discard-mod/' . urlencode($mod['slug'])) . '">Discard mod</a>' : '') . '</p>
|
||
|
<span class="badge">' . ($mod['is_rejected'] ? 'Rejected' : 'Pending') . '</span>
|
||
|
<span class="badge">' . ($mod['is_paid'] ? 'Paid' : 'Gratis') . '</span>
|
||
|
</div>
|
||
|
</div>
|
||
|
</div>
|
||
|
</div>';
|
||
|
}
|
||
|
if ($modsPresent) {
|
||
|
echo '</div>';
|
||
|
} else {
|
||
|
echo '<p>No mods.</p>';
|
||
|
}
|
||
|
$statement->close();
|
||
|
if ($totalPages > 1) {
|
||
|
$begPage = $pageNumber - 2;
|
||
|
$endPage = $pageNumber + 2;
|
||
|
if ($endPage > $totalPages) {
|
||
|
$begPage -= $endPage - $totalPages;
|
||
|
$endPage = $totalPages;
|
||
|
}
|
||
|
if ($begPage < 1) {
|
||
|
$endPage += 1 - $begPage;
|
||
|
$begPage = 1;
|
||
|
}
|
||
|
|
||
|
echo '<div class="pagination">';
|
||
|
echo $pageNumber <= 1 ? '<span>‹</span>' : '<a href="' . htmlspecialchars((URL_REWRITTEN ? APP_ROOT : APP_ROOT . APP_FILENAME . '/') . 'pending-mods?page=' . urlencode(strval($pageNumber - 1))) . '">‹</a>';
|
||
|
for ($i = 0; $i < ($totalPages > 5 ? 5 : $totalPages); $i++) {
|
||
|
echo $pageNumber == $begPage + $i ? '<span>' . htmlspecialchars(strval($begPage + $i)) . '</span>' : '<a href="' . htmlspecialchars((URL_REWRITTEN ? APP_ROOT : APP_ROOT . APP_FILENAME . '/') . 'pending-mods?page=' . urlencode(strval($begPage + $i))) . '">' . htmlspecialchars(strval($begPage + $i)) . '</a>';
|
||
|
}
|
||
|
echo $pageNumber >= $totalPages ? '<span>›</span>' : '<a href="' . htmlspecialchars((URL_REWRITTEN ? APP_ROOT : APP_ROOT . APP_FILENAME . '/') . 'pending-mods?page=' . urlencode(strval($pageNumber + 1))) . '">›</a>';
|
||
|
echo '</div>';
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
?>
|
||
|
</main>
|
||
|
<?php
|
||
|
include 'footer.php';
|
||
|
?>
|