session_start();
$acyear = date('Y');
$acyear++;
$states = array ( "AL"=>"Alabama", "AK"=>"Alaska", "AZ"=>"Arizona", "AR"=>"Arkansas", "CA"=>"California", "CO"=>"Colorado",
"CT"=>"Connecticut", "DE"=>"Delaware", "DC"=>"District of Columbia", "FL"=>"Florida", "GA"=>"Georgia",
"HI"=>"Hawaii", "ID"=>"Idaho", "IL"=>"Illinois", "IN"=>"Indiana", "IA"=>"Iowa", "KS"=>"Kansas", "KY"=>"Kentucky",
"LA"=>"Louisiana", "ME"=>"Maine", "MD"=>"Maryland", "MA"=>"Massachusetts", "MI"=>"Michigan", "MN"=>"Minnesota",
"MS"=>"Mississippi", "MO"=>"Missouri", "MT"=>"Montana", "NE"=>"Nebraska", "NV"=>"Nevada", "NH"=>"New Hampshire",
"NJ"=>"New Jersey", "NM"=>"New Mexico", "NY"=>"New York", "NC"=>"North Carolina", "ND"=>"North Dakota", "OH"=>"Ohio",
"OK"=>"Oklahoma", "OR"=>"Oregon", "PA"=>"Pennsylvania", "RI"=>"Rhode Island", "SC"=>"South Carolina", "SD"=>"South Dakota",
"TN"=>"Tennessee", "TX"=>"Texas", "UT"=>"Utah", "VT"=>"Vermont", "VA"=>"Virginia", "WA"=>"Washington",
"WV"=>"West Virginia", "WI"=>"Wisconsin", "WY"=>"Wyoming", "Other"=>"Other" );
$found = array ( "1"=>"Your Advisor", "2"=>"Electronic Announcement or Web site", "3"=>"Career Planning/Job Placement",
"4"=>"College or department staff member", "5"=>"Friend or previous REU student", "6"=>"Announcement on a bulletin board",
"7"=>"Scientific journal or other publication", "8"=>"Other");
$clevel = array ( "1"=>"Freshman (Year 1 of 4)", "2"=>"Sophmore (Year 2 of 4)", "3"=>"Junior (Year 3 of 4, or 4 of 5)" );
$cityz = array ( "citizen"=>"United States Citizen", "resident"=>"Permanent Resident of the United States" );
$transcripts = array( 'college', 'major', 'from', 'to', 'degree', 'degreeDate' ) ;
$references = array( 'ref', 'refCollege', 'refDept', 'refPhone', 'refEmail' ) ;
$employment = array( 'jobDateFrom', 'jobDateTo', 'employerName', 'employerAddress', 'jobTitle', 'duties' ) ;
$astroFields = array( 'galactic', 'extragalactic', 'planetary', 'stellar', 'other' ) ;
$workFields = array( 'computational', 'instrumentation', 'observational', 'theoretical' ) ;
$transDates = array( 'from', 'to', 'degreeDate' ) ;
$jobsDates = array( 'jobDateFrom', 'jobDateTo' ) ;
$maxNumTranscripts = 5 ;
$minNumTranscripts = 1 ;
$maxNumRefs = 3 ;
$minNumRefs = 2 ;
$minNumAstroFields = 3 ;
$minNumWorkFields = 3 ;
$maxNumEmploy = 5 ;
$minNumEmploy = 0 ;
cleanSeries( $transcripts, $maxNumTranscripts ) ;
cleanSeries( $references, $maxNumRefs ) ;
cleanSeries( $employment, $maxNumEmploy ) ;
############# Functions
function cleanSeries( $series, $max ){
for( $i = 1; $i <= $max ; $i++ ){
foreach( $series as $field ){
$_POST[ "$field$i" ] = trim( $_POST[ "$field$i" ] ) ;
}
}
}
function verifyDate( $date, $pattern ) {
if ( preg_match( $pattern, $date ) ) {
return 1 ;
} else {
return 0 ;
}
}
function verifyGPA($gpa) {
if ( preg_match('/^\d+(\.\d+)?$/', $gpa) ) {
return 1;
} else {
return 0;
}
}
function checkDateSeries( $series, $pattern, $max = 5 ) {
$dateProb = 0 ;
for ( $i = 1; $i <= $max; $i++ ) {
foreach ( $series as $field ) {
if ( $_POST[ "$field$i" ] && !verifyDate( $_POST[ "$field$i" ], $pattern ) ) {
$dateProb = 1 ;
}
}
}
if ( !$dateProb ) { return 1 ; }
else { return 0 ; }
}
function checkNumSeries( $series, $min = 1, $max = 5 ) {
$vSeries = array() ;
for ( $i = 1 ; $i <= $max; $i++ ) {
foreach ( $series as $field ) {
if ( $_POST[ "$field$i" ] ) {
$vSeries[ $i ][ "$field$i" ] = 1 ;
}
}
}
if ( count( $vSeries ) >= $min ) { return 1 ; }
else { return 0 ; }
}
function checkNumAssocFields( $series, $min = 1 ) {
$vSeries = array() ;
foreach ( $series as $field ) {
if ( $_POST[ $field ] ) {
$vSeries[ $field ] = 1 ;
}
}
if( count( $vSeries ) >= $min ) { return 1 ; }
else { return 0 ; }
}
include("ctioreu.header");
if ( ( isset($_POST["preview"]) ) && ( $_POST["preview"] == "Preview Application" ) ) {
$error = 0;
if( !$_POST[ "nameLast" ] ) {
$error = 1 ;
echo "Please enter a last name.
" ;
}
if( !$_POST[ "nameFirst" ] ) {
$error = 1 ;
echo "Please enter a first name.
" ;
}
if ( !$_POST[ "mailStreet" ] ) {
$error = 1 ;
echo "Please enter a mailing address.
" ;
}
if ( !$_POST[ "mailCity" ] ) {
$error = 1 ;
echo "Please enter a city.
" ;
}
if ( ( $_POST[ "mailState" ] == "Other" ) && ( !$_POST[ "otherState" ] ) ) {
$error = 1 ;
echo "Please provide a state.
" ;
}
if ( !$_POST[ "mailZip" ] ) {
$error = 1 ;
echo "Please provide a zip code.
";
}
if ( !$_POST[ "mailPhoneAC" ] ) {
$error = 1 ;
echo "Please provide an area code.
";
}
if ( !$_POST[ "mailPhonePrefix" ] ) {
$error = 1 ;
echo "Please provide a complete phone number.
";
}
if ( !$_POST[ "mailPhonePost" ] ) {
$error = 1 ;
echo "Please provide a complete phone number.
";
}
if ( !$_POST[ "homeStreet" ] ) {
$error = 1 ;
echo "Please enter a mailing address.
";
}
if ( !$_POST[ "homeCity" ] ) {
$error = 1 ;
echo "Please enter a city.
";
}
if ( ( $_POST[ "homeState" ] == "Other" ) && ( !$_POST[ "otherState2" ] ) ) {
$error = 1 ;
echo "Please provide a state.
";
}
if ( !$_POST[ "homeZip" ] ) {
$error = 1 ;
echo "Please provide a zip code.
";
}
if ( !$_POST[ "homePhoneAC" ] ) {
$error = 1 ;
echo "Please provide an area code.
";
}
if ( !$_POST[ "homePhonePrefix" ] ) {
$error = 1 ;
echo "Please provide a complete phone number.
";
}
if ( !$_POST[ "homePhonePost" ] ) {
$error = 1 ;
echo "Please provide a complete phone number.
";
}
if ( !$_POST[ "email" ] ) {
$error = 1 ;
echo "Please provide an e-mail.
";
}
if ( !$_POST[ "citizen" ] ) {
$error = 1 ;
echo "Please provide citizenship information.
";
}
if ( !$_POST[ "found" ] ) {
$error = 1 ;
echo "Please tell us how you found out about the REU program.
";
}
if ( !$_POST[ "academicLevel" ] ) {
$error = 1 ;
echo "Please tell us your current academic level.
";
}
if ( !checkNumSeries( $transcripts, $minNumTranscripts, $maxNumTranscripts ) ) {
$error = 1 ;
echo "Please provide information for at least $minNumTranscripts transcript.
";
}
if ( !checkDateSeries( $transDates, "/^(\d)?\d\/\d\d\d\d$/", $maxNumTranscripts ) ) {
$error = 1 ;
echo "Dates must be in the form mm/yyyy.
";
}
if ( ( !$_POST[ "gpaAll" ] ) || ( !verifyGPA($_POST[ "gpaAll" ]) ) ) {
$error = 1 ;
echo "Please tell us your overall GPA (as a number).
";
}
if ( ( !$_POST[ "gpaMathSci" ] ) || ( !verifyGPA($_POST[ "gpaMathSci" ]) ) ) {
$error = 1 ;
echo "Please tell us your GPA in physical science and math (as a number).
";
}
if ( ( !$_POST[ "gpaMax" ] ) || ( !verifyGPA($_POST[ "gpaMax" ]) ) ) {
$error = 1 ;
echo "Please tell us you maximum GPA (as a number).
";
}
if ( !checkNumSeries( $references, $minNumRefs, $maxNumRefs ) ) {
$error = 1 ;
echo "Please provide information for at least $minNumRefs references.
";
}
if ( !$_POST[ "availFrom" ] ) {
$error = 1 ;
echo "Please tell us when you are first available for the program.
";
}
if ( ( $_POST[ "availFrom" ] ) && (!verifyDate( $_POST[ "availFrom" ], "/^(\d)?\d\/(\d)?\d\/\d\d\d\d$/" ) ) ) {
$error = 1 ;
echo "Dates must be in the form mm/dd/yyyy.
";
}
if ( !$_POST[ "availTo" ] ) {
$error = 1 ;
echo "Please tell us how long you are available for the program.
";
}
if ( ( $_POST[ "availTo" ] ) && !verifyDate( $_POST[ "availTo" ], "/^(\d)?\d\/(\d)?\d\/\d\d\d\d$/" ) ) {
$error = 1 ;
echo "Dates must be in the form mm/dd/yyyy.
";
}
if ( !checkNumAssocFields( $astroFields, $minNumAstroFields ) ) {
$error = 1 ;
echo "Please rank your top $minNumAstroFields choices of astronomical field.
";
}
if ( !checkNumAssocFields( $workFields, $minNumWorkFields ) ) {
$error = 1 ;
echo "Please rank your top $minNumWorkFields preferred types of work.
";
}
if ( !$_POST[ "compExp" ] ) {
$error = 1 ;
echo "Please tell us about your computer experience.
";
}
if ( !checkDateSeries( $jobsDates, "/^(\d)?\d\/\d\d\d\d$/", $maxNumEmploy ) ) {
$error = 1 ;
echo "Dates must be in the form mm/yyyy.
";
}
if ( ( !$_POST[ "bymail" ] ) && ( !$_POST[ "letter" ] ) ) {
$error = 1 ;
echo "Please provide your letter in the space provided.
";
}
}
if ( ( isset($_POST["preview"]) ) && ( $_POST["preview"] == "Preview Application" ) && ( $error == 0 ) ) {
echo "