Beispiel #1
0
 function check_input_errors($edit = array())
 {
     global $lr_session;
     $errors = array();
     if ($lr_session->has_permission('person', 'edit', $this->person->user_id, 'name')) {
         if (!validate_name_input($edit['firstname']) || !validate_name_input($edit['lastname'])) {
             $errors[] = "You can only use letters, numbers, spaces, and the characters - ' and . in first and last names";
         }
     }
     if ($lr_session->has_permission('person', 'edit', $this->person->user_id, 'username')) {
         if (!validate_name_input($edit['username'])) {
             $errors[] = "You can only use letters, numbers, spaces, and the characters - ' and . in usernames";
         }
         $user = Person::load(array('username' => $edit['username']));
         # TODO: BUG: need to check that $user->user_id != current id
         if ($user && !$lr_session->is_admin()) {
             $errors[] = "A user with that username already exists; please choose another";
         }
     }
     if (!validate_email_input($edit['email'])) {
         $errors[] = "You must supply a valid email address";
     }
     if (!validate_nonblank($edit['home_phone']) && !validate_nonblank($edit['work_phone']) && !validate_nonblank($edit['mobile_phone'])) {
         $errors[] = "You must supply at least one valid telephone number.  Please supply area code, number and (if any) extension.";
     }
     if (validate_nonblank($edit['home_phone']) && !validate_telephone_input($edit['home_phone'])) {
         $errors[] = "Home telephone number is not valid.  Please supply area code, number and (if any) extension.";
     }
     if (validate_nonblank($edit['work_phone']) && !validate_telephone_input($edit['work_phone'])) {
         $errors[] = "Work telephone number is not valid.  Please supply area code, number and (if any) extension.";
     }
     if (validate_nonblank($edit['mobile_phone']) && !validate_telephone_input($edit['mobile_phone'])) {
         $errors[] = "Mobile telephone number is not valid.  Please supply area code, number and (if any) extension.";
     }
     $address_errors = validate_address($edit['addr_street'], $edit['addr_city'], $edit['addr_prov'], $edit['addr_postalcode'], $edit['addr_country']);
     if (count($address_errors) > 0) {
         $errors = array_merge($errors, $address_errors);
     }
     if (!preg_match("/^[mf]/i", $edit['gender'])) {
         $errors[] = "You must select either male or female for gender.";
     }
     if (!validate_yyyymmdd_input($edit['birthdate'])) {
         $errors[] = "You must provide a valid birthdate";
     }
     if (validate_nonblank($edit['height'])) {
         if (!$lr_session->is_admin() && ($edit['height'] < 36 || $edit['height'] > 84)) {
             $errors[] = "Please enter a reasonable and valid value for your height.";
         }
     }
     if ($edit['skill_level'] < 1 || $edit['skill_level'] > 10) {
         $errors[] = "You must select a skill level between 1 and 10. You entered " . $edit['skill_level'];
     }
     $current = localtime(time(), 1);
     $this_year = $current['tm_year'] + 1900;
     if ($edit['year_started'] > $this_year) {
         $errors[] = "Year started must be before current year.";
     }
     if ($edit['year_started'] < 1986) {
         $errors[] = "Year started must be after 1986.  For the number of people who started playing before then, I don't think it matters if you're listed as having played 17 years or 20, you're still old. :)";
     }
     $birth_year = substr($edit['birthdate'], 0, 4);
     $yearDiff = $edit['year_started'] - $birth_year;
     if ($yearDiff < 8) {
         $errors[] = "You can't have started playing when you were {$yearDiff} years old!  Please correct your birthdate, or your starting year";
     }
     return $errors;
 }
// Include validate.php which contains functions for verifying the POST data.
include 'validate.php';
include 'database.php';
// Assign POST data
$first_name = $_POST['first_name'];
$last_name = $_POST['last_name'];
$address1 = $_POST['address1'];
$address2 = $_POST['address2'];
$city = $_POST['city'];
$state = $_POST['state'];
$zip = $_POST['zip'];
$country = $_POST['country'];
// Validate POST data
$b_is_first_name_valid = validate_string($first_name);
$b_is_last_name_valid = validate_string($last_name);
$b_is_address_valid = validate_address($address1, $address2);
$b_is_city_valid = validate_city($city);
$b_is_state_valid = validate_string($state);
$b_is_zip_valid = validate_zip($zip);
$b_is_country_valid = validate_string($country);
// Verify required fields have been populated with valid input.
if ($b_is_first_name_valid == true && $b_is_last_name_valid == true && $b_is_address_valid == true && $b_is_city_valid == true && $b_is_state_valid == true && $b_is_zip_valid == true && $b_is_country_valid == true) {
    // Create array of data to submit.
    $data = array('first_name' => $first_name, 'last_name' => $last_name, 'address1' => $address1, 'address2' => $address2, 'city' => $city, 'state' => $state, 'zip' => $zip, 'country' => $country);
    // Submit data to database.
    $b_rc = submit_to_database($data);
    if ($b_rc == true) {
        // Print html and body tags.
        echo "<html>\n";
        echo "<body>\n";
        // Show registration confirmation message.