?> <?php // 3. Use returned data (if any) while ($subject = $dbo->fetch_assoc($subject_set)) { ?> <a href="index.php?subject=<?php echo urlencode($subject["id"]); ?> "><?php echo htmlentities($subject["menu_name"]); ?> </a> <?php $page_set = page::find_pages_for_subject($subject["id"]); ?> <ul class="sidemenu"> <?php while ($page = $dbo->fetch_assoc($page_set)) { ?> <?php echo "<li"; if ($current_page && $current_page["id"] == $page["id"]) { echo " class=\"selected\""; } echo ">"; ?>
ID: <?php echo $current_subject["id"]; ?> <br /> <br /> <a href="edit_subject.php?subject=<?php echo urlencode($current_subject["id"]); ?> ">Edit Subject</a> <br /> </p> <h2>Pages in this subject:</h2> <?php $page_set = page::find_pages_for_subject($current_subject["id"], false); ?> <?php echo page::print_page_tables($page_set); ?> <p><a href="create_page.php?subject=<?php echo urlencode($current_subject["id"]); ?> ">+Add a new page to this subject</a> </p> <?php } elseif ($current_page) { ?> <p><h2>Manage Page</h2></p>
/** * delete a subject according user submit * @param string $subject_id get from user click delete link */ public static function delete_subject($subject_id) { global $dbo; $page_set = page::find_pages_for_subject($subject_id, false); if ($dbo->count_number_rows($page_set) > 0) { // can't delete subject with pages $_SESSION["message"] = "can't delete subject with pages."; utility::redirect_to("manage_content.php?shubject={$current_subject["id"]}"); // redirect have exit() affect, will not excuate below code } $id = $subject_id; $query = "DELETE FROM subjects WHERE id = {$id} LIMIT 1"; $result = $dbo->query($query); if (isset($result) && $dbo->affected_rows($result) == 1) { // Success $_SESSION["message"] = "Subject deletion succeed."; utility::redirect_to("manage_content.php"); } else { // Failure $_SESSION["message"] = "Subject deletion failed."; utility::redirect_to("manage_content.php?shubject={$id}"); } }