<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');

	$db = mysql_select_db('uclit_db', $uclit_dbConn) or die ("Unable to select uclit_db database.");
	$QueryDept = "SELECT dept_id, dept_name, building, dept_head_id FROM departments ORDER BY dept_name" ;
	$dept_result = mysql_query($QueryDept, $equipConn) or die("Couldn't execute query. <p>$QueryDept</p>");
		
	if(!$_GET['pid'])
	{
		$pid = '';
		$lname = '';
		$fname = '';
		$mname = '';
		$dept_id = '';
		$mail_location = '';
		$email = '';
		$phone = '';
		$fax = '';
		$web_role = '';
	}
	else //Page is being called from edit or delete
	{
		$pid = $_GET['pid'];
		$uaction = $_GET['uaction'];

		$sql_personnel = "SELECT personnel.personnel_id,
       personnel.last_name,
       personnel.first_name,
       personnel.middle_name,
       personnel.dept_id,
       personnel.e_mail,
       personnel.phone,
       personnel.web_role,
       personnel.room,
       personnel.duties,
       personnel.duties_sec,
       personnel.removed,
       personnel.title,
       personnel.ID_Num,
	   personnel.PAF,
	   personnel.PAF_date,
       departments.dept_id,
       departments.dept_name,
       departments.building,
       departments.dept_head_id
					FROM departments
  				    INNER JOIN personnel ON (departments.dept_id = personnel.dept_id) WHERE personnel_id='$pid'";
			
		$employee_result = mysql_query($sql_personnel, $uclit_dbConn) or die ("Unable to exercute query: <p>$sql_personnel</p>");
		
		while($row = mysql_fetch_array($employee_result))
		{
			$pid = $row['personnel_id'];
			$lname = $row['last_name'];
			$fname = $row['first_name'];
			$mname = $row['middle_name'];
			$dept_id = $row['dept_id'];
			$email = $row['e_mail'];
			$phone = $row['phone'];
			$web_role = $row['web_role'];
			$title = $row['title'];
			$id_num = $row['ID_Num'];
			$PAF = $row['PAF'];
			$PAF_date = $row['PAF_date'];
			$bldg = $row['building'];
			$dept_head_id = $row['dept_head_id'];
		}
		$sql_datajack = "SELECT equipment_detail.personnel_id, equipment_detail.jacks_id, personnel.personnel_id FROM equipment_detail
		INNER JOIN personnel ON (equipment_detail.personnel_id = personnel.personnel_id) WHERE equipment_detail.personnel_id='$pid'";
		$db = mysql_select_db('equipment', $equipConn) or die ("Unable to select equipment database.");
		$datajack_result = mysql_query($sql_datajack, $equipConn) or die ("Unable to execute query: <p>$sql_datajack</p>");
			
		while($row = mysql_fetch_array($datajack_result))
		{
			$djid = $row['jacks_id'];
			$sql_jack_personnel = "SELECT data_jacks.jack_id, data_jacks.data_jack, data_jacks.approved, data_jacks.active FROM data_jacks
			INNER JOIN equipment_detail ON (equipment_detail.jacks_id = data_jacks.jack_id) WHERE data_jacks.jack_id='$djid'";
			$jack_personnel_result = mysql_query($sql_jack_personnel, $equipConn) or die ("Unable to execute query: <p>$sql_jack_personnel</p>");
			while($row = mysql_fetch_array($jack_personnel_result))
			{
				$datajack = $row['data_jack'];
				$datajackid = $row['jack_id'];
				$approvedjack = $row['approved'];
				$activejack = $row['active'];
				$approveddate = $row['date_approved'];
		
		
				$DisplayQuote .="<tr>
						  <td>$datajack</td>
						  <td>$approvedjack</td>
						  <td>$approveddate</td>
						  <td>$activejack</td>
						  </tr>";
			}
		}
		$sql_voicejack = "SELECT equipment_detail.personnel_id, equipment_detail.voice_id, personnel.personnel_id FROM equipment_detail
		INNER JOIN personnel ON (equipment_detail.personnel_id = personnel.personnel_id) WHERE equipment_detail.personnel_id='$pid'";
		$voicejack_result = mysql_query($sql_voicejack, $equipConn) or die ("Unable to execute query: <p>$sql_datajack</p>");
		
		while($row = mysql_fetch_array($voicejack_result))
		{
			$vid = $row['voice_id'];
			$sql_vjack_personnel = "SELECT voice_jacks.jack_id, voice_jacks.voice_jack, voice_jacks.approved, voice_jacks.active, voice_jacks.date_approved FROM voice_jacks
			INNER JOIN equipment_detail ON (equipment_detail.voice_id = voice_jacks.jack_id) WHERE voice_jacks.jack_id='$vid'";
			$vjack_personnel_result = mysql_query($sql_vjack_personnel, $equipConn) or die ("Unable to execute query: <p>$sql_vjack_personnel</p>");
			while($row = mysql_fetch_array($vjack_personnel_result))
			{
				$voicejack = $row['voice_jack'];
				$voicejackid = $row['jack_id'];
				$approvedvjack = $row['approved'];
				$activevjack = $row['active'];
				$approvedvdate = $row['date_approved'];

				$DisplayQuote2 ="<tr>
						  <td>$voicejack</td>
						  <td>$approvedvjack</td>
						  <td>$approvedvdate</td>
						  <td>$activevjack</td>
						  </tr>";
			}
		}
	}	

	if(!isset($uaction))
	{
		$h3 = 'Add New Employee';
		$goto = 'process_employee_add.php';
		$buttonvalue = 'Add Employee';
	}
	elseif ($uaction == 'edit')
	{
		$h3 = "Update Record[ '$pid' ] from Personnel";
		$goto = 'process_employeeud.php';
		$buttonvalue = 'Update Employee';
	}
	elseif ($uaction == 'delete')
	{
		$h3 = "Delete Current Record[ '$pid' ] from Monitors?";
		$goto = 'process_employeeud.php';
		$buttonvalue = 'Delete Employee';
	}	

echo "
    <h2>$h3</h2>
	<font color='red'>*</font><font size='-1'>- Indicates required fields</font>
    <form action='$goto' method='post' name='employee_form' onSubmit='return validator();'>
	<table width='400' height='260'border='0' cellspacing='1' cellpadding='1'>
	  <tr>
	    <td width='33%' align='right'>Personnel ID:&nbsp;</td>
	    <td width='67%'><input name='pid' type='text' value='$pid' disabled></td>
	  	<td width='40%' align='right' >PAF Received:&nbsp;</td>";
	    
		echo"    <td align=left>
	 <INPUT type='checkbox' name='PAF_sel' value='1'";  
	 if($PAF == '1')
 		echo"CHECKED disabled>"; 
	 else
		echo" disabled>";
echo"
		  
	  </tr>
	  <tr>
	    <td align='right'>Last Name:&nbsp;</td>
	    <td><input name='lname' type='text' value='$lname'><font color='red'>*</font></td>
	    <td width='40%' align='right'>PAF Received Date:&nbsp;</td>
	    <td width='60%'><input name='PAF_date' type='text' value='$PAF_date' disabled></td>
	  </tr>
	  <tr>
	    <td align='right'>First Name:&nbsp;</td>
	    <td><input name='fname' type='text' value='$fname'><font color='red'>*</font></td>
	  </tr>
	  <tr>
	    <td align='right'>Middle Name Initial:&nbsp;</td>
	    <td><input name='mname' type='text' value='$mname' size='2' maxlength='1'></td>
	  </tr>
	  <tr>
	    <td align='right'>Department ID:&nbsp;</td>
	    <td><select name='department'>
			  <option value=''>Select ...</option>";
		while($row = mysql_fetch_array($dept_result))
		{
			$fdept_id = $row['dept_id'];
			$dept_name = $row['dept_name'];
		
			if ($dept_id == $fdept_id)
			{	echo "$dept_id == $fdept_id";
				echo "<option value='$fdept_id' selected>$dept_name</option>";
			}
			else 
			{
				echo "<option value='$fdept_id'>$dept_name</option>";
			}

		}
			  
echo "			  
	        </select><font color='red'>*</font></td>
	  </tr>
	  <tr>
	    <td align='right'>E-mail:&nbsp;</td>
	    <td><input name='email' type='text' value='$email' size='35' maxlength='30'></td>
	  </tr>
	  <tr>
	    <td align='right'>Telephone #:&nbsp;</td>
	    <td><input name='phone' type='text' value='$phone' size='20' maxlength='15'></td>
	  </tr>
	  <tr>
	    <td align='right'>Web Role:&nbsp;</td>
	    <td><!--<input name='web_role' type='text' value='$web_role' size='20' maxlength='15'>-->
		<select name='web_role'> ";
		if ($web_role != '' && isset($uaction))
		{
			if (web_role == '*')
				echo "<option value='$web_role' selected>None</option>";
			else 
				echo "<option value='$web_role' selected>$web_role</option>";
		}
		echo "
		   <option value='*'>None</option>
		   <option value='Contributor'>Contributor</option>
		   <option value='Developer'>Developer</option>
		   <option value='Editor'>Editor</option>

	     </select>
        </td>
	  </tr>
	  <tr>";
	   
		$sql_supervisor = "SELECT personnel.personnel_id,
      					 personnel.last_name,
      					 personnel.first_name,
      					departments.dept_id,
       					departments.dept_name,
       					departments.building,
       					departments.dept_head_id
						FROM departments
   						INNER JOIN personnel ON (departments.dept_id = personnel.dept_id) WHERE personnel_id='$dept_head_id'";

		$db = mysql_select_db('uclit_db', $uclit_dbConn) or die ("Unable to select uclit_db database."); 
	  	$supervisor_result = mysql_query($sql_supervisor, $uclit_dbConn) or die ("Unable to exercute query: <p>$sql_personnel</p>");
			
			while($row = mysql_fetch_array($supervisor_result))
			{
				$pid_sup = $row['personnel_id'];
				$lname_sup = $row['last_name'];
				$fname_sup = $row['first_name'];
				$mname_sup = $row['middle_name'];
				$dept_id_sup = $row['dept_id'];
				$bldg_sup = $row['building'];
				$dept_head_id = $row['dept_head_id'];
			}
		echo"
	    <td width='33%' align='right'>Supervisor:&nbsp;</td>
	    <td width='67%'><input name='supervisor' type='text' value='$lname_sup, $fname_sup' disabled></td>
	  </tr>
	   <tr>
	    <td width='33%' align='right'>Building:&nbsp;</td>
	    <td width='67%'><input name='building' type='text' value='$bldg' disabled></td>
	  </tr>
	  <tr>
	    <td width='33%' align='right'>Title:&nbsp;</td>
	    <td width='67%'><input name='title' type='text' value='$title'></td>
	  </tr>
	  <tr>
	    <td width='33%' align='right'>University ID Number:&nbsp;</td>
	    <td width='67%'><input name='id_num' type='text' value='$id_num'></td>
	  </tr>
	  <tr>
	    <td><input name='hpid' type='hidden' value='$pid'></td>
	    <td><input name='uaction' type='hidden' value='$uaction'></td>
	  </tr>
	  <tr>
	    <td>&nbsp;</td>
	    <td><input name='submit' type='submit' value='$buttonvalue'></td>
	  </tr>
	  <tr>
	    <td colspan='2'></td>
	  </tr>
	</table>
	Data Jack Status
	<table border='1' width='90%' cellpadding='1' cellspacing='1' >
    <tr>
    	<td align='center'><b>Data Jack Number</b></td>
    	<td align='center'><b>Approved</b></td>
    	<td align='center'><b>Approved Date</b></td>
    	<td align='center'><b>Active</b></td>
    </tr>
	
	$DisplayQuote 
	</table>
	<br>
	Voice Jack Status
	<table border='1' width='90%' cellpadding='1' cellspacing='1' >
    <tr>
    	<td align='center'><b>Voice Jack Number</b></td>
    	<td align='center'><b>Approved</b></td>
    	<td align='center'><b>Approved Date</b></td>
    	<td align='center'><b>Active</b></td>
    </tr>
	$DisplayQuote2 
	</table>
	</form>
	<tr>
	    <td colspan='2' align='center'>
		</td>
	  </tr>";
	
?>
	<script language='javascript'>

	function validator()
	{
		var noErrors;
		var msgError = 'Please enter data in the following fields\\n';
		var obj = document.employee_form;
		
		if (obj.lname.value != '' && obj.fname.value != '' && obj.department.value != '')
		{
			return (true);
		}
		else //
		{
			//required fields is empty
			noErrors = false;
	
			if(obj.lname.value == '')
			{
				msgError += ''Last Name' field\\n';
				obj.lname.focus();
			}
			if(obj.fname.value == '')
			{
				msgError += ''First Name' field\\n';
				if(obj.lname.value != '')
					obj.fname.focus();
			}
			if(obj.department.value == '')
			{	
				msgError += ''Department' list\\n';
				if(obj.fname.value != '')
					obj.department.focus();
			}
	
			//errors found
			if(!noErrors)
			{
				alert(msgError);
				return (noErrors);
			}
		}
	}//end function
	</script>