if ($day == "" || $shift == "") {
    echo "<p>Invalid schedule parameters.  Please click on the \"Master Schedule\" link above to edit a master schedule shift.</p>";
} else {
    $master_entry = retrieve_dbMasterSchedule($venue . $day . $shift[1]);
    if ($master_entry == false) {
        $result = process_set_times($_POST, $day);
        if ($result) {
            $returnpoint = "viewSchedule.php?frequency=" . $venue;
            echo "<table align=\"center\"><tr><td align=\"center\" width=\"442\">\r\n                                        <br><a href=\"" . $returnpoint . "\">\r\n                                        Back to Master Schedule</a></td></tr></table>";
        } else {
            //$groupdisplay = $venue . " Group ".$group;
            echo "<table align=\"center\" width=\"450\"><tr><td align=\"center\" colspan=\"2\"><b>\r\n\t\t                                Adding a new " . ucfirst($venue) . " shift for " . substr($shift[0], 3) . " " . $shift[2] . " which starts at " . explode(" to ", do_name($_GET['shift']))[0] . "</b></td></tr>" . "<tr><td>\r\n                                            <b>Shift Name:</b>\r\n                                            <form method=\"POST\" style=\"margin-bottom:0;\">\r\n                                            <input name=\"shift_name\" type=\"text\"><br>\r\n                                            \t\t<select hidden name=\"new_start\">\r\n                                                    <option value=\"0\">Please select a new starting time</option>" . get_all_times() . "\r\n                                                    </select>\r\n                                                    <select name=\"new_end\">\r\n                                                    <option value=\"0\">Default End</option>" . get_all_end_times(explode("-", $shift[1])[1]) . "\r\n                                                    </select>\r\n                                                    <input type=\"hidden\" name=\"_submit_change_times\" value=\"1\">\r\n\t\t                                    <input type=\"submit\" value=\"Add New Shift\" name=\"submit\">\r\n\t\t                                    </form><br></td></tr></table>";
        }
    } else {
        // if one is there, see what we can do to update it
        if (!process_remove_shift($_POST, $shift, $day, $shift[1], $venue)) {
            // try to remove the shift
            // we've tried to clear the shift, add a slot, or remove a slot;
            // so now display the shift again.
            // $groupdisplay = $venue . " Group ".$group;
            echo "<table align=\"center\" width=\"450\"><tr><td align=\"center\" colspan=\"2\"><b>" . ucfirst($venue) . " shift for " . " " . $shift[2] . ", " . do_name($shift[1]) . "<br> \"" . $master_entry->get_Shifts() . "\"" . "</b>\r\n\t\t\t<form method=\"POST\" style=\"margin-bottom:0;\">\r\n\t\t\t<input type=\"hidden\" name=\"_submit_remove_shift\" value=\"1\"><br>\r\n\t\t\t<input type=\"submit\" value=\"Remove Entire Shift\"\r\n\t\t\tname=\"submit\">\r\n\t\t\t</form><br>\r\n\t\t\t</td></tr>";
            $returnpoint = "viewSchedule.php?frequency=" . $venue;
            echo "<table align=\"center\"><tr><td align=\"center\" width=\"442\">\r\n\t\t\t<br><a href=\"" . $returnpoint . "\">\r\n\t\t\t Back to Master Schedule</a></td></tr></table>";
        }
    }
}
?>
                    <br>
                </div>
                <?php 
include 'footer.inc';
// Mon
$shiftname = $_GET['shift'];
// 9-12
$id = $group . ":" . $day . ":" . $shiftname . ":" . $venue;
$msentry = retrieve_dbMasterSchedule($id);
if (!$msentry) {
    $result = process_add_shift($_POST, $group, $day, $shiftname, $venue);
    if ($result) {
        $returnpoint = "viewSchedule.php?venue=" . $venue;
        echo "<table align=\"center\"><tr><td align=\"center\" width=\"442\">\n\t\t\t\t\t\t\t\t<br><a href=\"" . $returnpoint . "\">\n\t\t\t\t\t\t\t\tBack to Master Schedule</a></td></tr></table>";
    } else {
        echo "Failed to add a master schedule shift";
    }
} else {
    // if a shift is there, see what we can do to update it
    if (!process_fill_vacancy($_POST, $msentry) && !process_add_volunteer($_POST, $msentry) && !process_remove_shift($_POST, $msentry, $group, $day, $shiftname, $venue)) {
        if (process_unfill_shift($_POST, $msentry, $venue)) {
            // try to remove a person
        } else {
            if (process_add_slot($_POST, $msentry, $venue)) {
                // try to add a new slot
            } else {
                if (process_ignore_slot($_POST, $msentry, $venue)) {
                    //try to remove a slot
                }
            }
        }
        // we've tried to clear the shift, add a slot, or remove a slot;
        // so now display the shift again.
        $msentry = retrieve_dbMasterSchedule($id);
        $persons = get_persons($msentry->get_id());