/**
 * process_form sanitizes data, concatenates needed data, and enters it all into a database
 */
function process_form($id)
{
    //echo($_POST['first_name']);
    //step one: sanitize data by replacing HTML entities and escaping the ' character
    $first_name = trim(str_replace('\\\'', '', htmlentities(str_replace('&', 'and', $_POST['first_name']))));
    //    $first_name = str_replace(' ', '_', $first_name);
    $last_name = trim(str_replace('\\\'', '\'', htmlentities($_POST['last_name'])));
    if ($_POST['DateOfBirth_Year'] == "") {
        $birthday = $_POST['DateOfBirth_Month'] . '-' . $_POST['DateOfBirth_Day'] . '-XX';
    } else {
        $birthday = $_POST['DateOfBirth_Month'] . '-' . $_POST['DateOfBirth_Day'] . '-' . $_POST['DateOfBirth_Year'];
    }
    $gender = trim(htmlentities($_POST['gender']));
    $address = trim(str_replace('\\\'', '\'', htmlentities($_POST['address'])));
    $city = trim(str_replace('\\\'', '\'', htmlentities($_POST['city'])));
    $state = trim(htmlentities($_POST['state']));
    $zip = trim(htmlentities($_POST['zip']));
    $county = trim(htmlentities($_POST['county']));
    $phone1 = trim(str_replace(' ', '', htmlentities($_POST['phone1'])));
    $clean_phone1 = ereg_replace("[^0-9]", "", $phone1);
    $phone2 = trim(str_replace(' ', '', htmlentities($_POST['phone2'])));
    $clean_phone2 = ereg_replace("[^0-9]", "", $phone2);
    $email = $_POST['email'];
    $contact_preference = $_POST['contact_preference'];
    $dateAdded = $_POST['dateadded'];
    //Edited out by James Loeffler because these are not included in the new person.php
    /* $contact_preference = $_POST['contact_preference'];
                      $emergency_contact = $_POST['emergency_contact'];
                      $emergency_phone = trim(str_replace(' ', '', htmlentities($_POST['emergency_phone'])));
                      $clean_emergency_phone = ereg_replace("[^0-9]", "", $emergency_phone);
    
                      $screening_type = $_POST['screening_type'];
                      if ($screening_type!="") {
                      $screening = retrieve_dbApplicantScreenings($screening_type);
                      $step_array = $screening->get_steps();
                      $step_count = count($step_array);
                      $date_array = array();
                      for ($i = 0; $i < $step_count; $i++) {
                      $date_array[$i] = $_POST['ss_month'][$i] . '-' . $_POST['ss_day'][$i] . '-' . $_POST['ss_year'][$i];
                      if ($date_array[$i]!="--" && strlen($date_array[$i]) != 8) {
                      if (strlen($date_array[$i] != 2))
                      echo('<p>Date of completion for step: "' . $step_array[$i] . '" is in error, please select month, day <i>and</i> year.<br>');
                      $date_array[$i] = null;
                      }
                      }
    
                      }
                      $status = $_POST['status'];
                      $occupation = $_POST['occupation'];
                      $refs = $_POST['refs'];
    
                      $motivation = trim(str_replace('\\\'', '\'', htmlentities($_POST['motivation'])));
                      $specialties = trim(str_replace('\\\'', '\'', htmlentities($_POST['specialties']))); */
    $type = $_POST['type'];
    // added by James Loeffler
    $status = $_POST['status'];
    $schedule = $_POST['schedule'];
    //concatenate birthday and start_date strings
    /* if ($_POST['DateOfBirth_Year'] == "")
       $birthday = $_POST['DateOfBirth_Month'] . '-' . $_POST['DateOfBirth_Day'] . '-XX';
       else
       $birthday = $_POST['DateOfBirth_Month'] . '-' . $_POST['DateOfBirth_Day'] . '-' . $_POST['DateOfBirth_Year'];
       if (strlen($birthday) < 8)
       $birthday = '';
       $start_date = $_POST['DateOfStart_Month'] . '-' . $_POST['DateOfStart_Day'] . '-' . $_POST['DateOfStart_Year'];
       if (strlen($start_date) < 8)
       $start_date = ''; */
    $notes = trim(str_replace('\\\'', '\'', htmlentities($_POST['notes'])));
    $skills = trim(str_replace('\\\'', '\'', htmlentities($_POST['skills'])));
    $reason_interested = trim(str_replace('\\\'', '\'', htmlentities($_POST['reason_interested'])));
    //password here?
    if ($_POST['availability'] != null) {
        $availability = implode(',', $_POST['availability']);
    } else {
        $availability = "";
    }
    // these two are not visible for editing, so they go in and out unchanged
    //used for url path in linking user back to edit form
    $path = strrev(substr(strrev($_SERVER['SCRIPT_NAME']), strpos(strrev($_SERVER['SCRIPT_NAME']), '/')));
    //step two: try to make the deletion, password change, addition, or change
    if ($_POST['deleteMe'] == "DELETE") {
        $result = retrieve_person($id);
        if (!$result) {
            echo '<p>Unable to delete. ' . $first_name . ' ' . $last_name . ' is not in the database. <br>Please report this error to the House Manager.';
        } else {
            //What if they're the last remaining manager account?
            if (strpos($type, 'manager') !== false) {
                //They're a manager, we need to check that they can be deleted
                $managers = getall_type('manager');
                if (!$managers || mysql_num_rows($managers) <= 1) {
                    echo '<p class="error">You cannot remove the last remaining manager from the database.</p>';
                } else {
                    $result = remove_person($id);
                    echo "<p>You have successfully removed " . $first_name . " " . $last_name . " from the database.</p>";
                    if ($id == $_SESSION['_id']) {
                        session_unset();
                        session_destroy();
                    }
                }
            } else {
                $result = remove_person($id);
                echo "<p>You have successfully removed " . $first_name . " " . $last_name . " from the database.</p>";
                if ($id == $_SESSION['_id']) {
                    session_unset();
                    session_destroy();
                }
            }
        }
    } else {
        if ($_POST['reset_pass'] == "RESET") {
            $id = $_POST['old_id'];
            $result = remove_person($id);
            $pass = $first_name . $clean_phone1;
            //edited by James Loeffler
            $newperson = new Person($first_name, $last_name, $birthday, $gender, $address, $city, $state, $zip, $clean_phone1, $clean_phone2, $email, $type, $status, $schedule, $notes, $skills, $reason_interested, $dateAdded, md5($pass), $availability, $contact_preference);
            $result = add_person($newperson);
            if (!$result) {
                echo '<p class="error">Unable to reset ' . $first_name . ' ' . $last_name . "'s password.. <br>Please report this error to the House Manager.";
            } else {
                echo "<p>You have successfully reset " . $first_name . " " . $last_name . "'s password.</p>";
            }
        } else {
            if ($_POST['old_id'] == 'new') {
                $id = $first_name . $clean_phone1;
                //check if there's already an entry
                $dup = retrieve_person($id);
                if ($dup) {
                    echo '<p class="error">Unable to add ' . $first_name . ' ' . $last_name . ' to the database. <br>Another person with the same name and phone is already there.';
                } else {
                    //edited by James Loeffler
                    $newperson = new Person($first_name, $last_name, $birthday, $gender, $address, $city, $state, $zip, $clean_phone1, $clean_phone2, $email, $type, $status, $schedule, $notes, $skills, $reason_interested, $dateAdded, md5($pass), $availability, $contact_preference);
                    $result = add_person($newperson);
                    if (!$result) {
                        echo '<p class="error">Unable to add " .$first_name." ".$last_name. " in the database. <br>Please report this error to the House Manager.';
                    } else {
                        if ($_SESSION['access_level'] == 0) {
                            /*
                             $to      = '*****@*****.**';
                             $subject = 'Your Login!';
                             $message = 'Your Login ID id: XXXXXXXXXXXXX' . "\r\n"
                             'Your Login Password is: XXXXXXXXXXXXX';
                             $headers = 'From: webmaster@example.com' . "\r\n" .
                             'Reply-To: webmaster@example.com' . "\r\n" .
                             'X-Mailer: PHP/' . phpversion();
                            
                             mail($to, $subject, $message, $headers);
                            */
                            //this is a possible email function template that we can use
                            echo "<p>Your application has been successfully submitted.<br>  You will be recieving an email shortly with your ID and Password soon!";
                            error_log('The Email has been sent!');
                        } else {
                            echo "<p>You have successfully added " . $first_name . " " . $last_name . " to the database.</p>";
                        }
                    }
                }
            } else {
                $id = $_POST['old_id'];
                $pass = $_POST['old_pass'];
                $result = remove_person($id);
                if (!$result) {
                    echo '<p class="error">Unable to update ' . $first_name . ' ' . $last_name . '. <br>Please report this error to the House Manager.';
                } else {
                    //Edited by James Loeffler
                    $newperson = new Person($first_name, $last_name, $birthday, $gender, $address, $city, $state, $zip, $clean_phone1, $clean_phone2, $email, $type, $status, $schedule, $notes, $skills, $reason_interested, $dateAdded, md5($pass), $availability, $contact_preference);
                    $result = add_person($newperson);
                    if (!$result) {
                        echo '<p class="error">Unable to update ' . $first_name . ' ' . $last_name . '. <br>Please report this error to the House Manager.';
                    } else {
                        echo '<p>You have successfully edited <a href="' . $path . 'personEdit.php?id=' . $id . '"><b>' . $first_name . ' ' . $last_name . ' </b></a> in the database.</p>';
                    }
                    add_log_entry('<a href=\\"personEdit.php?id=' . $id . '\\">' . $first_name . ' ' . $last_name . '</a>\'s Personnel Edit Form has been changed.');
                }
            }
        }
    }
}
/**
 * process_form sanitizes data, concatenates needed data, and enters it all into a database
 */
function process_form($id)
{
    //echo($_POST['first_name']);
    //step one: sanitize data by replacing HTML entities and escaping the ' character
    if (substr($_POST['date'], 0, 2) == 20) {
        $eurodate = explode('-', $_POST['date']);
        $eurodate[0] = substr($eurodate[0], 2, 3);
        $swapdate = [$eurodate[1], $eurodate[2], $eurodate[0]];
        $amerdate = implode('/', $swapdate);
        $mm_dd_yy = $amerdate;
    } else {
        $mm_dd_yy = $_POST['date'];
    }
    error_log("In process form this is " . $mm_dd_yy);
    $address = $_POST['address'];
    //trim(str_replace('\\\'', '\'', htmlentities($_POST['address'])));
    $name = $_POST['name'];
    //trim(htmlentities($_POST['name']));
    $type = $_POST['project_type'];
    $start_time = $_POST['start_time'];
    //ereg_replace("[^0-9]", "", $_POST['start_time']);
    $end_time = $_POST['end_time'];
    //ereg_replace("[^0-9]", "", $_POST['end_time']);
    //$dayOfWeek = trim(htmlentities($_POST['dayOfWeek']));
    $vacancies = $_POST['vacancies'];
    //ereg_replace("[^0-9]", "", $_POST['vacancies']);
    //$persons = trim(htmlentities($_POST['persons']));_log("In process form this is ".$mm_dd_yy);
    $age = $_POST['age'];
    $id = $_POST['old_id'];
    //trim(htmlentities($_POST['old_id']));
    $project_description = $_POST['notes'];
    //trim(htmlentities($_POST['notes']));
    $path = strrev(substr(strrev($_SERVER['SCRIPT_NAME']), strpos(strrev($_SERVER['SCRIPT_NAME']), '/')));
    //step two: try to make the deletion, password change, addition, or change
    if ($_POST['deleteMe'] == "DELETE") {
        $result = select_dbProjects($id);
        if (!$result) {
            echo '<p>Unable to delete. ' . $mm_dd_yy . ' is not in the database. <br>Please report this error to the House Manager.';
        } else {
            //What if they're the last remaining manager account?
            if (strpos($type, 'manager') !== false) {
                //They're a manager, we need to check that they can be deleted
                $managers = getall_type('manager');
                if (!$managers || mysql_num_rows($managers) <= 1) {
                    echo '<p class="error">You cannot remove the last remaining manager from the database.</p>';
                } else {
                    $result = delete_dbProjects($id);
                    echo "<p>You have successfully removed " . mm_dd_yy . " from the database.</p>";
                    if ($id == $_SESSION['_id']) {
                        session_unset();
                        session_destroy();
                    }
                }
            } else {
                $result = delete_dbProjects($id);
                echo "<p>You have successfully removed " . $mm_dd_yy . " from the database.</p>";
                if ($id == $_SESSION['_id']) {
                    session_unset();
                    session_destroy();
                }
            }
        }
    }
    // try to add a new project to the database
    //else {
    if ($_POST['old_id'] == 'new') {
        $id = $mm_dd_yy;
        //check if there's already an entry
        $dup = select_dbProjects($id);
        if ($dup) {
            echo '<p class="error">Unable to add ' . $mm_dd_yy . ' to the database. <br>Another project with the same name is already there.';
        } else {
            $newproject = new Project($mm_dd_yy, $address, $type, $name, $start_time, $end_time, $vacancies, $persons, $age, $project_description);
            $result = insert_dbProjects($newproject);
            $db_date_format = str_replace("/", "-", $mm_dd_yy);
            $update = update_dbDates_projects($db_date_format);
            if (!$update) {
                delete_dbProjects($newproject);
                error_log("Project has not been added");
                echo "<p class='error'>The week of " . $mm_dd_yy . " must be added to the weekly calendar first. Select the Project Calendar tab and then choose Manage Weeks";
            } else {
                if ($_SESSION['access_level'] == 0) {
                    echo "<p>Your application has been successfully submitted.<br>  The House Manager will contact you soon.  Thank you!";
                } else {
                    echo "<p>You have successfully added " . $newproject->get_id() . " to the database.</p>";
                }
            }
        }
    } else {
        $id = $_POST['old_id'];
        $result = delete_dbProjects($id);
        if (!$result) {
            echo '<p class="error">Unable to update ' . $mm_dd_yy . '. <br>Please report this error to the House Manager.';
        } else {
            $newproject = new Project($mm_dd_yy, $address, $name, $start_time, $end_time, $vacancies, $persons, $project_description);
            echo '<p>You have successfully edited <a href="' . $path . 'projectEdit.php?id=' . $id . '"><b>' . $mm_dd_yy . ' </b></a> in the database.</p>';
        }
        add_log_entry('<a href=\\"projectEdit.php?id=' . $id . '\\">' . $mm_dd_yy . ' </a>\'s Project Edit Form has been changed.');
    }
}
예제 #3
0
/**
 * process_form sanitizes data, concatenates needed data, and enters it all into a database
 */
function process_form($id, $person)
{
    //echo($_POST['first_name']);
    //step one: sanitize data by replacing HTML entities and escaping the ' character
    if ($person->get_first_name() == "new") {
        $first_name = trim(str_replace('\\\'', '', htmlentities(str_replace('&', 'and', $_POST['first_name']))));
    } else {
        $first_name = $person->get_first_name();
    }
    $last_name = trim(str_replace('\\\'', '\'', htmlentities($_POST['last_name'])));
    $location = $_POST['location'];
    $address = trim(str_replace('\\\'', '\'', htmlentities($_POST['address'])));
    $city = trim(str_replace('\\\'', '\'', htmlentities($_POST['city'])));
    $state = trim(htmlentities($_POST['state']));
    $zip = trim(htmlentities($_POST['zip']));
    if ($person->get_first_name() == "new") {
        $phone1 = trim(str_replace(' ', '', htmlentities($_POST['phone1'])));
        $clean_phone1 = preg_replace("/[^0-9]/", "", $phone1);
        $phone1type = $_POST['phone1type'];
    } else {
        $clean_phone1 = $person->get_phone1();
        $phone1type = $person->get_phone1type();
    }
    $phone2 = trim(str_replace(' ', '', htmlentities($_POST['phone2'])));
    $clean_phone2 = preg_replace("/[^0-9]/", "", $phone2);
    $phone2type = $_POST['phone2type'];
    $email = $_POST['email'];
    $type = implode(',', $_POST['type']);
    $screening_type = $_POST['screening_type'];
    if ($screening_type != "") {
        $screening = retrieve_dbApplicantScreenings($screening_type);
        $step_array = $screening->get_steps();
        $step_count = count($step_array);
        $date_array = array();
        for ($i = 0; $i < $step_count; $i++) {
            $date_array[$i] = $_POST['screening_status'][$i];
            if ($date_array[$i] != "" && $date_array[$i] != "--" && strlen($date_array[$i]) != 8) {
                echo '<p>Completion Date for step: "' . $step_array[$i] . '" is in error, please enter mm-dd-yy.<br>';
            }
        }
        $screening_status = implode(',', $date_array);
    }
    $status = $_POST['status'];
    if ($_POST['isstudent'] == "yes") {
        $position = "student";
        $employer = $_POST['nameofschool'];
    } else {
        $position = $_POST['position'];
        $employer = $_POST['employer'];
    }
    $credithours = $_POST['credithours'];
    $motivation = trim(str_replace('\\\'', '\'', htmlentities($_POST['motivation'])));
    $specialties = trim(str_replace('\\\'', '\'', htmlentities($_POST['specialties'])));
    $convictions = $_POST['convictions'];
    if (!$_POST['availability']) {
        $availability = null;
    } else {
        $availability = implode(',', $_POST['availability']);
    }
    // these two are not visible for editing, so they go in and out unchanged
    $schedule = $_POST['schedule'];
    $hours = $_POST['hours'];
    $birthday = $_POST['birthday'];
    $start_date = $_POST['start_date'];
    $howdidyouhear = $_POST['howdidyouhear'];
    $notes = trim(str_replace('\\\'', '\'', htmlentities($_POST['notes'])));
    //used for url path in linking user back to edit form
    $path = strrev(substr(strrev($_SERVER['SCRIPT_NAME']), strpos(strrev($_SERVER['SCRIPT_NAME']), '/')));
    //step two: try to make the deletion, password change, addition, or change
    if ($_POST['deleteMe'] == "DELETE") {
        $result = retrieve_person($id);
        if (!$result) {
            echo '<p>Unable to delete. ' . $first_name . ' ' . $last_name . ' is not in the database. <br>Please report this error to the House Manager.';
        } else {
            //What if they're the last remaining manager account?
            if (strpos($type, 'manager') !== false) {
                //They're a manager, we need to check that they can be deleted
                $managers = getall_type('manager');
                if (!$managers || mysql_num_rows($managers) <= 1) {
                    echo '<p class="error">You cannot remove the last remaining manager from the database.</p>';
                } else {
                    $result = remove_person($id);
                    echo "<p>You have successfully removed " . $first_name . " " . $last_name . " from the database.</p>";
                    if ($id == $_SESSION['_id']) {
                        session_unset();
                        session_destroy();
                    }
                }
            } else {
                $result = remove_person($id);
                echo "<p>You have successfully removed " . $first_name . " " . $last_name . " from the database.</p>";
                if ($id == $_SESSION['_id']) {
                    session_unset();
                    session_destroy();
                }
            }
        }
    } else {
        if ($_POST['reset_pass'] == "RESET") {
            $id = $_POST['old_id'];
            $result = remove_person($id);
            $pass = $first_name . $clean_phone1;
            $newperson = new Person($first_name, $last_name, $location, $address, $city, $state, $zip, $clean_phone1, $phone1type, $clean_phone2, $phone2type, $email, $type, $screening_type, $screening_status, $status, $employer, $position, $credithours, $commitment, $motivation, $specialties, $convictions, $availability, $schedule, $hours, $birthday, $start_date, $howdidyouhear, $notes, "");
            $result = add_person($newperson);
            if (!$result) {
                echo '<p class="error">Unable to reset ' . $first_name . ' ' . $last_name . "'s password.. <br>Please report this error to the House Manager.";
            } else {
                echo "<p>You have successfully reset " . $first_name . " " . $last_name . "'s password.</p>";
            }
        } else {
            if ($_POST['old_id'] == 'new') {
                $id = $first_name . $clean_phone1;
                //check if there's already an entry
                $dup = retrieve_person($id);
                if ($dup) {
                    echo '<p class="error">Unable to add ' . $first_name . ' ' . $last_name . ' to the database. <br>Another person with the same name and phone is already there.';
                } else {
                    $newperson = new Person($first_name, $last_name, $location, $address, $city, $state, $zip, $clean_phone1, $phone1type, $clean_phone2, $phone2type, $email, $type, $screening_type, $screening_status, $status, $employer, $position, $credithours, $commitment, $motivation, $specialties, $convictions, $availability, $schedule, $hours, $birthday, $start_date, $howdidyouhear, $notes, "");
                    $result = add_person($newperson);
                    if (!$result) {
                        echo '<p class="error">Unable to add " .$first_name." ".$last_name. " in the database. <br>Please report this error to the House Manager.';
                    } else {
                        if ($_SESSION['access_level'] == 0) {
                            echo "<p>Your application has been successfully submitted.<br>  The House Manager will contact you soon.  Thank you!";
                        } else {
                            echo '<p>You have successfully added <a href="' . $path . 'personEdit.php?id=' . $id . '"><b>' . $first_name . ' ' . $last_name . ' </b></a> to the database.</p>';
                        }
                    }
                }
            } else {
                $id = $_POST['old_id'];
                $pass = $_POST['old_pass'];
                $result = remove_person($id);
                if (!$result) {
                    echo '<p class="error">Unable to update ' . $first_name . ' ' . $last_name . '. <br>Please report this error to the House Manager.';
                } else {
                    $newperson = new Person($first_name, $last_name, $location, $address, $city, $state, $zip, $clean_phone1, $phone1type, $clean_phone2, $phone2type, $email, $type, $screening_type, $screening_status, $status, $employer, $position, $credithours, $commitment, $motivation, $specialties, $convictions, $availability, $schedule, $hours, $birthday, $start_date, $howdidyouhear, $notes, $pass);
                    $result = add_person($newperson);
                    if (!$result) {
                        echo '<p class="error">Unable to update ' . $first_name . ' ' . $last_name . '. <br>Please report this error to the House Manager.';
                    } else {
                        echo '<p>You have successfully edited <a href="' . $path . 'personEdit.php?id=' . $id . '"><b>' . $first_name . ' ' . $last_name . ' </b></a> in the database.</p>';
                    }
                    add_log_entry('<a href=\\"personEdit.php?id=' . $id . '\\">' . $first_name . ' ' . $last_name . '</a>\'s Personnel Edit Form has been changed.');
                }
            }
        }
    }
}
/**
* process_form sanitizes data, concatenates needed data, and enters it all into the database
*/
function process_form($id, $person)
{
    // Get the info of the user who is making the update
    $user = retrieve_dbPersons($_SESSION['_id']);
    $name = $user->get_first_name() . " " . $user->get_last_name();
    $first_name = trim(str_replace("'", "\\'", htmlentities(str_replace('&', 'and', $_POST['first_name']))));
    $last_name = trim(str_replace("'", "\\'", htmlentities($_POST['last_name'])));
    $address = trim(str_replace("'", "\\'", htmlentities($_POST['address'])));
    $city = trim(str_replace("'", "\\'", htmlentities($_POST['city'])));
    $state = $_POST['state'];
    $zip = trim(htmlentities($_POST['zip']));
    $phone1 = trim(str_replace(' ', '', htmlentities($_POST['phone1'])));
    $clean_phone1 = ereg_replace("[^0-9]", "", $phone1);
    $phone2 = trim(str_replace(' ', '', htmlentities($_POST['phone2'])));
    $clean_phone2 = ereg_replace("[^0-9]", "", $phone2);
    $email = trim(str_replace("'", "\\'", htmlentities($_POST['email'])));
    $patient_name = trim(str_replace("'", "\\'", htmlentities($_POST['patient_name'])));
    $patient_birthdate = $_POST['DateOfBirth_Year'] . '-' . $_POST['DateOfBirth_Month'] . '-' . $_POST['DateOfBirth_Day'];
    $patient_relation = trim(str_replace('\\\'', '\'', htmlentities($_POST['patient_relation'])));
    $type = implode(',', $_POST['type']);
    $prior_bookings = implode(',', $person->get_prior_bookings());
    $newperson = new Person($last_name, $first_name, $address, $city, $state, $zip, $clean_phone1, $clean_phone2, $email, $type, $prior_bookings, $patient_name, $patient_birthdate, $patient_relation, "");
    if (!retrieve_dbPersons($newperson->get_id())) {
        insert_dbPersons($newperson);
        return $newperson;
    } else {
        if ($_POST['deleteMe'] != "DELETE" && $_POST['reset_pass'] != "RESET") {
            update_dbPersons($newperson);
            return $newperson;
        }
    }
    //step two: try to make the deletion or password change
    if ($_POST['deleteMe'] == "DELETE") {
        $result = retrieve_dbPersons($id);
        if (!$result) {
            echo '<p>Unable to delete. ' . $first_name . ' ' . $last_name . ' is not in the database. <br>Please report this error to the House Manager.';
        } else {
            //What if they're the last remaining manager account?
            if (strpos($type, 'manager') !== false) {
                //They're a manager, we need to check that they can be deleted
                $managers = getall_type('manager');
                if (!$managers || mysql_num_rows($managers) <= 1) {
                    echo '<p class="error">You cannot remove the last remaining manager from the database.</p>';
                } else {
                    $result = delete_dbPersons($id);
                    echo "<p>You have successfully removed " . $first_name . " " . $last_name . " from the database.</p>";
                    if ($id == $_SESSION['_id']) {
                        session_unset();
                        session_destroy();
                    }
                }
            } else {
                $result = delete_dbPersons($id);
                echo "<p>You have successfully removed " . $first_name . " " . $last_name . " from the database.</p>";
                if ($id == $_SESSION['_id']) {
                    session_unset();
                    session_destroy();
                }
            }
            // Create the log message
            $message = "<a href='viewPerson.php?id=" . $_SESSION['_id'] . "'>" . $name . "</a>" . " has removed " . $first_name . " " . $last_name . " from the database";
            add_log_entry($message);
        }
        return $person;
    } else {
        if ($_POST['reset_pass'] == "RESET") {
            $id = $_POST['old_id'];
            // $result = delete_dbPersons($id);
            // $pass = $first_name . $phone1;
            $person = new Person($last_name, $first_name, $address, $city, $state, $zip, $clean_phone1, $clean_phone2, $email, $type, implode(',', $person->get_prior_bookings()), $patient_name, $patient_birthdate, $patient_relation, "");
            $result = insert_dbPersons($person);
            if (!$result) {
                echo '<p class="error">Unable to reset ' . $first_name . ' ' . $last_name . "'s password.. <br>Please report this error to the House Manager.";
            } else {
                echo "<p>You have successfully reset " . $first_name . " " . $last_name . "'s password.</p>";
                // Create the log message
                $message = "<a href='viewPerson.php?id=" . $_SESSION['_id'] . "'>" . $name . "</a>" . " has reset the password for <a href='viewPerson.php?id=" . $id . "'>" . $first_name . " " . $last_name . "</a>";
                add_log_entry($message);
            }
            return $person;
        }
    }
}
/**
 * process_form sanitizes data, concatenates needed data, and enters it all into a database
 */
function process_form($id, $person)
{
    //echo($_POST['first_name']);
    //step one: sanitize data by replacing HTML entities and escaping the ' character
    if ($id == "new") {
        $first_name = trim(str_replace('\\\'', '', htmlentities(str_replace('&', 'and', $_POST['first_name']))));
    } else {
        $first_name = $person->get_first_name();
    }
    //    $first_name = str_replace(' ', '_', $first_name);
    $last_name = trim(str_replace('\\\'', '\'', htmlentities($_POST['last_name'])));
    $address = trim(str_replace('\\\'', '\'', htmlentities($_POST['address'])));
    $city = trim(str_replace('\\\'', '\'', htmlentities($_POST['city'])));
    $state = trim(htmlentities($_POST['state']));
    $zip = trim(htmlentities($_POST['zip']));
    if ($id == "new") {
        $phone1 = trim(str_replace(' ', '', htmlentities($_POST['phone1'])));
    } else {
        $phone1 = $person->get_phone1();
    }
    $clean_phone1 = mb_ereg_replace("[^0-9]", "", $phone1);
    $phone2 = trim(str_replace(' ', '', htmlentities($_POST['phone2'])));
    $clean_phone2 = mb_ereg_replace("[^0-9]", "", $phone2);
    $email = $_POST['email'];
    $type = implode(',', $_POST['type']);
    if ($_POST['group']) {
        $group = implode(',', $_POST['group']);
    } else {
        $group = "";
    }
    if ($_POST['role']) {
        $role = implode(' ', $_POST['role']);
    } else {
        $role = "";
    }
    $status = $_POST['status'];
    if ($_POST['availability'] != null) {
        $availability = implode(',', $_POST['availability']);
    } else {
        $availability = "";
    }
    // these two are not visible for editing, so they go in and out unchanged
    $schedule = $_POST['schedule'];
    //concatenate birthday and start_date strings
    if ($_POST['DateOfBirth_Year'] == "") {
        $birthday = $_POST['DateOfBirth_Month'] . '-' . $_POST['DateOfBirth_Day'] . '-XX';
    } else {
        $birthday = $_POST['DateOfBirth_Month'] . '-' . $_POST['DateOfBirth_Day'] . '-' . $_POST['DateOfBirth_Year'];
    }
    if (strlen($birthday) < 8) {
        $birthday = '';
    }
    $start_date = $_POST['DateOfStart_Month'] . '-' . $_POST['DateOfStart_Day'] . '-' . $_POST['DateOfStart_Year'];
    if (strlen($start_date) < 8) {
        $start_date = '';
    }
    $notes = trim(str_replace('\\\'', '\'', htmlentities($_POST['notes'])));
    //used for url path in linking user back to edit form
    $path = strrev(substr(strrev($_SERVER['SCRIPT_NAME']), strpos(strrev($_SERVER['SCRIPT_NAME']), '/')));
    //step two: try to make the deletion, password change, addition, or change
    if (@$_POST['deleteMe'] == "DELETE") {
        $result = retrieve_person($id);
        if (!$result) {
            echo '<p>Unable to delete. ' . $first_name . ' ' . $last_name . ' is not in the database. <br>Please report this error to the admin.';
        } else {
            //What if they're the last remaining manager account?
            if (strpos($type, 'manager') !== false) {
                //They're a manager, we need to check that they can be deleted
                $managers = getall_type('manager');
                if (!$managers || mysql_num_rows($managers) <= 1) {
                    echo '<p class="error">You cannot remove the last remaining manager from the database.</p>';
                } else {
                    $result = remove_person($id);
                    echo "<p>You have successfully removed " . $first_name . " " . $last_name . " from the database.</p>";
                    if ($id == $_SESSION['_id']) {
                        session_unset();
                        session_destroy();
                    }
                }
            } else {
                $result = remove_person($id);
                echo "<p>You have successfully removed " . $first_name . " " . $last_name . " from the database.</p>";
                if ($id == $_SESSION['_id']) {
                    session_unset();
                    session_destroy();
                }
            }
        }
    } else {
        if (@$_POST['reset_pass'] == "RESET") {
            $id = $_POST['old_id'];
            $result = remove_person($id);
            $pass = $first_name . $clean_phone1;
            $newperson = new Person($first_name, $last_name, $address, $city, $state, $zip, $clean_phone1, $clean_phone2, $email, $type, $group, $role, $status, $availability, $schedule, $birthday, $start_date, $notes, md5($pass));
            $result = add_person($newperson);
            if (!$result) {
                echo '<p class="error">Unable to reset ' . $first_name . ' ' . $last_name . "'s password.. <br>Please report this error to the Operations Manager.";
            } else {
                echo "<p>You have successfully reset " . $first_name . " " . $last_name . "'s password.</p>";
            }
        } else {
            if (@$_POST['old_id'] == 'new') {
                $id = $first_name . $clean_phone1;
                //check if there's already an entry
                $dup = retrieve_person($id);
                if ($dup) {
                    echo '<p class="error">Unable to add ' . $first_name . ' ' . $last_name . ' to the database. <br>Another person with the same name and phone is already there.';
                } else {
                    $pass = $_POST['old_pass'];
                    $newperson = new Person($first_name, $last_name, $address, $city, $state, $zip, $clean_phone1, $clean_phone2, $email, $type, $group, $role, $status, $availability, $schedule, $birthday, $start_date, $notes, md5($pass));
                    $result = add_person($newperson);
                    if (!$result) {
                        echo '<p class="error">Unable to add " .$first_name." ".$last_name. " in the database. <br>Please report this error to the Operations Manager.';
                    } else {
                        if ($_SESSION['access_level'] == 0) {
                            echo "<p>Your application has been successfully submitted.<br>  An MCHPP staff member will contact you soon.  Thank you!";
                        } else {
                            echo "<p>You have successfully added " . $first_name . " " . $last_name . " to the database.</p>";
                        }
                    }
                }
            } else {
                $id = $_POST['old_id'];
                $pass = $_POST['old_pass'];
                $result = remove_person($id);
                if (!$result) {
                    echo '<p class="error">Unable to update ' . $first_name . ' ' . $last_name . '. <br>Please report this error to the Operations Manager.';
                } else {
                    $newperson = new Person($first_name, $last_name, $address, $city, $state, $zip, $clean_phone1, $clean_phone2, $email, $type, $group, $role, $status, $availability, $schedule, $birthday, $start_date, $notes, md5($pass));
                    $result = add_person($newperson);
                    if (!$result) {
                        echo '<p class="error">Unable to update ' . $first_name . ' ' . $last_name . '. <br>Please report this error to the Operations Manager.';
                    } else {
                        echo '<p>You have successfully edited <a href="' . $path . 'personEdit.php?id=' . $id . '"><b>' . $first_name . ' ' . $last_name . ' </b></a> in the database.</p>';
                    }
                    add_log_entry('<a href=\\"personEdit.php?id=' . $id . '\\">' . $first_name . ' ' . $last_name . '</a>\'s Personnel Edit Form has been changed.');
                }
            }
        }
    }
}