//require the framework require_once "../requires/initialize.php"; // create the page $page = new Page(); $page->name = "Color Management"; $page->is_admin_only = true; // this page allows ADMINs and STAFFs to view colors, create new colors, // update current colors and delete current colors // if deleting a color if (isset($_GET["delete_color_wk"])) { $delete_color = Color::find_by_id($_GET["delete_color_wk"]); // check if any pets are referencing this color key // if they are, reassign them to 'color_wk' = 0 // which should be reserved for default "undefined" color while ($pet = Pet::find_by_name($delete_color->color_wk, "color_wk")) { $failed = false; // tracks if any of the color reassignments were not successful $pet->color_wk = 0; if ($pet->save()) { $session->message($session->message . $pet->name . "'s color changed to " . $pet->color_wk . ". "); } else { $session->message($session->message . "Unable to reassign " . $pet->name . "'s color at this time. "); $failed = true; } } // try to delete the color if (!$failed) { if ($delete_color->delete()) { $session->message($session->message . "The color " . $delete_color->name . " was successfully deleted! "); redirect_head(ROOT_URL . "admin/manage_colors.php");