<table width="200" border="0" align="center">
  <tr>
    <td><a href="http://ul.uc.edu/uclit/teaming/equipment/add_home.php"><img src="addequip.jpg" alt="Add" width="120" height="50" border="0" /></a></td>
    <td><a href="http://ul.uc.edu/uclit/teaming/equipment/sel_allequiptdetail.php"><img src="equipbydept.jpg" alt="dept" width="120" height="50" border="0" /></a></td>
    <td><a href="http://ul.uc.edu/uclit/teaming/equipment/show_move.php"><img src="searchequip.jpg" alt="search" width="120" height="50" border="0" /></a></td>
    <td><a href="http://ul.uc.edu/uclit/teaming/equipment/show_assignequipt.php"><img src="Assign.jpg" alt="assign" width="120" height="50" border="0" /></a></td>
    <td><a href="http://ul.uc.edu/uclit/teaming/equipment/printmon.php"><img src="printmon.jpg" alt="print" width="120" height="50" border="0" /></a></td>
  </tr>
</table>

<?php

	include('/var/www/html/uclit/protected/connections/db_equip.php');
	include('/var/www/html/uclit/protected/connections/db_pers.php');
	
    	$dept_id = $_POST['staff_dept'];
		$sql_dept = "SELECT dept_name
				FROM departments
   				WHERE dept_id='$dept_id'";

    	$db = mysql_select_db('uclit_db', $uclit_dbConn) or die ("Unable to select uclit_db database.");
    	$sql_dept_result = mysql_query($sql_dept, $uclit_dbConn) or die ("Unable to query the following SQL statement:<p>$sql</p>");
    
		while ($row = mysql_fetch_array($sql_dept_result))
    	{
			$department_dept_name = $row['dept_name'];
		}

			echo"<h2>List of ALL The Equipment in <br> $department_dept_name</h2>";
?>			
			<table width='660' border='1' class='sortable' id='maintable' border='1' cellpadding='2' cellspacing='2'>
				  <tr>
                    <td align='center' width='60'>ReAssign</td>
					<td align='center' width='60'>Detail ID</td>
					<td align='center' width='93'>Employee ID</td>
					<td align='center' width='140'>Workstation ID</td>
					<td align='center' width='140'>Printer Serial</td>
					<td align='center' width='95'>Data Jack ID</td>
					<td align='center' width='95'>Voice Jack ID</td>
				  </tr>
<?php			
		$sql = "SELECT personnel.personnel_id,
       				personnel.last_name,
       				personnel.first_name,
       				personnel.dept_id,
       				personnel.middle_name,
       				departments.dept_id,
       				departments.dept_name
				FROM personnel
   				INNER JOIN departments ON (personnel.dept_id = departments.dept_id)
				WHERE personnel.dept_id LIKE '%$dept_id%'";

    	$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'];
			$department_dept_name = $row['dept_name'];
			$db_equipt_detail_tbl = 'equipment_detail';
    		$sql_detail = "SELECT 
							  computers.workstation_id,
							  equipment_detail.detail_id,
							  equipment_detail.personnel_id,
							  equipment_detail.computer_serial,
							  equipment_detail.monitor_serial,
							  equipment_detail.printer_serial,
							  equipment_detail.jacks_id,
							  equipment_detail.voice_id
							FROM
							  $db_equipt_detail_tbl
							  INNER JOIN computers ON ($db_equipt_detail_tbl.computer_serial = computers.computer_serial)
							  INNER JOIN personnel ON ($db_equipt_detail_tbl.personnel_id = personnel.personnel_id)
							WHERE
							  personnel.personnel_id='$personnel_id'";
    		
			$db = mysql_select_db('equipment', $equipConn) or die ("Unable to select equipment database.");
			$sql_detail_result = mysql_query($sql_detail, $equipConn) or die ("Unable to query the following SQL_detail statment :<p>$sql_detail</p>");
			$counter = 0;
			
			while($rowPC = mysql_fetch_array($sql_detail_result))
			{
				$edid = $rowPC['detail_id'];
				$ekey = $rowPC['personnel_id'];
				$wkey = $rowPC['workstation_id'];
				$pckey = $rowPC['computer_serial'];
				$mkey = $rowPC['monitor_serial'];
				$pkey = $rowPC['printer_serial'];
				$vdjkey = $rowPC['jacks_id'];
				$voicekey = $rowPC['voice_id'];
				$counter++;
				if ($counter % 2 == 0)
					$columnColor = '#CCCCCC';
				else 
					$columnColor = '#FFFFFF';
				
				$sql_dj = "SELECT data_jack
				FROM data_jacks
   				WHERE jack_id='$vdjkey'";

    			$sql_dj_result = mysql_query($sql_dj, $equipConn) or die ("Unable to query the following SQL statement:<p>$sql</p>");
    
				while ($row = mysql_fetch_array($sql_dj_result))
    			{
					$dj_name = $row['data_jack'];
				}
				
				$sql_vj = "SELECT voice_jack
				FROM voice_jacks
   				WHERE jack_id='$voicekey'";

    			$sql_vj_result = mysql_query($sql_vj, $equipConn) or die ("Unable to query the following SQL statement:<p>$sql</p>");
    
				while ($row = mysql_fetch_array($sql_vj_result))
    			{
					$vj_name = $row['voice_jack'];
				}	
							
				$displayblock = "
			<tr>
			 <td align='center' bgcolor='$columnColor'><a href='show_reassign.php?edid=$edid&pid=$ekey&computer_serial=$pckey&monitor_serial=$mkey&jack_id=$vdjkey&vjack_id=$voicekey&pkey=$pkey'><img src='../../images/ReAssign.gif' border='0'></a></td>
			
			  <td align='center' bgcolor='$columnColor'><a href='show_relationdetail.php?edid=$edid&uaction=display'>$edid</a></td>
			  <td align='center' bgcolor='$columnColor'><a href='show_addemployee.php?pid=$ekey&uaction=edit'>$last_name, $first_name</a></td>
			  <td bgcolor='$columnColor'><a href='show_pcspecs.php?computer_serial=$pckey'>$wkey ($pckey)</a></td>
			  <td bgcolor='$columnColor'><a href='show_addprinter.php?printer_serial=$pkey&uaction=edit'>$pkey</a></td>
			  <td align='center' bgcolor='$columnColor'><a href='show_addpdjack.php?jack_id=$vdjkey&uaction=edit'>$dj_name</a></td>
			  <td align='center' bgcolor='$columnColor'><a href='show_addvjack.php?jack_id=$voicekey&uaction=edit'>$vj_name</a></td>
			</tr>";	
			echo "$displayblock ";
			}    
		}
		
		echo "</table> ";
