<?php require_once "../includes/session.php"; require_once "../includes/db_connection.php"; require_once "../includes/functions.php"; $current_window = find_window_by_id($_GET["window"], false); if (!$current_window) { redirect_to("manage_content.php"); } $product_set = find_products_for_windows($current_window["id"]); if (mysqli_num_rows($product_set) > 0) { $_SESSION["message"] = "Can't delete a subject with products."; redirect_to("new_window.php?window = {$current_window["id"]}"); } $id = $current_window["id"]; $query = "DELETE FROM windows WHERE id = {$id} LIMIT 1"; $result = mysqli_query($conn, $query); if ($result && mysqli_affected_rows($conn) == 1) { $_SESSION["message"] = "Window deleted."; redirect_to("manage_content.php"); } else { $_SESSION["message"] = "Window deletion failed."; redirect_to("new_window.php?window = {$id}"); } ?>
function find_selected_product($public = false) { global $current_window; global $current_product; if (isset($_GET["window"])) { $current_window = find_window_by_id($_GET["window"], $public); if ($current_window && $public) { $current_product = find_default_product_for_window($current_window["id"]); } else { $current_product = null; } } elseif (isset($_GET["product"])) { $current_product = find_product_by_id($_GET["product"], $public); $current_window = null; } else { $current_window = null; $current_product = null; } }