contactId = $contactId; print "FOO:"; print_r( $foo ); print "BAR"; $post->healthPostId = $foo['id']; dbClose($db); return $post; } public static function fetch( $id ) { $db = dbConnect(); $post = new healthPost(); $query = "SELECT * FROM healthPosts WHERE id= $id;"; $result = mysqli_query($db,$query) or die('Query failed: '. $query .mysqli_error($db)); $foo = mysqli_fetch_assoc( $result ); $post->contactInfoId = $foo['contactInfoId']; $post->healthPostId = $foo['id']; $post->birthDate = $foo['birthDate']; $post->arrivalId = $foo['arrivalId']; $post->contactInfo = rpContactInfo::fetch( $post->contactInfoId ); dbClose($db); return $post; } function __construct( ) { } function saveFromInput( &$errors ) { //save contact info $this->contactInfo = new rpContactInfo(); $retVal = $this->contactInfo->saveFromInput( $errors ); $this->numPeople = getRequestVar( 'numPeople' ); if( $this->numPeople < 1 || $this->numPeople > 12 ) $this->numPeople = 0; if( $this->numPeople == 0 ) { $errors['numPeople'] = "Please select the number of people in your household"; } $this->income = intval(getRequestVar( 'income' )); if( $this->income < 1 || $this->income > 1000000 ) $this->income = 0; if( $this->income == 0 ) { $errors['income'] = "Please select your household income"; } /* $this->heightInches = intval(getRequestVar( 'heightFeet' )) * 12 + intval(getRequestVar( 'heightInches' )); if( $this->heightInches < 36 || $this->heightInches > 96 ) $this->heightInches = 0; if( $this->heightInches == 0 ) { $errors['heightFeet'] = "Please enter a valid height"; } $this->weightPounds = intval(getRequestVar( 'weight' )); if( $this->weightPounds < 50 || $this->weightPounds > 700 ) $this->weightPounds = 0; if( $this->weightPounds == 0 ) { $errors['weight'] = "Please enter a valid weight"; } */ $this->heightInches = 68; $this->weightPounds = 160; $birthYear = getRequestVar( 'birthYear'); $birthMonth = getRequestVar( 'birthMonth' ); $birthDate = getRequestVar( 'birthDate' ); if( !checkdate( $birthMonth,$birthDate,$birthYear) ) { $errors['birthMonth'] = "Please enter a valid birthdate"; } $this->birthDate = "$birthYear-$birthMonth-$birthDate"; if( !$retVal || !empty( $errors ) || !empty( $errorFields ) ) return false; $this->contactInfoId = $this->contactInfo->getId(); $arrival = new rpArrival(); $this->arrivalId = $arrival->getUserId(); $db = dbConnect(); // add code to set other fields $query = "INSERT INTO healthPosts (contactInfoId,numPeople,income,heightInches,weightPounds,birthDate,arrivalId) VALUES( {$this->contactInfoId},{$this->numPeople},{$this->income},{$this->heightInches},{$this->weightPounds},'{$this->birthDate}','{$this->arrivalId}');"; $result = mysqli_query($db,$query) or die('Query failed: '. $query .mysqli_error($db)); $this->healthPostId = mysqli_insert_id($db); return true; } function post() { $buyer = new datalotHealth(); $result =$buyer->sendMessage( $this->contactInfo, $this ); libxml_use_internal_errors(true); $xmlResponse = simplexml_load_string( $result ); libxml_use_internal_errors(false); $postResponse = new healthPostResponse( $this->getId(), $xmlResponse); if( $postResponse==null ) error_log( "Empty post response" ); return $postResponse; } function getContactInfo() { return $this->contactInfo; } function getId() { return $this->healthPostId; } function getBirthYear() { $parts = explode( '-',$this->birthDate ); return $parts[0]; } function getBirthMonth() { $parts = explode( '-',$this->birthDate ); return $parts[1]; } function getBirthDate() { $parts = explode( '-',$this->birthDate ); return $parts[2]; } function getAge() { return date_diff(date_create($this->birthDate), date_create('today'))->y; } function getHeightInchesPart() { return $this->heightInches % 12; } function getHeightFeetPart() { return floor($this->heightInches / 12); } function getWeight() { return $this->weightPounds; } function getNumPeople() { return $this->numPeople; } function getIncome() { return $this->income; } } ?> $maxLength ) { $errors[$key]=$errorMessage; return null; } //ugly special case if( $key == 'email' ) { $goodEmail = filter_var( $input, FILTER_VALIDATE_EMAIL ); if( !$goodEmail ) { $newInput = strtr( $input, ',', '.' ); $goodEmail = filter_var( $newInput, FILTER_VALIDATE_EMAIL ); if( $goodEmail ) { $_REQUEST[$key] = $newInput; } else { $errors[$key]=$errorMessage; return null; } } } else if( $key =='zip' ) { $goodZip = preg_match( "/^[0-9]{5}$/", $input ); if( !$goodZip ) { $errors[$key]=$errorMessage; return null; } } return $input; } ?>