<?php
	include('/var/www/html/uclit/protected/common/login/check.php');
	include('/var/www/html/uclit/protected/common/css_login/css_head2.php');
	include('/var/www/html/uclit/protected/connections/db_login.php');

	
	$username = $_SESSION['username'];
	
	$sql_pers = "Select username, personnel_id From users Where username = '$username'";
    $dbpers = mysql_select_db("login", $loginConn) or die ("Unable to select uclit_db database."); 
	$pers_result = mysql_query($sql_pers, $loginConn) or die ("Unable to query the following SQL statement:<p>$sql_pers</p>");	
	
	while($row = mysql_fetch_array($pers_result))
	{
		$personnel_id = $row['personnel_id'];
	}
	
	include('/var/www/html/uclit/protected/connections/db_pers.php');

	$sql_dept = "SELECT dept_id, personnel_id from personnel WHERE personnel_id='$personnel_id'";
    $db = mysql_select_db('uclit_db', $uclit_dbConn) or die ("Unable to select uclit_db database.");   	
    $dept_result = mysql_query($sql_dept, $uclit_dbConn) or die ("Unable to query the following SQL statement:<p>$sql_dept</p>");	
	
	while($row = mysql_fetch_array($dept_result))
	{
		$dept_id = $row['dept_id'];
	}

?>
<table border='1' width='90%' cellpadding='1' cellspacing='1' >
  <tr>
    <td align='center'><b>Last Name</b></td>
    <td align='center'><b>First Name</b></td>
    <td align='center'><b>Department Name</b></td>
    <td align='center'><b>E-mail</b></td>
    <td align='center'><b>Telephone</b></td>
    <td align='center'><b>Room</b></td>
    <td align='center'><b>Working Title</b></td>
    <td align='center'><b>Edit</b></td>
  </tr>	
<?php    	

	$sql = "SELECT personnel.personnel_id,
				personnel.last_name,
				personnel.first_name,
				personnel.dept_id,
				personnel.middle_name,
				personnel.e_mail,
				personnel.phone,
				personnel.web_role,
				personnel.room,
				personnel.duties,
				personnel.duties_sec,
				personnel.removed,
				personnel.working_title,
				departments.dept_id,
				departments.dept_name
			FROM personnel
			INNER JOIN departments ON (personnel.dept_id = departments.dept_id)
			WHERE personnel.removed='0' and personnel.dept_id=\"$dept_id\"";
	//new query
	//SELECT personnel_id, last_name, first_name, middle_name, dept_id, e_mail, phone, web_role FROM personnel ORDER BY dept_id, last_name, first_name
	//old query
	//SELECT pid, lname, fname, mname, dept_id, mail_location, email, phone, fax, web_role FROM $dbtable ORDER BY dept_id, lname, fname

	$db = mysql_select_db('uclit_db', $uclit_dbConn) or die ("Unable to select uclit_db database.");
	$sql_result = mysql_query($sql, $uclit_dbConn) or die ("Unable to query the following SQL statement:<p>$sql</p>");

	while ($row = mysql_fetch_array($sql_result))
	{
		$personnel_id = $row['personnel_id'];
		$last_name = $row['last_name'];
		$first_name = $row['first_name'];
		$middle_name = $row['middle_name'];
		$dept_id = $row['dept_id'];
		$e_mail = $row['e_mail'];
		$phone = $row['phone'];
		$web_role = $row['web_role'];
		$room = $row['room'];
		$duties = $row['duties'];
		$duties_sec = $row['duties_sec'];
		$removed = $row['removed'];
		$title = $row['working_title'];
		$department_dept_id = $row['departments.dept_id'];
		$department_dept_name = $row['dept_name'];
			
    		
		echo"<tr>
			   <td>$last_name</td>
			   <td>$first_name</td>
			   <td>$department_dept_name</td>
			   <td><a href=mailto:$e_mail>$e_mail</a></td>
			   <td>$phone</td>
			   <td>$room</td>
			   <td>$title</td>  
			   <td align='center'><a href=\"http://ul.uc.edu/uclit/protected/depthead/edit_staff.php?idnum=$personnel_id\"><img src=\"edit2.gif\" border='0'></a></td>  
			 </tr>";
	}
	echo"</table>";
		
	include('/var/www/html/uclit/protected/common/css_login/css_foot2.php');
?>