<?php session_start();
require("DB.php");
if($userType != 'm')
  header("Location: logout.php");

//print session_encode();
$applicantID = $event_id;

//Connect to Database
$db = new DB("andromeda","gradinfo");
$link = $db->connect();



if($aF1==1){	
	$aF1=0;
	session_register('aF1');

//	echo" SUBMITTED ";

	//connect to database
	$obj = new Applicant;
	
	//ID and Name
	$obj->userId=$form[userId];
	$obj->name->firstName = $form[firstName];
	$obj->name->lastName = $form[lastName];
	$obj->name->MI = $form[MI];
	$obj->email = $form[email];
	
	//address
	$obj->address->streetName=$form[streetName];
	$obj->address->POBox = $form[POBox];
	$obj->address->city=$form[city];
	$obj->address->state=$form[state];
	$obj->address->zipcode=$form[zipcode];
	$obj->address->country=$form[country];
	

	//school
	$obj->school->idNumber=$form[sID];
	$obj->school->schoolName=$form[schoolName];	
	
	//school address
	$obj->school->address->streetName=$form[sStreet];
	$obj->school->address->city=$form[sCity];
	$obj->school->address->state=$form[sState];
	$obj->school->address->country=$form[sCountry];
	$obj->school->address->POBox=$form[sPOBox];
	$obj->school->address->zipcode=$form[sZip];
		
	
	//phone
	$obj->phoneNumber->area=$form[area];
	$obj->phoneNumber->prefix=$form[prefix];
	$obj->phoneNumber->suffix=$form[suffix];
	
	//GRE
	$obj->gre->verbal = $form[verbal];
	$obj->gre->math = $form[math];
	$obj->gre->analytical=$form[analytical];

	$obj->major=$form[major];

	//Info
	if($form[status]=="Rejected"){
		$obj->status=2;
	}
	elseif($form[status]=="Accepted"){
		$obj->status=1;
	}
	else{
		$obj->status=0;
	}

	$obj->toefl=$form[toefl];
	$obj->ssNumber=$form[ssNumber];
	$obj->tGPA=$form[tGPA];
	$obj->dob=$form[dob];
	$obj->message=$form[message];
	$obj->finalLetter=$form[finalLetter];
	$obj->dateGrad=$form[dateGrad];
	$obj->dateAttend=$form[dateAttend];
	$obj->programType=$form[programType];
	$obj->typeProg=$form[typeProg];
	$obj->cGPA = $form[cGPA];
	$obj->degree = $form[degree];

	$db->updateApplicant($obj);    //, $applicantID);
//	$app = $db->getApplicant($applicantID);
	
	$db->disconnect();
	
	 header("location: gradApp.php");  //viewA.php?event_id=$applicantID");
	 exit;
}
else {
	$aF1=1;
	session_register('aF1');
}

//print $message;
$app = $db->getApplicant($applicantID);
//echo $app->name->firstName ;
//$db->disconnect();
require("asstHeader.php");
?>
<html><body>
<!-- comments::space &nbsp-->
<h2 align=left>UNR Computer Science--Applicant Infomation</h2> 
<form action="<? print "$PHP_SELF?aF1=1" ?>">
<input type="hidden" name="event_id" value="<? print $applicantID ?>">
<table border = 2> 
<tr><th width=765> NAME AND CONTACT INFORMATION</th> 
</table><br> 
<table border = 1> 
<? echo $app->name->firstName;?>
<tr><td>First Name</td><td><input type="text" name="form[firstName]" value="<? print $app->name->firstName;?>"></td> 
<td>Last Name</td><td><input type="text" name="form[lastName]" value="<? print $app->name->lastName;?>"></td> 
<td>Middle Initial</td><td><input type="text" name="form[MI]" value="<? print $app->name->MI;?>"></td> 
<tr><td>Social Security Number</td><td><input type="text" name="form[ssNumber]" 
	value="<? print $app->ssNumber;?>"></td> 
<td>Date of Birth</td><td><input type="text" name="form[dob]" value="<? print $app->dob;?>"></td>  
	<td>User ID</td><td><input type="text" name="form[userId]" value="<? print$app->userId; ?>"</td>
<tr><td colspan=6>Mailing Address</td> 
<tr><td>Street Name</td><td colspan=3><input type="text" name="form[streetName]" 
	value="<? print $app->address->streetName;?>"size=55></td> 
<td>P.O. Box</td><td><input type="text" name="form[POBox]" value="<? print $app->address->POBox;?>"></td> 
<tr><td>City</td><td><input type="text" name="form[city]" value="<? print $app->address->city;?>"></td> 
<td>State</td><td><input type="text" name="form[state]" value="<? print $app->address->state;?>"></td> 
<td>Zip Code</td><td><input type="text" name="form[zipcode]" value="<? print $app->address->zipcode;?>"></td> 
<tr><td>Country </td><td><input type="text" name="form[country]" value="<? print $app->address->country;?>"></td>
<td>E-Mail</td><td><input type="text" name="form[email]" value="<? print $app->email?>"></td>
</table>
<table border = 1>
<tr><td>Phone Number</td><td>(</td> 
<td><input type="text" name="form[area]" value="<? print $app->phoneNumber->area;?>" size=5></td><td>)</td> 
<td><input type="text" name="form[prefix]" value="<? print $app->phoneNumber->prefix;?>" size=5></td><td><b>-</b></td>
<td><input type="text" name="form[suffix]" value="<? print $app->phoneNumber->suffix;?>" size=7></td>
<td>Country Code</td><td><input type="text" name="form[countryCode]" 
	value="<? print $app->phoneNumber->countryCode?>" size=7></td> <!-- maxlength -->
</table><br> 
 
<table border = 2><tr><th width=765> GRADUATE PROGRAM INFORMATION</th></table> 
</table><br>
 
<table border = 1> 
<tr><td>Program type</td><td><select name="form[programType]">
	 	<? 
		if($app->programType == 1){
		     $select = "Computer Engineering";
		     	print "<option>" .$select;	
		     	print "<option>Computer Science";
		}
		else{
		     $select = "Computer Science";
			print "<option>" .$select;	
		     	print "<option>Computer Engineering";	
		}?>
		</select></td>

<td>Degree</td><td><select name="form[typeProg]">
	<? 
		if($app->typeProg == "M.S."){
		     $select = "M.S.";
		     	print "<option>" .$select;	
		     	print "<option>Ph.D.";
		}
		else{
		     $select = "Ph.D.";
			print "<option>" .$select;	
		     	print "<option>M.S.";	
		}?>
		</select></td>

<td>Status</td><td><select name="form[status]">
	<? 
		if($app->status == "In Progress"){
		     $select = "In Progress";
		     	print "<option>" .$select;	
		     	print "<option>Accepted";
			print "<option>Rejected";
		}
		elseif($app->status == "Accepted"){
		     $select = "In Progress";
		     	print "<option>" .$select;	
		     	print "<option>In Progress";
			print "<option>Rejected";
		}else{
		      $select = "Rejected";
		     	print "<option>" .$select;	
		     	print "<option>In Progress";
			print "<option>Accepted";	
		}?>
		</select></td>
</table><br>

<table border = 2><tr><th width=765> EDUCATION</th></table> 
</table><br> 

<table border = 1> 
<tr><td >Name of College or University</td>
<tr><td><input type="text" name="form[schoolName]" 
	value="<? print $app->school->schoolName;?>"size=91></td>
<tr><td><b>School Address</b><td>
<tr><td>Street Name </td>
<tr><td><input type="text" name="form[sStreet]" 
	value="<? print $app->school->address->streetName;?>"size=91></td></table>

<table border = 1>
<tr><td>City</td><td><input type="text" name="form[sCity]" 
	value="<? print $app->school->address->city;?>"></td>
	<td>State</td><td><input type="text" name="form[sState]" 
	value="<? print $app->school->address->state;?>"></td>
	<td>Zip Code</td><td><input type="text" name="form[sZip]" 
	value="<? print $app->school->address->zipcode;?>"></td>
<tr><td>Country</td><td><input type="text" name="form[sCountry]" 
	value="<? print $app->school->address->country;?>"></td>
	<td>ID Number</td><td><input type="text" name="form[sID]" 
	value="<? print $app->school->idNumber;?>"></td>
	<td>P.O. Box</td><td><input type="text" name="form[sPOBox]" 
	value="<? print $app->school->address->POBox?>"></td>
<tr><td>Degree Earned</td><td><input type="text" name="form[degree]" 
	value="<? print $app->degree;?>"></td> 
	<td>Major</td><td><input type="text" name="form[major]" 
	value="<? print $app->major;?>"></td></table><br> 

<br><table border=1> 
<tr><td>Graduation / Expected Graduation Date</td><td><input type="text" name="form[dateGrad]" 
	value="<? print $app->dateGrad;?>"size=31></td> 
<td>Date Attended</td><td colspan=4><input type="text" name="form[dateAttend]" 
	value="<? print $app->dateAttend;?>"size=31></td></table><br> 

<table border = 1> 
<tr><td size=10>GPA</td><td>Undergraduate GPA</td><td><input type="text" name="form[cGPA]" 
	value="<? print $app->cGPA;?>"></td> 
<td>Graduate GPA</td><td><input type="text" name="form[tGPA]"
	 value="<? print $app->tGPA;?>"></td> 
<td>TOEFL</td><td><input type="text" name="form[toefl]" 
	value="<? print $app->toefl;?>"size=17></td> 
<tr><td size=10>GRE</td><td>Analytical</td><td><input type="text" name="form[analytical]" 
	value="<? print $app->gre->analytical;?>"></td> 
<td>Verbal</td><td><input type="text" name="form[verbal]" 
	value="<? print $app->gre->verbal;?>"></td> 
<td>Quantitative</td><td><input type="text" name="form[math]" 
	value="<? print $app->gre->math;?>" size=17></td> 
</table><br> 

<table border = 2><tr><th width=765> RECOMMENDATIONS</th></table> 
</table><br> 
<table border = 1> 
<tr><th>UNR Committee Members</th> 
<tr><td><textarea name="form[message]" rows=5 cols=93>
	<? print $app->message;?></textarea></td> 
</table> 
<table border = 1> 
<tr><th>UNR Graduate Director</th> 
<tr><td><textarea name="form[finalLetter]" rows=5 cols=93>
	<? print $app->finalLetter;?></textarea></td> 
</textarea></td> 
</table><br>
<input type="submit" name="aF1" value="Update Data">
</form><br>

</body></html>
