include 'header.php';
?>
    <div id="content">
        <?php 
$shiftid = $_GET['shift'];
$venue = $_GET['venue'];
include_once 'editShift.inc';
if ($shiftid == "") {
    echo "<p>No Shift ID Supplied.  Click on \"Calendar\" above to edit shifts.</p>";
} else {
    $shift = select_dbShifts($shiftid);
    if (!$shift instanceof Shift) {
        echo "<p>Invalid Shift ID Supplied.  Click on \"Calendar\" above to edit shifts.</p>";
    } else {
        if (!process_fill_vacancy($_POST, $shift, $venue) && !process_add_volunteer($_POST, $shift, $venue) && !process_move_shift($_POST, $shift) && !process_change_times($_POST, $shift)) {
            if (process_unfill_shift($_POST, $shift, $venue)) {
                $shift = select_dbShifts($shiftid);
            } else {
                if (process_add_slot($_POST, $shift, $venue)) {
                    $shift = select_dbShifts($shiftid);
                } else {
                    if (process_clear_shift($_POST, $shift, $venue)) {
                        $shift = select_dbShifts($shiftid);
                    } else {
                        if (process_ignore_slot($_POST, $shift, $venue)) {
                            $shift = select_dbShifts($shiftid);
                        }
                    }
                }
            }
            $persons = $shift->get_persons();
$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());
        // $groupdisplay = $venue . " Group ".$group;