<?
session_start(); 

require("DB.php");


if(	empty($form[firstName]) || empty($form[lastName]) ||
	empty($form[rNumber]) )
{
        $eID = 1;
	session_register('eID');
	header("Location: s.php");
}
else
{	
	//connect to database
	$dbVar = new DB("andromeda", "gradinfo");
	$dbVar->connect();
	
	  $id = $dbVar->checkUser($form[rNumber]);
	if( $id == 1){
	   $usedSId = 1;
	   session_register('usedSId');	
	   header("Location: s.php");
	   exit;
	}


	//add student as a user
	$uObj = new User();
	$uObj->name->firstName=$form[firstName];
	$uObj->name->lastName = $form[lastName];
	$uObj->userId = $form[rNumber];
	$uObj->password = $form[rNumber];
	$uObj->userType = 's';
	
	/*
	print $uObj->name->firstName;
	print $uObj->name->lastName;
	print $uObj->userId;
	print $uObj->password;
	print $uObj->userType;*/

	$dbVar->putUser($uObj);

	//add student info
	$obj = new Student;
	
	//ID and Name
	$obj->rNumber=$form[rNumber];
	$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[schoolidNumber];
	$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->major=$form[major];
	
	//GRE
	$obj->gre->verbal = $form[verbal];
	$obj->gre->math = $form[math];
	$obj->gre->analytical=$form[analytical];
	$obj->status = 1; //accepted
	$obj->toefl=$form[toefl];
	$obj->ssNumber=$form[ssNumber];
	$obj->tGPA=$form[tGPA];
	$obj->dob=$form[dob];
	$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->major=$form[major];
	$obj->degree = $form[degree];

	//student
	$obj->ucGPA = $form[ucGPA];
	$obj->advisor=$form[advisor];
	//$obj->comment=$form[comment];
	//$obj->commentDate=$form[commentDate];

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

	$dbVar->disconnect();

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