function testdbApplicantScreeningsModule()
 {
     //create empty dbApplicantScreenings table
     //$this->assertTrue(create_dbApplicantScreenings());
     // create several applicant screening objects to add to table
     $screening1 = new ApplicantScreening("guestchef", "Gabrielle1111234567", "complete application,background check,complete interview", "unpublished");
     $screening2 = new ApplicantScreening("volunteer", "Jackson6269170632", "complete interview", "published");
     $screening3 = new ApplicantScreening("manager", "Jill2075556666", null, null);
     $screening4 = new ApplicantScreening("socialworker", "Jackson6269170632", null, "unpublished");
     $this->assertTrue(insert_dbApplicantScreenings($screening1));
     $this->assertTrue(insert_dbApplicantScreenings($screening2));
     $this->assertTrue(insert_dbApplicantScreenings($screening3));
     $this->assertTrue(insert_dbApplicantScreenings($screening4));
     //tests the retrieve function
     $this->assertEqual(retrieve_dbApplicantScreenings($screening1->get_type())->get_type(), "guestchef");
     $this->assertEqual(retrieve_dbApplicantScreenings($screening1->get_type())->get_creator(), "Gabrielle1111234567");
     $this->assertEqual(retrieve_dbApplicantScreenings($screening1->get_type())->get_steps(), array("complete application", "background check", "complete interview"));
     $this->assertEqual(retrieve_dbApplicantScreenings($screening1->get_type())->get_status(), "unpublished");
     //tests the update function
     $screening1->set_status("published");
     $this->assertTrue(update_dbApplicantScreenings($screening1));
     $this->assertEqual(retrieve_dbApplicantScreenings($screening1->get_type())->get_status(), "published");
     // tests get_all function
     $allscreenings = getall_ApplicantScreenings();
     $this->assertTrue($allscreenings);
     // tests delete function
     $this->assertTrue(delete_dbApplicantScreenings($screening1->get_type()));
     $this->assertTrue(delete_dbApplicantScreenings($screening2->get_type()));
     $this->assertTrue(delete_dbApplicantScreenings($screening3->get_type()));
     $this->assertTrue(delete_dbApplicantScreenings($screening4->get_type()));
     echo "testdbApplicantScreenings complete";
 }
function update_dbApplicantScreenings($screening)
{
    if (!$screening instanceof ApplicantScreening) {
        error_log("Invalid argument for update_dbApplicantScreenings function call");
        return false;
    }
    if (delete_dbApplicantScreenings($screening->get_type())) {
        return insert_dbApplicantScreenings($screening);
    } else {
        error_log(mysql_error() . "unable to update DBAPPLICANTSCREENINGS table: " . $screening->get_type());
        return false;
    }
}
function update_dbApplicantScreenings($screening)
{
    if (!$screening instanceof ApplicantScreening) {
        echo "Invalid argument for update_dbApplicantScreenings function call";
        return false;
    }
    if (delete_dbApplicantScreenings($screening->get_type())) {
        return insert_dbApplicantScreenings($screening);
    } else {
        echo mysql_error() . "unable to update dbApplicantScreenings table: " . $screening->get_type();
        return false;
    }
}
/**
 * process_form gathers data and enters it into a database
 */
function process_form($oldScreening)
{
    //step one: gather data.
    $oldType = $_POST['_old_type'];
    if ($_POST['_form_type'] == "new") {
        $creator = $_SESSION['_id'];
    } else {
        $creator = $oldScreening->get_creator();
    }
    $steps = [];
    // reset steps array
    if (isset($_POST['steps'])) {
        foreach ($_POST['steps'] as $step) {
            $steps[] = $step;
        }
    } else {
        $steps = $oldScreening->get_steps();
    }
    $type = $_POST['new_type'];
    foreach ($steps as $key => $value) {
        if (empty($value)) {
            unset($steps[$key]);
        }
    }
    $steps = implode(',', $steps);
    // set published variable
    if ($_POST['Status'] == "published") {
        $newstatus = "published";
    } else {
        $newstatus = "unpublished";
    }
    $status = $newstatus;
    if (empty($type)) {
        $type = $oldType;
        // keeps "new" screening free from predefined steps and status
        if ($type == "new") {
            $steps = null;
            $status = "unpublished";
        }
    }
    //used to put together url for return to screenings link
    $path = strrev(substr(strrev($_SERVER['SCRIPT_NAME']), strpos(strrev($_SERVER['SCRIPT_NAME']), '/')));
    //step two: try to delete, add new, or replace
    if ($_POST['deleteMe'] == "DELETE") {
        $result = retrieve_dbApplicantScreenings($type);
        if (!$result) {
            echo '<p>Unable to delete. ' . $type . ' is not in the screenings database. To delete ' . $oldType . ',
 				try to delete again but do not rename screening type.';
        } else {
            $result = delete_dbApplicantScreenings($type);
            echo "<p>You have successfully removed " . $type . " from the screnings database.</p>";
            echo '<p><a href="' . $path . 'viewScreenings.php?type=' . $type . '"><b>click here</b> to 
				return to applicant screenings.</a><br><br></p>';
            add_log_entry('ApplicantScreening type <a href=\\"viewScreenings.php?type=' . $type . '\\">' . $type . '</a>\'
				 has been deleted.');
        }
    } else {
        if ($_POST['_form_type'] == "new") {
            if ($_POST['$type_s']) {
                $dup = retrieve_dbApplicantScreenings($type);
            }
            if ($dup) {
                echo '<p class="error">Unable to add new screening type: ' . $type . ' to the screenings database. <br>
				Another screening with the same type is already there.';
            } else {
                $screening = new ApplicantScreening($type, $creator, $steps, $status);
                $result = insert_dbApplicantScreenings($screening);
                if (!$result) {
                    echo '<p class="error">Unable to add ' . $type . ' in the screenings database. <br>
           			Please report this error to the House Manager.';
                } else {
                    echo "<p>You have successfully added '{$type}' to the screenings database.</p>";
                }
                echo '<p>click <a href="' . $path . 'viewScreenings.php?type=' . $type . '">here</a> to
				return to applicant screenings.<br><br></p>';
                add_log_entry('ApplicantScreening process <a href=\\"viewScreenings.php?type=' . $type . '\\">' . $type . '</a>\'
				 has been added.');
            }
        } else {
            $result = delete_dbApplicantScreenings($oldType);
            if (!$result) {
                echo '<p class="error">Unable to update ' . $oldType . ' as ' . $type;
            } else {
                $newscreening = new ApplicantScreening($type, $creator, $steps, $status);
                $result = insert_dbApplicantScreenings($newscreening);
                if (!$result) {
                    echo '<p class="error">Unable to update ' . $type . ' in the screenings database. <br>
           			Please report this error to the House Manager.';
                } else {
                    echo '<p>You have successfully edited "' . $type . '" in the screenings database.</p>';
                }
                echo '<p><a href="' . $path . 'viewScreenings.php?type=' . $type . '"><b>click here</b> to
				return to applicant screenings.</a><br><br></p>';
                add_log_entry('ApplicantScreening process <a href=\\"viewScreenings.php?type=' . $type . '\\">' . $type . '</a>\'
				 has been changed.');
            }
        }
    }
    //if (retrieve_dbApplicantScreenings("new")!= null)
    //	delete_dbApplicantScreenings("new");
}