<?php 
$projectid = $_GET['project'];
$venue = $_GET['venue'];
include_once 'editProject.inc';
if ($projectid == "") {
    echo "<p>No Project ID Supplied.  Click on \"Calendar\" above to edit projects.</p>";
} else {
    $project = select_dbProjects($projectid);
    if (!$project instanceof Project) {
        echo "<p>Invalid Project ID Supplied.  Click on \"Calendar\" above to edit projects.</p>";
    } else {
        if (!process_fill_vacancy($_POST, $project, $venue) && !process_add_volunteer($_POST, $project, $venue) && !process_move_project($_POST, $project) && !process_change_times($_POST, $project)) {
            if (process_unfill_project($_POST, $project, $venue)) {
                $project = select_dbProjects($projectid);
            } else {
                if (process_add_slot($_POST, $project, $venue)) {
                    $project = select_dbProjects($projectid);
                } else {
                    if (process_clear_project($_POST, $project, $venue)) {
                        $project = select_dbProjects($projectid);
                    } else {
                        if (process_ignore_slot($_POST, $project, $venue)) {
                            $project = select_dbProjects($projectid);
                        }
                    }
                }
            }
            $persons = $project->get_persons();
            echo "<br><br><table align=\"center\" border=\"1px\"><tr><td align=\"center\" colspan=\"2\"><b>" . get_project_name_from_id($projectid) . "</b></td></tr>";
            if ($_SESSION['access_level'] >= 2) {
                echo "<tr><td valign=\"top\"><br>&nbsp;" . do_slot_num($persons, $project > num_vacancies()) . "</td><td>";
        <?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();
            echo "<br><br><table align=\"center\" border=\"1px\"><tr><td align=\"center\" colspan=\"2\"><b>" . get_shift_name_from_id($shiftid) . "</b></td></tr>";
            if ($_SESSION['access_level'] >= 2) {
                echo "<tr><td valign=\"top\"><br>&nbsp;" . do_slot_num($persons, $shift->num_vacancies()) . "</td><td>";
$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;
        echo "<table align=\"center\" width=\"450\"><tr><td align=\"center\" colspan=\"2\"><b>" . $msentry->get_name() . "</b>\n\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<input type=\"hidden\" name=\"_submit_remove_shift\" value=\"1\"><br>\n\t\t\t\t\t\t\t\t\t<input type=\"submit\" value=\"Remove Entire Shift\"\n\t\t\t\t\t\t\t\t\tname=\"submit\">\n\t\t\t\t\t\t\t\t\t</form><br>\n\t\t\t\t\t\t\t\t</td></tr>" . "<tr><td valign=\"top\"><br>&nbsp;" . do_slot_num($msentry) . "</td><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<input type=\"hidden\" name=\"_submit_add_slot\" value=\"1\"><br>\n\t\t\t\t\t\t\t\t\t<input type=\"submit\" value=\"Add Slot\"\n\t\t\t\t\t\t\t\t\tname=\"submit\" style=\"width: 250px\">\n\t\t\t\t\t\t\t\t\t</form><br></td></tr>";
        echo display_filled_slots($persons) . display_vacant_slots($msentry->get_slots() - count($persons)) . "</table>";
        $returnpoint = "viewSchedule.php?venue=" . $venue;
include_once 'database/dbLog.php';
include_once 'editCrew.inc';
$crewid = $_GET['id'];
$group = substr($crewid, 9);
if ($crewid == "") {
    echo "<p>No Crew ID Supplied.  Click on \"Calendar\" above to edit crews.</p>";
} else {
    $crew = select_dbCrews($crewid);
    if (!$crew instanceof Crew) {
        echo "<p>Invalid Crew ID Supplied.  Click on \"Calendar\" above to edit crews.</p>";
    } else {
        if (!process_fill_vacancy($_POST, $crew, $group) && !process_add_volunteer($_POST, $crew, $group)) {
            if (process_unfill_crew($_POST, $crew, $group)) {
                $crew = select_dbCrews($crewid);
            } else {
                if (process_add_slot($_POST, $crew, $group)) {
                    $crew = select_dbCrews($crewid);
                } else {
                    if (process_clear_crew($_POST, $crew, $group)) {
                        $crew = select_dbCrews($crewid);
                    } else {
                        if (process_ignore_slot($_POST, $crew, $group)) {
                            $crew = select_dbCrews($crewid);
                        }
                    }
                }
            }
            $persons = $crew->get_persons();
            echo "<br><br><table align=\"center\" border=\"1px\"><tr><td align=\"center\" colspan=\"3\"><b>" . get_crew_name_from_id($crewid) . "</b></td><td></td></tr>";
            echo "<tr><td valign=\"top\"><br>&nbsp;" . do_slot_num($crew->get_slots()) . "</td><td>";
            if ($_SESSION['access_level'] == 2) {
 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
             } else {
                 if (process_ignore_slot($_POST, $group, $day, $week_no)) {
                     //try to remove a slot
                 }
             }
         }
         // we've tried to clear the crew, add a slot, or remove a slot;
         // so now display the crew again.
         $persons = get_persons($group, $day, $week_no);
         echo "<br><table align=\"center\" width=\"450\" border=\"1px\"><tr><td align=\"center\" colspan=\"2\"><b>\n\t\t\t\t\t\t\t\tEditing master schedule crew for " . do_group_name($group) . "<br>" . do_week_name($week_no) . " " . do_day_name($day) . "\n\t\t\t\t\t\t\t\t</b>\n\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<input type=\"hidden\" name=\"_submit_remove_crew\" value=\"1\"><br>\n\t\t\t\t\t\t\t\t\t<input type=\"submit\" value=\"Remove Entire Crew\"\n\t\t\t\t\t\t\t\t\tname=\"submit\">\n\t\t\t\t\t\t\t\t\t</form>\n\t\t\t\t\t\t\t\t</td></tr>" . "<tr><td valign=\"top\"><br>&nbsp;" . do_slot_num($group, $day, $week_no) . "</td><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<input type=\"hidden\" name=\"_submit_add_slot\" value=\"1\"><br>\n\t\t\t\t\t\t\t\t\t<input type=\"submit\" value=\"Add Slot\"\n\t\t\t\t\t\t\t\t\tname=\"submit\" style=\"width: 250px\">\n\t\t\t\t\t\t\t\t\t</form></td></tr>";
         echo display_filled_slots($persons) . display_vacant_slots(get_total_vacancies($group, $day, $week_no)) . "</table>";
         $returnpoint = "viewSchedule.php?group=" . $group;
         echo "<table align=\"center\"><tr><td align=\"center\" width=\"442\">\n\t\t\t\t\t\t\t\t\t       <br><a href=\"" . $returnpoint . "\">\n\t\t\t\t\t\t\t\t\t\t   Back to Master Schedule</a></td></tr></table>";
     }