}
// $frequency=$_GET['frequency'];
$venue = $_GET['venue'];
$day = $_GET['day'];
$shift = [$day, $_GET['shift']];
$shift = get_day_names($shift, $day);
include_once 'database/dbMasterSchedule.php';
include_once 'domain/MasterScheduleEntry.php';
include_once 'database/dbLog.php';
//if($group=="" || $day=="" || $shift=="") {
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>";
if (isset($_SESSION['mygroup'])) {
    $group = $_SESSION['mygroup'];
} else {
    $group = "foodbank";
}
$group = $_GET['group'];
$day = $_GET['day'];
$week_no = $_GET['week_no'];
include_once 'database/dbMasterSchedule.php';
include_once 'domain/MasterScheduleEntry.php';
include_once 'database/dbLog.php';
if ($group == "" || $day == "" || $week_no == "") {
    echo "<p>Invalid schedule parameters.  Please click on the \"Master Schedule\" link above to edit a master schedule crew.</p>";
} else {
    if (retrieve_dbMasterSchedule($group . $day . $week_no) == false) {
        $result = process_set_times($_POST, $group, $day, $week_no);
        if ($result) {
            $returnpoint = "viewSchedule.php?group=" . $group;
            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 "<table align=\"center\" width=\"450\"><tr><td align=\"center\" colspan=\"2\"><b>\n\t\t\t\t\t\t\t\tAdding a New Master Schedule crew for " . $do_group_name($group) . ", " . do_week_name($week_no) . " " . do_day_name($day) . " " . "</b></td></tr>" . "<tr><td>\n\t\t\t\t\t\t\t\t\t<form method=\"POST\" style=\"margin-bottom:0;\">\n\t\t\t\t\t\t\t\t\t<select name=\"new_slots\">\n\t\t\t\t\t\t\t\t\t<option value=\"0\">Please select the number of slots for this crew</option>" . slots_select() . "</select><br>\n\t\t\t\t\t\t\t\t\t<br><br>\n\t\t\t\t\t\t\t\t\t<input type=\"hidden\" name=\"_submit_change_times\" value=\"1\">\n\t\t\t\t\t\t\t\t\t<input type=\"submit\" value=\"Add New Crew\" name=\"submit\">\n\t\t\t\t\t\t\t\t\t</form><br></td></tr></table>";
        }
    } else {
        // if one is there, see what we can do to update it
        if (!process_fill_vacancy($_POST, $group, $day, $week_no) && !process_add_volunteer($_POST, $group, $day, $week_no) && !process_remove_crew($_POST, $group, $day, $week_no)) {
            // try to remove the crew
            if (process_unfill_crew($_POST, $group, $day, $week_no)) {
                // try to remove a person
            } else {
                if (process_add_slot($_POST, $group, $day, $week_no)) {
                    // try to add a new slot