<?
/*********************************************************
* Classname: DB
* Purpose: Inserts and retrieves user information from the
*	   database
* Version information
* Date: November 5, 2001
* Copyright notice
***********************************************************/
require("user.php");
class DB {

      var $DB_Host;   // Computer hosting database
      var $DB_Name;   // Database name
      var $DB_Tables; // List of databases tables
      var $DB_User;   // Username with access to database
      var $DB_User_Password; // Password of valid user
      var $conxn;

      //  Constructor
      function DB($user, $password){
      $this->DB_Name = "Andromeda_GPA";
      $this->DB_User = $user;
      $this->DB_User_Password = $password;
      $this->DB_Host = "mysql";
      }


//**********************************************************************
//**********************************************************************
      // Opens connection to database
      // returns an integer which identifies the connection
      function connect(){

      $cnxn = mysql_connect($this->DB_Host, $this->DB_User, $this->DB_User_Password);
      mysql_select_db($this->DB_Name);
      $this->conxn = cnxn;
      return $cnxn;
      
      }


//**********************************************************************
//**********************************************************************
function disconnect(){
	mysql_close();
}


//**********************************************************************
//**********************************************************************
      // insert values into fields of a table all specified by the user
      function insert($tbl,$fieldNames,$data){
	$query = "INSERT INTO $tbl $fieldNames VALUES $data";
	$rslt = mysql_query($query);

      }


//**********************************************************************
//**********************************************************************
      // check if the username appears in the database
      function checkUser($uName){
	$query = "SELECT * FROM user WHERE username = \"$uName\""; 
	$checkuser = mysql_query($query);
	$num_Rows = mysql_num_ROWS($checkuser);
	 if($num_Rows > 0)
	  return 1;
	 return 0;	
      }


//**********************************************************************
//**********************************************************************
      // retrieve information about a student in the database
      function retrieveStudentByID($id){
	$query = "SELECT * FROM students WHERE rNumber = $id";
	$results = mysql_query($query) or die ("No Retrieval");
      	return $results;
      }


//**********************************************************************
//**********************************************************************
      // retrieve information about a student in the database
      function retrieveStudentByName($first,$last){
	$query = "SELECT * FROM students 
		  WHERE first =\"$first\" AND last =\"$last\"";
	$results = mysql_query($query) or 
		     die("No Retrieval of student by name");
	return $results;
      }


//**********************************************************************
//**********************************************************************
      // ensure that the the username and password given exist in the database
      //   get first,last names and return them as reference parameters
      function checkValidUser(&$user){

//$username,$pwd,&$firstName,&$lastName, &$userType

	$query = "SELECT * FROM user 
	  WHERE username=\"$user->username\" AND password = password(\"$user->password\")";

        $result = mysql_query($query) or die("No authentication");

      $num = mysql_num_rows($result);

      if($num != 0) {
        $getName = "SELECT first,last,userType FROM user 
	     WHERE username=\"$user->username\" AND password=password(\"$user->password\")";
 	$rslt = mysql_query($getName) or die("no query for getname");

 	$row = mysql_fetch_array($rslt);
  	$user->name->firstName = $row['first'];
  	$user->name->lastName = $row['last'];
	$user->userType = $row['userType'];
	}      
 
	return $num;
      }



//**********************************************************************
//**********************************************************************
function getStudent($studentID) {

	$stud = new Student();



	$query = "SELECT * FROM students WHERE rNumber = \"$studentID\"";
	$gotStudent = mysql_query($query) or Die("STUDENT QUERY DIED");
	
	$row = mysql_fetch_array($gotStudent);
	
	$stud->name->firstName = $row['firstName'];
	$stud->name->lastName = $row['lastName'];
	$stud->name->MI = $row['MI'];
	
	$stud->email = $row['email'];
	$stud->address->city = $row['city'];
	$stud->address->state = $row['state'];
	$stud->address->country = $row['country'];
	$stud->address->zipcode = $row['zip'];
	$stud->address->streetName = $row['street'];
	$stud->address->POBox = $row['POBox'];

	$stud->phoneNumber->area = $row['area'];
	$stud->phoneNumber->prefix = $row['prefix'];
	$stud->phoneNumber->suffix = $row['sufix'];
	$stud->phoneNumber->countryCode = $row['cCode'];

	$stud->ssNumber = $row['ssn'];

	$stud->toefl = $row['toefl'];
	$stud->gre->math = $row['math'];
	$stud->gre->verbal = $row['verbal'];
	$stud->gre->analytical = $row['analy'];
	$stud->tGPA = $row['tgpa'];

	$stud->dob = $row['dob'];
	
	$stud->status = $row['status'];
	$stud->finalLetter = $row['finalLetter'];

	$stud->rNumber = $row['rNumber'];
	$stud->cGPA = $row['cGPA'];
	$stud->programType = $row['programType'];
	$stud->project = $row['project'];
	$stud->typeProg = $row['typeProg'];
	$stud->advisor = $row['advisor'];

	$sID  = $row['sID'];
 	$stud->school->idNumber = $sID;
	
	echo $sID;
	echo $stud->school->idNumber;

	$sSt  = $row['sStreet'];
	$stud->school->address->streetName = $sSt;

	$sCit = $row['sCity'];
	$stud->school->address->city = $sCit;

	$sSta = $row['sState'];
	$stud->school->address->state = $sSta;

	$sCo = $row['sCountry'];
	$stud->school->address->country = $sCo;

	$sZ = $row['sZip'];
	$stud->school->address->zipcode = $sZ;

	$sPo = $row['sPOBox'];
	$stud->school->address->POBox = $sPo;

	$sN = $row['sName'];	
	$stud->school->schoolName = $sN;

	$stud->major = $row['major'];
	$stud->dateGrad = $row['dateGrad'];
	$stud->degree = $row['degree'];
	
	
	$query = "SELECT * FROM classes WHERE rNumber = \"$studentID\"";
	$gotClasses = mysql_query($query);


	while($classes = mysql_fetch_array($gotClasses)){
		$c = new Course($classes['course'],$classes['grade'],$classes['semester'],$classes['type'],$classes['status']);
	array_push($stud->list_of_courses,$c);
	
	}


	return $stud;
}



//**********************************************************************
//**********************************************************************

function putStudent(&$stud){
	

	$first = $stud->name->firstName;
	$last = $stud->name->lastName;
	$mi = $stud->name->MI;

	$city = $stud->address->city;
	$state = $stud->address->state;
	$zip = $stud->address->zipcode;
	$street = $stud->address->streetName;
	$country = $stud->address->country;
	$POBox = $stud->address->POBox;

	$area = $stud->phoneNumber->area;
	$prefix = $stud->phoneNumber->prefix;
	$suffix = $stud->phoneNumber->suffix;
	$countryCode = $stud->phoneNumber->countryCode;
	
/* 
	School info to be added
      +-------------------------+
*/
	$sID = $stud->school->idNumber;
	$sstreet = $stud->school->address->streetName;
	$scity = $stud->school->address->city;
   	$sstate = $stud->school->address->state;	
	$scountry = $stud->school->address->country;
	$sPOBox = $stud->school->address->POBox;
	$sZip = $stud->school->address->zipcode;
	$sName = $stud->school->schoolName;

	$math = $stud->gre->math;
	$verbal = $stud->gre->verbal;
	$analytical = $stud->gre->analytical;


	$query = "INSERT into students(firstName, 
					lastName, 
					MI, 
					email, 
					city, 
					state, 
					zip, 
					country, 
					street, 
					POBox, 
					area, 
					prefix, 
					sufix, 
					cCode, 
					ssn, 
					toefl, 
					math, 
					verbal, 
					analy, 
					tgpa, 
			    		dob, 
					status, 
					finalLetter, 
					cGPA, 
					programType, 
					project, 
					typeProg, 
					advisor, 
					app,
					rNumber,
					sID,
					sName,
					sStreet,
					sCity,
					sState,
					sCountry,
					sPOBox,
					sZip,
					major,
					dateGrad,
					degree) 

       		  VALUES ('$first', 
			  '$last',	
			  '$mi',           
			  '$stud->email',	
	 	          '$city', 
			  '$state',  
			  '$zip', 
	 	          '$country', 
			  '$street', 
			  '$POBox', 
	  	          '$area', 
			  '$prefix', 
			  '$suffix', 
	  	          '$countryCode', 
			  '$stud->ssNumber', 
			  '$stud->toefl', 
			  '$math', 
	   	      	  '$verbal',
			  '$analytical', 
			  '$stud->tGPA', 
			  '$stud->dob', 
			  '$stud->status', 
	   	          '$stud->finalLetter', 
			  '$stud->cGPA',  
			  '$stud->programType', 
			  '$stud->project', 
			  '$stud->typeProg',
	    	     	  '$stud->advisor',
			  '0',
			  '$stud->rNumber',
			  '$sID', 
			  '$sName',
			  '$sstreet',
			  '$scity',
			  '$sstate',
			  '$scountry',
			  '$sPOBox',
			  '$sZip',
			  '$stud->major',
			  '$stud->dateGrad',
			  '$stud->degree')";

	$results = mysql_query($query) or die("Could not Insert Student $stud->rNumber "); 

	return $results;

}


//**********************************************************************
//**********************************************************************
function addToClassList($studentID,$classToAdd){

	$query = "INSERT into classes (rNumber,grade,semester,course,type,status)
		    VALUES ('$studentID', '$classToAdd->grade', 
					  '$classToAdd->semester', 
					  '$classToAdd->course',
					  '$classToAdd->type',
					  '$classToAdd->courseStatus')";

	$result = mysql_query($query) or Die("Unable to add Class $classToAdd->course to $studentID");
	
	return $result;

}


//**********************************************************************
//**********************************************************************
function removeFromClassList($studentID, $classToRemove){
	$query = "DELETE FROM classes WHERE rNumber = \"$studentID\" AND 
				            course = \"$classToRemove->course\"";
	$result = mysql_query($query) or die("Could not delete $classToRemove->course from $studentID");

	return $result;
	
}


//**********************************************************************
//**********************************************************************
Function changeClassGrade($studentID, $class){

	$query = "UPDATE classes SET grade=\"$class->grade\" WHERE rNumber = \"$studentID\" AND course = \"$class->course\"";

	$result = mysql_query($query) or die("Could not update $class->course to grade $class->grade for $studentID");
	return $result;

}


function appToStud($appID){
	$i = 0;
	
	$query = "UPDATE students SET app='$i' WHERE rNumber='$appID'";

	$res = mysql_query($query) or die("Could not change App to Stud");
	
	$q = "UPDATE user SET userType='s' WHERE username='$appID'";
	$r = mysql_query($q) or Die("Could not convert userType to stud from appin user table");

	return $res;

}
//**********************************************************************
//**********************************************************************
function changeAdvisor($studentID, $advisor){

	$query = "UPDATE students SET advisor='$advisor' WHERE rNumber=\'$studentID\'";

	$result = mysql_query($query) or die("Could not update $studentID advisor to $advisor");

	return $result;
}


//**********************************************************************
//**********************************************************************
function getComments($studentID, &$commentString){
	
	$query = "SELECT * FROM comments WHERE rNumber = \"$studentID\"";
	
	$result = mysql_query($query) or die("Could not get comments for $studentID");
	
	$commentString = mysql_fetch_array($result);	
	
	return 1;

}


//**********************************************************************
//**********************************************************************
function putComments($studentID, $commentString){

	$query = "INSERT INTO comments ('rNumber', 'comment') VALUES ('$studentID','$commentString')";

	$result = mysql_query($query) or die("Could not put comments for $studentID");

	return $result;

}


//**********************************************************************
//**********************************************************************
function getCourseList($studentID){
 $list_of_courses = array();

	$query = "SELECT * FROM classes WHERE rNumber = \"$studentID\"";
	$gotUNRClasses = mysql_query($query) or die("No UNR classes gotten");
	
	while($UNRclasses = mysql_fetch_array($gotUNRClasses)){
	  	$grade = $UNRclasses['grade'];
		$semester = $UNRclasses['semester'];
		$course = $UNRclasses['course'];
		$type = $UNRclasses['type'];
		$status = $UNRclasses['status'];
	$clas = new Course($course,$grade,$semester,$type,$status);
	array_push($list_of_courses,$clas);	
	}
return $list_of_courses;

}


//**********************************************************************
//**********************************************************************
function getApplicant($applicantID){

	$app = new Applicant();

	$query = "SELECT * FROM students WHERE rNumber = \"$applicantID\"";
	$gotApplicant = mysql_query($query) or Die("STUDENT QUERY DIED");
	
	$row = mysql_fetch_array($gotApplicant);
	
	$app->name->firstName = $row['firstName'];
	$app->name->lastName = $row['lastName'];
	$app->name->MI = $row['MI'];
	
	$app->email = $row['email'];
	$app->address->city = $row['city'];
	$app->address->state = $row['state'];
	$app->address->country = $row['country'];
	$app->address->zipcode = $row['zip'];
	$app->address->streetName = $row['street'];
	$app->address->POBox = $row['POBox'];

	$app->phoneNumber->area = $row['area'];
	$app->phoneNumber->prefix = $row['prefix'];
	$app->phoneNumber->suffix = $row['sufix'];
	$app->phoneNumber->countryCode = $row['cCode'];

	$app->ssNumber = $row['ssn'];

	$app->toefl = $row['toefl'];
	$app->gre->math = $row['math'];
	$app->gre->verbal = $row['verbal'];
	$app->gre->analytical = $row['analy'];
	$app->tGPA = $row['tgpa'];

	$app->dob = $row['dob'];
	
	$app->status = $row['status'];
	$app->finalLetter = $row['finalLetter'];

	$app->userId = $row['rNumber'];
	$app->cGPA = $row['cGPA'];	
	$app->programType = $row['programType'];

	$app->typeProg = $row['typeProg'];
	
	$app->school->idNumber = $row['sID'];
	$app->school->address->streetName = $row['sStreet'];
	$app->school->address->city = $row['sCity'];
	$app->school->address->state = $row['sState'];
	$app->school->address->country = $row['sCountry'];
	$app->school->address->zipcode = $row['sZip'];
	$app->school->address->POBox = $row['sPOBox'];
	$app->school->schoolName = $row['sName'];	

	$app->major = $row['major'];
	$app->dateGrad = $row['dateGrad'];
	$app->degree = $row['degree'];



	$query = "SELECT * FROM classes WHERE rNumber = \"$applicantID\"";
	$gotClasses = mysql_query($query);

	while($classes = mysql_fetch_array($gotClasses)){
		$c = new Course($classes['course'],$classes['grade'],$classes['semester'],$classes['type'],$classes['status']);
	array_push($app->list_of_courses,$c);
	
	}

	return $app;
}





//**********************************************************************
//**********************************************************************
function putApplicant($app){


	$first = $app->name->firstName;
	$last = $app->name->lastName;
	$mi = $app->name->MI;

	$city = $app->address->city;
	$state = $app->address->state;
	$zip = $app->address->zipcode;
	$street = $app->address->streetName;
	$country = $app->address->country;
	$POBox = $app->address->POBox;

	$area = $app->phoneNumber->area;
	$prefix = $app->phoneNumber->prefix;
	$suffix = $app->phoneNumber->suffix;
	$countryCode = $app->phoneNumber->countryCode;
	 

	$math = $app->gre->math;
	$verbal = $app->gre->verbal;
	$analytical = $app->gre->analytical;

/* 
	School info to be added
      +-------------------------+

*/
	$sID = $app->school->idNumber;
	$sstreet = $app->school->address->streetName;
	$scity = $app->school->address->city;
   	$sstate = $app->school->address->state;	
	$scountry = $app->school->address->country;
	$sPOBox = $app->school->address->POBox;
	$sZip = $app->school->address->zipcode;
	
	$sName = $app->school->schoolName;



	$query = "INSERT into students(firstName, 
					lastName, 
					MI, 
					email, 
					city, 
					state, 
					zip, 
					country, 
					street, 
					POBox, 
					area, 
					prefix, 
					sufix, 
					cCode, 
					ssn, 
					toefl, 
					math, 
					verbal, 
					analy, 
					tgpa, 
			    		dob, 
					status, 
					finalLetter, 
					cGPA, 
					programType, 
					typeProg,
					rNumber,
					app,
					sID,
					sName,
					sStreet,
					sCity,
					sState,
					sCountry,
					sPOBox,
					sZip,
					major,
					dateGrad,
					degree) 

       		  VALUES ('$first', 
			  '$last',	
			  '$mi',           
			  '$app->email',	
	 	          '$city', 
			  '$state',  
			  '$zip', 
	 	          '$country', 
			  '$street', 
			  '$POBox', 
	  	          '$area', 
			  '$prefix', 
			  '$suffix', 
	  	          '$countryCode', 
			  '$app->ssNumber', 
			  '$app->toefl', 
			  '$math', 
	   	      	  '$verbal',
			  '$analytical', 
			  '$app->tGPA', 
			  '$app->dob', 
			  '$app->status', 
	   	          '$app->finalLetter', 
			  '$app->cGPA',  
			  '$app->programType', 
			  '$app->typeProg',
			  '$app->userId',
			  '1',
			  '$sID', 
			  '$sName',
			  '$sstreet',
			  '$scity',
			  '$sstate',
			  '$scountry',
			  '$sPOBox',
			  '$sZip',
			  '$app->major',
			  '$app->dateGrad',
			  '$app->degree')";

	$results = mysql_query($query) or die("Could not Insert Applicant $app->userId");

	return $results;


}



//**********************************************************************
//**********************************************************************
function getNotes($applicantID){

	$query = "SELECT * FROM comments WHERE rNumber = \"$applicantID\"";
	$results = mysql_query($query) or die("Could not get notes for $applicantID");

	$res = mysql_fetch_array($results);

	return $res;


}



//**********************************************************************
//**********************************************************************
function putNotes($applicantID,$noteString){

	$query = "INSERT INTO comments (rNumber, comment) VALUES ('$applicantID','$noteString')";
	
	$results = mysql_query($query) or die("Could not insert notes for $applicantID");;

	return $results;


}




//**********************************************************************
//**********************************************************************
function updateStudent($stud){

	$first = $stud->name->firstName;
	$last = $stud->name->lastName;
	$mi = $stud->name->MI;

	$city = $stud->address->city;
	$state = $stud->address->state;
	$zip = $stud->address->zipcode;
	$street = $stud->address->streetName;
	$country = $stud->address->country;
	$POBox = $stud->address->POBox;

	$area = $stud->phoneNumber->area;
	$pref = $stud->phoneNumber->prefix;
	$suffix = $stud->phoneNumber->suffix;
	$countryCode = $stud->phoneNumber->countryCode;
	 

	$math = $stud->gre->math;
	$verbal = $stud->gre->verbal;
	$analytical = $stud->gre->analytical;

	$sID = $stud->school->idNumber;

	$query = "UPDATE students SET firstName='$first', 
				        lastName='$last',
				        MI='$mi',
					email='$stud->email',
					city='$city',
					state='$state',
					zip='$zip',
					country='$country',	 
					street='$street',
					POBox='$POBox',
					area='$area',
					prefix='$pref',
					sufix='$suffix',
					cCode='$countryCode',
					ssn='$stud->ssNumber',
					toefl='$stud->toefl',
					math='$math',
					verbal='$verbal',
					analy='$analytical',
					tgpa='$stud->tgpa',
					dob='$stud->dob',
					status='$stud->status',
					finalLetter='$stud->finalLetter',
					cGpa='$stud->cGPA',
					programType='$stud->programType',
					project='$stud->project',
					typeProg='$stud->typeProg',
					advisor='$stud->advisor', 
					major='$stud->major',
					sID='$sID'
                            WHERE	rNumber='$stud->rNumber'";	

	$rslt = mysql_query($query) or Die("Could not update student $stud->rNumber");

		return $rslt;			


}



//**********************************************************************
//**********************************************************************

function updateApplicant($app){

	$first = $app->name->firstName;
	$last = $app->name->lastName;
	$mi = $app->name->MI;

	$city = $app->address->city;
	$state = $app->address->state;
	$zip = $app->address->zipcode;
	$street = $app->address->streetName;
	$country = $app->address->country;
	$POBox = $app->address->POBox;

	$area = $app->phoneNumber->area;
	$pref = $app->phoneNumber->prefix;
	$suffix = $app->phoneNumber->suffix;
	$countryCode = $app->phoneNumber->countryCode;
	 

	$math = $app->gre->math;
	$verbal = $app->gre->verbal;
	$analytical = $app->gre->analytical;

	$sID = $app->school->idNumber;

	$query = "UPDATE students SET firstName='$first', 
				        lastName='$last',
				        MI='$mi',
					email='$app->email',
					city='$city',
					state='$state',
					zip='$zip',
					country='$country',	 
					street='$street',
					POBox='$POBox',
					area='$area',
					prefix='$pref',
					sufix='$suffix',
					cCode='$countryCode',
					ssn='$app->ssNumber',
					toefl='$app->toefl',
					math='$math',
					verbal='$verbal',
					analy='$analytical',
					tgpa='$app->tgpa',
					dob='$app->dob',
					status='$app->status',
					finalLetter='$app->finalLetter',
					cGpa='$app->cGPA',
					programType='$app->programType',
					typeProg='$app->typeProg',
					major='$app->major',
					sID ='$sID'
                            WHERE	rNumber='$app->userId'";	

	$rslt = mysql_query($query) or Die("Could not update Applicant");

		return $rslt;			


}



//**********************************************************************
//**********************************************************************
function updateUser($user){

	$first=$user->name->firstName;
	$last=$user->name->lastName;
	$mi=$user->name->MI;

	$query = "UPDATE user SET first='$first',
				last='$last',
			
				email='$user->email',
				password='$user->password',
				userType='$user->userType'
			WHERE   username='$user->userId'";

	$result = mysql_query($query) or Die("Could not update user");

	return $result;
}



//**********************************************************************
//**********************************************************************
function putUser($user){
	$first=$user->name->firstName;
	$last=$user->name->lastName;


	$query = "INSERT INTO user (username,first,last,email,password,userType)
			VALUES ('$user->userId','$first','$last','$user->email','$user->password','$user->userType')";

	$result = mysql_query($query) or Die("Could not insert User");

	return $result;
	


}



//**********************************************************************
//**********************************************************************
function getUser($userID){

	$user = new User();

	$query = "SELECT * FROM user WHERE username=\"$userID\"";

	$result = mysql_query($query) or Die("Could not get User");

	$row = mysql_fetch_array($result);

	$user->name->firstName = $row['first'];
	$user->name->lastName = $row['last'];
	$user->email = $row['email'];
	$user->password=$row['password'];
	$user->userId = $userID;
	$user->userType = $row['userType'];

return $user;
}



//**********************************************************************
//**********************************************************************
function deleteStudent($studID){

	$query = "DELETE FROM students WHERE rNumber=\"$studID\"";

	$rslt = mysql_query($query) or Die("Could not delete Student");

	return $rslt;
}



//**********************************************************************
//**********************************************************************
function deleteApplicant($appID){

	$query = "DELETE FROM students WHERE rNumber=\"$appID\"";
	
	$reslt = mysql_query($query) or Die ("Could not delete applicant");

	return $reslt;
}



//**********************************************************************
//**********************************************************************
function deleteCourse($studID,$course){

	$query = "DELETE FROM classes WHERE rNumber=\"$studID\" AND course=\"$course->course\" AND semester=\"$course->semester\"";

	$rslt = mysql_query($query) or Die("Could not delete Course");

	return $rslt;
}


//**********************************************************************
//**********************************************************************
function addUser($user){

	$first = $user->name->firstName;
	$last = $user->name->lastName;
	

	$query = "INSERT INTO user (first,last,email,username,password,userType)
			VALUES ('$first','$last','$user->email',
				'$user->userId','$user->password','$user->userType')";

	$result = mysql_query($query) or die("Could not add user");

	return $result;

}



//**********************************************************************
//**********************************************************************
function deleteUser($userID){
	
	$query = "DELETE FROM user WHERE username=\"$userID\"";

	$reslt = mysql_query($query) or die("Could not delete user");

	return $reslt;
}


//**********************************************************************
//**********************************************************************
function putProject($rNumber,$projToAdd){

	$query = "INSERT INTO project (rNumber,name,sponsor,semester) VALUES ('$rNumber','$projToAdd->projectName','$projToAdd->sponsor','$projToAdd->pSemester')";
	$result = mysql_query($query) or Die("Failed to add project");

	return $result;
}


//**********************************************************************
//**********************************************************************
function deleteProject($id,$proj){
	
	$query="delete from project where rNumber=\"$id\" AND name=\"$proj->projectName\"";

	$res = mysql_query($query) or die("Could not delete project");

	return $res;
}


//**********************************************************************
//**********************************************************************
function getProjectList($rNumber){
	$proj = array();

  $query = "SELECT * FROM project WHERE rNumber=\"$rNumber\"";

	$relst = mysql_query($query) or Die("No project dice");

	while($row = mysql_fetch_array($relst)){
	$projectName = $row['name'];
	$sponsor = $row['sponsor'];
	$pSemester = $row['semester'];
	$p = new Project($projectName,$sponsor,$pSemester);
	array_push($proj,$p);
	}

        return $proj;
}



//**********************************************************************
//**********************************************************************
function getListApplicants(){
	$ret = array();
	$result = mysql_query("SELECT * FROM students WHERE app=1");
	while($row = mysql_fetch_array($result)){
		array_push($ret, $row);
	}	
	return $ret;
}



//**********************************************************************
//**********************************************************************
function getListUsers(){	
	$ret = array();
	//mysql stuff here
	$result = mysql_query("SELECT * FROM user ORDER BY userType");
	while($row = mysql_fetch_array($result))
	{
		array_push($ret, $row);
	}	

	return $ret;
}



//**********************************************************************
//**********************************************************************
function getListStudents(){
	$ret = array();
	$result = mysql_query("SELECT * FROM students WHERE app=0");
	while($row = mysql_fetch_array($result))
	{
		array_push($ret, $row);
	}	
	return $ret;
}





//**********************************************************************
//    Added by Beifang:
//To get student List
//**********************************************************************
function getStudentList(){
        $list_of_students = array();

	$query = "SELECT firstName, lastName, rNumber FROM students WHERE app=0 ORDER BY lastName desc";
	$gotSList = mysql_query($query) or die("No Student List gotten");

	while($student = mysql_fetch_array($gotSList)){
	  	$first = $student['firstName'];
		$last = $student['lastName'];
		$rNumber = $student['rNumber'];
	$sdt = new SimpleStudent($first,$last,$rNumber);
	array_push($list_of_students,$sdt);
	}
        return $list_of_students;

}


//**********************************************************************
//    Added by Beifang:
//To get applicant List
//**********************************************************************
function getApplicantList(){
        $list_of_students = array();

	$query = "SELECT firstName, lastName,rNumber FROM students WHERE app=1 ORDER BY lastName desc";
	$gotSList = mysql_query($query) or die("No Student List gotten");

	while($student = mysql_fetch_array($gotSList)){
	  	$first = $student['firstName'];
		$last = $student['lastName'];
		$rNumber = $student['rNumber'];
	$sdt = new SimpleStudent($first,$last,$rNumber);
	array_push($list_of_students,$sdt);
	}
        return $list_of_students;

}


//**********************************************************************
//  Added by Beifang Yi
// To get tCourses List
//**********************************************************************
function getTransCourseList($studentID){
 $list_of_unr_courses = array();

	$query = "SELECT * FROM classes WHERE rNumber = \"$studentID\"";
	$gotUNRClasses = mysql_query($query) or die("No UNR classes gotten");
	

	while($UNRClasses = mysql_fetch_array($gotUNRClasses)){
	  	$grade = $UNRClasses['grade'];
		$semester = $UNRClasses['semester'];
		$course = $UNRClasses['course'];
		$type = $UNRClasses['type'];
		$status = $UNRClasses['status'];
	$clas = new Course($course,$grade,$semester,$type,$status);
	array_push($list_of_unr_courses,$clas);	

	}
return $list_of_unr_courses;

}

//**********************************************************************
// Added by Beifang Yi
//**********************************************************************
function getNoteses($applicantID){
   
        $res=array();
	$query = "SELECT comment FROM comments WHERE rNumber = \"$applicantID\"";
	$results = mysql_query($query) or die("Could not get notes for $applicantID");
       while(($ress=mysql_fetch_array($results))!=NULL) 
        $res[]=$ress['comment'];
	//$res = mysql_fetch_row($results);

	return $res;


}



}

?>
