<?php require_once "../includes/session.php"; require_once "../includes/db_connection.php"; require_once "../includes/functions.php"; confirm_logged_in(); ?> <?php $current_category = find_category_by_id($_GET["category"], false); if (!$current_category) { // category ID was missing or invalid or // category couldn't be found in database redirect_to("manage_content.php"); } $book_set = find_books_for_category($current_category["id"], false); if (mysqli_num_rows($books_set) > 0) { $_SESSION["message"] = "Can't delete a category with books."; redirect_to("manage_content.php?category={$current_category["id"]}"); } $id = $current_category["id"]; $query = "DELETE FROM yb_category WHERE id = {$id} LIMIT 1"; $result = mysqli_query($connection, $query); if ($result && mysqli_affected_rows($connection) == 1) { // Success $_SESSION["message"] = "category deleted."; redirect_to("manage_content.php"); } else { // Failure $_SESSION["message"] = "category deletion failed."; redirect_to("manage_content.php?category={$id}");
/** * This navigation will shown to all website's visitors * * @param category_array showing the list of all categories list menu * @param book_array showing the list of all books list menu * @return output */ function public_navigation($category_array, $book_array) { $output = "<ul class=\"category\">"; $category_set = find_all_category(); while ($category = mysqli_fetch_assoc($category_set)) { $output .= "<li"; if ($category_array && $category["id"] == $category_array["id"]) { $output .= " class=\"selected\""; } $output .= ">"; $output .= "<a href=\"index.php?category="; $output .= urlencode($category["id"]); $output .= "\">"; $output .= htmlentities($category["category_name"]); $output .= "</a>"; if ($category_array["id"] == $category["id"] || $book_array["category_id"] == $category["id"]) { $book_set = find_books_for_category($category["id"]); $output .= "<ul class=\"books\">"; while ($book = mysqli_fetch_assoc($book_set)) { $output .= "<li"; if ($book_array && $book["id"] == $book_array["id"]) { $output .= " class=\"selected\""; } $output .= ">"; $output .= "<a href=\"index.php?book="; $output .= urlencode($book["id"]); $output .= "\">"; $output .= htmlentities($book["category_name"]); $output .= "</a></li>"; } $output .= "</ul>"; mysqli_free_result($book_set); } $output .= "</li>"; // end of the subject li } mysqli_free_result($category_set); $output .= "</ul>"; return $output; }
<br /> Position: <?php echo $current_category["position"]; ?> <br /> <br /> <a href="edit_category.php?category=<?php echo urlencode($current_category["id"]); ?> ">Edit Category</a> <div style="margin-top: 2em; border-top: 1px solid #000000;"> <h3>Books in this Category:</h3> <ul> <?php $category_books = find_books_for_category($current_category["id"], false); while ($book = mysqli_fetch_assoc($category_books)) { echo "<li>"; $safe_book_id = urlencode($book["id"]); echo "<a href=\"manage_content.php?book={$safe_book_id}\">"; echo htmlentities($book["category_name"]); echo "</a>"; echo "</li>"; } ?> </ul> <br /> + <a href="new_book.php?category=<?php echo urlencode($current_category["id"]); ?> ">Add a new book to this category</a>