<?php
session_start();

require("DB.php");



if(	empty($form[firstName]) || empty($form[lastName]) ||
	empty($form[userId]) )
{
        $eIDApp = 1;
	session_register('eIDApp');
	header("Location: a.php");
}
else
{	

	//connect to database
	$dbVar = new DB("andromeda", "gradinfo");
	$tmp = $dbVar->connect();
  $id = $dbVar->checkUser($form[userId]);
	if( $id == 1){
	   $usedId = 1;
	   session_register('usedId');	
	   header("Location: a.php");
	   exit;
	}

	//print $tmp;
	$obj = new Applicant();
	
	//add applicant as a user
	$uObj = new User();
	$uObj->name->firstName=$form[firstName];
	$uObj->name->lastName = $form[lastName];
	$uObj->userId = $form[userId];
	$uObj->password = $form[userId];
	$uObj->userType = 'a';
	$dbVar->putUser($uObj);

	//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];
	$obj->phoneNumber->countryCode=$form[countryCode];
	
	//GRE
	$obj->gre->verbal = $form[verbal];
	$obj->gre->math = $form[math];
	$obj->gre->analytical=$form[analytical];

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

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

	$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];

	/*if($form[programType] == "Computer Science"){
		$obj->programType = 0;
	}
	else{
		$obj->programType = 1;
	}*/
	$obj->programType=$form[programType];
	
	$obj->typeProg=$form[typeProg];
	$obj->cGPA = $form[cGPA];
	$obj->degree = $form[degree];

	//put applicant info into database
	//********************************
	$tmp = $dbVar->putApplicant($obj);
	//if((strlen($messge) == 0) && ($tmp == 0)){
	/*if($tmp == 0){
		$message = "Error! Applicant is not stored into the database";
	}
	else{
		$message = "Applicant: " .$form[firstName] 
			." has been added to the database.";
	}*/		
	$dbVar->disconnect();

	header("location: gradApp.php");
//	exit;
}
//print $message;
require("asstHeader.php");
?>
