prepare("SELECT slug FROM categories WHERE slug = ?"); if (!$statement) { $slugError = true; $errorMessage = "An unexpected error occurred while adding the category."; break; } else { $tempSlug2 = $tempSlug . ($tempSlugCount > 1 ? '-' . strval($tempSlugCount) : ''); $statement->bind_param('s', $tempSlug2); $statement->execute(); $slugExistsResult = $statement->get_result(); if (!$slugExistsResult) { $slugError = true; $errorMessage = "An unexpected error occurred while adding the category."; $statement->close(); break; } else { $slugExists = boolval($slugExistsResult->fetch_assoc()); $statement->close(); if (!$slugExists) { $slug = $tempSlug2; } else { $tempSlugCount++; } } } } if (!$slugError) { $statement = $connection->prepare('INSERT INTO categories (name, slug) VALUES (?, ?);'); if (!$statement) { $errorMessage = "An unexpected error occurred while adding the category."; } else { $statement->bind_param('ss', $_POST['categoryname'], $slug); if (!$statement->execute()) { $errorMessage = "An unexpected error occurred while adding the category."; } else { $categoryAdded = true; } $statement->close(); } } } } elseif ($_POST['action'] == "rename") { if (!isset($_POST['category'], $_POST['categoryname']) || !$_POST['category'] || !$_POST['categoryname']) { $errorMessage = "You need to specify the category you want to rename and the new category name."; } elseif (!filter_var($_POST['category'], FILTER_VALIDATE_INT)) { $errorMessage = "Invalid category."; } else { $categoryID = intval($_POST['category']); $statement = $connection->prepare("SELECT id FROM categories WHERE id = ?"); if (!$statement) { $errorMessage = "An unexpected error occurred while renaming the category."; } else { $statement->bind_param('i', $categoryID); $statement->execute(); $result = $statement->get_result(); if (!$result) { $errorMessage = "An unexpected error occurred while renaming the category."; $statement->close(); } else { $isCategoryPresent = boolval($result->fetch_assoc()); $statement->close(); if (!$isCategoryPresent) { $errorMessage = "The selected category doesn't exist."; } else { $statement = $connection->prepare('UPDATE categories SET name = ? WHERE id = ?;'); if (!$statement) { $errorMessage = "An unexpected error occurred while renaming the category."; } else { $statement->bind_param('si', $_POST['categoryname'], $categoryID); if (!$statement->execute()) { $errorMessage = "An unexpected error occurred while renaming the category."; } else { $categoryRenamed = true; } $statement->close(); } } } } } } elseif ($_POST['action'] == "remove") { if (!isset($_POST['category']) || !$_POST['category']) { $errorMessage = "You need to specify the category you want to remove."; } elseif (!filter_var($_POST['category'], FILTER_VALIDATE_INT)) { $errorMessage = "Invalid category."; } else { $categoryID = intval($_POST['category']); $statement = $connection->prepare("SELECT id FROM categories WHERE id = ?"); if (!$statement) { $errorMessage = "An unexpected error occurred while removing the category."; } else { $statement->bind_param('i', $categoryID); $statement->execute(); $result = $statement->get_result(); if (!$result) { $errorMessage = "An unexpected error occurred while removing the category."; $statement->close(); } else { $isCategoryPresent = boolval($result->fetch_assoc()); $statement->close(); if (!$isCategoryPresent) { $errorMessage = "The selected category doesn't exist."; } else { $statement = $connection->prepare('DELETE FROM categories WHERE id = ?;'); if (!$statement) { $errorMessage = "An unexpected error occurred while removing the category."; } else { $statement->bind_param('i', $categoryID); if (!$statement->execute()) { $errorMessage = "An unexpected error occurred while removing the category."; } else { $categoryRemoved = true; } $statement->close(); } } } } } } else { $errorMessage = "Unknown action specified."; } } $pageTitle = "Categories"; include '../includes/moderation_header.php'; ?>

Categories

' . htmlspecialchars($errorMessage) . '

'; ?> Category has been added.

'; } elseif ($categoryRenamed) { echo '

Category has been renamed.

'; } elseif ($categoryRemoved) { echo '

Category has been removed.

'; } ?>

Add category

Rename category

Remove category

This will cause mods in the category you want to remove to be of invalid category.

List of categories

query("SELECT categories.id AS id, categories.name AS name, categories.slug AS slug, ( SELECT COUNT(mods.id) FROM mods JOIN users ON users.id = mods.user WHERE mods.category = categories.id AND mods.is_removed = 0 AND users.is_suspended = 0 AND users.is_verified = 1 AND users.is_deleted = 0 LIMIT 1 ) AS count FROM categories;"); if (!$result) { echo "

An unexpected error occurred while fetching categories.

"; } else { $categoriesPresent = false; while ($category = $result->fetch_assoc()) { $categoriesPresent = true; echo '

' . htmlspecialchars($category['name']) . '

Mods: ' . htmlspecialchars(number_format($category['count'], 0)) . '

'; } if (!$categoriesPresent) { echo '

No categories.

'; } } ?>